Changeset 1590 for trunk/picture.php


Ignore:
Timestamp:
Nov 1, 2006, 6:54:35 AM (17 years ago)
Author:
rvelices
Message:

plugins last modifications + events are triggered now from picture.php

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/picture.php

    r1503 r1590  
    4747}
    4848
     49// add default event handler for rendering element content
     50add_event_handler('render_element_content', 'default_picture_content',
     51  EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
     52trigger_action('loc_begin_picture');
     53
     54// this is the default handler that generates the display for the element
     55function default_picture_content($content, $element_info)
     56{
     57  if ( !empty($content) )
     58  {// someone hooked us - so we skip;
     59    return $content;
     60  }
     61  if (!isset($element_info['image_url']))
     62  { // nothing to do
     63    return $content;
     64  }
     65  global $user;
     66  $my_template = new Template(PHPWG_ROOT_PATH.'template/'.$user['template'],
     67    $user['theme'] );
     68  $my_template->set_filenames( array('default_content'=>'picture_content.tpl') );
     69
     70  if (isset($element_info['high_url']))
     71  {
     72    $uuid = uniqid(rand());
     73    $my_template->assign_block_vars(
     74      'high',
     75      array(
     76        'U_HIGH' => $element_info['high_url'],
     77        'UUID'   => $uuid,
     78        )
     79      );
     80  }
     81  $my_template->assign_vars( array(
     82      'SRC_IMG' => $element_info['image_url'],
     83      'ALT_IMG' => $element_info['file'],
     84      'WIDTH_IMG' => $element_info['scaled_width'],
     85      'HEIGHT_IMG' => $element_info['scaled_height'],
     86      )
     87    );
     88  return $my_template->parse( 'default_content', true);
     89}
     90
     91
     92
    4993// +-----------------------------------------------------------------------+
    5094// |                            initialization                             |
     
    100144 */
    101145
    102 if (isset($_GET['action']) and !is_adviser())
     146if (isset($_GET['action']))
    103147{
    104148  switch ($_GET['action'])
     
    140184    case 'set_as_representative' :
    141185    {
    142       if (is_admin() and isset($page['category']))
     186      if (is_admin() and !is_adviser() and isset($page['category']))
    143187      {
    144188        $query = '
     
    175219      if (isset($_GET['comment_to_delete'])
    176220          and is_numeric($_GET['comment_to_delete'])
    177           and is_admin())
     221          and is_admin() and !is_adviser() )
    178222      {
    179223        $query = '
     
    276320  $file_wo_ext = get_filename_wo_extension($row['file']);
    277321
    278   if (isset($row['representative_ext']) and $row['representative_ext'] != '')
    279   {
    280     $picture[$i]['src'] =
    281       $cat_directory.'/pwg_representative/'
    282       .$file_wo_ext.'.'.$row['representative_ext'];
    283   }
    284   else
    285   {
    286     $icon = get_themeconf('mime_icon_dir');
    287     $icon.= strtolower(get_extension($row['file'])).'.png';
    288     $picture[$i]['src'] = $icon;
    289   }
    290   // special case for picture files
     322  // ------ build element_path and element_url
     323  $picture[$i]['element_url'] = $row['path'];
     324  if ( ! url_is_remote($row['path']) )
     325  {
     326    $picture[$i]['element_url'] = get_root_url().$row['path'];
     327  }
     328
     329  // ------ build image_path and image_url
    291330  if ($picture[$i]['is_picture'])
    292331  {
    293     $picture[$i]['src'] = $row['path'];
     332    $picture[$i]['image_path'] = $row['path'];
    294333    // if we are working on the "current" element, we search if there is a
    295334    // high quality picture
     
    299338      {
    300339        $url_high=$cat_directory.'/pwg_high/'.$row['file'];
    301         $picture[$i]['high_file_system'] = $picture[$i]['high'] = $url_high;
    302         if ( ! url_is_remote($picture[$i]['high']) )
     340         $picture[$i]['high_url'] = $picture[$i]['high_path'] = $url_high;
     341        if ( ! url_is_remote($picture[$i]['high_path']) )
    303342        {
    304           $picture[$i]['high'] = get_root_url().$picture[$i]['high'];
     343          $picture[$i]['high_url'] = get_root_url().$picture[$i]['high_path'];
    305344        }
    306345      }
    307346    }
    308347  }
    309   $picture[$i]['src_file_system'] = $picture[$i]['src'];
    310   if ( ! url_is_remote($picture[$i]['src']) )
    311   {
    312     $picture[$i]['src'] = get_root_url(). $picture[$i]['src'];
    313   }
    314 
    315   // if picture is not a file, we need the download link
     348  else
     349  {// not a picture
     350    if (isset($row['representative_ext']) and $row['representative_ext']!='')
     351    {
     352      $picture[$i]['image_path'] =
     353        $cat_directory.'/pwg_representative/'
     354        .$file_wo_ext.'.'.$row['representative_ext'];
     355    }
     356    else
     357    {
     358      $picture[$i]['image_path'] =
     359        get_themeconf('mime_icon_dir')
     360        .strtolower(get_extension($row['file'])).'.png';
     361    }
     362  }
     363
     364  $picture[$i]['image_url'] = $picture[$i]['image_path'];
     365  if ( ! url_is_remote($picture[$i]['image_path']) )
     366  {
     367    $picture[$i]['image_url'] = get_root_url().$picture[$i]['image_path'];
     368  }
     369
    316370  if (!$picture[$i]['is_picture'])
    317   {
    318     $picture[$i]['download'] = url_is_remote($row['path']) ? '' : get_root_url();
    319     $picture[$i]['download'].= $row['path'];
     371  {// if picture is not a file, we need the download link
     372    $picture[$i]['download_url'] = $picture[$i]['element_url'];
     373  }
     374  else
     375  {// if picture is a file with high, we put the download link
     376    if ( isset($picture[$i]['high_path']) )
     377    {
     378      $picture[$i]['download_url'] = get_root_url().'action.php?dwn='
     379        .$picture[$i]['high_path'];
     380    }
    320381  }
    321382
     
    351412}
    352413
     414// calculation of width and height for the current picture
     415if (empty($picture['current']['width']))
     416{
     417  $taille_image = @getimagesize($picture['current']['image_path']);
     418  if ($taille_image!==false)
     419  {
     420    $picture['current']['width'] = $taille_image[0];
     421    $picture['current']['height']= $taille_image[1];
     422  }
     423}
     424
     425if (!empty($picture['current']['width']))
     426{
     427  list($picture['current']['scaled_width'],$picture['current']['scaled_height']) =
     428    get_picture_size(
     429      $picture['current']['width'],
     430      $picture['current']['height'],
     431      @$user['maxwidth'],
     432      @$user['maxheight']
     433    );
     434}
     435
     436// now give an opportunity to the filters to alter element_url,
     437// image_url, high_url and download_url
     438$picture = trigger_event('picture_navigation', $picture);
     439
    353440$url_admin =
    354441  get_root_url().'admin.php?page=picture_modify'
     
    378465$title_nb = ($page['current_rank'] + 1).'/'.$page['cat_nb_images'];
    379466
    380 // calculation of width and height
    381 if (empty($picture['current']['width']))
    382 {
    383   $taille_image = @getimagesize($picture['current']['src_file_system']);
    384   $original_width = $taille_image[0];
    385   $original_height = $taille_image[1];
    386 }
    387 else
    388 {
    389   $original_width = $picture['current']['width'];
    390   $original_height = $picture['current']['height'];
    391 }
    392 
    393 $picture_size = get_picture_size(
    394   $original_width,
    395   $original_height,
    396   @$user['maxwidth'],
    397   @$user['maxheight']
    398   );
    399 
    400467// metadata
    401468$url_metadata = duplicate_picture_url();
    402 if ($conf['show_exif'] or $conf['show_iptc'])
    403 {
    404   $metadata_showable = true;
     469
     470// do we have a plugin that can show metadata for something else than images?
     471$metadata_showable = trigger_event('get_element_metadata_available',
     472    (
     473      ($conf['show_exif'] or $conf['show_iptc'])
     474      and isset($picture['current']['image_path'])
     475    ),
     476    $picture['current']['path'] );
     477if ($metadata_showable)
     478{
    405479  if ( !isset($_GET['metadata']) )
    406480  {
     
    408482  }
    409483}
    410 else
    411 {
    412   $metadata_showable = false;
    413 }
    414484
    415485$page['body_id'] = 'thePicturePage';
     486
     487// maybe someone wants a special display (call it before page_header so that they
     488// can add stylesheets)
     489$element_content = trigger_event('render_element_content',
     490                      '', $picture['current'] );
     491
     492if ( isset($picture['next']['image_url'])
     493      and isset($picture['next']['is_picture']) )
     494{
     495  $template->assign_block_vars( 'prefetch',
     496    array (
     497      'URL' => $picture['next']['image_url']
     498    )
     499  );
     500}
     501include(PHPWG_ROOT_PATH.'include/page_header.php');
     502$template->set_filenames(array('picture'=>'picture.tpl'));
     503
    416504//------------------------------------------------------- navigation management
    417505foreach ( array('first','previous','next','last') as $which_image )
     
    425513        'IMG' => $picture[$which_image]['thumbnail'],
    426514        'U_IMG' => $picture[$which_image]['url'],
    427         'U_IMG_SRC' => $picture[$which_image]['src']
    428515        )
    429516      );
    430517  }
    431518}
    432 
    433 include(PHPWG_ROOT_PATH.'include/page_header.php');
    434 $template->set_filenames(array('picture'=>'picture.tpl'));
    435519
    436520$template->assign_vars(
     
    440524    'PHOTO' => $title_nb,
    441525    'TITLE' => $picture['current']['name'],
    442     'SRC_IMG' => $picture['current']['src'],
    443     'ALT_IMG' => $picture['current']['file'],
    444     'WIDTH_IMG' => $picture_size[0],
    445     'HEIGHT_IMG' => $picture_size[1],
     526    'ELEMENT_CONTENT' => $element_content,
    446527
    447528    'LEVEL_SEPARATOR' => $conf['level_separator'],
    448 
    449     'L_HOME' => $lang['home'],
    450     'L_SLIDESHOW' => $lang['slideshow'],
    451     'L_STOP_SLIDESHOW' => $lang['slideshow_stop'],
    452     'L_PREV_IMG' =>$lang['previous_page'].' : ',
    453     'L_NEXT_IMG' =>$lang['next_page'].' : ',
    454     'L_ADMIN' =>$lang['link_info_image'],
    455     'L_COMMENT_TITLE' =>$lang['comments_title'],
    456     'L_ADD_COMMENT' =>$lang['comments_add'],
    457     'L_DELETE_COMMENT' =>$lang['comments_del'],
    458     'L_DELETE' =>$lang['delete'],
    459     'L_SUBMIT' =>$lang['submit'],
    460     'L_AUTHOR' =>  $lang['upload_author'],
    461     'L_COMMENT' =>$lang['comment'],
    462     'L_DOWNLOAD' => $lang['download'],
    463     'L_DOWNLOAD_HINT' => $lang['download_hint'],
    464     'L_PICTURE_METADATA' => $lang['picture_show_metadata'],
    465     'L_PICTURE_HIGH' => $lang['picture_high'],
    466     'L_UP_HINT' => $lang['home_hint'],
    467     'L_UP_ALT' => $lang['home'],
    468529
    469530    'U_HOME' => make_index_url(),
     
    483544//------------------------------------------------------- upper menu management
    484545
    485 // download link if file is not a picture
    486 if (!$picture['current']['is_picture'])
     546// download link
     547if ( isset($picture['current']['download_url']) )
    487548{
    488549  $template->assign_block_vars(
    489550    'download',
    490551    array(
    491       'U_DOWNLOAD' => $picture['current']['download']
    492       )
    493     );
    494 }
    495 
    496 // display a high quality link if present
    497 if (isset($picture['current']['high']))
    498 {
    499   $uuid = uniqid(rand());
    500 
    501   $template->assign_block_vars(
    502     'high',
    503     array(
    504       'U_HIGH' => $picture['current']['high'],
    505       'UUID'   => $uuid,
    506       )
    507     );
    508 
    509   $template->assign_block_vars(
    510     'download',
    511     array(
    512       'U_DOWNLOAD' => get_root_url().'action.php?dwn='
    513       .$picture['current']['high_file_system']
     552      'U_DOWNLOAD' => $picture['current']['download_url']
    514553      )
    515554    );
     
    656695
    657696// size in pixels
    658 if ($picture['current']['is_picture'])
    659 {
    660   if ($original_width != $picture_size[0]
    661       or $original_height != $picture_size[1])
     697if ($picture['current']['is_picture'] and isset($picture['current']['width']) )
     698{
     699  if ($picture['current']['scaled_width'] !== $picture['current']['width'] )
    662700  {
    663701    $infos['INFO_DIMENSIONS'] =
    664       '<a href="'.$picture['current']['src'].'" title="'.
     702      '<a href="'.$picture['current']['image_url'].'" title="'.
    665703      l10n('Original dimensions').'">'.
    666       $original_width.'*'.$original_height.'</a>';
     704      $picture['current']['width'].'*'.$picture['current']['height'].'</a>';
    667705  }
    668706  else
    669707  {
    670     $infos['INFO_DIMENSIONS'] = $original_width.'*'.$original_height;
     708    $infos['INFO_DIMENSIONS'] =
     709      $picture['current']['width'].'*'.$picture['current']['height'];
    671710  }
    672711}
Note: See TracChangeset for help on using the changeset viewer.