phpDocumentor PHPShopClass
[ class tree: PHPShopClass ] [ all elements ]

Source for file core.class.php

Documentation is available at core.class.php

  1. <?php
  2. /**
  3.  * Родительский класс ядра
  4.  * Примеры использования размещены в папке phpshop/core/
  5.  * @author PHPShop Software
  6.  * @version 1.4
  7.  * @package PHPShopClass
  8.  */
  9.  
  10. class PHPShopCore {
  11.     /**
  12.      * @var string имя БД
  13.      */
  14.     var $objBase;
  15.     /**
  16.      * @var bool режим отладки
  17.      */
  18.     var $debug=false;
  19.     /**
  20.      * @var string результат работы парсера
  21.      */
  22.     var $Disp,$ListInfoItems;
  23.     /**
  24.      * @var array массив обработки POST, GET запросов
  25.      */
  26.     var $action=array("nav"=>"index");
  27.     /**
  28.      * @var string метатеги
  29.      */
  30.     /**
  31.      * @var string ссылка в навигации от корня
  32.      */
  33.     var $navigation_link='';
  34.     /**
  35.      * @var string шаблон вывода
  36.      */
  37.     var $template='templates.shop';
  38.     /**
  39.      * @var string массив навигации (каталог/фото)
  40.      */
  41.     var $navigationArray='CatalogPage';
  42.     /**
  43.      * @var string  таблица массива навигации
  44.      */
  45.     var $navigationBase='base.table_name';
  46.     /**
  47.      * @var bool включить парсер php функций в *.html файлах 
  48.      */
  49.     var $parser=false;
  50.  
  51.     /**
  52.      * Конструктор
  53.      * @global array $PHPShopSystem
  54.      * @global array $PHPShopNav
  55.      * @global array $PHPShopModules
  56.      */
  57.     function PHPShopCore({
  58.         global $PHPShopSystem,$PHPShopNav,$PHPShopModules;
  59.  
  60.         if($this->objBase)
  61.             $this->PHPShopOrm &new PHPShopOrm($this->objBase);
  62.  
  63.         $this->PHPShopOrm->debug=$this->debug;
  64.         $this->SysValue=&$GLOBALS['SysValue'];
  65.         $this->LoadItems=&$GLOBALS['LoadItems'];
  66.         $this->PHPShopSystem=&$PHPShopSystem;
  67.         $this->num_row=$this->PHPShopSystem->getParam('num_row');
  68.         $this->PHPShopNav=&$PHPShopNav;
  69.         $this->PHPShopModules=&$PHPShopModules;
  70.         $this->page=$this->PHPShopNav->getId();
  71.         if(strlen($this->page)==0$this->page=1;
  72.  
  73.         // Определяем переменные
  74.         $this->set('pageReg',"PHPShop CMS Free");
  75.         $this->set('pageDomen',"No");
  76.         $this->set('pageProduct',$this->SysValue['license']['product_name']);
  77.  
  78.     }
  79.  
  80.  
  81.     /**
  82.      * Возврат содержимого файла
  83.      * @global array $SysValue настройки
  84.      * @param string $path имя файла без расширения
  85.      * @return string
  86.      */
  87.     function OpenHTML($path{
  88.         global $SysValue;
  89.         $dir="pageHTML/";
  90.         $pages=$path.".html";
  91.         $handle=opendir($dir);
  92.         while ($file readdir($handle)) {
  93.             if($file==$pages{
  94.                 $urlfile=fopen ("$dir$file","r");
  95.                 $text=fread($urlfile,1000000);
  96.                 $text=Parser($text,$this->parser);
  97.                 return $text;
  98.             }
  99.         }
  100.         return false;
  101.     }
  102.  
  103.     function getMeta($content{
  104.  
  105.         // Title
  106.         $patern="/<H1>(.*)<\/H1>/i";
  107.         preg_match($patern,$content,$matches);
  108.         $title $matches[1];
  109.  
  110.         // Description
  111.         $patern="/<desc>(.*)<\/desc>/i";
  112.         preg_match($patern,$content,$matches);
  113.         $description $matches[1];
  114.  
  115.         // Keywords
  116.         $patern="/<key>(.*)<\/key>/i";
  117.         preg_match($patern,$content,$matches);
  118.         $keywords $matches[1];
  119.  
  120.         return array('title'=>$title,'description'=>$description,'keywords'=>$keywords);
  121.     }
  122.  
  123.     function getNavigationPath($id{
  124.         global $array;
  125.         $PHPShopOrm &new PHPShopOrm($this->getValue($this->navigationBase));
  126.         $PHPShopOrm->debug=$this->debug;
  127.  
  128.         if($id)
  129.             if(empty($this->LoadItems[$this->navigationArray][$id]['name'])) {
  130.                 $PHPShopOrm->comment="Навигация";
  131.                 $v=$PHPShopOrm->select(array('name','id','parent_to'),array('id'=>'='.$id),false,array('limit'=>1));
  132.  
  133.                 if(is_array($v)) {
  134.                     $array[]=array('id'=>$v['id'],'name'=>$v['name'],'parent_to'=>$v['parent_to']);
  135.                     $this->getNavigationPath($v['parent_to']);
  136.                 }
  137.             }else {
  138.                 foreach($this->LoadItems[$this->navigationArrayas $k=>$v)
  139.                     if($k == $id{
  140.                         $array[]=array('id'=>$id,'name'=>$v['name'],'parent_to'=>$v['parent_to']);
  141.                         $this->getNavigationPath($v['parent_to']);
  142.                     }
  143.             }
  144.         return $array;
  145.     }
  146.     /**
  147.      * Навигация хлебных крошек
  148.      * @param int $id текущий ИД позиции
  149.      * @param string $name имя раздела
  150.      */
  151.     function navigation($id,$name{
  152.         $dis='';
  153.         $spliter=ParseTemplateReturn($this->getValue('templates.breadcrumbs_splitter'));
  154.         $home=ParseTemplateReturn($this->getValue('templates.breadcrumbs_home'));
  155.  
  156.         $arrayPath=$this->getNavigationPath($id);
  157.  
  158.         if(is_array($arrayPath)) {
  159.             $arrayPath=array_reverse$arrayPath);
  160.  
  161.             // Убираем последнее значение если каталог
  162.             if($this->PHPShopNav->getNav(== "CID" )
  163.                 array_pop($arrayPath);
  164.  
  165.             foreach($arrayPath as $v{
  166.                 $dis.= $spliter.'<A href="/'.$this->PHPShopNav->getPath().'/CID_'.$v['id'].'.html">'.$v['name'].'</a>';
  167.             }
  168.  
  169.         }
  170.  
  171.         $dis=$home.$dis.$spliter.'<b>'.$name.'</b>';
  172.         $this->set('breadCrumbs',$dis);
  173.  
  174.         // Навигация для javascript в shop.tpl
  175.         $this->set('pageNameId',$id);
  176.     }
  177.  
  178.     /**
  179.      * Генерация даты изменения документа
  180.      */
  181.     function header({
  182.         if($this->getValue("my.last_modified"== "true"{
  183.             @Header("Cache-Control: no-cache, must-revalidate");
  184.             @Header("Pragma: no-cache");
  185.  
  186.             if(!empty($this->lastmodified)) {
  187.                 $updateDate=@gmdate("D, d M Y H:i:s",$this->lastmodified);
  188.             }
  189.             else {
  190.                 $updateDate=gmdate("D, d M Y H:i:s",(date("U")-21600));
  191.             }
  192.  
  193.             @Header("Last-Modified: ".$updateDate." GMT");
  194.         }
  195.     }
  196.  
  197.     /**
  198.      * Генерация заголовков документа
  199.      */
  200.     function meta({
  201.  
  202.         if(!empty($this->title)) $this->set('pageTitl',$this->title);
  203.         else $this->set('pageTitl',$this->PHPShopSystem->getValue("title"));
  204.  
  205.         if(!empty($this->description)) $this->set('pageDesc',$this->description);
  206.         else $this->set('pageDesc',$this->title);
  207.  
  208.         if(!empty($this->keywords)) $this->set('pageKeyw',$this->keywords);
  209.         else $this->set('pageKeyw',$this->title);
  210.  
  211.     }
  212.  
  213.     /**
  214.      * Загрузка экшенов
  215.      */
  216.     function loadActions({
  217.         $core_file="./pages/".$this->PHPShopNav->getPath().".php";
  218.         if(!is_file($core_file)) {
  219.             $this->setAction();
  220.             $this->Compile();
  221.         }else {
  222.  
  223.             // Поддержка старого API для /pages/*.php
  224.             include_once($core_file);
  225.         }
  226.     }
  227.  
  228.     /**
  229.      * Выдача списка данных
  230.      * @param array $select имена колонок БД для выборки
  231.      * @param array $where параметры условий запроса
  232.      * @param array $order параметры сортировки данных при выдаче
  233.      * @return array
  234.      */
  235.     function getListInfoItem($select=false,$where=false,$order=false{
  236.         $this->ListInfoItems='';
  237.         $this->where=$where;
  238.  
  239.         // Обработка номера страницы
  240.         if(!PHPShopSecurity::true_num($this->page)) return $this->setError404();
  241.  
  242.         if(empty($this->page)) {
  243.             $num_ot=0;
  244.             $num_do=$this->num_row;
  245.         }
  246.         else {
  247.             $num_ot=$this->num_row*($this->page-1);
  248.             $num_do=$this->num_row;
  249.         }
  250.  
  251.         $option=array('limit'=>$num_ot.','.$num_do);
  252.  
  253.         $this->set('productFound',$this->getValue('lang.found_of_products'));
  254.         $this->set('productNumOnPage',$this->getValue('lang.row_on_page'));
  255.         $this->set('productPage',$this->getValue('lang.page_now'));
  256.  
  257.         return $this->PHPShopOrm->select($select,$where,$order,$option);
  258.     }
  259.  
  260.     /**
  261.      * Генерация пагинатора
  262.      */
  263.     function setPaginator({
  264.         $SQL='';
  265.         // Выборка по параметрам WHERE
  266.         $nWhere=1;
  267.         if(is_array($this->where)) {
  268.             $SQL.=' where ';
  269.             foreach($this->where as $pole=>$value{
  270.                 $SQL.=$pole.$value;
  271.                 if($nWhere<count($this->where)) $SQL.=$this->PHPShopOrm->Option['where'];
  272.                 $nWhere++;
  273.             }
  274.         }
  275.  
  276.  
  277.         // Кол-во страниц
  278.         $result=$this->PHPShopOrm->query("select COUNT('id') as count from ".$this->objBase.$SQL);
  279.         $row mysql_fetch_array($result);
  280.         $this->num_page=$row['count'];
  281.  
  282.         $i=1;
  283.         $navigat='';
  284.         $num=$this->num_page/$this->num_row;
  285.  
  286.         while ($i<$num+1{
  287.             if($i!=$this->page$navigat.="<a href=\"".$this->objPath.$i.".html\">$i</a> / ";
  288.             else $navigat.="<b$i</b> / ";
  289.             $i++;
  290.         }
  291.         if($num>1{
  292.             if($this->page>=$num{
  293.                 $p_to=$i-1;
  294.                 $p_do=$this->page-1;
  295.             }else {
  296.                 $p_to=$this->page+1;
  297.                 $p_do=1;
  298.             }
  299.             $this->set('productPageNav',$this->getValue('lang.page_now').":
  300. <a href=\"".$this->objPath.($p_do).".html\">&laquo;&laquo;&nbsp;</a>&nbsp;/
  301.                     $navigat&nbsp<a href=\"".$this->objPath.$p_to.".html\">&nbsp;&raquo;&raquo;</a>");
  302.         }
  303.     }
  304.  
  305.     /**
  306.      * Выдача подробного описания
  307.      * @param array $select имена колонок БД для выборки
  308.      * @param array $where параметры условий запроса
  309.      * @param array $order параметры сортировки данных при выдаче
  310.      * @return array
  311.      */
  312.     function getFullInfoItem($select,$where,$order=false{
  313.         return $this->PHPShopOrm->select($select,$where,$order,array('limit'=>'1'));
  314.     }
  315.  
  316.     /**
  317.      * Добавление данных в вывод парсера
  318.      * @param string $template шаблон для парсинга
  319.      */
  320.     function addToTemplate($template{
  321.         $template_file=$this->getValue('dir.templates').chr(47).$_SESSION['skin'].chr(47).$template;
  322.         if(is_file($template_file)) {
  323.             $this->ListInfoItems.=ParseTemplateReturn($template);
  324.             $this->set('pageContent',$this->ListInfoItems);
  325.         }else $this->setError("addToTemplate",$template_file);
  326.     }
  327.  
  328.     /**
  329.      * Добавление данных
  330.      * @param string $content содержание
  331.      * @param bool $list [1] - добавление в список данных, [0] - добавление в общую переменную вывода
  332.      */
  333.     function add($content,$list=false{
  334.         if($list$this->ListInfoItems.=$content;
  335.         else $this->Disp.=$content;
  336.     }
  337.  
  338.     /**
  339.      * Парсинг шаблона и добавление в общую переменную вывода
  340.      * @param string $template имя шаблона
  341.      */
  342.     function parseTemplate($template{
  343.         $this->set('productPageDis',$this->ListInfoItems);
  344.         $this->Disp=ParseTemplateReturn($template);
  345.     }
  346.  
  347.     /**
  348.      * Сообщение об ошибке
  349.      * @param string $name имя функции
  350.      * @param string $action сообщение
  351.      */
  352.     function setError($name,$action{
  353.         echo '<p style="BORDER: #000000 1px dashed;padding-top:10px;padding-bottom:10px;background-color:#FFFFFF;color:000000;font-size:12px">
  354. <img hspace="10" style="padding-left:10px" align="left" src="../phpshop/admpanel/img/i_domainmanager_med[1].gif"
  355. width="32" height="32" alt="PHPShopCore Debug On"/ ><strong>Ошибка обработчика события:</strong> '.$name.'()
  356.      <br><em>'.$action.'</em></p>';
  357.     }
  358.  
  359.     /**
  360.      * Компиляция парсинга
  361.      */
  362.     function Compile({
  363.         $this->set('DispShop',$this->Disp);
  364.  
  365.         // Мета
  366.         $this->meta();
  367.  
  368.         // Дата модификации
  369.         $this->header();
  370.  
  371.         ParseTemplate($this->getValue($this->template));
  372.     }
  373.  
  374.     /**
  375.      * Создание системной переменной для парсинга
  376.      * @param string $name имя
  377.      * @param mixed $value значение
  378.      * @param bool $flag [1] - добавить, [0] - переписать
  379.      */
  380.     function set($name,$value,$flag=false{
  381.         if($flag$this->SysValue['other'][$name].=$value;
  382.         else $this->SysValue['other'][$name]=$value;
  383.     }
  384.  
  385.     /**
  386.      * Выдача системной переменной
  387.      * @param string $param раздел.имя переменной
  388.      * @return mixed
  389.      */
  390.     function getValue($param{
  391.         $param=explode(".",$param);
  392.         return $this->SysValue[$param[0]][$param[1]];
  393.     }
  394.  
  395.     /**
  396.      * Назначение экшена обработки перемнных POST и GET
  397.      */
  398.     function setAction({
  399.         global $SysValue;
  400.  
  401.         if(is_array($this->action)) {
  402.             foreach($this->action as $k=>$v{
  403.  
  404.                 switch($k{
  405.  
  406.                     case("post"):
  407.                         if(!empty($_POST[$v]and $this->isAction($v))
  408.                             call_user_func(array(&$this$v));
  409.                         break;
  410.  
  411.                     case("get"):
  412.                         if(!empty($_GET[$v]and $this->isAction($v))
  413.                             call_user_func(array(&$this$v));
  414.                         break;
  415.  
  416.                     case("nav"):
  417.                         if($this->PHPShopNav->getNav(== $v and $this->isAction($v))
  418.                             call_user_func(array(&$this$v));
  419.                         elseif($this->isAction('index')) call_user_func(array(&$this'index'));
  420.                         else $this->setError("index","метод не существует");
  421.  
  422.                         break;
  423.  
  424.                 }
  425.             }
  426.         }else $this->setError("action","экшены объявлена неверно");
  427.     }
  428.  
  429.     /**
  430.      * Проверка экшена
  431.      * @param string $method_name имя метода
  432.      * @return bool
  433.      */
  434.     function isAction($method_name{
  435.         if(method_exists($this,$method_name)) return true;
  436.     }
  437.  
  438.     /**
  439.      * Генерация ошибки 404
  440.      */
  441.     function setError404({
  442.  
  443.         // Титл
  444.         $this->title="Ошибка 404  - ".$this->PHPShopSystem->getValue("name");
  445.  
  446.         // Заголовок ошибки
  447.         header("HTTP/1.0 404 Not Found");
  448.         header("Status: 404 Not Found");
  449.  
  450.         // Подключаем шаблон
  451.         $this->parseTemplate($this->getValue('templates.error_page_forma'));
  452.     }
  453. }
  454. ?>

Documentation generated on Mon, 25 Jun 2012 15:09:41 +0400 by phpDocumentor 1.4.3