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

Source for file news.core.php

Documentation is available at news.core.php

  1. <?php
  2. /**
  3.  * Обработчик новостей
  4.  * @author PHPShop Software
  5.  * @version 1.2
  6.  * @package PHPShopCore
  7.  */
  8. class PHPShopNews extends PHPShopCore {
  9.  
  10.     /**
  11.      * Конструктор
  12.      */
  13.     function PHPShopNews({
  14.         // Имя Бд
  15.         $this->objBase=$GLOBALS['SysValue']['base']['table_name8'];
  16.  
  17.         // Путь для навигации
  18.         $this->objPath="/news/news_";
  19.  
  20.         // Отладка
  21.         $this->debug=false;
  22.  
  23.         // Список экшенов
  24.         $this->action=array("nav"=>"ID","post"=>"news_plus","get"=>"news_del");
  25.         parent::PHPShopCore();
  26.     }
  27.  
  28.     /**
  29.      * Экшен по умолчанию
  30.      */
  31.     function index({
  32.  
  33.         // Выборка данных
  34.         $this->dataArray=parent::getListInfoItem(array('*'),false,array('order'=>'id DESC'));
  35.  
  36.         // 404
  37.         if(!isset($this->dataArray)) return $this->setError404();
  38.  
  39.         if(is_array($this->dataArray))
  40.             foreach($this->dataArray as $row{
  41.  
  42.                 // Определяем переменные
  43.                 $this->set('newsId',$row['id']);
  44.                 $this->set('newsData',$row['date']);
  45.                 $this->set('newsZag',$row['title']);
  46.                 $this->set('newsKratko',$row['description']);
  47.  
  48.  
  49.                 // Подключаем шаблон
  50.                 $this->addToTemplate($this->getValue('templates.main_news_forma'));
  51.             }
  52.  
  53.         // Пагинатор
  54.         $this->setPaginator();
  55.  
  56.         // Мета
  57.         $this->title="Новости - ".$this->PHPShopSystem->getValue("name");
  58.  
  59.         // Подключаем шаблон
  60.         $this->parseTemplate($this->getValue('templates.news_page_list'));
  61.     }
  62.  
  63.  
  64.     /**
  65.      * Пагинация в подробном описании
  66.      * @return string
  67.      */
  68.     function setPaginatorContent({
  69.  
  70.         // Расчет записей
  71.         $curId $this->PHPShopNav->getId();
  72.         $prevId $curId-1;
  73.         $nextId $curId+1;
  74.  
  75.         // Проверка записей
  76.         $PHPShopOrm &new PHPShopOrm($this->objBase);
  77.         $PHPShopOrm->Option['where'' or ';
  78.         $PHPShopOrm->debug $this->debug;
  79.         $PHPShopOrm->sql 'select id from '.$this->objBase.' where id='.$prevId.' or id='.$nextId;
  80.         $row $PHPShopOrm->select();
  81.  
  82.         // Проверка на последнюю запись
  83.         if(count($row== 1$data[0$row;
  84.         else $data $row;
  85.  
  86.         if(is_array($data)) {
  87.  
  88.             if($data[0]['id'== $prevId$navigat='<a href="./ID_'.$prevId.'.html" title="'.$this->getValue('lang.prev_page').'">'.
  89.                         $this->getValue('lang.prev_page').'</a>';
  90.             else $navigat='';
  91.  
  92.             if($data[1]['id'== $nextId$navigat.=' | <a href="./ID_'.$nextId.'.html" title="'.$this->getValue('lang.next_page').'">'.
  93.                         $this->getValue('lang.next_page').'</a>';
  94.             else $navigat.='';
  95.         }
  96.         return $navigat;
  97.     }
  98.  
  99.  
  100.     /**
  101.      * Экшен выборки подробной информации при наличии переменной навигации ID
  102.      * @return string
  103.      */
  104.     function ID({
  105.  
  106.         // Безопасность
  107.         if(!PHPShopSecurity::true_num($this->PHPShopNav->getId())) return $this->setError404();
  108.  
  109.         // Выборка данных
  110.         $row=parent::getFullInfoItem(array('*'),array('id'=>'='.$this->PHPShopNav->getId()));
  111.  
  112.         // 404
  113.         if(!isset($row)) return $this->setError404();
  114.  
  115.         // Определяем переменые
  116.         $this->set('newsData',$row['date']);
  117.         $this->set('newsZag',$row['title']);
  118.         $this->set('newsKratko',$row['description']);
  119.         $this->set('newsPodrob',$row['content']);
  120.  
  121.         // Пагинатор
  122.         $this->set('paginatorContent',$this->setPaginatorContent());
  123.  
  124.         // Подключаем шаблон
  125.         $this->addToTemplate($this->getValue('templates.main_news_forma_full'));
  126.  
  127.         // Мета
  128.         $this->title=$row['title']." - ".$this->PHPShopSystem->getValue("name");
  129.         $this->description=strip_tags($row['description']);
  130.         $this->lastmodified=PHPShopDate::GetUnixTime($row['date']);
  131.  
  132.  
  133.         // Подключаем шаблон
  134.         $this->parseTemplate($this->getValue('templates.news_page_full'));
  135.     }
  136.  
  137.     /**
  138.      * Экшен записи новости при получении $_POST[news_plus]
  139.      */
  140.     function news_plus({
  141.         $mail=PHPShopSecurity::TotalClean($_POST['mail'],3);
  142.  
  143.         switch($_POST['status']{
  144.  
  145.             case 1:
  146.                 $this->write($mail);
  147.                 break;
  148.  
  149.             case 0:
  150.                 $this->del($mail);
  151.                 break;
  152.         }
  153.  
  154.         // Мета
  155.         $this->title="Новости - Подписка - ".$this->PHPShopSystem->getValue("name");
  156.  
  157.         // Подключаем шаблон
  158.         $this->parseTemplate($this->getValue('templates.news_forma_message'));
  159.     }
  160.  
  161.  
  162.     /**
  163.      * Есть ли адрес в базе
  164.      * @param string $mail почта
  165.      * @return bool
  166.      */
  167.     function chek($mail{
  168.         $PHPShopOrm &new PHPShopOrm($this->getValue('base.table_name9'));
  169.         $PHPShopOrm->debug=$this->debug;
  170.         $num=$PHPShopOrm->select(array('id'),array('mail'=>"='$mail'"),false,array('limit'=>1));
  171.         if(empty($num['id'])) return true;
  172.     }
  173.  
  174.     /**
  175.      * Добавление адреса  в БД
  176.      * @param string $mail
  177.      */
  178.     function write($mail{
  179.  
  180.         if(!empty($mail)) {
  181.  
  182.             if($this->chek($mail)) {
  183.                 $PHPShopOrm &new PHPShopOrm($this->getValue('base.table_name9'));
  184.                 $PHPShopOrm->debug=$this->debug;
  185.                 $PHPShopOrm->insert(array('date'=>date("d-m-y"),'mail'=>$mail),$prefix='');
  186.  
  187.  
  188.                 $mes="<FONT style=\"font-size:14px;color:red\">
  189.                     <B>".$this->getValue('lang.good_news_message_1')."</B></FONT><BR>".$this->getValue('lang.good_news_message_2');
  190.             }else {
  191.                 $mes="<FONT style=\"font-size:14px;color:red\">
  192.                     <B>".$this->getValue('lang.bad_news_message_1')."</B></FONT><BR>".$this->getValue('lang.good_news_message_2');
  193.             }
  194.  
  195.         }
  196.  
  197.         else {
  198.             $mes="<FONT style=\"font-size:14px;color:red\">
  199.                     <B>".$this->getValue('lang.bad_news_message_3')."</B></FONT><BR>".$this->getValue('lang.good_news_message_2');
  200.         }
  201.  
  202.         $this->set('mesageText',$mes);
  203.     }
  204.  
  205.     /**
  206.      * Удаление адреса из БД
  207.      * @param string $mail
  208.      */
  209.     function del($mail{
  210.  
  211.         if(!$this->chek($mail)) {
  212.             $PHPShopOrm &new PHPShopOrm($this->getValue('base.table_name9'));
  213.             $PHPShopOrm->debug=$this->debug;
  214.             $PHPShopOrm->delete(array('mail'=>"='$mail'"));
  215.             $mes="<FONT style=\"font-size:14px;color:red\">
  216.                     <B>".$this->getValue('lang.bad_news_message_2')."</B></FONT><BR>".$this->getValue('lang.good_news_message_2');
  217.  
  218.         }else {
  219.             $mes="<FONT style=\"font-size:14px;color:red\">
  220.                     <B>".$this->getValue('lang.bad_news_message_3')."</B></FONT><BR>".$this->getValue('lang.good_news_message_2');
  221.         }
  222.  
  223.         $this->set('mesageText',$mes);
  224.     }
  225.  
  226.  
  227.     /**
  228.      * Экшен удаления подписчика при получении $_GET[news_del]
  229.      */
  230.     function news_del({
  231.  
  232.         // Проверка на безопсность
  233.         $mail=PHPShopSecurity::TotalClean($_GET['mail'],3);
  234.  
  235.         // Удаление записи
  236.         $this->del($mail);
  237.         
  238.         // Мета
  239.         $this->title="Новости - Отписка - ".$this->PHPShopSystem->getValue("name");
  240.  
  241.         // Подключаем шаблон
  242.         $this->parseTemplate($this->getValue('templates.news_forma_message'));
  243.     }
  244. }
  245. ?>

Documentation generated on Thu, 17 Feb 2011 15:58:41 +0300 by phpDocumentor 1.4.3