Changeset 20516


Ignore:
Timestamp:
Feb 2, 2013, 8:09:52 AM (11 years ago)
Author:
rvelices
Message:

feature 2831: simple way to protect urls of originals

Location:
trunk/include
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/common.inc.php

    r19703 r20516  
    267267add_event_handler('render_tag_url', 'str2url');
    268268add_event_handler('blockmanager_register_blocks', 'register_default_menubar_blocks', EVENT_HANDLER_PRIORITY_NEUTRAL-1);
     269if ( !empty($conf['original_url_protection']) )
     270{
     271  add_event_handler('get_element_url', 'get_element_url_protection_handler', EVENT_HANDLER_PRIORITY_NEUTRAL, 2 );
     272  add_event_handler('get_src_image_url', 'get_src_image_url_protection_handler', EVENT_HANDLER_PRIORITY_NEUTRAL, 2 );
     273}
    269274trigger_action('init');
    270275?>
  • trunk/include/config_default.inc.php

    r20449 r20516  
    778778//Maximum Ajax requests at once, for thumbnails on-the-fly generation
    779779$conf['max_requests']=3;
     780
     781// one of '', 'images', 'all'
     782//TODO: Put this in admin and also manage .htaccess in #sites and upload folders
     783$conf['original_url_protection'] = '';
    780784?>
  • trunk/include/derivative.inc.php

    r19878 r20516  
    2020// +-----------------------------------------------------------------------+
    2121
    22 /*A source image is used to get a derivative image. A source image is either the original file for a jpg or a 
     22/*A source image is used to get a derivative image. A source image is either the original file for a jpg or a
    2323'representative' image of a non image file or a standard icon for the non-image file.*/
    2424final class SrcImage
     
    7979          $height = $infos['width'];
    8080        }
    81        
     81
    8282        $this->size = array($width, $height);
    8383      }
     
    107107  {
    108108    $url = get_root_url().$this->rel_path;
    109     if ($this->flags & self::IS_ORIGINAL)
     109    if ( !($this->flags & self::IS_MIMETYPE) )
    110110    {
    111111      $url = trigger_event('get_src_image_url', $url, $this);
     
    171171  }
    172172
    173   /** 
     173  /**
    174174  @return derivative image url
    175175  @param type string of standard derivative param type (e.g. IMG_???) or a DerivativeParams object
  • trunk/include/functions_html.inc.php

    r19703 r20516  
    594594}
    595595
     596/** optional event handler to protect src image urls */
     597function get_src_image_url_protection_handler($url, $src_image)
     598{
     599  return get_action_url($src_image->id, $src_image->is_original() ? 'e' : 'r', false);
     600}
     601
     602/** optional event handler to protect element urls */
     603function get_element_url_protection_handler($url, $infos)
     604{
     605  global $conf;
     606  if ('images'==$conf['original_url_protection'])
     607  {// protect only images and not other file types (for example large movies that we don't want to send through our file proxy)
     608    $ext = get_extension($infos['path']);
     609    if (!in_array($ext, $conf['picture_ext']))
     610    {
     611      return $url;
     612    }
     613  }
     614  return get_action_url($infos['id'], 'e', false);
     615}
     616
    596617?>
Note: See TracChangeset for help on using the changeset viewer.