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_search_results() { $keywords = preg_split('/\\s+/u', trim($_POST['keywords']), null, PREG_SPLIT_NO_EMPTY); if (empty($keywords)) { $posts = array(); } else { $posts = nm_get_posts(); $mb = function_exists('mb_stripos'); foreach ($keywords as $keyword) { $match = array(); foreach ($posts as $post) { $data = getXML(NMPOSTPATH . $post->slug . '.xml'); $content = $data->title . $data->content; if ($mb && mb_stripos($content, $keyword, 0, 'UTF-8') !== false || !$mb && stripos($content, $keyword) !== false) { $match[] = $post; } } $posts = $match; } } if (!empty($posts)) { $showexcerpt = nm_get_option('excerpt'); echo '<p>' . i18n_r('news_manager/FOUND') . '</p>', PHP_EOL; foreach ($posts as $post) { nm_show_post($post->slug, $showexcerpt, false); } } else { echo '<p>' . i18n_r('news_manager/NOT_FOUND') . '</p>', PHP_EOL; } }