= 0 && $index < sizeof($pages)) $posts = $pages[$index]; else $posts = array(); nm_set_pagetype_options('main'); nm_get_layout_block('nm-init'); nm_get_layout_block('nm-top-main') || nm_get_layout_block('nm-top'); if (!empty($posts)) { $showexcerpt = nm_get_option('excerpt'); foreach ($posts as $post) nm_show_post($post->slug, $showexcerpt); if (sizeof($pages) > 1) nm_show_navigation($index, sizeof($pages)); } else { echo '
' . i18n_r('news_manager/NO_POSTS') . '
'; } nm_get_layout_block('nm-bottom-main') || nm_get_layout_block('nm-bottom'); nm_get_layout_block('nm-end'); } /******************************************************* * @function nm_show_archive * @param $id - unique archive id * @action show posts by archive */ function nm_show_archive($archive) { global $NMARCHIVESBY; $archives = nm_get_archives($NMARCHIVESBY); if (array_key_exists($archive, $archives)) { nm_set_pagetype_options('archive'); nm_get_layout_block('nm-init'); nm_get_layout_block('nm-top-archive') || nm_get_layout_block('nm-top'); $showexcerpt = nm_get_option('excerpt'); $posts = $archives[$archive]; foreach ($posts as $slug) nm_show_post($slug, $showexcerpt); } nm_get_layout_block('nm-bottom-archive') || nm_get_layout_block('nm-bottom'); nm_get_layout_block('nm-end'); } /******************************************************* * @function nm_show_tag * @param $id - unique tag id * @action show posts by tag */ function nm_show_tag($tag) { $tags = nm_get_tags(); if (array_key_exists($tag, $tags)) { nm_set_pagetype_options('tag'); nm_get_layout_block('nm-init'); nm_get_layout_block('nm-top-tag') || nm_get_layout_block('nm-top'); $showexcerpt = nm_get_option('excerpt'); $posts = $tags[$tag]; foreach ($posts as $slug) nm_show_post($slug, $showexcerpt); nm_get_layout_block('nm-bottom-tag') || nm_get_layout_block('nm-bottom'); nm_get_layout_block('nm-end'); } } /******************************************************* * @function nm_show_search_results() * @action search posts by keyword(s) */ function nm_show_search_results() { $keywords = @explode(' ', $_POST['keywords']); $posts = nm_get_posts(); foreach ($keywords as $keyword) { $match = array(); foreach ($posts as $post) { $data = getXML(NMPOSTPATH.$post->slug.'.xml'); $content = $data->title . $data->content; if (stripos($content, $keyword) !== false) $match[] = $post; } $posts = $match; } nm_set_pagetype_options('search'); nm_get_layout_block('nm-init'); nm_get_layout_block('nm-top-search') || nm_get_layout_block('nm-top'); if (!empty($posts)) { $showexcerpt = nm_get_option('excerpt'); echo '' . i18n_r('news_manager/FOUND') . '
'; foreach ($posts as $post) nm_show_post($post->slug, $showexcerpt); } else { echo '' . i18n_r('news_manager/NOT_FOUND') . '
'; } nm_get_layout_block('nm-bottom-search') || nm_get_layout_block('nm-bottom'); nm_get_layout_block('nm-end'); } /******************************************************* * @function nm_show_single * @param $slug post slug * @action show single post on news page */ function nm_show_single($slug) { nm_set_pagetype_options('single'); nm_get_layout_block('nm-init'); nm_get_layout_block('nm-top-single') || nm_get_layout_block('nm-top'); nm_show_post($slug); nm_get_layout_block('nm-bottom-single') || nm_get_layout_block('nm-bottom'); nm_get_layout_block('nm-end'); } /******************************************************* * @function nm_set_pagetype_options * @param $pagetype news page type, can be 'single', 'main', 'archive', 'tag' or 'search' * @action set page type and default post layout values * @since 2.5 */ function nm_set_pagetype_options($pagetype) { global $nmoption, $NMSHOWEXCERPT; $nmoption = array(); # general options $nmoption['excerpt'] = ($NMSHOWEXCERPT == 'Y' || in_array($pagetype, array('archive','search','tag'))); $nmoption['titlelink'] = true; $nmoption['gobacklink'] = true; // only supported in single post pages # images: $nmoption['showimages'] = true; $nmoption['images']['alt']= false; $nmoption['images']['title']= false; $nmoption['images']['link']= false; $nmoption['images']['external']= false; $nmoption['images']['default']= ''; # news page type $nmoption['pagetype'] = $pagetype; } /******************************************************* * @function nm_show_post * @param $slug post slug * @param $showexcerpt - if TRUE, print only a short summary (other options: 'readmore', 'forcereadmore') * @action show the requested post on front-end news page, as defined by $nmoption values */ function nm_show_post($slug, $showexcerpt=false) { global $nmoption; $file = NMPOSTPATH.$slug.'.xml'; if (dirname(realpath($file)) == realpath(NMPOSTPATH)) // no path traversal $post = @getXML($file); if (!empty($post) && $post->private != 'Y') { $url = nm_get_url('post') . $slug; $title = stripslashes($post->title); $date = nm_get_date(i18n_r('news_manager/DATE_FORMAT'), strtotime($post->date)); $content = strip_decode($post->content); if ($showexcerpt) { if ($showexcerpt === 'readmore') $content = nm_create_excerpt($content, $url); elseif ($showexcerpt === 'forcereadmore') $content = nm_create_excerpt($content, $url, true); else $content = nm_create_excerpt($content); } $image = $nmoption['showimages'] ? nm_get_image_url(stripslashes($post->image)) : false; if ($image) { $imghtml = ''; $imghtml .= $nmoption['images']['alt'] ? ' alt="'.htmlspecialchars($title, ENT_COMPAT).'"' : ''; $imghtml .= $nmoption['images']['title'] ? ' title="'.htmlspecialchars($title, ENT_COMPAT).'"' : ''; $imghtml = ''; if ($nmoption['images']['link']) $imghtml = ''.$imghtml.''; $imghtml = '