Beispiel #1
0
/**
 * Update array if need be with correct topic.
 *
 * @param    array  $A        Array of articles from db
 * @param    string $tid_list List of child topics of current topic
 */
function fixTopic(&$A, $tid_list)
{
    global $_TABLES, $topic;
    if (!empty($topic)) {
        // This case may happen if a article belongs to the current topic but the default topic for the article is a child  of the current topic.
        $sql = "SELECT t.topic, t.imageurl\n            FROM {$_TABLES['topics']} t, {$_TABLES['topic_assignments']} ta\n            WHERE t.tid = ta.tid\n            AND ta.type = 'article' AND ta.id = '{$A['sid']}' AND ta.tid = '{$topic}'\n            " . COM_getLangSQL('tid', 'AND', 't') . COM_getPermSQL('AND', 0, 2, 't');
        $result = DB_query($sql);
        $nrows = DB_numRows($result);
        if ($nrows > 0) {
            $B = DB_fetchArray($result);
            $A['topic'] = $B['topic'];
            $A['imageurl'] = $B['imageurl'];
        } else {
            // Does not belong to current topic so check inherited
            // Make sure sort order the same as in TOPIC_getTopic or articles with multiple topics might not display in the right topic when clicked
            $sql = "SELECT t.topic, t.imageurl\n                FROM {$_TABLES['topics']} t, {$_TABLES['topic_assignments']} ta\n                WHERE t.tid = ta.tid\n                AND ta.type = 'article' AND ta.id = '{$A['sid']}'\n                AND (ta.tid IN({$tid_list}) AND (ta.inherit = 1 OR (ta.inherit = 0 AND ta.tid = '{$topic}')))\n                " . COM_getLangSQL('tid', 'AND', 't') . COM_getPermSQL('AND', 0, 2, 't') . "\n                ORDER BY ta.tdefault DESC, ta.tid ASC";
            $result = DB_query($sql);
            $nrows = DB_numRows($result);
            if ($nrows > 0) {
                $B = DB_fetchArray($result);
                $A['topic'] = $B['topic'];
                $A['imageurl'] = $B['imageurl'];
            }
        }
    }
}
Beispiel #2
0
/**
* Shows any new information in a block
*
* Return the HTML that shows any new stories, comments, etc
*
* @param    string  $help     Help file for block
* @param    string  $title    Title used in block header
* @param    string  $position Position in which block is being rendered 'left', 'right' or blank (for centre)
* @return   string  Return the HTML that shows any new stories, comments, etc
*
*/
function COM_whatsNewBlock($help = '', $title = '', $position = '')
{
    global $_CONF, $_TABLES, $_USER, $LANG01, $LANG_WHATSNEW, $page, $newstories;
    $retval = COM_startBlock($title, $help, COM_getBlockTemplate('whats_new_block', 'header', $position));
    $topicsql = '';
    if ($_CONF['hidenewstories'] == 0 || $_CONF['hidenewcomments'] == 0 || $_CONF['trackback_enabled'] && $_CONF['hidenewtrackbacks'] == 0) {
        $topicsql = COM_getTopicSql('AND', 0, $_TABLES['stories']);
    }
    if ($_CONF['hidenewstories'] == 0) {
        $archsql = '';
        $archivetid = DB_getItem($_TABLES['topics'], 'tid', "archive_flag=1");
        if (!empty($archivetid)) {
            $archsql = " AND (tid <> '" . addslashes($archivetid) . "')";
        }
        // Find the newest stories
        $sql = "SELECT COUNT(*) AS count FROM {$_TABLES['stories']} WHERE (date >= (date_sub(NOW(), INTERVAL {$_CONF['newstoriesinterval']} SECOND))) AND (date <= NOW()) AND (draft_flag = 0)" . $archsql . COM_getPermSQL('AND') . $topicsql . COM_getLangSQL('sid', 'AND');
        $result = DB_query($sql);
        $A = DB_fetchArray($result);
        $nrows = $A['count'];
        if (empty($title)) {
            $title = DB_getItem($_TABLES['blocks'], 'title', "name='whats_new_block'");
        }
        // Any late breaking news stories?
        $retval .= '<h3>' . $LANG01[99] . '</h3>';
        if ($nrows > 0) {
            $newmsg = COM_formatTimeString($LANG_WHATSNEW['new_string'], $_CONF['newstoriesinterval'], $LANG01[11], $nrows);
            if ($newstories && $page < 2) {
                $retval .= $newmsg . '<br' . XHTML . '>';
            } else {
                $retval .= COM_createLink($newmsg, $_CONF['site_url'] . '/index.php?display=new') . '<br' . XHTML . '>';
            }
        } else {
            $retval .= $LANG01[100] . '<br' . XHTML . '>';
        }
        if ($_CONF['hidenewcomments'] == 0 || $_CONF['trackback_enabled'] && $_CONF['hidenewtrackbacks'] == 0 || $_CONF['hidenewplugins'] == 0) {
            $retval .= '<br' . XHTML . '>';
        }
    }
    if ($_CONF['hidenewcomments'] == 0) {
        // Go get the newest comments
        $retval .= '<h3>' . $LANG01[83] . ' <small>' . COM_formatTimeString($LANG_WHATSNEW['new_last'], $_CONF['newcommentsinterval']) . '</small></h3>';
        $stwhere = '';
        if (!COM_isAnonUser()) {
            $stwhere .= "({$_TABLES['stories']}.owner_id IS NOT NULL AND {$_TABLES['stories']}.perm_owner IS NOT NULL) OR ";
            $stwhere .= "({$_TABLES['stories']}.group_id IS NOT NULL AND {$_TABLES['stories']}.perm_group IS NOT NULL) OR ";
            $stwhere .= "({$_TABLES['stories']}.perm_members IS NOT NULL)";
        } else {
            $stwhere .= "({$_TABLES['stories']}.perm_anon IS NOT NULL)";
        }
        $sql = "SELECT DISTINCT COUNT(*) AS dups, type, {$_TABLES['stories']}.title, {$_TABLES['stories']}.sid, max({$_TABLES['comments']}.date) AS lastdate FROM {$_TABLES['comments']} LEFT JOIN {$_TABLES['stories']} ON (({$_TABLES['stories']}.sid = {$_TABLES['comments']}.sid)" . COM_getPermSQL('AND', 0, 2, $_TABLES['stories']) . " AND ({$_TABLES['stories']}.draft_flag = 0) AND ({$_TABLES['stories']}.commentcode >= 0)" . $topicsql . COM_getLangSQL('sid', 'AND', $_TABLES['stories']) . ") WHERE ({$_TABLES['comments']}.date >= (DATE_SUB(NOW(), INTERVAL {$_CONF['newcommentsinterval']} SECOND))) AND ((({$stwhere}))) GROUP BY {$_TABLES['comments']}.sid,type, {$_TABLES['stories']}.title, {$_TABLES['stories']}.title, {$_TABLES['stories']}.sid ORDER BY 5 DESC LIMIT 15";
        $result = DB_query($sql);
        $nrows = DB_numRows($result);
        if ($nrows > 0) {
            $newcomments = array();
            for ($x = 0; $x < $nrows; $x++) {
                $A = DB_fetchArray($result);
                if ($A['type'] == 'article' || empty($A['type'])) {
                    $url = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $A['sid']) . '#comments';
                }
                $title = COM_undoSpecialChars(stripslashes($A['title']));
                $titletouse = COM_truncate($title, $_CONF['title_trim_length'], '...');
                if ($title != $titletouse) {
                    $attr = array('title' => htmlspecialchars($title));
                } else {
                    $attr = array();
                }
                $acomment = str_replace('$', '&#36;', $titletouse);
                $acomment = str_replace(' ', '&nbsp;', $acomment);
                if ($A['dups'] > 1) {
                    $acomment .= ' [+' . $A['dups'] . ']';
                }
                $newcomments[] = COM_createLink($acomment, $url, $attr);
            }
            $retval .= COM_makeList($newcomments, 'list-new-comments');
        } else {
            $retval .= $LANG01[86] . '<br' . XHTML . '>' . LB;
        }
        if ($_CONF['hidenewplugins'] == 0 || $_CONF['trackback_enabled'] && $_CONF['hidenewtrackbacks'] == 0) {
            $retval .= '<br' . XHTML . '>';
        }
    }
    if ($_CONF['trackback_enabled'] && $_CONF['hidenewtrackbacks'] == 0) {
        $retval .= '<h3>' . $LANG01[114] . ' <small>' . COM_formatTimeString($LANG_WHATSNEW['new_last'], $_CONF['newtrackbackinterval']) . '</small></h3>';
        $sql = "SELECT DISTINCT COUNT(*) AS count,{$_TABLES['stories']}.title,t.sid,max(t.date) AS lastdate FROM {$_TABLES['trackback']} AS t,{$_TABLES['stories']} WHERE (t.type = 'article') AND (t.sid = {$_TABLES['stories']}.sid) AND (t.date >= (DATE_SUB(NOW(), INTERVAL {$_CONF['newtrackbackinterval']} SECOND)))" . COM_getPermSQL('AND', 0, 2, $_TABLES['stories']) . " AND ({$_TABLES['stories']}.draft_flag = 0) AND ({$_TABLES['stories']}.trackbackcode = 0)" . $topicsql . COM_getLangSQL('sid', 'AND', $_TABLES['stories']) . " GROUP BY t.sid, {$_TABLES['stories']}.title ORDER BY lastdate DESC LIMIT 15";
        $result = DB_query($sql);
        $nrows = DB_numRows($result);
        if ($nrows > 0) {
            $newcomments = array();
            for ($i = 0; $i < $nrows; $i++) {
                $A = DB_fetchArray($result);
                $url = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $A['sid']) . '#trackback';
                $title = COM_undoSpecialChars(stripslashes($A['title']));
                $titletouse = COM_truncate($title, $_CONF['title_trim_length'], '...');
                if ($title != $titletouse) {
                    $attr = array('title' => htmlspecialchars($title));
                } else {
                    $attr = array();
                }
                $acomment = str_replace('$', '&#36;', $titletouse);
                $acomment = str_replace(' ', '&nbsp;', $acomment);
                if ($A['count'] > 1) {
                    $acomment .= ' [+' . $A['count'] . ']';
                }
                $newcomments[] = COM_createLink($acomment, $url, $attr);
            }
            $retval .= COM_makeList($newcomments, 'list-new-trackbacks');
        } else {
            $retval .= $LANG01[115] . '<br' . XHTML . '>' . LB;
        }
        if ($_CONF['hidenewplugins'] == 0) {
            $retval .= '<br' . XHTML . '>';
        }
    }
    if ($_CONF['hidenewplugins'] == 0) {
        list($headlines, $smallheadlines, $content) = PLG_getWhatsNew();
        $plugins = count($headlines);
        if ($plugins > 0) {
            for ($i = 0; $i < $plugins; $i++) {
                $retval .= '<h3>' . $headlines[$i] . ' <small>' . $smallheadlines[$i] . '</small></h3>';
                if (is_array($content[$i])) {
                    $retval .= COM_makeList($content[$i], 'list-new-plugins');
                } else {
                    $retval .= $content[$i];
                }
                if ($i + 1 < $plugins) {
                    $retval .= '<br' . XHTML . '>';
                }
            }
        }
    }
    $retval .= COM_endBlock(COM_getBlockTemplate('whats_new_block', 'footer', $position));
    return $retval;
}
Beispiel #3
0
/**
* Display main view (list of years)
*
* Displays an overview of all the years and months, starting with the first
* year for which a story has been posted. Can optionally display a list of
* the stories for the current month at the top of the page.
*
* @param    ref    &$template  reference of the template
* @param    string  $dir_topic current topic
* @return   string             list of all the years in the db
*
*/
function DIR_displayAll(&$template, $dir_topic)
{
    global $_TABLES, $LANG_DIR;
    $retval = '';
    $yearsql = array();
    $yearsql['mysql'] = "SELECT DISTINCT YEAR(date) AS year,date FROM {$_TABLES['stories']} WHERE (draft_flag = 0) AND (date <= NOW())" . COM_getTopicSql('AND') . COM_getPermSql('AND') . COM_getLangSQL('sid', 'AND');
    $ysql = array();
    $ysql['mysql'] = $yearsql['mysql'] . " GROUP BY YEAR(date) ORDER BY date DESC";
    $yresult = DB_query($ysql);
    $numyears = DB_numRows($yresult);
    if ($numyears > 0) {
        for ($i = 0; $i < $numyears; $i++) {
            $Y = DB_fetchArray($yresult);
            $template->set_var('section_title', $Y['year']);
            $retval .= $template->parse('title', 'section-title') . LB;
            $retval .= DIR_displayYear($template, $dir_topic, $Y['year']);
        }
    } else {
        $retval .= $template->parse('message', 'no-articles') . LB;
    }
    return $retval;
}
Beispiel #4
0
 /**
  * Performs search on all stories
  *
  * @return object plugin object
  *
  */
 private function _searchStories()
 {
     global $_TABLES, $_DB_dbms, $LANG09;
     // Make sure the query is SQL safe
     $query = trim(DB_escapeString($this->_query));
     $sql = 'SELECT s.sid AS id, s.title AS title, s.introtext AS description, ';
     $sql .= 'UNIX_TIMESTAMP(s.date) AS date, s.uid AS uid, s.hits AS hits, ';
     $sql .= 'CONCAT(\'/article.php?story=\',s.sid) AS url ';
     $sql .= 'FROM ' . $_TABLES['stories'] . ' AS s, ' . $_TABLES['users'] . ' AS u, ' . $_TABLES['topic_assignments'] . ' AS ta ';
     $sql .= 'WHERE (draft_flag = 0) AND (date <= NOW()) AND (u.uid = s.uid) ';
     $sql .= 'AND ta.type = \'article\' AND ta.id = sid ';
     $sql .= COM_getPermSQL('AND') . COM_getTopicSQL('AND', 0, 'ta') . COM_getLangSQL('sid', 'AND') . ' ';
     if (!empty($this->_topic)) {
         // Retrieve list of inherited topics
         if ($this->_topic == TOPIC_ALL_OPTION) {
             // Stories do not have an all option so just return all stories that meet the requirements and permissions
             //$sql .= "AND (ta.inherit = 1 OR (ta.inherit = 0 AND ta.tid = '".$this->_topic."')) ";
         } else {
             $tid_list = TOPIC_getChildList($this->_topic);
             $sql .= "AND (ta.tid IN({$tid_list}) AND (ta.inherit = 1 OR (ta.inherit = 0 AND ta.tid = '" . $this->_topic . "'))) ";
         }
     }
     if (!empty($this->_author)) {
         $sql .= 'AND (s.uid = \'' . $this->_author . '\') ';
     }
     $search_s = new SearchCriteria('stories', $LANG09[65]);
     $columns = array('title' => 'title', 'introtext', 'bodytext');
     $sql .= $search_s->getDateRangeSQL('AND', 'date', $this->_dateStart, $this->_dateEnd);
     list($sql, $ftsql) = $search_s->buildSearchSQL($this->_keyType, $query, $columns, $sql);
     $sql .= " GROUP BY s.sid";
     $search_s->setSQL($sql);
     $search_s->setFTSQL($ftsql);
     $search_s->setRank(5);
     $search_s->setURLRewrite(true);
     // Search Story Comments
     $sql = 'SELECT c.cid AS id, c.title AS title, c.comment AS description, ';
     $sql .= 'UNIX_TIMESTAMP(c.date) AS date, c.uid AS uid, \'0\' AS hits, ';
     // MSSQL has a problem when concatenating numeric values
     if ($_DB_dbms == 'mssql') {
         $sql .= '\'/comment.php?mode=view&amp;cid=\' + CAST(c.cid AS varchar(10)) AS url ';
     } else {
         $sql .= 'CONCAT(\'/comment.php?mode=view&amp;cid=\',c.cid) AS url ';
     }
     $sql .= 'FROM ' . $_TABLES['users'] . ' AS u, ' . $_TABLES['topic_assignments'] . ' AS ta, ' . $_TABLES['comments'] . ' AS c ';
     $sql .= 'LEFT JOIN ' . $_TABLES['stories'] . ' AS s ON ((s.sid = c.sid) ';
     $sql .= COM_getPermSQL('AND', 0, 2, 's') . COM_getLangSQL('sid', 'AND', 's') . ') ';
     $sql .= 'WHERE (u.uid = c.uid) AND (s.draft_flag = 0) AND (s.commentcode >= 0) AND (s.date <= NOW()) ';
     $sql .= 'AND ta.type = \'article\' AND ta.id = s.sid ' . COM_getTopicSQL('AND', 0, 'ta');
     if (!empty($this->_topic)) {
         if ($this->_topic == TOPIC_ALL_OPTION) {
             // Stories do not have an all option so just return all story comments that meet the requirements and permissions
             //$sql .= "AND (ta.inherit = 1 OR (ta.inherit = 0 AND ta.tid = '".$this->_topic."')) ";
         } else {
             $sql .= "AND (ta.tid IN({$tid_list}) AND (ta.inherit = 1 OR (ta.inherit = 0 AND ta.tid = '" . $this->_topic . "'))) ";
         }
     }
     if (!empty($this->_author)) {
         $sql .= 'AND (c.uid = \'' . $this->_author . '\') ';
     }
     $search_c = new SearchCriteria('comments', array($LANG09[65], $LANG09[66]));
     $columns = array('title' => 'c.title', 'comment');
     $sql .= $search_c->getDateRangeSQL('AND', 'c.date', $this->_dateStart, $this->_dateEnd);
     list($sql, $ftsql) = $search_c->buildSearchSQL($this->_keyType, $query, $columns, $sql);
     $sql .= " GROUP BY id";
     $search_c->setSQL($sql);
     $search_c->setFTSQL($ftsql);
     $search_c->setRank(2);
     return array($search_s, $search_c);
 }
