コード例 #1
0
 /**
  * Display a list of recent comments
  */
 public function tpl_recentcomments($tpl = 'default', $num = 5, $blogs = array('default'), $types = array())
 {
     // check template
     $tpl = helper_plugin_blogtng_tools::getTplFile($tpl, 'recentcomments');
     if ($tpl === false) {
         return false;
     }
     if (!$this->sqlitehelper->ready()) {
         return false;
     }
     // prepare and execute query
     if (count($types)) {
         $types = $this->sqlitehelper->getDB()->quote_and_join($types, ',');
         $tquery = " AND B.source IN ({$types}) ";
     } else {
         $tquery = "";
     }
     $blog_query = '(A.blog = ' . $this->sqlitehelper->getDB()->quote_and_join($blogs, ' OR A.blog = ') . ')';
     $query = "SELECT A.pid as pid, page, title, cid\n                    FROM entries A, comments B\n                   WHERE {$blog_query}\n                     AND A.pid = B.pid\n                     {$tquery}\n                     AND B.status = 'visible'\n                     AND GETACCESSLEVEL(A.page) >= " . AUTH_READ . "\n                ORDER BY B.created DESC\n                   LIMIT " . (int) $num;
     $res = $this->sqlitehelper->getDB()->query($query);
     if (!$this->sqlitehelper->getDB()->res2count($res)) {
         return false;
     }
     // no results found
     $res = $this->sqlitehelper->getDB()->res2arr($res);
     // print all hits using the template
     foreach ($res as $row) {
         /** @var helper_plugin_blogtng_entry $entry */
         $entry = plugin_load('helper', 'blogtng_entry');
         $entry->load_by_pid($row['pid']);
         $comment = $this->comment_by_cid($row['cid']);
         include $tpl;
     }
     return true;
 }
コード例 #2
0
ファイル: tags.php プロジェクト: stupid-beard/plugin-blogtng
 /**
  * Parses query string to a where clause for use in a query
  * in the query string:
  *  - tags are space separated
  *  - prefix + is AND
  *  - prefix - is NOT
  *  - no prefix is OR
  *
  * @param string $tagquery query string to be parsed
  * @return null|string
  */
 public function parse_tag_query($tagquery)
 {
     if (!$tagquery) {
         return null;
     }
     if (!$this->sqlitehelper->ready()) {
         return null;
     }
     $tags = array_map('trim', explode(' ', $tagquery));
     $tag_clauses = array('OR' => array(), 'AND' => array(), 'NOT' => array());
     foreach ($tags as $tag) {
         if ($tag[0] == '+') {
             array_push($tag_clauses['AND'], 'tag = ' . $this->sqlitehelper->getDB()->quote_string(substr($tag, 1)));
         } else {
             if ($tag[0] == '-') {
                 array_push($tag_clauses['NOT'], 'tag != ' . $this->sqlitehelper->getDB()->quote_string(substr($tag, 1)));
             } else {
                 array_push($tag_clauses['OR'], 'tag = ' . $this->sqlitehelper->getDB()->quote_string($tag));
             }
         }
     }
     $tag_clauses = array_map('array_unique', $tag_clauses);
     $where = '';
     if ($tag_clauses['OR']) {
         $where .= '(' . join(' OR ', $tag_clauses['OR']) . ')';
     }
     if ($tag_clauses['AND']) {
         $where .= (!empty($where) ? ' AND ' : '') . join(' AND ', $tag_clauses['AND']);
     }
     if ($tag_clauses['NOT']) {
         $where .= (!empty($where) ? ' AND ' : '') . join(' AND ', $tag_clauses['NOT']);
     }
     return $where;
 }
コード例 #3
0
ファイル: admin.php プロジェクト: stupid-beard/plugin-blogtng
 /**
  * Display the latest comments or entries
  *
  * @author Michael Klier <*****@*****.**>
  * @author hArpanet <*****@*****.**>
  *
  * @param $query
  */
 private function xhtml_latest_items($query)
 {
     $resultset = $query['resultset'];
     printf("<h2 id='{$resultset}_latest'>" . $this->getLang($resultset . '_latest') . '</h2>', $this->getLimitParam($query));
     $this->xhtml_limit_form($query);
     if (!$this->sqlitehelper->ready()) {
         return;
     }
     $count = 'SELECT COUNT(pid) as count ';
     $select = 'SELECT * ';
     if ($resultset == 'entry') {
         $from = 'FROM entries ';
         $where = 'WHERE blog != "" ';
         $itemdisplaycallback = 'xhtml_entry_list';
     } else {
         $from = 'FROM comments ';
         $where = '';
         $itemdisplaycallback = 'xhtml_comment_list';
     }
     $orderby = 'ORDER BY created DESC ';
     $sqlcount = $count . $from . $where;
     $sqlselect = $select . $from . $where . $orderby;
     $limit = $this->getLimitParam($query);
     $offset = $this->getOffsetParam($query);
     $sqlselect .= 'LIMIT ' . $limit;
     if ($offset) {
         $sqlselect .= ' OFFSET ' . $offset;
     }
     $res = $this->sqlitehelper->getDB()->query($sqlcount);
     $count = $this->sqlitehelper->getDB()->res2single($res);
     $resid = $this->sqlitehelper->getDB()->query($sqlselect);
     if (!$resid) {
         return;
     }
     $this->xhtml_show_paginated_result($resid, $query, $itemdisplaycallback, $count, $limit);
 }
コード例 #4
0
ファイル: entry.php プロジェクト: stupid-beard/plugin-blogtng
 /**
  * Gets the adjacent (previous and next) links of a blog entry.
  *
  * @param bool|string $id page id of the entry for which to get said links
  * @return array 2d assoziative array containing page id, title, author and creation date
  *              for both prev and next link
  */
 public function getAdjacentLinks($id = false)
 {
     global $INFO;
     if ($id === false) {
         $id = $INFO['id'];
     }
     //sidebar safe
     $pid = md5(cleanID($id));
     $related = array();
     if (!$this->sqlitehelper->ready()) {
         return $related;
     }
     foreach (array('prev', 'next') as $type) {
         $operator = $type == 'prev' ? '<' : '>';
         $order = $type == 'prev' ? 'DESC' : 'ASC';
         $query = "SELECT A.page AS page, A.title AS title,\n                             A.author AS author, A.created AS created\n                        FROM entries A, entries B\n                       WHERE B.pid = ?\n                         AND A.pid != B.pid\n                         AND A.created {$operator} B.created\n                         AND A.blog = B.blog\n                         AND GETACCESSLEVEL(A.page) >= " . AUTH_READ . "\n                    ORDER BY A.created {$order}\n                       LIMIT 1";
         $res = $this->sqlitehelper->getDB()->query($query, $pid);
         if ($this->sqlitehelper->getDB()->res2count($res) > 0) {
             $result = $this->sqlitehelper->getDB()->res2arr($res);
             $related[$type] = $result[0];
         }
     }
     return $related;
 }