= $p1 && $index-$p1 < sizeof($pages)) $posts = $pages[$index-$p1]; else $posts = array(); if (!empty($posts)) { $showexcerpt = nm_get_option('excerpt'); if ($filter) ob_start(); foreach ($posts as $post) nm_show_post($post->slug, $showexcerpt, false); if (sizeof($pages) > 1 && nm_get_option('shownav',true)) nm_show_navigation($index, sizeof($pages)); if ($filter) echo nm_ob_get_content(true); } else { echo '
' . i18n_r('news_manager/NO_POSTS') . '
'; } } /******************************************************* * @function nm_show_archive * @param $id - unique archive id * @param $filter - if true, apply content filter * @action show posts by archive * @return true if posts shown */ function nm_show_archive($archive, $filter=true) { global $NMSETTING; $archives = nm_get_archives($NMSETTING['archivesby']); if (array_key_exists($archive, $archives)) { $showexcerpt = nm_get_option('excerpt'); $posts = $archives[$archive]; if ($filter) ob_start(); foreach ($posts as $slug) nm_show_post($slug, $showexcerpt, false); if ($filter) echo nm_ob_get_content(true); return true; } else { return false; } } /******************************************************* * @function nm_show_tag * @param $tag - unique tag id * @param $filter - if true, apply content filter * @action show posts by tag * @return true if posts shown */ function nm_show_tag($tag, $filter=true) { $tag = nm_lowercase_tags($tag); $tags = nm_get_tags(); if (array_key_exists($tag, $tags)) { $showexcerpt = nm_get_option('excerpt'); $posts = $tags[$tag]; if ($filter) ob_start(); foreach ($posts as $slug) nm_show_post($slug, $showexcerpt, false); if ($filter) echo nm_ob_get_content(true); return true; } else { return false; } } /******************************************************* * @function nm_show_tag_page * @param $tag - unique tag id * @param $index - page index (pagination) * @param $filter - if true, apply content filter * @action show posts by tag with pagination * @return true if posts shown * @since 3.0 */ function nm_show_tag_page($tag, $index=NMFIRSTPAGE, $filter=true) { global $NMPOSTSPERPAGE; $tag = nm_lowercase_tags($tag); $tags = nm_get_tags(); if (array_key_exists($tag, $tags)) { $showexcerpt = nm_get_option('excerpt'); $posts = $tags[$tag]; $p1 = intval(NMFIRSTPAGE); $index = intval($index); $pages = array_chunk($posts, intval($NMPOSTSPERPAGE), true); if ($index >= $p1 && $index-$p1 < sizeof($pages)) { $posts = $pages[$index-$p1]; if ($filter) ob_start(); foreach ($posts as $slug) nm_show_post($slug, $showexcerpt, false); if (sizeof($pages) > 1 && nm_get_option('shownav',true)) nm_show_navigation($index, sizeof($pages), $tag); if ($filter) echo nm_ob_get_content(true); return true; } } return false; } /******************************************************* * @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; } if (!empty($posts)) { $showexcerpt = nm_get_option('excerpt'); echo '' . i18n_r('news_manager/FOUND') . '
',PHP_EOL; foreach ($posts as $post) nm_show_post($post->slug, $showexcerpt, false); } else { echo '' . i18n_r('news_manager/NOT_FOUND') . '
',PHP_EOL; } } /******************************************************* * @function nm_reset_options * @param $pagetype news page type, can be 'single', 'main', 'archive', 'tag', 'search' or empty * @action set default or specific layout values * @since 3.0 */ function nm_reset_options($pagetype='') { global $nmoption, $NMSETTING, $NMSHOWEXCERPT; $nmoption = array(); # full/excerpt, readmore if ($NMSHOWEXCERPT == 'Y' || in_array($pagetype, array('archive','search','tag'))) { $nmoption['excerpt'] = true; if ($NMSETTING['readmore'] == 'R') $nmoption['readmore'] = true; elseif ($NMSETTING['readmore'] == 'F') $nmoption['readmore'] = 'a'; else $nmoption['readmore'] = false; } else { $nmoption['excerpt'] = false; // full post } # title link $nmoption['titlelink'] = ($NMSETTING['titlelink']=='Y' || ($NMSETTING['titlelink']=='P' && $pagetype != 'single')); # go back link if ($pagetype == 'single') { if ($NMSETTING['gobacklink'] == 'N') $nmoption['gobacklink'] = false; elseif ($NMSETTING['gobacklink'] == 'M') $nmoption['gobacklink'] = 'main'; else $nmoption['gobacklink'] = true; } # tag separator $nmoption['tagseparator'] = ' '; # author $nmoption['showauthor'] = false; $nmoption['defaultauthor'] = ''; # images if ( $NMSETTING['images'] == 'N' || ($pagetype == 'single' && $NMSETTING['images'] == 'P') || ($pagetype != 'main' && $NMSETTING['images'] == 'M') ) { $nmoption['showimages'] = false; } else { $nmoption['showimages'] = true; } $nmoption['imagewidth'] = intval($NMSETTING['imagewidth']); $nmoption['imageheight'] = intval($NMSETTING['imageheight']); $nmoption['imagecrop'] = ($NMSETTING['imagecrop'] == '1'); $nmoption['imagealt'] = ($NMSETTING['imagealt'] == '1'); $nmoption['imagelink'] = ($pagetype != 'single' && $NMSETTING['imagelink'] == '1'); $nmoption['imagetitle'] = false; $nmoption['imageexternal'] = false; $nmoption['imagedefault'] = ''; $nmoption['imagesizeattr'] = false; # custom settings if ($NMSETTING['enablecustomsettings'] == '1') { # extract settings foreach(preg_split('~\R~', $NMSETTING['customsettings']) as $line) { $line = trim($line); if ($line && strpos($line,'#') !== 0 && strpos($line,'//') !== 0) { // exclude empty and commented lines $arr = explode(' ',preg_replace("/[[:blank:]]+/"," ",$line)); if (count($arr) > 1) { if (in_array($arr[0], array('main','single','archive','tag','search'))) $customsettings[$arr[0]][$arr[1]] = implode(' ',array_slice($arr,2)); else $customsettings['default'][$arr[0]] = implode(' ',array_slice($arr,1)); } } } # process settings and strings foreach(array('default', $pagetype) as $type) { if (isset($customsettings[$type])) { foreach($customsettings[$type] as $key=>$value) { if (substr($value,0,1) == '"' || substr($value,0,1) == "'") $value = substr($value,1,strlen($value)-2); if (strtoupper($key) == $key) { # language string nm_set_text($key, $value); } else { # setting $nmoption[strtolower($key)] = $value; } } } } } # html tags $nmoption['markuppost'] = isset($nmoption['markuppost']) ? str_replace(array('<','>'),'',$nmoption['markuppost']) : 'div'; $nmoption['markuptitle'] = isset($nmoption['markuptitle']) ? str_replace(array('<','>'),'',$nmoption['markuptitle']) : 'h3'; # fields if (isset($nmoption['showfields'])) { $nmoption['fields'] = explode(' ',preg_replace('/ +/', ' ',trim(str_replace(',',' ',$nmoption['showfields'])))); } else { $nmoption['fields'] = array('title','date','author','image','content','tags'); } # imagesize shorthand if (isset($nmoption['imagesize'])) { if ($nmoption['imagesize'] == 0 || $nmoption['imagesize'] == 'full') { $nmoption['imagewidth'] = 0; $nmoption['imageheight'] = 0; $nmoption['imagecrop'] = 0; } else { $imageparams = explode(' ',preg_replace('/ +/', ' ',trim(str_replace(',',' ',$nmoption['imagesize'])))); $nmoption['imagewidth'] = isset($imageparams[0]) ? $imageparams[0] : 0; $nmoption['imageheight'] = isset($imageparams[1]) ? $imageparams[1] : 0; $nmoption['imagecrop'] = isset($imageparams[2]) ? $imageparams[2] : 0; } } # custom excerpt length if (isset($nmoption['excerptlength'])) { global $NMEXCERPTLENGTH; $NMEXCERPTLENGTH = $nmoption['excerptlength']; // workaround(*) } # more if (!isset($nmoption['more'])) $nmoption['more'] = false; # readmore if (!isset($nmoption['readmore'])) $nmoption['readmore'] = false; else // custom setting - anything beginning with 'a' (all, Always, ...) if (strtolower($nmoption['readmore'][0]) == 'a') $nmoption['readmore'] = 'a'; # tag pagination if (!isset($nmoption['tagpagination'])) { $nmoption['tagpagination'] = false; } else { // anything beginning with 'd' (Default, Dynamic...) or 'f' (Fancy, Folder...) $nmoption['tagpagination'] = strtolower($nmoption['tagpagination'][0]); if (!in_array($nmoption['tagpagination'], array('d','f'))) $nmoption['tagpagination'] = false; } } /******************************************************* * @function nm_show_post * @param $slug post slug * @param $showexcerpt - if TRUE, print only a short summary * @param $filter - if true, apply content filter * @param $single post page? * @action show the requested post on front-end news page, as defined by $nmoption values * @return true if post exists */ function nm_show_post($slug, $showexcerpt=false, $filter=true, $single=false) { global $nmoption, $nmdata; $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); $image = stripslashes($post->image); $tags = !empty($post->tags) ? explode(',', nm_lowercase_tags(strip_decode($post->tags))) : array(); # save post data? $nmdata = ($single) ? compact('slug', 'url', 'title', 'content', 'image', 'tags') : array(); if ($filter) ob_start(); echo ' <',$nmoption['markuppost'],' class="nm_post'; if ($single) echo ' nm_post_single'; echo '">',PHP_EOL; foreach ($nmoption['fields'] as $field) { switch($field) { case 'title': echo ' <',$nmoption['markuptitle'],' class="nm_post_title">'; if ($nmoption['titlelink']) echo '',$title,''; else echo $title; echo '',$nmoption['markuptitle'],'>',PHP_EOL; break; case 'date': echo '',i18n_r('news_manager/PUBLISHED'),' ',$date,'
',PHP_EOL; break; case 'content': echo ''; i18n('news_manager/GO_BACK'); echo '
',PHP_EOL; } } echo ' ',$nmoption['markuppost'],'>',PHP_EOL; if (isset($nmoption['componentafterpost'])) { get_component($nmoption['componentafterpost']); echo PHP_EOL; } if ($filter) echo nm_ob_get_content(true); return true; } else { echo '' . i18n_r('news_manager/NOT_EXIST') . '
',PHP_EOL; return false; } } /******************************************************* * @function nm_show_navigation * @param $index - current page index * @param $total - total number of subpages * @param $tag - tag to filter by (optional) * @action provides links to navigate between subpages in main news or tag page */ function nm_show_navigation($index, $total, $tag=null) { $p1 = intval(NMFIRSTPAGE); if (!$tag) { $first = nm_get_url(); $page = nm_get_url('page'); } else { $first = nm_get_url('tag').rawurlencode($tag); if (nm_get_option('tagpagination') == 'f') $page = $first.'/'.NMPARAMPAGE.'/'; else $page = $first.'&'.NMPARAMPAGE.'='; } echo '