Example #1
0
 /**
  * @return array
  */
 public static function set()
 {
     //Current URL
     $getUrl = http_url::getUrl(true);
     $parseUrl = parse_url($getUrl);
     $setPositionStart = strpos($parseUrl['path'], "/") + 1;
     if (strrpos($parseUrl['path'], "/") < 3) {
         $setPositionEnd = strrpos($parseUrl['path'], "/") - 1;
         $setModule = substr($parseUrl['path'], $setPositionStart, $setPositionEnd);
     } else {
         $setModule = substr($parseUrl['path'], $setPositionStart);
     }
     $getModule = explode('/', $setModule);
     return $getModule;
 }
Example #2
0
 /**
  * Envoi une image sur le serveur avec la méthode upload
  * @param files $img
  * @param dir $path
  * @param bool $setOption
  * @param bool|\debug $debug $debug
  * @return null|string|\true
  */
 public static function uploadImg($img, $path, $setOption = false, $debug = false)
 {
     $error = null;
     $makefile = new filesystem_makefile();
     $firebug = new debug_firephp();
     if (is_array($setOption)) {
         if (array_key_exists('maxwidth', $setOption)) {
             $maxwidth = $setOption['maxwidth'];
         } else {
             $maxwidth = 2500;
         }
         if (array_key_exists('maxheight', $setOption)) {
             $maxheight = $setOption['maxheight'];
         } else {
             $maxheight = 2500;
         }
         if (array_key_exists('minheight', $setOption)) {
             $minheight = $setOption['minheight'];
         } else {
             $minheight = 5;
         }
         if (array_key_exists('minwidth', $setOption)) {
             $minwidth = $setOption['minwidth'];
         } else {
             $minwidth = 5;
         }
     } else {
         $maxwidth = 2500;
         $maxheight = 2500;
         $minheight = 5;
         $minwidth = 5;
     }
     /**
      * Envoi de l'image
      */
     if (isset($_FILES[$img])) {
         if ($_FILES[$img]['error'] == UPLOAD_ERR_OK) {
             if (self::imageValid($_FILES[$img]['tmp_name']) === false) {
                 $error .= 'Invalid image format (gif, png, jpeg only)';
             } else {
                 if (!is_readable($_FILES[$img]["tmp_name"])) {
                     //$tmp_img = chmod($_FILES[$img]["tmp_name"],0777);
                     $tmp_img = $makefile->chmod(array($_FILES[$img]["tmp_name"]), 0777);
                 } else {
                     $tmp_img = $_FILES[$img]["tmp_name"];
                 }
                 //if(chmod($_FILES[$img]["tmp_name"],0777)){
                 if (is_uploaded_file($_FILES[$img]["tmp_name"])) {
                     $source = $tmp_img;
                     $cible = component_core_system::basePath() . $path . '/' . http_url::clean($_FILES[$img]["name"]);
                     if (self::imgSizeMax($source, $maxwidth, $maxheight) == false) {
                         $error .= 'Exceeds the maximum size ' . $maxwidth . ' x ' . $maxheight;
                     } elseif (self::imgSizeMin($source, $minwidth, $minheight) == false) {
                         $error .= 'The file is too small: ' . $minwidth . ' x ' . $minheight;
                     } else {
                         if (!move_uploaded_file($source, $cible)) {
                             $error .= 'Error in temporary file';
                         } else {
                             if ($debug != false) {
                                 $firebug->group('Upload image infos');
                                 $firebug->log('Success', 'Status');
                                 $firebug->log($source, 'Source');
                                 $firebug->log($cible, 'Cible');
                                 $firebug->groupEnd();
                             }
                         }
                     }
                 } else {
                     $error .= 'Disk write error';
                 }
                 //}
             }
         } elseif (UPLOAD_ERR_INI_SIZE == true) {
             $error .= 'The file is too large';
         } elseif (UPLOAD_ERR_CANT_WRITE == true) {
             $error .= 'Disk write error';
         } elseif (UPLOAD_ERR_FORM_SIZE == true) {
             $error .= 'The file is too large: maximum size ' . $maxwidth . ' x ' . $maxheight;
         }
     } elseif (UPLOAD_ERR_NO_FILE == true) {
         $error .= 'No file';
     } else {
         $error .= 'Disk write error';
     }
     if ($error != null) {
         $n = $firebug->group('Upload image analyse');
         $n .= $firebug->log($error);
         $n .= $firebug->groupEnd();
     } else {
         $n = NULL;
     }
     return $n;
 }
