Dotclear


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

Code formatting (PSR-2)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inc/core/class.dc.postmedia.php

    r3481 r3730  
    1010# 
    1111# -- END LICENSE BLOCK ----------------------------------------- 
    12 if (!defined('DC_RC_PATH')) { return; } 
     12if (!defined('DC_RC_PATH')) {return;} 
    1313 
    1414class dcPostMedia 
    1515{ 
    16      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 
     16    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 
    1919 
    20      /** 
    21      Object constructor. 
     20    /** 
     21    Object constructor. 
    2222 
    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      } 
     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    } 
    3232 
    33      /** 
    34      Returns media items attached to a blog post. Result is an array containing 
    35      fileItems objects. 
     33    /** 
     34    Returns media items attached to a blog post. Result is an array containing 
     35    fileItems objects. 
    3636 
    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 '; 
     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 '; 
    4646 
    47           if (!empty($params['columns']) && is_array($params['columns'])) { 
    48                $strReq .= implode(', ',$params['columns']).', '; 
    49           } 
     47        if (!empty($params['columns']) && is_array($params['columns'])) { 
     48            $strReq .= implode(', ', $params['columns']) . ', '; 
     49        } 
    5050 
    51           $strReq .= 
    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) '; 
    5454 
    55           if (!empty($params['from'])) { 
    56                $strReq .= $params['from'].' '; 
    57           } 
     55        if (!empty($params['from'])) { 
     56            $strReq .= $params['from'] . ' '; 
     57        } 
    5858 
    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           } 
     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        } 
    7474 
    75           $strReq .= 'WHERE '.join('AND ',$where).' '; 
     75        $strReq .= 'WHERE ' . join('AND ', $where) . ' '; 
    7676 
    77           if (isset($params['sql'])) { 
    78                $strReq .= $params['sql']; 
    79           } 
     77        if (isset($params['sql'])) { 
     78            $strReq .= $params['sql']; 
     79        } 
    8080 
    81           $rs = $this->con->select($strReq); 
     81        $rs = $this->con->select($strReq); 
    8282 
    83           return $rs; 
    84      } 
     83        return $rs; 
     84    } 
    8585 
    86      /** 
    87      Attaches a media to a post. 
     86    /** 
     87    Attaches a media to a post. 
    8888 
    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; 
     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; 
    9797 
    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)); 
    9999 
    100           if (!$f->isEmpty()) { 
    101                return; 
    102           } 
     100        if (!$f->isEmpty()) { 
     101            return; 
     102        } 
    103103 
    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; 
     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; 
    108108 
    109           $cur->insert(); 
    110           $this->core->blog->triggerBlog(); 
    111      } 
     109        $cur->insert(); 
     110        $this->core->blog->triggerBlog(); 
     111    } 
    112112 
    113      /** 
    114      Detaches a media from a post. 
     113    /** 
     114    Detaches a media from a post. 
    115115 
    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; 
     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; 
    124124 
    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      } 
     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    } 
    134134 
    135      /** 
    136      Returns media items attached to a blog post. Result is an array containing 
    137      fileItems objects. 
     135    /** 
     136    Returns media items attached to a blog post. Result is an array containing 
     137    fileItems objects. 
    138138 
    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; 
     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; 
    146146 
    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.' '; 
     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 . ' '; 
    154154 
    155           if ($media_id) { 
    156                $strReq .= 'AND M.media_id = '.(integer) $media_id.' '; 
    157           } 
     155        if ($media_id) { 
     156            $strReq .= 'AND M.media_id = ' . (integer) $media_id . ' '; 
     157        } 
    158158 
    159           $rs = $this->con->select($strReq); 
     159        $rs = $this->con->select($strReq); 
    160160 
    161           $res = array(); 
     161        $res = array(); 
    162162 
    163           while ($rs->fetch()) { 
    164                $f = $this->fileRecord($rs); 
    165                if ($f !== null) { 
    166                     $res[] = $f; 
    167                } 
    168           } 
     163        while ($rs->fetch()) { 
     164            $f = $this->fileRecord($rs); 
     165            if ($f !== null) { 
     166                $res[] = $f; 
     167            } 
     168        } 
    169169 
    170           return $res; 
    171      } 
     170        return $res; 
     171    } 
    172172 
    173173} 
Note: See TracChangeset for help on using the changeset viewer.

Sites map