Beispiel #5
0
 /**
  * Returns an array of (
  *   'id'        => $id (string),
  *   'title'     => $title (string),
  *   'uri'       => $uri (string),
  *   'date'      => $date (int: Unix timestamp),
  *   'image_uri' => $image_uri (string)
  * )
  */
 public function getItemsByDate($tid = '', $all_langs = FALSE)
 {
     global $_CONF, $_TABLES;
     $entries = array();
     if (empty(Dataproxy::$startDate) or empty(Dataproxy::$endDate)) {
         return $entries;
     }
     $sql = "SELECT sid, title, UNIX_TIMESTAMP(date) AS day " . "  FROM {$_TABLES['stories']} " . "WHERE (draft_flag = 0) AND (date <= NOW()) " . "  AND (UNIX_TIMESTAMP(date) BETWEEN '" . Dataproxy::$startDate . "' AND '" . Dataproxy::$endDate . "') ";
     if (!empty($tid)) {
         $sql .= "AND (tid = '" . addslashes($tid) . "') ";
     }
     if (!Dataproxy::isRoot()) {
         $sql .= COM_getTopicSql('AND', Dataproxy::uid()) . COM_getPermSql('AND', Dataproxy::uid());
         if (function_exists('COM_getLangSQL') and $all_langs === FALSE) {
             $sql .= COM_getLangSQL('sid', 'AND');
         }
     }
     $result = DB_query($sql);
     if (DB_error()) {
         return $entries;
     }
     while (($A = DB_fetchArray($result, FALSE)) !== FALSE) {
         $entry = array();
         $entry['id'] = stripslashes($A['sid']);
         $entry['title'] = stripslashes($A['title']);
         $entry['uri'] = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . stripslashes($A['sid']));
         $entry['date'] = $A['day'];
         $entry['imageurl'] = FALSE;
         $entries[] = $entry;
     }
     return $entries;
 }
Beispiel #6
0
/**
 * Return new Story comments for the What's New block
 *
 * @param    string $numreturn   If 0 will return results for What's New Block.
 *                               If > 0 will return last X new comments for User Profile.
 * @param    string $uid         ID of the user to return results for. 0 = all users.
 * @return   array list of new comments (dups, type, title, sid, lastdate) or (sid, title, cid, unixdate)
 */
function plugin_getwhatsnewcomment_story($numreturn = 0, $uid = 0)
{
    global $_CONF, $_TABLES;
    $topicsql = COM_getTopicSql('AND', 0, 'ta');
    $stwhere = '';
    if (!COM_isAnonUser()) {
        $stwhere .= "((s.owner_id IS NOT NULL AND s.perm_owner IS NOT NULL) OR ";
        $stwhere .= "(s.group_id IS NOT NULL AND s.perm_group IS NOT NULL) OR ";
        $stwhere .= "(s.perm_members IS NOT NULL))";
    } else {
        $stwhere .= "(s.perm_anon IS NOT NULL)";
    }
    if ($uid > 0) {
        $stwhere .= " AND (c.uid = {$uid})";
    }
    if ($numreturn == 0) {
        $sql['mysql'] = "SELECT DISTINCT COUNT(*) AS dups, c.type, s.title, s.sid, max(c.date) AS lastdate\n            FROM {$_TABLES['comments']} c LEFT JOIN {$_TABLES['stories']} s ON ((s.sid = c.sid) AND type = 'article' " . COM_getPermSQL('AND', 0, 2, 's') . " AND (s.draft_flag = 0) AND (s.commentcode >= 0)" . COM_getLangSQL('sid', 'AND', 's') . ")\n            , {$_TABLES['topic_assignments']} ta\n            WHERE ta.type = 'article' AND ta.id = s.sid AND ta.tdefault = 1 {$topicsql} AND (c.date >= (DATE_SUB(NOW(), INTERVAL {$_CONF['newcommentsinterval']} SECOND))) AND ((({$stwhere})))\n            GROUP BY c.sid, c.type, s.title, s.title, s.sid\n            ORDER BY 5 DESC LIMIT 15";
        $sql['pgsql'] = "SELECT DISTINCT COUNT(*) AS dups, c.type, s.title, s.sid, max(c.date) AS lastdate\n            FROM {$_TABLES['comments']} c LEFT JOIN {$_TABLES['stories']} s ON ((s.sid = c.sid) AND type = 'article' " . COM_getPermSQL('AND', 0, 2, 's') . " AND (s.draft_flag = 0) AND (s.commentcode >= 0)" . COM_getLangSQL('sid', 'AND', 's') . ")\n            , {$_TABLES['topic_assignments']} ta\n            WHERE ta.type = 'article' AND ta.id = s.sid AND ta.tdefault = 1 {$topicsql} AND (c.date >= (NOW()+ INTERVAL '{$_CONF['newcommentsinterval']} SECOND')) AND ((({$stwhere})))\n            GROUP BY c.sid,c.type, s.title, s.title, s.sid\n            ORDER BY 5 DESC LIMIT 15";
    } else {
        $sql = "SELECT s.sid, c.title, cid, UNIX_TIMESTAMP(c.date) AS unixdate\n            FROM {$_TABLES['comments']} c LEFT JOIN {$_TABLES['stories']} s ON ((s.sid = c.sid) AND type = 'article' " . COM_getPermSQL('AND', 0, 2, 's') . " AND (s.draft_flag = 0) AND (s.commentcode >= 0)" . COM_getLangSQL('sid', 'AND', 's') . ")\n            , {$_TABLES['topic_assignments']} ta\n            WHERE ta.type = 'article' AND ta.id = s.sid AND ta.tdefault = 1 {$topicsql} AND ({$stwhere}) ORDER BY unixdate DESC LIMIT {$numreturn}";
    }
    $result = DB_query($sql);
    $nrows = DB_numRows($result);
    if ($nrows > 0) {
        for ($x = 0; $x < $nrows; $x++) {
            $A[] = DB_fetchArray($result);
        }
        return $A;
    }
}
Beispiel #7
0
/**
* Shows any new information in a block
*
* Return the HTML that shows any new stories, comments, etc
*
* @param    string  $help     Help file for block
* @param    string  $title    Title used in block header
* @param    string  $position Position in which block is being rendered 'left', 'right' or blank (for centre)
* @return   string  Return the HTML that shows any new stories, comments, etc
*
*/
function COM_whatsNewBlock($help = '', $title = '', $position = '')
{
    global $_CONF, $_TABLES, $LANG01, $LANG_WHATSNEW, $page, $newstories;
    $retval = COM_startBlock($title, $help, COM_getBlockTemplate('whats_new_block', 'header', $position));
    $topicsql = '';
    if ($_CONF['hidenewstories'] == 0 || $_CONF['hidenewcomments'] == 0 || $_CONF['trackback_enabled'] && $_CONF['hidenewtrackbacks'] == 0) {
        $topicsql = COM_getTopicSql('AND', 0, $_TABLES['stories']);
    }
    if ($_CONF['hidenewstories'] == 0) {
        $archsql = '';
        $archivetid = DB_getItem($_TABLES['topics'], 'tid', "archive_flag=1");
        if (!empty($archivetid)) {
            $archsql = " AND (tid <> '" . addslashes($archivetid) . "')";
        }
        // Find the newest stories
        $sql['mssql'] = "SELECT COUNT(*) AS count FROM {$_TABLES['stories']} WHERE (date >= (date_sub(NOW(), INTERVAL {$_CONF['newstoriesinterval']} SECOND))) AND (date <= NOW()) AND (draft_flag = 0)" . $archsql . COM_getPermSQL('AND') . $topicsql . COM_getLangSQL('sid', 'AND');
        $sql['mysql'] = "SELECT COUNT(*) AS count FROM {$_TABLES['stories']} WHERE (date >= (date_sub(NOW(), INTERVAL {$_CONF['newstoriesinterval']} SECOND))) AND (date <= NOW()) AND (draft_flag = 0)" . $archsql . COM_getPermSQL('AND') . $topicsql . COM_getLangSQL('sid', 'AND');
        $sql['pgsql'] = "SELECT COUNT(*) AS count FROM {$_TABLES['stories']} WHERE (date >= (NOW() - INTERVAL '{$_CONF['newstoriesinterval']} SECOND')) AND (date <= NOW()) AND (draft_flag = 0)" . $archsql . COM_getPermSQL('AND') . $topicsql . COM_getLangSQL('sid', 'AND');
        $result = DB_query($sql);
        $A = DB_fetchArray($result);
        $nrows = $A['count'];
        if (empty($title)) {
            $title = DB_getItem($_TABLES['blocks'], 'title', "name='whats_new_block'");
        }
        // Any late breaking news stories?
        $retval .= '<h3>' . $LANG01[99] . '</h3>';
        if ($nrows > 0) {
            $newmsg = COM_formatTimeString($LANG_WHATSNEW['new_string'], $_CONF['newstoriesinterval'], $LANG01[11], $nrows);
            if ($newstories && $page < 2) {
                $retval .= $newmsg . '<br' . XHTML . '>';
            } else {
                $retval .= COM_createLink($newmsg, $_CONF['site_url'] . '/index.php?display=new') . '<br' . XHTML . '>';
            }
        } else {
            $retval .= $LANG01[100] . '<br' . XHTML . '>';
        }
        if ($_CONF['hidenewcomments'] == 0 || $_CONF['trackback_enabled'] && $_CONF['hidenewtrackbacks'] == 0 || $_CONF['hidenewplugins'] == 0) {
            $retval .= '<br' . XHTML . '>';
        }
    }
    if ($_CONF['hidenewcomments'] == 0) {
        // Go get the newest comments
        $retval .= '<h3>' . $LANG01[83] . ' <small>' . COM_formatTimeString($LANG_WHATSNEW['new_last'], $_CONF['newcommentsinterval']) . '</small></h3>';
        $new_plugin_comments = array();
        $new_plugin_comments = PLG_getWhatsNewComment();
        if (!empty($new_plugin_comments)) {
            // Sort array by element lastdate newest to oldest
            foreach ($new_plugin_comments as $k => $v) {
                $b[$k] = strtolower($v['lastdate']);
            }
            arsort($b);
            foreach ($b as $key => $val) {
                $temp[] = $new_plugin_comments[$key];
            }
            $new_plugin_comments = $temp;
            $newcomments = array();
            $count = 0;
            foreach ($new_plugin_comments as $A) {
                $count .= +1;
                $url = '';
                $info = PLG_getItemInfo($A['type'], $A['sid'], 'url');
                if (!empty($info)) {
                    $url = $info . '#comments';
                }
                // Check to see if url (plugin may not support PLG_getItemInfo
                if (!empty($url)) {
                    $title = COM_undoSpecialChars(stripslashes($A['title']));
                    $titletouse = COM_truncate($title, $_CONF['title_trim_length'], '...');
                    if ($title != $titletouse) {
                        $attr = array('title' => htmlspecialchars($title));
                    } else {
                        $attr = array();
                    }
                    $acomment = str_replace('$', '&#36;', $titletouse);
                    $acomment = str_replace(' ', '&nbsp;', $acomment);
                    if ($A['dups'] > 1) {
                        $acomment .= ' [+' . $A['dups'] . ']';
                    }
                    $newcomments[] = COM_createLink($acomment, $url, $attr);
                    if ($count == 15) {
                        break;
                    }
                }
            }
            $retval .= COM_makeList($newcomments, 'list-new-comments');
        } else {
            $retval .= $LANG01[86] . '<br' . XHTML . '>' . LB;
        }
        if ($_CONF['hidenewplugins'] == 0 || $_CONF['trackback_enabled'] && $_CONF['hidenewtrackbacks'] == 0) {
            $retval .= '<br' . XHTML . '>';
        }
    }
    if ($_CONF['trackback_enabled'] && $_CONF['hidenewtrackbacks'] == 0) {
        $retval .= '<h3>' . $LANG01[114] . ' <small>' . COM_formatTimeString($LANG_WHATSNEW['new_last'], $_CONF['newtrackbackinterval']) . '</small></h3>';
        $sql['mssql'] = "SELECT DISTINCT COUNT(*) AS count,{$_TABLES['stories']}.title,t.sid,max(t.date) AS lastdate FROM {$_TABLES['trackback']} AS t,{$_TABLES['stories']} WHERE (t.type = 'article') AND (t.sid = {$_TABLES['stories']}.sid) AND (t.date >= (DATE_SUB(NOW(), INTERVAL {$_CONF['newtrackbackinterval']} SECOND)))" . COM_getPermSQL('AND', 0, 2, $_TABLES['stories']) . " AND ({$_TABLES['stories']}.draft_flag = 0) AND ({$_TABLES['stories']}.trackbackcode = 0)" . $topicsql . COM_getLangSQL('sid', 'AND', $_TABLES['stories']) . " GROUP BY t.sid, {$_TABLES['stories']}.title ORDER BY lastdate DESC LIMIT 15";
        $sql['mysql'] = "SELECT DISTINCT COUNT(*) AS count,{$_TABLES['stories']}.title,t.sid,max(t.date) AS lastdate FROM {$_TABLES['trackback']} AS t,{$_TABLES['stories']} WHERE (t.type = 'article') AND (t.sid = {$_TABLES['stories']}.sid) AND (t.date >= (DATE_SUB(NOW(), INTERVAL {$_CONF['newtrackbackinterval']} SECOND)))" . COM_getPermSQL('AND', 0, 2, $_TABLES['stories']) . " AND ({$_TABLES['stories']}.draft_flag = 0) AND ({$_TABLES['stories']}.trackbackcode = 0)" . $topicsql . COM_getLangSQL('sid', 'AND', $_TABLES['stories']) . " GROUP BY t.sid, {$_TABLES['stories']}.title ORDER BY lastdate DESC LIMIT 15";
        $sql['pgsql'] = "SELECT DISTINCT COUNT(*) AS count,{$_TABLES['stories']}.title,t.sid,max(t.date) AS lastdate FROM {$_TABLES['trackback']} AS t,{$_TABLES['stories']} WHERE (t.type = 'article') AND (t.sid = {$_TABLES['stories']}.sid) AND (t.date >= (NOW()+ INTERVAL '{$_CONF['newtrackbackinterval']} SECOND'))" . COM_getPermSQL('AND', 0, 2, $_TABLES['stories']) . " AND ({$_TABLES['stories']}.draft_flag = 0) AND ({$_TABLES['stories']}.trackbackcode = 0)" . $topicsql . COM_getLangSQL('sid', 'AND', $_TABLES['stories']) . " GROUP BY t.sid, {$_TABLES['stories']}.title ORDER BY lastdate DESC LIMIT 15";
        $result = DB_query($sql);
        $nrows = DB_numRows($result);
        if ($nrows > 0) {
            $newcomments = array();
            for ($i = 0; $i < $nrows; $i++) {
                $A = DB_fetchArray($result);
                $url = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $A['sid']) . '#trackback';
                $title = COM_undoSpecialChars(stripslashes($A['title']));
                $titletouse = COM_truncate($title, $_CONF['title_trim_length'], '...');
                if ($title != $titletouse) {
                    $attr = array('title' => htmlspecialchars($title));
                } else {
                    $attr = array();
                }
                $acomment = str_replace('$', '&#36;', $titletouse);
                $acomment = str_replace(' ', '&nbsp;', $acomment);
                if ($A['count'] > 1) {
                    $acomment .= ' [+' . $A['count'] . ']';
                }
                $newcomments[] = COM_createLink($acomment, $url, $attr);
            }
            $retval .= COM_makeList($newcomments, 'list-new-trackbacks');
        } else {
            $retval .= $LANG01[115] . '<br' . XHTML . '>' . LB;
        }
        if ($_CONF['hidenewplugins'] == 0) {
            $retval .= '<br' . XHTML . '>';
        }
    }
    if ($_CONF['hidenewplugins'] == 0) {
        list($headlines, $smallheadlines, $content) = PLG_getWhatsNew();
        $plugins = count($headlines);
        if ($plugins > 0) {
            for ($i = 0; $i < $plugins; $i++) {
                $retval .= '<h3>' . $headlines[$i] . ' <small>' . $smallheadlines[$i] . '</small></h3>';
                if (is_array($content[$i])) {
                    $retval .= COM_makeList($content[$i], 'list-new-plugins');
                } else {
                    $retval .= $content[$i];
                }
                if ($i + 1 < $plugins) {
                    $retval .= '<br' . XHTML . '>';
                }
            }
        }
    }
    $retval .= COM_endBlock(COM_getBlockTemplate('whats_new_block', 'footer', $position));
    return $retval;
}
Beispiel #8
0
 /**
  * Performs search on all stories
  *
  * @access private
  * @return object plugin object
  *
  */
 function _searchStories()
 {
     global $_TABLES, $_DB_dbms, $LANG09;
     // Make sure the query is SQL safe
     $query = trim(addslashes($this->_query));
     $sql = 'SELECT s.sid AS id, s.title AS title, s.introtext AS description, ';
     $sql .= 'UNIX_TIMESTAMP(s.date) AS date, s.uid AS uid, s.hits AS hits, ';
     $sql .= 'CONCAT(\'/article.php?story=\',s.sid) AS url ';
     $sql .= 'FROM ' . $_TABLES['stories'] . ' AS s, ' . $_TABLES['users'] . ' AS u ';
     $sql .= 'WHERE (draft_flag = 0) AND (date <= NOW()) AND (u.uid = s.uid) ';
     $sql .= COM_getPermSQL('AND') . COM_getTopicSQL('AND') . COM_getLangSQL('sid', 'AND') . ' ';
     if (!empty($this->_topic)) {
         $sql .= 'AND (s.tid = \'' . $this->_topic . '\') ';
     }
     if (!empty($this->_author)) {
         $sql .= 'AND (s.uid = \'' . $this->_author . '\') ';
     }
     $search_s = new SearchCriteria('stories', $LANG09[65]);
     $columns = array('title' => 'title', 'introtext', 'bodytext');
     $sql .= $search_s->getDateRangeSQL('AND', 'date', $this->_dateStart, $this->_dateEnd);
     list($sql, $ftsql) = $search_s->buildSearchSQL($this->_keyType, $query, $columns, $sql);
     $search_s->setSQL($sql);
     $search_s->setFTSQL($ftsql);
     $search_s->setRank(5);
     $search_s->setURLRewrite(true);
     // Search Story Comments
     $sql = 'SELECT c.cid AS id, c.title AS title, c.comment AS description, ';
     $sql .= 'UNIX_TIMESTAMP(c.date) AS date, c.uid AS uid, ';
     // MSSQL has a problem when concatenating numeric values
     if ($_DB_dbms == 'mssql') {
         $sql .= '\'/comment.php?mode=view&amp;cid=\' + CAST(c.cid AS varchar(10)) AS url ';
     } else {
         $sql .= 'CONCAT(\'/comment.php?mode=view&amp;cid=\',c.cid) AS url ';
     }
     $sql .= 'FROM ' . $_TABLES['users'] . ' AS u, ' . $_TABLES['comments'] . ' AS c ';
     $sql .= 'LEFT JOIN ' . $_TABLES['stories'] . ' AS s ON ((s.sid = c.sid) ';
     $sql .= COM_getPermSQL('AND', 0, 2, 's') . COM_getTopicSQL('AND', 0, 's') . COM_getLangSQL('sid', 'AND', 's') . ') ';
     $sql .= 'WHERE (u.uid = c.uid) AND (s.draft_flag = 0) AND (s.commentcode >= 0) AND (s.date <= NOW()) ';
     if (!empty($this->_topic)) {
         $sql .= 'AND (s.tid = \'' . $this->_topic . '\') ';
     }
     if (!empty($this->_author)) {
         $sql .= 'AND (c.uid = \'' . $this->_author . '\') ';
     }
     $search_c = new SearchCriteria('comments', array($LANG09[65], $LANG09[66]));
     $columns = array('title' => 'c.title', 'comment');
     $sql .= $search_c->getDateRangeSQL('AND', 'c.date', $this->_dateStart, $this->_dateEnd);
     list($sql, $ftsql) = $search_c->buildSearchSQL($this->_keyType, $query, $columns, $sql);
     $search_c->setSQL($sql);
     $search_c->setFTSQL($ftsql);
     $search_c->setRank(2);
     return array($search_s, $search_c);
 }
