/**
 * sidに対応する多言語記事が存在する場合はその記事へのリンクを作成し返す関数
 *   $sid : story id
 *   --------------
 *   return : 多言語記事へのリンク
**/
function CUSTOM_multilangstory($sid)
{
    global $_CONF, $_TABLES;
    $retval = '';
    if (empty($_CONF['languages']) || empty($_CONF['language_files']) || count($_CONF['languages']) != count($_CONF['language_files'])) {
        return $retval;
    }
    $work = split('_', $sid);
    $cur_lang = array_pop($work);
    if (empty($cur_lang) || !array_key_exists($cur_lang, $_CONF['languages'])) {
        return $retval;
    }
    $entries = array();
    $mini_sid = implode('_', $work);
    foreach ($_CONF['languages'] as $key => $value) {
        if ($cur_lang != $key) {
            $mul_sid = DB_getItem($_TABLES['stories'], 'sid', 'sid="' . $mini_sid . '_' . $key . '"');
            if (!empty($mul_sid)) {
                $url = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $mul_sid);
                $entries[] = '<a href="' . $url . '">' . $value . '</a>';
            }
        }
    }
    if (sizeof($entries) > 0) {
        $retval .= COM_makeList($entries);
    }
    return $retval;
}
示例#2
0
/**
 * Create "What's Related" links for a story
 * Creates an HTML-formatted list of links to be used for the What's Related
 * block next to a story (in article view).
 *
 * @param        string $related contents of gl_stories 'related' field
 * @param        int    $uid     user id of the author
 * @param        int    $sid     story id
 * @return       string      HTML-formatted list of links
 */
function STORY_whatsRelated($related, $uid, $sid)
{
    global $_CONF, $_TABLES, $LANG24;
    // Is it enabled?
    // Disabled' => 0, 'Enabled' => 1, 'Enabled (No Links)' => 2, 'Enabled (No Outbound Links)' => 3
    if ($_CONF['whats_related']) {
        // get the links from the story text
        if ($_CONF['whats_related'] != 2) {
            if (!empty($related)) {
                $rel = explode("\n", $related);
            } else {
                $rel = array();
            }
            // Used to hunt out duplicates. Stores urls that have already passed filters
            $urls = array();
            foreach ($rel as $key => &$value) {
                if (preg_match("/<a[^>]*href=[\"']([^\"']*)[\"'][^>]*>(.*?)<\\/a>/i", $value, $matches) === 1) {
                    // Go through array and remove links with no link text except link. Since a max of only 23 characters of link text showen then compare only this
                    if (substr($matches[1], 0, 23) != substr($matches[2], 0, 23)) {
                        // Check if outbound links (if needed)
                        $passd_check = false;
                        if ($_CONF['whats_related'] == 3) {
                            // no outbound links
                            if ($_CONF['site_url'] == substr($matches[1], 0, strlen($_CONF['site_url']))) {
                                $passd_check = true;
                            }
                        } else {
                            $passd_check = true;
                        }
                        if ($passd_check) {
                            // Go through array and remove any duplicates of this link
                            if (in_array($matches[1], $urls)) {
                                // remove it from the array
                                unset($rel[$key]);
                            } else {
                                $urls[] = $matches[1];
                                // Now Check Words
                                $value = '<a href="' . $matches[1] . '">' . COM_checkWords($matches[2], 'story') . '</a>';
                            }
                        } else {
                            // remove it from the array
                            unset($rel[$key]);
                        }
                    } else {
                        // remove it from the array
                        unset($rel[$key]);
                    }
                } else {
                    $value = COM_checkWords($value, 'story');
                }
            }
        }
        $topics = array();
        if (!COM_isAnonUser() || $_CONF['loginrequired'] == 0 && $_CONF['searchloginrequired'] == 0) {
            // add a link to "search by author"
            if ($_CONF['contributedbyline'] == 1) {
                $author = $LANG24[37] . ' ' . COM_getDisplayName($uid);
                if ($_CONF['whats_related_trim'] > 0 && MBYTE_strlen($author) > $_CONF['whats_related_trim']) {
                    $author = substr($author, 0, $_CONF['whats_related_trim'] - 3) . '...';
                }
                $topics[] = "<a href=\"{$_CONF['site_url']}/search.php?mode=search&amp;type=stories&amp;author={$uid}\">{$author}</a>";
            }
            // Retrieve topics
            $tids = TOPIC_getTopicIdsForObject('article', $sid, 0);
            foreach ($tids as $tid) {
                // add a link to "search by topic"
                $topic = $LANG24[38] . ' ' . stripslashes(DB_getItem($_TABLES['topics'], 'topic', "tid = '{$tid}'"));
                // trim topics if needed
                if ($_CONF['whats_related_trim'] > 0 && MBYTE_strlen($topic) > $_CONF['whats_related_trim']) {
                    $topic = substr($topic, 0, $_CONF['whats_related_trim'] - 3) . '...';
                }
                $topics[] = '<a href="' . $_CONF['site_url'] . '/search.php?mode=search&amp;type=stories&amp;topic=' . $tid . '">' . $topic . '</a>';
            }
        }
        // If line limit then split between related links and topics
        if ($_CONF['whats_related_max'] > 0) {
            if ($_CONF['whats_related_max'] < 3) {
                $rel = array();
                // Reset related links so at least user search and default topic search is displayed
                $topics = array_slice($topics, 0, 2);
            } else {
                $rel_max_num_items = intval($_CONF['whats_related_max'] / 2);
                $topic_max_num_items = $rel_max_num_items;
                if ($rel_max_num_items + $topic_max_num_items != $_CONF['whats_related_max']) {
                    $topic_max_num_items = $topic_max_num_items + 1;
                }
                // Now check if we have enough topics to display else give it to links
                $topic_num_items = count($topics);
                $rel_num_items = count($rel);
                $added_flag = false;
                if ($topic_num_items < $topic_max_num_items) {
                    $rel_max_num_items = $rel_max_num_items + ($topic_max_num_items - $topic_num_items);
                    $added_flag = true;
                }
                if (!$added_flag && $rel_num_items < $rel_max_num_items) {
                    $topic_max_num_items = $topic_max_num_items + ($rel_max_num_items - $rel_num_items);
                }
                $rel = array_slice($rel, 0, $rel_max_num_items);
                $topics = array_slice($topics, 0, $topic_max_num_items);
            }
        }
        $result = array_merge($rel, $topics);
        $related = '';
        if (count($result) > 0) {
            $related = COM_makeList($result, 'list-whats-related');
        }
    } else {
        $related = '';
    }
    return $related;
}
示例#3
0
/**
 * Display year view
 *
 * @param    Template $template  reference of the template
 * @param    string   $dir_topic current topic
 * @param    int      $year      year to display
 * @return   string                list of months (+ number of stories) for given year
 */
