Changeset 2566:9bf417837888 for plugins/blogroll/class.dc.blogroll.php
- Timestamp:
- 11/17/13 20:25:53 (12 years ago)
- Branch:
- 2.6
- Children:
- 2567:6c11245cbf04, 2568:61c67a7d17fa
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/blogroll/class.dc.blogroll.php
r1179 r2566 17 17 private $con; 18 18 private $table; 19 19 20 20 public function __construct($blog) 21 21 { … … 24 24 $this->table = $this->blog->prefix.'link'; 25 25 } 26 26 27 27 public function getLinks($params=array()) 28 28 { … … 31 31 'FROM '.$this->table.' '. 32 32 "WHERE blog_id = '".$this->con->escape($this->blog->id)."' "; 33 33 34 34 if (isset($params['link_id'])) { 35 35 $strReq .= 'AND link_id = '.(integer) $params['link_id'].' '; 36 36 } 37 37 38 38 $strReq .= 'ORDER BY link_position '; 39 39 40 40 $rs = $this->con->select($strReq); 41 41 $rs = $rs->toStatic(); 42 42 43 43 $this->setLinksData($rs); 44 44 45 45 return $rs; 46 46 } 47 47 48 48 public function getLink($id) 49 49 { 50 50 $params['link_id'] = $id; 51 51 52 52 $rs = $this->getLinks($params); 53 53 54 54 return $rs; 55 55 } 56 56 57 57 public function addLink($title,$href,$desc='',$lang='', $xfn='') 58 58 { 59 59 $cur = $this->con->openCursor($this->table); 60 60 61 61 $cur->blog_id = (string) $this->blog->id; 62 62 $cur->link_title = (string) $title; … … 65 65 $cur->link_lang = (string) $lang; 66 66 $cur->link_xfn = (string) $xfn; 67 67 68 68 if ($cur->link_title == '') { 69 69 throw new Exception(__('You must provide a link title')); 70 70 } 71 71 72 72 if ($cur->link_href == '') { 73 73 throw new Exception(__('You must provide a link URL')); 74 74 } 75 75 76 76 $strReq = 'SELECT MAX(link_id) FROM '.$this->table; 77 77 $rs = $this->con->select($strReq); 78 78 $cur->link_id = (integer) $rs->f(0) + 1; 79 79 80 80 $cur->insert(); 81 81 $this->blog->triggerBlog(); 82 82 } 83 83 84 84 public function updateLink($id,$title,$href,$desc='',$lang='', $xfn='') 85 85 { 86 86 $cur = $this->con->openCursor($this->table); 87 87 88 88 $cur->link_title = (string) $title; 89 89 $cur->link_href = (string) $href; … … 91 91 $cur->link_lang = (string) $lang; 92 92 $cur->link_xfn = (string) $xfn; 93 93 94 94 if ($cur->link_title == '') { 95 95 throw new Exception(__('You must provide a link title')); 96 96 } 97 97 98 98 if ($cur->link_href == '') { 99 99 throw new Exception(__('You must provide a link URL')); 100 100 } 101 101 102 102 $cur->update('WHERE link_id = '.(integer) $id. 103 103 " AND blog_id = '".$this->con->escape($this->blog->id)."'"); 104 104 $this->blog->triggerBlog(); 105 105 } 106 106 107 107 public function updateCategory($id,$desc) 108 108 { 109 109 $cur = $this->con->openCursor($this->table); 110 110 111 111 $cur->link_desc = (string) $desc; 112 112 113 113 if ($cur->link_desc == '') { 114 114 throw new Exception(__('You must provide a category title')); 115 115 } 116 116 117 117 $cur->update('WHERE link_id = '.(integer) $id. 118 118 " AND blog_id = '".$this->con->escape($this->blog->id)."'"); 119 119 $this->blog->triggerBlog(); 120 120 } 121 121 122 122 public function addCategory($title) 123 123 { 124 124 $cur = $this->con->openCursor($this->table); 125 125 126 126 $cur->blog_id = (string) $this->blog->id; 127 127 $cur->link_desc = (string) $title; 128 128 $cur->link_href = ''; 129 129 $cur->link_title = ''; 130 130 131 131 if ($cur->link_desc == '') { 132 132 throw new Exception(__('You must provide a category title')); 133 133 } 134 134 135 135 $strReq = 'SELECT MAX(link_id) FROM '.$this->table; 136 136 $rs = $this->con->select($strReq); 137 137 $cur->link_id = (integer) $rs->f(0) + 1; 138 138 139 139 $cur->insert(); 140 140 $this->blog->triggerBlog(); 141 141 142 142 return $cur->link_id; 143 143 } 144 144 145 145 public function delItem($id) 146 146 { 147 147 $id = (integer) $id; 148 148 149 149 $strReq = 'DELETE FROM '.$this->table.' '. 150 150 "WHERE blog_id = '".$this->con->escape($this->blog->id)."' ". 151 151 'AND link_id = '.$id.' '; 152 152 153 153 $this->con->execute($strReq); 154 154 $this->blog->triggerBlog(); 155 155 } 156 156 157 157 public function updateOrder($id,$position) 158 158 { 159 159 $cur = $this->con->openCursor($this->table); 160 160 $cur->link_position = (integer) $position; 161 161 162 162 $cur->update('WHERE link_id = '.(integer) $id. 163 163 " AND blog_id = '".$this->con->escape($this->blog->id)."'"); 164 164 $this->blog->triggerBlog(); 165 165 } 166 167 166 167 168 168 private function setLinksData($rs) 169 169 { … … 171 171 while ($rs->fetch()) { 172 172 $rs->set('is_cat',!$rs->link_title && !$rs->link_href); 173 173 174 174 if ($rs->is_cat) { 175 175 $cat_title = $rs->link_desc; … … 181 181 $rs->moveStart(); 182 182 } 183 183 184 184 public function getLinksHierarchy($rs) 185 185 { 186 186 $res = array(); 187 187 188 188 foreach ($rs->rows() as $k => $v) 189 189 { … … 192 192 } 193 193 } 194 194 195 195 return $res; 196 196 } 197 197 } 198 ?>
Note: See TracChangeset
for help on using the changeset viewer.