Dotclear


Ignore:
Timestamp:
03/08/18 17:58:39 (8 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Code formatting (PSR-2)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • plugins/blogroll/class.dc.blogroll.php

    r2566 r3730  
    1010# 
    1111# -- END LICENSE BLOCK ----------------------------------------- 
    12 if (!defined('DC_RC_PATH')) { return; } 
     12if (!defined('DC_RC_PATH')) {return;} 
    1313 
    1414class dcBlogroll 
    1515{ 
    16      private $blog; 
    17      private $con; 
    18      private $table; 
     16    private $blog; 
     17    private $con; 
     18    private $table; 
    1919 
    20      public function __construct($blog) 
    21      { 
    22           $this->blog =& $blog; 
    23           $this->con =& $blog->con; 
    24           $this->table = $this->blog->prefix.'link'; 
    25      } 
     20    public function __construct($blog) 
     21    { 
     22        $this->blog  = &$blog; 
     23        $this->con   = &$blog->con; 
     24        $this->table = $this->blog->prefix . 'link'; 
     25    } 
    2626 
    27      public function getLinks($params=array()) 
    28      { 
    29           $strReq = 'SELECT link_id, link_title, link_desc, link_href, '. 
    30                     'link_lang, link_xfn, link_position '. 
    31                     'FROM '.$this->table.' '. 
    32                     "WHERE blog_id = '".$this->con->escape($this->blog->id)."' "; 
     27    public function getLinks($params = array()) 
     28    { 
     29        $strReq = 'SELECT link_id, link_title, link_desc, link_href, ' . 
     30        'link_lang, link_xfn, link_position ' . 
     31        'FROM ' . $this->table . ' ' . 
     32        "WHERE blog_id = '" . $this->con->escape($this->blog->id) . "' "; 
    3333 
    34           if (isset($params['link_id'])) { 
    35                $strReq .= 'AND link_id = '.(integer) $params['link_id'].' '; 
    36           } 
     34        if (isset($params['link_id'])) { 
     35            $strReq .= 'AND link_id = ' . (integer) $params['link_id'] . ' '; 
     36        } 
    3737 
    38           $strReq .= 'ORDER BY link_position '; 
     38        $strReq .= 'ORDER BY link_position '; 
    3939 
    40           $rs = $this->con->select($strReq); 
    41           $rs = $rs->toStatic(); 
     40        $rs = $this->con->select($strReq); 
     41        $rs = $rs->toStatic(); 
    4242 
    43           $this->setLinksData($rs); 
     43        $this->setLinksData($rs); 
    4444 
    45           return $rs; 
    46      } 
     45        return $rs; 
     46    } 
    4747 
    48      public function getLink($id) 
    49      { 
    50           $params['link_id'] = $id; 
     48    public function getLink($id) 
     49    { 
     50        $params['link_id'] = $id; 
    5151 
    52           $rs = $this->getLinks($params); 
     52        $rs = $this->getLinks($params); 
    5353 
    54           return $rs; 
    55      } 
     54        return $rs; 
     55    } 
    5656 
    57      public function addLink($title,$href,$desc='',$lang='', $xfn='') 
    58      { 
    59           $cur = $this->con->openCursor($this->table); 
     57    public function addLink($title, $href, $desc = '', $lang = '', $xfn = '') 
     58    { 
     59        $cur = $this->con->openCursor($this->table); 
    6060 
    61           $cur->blog_id = (string) $this->blog->id; 
    62           $cur->link_title = (string) $title; 
    63           $cur->link_href = (string) $href; 
    64           $cur->link_desc = (string) $desc; 
    65           $cur->link_lang = (string) $lang; 
    66           $cur->link_xfn = (string) $xfn; 
     61        $cur->blog_id    = (string) $this->blog->id; 
     62        $cur->link_title = (string) $title; 
     63        $cur->link_href = (string) $href; 
     64        $cur->link_desc = (string) $desc; 
     65        $cur->link_lang = (string) $lang; 
     66        $cur->link_xfn  = (string) $xfn; 
    6767 
    68           if ($cur->link_title == '') { 
    69                throw new Exception(__('You must provide a link title')); 
    70           } 
     68        if ($cur->link_title == '') { 
     69            throw new Exception(__('You must provide a link title')); 
     70        } 
    7171 
    72           if ($cur->link_href == '') { 
    73                throw new Exception(__('You must provide a link URL')); 
    74           } 
     72        if ($cur->link_href == '') { 
     73            throw new Exception(__('You must provide a link URL')); 
     74        } 
    7575 
    76           $strReq = 'SELECT MAX(link_id) FROM '.$this->table; 
    77           $rs = $this->con->select($strReq); 
    78           $cur->link_id = (integer) $rs->f(0) + 1; 
     76        $strReq       = 'SELECT MAX(link_id) FROM ' . $this->table; 
     77        $rs          = $this->con->select($strReq); 
     78        $cur->link_id = (integer) $rs->f(0) + 1; 
    7979 
    80           $cur->insert(); 
    81           $this->blog->triggerBlog(); 
    82      } 
     80        $cur->insert(); 
     81        $this->blog->triggerBlog(); 
     82    } 
    8383 
    84      public function updateLink($id,$title,$href,$desc='',$lang='', $xfn='') 
    85      { 
    86           $cur = $this->con->openCursor($this->table); 
     84    public function updateLink($id, $title, $href, $desc = '', $lang = '', $xfn = '') 
     85    { 
     86        $cur = $this->con->openCursor($this->table); 
    8787 
    88           $cur->link_title = (string) $title; 
    89           $cur->link_href = (string) $href; 
    90           $cur->link_desc = (string) $desc; 
    91           $cur->link_lang = (string) $lang; 
    92           $cur->link_xfn = (string) $xfn; 
     88        $cur->link_title = (string) $title; 
     89        $cur->link_href = (string) $href; 
     90        $cur->link_desc = (string) $desc; 
     91        $cur->link_lang = (string) $lang; 
     92        $cur->link_xfn  = (string) $xfn; 
    9393 
    94           if ($cur->link_title == '') { 
    95                throw new Exception(__('You must provide a link title')); 
    96           } 
     94        if ($cur->link_title == '') { 
     95            throw new Exception(__('You must provide a link title')); 
     96        } 
    9797 
    98           if ($cur->link_href == '') { 
    99                throw new Exception(__('You must provide a link URL')); 
    100           } 
     98        if ($cur->link_href == '') { 
     99            throw new Exception(__('You must provide a link URL')); 
     100        } 
    101101 
    102           $cur->update('WHERE link_id = '.(integer) $id. 
    103                " AND blog_id = '".$this->con->escape($this->blog->id)."'"); 
    104           $this->blog->triggerBlog(); 
    105      } 
     102        $cur->update('WHERE link_id = ' . (integer) $id . 
     103            " AND blog_id = '" . $this->con->escape($this->blog->id) . "'"); 
     104        $this->blog->triggerBlog(); 
     105    } 
    106106 
    107      public function updateCategory($id,$desc) 
    108      { 
    109           $cur = $this->con->openCursor($this->table); 
     107    public function updateCategory($id, $desc) 
     108    { 
     109        $cur = $this->con->openCursor($this->table); 
    110110 
    111           $cur->link_desc = (string) $desc; 
     111        $cur->link_desc = (string) $desc; 
    112112 
    113           if ($cur->link_desc == '') { 
    114                throw new Exception(__('You must provide a category title')); 
    115           } 
     113        if ($cur->link_desc == '') { 
     114            throw new Exception(__('You must provide a category title')); 
     115        } 
    116116 
    117           $cur->update('WHERE link_id = '.(integer) $id. 
    118           " AND blog_id = '".$this->con->escape($this->blog->id)."'"); 
    119           $this->blog->triggerBlog(); 
    120      } 
     117        $cur->update('WHERE link_id = ' . (integer) $id . 
     118            " AND blog_id = '" . $this->con->escape($this->blog->id) . "'"); 
     119        $this->blog->triggerBlog(); 
     120    } 
    121121 
    122      public function addCategory($title) 
    123      { 
    124           $cur = $this->con->openCursor($this->table); 
     122    public function addCategory($title) 
     123    { 
     124        $cur = $this->con->openCursor($this->table); 
    125125 
    126           $cur->blog_id = (string) $this->blog->id; 
    127           $cur->link_desc = (string) $title; 
    128           $cur->link_href = ''; 
    129           $cur->link_title = ''; 
     126        $cur->blog_id    = (string) $this->blog->id; 
     127        $cur->link_desc = (string) $title; 
     128        $cur->link_href = ''; 
     129        $cur->link_title = ''; 
    130130 
    131           if ($cur->link_desc == '') { 
    132                throw new Exception(__('You must provide a category title')); 
    133           } 
     131        if ($cur->link_desc == '') { 
     132            throw new Exception(__('You must provide a category title')); 
     133        } 
    134134 
    135           $strReq = 'SELECT MAX(link_id) FROM '.$this->table; 
    136           $rs = $this->con->select($strReq); 
    137           $cur->link_id = (integer) $rs->f(0) + 1; 
     135        $strReq       = 'SELECT MAX(link_id) FROM ' . $this->table; 
     136        $rs          = $this->con->select($strReq); 
     137        $cur->link_id = (integer) $rs->f(0) + 1; 
    138138 
    139           $cur->insert(); 
    140           $this->blog->triggerBlog(); 
     139        $cur->insert(); 
     140        $this->blog->triggerBlog(); 
    141141 
    142           return $cur->link_id; 
    143      } 
     142        return $cur->link_id; 
     143    } 
    144144 
    145      public function delItem($id) 
    146      { 
    147           $id = (integer) $id; 
     145    public function delItem($id) 
     146    { 
     147        $id = (integer) $id; 
    148148 
    149           $strReq = 'DELETE FROM '.$this->table.' '. 
    150                     "WHERE blog_id = '".$this->con->escape($this->blog->id)."' ". 
    151                     'AND link_id = '.$id.' '; 
     149        $strReq = 'DELETE FROM ' . $this->table . ' ' . 
     150        "WHERE blog_id = '" . $this->con->escape($this->blog->id) . "' " . 
     151            'AND link_id = ' . $id . ' '; 
    152152 
    153           $this->con->execute($strReq); 
    154           $this->blog->triggerBlog(); 
    155      } 
     153        $this->con->execute($strReq); 
     154        $this->blog->triggerBlog(); 
     155    } 
    156156 
    157      public function updateOrder($id,$position) 
    158      { 
    159           $cur = $this->con->openCursor($this->table); 
    160           $cur->link_position = (integer) $position; 
     157    public function updateOrder($id, $position) 
     158    { 
     159        $cur                = $this->con->openCursor($this->table); 
     160        $cur->link_position = (integer) $position; 
    161161 
    162           $cur->update('WHERE link_id = '.(integer) $id. 
    163                " AND blog_id = '".$this->con->escape($this->blog->id)."'"); 
    164           $this->blog->triggerBlog(); 
    165      } 
     162        $cur->update('WHERE link_id = ' . (integer) $id . 
     163            " AND blog_id = '" . $this->con->escape($this->blog->id) . "'"); 
     164        $this->blog->triggerBlog(); 
     165    } 
    166166 
     167    private function setLinksData($rs) 
     168    { 
     169        $cat_title = null; 
     170        while ($rs->fetch()) { 
     171            $rs->set('is_cat', !$rs->link_title && !$rs->link_href); 
    167172 
    168      private function setLinksData($rs) 
    169      { 
    170           $cat_title = null; 
    171           while ($rs->fetch()) { 
    172                $rs->set('is_cat',!$rs->link_title && !$rs->link_href); 
     173            if ($rs->is_cat) { 
     174                $cat_title = $rs->link_desc; 
     175                $rs->set('cat_title', null); 
     176            } else { 
     177                $rs->set('cat_title', $cat_title); 
     178            } 
     179        } 
     180        $rs->moveStart(); 
     181    } 
    173182 
    174                if ($rs->is_cat) { 
    175                     $cat_title = $rs->link_desc; 
    176                     $rs->set('cat_title',null); 
    177                } else { 
    178                     $rs->set('cat_title',$cat_title); 
    179                } 
    180           } 
    181           $rs->moveStart(); 
    182      } 
     183    public function getLinksHierarchy($rs) 
     184    { 
     185        $res = array(); 
    183186 
    184      public function getLinksHierarchy($rs) 
    185      { 
    186           $res = array(); 
     187        foreach ($rs->rows() as $k => $v) { 
     188            if (!$v['is_cat']) { 
     189                $res[$v['cat_title']][] = $v; 
     190            } 
     191        } 
    187192 
    188           foreach ($rs->rows() as $k => $v) 
    189           { 
    190                if (!$v['is_cat']) { 
    191                     $res[$v['cat_title']][] = $v; 
    192                } 
    193           } 
    194  
    195           return $res; 
    196      } 
     193        return $res; 
     194    } 
    197195} 
Note: See TracChangeset for help on using the changeset viewer.

Sites map