예제 #1
0
/**
 * Takes an article class and renders HTML in the specified template and style.
 * Formats the given article into HTML. Called by index.php, article.php,
 * submit.php and admin/story.php (Preview mode for the last two).
 *
 * @param   Story  $story    The story to display, an instance of the Story class.
 * @param   string $index    n = Full display of article. p = 'Preview' mode. Else introtext only.
 * @param   string $storyTpl The template to use to render the story.
 * @param   string $query    A search query, if one was specified.
 * @return  string           Article as formatted HTML.
 *                            Note: Formerly named COM_Article, and re-written totally since then.
 */
function STORY_renderArticle($story, $index = '', $storyTpl = 'storytext.thtml', $query = '')
{
    global $_CONF, $_TABLES, $_USER, $LANG01, $LANG05, $LANG11, $LANG_TRB, $_IMAGE_TYPE, $mode;
    static $storyCounter = 0;
    if ($story->DisplayElements('featured') == 1) {
        $article_filevar = 'featuredarticle';
    } elseif ($story->DisplayElements('statuscode') == STORY_ARCHIVE_ON_EXPIRE && $story->DisplayElements('expire') <= time()) {
        $article_filevar = 'archivearticle';
    } else {
        $article_filevar = 'article';
    }
    if (empty($storyTpl)) {
        $storyTpl = 'storytext.thtml';
    }
    // Change article template file with the topic (feature request #275)
    $templateDir = $_CONF['path_layout'];
    $topicDir = $templateDir . 'topics/' . $story->DisplayElements('tid') . '/';
    if (is_dir($topicDir) && file_exists($topicDir . $storyTpl)) {
        $templateDir = $topicDir;
    }
    $article = COM_newTemplate($templateDir);
    $article->set_file(array('article' => $storyTpl, 'bodytext' => 'storybodytext.thtml', 'featuredarticle' => 'featuredstorytext.thtml', 'featuredbodytext' => 'featuredstorybodytext.thtml', 'archivearticle' => 'archivestorytext.thtml', 'archivebodytext' => 'archivestorybodytext.thtml'));
    // begin instance caching...
    $cache_time = $story->DisplayElements('cache_time');
    $current_article_tid = $story->DisplayElements('tid');
    $retval = false;
    // If stays false will rebuild article and not used cache (checks done below)
    if ($cache_time > 0 || $cache_time == -1) {
        $hash = CACHE_security_hash();
        $cacheInstance = 'article__' . $story->getSid() . '_' . $index . $mode . '_' . $article_filevar . '_' . $current_article_tid . '_' . $hash . '_' . $_USER['theme'];
        if ($_CONF['cache_templates']) {
            $retval = $article->check_instance($cacheInstance, $article_filevar);
        } else {
            $retval = CACHE_check_instance($cacheInstance);
        }
        if ($retval && $cache_time == -1) {
            // Cache file found so use it since no time limit set to recreate
        } elseif ($retval && $cache_time > 0) {
            $lu = CACHE_get_instance_update($cacheInstance);
            $now = time();
            if ($now - $lu < $cache_time) {
                // Cache file found so use it since under time limit set to recreate
            } else {
                // generate article and create cache file
                // Cache time is not built into template caching so need to delete it manually and reset $retval
                if ($_CONF['cache_templates']) {
                    // Need to close and recreate template class since issues arise when theme templates are cached
                    unset($article);
                    // Close template class
                    CACHE_remove_instance($cacheInstance);
                    $article = COM_newTemplate($_CONF['path_layout']);
                    $article->set_file(array('article' => $storyTpl, 'bodytext' => 'storybodytext.thtml', 'featuredarticle' => 'featuredstorytext.thtml', 'featuredbodytext' => 'featuredstorybodytext.thtml', 'archivearticle' => 'archivestorytext.thtml', 'archivebodytext' => 'archivestorybodytext.thtml'));
                } else {
                    // theme templates are not cache so can go ahead and delete story cache
                    CACHE_remove_instance($cacheInstance);
                }
                $retval = false;
            }
        } else {
            // Need to reset especially if caching is disabled for a certain story but template caching has been enabled for the theme
            $retval = false;
        }
    }
    $articleUrl = COM_buildURL($_CONF['site_url'] . '/article.php?story=' . $story->getSid());
    $article->set_var('article_url', $articleUrl);
    $article->set_var('story_title', $story->DisplayElements('title'));
    // Date formatting set by user therefore cannot be cached
    $article->set_var('story_date', $story->DisplayElements('date'), false, true);
    $article->set_var('story_datetime', $story->DisplayElements('datetime'), false, true);
    // Story views increase with every visit so cannot be cached
    if ($_CONF['hideviewscount'] != 1) {
        $article->set_var('lang_views', $LANG01[106], false, true);
        $article->set_var('story_hits', $story->DisplayElements('hits'), false, true);
    }
    // Topic Icon is user configurable so do not cache
    $topicname = $story->DisplayElements('topic');
    $topicurl = COM_buildURL($_CONF['site_url'] . '/index.php?topic=' . $story->DisplayElements('tid'));
    if ((!isset($_USER['noicons']) || $_USER['noicons'] != 1) && $story->DisplayElements('show_topic_icon') == 1) {
        $imageurl = $story->DisplayElements('imageurl');
        if (!empty($imageurl)) {
            $imageurl = COM_getTopicImageUrl($imageurl);
            $article->set_var('story_topic_image_url', $imageurl, false, true);
            $topicimage = '<img src="' . $imageurl . '" class="float' . $_CONF['article_image_align'] . '" alt="' . $topicname . '" title="' . $topicname . '"' . XHTML . '>';
            $article->set_var('story_anchortag_and_image', COM_createLink($topicimage, $topicurl, array()), false, true);
            $article->set_var('story_topic_image', $topicimage, false, true);
            $topicimage_noalign = '<img src="' . $imageurl . '" alt="' . $topicname . '" title="' . $topicname . '"' . XHTML . '>';
            $article->set_var('story_anchortag_and_image_no_align', COM_createLink($topicimage_noalign, $topicurl, array()), false, true);
            $article->set_var('story_topic_image_no_align', $topicimage_noalign, false, true);
        }
    }
    // Main article content
    if ($index == 'p') {
        $introtext = $story->getPreviewText('introtext');
        $bodytext = $story->getPreviewText('bodytext');
    } else {
        $introtext = $story->displayElements('introtext');
        $bodytext = $story->displayElements('bodytext');
    }
    $readmore = empty($bodytext) ? 0 : 1;
    $numwords = COM_numberFormat(count(explode(' ', COM_getTextContent($bodytext))));
    if (COM_onFrontpage()) {
        $bodytext = '';
    }
    if (!empty($query)) {
        $introtext = COM_highlightQuery($introtext, $query);
        $bodytext = COM_highlightQuery($bodytext, $query);
    }
    // Create article only if preview, or query not empty, or if no cache version or cache version is not required
    if ($index == 'p' || !empty($query) || !$retval) {
        $article->set_var('article_filevar', '');
        $article->set_var('site_name', $_CONF['site_name']);
        //$article->set_var( 'story_date', $story->DisplayElements('date') );
        $article->set_var('story_date_short', $story->DisplayElements('shortdate'));
        $article->set_var('story_date_only', $story->DisplayElements('dateonly'));
        $article->set_var('story_id', $story->getSid());
        if ($_CONF['contributedbyline'] == 1) {
            $article->set_var('lang_contributed_by', $LANG01[1]);
            $article->set_var('contributedby_uid', $story->DisplayElements('uid'));
            $fullname = $story->DisplayElements('fullname');
            $username = $story->DisplayElements('username');
            $article->set_var('contributedby_user', $username);
            if (empty($fullname)) {
                $article->set_var('contributedby_fullname', $username);
            } else {
                $article->set_var('contributedby_fullname', $fullname);
            }
            $authorname = COM_getDisplayName($story->DisplayElements('uid'), $username, $fullname);
            $article->set_var('contributedby_author', $authorname);
            $article->set_var('author', $authorname);
            $profileUrl = '';
            if ($story->DisplayElements('uid') > 1) {
                $profileUrl = $_CONF['site_url'] . '/users.php?mode=profile&amp;uid=' . $story->DisplayElements('uid');
                $article->set_var('start_contributedby_anchortag', '<a class="storybyline" href="' . $profileUrl . '" rel="author">');
                $article->set_var('end_contributedby_anchortag', '</a>');
                $article->set_var('contributedby_url', $profileUrl);
            }
            $photo = '';
            if ($_CONF['allow_user_photo'] == 1) {
                $authphoto = $story->DisplayElements('photo');
                if (empty($authphoto)) {
                    $authphoto = '(none)';
                    // user does not have a photo
                }
                $photo = USER_getPhoto($story->DisplayElements('uid'), $authphoto, $story->DisplayElements('email'));
            }
            if (!empty($photo)) {
                $article->set_var('contributedby_photo', $photo);
                $article->set_var('author_photo', $photo);
                $camera_icon = '<img src="' . $_CONF['layout_url'] . '/images/smallcamera.' . $_IMAGE_TYPE . '" alt=""' . XHTML . '>';
                $article->set_var('camera_icon', COM_createLink($camera_icon, $profileUrl));
            } else {
                $article->set_var('contributedby_photo', '');
                $article->set_var('author_photo', '');
                $article->set_var('camera_icon', '');
            }
        }
        $article->set_var('story_topic_id', $story->DisplayElements('tid'));
        $article->set_var('story_topic_name', $topicname);
        $article->set_var('story_topic_url', $topicurl);
        $recent_post_anchortag = '';
        $article->set_var('lang_permalink', $LANG01[127]);
        $show_comments = true;
        // n = Full display of article. p = 'Preview' mode.
        if ($index != 'n' && $index != 'p' || !empty($query)) {
            $attributes = ' class="non-ul"';
            $attr_array = array('class' => 'non-ul');
            if (!empty($query)) {
                $attributes .= ' rel="bookmark"';
                $attr_array['rel'] = 'bookmark';
            }
            $article->set_var('start_storylink_anchortag', '<a href="' . $articleUrl . '"' . $attributes . '>');
            $article->set_var('end_storylink_anchortag', '</a>');
            $article->set_var('story_title_link', COM_createLink($story->DisplayElements('title'), $articleUrl, $attr_array));
        } else {
            $article->set_var('story_title_link', $story->DisplayElements('title'));
        }
        $related_topics = '';
        if ($index == 'n') {
            if ($_CONF['supported_version_theme'] == '1.8.1') {
                $article->set_var('breadcrumb_trail', TOPIC_breadcrumbs('article', $story->getSid()));
            }
            if ($_CONF['related_topics'] > 0) {
                $related_topics = TOPIC_relatedTopics('article', $story->getSid(), $_CONF['related_topics_max']);
                $article->set_var('related_topics', $related_topics);
            }
        } elseif ($index != 'p') {
            if ($_CONF['related_topics'] > 1) {
                $related_topics = TOPIC_relatedTopics('article', $story->getSid(), $_CONF['related_topics_max']);
                $article->set_var('related_topics', $related_topics);
            }
        }
        $page_selector = '';
        $readmore_link = '';
        $post_comment_link = '';
        $plugin_itemdisplay = '';
        $comments_with_count = '';
        $trackbacks_with_count = '';
        if ($index == 'n' || $index == 'p') {
            if (empty($bodytext)) {
                $article->set_var('story_introtext', $introtext);
                $article->set_var('story_text_no_br', $introtext);
            } else {
                if ($_CONF['allow_page_breaks'] == 1 && $index == 'n') {
                    $story_page = 1;
                    // page selector
                    if (is_numeric($mode)) {
                        $story_page = $mode;
                        if ($story_page <= 0) {
                            $story_page = 1;
                            $mode = 0;
                        } elseif ($story_page > 1) {
                            $introtext = '';
                        }
                    }
                    $article_array = explode('[page_break]', $bodytext);
                    $page_break_count = count($article_array);
                    if ($story_page > $page_break_count) {
                        // Can't have page count greater than actual number of pages
                        $story_page = $page_break_count;
                    }
                    $page_selector = COM_printPageNavigation($articleUrl, $story_page, $page_break_count, 'mode=', $_CONF['url_rewrite'], $LANG01[118]);
                    if (count($article_array) > 1) {
                        $bodytext = $article_array[$story_page - 1];
                    }
                    $article->set_var('page_selector', $page_selector);
                    if ($_CONF['page_break_comments'] == 'last' && $story_page < count($article_array) || $_CONF['page_break_comments'] == 'first' && $story_page != 1) {
                        $show_comments = false;
                    }
                    $article->set_var('story_page', $story_page);
                }
                $article->set_var('story_introtext', $introtext . '<br' . XHTML . '><br' . XHTML . '>' . $bodytext);
                $article->set_var('story_text_no_br', $introtext . ' ' . $bodytext);
            }
            $article->set_var('story_introtext_only', $introtext);
            $article->set_var('story_bodytext_only', $bodytext);
            if (($_CONF['trackback_enabled'] || $_CONF['pingback_enabled']) && SEC_hasRights('story.ping')) {
                $url = $_CONF['site_admin_url'] . '/trackback.php?mode=sendall&amp;id=' . $story->getSid();
                $article->set_var('send_trackback_link', COM_createLink($LANG_TRB['send_trackback'], $url));
                $pingico = '<img src="' . $_CONF['layout_url'] . '/images/sendping.' . $_IMAGE_TYPE . '" alt="' . $LANG_TRB['send_trackback'] . '" title="' . $LANG_TRB['send_trackback'] . '"' . XHTML . '>';
                $article->set_var('send_trackback_icon', COM_createLink($pingico, $url));
                $article->set_var('send_trackback_url', $url);
                $article->set_var('lang_send_trackback_text', $LANG_TRB['send_trackback']);
            }
            $article->set_var('story_display', $index == 'p' ? 'preview' : 'article');
            $article->set_var('story_counter', 0);
        } else {
            $article->set_var('story_introtext', $introtext);
            $article->set_var('story_text_no_br', $introtext);
            $article->set_var('story_introtext_only', $introtext);
            if ($readmore) {
                $article->set_var('lang_readmore', $LANG01[2]);
                $article->set_var('lang_readmore_words', $LANG01[62]);
                $article->set_var('readmore_words', $numwords);
                $readmore_link = COM_createLink($LANG01[2], $articleUrl, array('class' => 'story-read-more-link')) . ' (' . $numwords . ' ' . $LANG01[62] . ') ';
                $article->set_var('readmore_link', $readmore_link);
                $article->set_var('start_readmore_anchortag', '<a href="' . $articleUrl . '" class="story-read-more-link">');
                $article->set_var('end_readmore_anchortag', '</a>');
                $article->set_var('read_more_class', 'class="story-read-more-link"');
            }
            if ($story->DisplayElements('commentcode') >= 0 && $show_comments) {
                $commentsUrl = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $story->getSid()) . '#comments';
                $article->set_var('comments_url', $commentsUrl);
                $article->set_var('comments_text', COM_numberFormat($story->DisplayElements('comments')) . ' ' . $LANG01[3]);
                $article->set_var('comments_count', COM_numberFormat($story->DisplayElements('comments')));
                $article->set_var('lang_comments', $LANG01[3]);
                $comments_with_count = sprintf($LANG01[121], COM_numberFormat($story->DisplayElements('comments')));
                if ($story->DisplayElements('comments') > 0) {
                    $result = DB_query("SELECT UNIX_TIMESTAMP(date) AS day,username,fullname,{$_TABLES['comments']}.uid as cuid FROM {$_TABLES['comments']},{$_TABLES['users']} WHERE {$_TABLES['users']}.uid = {$_TABLES['comments']}.uid AND sid = '" . $story->getSid() . "' ORDER BY date DESC LIMIT 1");
                    $C = DB_fetchArray($result);
                    $recent_post_anchortag = '<span class="storybyline">' . $LANG01[27] . ': ' . strftime($_CONF['daytime'], $C['day']) . ' ' . $LANG01[104] . ' ' . COM_getDisplayName($C['cuid'], $C['username'], $C['fullname']) . '</span>';
                    $comments_with_count = COM_createLink($comments_with_count, $commentsUrl);
                    $article->set_var('comments_with_count', $comments_with_count);
                    $article->set_var('start_comments_anchortag', '<a href="' . $commentsUrl . '">');
                    $article->set_var('end_comments_anchortag', '</a>');
                } else {
                    $article->set_var('comments_with_count', $comments_with_count);
                    if ($_CONF['comment_on_same_page'] == true) {
                        $recent_post_anchortag = COM_createLink($LANG01[60], $_CONF['site_url'] . '/article.php?story=' . $story->getSid() . '#commenteditform');
                    } else {
                        $recent_post_anchortag = COM_createLink($LANG01[60], $_CONF['site_url'] . '/comment.php?sid=' . $story->getSid() . '&amp;pid=0&amp;type=article');
                        if ($_CONF['show_comments_at_replying'] == true) {
                            $recent_post_anchortag .= '#commenteditform';
                        }
                    }
                }
                if ($story->DisplayElements('commentcode') == 0) {
                    if ($_CONF['comment_on_same_page'] == true) {
                        $postCommentUrl = $_CONF['site_url'] . '/article.php?story=' . $story->getSid() . '#commenteditform';
                    } else {
                        $postCommentUrl = $_CONF['site_url'] . '/comment.php?sid=' . $story->getSid() . '&amp;pid=0&amp;type=article';
                        if ($_CONF['show_comments_at_replying'] == true) {
                            $postCommentUrl .= '#commenteditform';
                        }
                    }
                    $post_comment_link = COM_createLink($LANG01[60], $postCommentUrl, array('rel' => 'nofollow'));
                    $article->set_var('post_comment_link', $post_comment_link);
                    /*
                        $article->set_var( 'subscribe_link',
                                COM_createLink('Nubbies', '', array('rel' => 'nofollow'))
                                         );
                    */
                    $article->set_var('lang_post_comment', $LANG01[60]);
                    $article->set_var('start_post_comment_anchortag', '<a href="' . $postCommentUrl . '" rel="nofollow">');
                    $article->set_var('end_post_comment_anchortag', '</a>');
                }
            }
            if (($_CONF['trackback_enabled'] || $_CONF['pingback_enabled']) && $story->DisplayElements('trackbackcode') >= 0 && $show_comments) {
                $num_trackbacks = COM_numberFormat($story->DisplayElements('trackbacks'));
                $trackbacksUrl = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $story->getSid()) . '#trackback';
                $article->set_var('trackbacks_url', $trackbacksUrl);
                $article->set_var('trackbacks_text', $num_trackbacks . ' ' . $LANG_TRB['trackbacks']);
                $article->set_var('trackbacks_count', $num_trackbacks);
                $article->set_var('lang_trackbacks', $LANG_TRB['trackbacks']);
                if (SEC_hasRights('story.ping')) {
                    $pingurl = $_CONF['site_admin_url'] . '/trackback.php?mode=sendall&amp;id=' . $story->getSid();
                    $pingico = '<img src="' . $_CONF['layout_url'] . '/images/sendping.' . $_IMAGE_TYPE . '" alt="' . $LANG_TRB['send_trackback'] . '" title="' . $LANG_TRB['send_trackback'] . '"' . XHTML . '>';
                    $article->set_var('send_trackback_icon', COM_createLink($pingico, $pingurl));
                }
                $trackbacks_with_count = sprintf($LANG01[122], $num_trackbacks);
                if ($story->DisplayElements('trackbacks') > 0) {
                    $trackbacks_with_count = COM_createLink($trackbacks_with_count, $trackbacksUrl);
                }
                $article->set_var('trackbacks_with_count', $trackbacks_with_count);
            }
            if ($_CONF['hideemailicon'] == 1 || COM_isAnonUser() && ($_CONF['loginrequired'] == 1 || $_CONF['emailstoryloginrequired'] == 1)) {
                $article->set_var('email_icon', '');
            } else {
                $emailUrl = $_CONF['site_url'] . '/profiles.php?sid=' . $story->getSid() . '&amp;what=emailstory';
                $emailicon = '<img src="' . $_CONF['layout_url'] . '/images/mail.' . $_IMAGE_TYPE . '" alt="' . $LANG01[64] . '" title="' . $LANG11[2] . '"' . XHTML . '>';
                $article->set_var('email_icon', COM_createLink($emailicon, $emailUrl));
                $article->set_var('email_story_url', $emailUrl);
                $article->set_var('lang_email_story', $LANG11[2]);
                $article->set_var('lang_email_story_alt', $LANG01[64]);
            }
            $printUrl = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $story->getSid() . '&amp;mode=print');
            if ($_CONF['hideprintericon'] == 1) {
                $article->set_var('print_icon', '');
            } else {
                $printicon = '<img src="' . $_CONF['layout_url'] . '/images/print.' . $_IMAGE_TYPE . '" alt="' . $LANG01[65] . '" title="' . $LANG11[3] . '"' . XHTML . '>';
                $article->set_var('print_icon', COM_createLink($printicon, $printUrl, array('rel' => 'nofollow')));
                $article->set_var('print_story_url', $printUrl);
                $article->set_var('lang_print_story', $LANG11[3]);
                $article->set_var('lang_print_story_alt', $LANG01[65]);
            }
            $article->set_var('story_display', 'index');
            $storyCounter++;
            $article->set_var('story_counter', $storyCounter);
        }
        $article->set_var('recent_post_anchortag', $recent_post_anchortag);
        if ($index != 'p' && SEC_hasRights('story.edit') && $story->checkAccess() == 3 && TOPIC_hasMultiTopicAccess('article', $story->DisplayElements('sid')) == 3) {
            $editUrl = $_CONF['site_admin_url'] . '/story.php?mode=edit&amp;sid=' . $story->getSid();
            $editiconhtml = '<img src="' . $_CONF['layout_url'] . '/images/edit.' . $_IMAGE_TYPE . '" alt="' . $LANG01[4] . '" title="' . $LANG01[4] . '"' . XHTML . '>';
            $article->set_var('edit_link', COM_createLink($LANG01[4], $editUrl));
            $article->set_var('edit_url', $editUrl);
            $article->set_var('lang_edit_text', $LANG01[4]);
            $article->set_var('edit_icon', COM_createLink($editiconhtml, $editUrl, array('class' => 'editlink')));
            $article->set_var('edit_image', $editiconhtml);
        }
        $navi_list = true;
        $feedback_list = true;
        if ($index == 'p') {
            $navi_list = false;
            $feedback_list = false;
        } else {
            $navi_list = $page_selector !== '' || $readmore_link !== '' || $post_comment_link !== '';
            $feedback_list = $plugin_itemdisplay !== '' || $comments_with_count !== '' || $trackbacks_with_count !== '';
        }
        $story_footer = $navi_list || $feedback_list || $related_topics !== '';
        $article->set_var('navi_list', $navi_list);
        $article->set_var('feedback_list', $feedback_list);
        $article->set_var('story_footer', $story_footer);
        if ($story->DisplayElements('featured') == 1) {
            $article->set_var('lang_todays_featured_article', $LANG05[4]);
            $article->parse('story_bodyhtml', 'featuredbodytext', true);
            PLG_templateSetVars('featuredstorytext', $article);
        } elseif ($story->DisplayElements('statuscode') == STORY_ARCHIVE_ON_EXPIRE && $story->DisplayElements('expire') <= time()) {
            $article->parse('story_bodyhtml', 'archivestorybodytext', true);
            PLG_templateSetVars('archivestorytext', $article);
        } else {
            $article->parse('story_bodyhtml', 'bodytext', true);
            PLG_templateSetVars('storytext', $article);
        }
        // Add related articles
        if ($index === 'n') {
            $article->set_var('related_articles_by_keyword', Story::getRelatedArticlesByKeywords($story->getSid(), $story->DisplayElements('meta_keywords')));
        }
        PLG_templateSetVars($article_filevar, $article);
        if ($index != 'p' && ($cache_time > 0 || $cache_time == -1)) {
            $article->create_instance($cacheInstance, $article_filevar);
            // CACHE_create_instance($cacheInstance, $article);
        }
    } else {
        PLG_templateSetVars($article_filevar, $article);
        if (!$_CONF['cache_templates']) {
            // Hack (see Geeklog Bug Tracker issue #0001817): Cannot set the template variable directly with set_var since
            // this template variable was set with set_file which uses the templatecode array (set_var uses varvals array)
            // so have to update the templatecode array directly. This array really shouldn't be accessed this way
            // and this hack should be changed in the future: either set_var or set_file functions need to allow update of the file template variable found in templatecode
            // $article->set_var($article_filevar, $retval);
            $article->templateCode[$article_filevar] = $retval;
        }
    }
    $article->parse('finalstory', $article_filevar);
    return $article->finish($article->get_var('finalstory'));
}
예제 #2
0
/**
* Displays a list of topics
*
* Lists all the topics and their icons.
*
* @return   string      HTML for the topic list
*
*/
function listtopics()
{
    global $_CONF, $_TABLES, $LANG27, $LANG_ACCESS, $LANG_ADMIN;
    require_once $_CONF['path_system'] . 'lib-admin.php';
    $retval = '';
    $retval .= COM_startBlock($LANG27[8], '', COM_getBlockTemplate('_admin_block', 'header'));
    $topic_templates = new Template($_CONF['path_layout'] . 'admin/topic');
    $topic_templates->set_file(array('list' => 'topiclist.thtml', 'item' => 'listitem.thtml'));
    $topic_templates->set_var('xhtml', XHTML);
    $topic_templates->set_var('site_url', $_CONF['site_url']);
    $topic_templates->set_var('site_admin_url', $_CONF['site_admin_url']);
    $topic_templates->set_var('layout_url', $_CONF['layout_url']);
    $topic_templates->set_var('lang_newtopic', $LANG_ADMIN['create_new']);
    $topic_templates->set_var('lang_adminhome', $LANG27[18]);
    $topic_templates->set_var('lang_instructions', $LANG27[9]);
    $topic_templates->set_var('begin_row', '<tr align="center" valign="bottom">');
    $result = DB_query("SELECT * FROM {$_TABLES['topics']}");
    $nrows = DB_numRows($result);
    $counter = 1;
    $menu_arr = array(array('url' => $_CONF['site_admin_url'] . '/topic.php?mode=edit', 'text' => $LANG_ADMIN['create_new']), array('url' => $_CONF['site_admin_url'], 'text' => $LANG_ADMIN['admin_home']));
    $menu = ADMIN_createMenu($menu_arr, $LANG27[9], $_CONF['layout_url'] . "/images/icons/topic.png");
    $topic_templates->set_var('top_menu', $menu);
    for ($i = 0; $i < $nrows; $i++) {
        $A = DB_fetchArray($result);
        $access = SEC_hasAccess($A['owner_id'], $A['group_id'], $A['perm_owner'], $A['perm_group'], $A['perm_members'], $A['perm_anon']);
        if ($access > 0) {
            if ($access == 3) {
                $access = $LANG_ACCESS['edit'];
            } else {
                $access = $LANG_ACCESS['readonly'];
            }
            $topic_templates->set_var('topic_id', $A['tid']);
            $topic_templates->set_var('topic_name', stripslashes($A['topic']));
            $topic_templates->set_var('topic_access', $access);
            if ($A['is_default'] == 1) {
                $topic_templates->set_var('default_topic', $LANG27[24]);
            } else {
                $topic_templates->set_var('default_topic', '');
            }
            if (empty($A['imageurl'])) {
                $topic_templates->set_var('image_tag', '');
            } else {
                $imageurl = COM_getTopicImageUrl($A['imageurl']);
                $topic_templates->set_var('image_tag', '<img src="' . $imageurl . '" alt=""' . XHTML . '>');
            }
            if ($counter == 5) {
                $counter = 1;
                $topic_templates->set_var('end_row', '</tr>');
                $topic_templates->parse('list_row', 'item', true);
                $topic_templates->set_var('begin_row', '<tr align="center" valign="bottom">');
            } else {
                if ($i == $nrows - 1) {
                    $topic_templates->set_var('end_row', '</tr>');
                } else {
                    $topic_templates->set_var('end_row', '');
                }
                $topic_templates->parse('list_row', 'item', true);
                $topic_templates->set_var('begin_row', '');
                $counter = $counter + 1;
            }
        }
    }
    $topic_templates->parse('output', 'list');
    $retval .= $topic_templates->finish($topic_templates->get_var('output'));
    $retval .= COM_endBlock(COM_getBlockTemplate('_admin_block', 'footer'));
    return $retval;
}
예제 #3
0
/**
 * used for the list of topics in admin/topic.php
 *
 * @param  string $fieldName
 * @param  string $fieldValue
 * @param  array  $A
 * @param  array  $icon_arr
 * @param  string $token
 * @return string
 */
