Esempio n. 1
0
function theme_remove_last_slash($url)
{
    $len = theme_strlen($url);
    if ($len > 0 && $url[$len - 1] == '/') {
        $url = substr($url, 0, -1);
    }
    return $url;
}
Esempio n. 2
0
function theme_get_metadata_icons($icons = '', $class = '')
{
    global $post;
    if (!is_string($icons) || theme_strlen($icons) == 0) {
        return;
    }
    $icons = explode(",", str_replace(' ', '', $icons));
    if (!is_array($icons) || count($icons) == 0) {
        return;
    }
    $result = array();
    for ($i = 0; $i < count($icons); $i++) {
        $icon = $icons[$i];
        switch ($icon) {
            case 'date':
                $result[] = '<span class="mmb-postdateicon">' . sprintf(__('<span class="%1$s"></span> %2$s', THEME_NS), 'date', sprintf('<span class="entry-date" title="%1$s">%2$s</span>', esc_attr(get_the_time()), get_the_date())) . '</span>';
                break;
            case 'author':
                $result[] = '<span class="mmb-postauthoricon">' . sprintf(__('<span class="%1$s">By</span> %2$s', THEME_NS), 'author', sprintf('<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>', get_author_posts_url(get_the_author_meta('ID')), sprintf(esc_attr(__('View all posts by %s', THEME_NS)), get_the_author()), get_the_author())) . '</span>';
                break;
            case 'category':
                $categories = get_the_category_list(', ');
                if (theme_strlen($categories) == 0) {
                    break;
                }
                $result[] = '<span class="mmb-postcategoryicon">' . sprintf(__('<span class="%1$s">Posted in</span> %2$s', THEME_NS), 'categories', get_the_category_list(', ')) . '</span>';
                break;
            case 'tag':
                $tags_list = get_the_tag_list('', ', ');
                if (!$tags_list) {
                    break;
                }
                $result[] = '<span class="mmb-posttagicon">' . sprintf(__('<span class="%1$s">Tagged</span> %2$s', THEME_NS), 'tags', $tags_list) . '</span>';
                break;
            case 'comments':
                if (!comments_open() || !theme_get_option('theme_allow_comments')) {
                    break;
                }
                theme_ob_start();
                comments_popup_link(__('Leave a comment', THEME_NS), __('1 Comment', THEME_NS), __('% Comments', THEME_NS));
                $result[] = '<span class="mmb-postcommentsicon">' . theme_ob_get_clean() . '</span>';
                break;
            case 'edit':
                if (!current_user_can('edit_post', $post->ID)) {
                    break;
                }
                theme_ob_start();
                edit_post_link(__('Edit', THEME_NS), '');
                $result[] = '<span class="mmb-postediticon">' . theme_ob_get_clean() . '</span>';
                break;
        }
    }
    $result = implode(theme_get_option('theme_metadata_separator'), $result);
    if (theme_is_empty_html($result)) {
        return;
    }
    return "<div class=\"mmb-post{$class}icons mmb-metadata-icons\">{$result}</div>";
}
function theme_trim_long_str($str, $len = 50, $sep = ' ')
{
    $words = explode($sep, $str);
    $wcount = count($words);
    while ($wcount > 0 && theme_strlen(join($sep, array_slice($words, 0, $wcount))) > $len) {
        $wcount--;
    }
    if ($wcount != count($words)) {
        $str = join($sep, array_slice($words, 0, $wcount)) . '&hellip;';
    }
    return $str;
}
Esempio n. 4
0
function theme_get_excerpt($args = array())
{
    global $post;
    $more_tag = theme_get_array_value($args, 'more_tag', __('Continue reading <span class="meta-nav">&rarr;</span>', THEME_NS));
    $auto = theme_get_array_value($args, 'auto', theme_get_option('theme_metadata_excerpt_auto'));
    $all_words = theme_get_array_value($args, 'all_words', theme_get_option('theme_metadata_excerpt_words'));
    $min_remainder = theme_get_array_value($args, 'min_remainder', theme_get_option('theme_metadata_excerpt_min_remainder'));
    $allowed_tags = theme_get_array_value($args, 'allowed_tags', theme_get_option('theme_metadata_excerpt_use_tag_filter') ? explode(',', str_replace(' ', '', theme_get_option('theme_metadata_excerpt_allowed_tags'))) : null);
    $perma_link = get_permalink($post->ID);
    $more_token = '%%theme_more%%';
    $show_more_tag = false;
    $tag_disbalance = false;
    if (post_password_required($post)) {
        return get_the_excerpt();
    }
    if ($auto && has_excerpt($post->ID)) {
        $excerpt = get_the_excerpt();
        $show_more_tag = theme_strlen($post->post_content) > 0;
    } else {
        $excerpt = get_the_content($more_token);
        // hack for badly written plugins
        theme_ob_start();
        echo apply_filters('the_content', $excerpt);
        $excerpt = theme_ob_get_clean();
        global $multipage;
        if ($multipage && theme_strpos($excerpt, $more_token) === false) {
            $show_more_tag = true;
        }
        if (theme_is_empty_html($excerpt)) {
            return $excerpt;
        }
        if ($allowed_tags !== null) {
            $allowed_tags = '<' . implode('><', $allowed_tags) . '>';
            $excerpt = strip_tags($excerpt, $allowed_tags);
        }
        if (theme_strpos($excerpt, $more_token) !== false) {
            $excerpt = str_replace($more_token, $more_tag, $excerpt);
        } elseif ($auto && is_numeric($all_words)) {
            $token = "%theme_tag_token%";
            $content_parts = explode($token, str_replace(array('<', '>'), array($token . '<', '>' . $token), $excerpt));
            $content = array();
            $word_count = 0;
            foreach ($content_parts as $part) {
                if (theme_strpos($part, '<') !== false || theme_strpos($part, '>') !== false) {
                    $content[] = array('type' => 'tag', 'content' => $part);
                } else {
                    $all_chunks = preg_split('/([\\s])/u', $part, -1, PREG_SPLIT_DELIM_CAPTURE);
                    foreach ($all_chunks as $chunk) {
                        if ('' != trim($chunk)) {
                            $content[] = array('type' => 'word', 'content' => $chunk);
                            $word_count += 1;
                        } elseif ($chunk != '') {
                            $content[] = array('type' => 'space', 'content' => $chunk);
                        }
                    }
                }
            }
            if ($all_words < $word_count && $all_words + $min_remainder <= $word_count) {
                $show_more_tag = true;
                $tag_disbalance = true;
                $current_count = 0;
                $excerpt = '';
                foreach ($content as $node) {
                    if ($node['type'] == 'word') {
                        $current_count++;
                    }
                    $excerpt .= $node['content'];
                    if ($current_count == $all_words) {
                        break;
                    }
                }
                $excerpt .= '&hellip;';
                // ...
            }
        }
    }
    if ($show_more_tag) {
        $excerpt = $excerpt . ' <a class="more-link" href="' . $perma_link . '">' . $more_tag . '</a>';
    }
    if ($tag_disbalance) {
        $excerpt = force_balance_tags($excerpt);
    }
    return $excerpt;
}