Beispiel #9
0
function fncList()
{
    global $_CONF;
    global $_TABLES;
    global $LANG_ADMIN;
    global $LANG09;
    global $LANG28;
    global $LANG_USERBOX_ADMIN;
    global $LANG_USERBOX;
    global $_USERBOX_CONF;
    $table = $_TABLES['USERBOX_base'];
    $table1 = $_TABLES['users'];
    require_once $_CONF['path_system'] . 'lib-admin.php';
    $retval = '';
    $retval .= COM_startBlock($LANG_USERBOX['list']);
    //MENU1:管理画面
    $menu_arr = array();
    if ($_USERBOX_CONF['hide_whatsnew'] == 'modified') {
        $datecolumn = 'modified';
    } else {
        $datecolumn = 'created';
    }
    //ヘッダ:編集~
    $header_arr[] = array('text' => $LANG28['2'], 'field' => 'id', 'sort' => true);
    $header_arr[] = array('text' => $LANG28['3'], 'field' => 'username', 'sort' => username);
    $header_arr[] = array('text' => $LANG_USERBOX_ADMIN[$datecolumn], 'field' => $datecolumn, 'sort' => true);
    $header_arr[] = array('text' => $LANG28['4'], 'field' => 'fullname', 'sort' => fullname);
    //
    $text_arr = array('has_menu' => true, 'has_extras' => true, 'form_url' => $_CONF['site_url'] . "/" . THIS_SCRIPT);
    //kokokara
    $sql = "SELECT ";
    $sql .= " id";
    $sql .= " ,draft_flag";
    $sql .= " ,UNIX_TIMESTAMP(udatetime) AS udatetime";
    $sql .= " ,orderno";
    $sql .= " ,UNIX_TIMESTAMP(" . $datecolumn . ") AS " . $datecolumn;
    $sql .= " ,t1.username";
    $sql .= " ,t1.fullname";
    $sql .= " FROM ";
    $sql .= " {$table} AS t";
    $sql .= " ,{$table1} AS t1";
    $sql .= " WHERE ";
    $sql .= " t.id=t1.uid";
    $sql .= COM_getLangSQL('username', 'AND', 't1') . LB;
    //管理者の時,下書データも含む
    //if ( SEC_hasRights('userbox.admin')) {
    //}else{
    $sql .= " AND draft_flag=0" . LB;
    //}
    //アクセス権のないデータ はのぞく
    $sql .= COM_getPermSql('AND');
    //公開日以前のデータはのぞく
    $sql .= " AND (released <= NOW())";
    //公開終了日を過ぎたデータはのぞく
    $sql .= " AND (expired=0 OR expired > NOW())";
    //
    $query_arr = array('table' => " {$table} AS t ,{$table1} AS t1", 'sql' => $sql, 'query_fields' => array('id', 'username', 'fullname', 'draft_flag'), 'default_filter' => $exclude);
    //デフォルトソート項目:
    $defsort_arr = array('field' => 'id', 'direction' => 'ASC');
    //List 取得
    //ADMIN_list($component, $fieldfunction, $header_arr, $text_arr,
    //       $query_arr, $menu_arr, $defsort_arr, $filter = '', $extra = '', $options = '')
    $retval .= ADMIN_list('userbox', "fncGetListField", $header_arr, $text_arr, $query_arr, $defsort_arr);
    $retval .= COM_endBlock();
    return $retval;
}
Beispiel #10
0
 /**
  * Returns an array of (
  *   'id'        => $id (string),
  *   'title'     => $title (string),
  *   'uri'       => $uri (string),
  *   'date'      => $date (int: Unix timestamp),
  *   'image_uri' => $image_uri (string)
  * )
  */
 public function getItemsByDate($tid = '', $all_langs = FALSE)
 {
     global $_CONF, $_TABLES;
     $retval = array();
     if (empty(Dataproxy::$startDate) or empty(Dataproxy::$endDate)) {
         return $retval;
     }
     // Collects sids
     $sql = "SELECT id " . "  FROM {$_TABLES['topic_assignments']} " . "WHERE (type= 'article') AND (tdefault = 1) ";
     if (!empty($tid)) {
         $sql .= "  AND (tid = '" . addslashes($tid) . "') ";
     }
     if (!Dataproxy::isRoot()) {
         $sql .= COM_getTopicSql('AND', Dataproxy::uid());
     }
     $result = DB_query($sql);
     if (DB_error()) {
         return $retval;
     } else {
         $sids = array();
         while (($A = DB_fetchArray($result, FALSE)) !== FALSE) {
             $sids[] = addslashes($A['id']);
         }
         if (count($sids) === 0) {
             return $retval;
         }
     }
     $sql = "SELECT sid, title, UNIX_TIMESTAMP(date) AS day " . "  FROM {$_TABLES['stories']} " . "WHERE (draft_flag = 0) AND (date <= NOW()) " . "  AND (UNIX_TIMESTAMP(date) BETWEEN '" . Dataproxy::$startDate . "' AND '" . Dataproxy::$endDate . "') " . "  AND (sid IN ('" . implode("', '", $sids) . "')) ";
     if (!Dataproxy::isRoot()) {
         $sql .= COM_getPermSql('AND', Dataproxy::uid());
         if ($all_langs === FALSE) {
             $sql .= COM_getLangSQL('sid', 'AND');
         }
     }
     $sql .= " ORDER BY date DESC ";
     $result = DB_query($sql);
     if (DB_error()) {
         return $retval;
     }
     while (($A = DB_fetchArray($result, FALSE)) !== FALSE) {
         $entry = array();
         $entry['id'] = stripslashes($A['sid']);
         $entry['title'] = stripslashes($A['title']);
         $entry['uri'] = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . stripslashes($A['sid']));
         $entry['date'] = $A['day'];
         $entry['imageurl'] = FALSE;
         $retval[] = $entry;
     }
     return $retval;
 }
Beispiel #11
0
/**
* Display main view (list of years)
*
* Displays an overview of all the years and months, starting with the first
* year for which a story has been posted. Can optionally display a list of
* the stories for the current month at the top of the page.
*
* @param    string  $topic                  current topic
* @param    boolean $list_current_month     true = list stories f. current month
* @return   string                          list of all the years in the db
*
*/
function DIR_displayAll($topic, $list_current_month = false)
{
    global $_TABLES, $LANG_DIR;
    $retval = '';
    if ($list_current_month) {
        $currentyear = date('Y', time());
        $currentmonth = date('n', time());
        $retval .= DIR_displayMonth($topic, $currentyear, $currentmonth);
        $retval .= '<hr' . XHTML . '>' . LB;
    }
    $retval .= '<div><h1 style="display:inline">' . $LANG_DIR['title'] . '</h1> ' . DIR_topicList($topic) . '</div>' . LB;
    $yearsql = array();
    $yearsql['mysql'] = "SELECT DISTINCT YEAR(date) AS year,date FROM {$_TABLES['stories']} WHERE (draft_flag = 0) AND (date <= NOW())" . COM_getTopicSql('AND') . COM_getPermSql('AND') . COM_getLangSQL('sid', 'AND');
    $yearsql['mssql'] = "SELECT YEAR(date) AS year FROM {$_TABLES['stories']} WHERE (draft_flag = 0) AND (date <= NOW())" . COM_getTopicSql('AND') . COM_getPermSql('AND') . COM_getLangSQL('sid', 'AND');
    $yearsql['pgsql'] = "SELECT EXTRACT( YEAR from date) AS year FROM {$_TABLES['stories']} WHERE (draft_flag = 0) AND (date <= NOW())" . COM_getTopicSql('AND') . COM_getPermSql('AND') . COM_getLangSQL('sid', 'AND');
    $ysql = array();
    $ysql['mysql'] = $yearsql['mysql'] . " GROUP BY YEAR(date) ORDER BY date DESC";
    $ysql['mssql'] = $yearsql['mssql'] . " GROUP BY YEAR(date) ORDER BY YEAR(date) DESC";
    $ysql['pgsql'] = $yearsql['pgsql'] . " GROUP BY year,date ORDER BY year DESC";
    $yresult = DB_query($ysql);
    $numyears = DB_numRows($yresult);
    for ($i = 0; $i < $numyears; $i++) {
        $Y = DB_fetchArray($yresult);
        $retval .= DIR_displayYear($topic, $Y['year']);
    }
    return $retval;
}
Beispiel #12
0
/**
* Return new Story comments for the What's New block
*
* @param    string  $numreturn  If 0 will return results for What's New Block. 
*                               If > 0 will return last X new comments for User Profile.
* @param    string  $uid        ID of the user to return results for. 0 = all users.
* @return   array list of new comments (dups, type, title, sid, lastdate) or (sid, title, cid, unixdate)
*
*/
function plugin_getwhatsnewcomment_story($numreturn = 0, $uid = 0)
{
    global $_CONF, $_TABLES;
    $topicsql = COM_getTopicSql('AND', 0, $_TABLES['stories']);
    $stwhere = '';
    if (!COM_isAnonUser()) {
        $stwhere .= "(({$_TABLES['stories']}.owner_id IS NOT NULL AND {$_TABLES['stories']}.perm_owner IS NOT NULL) OR ";
        $stwhere .= "({$_TABLES['stories']}.group_id IS NOT NULL AND {$_TABLES['stories']}.perm_group IS NOT NULL) OR ";
        $stwhere .= "({$_TABLES['stories']}.perm_members IS NOT NULL))";
    } else {
        $stwhere .= "({$_TABLES['stories']}.perm_anon IS NOT NULL)";
    }
    if ($uid > 0) {
        $stwhere .= " AND ({$_TABLES['comments']}.uid = {$uid})";
    }
    if ($numreturn == 0) {
        $sql['mssql'] = "SELECT DISTINCT COUNT(*) AS dups, type, {$_TABLES['stories']}.title, {$_TABLES['stories']}.sid, max({$_TABLES['comments']}.date) AS lastdate FROM {$_TABLES['comments']} LEFT JOIN {$_TABLES['stories']} ON (({$_TABLES['stories']}.sid = {$_TABLES['comments']}.sid) AND type = 'article' " . COM_getPermSQL('AND', 0, 2, $_TABLES['stories']) . " AND ({$_TABLES['stories']}.draft_flag = 0) AND ({$_TABLES['stories']}.commentcode >= 0)" . $topicsql . COM_getLangSQL('sid', 'AND', $_TABLES['stories']) . ") WHERE ({$_TABLES['comments']}.date >= (DATE_SUB(NOW(), INTERVAL {$_CONF['newcommentsinterval']} SECOND))) AND ((({$stwhere}))) GROUP BY {$_TABLES['comments']}.sid,type, {$_TABLES['stories']}.title, {$_TABLES['stories']}.title, {$_TABLES['stories']}.sid ORDER BY 5 DESC LIMIT 15";
        $sql['mysql'] = "SELECT DISTINCT COUNT(*) AS dups, type, {$_TABLES['stories']}.title, {$_TABLES['stories']}.sid, max({$_TABLES['comments']}.date) AS lastdate FROM {$_TABLES['comments']} LEFT JOIN {$_TABLES['stories']} ON (({$_TABLES['stories']}.sid = {$_TABLES['comments']}.sid) AND type = 'article' " . COM_getPermSQL('AND', 0, 2, $_TABLES['stories']) . " AND ({$_TABLES['stories']}.draft_flag = 0) AND ({$_TABLES['stories']}.commentcode >= 0)" . $topicsql . COM_getLangSQL('sid', 'AND', $_TABLES['stories']) . ") WHERE ({$_TABLES['comments']}.date >= (DATE_SUB(NOW(), INTERVAL {$_CONF['newcommentsinterval']} SECOND))) AND ((({$stwhere}))) GROUP BY {$_TABLES['comments']}.sid,type, {$_TABLES['stories']}.title, {$_TABLES['stories']}.title, {$_TABLES['stories']}.sid ORDER BY 5 DESC LIMIT 15";
        $sql['pgsql'] = "SELECT DISTINCT COUNT(*) AS dups, type, {$_TABLES['stories']}.title, {$_TABLES['stories']}.sid, max({$_TABLES['comments']}.date) AS lastdate FROM {$_TABLES['comments']} LEFT JOIN {$_TABLES['stories']} ON (({$_TABLES['stories']}.sid = {$_TABLES['comments']}.sid) AND type = 'article' " . COM_getPermSQL('AND', 0, 2, $_TABLES['stories']) . " AND ({$_TABLES['stories']}.draft_flag = 0) AND ({$_TABLES['stories']}.commentcode >= 0)" . $topicsql . COM_getLangSQL('sid', 'AND', $_TABLES['stories']) . ") WHERE ({$_TABLES['comments']}.date >= (NOW()+ INTERVAL '{$_CONF['newcommentsinterval']} SECOND')) AND ((({$stwhere}))) GROUP BY {$_TABLES['comments']}.sid,type, {$_TABLES['stories']}.title, {$_TABLES['stories']}.title, {$_TABLES['stories']}.sid ORDER BY 5 DESC LIMIT 15";
    } else {
        $sql = "SELECT {$_TABLES['stories']}.sid, {$_TABLES['comments']}.title, cid, UNIX_TIMESTAMP({$_TABLES['comments']}.date) AS unixdate FROM {$_TABLES['comments']} LEFT JOIN {$_TABLES['stories']} ON (({$_TABLES['stories']}.sid = {$_TABLES['comments']}.sid) AND type = 'article' " . COM_getPermSQL('AND', 0, 2, $_TABLES['stories']) . " AND ({$_TABLES['stories']}.draft_flag = 0) AND ({$_TABLES['stories']}.commentcode >= 0)" . $topicsql . COM_getLangSQL('sid', 'AND', $_TABLES['stories']) . ") WHERE ({$stwhere}) ORDER BY unixdate DESC LIMIT {$numreturn}";
    }
    $result = DB_query($sql);
    $nrows = DB_numRows($result);
    if ($nrows > 0) {
        for ($x = 0; $x < $nrows; $x++) {
            $A[] = DB_fetchArray($result);
        }
        return $A;
    }
}
/**
 * Shows any new information in a block
 * Return the HTML that shows any new stories, comments, etc
 *
 * @param    string $help     Help file for block
 * @param    string $title    Title used in block header
 * @param    string $position Position in which block is being rendered 'left', 'right' or blank (for centre)
 * @return   string           Return the HTML that shows any new stories, comments, etc
 */