Example #3
0
 /**
  * Conbine function trim and rplMagixString
  *
  * @param string $str
  * @return string
  */
 public static function rewriteUrl($str)
 {
     return filter_escapeHtml::trim(http_url::clean($str));
 }
Example #4
0
/**
 * Smarty {geturl} function plugin
 *
 * Type:     function
 * Name:     getUrl
 * Date:     August 21, 2009
 * Purpose:  Récupère l'url du nom de domaine ou défini le root du site automatiquement
 * Examples: {geturl}
 * Output:   
 * @link 
 * @author   Gerits Aurelien
 * @version  1.0
 * @param array
 * @param Smarty
 * @return string
 */
function smarty_function_geturl($params, $template)
{
    return http_url::getUrl();
}
Example #5
0
 /**
  * @access public
  * @static
  * getUrlConcat Retourne la concaténation de la minification de fichiers
  * @param $options
  * @return string
  * @throws Exception
  * @author Gérits Aurelien and JB Demonte (http://jb.demonte.fr/)
  */
 public static function getUrlConcat($options)
 {
     if (is_array($options)) {
         if (array_key_exists('caches', $options)) {
             $min_cachePath = $options['caches'];
         } else {
             throw new Exception("Error caches dir is not defined");
         }
         if (array_key_exists('href', $options)) {
             $url = $options["href"];
             $ext = 'css';
         } elseif (array_key_exists('src', $options)) {
             $url = $options["src"];
             $ext = 'js';
         }
         if (array_key_exists('filesgroups', $options)) {
             $filesgroups = $options['filesgroups'];
         } else {
             $filesgroups = 'min/groupsConfig.php';
         }
         if (array_key_exists('minDir', $options)) {
             $minDir = $options['minDir'];
         } else {
             $minDir = '/min/';
         }
         if (array_key_exists('callback', $options)) {
             $callback = $options['callback'];
         } else {
             $callback = '';
         }
     } else {
         throw new Exception("Error options is not array");
     }
     $name = "";
     //Parse a URL and return its components
     $parseurl = parse_url($url);
     //return position
     $position = strpos($parseurl['query'], '=');
     //return first query
     $query = substr($parseurl['query'], 0, $position);
     //return url after query
     $filesPath = substr(strrchr($parseurl['query'], '='), 1);
     // Group
     if ($query === 'g') {
         $filesCollection = array();
         if (file_exists($filesgroups)) {
             $groups = (require $filesgroups);
             foreach (explode(",", $filesPath) as $group) {
                 $filesCollection = array_merge($filesCollection, isset($groups[$group]) ? $groups[$group] : array());
             }
         } else {
             throw new Exception("filesgroups is not exist");
         }
         // Files
     } elseif ($query === 'f') {
         $filesCollection = explode(",", $filesPath);
     }
     foreach ($filesCollection as &$file) {
         $file = ltrim($file, "/");
         $name .= $file . "|" . filemtime(self::basePath() . $file) . "|" . filesize(self::basePath() . $file) . "/";
     }
     $sha1name = sha1($name) . "." . $ext;
     if (file_exists($min_cachePath) and is_writable($min_cachePath)) {
         $filepath = realpath(".") . "/" . $min_cachePath . "/" . $sha1name;
         if (!file_exists($filepath)) {
             $content = file_get_contents(http_url::getUrl() . $minDir . '?f=' . implode(",", $filesCollection));
             file_put_contents($filepath, $content);
         }
         return $callback . "/" . $min_cachePath . "/" . $sha1name;
     } else {
         throw new Exception("Error " . $min_cachePath . " is not writable");
     }
 }