Exemplo n.º 1
0
 public function getProductsJSON()
 {
     $model = rad_instances::get('model_coremenus_tree');
     $model->setState('pid', $this->request('npid', $this->request('pid')));
     $model->setState('lang', $this->getContentLangID());
     $items = $model->getItems();
     $nodes = array();
     $search = array('"', '&');
     $replace = array('"', '&');
     $modelCat = rad_instances::get('model_corecatalog_catalog');
     if (count($items)) {
         foreach ($items as $id) {
             $modelCat->clearState();
             $modelCat->setState('tre_id', $id->tre_id)->setState('lang', $this->getContentLangID());
             $productsCntInTree = (int) $modelCat->getProductsListCount();
             if (!$id->tre_islast or $productsCntInTree) {
                 $nodes[] = array('property' => array('name' => str_replace($search, $replace, $id->tre_name), 'hasCheckbox' => false), 'type' => 'folder', 'data' => array('npid' => $id->tre_id));
             } elseif ($id->tre_islast and $productsCntInTree === 0) {
                 $nodes[] = array('property' => array('name' => str_replace($search, $replace, $id->tre_name), 'hasCheckbox' => false), 'type' => 'empty');
             }
         }
     }
     $modelCat->setState('tre_id', $this->request('npid', $this->request('pid')));
     $modelCat->setState('lang', $this->getContentLangID());
     $productsInTree = $modelCat->getProductsList();
     if (count($productsInTree)) {
         foreach ($productsInTree as $product) {
             $imgLink = empty($product->img_filename) ? '' : rad_gd_image::getLinkToImage('corecatalog', $product->img_filename, 'productstree');
             $nodes[] = array('property' => array('name' => str_replace($search, $replace, $product->cat_name), 'openIconUrl' => $imgLink, 'closeIconUrl' => $imgLink), 'type' => 'file', 'data' => array('product_id' => $product->cat_id));
         }
     }
     $this->header('Content-Type: application/json');
     echo json_encode($nodes);
 }
