Ejemplo n.º 1
0
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;
    }
}
Ejemplo n.º 2
0
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
    }
}