function nm_frontend_init() { global $NMPAGEURL, $nmpagetype, $nmsingletag; if (function_exists('i18n_init')) { i18n_init(); } // I18N plugin $nmpagetype = array(); nm_i18n_merge(); if (strval(get_page_slug(false)) == $NMPAGEURL) { global $content, $metad; $metad_orig = $metad == '' ? ' ' : $metad; $metad = ' '; $nmpagetype[] = 'site'; ob_start(); echo PHP_EOL; if (isset($_POST['search'])) { nm_reset_options('search'); nm_show_search_results(); $nmpagetype[] = 'search'; } elseif (isset($_GET[NMPARAMARCHIVE])) { nm_reset_options('archive'); if (nm_show_archive($_GET[NMPARAMARCHIVE], false)) { $nmpagetype[] = 'archive'; } } elseif (isset($_GET[NMPARAMTAG])) { $tag = rawurldecode($_GET[NMPARAMTAG]); $result = false; nm_reset_options('tag'); if (nm_get_option('tagpagination')) { $index = isset($_GET[NMPARAMPAGE]) ? intval($_GET[NMPARAMPAGE]) : NMFIRSTPAGE; $result = nm_show_tag_page($tag, $index, false); } else { $result = nm_show_tag($tag, false); } if ($result) { $nmpagetype[] = 'tag'; $nmsingletag = $tag; } } elseif (isset($_GET[NMPARAMPOST])) { nm_reset_options('single'); if (nm_show_post($_GET[NMPARAMPOST], false, false, true)) { $nmpagetype[] = 'single'; if (nm_get_option('metakeywordstags')) { nm_update_meta_keywords(); } if (nm_get_option('autometad')) { $metad = nm_post_excerpt(150, null, false); } } } elseif (isset($_GET[NMPARAMPAGE]) && intval($_GET[NMPARAMPAGE]) > NMFIRSTPAGE) { nm_reset_options('main'); nm_show_page($_GET[NMPARAMPAGE], false); $nmpagetype[] = 'main'; } else { $metad = $metad_orig; nm_reset_options('main'); nm_show_page(NMFIRSTPAGE, false); array_push($nmpagetype, 'main', 'home'); } $content = nm_ob_get_content(false); $content = addslashes(htmlspecialchars($content, ENT_QUOTES, 'UTF-8')); if (nm_get_option('templatefile')) { nm_switch_template_file(nm_get_option('templatefile')); } } nm_update_page_title(); nm_reset_options(); }
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' || $single && function_exists('is_logged_in') && is_logged_in())) { $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="', $nmoption['classpost'], '">', PHP_EOL; foreach ($nmoption['fields'] as $field) { switch ($field) { case 'title': echo ' <', $nmoption['markupposttitle'], ' class="', $nmoption['classposttitle'], '">'; if ($nmoption['titlelink']) { $class = $nmoption['classposttitlelink'] ? ' class="' . $nmoption['classposttitlelink'] . '"' : ''; echo '<a', $class, ' href="', $url, '">', $title, '</a>'; } else { echo $title; } echo '</', $nmoption['markupposttitle'], '>', PHP_EOL; break; case 'date': echo ' <', $nmoption['markuppostdate'], ' class="', $nmoption['classpostdate'], '">', i18n_r('news_manager/PUBLISHED'), ' ', $date, '</', $nmoption['markuppostdate'], '>', PHP_EOL; break; case 'content': echo ' <', $nmoption['markuppostcontent'], ' class="', $nmoption['classpostcontent'], '">'; if ($single) { echo $content; } else { $slice = ''; $class = ''; $readmore = $nmoption['readmore']; if ($readmore) { $class = $nmoption['classreadmorelink'] ? ' class="' . $nmoption['classreadmorelink'] . '"' : ''; } if ($nmoption['more']) { $morepos = strpos($content, '<hr'); if ($morepos !== false) { $slice = substr($content, 0, $morepos); if ($readmore) { $slice .= ' <p class="' . $nmoption['classreadmore'] . '"><a' . $class . ' href="' . $url . '">' . i18n_r('news_manager/READ_MORE') . '</a></p>' . PHP_EOL; } } } if ($slice) { echo $slice; } else { if ($showexcerpt) { if (!$readmore) { echo nm_create_excerpt($content); } elseif ($readmore === 'a') { echo nm_create_excerpt($content, $url, true); } else { echo nm_create_excerpt($content, $url); } } else { echo $content; if ($readmore === 'a') { echo ' <p class="', $nmoption['classreadmore'], '"><a', $class, ' href="', $url, '">', i18n_r('news_manager/READ_MORE'), '</a></p>', PHP_EOL; } } } } echo ' </', $nmoption['markuppostcontent'], '>', PHP_EOL; break; case 'tags': if ($tags) { echo ' <', $nmoption['markupposttags'], ' class="', $nmoption['classposttags'], '"><b>', i18n_r('news_manager/TAGS'), ':</b> '; $sep = ''; foreach ($tags as $tag) { if (substr($tag, 0, 1) != '_') { echo $sep, '<a href="', nm_get_url('tag') . rawurlencode($tag), '">', htmlspecialchars($tag), '</a>'; if ($sep == '') { $sep = $nmoption['tagseparator']; } } } echo '</', $nmoption['markupposttags'], '>', PHP_EOL; } break; case 'image': $imageurl = $nmoption['showimages'] ? nm_get_image_url($image) : false; if ($imageurl) { $str = ''; if (isset($nmoption['imageclass'])) { $str .= ' class="' . $nmoption['imageclass'] . '"'; } if ($nmoption['imagesizeattr'] && $nmoption['imagewidth'] && $nmoption['imageheight']) { $str .= ' width="' . $nmoption['imagewidth'] . '" height="' . $nmoption['imageheight'] . '"'; } $str .= $nmoption['imagealt'] ? ' alt="' . htmlspecialchars($title, ENT_COMPAT) . '"' : ' alt=""'; $str .= $nmoption['imagetitle'] ? ' title="' . htmlspecialchars($title, ENT_COMPAT) . '"' : ''; $str = '<img src="' . htmlspecialchars($imageurl) . '"' . $str . ' />'; if ($nmoption['imagelink']) { $str = '<a href="' . $url . '">' . $str . '</a>'; } echo ' <', $nmoption['markuppostimage'], ' class="', $nmoption['classpostimage'], '">', $str, '</', $nmoption['markuppostimage'], '>', PHP_EOL; } break; case 'author': if ($nmoption['showauthor']) { $author = nm_get_author_name_html(stripslashes($post->author)); if (empty($author) && $nmoption['defaultauthor']) { $author = $nmoption['defaultauthor']; } if (!empty($author)) { echo ' <', $nmoption['markuppostauthor'], ' class="', $nmoption['classpostauthor'], '">', i18n_r('news_manager/AUTHOR'), ' <', $nmoption['markuppostauthorname'], '>', $author, '</', $nmoption['markuppostauthorname'], '></', $nmoption['markuppostauthor'], '>', PHP_EOL; } } break; } } if (isset($nmoption['componentbottompost'])) { get_component($nmoption['componentbottompost']); echo PHP_EOL; } if ($single) { # show "go back" link? if ($nmoption['gobacklink']) { $goback = $nmoption['gobacklink'] === 'main' ? nm_get_url() : 'javascript:history.back()'; $class = $nmoption['classgobacklink'] ? ' class="' . $nmoption['classgobacklink'] . '"' : ''; echo ' <', $nmoption['markupgoback'], ' class="' . $nmoption['classgoback'] . '"><a', $class, ' href="' . $goback . '">'; i18n('news_manager/GO_BACK'); echo '</a></', $nmoption['markupgoback'], '>', 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 '<p>' . i18n_r('news_manager/NOT_EXIST') . '</p>', PHP_EOL; return false; } }