function ADMIN_getListField_topics($fieldName, $fieldValue, $A, $icon_arr, $token)
{
    global $_CONF, $LANG_ACCESS, $_TABLES, $LANG27, $LANG32;
    $retval = false;
    $access = SEC_hasAccess($A['owner_id'], $A['group_id'], $A['perm_owner'], $A['perm_group'], $A['perm_members'], $A['perm_anon']);
    switch ($fieldName) {
        case 'edit':
            if ($access == 3) {
                $editUrl = $_CONF['site_admin_url'] . '/topic.php?mode=edit&amp;tid=' . $A['tid'];
                $retval = COM_createLink($icon_arr['edit'], $editUrl);
            }
            break;
        case 'sortnum':
            if ($_CONF['sortmethod'] === 'sortnum') {
                $style = 'style="vertical-align: middle;"';
                $upImage = $_CONF['layout_url'] . '/images/admin/up.png';
                $downImage = $_CONF['layout_url'] . '/images/admin/down.png';
                $url = $_CONF['site_admin_url'] . '/topic.php?mode=change_sortnum' . '&amp;tid=' . $A['tid'] . '&amp;' . CSRF_TOKEN . '=' . $token . '&amp;where=';
                $retval .= COM_createLink("<img {$style} alt=\"+\" src=\"{$upImage}\"" . XHTML . ">", $url . 'up', array('title' => $LANG32[44]));
                $retval .= '&nbsp;' . $fieldValue . '&nbsp;';
                $retval .= COM_createLink("<img {$style} alt=\"-\" src=\"{$downImage}\"" . XHTML . ">", $url . 'dn', array('title' => $LANG32[45]));
            } else {
                $retval = $fieldValue;
            }
            break;
        case 'image':
            $retval = '';
            if (!empty($A['imageurl'])) {
                $imageUrl = COM_getTopicImageUrl($A['imageurl']);
                $image_tag = '<img src="' . $imageUrl . '" width="24" height="24" id="topic-' . $A['tid'] . '" class="admin-topic-image" alt=""' . XHTML . '>';
                $url = COM_buildURL($_CONF['site_url'] . '/index.php?topic=' . $A['tid']);
                $retval = COM_createLink($image_tag, $url);
            }
            break;
        case 'topic':
            $default = $A['is_default'] == 1 ? $LANG27[24] : '';
            $level = -1;
            $tid = $A['tid'];
            while ($tid !== TOPIC_ROOT) {
                $tid = DB_getItem($_TABLES['topics'], 'parent_id', "tid = '{$tid}'");
                $level++;
            }
            $level *= 15;
            $content = '<span style="margin-left:' . $level . 'px">' . $fieldValue . '</span>';
            $url = COM_buildURL($_CONF['site_url'] . '/index.php?topic=' . $A['tid']);
            $retval = COM_createLink($content, $url) . $default;
            break;
        case 'access':
            $retval = $LANG_ACCESS['readonly'];
            if ($access == 3) {
                $retval = $LANG_ACCESS['edit'];
            }
            break;
        case 'inherit':
        case 'hidden':
            $yes = empty($LANG27[50]) ? 'Yes' : $LANG27[50];
            $no = empty($LANG27[50]) ? 'No' : $LANG27[51];
            $retval = $fieldValue == 1 ? $yes : $no;
            break;
        case 'story':
            // Retrieve list of inherited topics
            $tid_list = TOPIC_getChildList($A['tid']);
            // Calculate number of stories in topic, includes any inherited ones
            $sql = "SELECT sid FROM {$_TABLES['stories']}, {$_TABLES['topic_assignments']} ta " . "WHERE (draft_flag = 0) AND (date <= NOW()) " . COM_getPermSQL('AND') . "AND ta.type = 'article' AND ta.id = sid " . "AND (ta.tid IN({$tid_list}) " . "AND (ta.inherit = 1 OR (ta.inherit = 0 AND ta.tid = '{$A['tid']}'))) " . "GROUP BY sid";
            $result = DB_query($sql);
            $numRows = DB_numRows($result);
            $retval = COM_numberFormat($numRows);
            break;
        default:
            $retval = $fieldValue;
            break;
    }
    return $retval;
}
예제 #4
0
/**
* Shows all available topics
*
* Show the topics in the system the user has access to and prints them in HTML.
* This function is used to show the topics in the topics block.
*
* @param    string    $topic      ID of currently selected topic
* @return   string                HTML formatted topic list
*
*/
function COM_showTopics($topic = '')
{
    global $_CONF, $_TABLES, $_USER, $LANG01, $_BLOCK_TEMPLATE, $page;
    $langsql = COM_getLangSQL('tid');
    if (empty($langsql)) {
        $op = 'WHERE';
    } else {
        $op = 'AND';
    }
    $sql = "SELECT tid,topic,imageurl,meta_description FROM {$_TABLES['topics']}" . $langsql;
    if (!COM_isAnonUser()) {
        $tids = DB_getItem($_TABLES['userindex'], 'tids', "uid = '{$_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);
    $retval = '';
    $sections = COM_newTemplate($_CONF['path_layout']);
    if (isset($_BLOCK_TEMPLATE['topicoption'])) {
        $templates = explode(',', $_BLOCK_TEMPLATE['topicoption']);
        $sections->set_file(array('option' => $templates[0], 'current' => $templates[1]));
    } else {
        $sections->set_file(array('option' => 'topicoption.thtml', 'inactive' => 'topicoption_off.thtml'));
    }
    $sections->set_var('block_name', str_replace('_', '-', 'section_block'));
    if ($_CONF['hide_home_link'] == 0) {
        // Give a link to the homepage here since a lot of people use this for
        // navigating the site
        if (COM_onFrontpage()) {
            $sections->set_var('option_url', '');
            $sections->set_var('option_label', $LANG01[90]);
            $sections->set_var('option_count', '');
            $sections->set_var('option_attributes', '');
            $sections->set_var('topic_image', '');
            $retval .= $sections->parse('item', 'inactive');
        } else {
            $sections->set_var('option_url', $_CONF['site_url'] . '/');
            $sections->set_var('option_label', $LANG01[90]);
            $sections->set_var('option_count', '');
            $sections->set_var('option_attributes', ' rel="home"');
            $sections->set_var('topic_image', '');
            $retval .= $sections->parse('item', 'option');
        }
    }
    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 = stripslashes($A['topic']);
        $sections->set_var('option_url', $_CONF['site_url'] . '/index.php?topic=' . $A['tid']);
        $sections->set_var('option_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 .= ')';
        }
        $sections->set_var('option_count', $countstring);
        $sections->set_var('option_attributes', '');
        $topicimage = '';
        if (!empty($A['imageurl'])) {
            $imageurl = COM_getTopicImageUrl($A['imageurl']);
            $topicimage = '<img src="' . $imageurl . '" alt="' . $topicname . '" title="' . $topicname . '"' . XHTML . '>';
        }
        $sections->set_var('topic_image', $topicimage);
        $desc = trim($A['meta_description']);
        $sections->set_var('topic_description', $desc);
        $desc_escaped = htmlspecialchars($desc);
        $sections->set_var('topic_description_escaped', $desc_escaped);
        if (!empty($desc)) {
            $sections->set_var('topic_title_attribute', 'title="' . $desc_escaped . '"');
        } else {
            $sections->set_var('topic_title_attribute', '');
        }
        if ($A['tid'] == $topic && $page == 1) {
            $retval .= $sections->parse('item', 'inactive');
        } else {
            $retval .= $sections->parse('item', 'option');
        }
    }
    return $retval;
}
예제 #5
0
/**
 * Takes an article class and renders HTML in the specified template and style.
 *
 * Formats the given article into HTML. Called by index.php, article.php,
 * submit.php and admin/story.php (Preview mode for the last two).
 *
 * @param   object  $story      The story to display, an instance of the Story class.
 * @param   string  $index      n = 'Compact display' for list of stories. p = 'Preview' mode. Else full display of article.
 * @param   string  $storytpl   The template to use to render the story.
 * @param   string  $query      A search query, if one was specified.
 *
 * @return  string  Article as formated HTML.
 *
 * Note: Formerly named COM_Article, and re-written totally since then.
 */