function COM_whatsNewBlock($help = '', $title = '', $position = '')
{
    global $_CONF, $_TABLES, $LANG01, $LANG_WHATSNEW;
    if ($_CONF['whatsnew_cache_time'] > 0) {
        $cacheInstance = 'whatsnew__' . CACHE_security_hash() . '__' . $_CONF['theme'];
        $retval = CACHE_check_instance($cacheInstance);
        if ($retval) {
            $lu = CACHE_get_instance_update($cacheInstance);
            $now = time();
            if ($now - $lu < $_CONF['whatsnew_cache_time']) {
                return $retval;
            }
        }
    }
    $retval = COM_startBlock($title, $help, COM_getBlockTemplate('whats_new_block', 'header', $position));
    $topicSql = '';
    if ($_CONF['hidenewstories'] == 0 || $_CONF['hidenewcomments'] == 0 || $_CONF['trackback_enabled'] && $_CONF['hidenewtrackbacks'] == 0) {
        $topicSql = COM_getTopicSQL('AND', 0, 'ta');
    }
    if ($_CONF['hidenewstories'] == 0) {
        $where_sql = " AND ta.type = 'article' AND ta.id = sid";
        $archiveTid = DB_getItem($_TABLES['topics'], 'tid', "archive_flag=1");
        if (!empty($archiveTid)) {
            $where_sql .= " AND (ta.tid <> '{$archiveTid}')";
        }
        // Find the newest stories
        $sql['mysql'] = "SELECT sid, title FROM {$_TABLES['stories']}, {$_TABLES['topic_assignments']} ta\n            WHERE (date >= (date_sub(NOW(), INTERVAL {$_CONF['newstoriesinterval']} SECOND))) AND (date <= NOW()) AND (draft_flag = 0)" . $where_sql . COM_getPermSQL('AND') . $topicSql . COM_getLangSQL('sid', 'AND') . "\n            GROUP BY sid, title, date ORDER BY date DESC";
        $sql['pgsql'] = "SELECT sid, title FROM {$_TABLES['stories']}, {$_TABLES['topic_assignments']} ta\n            WHERE (date >= (NOW() - INTERVAL '{$_CONF['newstoriesinterval']} SECOND')) AND (date <= NOW()) AND (draft_flag = 0)" . $where_sql . COM_getPermSQL('AND') . $topicSql . COM_getLangSQL('sid', 'AND') . "\n            GROUP BY sid, title, date ORDER BY date DESC";
        $result = DB_query($sql);
        $numRows = DB_numRows($result);
        if (empty($title)) {
            $title = DB_getItem($_TABLES['blocks'], 'title', "name='whats_new_block'");
        }
        // Any late breaking news stories?
        $retval .= '<h3>' . $LANG01[99] . ' <small>' . COM_formatTimeString($LANG_WHATSNEW['new_last'], $_CONF['newstoriesinterval']) . '</small></h3>';
        if ($numRows > 0) {
            $newArticles = array();
            for ($x = 0; $x < $numRows; $x++) {
                $A = DB_fetchArray($result);
                $url = COM_buildURL($_CONF['site_url'] . '/article.php?story=' . $A['sid']);
                $title = COM_undoSpecialChars(stripslashes($A['title']));
                $titleToUse = COM_truncate($title, $_CONF['title_trim_length'], '...');
                if ($title != $titleToUse) {
                    $attr = array('title' => htmlspecialchars($title));
                } else {
                    $attr = array();
                }
                $anchorText = str_replace('$', '&#36;', $titleToUse);
                $anchorText = str_replace(' ', '&nbsp;', $anchorText);
                $newArticles[] = COM_createLink($anchorText, $url, $attr);
            }
            $retval .= COM_makeList($newArticles, 'list-new-plugins');
        } else {
            $retval .= $LANG01[100] . '<br' . XHTML . '>' . LB;
            // No new stories
        }
        if ($_CONF['hidenewcomments'] == 0 || $_CONF['hidenewplugins'] == 0 || $_CONF['trackback_enabled'] && $_CONF['hidenewtrackbacks'] == 0) {
            $retval .= '<div class="divider-whats-new"></div>';
        }
    }
    if ($_CONF['hidenewcomments'] == 0) {
        // Go get the newest comments
        $retval .= '<h3>' . $LANG01[83] . ' <small>' . COM_formatTimeString($LANG_WHATSNEW['new_last'], $_CONF['newcommentsinterval']) . '</small></h3>';
        $new_plugin_comments = PLG_getWhatsNewComment();
        if (!empty($new_plugin_comments)) {
            // Sort array by element lastdate newest to oldest
            foreach ($new_plugin_comments as $k => $v) {
                $b[$k] = strtolower($v['lastdate']);
            }
            arsort($b);
            $temp = array();
            foreach ($b as $key => $val) {
                $temp[] = $new_plugin_comments[$key];
            }
            $new_plugin_comments = $temp;
            $newComments = array();
            $count = 0;
            foreach ($new_plugin_comments as $A) {
                $count .= +1;
                $url = '';
                $info = PLG_getItemInfo($A['type'], $A['sid'], 'url');
                if (!empty($info)) {
                    $url = $info . '#comments';
                }
                // Check to see if url (plugin may not support PLG_getItemInfo
                if (!empty($url)) {
                    $title = COM_undoSpecialChars(stripslashes($A['title']));
                    $titleToUse = COM_truncate($title, $_CONF['title_trim_length'], '...');
                    if ($title != $titleToUse) {
                        $attr = array('title' => htmlspecialchars($title));
                    } else {
                        $attr = array();
                    }
                    $anchorComment = str_replace('$', '&#36;', $titleToUse);
                    $anchorComment = str_replace(' ', '&nbsp;', $anchorComment);
                    if ($A['dups'] > 1) {
                        $anchorComment .= ' [+' . $A['dups'] . ']';
                    }
                    $newComments[] = COM_createLink($anchorComment, $url, $attr);
                    if ($count == 15) {
                        break;
                    }
                }
            }
            $retval .= COM_makeList($newComments, 'list-new-comments');
        } else {
            $retval .= $LANG01[86] . '<br' . XHTML . '>' . LB;
        }
        if ($_CONF['hidenewplugins'] == 0 || $_CONF['trackback_enabled'] && $_CONF['hidenewtrackbacks'] == 0) {
            $retval .= '<div class="divider-whats-new"></div>';
        }
    }
    if ($_CONF['trackback_enabled'] && $_CONF['hidenewtrackbacks'] == 0) {
        $retval .= '<h3>' . $LANG01[114] . ' <small>' . COM_formatTimeString($LANG_WHATSNEW['new_last'], $_CONF['newtrackbackinterval']) . '</small></h3>';
        $sql['mysql'] = "SELECT DISTINCT COUNT(*) AS count,s.title,t.sid,max(t.date) AS lastdate\n            FROM {$_TABLES['trackback']} AS t, {$_TABLES['stories']} s, {$_TABLES['topic_assignments']} ta\n            WHERE ta.type = 'article' AND ta.id = s.sid AND (t.type = 'article') AND (t.sid = s.sid) AND (t.date >= (DATE_SUB(NOW(), INTERVAL {$_CONF['newtrackbackinterval']} SECOND)))" . COM_getPermSQL('AND', 0, 2, 's') . " AND (s.draft_flag = 0) AND (s.trackbackcode = 0)" . $topicSql . COM_getLangSQL('sid', 'AND', 's') . "\n            GROUP BY t.sid, s.title\n            ORDER BY lastdate DESC LIMIT 15";
        $sql['pgsql'] = "SELECT DISTINCT COUNT(*) AS count,s.title,t.sid,max(t.date) AS lastdate\n            FROM {$_TABLES['trackback']} AS t, {$_TABLES['stories']} s, {$_TABLES['topic_assignments']} ta\n            WHERE ta.type = 'article' AND ta.id = s.sid AND (t.type = 'article') AND (t.sid = s.sid) AND (t.date >= (NOW()+ INTERVAL '{$_CONF['newtrackbackinterval']} SECOND'))" . COM_getPermSQL('AND', 0, 2, 's') . " AND (s.draft_flag = 0) AND (s.trackbackcode = 0)" . $topicSql . COM_getLangSQL('sid', 'AND', 's') . "\n            GROUP BY t.sid, s.title\n            ORDER BY lastdate DESC LIMIT 15";
        $result = DB_query($sql);
        $numRows = DB_numRows($result);
        if ($numRows > 0) {
            $newComments = array();
            for ($i = 0; $i < $numRows; $i++) {
                $A = DB_fetchArray($result);
                $url = COM_buildURL($_CONF['site_url'] . '/article.php?story=' . $A['sid']) . '#trackback';
                $title = COM_undoSpecialChars(stripslashes($A['title']));
                $titleToUse = COM_truncate($title, $_CONF['title_trim_length'], '...');
                if ($title != $titleToUse) {
                    $attr = array('title' => htmlspecialchars($title));
                } else {
                    $attr = array();
                }
                $anchorComment = str_replace('$', '&#36;', $titleToUse);
                $anchorComment = str_replace(' ', '&nbsp;', $anchorComment);
                if ($A['count'] > 1) {
                    $anchorComment .= ' [+' . $A['count'] . ']';
                }
                $newComments[] = COM_createLink($anchorComment, $url, $attr);
            }
            $retval .= COM_makeList($newComments, 'list-new-trackbacks');
        } else {
            $retval .= $LANG01[115] . '<br' . XHTML . '>' . LB;
        }
        if ($_CONF['hidenewplugins'] == 0) {
            $retval .= '<div class="divider-whats-new"></div>';
        }
    }
    if ($_CONF['hidenewplugins'] == 0) {
        list($headlines, $smallHeadlines, $content) = PLG_getWhatsNew();
        $plugins = count($headlines);
        if ($plugins > 0) {
            for ($i = 0; $i < $plugins; $i++) {
                $retval .= '<h3>' . $headlines[$i] . ' <small>' . $smallHeadlines[$i] . '</small></h3>';
                if (is_array($content[$i])) {
                    $retval .= COM_makeList($content[$i], 'list-new-plugins');
                } else {
                    $retval .= $content[$i];
                }
                if ($i + 1 < $plugins) {
                    $retval .= '<div class="divider-whats-new"></div>';
                }
            }
        }
    }
    $retval .= COM_endBlock(COM_getBlockTemplate('whats_new_block', 'footer', $position));
    if ($_CONF['whatsnew_cache_time'] > 0) {
        CACHE_create_instance($cacheInstance, $retval);
    }
    return $retval;
}
Beispiel #14
0
function fncList()
{
    global $_CONF;
    global $_TABLES;
    global $LANG_ADMIN;
    global $LANG09;
    global $_DATABOX_CONF;
    global $LANG_DATABOX_ADMIN;
    global $LANG_DATABOX;
    require_once $_CONF['path_system'] . 'lib-admin.php';
    $retval = '';
    $retval .= COM_startBlock($LANG_DATABOX['list']);
    //MENU1:管理画面
    $menu_arr = array();
    if ($_DATABOX_CONF['hide_whatsnew'] == 'hide') {
        $datecolumn = 'created';
    } else {
        $datecolumn = $_DATABOX_CONF['hide_whatsnew'];
    }
    //ヘッダ:編集~
    $header_arr[] = array('text' => $LANG_DATABOX_ADMIN['orderno'], 'field' => 'orderno', 'sort' => true);
    if ($_DATABOX_CONF['datacode']) {
        $header_arr[] = array('text' => $LANG_DATABOX_ADMIN['code'], 'field' => 'code', 'sort' => true);
    } else {
        $header_arr[] = array('text' => $LANG_DATABOX_ADMIN['id'], 'field' => 'id', 'sort' => true);
    }
    $header_arr[] = array('text' => $LANG_DATABOX_ADMIN['title'], 'field' => 'title', 'sort' => true);
    $header_arr[] = array('text' => $LANG_DATABOX_ADMIN['remaingdays'], 'field' => 'remaingdays', 'sort' => true);
    $header_arr[] = array('text' => $LANG_DATABOX_ADMIN[$datecolumn], 'field' => $datecolumn, 'sort' => true);
    //
    $text_arr = array('has_menu' => true, 'has_extras' => true, 'form_url' => $form_url);
    $tet_arr['has_menu'] = true;
    $tet_arr['has_extras'] = true;
    $tet_arr['form_url'] = $_CONF['site_url'] . "/" . THIS_SCRIPT;
    $sql = "SELECT ";
    $sql .= " id";
    $sql .= " ,title";
    $sql .= " ,code";
    $sql .= " ,draft_flag";
    $sql .= " ,UNIX_TIMESTAMP(udatetime) AS udatetime";
    $sql .= " ,orderno";
    $sql .= " ,UNIX_TIMESTAMP(" . $datecolumn . ") AS " . $datecolumn;
    $sql .= " ,(SELECT DATEDIFF(expired , NOW()) ";
    $sql .= " FROM {$_TABLES['DATABOX_base']} AS t3  ";
    $sql .= " where   t.id=t3.id AND DATEDIFF(expired , NOW())>0)";
    $sql .= "\t+ 1 AS remaingdays";
    $sql .= " FROM ";
    $sql .= " {$_TABLES['DATABOX_base']} AS t";
    $sql .= " WHERE ";
    $sql .= " 1=1";
    $sql .= COM_getLangSQL('code', 'AND', 't') . LB;
    //管理者の時,下書データも含む
    //if ( SEC_hasRights('databox.admin')) {
    //}else{
    $sql .= " AND draft_flag=0" . LB;
    //}
    //アクセス権のないデータ はのぞく
    $sql .= COM_getPermSql('AND');
    //公開日以前のデータはのぞく
    $sql .= " AND (released <= NOW())";
    //公開終了日を過ぎたデータはのぞく
    $sql .= " AND (expired=0 OR expired > NOW())";
    //
    $query_arr = array('table' => 'DATABOX_base', 'sql' => $sql, 'query_fields' => array('orderno', 'id', 'title', 'code', 'draft_flag'), 'default_filter' => $exclude);
    //デフォルトソート項目:
    $defsort_arr = array('field' => 'orderno', 'direction' => 'ASC');
    //List 取得
    //ADMIN_list($component, $fieldfunction, $header_arr, $text_arr,
    //       $query_arr, $menu_arr, $defsort_arr, $filter = '', $extra = '', $options = '')
    $retval .= ADMIN_list('databox', "fncGetListField", $header_arr, $text_arr, $query_arr, $defsort_arr);
    $retval .= COM_endBlock();
    return $retval;
}
Beispiel #15
0
 public function parse($p1, $p2 = '', $fulltag)
 {
     global $_CONF, $_TABLES, $_USER, $LANG01;
     USES_lib_comments();
     $retval = '';
     $skip = 0;
     $dt = new Date('now', $_USER['tzid']);
     // topic = specific topic or 'all'
     // display = how many stories to display, if 0, then all
     // meta = show meta data (i.e.; who when etc)
     // titleLink - make title a hot link
     // featured - 0 = show all, 1 = only featured, 2 = all except featured
     // frontpage - 1 = show only items marked for frontpage - 0 = show all
     // cols - number of columns to show
     // template - the template name
     $topic = $p1;
     if ($topic == 'all') {
         $topic = '';
     }
     $uniqueID = md5($p1 . $p2);
     $display = 10;
     // display 10 articles
     $meta = 0;
     // do not display meta data
     $titleLink = 0;
     // do not use links in title
     $featured = 0;
     // 0 = show all, 1 = only featured, 2 = all except featured
     $frontpage = 0;
     // only show items marked for frontpage
     $cols = 3;
     // number of columns
     $truncate = 0;
     // maximum number of characters to include in story text
     $template = 'headlines.thtml';
     $px = explode(' ', trim($p2));
     if (is_array($px)) {
         foreach ($px as $part) {
             if (substr($part, 0, 8) == 'display:') {
                 $a = explode(':', $part);
                 $display = $a[1];
                 $skip++;
             } elseif (substr($part, 0, 5) == 'meta:') {
                 $a = explode(':', $part);
                 $meta = $a[1];
                 $skip++;
             } elseif (substr($part, 0, 10) == 'titlelink:') {
                 $a = explode(':', $part);
                 $titleLink = $a[1];
                 $skip++;
             } elseif (substr($part, 0, 9) == 'featured:') {
                 $a = explode(':', $part);
                 $featured = $a[1];
                 $skip++;
             } elseif (substr($part, 0, 10) == 'frontpage:') {
                 $a = explode(':', $part);
                 $frontpage = (int) $a[1];
                 $skip++;
             } elseif (substr($part, 0, 5) == 'cols:') {
                 $a = explode(':', $part);
                 $cols = $a[1];
                 $skip++;
             } elseif (substr($part, 0, 9) == 'template:') {
                 $a = explode(':', $part);
                 $template = $a[1];
                 $skip++;
             } elseif (substr($part, 0, 9) == 'truncate:') {
                 $a = explode(':', $part);
                 $truncate = (int) $a[1];
                 $skip++;
             } else {
                 break;
             }
         }
         if ($skip != 0) {
             if (count($px) > $skip) {
                 for ($i = 0; $i < $skip; $i++) {
                     array_shift($px);
                 }
                 $caption = trim(implode(' ', $px));
             } else {
                 $caption = '';
             }
         }
     } else {
         $caption = trim($p2);
     }
     if ($display < 0) {
         $display = 3;
     }
     $hash = CACHE_security_hash();
     $instance_id = 'whatsnew_headlines_' . $uniqueID . '_' . $hash . '_' . $_USER['theme'];
     if (($cache = CACHE_check_instance($instance_id, 0)) !== FALSE) {
         return $cache;
     }
     $archivetid = DB_getItem($_TABLES['topics'], 'tid', "archive_flag=1");
     $sql = " (date <= NOW()) AND (draft_flag = 0)";
     if (empty($topic)) {
         $sql .= COM_getLangSQL('tid', 'AND', 's');
     }
     // if a topic was provided only select those stories.
     if (!empty($topic)) {
         $sql .= " AND s.tid = '" . DB_escapeString($topic) . "' ";
     }
     if ($featured == 1) {
         $sql .= " AND s.featured = 1 ";
     } else {
         if ($featured == 2) {
             $sql .= " AND s.featured = 0 ";
         }
     }
     if ($frontpage == 1) {
         $sql .= " AND frontpage = 1 ";
     }
     if ($topic != $archivetid) {
         $sql .= " AND s.tid != '{$archivetid}' ";
     }
     $sql .= COM_getPermSQL('AND', 0, 2, 's');
     $sql .= COM_getTopicSQL('AND', 0, 's') . ' ';
     $userfields = 'u.uid, u.username, u.fullname';
     if ($_CONF['allow_user_photo'] == 1) {
         $userfields .= ', u.photo';
         if ($_CONF['use_gravatar']) {
             $userfields .= ', u.email';
         }
     }
     $orderBy = ' date DESC ';
     $headlinesSQL = "SELECT STRAIGHT_JOIN s.*, UNIX_TIMESTAMP(s.date) AS unixdate, " . 'UNIX_TIMESTAMP(s.expire) as expireunix, ' . $userfields . ", t.topic, t.imageurl " . "FROM {$_TABLES['stories']} AS s, {$_TABLES['users']} AS u, " . "{$_TABLES['topics']} AS t WHERE (s.uid = u.uid) AND (s.tid = t.tid) AND" . $sql . "ORDER BY featured DESC," . $orderBy;
     if ($display > 0) {
         $headlinesSQL .= " LIMIT " . $display;
     }
     $result = DB_query($headlinesSQL);
     $numRows = DB_numRows($result);
     if ($numRows < $cols) {
         $cols = $numRows;
     }
     if ($cols > 6) {
         $cols = 6;
     }
     if ($numRows > 0) {
         $T = new Template($_CONF['path'] . 'system/autotags/');
         $T->set_file('page', $template);
         $T->set_var('columns', $cols);
         $T->set_block('page', 'headlines', 'hl');
         $newstories = array();
         while ($A = DB_fetchArray($result)) {
             $T->unset_var('readmore_url');
             $T->unset_var('lang_readmore');
             if ($A['attribution_author'] != '') {
                 $author = $A['attribution_author'];
             } else {
                 $author = $A['username'];
             }
             $title = COM_undoSpecialChars($A['title']);
             $title = str_replace('&nbsp;', ' ', $title);
             $subtitle = COM_undoSpecialChars($A['subtitle']);
             if ($A['story_image'] != '') {
                 $story_image = $_CONF['site_url'] . $A['story_image'];
             } else {
                 $story_image = '';
             }
             $A['introtext'] = STORY_renderImages($A['sid'], $A['introtext']);
             if (!empty($A['bodytext'])) {
                 $closingP = strrpos($A['introtext'], "</p>");
                 if ($closingP !== FALSE) {
                     $text = substr($A['introtext'], 0, $closingP);
                     $A['introtext'] = $text;
                 }
                 // adds the read more link
                 $T->set_var('readmore_url', COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $A['sid']));
                 $T->set_var('lang_readmore', $LANG01['continue_reading']);
             }
             if ($truncate > 0) {
                 $A['introtext'] = $this->truncateHTML($A['introtext'], $truncate, '...');
             }
             $topicurl = $_CONF['site_url'] . '/index.php?topic=' . $A['tid'];
             $dt->setTimestamp($A['unixdate']);
             if ($A['commentcode'] >= 0) {
                 $cmtLinkArray = CMT_getCommentLinkWithCount('article', $A['sid'], $_CONF['site_url'] . '/article.php?story=' . $A['sid'], $A['comments'], 1);
                 $T->set_var(array('lang_comments' => '', 'comments_count' => $cmtLinkArray['comment_count'], 'comments_url' => $cmtLinkArray['url'], 'comments_url_extra' => $cmtLinkArray['url_extra']));
             } else {
                 $T->unset_var('lang_comments');
                 $T->unset_var('comments_count');
                 $T->unset_var('comments_url');
                 $T->unset_var('comments_url_extra');
             }
             $T->set_var(array('titlelink' => $titleLink ? TRUE : '', 'meta' => $meta ? TRUE : '', 'lang_by' => $LANG01[95], 'lang_posted_in' => $LANG01['posted_in'], 'story_topic_url' => $topicurl, 'title' => $title, 'subtitle' => $subtitle, 'story_image' => $story_image, 'text' => PLG_replaceTags($A['introtext']), 'date' => $A['date'], 'time' => $dt->format('Y-m-d', true) . 'T' . $dt->format('H:i:s', true), 'topic' => $A['topic'], 'tid' => $A['tid'], 'author' => $author, 'author_id' => $A['uid'], 'sid' => $A['sid'], 'short_date' => $dt->format($_CONF['shortdate'], true), 'date_only' => $dt->format($_CONF['dateonly'], true), 'date' => $dt->format($dt->getUserFormat(), true), 'url' => COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $A['sid']), 'attribution_url' => $A['attribution_url'], 'attribution_name' => $A['attribution_name']));
             $T->parse('hl', 'headlines', true);
         }
         $retval = $T->finish($T->parse('output', 'page'));
         CACHE_create_instance($instance_id, $retval, 0);
     }
     return $retval;
 }
