PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/mod_news_pro_gk5/tmpl/com_k2/view.php

https://bitbucket.org/ghazalp/news-show-pro-gk5
PHP | 255 lines | 201 code | 14 blank | 40 comment | 106 complexity | 7a01dbca044f778d58930536a89046f6 MD5 | raw file
  1. <?php
  2. /**
  3. *
  4. * This View is responsible for generating layout parts for the
  5. * com_content data source
  6. *
  7. **/
  8. // no direct access
  9. defined('_JEXEC') or die('Restricted access');
  10. // load necessary K2 Route Helper
  11. require_once (JPATH_SITE.DS.'components'.DS.'com_k2'.DS.'helpers'.DS.'route.php');
  12. //
  13. class NSP_GK5_com_k2_View {
  14. // header generator
  15. static function header($config, $item) {
  16. if($config['news_content_header_pos'] != 'disabled') {
  17. $class = ' t'.$config['news_content_header_pos'].' f'.$config['news_content_header_float'];
  18. $output = NSP_GK5_Utils::cutText(htmlspecialchars($item['title']), $config, 'title_limit', '&hellip;');
  19. $output = str_replace('"', "&quot;", $item['title']);
  20. $link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($item['id'].':'.urlencode($item['alias']), $item['cid'].':'.urlencode($item['cat_alias']))));
  21. //
  22. if($config['news_header_link'] == 1) {
  23. return '<h4 class="nspHeader'.$class.'"><a href="'.$link.'" title="'.htmlspecialchars($item['title']).'">'.$output.'</a></h4>';
  24. } else {
  25. return '<h4 class="nspHeader'.$class.'" title="'.htmlspecialchars($item['title']).'">'.$output.'</h4>';
  26. }
  27. } else {
  28. return '';
  29. }
  30. }
  31. // article text generator
  32. static function text($config, $item, $readmore) {
  33. if($config['news_content_text_pos'] != 'disabled') {
  34. if($config['clean_xhtml'] == 1) {
  35. $item['text'] = strip_tags($item['text']);
  36. }
  37. //
  38. $item['text'] = NSP_GK5_Utils::cutText($item['text'], $config, 'news_limit');
  39. $link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($item['id'].':'.urlencode($item['alias']), $item['cid'].':'.urlencode($item['cat_alias']))));
  40. //
  41. $item['text'] = ($config['news_text_link'] == 1) ? '<a href="'.$link.'">'.$item['text'].'</a>' : $item['text'];
  42. $class = ' t'.$config['news_content_text_pos'].' f'.$config['news_content_text_float'];
  43. //
  44. if($config['news_content_readmore_pos'] == 'after') {
  45. return '<p class="nspText'.$class.'">'.$item['text'].' '.$readmore.'</p>';
  46. } else {
  47. return '<p class="nspText'.$class.'">'.$item['text'].'</p>';
  48. }
  49. } else {
  50. return '';
  51. }
  52. }
  53. // article image generator
  54. static function image($config, $item, $only_url = false, $pm = false){
  55. if($config['news_content_image_pos'] != 'disabled' || $pm) {
  56. $IMG_SOURCE = '';
  57. $item['title'] = str_replace('"', "&quot;", $item['title']);
  58. $uri = JURI::getInstance();
  59. //
  60. if(JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item['id']).'_L.jpg')){
  61. $IMG_SOURCE = JURI::root().'media/k2/items/cache/'.md5("Image".$item['id']).'_L.jpg';
  62. }elseif(JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item['id']).'_S.jpg')){
  63. $IMG_SOURCE = JURI::root().'media/k2/items/cache/'.md5("Image".$item['id']).'_S.jpg';
  64. } else {
  65. // set image to first in article content
  66. if(preg_match('/\<img.*src=.*?\>/',$item['text'])){
  67. $imgStartPos = JString::strpos($item['text'], 'src="');
  68. if($imgStartPos) {
  69. $imgEndPos = JString::strpos($item['text'], '"', $imgStartPos + 5);
  70. }
  71. if($imgStartPos > 0) {
  72. $IMG_SOURCE = JString::substr($item['text'], ($imgStartPos + 5), ($imgEndPos - ($imgStartPos + 5)));
  73. }
  74. }
  75. }
  76. //
  77. if($config['create_thumbs'] == 1 && $IMG_SOURCE != ''){
  78. // try to override standard image
  79. if(strpos($IMG_SOURCE, 'http://') == FALSE) {
  80. $img_file = NSP_GK5_Thumbs::createThumbnail(str_replace(JURI::root() . 'media', 'media', $IMG_SOURCE), $config, true);
  81. if(is_array($img_file)) {
  82. $IMG_SOURCE = $uri->root().'modules/mod_news_pro_gk5/cache/'.$img_file[1];
  83. } elseif($config['create_thumbs'] == 1) {
  84. jimport('joomla.filesystem.file');
  85. if(is_file(JPATH_ROOT.DS.'modules'.DS.'mod_news_pro_gk5'.DS.'cache'.DS.'default'.DS.'default'.$config['module_id'].'.png')) {
  86. $IMG_SOURCE = $uri->root().'modules/mod_news_pro_gk5/cache/default/default'.$config['module_id'].'.png';
  87. }
  88. } else {
  89. $IMG_SOURCE = '';
  90. }
  91. }
  92. } elseif($config['create_thumbs'] == 1) {
  93. jimport('joomla.filesystem.file');
  94. if(is_file(JPATH_ROOT.DS.'modules'.DS.'mod_news_pro_gk5'.DS.'cache'.DS.'default'.DS.'default'.$config['module_id'].'.png')) {
  95. $IMG_SOURCE = $uri->root().'modules/mod_news_pro_gk5/cache/default/default'.$config['module_id'].'.png';
  96. }
  97. }
  98. if($only_url) {
  99. return $IMG_SOURCE;
  100. } else {
  101. //
  102. if($IMG_SOURCE != '') {
  103. $class = ' t'.$config['news_content_image_pos'].' f'.$config['news_content_image_float'];
  104. $size = '';
  105. $margins = '';
  106. //
  107. if($config['responsive_images'] == 1) {
  108. $class .= ' gkResponsive';
  109. }
  110. //
  111. if($config['img_width'] != 0 && !$config['img_keep_aspect_ratio'] && $config['responsive_images'] == 0) $size .= 'width:'.$config['img_width'].'px;';
  112. if($config['img_height'] != 0 && !$config['img_keep_aspect_ratio'] && $config['responsive_images'] == 0) $size .= 'height:'.$config['img_height'].'px;';
  113. if($config['img_margin'] != '') $margins = ' style="margin:'.$config['img_margin'].';"';
  114. //
  115. if($config['news_image_link'] == 1) {
  116. $link = urldecode( JRoute::_(K2HelperRoute::getItemRoute($item['id'].':'.urlencode($item['alias']), $item['cid'].':'.urlencode($item['cat_alias']))) );
  117. return ($config['news_content_image_pos'] == 'center') ? '<div class="center'.$class.'"><a href="'.$link.'" class="nspImageWrapper'.$class.'"'.$margins.'><img class="nspImage" src="'.$IMG_SOURCE.'" alt="'.htmlspecialchars($news_title).'" style="'.$size.'" /></a></div>' : '<a href="'.$link.'" class="nspImageWrapper'.$class.'"'.$margins.'><img class="nspImage'.$class.'" src="'.$IMG_SOURCE.'" alt="'.htmlspecialchars($news_title).'" style="'.$size.'" /></a>';
  118. } else {
  119. return ($config['news_content_image_pos'] == 'center') ? '<div class="center'.$class.'"><span class="nspImageWrapper'.$class.'"'.$margins.'><img class="nspImage" src="'.$IMG_SOURCE.'" alt="'.htmlspecialchars($news_title).'" '.$size.' /></span></div>' : '<span class="nspImageWrapper'.$class.'"'.$margins.'><img class="nspImage'.$class.'" src="'.$IMG_SOURCE.'" alt="'.htmlspecialchars($news_title).'" style="'.$size.'" /></span>';
  120. }
  121. } else {
  122. return '';
  123. }
  124. }
  125. } else {
  126. return '';
  127. }
  128. }
  129. // ReadMore button generator
  130. static function readMore($config, $item) {
  131. //
  132. if($config['news_content_readmore_pos'] != 'disabled') {
  133. $class = ' f'.$config['news_content_readmore_pos'];
  134. $link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($item['id'].':'.urlencode($item['alias']), $item['cid'].':'.urlencode($item['cat_alias']))));
  135. //
  136. if($config['news_content_readmore_pos'] == 'after') {
  137. return '<a class="readon inline" href="'.$link.'">'.JText::_('MOD_NEWS_PRO_GK5_NSP_READMORE').'</a>';
  138. } else {
  139. return '<a class="readon '.$class.'" href="'.$link.'">'.JText::_('MOD_NEWS_PRO_GK5_NSP_READMORE').'</a>';
  140. }
  141. } else {
  142. return '';
  143. }
  144. }
  145. // article information generator
  146. static function info($config, $item, $num = 1) {
  147. // %AUTHOR %DATE %HITS %CATEGORY
  148. $news_info = '';
  149. //
  150. if($num == 1){
  151. if($config['news_content_info_pos'] != 'disabled') {
  152. $class = 'nspInfo1 t'.$config['news_content_info_pos'].' f'.$config['news_content_info_float'];
  153. }
  154. } else {
  155. if($config['news_content_info2_pos'] != 'disabled') {
  156. $class = 'nspInfo2 t'.$config['news_content_info2_pos'].' f'.$config['news_content_info2_float'];
  157. }
  158. }
  159. //
  160. if(
  161. ($config['news_content_info_pos'] != 'disabled' && $num == 1) ||
  162. ($config['news_content_info2_pos'] != 'disabled' && $num == 2)
  163. ) {
  164. $news_info = '<p class="nspInfo '.$class.'">'.$config['info'.(($num == 2) ? '2' : '').'_format'].'</p>';
  165. //
  166. $author = (trim(htmlspecialchars($item['author_alias'])) != '') ? htmlspecialchars($item['author_alias']) : htmlspecialchars($item['author_username']);
  167. $info_author = ($config['user_avatar'] == 1) ? '<span><img src="'.K2HelperUtilities::getAvatar($item['author_id'], $item['author_email'], $config['avatar_size']).'" alt="'.$author.' - avatar" class="nspAvatar" width="'.$config['avatar_size'].'" height="'.$config['avatar_size'].'" /> '.$author.'</span>' : $author;
  168. $info_date = JHTML::_('date', $item['date'], $config['date_format']);
  169. $info_hits = JText::_('MOD_NEWS_PRO_GK5_NHITS').$item['hits'];
  170. $info_rate = ($item['rating_count'] > 0) ? '<span class="nspRate">' . JText::_('MOD_NEWS_PRO_GK5_NSP_RATE') .' '. number_format($item['rating_sum'] / $item['rating_count'], 2) . '</span>': '';
  171. $info_category = ($config['category_link'] == 1) ? '<a href="'. urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($item['cid'].':'.urlencode($item['cat_alias'])))) .'" >'.$item['catname'].'</a>' : $item['catname'];
  172. $info_comments = JText::_('MOD_NEWS_PRO_GK5_NO_COMMENTS');
  173. //
  174. if(isset($item['comments'])) {
  175. if($item['comments'] == 1) {
  176. $info_comments = JText::_('MOD_NEWS_PRO_GK5_1COMMENT');
  177. } else if($item['comments'] > 1 && $item['comments'] < 5) {
  178. $info_comments = $item['comments'] . ' ' . JText::_('MOD_NEWS_PRO_GK5_MORECOMMENTS');
  179. } else if($item['comments'] >= 5) {
  180. $info_comments = $item['comments'] . ' ' . JText::_('MOD_NEWS_PRO_GK5_MUCHMORECOMMENTS');
  181. }
  182. }
  183. //
  184. $info_tags = '';
  185. if(isset($item['tags']) && count($item['tags']) > 0) {
  186. $i = 0;
  187. foreach($item['tags'] as $tag) {
  188. $link = urldecode(JRoute::_(K2HelperRoute::getTagRoute($tag)));
  189. if($i == 0) {
  190. $info_tags .= '<a href="' . $link . '">' . $tag . '</a>';
  191. } else {
  192. $info_tags .= ', <a href="' . $link . '">' . $tag . '</a>';
  193. }
  194. //
  195. $i++;
  196. }
  197. }
  198. //
  199. $news_info = str_replace('%AUTHOR', $info_author, $news_info);
  200. $news_info = str_replace('%DATE', $info_date, $news_info);
  201. $news_info = str_replace('%HITS', $info_hits, $news_info);
  202. $news_info = str_replace('%CATEGORY', $info_category, $news_info);
  203. $news_info = str_replace('%RATE', $info_rate, $news_info);
  204. $news_info = str_replace('%COMMENTS', $info_comments, $news_info);
  205. $news_info = str_replace('%TAGS', $info_tags, $news_info);
  206. } else {
  207. return '';
  208. }
  209. //
  210. return $news_info;
  211. }
  212. // rest link list generator
  213. static function lists($config, $item, $num) {
  214. $odd = $num % 2;
  215. if($config['news_short_pages'] > 0) {
  216. $text = '';
  217. $title = '';
  218. if($config['list_text_limit'] > 0) {
  219. $text = NSP_GK5_Utils::cutText(strip_tags(preg_replace("/\{.+?\}/", "", $item['text'])), $config, 'list_text_limit', '&hellip;');
  220. $text = preg_replace("/\{.+?\}/", "", $text);
  221. if(JString::strlen($text) > 0) {
  222. $text = '<p>'.$text.'</p>';
  223. }
  224. }
  225. if($config['list_title_limit'] > 0) {
  226. $title = htmlspecialchars($item['title']);
  227. $title = NSP_GK5_Utils::cutText($title, $config, 'list_text_limit', '&hellip;');
  228. $title = str_replace('"', "&quot;", $title);
  229. $link = urldecode( JRoute::_(K2HelperRoute::getItemRoute($item['id'].':'.urlencode($item['alias']), $item['cid'].':'.urlencode($item['cat_alias']))) );
  230. if(JString::strlen($title) > 0) {
  231. $title = '<h4><a href="'.$link.'" title="'.htmlspecialchars($item['title']).'">'.$title.'</a></h4>';
  232. }
  233. }
  234. // creating rest news list
  235. return '<li class="'.(($odd == 1) ? 'odd' : 'even').'">' . $title . $text . '</li>';
  236. } else {
  237. return '';
  238. }
  239. }
  240. }
  241. // EOF