= 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 = '
'.$imghtml.'
'.PHP_EOL; } else { $imghtml = ''; } # print post data ?>

',$title,''; else echo $title; ?>

tags)) { echo '

' . i18n_r('news_manager/TAGS') . ':'; $tags = explode(',', $post->tags); foreach ($tags as $tag) if (substr($tag, 0, 1) != '_') { $url = nm_get_url('tag') . $tag; echo ' ',$tag,''; } echo '

'; } # single post page? if ($nmoption['pagetype'] == 'single') { # store post title global $NMPOSTTITLE; $NMPOSTTITLE = $title; if ($nmoption['gobacklink']) { # show "go back" link $goback = ($nmoption['gobacklink'] === 'main') ? nm_get_url() : 'javascript:history.back()'; echo '

'; i18n('news_manager/GO_BACK'); echo '

'; } } ?>
' . i18n_r('news_manager/NOT_EXIST') . '

'; } } /******************************************************* * @function nm_show_navigation * @param $index - current page index * @param $total - total number of subpages * @action provides links to navigate between subpages */ function nm_show_navigation($index, $total) { $url = nm_get_url('page'); echo '
'; if ($index < $total - 1) { ?>
0) { ?>
'; } /******************************************************* * @function nm_post_title * @param $before Text to place before the title. Defaults to '' * @param $after Text to place after the title. Defaults to '' * @param $echo Display (true) or return (false) * @action Display or return the post title. Returns false if not on single post page * @since 2.3 */ function nm_post_title($before='', $after='', $echo=true) { global $NMPAGEURL; $title = false; if (isset($_GET['post']) && strval(get_page_slug(false)) == $NMPAGEURL) { global $NMPOSTTITLE; if ($NMPOSTTITLE) { # use previously read post title $title = $before.$NMPOSTTITLE.$after; if ($echo) echo $title; } } return $title; } /*** frontend functions, since 2.5 ***/ // conditionals function nm_is_single() { global $nmoption; return ($nmoption['pagetype'] == 'single'); } function nm_is_main() { global $nmoption; return ($nmoption['pagetype'] == 'main'); } function nm_is_tag() { global $nmoption; return ($nmoption['pagetype'] == 'tag'); } function nm_is_archive() { global $nmoption; return ($nmoption['pagetype'] == 'archive'); } function nm_is_search() { global $nmoption; return ($nmoption['pagetype'] == 'search'); } // set general option function nm_set_option($option, $value=true) { global $nmoption; if ($option) $nmoption[$option] = $value; } // get option value, return $default if not defined function nm_get_option($option, $default=false) { global $nmoption; if ($option) { if (isset ($nmoption[$option])) return $nmoption[$option]; else return $default; } } // images function nm_enable_images() { global $nmoption; $nmoption['showimages'] = true; } function nm_disable_images() { global $nmoption; $nmoption['showimages'] = false; } function nm_set_image_option($option, $value=true) { global $nmoption; if ($option) $nmoption['images'][$option] = $value; } function nm_set_image_size($width=null, $height=null, $crop=false) { global $nmoption; $nmoption['images']['width'] = $width; $nmoption['images']['height'] = $height; $nmoption['images']['crop'] = $crop; } // custom text/language strings function nm_set_text($i18nkey=null, $i18nvalue=null) { global $i18n; if ($i18nkey && $i18nvalue) $i18n['news_manager/'.$i18nkey] = $i18nvalue; } // used by nm_get_layout_block if (!function_exists('component_exists')) { function component_exists($id) { global $components; if (!$components) { if (file_exists(GSDATAOTHERPATH.'components.xml')) { $data = getXML(GSDATAOTHERPATH.'components.xml'); $components = $data->item; } else { $components = array(); } } $exists = FALSE; if (count($components) > 0) { foreach ($components as $component) { if ($id == $component->slug) { $exists = TRUE; break; } } } return $exists; } } // get template component, return false if not exists function nm_get_layout_block($templ) { if (component_exists($templ)) { get_component($templ); return true; } else { return false; } } ?>