function MYCALJP_showStoriesIntro()
{
    global $_CONF, $_TABLES, $_MYCALJP2_CONF;
    if (!$_MYCALJP2_CONF['showstoriesintro']) {
        return '';
    }
    $retval = '';
    $_dateStart = COM_applyFilter($_GET['datestart']);
    $_dateEnd = COM_applyFilter($_GET['dateend']);
    if (!empty($_dateStart) && !empty($_dateEnd)) {
        $ds = explode("-", $_dateStart);
        $de = explode("-", $_dateEnd);
        $startdate = mktime(0, 0, 0, $ds[1], $ds[2], $ds[0]);
        $enddate = mktime(23, 59, 59, $de[1], $de[2], $de[0]);
        $sql = "AND (UNIX_TIMESTAMP(date) BETWEEN '{$startdate}' AND '{$enddate}') ";
    }
    $sql .= "AND (draft_flag = 0) ";
    $sql .= COM_getPermSQL('AND', 0, 2, 's') . ' ';
    $sql .= COM_getTopicSQL('AND', 0, 'ta') . ' ';
    $sql .= COM_getLangSQL('sid', 'AND', 's') . ' ';
    $userfields = 'u.username, u.fullname';
    if ($_CONF['allow_user_photo'] == 1) {
        $userfields .= ', u.photo';
        if ($_CONF['use_gravatar']) {
            $userfields .= ', u.email';
        }
    }
    $msql = array();
    $msql['mysql'] = "SELECT DISTINCT STRAIGHT_JOIN s.*, UNIX_TIMESTAMP(s.date) AS unixdate, " . "UNIX_TIMESTAMP(s.expire) AS expireunix, " . $userfields . ", t.topic, t.imageurl " . "FROM {$_TABLES['stories']} AS s, {$_TABLES['users']} AS u, " . "{$_TABLES['topics']} AS t, {$_TABLES['topic_assignments']} AS ta " . "WHERE (ta.type = 'article') AND (ta.tdefault = 1) AND (s.uid = u.uid) AND (ta.tid = t.tid) AND (s.sid = ta.id) " . $sql . "ORDER BY featured DESC, date DESC";
    /*
        $msql['mssql']="SELECT STRAIGHT_JOIN s.sid, s.uid, s.draft_flag, s.tid, s.date, s.title, cast(s.introtext as text) as introtext, cast(s.bodytext as text) as bodytext, s.hits, s.numemails, s.comments, s.trackbacks, s.related, s.featured, s.show_topic_icon, s.commentcode, s.trackbackcode, s.statuscode, s.expire, s.postmode, s.frontpage, s.in_transit, s.owner_id, s.group_id, s.perm_owner, s.perm_group, s.perm_members, s.perm_anon, s.advanced_editor_mode, "
                 . " UNIX_TIMESTAMP(s.date) AS unixdate, "
                 . 'UNIX_TIMESTAMP(s.expire) as expireunix, '
                 . $userfields . ", t.topic, t.imageurl "
                 . "FROM {$_TABLES['stories']} AS s, {$_TABLES['users']} AS u, "
                 . "{$_TABLES['topics']} AS t, {$_TABLES['topic_assignments']} AS ta "
                 . "WHERE (ta.type = 'article') AND (ta.tdefault = 1) AND (s.uid = u.uid) AND (ta.tid = t.tid) AND (s.sid = ta.id) "
                 . $sql . "ORDER BY featured DESC, date DESC";
    */
    $result = DB_query($msql);
    require_once $_CONF['path_system'] . 'lib-story.php';
    $story = new Story();
    while ($A = DB_fetchArray($result)) {
        $story->loadFromArray($A);
        $retval .= STORY_renderArticle($story, 'y');
    }
    return $retval;
}
Beispiel #17
0
/**
* Shows any new information in a block
*
* Return the HTML that shows any new stories, comments, etc
*
* @param    string  $help     Help file for block
* @param    string  $title    Title used in block header
* @param    string  $position Position in which block is being rendered 'left', 'right' or blank (for centre)
* @return   string  Return the HTML that shows any new stories, comments, etc
*
*/
function COM_whatsNewBlock($help = '', $title = '', $position = '')
{
    global $_CONF, $_TABLES, $_USER, $_PLUGINS, $LANG01, $LANG_WHATSNEW, $page, $newstories;
    if (!isset($_CONF['whatsnew_cache_time'])) {
        $_CONF['whatsnew_cache_time'] = 3600;
    }
    $cacheInstance = 'whatsnew__' . CACHE_security_hash() . '__' . $_USER['theme'];
    $retval = CACHE_check_instance($cacheInstance, 0);
    if ($retval) {
        $lu = CACHE_get_instance_update($cacheInstance, 0);
        $now = time();
        if ($now - $lu < $_CONF['whatsnew_cache_time']) {
            return $retval;
        }
    }
    $T = new Template($_CONF['path_layout'] . 'blocks');
    $T->set_file('block', 'whatsnew.thtml');
    $items_found = 0;
    $header = COM_startBlock($title, $help, COM_getBlockTemplate('whats_new_block', 'header', $position), 'whats_new_block');
    $T->set_var('block_start', $header);
    $topicsql = '';
    if ($_CONF['hidenewstories'] == 0 || $_CONF['hidenewcomments'] == 0 || $_CONF['trackback_enabled'] && $_CONF['hidenewtrackbacks'] == 0) {
        $topicsql = COM_getTopicSql('AND', 0, $_TABLES['stories']);
    }
    if ($_CONF['hidenewstories'] == 0) {
        $archsql = '';
        $archivetid = DB_getItem($_TABLES['topics'], 'tid', "archive_flag=1");
        if (!empty($archivetid)) {
            $archsql = " AND (tid <> '" . DB_escapeString($archivetid) . "')";
        }
        // Find the newest stories
        $sql = "SELECT * FROM {$_TABLES['stories']} WHERE (date >= (date_sub(NOW(), INTERVAL {$_CONF['newstoriesinterval']} SECOND))) AND (date <= NOW()) AND (draft_flag = 0)" . $archsql . COM_getPermSQL('AND') . $topicsql . COM_getLangSQL('sid', 'AND') . ' ORDER BY date DESC';
        $result = DB_query($sql);
        $nrows = DB_numRows($result);
        if (empty($title)) {
            $title = DB_getItem($_TABLES['blocks'], 'title', "name='whats_new_block'");
        }
        $T->set_block('block', 'section', 'sectionblock');
        if ($nrows > 0) {
            // Any late breaking news stories?
            $T->set_var('section_title', $LANG01[99]);
            $T->set_var('interval', COM_formatTimeString($LANG_WHATSNEW['new_last'], $_CONF['newcommentsinterval']));
            $newstory = array();
            $T->set_block('block', 'datarow', 'datablock');
            while ($A = DB_fetchArray($result)) {
                $title = COM_undoSpecialChars($A['title']);
                $title = str_replace('&nbsp;', ' ', $title);
                $titletouse = COM_truncate($title, $_CONF['title_trim_length'], '...');
                $attr = array('title' => htmlspecialchars($title, ENT_COMPAT, COM_getEncodingt()));
                $url = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $A['sid']);
                $storyitem = COM_createLink($titletouse, $url, $attr);
                $newstory[] = $storyitem;
                $T->set_var('data_item', $storyitem);
                $T->parse('datablock', 'datarow', true);
                $items_found++;
            }
            $T->parse('sectionblock', 'section', true);
        }
    }
    $T->unset_var('datablock');
    if ($_CONF['hidenewcomments'] == 0) {
        // Go get the newest comments
        $commentHeader = 0;
        $newcomments = array();
        $commentrow = array();
        // get story whats new
        $stwhere = '';
        if (!COM_isAnonUser()) {
            $stwhere .= "({$_TABLES['stories']}.owner_id IS NOT NULL AND {$_TABLES['stories']}.perm_owner IS NOT NULL) OR ";
            $stwhere .= "({$_TABLES['stories']}.group_id IS NOT NULL AND {$_TABLES['stories']}.perm_group IS NOT NULL) OR ";
            $stwhere .= "({$_TABLES['stories']}.perm_members IS NOT NULL)";
        } else {
            $stwhere .= "({$_TABLES['stories']}.perm_anon IS NOT NULL)";
        }
        $sql = "SELECT DISTINCT COUNT(*) AS dups, type, {$_TABLES['stories']}.title, {$_TABLES['stories']}.sid, UNIX_TIMESTAMP(max({$_TABLES['comments']}.date)) AS lastdate FROM {$_TABLES['comments']} LEFT JOIN {$_TABLES['stories']} ON (({$_TABLES['stories']}.sid = {$_TABLES['comments']}.sid)" . COM_getPermSQL('AND', 0, 2, $_TABLES['stories']) . " AND ({$_TABLES['stories']}.draft_flag = 0) AND ({$_TABLES['stories']}.commentcode >= 0)" . $topicsql . COM_getLangSQL('sid', 'AND', $_TABLES['stories']) . ") WHERE ({$_TABLES['comments']}.date >= (DATE_SUB(NOW(), INTERVAL {$_CONF['newcommentsinterval']} SECOND))) AND ((({$stwhere}))) GROUP BY {$_TABLES['comments']}.sid,type, {$_TABLES['stories']}.title, {$_TABLES['stories']}.title, {$_TABLES['stories']}.sid ORDER BY 5 DESC LIMIT 15";
        $result = DB_query($sql);
        $nrows = DB_numRows($result);
        if ($nrows > 0) {
            $T->set_var('section_title', $LANG01[83]);
            $T->set_var('interval', COM_formatTimeString($LANG_WHATSNEW['new_last'], $_CONF['newcommentsinterval']));
            $commentHeader = 1;
            for ($x = 0; $x < $nrows; $x++) {
                $A = DB_fetchArray($result);
                $A['url'] = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $A['sid']) . '#comments';
                $commentrow[] = $A;
            }
        }
        $pluginComments = PLG_getWhatsNewComment();
        $commentrow = array_merge($pluginComments, $commentrow);
        usort($commentrow, '_commentsort');
        $nrows = count($commentrow);
        if ($nrows > 0) {
            if ($commentHeader == 0) {
                $commentHeader = 1;
                $T->set_var('section_title', $LANG01[83]);
                $T->set_var('interval', COM_formatTimeString($LANG_WHATSNEW['new_last'], $_CONF['newcommentsinterval']));
            }
            $newcomments = array();
            for ($x = 0; $x < $nrows; $x++) {
                $titletouse = '';
                $url = $commentrow[$x]['url'];
                $title = COM_undoSpecialChars($commentrow[$x]['title']);
                $title = str_replace('&nbsp;', ' ', $title);
                $titletouse = COM_truncate($title, $_CONF['title_trim_length'], '...');
                $attr = array('title' => htmlspecialchars($title, ENT_COMPAT, COM_getEncodingt()));
                if ($commentrow[$x]['dups'] > 1) {
                    $titletouse .= ' [+' . $commentrow[$x]['dups'] . ']';
                }
                $newcomments[] = COM_createLink($titletouse, $url, $attr);
            }
            $T->set_block('block', 'datarow', 'datablock');
            foreach ($newcomments as $comment) {
                $T->set_var('data_item', $comment);
                $T->parse('datablock', 'datarow', true);
                $items_found++;
            }
            $T->parse('sectionblock', 'section', true);
        }
    }
    $T->unset_var('datablock');
    if ($_CONF['trackback_enabled'] && $_CONF['hidenewtrackbacks'] == 0) {
        $sql = "SELECT DISTINCT COUNT(*) AS count,{$_TABLES['stories']}.title,t.sid,max(t.date) AS lastdate FROM {$_TABLES['trackback']} AS t,{$_TABLES['stories']} WHERE (t.type = 'article') AND (t.sid = {$_TABLES['stories']}.sid) AND (t.date >= (DATE_SUB(NOW(), INTERVAL {$_CONF['newtrackbackinterval']} SECOND)))" . COM_getPermSQL('AND', 0, 2, $_TABLES['stories']) . " AND ({$_TABLES['stories']}.draft_flag = 0) AND ({$_TABLES['stories']}.trackbackcode = 0)" . $topicsql . COM_getLangSQL('sid', 'AND', $_TABLES['stories']) . " GROUP BY t.sid, {$_TABLES['stories']}.title ORDER BY lastdate DESC LIMIT 15";
        $result = DB_query($sql);
        $nrows = DB_numRows($result);
        if ($nrows > 0) {
            $T->set_var('section_title', $LANG01[114]);
            $T->set_var('interval', COM_formatTimeString($LANG_WHATSNEW['new_last'], $_CONF['newtrackbackinterval']));
            $newcomments = array();
            $T->set_block('block', 'datarow', 'datablock');
            for ($i = 0; $i < $nrows; $i++) {
                $titletouse = '';
                $A = DB_fetchArray($result);
                $url = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $A['sid']) . '#trackback';
                $title = COM_undoSpecialChars($A['title']);
                $title = str_replace('&nbsp;', ' ', $title);
                $titletouse = COM_truncate($title, $_CONF['title_trim_length'], '...');
                $attr = array('title' => htmlspecialchars($title, ENT_COMPAT, COM_getEncodingt()));
                if ($A['count'] > 1) {
                    $titletouse .= ' [+' . $A['count'] . ']';
                }
                $trackback = COM_createLink($titletouse, $url, $attr);
                $newcomments[] = $trackback;
                $T->set_var('data_item', $trackback);
                $T->parse('datablock', 'datarow', true);
                $items_found++;
            }
            $T->parse('sectionblock', 'section', true);
        }
    }
    $T->unset_var('datablock');
    if ($_CONF['hidenewplugins'] == 0) {
        list($headlines, $smallheadlines, $content) = PLG_getWhatsNew();
        $plugins = count($headlines);
        if ($plugins > 0) {
            for ($i = 0; $i < $plugins; $i++) {
                $T->set_var('section_title', $headlines[$i]);
                $T->set_var('interval', $smallheadlines[$i]);
                $T->set_block('block', 'datarow', 'datablock');
                if (is_array($content[$i])) {
                    foreach ($content[$i] as $item) {
                        $T->set_var('data_item', $item);
                        $T->parse('datablock', 'datarow', true);
                        $items_found++;
                    }
                } else {
                    $T->set_var('data_item', $content[$i]);
                    $T->parse('datablock', 'datarow', true);
                    $items_found++;
                }
                $T->parse('sectionblock', 'section', true);
                $T->unset_var('datablock');
                $T->unset_var('interval');
                $T->unset_var('section_title');
            }
        }
    }
    if ($items_found == 0) {
        $T->set_var('no_items_found', $LANG01['no_new_items']);
    } else {
        $T->set_var('no_items_found', '');
    }
    $T->set_var('block_end', COM_endBlock(COM_getBlockTemplate('whats_new_block', 'footer', $position)));
    $T->parse('output', 'block');
    $final = $T->finish($T->get_var('output'));
    CACHE_create_instance($cacheInstance, $final, 0);
    return $final;
}
Beispiel #18
0
/**
* This function will allow plugins to support the use of custom autolinks
* in other site content. Plugins can now use this API when saving content
* and have the content checked for any autolinks before saving.
* The autolink would be like:  [story:20040101093000103 here]
*
* @param   string   $content   Content that should be parsed for autolinks
* @param    string  $namespace Optional Namespace or plugin name collecting tag info
* @param    string  $operation Optional Operation being performed
* @param   string   $plugin    Optional if you only want to parse using a specific plugin
*
*/
function PLG_replaceTags($content, $namespace = '', $operation = '', $plugin = '')
{
    global $_CONF, $_TABLES, $_BLOCK_TEMPLATE, $LANG32, $_AUTOTAGS, $mbMenu, $autoTagUsage;
    if (isset($_CONF['disable_autolinks']) && $_CONF['disable_autolinks'] == 1) {
        // autolinks are disabled - return $content unchanged
        return $content;
    }
    static $recursionCount = 0;
    if ($recursionCount > 5) {
        COM_errorLog("AutoTag infinite recursion detected on " . $namespace . " " . $operation);
        return $content;
    }
    $autolinkModules = PLG_collectTags();
    $autoTagUsage = PLG_autoTagPerms();
    if (!empty($namespace) && !empty($operation)) {
        $postFix = '.' . $namespace . '.' . $operation;
    } else {
        $postFix = '';
    }
    // For each supported module, scan the content looking for any AutoLink tags
    $tags = array();
    $contentlen = utf8_strlen($content);
    $content_lower = utf8_strtolower($content);
    foreach ($autolinkModules as $moduletag => $module) {
        $autotag_prefix = '[' . $moduletag . ':';
        $offset = 0;
        $prev_offset = 0;
        while ($offset < $contentlen) {
            $start_pos = utf8_strpos($content_lower, $autotag_prefix, $offset);
            if ($start_pos === false) {
                break;
            } else {
                $end_pos = utf8_strpos($content_lower, ']', $start_pos);
                $next_tag = utf8_strpos($content_lower, '[', $start_pos + 1);
                if ($end_pos > $start_pos and ($next_tag === false or $end_pos < $next_tag)) {
                    $taglength = $end_pos - $start_pos + 1;
                    $tag = utf8_substr($content, $start_pos, $taglength);
                    $parms = explode(' ', $tag);
                    // Extra test to see if autotag was entered with a space
                    // after the module name
                    if (utf8_substr($parms[0], -1) == ':') {
                        $startpos = utf8_strlen($parms[0]) + utf8_strlen($parms[1]) + 2;
                        $label = str_replace(']', '', utf8_substr($tag, $startpos));
                        $tagid = $parms[1];
                    } else {
                        $label = str_replace(']', '', utf8_substr($tag, utf8_strlen($parms[0]) + 1));
                        $parms = explode(':', $parms[0]);
                        if (count($parms) > 2) {
                            // whoops, there was a ':' in the tag id ...
                            array_shift($parms);
                            $tagid = implode(':', $parms);
                        } else {
                            $tagid = $parms[1];
                        }
                    }
                    $newtag = array('module' => $module, 'tag' => $moduletag, 'tagstr' => $tag, 'startpos' => $start_pos, 'length' => $taglength, 'parm1' => str_replace(']', '', $tagid), 'parm2' => $label);
                    $tags[] = $newtag;
                } else {
                    // Error: tags do not match - return with no changes
                    return $content . $LANG32[32];
                }
                $prev_offset = $offset;
                $offset = $end_pos;
            }
        }
    }
    // If we have found 1 or more AutoLink tag
    if (count($tags) > 0) {
        // Found the [tag] - Now process them all
        $recursionCount++;
        foreach ($tags as $autotag) {
            $permCheck = $autotag['tag'] . $postFix;
            if (empty($postFix) || !isset($autoTagUsage[$permCheck]) || $autoTagUsage[$permCheck] == 1) {
                $function = 'plugin_autotags_' . $autotag['module'];
                if ($autotag['module'] == 'glfusion' and (empty($plugin) or $plugin == 'glfusion')) {
                    $url = '';
                    $linktext = $autotag['parm2'];
                    if ($autotag['tag'] == 'story') {
                        $autotag['parm1'] = COM_applyFilter($autotag['parm1']);
                        $url = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $autotag['parm1']);
                        if (empty($linktext)) {
                            $linktext = DB_getItem($_TABLES['stories'], 'title', "sid = '" . DB_escapeString($autotag['parm1']) . "'");
                        }
                    }
                    if (!empty($url)) {
                        $filelink = COM_createLink($linktext, $url);
                        $content = str_replace($autotag['tagstr'], $filelink, $content);
                    }
                    if ($autotag['tag'] == 'story_introtext') {
                        $url = '';
                        $linktext = '';
                        USES_lib_story();
                        if (isset($_USER['uid']) && $_USER['uid'] > 1) {
                            $result = DB_query("SELECT maxstories,tids,aids FROM {$_TABLES['userindex']} WHERE uid = {$_USER['uid']}");
                            $U = DB_fetchArray($result);
                        } else {
                            $U['maxstories'] = 0;
                            $U['aids'] = '';
                            $U['tids'] = '';
                        }
                        $sql = " (date <= NOW()) AND (draft_flag = 0)";
                        if (empty($topic)) {
                            $sql .= COM_getLangSQL('tid', 'AND', 's');
                        }
                        $sql .= COM_getPermSQL('AND', 0, 2, 's');
                        if (!empty($U['aids'])) {
                            $sql .= " AND s.uid NOT IN (" . str_replace(' ', ",", $U['aids']) . ") ";
                        }
                        if (!empty($U['tids'])) {
                            $sql .= " AND s.tid NOT IN ('" . str_replace(' ', "','", $U['tids']) . "') ";
                        }
                        $sql .= COM_getTopicSQL('AND', 0, 's') . ' ';
                        $userfields = 'u.uid, u.username, u.fullname';
                        $msql = "SELECT STRAIGHT_JOIN s.*, UNIX_TIMESTAMP(s.date) AS unixdate, " . 'UNIX_TIMESTAMP(s.expire) as expireunix, ' . $userfields . ", t.topic, t.imageurl " . "FROM {$_TABLES['stories']} AS s, {$_TABLES['users']} AS u, " . "{$_TABLES['topics']} AS t WHERE s.sid = '" . $autotag['parm1'] . "' AND (s.uid = u.uid) AND (s.tid = t.tid) AND" . $sql;
                        $result = DB_query($msql);
                        $nrows = DB_numRows($result);
                        if ($A = DB_fetchArray($result)) {
                            $story = new Story();
                            $story->loadFromArray($A);
                            $linktext = STORY_renderArticle($story, 'y');
                        }
                        $content = str_replace($autotag['tagstr'], $linktext, $content);
                    }
                    if ($autotag['tag'] == 'showblock') {
                        $blockName = COM_applyBasicFilter($autotag['parm1']);
                        $result = DB_query("SELECT * FROM {$_TABLES['blocks']} WHERE name = '" . DB_escapeString($blockName) . "'" . COM_getPermSQL('AND'));
                        if (DB_numRows($result) > 0) {
                            $skip = 0;
                            $B = DB_fetchArray($result);
                            $template = '';
                            $side = '';
                            $px = explode(' ', trim($autotag['parm2']));
                            if (is_array($px)) {
                                foreach ($px as $part) {
                                    if (substr($part, 0, 9) == 'template:') {
                                        $a = explode(':', $part);
                                        $template = $a[1];
                                        $skip++;
                                    } elseif (substr($part, 0, 5) == 'side:') {
                                        $a = explode(':', $part);
                                        $side = $a[1];
                                        $skip++;
                                        break;
                                    }
                                }
                                if ($skip != 0) {
                                    if (count($px) > $skip) {
                                        for ($i = 0; $i < $skip; $i++) {
                                            array_shift($px);
                                        }
                                        $caption = trim(implode(' ', $px));
                                    } else {
                                        $caption = '';
                                    }
                                }
                            }
                            if ($template != '') {
                                $_BLOCK_TEMPLATE[$blockName] = 'blockheader-' . $template . '.thtml,blockfooter-' . $template . '.thtml';
                            }
                            if ($side == 'left') {
                                $B['onleft'] = 1;
                            } else {
                                if ($side == 'right') {
                                    $B['onleft'] = 0;
                                }
                            }
                            $linktext = COM_formatBlock($B);
                            $content = str_replace($autotag['tagstr'], $linktext, $content);
                        } else {
                            $content = str_replace($autotag['tagstr'], '', $content);
                        }
                    }
                    if ($autotag['tag'] == 'menu') {
                        $menu = '';
                        $menuID = trim($autotag['parm1']);
                        $menuHTML = displayMenu($menuID);
                        $content = str_replace($autotag['tagstr'], $menuHTML, $content);
                    }
                    if (isset($_AUTOTAGS[$autotag['tag']])) {
                        $content = autotags_autotag('parse', $content, $autotag);
                    }
                } else {
                    if (function_exists($function) and (empty($plugin) or $plugin == $autotag['module'])) {
                        $content = $function('parse', $content, $autotag);
                    }
                }
            }
        }
        $recursionCount--;
    }
    return $content;
}
Beispiel #19
0
function getTopicMenu()
{
    global $_SP_CONF, $_USER, $_TABLES, $LANG01, $LANG_MB01, $LANG_LOGO, $LANG_AM, $LANG29, $_CONF, $_GROUPS;
    $item_array = array();
    $langsql = COM_getLangSQL('tid');
    if (empty($langsql)) {
        $op = 'WHERE';
    } else {
        $op = 'AND';
    }
    $sql = "SELECT tid,topic,imageurl FROM {$_TABLES['topics']}" . $langsql;
    if (!COM_isAnonUser()) {
        $tids = DB_getItem($_TABLES['userindex'], 'tids', "uid=" . (int) $_USER['uid']);
        if (!empty($tids)) {
            $sql .= " {$op} (tid NOT IN ('" . str_replace(' ', "','", $tids) . "'))" . COM_getPermSQL('AND');
        } else {
            $sql .= COM_getPermSQL($op);
        }
    } else {
        $sql .= COM_getPermSQL($op);
    }
    if ($_CONF['sortmethod'] == 'alpha') {
        $sql .= ' ORDER BY topic ASC';
    } else {
        $sql .= ' ORDER BY sortnum';
    }
    $result = DB_query($sql);
    if ($_CONF['showstorycount']) {
        $sql = "SELECT tid, COUNT(*) AS count FROM {$_TABLES['stories']} " . 'WHERE (draft_flag = 0) AND (date <= NOW()) ' . COM_getPermSQL('AND') . ' GROUP BY tid';
        $rcount = DB_query($sql);
        while ($C = DB_fetchArray($rcount)) {
            $storycount[$C['tid']] = $C['count'];
        }
    }
    if ($_CONF['showsubmissioncount']) {
        $sql = "SELECT tid, COUNT(*) AS count FROM {$_TABLES['storysubmission']} " . ' GROUP BY tid';
        $rcount = DB_query($sql);
        while ($C = DB_fetchArray($rcount)) {
            $submissioncount[$C['tid']] = $C['count'];
        }
    }
    while ($A = DB_fetchArray($result)) {
        $topicname = $A['topic'];
        $url = $_CONF['site_url'] . '/index.php?topic=' . $A['tid'];
        $label = $topicname;
        $countstring = '';
        if ($_CONF['showstorycount'] || $_CONF['showsubmissioncount']) {
            $countstring .= ' (';
            if ($_CONF['showstorycount']) {
                if (empty($storycount[$A['tid']])) {
                    $countstring .= 0;
                } else {
                    $countstring .= COM_numberFormat($storycount[$A['tid']]);
                }
            }
            if ($_CONF['showsubmissioncount']) {
                if ($_CONF['showstorycount']) {
                    $countstring .= '/';
                }
                if (empty($submissioncount[$A['tid']])) {
                    $countstring .= 0;
                } else {
                    $countstring .= COM_numberFormat($submissioncount[$A['tid']]);
                }
            }
            $countstring .= ')';
        }
        $label .= $countstring;
        $item_array[] = array('label' => $label, 'url' => $url);
    }
    return $item_array;
}
Beispiel #20
0
/**
 * Display main view (list of years)
 * Displays an overview of all the years and months, starting with the first
 * year for which a story has been posted. Can optionally display a list of
 * the stories for the current month at the top of the page.
 *
 * @param    Template $template  reference of the template
 * @param    string   $dir_topic current topic
 * @return   string                list of all the years in the db
 */
