Source for file GBFilePicker.module.php

Documentation is available at GBFilePicker.module.php

  1. <?php
  2. #-------------------------------------------------------------------------------
  3. #
  4. # Module : GBFilePicker (c) 2010-2012 by Georg Busch (georg.busch@gmx.net)
  5. #          a file picker tool for CMS Made Simple
  6. #          The projects homepage is: dev.cmsmadesimple.org/projects/gbfilepicker
  7. #          CMS Made Simple is (c) 2004-2012 by Ted Kulp
  8. #          The projects homepage is: cmsmadesimple.org
  9. # Version: 1.3
  10. # File   : GBFilePicker.module.php
  11. # Purpose: main module class
  12. # License: GPL
  13. #
  14. #-------------------------------------------------------------------------------
  15.  
  16. /**
  17.  * Class definition and methods for GBFilePicker
  18.  *
  19.  * @package CMSModule
  20.  * @license GPL
  21.  */
  22.  
  23. /**
  24.  * Main class of the GBFilePicker Module
  25.  *
  26.  * @author Georg Busch (NaN)
  27.  * @copyright 2010 Georg Busch (NaN)
  28.  * @version 1.3
  29.  *
  30.  * @package CMSModule
  31.  * @license GPL
  32.  */
  33. class GBFilePicker extends CMSModule
  34. {
  35.     /**
  36.      * @access protected
  37.      * @var boolean 
  38.      * @ignore
  39.      */
  40.     protected $_isAdmin;
  41.     
  42.     /**
  43.      * @access protected
  44.      * @var boolean 
  45.      * @ignore
  46.      */
  47.     protected $_loaded;
  48.     
  49.     /**
  50.      * @access protected
  51.      * @var string 
  52.      * @ignore
  53.      */
  54.     protected $_username;
  55.     
  56.     /**
  57.      * @access protected
  58.      * @var string 
  59.      * @ignore
  60.      */
  61.     protected $_pp '<div style="float:right"><form action="https://www.paypal.com/cgi-bin/webscr" method="post">
  62. <input type="hidden" name="cmd" value="_s-xclick" />
  63. <input type="hidden" name="hosted_button_id" value="FA2D3FPLSTAKJ" />
  64. <input type="image" src="https://www.paypal.com/en_GB/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online." />
  65. <img alt="" border="0" src="https://www.paypal.com/de_DE/i/scr/pixel.gif" width="1" height="1" />
  66. </form></div>';
  67.  
  68.     /**
  69.      * Constructor
  70.      * @ignore
  71.      */
  72.     function GBFilePicker()
  73.     {
  74.         parent::CMSModule();
  75.         $this->_loaded false;
  76.         global $CMS_ADMIN_PAGE$config;
  77.         if(isset($CMS_ADMIN_PAGE&& $CMS_ADMIN_PAGE == 1)
  78.         {
  79.             if(!file_exists(cms_join_path($config['previews_path''GBFilePickerThumbs')))
  80.             {
  81.                 @mkdir(cms_join_path($config['previews_path''GBFilePickerThumbs')0755);
  82.             }
  83.             $userops         =cmsms()->GetUserOperations();
  84.             $this->_isAdmin  $userops->UserInGroup(get_userid(false),1);
  85.             if($user =$userops->LoadUserById(get_userid(false)))
  86.             {
  87.                 $this->_username $user->username;
  88.             }
  89.         }
  90.     }
  91.     
  92.     /**
  93.      * @link http://www.cmsmadesimple.org/apidoc/CMS/CMSModule.html#GetName
  94.      * @ignore
  95.      */
  96.     function GetName()
  97.     {
  98.         return 'GBFilePicker';
  99.     }
  100.     
  101.     /**
  102.      * @link http://www.cmsmadesimple.org/apidoc/CMS/CMSModule.html#GetFriendlyName
  103.      * @ignore
  104.      */
  105.     function GetFriendlyName()
  106.     {
  107.         return $this->Lang('GBFilePicker');
  108.     }
  109.     
  110.     /**
  111.      * @link http://www.cmsmadesimple.org/apidoc/CMS/CMSModule.html#GetVersion
  112.      * @ignore
  113.      */
  114.     function GetVersion()
  115.     {
  116.         return '1.3';
  117.     }
  118.     
  119.     /**
  120.      * @link http://www.cmsmadesimple.org/apidoc/CMS/CMSModule.html#GetHelp
  121.      * @ignore
  122.      */
  123.     function GetHelp()
  124.     {
  125.         $path dirname(__FILE__DIRECTORY_SEPARATOR 'doc' DIRECTORY_SEPARATOR;
  126.         if(file_exists($path 'help_' $this->curlang '.html'))
  127.         {
  128.             return $this->_pp.file_get_contents($path 'help_' $this->curlang '.html');
  129.         }
  130.         return $this->_pp.$this->lang('help');
  131.     }
  132.     
  133.     /**
  134.      * @link http://www.cmsmadesimple.org/apidoc/CMS/CMSModule.html#GetAuthor
  135.      * @ignore
  136.      */
  137.     function GetAuthor()
  138.     {
  139.         return 'Georg Busch (NaN)';
  140.     }
  141.     
  142.     /**
  143.      * @link http://www.cmsmadesimple.org/apidoc/CMS/CMSModule.html#GetChangeLog
  144.      * @ignore
  145.      */
  146.     function GetChangeLog()
  147.     {
  148.         $path dirname(__FILE__DIRECTORY_SEPARATOR 'doc' DIRECTORY_SEPARATOR;
  149.         if(file_exists($path 'changelog_' $this->curlang '.html'))
  150.         {
  151.             return $this->_pp.file_get_contents($path 'changelog_' $this->curlang '.html');
  152.         }
  153.         return $this->_pp.$this->lang('changelog');
  154.     }
  155.     
  156.     /**
  157.      * @link http://www.cmsmadesimple.org/apidoc/CMS/CMSModule.html#HasAdmin
  158.      * @ignore
  159.      */
  160.     function HasAdmin()
  161.     {
  162.         return $this->CheckPermission('Manage GBFilePicker');
  163.     }
  164.     
  165.     /**
  166.      * @link http://www.cmsmadesimple.org/apidoc/CMS/CMSModule.html#GetAdminSection
  167.      * @ignore
  168.      */
  169.     function GetAdminSection()
  170.     {
  171.         return 'extensions';
  172.     }
  173.     
  174.     /**
  175.      * @link http://www.cmsmadesimple.org/apidoc/CMS/CMSModule.html#GetAdminDescription
  176.      * @ignore
  177.      */
  178.     function GetAdminDescription()
  179.     {
  180.         return $this->lang('admindescription');
  181.     }
  182.     
  183.     /**
  184.      * @link http://www.cmsmadesimple.org/apidoc/CMS/CMSModule.html#VisibleToAdminUser
  185.      * @ignore
  186.      */
  187.     function VisibleToAdminUser()
  188.     {
  189.         return $this->CheckPermission('Manage GBFilePicker');
  190.     }
  191.     
  192.     /**
  193.      * @link http://www.cmsmadesimple.org/apidoc/CMS/CMSModule.html#MinimumCMSVersion
  194.      * @ignore
  195.      */
  196.     function MinimumCMSVersion()
  197.     {
  198.         return "1.8.2";
  199.     }
  200.     
  201.     /**
  202.      * @link http://www.cmsmadesimple.org/apidoc/CMS/CMSModule.html#MaximumCMSVersion
  203.      * @ignore
  204.      */
  205.     function MaximumCMSVersion()
  206.     {
  207.         return "1.99";
  208.     }
  209.     
  210.     /**
  211.      * @link http://www.cmsmadesimple.org/apidoc/CMS/CMSModule.html#InstallPostMessage
  212.      * @ignore
  213.      */
  214.     function InstallPostMessage()
  215.     {
  216.         return $this->Lang('post_install'$this->GetVersion());
  217.     }
  218.     
  219.     /**
  220.      * @link http://www.cmsmadesimple.org/apidoc/CMS/CMSModule.html#UninstallPostMessage
  221.      * @ignore
  222.      */
  223.     function UninstallPostMessage()
  224.     {
  225.         return $this->Lang('post_uninstall'$this->GetVersion());
  226.     }
  227.     
  228.     /**
  229.      * @link http://www.cmsmadesimple.org/apidoc/CMS/CMSModule.html#UninstallPreMessage
  230.      * @ignore
  231.      */
  232.     function UninstallPreMessage()
  233.     {
  234.         return $this->Lang('confirm_uninstall');
  235.     }
  236.     
  237.     /**
  238.      * @link http://www.cmsmadesimple.org/apidoc/CMS/CMSModule.html#HandlesEvents
  239.      * @ignore
  240.      */
  241.     function HandlesEvents()
  242.     {
  243.         $feu_access $this->CleanArray(explode(',',$this->GetPreference('feu_access')));
  244.         if(!empty($feu_access))
  245.         {
  246.             return true;
  247.         }
  248.         return false;
  249.     }
  250.     
  251.     /**
  252.      * @link http://www.cmsmadesimple.org/apidoc/CMS/CMSModule.html#IsPluginModule
  253.      * @ignore
  254.      */
  255.     function IsPluginModule()
  256.     {
  257.         $feu_access $this->CleanArray(explode(',',$this->GetPreference('feu_access')));
  258.         if(!empty($feu_access))
  259.         {
  260.             return true;
  261.         }
  262.         return false;
  263.     }
  264.     
  265.     /**
  266.      * @link http://www.cmsmadesimple.org/apidoc/CMS/CMSModule.html#DoAction
  267.      * @ignore
  268.      */
  269.     function DoAction($action$id$params$returnid '')
  270.     {
  271.         switch($action)
  272.         {
  273.             case 'upload':
  274.             case 'savePrefs':
  275.             case 'fileBrowser':
  276.             case 'defaultadmin':
  277.             case 'reloadDropdown':
  278.                 parent::DoAction($action$id$params$returnid);
  279.                 break;
  280.             case 'delete':
  281.                 unset($params['action']);
  282.                 parent::DoAction('fileBrowser'$id$params$returnid);
  283.                 break;
  284.             defaultbreak;
  285.         }
  286.     }
  287.     
  288.     /**
  289.      * @link http://www.cmsmadesimple.org/apidoc/CMS/CMSModule.html#SetParameters
  290.      * @todo create list of allowed parameters!
  291.      */
  292.     function SetParameters()
  293.     {
  294.         #$this->RestrictUnknownParams();
  295.     }
  296.     
  297.     /**
  298.      * @link http://www.cmsmadesimple.org/apidoc/CMS/CMSModule.html#HasCapability
  299.      * @ignore
  300.      */
  301.     function HasCapability($capability,$params array())
  302.     {
  303.         switch$capability )
  304.         {
  305.             case 'contentblocks':
  306.             case 'content_attributes':
  307.                 return TRUE;
  308.             default:
  309.                 return FALSE;
  310.         }
  311.     }
  312.     
  313.     /**
  314.      * @link http://www.cmsmadesimple.org/apidoc/CMS/CMSModule.html#GetContentBlockInput
  315.      * @ignore
  316.      */
  317.     function GetContentBlockInput($blockname,$value,$params,$adding false)
  318.     {
  319.         if($this->CheckPermission('Use GBFilePicker'))
  320.         {
  321.             if(isset($params['smarty']&& $this->IsTrue($params['smarty']))
  322.             {
  323.                 foreach($params as $k=>$v)
  324.                 {
  325.                     $params[$k$this->DoSmarty($v);
  326.                 }
  327.             }
  328.             return $this->CreateFilePickerInput($this''str_replace(' ','_',$blockname)$value$params);
  329.         }
  330.         return;
  331.     }
  332.     
  333.     /**
  334.      * @link http://www.cmsmadesimple.org/apidoc/CMS/CMSModule.html#GetHeaderHTML
  335.      * @ignore
  336.      */
  337.     function GetHeaderHTML()
  338.     {
  339.         $this->smarty->assign('gbfp_reload_dir_text'$this->lang('reload_dir'));
  340.         $this->smarty->assign('gbfp_clear_cache_text'$this->lang('clear_cache'));
  341.         $this->smarty->assign('gbfp_close_text'$this->lang('close'));
  342.         $this->smarty->assign('thumb_width'get_site_preference('thumbnail_width',96));
  343.         $this->smarty->assign('thumb_height'get_site_preference('thumbnail_height',96));
  344.         $this->smarty->assign('gbfp_title'$this->Lang('browser_title'));
  345.         $this->smarty->assign('gbfp_id''');
  346.         return $this->ProcessTemplate('themes'.DIRECTORY_SEPARATOR.$this->GetPreference('default_admin_theme','Default (AJAX)').DIRECTORY_SEPARATOR.'header.tpl');
  347.     }
  348.  
  349. #-------------------------------------------------------------------------------
  350. # Not part of the CMSms module API
  351. #-------------------------------------------------------------------------------
  352.     
  353.     /**
  354.      * Creates the filepicker input.
  355.      *
  356.      * @since 1.0
  357.      * @access public
  358.      *
  359.      * @param object &$module - the module instance that calls the filepicker (this is only needed if you want to process own templates; pass the filepicker instance itself or leave it empty if you don't need this)
  360.      * @param string $id - the id of the moduleinstance that creates the filepicker input
  361.      * @param string $name - the name of the input field
  362.      * @param string $value - the preselected value
  363.      * @param array $params - the input params (param_name => param_value):<br /><ul>
  364.      *         <li>(string)  'feu_access'               => a csv of group ids of the frontend users module,</li>
  365.      *         <li>(boolean) 'restrict_users_diraccess' => set to true if user may only access a dir of his username (notice: this has no effect if you are admin; in frontend this will always be true),</li>
  366.      *         <li>(string)  'header_template'          => specify wich template should be used to create the html output that will be placed in the &lt;head&gt; section (default is header.tpl of the selected theme of GBFilePickers preferences),</li>
  367.      *         <li>(string)  'input_template'           => specify wich template should be used to create the input elements (default is input.tpl of the selected theme of GBFilePickers preferences),</li>
  368.      *         <li>(string)  'upload_template'          => specify wich template should be used to create the upload form of mode dropdown (default is upload.tpl of the selected theme of GBFilePickers preferences),</li>
  369.      *         <li>(string)  'filebrowser_template'     => specify wich template should be used to create the filebrowser output (default is fileBrowser.tpl of the selected theme of GBFilePickers preferences),</li>
  370.      *         <li>(string)  'prompt'                   => the prompt of the input field,</li>
  371.      *         <li>(string)  'media_type'               => the media type (at the moment only image / file are supported),</li>
  372.      *         <li>(mixed)   'file_extensions'          => an array or a csv of allowed file extensions,</li>
  373.      *         <li>(mixed)   'exclude_prefix'           => an array or a csv of file prefixes that will be excluded,</li>
  374.      *         <li>(mixed)   'exclude_sufix'            => an array or a csv of file suffixes that will be excluded,</li>
  375.      *         <li>(mixed)   'include_prefix'           => an array or a csv of file prefixes that will be included,</li>
  376.      *         <li>(mixed)   'include_sufix'            => an array or a csv of file suffixes that will be included,</li>
  377.      *         <li>(boolean) 'show_subdirs'             => set to true if user may browse subdirs (notice: this has no effect if you are admin)</li>
  378.      *         <li>(string)  'mode'                     => dropdown/browser,</li>
  379.      *         <li>(boolean) 'allow_none'               => set to false if the option "none" should not be shown (notice: this has no effect if you are admin),</li>
  380.      *         <li>(boolean) 'lock_input'               => set to false if user may enter the path in the inputfield ('mode'=>'browser', 'media_type' => 'file') (notice: this has no effect if you are admin),</li>
  381.      *         <li>(boolean) 'upload'                   => set to true if user may upload files (notice: this has no effect if you are admin or have permission to modify files),</li>
  382.      *         <li>(boolean) 'delete'                   => set to true if user may delete files/dirs (notice: this has no effect if you are admin or have permission to modify files),</li>
  383.      *         <li>(boolean) 'create_dirs'              => set to true if user may create dirs (notice: this has no effect if you are admin or have permission to modify files),</li>
  384.      *         <li>(string)  'add_txt'                  => any additional text that will be added to the html input when tag is rendered,</li>
  385.      *         <li>(integer) 'size'                     => the size of the textinput ('mode' => 'browser', 'media_type' => 'file' only),</li>
  386.      *         <li>(integer) 'maxlength'                => the max length of the textinput ('mode' => 'browser', 'media_type' => 'file' only),</li>
  387.      *         <li>(integer) 'scaling_width'            => the default width of images when allow_scaling is true,</li>
  388.      *         <li>(integer) 'scaling_height'           => the default height of images when allow_scaling is true,</li>
  389.      *         <li>(boolean) 'show_thumbfiles'          => set to true if thumbs should also be shown as regular files,</li>
  390.      *         <li>(boolean) 'allow_scaling'            => set to false if user may not scale the images on upload,</li>
  391.      *         <li>(boolean) 'create_thumbs'            => set to false if the module may not create thumbs for the input,</li>
  392.      *         <li>(boolean) 'allow_upscaling'          => set to true if user may enlarge the images</li>
  393.      *         <li>(boolean) 'force_scaling'            => set to true to force resizing of image to a given size if user may not resize images</li>
  394.      *         <li>(boolean) 'keep_aspectratio'         => set to false to change aspect ratio to that one of the scaling size on resizing images</li></ul>
  395.      * @param integer $returnid - the page id to return to and to print out the result after module has finished its task;<br />usually this has nothing to say but is required for frontend usage (must be an existing content id)
  396.      *
  397.      * @return string - the HTML output of the filepicker
  398.      *
  399.      */
  400.     public function CreateFilePickerInput(&$module$id$name$value ''$params array()$returnid '')
  401.     {
  402.         global $config;
  403.         if(class_exists('cms_utils'&& cms_utils::get_current_pageid(&& $returnid == '')
  404.         {
  405.             $returnid cms_utils::get_current_pageid();
  406.         }
  407.         $name str_replace(' ','_',$name);
  408.         if($module == '')
  409.         {
  410.             $module =$this;
  411.         }
  412.         if(!$params =$this->SetInputParams($module$id$name$params))
  413.         {
  414.             return;
  415.         }
  416.         $value  $this->CleanUrl($valuefalse);
  417.         $module->smarty->assign('thumb_width'get_site_preference('thumbnail_width',96));
  418.         $module->smarty->assign('thumb_height'get_site_preference('thumbnail_height',96));
  419.         
  420.         if($params['media_type'== 'image')
  421.         {
  422.             $thumbnail_size $this->GetThumbnailSize($value);
  423.             $module->smarty->assign('gbfp_thumb_width'$thumbnail_size[0]);
  424.             $module->smarty->assign('gbfp_thumb_height'$thumbnail_size[1]);
  425.             $module->smarty->assign('gbfp_thumburl'$this->GetThumbnail($value$params['create_thumbs'],true));
  426.         }
  427.         $module->smarty->assign('gbfp_value'$value);
  428.         $module->smarty->assign('gbfp_loaded'$this->_loaded);
  429.         if(!$this->_loaded)
  430.         {
  431.             // ugly hack!
  432.             $headers_list headers_list();
  433.             $output str_replace('</head>'$this->GetHeaderHTML('</head>'ob_get_contents());
  434.             @ob_end_clean();
  435.             @ob_start();
  436.             foreach($headers_list as $header)
  437.             {
  438.                 header($header);
  439.             }
  440.             echo $output;
  441.             //--- but works :D
  442.         }
  443.         $this->_loaded true;
  444.         
  445.         $input       '';
  446.         $upload_link '';
  447.         $browse_link '';
  448.         $clear_link  '';
  449.         $reload_link '';
  450.         $upload_url  '';
  451.         $browse_url  '';
  452.         $reload_url  '';
  453.         
  454.         $filebrowser_url str_replace('&amp;','&',$this->CreateLink(($id == '' 'm1_' $id)'fileBrowser'$returnid'',array('name' =>$name,'dir'=>($this->_isAdmin?$params['dir']:'')),''true));
  455.         
  456.         if($params['mode'== 'dropdown')
  457.         {
  458.             $input $this->CreateFileDropdown(
  459.                 $id,
  460.                 $name,
  461.                 $params['dir'],
  462.                 $value,
  463.                 $params['exclude_prefix'],
  464.                 $params['include_prefix'],
  465.                 $params['exclude_sufix'],
  466.                 $params['include_sufix'],
  467.                 $params['file_extensions'],
  468.                 $params['media_type'],
  469.                 $params['allow_none'],
  470.                 $params['add_txt']);
  471.             
  472.             if($params['upload'])
  473.             {
  474.                 $upload_url  str_replace('&amp;','&',$this->CreateLink(($id == '' 'm1_' $id)'upload'$returnid$this->lang('upload'),array('name' =>$name,'dir'=>($this->_isAdmin?$params['dir']:'')),''true));
  475.                 $upload_link $this->CreateLink(($id == '' 'm1_' $id)'upload'$returnid$this->lang('upload')array('name' =>$name)''falsefalse'id="'.$id.$name.'_GBFP_upload" class="GBFP_link GBFP_upload"');
  476.             }
  477.             
  478.             $reload_url  str_replace('&amp;','&',$this->CreateLink(($id == '' 'm1_' $id),'reloadDropdown',$returnid,$this->lang('reload_dropdown'),array('name' =>$name,'dir'=>($this->_isAdmin?$params['dir']:'')),'',true));
  479.             $reload_link $this->CreateLink(($id == '' 'm1_' $id)'reloadDropdown'$returnid$this->lang('reload_dropdown')array('name' =>$name)''falsefalse'id="'.$id.$name.'_GBFP_reload_dropdown" class="GBFP_link GBFP_reload_dropdown"');
  480.         }
  481.         else if($params['mode'== 'browser')
  482.         {
  483.             if($params['media_type'== 'image')
  484.             {
  485.                 $input '<input id="'.$id.$name.'" type="hidden" name="'.$id.$name.'" value="' $value '" />';
  486.             }
  487.             else if($params['media_type'== 'file')
  488.             {
  489.                 $input '<input id="'.$id.$name.'" class="GBFP_input GBFP_textinput" type="text"' ($params['lock_input']?' disabled="disabled"':''($params['add_txt'!= ''' '.$params['add_txt'].' ':''($params['size'!= ''?' size="' $params['size''"':''($params['maxlength'!= ''?' maxlength="' $params['maxlength''"':''' name="' $id.$name '" value="' $value '" />';
  490.             }
  491.             
  492.             $browse_url  str_replace('&amp;','&',$this->CreateLink(($id == '' 'm1_' $id)'fileBrowser'$returnid$this->lang('browse_'.$params['media_type']),array('name' =>$name,'dir'=>($this->_isAdmin?$params['dir']:'')),''true));
  493.             $browse_link $this->CreateLink(($id == '' 'm1_' $id)'fileBrowser'$returnid$this->lang('browse_'.$params['media_type'])array('name' =>$name,'dir'=>($this->_isAdmin?$params['dir']:''))''falsefalse'id="'.$id.$name.'_GBFP_browse" class="GBFP_link GBFP_browse"');
  494.             if($params['allow_none'])
  495.             {
  496.                 $clear_link '<a href="#" onclick="document.getElementById(\''.$id.$name.'\').value = \'\';return false;" id="'.$id.$name.'_GBFP_clear" class="GBFP_link GBFP_clear">'.$this->lang('none').'</a>';
  497.             }
  498.         }
  499.         
  500.         debug_buffer($params,'GBFilePicker input params; input = "'.$id.$name.'"; function CreateFilePickerInput() FINAL');
  501.         $module->smarty->assign('gbfp_filebrowser_url'$filebrowser_url);
  502.         $module->smarty->assign('gbfp_input'$input);
  503.         $module->smarty->assign('gbfp_upload_url'$upload_url);
  504.         $module->smarty->assign('gbfp_upload_link'$upload_link);
  505.         $module->smarty->assign('gbfp_reload_dropdown_url'$reload_url);
  506.         $module->smarty->assign('gbfp_reload_dropdown_link'$reload_link);
  507.         $module->smarty->assign('gbfp_browse_url'$browse_url);
  508.         $module->smarty->assign('gbfp_browse_link'$browse_link);
  509.         $module->smarty->assign('gbfp_clear_link'$clear_link);
  510.         
  511.         $module->smarty->assign('gbfp_name'$name);
  512.         $module->smarty->assign('gbfp_inputid'$id.$name);
  513.         
  514.         $module->smarty->assign('gbfp_title'$this->Lang('browser_title'));
  515.         
  516.         foreach($params as $k => $v)
  517.         {
  518.             $module->smarty->assign('gbfp_'.$k,$v);
  519.         }
  520.         $module->smarty->assign('gbfp_id'($id == '' 'm1_' $id));
  521.         $module->smarty->assign('gbfp_reload_dir_text'$this->lang('reload_dir'));
  522.         $module->smarty->assign('gbfp_clear_cache_text'$this->lang('clear_cache'));
  523.         $module->smarty->assign('gbfp_close_text'$this->lang('close'));
  524.         
  525.         if(endswith($params['input_template'],'.tpl'))
  526.         {
  527.             return $module->ProcessTemplate($params['input_template']);
  528.         }
  529.         return $module->ProcessTemplateFromDatabase($params['input_template']);
  530.     }
  531.     
  532.     
  533.     /**
  534.      * @since 1.1
  535.      * @access private
  536.      * @ignore
  537.      */
  538.     private function &SetInputParams(&$module$id$name$params array())
  539.     {
  540.         global $CMS_ADMIN_PAGE$config;
  541.         @session_start();
  542.         $_SESSION['GPFP_' ($id == '' 'm1_' $id).$namearray();
  543.         $result false;
  544.         $name str_replace(' ','_',$name);
  545.         if(!$session_params =$this->GetInputParams($id$name))
  546.         {
  547.             return $result;
  548.         }
  549.         
  550.         if(isset($params['prompt']))
  551.         {
  552.             $session_params['prompt'$params['prompt'];
  553.         }
  554.         
  555.         if(isset($params['header_template']))
  556.         {
  557.             $session_params['header_template'$params['header_template'];
  558.         }
  559.         if(isset($params['input_template']))
  560.         {
  561.             $session_params['input_template'$params['input_template'];
  562.         }
  563.         if(isset($params['upload_template']))
  564.         {
  565.             $session_params['upload_template'$params['upload_template'];
  566.         }
  567.         if(isset($params['filebrowser_template']))
  568.         {
  569.             $session_params['filebrowser_template'$params['filebrowser_template'];
  570.         }
  571.         
  572.         $session_params['module'$module->GetName();
  573.         if(isset($params['feu_access']))
  574.         {
  575.             if(!is_array($params['feu_access']))
  576.             {
  577.                 $session_params['feu_access'$this->CleanArray(explode(',',$params['feu_access']));
  578.             }
  579.             else
  580.             {
  581.                 $session_params['feu_access'$this->CleanArray($params['feu_access']);
  582.             }
  583.         }
  584.         if(isset($params['restrict_users_diraccess']&& $this->IsFalse($params['restrict_users_diraccess']))
  585.         {
  586.             $session_params['restrict_users_diraccess'false;
  587.         }
  588.         
  589.         $dir $session_params['start_dir'];
  590.         if(isset($params['dir']&& $params['dir'!= '')
  591.         {
  592.             $dir $this->CleanUrl($params['dir'],false);
  593.             if(!$this->_isAdmin)
  594.             {
  595.                 $session_params['start_dir'$dir;
  596.             }
  597.         }
  598.         
  599.         if(isset($CMS_ADMIN_PAGE&& $CMS_ADMIN_PAGE == 1)
  600.         {
  601.             check_login();
  602.             if(!$this->CheckPermission('Use GBFilePicker'))
  603.             {
  604.                 return $result;
  605.             }
  606.             $username $this->_username;
  607.         }
  608.         else
  609.         {
  610.             if!$feusers =$this->GetModuleInstance('FrontEndUsers' ) )
  611.             {
  612.                 return $result;
  613.             }
  614.             if(!$userid $feusers->LoggedInId())
  615.             {
  616.                 return $result;
  617.             }
  618.             if(!$groups $feusers->GetMemberGroupsArray($userid))
  619.             {
  620.                 return $result;
  621.             }
  622.             $access false;
  623.             foreach($groups as $_group)
  624.             {
  625.                 if(in_array($_group['groupid'],$session_params['feu_access']))
  626.                 {
  627.                     $access true;
  628.                     break;
  629.                 }
  630.             }
  631.             if(!$access)
  632.             {
  633.                 return $result;
  634.             }
  635.             
  636.             $username $feusers->GetUserName($userid);
  637.             $params['media_type''image';
  638.             $params['restrict_users_diraccess'true;
  639.         }
  640.         
  641.         if(!$this->_isAdmin && $session_params['restrict_users_diraccess'])
  642.         {
  643.             if(!in_array($username$this->CleanArray(explode('/',$dir))))
  644.             {
  645.                 $session_params['start_dir'.= '/' $dir;
  646.             }
  647.             else
  648.             {
  649.                 $session_params['start_dir'$dir;
  650.             }
  651.             
  652.             $_dir $this->CleanPath($session_params['start_dir']);
  653.             if(!@mkdir($_dir0755true&& !file_exists($_dir&& !is_dir($_dir))
  654.             {
  655.                 return $result;
  656.             }
  657.         }
  658.         
  659.         if(isset($params['media_type']))
  660.         {
  661.             $session_params['media_type'strtolower($params['media_type']);
  662.         }
  663.         
  664.         if($session_params['media_type'== 'file')
  665.         {
  666.             $session_params['file_extensions'array();
  667.         }
  668.         if(isset($params['file_extensions']&& $params['file_extensions'!= '')
  669.         {
  670.             $_file_ext $this->CleanArray(explode(',',strtolower($params['file_extensions'])));
  671.             if($session_params['media_type'== 'image')
  672.             {
  673.                 $_file_ext $this->CleanArray(array_intersect($_file_extarray('jpg','jpeg','gif','png')));
  674.             }
  675.             if(empty($_file_ext))
  676.             {
  677.                 $_file_ext $session_params['file_extensions'];
  678.             }
  679.             $session_params['file_extensions'$_file_ext;
  680.         }
  681.         if(isset($params['exclude_prefix']))
  682.         {
  683.             $session_params['exclude_prefix'trim($params['exclude_prefix']);
  684.         }
  685.         if(isset($params['exclude_sufix']))
  686.         {
  687.             $session_params['exclude_sufix'trim($params['exclude_sufix']);
  688.         }
  689.         if(isset($params['include_prefix']))
  690.         {
  691.             $session_params['include_prefix'trim($params['include_prefix']);
  692.         }
  693.         if(isset($params['include_sufix']))
  694.         {
  695.             $session_params['include_sufix'trim($params['include_sufix']);
  696.         }
  697.         
  698.         if(isset($params['show_subdirs']&& $this->IsTrue($params['show_subdirs']))
  699.         {
  700.             $session_params['show_subdirs'true;
  701.         }
  702.         else if(isset($params['show_subdirs']&& $this->IsFalse($params['show_subdirs']&& !$this->_isAdmin)
  703.         {
  704.             $session_params['show_subdirs'false;
  705.         }
  706.         
  707.         if(isset($params['mode']))
  708.         {
  709.             $session_params['mode'strtolower($params['mode']);
  710.         }
  711.         if(isset($params['allow_none']&& $this->IsFalse($params['allow_none']&& !$this->_isAdmin)
  712.         {
  713.             $session_params['allow_none'false;
  714.         }
  715.         
  716.         if(isset($params['lock_input']&& $this->IsFalse($params['lock_input']))
  717.         {
  718.             $session_params['lock_input'false;
  719.         }
  720.         else if(isset($params['lock_input']&& $this->IsTrue($params['lock_input']&& !$this->_isAdmin)
  721.         {
  722.             $session_params['lock_input'true;
  723.         }
  724.         
  725.         if(isset($params['upload']&& $this->IsTrue($params['upload']&& $this->GetPreference('show_filemanagement'))
  726.         {
  727.             $session_params['upload'true;
  728.         }
  729.         else if(isset($params['upload']&& $this->IsFalse($params['upload']&& !$this->_isAdmin)
  730.         {
  731.             $session_params['upload'false;
  732.         }
  733.         
  734.         if(isset($params['delete']&& $this->IsTrue($params['delete']&& $this->GetPreference('show_filemanagement'))
  735.         {
  736.             $session_params['delete'true;
  737.         }
  738.         else if(isset($params['delete']&& $this->IsFalse($params['delete']&& !$this->_isAdmin)
  739.         {
  740.             $session_params['delete'false;
  741.         }
  742.         
  743.         if(isset($params['create_dirs']&& $this->IsTrue($params['create_dirs']&& $this->GetPreference('show_filemanagement'))
  744.         {
  745.             $session_params['create_dirs'true;
  746.         }
  747.         else if(isset($params['create_dirs']&& $this->IsFalse($params['create_dirs']&& !$this->_isAdmin)
  748.         {
  749.             $session_params['create_dirs'false;
  750.         }
  751.         
  752.         if(isset($params['add_txt']))
  753.         {
  754.             $session_params['add_txt'trim($params['add_txt']);
  755.         }
  756.         if(isset($params['size']))
  757.         {
  758.             $session_params['size'intval($params['size']);
  759.         }
  760.         if(isset($params['maxlength']))
  761.         {
  762.             $session_params['maxlength'intval($params['maxlength']);
  763.         }
  764.         if(isset($params['scaling_width']))
  765.         {
  766.             $session_params['scaling_width'intval($params['scaling_width']);
  767.         }
  768.         if(isset($params['scaling_height']))
  769.         {
  770.             $session_params['scaling_height'intval($params['scaling_height']);
  771.         }
  772.         if(isset($params['show_thumbfiles']))
  773.         {
  774.             $session_params['show_thumbfiles'intval($params['show_thumbfiles']);
  775.         }
  776.         if(isset($params['allow_scaling']))
  777.         {
  778.             $session_params['allow_scaling'intval($params['allow_scaling']);
  779.         }
  780.         if(isset($params['create_thumbs']))
  781.         {
  782.             $session_params['create_thumbs'intval($params['create_thumbs']);
  783.         }
  784.         if(isset($params['allow_upscaling']))
  785.         {
  786.             $session_params['allow_upscaling'intval($params['allow_upscaling']);
  787.         }
  788.         if(isset($params['force_scaling']))
  789.         {
  790.             $session_params['force_scaling'intval($params['force_scaling']);
  791.         }
  792.         if(isset($params['keep_aspect_ratio']))
  793.         {
  794.             $session_params['keep_aspect_ratio'intval($params['keep_aspect_ratio']);
  795.         }
  796.         
  797.         if($session_params['mode'== 'dropdown')
  798.         {
  799.             $session_params['dir']       $dir;
  800.             $session_params['start_dir'$dir;
  801.         }
  802.         
  803.         $_SESSION['GBFP_id_'.$name($id == '' 'm1_' $id);
  804.         
  805.         $_SESSION['GPFP_' ($id == '' 'm1_' $id).$name$session_params;
  806.         
  807.         #debug_buffer($session_params,'GBFilePicker session vars; input = "'.$id.$name.'"; function SetInputParams()');
  808.         
  809.         $session_params['dir'$dir;
  810.         return $session_params;
  811.     }
  812.     
  813.     
  814.     /**
  815.      * @since 1.1
  816.      * @access protected
  817.      * @ignore
  818.      */
  819.     protected function &GetInputParams($id$name)
  820.     {
  821.         $name   str_replace(' ','_',$name);
  822.         $params array(
  823.             'id'                       => $id,
  824.             'name'                     => $name,
  825.             'module'                   => $this->GetName(),
  826.             'start_dir'                => '',
  827.             'feu_access'               => $this->CleanArray(explode(',',$this->GetPreference('feu_access'))),
  828.             'restrict_users_diraccess' => intval($this->GetPreference('restrict_users_diraccess'false)),
  829.             'prompt'                   => '',
  830.             'media_type'               => 'image',
  831.             'file_extensions'          => array('jpg','jpeg','gif','png'),
  832.             'exclude_prefix'           => '',
  833.             'exclude_sufix'            => '',
  834.             'include_prefix'           => '',
  835.             'include_sufix'            => '',
  836.             'show_subdirs'             => intval($this->_isAdmin),
  837.             'mode'                     => 'dropdown',
  838.             'allow_none'               => true,
  839.             'lock_input'               => intval(!$this->_isAdmin),
  840.             'upload'                   => intval($this->_isAdmin || ($this->GetPreference('show_filemanagement'false&& $this->CheckPermission('Modify Files'))),
  841.             'delete'                   => intval($this->_isAdmin || ($this->GetPreference('show_filemanagement'false&& $this->CheckPermission('Modify Files'))),
  842.             'create_dirs'              => intval($this->_isAdmin || ($this->GetPreference('show_filemanagement'false&& $this->CheckPermission('Modify Files'))),
  843.             'add_txt'                  => '',
  844.             'size'                     => '',
  845.             'maxlength'                => '',
  846.             'scaling_width'            => intval($this->GetPreference('scaling_width''')),
  847.             'scaling_height'           => intval($this->GetPreference('scaling_height''')),
  848.             'show_thumbfiles'          => intval($this->GetPreference('show_thumbfiles'false)),
  849.             'allow_scaling'            => intval($this->GetPreference('allow_scaling'false|| $this->_isAdmin),
  850.             'create_thumbs'            => intval($this->GetPreference('create_thumbs'true)),
  851.             'allow_upscaling'          => intval($this->GetPreference('allow_upscaling'false|| $this->_isAdmin),
  852.             'force_scaling'            => intval($this->GetPreference('force_scaling',false)),
  853.             'keep_aspect_ratio'        => intval($this->GetPreference('keep_aspectratio',true)));
  854.         
  855.         global $CMS_ADMIN_PAGE$config;
  856.         $result false;
  857.         if(isset($CMS_ADMIN_PAGE&& $CMS_ADMIN_PAGE == 1)
  858.         {
  859.             check_login();
  860.             if(!$this->CheckPermission('Use GBFilePicker'))
  861.             {
  862.                 return $result;
  863.             }
  864.             if(!$this->_isAdmin && $params['restrict_users_diraccess'])
  865.             {
  866.                 $params['start_dir'$this->_username;
  867.             }
  868.             $params['input_template''themes'.DIRECTORY_SEPARATOR.$this->GetPreference('default_admin_theme','Default (AJAX)').DIRECTORY_SEPARATOR.'input.tpl';
  869.             $params['filebrowser_template''themes'.DIRECTORY_SEPARATOR.$this->GetPreference('default_admin_theme','Default (AJAX)').DIRECTORY_SEPARATOR.'fileBrowser.tpl';
  870.             $params['upload_template''themes'.DIRECTORY_SEPARATOR.$this->GetPreference('default_admin_theme','Default (AJAX)').DIRECTORY_SEPARATOR.'upload.tpl';
  871.             $params['header_template''themes'.DIRECTORY_SEPARATOR.$this->GetPreference('default_admin_theme','Default (AJAX)').DIRECTORY_SEPARATOR.'header.tpl';
  872.         }
  873.         else
  874.         {
  875.             if!$feusers =$this->GetModuleInstance('FrontEndUsers' ) )
  876.             {
  877.                 return $result;
  878.             }
  879.             if(!$userid $feusers->LoggedInId())
  880.             {
  881.                 return $result;
  882.             }
  883.             if(!$groups $feusers->GetMemberGroupsArray($userid))
  884.             {
  885.                 return $result;
  886.             }
  887.             $access false;
  888.             foreach($groups as $_group)
  889.             {
  890.                 if(in_array($_group['groupid'],$params['feu_access']))
  891.                 {
  892.                     $access true;
  893.                     break;
  894.                 }
  895.             }
  896.             if(!$access)
  897.             {
  898.                 return $result;
  899.             }
  900.             $params['input_template''themes'.DIRECTORY_SEPARATOR.$this->GetPreference('default_frontend_theme','Default (AJAX)').DIRECTORY_SEPARATOR.'input.tpl';
  901.             $params['filebrowser_template''themes'.DIRECTORY_SEPARATOR.$this->GetPreference('default_frontend_theme','Default (AJAX)').DIRECTORY_SEPARATOR.'fileBrowser.tpl';
  902.             $params['upload_template''themes'.DIRECTORY_SEPARATOR.$this->GetPreference('default_frontend_theme','Default (AJAX)').DIRECTORY_SEPARATOR.'upload.tpl';
  903.             $params['header_template''themes'.DIRECTORY_SEPARATOR.$this->GetPreference('default_frontend_theme','Default (AJAX)').DIRECTORY_SEPARATOR.'header.tpl';
  904.             $params['restrict_users_diraccess'true;
  905.             $params['start_dir'$feusers->GetPreference('image_destination_path''feusers''/' $feusers->GetUserName($userid);
  906.         }
  907.         
  908.         #debug_buffer($params,'GBFilePicker input params; input = "'.$id.$name.'"; function GetInputParams()');
  909.         
  910.         if(isset($_SESSION['GPFP_' ($id == '' 'm1_' $id).$name]))
  911.         {
  912.             $params array_merge($params$_SESSION['GPFP_' ($id == '' 'm1_' $id).$name]);
  913.             return $params;
  914.         }
  915.         return $params;
  916.     }
  917.     
  918.     /**
  919.      * Gets the file type of a file.
  920.      *
  921.      * @since 1.0
  922.      * @access public
  923.      *
  924.      * @param string $file - the path to a file
  925.      * @param string $use_mime - set to true to detect file type by mime type
  926.      *
  927.      * @return string - the mime-type or file extension
  928.      */
  929.     public function GetFileType($file$use_mime false)
  930.     {
  931.         $filetype '';
  932.         if($use_mime)
  933.         {
  934.             if (version_compare(PHP_VERSION'5.3.0'>= && function_exists('finfo_open'))
  935.             {
  936.                 $finfo    finfo_open(FILEINFO_MIME_TYPE);
  937.                 $filetype strtolower(finfo_file($finfo$file));
  938.                 finfo_close($finfo);
  939.             }
  940.             else if(function_exists('mime_content_type'))
  941.             {
  942.                 $filetype strtolower(mime_content_type($file));
  943.             }
  944.         }
  945.         else
  946.         {
  947.             $fileinfo pathinfo($file);
  948.             if(isset($fileinfo['extension']))
  949.             {
  950.                 $filetype strtolower($fileinfo['extension']);
  951.             }
  952.         }
  953.         return $filetype;
  954.     }
  955.     
  956.     
  957.     /**
  958.      * Create a dropdown form element containing a list of files that match certain conditions
  959.      *
  960.      * @since 1.0
  961.      * @access public
  962.      *
  963.      * @param string $id - the id of the moduleinstance that creates the filepicker input
  964.      * @param string $name - the name of the input field
  965.      * @param string $dir - the directory to list the files of (may be relative to uploads dir or absolute path)
  966.      * @param string $selected - the preselected value
  967.      * @param array|string$excl_prefix - fileprefixes to exclude (array('foo','bar',...) or csv)
  968.      * @param array|string$incl_prefix - fileprefixes to include (array('foo','bar',...) or csv)
  969.      * @param array|string$excl_sufix - filesufixes to exclude (array('foo','bar',...) or csv)
  970.      * @param array|string$incl_sufix - filesufixes to include (array('foo','bar',...) or csv)
  971.      * @param array|string$file_ext - filesufixes to include (array('foo','bar',...) or csv)
  972.      * @param string $media_type - file or image
  973.      * @param boolean $allow_none - set to false to hide the option 'none'
  974.      * @param string $add_txt - any additional text that will be added to the html input when tag is rendered
  975.      *
  976.      * @return string - the HTML output of a select element with options
  977.      */
  978.     public function CreateFileDropdown($id$name$dir ''$selected ''$excl_prefix ''$incl_prefix '',
  979.         $excl_sufix ''$incl_sufix ''$file_ext ''$media_type ''$allow_none true$add_txt '')
  980.     {
  981.         $files =$this->GetInputFiles($id$name$dir);
  982.         if(empty($files&& !$allow_none)
  983.         {
  984.             return $this->lang('dir_empty');
  985.         }
  986.         $dropdown '<select class="GBFP_input GBFP_dropdown GBFP_'.$media_type.'" name="'.$id.$name.'" id="'.$id.$name.'"';
  987.         if($add_txt != '')
  988.         {
  989.             $dropdown .= ' '.$add_txt;
  990.         }
  991.         $dropdown .= '>';
  992.         if$allow_none )
  993.         {
  994.             $dropdown .= '<option value=""';
  995.             if($selected == '')
  996.             {
  997.                 $dropdown .= ' selected="selected"';
  998.             }
  999.             $dropdown .= ' thumbnail="">--- '.lang('none').' ---</option>';
  1000.         }
  1001.         foreach$files as $file )
  1002.         {
  1003.             $dropdown .= '<option value="'.$file->relurl.'"';
  1004.             if($file->relurl == $selected)
  1005.             {
  1006.                 $dropdown .= ' selected="selected"';
  1007.             }
  1008.             if($file->is_image && $media_type == 'image')
  1009.             {
  1010.                 $dropdown .= ' thumbnail="'.(isset($file->thumburl&& $file->thumburl!=''?$file->thumburl:$file->fullurl).'"';
  1011.             }
  1012.             $dropdown .= '>'.$file->basename.'</option>';
  1013.         }
  1014.         $dropdown .= "</select>";
  1015.         return $dropdown;
  1016.     }
  1017.     
  1018.     
  1019.     /**
  1020.      * Return an array containing a list of files in a directory related to a certain input.<br />
  1021.      * Performs a non recursive search.
  1022.      *
  1023.      * @since 1.1
  1024.      * @access public
  1025.      *
  1026.      * @param string $id - the id of the moduleinstance that creates the filepicker input
  1027.      * @param string $name - the name of the input field
  1028.      * @param string $dir - the directory to list the files of (may be relative to uploads dir or absolute path)
  1029.      *
  1030.      * @return array 
  1031.      */
  1032.     public function &GetInputFiles($id$name$dir)
  1033.     {
  1034.         $params =$this->GetInputParams($id$name);
  1035.         return $this->GetFiles($dir$params['exclude_prefix'],
  1036.             $params['include_prefix']$params['exclude_sufix'],
  1037.             $params['include_sufix']$params['file_extensions'],
  1038.             $params['media_type']($params['mode'== 'dropdown' true !$params['show_subdirs'])$params['show_thumbfiles'],
  1039.             $params['create_thumbs']);
  1040.     }
  1041.     
  1042.     
  1043.     /**
  1044.      * Return an array containing a list of files in a directory.<br />
  1045.      * Performs a non recursive search.
  1046.      *
  1047.      * @since 1.0
  1048.      * @access public
  1049.      *
  1050.      * @param string $dir - the directory to list the files of (may be relative to uploads dir or absolute path)
  1051.      * @param array|string$excl_prefix - fileprefixes to exclude (array('foo','bar',...) or csv)
  1052.      * @param array|string$incl_prefix - fileprefixes to include (array('foo','bar',...) or csv)
  1053.      * @param array|string$excl_sufix - filesufixes to exclude (array('foo','bar',...) or csv)
  1054.      * @param array|string$incl_sufix - filesufixes to include (array('foo','bar',...) or csv)
  1055.      * @param array|string$file_ext - filesufixes to include (array('foo','bar',...) or csv)
  1056.      * @param string $media_type - file or image
  1057.      * @param boolean $excl_dirs - set to true to exclude directories
  1058.      * @param boolean $show_thumbfiles 
  1059.      * @param boolean $create_thumbs = true
  1060.      *
  1061.      * @return array 
  1062.      */
  1063.     public function &GetFiles($dir ''$excl_prefix ''$incl_prefix ''$excl_sufix '',
  1064.         $incl_sufix ''$file_ext ''$media_type 'image'$excl_dirs false$show_thumbfiles false$create_thumbs true)
  1065.     {
  1066.         global $config;
  1067.         $files  Array();
  1068.         $dir    $this->CleanPath($dir);
  1069.         $url    $this->CleanURL($dir);
  1070.         
  1071.         if(!file_exists($dir|| !is_dir($dir))
  1072.         {
  1073.             return $files;
  1074.         }
  1075.         
  1076.         if(!is_array($excl_prefix))
  1077.         {
  1078.             $excl_prefix $this->CleanArray(explode(',',$excl_prefix));
  1079.         }
  1080.         
  1081.         if(!is_array($incl_prefix))
  1082.         {
  1083.             $incl_prefix $this->CleanArray(explode(',',$incl_prefix));
  1084.         }
  1085.         
  1086.         if(!is_array($excl_sufix))
  1087.         {
  1088.             $excl_sufix $this->CleanArray(explode(',',$excl_sufix));
  1089.         }
  1090.         
  1091.         if(!is_array($incl_sufix))
  1092.         {
  1093.             $incl_sufix $this->CleanArray(explode(',',$incl_sufix));
  1094.         }
  1095.         
  1096.         if(!is_array($file_ext))
  1097.         {
  1098.             $file_ext $this->CleanArray(explode(',',$file_ext));
  1099.         }
  1100.         
  1101.         $_file_ext array('jpg','jpeg','gif','png');
  1102.         if($media_type == 'image')
  1103.         {
  1104.             $file_ext $this->CleanArray(array_intersect($_file_ext$file_ext));
  1105.             if(empty($file_ext))
  1106.             {
  1107.                 $file_ext $_file_ext;
  1108.             }
  1109.         }
  1110.         
  1111.         $excl_prefix $this->CleanArray(array_diff($excl_prefix$incl_prefix));
  1112.         $excl_sufix  $this->CleanArray(array_diff($excl_sufix$incl_sufix));
  1113.         
  1114.         $d dir($dir);
  1115.         while ($entry $d->read())
  1116.         {
  1117.             if ($entry[0== '.' || (is_dir($dir.$entry&& $excl_dirs))
  1118.             {
  1119.                 continue;
  1120.             }
  1121.             
  1122.             $skip        false;
  1123.             $incl_thumbs false;
  1124.             
  1125.             $file         new stdClass();
  1126.             $file->is_dir is_dir($dir.$entry);
  1127.             $fileinfo     pathinfo($dir.$entry);
  1128.             foreach($fileinfo as $k=>$v)
  1129.             {
  1130.                 $file->$k $v;
  1131.             }
  1132.             if(!$file->is_dir)
  1133.             {
  1134.                 foreach($excl_prefix as $str)
  1135.                 {
  1136.                     if(startswith($file->filename,$str))
  1137.                     {
  1138.                         $skip true;
  1139.                         break;
  1140.                     }
  1141.                 }
  1142.                 if($skipcontinue;
  1143.                 
  1144.                 foreach($incl_prefix as $str)
  1145.                 {
  1146.                     if(startswith($str,'thumb_'))
  1147.                     {
  1148.                         $incl_thumbs true;
  1149.                     }
  1150.                     if(!startswith($file->filename,$str))
  1151.                     {
  1152.                         $skip true;
  1153.                         break;
  1154.                     }
  1155.                 }
  1156.                 if($skipcontinue;
  1157.                 
  1158.                 foreach($excl_sufix as $str)
  1159.                 {
  1160.                     if(endswith($file->filename,$str))
  1161.                     {
  1162.                         $skip true;
  1163.                         break;
  1164.                     }
  1165.                 }
  1166.                 if($skipcontinue;
  1167.                 
  1168.                 foreach($incl_sufix as $str)
  1169.                 {
  1170.                     if(!endswith($file->filename,$str))
  1171.                     {
  1172.                         $skip true;
  1173.                         break;
  1174.                     }
  1175.                 }
  1176.                 if($skip)
  1177.                     continue;
  1178.             }
  1179.             
  1180.             if(startswith($entry,'thumb_'&& !$show_thumbfiles && !$incl_thumbs)
  1181.             {
  1182.                 continue;
  1183.             }
  1184.             
  1185.             $filetype $this->GetFileType($dir.$entry,$this->GetPreference('use_mimetype',false));
  1186.             if (!$file->is_dir && $media_type == 'image' && !in_array(str_replace('image/','',$filetype),$file_ext))
  1187.             {
  1188.                 continue;
  1189.             }
  1190.             else if(!$file->is_dir && $media_type != 'image' && !in_array($file->extension,$file_ext&& !empty($file_ext))
  1191.             {
  1192.                 continue;
  1193.             }
  1194.             
  1195.             $file->fullurl      $url.$entry;
  1196.             $file->relurl       trim(str_replace($config['uploads_url'],'',$file->fullurl),'/');
  1197.             $file->id           munge_string_to_url($file->relurl);
  1198.             $file->last_modifed filemtime($dir.$entry);
  1199.             
  1200.             if (!$file->is_dir)
  1201.             {
  1202.                 $file->is_image false;
  1203.                 if (!$file->is_dir && in_array(str_replace('image/','',$filetype),array('jpg','jpeg','gif','png')))
  1204.                 {
  1205.                     $file->is_image true;
  1206.                 }
  1207.                 $file->filetype $filetype;
  1208.                 if($file->is_image)
  1209.                 {
  1210.                     $file->thumbnail '';
  1211.                     $file->thumburl  '';
  1212.                     if ($show_thumbfiles || $incl_thumbs)
  1213.                     {
  1214.                         $file->thumbnail $this->GetThumbnail($dir.str_replace('thumb_'''$entry)$create_thumbs);
  1215.                         $file->thumburl  $this->GetThumbnail($dir.str_replace('thumb_'''$entry)$create_thumbs,true);
  1216.                     }
  1217.                     else
  1218.                     {
  1219.                         $file->thumbnail $this->GetThumbnail($dir.$entry$create_thumbs);
  1220.                         $file->thumburl  $this->GetThumbnail($dir.$entry$create_thumbs,true);
  1221.                     }
  1222.                     
  1223.                     $file->imgsize '';
  1224.                     $imgsize @getimagesize($dir.$entry);
  1225.                     if ($imgsize)
  1226.                     {
  1227.                         $file->imgsize $imgsize[0' x ' $imgsize[1];
  1228.                     }
  1229.                     else
  1230.                     {
  1231.                         $file->imgsize '&nbsp;';
  1232.                     }
  1233.                 }
  1234.                 $file->filesize '';
  1235.                 $info @stat($dir.$entry);
  1236.                 if ($info)
  1237.                 {
  1238.                     $file->filesize $info['size'];
  1239.                 }
  1240.                 $file->fileicon $this->GetFileIcon($file->extension,false,true);
  1241.             }
  1242.             else
  1243.             {
  1244.                 $file->fileicon $this->GetFileIcon('',true);
  1245.             }
  1246.             $files[$file;
  1247.         }
  1248.         $d->close();
  1249.         usort($filesarray($this'SortFiles'));
  1250.         return $files;
  1251.     }
  1252.     
  1253.     
  1254.     /**
  1255.      * Replaces all multiple DIRECTORY_SEPARATOR, dots and (multiple) slashes with one single DIRECTORY_SEPARATOR to make a clean secure path parameter
  1256.      *
  1257.      * @since 1.0
  1258.      * @access public
  1259.      *
  1260.      * @param string $path - the path to clean
  1261.      * @param string $full_path - true to prepend uploads path on return, false to return only the cleaned $path
  1262.      *
  1263.      * @return string - the clean path
  1264.      */
  1265.     public function CleanPath($path$full_path true)
  1266.     {
  1267.         global $config;
  1268.         $path trim(str_replace(array($config['uploads_path'],$config['uploads_url'])''$path),'/'.DIRECTORY_SEPARATOR);
  1269.         $path str_replace(DIRECTORY_SEPARATOR,'/',$path);
  1270.         $path trim(preg_replace('/(\/\.)|(\.\/)|(\/?\.\.\/?)/','/',$path),'./');
  1271.         if($full_path)
  1272.         {
  1273.             $path preg_replace('/[\\/]+/',DIRECTORY_SEPARATOR'/' $path '/');
  1274.             $path $config['uploads_path'$path;
  1275.             return $path;
  1276.         }
  1277.         return trim(preg_replace('/[\\/]+/',DIRECTORY_SEPARATOR$pathDIRECTORY_SEPARATOR);
  1278.     }
  1279.     
  1280.     
  1281.     /**
  1282.      * Replaces all multiple slashes, dots and (multiple) backslashes with one single slash to make a clean secure url parameter
  1283.      *
  1284.      * @since 1.0
  1285.      * @access public
  1286.      *
  1287.      * @param string $url - the url to clean
  1288.      * @param string $full_url - true to prepend uploads url on return, false to return only the cleaned $url
  1289.      *
  1290.      * @return string - the clean url
  1291.      */
  1292.     public function CleanURL($url$full_url true)
  1293.     {
  1294.         global $config;
  1295.         $url trim(str_replace(array($config['uploads_path'],$config['uploads_url'])''$url),'/'.DIRECTORY_SEPARATOR);
  1296.         $url str_replace(DIRECTORY_SEPARATOR,'/',$url);
  1297.         $url trim(preg_replace('/(\/\.)|(\.\/)|(\/?\.\.\/?)/','/',$url),'./');
  1298.         if($full_url)
  1299.         {
  1300.             $url preg_replace('/\/+/','/''/' str_replace('http://','',$url'/');
  1301.             $url $config['uploads_url'$url;
  1302.             return $url;
  1303.         }
  1304.         return trim(preg_replace('/\/+/','/',$url),'/');
  1305.     }
  1306.     
  1307.     
  1308.     /**
  1309.      * Returns the thumbnail of a given image file.
  1310.      *
  1311.      * @since 1.0
  1312.      * @access public
  1313.      *
  1314.      * @param string $path - the path of the file to create a thumbnail of (can be relative to the uploads dir or absolute)
  1315.      * @param string $create_thumb - set to false if thumbnail may not be created if not exists
  1316.      * @param string $urlonly - set to true to get only the url to the thumbnail
  1317.      *
  1318.      * @return string - HTML img element or url
  1319.      */
  1320.     public function GetThumbnail($path$create_thumb true$urlonly false)
  1321.     {
  1322.         if($path == '')
  1323.         {
  1324.             return false;
  1325.         }
  1326.         global $config;
  1327.         $filename basename($path);
  1328.         $path     $this->CleanPath(str_replace($filename,'',$path));
  1329.         $url      $this->CleanUrl(str_replace($filename,'',$path));
  1330.         $thumbnailcms_join_path($config['previews_path''GBFilePickerThumbs' 'thumb_' munge_string_to_url(str_replace($config['uploads_path']''$path)) '_' $filename);
  1331.         
  1332.         if((!file_exists($thumbnail|| filemtime($path $filenamefilemtime($thumbnail)) && $create_thumb)
  1333.         {
  1334.             $this->HandleFileResizing($path $filename$thumbnailget_site_preference('thumbnail_width'96)get_site_preference('thumbnail_height',96),true,false,60,false);
  1335.         }
  1336.         if(file_exists($thumbnail))
  1337.         {
  1338.             $thumbUrl $config['root_url''/' $this->CleanUrl(str_replace($config['root_path']''$thumbnail)false);
  1339.         }
  1340.         else
  1341.         {
  1342.             $thumbUrl $url $filename;
  1343.             $thumbnail_size $this->GetThumbnailSize($path $filename);
  1344.         }
  1345.         if($urlonly)
  1346.         {
  1347.             return $thumbUrl;
  1348.         }
  1349.         return '<img class="GBFP_thumbnail"' (isset($thumbnail_size&& is_array($thumbnail_size' width="'.$thumbnail_size[0].'" height="'.$thumbnail_size[1].'"' ''' id="' munge_string_to_url($filename'_GBFP_thumbnail" src="' $thumbUrl '" alt="' str_replace($config['uploads_url'],'',$url$filename '" title="' str_replace($config['uploads_url'],'',$url$filename '" />';
  1350.     }
  1351.     
  1352.     
  1353.     /**
  1354.      * Creates the thumbnail of a given image file.
  1355.      *
  1356.      * @since 1.2.9
  1357.      * @access public
  1358.      *
  1359.      * @param string $path - the path of the file to create a thumbnail from (can be relative to the uploads dir or absolute)
  1360.      *
  1361.      * @return string - absolute path of the thumbnail
  1362.      */
  1363.     public function CreateThumbnail($path)
  1364.     {
  1365.         if($path == '')
  1366.         {
  1367.             return;
  1368.         }
  1369.         global $config;
  1370.         $filename basename($path);
  1371.         $path     $this->CleanPath(str_replace($filename,'',$path));
  1372.         $thumbnailcms_join_path($config['previews_path''GBFilePickerThumbs' 'thumb_' munge_string_to_url(str_replace($config['uploads_path']''$path)) '_' $filename);
  1373.         
  1374.         if(!file_exists($thumbnail|| filemtime($path $filenamefilemtime($thumbnail))
  1375.         {
  1376.             if(!$this->HandleFileResizing($path $filename$thumbnailget_site_preference('thumbnail_width'96)get_site_preference('thumbnail_height',96),true,false,60,false))
  1377.             {
  1378.                 return;
  1379.             }
  1380.         }
  1381.         return $thumbnail;
  1382.     }
  1383.     
  1384.     
  1385.     /**
  1386.      * Gets the icon for a file.<br />
  1387.      * If FileManager is installed it uses FileManager icons.<br />
  1388.      * Otherwise it uses own icons.
  1389.      *
  1390.      * @since 1.0
  1391.      * @access public
  1392.      *
  1393.      * @param string $ext - the file extension
  1394.      * @param bool $is_dir 
  1395.      * @param bool $is_image 
  1396.      * @return string - the HTML ouput of an image
  1397.      */
  1398.     public function GetFileIcon($ext ''$is_dir false$is_image false)
  1399.     {
  1400.         global $config;
  1401.         if($fm =$this->GetModuleInstance('FileManager'))
  1402.         {
  1403.             return $fm->GetFileIcon($ext$is_dir);
  1404.         }
  1405.         if($is_dir)
  1406.         {
  1407.             return '<img class="GBFP_fileicon" src="'.$config['root_url'].'/modules/GBFilePicker/images/dir.gif" alt="" />';
  1408.         }
  1409.         if ($is_image)
  1410.         {
  1411.             return '<img class="GBFP_fileicon" src="'.$config['root_url'].'/modules/GBFilePicker/images/images.gif" alt="" />';
  1412.         }
  1413.         return '<img class="GBFP_fileicon" src="'.$config['root_url'].'/modules/GBFilePicker/images/fileicon.gif" alt="" />';
  1414.     }
  1415.     
  1416.     
  1417.     /**
  1418.      * Gets the icon for the file operation. <br />
  1419.      * If FileManager is installed it uses FileManager icons. <br />
  1420.      * Otherwise it uses own icons<br />
  1421.      *
  1422.      * @since 1.0
  1423.      * @access public
  1424.      *
  1425.      * @param string $action - the file operation (e.g. 'delete')
  1426.      * @return string - the HTML ouput of an image
  1427.      */
  1428.     public function GetActionIcon($action)
  1429.     {
  1430.         global $config;
  1431.         if($fm =$this->GetModuleInstance('FileManager'))
  1432.         {
  1433.             return $fm->GetActionIcon($action);
  1434.         }
  1435.         else
  1436.         {
  1437.             return '<img class="GBFP_actionicon" src="'.$config['root_url'].'/modules/GBFilePicker/images/'.$action.'.gif" title="'.$action.'" alt="'.$action.'" />';
  1438.         }
  1439.     }
  1440.     
  1441.     
  1442.     /**
  1443.      * Checks if a directory is empty<br />
  1444.      * Taken from TinyMCE Module (extracted from filepicker).
  1445.      * @since 1.0
  1446.      * @access public
  1447.      * @param string $dir - the path to a directory
  1448.      * @return boolean 
  1449.      */
  1450.     public function IsDirEmpty($dir)
  1451.     {
  1452.         $d dir($this->CleanPath($dir));
  1453.         while ($entry $d->read())
  1454.         {
  1455.             if ($entry == '.')
  1456.             {
  1457.                 continue;
  1458.             }
  1459.             if ($entry == '..')
  1460.             {
  1461.                 continue;
  1462.             }
  1463.             return false;
  1464.         }
  1465.         return true;
  1466.     }
  1467.     
  1468.     
  1469.     /**
  1470.      * Sorts the files by filename; shows directories first<br />
  1471.      * this function is meant to be called from the php usort() function: usort($array,array($this,'SortFiles')<br />
  1472.      * Taken from TinyMCE filepicker.
  1473.      * @since 1.0
  1474.      * @access public
  1475.      * @param object $file1 - one file to compare <br />a php stdClass with properties (boolean) $is_dir - a flag that specifys if it is a dir or a file;<br />(string) $basename - the basename of the file;
  1476.      * @param object $file2 - the other file to compare <br />a php stdClass with properties (boolean) $is_dir - a flag that specifys if it is a dir or a file;<br />(string) $basename - the basename of the file;
  1477.      * @return integer -1 or 1
  1478.      */
  1479.     public function SortFiles($file1$file2)
  1480.     {
  1481.         if ($file1->is_dir && !$file2->is_dirreturn -1;
  1482.         if (!$file1->is_dir && $file2->is_dirreturn 1;
  1483.         return strnatcasecmp($file1->basename$file2->basename);
  1484.     }
  1485.     
  1486.     
  1487.     /**
  1488.      * resizes images<br />
  1489.      * Adapted from TinyMCE filepicker.
  1490.      * @since 1.0
  1491.      * @access public
  1492.      *
  1493.      * @param string $source - the source path of the image
  1494.      * @param string $output - the destination path of the resized image
  1495.      * @param integer $new_width - the new wdth to scale the image to (if $keep_aspectratio is set to true this will be just some kind of max value)
  1496.      * @param integer $new_height - the new height to scale the image to (if $keep_aspectratio is set to true this will be just some kind of max value)
  1497.      * @param boolean $keep_aspectratio - set to false if image aspect ratio may be changed
  1498.      * @param boolean $allow_upscaling - set to true if user may enlarge the image
  1499.      * @param integer $quality - the quality of the new image (jpg only)
  1500.      * @param boolean $clean_path - set to false if source is the upload_tmp_dir
  1501.      *
  1502.      * @todo enable format change?
  1503.      */
  1504.     public function HandleFileResizing($source$output$new_width$new_height
  1505.         $keep_aspectratio true$allow_upscaling false$quality 100$clean_path true)
  1506.     {
  1507.         if(@ini_get("upload_tmp_dir"&& !startswith($source,@ini_get("upload_tmp_dir")) && $clean_path)
  1508.         {
  1509.             $source $this->CleanPath(str_replace(basename($source),'',$source)).basename($source);
  1510.         }
  1511.         if($clean_path)
  1512.         {
  1513.             $output $this->CleanPath(str_replace(basename($output),'',$output)).basename($output);
  1514.         }
  1515.         $img_data @getimagesize($source);
  1516.         
  1517.         if (!$img_data)
  1518.         {
  1519.             return false;
  1520.         }
  1521.         
  1522.         $orig_image '';
  1523.         switch($img_data['mime'])
  1524.         {
  1525.             case 'image/jpeg':
  1526.                 $orig_image @imagecreatefromjpeg($source);
  1527.                 break;
  1528.             case 'image/gif' :
  1529.                 $orig_image @imagecreatefromgif($source);
  1530.                 break;
  1531.             case 'image/png' :
  1532.                 $orig_image @imagecreatefrompng($source);
  1533.                 break;
  1534.             default:
  1535.                 return false;
  1536.         }
  1537.         $orig_width   @imagesx($orig_image);
  1538.         $orig_height  @imagesy($orig_image);
  1539.         $aspectratio $orig_width $orig_height;
  1540.         
  1541.         $new_width  floor($new_width);
  1542.         $new_height floor($new_height);
  1543.         
  1544.         if($new_width <= && $new_height 0// force height
  1545.             $new_width $orig_width;
  1546.             if($new_height $orig_height && !$allow_upscaling)
  1547.             {
  1548.                 $new_height $orig_height;
  1549.             }
  1550.             if($keep_aspectratio)
  1551.             {
  1552.                 $new_width floor($new_height $aspectratio);
  1553.             }
  1554.         }
  1555.         else if($new_height <= && $new_width 0// force width
  1556.             $new_height $orig_height;
  1557.             if($new_width $orig_width && !$allow_upscaling)
  1558.             {
  1559.                 $new_width $orig_width;
  1560.             }
  1561.             if($keep_aspectratio)
  1562.             {
  1563.                 $new_height floor($new_width $aspectratio);
  1564.             }
  1565.         }
  1566.         else if($new_height && $new_width 0// both
  1567.             if($new_width $orig_width && !$allow_upscaling)
  1568.             {
  1569.                 $new_width $orig_width;
  1570.             }
  1571.             if($new_height $orig_height && !$allow_upscaling)
  1572.             {
  1573.                 $new_height $orig_height;
  1574.             }
  1575.             $new_aspectratio $new_width $new_height;
  1576.             if($keep_aspectratio)
  1577.             {
  1578.                 if($aspectratio && $new_aspectratio 1)
  1579.                 // landscape to portrait
  1580.                     $_tmp floor($new_width $aspectratio);
  1581.                     if($_tmp && $_tmp <= $new_height)
  1582.                     {
  1583.                         $new_height $_tmp;
  1584.                     }
  1585.                 }
  1586.                 else if($aspectratio && $new_aspectratio 1)
  1587.                 // portrait to landscape
  1588.                     $_tmp floor($new_height $aspectratio);
  1589.                     if($_tmp && $_tmp <= $new_width)
  1590.                     {
  1591.                         $new_width $_tmp;
  1592.                     }
  1593.                 }
  1594.                 else
  1595.                 {
  1596.                     if($new_aspectratio $aspectratio)
  1597.                     {
  1598.                         $_tmp floor($new_width $aspectratio);
  1599.                         if($_tmp && $_tmp <= $new_height)
  1600.                         {
  1601.                             $new_height $_tmp;
  1602.                         }
  1603.                     }
  1604.                     else if($new_aspectratio $aspectratio)
  1605.                     {
  1606.                         $_tmp floor($new_height $aspectratio);
  1607.                         if($_tmp && $_tmp <= $new_width)
  1608.                         {
  1609.                             $new_width $_tmp;
  1610.                         }
  1611.                     }
  1612.                 }
  1613.             }
  1614.         }
  1615.         else
  1616.         {
  1617.             $new_height $orig_height;
  1618.             $new_width  $orig_width;
  1619.         }
  1620.         
  1621.         if($new_width 1)
  1622.         {
  1623.             $new_width 1;
  1624.         }
  1625.         if($new_height 1)
  1626.         {
  1627.             $new_height 1;
  1628.         }
  1629.         
  1630.         $new_image @imagecreatetruecolor(floor($new_width)floor($new_height));
  1631.         
  1632.         // handle transparency (adapted from supersizer plugin)
  1633.         if($img_data['mime'== 'image/gif')
  1634.         {
  1635.             imagetruecolortopalette($new_imagetrue256);
  1636.             imagealphablending($new_imagefalse);
  1637.             imagesavealpha($new_image,true);
  1638.             $transparent imagecolorallocatealpha($new_image255255255127);
  1639.             imagefilledrectangle($new_image00$new_width$new_height$transparent);
  1640.             imagecolortransparent($new_image$transparent);
  1641.         }
  1642.         else if ($img_data['mime'== 'image/png')
  1643.         {
  1644.             imagecolortransparent($new_imageimagecolorallocate($new_image000));   
  1645.             imagealphablending($new_imagefalse);
  1646.             $color imagecolorallocatealpha($new_image000127);
  1647.             imagefill($new_image00$color);
  1648.             imagesavealpha($new_imagetrue);
  1649.         }
  1650.         
  1651.         @imagecopyresampled($new_image$orig_image0000$new_width$new_height$orig_width$orig_height);
  1652.         switch($img_data['mime'])
  1653.         {
  1654.             case 'image/jpeg'return @imagejpeg($new_image$output$quality);
  1655.             case 'image/gif' return @imagegif($new_image$output);
  1656.             case 'image/png' return @imagepng($new_image$output);
  1657.             default          return false;
  1658.         }
  1659.         
  1660.         /*
  1661.         $format = 'unchanged';
  1662.         if ($format=='unchanged')
  1663.         {
  1664.             switch($img_data['mime'])
  1665.             {
  1666.                 case 'image/jpeg': return @imagejpeg($newImage, $output, $quality);
  1667.                 case 'image/gif' : return @imagegif($newImage, $output);
  1668.                 case 'image/png' : return @imagepng($newImage, $output);
  1669.                 default          : return false;
  1670.             }
  1671.         } else
  1672.         {
  1673.             switch ($format)
  1674.             {
  1675.                 case 'jpg': return @imagejpeg($newImage, $output, $quality);
  1676.                 case 'gif': return @imagegif($newImage, $output);
  1677.                 case 'png': return @imagepng($newImage, $output);
  1678.                 default   : return;
  1679.             }
  1680.         }
  1681.         */
  1682.     }
  1683.     
  1684.     
  1685.     /**
  1686.      * returns the calculated size of the thumbnail<br />
  1687.      *
  1688.      * @since 1.2
  1689.      * @access public
  1690.      *
  1691.      * @param string $path - the source path of the image
  1692.      * @return array - array(width,height)
  1693.      */
  1694.     public function GetThumbnailSize($path)
  1695.     {
  1696.         $path $this->CleanPath(str_replace(basename($path),'',$path)).basename($path);
  1697.         $img_data @getimagesize($path);
  1698.         
  1699.         if (!$img_data)
  1700.         {
  1701.             return false;
  1702.         }
  1703.         
  1704.         $orig_width  $img_data[0];
  1705.         $orig_height $img_data[1];
  1706.         $aspectratio $orig_width $orig_height;
  1707.         
  1708.         $new_width  floor(get_site_preference('thumbnail_width'96));
  1709.         $new_height floor(get_site_preference('thumbnail_height'96));
  1710.         
  1711.         if($new_width <= 0)
  1712.         {
  1713.             $new_width 96;
  1714.         }
  1715.         
  1716.         if($new_height <= 0)
  1717.         {
  1718.             $new_height 96;
  1719.         }
  1720.         
  1721.         if($new_width $orig_width)
  1722.         {
  1723.             $new_width $orig_width;
  1724.         }
  1725.         if($new_height $orig_height)
  1726.         {
  1727.             $new_height $orig_height;
  1728.         }
  1729.         $new_aspectratio $new_width $new_height;
  1730.         
  1731.         if($aspectratio && $new_aspectratio 1)
  1732.         // landscape to portrait
  1733.             $_tmp floor($new_width $aspectratio);
  1734.             if($_tmp && $_tmp <= $new_height)
  1735.             {
  1736.                 $new_height $_tmp;
  1737.             }
  1738.         }
  1739.         else if($aspectratio && $new_aspectratio 1)
  1740.         // portrait to landscape
  1741.             $_tmp floor($new_height $aspectratio);
  1742.             if($_tmp && $_tmp <= $new_width)
  1743.             {
  1744.                 $new_width $_tmp;
  1745.             }
  1746.         }
  1747.         else
  1748.         {
  1749.             if($new_aspectratio $aspectratio)
  1750.             {
  1751.                 $_tmp floor($new_width $aspectratio);
  1752.                 if($_tmp && $_tmp <= $new_height)
  1753.                 {
  1754.                     $new_height $_tmp;
  1755.                 }
  1756.             }
  1757.             else if($new_aspectratio $aspectratio)
  1758.             {
  1759.                 $_tmp floor($new_height $aspectratio);
  1760.                 if($_tmp && $_tmp <= $new_width)
  1761.                 {
  1762.                     $new_width $_tmp;
  1763.                 }
  1764.             }
  1765.         }
  1766.         
  1767.         if($new_width 1)
  1768.         {
  1769.             $new_width 1;
  1770.         }
  1771.         if($new_height 1)
  1772.         {
  1773.             $new_height 1;
  1774.         }
  1775.         return array($new_width$new_height);
  1776.     }
  1777.     
  1778.     
  1779.     /**
  1780.      * Checks if a filename contains illegal chars<br />
  1781.      * Taken from TinyMCE Module.
  1782.      * @since 1.0
  1783.      * @access public
  1784.      * @param string $filename - the filename to check
  1785.      * @return boolean 
  1786.      */
  1787.     public function ContainsIllegalChars($filename)
  1788.     {
  1789.         if (strpos($filename'\''!== falsereturn true;
  1790.         if (strpos($filename'"' !== falsereturn true;
  1791.         if (strpos($filename'/' !== falsereturn true;
  1792.         if (strpos($filename'\\'!== falsereturn true;
  1793.         if (strpos($filename'&' !== falsereturn true;
  1794.         if (strpos($filename'\$'!== falsereturn true;
  1795.         if (strpos($filename'+' !== falsereturn true;
  1796.         return false;
  1797.     }
  1798.     
  1799.     
  1800.     /**
  1801.      * Checks if a var is empty. <br />
  1802.      * If $var is an array it recursivley checks all elements.
  1803.      *
  1804.      * @since 1.0
  1805.      * @access public
  1806.      *
  1807.      * @param mixed &$var - the var to check for empty value(s)
  1808.      * @param boolean $trim - true to trim off spaces
  1809.      * @param boolean $unset_empty_indexes - true to delete empty elements from array
  1810.      * @return boolean - true if empty, false if not
  1811.      */
  1812.     public function IsVarEmpty(&$var$trim true$unset_empty_indexes false)
  1813.     {
  1814.         if (is_array($var))
  1815.         {
  1816.             foreach ($var as $k=>$v)
  1817.             {
  1818.                 if (!$this->IsVarEmpty($v))
  1819.                 {
  1820.                     return false;
  1821.                 }
  1822.                 
  1823.                 if($unset_empty_indexes)
  1824.                 {
  1825.                     unset($var[$k]);
  1826.                 }
  1827.                 return true;
  1828.             }
  1829.         }
  1830.         else if($trim && trim($var== '')
  1831.         {
  1832.             return true;
  1833.         }
  1834.         else if($var == '')
  1835.         {
  1836.             return true;
  1837.         }
  1838.         return false;
  1839.     }
  1840.     
  1841.     
  1842.     /**
  1843.      * Removes empty elements from an array. <br />
  1844.      * (can be useful when using function explode to create the array from a csv)
  1845.      *
  1846.      * @since 1.0
  1847.      * @access public
  1848.      *
  1849.      * @param array $array - the array to clean up
  1850.      * @return array - an array without empty elements or an empty array
  1851.      */
  1852.     public function CleanArray($array)
  1853.     {
  1854.         if (is_array($array))
  1855.         {
  1856.             foreach ($array as $k=>$v)
  1857.             {
  1858.                 if ($this->IsVarEmpty($v,true,true))
  1859.                 {
  1860.                     unset($array[$k]);
  1861.                 }
  1862.                 else
  1863.                 {
  1864.                     if(is_array($v))
  1865.                     {
  1866.                         $v $this->CleanArray($v);
  1867.                         if($this->IsVarEmpty($v,true,true))
  1868.                         {
  1869.                             unset($array[$k]);
  1870.                         }
  1871.                         else
  1872.                         {
  1873.                             $array[$k$v;
  1874.                         }
  1875.                     }
  1876.                 }
  1877.             }
  1878.             return $array;
  1879.         }
  1880.         return array();
  1881.     }
  1882.     
  1883.     
  1884.     /**
  1885.      * Checks if a value is really meant to be "true". <br />
  1886.      * Can be usefull when checking smarty params for the value true
  1887.      *
  1888.      * @since 1.0
  1889.      * @access public
  1890.      *
  1891.      * @param mixed $value - the value to check
  1892.      * @return bool 
  1893.      */
  1894.     public function IsTrue($value)
  1895.     {
  1896.         return (strtolower($value=== 'true' || $value === || $value === '1' || $value === true);
  1897.     }
  1898.     
  1899.     
  1900.     /**
  1901.      * Checks if a value is really meant to be "false". <br />
  1902.      * Can be usefull when checking smarty params for the value false
  1903.      *
  1904.      * @since 1.0
  1905.      * @access public
  1906.      *
  1907.      * @param mixed $value - the value to check
  1908.      * @return bool 
  1909.      */
  1910.     public function IsFalse($value)
  1911.     {
  1912.         return (strtolower($value=== 'false' || $value === '0' || $value === || $value === false || $value === '');
  1913.     }
  1914.     
  1915.     
  1916.     /**
  1917.      * Indicates if GBFilePicker output is already done<br />
  1918.      * can be useful to avoid ouput of javascript and css twice
  1919.      *
  1920.      * @since 1.1
  1921.      * @access public
  1922.      *
  1923.      * @return bool - true if output done; false if not
  1924.      */
  1925.     public function Loaded()
  1926.     {
  1927.         return $this->_loaded;
  1928.     }
  1929.     
  1930.     
  1931.     /**
  1932.      * Processes given value using smarty
  1933.      * @since 1.2.9
  1934.      * @access public
  1935.      *
  1936.      * @param string $tpl - the value to process by smarty
  1937.      * @return string - the processed value
  1938.      * @ignore
  1939.      */
  1940.     public function DoSmarty($tpl)
  1941.     {
  1942.         if(!is_array($tpl&& !is_object($tpl&& preg_match_all('/:::([^:]+):::/'$tpl$matches))
  1943.         {
  1944.             if(isset($_GET['content_id']))
  1945.             {
  1946.                 $manager =cmsms()->GetHierarchyManager();
  1947.                 $node $manager->sureGetNodeByAlias($_GET['content_id']);
  1948.             }
  1949.             if(isset($node&& is_object($node))
  1950.             {
  1951.                 $content =$node->GetContent();
  1952.             }
  1953.             if(isset($content&& is_object($content&& $content->Type(!= 'content2')
  1954.             {
  1955.                 if(version_compare(CMS_VERSION'1.9'&& !isset(cmsms()->variables['pageinfo']->content_id))
  1956.                 {
  1957.                     // fake frontend rendering
  1958.                     cmsms()->variables['pageinfo']                              new stdClass();
  1959.                     cmsms()->variables['pageinfo']->content_id                  $content->mId;
  1960.                     cmsms()->variables['pageinfo']->content_title               $content->mName;
  1961.                     cmsms()->variables['pageinfo']->content_alias               $content->mAlias;
  1962.                     cmsms()->variables['pageinfo']->content_menutext            $content->mMenuText;
  1963.                     cmsms()->variables['pageinfo']->content_titleattribute      $content->mTitleAttribute;
  1964.                     cmsms()->variables['pageinfo']->content_hierarchy           $content->mHierarchy;
  1965.                     cmsms()->variables['pageinfo']->content_id_hierarchy        $content->mIdHierarchy;
  1966.                     cmsms()->variables['pageinfo']->content_type                $content->mType;
  1967.                     cmsms()->variables['pageinfo']->content_props               $content->mProperties->mPropertyNames;
  1968.                     cmsms()->variables['pageinfo']->content_metadata            $content->mMetadata;
  1969.                     cmsms()->variables['pageinfo']->content_modified_date       $content->mModifiedDate;
  1970.                     cmsms()->variables['pageinfo']->content_created_date        $content->mCreationDate;
  1971.                     cmsms()->variables['pageinfo']->content_last_modified_date  $content->mModifiedDate;
  1972.                     cmsms()->variables['pageinfo']->content_last_modified_by_id $content->mOwner;
  1973.                     cmsms()->variables['pageinfo']->template_id                 $content->mTemplateId;
  1974.                     cmsms()->variables['pageinfo']->template_encoding           get_encoding('');
  1975.                     cmsms()->variables['pageinfo']->template_modified_date      time()// ???
  1976.                     cmsms()->variables['pageinfo']->cachable                    $content->mCachable;
  1977.                     cmsms()->variables['pageinfo']->content_hierarchy_path      $content->mHierarchyPath;
  1978.                     
  1979.                     cmsms()->variables['content_id']                            $content->mId;
  1980.                     cmsms()->variables['page']                                  $content->mAlias;
  1981.                     cmsms()->variables['page_id']                               $content->mAlias;
  1982.                     cmsms()->variables['page_alias']                            $content->mAlias;
  1983.                     cmsms()->variables['content_alias']                         $content->mAlias;
  1984.                     cmsms()->variables['page_name']                             $content->mAlias;
  1985.                     cmsms()->variables['position']                              $content->mHierarchy;
  1986.                     cmsms()->variables['friendly_position']                     cmsms()->GetContentOperations()->CreateFriendlyHierarchyPosition($content->mHierarchy);
  1987.                 }
  1988.                 
  1989.                 $this->smarty->assign_by_ref('content_obj'$content);
  1990.                 $this->smarty->assign('content_id'$content->Id());
  1991.                 $this->smarty->assign('content_alias'$content->Alias());
  1992.                 $this->smarty->assign('page'$content->Alias());
  1993.                 $this->smarty->assign('page_id'$content->Alias());
  1994.                 $this->smarty->assign('page_alias'$content->Alias());
  1995.                 $this->smarty->assign('page_name'$content->Alias());
  1996.                 $this->smarty->assign('position'$content->Hierarchy());
  1997.                 $this->smarty->assign('friendly_position'cmsms()->GetContentOperations()->CreateFriendlyHierarchyPosition($content->Hierarchy()));
  1998.             }
  1999.             $tpl $this->ProcessTemplateFromData(preg_replace('/:::([^:]+):::/''{$1}'$tpl));
  2000.         }
  2001.         return $tpl;
  2002.     }
  2003.     
  2004.     
  2005.     /**
  2006.      * Returns a list of available themes
  2007.      * @since 1.2.9
  2008.      * @access public
  2009.      * @return array - the themes
  2010.      */
  2011.     public function GetThemesList()
  2012.     {
  2013.         $dir cms_join_path(dirname(__FILE__)'templates''themes'DIRECTORY_SEPARATOR;
  2014.         $d   dir($dir);
  2015.         $default_themes array();
  2016.         while ($entry $d->read())
  2017.         {
  2018.             if ($entry[0== '.' 
  2019.                 || !is_dir($dir.$entry)
  2020.                 || !file_exists(cms_join_path($dir.$entry,'input.tpl'))
  2021.                 || !file_exists(cms_join_path($dir.$entry,'fileBrowser.tpl'))
  2022.                 || !file_exists(cms_join_path($dir.$entry,'header.tpl')))
  2023.             {
  2024.                 continue;
  2025.             }
  2026.             $default_themes[$entry$entry;
  2027.         }
  2028.         $d->close();
  2029.         
  2030.         //global $config;
  2031.         //$dir = cms_join_path($config['root_path'],'module_custom','GBFilePicker','templates','themes') . DIRECTORY_SEPARATOR;
  2032.         //$custom_themes = array();
  2033.         //if(file_exists($dir) && is_dir($dir))
  2034.         //{
  2035.         //    $d = dir($dir);
  2036.         //    while ($entry = $d->read())
  2037.         //    {
  2038.         //        if ($entry[0] == '.' 
  2039.         //            || !is_dir($dir.$entry)
  2040.         //            || !file_exists(cms_join_path($dir.$entry,'input.tpl'))
  2041.         //            || !file_exists(cms_join_path($dir.$entry,'fileBrowser.tpl'))
  2042.         //            || !file_exists(cms_join_path($dir.$entry,'header.tpl')))
  2043.         //        {
  2044.         //            continue;
  2045.         //        }
  2046.         //        $custom_themes[$entry] = $entry;
  2047.         //    }
  2048.         //    $d->close();
  2049.         //}
  2050.         //$themes = $this->CleanArray(array_merge($default_themes,$custom_themes));
  2051.         //asort($themes);
  2052.         asort($default_themes);
  2053.         //return $themes;
  2054.         return $default_themes;
  2055.     }
  2056. }
  2057. ?>

Documentation generated on Wed, 23 Feb 2011 21:38:09 +0100 by phpDocumentor 1.4.0a2