Exemplo n.º 2
0
if (!preg_match('~^[a-zA-Z0-9][-_.a-zA-Z0-9]*(?:/[a-zA-Z0-9][-_.a-zA-Z0-9]*)*\\.(?:jp(?:e?g|e|2)|gif|png|gd)$~i', $filename)) {
    //filename is a correct image file name
    errorMsg("File name is incorrect!");
}
$theme_name = rad_themer::getCurrentTheme();
$originalFile = rad_themer::getFilePath($theme_name, 'img', $module, $filename);
if (!$originalFile) {
    errorMsg("File does not exist!");
}
$resizedFile = $config['rootPath'] . 'cache' . DS . 'img' . DS . $theme_name . DS . $module . DS . $preset . DS . $filename;
$resizedPath = dirname($resizedFile);
if (!recursive_mkdir($resizedPath, 0777)) {
    errorMsg("Can not create dir! Path: {$resizedPath}");
}
if (!file_exists($resizedFile) || time() - filemtime($resizedFile) >= (int) $config['cache.power.time']) {
    $img = new rad_gd_image();
    if ($img->set($originalFile, $resizedFile, $preset)) {
        $r = $img->resize();
        if (!$r) {
            errorMsg($img->getError());
        }
    } else {
        errorMsg($img->getError());
    }
}
switch (rad_gd_image::getFileExtension($resizedFile)) {
    case 'jpg':
    case 'jpeg':
    case 'jpe':
        header('Content-type: image/jpeg');
        break;
Exemplo n.º 3
0
 function getRemoteImg()
 {
     $url = $this->request('url');
     $url = urldecode($url);
     $filename = md5($url . mktime(0, 0, 0, date("n"), date("j"), date("Y")));
     $fileadr = SMARTYCACHEPATH . $filename;
     $root_path = rad_config::getParam('rootPath');
     $theme_name = rad_config::getParam('theme.default');
     if (empty($theme_name)) {
         $theme_name = 'default';
     }
     $msg = '';
     if ($url and strpos($url, "http") === 0) {
         $opts = array('http' => array('method' => "GET", 'max_redirects' => 5, 'timeout' => 5, 'ignore_errors' => false));
         $context = stream_context_create($opts);
         $i = 3;
         $fileData = NULL;
         //try to recieve image file data 3 times with timeout 5 seconds
         do {
             $header = get_headers($url, 1);
             if (isset($header['Content-Length'])) {
                 $contentLength = (int) $header['Content-Length'];
                 $maxPost = (int) $this->configSys('max_post');
                 if ($contentLength <= $maxPost) {
                     if (!file_exists($fileadr)) {
                         $fileData = @file_get_contents($url, false, $context);
                         if ($fileData) {
                             $i = 0;
                         } else {
                             $i--;
                         }
                     } else {
                         $fileExt = $this->_getImageExtension($fileadr);
                         if ($fileExt) {
                             die(json_encode(array('is_success' => true, 'theme' => $theme_name, 'origname' => $filename, 'filename' => $filename . '.' . $fileExt)));
                         } else {
                             unlink($fileadr);
                             $i--;
                         }
                     }
                 } else {
                     $i = 0;
                     $msg = $this->lang('imagesizetoobig.catalog.error');
                 }
             }
         } while ($i > 0);
         if ($fileData) {
             // if file data recieved, put it on the server into temp folder
             $hFile = fopen($fileadr, 'w');
             if ($hFile) {
                 fputs($hFile, $fileData);
                 flush();
                 fclose($hFile);
                 $fileExt = $this->_getImageExtension($fileadr);
                 if ($fileExt) {
                     $resizedFile = $root_path . 'cache' . DS . 'img' . DS . $theme_name . DS . 'corecatalog' . DS . 'product_thumb' . DS . $filename . '.' . $fileExt;
                     $resizedPath = dirname($resizedFile);
                     if (recursive_mkdir($resizedPath, 0777)) {
                         $gdImg = new rad_gd_image();
                         if ($gdImg->set($fileadr, $resizedFile, 'product_thumb')) {
                             $r = $gdImg->resize();
                             if ($r) {
                                 die(json_encode(array('is_success' => true, 'theme' => $theme_name, 'origname' => $filename, 'filename' => $filename . '.' . $fileExt)));
                             } else {
                                 unlink($fileadr);
                                 $msg = $gdImg->getError();
                             }
                         } else {
                             unlink($fileadr);
                             $msg = $gdImg->getError();
                         }
                     } else {
                         unlink($fileadr);
                         $msg = "Can not create dir! Path: {$resizedPath}";
                     }
                 } else {
                     unlink($fileadr);
                     $msg = $this->lang('wrongfiledata.catalog.error');
                 }
             } else {
                 $msg = $this->lang('cannotcreatefile.catalog.error');
             }
         }
     } else {
         $msg = $this->lang('wrongimageurl.catalog.error');
     }
     die(json_encode(array('is_success' => false, 'msg' => $msg)));
 }
Exemplo n.º 4
0
/**
 * @example
 * {url type="js" module="core" file="..." load="sync|defer|async|inplace" tag="0"}
 *
 * Parameter "tag" is used only with type="js|css|image":
 * tag="0" - return only link
 * tag="1" - return html code
 * for type="image" default value is "0", for type="js|css" default value is "1"
 *
 * Parameter "load" is used only with type="js":
 * load="defer" - the script will not run until after the page has loaded (default value)
 * load="async" - the script will be run asynchronously
 * load="inplace" - the script will be insert into template where {url} tag was placed
 * load="sync" - the script will be run in order during the page rendering
 *
 * Parameter "attr" contains a list of additional attributes, that will be inserted into the tag
 * @example
 * {url type="css" module="core" file="..." attr="media=screen"}
 * {url type="image" module="core" file="..." attr="border=0&class=preview"}
 */
function smarty_function_url($params, $smarty)
{
    $valid_attributes = array('css' => array('media'), 'image' => array('class', 'border'));
    $params += array('load' => false, 'type' => '', 'tag' => isset($params['type']) && $params['type'] == 'image' ? 0 : 1, 'priority' => 0);
    if (isset($params['href']) != empty($params['file'])) {
        //Either both params are set or both ain't.
        if (rad_config::getParam('debug.showErrors')) {
            throw new rad_exception('url file=[EMPTY]!');
        } else {
            return '';
        }
    }
    if (isset($params['href'])) {
        $url = $params['href'];
        if (!is_link_absolute($url)) {
            if (!empty($params['canonical'])) {
                if (empty($url)) {
                    $url = SITE_URL . 'index.php?lang=' . rad_lang::getCurrentLanguage();
                } else {
                    $url = SITE_URL . 'index.php?lang=' . rad_lang::getCurrentLanguage() . '&' . $url;
                }
            } else {
                $url = rad_input::makeURL($url, true);
            }
        }
    } else {
        if (!empty($params['type'])) {
            if (!isset($params['module'])) {
                if (rad_config::getParam('debug.showErrors')) {
                    throw new RuntimeException("Module is required in {url type='{$params['type']}' TAG");
                } else {
                    return '';
                }
            }
            try {
                switch ($params['type']) {
                    case 'js':
                        $url = rad_jscss::getLinkToJS($params['module'], $params['file']);
                        break;
                    case 'css':
                        $url = rad_jscss::getLinkToCSS($params['module'], $params['file']);
                        break;
                    case 'dfile':
                        //TODO: implement per-component dfiles folders and dfiles caching.
                        return DOWNLOAD_FILES . $params['module'] . '/' . $params['file'];
                    case 'image':
                        $url = rad_gd_image::getLinkToImage($params['module'], $params['file'], $params['preset']);
                        break;
                    default:
                        throw new rad_exception("Wrong parameter type in {url type='{$params['type']}'}");
                }
            } catch (Exception $e) {
                if (rad_config::getParam('debug.showErrors')) {
                    throw $e;
                } else {
                    return '';
                }
            }
            /* TODO: some draft for future #850 implementation
               } elseif(get_class($params['file'])=='struct_core_files') {
                   if(!isset($params['module'])) {
                       $smarty->_syntax_error("url: missing 'module' parameter for struct_core_files class when genere url", E_USER_ERROR);
                   }
                   $module = $params['module'];
                   if( rad_input::getDefine( strtoupper($module.'PATH') ) != strtoupper($module.'PATH') ) {
                       return SITE_URL.str_replace( rad_input::getDefine('rootPath') ,'', rad_input::getDefine( strtoupper($module.'PATH') ));
                   } elseif(rad_input::getDefine('DOWNLOAD_FILES')!='DOWNLOAD_FILES') {
                       return DOWNLOAD_FILES.$params['file']->rfl_filename.'/'.$module.'/'.$params['file']->rfl_name;
                   } else {
                       throw new rad_exception('DOWNLOAD_FILES_DIR or '.strtoupper($module.'PATH').' not defined in config!');
                   }
               */
        } elseif (get_class($params['file']) == 'struct_corecatalog_cat_files') {
            return DOWNLOAD_FILES . $params['file']->rcf_filename . '/' . $params['file']->rcf_name;
        } else {
            if (rad_config::getParam('debug.showErrors')) {
                throw new rad_exception('Unknown class in url function "' . get_class($params['file']) . '" ', __LINE__);
            } else {
                return '';
            }
        }
    }
    if (!empty($params['type']) && $params['tag']) {
        $attributes = '';
        if (!empty($params['attr']) && !empty($valid_attributes[$params['type']])) {
            parse_str($params['attr'], $attr_array);
            $attributes_array = array_intersect_key($attr_array, array_flip($valid_attributes[$params['type']]));
            foreach ($attributes_array as $k => $v) {
                $v = htmlspecialchars($v);
                $attributes .= " {$k}='{$v}'";
            }
        }
        switch ($params['type']) {
            case 'js':
                switch ($params['load']) {
                    case 'async':
                        $attributes .= " async='true'";
                    case 'defer':
                        //NB: also for "async" mode for IE compatibility
                        $attributes .= " defer='true'";
                }
                $html = "<script type='text/javascript' src='{$url}'{$attributes}></script>";
                if ($params['load'] == 'inplace') {
                    return $html;
                }
                if (isset($params['href'])) {
                    rad_jscss::addFile('--EXTERNAL--', $params['href'], $html, (int) $params['priority']);
                } else {
                    rad_jscss::addFile($params['module'], $params['file'], $html, (int) $params['priority']);
                }
                return '';
            case 'css':
                $html = "<link rel='stylesheet' type='text/css' href='{$url}'{$attributes} />";
                if (isset($params['href'])) {
                    rad_jscss::addFile('--EXTERNAL--', $params['href'], $html, (int) $params['priority']);
                } else {
                    rad_jscss::addFile($params['module'], $params['file'], $html, (int) $params['priority']);
                }
                return '';
            case 'image':
                return "<img src='{$url}'{$attributes} />";
        }
    }
    return $url;
}
Exemplo n.º 5
0
 private function uploadImage($currency_id, $previous_image = '', $delete = false)
 {
     if (!empty($_FILES['cur_image']['size']) && !$_FILES['cur_image']['error']) {
         $ext = rad_gd_image::getFileExtension($_FILES['cur_image']['tmp_name']);
         if ($ext) {
             if ($previous_image) {
                 $this->deleteImage($previous_image);
             }
             $filename = $currency_id . '.' . $ext;
             if (move_uploaded_file($_FILES['cur_image']['tmp_name'], $this->getImagePath($filename))) {
                 return $filename;
             }
             return '';
         }
     } elseif ($previous_image && $delete) {
         $this->deleteImage($previous_image);
         return '';
     }
     return $previous_image;
 }