function DIR_displayAll($template, $dir_topic)
{
    global $_TABLES, $LANG_DIR;
    $retval = '';
    $yearsql = array();
    $yearsql['mysql'] = "SELECT DISTINCT YEAR(date) AS year, date\n        FROM {$_TABLES['stories']}, {$_TABLES['topic_assignments']} ta\n        WHERE (draft_flag = 0) AND (date <= NOW())\n        AND ta.type = 'article' AND ta.id = sid\n        " . COM_getTopicSQL('AND', 0, 'ta') . COM_getPermSql('AND') . COM_getLangSQL('sid', 'AND');
    $yearsql['pgsql'] = "SELECT EXTRACT(YEAR from date) AS year\n        FROM {$_TABLES['stories']}, {$_TABLES['topic_assignments']} ta\n        WHERE (draft_flag = 0) AND (date <= NOW())\n        AND ta.type = 'article' AND ta.id = sid\n        " . COM_getTopicSQL('AND', 0, 'ta') . COM_getPermSql('AND') . COM_getLangSQL('sid', 'AND');
    $ySql = array();
    $ySql['mysql'] = $yearsql['mysql'] . " GROUP BY year, date ORDER BY date DESC";
    $ySql['pgsql'] = $yearsql['pgsql'] . " GROUP BY year, date ORDER BY year DESC";
    $yResult = DB_query($ySql);
    $numYears = DB_numRows($yResult);
    if ($numYears > 0) {
        for ($i = 0; $i < $numYears; $i++) {
            $Y = DB_fetchArray($yResult);
            if (TEMPLATE_EXISTS) {
                $template->set_var('section_title', $Y['year']);
                $retval .= $template->parse('title', 'section-title') . LB;
            } else {
                $retval .= '<h3>' . $Y['year'] . '</h3>' . LB;
            }
            $retval .= DIR_displayYear($template, $dir_topic, $Y['year']);
        }
    } else {
        if (TEMPLATE_EXISTS) {
            $retval .= $template->parse('message', 'no-articles') . LB;
        } else {
            $retval .= '<p>' . $LANG_DIR['no_articles'] . '</p>' . LB;
        }
    }
    return $retval;
}
 /**
  * Returns an array of (
  *   'id'        => $id (string),
  *   'title'     => $title (string),
  *   'uri'       => $uri (string),
  *   'date'      => $date (int: Unix timestamp),
  *   'image_uri' => $image_uri (string)
  * )
  */
 public function getItemsByDate($cid = '', $all_langs = FALSE)
 {
     global $_CONF, $_TABLES;
     $entries = array();
     if (empty(Dataproxy::$startDate) or empty(Dataproxy::$endDate)) {
         return $entries;
     }
     $sql = "SELECT f.lid, f.title, f.logourl, f.date " . "  FROM {$_TABLES['downloads']} AS f " . "  LEFT JOIN {$_TABLES['downloadcategories']} AS c " . "    ON f.cid = c.cid " . "WHERE (f.is_released = 1) " . "  AND (f.is_listing = 1) " . "  AND (f.date <= UNIX_TIMESTAMP(NOW())) " . "  AND (f.date BETWEEN '" . Dataproxy::$startDate . "' AND '" . Dataproxy::$endDate . "') ";
     if (!empty($cid)) {
         $sql .= "  AND (c.is_enabled = 1) " . "  AND (f.cid = '" . addslashes($cid) . "') ";
         if ($all_langs === FALSE) {
             $sql .= COM_getLangSQL('cid', 'AND', 'c');
         }
     }
     if (!Dataproxy::isRoot()) {
         $sql .= COM_getPermSQL('AND', Dataproxy::uid(), 2, 'c');
     }
     $result = DB_query($sql);
     if (DB_error()) {
         return $entries;
     }
     while (($A = DB_fetchArray($result, FALSE)) !== FALSE) {
         $entry = array();
         $entry['id'] = $A['lid'];
         $entry['title'] = stripslashes($A['title']);
         $entry['uri'] = COM_buildUrl($_CONF['site_url'] . '/downloads/index.php?id=' . $entry['id']);
         $entry['date'] = (int) $A['date'];
         $entry['image_uri'] = $A['logourl'];
         $entries[] = $entry;
     }
     return $entries;
 }
