linea21-externals
[ class tree: linea21-externals ] [ index: linea21-externals ] [ all elements ]

Source for file filemanager.class.php

Documentation is available at filemanager.class.php

  1. <?php
  2. /**
  3.  *    Filemanager PHP class
  4.  *
  5.  *    filemanager.class.php
  6.  *    class for the filemanager.php connector
  7.  *
  8.  *    @license    MIT License
  9.  *    @author        Riaan Los <mail (at) riaanlos (dot) nl>
  10.  *    @author        Simon Georget <simon (at) linea21 (dot) com>
  11.  *    @copyright    Authors
  12.  *  @package        linea21.externals
  13.  *  @subpackage Filemanager
  14.  */
  15.  
  16. class Filemanager {
  17.  
  18.     protected $config = array();
  19.     protected $language = array();
  20.     protected $get = array();
  21.     protected $post = array();
  22.     protected $properties = array();
  23.     protected $item = array();
  24.     protected $languages = array();
  25.     protected $root = '';
  26.     protected $doc_root = '';
  27.     protected $logger = false;
  28.     protected $logfile = '/tmp/filemanager.log';
  29.  
  30.     public function __construct($config ''{
  31.             
  32.         $content file_get_contents("../../scripts/filemanager.config.js");
  33.         $config json_decode($contenttrue);
  34.             
  35.         $this->config = $config;
  36.  
  37.         // override config options if needed
  38.         if(!empty($config)) {
  39.             $this->setup($config);
  40.         }
  41.  
  42.         $this->root = dirname(dirname(dirname(__FILE__))).DIRECTORY_SEPARATOR;
  43.         $this->properties = array(
  44.                 'Date Created'=>null,
  45.                 'Date Modified'=>null,
  46.                 'Height'=>null,
  47.                 'Width'=>null,
  48.                 'Size'=>null
  49.         );
  50.  
  51.         // Log actions or not?
  52.         if ($this->config['options']['logger'== true {
  53.             $this->enableLog();
  54.             if(isset($this->config['options']['logfile'])) {
  55.                 $this->logfile = $this->config['options']['logfile'];
  56.             }
  57.         }
  58.  
  59.         // if fileRoot is set manually, $this->doc_root takes fileRoot value
  60.         // for security check in isValidPath() method
  61.         // else it takes $_SERVER['DOCUMENT_ROOT'] default value
  62.         if ($this->config['options']['fileRoot'!== false {
  63.             if($this->config['options']['serverRoot'=== true{
  64.                 $this->doc_root = $_SERVER['DOCUMENT_ROOT'];
  65.             else {
  66.                 $this->doc_root = $this->config['options']['fileRoot'];
  67.             }
  68.         else {
  69.             $this->doc_root = $_SERVER['DOCUMENT_ROOT'];
  70.         }
  71.  
  72.         $this->__log(__METHOD__ . ' $this->doc_root value ' $this->doc_root);
  73.  
  74.         $this->setParams();
  75.         $this->availableLanguages();
  76.         $this->loadLanguageFile();
  77.     }
  78.  
  79.     // $extraconfig should be formatted as json config array.
  80.     public function setup($extraconfig{
  81.  
  82.         $this->config = array_merge($this->config$extraconfig);
  83.             
  84.     }
  85.  
  86.     // allow Filemanager to be used with dynamic folders
  87.     public function setFileRoot($path{
  88.  
  89.         if($this->config['options']['serverRoot'=== true{
  90.             $this->doc_root = $_SERVER['DOCUMENT_ROOT']'/'.  $path;
  91.         else {
  92.             $this->doc_root =  $path;;
  93.         }
  94.  
  95.     }
  96.  
  97.     public function error($string,$textarea=false{
  98.         $array array(
  99.                 'Error'=>$string,
  100.                 'Code'=>'-1',
  101.                 'Properties'=>$this->properties
  102.         );
  103.  
  104.         $this->__log__METHOD__ . ' - error message : ' $string);
  105.  
  106.         if($textarea{
  107.             echo '<textarea>' json_encode($array'</textarea>';
  108.         else {
  109.             echo json_encode($array);
  110.         }
  111.         die();
  112.     }
  113.  
  114.     public function lang($string{
  115.         if(isset($this->language[$string]&& $this->language[$string]!=''{
  116.             return $this->language[$string];
  117.         else {
  118.             return 'Language string error on ' $string;
  119.         }
  120.     }
  121.  
  122.     public function getvar($var{
  123.         if(!isset($_GET[$var]|| $_GET[$var]==''{
  124.             $this->error(sprintf($this->lang('INVALID_VAR'),$var));
  125.         else {
  126.             $this->get[$var$this->sanitize($_GET[$var]);
  127.             return true;
  128.         }
  129.     }
  130.     public function postvar($var{
  131.         if(!isset($_POST[$var]|| $_POST[$var]==''{
  132.             $this->error(sprintf($this->lang('INVALID_VAR'),$var));
  133.         else {
  134.             $this->post[$var$_POST[$var];
  135.             return true;
  136.         }
  137.     }
  138.  
  139.     public function getinfo({
  140.         $this->item = array();
  141.         $this->item['properties'$this->properties;
  142.         $this->get_file_info();
  143.  
  144.         $array array(
  145.                 'Path'=> $this->get['path'],
  146.                 'Filename'=>$this->item['filename'],
  147.                 'File Type'=>$this->item['filetype'],
  148.                 'Preview'=>$this->item['preview'],
  149.                 'Properties'=>$this->item['properties'],
  150.                 'Error'=>"",
  151.                 'Code'=>0
  152.         );
  153.         return $array;
  154.     }
  155.  
  156.     public function getfolder({
  157.         $array array();
  158.         $filesDir array();
  159.  
  160.         $current_path $this->getFullPath();
  161.  
  162.  
  163.         if(!$this->isValidPath($current_path)) {
  164.             $this->error("No way.");
  165.         }
  166.  
  167.         if(!is_dir($current_path)) {
  168.             $this->error(sprintf($this->lang('DIRECTORY_NOT_EXIST'),$this->get['path']));
  169.         }
  170.         if(!$handle opendir($current_path)) {
  171.             $this->error(sprintf($this->lang('UNABLE_TO_OPEN_DIRECTORY'),$this->get['path']));
  172.         else {
  173.             while (false !== ($file readdir($handle))) {
  174.                 if($file != "." && $file != ".."{
  175.                     array_push($filesDir$file);
  176.                 }
  177.             }
  178.             closedir($handle);
  179.  
  180.             natcasesort($filesDir)// sorting by names
  181.  
  182.             // Sort files by modified time, latest to earliest
  183.             // Use SORT_ASC in place of SORT_DESC for earliest to latest
  184.             //      array_multisort(
  185.             //        array_map( 'filemtime', $filesDir ),
  186.             //        SORT_NUMERIC,
  187.             //        SORT_DESC,
  188.             //        $filesDir
  189.             //      );
  190.  
  191.             foreach($filesDir as $file{
  192.  
  193.                 if(is_dir($current_path $file)) {
  194.                     if(!in_array($file$this->config['exclude']['unallowed_dirs']&& !preg_match$this->config['exclude']['unallowed_dirs_REGEXP']$file)) {
  195.                         $array[$this->get['path'$file .'/'array(
  196.                                 'Path'=> $this->get['path'$file .'/',
  197.                                 'Filename'=>$file,
  198.                                 'File Type'=>'dir',
  199.                                 'Preview'=> $this->config['icons']['path'$this->config['icons']['directory'],
  200.                                 'Properties'=>array(
  201.                                         'Date Created'=>null,
  202.                                         'Date Modified'=>null,
  203.                                         'Height'=>null,
  204.                                         'Width'=>null,
  205.                                         'Size'=>null
  206.                                 ),
  207.                                 'Error'=>"",
  208.                                 'Code'=>0
  209.                         );
  210.                     }
  211.                 else if (!in_array($file$this->config['exclude']['unallowed_files'])  && !preg_match$this->config['exclude']['unallowed_files_REGEXP']$file)) {
  212.                     $this->item = array();
  213.                     $this->item['properties'$this->properties;
  214.                     $this->get_file_info($this->get['path'$file);
  215.  
  216.                     if(!isset($this->params['type']|| (isset($this->params['type']&& strtolower($this->params['type'])=='images' && in_array(strtolower($this->item['filetype']),$this->config['images']['imagesExt']))) {
  217.                         if($this->config['upload']['imagesOnly']== false || ($this->config['upload']['imagesOnly']== true && in_array(strtolower($this->item['filetype']),$this->config['images']['imagesExt']))) {
  218.                             $array[$this->get['path'$filearray(
  219.                                     'Path'=>$this->get['path'$file,
  220.                                     'Filename'=>$this->item['filename'],
  221.                                     'File Type'=>$this->item['filetype'],
  222.                                     'Preview'=>$this->item['preview'],
  223.                                     'Properties'=>$this->item['properties'],
  224.                                     'Error'=>"",
  225.                                     'Code'=>0
  226.                             );
  227.                         }
  228.                     }
  229.                 }
  230.             }
  231.         }
  232.  
  233.         return $array;
  234.     }
  235.  
  236.     public function rename({
  237.  
  238.         $suffix='';
  239.  
  240.  
  241.         if(substr($this->get['old'],-1,1)=='/'{
  242.             $this->get['old'substr($this->get['old'],0,(strlen($this->get['old'])-1));
  243.             $suffix='/';
  244.         }
  245.         $tmp explode('/',$this->get['old']);
  246.         $filename $tmp[(sizeof($tmp)-1)];
  247.         $path str_replace('/' $filename,'',$this->get['old']);
  248.  
  249.         $new_file $this->getFullPath($path '/' $this->get['new'])$suffix;
  250.         $old_file $this->getFullPath($this->get['old']$suffix;
  251.  
  252.         if(!$this->isValidPath($old_file)) {
  253.             $this->error("No way.");
  254.         }
  255.  
  256.         $this->__log(__METHOD__ . ' - renaming '$old_file' to ' $new_file);
  257.  
  258.         if(file_exists ($new_file)) {
  259.             if($suffix=='/' && is_dir($new_file)) {
  260.                 $this->error(sprintf($this->lang('DIRECTORY_ALREADY_EXISTS'),$this->get['new']));
  261.             }
  262.             if($suffix=='' && is_file($new_file)) {
  263.                 $this->error(sprintf($this->lang('FILE_ALREADY_EXISTS'),$this->get['new']));
  264.             }
  265.         }
  266.  
  267.         if(!rename($old_file,$new_file)) {
  268.             if(is_dir($old_file)) {
  269.                 $this->error(sprintf($this->lang('ERROR_RENAMING_DIRECTORY'),$filename,$this->get['new']));
  270.             else {
  271.                 $this->error(sprintf($this->lang('ERROR_RENAMING_FILE'),$filename,$this->get['new']));
  272.             }
  273.         }
  274.         $array array(
  275.                 'Error'=>"",
  276.                 'Code'=>0,
  277.                 'Old Path'=>$this->get['old'],
  278.                 'Old Name'=>$filename,
  279.                 'New Path'=>$path '/' $this->get['new'].$suffix,
  280.                 'New Name'=>$this->get['new']
  281.         );
  282.         return $array;
  283.     }
  284.  
  285.     public function delete({
  286.  
  287.         $current_path $this->getFullPath();
  288.             
  289.         if(!$this->isValidPath($current_path)) {
  290.             $this->error("No way.");
  291.         }
  292.             
  293.         if(is_dir($current_path)) {
  294.             $this->unlinkRecursive($current_path);
  295.             $array array(
  296.                     'Error'=>"",
  297.                     'Code'=>0,
  298.                     'Path'=>$this->get['path']
  299.             );
  300.  
  301.             $this->__log(__METHOD__ . ' - deleting folder '$current_path);
  302.             return $array;
  303.  
  304.         else if(file_exists($current_path)) {
  305.             unlink($current_path);
  306.             $array array(
  307.                     'Error'=>"",
  308.                     'Code'=>0,
  309.                     'Path'=>$this->get['path']
  310.             );
  311.  
  312.             $this->__log(__METHOD__ . ' - deleting file '$current_path);
  313.             return $array;
  314.  
  315.         else {
  316.             $this->error(sprintf($this->lang('INVALID_DIRECTORY_OR_FILE')));
  317.         }
  318.     }
  319.  
  320.     public function add({
  321.             
  322.         $this->setParams();
  323.  
  324.         if(!isset($_FILES['newfile']|| !is_uploaded_file($_FILES['newfile']['tmp_name'])) {
  325.             $this->error(sprintf($this->lang('INVALID_FILE_UPLOAD')),true);
  326.         }
  327.         // we determine max upload size if not set
  328.         if($this->config['upload']['fileSizeLimit'== 'auto'{
  329.             $this->config['upload']['fileSizeLimit'$this->getMaxUploadFileSize();
  330.         }
  331.         if($_FILES['newfile']['size'($this->config['upload']['fileSizeLimit'1024 1024)) {
  332.             $this->error(sprintf($this->lang('UPLOAD_FILES_SMALLER_THAN'),$this->config['upload']['size''Mb'),true);
  333.         }
  334.         if($this->config['upload']['imagesOnly'|| (isset($this->params['type']&& strtolower($this->params['type'])=='images')) {
  335.             if(!($size @getimagesize($_FILES['newfile']['tmp_name']))){
  336.                 $this->error(sprintf($this->lang('UPLOAD_IMAGES_ONLY')),true);
  337.             }
  338.             if(!in_array($size[2]array(12378))) {
  339.                 $this->error(sprintf($this->lang('UPLOAD_IMAGES_TYPE_JPEG_GIF_PNG')),true);
  340.             }
  341.         }
  342.         $_FILES['newfile']['name'$this->cleanString($_FILES['newfile']['name'],array('.','-'));
  343.  
  344.         $current_path $this->getFullPath($this->post['currentpath']);
  345.  
  346.         if(!$this->isValidPath($current_path)) {
  347.             $this->error("No way.");
  348.         }
  349.  
  350.         if(!$this->config['upload']['overwrite']{
  351.             $_FILES['newfile']['name'$this->checkFilename($current_path,$_FILES['newfile']['name']);
  352.         }
  353.         move_uploaded_file($_FILES['newfile']['tmp_name']$current_path $_FILES['newfile']['name']);
  354.         chmod($current_path $_FILES['newfile']['name']0644);
  355.  
  356.         $response array(
  357.                 'Path'=>$this->post['currentpath'],
  358.                 'Name'=>$_FILES['newfile']['name'],
  359.                 'Error'=>"",
  360.                 'Code'=>0
  361.         );
  362.  
  363.         $this->__log(__METHOD__ . ' - adding file '$_FILES['newfile']['name']' into '$current_path);
  364.  
  365.         echo '<textarea>' json_encode($response'</textarea>';
  366.         die();
  367.     }
  368.  
  369.     public function addfolder({
  370.             
  371.         $current_path $this->getFullPath();
  372.             
  373.         if(!$this->isValidPath($current_path)) {
  374.             $this->error("No way.");
  375.         }
  376.         if(is_dir($current_path $this->get['name'])) {
  377.             $this->error(sprintf($this->lang('DIRECTORY_ALREADY_EXISTS'),$this->get['name']));
  378.  
  379.         }
  380.         $newdir $this->cleanString($this->get['name']);
  381.         if(!mkdir($current_path $newdir,0755)) {
  382.             $this->error(sprintf($this->lang('UNABLE_TO_CREATE_DIRECTORY'),$newdir));
  383.         }
  384.         $array array(
  385.                 'Parent'=>$this->get['path'],
  386.                 'Name'=>$this->get['name'],
  387.                 'Error'=>"",
  388.                 'Code'=>0
  389.         );
  390.         $this->__log(__METHOD__ . ' - adding folder '$current_path $newdir);
  391.  
  392.         return $array;
  393.     }
  394.  
  395.     public function download({
  396.             
  397.         $current_path $this->getFullPath();
  398.             
  399.         if(!$this->isValidPath($current_path)) {
  400.             $this->error("No way.");
  401.         }
  402.  
  403.         if(isset($this->get['path']&& file_exists($current_path)) {
  404.             header("Content-type: application/force-download");
  405.             header('Content-Disposition: inline; filename="' basename($current_path'"');
  406.             header("Content-Transfer-Encoding: Binary");
  407.             header("Content-length: ".$current_path);
  408.             header('Content-Type: application/octet-stream');
  409.             header('Content-Disposition: attachment; filename="' basename($current_path'"');
  410.             readfile($current_path);
  411.             $this->__log(__METHOD__ . ' - downloading '$current_path);
  412.             exit();
  413.         else {
  414.             $this->error(sprintf($this->lang('FILE_DOES_NOT_EXIST'),$current_path));
  415.         }
  416.     }
  417.  
  418.     public function preview({
  419.             
  420.         $current_path $this->getFullPath();
  421.             
  422.         if(isset($this->get['path']&& file_exists($current_path)) {
  423.             header("Content-type: image/" .$ext pathinfo($current_pathPATHINFO_EXTENSION));
  424.             header("Content-Transfer-Encoding: Binary");
  425.             header("Content-length: ".filesize($current_path));
  426.             header('Content-Disposition: inline; filename="' basename($current_path'"');
  427.             readfile($current_path);
  428.             $this->__log(__METHOD__ . ' - previewing '$current_path);
  429.             exit();
  430.         else {
  431.             $this->error(sprintf($this->lang('FILE_DOES_NOT_EXIST'),$current_path));
  432.         }
  433.     }
  434.  
  435.     public function getMaxUploadFileSize({
  436.             
  437.         $max_upload = (int) ini_get('upload_max_filesize');
  438.         $max_post = (int) ini_get('post_max_size');
  439.         $memory_limit = (int) ini_get('memory_limit');
  440.  
  441.         $upload_mb min($max_upload$max_post$memory_limit);
  442.  
  443.         $this->__log(__METHOD__ . ' - max upload file size is '$upload_mb'Mb');
  444.  
  445.         return $upload_mb;
  446.     }
  447.  
  448.     private function setParams({
  449.         $tmp (isset($_SERVER['HTTP_REFERER']$_SERVER['HTTP_REFERER''/');
  450.         $tmp explode('?',$tmp);
  451.         $params array();
  452.         if(isset($tmp[1]&& $tmp[1]!=''{
  453.             $params_tmp explode('&',$tmp[1]);
  454.             if(is_array($params_tmp)) {
  455.                 foreach($params_tmp as $value{
  456.                     $tmp explode('=',$value);
  457.                     if(isset($tmp[0]&& $tmp[0]!='' && isset($tmp[1]&& $tmp[1]!=''{
  458.                         $params[$tmp[0]] $tmp[1];
  459.                     }
  460.                 }
  461.             }
  462.         }
  463.         $this->params $params;
  464.     }
  465.  
  466.  
  467.     private function get_file_info($path='',$return=array()) {
  468.             
  469.         // DO NOT  rawurlencode() since $current_path it
  470.         // is used for displaying name file
  471.         if($path==''{
  472.             $current_path $this->get['path'];
  473.         else {
  474.             $current_path $path;
  475.         }
  476.         $tmp explode('/',$current_path);
  477.         $this->item['filename'$tmp[(sizeof($tmp)-1)];
  478.  
  479.         $tmp explode('.',$this->item['filename']);
  480.         $this->item['filetype'$tmp[(sizeof($tmp)-1)];
  481.         $this->item['filemtime'filemtime($this->getFullPath($current_path));
  482.         $this->item['filectime'filectime($this->getFullPath($current_path));
  483.  
  484.         $this->item['preview'$this->config['icons']['path'$this->config['icons']['default'];
  485.  
  486.         if(is_dir($current_path)) {
  487.  
  488.             $this->item['preview'$this->config['icons']['path'$this->config['icons']['directory'];
  489.  
  490.         else if(in_array(strtolower($this->item['filetype']),$this->config['images']['imagesExt'])) {
  491.  
  492.             $this->item['preview''connectors/php/filemanager.php?mode=preview&path='rawurlencode($current_path);
  493.             //if(isset($get['getsize']) && $get['getsize']=='true') {
  494.             $this->item['properties']['Size'filesize($this->getFullPath($current_path));
  495.             if ($this->item['properties']['Size']{
  496.                 list($width$height$type$attrgetimagesize($this->getFullPath($current_path));
  497.             else {
  498.                 $this->item['properties']['Size'0;
  499.                 list($width$heightarray(00);
  500.             }
  501.             $this->item['properties']['Height'$height;
  502.             $this->item['properties']['Width'$width;
  503.             $this->item['properties']['Size'filesize($this->getFullPath($current_path));
  504.             //}
  505.  
  506.     else if(file_exists($this->root . $this->config['icons']['path'strtolower($this->item['filetype']'.png')) {
  507.  
  508.         $this->item['preview'$this->config['icons']['path'strtolower($this->item['filetype']'.png';
  509.         $this->item['properties']['Size'filesize($this->getFullPath($current_path));
  510.         if (!$this->item['properties']['Size']$this->item['properties']['Size'0;
  511.  
  512.     }
  513.  
  514.     $this->item['properties']['Date Modified'date($this->config['options']['dateFormat']$this->item['filemtime']);
  515.     //$return['properties']['Date Created'] = $this->config['options']['dateFormat'], $return['filectime']); // PHP cannot get create timestamp
  516. }
  517.  
  518. private function getFullPath($path ''{
  519.         
  520.     if($path == ''{
  521.         $path $this->get['path'];
  522.     }
  523.         
  524.     if($this->config['options']['fileRoot'!== false{
  525.         $full_path $this->doc_root . rawurldecode(str_replace $this->doc_root '' $path));
  526.     else {
  527.         $full_path $this->doc_root . rawurldecode($path);
  528.     }
  529.         
  530.     $full_path str_replace("//""/"$full_path);
  531.         
  532.     // $this->__log(__METHOD_. " path : " . $full_path);
  533.         
  534.     return $full_path;
  535.         
  536. }
  537.  
  538. private function isValidPath($path{
  539.         
  540.     // @todo remove debug message
  541.     // $this->__log('compare : ' .$this->getFullPath(). '($this->getFullPath())  and ' . $path . '(path)');
  542.     // $this->__log('strncmp() retruned value : ' .strncmp($path, $this->getFullPath(), strlen($this->getFullPath())));
  543.         
  544.     return !strncmp($path$this->getFullPath()strlen($this->getFullPath()));
  545.  
  546. }
  547.  
  548. private function unlinkRecursive($dir,$deleteRootToo=true{
  549.     if(!$dh @opendir($dir)) {
  550.         return;
  551.     }
  552.     while (false !== ($obj readdir($dh))) {
  553.         if($obj == '.' || $obj == '..'{
  554.             continue;
  555.         }
  556.  
  557.         if (!@unlink($dir '/' $obj)) {
  558.             $this->unlinkRecursive($dir.'/'.$objtrue);
  559.         }
  560.     }
  561.  
  562.     closedir($dh);
  563.  
  564.     if ($deleteRootToo{
  565.         @rmdir($dir);
  566.     }
  567.  
  568.     return;
  569. }
  570.  
  571. private function cleanString($string$allowed array()) {
  572.     $allow null;
  573.  
  574.     if (!empty($allowed)) {
  575.         foreach ($allowed as $value{
  576.             $allow .= "\\$value";
  577.         }
  578.     }
  579.  
  580.     $mapping array(
  581.             'Š'=>'S''š'=>'s''Đ'=>'Dj''đ'=>'dj''Ž'=>'Z''ž'=>'z''Č'=>'C''č'=>'c''Ć'=>'C''ć'=>'c',
  582.             'À'=>'A''Á'=>'A''Â'=>'A''Ã'=>'A''Ä'=>'A''Å'=>'A''Æ'=>'A''Ç'=>'C''È'=>'E''É'=>'E',
  583.             'Ê'=>'E''Ë'=>'E''Ì'=>'I''Í'=>'I''Î'=>'I''Ï'=>'I''Ñ'=>'N''Ò'=>'O''Ó'=>'O''Ô'=>'O',
  584.             'Õ'=>'O''Ö'=>'O''Ő'=>'O''Ø'=>'O''Ù'=>'U''Ú'=>'U''Û'=>'U''Ü'=>'U''Ű'=>'U''Ý'=>'Y',
  585.             'Þ'=>'B''ß'=>'Ss','à'=>'a''á'=>'a''â'=>'a''ã'=>'a''ä'=>'a''å'=>'a''æ'=>'a''ç'=>'c',
  586.             'è'=>'e''é'=>'e''ê'=>'e''ë'=>'e''ì'=>'i''í'=>'i''î'=>'i''ï'=>'i''ð'=>'o''ñ'=>'n',
  587.             'ò'=>'o''ó'=>'o''ô'=>'o''õ'=>'o''ö'=>'o''ő'=>'o''ø'=>'o''ù'=>'u''ú'=>'u''ű'=>'u',
  588.             'û'=>'u''ý'=>'y''ý'=>'y''þ'=>'b''ÿ'=>'y''Ŕ'=>'R''ŕ'=>'r'' '=>'_'"'"=>'_''/'=>''
  589.     );
  590.  
  591.     if (is_array($string)) {
  592.  
  593.         $cleaned array();
  594.  
  595.         foreach ($string as $key => $clean{
  596.             $clean strtr($clean$mapping);
  597.  
  598.             if($this->config['options']['chars_only_latin'== true{
  599.                 $clean preg_replace("/[^{$allow}_a-zA-Z0-9]/u"''$clean);
  600.                 // $clean = preg_replace("/[^{$allow}_a-zA-Z0-9\x{0430}-\x{044F}\x{0410}-\x{042F}]/u", '', $clean); // allow only latin alphabet with cyrillic
  601.             }
  602.             $cleaned[$keypreg_replace('/[_]+/''_'$clean)// remove double underscore
  603.         }
  604.     else {
  605.         $string strtr($string$mapping);
  606.         if($this->config['options']['chars_only_latin'== true{
  607.             $clean preg_replace("/[^{$allow}_a-zA-Z0-9]/u"''$string);
  608.             // $clean = preg_replace("/[^{$allow}_a-zA-Z0-9\x{0430}-\x{044F}\x{0410}-\x{042F}]/u", '', $string); // allow only latin alphabet with cyrillic
  609.         }
  610.         $cleaned preg_replace('/[_]+/''_'$string)// remove double underscore
  611.         
  612.     }
  613.     return $cleaned;
  614. }
  615.  
  616. private function sanitize($var{
  617.     $sanitized strip_tags($var);
  618.     $sanitized str_replace('http://'''$sanitized);
  619.     $sanitized str_replace('https://'''$sanitized);
  620.     $sanitized str_replace('../'''$sanitized);
  621.     return $sanitized;
  622. }
  623.  
  624. private function checkFilename($path,$filename,$i=''{
  625.     if(!file_exists($path $filename)) {
  626.         return $filename;
  627.     else {
  628.         $_i $i;
  629.         $tmp explode(/*$this->config['upload']['suffix'] . */$i '.',$filename);
  630.         if($i==''{
  631.             $i=1;
  632.         else {
  633.             $i++;
  634.         }
  635.         $filename str_replace($_i '.' $tmp[(sizeof($tmp)-1)],$i '.' $tmp[(sizeof($tmp)-1)],$filename);
  636.         return $this->checkFilename($path,$filename,$i);
  637.     }
  638. }
  639.  
  640. private function loadLanguageFile({
  641.  
  642.     // we load langCode var passed into URL if present and if exists
  643.     // else, we use default configuration var
  644.     $lang $this->config['options']['culture'];
  645.     if(isset($this->params['langCode']&& in_array($this->params['langCode']$this->languages)) $lang $this->params['langCode'];
  646.  
  647.     if(file_exists($this->root'scripts/languages/'.$lang.'.js')) {
  648.         $stream =file_get_contents($this->root'scripts/languages/'.$lang.'.js');
  649.         $this->language = json_decode($streamtrue);
  650.     else {
  651.         $stream =file_get_contents($this->root'scripts/languages/'.$lang.'.js');
  652.         $this->language = json_decode($streamtrue);
  653.     }
  654. }
  655.  
  656. private function availableLanguages({
  657.  
  658.     if ($handle opendir($this->root.'/scripts/languages/')) {
  659.         while (false !== ($file readdir($handle))) {
  660.             if ($file != "." && $file != ".."{
  661.                 array_push($this->languagespathinfo($filePATHINFO_FILENAME));
  662.             }
  663.         }
  664.         closedir($handle);
  665.     }
  666. }
  667.  
  668. private function __log($msg{
  669.         
  670.     if($this->logger == true{
  671.  
  672.         $fp fopen($this->logfile"a");
  673.         $str "[" date("d/m/Y h:i:s"mktime()) "] " $msg;
  674.         fwrite($fp$str PHP_EOL);
  675.         fclose($fp);
  676.     }
  677.         
  678. }
  679.  
  680. public function enableLog($logfile ''{
  681.         
  682.     $this->logger = true;
  683.         
  684.     if($logfile != ''{
  685.         $this->logfile = $logfile;
  686.     }
  687.         
  688.     $this->__log(__METHOD__ . ' - Log enabled (in '$this->logfile' file)');
  689.         
  690. }
  691.  
  692. public function disableLog({
  693.  
  694.     $this->logger = false;
  695.  
  696.     $this->__log(__METHOD__ . ' - Log disabled');
  697. }
  698. }
  699. ?>

Documentation generated on Mon, 08 Apr 2013 18:14:31 +0200 by phpDocumentor 1.4.1