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_create_excerpt($content, $url = false, $forcereadmore = false) { global $NMEXCERPTLENGTH; $len = intval($NMEXCERPTLENGTH); if ($len == 0) { return ''; } else { $ellipsis = i18n_r('news_manager/ELLIPSIS'); $break = nm_get_option('breakwords'); $class = nm_get_option('classreadmorelink'); $class = $class ? ' class="' . $class . '"' : ''; if ($url) { $readmorehtml = '<span class="' . nm_get_option('classreadmore', 'nm_readmore') . '"><a' . $class . ' href="' . $url . '">' . i18n_r('news_manager/READ_MORE') . '</a></span>'; if ($forcereadmore) { $content = nm_make_excerpt($content, $len, $ellipsis, $break) . ' ' . $readmorehtml; } else { $content = nm_make_excerpt($content, $len, $ellipsis . $readmorehtml, $break); } } else { $content = nm_make_excerpt($content, $len, $ellipsis, $break); } return '<p>' . $content . '</p>'; } }
function nm_update_page_title() { global $title, $nmpagetitle; $nmpagetitle = false; if (nm_is_site() && nm_get_option('titletag', true) && !function_exists('nmt_set_gstitle')) { if (nm_is_single()) { $nmpagetitle = $title; $title = nm_post_title('', ' - ' . $title, false); } elseif (nm_is_tag()) { $nmpagetitle = $title; $title = nm_single_tag_title('', ' - ' . $title, false); } } }
function nm_custom_display_posts($templ = '', $tag = '', $type = '') { global $NMRECENTPOSTS, $NMCUSTOMIMAGES, $NMCUSTOMOFFSET; if ($templ == '') { $templ = '<p><a href="{{ post_link }}">{{ post_title }}</a> {{ post_date }}</p>' . PHP_EOL; } foreach (array('post_link', 'post_slug', 'post_title', 'post_date', 'post_excerpt', 'post_content', 'post_number', 'post_image', 'post_image_url', 'post_author') as $token) { if (strpos($templ, '{{' . $token . '}}')) { $templ = str_replace('{{' . $token . '}}', '{{ ' . $token . ' }}', $templ); } } if ($type == 'future') { $posts = array_reverse(nm_get_posts(true)); $allposts = array(); $now = time(); foreach ($posts as $post) { if ($post->private != 'Y' && strtotime($post->date) > $now) { $allposts[] = $post; } } } else { $allposts = nm_get_posts(); } if (trim($tag) !== '') { $posts = array(); foreach ($allposts as $post) { if (in_array($tag, explode(',', $post->tags))) { $posts[] = $post; } } } else { $posts = $allposts; } unset($allposts); if (!empty($posts)) { ob_start(); // content filter if (strpos($templ, '{{ post_date }}') !== false) { global $NMCUSTOMDATE; $fmt = $NMCUSTOMDATE ? $NMCUSTOMDATE : i18n_r('news_manager/DATE_FORMAT'); } else { $fmt = false; } $w = isset($NMCUSTOMIMAGES['width']) ? $NMCUSTOMIMAGES['width'] : 0; $h = isset($NMCUSTOMIMAGES['height']) ? $NMCUSTOMIMAGES['height'] : 0; $c = isset($NMCUSTOMIMAGES['crop']) ? $NMCUSTOMIMAGES['crop'] : 0; $d = isset($NMCUSTOMIMAGES['default']) ? $NMCUSTOMIMAGES['default'] : ''; $count = 0; $offset = $NMCUSTOMOFFSET ? intval($NMCUSTOMOFFSET) : 0; $posts = array_slice($posts, $offset, $NMRECENTPOSTS, true); foreach ($posts as $post) { $str = $templ; $str = str_replace('{{ post_number }}', strval($count), $str); $str = str_replace('{{ post_slug }}', $post->slug, $str); $str = str_replace('{{ post_link }}', nm_get_url('post') . $post->slug, $str); $str = str_replace('{{ post_title }}', stripslashes($post->title), $str); if (strpos($str, '{{ post_image') !== false && function_exists('nm_get_image_url')) { $img = htmlspecialchars(nm_get_image_url((string) $post->image, $w, $h, $c, $d)); $str = str_replace('{{ post_image_url }}', $img, $str); if (!empty($img)) { $str = str_replace('{{ post_image }}', '<img src="' . $img . '" alt="" />', $str); } else { $str = str_replace('{{ post_image }}', '', $str); } } if ($fmt) { $date = nm_get_date($fmt, strtotime($post->date)); $str = str_replace('{{ post_date }}', $date, $str); } if (strpos($str, '{{ post_author }}') !== false) { if (isset($post->author)) { $author = strval($post->author); global $NMAUTHOR; // NM Custom Authors (array) if ($NMAUTHOR && isset($NMAUTHOR[$author])) { $author = $NMAUTHOR[$author]; } } else { if (function_exists('nm_get_option')) { $author = nm_get_option('defaultauthor'); // NM 3.0+ custom setting if (!$author) { $author = ''; } } else { $author = ''; } } $str = str_replace('{{ post_author }}', $author, $str); } if (strpos($str, '{{ post_excerpt }}') !== false || strpos($str, '{{ post_content }}') !== false) { $postxml = getXML(NMPOSTPATH . $post->slug . '.xml'); if (strpos($str, '{{ post_excerpt }}') !== false) { if (function_exists('nm_make_excerpt1')) { $excerpt = nm_make_excerpt(strip_decode($postxml->content)); } else { // NM < 3.0 - remove <p>, </p> $excerpt = substr(nm_create_excerpt(strip_decode($postxml->content)), 3, -4); } $str = str_replace('{{ post_excerpt }}', $excerpt, $str); } else { $str = str_replace('{{ post_content }}', strip_decode($postxml->content), $str); } } echo $str; $count++; } $output = ob_get_contents(); ob_end_clean(); echo exec_filter('content', $output); // content filter } }