Changeset 3730:5c45a5df9a59 for inc/core/class.dc.postmedia.php
- Timestamp:
- 03/08/18 17:58:39 (7 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/core/class.dc.postmedia.php
r3481 r3730 10 10 # 11 11 # -- END LICENSE BLOCK ----------------------------------------- 12 if (!defined('DC_RC_PATH')) { return;}12 if (!defined('DC_RC_PATH')) {return;} 13 13 14 14 class dcPostMedia 15 15 { 16 protected $core;///< <b>dcCore</b> dcCore instance17 protected $con;///< <b>connection</b> Database connection18 protected $table;///< <b>string</b> Post-Media table name16 protected $core; ///< <b>dcCore</b> dcCore instance 17 protected $con; ///< <b>connection</b> Database connection 18 protected $table; ///< <b>string</b> Post-Media table name 19 19 20 21 20 /** 21 Object constructor. 22 22 23 @param core <b>dcCore</b>dcCore instance24 @param type <b>string</b>Media type filter25 26 public function __construct($core,$type='')27 28 $this->core =&$core;29 $this->con =&$core->con;30 $this->table = $this->core->prefix.'post_media';31 23 @param core <b>dcCore</b> dcCore instance 24 @param type <b>string</b> Media type filter 25 */ 26 public function __construct($core, $type = '') 27 { 28 $this->core = &$core; 29 $this->con = &$core->con; 30 $this->table = $this->core->prefix . 'post_media'; 31 } 32 32 33 34 35 33 /** 34 Returns media items attached to a blog post. Result is an array containing 35 fileItems objects. 36 36 37 @param post_id <b>integer</b>Post ID38 @param media_id <b>integer</b>Optionnal media ID39 @return<b>array</b> Array of fileItems40 41 public function getPostMedia($params=array())42 43 44 'SELECT M.media_file, M.media_id, M.media_path, M.media_title, M.media_meta, M.media_dt, '.45 37 @param post_id <b>integer</b> Post ID 38 @param media_id <b>integer</b> Optionnal media ID 39 @return <b>array</b> Array of fileItems 40 */ 41 public function getPostMedia($params = array()) 42 { 43 $strReq = 44 'SELECT M.media_file, M.media_id, M.media_path, M.media_title, M.media_meta, M.media_dt, ' . 45 'M.media_creadt, M.media_upddt, M.media_private, M.user_id, PM.post_id '; 46 46 47 48 $strReq .= implode(', ',$params['columns']).', ';49 47 if (!empty($params['columns']) && is_array($params['columns'])) { 48 $strReq .= implode(', ', $params['columns']) . ', '; 49 } 50 50 51 52 'FROM '.$this->core->prefix.'media M '.53 'INNER JOIN '.$this->table.' PM ON (M.media_id = PM.media_id) ';51 $strReq .= 52 'FROM ' . $this->core->prefix . 'media M ' . 53 'INNER JOIN ' . $this->table . ' PM ON (M.media_id = PM.media_id) '; 54 54 55 56 $strReq .= $params['from'].' ';57 55 if (!empty($params['from'])) { 56 $strReq .= $params['from'] . ' '; 57 } 58 58 59 60 61 $where[] = "PM.post_id ".$this->con->in($params['post_id']);62 63 64 $where[] = "M.media_id ".$this->con->in($params['media_id']);65 66 67 $where[] = "M.media_path ".$this->con->in($params['media_path']);68 69 70 $where[] = "PM.link_type ".$this->con->in($params['link_type']);71 72 73 59 $where = array(); 60 if (isset($params['post_id'])) { 61 $where[] = "PM.post_id " . $this->con->in($params['post_id']); 62 } 63 if (isset($params['media_id'])) { 64 $where[] = "M.media_id " . $this->con->in($params['media_id']); 65 } 66 if (isset($params['media_path'])) { 67 $where[] = "M.media_path " . $this->con->in($params['media_path']); 68 } 69 if (isset($params['link_type'])) { 70 $where[] = "PM.link_type " . $this->con->in($params['link_type']); 71 } else { 72 $where[] = "PM.link_type='attachment'"; 73 } 74 74 75 $strReq .= 'WHERE '.join('AND ',$where).' ';75 $strReq .= 'WHERE ' . join('AND ', $where) . ' '; 76 76 77 78 79 77 if (isset($params['sql'])) { 78 $strReq .= $params['sql']; 79 } 80 80 81 81 $rs = $this->con->select($strReq); 82 82 83 84 83 return $rs; 84 } 85 85 86 87 86 /** 87 Attaches a media to a post. 88 88 89 @param post_id <b>integer</b>Post ID90 @param media_id <b>integer</b>Optionnal media ID91 @param link_type <b>string</b>Optionnal link type (default: attachment)92 93 public function addPostMedia($post_id,$media_id,$link_type='attachment')94 95 $post_id= (integer) $post_id;96 89 @param post_id <b>integer</b> Post ID 90 @param media_id <b>integer</b> Optionnal media ID 91 @param link_type <b>string</b> Optionnal link type (default: attachment) 92 */ 93 public function addPostMedia($post_id, $media_id, $link_type = 'attachment') 94 { 95 $post_id = (integer) $post_id; 96 $media_id = (integer) $media_id; 97 97 98 $f = $this->getPostMedia(array('post_id'=>$post_id,'media_id'=>$media_id,'link_type'=>$link_type));98 $f = $this->getPostMedia(array('post_id' => $post_id, 'media_id' => $media_id, 'link_type' => $link_type)); 99 99 100 101 102 100 if (!$f->isEmpty()) { 101 return; 102 } 103 103 104 $cur= $this->con->openCursor($this->table);105 $cur->post_id= $post_id;106 $cur->media_id= $media_id;107 104 $cur = $this->con->openCursor($this->table); 105 $cur->post_id = $post_id; 106 $cur->media_id = $media_id; 107 $cur->link_type = $link_type; 108 108 109 110 111 109 $cur->insert(); 110 $this->core->blog->triggerBlog(); 111 } 112 112 113 114 113 /** 114 Detaches a media from a post. 115 115 116 @param post_id <b>integer</b>Post ID117 @param media_id <b>integer</b>Optionnal media ID118 @param link_type <b>string</b>Optionnal link type119 120 public function removePostMedia($post_id,$media_id,$link_type=null)121 122 $post_id= (integer) $post_id;123 116 @param post_id <b>integer</b> Post ID 117 @param media_id <b>integer</b> Optionnal media ID 118 @param link_type <b>string</b> Optionnal link type 119 */ 120 public function removePostMedia($post_id, $media_id, $link_type = null) 121 { 122 $post_id = (integer) $post_id; 123 $media_id = (integer) $media_id; 124 124 125 $strReq = 'DELETE FROM '.$this->table.' '.126 'WHERE post_id = '.$post_id.' '.127 'AND media_id = '.$media_id.' ';128 129 $strReq .= "AND link_type = '".$this->con->escape($link_type)."'";130 131 132 133 125 $strReq = 'DELETE FROM ' . $this->table . ' ' . 126 'WHERE post_id = ' . $post_id . ' ' . 127 'AND media_id = ' . $media_id . ' '; 128 if ($link_type != null) { 129 $strReq .= "AND link_type = '" . $this->con->escape($link_type) . "'"; 130 } 131 $this->con->execute($strReq); 132 $this->core->blog->triggerBlog(); 133 } 134 134 135 136 137 135 /** 136 Returns media items attached to a blog post. Result is an array containing 137 fileItems objects. 138 138 139 @param post_id <b>integer</b>Post ID140 @param media_id <b>integer</b>Optionnal media ID141 @return<b>array</b> Array of fileItems142 143 public function getLegacyPostMedia($post_id,$media_id=null)144 145 139 @param post_id <b>integer</b> Post ID 140 @param media_id <b>integer</b> Optionnal media ID 141 @return <b>array</b> Array of fileItems 142 */ 143 public function getLegacyPostMedia($post_id, $media_id = null) 144 { 145 $post_id = (integer) $post_id; 146 146 147 148 'SELECT media_file, M.media_id, media_path, media_title, media_meta, media_dt, '.149 'media_creadt, media_upddt, media_private, user_id '.150 'FROM '.$this->table.' M '.151 'INNER JOIN '.$this->table_ref.' PM ON (M.media_id = PM.media_id) '.152 "WHERE media_path = '".$this->path."' ".153 'AND post_id = '.$post_id.' ';147 $strReq = 148 'SELECT media_file, M.media_id, media_path, media_title, media_meta, media_dt, ' . 149 'media_creadt, media_upddt, media_private, user_id ' . 150 'FROM ' . $this->table . ' M ' . 151 'INNER JOIN ' . $this->table_ref . ' PM ON (M.media_id = PM.media_id) ' . 152 "WHERE media_path = '" . $this->path . "' " . 153 'AND post_id = ' . $post_id . ' '; 154 154 155 156 $strReq .= 'AND M.media_id = '.(integer) $media_id.' ';157 155 if ($media_id) { 156 $strReq .= 'AND M.media_id = ' . (integer) $media_id . ' '; 157 } 158 158 159 159 $rs = $this->con->select($strReq); 160 160 161 161 $res = array(); 162 162 163 164 165 166 167 168 163 while ($rs->fetch()) { 164 $f = $this->fileRecord($rs); 165 if ($f !== null) { 166 $res[] = $f; 167 } 168 } 169 169 170 171 170 return $res; 171 } 172 172 173 173 }
Note: See TracChangeset
for help on using the changeset viewer.