Beispiel #22
0
while (list($sid, $expiretopic, $title, $expire, $statuscode) = DB_fetchArray($expiresql)) {
    if ($statuscode == STORY_ARCHIVE_ON_EXPIRE) {
        if (!empty($archivetid)) {
            COM_errorLog("Archive Story: {$sid}, Topic: {$archivetid}, Title: {$title}, Expired: {$expire}");
            DB_query("UPDATE {$_TABLES['stories']} SET tid = '{$archivetid}', frontpage = '0', featured = '0' WHERE sid='{$sid}'");
        }
    } else {
        if ($statuscode == STORY_DELETE_ON_EXPIRE) {
            COM_errorLog("Delete Story and comments: {$sid}, Topic: {$expiretopic}, Title: {$title}, Expired: {$expire}");
            STORY_doDeleteThisStoryNow($sid);
        }
    }
}
$sql = " (date <= NOW()) AND (draft_flag = 0)";
if (empty($topic)) {
    $sql .= COM_getLangSQL('tid', 'AND', 's');
}
// if a topic was provided only select those stories.
if (!empty($topic)) {
    $sql .= " AND s.tid = '{$topic}' ";
} elseif (!$newstories) {
    $sql .= " AND frontpage = 1 ";
}
if ($topic != $archivetid) {
    $sql .= " AND s.tid != '{$archivetid}' ";
}
$sql .= COM_getPermSQL('AND', 0, 2, 's');
if (!empty($U['aids'])) {
    $sql .= " AND s.uid NOT IN (" . str_replace(' ', ",", $U['aids']) . ") ";
}
if (!empty($U['tids'])) {
Beispiel #23
0
/**
* Create the links list depending on the category given
*
* @param    array   $message    message(s) to display
* @return   string              the links page
*
*/
function links_list($message)
{
    global $_CONF, $_TABLES, $_LI_CONF, $LANG_LINKS_ADMIN, $LANG_LINKS, $LANG_LINKS_STATS;
    $cid = $_LI_CONF['root'];
    $display = '';
    if (isset($_GET['category'])) {
        $cid = strip_tags(COM_stripslashes($_GET['category']));
    } elseif (isset($_POST['category'])) {
        $cid = strip_tags(COM_stripslashes($_POST['category']));
    }
    $cat = DB_escapeString($cid);
    $page = 0;
    if (isset($_GET['page'])) {
        $page = COM_applyFilter($_GET['page'], true);
    }
    if ($page == 0) {
        $page = 1;
    }
    if (empty($cid)) {
        if ($page > 1) {
            $page_title = sprintf($LANG_LINKS[114] . ' (%d)', $page);
        } else {
            $page_title = $LANG_LINKS[114];
        }
    } else {
        if ($cid == $_LI_CONF['root']) {
            $category = $LANG_LINKS['root'];
        } else {
            $category = DB_getItem($_TABLES['linkcategories'], 'category', "cid = '{$cat}'");
        }
        if ($page > 1) {
            $page_title = sprintf($LANG_LINKS[114] . ': %s (%d)', $category, $page);
        } else {
            $page_title = sprintf($LANG_LINKS[114] . ': %s', $category);
        }
    }
    // Check has access and existent to this category
    if ($cid != $_LI_CONF['root']) {
        $result = DB_query("SELECT owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon FROM {$_TABLES['linkcategories']} WHERE cid='{$cat}'");
        $A = DB_fetchArray($result);
        if (SEC_hasAccess($A['owner_id'], $A['group_id'], $A['perm_owner'], $A['perm_group'], $A['perm_members'], $A['perm_anon']) < 2) {
            $display .= COM_showMessage(5, 'links');
            $display = COM_createHTMLDocument($display, array('pagetitle' => $page_title));
            COM_output($display);
            exit;
        }
        // check existent
        if (!isset($A['owner_id'])) {
            $display .= COM_showMessage(16, 'links');
            $display = COM_createHTMLDocument($display, array('pagetitle' => $page_title));
            COM_output($display);
            exit;
        }
    }
    if (is_array($message) && !empty($message[0])) {
        $display .= COM_showMessageText($message[1], $message[0]);
    } else {
        if (isset($_REQUEST['msg'])) {
            $msg = COM_applyFilter($_REQUEST['msg'], true);
            if ($msg > 0) {
                $display .= COM_showMessage($msg, 'links');
            }
        }
    }
    $linklist = COM_newTemplate(CTL_plugin_templatePath('links'));
    $linklist->set_file(array('linklist' => 'links.thtml', 'catlinks' => 'categorylinks.thtml', 'link' => 'linkdetails.thtml', 'catnav' => 'categorynavigation.thtml', 'catrow' => 'categoryrow.thtml', 'catcol' => 'categorycol.thtml', 'actcol' => 'categoryactivecol.thtml', 'pagenav' => 'pagenavigation.thtml', 'catdrop' => 'categorydropdown.thtml'));
    $linklist->set_var('blockheader', COM_startBlock($LANG_LINKS[114]));
    if ($_LI_CONF['linkcols'] > 0) {
        // Create breadcrumb trail
        $linklist->set_var('breadcrumbs', links_breadcrumbs($_LI_CONF['root'], $cid));
        // Set dropdown for category jump
        $linklist->set_var('lang_go', $LANG_LINKS[124]);
        $linklist->set_var('link_dropdown', links_select_box(2, $cid));
        // Show categories
        $sql = "SELECT cid,pid,category,description FROM {$_TABLES['linkcategories']} WHERE pid='{$cat}'";
        $sql .= COM_getLangSQL('cid', 'AND');
        $sql .= COM_getPermSQL('AND') . " ORDER BY category";
        $result = DB_query($sql);
        $nrows = DB_numRows($result);
        if ($nrows > 0) {
            $linklist->set_var('lang_categories', $LANG_LINKS_ADMIN[14]);
            for ($i = 1; $i <= $nrows; $i++) {
                $C = DB_fetchArray($result);
                // Get number of child links user can see in this category
                $ccid = DB_escapeString($C['cid']);
                $result1 = DB_query("SELECT COUNT(*) AS count FROM {$_TABLES['links']} WHERE cid='{$ccid}'" . COM_getPermSQL('AND'));
                $D = DB_fetchArray($result1);
                // Get number of child categories user can see in this category
                $result2 = DB_query("SELECT COUNT(*) AS count FROM {$_TABLES['linkcategories']} WHERE pid='{$ccid}'" . COM_getPermSQL('AND'));
                $E = DB_fetchArray($result2);
                // Format numbers for display
                $display_count = '';
                // don't show zeroes
                if ($E['count'] > 0) {
                    $display_count = COM_numberFormat($E['count']);
                }
                if ($E['count'] > 0 && $D['count'] > 0) {
                    $display_count .= ', ';
                }
                if ($D['count'] > 0) {
                    $display_count .= COM_numberFormat($D['count']);
                }
                // add brackets if child items exist
                if ($display_count != '') {
                    $display_count = '(' . $display_count . ')';
                }
                $linklist->set_var('category_name', $C['category']);
                if ($_LI_CONF['show_category_descriptions']) {
                    $linklist->set_var('category_description', PLG_replaceTags($C['description']));
                } else {
                    $linklist->set_var('category_description', '');
                }
                $linklist->set_var('category_link', $_CONF['site_url'] . '/links/index.php?category=' . rawurlencode($C['cid']));
                $linklist->set_var('category_count', $display_count);
                $linklist->set_var('width', floor(100 / $_LI_CONF['linkcols']));
                if (!empty($cid) && $cid == $C['cid']) {
                    $linklist->parse('category_col', 'actcol', true);
                } else {
                    $linklist->parse('category_col', 'catcol', true);
                }
                if ($i % $_LI_CONF['linkcols'] == 0) {
                    $linklist->parse('category_row', 'catrow', true);
                    $linklist->set_var('category_col', '');
                }
            }
            if ($nrows % $_LI_CONF['linkcols'] != 0) {
                $linklist->parse('category_row', 'catrow', true);
            }
            $linklist->parse('category_navigation', 'catnav', true);
        } else {
            $linklist->set_var('category_navigation', '');
        }
    } else {
        $linklist->set_var('category_navigation', '');
    }
    if ($_LI_CONF['linkcols'] == 0) {
        $linklist->set_var('category_dropdown', '');
    } else {
        $linklist->parse('category_dropdown', 'catdrop', true);
    }
    $linklist->set_var('cid', $cid);
    $linklist->set_var('cid_plain', $cid);
    $linklist->set_var('cid_encoded', rawurlencode($cid));
    $linklist->set_var('lang_addalink', $LANG_LINKS[116]);
    // Build SQL for links
    $sql = 'SELECT lid,cid,url,description,title,hits,owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon';
    $from_where = " FROM {$_TABLES['links']}";
    if ($_LI_CONF['linkcols'] > 0) {
        if (!empty($cid)) {
            $from_where .= " WHERE cid='" . DB_escapeString($cid) . "'";
        } else {
            $from_where .= " WHERE cid=''";
        }
        $from_where .= COM_getPermSQL('AND');
    } else {
        $from_where .= COM_getPermSQL();
    }
    $order = ' ORDER BY cid ASC,title';
    $limit = '';
    if ($_LI_CONF['linksperpage'] > 0) {
        if ($page < 1) {
            $start = 0;
        } else {
            $start = ($page - 1) * $_LI_CONF['linksperpage'];
        }
        $limit = ' LIMIT ' . $start . ',' . $_LI_CONF['linksperpage'];
    }
    $result = DB_query($sql . $from_where . $order . $limit);
    $nrows = DB_numRows($result);
    if ($nrows == 0) {
        if ($cid == $_LI_CONF['root'] && $page <= 1 && $_LI_CONF['show_top10']) {
            $result = DB_query("SELECT lid,url,title,description,hits,owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon FROM {$_TABLES['links']} WHERE (hits > 0)" . COM_getPermSQL('AND') . LINKS_getCategorySQL('AND') . " ORDER BY hits DESC LIMIT 10");
            $nrows = DB_numRows($result);
            if ($nrows > 0) {
                $linklist->set_var('link_details', '');
                $linklist->set_var('link_category', $LANG_LINKS_STATS['stats_headline']);
                for ($i = 0; $i < $nrows; $i++) {
                    $A = DB_fetchArray($result);
                    prepare_link_item($A, $linklist);
                    $linklist->parse('link_details', 'link', true);
                }
                $linklist->parse('category_links', 'catlinks', true);
            }
        }
        $linklist->set_var('page_navigation', '');
    } else {
        $currentcid = '';
        for ($i = 0; $i < $nrows; $i++) {
            $A = DB_fetchArray($result);
            if (strcasecmp($A['cid'], $currentcid) != 0) {
                // print the category and link
                if ($i > 0) {
                    $linklist->parse('category_links', 'catlinks', true);
                    $linklist->set_var('link_details', '');
                }
                $currentcid = $A['cid'];
                $currentcategory = DB_getItem($_TABLES['linkcategories'], 'category', "cid = '" . DB_escapeString($currentcid) . "'");
                if ($A['cid'] == $_LI_CONF['root']) {
                    $linklist->set_var('link_category', $LANG_LINKS['root']);
                } else {
                    $linklist->set_var('link_category', $currentcategory);
                }
            }
            prepare_link_item($A, $linklist);
            $linklist->parse('link_details', 'link', true);
        }
        $linklist->parse('category_links', 'catlinks', true);
        $result = DB_query('SELECT COUNT(*) AS count ' . $from_where);
        list($numlinks) = DB_fetchArray($result);
        $pages = 0;
        if ($_LI_CONF['linksperpage'] > 0) {
            $pages = (int) ($numlinks / $_LI_CONF['linksperpage']);
            if ($numlinks % $_LI_CONF['linksperpage'] > 0) {
                $pages++;
            }
        }
        if ($pages > 0) {
            if ($_LI_CONF['linkcols'] > 0 && !empty($currentcid)) {
                $catlink = '?category=' . rawurlencode($currentcid);
            } else {
                $catlink = '';
            }
            $linklist->set_var('page_navigation', COM_printPageNavigation($_CONF['site_url'] . '/links/index.php' . $catlink, $page, $pages));
        } else {
            $linklist->set_var('page_navigation', '');
        }
    }
    $linklist->set_var('blockfooter', COM_endBlock());
    $linklist->parse('output', 'linklist');
    $display .= $linklist->finish($linklist->get_var('output'));
    $display = COM_createHTMLDocument($display, array('pagetitle' => $page_title));
    return $display;
}
Beispiel #24
0
/**
* Create the banner list depending on the category given
*
* @param    array   $message    message(s) to display
* @return   string              the banner page
*
*/
function banner_list($message)
{
    global $_CONF, $_TABLES, $_BAN_CONF, $LANG_BANNER_ADMIN, $LANG_BANNER, $LANG_BANNER_STATS;
    $cid = $_BAN_CONF['root'];
    $display = '';
    if (isset($_GET['category'])) {
        $cid = strip_tags(COM_stripslashes($_GET['category']));
    } elseif (isset($_POST['category'])) {
        $cid = strip_tags(COM_stripslashes($_POST['category']));
    }
    $cat = addslashes($cid);
    $page = 0;
    if (isset($_GET['page'])) {
        $page = COM_applyFilter($_GET['page'], true);
    }
    if ($page == 0) {
        $page = 1;
    }
    if (empty($cid)) {
        if ($page > 1) {
            $page_title = sprintf($LANG_BANNER[114] . ' (%d)', $page);
        } else {
            $page_title = $LANG_BANNER[114];
        }
    } else {
        if ($cid == $_BAN_CONF['root']) {
            $category = $LANG_BANNER['root'];
        } else {
            $category = DB_getItem($_TABLES['bannercategories'], 'category', "cid = '{$cat}'");
        }
        if ($page > 1) {
            $page_title = sprintf($LANG_BANNER[114] . ': %s (%d)', $category, $page);
        } else {
            $page_title = sprintf($LANG_BANNER[114] . ': %s', $category);
        }
    }
    // Check has access to this category
    if ($cid != $_BAN_CONF['root']) {
        $result = DB_query("SELECT owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon FROM {$_TABLES['bannercategories']} WHERE cid='{$cat}'");
        $A = DB_fetchArray($result);
        if (SEC_hasAccess($A['owner_id'], $A['group_id'], $A['perm_owner'], $A['perm_group'], $A['perm_members'], $A['perm_anon']) < 2) {
            $display .= COM_siteHeader('menu', $page_title);
            $display .= COM_showMessage(5, 'banner');
            $display .= COM_siteFooter();
            echo $display;
            exit;
        }
    }
    $display .= COM_siteHeader('menu', $page_title);
    if (is_array($message) && !empty($message[0])) {
        $display .= COM_startBlock($message[0], '', COM_getBlockTemplate('_msg_block', 'header'));
        $display .= $message[1];
        $display .= COM_endBlock(COM_getBlockTemplate('_msg_block', 'footer'));
    } else {
        if (isset($_REQUEST['msg'])) {
            $msg = COM_applyFilter($_REQUEST['msg'], true);
            if ($msg > 0) {
                $display .= COM_showMessage($msg, 'banner');
            }
        }
    }
    $bannerlist = new Template($_CONF['path'] . 'plugins/banner/templates/');
    $bannerlist->set_file(array('bannerlist' => 'banner.thtml', 'catbanner' => 'categorybanner.thtml', 'banner' => 'bannerdetails.thtml', 'catnav' => 'categorynavigation.thtml', 'catrow' => 'categoryrow.thtml', 'catcol' => 'categorycol.thtml', 'actcol' => 'categoryactivecol.thtml', 'pagenav' => 'pagenavigation.thtml', 'catdrop' => 'categorydropdown.thtml'));
    $bannerlist->set_var('xhtml', XHTML);
    $bannerlist->set_var('blockheader', COM_startBlock($LANG_BANNER[114]));
    $bannerlist->set_var('layout_url', $_CONF['layout_url']);
    if ($_BAN_CONF['bannercols'] > 0) {
        // Create breadcrumb trail
        $bannerlist->set_var('breadcrumbs', banner_breadcrumbs($_BAN_CONF['root'], $cid));
        // Set dropdown for category jump
        $bannerlist->set_var('lang_go', $LANG_BANNER[124]);
        $bannerlist->set_var('banner_dropdown', banner_select_box(2, $cid));
        // Show categories
        $sql = "SELECT cid,pid,category,description FROM {$_TABLES['bannercategories']} WHERE pid='{$cat}'";
        $sql .= COM_getLangSQL('cid', 'AND');
        $sql .= COM_getPermSQL('AND') . " ORDER BY category";
        $result = DB_query($sql);
        $nrows = DB_numRows($result);
        if ($nrows > 0) {
            $bannerlist->set_var('lang_categories', $LANG_BANNER_ADMIN[14]);
            for ($i = 1; $i <= $nrows; $i++) {
                $C = DB_fetchArray($result);
                // Get number of child banner user can see in this category
                $ccid = addslashes($C['cid']);
                $result1 = DB_query("SELECT COUNT(*) AS count FROM {$_TABLES['banner']} WHERE cid='{$ccid}'" . COM_getPermSQL('AND'));
                $D = DB_fetchArray($result1);
                // Get number of child categories user can see in this category
                $result2 = DB_query("SELECT COUNT(*) AS count FROM {$_TABLES['bannercategories']} WHERE pid='{$ccid}'" . COM_getPermSQL('AND'));
                $E = DB_fetchArray($result2);
                // Format numbers for display
                $display_count = '';
                // don't show zeroes
                if ($E['count'] > 0) {
                    $display_count = COM_numberFormat($E['count']);
                }
                if ($E['count'] > 0 && $D['count'] > 0) {
                    $display_count .= ', ';
                }
                if ($D['count'] > 0) {
                    $display_count .= COM_numberFormat($D['count']);
                }
                // add brackets if child items exist
                if ($display_count != '') {
                    $display_count = '(' . $display_count . ')';
                }
                $bannerlist->set_var('category_name', $C['category']);
                if ($_BAN_CONF['show_category_descriptions']) {
                    $bannerlist->set_var('category_description', $C['description']);
                } else {
                    $bannerlist->set_var('category_description', '');
                }
                $bannerlist->set_var('category_link', $_CONF['site_url'] . '/banner/index.php?category=' . urlencode($C['cid']));
                $bannerlist->set_var('category_count', $display_count);
                $bannerlist->set_var('width', floor(100 / $_BAN_CONF['bannercols']));
                if (!empty($cid) && $cid == $C['cid']) {
                    $bannerlist->parse('category_col', 'actcol', true);
                } else {
                    $bannerlist->parse('category_col', 'catcol', true);
                }
                if ($i % $_BAN_CONF['bannercols'] == 0) {
                    $bannerlist->parse('category_row', 'catrow', true);
                    $bannerlist->set_var('category_col', '');
                }
            }
            if ($nrows % $_BAN_CONF['bannercols'] != 0) {
                $bannerlist->parse('category_row', 'catrow', true);
            }
            $bannerlist->parse('category_navigation', 'catnav', true);
        } else {
            $bannerlist->set_var('category_navigation', '');
        }
    } else {
        $bannerlist->set_var('category_navigation', '');
    }
    if ($_BAN_CONF['bannercols'] == 0) {
        $bannerlist->set_var('category_dropdown', '');
    } else {
        $bannerlist->parse('category_dropdown', 'catdrop', true);
    }
    $bannerlist->set_var('site_url', $_CONF['site_url']);
    $bannerlist->set_var('cid', $cid);
    $bannerlist->set_var('cid_plain', $cid);
    $bannerlist->set_var('cid_encoded', urlencode($cid));
    $bannerlist->set_var('lang_addabanner', $LANG_BANNER[116]);
    // Build SQL for banner
    $sql = 'SELECT bid,cid,url,description,title,hits,owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon';
    $from_where = " FROM {$_TABLES['banner']}";
    if ($_BAN_CONF['bannercols'] > 0) {
        if (!empty($cid)) {
            $from_where .= " WHERE cid='" . addslashes($cid) . "'";
        } else {
            $from_where .= " WHERE cid=''";
        }
        $from_where .= ' AND (publishstart IS NULL OR publishstart < NOW()) and (publishend IS NULL OR publishend > NOW())';
        $from_where .= COM_getPermSQL('AND');
    } else {
        $from_where .= COM_getPermSQL();
    }
    $order = ' ORDER BY cid ASC,title';
    $limit = '';
    if ($_BAN_CONF['bannerperpage'] > 0) {
        if ($page < 1) {
            $start = 0;
        } else {
            $start = ($page - 1) * $_BAN_CONF['bannerperpage'];
        }
        $limit = ' LIMIT ' . $start . ',' . $_BAN_CONF['bannerperpage'];
    }
    $result = DB_query($sql . $from_where . $order . $limit);
    $nrows = DB_numRows($result);
    if ($nrows == 0) {
        if ($cid == $_BAN_CONF['root'] && $page <= 1 && $_BAN_CONF['show_top10']) {
            $result = DB_query("SELECT bid,url,title,description,hits,owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon FROM {$_TABLES['banner']} WHERE (hits > 0) AND (publishstart IS NULL OR publishstart < NOW()) and (publishend IS NULL OR publishend > NOW())" . COM_getPermSQL('AND') . " ORDER BY hits DESC LIMIT 10");
            $nrows = DB_numRows($result);
            if ($nrows > 0) {
                $bannerlist->set_var('banner_details', '');
                $bannerlist->set_var('banner_category', $LANG_BANNER_STATS['stats_headline']);
                for ($i = 0; $i < $nrows; $i++) {
                    $A = DB_fetchArray($result);
                    prepare_banner_item($A, $bannerlist);
                    $bannerlist->parse('banner_details', 'banner', true);
                }
                $bannerlist->parse('category_banner', 'catbanner', true);
            }
        }
        $bannerlist->set_var('page_navigation', '');
    } else {
        $currentcid = '';
        for ($i = 0; $i < $nrows; $i++) {
            $A = DB_fetchArray($result);
            if (strcasecmp($A['cid'], $currentcid) != 0) {
                // print the category and banner
                if ($i > 0) {
                    $bannerlist->parse('category_banner', 'catbanner', true);
                    $bannerlist->set_var('banner_details', '');
                }
                $currentcid = $A['cid'];
                $currentcategory = DB_getItem($_TABLES['bannercategories'], 'category', "cid = '" . addslashes($currentcid) . "'");
                $bannerlist->set_var('banner_category', $currentcategory);
            }
            prepare_banner_item($A, $bannerlist);
            $bannerlist->parse('banner_details', 'banner', true);
        }
        $bannerlist->parse('category_banner', 'catbanner', true);
        $result = DB_query('SELECT COUNT(*) AS count ' . $from_where);
        list($numbanner) = DB_fetchArray($result);
        $pages = 0;
        if ($_BAN_CONF['bannerperpage'] > 0) {
            $pages = (int) ($numbanner / $_BAN_CONF['bannerperpage']);
            if ($numbanner % $_BAN_CONF['bannerperpage'] > 0) {
                $pages++;
            }
        }
        if ($pages > 0) {
            if ($_BAN_CONF['bannercols'] > 0 && !empty($currentcid)) {
                $catbanner = '?category=' . urlencode($currentcid);
            } else {
                $catbanner = '';
            }
            $bannerlist->set_var('page_navigation', COM_printPageNavigation($_CONF['site_url'] . '/banner/index.php' . $catbanner, $page, $pages));
        } else {
            $bannerlist->set_var('page_navigation', '');
        }
    }
    $bannerlist->set_var('blockfooter', COM_endBlock());
    $bannerlist->parse('output', 'bannerlist');
    $display .= $bannerlist->finish($bannerlist->get_var('output'));
    return $display;
}
Beispiel #25
0
/**
* This function creates an html list of topics the object belongs too or
* creates a similar list based on topics passed to it
*
* @param    string          $type           Type of object to display access for
* @param    string          $id             Id of onject
* @param    integer         $max            Max number of items returned
* @param    string/array    $tids           Topics Ids to use instead of retrieving from db
* @return   HTML string
*
*/
function TOPIC_relatedTopics($type, $id, $max = 6, $tids = array())
{
    global $_CONF, $LANG27, $_TABLES;
    $retval = '';
    if ($max < 0) {
        $max = 6;
    }
    if (!is_array($tids)) {
        $tids = array($tids);
    }
    // if topic ids not passed then retrieve from db
    $from_db = false;
    if (empty($tids)) {
        $from_db = true;
    }
    if ($from_db) {
        // Retrieve Topic options
        $sql = "SELECT ta.tid, t.topic\n            FROM {$_TABLES['topic_assignments']} ta, {$_TABLES['topics']} t\n            WHERE t.tid = ta.tid AND ta.type = '{$type}' AND ta.id ='{$id}'\n            " . COM_getPermSQL('AND', 0, 2, 't') . COM_getLangSQL('tid', 'AND', 't') . "\n            AND t.tid != '" . TOPIC_ALL_OPTION . "' AND t.tid != '" . TOPIC_HOMEONLY_OPTION . "'";
    } else {
        $sql = "SELECT tid, topic\n            FROM {$_TABLES['topics']} t\n            WHERE (tid IN ('" . implode("','", $tids) . "'))";
    }
    $sql .= COM_getPermSQL('AND');
    if ($from_db) {
        $sql .= " ORDER BY tdefault DESC, topic ASC";
    } else {
        $sql .= " ORDER BY topic ASC";
    }
    if ($max > 0) {
        $sql .= " LIMIT " . $max;
    }
    $result = DB_query($sql);
    $nrows = DB_numRows($result);
    if ($nrows > 0) {
        $topicrelated = COM_newTemplate($_CONF['path_layout']);
        $topicrelated->set_file(array('topicrelated' => 'topicrelated.thtml'));
        $blocks = array('topicitem', 'separator');
        foreach ($blocks as $block) {
            $topicrelated->set_block('topicrelated', $block);
        }
        $topicrelated->set_var('lang_filed_under', $LANG27['filed_under:']);
        for ($i = 0; $i < $nrows; $i++) {
            $A = DB_fetchArray($result);
            $url = COM_buildURL($_CONF['site_url'] . '/index.php?topic=' . $A['tid']);
            $topicrelated->set_var('topic_url', $url);
            $topicrelated->set_var('topic', $A['topic']);
            $topicrelated->parse('topics', 'topicitem', true);
            if ($i + 1 < $nrows) {
                $topicrelated->parse('topics', 'separator', true);
            }
        }
        $retval = $topicrelated->finish($topicrelated->parse('topicrelated', 'topicrelated'));
    }
    return $retval;
}
Beispiel #26
0
 /**
  * Performs search on all comments
  *
  * @author Tony Bibbs <tony AT geeklog DOT net>
  *         Sami Barakat <s.m.barakat AT gmail DOT com>
  * @access private
  * @return object plugin object
  *
  */
 function _searchComments()
 {
     global $_CONF, $_TABLES, $_DB_dbms, $LANG09;
     // Make sure the query is SQL safe
     $query = trim(DB_escapeString(htmlspecialchars($this->_query)));
     $sql = "SELECT s.sid AS id, c.title AS title, c.comment AS description, UNIX_TIMESTAMP(c.date) AS date, c.uid AS uid, '0' AS hits, ";
     if ($_CONF['url_rewrite']) {
         $sql .= "CONCAT('/article.php/',s.sid,'#comments') AS url ";
     } else {
         $sql .= "CONCAT('/article.php?story=',s.sid,'#comments') AS url ";
     }
     $sql .= "FROM {$_TABLES['users']} AS u, {$_TABLES['comments']} AS c ";
     $sql .= "LEFT JOIN {$_TABLES['stories']} AS s ON ((s.sid = c.sid) ";
     $sql .= COM_getPermSQL('AND', 0, 2, 's') . COM_getTopicSQL('AND', 0, 's') . COM_getLangSQL('sid', 'AND', 's') . ") ";
     $sql .= "WHERE (u.uid = c.uid) AND (s.draft_flag = 0) AND (s.commentcode >= 0) AND (s.date <= NOW()) ";
     if (!empty($this->_topic)) {
         $sql .= "AND (s.tid = '" . DB_escapeString($this->_topic) . "') ";
     }
     if (!empty($this->_author)) {
         $sql .= "AND (c.uid = " . (int) $this->_author . ") ";
     }
     $search = new SearchCriteria('comments', $LANG09[65] . ' > ' . $LANG09[66]);
     $columns = array('comment', 'c.title');
     $sql .= $search->getDateRangeSQL('AND', 'UNIX_TIMESTAMP(c.date)', $this->_dateStart, $this->_dateEnd);
     list($sql, $ftsql) = $search->buildSearchSQL($this->_keyType, $query, $columns, $sql);
     $search->setSQL($sql);
     $search->setFTSQL($ftsql);
     $search->setRank(2);
     return $search;
 }
/**
* Common function to be called from phpblock_lastarticles() and
* phpblock_lastarticles2()
*/
function phpblock_lastarticles_common($numrows = 10, $length = 50, $additional_sql = '')
{
    global $_CONF, $_TABLES;
    if (!defined('XHTML')) {
        define('XHTML', '');
    }
    $numrows = intval($numrows);
    if ($numrows < 1) {
        $numrows = 10;
    }
    $length = intval($length);
    if ($length < 1) {
        $length = 50;
    }
    $sql = "SELECT STRAIGHT_JOIN " . LB;
    $sql .= " s.sid";
    $sql .= " , t.tid";
    $sql .= " , s.title, s.date, s.group_id " . LB;
    $sql .= " , s.introtext, s.bodytext, t.topic " . LB;
    $sql .= "  FROM {$_TABLES['stories']} AS s" . LB;
    $sql .= ", {$_TABLES['topics']} AS t " . LB;
    //FOR GL2.0.0
    if (COM_versionCompare(VERSION, "2.0.0", '>=')) {
        $sql .= " ,{$_TABLES['topic_assignments']} AS t2" . LB;
    }
    $sql .= "  WHERE " . LB;
    $sql .= " (s.title <> '') " . LB;
    //FOR GL2.0.0
    if (COM_versionCompare(VERSION, "2.0.0", '>=')) {
        $sql .= "  AND s.sid = t2.id" . LB;
        $sql .= "  AND t2.tid = t.tid" . LB;
    } else {
        $sql .= " AND (s.tid = t.tid) " . LB;
    }
    $sql .= " AND (s.draft_flag = 0) " . LB;
    $sql .= " AND (s.date <= NOW()) " . LB;
    $sql .= COM_getTopicSQL('AND', 0, 't') . LB;
    if (function_exists('COM_getLangSQL')) {
        $sql .= COM_getLangSQL('sid', 'AND', 's') . LB;
    }
    $sql .= $additional_sql . LB . "ORDER BY s.date DESC " . "LIMIT " . $numrows;
    $result = DB_query($sql);
    $template = LASTARTICLES_getTemplate();
    $encoding = LASTARTICLES_getEncoding();
    $retval = '';
    while (($A = DB_fetchArray($result, FALSE)) !== FALSE) {
        $introtext = PLG_replaceTags(stripslashes($A['introtext']));
        $bodytext = PLG_replaceTags(stripslashes($A['bodytext']));
        $article = mb_strimwidth(strip_tags($introtext), 0, LASTARTICLES_ARTICLE_LENGTH, '...', $encoding);
        $date = date(LASTARTICLES_DATE_FORMAT, strtotime($A['date']));
        $img = LASTARTICLES_renderImageTag($introtext . $bodytext);
        $link = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $A['sid']);
        $title = mb_strimwidth(stripslashes($A['title']), 0, $length, '...', $encoding);
        $topic = LASTARTICLES_esc($A['topic']);
        $retval .= str_replace(array('{article}', '{date}', '{img}', '{link}', '{title}', '{topic}', '{xhtml}'), array($article, $date, $img, $link, $title, $topic, XHTML), $template);
    }
    return $retval;
}