function STORY_renderArticle(&$story, $index = '', $storytpl = 'storytext.thtml', $query = '')
{
    global $_CONF, $_TABLES, $_USER, $LANG01, $LANG05, $LANG11, $LANG_TRB, $_IMAGE_TYPE, $mode;
    static $storycounter = 0;
    if (empty($storytpl)) {
        $storytpl = 'storytext.thtml';
    }
    $introtext = $story->displayElements('introtext');
    $bodytext = $story->displayElements('bodytext');
    if (!empty($query)) {
        $introtext = COM_highlightQuery($introtext, $query);
        $bodytext = COM_highlightQuery($bodytext, $query);
    }
    $article = new Template($_CONF['path_layout']);
    $article->set_file(array('article' => $storytpl, 'bodytext' => 'storybodytext.thtml', 'featuredarticle' => 'featuredstorytext.thtml', 'featuredbodytext' => 'featuredstorybodytext.thtml', 'archivearticle' => 'archivestorytext.thtml', 'archivebodytext' => 'archivestorybodytext.thtml'));
    $article->set_var('xhtml', XHTML);
    $article->set_var('layout_url', $_CONF['layout_url']);
    $article->set_var('site_url', $_CONF['site_url']);
    $article->set_var('site_admin_url', $_CONF['site_admin_url']);
    $article->set_var('site_name', $_CONF['site_name']);
    $article->set_var('story_date', $story->DisplayElements('date'));
    $article->set_var('story_date_short', $story->DisplayElements('shortdate'));
    $article->set_var('story_date_only', $story->DisplayElements('dateonly'));
    if ($_CONF['hideviewscount'] != 1) {
        $article->set_var('lang_views', $LANG01[106]);
        $article->set_var('story_hits', $story->DisplayElements('hits'));
    }
    $article->set_var('story_id', $story->getSid());
    if ($_CONF['contributedbyline'] == 1) {
        $article->set_var('lang_contributed_by', $LANG01[1]);
        $article->set_var('contributedby_uid', $story->DisplayElements('uid'));
        $fullname = $story->DisplayElements('fullname');
        $username = $story->DisplayElements('username');
        $article->set_var('contributedby_user', $username);
        if (empty($fullname)) {
            $article->set_var('contributedby_fullname', $username);
        } else {
            $article->set_var('contributedby_fullname', $fullname);
        }
        $authorname = COM_getDisplayName($story->DisplayElements('uid'), $username, $fullname);
        $article->set_var('contributedby_author', $authorname);
        $article->set_var('author', $authorname);
        if ($story->DisplayElements('uid') > 1) {
            $profileUrl = $_CONF['site_url'] . '/users.php?mode=profile&amp;uid=' . $story->DisplayElements('uid');
            $article->set_var('start_contributedby_anchortag', '<a class="storybyline" href="' . $profileUrl . '">');
            $article->set_var('end_contributedby_anchortag', '</a>');
            $article->set_var('contributedby_url', $profileUrl);
        }
        $photo = '';
        if ($_CONF['allow_user_photo'] == 1) {
            $authphoto = $story->DisplayElements('photo');
            if (empty($authphoto)) {
                $authphoto = '(none)';
                // user does not have a photo
            }
            $photo = USER_getPhoto($story->DisplayElements('uid'), $authphoto, $story->DisplayElements('email'));
        }
        if (!empty($photo)) {
            $article->set_var('contributedby_photo', $photo);
            $article->set_var('author_photo', $photo);
            $camera_icon = '<img src="' . $_CONF['layout_url'] . '/images/smallcamera.' . $_IMAGE_TYPE . '" alt=""' . XHTML . '>';
            $article->set_var('camera_icon', COM_createLink($camera_icon, $profileUrl));
        } else {
            $article->set_var('contributedby_photo', '');
            $article->set_var('author_photo', '');
            $article->set_var('camera_icon', '');
        }
    }
    $topicname = $story->DisplayElements('topic');
    $article->set_var('story_topic_id', $story->DisplayElements('tid'));
    $article->set_var('story_topic_name', $topicname);
    $topicurl = $_CONF['site_url'] . '/index.php?topic=' . $story->DisplayElements('tid');
    if ((!isset($_USER['noicons']) or $_USER['noicons'] != 1) and $story->DisplayElements('show_topic_icon') == 1) {
        $imageurl = $story->DisplayElements('imageurl');
        if (!empty($imageurl)) {
            $imageurl = COM_getTopicImageUrl($imageurl);
            $article->set_var('story_topic_image_url', $imageurl);
            $topicimage = '<img src="' . $imageurl . '" class="float' . $_CONF['article_image_align'] . '" alt="' . $topicname . '" title="' . $topicname . '"' . XHTML . '>';
            $article->set_var('story_anchortag_and_image', COM_createLink($topicimage, $topicurl, array('rel' => "category")));
            $article->set_var('story_topic_image', $topicimage);
            $topicimage_noalign = '<img src="' . $imageurl . '" alt="' . $topicname . '" title="' . $topicname . '"' . XHTML . '>';
            $article->set_var('story_anchortag_and_image_no_align', COM_createLink($topicimage_noalign, $topicurl, array('rel' => "category")));
            $article->set_var('story_topic_image_no_align', $topicimage_noalign);
        }
    }
    $article->set_var('story_topic_url', $topicurl);
    $recent_post_anchortag = '';
    $articleUrl = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $story->getSid());
    $article->set_var('story_title', $story->DisplayElements('title'));
    $article->set_var('lang_permalink', $LANG01[127]);
    $show_comments = true;
    // n = 'Compact display' for list of stories. p = 'Preview' mode.
    if ($index != 'n' && $index != 'p' || !empty($query)) {
        $attributes = ' class="non-ul"';
        $attr_array = array('class' => 'non-ul');
        if (!empty($query)) {
            $attributes .= ' rel="bookmark"';
            $attr_array['rel'] = 'bookmark';
        }
        $article->set_var('start_storylink_anchortag', '<a href="' . $articleUrl . '"' . $attributes . '>');
        $article->set_var('end_storylink_anchortag', '</a>');
        $article->set_var('story_title_link', COM_createLink($story->DisplayElements('title'), $articleUrl, $attr_array));
    } else {
        $article->set_var('story_title_link', $story->DisplayElements('title'));
    }
    if ($index == 'n' || $index == 'p') {
        if (empty($bodytext)) {
            $article->set_var('story_introtext', $introtext);
            $article->set_var('story_text_no_br', $introtext);
        } else {
            if ($_CONF['allow_page_breaks'] == 1 and $index == 'n') {
                $story_page = 1;
                // page selector
                if (is_numeric($mode)) {
                    $story_page = $mode;
                    if ($story_page <= 0) {
                        $story_page = 1;
                        $mode = 0;
                    } elseif ($story_page > 1) {
                        $introtext = '';
                    }
                }
                $article_array = explode('[page_break]', $bodytext);
                $pagelinks = COM_printPageNavigation($articleUrl, $story_page, count($article_array), 'mode=', $_CONF['url_rewrite'], $LANG01[118]);
                if (count($article_array) > 1) {
                    $bodytext = $article_array[$story_page - 1];
                }
                $article->set_var('page_selector', $pagelinks);
                if ($_CONF['page_break_comments'] == 'last' and $story_page < count($article_array) or $_CONF['page_break_comments'] == 'first' and $story_page != 1) {
                    $show_comments = false;
                }
                $article->set_var('story_page', $story_page);
            }
            $article->set_var('story_introtext', $introtext . '<br' . XHTML . '><br' . XHTML . '>' . $bodytext);
            $article->set_var('story_text_no_br', $introtext . ' ' . $bodytext);
        }
        $article->set_var('story_introtext_only', $introtext);
        $article->set_var('story_bodytext_only', $bodytext);
        if (($_CONF['trackback_enabled'] || $_CONF['pingback_enabled']) && SEC_hasRights('story.ping')) {
            $url = $_CONF['site_admin_url'] . '/trackback.php?mode=sendall&amp;id=' . $story->getSid();
            $article->set_var('send_trackback_link', COM_createLink($LANG_TRB['send_trackback'], $url));
            $pingico = '<img src="' . $_CONF['layout_url'] . '/images/sendping.' . $_IMAGE_TYPE . '" alt="' . $LANG_TRB['send_trackback'] . '" title="' . $LANG_TRB['send_trackback'] . '"' . XHTML . '>';
            $article->set_var('send_trackback_icon', COM_createLink($pingico, $url));
            $article->set_var('send_trackback_url', $url);
            $article->set_var('lang_send_trackback_text', $LANG_TRB['send_trackback']);
        }
        $article->set_var('story_display', $index == 'p' ? 'preview' : 'article');
        $article->set_var('story_counter', 0);
    } else {
        $article->set_var('story_introtext', $introtext);
        $article->set_var('story_text_no_br', $introtext);
        $article->set_var('story_introtext_only', $introtext);
        if (!empty($bodytext)) {
            $article->set_var('lang_readmore', $LANG01[2]);
            $article->set_var('lang_readmore_words', $LANG01[62]);
            $numwords = COM_numberFormat(count(explode(' ', COM_getTextContent($bodytext))));
            $article->set_var('readmore_words', $numwords);
            $article->set_var('readmore_link', COM_createLink($LANG01[2], $articleUrl, array('class' => 'story-read-more-link')) . ' (' . $numwords . ' ' . $LANG01[62] . ') ');
            $article->set_var('start_readmore_anchortag', '<a href="' . $articleUrl . '" class="story-read-more-link">');
            $article->set_var('end_readmore_anchortag', '</a>');
            $article->set_var('read_more_class', 'class="story-read-more-link"');
        }
        if ($story->DisplayElements('commentcode') >= 0 and $show_comments) {
            $commentsUrl = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $story->getSid()) . '#comments';
            $article->set_var('comments_url', $commentsUrl);
            $article->set_var('comments_text', COM_numberFormat($story->DisplayElements('comments')) . ' ' . $LANG01[3]);
            $article->set_var('comments_count', COM_numberFormat($story->DisplayElements('comments')));
            $article->set_var('lang_comments', $LANG01[3]);
            $comments_with_count = sprintf($LANG01[121], COM_numberFormat($story->DisplayElements('comments')));
            if ($story->DisplayElements('comments') > 0) {
                $result = DB_query("SELECT UNIX_TIMESTAMP(date) AS day,username,fullname,{$_TABLES['comments']}.uid as cuid FROM {$_TABLES['comments']},{$_TABLES['users']} WHERE {$_TABLES['users']}.uid = {$_TABLES['comments']}.uid AND sid = '" . $story->getsid() . "' ORDER BY date desc LIMIT 1");
                $C = DB_fetchArray($result);
                $recent_post_anchortag = '<span class="storybyline">' . $LANG01[27] . ': ' . strftime($_CONF['daytime'], $C['day']) . ' ' . $LANG01[104] . ' ' . COM_getDisplayName($C['cuid'], $C['username'], $C['fullname']) . '</span>';
                $article->set_var('comments_with_count', COM_createLink($comments_with_count, $commentsUrl));
                $article->set_var('start_comments_anchortag', '<a href="' . $commentsUrl . '">');
                $article->set_var('end_comments_anchortag', '</a>');
            } else {
                $article->set_var('comments_with_count', $comments_with_count);
                $recent_post_anchortag = COM_createLink($LANG01[60], $_CONF['site_url'] . '/comment.php?sid=' . $story->getsid() . '&amp;pid=0&amp;type=article');
            }
            if ($story->DisplayElements('commentcode') == 0) {
                $postCommentUrl = $_CONF['site_url'] . '/comment.php?sid=' . $story->getSid() . '&amp;pid=0&amp;type=article';
                $article->set_var('post_comment_link', COM_createLink($LANG01[60], $postCommentUrl, array('rel' => 'nofollow')));
                /*
                    $article->set_var( 'subscribe_link',
                            COM_createLink('Nubbies', '', array('rel' => 'nofollow'))
                                     );
                */
                $article->set_var('lang_post_comment', $LANG01[60]);
                $article->set_var('start_post_comment_anchortag', '<a href="' . $postCommentUrl . '" rel="nofollow">');
                $article->set_var('end_post_comment_anchortag', '</a>');
            }
        }
        if (($_CONF['trackback_enabled'] || $_CONF['pingback_enabled']) && $story->DisplayElements('trackbackcode') >= 0 && $show_comments) {
            $num_trackbacks = COM_numberFormat($story->DisplayElements('trackbacks'));
            $trackbacksUrl = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $story->getSid()) . '#trackback';
            $article->set_var('trackbacks_url', $trackbacksUrl);
            $article->set_var('trackbacks_text', $num_trackbacks . ' ' . $LANG_TRB['trackbacks']);
            $article->set_var('trackbacks_count', $num_trackbacks);
            $article->set_var('lang_trackbacks', $LANG_TRB['trackbacks']);
            $article->set_var('trackbacks_with_count', COM_createLink(sprintf($LANG01[122], $num_trackbacks), $trackbacksUrl));
            if (SEC_hasRights('story.ping')) {
                $pingurl = $_CONF['site_admin_url'] . '/trackback.php?mode=sendall&amp;id=' . $story->getSid();
                $pingico = '<img src="' . $_CONF['layout_url'] . '/images/sendping.' . $_IMAGE_TYPE . '" alt="' . $LANG_TRB['send_trackback'] . '" title="' . $LANG_TRB['send_trackback'] . '"' . XHTML . '>';
                $article->set_var('send_trackback_icon', COM_createLink($pingico, $pingurl));
            }
            if ($story->DisplayElements('trackbacks') > 0) {
                $article->set_var('trackbacks_with_count', COM_createLink(sprintf($LANG01[122], $num_trackbacks), $trackbacksUrl));
            } else {
                $article->set_var('trackbacks_with_count', sprintf($LANG01[122], $num_trackbacks));
            }
        }
        if ($_CONF['hideemailicon'] == 1 || empty($_USER['username']) && ($_CONF['loginrequired'] == 1 || $_CONF['emailstoryloginrequired'] == 1)) {
            $article->set_var('email_icon', '');
        } else {
            $emailUrl = $_CONF['site_url'] . '/profiles.php?sid=' . $story->getSid() . '&amp;what=emailstory';
            $emailicon = '<img src="' . $_CONF['layout_url'] . '/images/mail.' . $_IMAGE_TYPE . '" alt="' . $LANG01[64] . '" title="' . $LANG11[2] . '"' . XHTML . '>';
            $article->set_var('email_icon', COM_createLink($emailicon, $emailUrl));
            $article->set_var('email_story_url', $emailUrl);
            $article->set_var('lang_email_story', $LANG11[2]);
            $article->set_var('lang_email_story_alt', $LANG01[64]);
        }
        $printUrl = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $story->getSid() . '&amp;mode=print');
        if ($_CONF['hideprintericon'] == 1) {
            $article->set_var('print_icon', '');
        } else {
            $printicon = '<img src="' . $_CONF['layout_url'] . '/images/print.' . $_IMAGE_TYPE . '" alt="' . $LANG01[65] . '" title="' . $LANG11[3] . '"' . XHTML . '>';
            $article->set_var('print_icon', COM_createLink($printicon, $printUrl, array('rel' => 'nofollow')));
            $article->set_var('print_story_url', $printUrl);
            $article->set_var('lang_print_story', $LANG11[3]);
            $article->set_var('lang_print_story_alt', $LANG01[65]);
        }
        $article->set_var('story_display', 'index');
        $storycounter++;
        $article->set_var('story_counter', $storycounter);
    }
    $article->set_var('article_url', $articleUrl);
    $article->set_var('recent_post_anchortag', $recent_post_anchortag);
    if ($story->checkAccess() == 3 and SEC_hasrights('story.edit') and $index != 'p') {
        $article->set_var('edit_link', COM_createLink($LANG01[4], $_CONF['site_admin_url'] . '/story.php?mode=edit&amp;sid=' . $story->getSid()));
        $article->set_var('edit_url', $_CONF['site_admin_url'] . '/story.php?mode=edit&amp;sid=' . $story->getSid());
        $article->set_var('lang_edit_text', $LANG01[4]);
        $editicon = $_CONF['layout_url'] . '/images/edit.' . $_IMAGE_TYPE;
        $editiconhtml = '<img src="' . $editicon . '" alt="' . $LANG01[4] . '" title="' . $LANG01[4] . '"' . XHTML . '>';
        $article->set_var('edit_icon', COM_createLink($editiconhtml, $_CONF['site_admin_url'] . '/story.php?mode=edit&amp;sid=' . $story->getSid()));
        $article->set_var('edit_image', $editiconhtml);
    }
    if ($story->DisplayElements('featured') == 1) {
        $article->set_var('lang_todays_featured_article', $LANG05[4]);
        $article->parse('story_bodyhtml', 'featuredbodytext', true);
        PLG_templateSetVars('featuredstorytext', $article);
        $article->parse('finalstory', 'featuredarticle');
    } elseif ($story->DisplayElements('statuscode') == STORY_ARCHIVE_ON_EXPIRE and $story->DisplayElements('expire') <= time()) {
        $article->parse('story_bodyhtml', 'archivestorybodytext', true);
        PLG_templateSetVars('archivestorytext', $article);
        $article->parse('finalstory', 'archivearticle');
    } else {
        $article->parse('story_bodyhtml', 'bodytext', true);
        PLG_templateSetVars('storytext', $article);
        $article->parse('finalstory', 'article');
    }
    return $article->finish($article->get_var('finalstory'));
}
예제 #6
0
/**
* Shows all available topics
*
* Show the topics in the system the user has access to and prints them in HTML.
* This function is used to show the topics in the topics block.
*
* @param    string    $topic      ID of currently selected topic
* @return   string                HTML formatted topic list
*
*/
function COM_showTopics($topic = '')
{
    global $_CONF, $_TABLES, $_TOPICS, $_USER, $LANG01, $_BLOCK_TEMPLATE, $page;
    $retval = '';
    // See if topic block cache is there for specified topic (since topics can be hidden here depending on what topic is clicked)
    $cacheInstance = 'topicsblock__' . $topic . '__' . CACHE_security_hash() . '__' . $_CONF['theme'];
    $retval = CACHE_check_instance($cacheInstance);
    // Language and theme specific
    if ($retval) {
        return $retval;
    }
    $topicnavigation = COM_newTemplate($_CONF['path_layout']);
    if (isset($_BLOCK_TEMPLATE['topicnavigation'])) {
        $topicnavigation->set_file('topicnavigation', $_BLOCK_TEMPLATE['topicnavigation']);
    } else {
        $topicnavigation->set_file('topicnavigation', 'topicnavigation.thtml');
    }
    $blocks = array('option', 'option-with-hidden', 'option-off');
    foreach ($blocks as $block) {
        $topicnavigation->set_block('topicnavigation', $block);
    }
    $topicnavigation->set_var('block_name', str_replace('_', '-', 'section_block'));
    // Allow anything not in the blocks but in the rest of the template file to be displayed
    $retval .= $topicnavigation->parse('item', 'topicnavigation', true);
    if ($_CONF['hide_home_link'] == 0) {
        // Give a link to the homepage here since a lot of people use this for
        // navigating the site
        $start_branch = 1;
        // Sets indentation level for topics
        if (COM_onFrontpage()) {
            $topicnavigation->set_var('option_url', '');
            $topicnavigation->set_var('option_label', $LANG01[90]);
            $topicnavigation->set_var('option_count', '');
            $topicnavigation->set_var('option_attributes', '');
            $topicnavigation->set_var('topic_image', '');
            $retval .= $topicnavigation->parse('item', 'option-off');
        } else {
            $topicnavigation->set_var('option_url', $_CONF['site_url'] . '/');
            $topicnavigation->set_var('option_label', $LANG01[90]);
            $topicnavigation->set_var('option_count', '');
            $topicnavigation->set_var('option_attributes', ' rel="home"');
            $topicnavigation->set_var('topic_image', '');
            $retval .= $topicnavigation->parse('item', 'option');
        }
    } else {
        $start_branch = 2;
    }
    if ($_CONF['showsubmissioncount']) {
        $sql = "SELECT tid, COUNT(*) AS count FROM {$_TABLES['storysubmission']}, {$_TABLES['topic_assignments']} ta " . "WHERE ta.type = 'article' AND ta.id = sid " . ' GROUP BY ta.tid';
        $rcount = DB_query($sql);
        while ($C = DB_fetchArray($rcount)) {
            $submissioncount[$C['tid']] = $C['count'];
        }
    }
    $start_topic = 2;
    // Do not display Root
    $total_topic = count($_TOPICS);
    $branch_level_skip = 0;
    $lang_id = COM_getLanguageId();
    for ($count_topic = $start_topic; $count_topic <= $total_topic; $count_topic++) {
        $topic_in_path = TOPIC_inPath($_TOPICS[$count_topic]['id']);
        // Check if branch needs to be hidden due to a parent being hidden or a different language
        if ($branch_level_skip >= $_TOPICS[$count_topic]['branch_level']) {
            $branch_level_skip = 0;
        }
        if ($branch_level_skip == 0) {
            // Make sure to show topics for proper language only (and all languages)
            if ($_TOPICS[$count_topic]['exclude'] == 0 && $_TOPICS[$count_topic]['access'] > 0 && ($lang_id == '' || $lang_id != '' && ($_TOPICS[$count_topic]['language_id'] == $lang_id || $_TOPICS[$count_topic]['language_id'] == ''))) {
                $continue = false;
                if ($_TOPICS[$count_topic]['parent_id'] == $topic) {
                    // Make sure to list any hidden child topics else skip
                    $continue = true;
                } elseif ($topic_in_path) {
                    // Figure out if we are on the current topic breadcrumb and if so show all even if hidden
                    $continue = true;
                } else {
                    // Normal check see if hidden, if not then continue
                    if (!$_TOPICS[$count_topic]['hidden']) {
                        $continue = true;
                    }
                }
                if ($continue) {
                    $branch_spaces = "";
                    $level = 1;
                    for ($branch_count = $start_branch; $branch_count <= $_TOPICS[$count_topic]['branch_level']; $branch_count++) {
                        $branch_spaces .= "&nbsp;&nbsp;&nbsp;";
                        $level++;
                    }
                    $topicnavigation->set_var('branch_spaces', $branch_spaces);
                    $topicnavigation->set_var('branch_level', $level);
                    $topicname = stripslashes($_TOPICS[$count_topic]['title']);
                    $topicnavigation->set_var('option_url', $_CONF['site_url'] . '/index.php?topic=' . $_TOPICS[$count_topic]['id']);
                    $topicnavigation->set_var('option_label', $topicname);
                    $countstring = '';
                    if ($_CONF['showstorycount'] || $_CONF['showsubmissioncount']) {
                        $countstring .= '(';
                        // Retrieve list of inherited topics
                        $tid_list = TOPIC_getChildList($_TOPICS[$count_topic]['id']);
                        if ($_CONF['showstorycount']) {
                            // Calculate number of stories in topic, includes any inherited ones
                            $sql = "SELECT sid FROM {$_TABLES['stories']}, {$_TABLES['topic_assignments']} ta " . 'WHERE (draft_flag = 0) AND (date <= NOW()) ' . COM_getPermSQL('AND') . "AND ta.type = 'article' AND ta.id = sid " . COM_getLangSQL('sid', 'AND') . "AND (ta.tid IN({$tid_list}) AND (ta.inherit = 1 OR (ta.inherit = 0 AND ta.tid = '{$_TOPICS[$count_topic]['id']}'))) " . ' GROUP BY sid';
                            $resultD = DB_query($sql);
                            $nrows = DB_numRows($resultD);
                            $countstring .= COM_numberFormat($nrows);
                        }
                        if ($_CONF['showsubmissioncount']) {
                            if ($_CONF['showstorycount']) {
                                $countstring .= '/';
                            }
                            // Calculate number of story submissions in topic, includes any inherited ones
                            $sql = "SELECT sid FROM {$_TABLES['storysubmission']}, {$_TABLES['topic_assignments']} ta " . "WHERE ta.type = 'article' AND ta.id = sid " . "AND (ta.tid IN({$tid_list}) AND (ta.inherit = 1 OR (ta.inherit = 0 AND ta.tid = '{$_TOPICS[$count_topic]['id']}'))) " . ' GROUP BY sid';
                            $resultD = DB_query($sql);
                            $nrows = DB_numRows($resultD);
                            $countstring .= COM_numberFormat($nrows);
                        }
                        $countstring .= ')';
                    }
                    $topicnavigation->set_var('option_count', $countstring);
                    $topicnavigation->set_var('option_attributes', '');
                    $sql = "SELECT imageurl, meta_description FROM {$_TABLES['topics']} WHERE tid = '{$_TOPICS[$count_topic]['id']}'";
                    $result = DB_query($sql);
                    $A = DB_fetchArray($result);
                    $topicimage = '';
                    if (!empty($A['imageurl'])) {
                        $imageurl = COM_getTopicImageUrl($A['imageurl']);
                        $topicimage = '<img src="' . $imageurl . '" alt="' . $topicname . '" title="' . $topicname . '"' . XHTML . '>';
                    }
                    $topicnavigation->set_var('topic_image', $topicimage);
                    $desc = trim($A['meta_description']);
                    $topicnavigation->set_var('topic_description', $desc);
                    $desc_escaped = htmlspecialchars($desc);
                    $topicnavigation->set_var('topic_description_escaped', $desc_escaped);
                    if (!empty($desc)) {
                        $topicnavigation->set_var('topic_title_attribute', 'title="' . $desc_escaped . '"');
                    } else {
                        $topicnavigation->set_var('topic_title_attribute', '');
                    }
                    if ($_TOPICS[$count_topic]['id'] == $topic && $page == 1) {
                        $retval .= $topicnavigation->parse('item', 'option-off');
                    } else {
                        // See if we need to display hidden child topic sign
                        $sql = "SELECT tid FROM {$_TABLES['topics']}\n                                WHERE parent_id = '{$_TOPICS[$count_topic]['id']}' AND hidden = 1" . COM_getPermSQL('AND', 0, 2);
                        $result = DB_query($sql);
                        $nrows = DB_numRows($result);
                        $A = DB_fetchArray($result);
                        if ($topic_in_path and $nrows > 1 or !$topic_in_path and $nrows > 0 or $topic_in_path and $nrows == 1 and !TOPIC_inPath($A['tid'])) {
                            $retval .= $topicnavigation->parse('item', 'option-with-hidden');
                        } else {
                            $retval .= $topicnavigation->parse('item', 'option');
                        }
                    }
                } else {
                    // Hidden, so flag this to skip if we have children
                    $branch_level_skip = $_TOPICS[$count_topic]['branch_level'];
                }
            } else {
                // Different language or hidden, so flag this to skip if we have children
                $branch_level_skip = $_TOPICS[$count_topic]['branch_level'];
            }
        }
    }
    // Create cache so don't need to recreate unless change
    CACHE_create_instance($cacheInstance, $retval);
    return $retval;
}
예제 #7
0
/**
 * Takes an article class and renders HTML in the specified template and style.
 *
 * Formats the given article into HTML. Called by index.php, article.php,
 * submit.php and admin/story.php (Preview mode for the last two).
 *
 * @param   object  $story      The story to display, an instance of the Story class.
 * @param   string  $index      n = 'Compact display' for list of stories. p = 'Preview' mode. Else full display of article.
 * @param   string  $storytpl   The template to use to render the story.
 * @param   string  $query      A search query, if one was specified.
 *
 * @return  string  Article as formated HTML.
 *
 * Note: Formerly named COM_Article, and re-written totally since then.
 */