function DIR_displayYear($template, $dir_topic, $year)
{
    global $_CONF, $_TABLES, $LANG_MONTH, $LANG_DIR;
    $retval = '';
    $currentTime = time();
    $currentYear = date('Y', $currentTime);
    $currentMonth = date('m', $currentTime);
    $start = sprintf('%04d-01-01 00:00:00', $year);
    $end = sprintf('%04d-12-31 23:59:59', $year);
    $monthsql = array();
    $monthsql['mysql'] = "SELECT DISTINCT MONTH(s.date) AS month, COUNT(DISTINCT s.sid) AS count\n        FROM {$_TABLES['stories']} s, {$_TABLES['topic_assignments']} ta\n        WHERE (s.date >= '{$start}') AND (s.date <= '{$end}') AND (s.draft_flag = 0) AND (s.date <= NOW())\n        AND ta.type = 'article' AND ta.id = s.sid ";
    $monthsql['pgsql'] = "SELECT EXTRACT(Month from date) AS month,COUNT(DISTINCT sid) AS count\n        FROM {$_TABLES['stories']} , {$_TABLES['topic_assignments']} ta\n        WHERE (date >= '{$start}') AND (date <= '{$end}') AND (draft_flag = 0) AND (date <= NOW())\n        AND ta.type = 'article' AND ta.id = sid ";
    if ($dir_topic !== 'all') {
        // Retrieve list of inherited topics
        $tid_list = TOPIC_getChildList($dir_topic);
        $monthsql['mysql'] .= " AND (ta.tid IN({$tid_list}) AND (ta.inherit = 1 OR (ta.inherit = 0 AND ta.tid = '{$dir_topic}')))";
        $monthsql['pgsql'] .= " AND (ta.tid IN({$tid_list}) AND (ta.inherit = 1 OR (ta.inherit = 0 AND ta.tid = '{$dir_topic}')))";
    } else {
        $monthsql['mysql'] .= COM_getTopicSQL('AND', 0, 'ta');
        $monthsql['pgsql'] .= COM_getTopicSQL('AND', 0, 'ta');
    }
    $monthsql['mysql'] .= COM_getPermSql('AND') . COM_getLangSQL('sid', 'AND') . " GROUP BY month, date ORDER BY date ASC";
    $monthsql['pgsql'] .= COM_getPermSql('AND') . COM_getLangSQL('sid', 'AND') . " GROUP BY month, date ORDER BY DATE ASC";
    $mresult = DB_query($monthsql);
    $nummonths = DB_numRows($mresult);
    if ($nummonths > 0) {
        $items = array();
        $lastm = 1;
        for ($j = 0; $j < $nummonths; $j++) {
            $M = DB_fetchArray($mresult);
            for (; $lastm < $M['month']; $lastm++) {
                $items[] = DIR_monthLink($dir_topic, $year, $lastm, 0);
            }
            $lastm = $M['month'] + 1;
            $items[] = DIR_monthLink($dir_topic, $year, $M['month'], $M['count']);
        }
        if ($year == $currentYear) {
            $fillm = $currentMonth;
        } else {
            $fillm = 12;
        }
        if ($lastm <= $fillm) {
            for (; $lastm <= $fillm; $lastm++) {
                $items[] = DIR_monthLink($dir_topic, $year, $lastm, 0);
            }
        }
        $retval .= COM_makeList($items);
    } else {
        if (TEMPLATE_EXISTS) {
            $retval .= $template->parse('message', 'no-articles') . LB;
        } else {
            $retval .= '<p>' . $LANG_DIR['no_articles'] . '</p>' . LB;
        }
    }
    $retval .= LB;
    return $retval;
}
示例#4
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;
}
示例#5
0
/**
* Create "What's Related" links for a story
*
* Creates an HTML-formatted list of links to be used for the What's Related
* block next to a story (in article view).
*
* @param        string      $related    contents of gl_stories 'related' field
* @param        int         $uid        user id of the author
* @param        int         $tid        topic id
* @return       string      HTML-formatted list of links
*/
function STORY_whatsRelated($related, $uid, $tid)
{
    global $_CONF, $_TABLES, $_USER, $LANG24;
    // get the links from the story text
    if (!empty($related)) {
        $rel = explode("\n", $related);
    } else {
        $rel = array();
    }
    if (!empty($_USER['username']) || $_CONF['loginrequired'] == 0 && $_CONF['searchloginrequired'] == 0) {
        // add a link to "search by author"
        if ($_CONF['contributedbyline'] == 1) {
            $author = COM_getDisplayName($uid);
            $rel[] = "<a href=\"{$_CONF['site_url']}/search.php?mode=search&amp;type=stories&amp;author={$uid}\">{$LANG24[37]} {$author}</a>";
        }
        // add a link to "search by topic"
        $topic = DB_getItem($_TABLES['topics'], 'topic', "tid = '{$tid}'");
        $rel[] = '<a href="' . $_CONF['site_url'] . '/search.php?mode=search&amp;type=stories&amp;topic=' . $tid . '">' . $LANG24[38] . ' ' . stripslashes($topic) . '</a>';
    }
    $related = '';
    if (count($rel) > 0) {
        $related = COM_checkWords(COM_makeList($rel, 'list-whats-related'));
    }
    return $related;
}
示例#6
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;
}
示例#7
0
/**
* This function creates a list of the newest and recently modified items that are related based on
* the topics passed or that the object belongs too
*
* @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    integer         $trim           Max length of link text
* @param    string/array    $tids           Topics Ids to use instead of retrieving from db
* @return   HTML string
*
*/
function TOPIC_relatedItems($type, $id, $include_types = array(), $max = 10, $trim = 0, $tids = array())
{
    global $_CONF, $LANG27, $_TABLES;
    $retval = '';
    $related_items = array();
    if ($max < 1) {
        $max = 1;
    }
    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;
    }
    // Find all topics user has access too
    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            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') . "\n        ORDER BY topic ASC LIMIT " . $max;
    $result = DB_query($sql);
    $nrows = DB_numRows($result);
    if ($nrows > 0) {
        $tids = array();
        for ($i = 0; $i < $nrows; $i++) {
            $A = DB_fetchArray($result);
            $tids[] = $A['tid'];
        }
        // Now pass the topic ids to the plugins so they return the latest related items
        $related_items = PLG_getRelatedItems($include_types, $tids, $max, $trim);
        if (!empty($related_items)) {
            // Sort date so newest is first
            krsort($related_items);
            // Return only max number
            if ($max > 0) {
                $related_items = array_slice($related_items, 0, $max);
            }
        } else {
            // No related items found so and that to the list
            $related_items[] = $LANG27['no_related_items'];
        }
    } else {
        // No Topics found, most likely setting an autotag mistake but return a nice message
        $related_items[] = $LANG27['no_related_items'];
    }
    // Make html list
    $retval = COM_makeList($related_items, 'list-new-plugins');
    return $retval;
}
/**
* Returns a list of stories with a give topic id
*/
function SITEMAPMENU_listStory($tid)
{
    global $_CONF, $_TABLES, $LANG_DIR;
    $retval = '';
    $sql = "SELECT sid, title, UNIX_TIMESTAMP(date) AS day " . "FROM {$_TABLES['stories']} " . "WHERE (draft_flag = 0) AND (date <= NOW())";
    if ($tid != 'all') {
        $sql .= " AND (tid = '{$tid}')";
    }
    $sql .= COM_getTopicSql('AND') . COM_getPermSql('AND') . " ORDER BY date DESC";
    $result = DB_query($sql);
    $numrows = DB_numRows($result);
    if ($numrows > 0) {
        $entries = array();
        for ($i = 0; $i < $numrows; $i++) {
            $A = DB_fetchArray($result);
            $url = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $A['sid']);
            $entries[] = '<a class="nav-link" href="' . $url . '">' . SITEMAPMENU_esc(stripslashes($A['title'])) . '</a>';
        }
        $retval .= COM_makeList($entries) . LB;
    }
    return $retval;
}
示例#9
0
     }
 }
 /*
     if (true) { // can subscribe
         $commentSubscribeURL = '';
         $story_options[] = COM_createLink('Nubbies', $commentSubscribeURL, array('rel' => 'nofollow'));
         $story_template->set_var ('comment_subscribe_url', $commentSubscribeURL);
         $story_template->set_var ('lang_comment_subscribe', 'Nubbies');
     }
 */
 $related = STORY_whatsRelated($story->displayElements('related'), $story->displayElements('uid'), $story->displayElements('tid'));
 if (!empty($related)) {
     $related = COM_startBlock($LANG11[1], '', COM_getBlockTemplate('whats_related_block', 'header')) . $related . COM_endBlock(COM_getBlockTemplate('whats_related_block', 'footer'));
 }
 if (count($story_options) > 0) {
     $optionsblock = COM_startBlock($LANG11[4], '', COM_getBlockTemplate('story_options_block', 'header')) . COM_makeList($story_options, 'list-story-options') . COM_endBlock(COM_getBlockTemplate('story_options_block', 'footer'));
 } else {
     $optionsblock = '';
 }
 $story_template->set_var('whats_related', $related);
 $story_template->set_var('story_options', $optionsblock);
 $story_template->set_var('whats_related_story_options', $related . $optionsblock);
 // Another option here could be to figure out if story is first on page
 $tmpl = $_CONF['showfirstasfeatured'] ? 'featuredstorytext.thtml' : '';
 $story_template->set_var('formatted_article', STORY_renderArticle($story, 'n', $tmpl, $query));
 // display comments or not?
 if (is_numeric($mode) and $_CONF['allow_page_breaks'] == 1) {
     $story_page = $mode;
     $mode = '';
     if ($story_page <= 0) {
         $story_page = 1;
示例#10
0
/**
* Display month view
*
* @param    string  $topic  current topic
* @param    int     $year   year to display
* @param    int     $month  month to display
* @param    boolean $main   true: display view on its own page
* @return   string          list of articles for the given month
*
*/
function DIR_displayMonth($topic, $year, $month, $main = false)
{
    global $_CONF, $_TABLES, $LANG_MONTH, $LANG_DIR;
    $retval = '';
    if ($main) {
        $retval .= '<div><h1 style="display:inline">' . $LANG_MONTH[$month] . ' ' . $year . '</h1> ' . DIR_topicList($topic, $year, $month) . '</div>' . LB;
    } else {
        $retval .= '<h1>' . $LANG_MONTH[$month] . ' ' . $year . '</h1>' . LB;
    }
    $start = sprintf('%04d-%02d-01 00:00:00', $year, $month);
    $lastday = DIR_lastDayOfMonth($month, $year);
    $end = sprintf('%04d-%02d-%02d 23:59:59', $year, $month, $lastday);
    $sql = array();
    $sql['mysql'] = "SELECT sid,title,UNIX_TIMESTAMP(date) AS day,DATE_FORMAT(date, '%e') AS mday FROM {$_TABLES['stories']} WHERE (date >= '{$start}') AND (date <= '{$end}') AND (draft_flag = 0) AND (date <= NOW())";
    $sql['mssql'] = "SELECT sid,title,UNIX_TIMESTAMP(date) AS day,DATE_FORMAT(date, '%e') AS mday FROM {$_TABLES['stories']} WHERE (date >= '{$start}') AND (date <= '{$end}') AND (draft_flag = 0) AND (date <= NOW())";
    $sql['pgsql'] = "SELECT sid,title,UNIX_TIMESTAMP(date) AS day,EXTRACT(day from date) AS mday FROM {$_TABLES['stories']} WHERE (date >= '{$start}') AND (date <= '{$end}') AND (draft_flag = 0) AND (date <= NOW())";
    if ($topic != 'all') {
        $sql['mysql'] .= " AND (tid = '{$topic}')";
        $sql['mssql'] .= " AND (tid = '{$topic}')";
        $sql['pgsql'] .= " AND (tid = '{$topic}')";
    }
    $sql['mysql'] .= COM_getTopicSql('AND') . COM_getPermSql('AND') . COM_getLangSQL('sid', 'AND') . " ORDER BY date ASC";
    $sql['mssql'] .= COM_getTopicSql('AND') . COM_getPermSql('AND') . COM_getLangSQL('sid', 'AND') . " ORDER BY date ASC";
    $sql['pgsql'] .= COM_getTopicSql('AND') . COM_getPermSql('AND') . COM_getLangSQL('sid', 'AND') . " ORDER BY date ASC";
    $result = DB_query($sql);
    $numrows = DB_numRows($result);
    if ($numrows > 0) {
        $entries = array();
        $mday = 0;
        for ($i = 0; $i < $numrows; $i++) {
            $A = DB_fetchArray($result);
            if ($mday != $A['mday']) {
                if (count($entries) > 0) {
                    $retval .= COM_makeList($entries);
                    $entries = array();
                }
                $day = strftime($_CONF['shortdate'], $A['day']);
                $retval .= '<h2>' . $day . '</h2>' . LB;
                $mday = $A['mday'];
            }
            $url = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $A['sid']);
            $entries[] = COM_createLink(stripslashes($A['title']), $url);
        }
        if (count($entries) > 0) {
            $retval .= COM_makeList($entries);
        }
    } else {
        $retval .= '<p>' . $LANG_DIR['no_articles'] . '</p>';
    }
    $retval .= LB;
    return $retval;
}
示例#11
0
/**
* Syndication import function. Imports headline data to a portal block.
*
* Rewritten December 19th 2004 by Michael Jervis (mike@*censored*ingbrit.com). Now
* utilises a Factory Pattern to open a URL and automaticaly retreive a feed
* object populated with feed data. Then import it into the portal block.
*
* @param    string  $bid            Block ID
* @param    string  $rdfurl         URL to get content from
* @param    int     $maxheadlines   Maximum number of headlines to display
* @return   void
* @see function COM_rdfCheck
*
*/
function COM_rdfImport($bid, $rdfurl, $maxheadlines = 0)
{
    global $_CONF, $_TABLES, $LANG21;
    require_once $_CONF['path'] . '/lib/simplepie/autoloader.php';
    $result = DB_query("SELECT rdf_last_modified, rdf_etag FROM {$_TABLES['blocks']} WHERE bid = " . (int) $bid);
    list($last_modified, $etag) = DB_fetchArray($result);
    // Load the actual feed handlers:
    $feed = new SimplePie();
    $feed->set_useragent('glFusion/' . GVERSION . ' ' . SIMPLEPIE_USERAGENT);
    $feed->set_feed_url($rdfurl);
    $feed->set_cache_location($_CONF['path'] . '/data/layout_cache');
    $rc = $feed->init();
    if ($rc == true) {
        $feed->handle_content_type();
        /* We have located a reader, and populated it with the information from
         * the syndication file. Now we will sort out our display, and update
         * the block.
         */
        if ($maxheadlines == 0) {
            if (!empty($_CONF['syndication_max_headlines'])) {
                $maxheadlines = $_CONF['syndication_max_headlines'];
            }
        }
        if ($maxheadlines == 0) {
            $number_of_items = $feed->get_item_quantity();
        } else {
            $number_of_items = $feed->get_item_quantity($maxheadlines);
        }
        $etag = '';
        $update = date('Y-m-d H:i:s');
        $last_modified = $update;
        $last_modified = DB_escapeString($last_modified);
        if (empty($last_modified)) {
            DB_query("UPDATE {$_TABLES['blocks']} SET rdfupdated = '{$update}', rdf_last_modified = NULL, rdf_etag = NULL WHERE bid = " . (int) $bid);
        } else {
            DB_query("UPDATE {$_TABLES['blocks']} SET rdfupdated = '{$update}', rdf_last_modified = '{$last_modified}', rdf_etag = '{$etag}' WHERE bid = " . (int) $bid);
        }
        for ($i = 0; $i < $number_of_items; $i++) {
            $item = $feed->get_item($i);
            $title = $item->get_title();
            if (empty($title)) {
                $title = $LANG21[61];
            }
            $link = $item->get_permalink();
            $enclosure = $item->get_enclosure();
            if ($link != '') {
                $content = COM_createLink($title, $link, $attr = array('target' => '_blank'));
            } elseif ($enclosure != '') {
                $content = COM_createLink($title, $enclosure, $attr = array('target' => '_blank'));
            } else {
                $content = $title;
            }
            $articles[] = $content;
        }
        // build a list
        $content = COM_makeList($articles, 'list-feed');
        $content = str_replace(array("\r", "\n"), '', $content);
        if (strlen($content) > 65000) {
            $content = $LANG21[68];
        }
        // Standard theme based function to put it in the block
        $result = DB_change($_TABLES['blocks'], 'content', DB_escapeString($content), 'bid', (int) $bid);
    } else {
        $err = $feed->error();
        COM_errorLog($err);
        $content = DB_escapeString($err);
        DB_query("UPDATE {$_TABLES['blocks']} SET content = '{$content}', rdf_last_modified = NULL, rdf_etag = NULL WHERE bid = " . (int) $bid);
    }
}
示例#12
0
/**
* Create "What's Related" links for a story
*
* Creates an HTML-formatted list of links to be used for the What's Related
* block next to a story (in article view).
*
* @param        string      $related    contents of gl_stories 'related' field
* @param        int         $uid        user id of the author
* @param        int         $tid        topic id
* @param        int         $atid       alternate tid
* @return       string      HTML-formatted list of links
*/
function STORY_whatsRelated($related, $uid, $tid, $atid = '')
{
    global $_CONF, $_TABLES, $_USER, $LANG24;
    if (function_exists('CUSTOM_whatsRelated')) {
        return CUSTOM_whatsRelated($related, $uid, $tid);
    }
    // get the links from the story text
    if (!empty($related)) {
        $rel = explode("\n", $related);
    } else {
        $rel = array();
    }
    if (!COM_isAnonUser() || $_CONF['loginrequired'] == 0 && $_CONF['searchloginrequired'] == 0) {
        // add a link to "search by author"
        if ($_CONF['contributedbyline'] == 1) {
            $author = COM_getDisplayName($uid);
            $rel[] = "<a href=\"{$_CONF['site_url']}/search.php?mode=search&amp;type=stories&amp;author={$uid}\">{$LANG24[37]} {$author}</a>";
        }
        // add a link to "search by topic"
        $topic = DB_getItem($_TABLES['topics'], 'topic', "tid = '" . DB_escapeString($tid) . "'");
        $rel[] = '<a href="' . $_CONF['site_url'] . '/index.php?topic=' . $tid . '">' . $LANG24[38] . ' ' . $topic . '</a>';
        if ($atid != '') {
            $atopic = DB_getItem($_TABLES['topics'], 'topic', "tid = '" . DB_escapeString($atid) . "'");
            $rel[] = '<a href="' . $_CONF['site_url'] . '/index.php?topic=' . $atid . '">' . $LANG24[38] . ' ' . $atopic . '</a>';
        }
    }
    $related = '';
    if (sizeof($rel) > 0) {
        $related = COM_checkWords(COM_makeList($rel, 'list-whats-related'));
    }
    return $related;
}
示例#13
0
/**
* Create "What's Related" links for a story
*
* Creates an HTML-formatted list of links to be used for the What's Related
* block next to a story (in article view).
*
* @param        string      $related    contents of gl_stories 'related' field
* @param        int         $uid        user id of the author
* @param        int         $tid        topic id
* @return       string      HTML-formatted list of links
*/
function STORY_whatsRelated($related, $uid, $tid)
{
    global $_CONF, $_TABLES, $LANG24;
    // get the links from the story text
    if (!empty($related)) {
        $rel = explode("\n", $related);
    } else {
        $rel = array();
    }
    foreach ($rel as &$value) {
        if (preg_match("/<a[^>]*href=[\"']([^\"']*)[\"'][^>]*>(.*?)<\\/a>/i", $value, $matches) === 1) {
            $value = '<a href="' . $matches[1] . '">' . COM_checkWords($matches[2]) . '</a>';
        } else {
            $value = COM_checkWords($value);
        }
    }
    if (!COM_isAnonUser() || $_CONF['loginrequired'] == 0 && $_CONF['searchloginrequired'] == 0) {
        // add a link to "search by author"
        if ($_CONF['contributedbyline'] == 1) {
            $author = COM_getDisplayName($uid);
            $rel[] = "<a href=\"{$_CONF['site_url']}/search.php?mode=search&amp;type=stories&amp;author={$uid}\">{$LANG24[37]} {$author}</a>";
        }
        // add a link to "search by topic"
        $topic = DB_getItem($_TABLES['topics'], 'topic', "tid = '{$tid}'");
        $rel[] = '<a href="' . $_CONF['site_url'] . '/search.php?mode=search&amp;type=stories&amp;topic=' . $tid . '">' . $LANG24[38] . ' ' . stripslashes($topic) . '</a>';
    }
    $related = '';
    if (count($rel) > 0) {
        $related = COM_makeList($rel, 'list-whats-related');
    }
    return $related;
}
示例#14
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;
    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;
}
示例#15
0
/**
* Display year view
*
* @param    ref    &$template   reference of the template
* @param    string  $dir_topic  current topic
* @param    int     $year   year to display
* @return   string          list of months (+ number of stories) for given year
*
*/
function DIR_displayYear(&$template, $topic, $year, $main = false)
{
    global $_CONF, $_TABLES, $LANG_MONTH, $LANG_DIR;
    $retval = '';
    $currentyear = date('Y', time());
    $currentmonth = date('m', time());
    $start = sprintf('%04d-01-01 00:00:00', $year);
    $end = sprintf('%04d-12-31 23:59:59', $year);
    $monthsql = array();
    $monthsql['mysql'] = "SELECT DISTINCT MONTH(date) AS month,COUNT(*) AS count FROM {$_TABLES['stories']} WHERE (date >= '{$start}') AND (date <= '{$end}') AND (draft_flag = 0) AND (date <= NOW())";
    if ($topic != 'all') {
        $monthsql['mysql'] .= " AND (tid = '" . DB_escapeString($topic) . "')";
    }
    $monthsql['mysql'] .= COM_getTopicSql('AND') . COM_getPermSql('AND') . COM_getLangSQL('sid', 'AND');
    $msql = array();
    $msql['mysql'] = $monthsql['mysql'] . " GROUP BY MONTH(date) ORDER BY date ASC";
    $mresult = DB_query($msql);
    $nummonths = DB_numRows($mresult);
    if ($nummonths > 0) {
        $items = array();
        $lastm = 1;
        for ($j = 0; $j < $nummonths; $j++) {
            $M = DB_fetchArray($mresult);
            for (; $lastm < $M['month']; $lastm++) {
                $items[] = DIR_monthLink($topic, $year, $lastm, 0);
            }
            $lastm = $M['month'] + 1;
            $items[] = DIR_monthLink($topic, $year, $M['month'], $M['count']);
        }
        if ($year == $currentyear) {
            $fillm = $currentmonth;
        } else {
            $fillm = 12;
        }
        if ($lastm <= $fillm) {
            for (; $lastm <= $fillm; $lastm++) {
                $items[] = DIR_monthLink($topic, $year, $lastm, 0);
            }
        }
        $retval .= COM_makeList($items);
    } else {
        $retval .= $template->parse('message', 'no-articles') . LB;
    }
    $retval .= LB;
    return $retval;
}
示例#16
0
/**
* This function record in the hello queue the message to send to the specified group or to csv list
*
* @param    array   $vars   Same as $_POST, holds all the email info
* @return   string          HTML with success or error message
*
*/
function send_messages($vars)
{
    global $_CONF, $_TABLES, $LANG31, $LANG_HELLO01;
    require_once $_CONF['path_system'] . 'lib-user.php';
    $retval = '';
    if (empty($vars['fra']) or empty($vars['fraepost']) or empty($vars['subject']) or empty($vars['content'])) {
        $retval .= COM_startBlock($LANG31[1], '', COM_getBlockTemplate('_msg_block', 'header'));
        $retval .= $LANG31[26];
        $retval .= COM_endBlock(COM_getBlockTemplate('_msg_block', 'footer'));
        $retval .= $display .= display_mailform($vars);
        return $retval;
    }
    // Urgent message!
    if (isset($vars['priority'])) {
        $priority = 1;
    } else {
        $priority = 0;
    }
    if (!empty($vars['to_group'])) {
        $groupList = implode(',', USER_getChildGroups($vars['to_group']));
        //Group name
        $group_name = DB_query("SELECT grp_name FROM {$_TABLES['groups']} WHERE grp_id =" . $vars['to_group'] . " ");
        $group_name = DB_fetchArray($group_name);
        $email_group = $group_name[0];
        if (isset($vars['overstyr'])) {
            $sql = "SELECT DISTINCT username,fullname,email FROM {$_TABLES['users']},{$_TABLES['group_assignments']} WHERE uid > 1";
            $sql .= " AND {$_TABLES['users']}.status = 3 AND ((email is not null) and (email != ''))";
            $sql .= " AND {$_TABLES['users']}.uid = ug_uid AND ug_main_grp_id IN ({$groupList})";
        } else {
            $sql = "SELECT DISTINCT username,fullname,email,emailfromadmin FROM {$_TABLES['users']},{$_TABLES['userprefs']},{$_TABLES['group_assignments']} WHERE {$_TABLES['users']}.uid > 1";
            $sql .= " AND {$_TABLES['users']}.status = 3 AND ((email is not null) and (email != ''))";
            $sql .= " AND {$_TABLES['users']}.uid = {$_TABLES['userprefs']}.uid AND emailfromadmin = 1";
            $sql .= " AND ug_uid = {$_TABLES['users']}.uid AND ug_main_grp_id IN ({$groupList})";
        }
        $result = DB_query($sql);
        $nrows = DB_numRows($result);
        $quantity = $nrows;
    } else {
        // OK, let's upload csv file
        require_once $_CONF['path_system'] . 'classes/upload.class.php';
        $upload = new upload();
        //Debug with story debug function
        if (isset($_CONF['debug_image_upload']) && $_CONF['debug_image_upload']) {
            $upload->setLogFile($_CONF['path'] . 'logs/error.log');
            $upload->setDebug(true);
        }
        $upload->setMaxFileUploads(1);
        $upload->setAllowedMimeTypes(array('text/csv' => '.csv', 'text/comma-separated-values' => '.csv', 'application/vnd.ms-excel' => '.csv', 'application/x-csv' => '.csv'));
        if (!$upload->setPath($_CONF['path_data'])) {
            $output = COM_siteHeader('menu', $LANG24[30]);
            $output .= COM_startBlock($LANG24[30], '', COM_getBlockTemplate('_msg_block', 'header'));
            $output .= $upload->printErrors(false);
            $output .= COM_endBlock(COM_getBlockTemplate('_msg_block', 'footer'));
            $output .= COM_siteFooter();
            echo $output;
            exit;
        }
        // Set file permissions on file after it gets uploaded (number is in octal)
        $upload->setPerms('0644');
        $curfile = current($_FILES);
        if (!empty($curfile['name'])) {
            $pos = strrpos($curfile['name'], '.') + 1;
            $fextension = substr($curfile['name'], $pos);
            $filename = 'import_hello_' . COM_makesid() . '.' . $fextension;
        }
        if ($filename == '') {
            $output = COM_siteHeader('menu', $LANG24[30]);
            $output .= COM_startBlock($LANG24[30], '', COM_getBlockTemplate('_msg_block', 'header'));
            $output .= 'Upload error: csv file name is empty. Please try again...';
            $output .= COM_endBlock(COM_getBlockTemplate('_msg_block', 'footer'));
            $output .= COM_siteFooter();
            echo $output;
            exit;
        }
        $upload->setFileNames($filename);
        reset($_FILES);
        $upload->uploadFiles();
        if ($upload->areErrors()) {
            $msg = $upload->printErrors(false);
            return $LANG24[30];
        }
        //email group
        $email_group = $LANG_HELLO01['csv_file'];
        $destinataires = array();
        $separator = $vars['separator'];
        if (!in_array($separator, array(',', 'tab', ';'))) {
            $separator = ',';
        }
        if ($separator == 'tab') {
            $separator = "\t";
        }
        if (($handle = fopen($_CONF['path_data'] . $filename, "r")) !== FALSE) {
            $quantity = 0;
            while (($data = fgetcsv($handle, 0, $separator)) !== FALSE) {
                //todo check if email is valid
                if ($data[0] != '' and COM_isEmail($data[0])) {
                    $quantity++;
                    $destinataires[] = $data[0];
                }
            }
            fclose($handle);
        }
    }
    $retval .= COM_startBlock($LANG31[1]);
    // register hello
    $creation = date('YmdHi', time());
    $subject = addslashes($vars['subject']);
    $content = addslashes($vars['content']);
    $from = COM_formatEmailAddress($vars['fra'], $vars['fraepost']);
    $sql_ajout_hello = "INSERT INTO {$_TABLES['hello']} (subject, creation, email_group, quantity, content) VALUES ('{$subject}', '{$creation}', '{$email_group}', '{$quantity}','{$content}')";
    DB_query($sql_ajout_hello);
    $new_hello_id = DB_insertId();
    // Loop through and send the messages in the DB!
    $successes = 0;
    $failures = 0;
    if (!empty($vars['to_group'])) {
        for ($i = 0; $i < $quantity; $i++) {
            $A = DB_fetchArray($result);
            $destinataire = $A['email'];
            $expediteur = $from;
            $date = date('YmdHi', time());
            $sql_ajout_hello = "INSERT INTO {$_TABLES['hello_queue']} (expediteur, destinataire, date, hello_id, subject, content, priority) VALUES ('{$expediteur}', '{$destinataire}', '{$date}', '{$new_hello_id}', '{$subject}', '{$content}', '{$priority}')";
            if ($destinataire != '') {
                if (DB_query($sql_ajout_hello)) {
                    $successes = $successes + 1;
                } else {
                    $failures = $failures + 1;
                }
            } else {
                $failures = $failures + 1;
            }
        }
    } else {
        //csv file
        for ($i = 0; $i < $quantity; $i++) {
            $destinataire = $destinataires[$i];
            $expediteur = $from;
            $date = date('YmdHi', time());
            $sql_ajout_hello = "INSERT INTO {$_TABLES['hello_queue']} (expediteur, destinataire, date, hello_id, subject, content, priority) VALUES ('{$expediteur}', '{$destinataire}', '{$date}', '{$new_hello_id}', '{$subject}', '{$content}', '{$priority}')";
            if (DB_query($sql_ajout_hello)) {
                $successes = $successes + 1;
            } else {
                $failures = $failures + 1;
            }
        }
    }
    if ($successes >= 0) {
        $retval .= $i . ' ' . $LANG_HELLO01['email_schedule'] . '<br />' . $vars['priority'];
    }
    if ($failures > 0) {
        $retval .= 'Oups... There was ' . $failures . ' failure(s)';
    }
    if (empty($vars['to_group'])) {
        //list emails from csv
        reset($destinataires);
        $retval .= COM_makeList($destinataires);
    }
    $retval .= COM_endBlock();
    return $retval;
}