Example #1
0
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>';
    }
}
Example #2
0
function nm_post_excerpt($len = null, $ellipsis = null, $echo = true)
{
    global $nmdata, $NMEXCERPTLENGTH, $nmoption;
    if (isset($nmdata['content']) && $nmdata['content']) {
        if (!$len) {
            $len = isset($nmoption['excerptlength']) ? $nmoption['excerptlength'] : $NMEXCERPTLENGTH;
        }
        // workaround(*)
        if (!$ellipsis && $ellipsis !== '') {
            $ellipsis = i18n_r('news_manager/ELLIPSIS');
        }
        $excerpt = nm_make_excerpt($nmdata['content'], $len, $ellipsis);
        if ($echo) {
            echo $excerpt;
        }
        return $excerpt;
    } else {
        return '';
    }
}
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
    }
}