function STORY_renderArticle(&$story, $index = '', $storytpl = 'storytext.thtml', $query = '')
{
    global $_CONF, $_TABLES, $_USER, $LANG01, $LANG05, $LANG11, $LANG_TRB, $_IMAGE_TYPE, $mode, $_GROUPS, $ratedIds;
    static $storycounter = 0;
    if (empty($storytpl)) {
        $storytpl = 'storytext.thtml';
    }
    $introtext = $story->displayElements('introtext');
    $bodytext = $story->displayElements('bodytext');
    if (!empty($query)) {
        $introtext = COM_highlightQuery($introtext, $query);
        $bodytext = COM_highlightQuery($bodytext, $query);
    }
    $article = new Template($_CONF['path_layout']);
    $article->set_file(array('article' => $storytpl, 'featuredarticle' => 'featuredstorytext.thtml', 'archivearticle' => 'archivestorytext.thtml'));
    if ($_CONF['hideviewscount'] != 1) {
        $article->set_var('lang_views', $LANG01[106]);
        $article->set_var('story_hits', $story->DisplayElements('hits'), false, true);
    }
    if ($_CONF['hidestorydate'] != 1) {
        $article->set_var('story_date', $story->DisplayElements('date'), false, true);
        // make sure date format is in user's preferred format
    }
    $articleUrl = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $story->getSid());
    $article->set_var('article_url', $articleUrl);
    $article->set_var('story_title', $story->DisplayElements('title'));
    // begin instance caching...
    if ($story->DisplayElements('featured') == 1) {
        $article_filevar = 'featuredarticle';
    } elseif ($story->DisplayElements('statuscode') == STORY_ARCHIVE_ON_EXPIRE and $story->DisplayElements('expire') <= time()) {
        $article_filevar = 'archivearticle';
    } else {
        $article_filevar = 'article';
    }
    $hash = CACHE_security_hash();
    $instance_id = 'story_' . $story->getSid() . '_' . $index . '_' . $article_filevar . '_' . $hash . '_' . $_USER['theme'];
    if ($index == 'p' || !empty($query) || !$article->check_instance($instance_id, $article_filevar)) {
        // end of instance cache
        $article->set_var('article_filevar', '');
        $article->set_var('site_name', $_CONF['site_name']);
        if ($_CONF['hidestorydate'] != 1) {
            $article->set_var('story_date_short', $story->DisplayElements('shortdate'));
            $article->set_var('story_date_only', $story->DisplayElements('dateonly'));
        }
        $article->set_var('story_id', $story->getSid());
        $article->set_var('lang_posted_in', $LANG01['posted_in']);
        if ($_CONF['contributedbyline'] == 1) {
            $article->set_var('lang_contributed_by', $LANG01[1]);
            $article->set_var('lang_by', $LANG01[95]);
            $article->set_var('contributedby_uid', $story->DisplayElements('uid'));
            $fullname = $story->DisplayElements('fullname');
            $username = $story->DisplayElements('username');
            $article->set_var('contributedby_user', $username);
            if (empty($fullname)) {
                $article->set_var('contributedby_fullname', $username);
            } else {
                $article->set_var('contributedby_fullname', $fullname);
            }
            $authorname = COM_getDisplayName($story->DisplayElements('uid'), $username, $fullname);
            $article->set_var('author', $authorname);
            $profileUrl = $_CONF['site_url'] . '/users.php?mode=profile&amp;uid=' . $story->DisplayElements('uid');
            if ($story->DisplayElements('uid') > 1) {
                $article->set_var('contributedby_url', $profileUrl);
                $authorname = COM_createLink($authorname, $profileUrl, array('class' => 'storybyline'));
            }
            $article->set_var('contributedby_author', $authorname);
            $photo = '';
            if ($_CONF['allow_user_photo'] == 1) {
                $authphoto = $story->DisplayElements('photo');
                if (empty($authphoto)) {
                    $authphoto = '(none)';
                    // user does not have a photo
                }
                $photo = USER_getPhoto($story->DisplayElements('uid'), $authphoto, $story->DisplayElements('email'));
            }
            if (!empty($photo)) {
                $article->set_var('contributedby_photo', $photo);
                $article->set_var('author_photo', $photo);
                $camera_icon = '<img src="' . $_CONF['layout_url'] . '/images/smallcamera.' . $_IMAGE_TYPE . '" alt=""' . '/>';
                $article->set_var('camera_icon', COM_createLink($camera_icon, $profileUrl));
            } else {
                $article->set_var('contributedby_photo', '');
                $article->set_var('author_photo', '');
                $article->set_var('camera_icon', '');
            }
        }
        $topicname = $story->DisplayElements('topic');
        if ($story->DisplayElements('alternate_tid') != NULL) {
            $alttopic = DB_getItem($_TABLES['topics'], 'topic', "tid = '" . DB_escapeString($story->DisplayElements('alternate_tid')) . "'");
        } else {
            $alttopic = '';
        }
        $article->set_var('story_topic_id', $story->DisplayElements('tid'));
        $article->set_var('alt_story_topic_id', $story->DisplayElements('alternate_tid'));
        $article->set_var('story_topic_name', $topicname);
        $article->set_var('story_alternate_topic_name', $alttopic);
        $topicurl = $_CONF['site_url'] . '/index.php?topic=' . $story->DisplayElements('tid');
        $alttopicurl = $_CONF['site_url'] . '/index.php?topic=' . $story->DisplayElements('alternate_tid');
        if ((!isset($_USER['noicons']) or $_USER['noicons'] != 1) and $story->DisplayElements('show_topic_icon') == 1) {
            $imageurl = $story->DisplayElements('imageurl');
            if (!empty($imageurl)) {
                $imageurl = COM_getTopicImageUrl($imageurl);
                $article->set_var('story_topic_image_url', $imageurl);
                $topicimage = '<img src="' . $imageurl . '" class="float' . $_CONF['article_image_align'] . '" alt="' . $topicname . '" title="' . $topicname . '" />';
                $article->set_var('story_anchortag_and_image', COM_createLink($topicimage, $topicurl, array('rel' => "category tag")));
                $article->set_var('story_topic_image', $topicimage);
                $topicimage_noalign = '<img src="' . $imageurl . '" alt="' . $topicname . '" title="' . $topicname . '" />';
                $article->set_var('story_anchortag_and_image_no_align', COM_createLink($topicimage_noalign, $topicurl, array('rel' => "category tag")));
                $article->set_var('story_topic_image_no_align', $topicimage_noalign);
            }
        }
        $article->set_var('story_topic_url', $topicurl);
        $article->set_var('alt_story_topic_url', $alttopicurl);
        $recent_post_anchortag = '';
        $articleUrl = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $story->getSid());
        $article->set_var('story_title', $story->DisplayElements('title'));
        $article->set_var('lang_permalink', $LANG01[127]);
        $show_comments = true;
        // n = 'Compact display' for list of stories. p = 'Preview' mode.
        if ($index != 'n' && $index != 'p' || !empty($query)) {
            $attributes = ' class="non-ul"';
            $attr_array = array('class' => 'non-ul');
            if (!empty($query)) {
                $attributes .= ' rel="bookmark"';
                $attr_array['rel'] = 'bookmark';
            }
            $article->set_var('start_storylink_anchortag', '<a href="' . $articleUrl . '"' . $attributes . '>');
            $article->set_var('end_storylink_anchortag', '</a>');
            $article->set_var('story_title_link', COM_createLink($story->DisplayElements('title'), $articleUrl, $attr_array));
        } else {
            $article->set_var('story_title_link', $story->DisplayElements('title'));
        }
        if ($index == 'n' || $index == 'p') {
            if (empty($bodytext)) {
                $article->set_var('story_introtext', $introtext);
                $article->set_var('story_text_no_br', $introtext);
            } else {
                if ($_CONF['allow_page_breaks'] == 1 and $index == 'n') {
                    $story_page = 1;
                    // page selector
                    if (is_numeric($mode)) {
                        $story_page = $mode;
                        if ($story_page <= 0) {
                            $story_page = 1;
                            $mode = 0;
                        } elseif ($story_page > 1) {
                            $introtext = '';
                        }
                    }
                    $article_array = explode('[page_break]', $bodytext);
                    $pagelinks = COM_printPageNavigation($articleUrl, $story_page, count($article_array), 'mode=', $_CONF['url_rewrite'], $LANG01[118]);
                    if (count($article_array) > 1) {
                        $bodytext = $article_array[$story_page - 1];
                    }
                    $article->set_var('page_selector', $pagelinks);
                    if ($_CONF['page_break_comments'] == 'last' and $story_page < count($article_array) or $_CONF['page_break_comments'] == 'first' and $story_page != 1) {
                        $show_comments = false;
                    }
                    $article->set_var('story_page', $story_page);
                }
                $article->set_var('story_introtext', $introtext . '<br />' . $bodytext);
                $article->set_var('story_text_no_br', $introtext . $bodytext);
            }
            $article->set_var('story_introtext_only', $introtext);
            $article->set_var('story_bodytext_only', $bodytext);
            if (($_CONF['trackback_enabled'] || $_CONF['pingback_enabled']) && SEC_hasRights('story.ping')) {
                $url = $_CONF['site_admin_url'] . '/trackback.php?mode=sendall&amp;id=' . $story->getSid();
                $article->set_var('send_trackback_link', COM_createLink($LANG_TRB['send_trackback'], $url));
                $pingico = '<img src="' . $_CONF['layout_url'] . '/images/sendping.' . $_IMAGE_TYPE . '" alt="' . $LANG_TRB['send_trackback'] . '" title="' . $LANG_TRB['send_trackback'] . '" />';
                $article->set_var('send_trackback_icon', COM_createLink($pingico, $url));
                $article->set_var('send_trackback_url', $url);
                $article->set_var('lang_send_trackback_text', $LANG_TRB['send_trackback']);
            }
            $article->set_var('story_display', $index == 'p' ? 'preview' : 'article');
            $article->set_var('story_counter', 0);
        } else {
            $article->set_var('story_introtext', $introtext);
            $article->set_var('story_text_no_br', $introtext);
            $article->set_var('story_introtext_only', $introtext);
            if (!empty($bodytext)) {
                $article->set_var('lang_readmore', $LANG01[2]);
                $article->set_var('lang_readmore_words', $LANG01[62]);
                $numwords = COM_numberFormat(sizeof(explode(' ', strip_tags($bodytext))));
                $article->set_var('readmore_words', $numwords);
                $article->set_var('readmore_link', COM_createLink($LANG01[2], $articleUrl, array('class' => 'story-read-more-link')) . ' (' . $numwords . ' ' . $LANG01[62] . ') ');
                $article->set_var('start_readmore_anchortag', '<a href="' . $articleUrl . '" class="story-read-more-link">');
                $article->set_var('end_readmore_anchortag', '</a>');
                $article->set_var('read_more_class', 'class="story-read-more-link"');
                $article->set_var('readmore_url', $articleUrl);
            }
            if ($story->DisplayElements('commentcode') >= 0 and $show_comments) {
                $commentsUrl = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $story->getSid()) . '#comments';
                $article->set_var('comments_url', $commentsUrl);
                $article->set_var('comments_text', COM_numberFormat($story->DisplayElements('comments')) . ' ' . $LANG01[3]);
                $article->set_var('comments_count', COM_numberFormat($story->DisplayElements('comments')));
                $article->set_var('lang_comments', $LANG01[3]);
                $comments_with_count = sprintf($LANG01[121], COM_numberFormat($story->DisplayElements('comments')));
                if ($story->DisplayElements('comments') > 0) {
                    $result = DB_query("SELECT UNIX_TIMESTAMP(date) AS day,username,fullname,{$_TABLES['comments']}.uid as cuid FROM {$_TABLES['comments']},{$_TABLES['users']} WHERE {$_TABLES['users']}.uid = {$_TABLES['comments']}.uid AND sid = '" . DB_escapeString($story->getsid()) . "' ORDER BY date desc LIMIT 1");
                    $C = DB_fetchArray($result);
                    $recent_post_anchortag = '<span class="storybyline">' . $LANG01[27] . ': ' . strftime($_CONF['daytime'], $C['day']) . ' ' . $LANG01[104] . ' ' . COM_getDisplayName($C['cuid'], $C['username'], $C['fullname']) . '</span>';
                    $article->set_var('comments_with_count', COM_createLink($comments_with_count, $commentsUrl));
                    $article->set_var('start_comments_anchortag', '<a href="' . $commentsUrl . '">');
                    $article->set_var('end_comments_anchortag', '</a>');
                } else {
                    $article->set_var('comments_with_count', $comments_with_count);
                    $recent_post_anchortag = COM_createLink($LANG01[60], $_CONF['site_url'] . '/comment.php?sid=' . $story->getsid() . '#comment_entry' . '&amp;pid=0&amp;type=article');
                }
                if ($story->DisplayElements('commentcode') == 0 && ($_CONF['commentsloginrequired'] == 0 || !COM_isAnonUser())) {
                    $postCommentUrl = $_CONF['site_url'] . '/comment.php?sid=' . $story->getSid() . '&amp;pid=0&amp;type=article#comment_entry';
                    $article->set_var('post_comment_link', COM_createLink($LANG01[60], $postCommentUrl, array('rel' => 'nofollow')));
                    $article->set_var('lang_post_comment', $LANG01[60]);
                    $article->set_var('start_post_comment_anchortag', '<a href="' . $postCommentUrl . '" rel="nofollow">');
                    $article->set_var('end_post_comment_anchortag', '</a>');
                    $article->set_var('post_comment_url', $postCommentUrl);
                }
            }
            if (($_CONF['trackback_enabled'] || $_CONF['pingback_enabled']) && $story->DisplayElements('trackbackcode') >= 0 && $show_comments) {
                $num_trackbacks = COM_numberFormat($story->DisplayElements('trackbacks'));
                $trackbacksUrl = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $story->getSid()) . '#trackback';
                $article->set_var('trackbacks_url', $trackbacksUrl);
                $article->set_var('trackbacks_text', $num_trackbacks . ' ' . $LANG_TRB['trackbacks']);
                $article->set_var('trackbacks_count', $num_trackbacks);
                $article->set_var('lang_trackbacks', $LANG_TRB['trackbacks']);
                $article->set_var('trackbacks_with_count', COM_createLink(sprintf($LANG01[122], $num_trackbacks), $trackbacksUrl));
                if (SEC_hasRights('story.ping')) {
                    $pingurl = $_CONF['site_admin_url'] . '/trackback.php?mode=sendall&amp;id=' . $story->getSid();
                    $pingico = '<img src="' . $_CONF['layout_url'] . '/images/sendping.' . $_IMAGE_TYPE . '" alt="' . $LANG_TRB['send_trackback'] . '" title="' . $LANG_TRB['send_trackback'] . '" />';
                    $article->set_var('send_trackback_icon', COM_createLink($pingico, $pingurl));
                }
                if ($story->DisplayElements('trackbacks') > 0) {
                    $article->set_var('trackbacks_with_count', COM_createLink(sprintf($LANG01[122], $num_trackbacks), $trackbacksUrl));
                } else {
                    $article->set_var('trackbacks_with_count', sprintf($LANG01[122], $num_trackbacks));
                }
            }
            if ($_CONF['hideemailicon'] == 1 || COM_isAnonUser() && ($_CONF['loginrequired'] == 1 || $_CONF['emailstoryloginrequired'] == 1)) {
                $article->set_var('email_icon', '');
            } else {
                $emailUrl = $_CONF['site_url'] . '/profiles.php?sid=' . $story->getSid() . '&amp;what=emailstory';
                $emailicon = '<img src="' . $_CONF['layout_url'] . '/images/mail.' . $_IMAGE_TYPE . '" alt="' . $LANG01[64] . '" title="' . $LANG11[2] . '" />';
                $article->set_var('email_icon', COM_createLink($emailicon, $emailUrl));
                $article->set_var('email_story_url', $emailUrl);
                $article->set_var('lang_email_story', $LANG11[2]);
                $article->set_var('lang_email_story_alt', $LANG01[64]);
            }
            $printUrl = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $story->getSid() . '&amp;mode=print');
            if ($_CONF['hideprintericon'] == 1) {
                $article->set_var('print_icon', '');
            } else {
                $printicon = '<img src="' . $_CONF['layout_url'] . '/images/print.' . $_IMAGE_TYPE . '" alt="' . $LANG01[65] . '" title="' . $LANG11[3] . '" />';
                $article->set_var('print_icon', COM_createLink($printicon, $printUrl, array('rel' => 'nofollow')));
                $article->set_var('print_story_url', $printUrl);
                $article->set_var('lang_print_story', $LANG11[3]);
                $article->set_var('lang_print_story_alt', $LANG01[65]);
            }
            $article->set_var('pdf_icon', '');
            if ($_CONF['backend'] == 1) {
                $tid = $story->displayElements('tid');
                $alt_tid = $story->displayElements('alternate_tid');
                $result = DB_query("SELECT filename, title FROM {$_TABLES['syndication']} WHERE type = 'article' AND topic = '" . DB_escapeString($tid) . "' AND is_enabled = 1");
                $feeds = DB_numRows($result);
                for ($i = 0; $i < $feeds; $i++) {
                    list($filename, $title) = DB_fetchArray($result);
                    $feedUrl = SYND_getFeedUrl($filename);
                    $feedTitle = sprintf($LANG11[6], $title);
                }
                if ($feeds > 0) {
                    $feedicon = '<img src="' . $_CONF['layout_url'] . '/images/rss_small.' . $_IMAGE_TYPE . '" alt="' . $feedTitle . '" title="' . $feedTitle . '" />';
                    $article->set_var('feed_icon', COM_createLink($feedicon, $feedUrl, array("type" => "application/rss+xml")));
                    $article->set_var('feed_url', $feedUrl);
                } else {
                    $article->set_var('feed_icon', '');
                }
            } else {
                $article->set_var('feed_icon', '');
            }
            $article->set_var('story_display', 'index');
            $storycounter++;
            $article->set_var('story_counter', $storycounter);
        }
        $article->set_var('article_url', $articleUrl);
        $article->set_var('recent_post_anchortag', $recent_post_anchortag);
        $access = $story->checkAccess();
        $storyAccess = min($access, SEC_hasTopicAccess($story->DisplayElements('tid')));
        if ($index != 'p' and SEC_hasRights('story.edit') and $story->checkAccess() == 3 and SEC_hasTopicAccess($story->DisplayElements('tid')) == 3) {
            $article->set_var('edit_link', COM_createLink($LANG01[4], $_CONF['site_admin_url'] . '/story.php?edit=x&amp;sid=' . $story->getSid()));
            $article->set_var('edit_url', $_CONF['site_admin_url'] . '/story.php?edit=x&amp;sid=' . $story->getSid());
            $article->set_var('lang_edit_text', $LANG01[4]);
            $editicon = $_CONF['layout_url'] . '/images/edit.' . $_IMAGE_TYPE;
            $editiconhtml = '<img src="' . $editicon . '" alt="' . $LANG01[4] . '" title="' . $LANG01[4] . '" />';
            $article->set_var('edit_icon', COM_createLink($editiconhtml, $_CONF['site_admin_url'] . '/story.php?edit=x&amp;sid=' . $story->getSid()));
            $article->set_var('edit_image', $editiconhtml);
        }
        $article->set_var('lang_continue_reading', $LANG01['continue_reading']);
        PLG_templateSetVars($article_filevar, $article);
        if ($_CONF['rating_enabled'] != 0 && $index != 'p') {
            if (@in_array($story->getSid(), $ratedIds)) {
                $static = true;
                $voted = 1;
            } else {
                $static = 0;
                $voted = 0;
            }
            $uid = isset($_USER['uid']) ? $_USER['uid'] : 1;
            if ($_CONF['rating_enabled'] == 2 && $uid != $story->DisplayElements('owner_id')) {
                $article->set_var('rating_bar', RATING_ratingBar('article', $story->getSid(), $story->DisplayElements('votes'), $story->DisplayElements('rating'), $voted, 5, $static, 'sm'), false, true);
            } else {
                if (!COM_isAnonUser() && $uid != $story->DisplayElements('owner_id')) {
                    $article->set_var('rating_bar', RATING_ratingBar('article', $story->getSid(), $story->DisplayElements('votes'), $story->DisplayElements('rating'), $voted, 5, $static, 'sm'), false, true);
                } else {
                    $article->set_var('rating_bar', RATING_ratingBar('article', $story->getSid(), $story->DisplayElements('votes'), $story->DisplayElements('rating'), 1, 5, TRUE, 'sm'), false, true);
                }
            }
        } else {
            $article->set_var('rating_bar', '', false, true);
        }
        if ($index != 'p') {
            $article->create_instance($instance_id, $article_filevar);
        }
    } else {
        PLG_templateSetVars($article_filevar, $article);
        if ($_CONF['rating_enabled'] != 0) {
            if (@in_array($story->getSid(), $ratedIds)) {
                $static = true;
                $voted = 1;
            } else {
                $static = 0;
                $voted = 0;
            }
            $uid = isset($_USER['uid']) ? $_USER['uid'] : 1;
            if ($_CONF['rating_enabled'] == 2 && $uid != $story->DisplayElements('owner_id')) {
                $article->set_var('rating_bar', RATING_ratingBar('article', $story->getSid(), $story->DisplayElements('votes'), $story->DisplayElements('rating'), $voted, 5, $static, 'sm'), false, true);
            } else {
                if (!COM_isAnonUser() && $uid != $story->DisplayElements('owner_id')) {
                    $article->set_var('rating_bar', RATING_ratingBar('article', $story->getSid(), $story->DisplayElements('votes'), $story->DisplayElements('rating'), $voted, 5, $static, 'sm'), false, true);
                } else {
                    $article->set_var('rating_bar', RATING_ratingBar('article', $story->getSid(), $story->DisplayElements('votes'), $story->DisplayElements('rating'), $voted, 5, TRUE, 'sm'), false, true);
                }
            }
        } else {
            $article->set_var('rating_bar', '', false, true);
        }
    }
    $article->parse('finalstory', $article_filevar);
    return $article->finish($article->get_var('finalstory'));
}