' . __('Options saved.', 'MiniPosts') . '

'; } else { echo '

'; echo __('Options partially saved. Error in the data submitted: ', 'MiniPosts'); foreach ($errors as $e) { echo '

  • '; echo $e; echo "
  • \n"; } echo '

    '; } } elseif (isset($_POST["update_miniposts"])) { $is_mini_post = $_POST["is_mini_post"]; foreach ($posts as $post) { delete_post_meta($post->ID, '_mini_post'); $setting = in_array($post->ID, $is_mini_post) ? 1 : 0; add_post_meta($post->ID, '_mini_post', $setting); } header("Location: options-general.php?page=" . basename(__FILE__) . "&miniposts_updated=true$paged_val"); exit(); } $ck_filter_mini_posts_from_loop = get_settings('filter_mini_posts_from_loop') == 1 ? 'checked="checked" ' : ''; $ck_suppress_autop_on_mini_posts = get_settings('suppress_autop_on_mini_posts') == 1 ? 'checked="checked" ' : ''; $ck_filter_mini_posts_from_feeds = get_settings('filter_mini_posts_from_feeds') == 1 ? 'checked="checked" ' : ''; ?>



    ">
    The name to display at the top of the miniposts widget.

    %date% - The date the minipost was posted.
    %title% - The title of the minipost
    %post% - The text of the post
    %commentcount% - The number of comments for the post
    %permalink% - The permalink to the post
    %more% - Text to be displayed if the post has more content than shown.
    ">
    The format of the text to be shown in place of the %more% keyword listed above. This keyword is shown if you use the Optional Excerpt or <!--more--> in your post. You may use any other keyword in this text.
    ">
    The format of the date to display. To set your own, see the list of standard PHP date() arguments.

    g:i:s a'); ?> post_status) _e(' - Private'); ?> /> $authordata->user_level) or ($user_login == $authordata->user_login)) { echo "" . __('Edit') . ""; } ?> $authordata->user_level) or ($user_login == $authordata->user_login)) { echo "" . __('Delete') . ""; } ?>
    %title%
    %post% %more% (%commentcount%)

    ', 'Format to use when displaying options.'); add_option('miniposts_date_format', 'Y/n/j', 'Date format.'); add_option('miniposts_more_text', 'More...', 'Text to display in place of "%more" when displaying multipart asides.'); add_option('miniposts_title', 'Miniposts 0.6.4', 'The title to display at the top of the minipost widget.'); add_option('miniposts_maximum', '0', 'The maximum number of miniposts to display. 0 is infinite.'); // Auto-install: If there are no previous meta values for '_mini_post', automatically add one for each post if (0 == $wpdb->get_var("SELECT count(meta_value) FROM $wpdb->postmeta WHERE meta_key = '_mini_post'")) { if ($posts = $wpdb->get_results("SELECT * FROM $wpdb->posts")) { foreach ($posts as $post) { add_post_meta($post->ID, '_mini_post', '0'); } } } /** Get the number of comments associted with the named post. Originally * written by Mountain Dew Virus: * http://dev.wp-plugins.org/file/comment-count/trunk/comment-count.php * * Heavily modified from the original. */ function miniposts_get_comment_count($post) { global $wpdb; $request = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID='" . $wpdb->escape($post) . "' AND " . " comment_approved='1'"; return $wpdb->get_var($request); } function is_mini_post() { global $post; return (bool) get_post_meta($post->ID, '_mini_post', true); } /** * Return the text to display for a minipost. The preferred order is: *
      *
    1. post_excerpt - If the post has an excerpt, this is returned. *
    2. post_content, before first <!--more--> - The text of the * post before the first more tag appears. *
    3. post_content- The text of the post. *
    * * @param $minipost An object containing the fields 'post_content' (the * text of the post) and 'post_excerpt' (the excerpt of * the post). * * @returns An array with the text of the post, and a boolean indicating * if there is more to the post. */ function miniposts_get_text(&$minipost) { // See if we have a post excerpt if (!is_null($minipost->post_excerpt) && strlen($minipost->post_excerpt) > 0 && strlen(trim($minipost->post_excerpt)) > 0 ) { return array($minipost->post_excerpt,true); } // See if we have a tag if (preg_match('/(.*)/s', $minipost->post_content, $matches)) { return array($matches[1], true); } return array($minipost->post_content, false); } function get_mini_posts( $format = null, $limit = null ) { global $wpdb; if (is_null($limit)) { $limit = get_option('miniposts_maximum'); } if (0 != (int)$limit ) { $limit = (int) $limit; $limit = ' LIMIT '.$limit; } else { $limit = ''; } $now = current_time('mysql'); if ($miniposts = $wpdb->get_results("SELECT ID, post_date, UNIX_TIMESTAMP(post_date) AS post_date_unix, post_content, post_excerpt, post_title FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE post_date < '$now' AND post_status = 'publish' AND $wpdb->postmeta.meta_key = '_mini_post' AND $wpdb->postmeta.meta_value = '1' ORDER BY post_date DESC" . $limit)) { if (is_null($format)) { $format = get_option("miniposts_format"); } $dateFormat = get_option("miniposts_date_format"); $moreText = get_option("miniposts_more_text"); echo '
    '; foreach ($miniposts as $minipost) { if ($minipost->post_date != '0000-00-00 00:00:00') { $url = get_permalink($minipost->ID); $commenturl = "$url#comments"; $title = $minipost->post_title; $count = miniposts_get_comment_count($minipost->ID); $commentcount = "$count"; if ($title) { $title = strip_tags($title); } else { $title = $minipost->ID; } list($text, $hasMore) = miniposts_get_text($minipost); $moreString = ''; if ($hasMore) { $moreString = $moreText; } $text = wptexturize($text); $meta = str_replace('%more%', $moreString, $format); $meta = str_replace('%permalink%', get_permalink($minipost->ID), $meta); $meta = str_replace('%title%', $title, $meta); $meta = str_replace('%date%', date($dateFormat, $minipost->post_date_unix), $meta); $meta = str_replace('%commentcount%', $commentcount, $meta); $text = str_replace('%post%', $text, $meta); echo "\t$text\n"; } } echo '
    '; /* class="miniposts" */ } } function mini_posts_join($text) { global $wpdb, $pagenow; if (!is_plugin_page() && $pagenow != 'post.php' && $pagenow != 'edit.php' && get_settings('filter_mini_posts_from_loop') && !is_single() && !is_archive() && !is_page() && (is_feed() && get_settings('filter_mini_posts_from_feeds') || !is_feed()) && !stristr($text, "wp_postmeta")) { $text .= " LEFT JOIN $wpdb->postmeta AS miniposts_meta ON ($wpdb->posts.ID = miniposts_meta.post_id)"; } return $text; } function mini_posts_where($text) { global $user_ID, $user_level, $wpdb, $pagenow; if (!is_plugin_page() && $pagenow != 'post.php' && $pagenow != 'edit.php' && (!is_search() && get_settings('filter_mini_posts_from_loop')) && !is_single() && !is_archive() && !is_page() && (is_feed() && get_settings('filter_mini_posts_from_feeds') || !is_feed())) { $text .= " AND (miniposts_meta.meta_key = '_mini_post' AND miniposts_meta.meta_value = 0)"; } return $text; } if (get_settings('suppress_autop_on_mini_posts')) { function mini_post_autop($pee, $br = 1) { if (!is_mini_post() || is_single()) { $pee = $pee . "\n"; // just to make things a little easier, pad the end $pee = preg_replace('|
    \s*
    |', "\n\n", $pee); // Space things out a little $pee = preg_replace('!(<(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|math|p|h[1-6])[^>]*>)!', "\n$1", $pee); $pee = preg_replace('!()!', "$1\n", $pee); $pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines $pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates $pee = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "\t

    $1

    \n", $pee); // make paragraphs, including one at the end $pee = preg_replace('|

    \s*?

    |', '', $pee); // under certain strange conditions it could create a P of entirely whitespace $pee = preg_replace('!

    \s*(]*>)\s*

    !', "$1", $pee); // don't pee all over a tag $pee = preg_replace("|

    (|", "$1", $pee); // problem with nested lists $pee = preg_replace('|

    ]*)>|i', "

    ", $pee); $pee = str_replace('

    ', '

    ', $pee); $pee = preg_replace('!

    \s*(]*>)!', "$1", $pee); $pee = preg_replace('!(]*>)\s*

    !', "$1", $pee); if ($br) $pee = preg_replace('|(?)\s*\n|', "
    \n", $pee); // optionally make line breaks $pee = preg_replace('!(]*>)\s*
    !', "$1", $pee); $pee = preg_replace('!
    (\s*)!', '$1', $pee); $pee = preg_replace('!()(.*?)!ise', " stripslashes('$1') . clean_pre('$2') . '' ", $pee); } return $pee; } } add_filter('posts_where', 'mini_posts_where'); add_filter('posts_join', 'mini_posts_join'); if (get_settings('suppress_autop_on_mini_posts')) { remove_filter('the_content', 'wpautop'); add_filter('the_content', 'mini_post_autop'); } function plugin_minipost2_sidebar() { $is_mini = get_post_meta($_REQUEST['post'], '_mini_post', true); $check = $is_mini ? 'checked="checked" ' : ''; ?>

    MiniPost

    '. __('This is a mini post', 'MiniPosts') . '
    '; } function plugin_minipost2_update_post($id) { if ( current_user_can('edit_post', $post_id) && isset($_POST["miniposts_nonce"]) && $_POST['miniposts_nonce'] == miniposts_nonce() ) { $setting = (isset($_POST["is_mini_post"]) && $_POST["is_mini_post"] == "1") ? 1 : 0; delete_post_meta($id, '_mini_post'); add_post_meta($id, '_mini_post', $setting); } return $post_id; } function plugin_minipost2_admin_menu() { add_options_page(__('Mini Post Manager', 'MiniPosts'), __('MiniPosts', 'MiniPosts'), 5, basename(__FILE__)); } add_action('save_post', 'plugin_minipost2_update_post'); add_action('edit_post', 'plugin_minipost2_update_post'); add_action('publish_post', 'plugin_minipost2_update_post'); add_action('admin_menu', 'plugin_minipost2_admin_menu'); remove_action('edit_form_advanced', 'mini_posts_checkbox'); remove_action('simple_edit_form', 'mini_posts_checkbox'); add_action('dbx_post_sidebar', 'plugin_minipost2_sidebar'); function widget_miniposts2_init() { function widget_miniposts2_display($args) { extract($args); ?>