Example #1
0
 public function exec()
 {
     $db = Core::getDb();
     $user = Core::getUser();
     $template = Template::getInstance();
     $template->append('stylesheets', \Kiki\Config::$kikiPrefix . "/scripts/prettify/prettify.css");
     $q = $db->buildQuery("SELECT id FROM articles a LEFT JOIN objects o ON o.object_id=a.object_id WHERE o.section_id=%d AND ((o.visible=1 AND o.ctime<=now()) OR o.user_id=%d) ORDER BY o.ctime DESC LIMIT 10", $this->instanceId, $user->id());
     $articleIds = $db->getObjectIds($q);
     $articles = array();
     foreach ($articleIds as $articleId) {
         $article = new Article($articleId);
         $articles[] = array('url' => $article->url(), 'title' => $article->title());
     }
     $template->assign('latestArticles', $articles);
     if (preg_match('/^page-([\\d]+)$/', $this->objectId, $matches) && isset($matches[1])) {
         $this->objectId = null;
         $currentPage = $matches[1];
     }
     if (isset($this->objectId) && $this->objectId) {
         $matches = array();
         if (preg_match('/^socialupdate-([\\d]+)$/', $this->objectId, $matches) && isset($matches[1])) {
             $updateId = $matches[1];
             $update = new SocialUpdate($updateId);
             if (!$update->id()) {
                 return;
             }
             $this->status = 200;
             $this->title = \Kiki\Misc::textSummary($update->body(), 50);
             $this->template = 'pages/default';
             $template = new Template('content/socialupdates-single');
             $template->assign('update', $update->templateData());
             $this->content = $template->fetch();
             return;
         }
         $article = new Article(0, $this->objectId);
         if ($article->id() && $article->sectionId() == $this->instanceId && ($article->visible() || $article->userId() == $user->id())) {
             $this->status = 200;
             $this->title = $article->title();
             $this->template = 'pages/default';
             $template = new Template('content/articles-single');
             $GLOBALS['articleAlbumId'] = $article->albumId();
             $template->assign('article', $article->templateData());
             $this->content = $template->fetch();
         } else {
             // $this->template = 'pages/default';
             // $template = new Template( 'content/articles-404' );
             // $this->content = $template->fetch();
             return false;
         }
     } else {
         $section = new \Kiki\Section($this->instanceId);
         $itemsPerPage = 25;
         if (!isset($currentPage)) {
             $currentPage = 1;
         }
         $this->status = 200;
         $this->title = $section->title();
         $this->template = 'pages/default';
         $this->content = null;
         // MultiBanner::articles( $section->id() );
         $article = new Article();
         $update = new SocialUpdate();
         $q = $db->buildQuery("SELECT count(*) FROM objects WHERE type IN ('%s', '%s', '%s', '%s') AND section_id=%d AND ((visible=1 AND ctime<=now()) OR user_id=%d)", 'Article', 'Kiki\\Article', 'SocialUpdate', 'Kiki\\SocialUpdate', $this->instanceId, $user->id());
         $totalPosts = $db->getSingleValue($q);
         $paging = new \Kiki\Paging();
         $paging->setCurrentPage($currentPage);
         $paging->setItemsPerPage($itemsPerPage);
         $paging->setTotalItems($totalPosts);
         $q = $db->buildQuery("SELECT object_id, ctime, type FROM objects WHERE type IN ('%s', '%s', '%s', '%s') AND section_id=%d AND ( (visible=1 AND ctime<=now()) OR user_id=%d) ORDER BY ctime DESC LIMIT %d,%d", 'Article', 'Kiki\\Article', 'SocialUpdate', 'Kiki\\SocialUpdate', $this->instanceId, $user->id(), $paging->firstItem() - 1, $itemsPerPage);
         $rs = $db->query($q);
         while ($o = $db->fetchObject($rs)) {
             switch ($o->type) {
                 case 'Article':
                 case 'Kiki\\Article':
                     $article->reset();
                     $article->setObjectId($o->object_id);
                     $article->load();
                     $template = new Template('content/articles-summary');
                     $template->assign('article', $article->templateData());
                     $this->content .= $template->fetch();
                     break;
                 case 'SocialUpdate':
                 case 'Kiki\\SocialUpdate':
                     $update->reset();
                     $update->setObjectId($o->object_id);
                     $update->load();
                     $template = new Template('content/socialupdates-summary');
                     $template->assign('update', $update->templateData());
                     $this->content .= $template->fetch();
                     break;
                 default:
             }
         }
         $this->content .= $paging->html();
     }
 }
Example #2
0
 $q = "SELECT a.id FROM articles a LEFT JOIN objects o ON o.object_id=a.object_id LEFT JOIN sections s ON s.id=o.section_id WHERE o.section_id=0 OR s.type='pages' ORDER BY s.base_uri ASC, FIELD(a.cname, 'index') ASC";
 $pages = $db->getObjectIds($q);
 echo "<ul>";
 echo "<li>";
 echo "<a href=\"?id=0\"><img src=\"/kiki/img/iconic/black/pen_alt_fill_16x16.png\" alt=\"New\"> " . _("Create a new page") . "</a>\n";
 echo "</li>";
 echo "</ul>";
 echo "<table>\n";
 echo "<thead>\n";
 echo "<tr><th></th><th></th><th></th></th><th colspan=\"2\">URL</th><th>Title</th></tr>\n";
 echo "</thead>\n";
 echo "<tbody>\n";
 if (count($pages)) {
     foreach ($pages as $pageId) {
         $article = new Article($pageId);
         $section = new Section($article->sectionId());
         $class = $article->visible() ? "" : "disabled";
         echo "<tr class=\"{$class}\">\n";
         echo "<td><a href=\"?id=" . $article->id() . "\"><img src=\"/kiki/img/iconic/black/pen_alt_fill_16x16.png\" alt=\"Edit\"></a></td>\n";
         echo "<td><a href=\"" . $article->url() . "\"><img src=\"/kiki/img/iconic/black/magnifying_glass_16x16.png\" alt=\"View\"></a></td>\n";
         echo "<td><a href=\"\"><img src=\"/kiki/img/iconic/black/trash_stroke_16x16.png\" alt=\"Delete\"></a></td>\n";
         if ($section->baseURI()) {
             echo "<td>" . $section->baseURI() . "</td>\n";
             echo "<td>" . $article->cname() . "</td>\n";
         } else {
             echo "<td colspan=\"2\">" . $article->cname() . "</td>\n";
         }
         echo "<td>" . $article->title() . "</td>\n";
         echo "</tr>\n";
     }
 }