1<?php 2/** 3 * @package tikiwiki 4 */ 5// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project 6// 7// All Rights Reserved. See copyright.txt for details and a complete list of authors. 8// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. 9// $Id$ 10 11use Tiki\Lib\Image\Image; 12 13$section = 'cms'; 14require_once('tiki-setup.php'); 15$artlib = TikiLib::lib('art'); 16$access->check_feature('feature_articles'); 17if (! isset($_REQUEST["articleId"])) { 18 $smarty->assign('msg', tra("No article indicated")); 19 $smarty->display("error.tpl"); 20 die; 21} 22 23$parserlib = TikiLib::lib('parser'); 24 25$article_data = $artlib->get_article($_REQUEST["articleId"]); 26$tikilib->get_perm_object($_REQUEST['articleId'], 'article'); 27if ($article_data === false) { 28 if (! $user) { 29 $_SESSION['loginfrom'] = $_SERVER['REQUEST_URI']; 30 } 31 $smarty->assign('errortype', 401); 32 $smarty->assign('msg', tra('Permission denied')); 33 $smarty->display('error.tpl'); 34 die; 35} 36if (! $article_data) { 37 $smarty->assign('msg', tra("Article not found")); 38 $smarty->display("error.tpl"); 39 die; 40} 41if (($article_data['publishDate'] > $tikilib->now) && ($article_data['author'] != $user && $tiki_p_admin != 'y' && $tiki_p_admin_cms != 'y') && ($article_data['type'] != 'Event')) { 42 $smarty->assign('msg', tra("Article is not published yet")); 43 $smarty->display("error.tpl"); 44 die; 45} 46 47if ($article_data['ispublished'] == 'n' && $tiki_p_edit_article != 'y') { 48 $smarty->assign('msg', tra("Article is not published yet")); 49 $smarty->display("error.tpl"); 50 die; 51} 52 53if (isset($_REQUEST['switchlang']) && $_REQUEST['switchlang'] == 'y' && $prefs['feature_multilingual'] == 'y' && $prefs['feature_sync_language'] == 'y' && ! empty($article_data["lang"]) && $prefs['language'] != $article_data["lang"]) { 54 header('Location: tiki-switch_lang.php?language=' . $article_data['lang']); 55 die; 56} 57 58$statslib = TikiLib::lib('stats'); 59if ($prefs['feature_categories'] == 'y') { 60 $categlib = TikiLib::lib('categ'); 61} 62//This is basicaly a copy of part of the freetag code from tiki-setup.php and should be only there. The problem is that the section name for articles is "cms" and the object name for article in the table tiki_objects is "article". Maybe it is a good idea to use "cms" on tiki_objects instead "article" and then this block of code can be removed. Another solution? 63if ($prefs['feature_freetags'] == 'y') { 64 $freetaglib = TikiLib::lib('freetag'); 65 $here = $sections[$section]; 66 if (isset($here['itemkey']) and isset($_REQUEST[$here['itemkey']])) { 67 $tags = $freetaglib->get_tags_on_object($_REQUEST[$here['itemkey']], "article " . $_REQUEST[$here['key']]); 68 } elseif (isset($here['key']) and isset($_REQUEST[$here['key']])) { 69 $tags = $freetaglib->get_tags_on_object($_REQUEST[$here['key']], "article"); 70 } else { 71 $tags = []; 72 } 73 $smarty->assign('freetags', $tags); 74} 75$artlib->add_article_hit($_REQUEST["articleId"]); 76$smarty->assign('articleId', $_REQUEST["articleId"]); 77$smarty->assign('arttitle', $article_data["title"]); 78$smarty->assign('topline', $article_data["topline"]); 79$smarty->assign('show_topline', $article_data["show_topline"]); 80$smarty->assign('subtitle', $article_data["subtitle"]); 81$smarty->assign('show_subtitle', $article_data["show_subtitle"]); 82$smarty->assign('linkto', $article_data["linkto"]); 83$smarty->assign('show_linkto', $article_data["show_linkto"]); 84$smarty->assign('image_caption', $article_data["image_caption"]); 85$smarty->assign('show_image_caption', $article_data["show_image_caption"]); 86$smarty->assign('lang', $article_data["lang"]); 87$smarty->assign('authorName', $article_data["authorName"]); 88$smarty->assign('author', $article_data["author"]); 89$smarty->assign('show_author', $article_data["show_author"]); 90$smarty->assign('topicId', $article_data["topicId"]); 91$smarty->assign('type', $article_data["type"]); 92$smarty->assign('rating', $article_data["rating"]); 93$smarty->assign('entrating', $article_data["entrating"]); 94$smarty->assign('useImage', $article_data["useImage"]); 95$smarty->assign('isfloat', $article_data["isfloat"]); 96$smarty->assign('image_name', $article_data["image_name"]); 97$smarty->assign('image_type', $article_data["image_type"]); 98$smarty->assign('image_size', $article_data["image_size"]); 99$smarty->assign('image_x', $article_data["image_x"]); 100$smarty->assign('list_image_x', $article_data["list_image_x"]); 101$smarty->assign('image_y', $article_data["image_y"]); 102$smarty->assign('image_data', urlencode($article_data["image_data"])); 103$smarty->assign('reads', $article_data["nbreads"]); 104$smarty->assign('show_reads', $article_data["show_reads"]); 105$smarty->assign('size', $article_data["size"]); 106$smarty->assign('show_size', $article_data["show_size"]); 107$smarty->assign('use_ratings', $article_data["use_ratings"]); 108$smarty->assign('comment_can_rate_article', $article_data["comment_can_rate_article"]); 109$smarty->assign('ispublished', $article_data["ispublished"]); 110if (strlen($article_data["image_data"]) > 0) { 111 $smarty->assign('hasImage', 'y'); 112} else { 113 $smarty->assign('hasImage', 'n'); 114} 115if ($article_data['image_x'] > 0) { 116 $smarty->assign('width', $article_data['image_x']); 117} else { 118 $img = Image::create($article_data['image_x'], false); 119 $smarty->assign('width', $img->getWidth() + 2); 120} 121$smarty->assign('heading', $article_data["heading"]); 122if ($prefs['article_paginate'] == 'y') { 123 if (! isset($_REQUEST['page'])) { 124 $_REQUEST['page'] = 1; 125 } 126 // Get ~pp~, ~np~ and <pre> out of the way. --rlpowell, 24 May 2004 127 $preparsed = []; 128 $noparsed = []; 129 130 $parserlib->plugins_remove($article_data["body"], $noparsed); 131 $parserlib->parse_first($article_data["body"], $preparsed, $noparsed); 132 $pages = $artlib->get_number_of_pages($article_data["body"]); 133 $article_data["body"] = $artlib->get_page($article_data["body"], $_REQUEST['page']); 134 $smarty->assign('pages', $pages); 135 if ($pages > $_REQUEST['page']) { 136 $smarty->assign('next_page', $_REQUEST['page'] + 1); 137 } else { 138 $smarty->assign('next_page', $_REQUEST['page']); 139 } 140 if ($_REQUEST['page'] > 1) { 141 $smarty->assign('prev_page', $_REQUEST['page'] - 1); 142 } else { 143 $smarty->assign('prev_page', 1); 144 } 145 $smarty->assign('first_page', 1); 146 $smarty->assign('last_page', $pages); 147 $smarty->assign('pagenum', $_REQUEST['page']); 148 // Put ~pp~, ~np~ and <pre> back. --rlpowell, 24 May 2004 149 $parserlib->replace_preparse($article_data["body"], $preparsed, $noparsed); 150} 151if ($prefs["article_custom_attributes"] == 'y') { 152 $t_article_attributes = $artlib->get_article_attributes($article_data["articleId"]); 153 $type_attributes = $artlib->get_article_type_attributes($article_data["type"], 'relationId ASC'); 154 $article_attributes = []; 155 foreach ($type_attributes as $attname => $att) { 156 if (in_array($att["itemId"], array_keys($t_article_attributes))) { 157 $article_attributes[$attname] = $t_article_attributes[$att["itemId"]]; 158 } 159 } 160 $smarty->assign('article_attributes', $article_attributes); 161} else { 162 $smarty->assign('article_attributes', []); 163} 164$smarty->assign('body', $article_data["body"]); 165$smarty->assign('publishDate', $article_data["publishDate"]); 166$smarty->assign('expireDate', $article_data["expireDate"]); 167$smarty->assign('show_pubdate', $article_data["show_pubdate"]); 168$smarty->assign('show_expdate', $article_data["show_expdate"]); 169$smarty->assign('edit_data', 'y'); 170$body = $article_data["body"]; 171$heading = $article_data["heading"]; 172 173// We need to figure out in which theme we are before the page parsing 174// in case the page contains pluginModule in which cas the parser triggers tiki-modules.php 175// which needs $tc_theme for deciding on the visible modules everywhere in the page 176include_once('tiki-section_options.php'); 177if ($prefs['feature_theme_control'] == 'y') { 178 $cat_type = 'article'; 179 $cat_objid = $_REQUEST["articleId"]; 180 include('tiki-tc.php'); 181} 182 183$smarty->assign('parsed_body', $parserlib->parse_data($body, ['is_html' => $artlib->is_html($article_data)])); 184$smarty->assign( 185 'parsed_heading', 186 $parserlib->parse_data( 187 $heading, 188 [ 189 'min_one_paragraph' => true, 190 'is_html' => $artlib->is_html($article_data, true), 191 ] 192 ) 193); 194if ($prefs['article_related_articles'] == 'y') { 195 $article_data['related_articles'] = $artlib->get_related_articles($article_data['articleId']); 196 if (isset($article_data['related_articles']) && ! empty($article_data['related_articles'])) { 197 $smarty->assign('related_articles', $article_data['related_articles']); 198 } 199} 200 201$topics = $artlib->list_topics(); 202if (isset($topics[$article_data['topicId']])) { 203 $smarty->assign('topicName', $topics[$article_data['topicId']]['name']); 204} 205$smarty->assign_by_ref('topics', $topics); 206 207$objId = $_REQUEST['articleId']; 208if ($prefs['feature_categories'] == 'y') { 209 $is_categorized = $categlib->is_categorized('article', $objId); 210} 211// Display category path or not (like {catpath()}) 212if (isset($is_categorized) && $is_categorized) { 213 $smarty->assign('is_categorized', 'y'); 214 if ($prefs['feature_categories'] == 'y' && $prefs['feature_categorypath'] == 'y') { 215 $cats = $categlib->get_object_categories('article', $objId); 216 $display_catpath = $categlib->get_categorypath($cats); 217 $smarty->assign('display_catpath', $display_catpath); 218 } 219 // Display current category objects or not (like {category()}) 220 if (isset($prefs['feature_categoryobjects']) and $prefs['feature_categories'] == 'y') { 221 if ($prefs['feature_categoryobjects'] == 'y') { 222 $catids = $categlib->get_object_categories('article', $objId); 223 $display_catobjects = $categlib->get_categoryobjects($catids); 224 $smarty->assign('display_catobjects', $display_catobjects); 225 } 226 } 227 if ($prefs['feature_categories'] == 'y' && $prefs['category_morelikethis_algorithm'] != '') { 228 $freetaglib = TikiLib::lib('freetag'); 229 $category_related_objects = $freetaglib->get_similar('article', $_REQUEST['articleId'], empty($prefs['category_morelikethis_mincommon_max']) ? $prefs['maxRecords'] : $prefs['category_morelikethis_mincommon_max'], null, 'category'); 230 $smarty->assign_by_ref('category_related_objects', $category_related_objects); 231 } 232} else { 233 $smarty->assign('is_categorized', 'n'); 234} 235 236if ($prefs['feature_multilingual'] == 'y' && $article_data['lang']) { 237 $multilinguallib = TikiLib::lib('multilingual'); 238 $trads = $multilinguallib->getTranslations('article', $article_data['articleId'], $article_data["title"], $article_data['lang']); 239 $smarty->assign('trads', $trads); 240} 241//Keep track of month of last viewed article for article months_links module foldable display 242$_SESSION['cms_last_viewed_month'] = TikiLib::date_format("%Y-%m", $article_data["publishDate"]); 243ask_ticket('article-read'); 244//add a hit 245$statslib->stats_hit($article_data["title"], "article", $article_data['articleId']); 246if ($prefs['feature_actionlog'] == 'y') { 247 $logslib->add_action('Viewed', $_REQUEST['articleId'], 'article'); 248} 249// Display the Index Template 250$smarty->assign('mid', 'tiki-read_article.tpl'); 251$smarty->display("tiki.tpl"); 252