Miniblog-COMPAT - Designed specificaly for Wordpress 2.1 only. Please do not try to enable this version if you have Wordpress 2.0.7 or below.
Allows miniature blogs, links, notes, asides, or whatever to be created. The menu, functionality, and documentation can be found in the Write : Miniblog menu once the plugin is activated. Previous developer Thomas Cort. Version: 0.16-COMPAT Author: Joe Author URI: http://blog.fileville.net/ */ /* Copyright 2006 Joe (ttech5593@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* Edit Only If Needed */ define("DREAMHOST", "FALSE"); /* Please do not edit below this point... */ /* We always want to load these */ if(!function_exists('miniblog_return_entries')) { function miniblog_return_entries($limit = 5, $offset = 0, $identifier = '', $sortby = '_date', $filter = TRUE, $full = 1, $limitperblog= 0) { global $wpdb; if(!is_numeric($offset)) { $offset = 0; } if(!is_numeric($limit) || $limit < 2) { $limit = 4; } if($identifier == 'all') { $identifier = ''; } if(!is_numeric($limitperblog)) { $limitperblog = 0; } $limit_q = $offset . ',' . $limit; $identifier_q = ''; if($identifier) { if(stristr($identifier, '%') !== FALSE) { $identifier_q = 'WHERE blog LIKE \'' . $identifier . '\''; } else { $identifier_q = 'WHERE blog="' . $identifier . '"'; } } /* Sort ordering */ $sort_o = '` ASC'; if (substr($sortby, 0, 1) == '_') { $sort_o = '` DESC'; $sortby = substr($sortby, 1); } $sortby_q = 'ORDER BY `' . $sortby; $sortby_q .= $sort_o; /* We can either show the most recent in each blog or show everything. Group By is just that way. The subquery table pre-sorts the data so that the Group By can pick up rows in the desired order. */ if(!empty($identifier) AND $limitperblog == 0) { // If $identifier is not empty and $limitperblog is 0 $query = 'SELECT * FROM ' . $wpdb->prefix . 'miniblog ' . $identifier_q . ' ' . $sortby_q . ' LIMIT ' . $limit_q; //$query = 'SELECT * FROM `' . $wpdb->prefix . 'miniblog` '.$identifier_q.' LIMIT '.$limit_q.''; } else { // If $identifier is empty and $limitperblog is 0 or a number $query = 'SELECT * FROM '.$wpdb->prefix.'miniblog ' . ( $limitperblog ? ' GROUP BY `blog`' : '' ) . ' ' . $sortby_q . ' LIMIT ' . $limit_q; } $results = $wpdb->get_results($query); if ($results) { $cnt = count($results); for($i = 0; $i < $cnt; $i++) { $results[$i]->blog = stripslashes($results[$i]->blog); $results[$i]->title = apply_filters('the_title', stripslashes($results[$i]->title)); $results[$i]->url = stripslashes($results[$i]->url); if($results[$i]->text) { if (preg_match('/\[readon\]/',$results[$i]->text) && $full == 0) { $parts = preg_split('/\[readon\]/',$results[$i]->text); $results[$i]->text = $parts[0] . '... read on.'; } else if ($full == 1) { $results[$i]->text = preg_replace('/\[readon\]/','',$results[$i]->text); } if ($filter == 'ON') { $results[$i]->text = apply_filters('the_content', stripslashes($results[$i]->text)); } else { $results[$i]->text = stripslashes($results[$i]->text); } } } } else { $results = array(); } return $results; } } /* Simple, beginner-friendly (not to mention smart) version of the above function */ if(!function_exists('miniblog_list_entries')) { function miniblog_list_entries($before = '
  • ', $between = '
    ', $after = '
  • ', $identifier = '', $limit = 5, $offset = 0, $sortby = '_date', $filter = TRUE, $full = 1) { $entries = array(); $entry = ''; $entries = miniblog_return_entries($limit, $offset, $identifier, $sortby, $filter, $full); foreach($entries as $entry) { $date = date("F j, Y", strtotime($entry->date)); echo $before; if ($entry->title && $entry->url) { echo '' . $entry->title . ''; } elseif ($entry->title) { echo $entry->title; } elseif ($entry->url) { echo '' . $date . ''; } else { echo $date; } if(trim($entry->text)) { if (strtolower($between) == strtolower('')) { echo str_replace("

    " , '', str_replace("

    " , '', $entry->text)); } else { echo $between; echo str_replace("\n" , '', $entry->text); } } echo $after . "\n"; } } } function miniblog_get_verison($miniblog_version="0.16-COMPAT") { if(ini_get('allow_url_fopen') == 'On' OR (ini_get('allow_url_fopen') == 1)) { // If this is disabled and is somehow selected stop the error from being shown $version_file = @file("http://blog.fileville.net/miniblog/version.xml"); $version_file = implode('', $version_file); } else { if(function_exists('curl_init')) { $version_check = curl_init(); curl_setopt($version_check, "CURLOPT_URL", $url); curl_setopt($version_check, "CURLOPT_RETURNTRANSFER", TRUE); /* This HAS to be set, if it is not you will be blocked */ curl_setopt($version_check, "CURLOPT_USERAGENT", "Miniblog Version Checker (Miniblog $current)"); $version_file = curl_exec($version_check); curl_close($version_check); } else { $disable = TRUE; echo " Check for Updates "; } } /* Finally get the version and check to see if Miniblog is up to date */ if(!isset($disable) OR $disable !== TRUE) { $pattern = "/\(.*?)\<\/version>/"; preg_match($pattern, $version_file, $pat); $string = trim($pat[1]); $v = version_compare($string, $miniblog_version); if (($v == -1) OR ($v == 0)) { // Compare version echo "Miniblog is up to date. "; } else { echo " Miniblog is out of date! "; } } } /* Get the current miniblog directory */ function miniblog_get_dirname($separator="") { /* If $separator is ever empty, lets try to fill in the separator */ /* if(empty($separator) AND defined(DIRECTORY_SEPARATOR)) { $separator = DIRECTORY_SEPARATOR; }*/ // $separator = "%^(http://www.|http://|www.)((.{1,}))$%"; $plugins = get_settings('active_plugins'); //$file = DIRECTORY_SEPARATOR."miniblog.php
    "; foreach($plugins as $plugin) { if($dir = str_replace("/miniblog.php", "", $plugin)) { break; } } return $dir."/"; //var_dump(in_array("miniblogblog", $plugins)); //echo preg_match($separator, get_settings('siteurl'), $matches)."
    "; // print_r($matches); // echo "
    "; // stristr("http://",get_settings('siteurl'))."
    "; // echo str_replace(get_settings('siteurl'), "", $_SERVER['PHP_SELF'])."
    "; //strrev(dirname(strrev($_SERVER['PHP_SELF']))); //$dirname = explode($separator, dirname($_SERVER['PHP_SELF'])); //print_r($dirname); } /* Creates the RSS feed URL to use in the href="" tag */ if(!function_exists('miniblog_create_rss_url')) { function miniblog_create_rss_url($limit = 5, $offset = 0, $identifier = '', $sortby = '_date', $title = '%site_name%', $description = '%site_description%', $version = 2) { /* Get the blog URL */ $url = get_settings('siteurl'); /* Build new URL */ $url .= '/wp-content/plugins/' . miniblog_get_dirname("/") . basename(__FILE__); $url .= '?action=rss&n=' . $limit . '&o=' . $offset; $url .= '&q=' . htmlentities(urlencode($identifier)) . '&s=' . htmlentities(urlencode($sortby)); $url .= '&t=' . htmlentities(urlencode($title)) . '&d=' . htmlentities(urlencode($description)); $url .= '&v=' . $version; return $url; } } /* Creates the Archive URL to use in the href="" tag */ if(!function_exists('miniblog_create_archive_url')) { function miniblog_create_archive_url($limit = 10, $offset = 0, $identifier = '', $sortby = '_date', $title = '', $before = '
  • ', $between = '
    ', $after = '
  • ', $full = 1) { /* Get the blog URL */ $url = get_settings('siteurl'); /* Build new URL */ $url .= '/wp-content/plugins/' . miniblog_get_dirname("/") . basename(__FILE__); $url .= '?action=archive&limit=' . $limit . '&offset=' . $offset; $url = ($identifier != '') ? $url . '&category=' . htmlentities(urlencode($identifier)) : $url; $url .= "&sortby=" . htmlentities(urlencode($sortby)); $url = ($title != '') ? $url . '&title=' . htmlentities(urlencode($title)) : $url; $url .= '&before=' . htmlentities(urlencode($before)); $url .= '&between=' . htmlentities(urlencode($between)); $url .= '&after=' . htmlentities(urlencode($after)); $url .= '&full=' . $full; return $url; } } /* Creates the Single Post URL to use in the href="" tag */ if(!function_exists('miniblog_create_post_url')) { function miniblog_create_post_url($postid) { /* Get the blog URL */ $url = get_settings('siteurl'); /* Build new URL */ $url .= '/wp-content/plugins/' . basename(__FILE__); $url .= '?action=single_post&postid=' . $postid; return $url; } } /* Cooperation with other popular plugins */ if(!function_exists('miniblog_cooperate')) { function miniblog_cooperate() { /* Staticize Reloaded */ if(function_exists('StaticizeClean')) { StaticizeClean(); } } } /* My general purpose variable sanitizer */ if(!function_exists('miniblog_clean_var')) { function miniblog_clean_var(&$var) { return trim(strip_tags(stripslashes($var))); } } /* This code is called when the plugin is viewed from the admin panel */ if(strpos($_SERVER['PHP_SELF'], 'wp-admin') !== FALSE) { if($_GET['page'] == basename(__FILE__)) { /* This function echos the plugin page contents */ if (!function_exists('miniblog_render_plugin_page')) { function miniblog_render_plugin_page($post_date='',$post_blog='',$post_title='',$post_url='',$post_text='', $post_id='') { global $wpdb; if(!$post_id) { $post_id = '-'; } if(!$post_blog) { $post_blog = 'default'; } /* Number of posts to list per page (editing pagination) */ $per_page = 50; ?>

    style="clear: both;">
    ", "id='content'>$post_text", $editor); ?>

    1) { $page = $_GET['p']; $page_url = '&p=' . $page; $page_first_num = ($page-1)*$per_page; if(!$page_first_num) { $page_first_num = '0'; } $page_query = $page_first_num . ',' . ($page+$per_page); } else { $page = 1; $page_url = '&p=' . $page; $page_query = '0,' . ($page+$per_page); } $posts = $wpdb->get_results('SELECT id,blog,title,url FROM ' . $wpdb->prefix . 'miniblog ORDER BY `date` DESC LIMIT ' . $page_query); if($posts) { $_alt = ' class="alternate"'; foreach($posts as $post) { ?> > 1) { $prev_page = $page - 1; $prev_page_url = '&p=' . $prev_page; $next_page = $page + 1; $next_page_num = (($next_page-1)*$per_page); if(!$next_page_num) { $next_page_num = '0'; } $next_page_query = $next_page_num . ',' . ($next_page+$per_page); } else { $next_page = 2; $next_page_query = $per_page . ',' . ($next_page+$per_page); } /* Find out if there are more entries on the next page */ $are_more = $wpdb->get_results('SELECT id FROM ' . $wpdb->prefix . 'miniblog LIMIT ' . $next_page_query); if(count($are_more)) { if(is_numeric($are_more[0]->id)) { $next_page_url = '&p=' . $next_page; } } ?>

    « Previous Next »

    id); ?> blog)); ?> title)); ?> url)); ?>

    To remove the table from the database, do it manually or enter the string "Remove Thyself" (case sensitive) in the box below and press submit.

    query('CREATE TABLE IF NOT EXISTS `' . $wpdb->prefix . 'miniblog` ( `id` bigint(20) unsigned NOT NULL auto_increment, `date` datetime NOT NULL default \'0000-00-00 00:00:00\', `blog` text NOT NULL, `title` text NOT NULL, `url` text NOT NULL, `text` text NOT NULL, FULLTEXT (`blog`), PRIMARY KEY (`id`)) ENGINE=MYISAM'); /* If the user requested to uninstall */ if($_POST['delstring'] == 'Remove Thyself') { $wpdb->query('DROP TABLE `' . $wpdb->prefix . 'miniblog`'); ?>

    The Miniblog table has been deleted from the MySQL database. To finish uninstalling the plugin, deactivate it from the "Plugins" menu and delete the file from the plugins directory.

    get_results('SELECT * FROM ' . $wpdb->prefix . 'miniblog WHERE id=' . $id . ' LIMIT 1'); if ($entry) { $entry = $entry[0]; if($entry->date) $post_date = stripslashes($entry->date); if($entry->blog) $post_blog = stripslashes($entry->blog); if($entry->title) $post_title = stripslashes($entry->title); if($entry->url) $post_url = stripslashes($entry->url); if($entry->text) $post_text = stripslashes($entry->text); if($entry->id) $post_id = stripslashes($entry->id); miniblog_render_plugin_page($post_date,$post_blog,$post_title,$post_url,$post_text,$post_id); } else { ?>

    Post not found.

    query('UPDATE ' . $wpdb->prefix . 'miniblog SET date="' . mysql_escape_string($_POST['date']) .'", blog="' . mysql_escape_string($_POST['blog']) .'", title="' . mysql_escape_string($_POST['title']) .'", url="' . mysql_escape_string($_POST['url']) .'", text="' . mysql_escape_string($_POST['content']) . '" WHERE id=' . $_POST['id'])) { ?>

    Unable to update entry.

    Entry successfully updated

    query('INSERT INTO ' . $wpdb->prefix . 'miniblog SET date="'. $timedate .'", blog="' . mysql_escape_string($_POST['blog']) .'", title="' . mysql_escape_string($_POST['title']) .'", url="' . mysql_escape_string($_POST['url']) .'", text="' . mysql_escape_string($_POST['content']) . '"')) { ?>

    Unable to add entry.

    Entry successfully added.

    query('DELETE FROM ' . $wpdb->prefix . 'miniblog WHERE id=' . $_GET['id'])) { ?>

    Unable to delete entry.

    Entry successfully deleted.

    $v) { $_GET[$k] = stripslashes($v); } foreach($_POST as $k => $v) { $_POST[$k] = stripslashes($v); } } $wordpress_dir = dirname(dirname(dirname(dirname(__FILE__)))); if(DREAMHOST == 'FALSE') { /* Call up the WordPress configuration stuff */ if (!file_exists($wordpress_dir . '/wp-config.php')) { die('Can\'t load wp-config.php (located in "' . $wordpress_dir . '"). You must put this plugin in your plugins directory ("/wordpress/wp-content/plugins/").'); } } require_once($wordpress_dir . '/wp-config.php'); /* RSS display */ if($_GET['action'] == 'rss') { /* Get the blog name and description (stupid stupid WordPress making me do this) */ $blog_name = get_settings('blogname'); $blog_description = get_settings('blogdescription'); /* Return to sanity */ $number = $_GET['n']; $offset = $_GET['o']; $blog_term = htmlspecialchars(urldecode($_GET['q'])); $sort_by = htmlspecialchars(urldecode($_GET['s'])); $title = htmlspecialchars(urldecode($_GET['t'])); $description = htmlspecialchars(urldecode($_GET['d'])); /* Parse custom tags */ $title = str_replace('%site_name%', $blog_name, $title); $description = str_replace('%site_name%', $blog_name, $description); $title = str_replace('%site_description%', $blog_description, $title); $description = str_replace('%site_description%', $blog_description, $description); /* Clean the variables */ $varstoclean = array(&$number, &$offset, &$blog_term, &$sort_by, &$title, &$description); foreach($varstoclean as $varname) { $varname = miniblog_clean_var($varname); } /* Render the RSS */ header('Content-type: text/xml; charset=' . get_settings('blog_charset'), true); echo "\n"; /* Modifications by Glenn Slaven 2005-06-20; added RSS 2.0 and fixed a duplicate entry bug */ switch ($_GET['v']) { case '0.92': echo "\n"; echo "\t\n"; echo "\t\t" . miniblog_clean_var($title) . "\n"; echo "\t\t"; bloginfo('url'); echo "\n"; echo "\t\t" . miniblog_clean_var($descriptions) . "\n"; echo "\t\thttp://backend.userland.com/rss092\n"; $entries = miniblog_return_entries($number, $offset, $blog_term, $sort_by, FALSE); foreach($entries as $entry) { echo "\t\t\n"; echo "\t\t\t" . miniblog_clean_var($entry->title) . "\n"; echo "\t\t\t" . miniblog_clean_var($entry->text) . "\n"; if (miniblog_clean_var($entry->url)) { echo "\t\t\turl) . "]]>\n"; } echo "\t\t\n"; } break; default /* RSS 2.0 */: echo "\n"; echo "\t\n"; echo "\t\t" . miniblog_clean_var($title) . "\n"; echo "\t\t"; bloginfo('url'); echo "\n"; echo "\t\t" . miniblog_clean_var($descriptions) . "\n"; echo "\t\thttp://blogs.law.harvard.edu/tech/rss\n"; $entries = miniblog_return_entries($number, $offset, $blog_term, $sort_by, FALSE); foreach($entries as $entry) { echo "\t\t\n"; echo "\t\t\t" . miniblog_clean_var($entry->title) . "\n"; echo "\t\t\t" . miniblog_clean_var($entry->text) . "\n"; echo "\t\t\t".mysql2date('D, d M Y H:i:s O', $entry->date, false)."\n"; if (miniblog_clean_var($entry->url)) { echo "\t\t\turl) . "]]>\n"; } echo "\t\t\n"; } } echo "\t\n"; print ""; } else if ($_REQUEST['action'] == "single_post") { global $wpdb; require_once( ABSPATH . 'wp-blog-header.php'); get_header(); echo '
    '; $postid = (isset($_REQUEST['postid']) && is_numeric($_REQUEST['postid'])) ? $_REQUEST['postid'] : -1; if ($postid < 0) { echo '

    Invalid Post

    '; } else { $sql = 'SELECT * FROM `' . $wpdb->prefix . 'miniblog` '; $sql .= "WHERE id = '$postid'"; $results = $wpdb->get_results($sql); if ($results) { $entry = $results[0]; $date = date("F j, Y", strtotime($entry->date)); echo '

    '; if ($entry->title && $entry->url) { echo '' . stripslashes($entry->title) . ''; } elseif ($entry->title) { echo stripslashes($entry->title); } elseif ($entry->url) { echo '' . $date . ''; } else { echo $date; } echo '

    '; $entry->text = preg_replace('/\[readon\]/','',$entry->text); if(trim($entry->text)) { $text = str_replace("\n" , '', $entry->text); echo stripslashes($text); } echo '

    '; } else { echo '

    Invalid Post

    '; } } echo '
    '; get_footer(); } else if ($_REQUEST['action'] == "archive") { global $wpdb; $sortby = isset($_REQUEST['sortby']) ? $_REQUEST['sortby'] : '_date'; $limit = (isset($_REQUEST['limit' ]) && is_numeric($_REQUEST['limit' ])) ? $_REQUEST['limit' ] : 10; $offset = (isset($_REQUEST['offset']) && is_numeric($_REQUEST['offset'])) ? $_REQUEST['offset'] : 0; $before = isset($_REQUEST['before']) ? $_REQUEST['before'] : '

    '; $between= isset($_REQUEST['between']) ? $_REQUEST['between'] : '

    '; $after = isset($_REQUEST['after']) ? $_REQUEST['after'] : '

    '; $full = isset($_REQUEST['full']) && is_numeric($_REQUEST['full']) ? $_REQUEST['full'] : 1; require_once( ABSPATH . 'wp-blog-header.php'); echo "NOTE:
    ".var_dump($_SESSION)."


    "; get_header(); echo "NOTE:
    ".var_dump($_SESSION)."


    "; echo '
    '; if (isset($_REQUEST['title'])) { echo '

    ' . $_REQUEST['title'] . '

    '; } else { echo '

    Miniblog Archive

    '; } /* display only a specific category */ if (isset($_REQUEST['category'])) { miniblog_list_entries($before, $between, $after, $_REQUEST['category'], $limit, $offset, $sortby, FALSE, $full); } else { /* Display All categories */ echo 'Categories:'; $results = $wpdb->get_results('SELECT DISTINCT blog FROM `' . $wpdb->prefix . 'miniblog`'); if ($results) { $cnt = count($results); for ($i = 0; $i < $cnt; $i++) { echo ' ' . $results[$i]->blog . ' '; } } miniblog_list_entries($before, $between, $after, '', $limit, $offset, $sortby, FALSE, $full); } /* next/prev links */ $sql = 'SELECT * FROM `' . $wpdb->prefix . 'miniblog`'; if (isset($_REQUEST['category'])) { $sql = $sql . " WHERE blog like '" . $_REQUEST['category'] . "'"; } echo '
    '; $results = $wpdb->get_results($sql); if ($results) { $cnt = count($results); } if ($results && $offset > 0) { if (isset($_REQUEST['category'])) { echo 'Previous Page'; } else { echo 'Previous Page'; } } echo '  '; if ($results && $cnt > ($offset+$limit)) { if (isset($_REQUEST['category'])) { echo 'Next Page'; } else { echo 'Next Page'; } } echo "NOTE:
    ".var_dump($_SESSION)."


    "; echo '
    '; echo 'Powered by Miniblog'; echo '
    '; get_footer(); } } } /* Add the menu item */ if(!function_exists('miniblog_menu')) { function miniblog_menu () { add_submenu_page('post.php', 'Miniblog', 'Miniblog', 9, basename(__FILE__), 'miniblog'); } } /* Add what we need to the Wordpress admin area header */ if(!function_exists('miniblog_header')) { function miniblog_header($switch=0) { if(stristr($_SERVER['REQUEST_URI'], "miniblog")) { if(user_can_richedit()) { $site_url = get_settings('siteurl'); /* If your having problem just comment the line below out */ $site_url = $site_url; $opt = ($switch == 1) ? "?ver=20061113" : ""; echo "\n"; } echo "\n"; } } } if(function_exists('add_action')) { add_action('admin_menu', 'miniblog_menu'); add_action('admin_head', 'miniblog_header'); } ?>