Dotclear

Changeset 3167:9b0e5988c0eb


Ignore:
Timestamp:
02/11/16 15:35:39 (9 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Cope with sort of "un-attached" media → allows new features as "featured media" plugin. Video and Audio HTML5 element are now used (if possible) rather than Flash object for attachments.

Files:
4 added
11 edited

Legend:

Unmodified
Added
Removed
  • admin/media.php

    r3165 r3167  
    3131$dir = null; 
    3232 
     33// Attachement type if any 
     34$link_type = !empty($_REQUEST['link_type']) ? $_REQUEST['link_type'] : null; 
     35 
    3336$page = !empty($_GET['page']) ? max(1,(integer) $_GET['page']) : 1; 
    3437$nb_per_page = ((integer) $core->auth->user_prefs->interface->media_by_page ? (integer) $core->auth->user_prefs->interface->media_by_page : 30); 
     
    8588$select = !empty($_REQUEST['select']) ? (integer)$_REQUEST['select'] : 0;  // 0 : none, 1 : single media, >1 : multiple medias 
    8689 
    87 $page_url_params = new ArrayObject(array('popup' => $popup,'select' => $select,'post_id' => $post_id)); 
     90$page_url_params = new ArrayObject(array('popup' => $popup,'select' => $select,'post_id' => $post_id,'link_type' => $link_type)); 
    8891if ($d) { 
    8992     $page_url_params['d'] = $d; 
     
    774777function mediaItemLine($f,$i,$query,$table=false) 
    775778{ 
    776      global $core, $page_url, $popup, $select, $post_id, $plugin_id, $page_url_params; 
     779     global $core, $page_url, $popup, $select, $post_id, $plugin_id, $page_url_params, $link_type; 
    777780 
    778781     $fname = $f->basename; 
     
    830833                    $act .= 
    831834                    '<a class="attach-media" title="'.__('Attach this file to entry').'" href="'. 
    832                     $core->adminurl->get("admin.post.media", array('media_id' => $f->media_id, 'post_id' => $post_id,'attach' => 1)). 
     835                    $core->adminurl->get("admin.post.media", 
     836                         array('media_id' => $f->media_id, 'post_id' => $post_id,'attach' => 1,'link_type' => $link_type)). 
    833837                    '">'. 
    834838                    '<img src="images/plus.png" alt="'.__('Attach this file to entry').'"/>'. 
  • admin/media_item.php

    r3154 r3167  
    2727} 
    2828 
     29// Attachement type if any 
     30$link_type = !empty($_REQUEST['link_type']) ? $_REQUEST['link_type'] : null; 
     31 
    2932$file = null; 
    3033$popup = (integer) !empty($_REQUEST['popup']); 
     
    3235$plugin_id = isset($_REQUEST['plugin_id']) ? html::sanitizeURL($_REQUEST['plugin_id']) : ''; 
    3336$page_url_params = array('popup' => $popup,'select' => $select,'post_id' => $post_id); 
    34 $media_page_url_params = array('popup' => $popup,'select' => $select,'post_id' => $post_id); 
     37$media_page_url_params = array('popup' => $popup,'select' => $select,'post_id' => $post_id,'link_type' => $link_type); 
    3538 
    3639if ($plugin_id != '') { 
  • admin/post_media.php

    r2720 r3167  
    1717$post_id = !empty($_REQUEST['post_id']) ? (integer) $_REQUEST['post_id'] : null; 
    1818$media_id = !empty($_REQUEST['media_id']) ? (integer) $_REQUEST['media_id'] : null; 
     19$link_type = !empty($_REQUEST['link_type']) ? $_REQUEST['link_type'] : null; 
    1920 
    2021if (!$post_id) { 
     
    3031     { 
    3132          $core->media = new dcMedia($core); 
    32           $core->media->addPostMedia($post_id,$media_id); 
     33          $core->media->addPostMedia($post_id,$media_id,$link_type); 
    3334        if (!empty($_SERVER['HTTP_X_REQUESTED_WITH'])) { 
    3435            header('Content-type: application/json'); 
     
    4142 
    4243     $core->media = new dcMedia($core); 
    43      $f = $core->media->getPostMedia($post_id,$media_id); 
     44     $f = $core->media->getPostMedia($post_id,$media_id,$link_type); 
    4445     if (empty($f)) { 
    4546          $post_id = $media_id = null; 
     
    5657     if (!empty($_POST['remove'])) 
    5758     { 
    58           $core->media->removePostMedia($post_id,$media_id); 
     59          $core->media->removePostMedia($post_id,$media_id,$link_type); 
    5960 
    6061          dcPage::addSuccessNotice(__('Attachment has been successfully removed.')); 
  • inc/core/class.dc.media.php

    r3138 r3167  
    573573     fileItems objects. 
    574574 
    575      @param    post_id   <b>integer</b>      Post ID 
     575     @param    post_id        <b>integer</b>      Post ID 
    576576     @param    media_id  <b>integer</b>      Optionnal media ID 
     577     @param    link_type <b>string</b>       Optionnal link type 
    577578     @return   <b>array</b> Array of fileItems 
    578579     */ 
    579      public function getPostMedia($post_id,$media_id=null) 
     580     public function getPostMedia($post_id,$media_id=null,$link_type=null) 
    580581     { 
    581582          $params = array( 
     
    586587               $params['media_id'] = (integer) $media_id; 
    587588          } 
     589          if ($link_type) { 
     590               $params['link_type'] = $link_type; 
     591          } 
    588592          $rs = $this->postmedia->getPostMedia($params); 
    589593 
     
    604608     @see dcPostMedia::addPostMedia 
    605609     */ 
    606      public function addPostMedia($post_id,$media_id) 
    607      { 
    608           $this->postmedia->addPostMedia($post_id,$media_id); 
     610     public function addPostMedia($post_id,$media_id,$link_type='attachment') 
     611     { 
     612          $this->postmedia->addPostMedia($post_id,$media_id,$link_type); 
    609613     } 
    610614 
     
    613617     @see dcPostMedia::removePostMedia 
    614618     */ 
    615      public function removePostMedia($post_id,$media_id) 
    616      { 
    617           $this->postmedia->removePostMedia($post_id,$media_id,"attachment"); 
     619     public function removePostMedia($post_id,$media_id,$link_type='attachment') 
     620     { 
     621          $this->postmedia->removePostMedia($post_id,$media_id,$link_type); 
    618622     } 
    619623 
  • inc/core/class.dc.postmedia.php

    r2566 r3167  
    7878               $strReq .= $params['sql']; 
    7979          } 
    80      //echo $strReq; exit; 
     80 
    8181          $rs = $this->con->select($strReq); 
    8282 
     
    8787     Attaches a media to a post. 
    8888 
    89      @param    post_id   <b>integer</b>      Post ID 
     89     @param    post_id        <b>integer</b>      Post ID 
    9090     @param    media_id  <b>integer</b>      Optionnal media ID 
     91     @param    link_type <b>string</b>       Optionnal link type (default: attachment) 
    9192     */ 
    9293     public function addPostMedia($post_id,$media_id,$link_type='attachment') 
     
    113114     Detaches a media from a post. 
    114115 
    115      @param    post_id   <b>integer</b>      Post ID 
     116     @param    post_id        <b>integer</b>      Post ID 
    116117     @param    media_id  <b>integer</b>      Optionnal media ID 
     118     @param    link_type <b>string</b>       Optionnal link type 
    117119     */ 
    118120     public function removePostMedia($post_id,$media_id,$link_type=null) 
  • inc/core/class.dc.rs.extensions.php

    r3106 r3167  
    447447     @return   <b>integer</b> 
    448448     */ 
    449      public static function countMedia($rs) 
     449     public static function countMedia($rs,$link_type=null) 
    450450     { 
    451451          if (isset($rs->_nb_media[$rs->index()])) 
     
    459459               'FROM '.$rs->core->prefix.'post_media '. 
    460460               'WHERE post_id = '.(integer) $rs->post_id.' '; 
     461               if ($link_type != null) { 
     462                    $strReq .= "AND link_type = '".$rs->core->con->escape($link_type)."'"; 
     463               } 
    461464 
    462465               $res = (integer) $rs->core->con->select($strReq)->f(0); 
  • inc/public/default-templates/currywurst/_entry-content.html

    r2938 r3167  
    4646     </tpl:AttachmentsHeader> 
    4747                    <li class="post-attachments-item {{tpl:AttachmentType}}"> 
    48                          <tpl:AttachmentIf is_mp3="1"> 
    49                               {{tpl:include src="_mp3_player.html"}} - 
     48                         <tpl:AttachmentIf is_audio="1"> 
     49                              {{tpl:include src="_audio_player.html"}} 
    5050                         </tpl:AttachmentIf> 
    51                          <tpl:AttachmentIf is_flv="1"> 
    52                               {{tpl:include src="_flv_player.html"}} 
     51                         <tpl:AttachmentIf is_video="1"> 
     52                              <tpl:AttachmentIf is_flv="0"> 
     53                                   {{tpl:include src="_video_player.html"}} 
     54                              {{tpl:else}} 
     55                                   {{tpl:include src="_flv_player.html"}} 
     56                              </tpl:AttachmentIf> 
    5357                         </tpl:AttachmentIf> 
    54                          <tpl:AttachmentIf is_flv="0"> 
     58                         <tpl:AttachmentIf is_video="0" is_audio="0"> 
    5559                              <a href="{{tpl:AttachmentURL}}" 
    5660                               title="{{tpl:AttachmentFileName}} ({{tpl:AttachmentSize}})">{{tpl:AttachmentTitle}}</a> 
  • inc/public/default-templates/mustek/post.html

    r3017 r3167  
    100100          </tpl:AttachmentsHeader> 
    101101               <li class="{{tpl:AttachmentType}}"> 
    102                     <tpl:AttachmentIf is_mp3="1"> 
    103                          {{tpl:include src="_mp3_player.html"}} - 
     102                    <tpl:AttachmentIf is_audio="1"> 
     103                         {{tpl:include src="_audio_player.html"}} 
    104104                    </tpl:AttachmentIf> 
    105                     <tpl:AttachmentIf is_flv="1"> 
    106                 {{tpl:include src="_flv_player.html"}} 
    107            </tpl:AttachmentIf> 
    108            <tpl:AttachmentIf is_flv="0"> 
     105                    <tpl:AttachmentIf is_video="1"> 
     106                         <tpl:AttachmentIf is_flv="0"> 
     107                              {{tpl:include src="_video_player.html"}} 
     108                         {{tpl:else}} 
     109                              {{tpl:include src="_flv_player.html"}} 
     110                         </tpl:AttachmentIf> 
     111                    </tpl:AttachmentIf> 
     112           <tpl:AttachmentIf is_audio="0" is_video="0"> 
    109113               <a href="{{tpl:AttachmentURL}}" 
    110114          title="{{tpl:AttachmentFileName}} ({{tpl:AttachmentSize}})">{{tpl:AttachmentTitle}}</a> 
  • plugins/attachments/_admin.php

    r3021 r3167  
    4646          { 
    4747               $core =& $GLOBALS['core']; 
    48                $post_media = $core->media->getPostMedia($post->post_id); 
     48               $post_media = $core->media->getPostMedia($post->post_id,null,'attachment'); 
    4949               $nb_media = count($post_media); 
    5050               $title = !$nb_media ? __('Attachments') : sprintf(__('Attachments (%d)'),$nb_media); 
     
    7171                         'post_id' => $post->post_id, 
    7272                         'media_id' => $f->media_id, 
     73                         'link_type' => 'attachment', 
    7374                         'remove' => '1' 
    7475                         )).'">'. 
     
    8586               } 
    8687               $item .= 
    87                     '<p class="s-attachments"><a class="button" href="'.$core->adminurl->get('admin.media',array('post_id' => $post->post_id)).'">'. 
     88                    '<p class="s-attachments"><a class="button" href="'.$core->adminurl->get('admin.media',array('post_id' => $post->post_id, 'link_type' => 'attachment')).'">'. 
    8889                    __('Add files to this entry').'</a></p>'; 
    8990               $sidebar['metas-box']['items']['attachments']= $item; 
     
    99100                    '<div>'.form::hidden(array('post_id'),$post->post_id). 
    100101                    form::hidden(array('media_id'),''). 
     102                    form::hidden(array('link_type'),'attachment'). 
    101103                    form::hidden(array('remove'),1). 
    102104                    $core->formNonce().'</div></form>'; 
  • plugins/attachments/_public.php

    r2832 r3167  
    4040          "<?php\n". 
    4141          'if ($_ctx->posts !== null && $core->media) {'."\n". 
    42                '$_ctx->attachments = new ArrayObject($core->media->getPostMedia($_ctx->posts->post_id));'."\n". 
     42               '$_ctx->attachments = new ArrayObject($core->media->getPostMedia($_ctx->posts->post_id,null,"attachment"));'."\n". 
    4343          "?>\n". 
    4444 
     
    8383     is_mp3    (0|1)     #IMPLIED  -- test if attachment is a mp3 file (value : 1) or not (value : 0) 
    8484     is_flv    (0|1)     #IMPLIED  -- test if attachment is a flv file (value : 1) or not (value : 0) 
     85     is_audio  (0|1)     #IMPLIED  -- test if attachment is an audio file (value : 1) or not (value : 0) 
     86     is_video  (0|1)     #IMPLIED  -- test if attachment is a video file (value : 1) or not (value : 0) 
    8587     > 
    8688     */ 
     
    107109 
    108110          if (isset($attr['is_flv'])) { 
    109                $sign = (boolean) $attr['is_flv'] ? '' : '!'; 
    110                $if[] = $sign. 
    111                     '($attach_f->type == "video/x-flv" || '. 
    112                     '$attach_f->type == "video/mp4" || '. 
    113                     '$attach_f->type == "video/x-m4v")'; 
     111               $sign = (boolean) $attr['is_flv'] ? '==' : '!='; 
     112               $if[] = '$attach_f->type '.$sign.' "video/x-flv"'; 
     113          } 
     114 
     115          if (isset($attr['is_audio'])) { 
     116               $sign = (boolean) $attr['is_audio'] ? '==' : '!='; 
     117               $if[] = '$attach_f->type_prefix '.$sign.' "audio"'; 
     118          } 
     119 
     120          if (isset($attr['is_video'])) { 
     121               $sign = (boolean) $attr['is_video'] ? '==' : '!='; 
     122               $if[] = '$attach_f->type_prefix '.$sign.' "video"'; 
    114123          } 
    115124 
     
    213222          global $core; 
    214223          return $core->tpl->displayCounter( 
    215                '$_ctx->posts->countMedia()', 
     224               '$_ctx->posts->countMedia(\'attachment\')', 
    216225               array( 
    217226                    'none' => 'no attachments', 
     
    231240          if ($tag == "EntryIf" && isset($attr['has_attachment'])) { 
    232241               $sign = (boolean) $attr['has_attachment'] ? '' : '!'; 
    233                $if[] = $sign.'$_ctx->posts->countMedia()'; 
     242               $if[] = $sign.'$_ctx->posts->countMedia(\'attachment\')'; 
    234243          } 
    235244     } 
  • plugins/pages/default-templates/mustek/page.html

    r3017 r3167  
    3737          </tpl:AttachmentsHeader> 
    3838                         <li class="{{tpl:AttachmentType}}"> 
    39           <tpl:AttachmentIf is_mp3="1"> 
    40                          {{tpl:include src="_mp3_player.html"}} - 
    41           </tpl:AttachmentIf> 
    42           <tpl:AttachmentIf is_flv="1"> 
    43                          {{tpl:include src="_flv_player.html"}} 
    44           </tpl:AttachmentIf> 
    45           <tpl:AttachmentIf is_flv="0"> 
     39                    <tpl:AttachmentIf is_audio="1"> 
     40                         {{tpl:include src="_audio_player.html"}} 
     41                    </tpl:AttachmentIf> 
     42                    <tpl:AttachmentIf is_video="1"> 
     43                         <tpl:AttachmentIf is_flv="0"> 
     44                              {{tpl:include src="_video_player.html"}} 
     45                         {{tpl:else}} 
     46                              {{tpl:include src="_flv_player.html"}} 
     47                         </tpl:AttachmentIf> 
     48                    </tpl:AttachmentIf> 
     49                    <tpl:AttachmentIf is_audio="0" is_video="0"> 
    4650                         <a href="{{tpl:AttachmentURL}}" 
    47                          title="{{tpl:AttachmentFileName}} ({{tpl:AttachmentSize}})">{{tpl:AttachmentTitle}}</a> 
    48           </tpl:AttachmentIf> 
     51                              title="{{tpl:AttachmentFileName}} ({{tpl:AttachmentSize}})">{{tpl:AttachmentTitle}}</a> 
     52                    </tpl:AttachmentIf> 
    4953                         </li> 
    5054          <tpl:AttachmentsFooter> 
Note: See TracChangeset for help on using the changeset viewer.

Sites map