Example #1
0
 /**
  * Метод перехода к определенному контроллеру приложения:
  * $controller - имя контроллера.
  * $action     - имя действия контроллера.
  */
 public function go($controller, $action = 'index')
 {
     if (class_exists($controller . 'Controller')) {
         $template = new Template();
         $ctrl_class = $controller . 'Controller';
         $ctrl = new $ctrl_class($this, $template);
         if (@$_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
             if (method_exists($ctrl, $action . 'AjaxAction')) {
                 $this->controller = $controller;
                 $this->action = $action;
                 $result = json_encode(call_user_func(array($ctrl, $action . 'AjaxAction'), $this));
             } else {
                 $result = json_encode(false);
             }
             $template->headerOk();
             $template->headerNoCache();
             $template->headerContentType('text/javascript', 'UTF-8');
             die($result);
         }
         if (method_exists($ctrl, $action . 'Action')) {
             $this->controller = $controller;
             $this->action = $action;
             if (call_user_func(array($ctrl, $action . 'Action'), $this, $template)) {
                 $ctrl->process($template);
             }
             return true;
         }
         throw new Exception('Controller ' . $controller . ' has no ' . $action . ' action!');
     }
     throw new Exception('Application has no ' . $controller . ' controller!');
 }
Example #2
0
 /**
  * Действие просмотр rss ленты всех постов:
  */
 public function rssAllAction(Application $application, Template $template)
 {
     $posts = Blog_BlogPostsModel::GetAllPosts(0, 20, false);
     if ($posts) {
         $rss = new rss('utf-8');
         $rss->channel('Первый канал - Все', 'http://1chan.ru/', 'Новости имиджборд и не только.');
         $rss->language('ru-ru');
         $rss->copyright('Все права пренадлежат вам © 2010');
         $rss->managingEditor('*****@*****.**');
         $rss->category('Все');
         $rss->startRSS();
         foreach ($posts as $key => $post) {
             $title = $post['category'] ? TemplateHelper::BlogCategory($post['category'], 'title') . ' — ' . $post['title'] : $post['title'];
             $rss->itemTitle($title);
             $rss->itemLink('http://' . TemplateHelper::getSiteUrl() . '/news/res/' . $post['id'] . '/');
             $rss->itemDescription($post['link'] ? '<a href="' . $post['link'] . '">' . $post['link'] . '</a><br />' . $post['text'] : $post['text']);
             $rss->itemAuthor('anonymous');
             $rss->itemGuid('http://' . TemplateHelper::getSiteUrl() . '/news/res/' . $post['id'] . '/', true);
             $rss->itemPubDate(date('D, d M Y H:i:s O', $post['created_at']));
             $rss->addItem();
         }
         $result = $rss->RSSdone();
     }
     EventModel::getInstance()->Broadcast('view_rss_all_post');
     $template->headerOk();
     $template->headerContentType('application/rss+xml', 'UTF-8');
     echo $result;
     return false;
 }