Forum Replies Created

Viewing 14 replies - 1 through 14 (of 14 total)
  • Thread Starter Pneumonic

    (@pneumonic)

    @mohib – Not sure which archive.php you’re looking for.

    @markushamburger – It’s a known issue. Currently that panel doesn’t work, but we’re working on a fix for it.

    @tsiwt – Can you provide an example page so I can see what you’re talking about?

    Thread Starter Pneumonic

    (@pneumonic)

    The current version posted here does somewhat work with 3.1. What doesn’t work is the linking to pages right now. You have to input it manually. We are currently looking into rewriting it entirely to utilize some of the new functionality provided by the newer versions of wp so keep watching for an update. Both of us have full-time gigs as well an we do this to support the community so please be patient with us. 🙂 Glad you’re interested in the plugin and the next version is going to be awesome.

    Thread Starter Pneumonic

    (@pneumonic)

    Glad you like the updates. I actually tried contacting you through your website at one point, but couldn’t get an email or anything to pop-up. I’ve sent you an email as well. 🙂

    Pneumonic

    (@pneumonic)

    Damn wordpress not notifying me of replies again…

    Anyhow. Yeah that’s spot on how I’d go about doing it though (without actually looking at my hacked-ass code :). Glad I was able to help.

    Thread Starter Pneumonic

    (@pneumonic)

    Update:

    * added an option to control the thumbnail size
    * when using full posts, the content now shows up with proper html formatting
    * fixed bug with thumbnail showing up in posts and excerpts no matter what was selected if there was a featured image

    Still need to add pagination, but I think it’s going to take more time consuming than I’m probably willing to invest. Sooooo, if someone has an idea of how it can be achieved, let me know and I’d be happy to work on it with you. Here’s the newest version:

    <?php
    /*
    Plugin Name: Category Page
    Plugin URI: http://pixline.net/wordpress-plugins/category-page-wordpress-plugin/en/
    Description: Use pages as category archive header, or list some posts from a category into a post/page. Heavily modified by John P. Neumann at http://AnimateShmanimate.com
    Author: Pixline, John P. Neumann
    Version: 2.6.3
    Author URI: http://pixline.net/
    
    Copyright (C) 2008 Paolo Tresso / Pixline (http://pixline.net/)
    Revisions (C) 2011 The Entire World - But John P. Neumann made the changes (http://animateshmanimate.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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    
    -----------------------------------------
    Revisions for excerpts, full posts and thumbnails done by John P. Neumann (john@animateshmanimate.com)
    
    - As a note: I appreciate the feedback and questions, but please remember that I'm broke, unemployed, have a wife, 2 kids and a dog and I do this to help support the community.
    
    /*
    	TODO Add pagination
    
    */
    /* 
    
    CHANGELOG
    
    2.6.3
    
    * added an option to control the thumbnail size
    * when using full posts, the content now shows up with proper html formatting
    * fixed bug with thumbnail showing up in posts and excerpts no matter what was selected if there was a featured image
    
    2.6.2
    
    * removed things that were unnecessary or broken
    * added pagination
    * added option to control image size
    * added option to not strip html tags
    
    2.6.1
    
    * added option to control excerpt length
    * added an option to include post-thumbnails
    * added an option to choose a class for the header h2 that's output
    * added an option to choose a class for the images for the posts thumbnails
    * changed version number to 2.6.1
    
    2.6
    
    * added 2 rows to the database named p2c_post_settings and p2c_excerpt_settings
    * added options to admin page for posts and excerpts
    * added code for both posts and settings to be available (although not at the same time)
    * added additional code for settings to be available
    * added the functionality
    * added code to disable both excerpts and posts if they are both checked since that would be stupid
    
    */
    if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) { die('You are not allowed to call this page directly.'); }
    
    /*
    	TODO If I'm going to manage this, then I need to update all this crap, but I don't really want to manage it.
    */
    define("PAGE2CAT_VERSION","2.6.3");
    define("PLUGIN_PATH",get_bloginfo('url')."/wp-content/plugins/page2cat/");
    
    define('PIXLINE_FOOTER','<p><hr style="margin-top:50px;height:1px;background:#CCC;border:0px;clear:both;" />
    <strong>
    <a href="http://pixline.net/wordpress-plugins/category-page-wordpress-plugin/en/">Category Page</a></strong> plugin
     | <strong><a href="http://animateshmanimate.com">John P. Neumann</a></strong>
    <strike><small> |
    <a href="http://talks.pixline.net/forum.php?id=3">Support Forum</a></strike> |
    GPL2&copy; &ge; 2007 <a href="http://pixline.net/about/en/">Paolo Tresso / Pixline</a> |
    <strike>If you like this plugin, support its development with a <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=paolo%40pixline%2enet&item_name=Support%20to%20opensource%20projects%20at%20Pixline&no_shipping=1&cn=Something%20to%20say%3f&tax=0&currency_code=EUR&lc=IT&bn=PP%2dDonationsBF&charset=UTF%2d8">small donation</a>.</strike>
    |<small>The support forums are nill and as such you shouldn\'t donate to something that isn\'t giving back and is broken.</small>
    </p>');
    /*
    END REMOVE
    */
    $wpdb->page2cat	= $table_prefix . 'page2cat';
    
    ######################################################
    # check version. #
    ######################################################
    
    $p2c_version = get_option('pixline_page2cat_version');
    	register_activation_hook(__FILE__, 'page2cat_install');
    
    // DB installation. usually happen just one time.
    function page2cat_install(){
    global $wpdb, $p2c_version;
    
    if ($version < 6):
    	$query = "
    	CREATE TABLE  <code>&quot;.$wpdb->prefix.&quot;page2cat</code> (
    	 <code>rel_ID</code> BIGINT NOT NULL AUTO_INCREMENT ,
    	 <code>page_ID</code> BIGINT NOT NULL ,
    	 <code>cat_ID</code> BIGINT NOT NULL ,
    	PRIMARY KEY (  <code>rel_ID</code> ) ,
    	INDEX (  <code>page_ID</code> ,  <code>cat_ID</code> )
    	);
    	";
    
    	if(is_file(ABSPATH . 'wp-admin/includes/upgrade.php')){
    		require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    	}elseif(is_file(ABSPATH . 'wp-admin/upgrade-functions.php')){
    		require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
    	}
    	/* TODO what the fuck is this - a forced update for the version number?*/
    	if($wpdb->get_var("SHOW TABLES LIKE '".$wpdb->prefix."page2cat'") != $wpdb->prefix."page2cat") {
    	dbDelta($query);
    	delete_option('pixline_page2cat_version');
    	add_option('pixline_page2cat_version', 6);
    	}
    
    update_option('p2c_use_empty','false');
    update_option('p2c_show_used_pages','false');
    update_option('p2c_catlist_limit',5);
    update_option('p2c_catlist_title','');
    update_option('p2c_excerpt_settings','');
    update_option('p2c_post_settings','');
    // new revisions
    update_option('p2c_excerpt_length', 500);
    update_option('p2c_use_thumbnail', 'false');
    update_option('p2c_img_class', 'alignleft');
    update_option('p2c_title_class', 'clearBoth');
    update_option('p2c_thumbnail_size', 'thumbnail');
    
    endif;
    
    delete_option('p2c_use_img');		// deprecated, so we're going to delete it anyway.
    if( !get_option('p2c_use_empty')) 		update_option('p2c_use_empty','false');
    if(!get_option('p2c_show_used_pages')) 	update_option('p2c_show_used_pages','false');
    if(!get_option('p2c_catlist_limit')) 	update_option('p2c_catlist_limit',5);
    if(!get_option('p2c_catlist_title')) 	update_option('p2c_catlist_title','');
    }
    if(!get_option('p2c_excerpt_settings')) update_option('p2c_excerpt_settings','');
    if(!get_option('p2c_post_settings')) update_option('p2c_post_settings','');
    // new revisions
    if(!get_option('p2c_excerpt_length')) update_option('p2c_excerpt_length',500);
    if(!get_option('p2c_use_thumbnail')) update_option('p2c_use_thumbnail','false');
    if(!get_option('p2c_img_class')) update_option('p2c_img_class','alignleft');
    if(!get_option('p2c_title_class')) update_option('p2c_title_class','clearBoth');
    if(!get_option('p2c_thumbnail_size')) update_option('p2c_thumbnail_size','thumbnail');
    
    ######################################
    # setup management and option panels #
    ######################################
    /*
    	TODO most of this shit is pointless especially the connections shit.
    */
    // adds a panel under "manage » category pages"
    // shows actual connections, and allow creations of new ones.
    function page2cat_manage_page(){
    global $wpdb, $wp_db_version;
    
    	#print_r($_POST); #die();
    
    	// multiple delete
    	if( isset($_POST['deleteit']) && !empty($_POST['p2c_reldel'])):
    		foreach($_POST['p2c_reldel'] as $key=>$id):
    			$query = "DELETE FROM {$wpdb->page2cat} WHERE rel_ID = '".$id."' LIMIT 1;";
    			$daje = $wpdb->get_results($query);
    		endforeach;
    	echo '<div id="message" class="updated fade">
    			<p><strong>Some connections deleted.</strong></p></div>';
    	endif;
    
    	// multiple link
    	if( isset($_POST['action']) && $_POST['p2c_linkto'] == true && $_POST['multipageid'] != ""):
    #	print_r($_POST);
    		$pageid = $_POST['multipageid'][0];
    		foreach($_POST['p2c_reladd'] as $key=>$id):
    		if(trim($id)!=""):
    			$query = "INSERT INTO {$wpdb->page2cat} (rel_ID, page_ID, cat_ID) VALUES ('', '".$pageid."', '".$id."');";
    			$daje = $wpdb->get_results($query);
    		endif;
    		endforeach;
    		echo '<div id="message" class="updated fade">
    			<p><strong>Connections created.</strong></p></div>';
    
    	elseif( isset($_POST['action']) && $_POST['p2c_update'] == true):
    #	print_r($_POST); die();
    		$pageid = $_POST['pageid'];
    		foreach($pageid as $cat_id=>$page_id):
    			if(trim($page_id) != ""):
    			$sql = "INSERT INTO {$wpdb->page2cat} (rel_ID, page_ID, cat_ID) VALUES ('', '".$page_id."', '".$cat_id."');";
    			$result = $wpdb->get_results($sql);
    			endif;
    		endforeach;
    		echo('<div id="message" class="updated fade">
    		<p><strong>New Category Page created succesfully.</strong></p></div>');
    	endif;
    
    	// single delete, confirm request
    	if( isset($_REQUEST['p2cdel']) && !isset($_REQUEST['p2c_confirm']) ):
    		$relid = $wpdb->escape($_REQUEST['p2cdel']);
    		echo "<div class='wrap'><h2>Delete this Category &rsaquo; Page relation?</h2>";
    		$opt = $wpdb->get_results("SELECT * FROM {$wpdb->page2cat} WHERE rel_ID = '".$relid."' LIMIT 1;");
    		$catid = $opt[0]->cat_ID;
    		$pageid = $opt[0]->page_ID;
    		$catname = get_cat_name($catid);
    		$page = get_page($pageid);
    		$title = $page->post_title;
    		echo "<form name='p2c_confirm' method='post'>";
    		echo "<p>You are going to delete the relationship between
    		Category <em>".$catname."</em> and Page <em>".$title."</em>. Confirm?</p>";
    		echo '<p>
    		<input type="hidden" name="p2cdel" value="'.$relid.'" />
    		<input type="hidden" name="p2c_confirm" value="true" />
    		<input type="reset" name="revert" value="Cancel" />
    		<input type="submit" name="confirm" value="DELETE &raquo;" />
    		</p></form>';
    		echo "</div>";
    	endif;
    
    	// confirmed, so delete this connection
    	if( isset($_REQUEST['p2cdel']) && $_REQUEST['p2c_confirm'] == 'true'):
    	$relid = $wpdb->escape($_REQUEST['p2cdel']);
    	$myopts = $wpdb->get_results("DELETE FROM {$wpdb->page2cat} WHERE rel_ID = '".$relid."' LIMIT 1;");
    	echo('<div id="message" class="updated fade"><p><strong>You have succesfully deleted a connection.</strong></p></div>');
    	echo "<div class='wrap'><a href='edit.php?page=category-pages'>Back to Category Pages manage page</a></div>";
    	endif;
    
    	/*
    		real pages
    	*/
    	$count_used = $wpdb->get_var("SELECT count(*) FROM {$wpdb->page2cat};");
    
    	if($wp_db_version >= 6124):	// this is WordPress >= 2.3
    	$count_full = $wpdb->get_var("SELECT count(*)
    		FROM {$wpdb->terms} AS t LEFT JOIN {$wpdb->term_taxonomy} AS tt
    		ON t.term_id = tt.term_id WHERE tt.taxonomy='category';");
    
    	$count_noempty = $wpdb->get_var("SELECT count(*)
    		FROM {$wpdb->terms} AS t LEFT JOIN {$wpdb->term_taxonomy} AS tt
    		ON t.term_id = tt.term_id WHERE tt.taxonomy='category' AND tt.count != '0';");
    	else: // WP < 2.3
    	$count_full = $wpdb->get_var("SELECT count(*) FROM {$wpdb->categories};");
    	$count_noempty = $wpdb->get_var("SELECT count(*) FROM {$wpdb->categories}; WHERE category_count != '0';");
    	endif;
    
    	$count_free = $count_full - $count_used;
    	if(get_option('p2c_use_empty') == "false"): $count_usable = $count_noempty - $count_used; else : $count_usable = $count_free; endif;
    
    	// this is the already connected page
    
    	$myopts = $wpdb->get_results("SELECT * FROM {$wpdb->page2cat} ORDER BY page_ID ASC;");
    	$usedcats = array();
    	$usedpages = array();
    
    		if($_REQUEST['view'] == 'new'):
    			$css1 = ''; 	$css2 = ' class="current"';
    			$pagetitle = "<small>New connection</small>";
    		else:
    			$css1 = ' class="current"'; $css2 = '';
    			$pagetitle = "<small>Manage connections</small>";
    		endif;
    
    	if( !isset($_REQUEST['p2cdel'])):
    		echo "<div class='wrap'><h2>Category Pages</h2>";
    		echo '<ul class="subsubsub">
    		<li><a href="edit.php?page=category-pages"'.$css1.'>Manage connections ('.$count_used.')</a> |</li>
    		<li><a href="edit.php?page=category-pages&view=new"'.$css2.'>Free categories ('.$count_usable.'/'.$count_free.')</a></li>
    		</ul>';
    
    if($_REQUEST['view'] != 'new'):
    
    		if(count($myopts) != 0):
    #		echo "<div><p>These categories and these pages are already connected each other. You can view the category page in your website, clicking on the Category name. You can also edit or delete each connection.</p>";
    
    		echo "<div class='tablenav'>";
    		echo "<div class='tablenav-pages'>&nbsp;</div>";
    		echo '<div style="float: left">
    			<form id="p2c_del" name="p2c_del" method="post"/>
    			<input type="hidden" name="page" value="category-pages" />
    			<input type="hidden" name="view" value="'.$_REQUEST['view'].'" />
    			<input type="hidden" name="action" value="p2c_del" />
    			<input type="submit" value="Delete Checked" name="deleteit" class="button-secondary delete" />
    			</div>';
    		echo "<br style='clear:both;' />";
    		echo "</div>";
    
    		echo "<br style='clear:both;' />";
    		echo '
    			';
    		echo "<table class='widefat'>";
    			echo "<thead>";
    			echo "<tr>
    				<th>";
    			if($wp_db_version >= 7098): echo "<input type='checkbox' onclick='checkAll(document.getElementById(\"p2c_del\"));' />" ;
    				else: echo "&nbsp;"; endif;
    			echo "</th>
    			<th>Host <strong>Category</strong></th>
    			<th>Header <strong>Page</strong></th>
    			<th>&nbsp;</th>
    			</tr>";
    			echo "</thead><tbody>";
    		foreach($myopts as $opt):
    			$catid = $opt->cat_ID;
    			$pageid = $opt->page_ID;
    			$catname = get_cat_name($catid);
    			$usedcats[] = $catid;
    			$usedpages[] = $pageid;
    			$page = get_page($pageid);
    			$title = $page->post_title;
    
    		echo "<tr>
    			<td><input type='checkbox' value='".$opt->rel_ID."' name='p2c_reldel[]' class='p2cbox' /></td>
    			<td><strong><a href='../?cat=".$catid."' title='View this Category Page in your website.'>".$catname."</a></strong>
    				<!-- (cat #".$catid.") --></td>
    			<td><strong><a href='page.php?action=edit&post=".$pageid."' title='Edit this page.'>".$title."
    				<!-- (page #".$pageid.") --></td>
    			<td><a href='?page=category-pages&p2cdel=".$opt->rel_ID."' class='delete' title='Delete this connection permanently.'>Delete</a></td>
    			</tr>";
    		endforeach;
    
    		echo "</tbody>";
    		echo "</table>";
    
    		echo "<div class='tablenav'>";
    		echo "<div class='tablenav-pages'>&nbsp;</div>";
    		echo '<div style="float: left">
    			<form name="p2c_del" method="post"/>
    			<input type="hidden" name="page" value="category-pages" />
    			<input type="hidden" name="view" value="'.$_REQUEST['view'].'" />
    			<input type="hidden" name="action" value="p2c_del" />
    			<input type="submit" value="Delete Checked" name="deleteit" class="button-secondary delete" />
    			</form>
    			</div>';
    		echo "<br style='clear:both;' />";
    		echo "</div>";
    
    		else:
    
    		echo "<p>Sorry, no Category &raquo; Page connection available (yet). Maybe you want to <a href='edit.php?page=category-pages&view=new'>create some new connections</a>?</p>";
    		endif;
    
    else:
    // this is the 'new' page
    
    		$usedcats = $wpdb->get_col("SELECT cat_ID FROM {$wpdb->page2cat};");
    #		print_r($usedcats);
    		$opt3 = get_option('p2c_use_empty');
    		if($opt3 == "true"): $empty = false; $excats = ""; elseif($opt3 == "false"): $empty = true; $excats = implode(',',$usedcats); endif;
    
    		$catdef = array('type' => 'post', 'child_of' => 0, 'orderby' => 'name', 'order' => 'ASC',
    		'hide_empty' => $empty, 'include_last_update_time' => false, 'hierarchical' => true,
    		'exclude' => $excats, 'include' => '', 'number' => '', 'pad_counts' => true);
    		$others = get_categories($catdef);
    
    		$used = count($usedcats);
    		$count = count($others);
    
    		if( $count == 0):
    		echo "<p>Sorry, you don't have any usable category (or there are some, but empty; <a href='options-general.php?page=category-page-options'>check your settings</a>).</p>";
    		else:
    #		echo "<h3>New connections</h3>";
    #		echo "<div><p>These categories aren't connected with any page. Here you can setup a connection with an existent page, or create a brand new one.</p>";
    
    		echo "<form id='page2cat_manage' name='page2cat_manage' method='post'>";
    		$pages_already_used = implode(',',$usedpages);
    		if(get_option('p2c_show_used_pages')=='true') $exclude = $pages_already_used; else $exclude ="";
    
    		// wp_dropdown_pages settings (for both boxes in this page)
    		$pre_ddprefs = array('depth' => 0, 'child_of' => 0, 'selected' => 0,
    			'echo' => 0,'name' => 'multipageid[]', 'exclude' => $exclude,
    			'show_option_none' => '(none)');
    
    /*
    		echo "<div class='tablenav'>";
    		echo "<div class='tablenav-pages'>
    			<input type='submit' name='p2c_update' value='Update Category Pages' class='button'/>
    			<br style='clear:both;' />
    			</div>";
    		echo '<div style="float:left;">
    			<input type="hidden" name="page" value="category-pages" />
    			<input type="hidden" name="view" value="'.$_REQUEST['view'].'" />
    			<input type="hidden" name="action" value="p2c_multilink" />
    			Link checked to:
    			'.wp_dropdown_pages($pre_ddprefs).'
    			<input type="submit" value="Link them!" name="p2c_linkto" class="button-secondary" />
    			</div>';
    		echo "<br style='clear:both;'/>&nbsp;<br style='clear:both;' />";
    		echo "</div>";
    */
    			echo "<table class='widefat'>";
    			echo "<thead>";
    			echo "<tr>
    			<th>";
    			if($wp_db_version >= 7098): echo "<input type='checkbox' onclick='checkAll(document.getElementById(\"page2cat_manage\"));' />";
    				else: echo "&nbsp;"; endif;
    			echo "</th>";
    			echo "<th>Host Category</th>
    			<th>Choose Page</th>
    			<th>Create New Page</th>
    			</tr>";
    			echo "</thead><tbody>";
    
    			foreach($others as $otro):
    			switch($wp_db_version):
    			// "7098"=>"2.5",	"6124"=>"2.3.3", "5183"=>"2.2.1", "4773"=>"2.1.3"
    				case ( $wp_db_version < 5183 ):	// WP 2.1.3 and smaller
    				$versioned_catid = $otro->cat_ID;
    				$versioned_catname = $otro->cat_name;
    				$versioned_slug = $otro->category_nicename;
    				$versioned_count = $otro->category_count + $otro->posts_private;
    				break;
    				case ( $wp_db_version >= 5183 ):	// WP 2.2.1 and greater
    				default:
    				$versioned_catid = $otro->term_id;
    				$versioned_catname = $otro->name;
    				$versioned_slug = $otro->category_nicename;
    				$versioned_count = $otro->count;
    				break;
    			endswitch;
    
    			// wp_dropdown_pages settings
    			$ddprefs = array('depth' => 0, 'child_of' => 0, 'selected' => 0,
    				'echo' => 0,'name' => 'pageid['.$versioned_catid.']',
    				'exclude' => $exclude, 'show_option_none' => '(none)');
    
    			$output = "<tr>
    			<td><input type='checkbox' value='".$versioned_catid."' name='p2c_reladd[]' /></td>
    			<td>".$versioned_catname." <!-- (".$versioned_count.") --></td>
    			<td>".wp_dropdown_pages($ddprefs)."</td>";
    			$output .= "<td><a href='page-new.php?p2c=".$versioned_catid."'>Create New</a></td>
    			</tr>";
    
    			$stringhe[$versioned_catname] = $output;
    			endforeach;
    
    			asort($stringhe);
    			reset($stringhe);
    
    			foreach($stringhe as $stringa):
    				echo $stringa;
    			endforeach;
    
    			echo "</tbody>";
    			echo "</table>";
    
    			echo "<div class='tablenav'>";
    			echo "<div style='float:right;'>
    				<input type='submit' name='p2c_update' value='Update Category Pages' class='button'/>
    				</div>";
    			echo '<div style="float:left;">
    				<input type="hidden" name="page" value="category-pages" />
    				<input type="hidden" name="view" value="'.$_REQUEST['view'].'" />
    				<input type="hidden" name="action" value="p2c_multilink" />
    				Link checked to:
    				'.wp_dropdown_pages($pre_ddprefs).'
    				<input type="submit" value="Link them!" name="p2c_linkto" class="button-secondary" />
    				</div>';
    			echo "<br style='clear:both;'/>";
    			echo "</div>";
    endif;
    
    		echo "</form>";
    		endif;
    		echo PIXLINE_FOOTER;
    		echo "</div>";
    	endif;
    }
    
    // adds styles in admin head (WP 2.5+)
    function page2cat_metabox_styles(){
    ?>
    <style type="text/css" media="screen">
    #p2c-scroller{
    	width:100%;
    }
    
    ul#p2c-bind li, ul#p2c-free li{
    	list-style-type:none;
    	width:32%;
    	float:left;
    	font-size:80%;
    }
    
    .p2c-cleaner{
    	clear:both;
    	height:1px;
    }
    .p2c-used{
    	color:#D66;
    	text-decoration:line-through;
    }
    .p2c-catlink{
    	color:#000;
    	text-decoration:none;
    	border-bottom:1px dotted #CCC;
    }
    </style>
    <?php
    wp_enqueue_script('admin-forms');
    }
    
    // adds styles in admin head (WP < 2.5)
    function page2cat_sidebox_styles(){
    ?>
    <style type="text/css" media="screen">
    #p2c-scroller{
    	height:120px;
    	overflow:auto;
    	width:90%;
    	margin:0% 5%;
    }
    
    #p2c-box p{
    	margin:0px;
    	padding:5px;
    	font-size:80%;
    }
    
    ul#p2c-bind, ul#p2c-free,
    ul#p2c-bind li, ul#p2c-free li{
    	margin:0px;
    	padding:0px;
    	list-style-type:none;
    }
    
    ul#p2c-bind{
    	font-size:90%;
    	margin:1% 0%;
    }
    
    ul#p2c-free{
    	font-size:80%;
    	color:#333;
    	margin:2%;
    }
    
    ul#p2c-free li{
    	padding:2px 1px;
    }
    
    .p2c-count{
    	color:#AAA;
    }
    
    .p2c-indent{
    	padding-left:10px;
    }
    
    .p2c-used{
    	color:#D66;
    	text-decoration:line-through;
    }
    
    .p2c-catlink{
    	color:#000;
    	text-decoration:none;
    	border-bottom:1px dotted #CCC;
    }
    
    </style>
    <?php
    }
    /*
    	TODO what the fuck is this for? or the meta box? useless shit.
    */
    // adds sidebox in page editing (until WP 2.3x)
    function page2cat_add_sidebox($post_ID){
    ?>
    <fieldset id="p2c-select" class="dbx-box">
    <h3 class="dbx-handle">Category Pages</h3>
    <div class="dbx-content" id="p2c-box">
    	<?php page2cat_add_meta_box($post_ID);	?>
    </div>
    </fieldset>
    <?php
    
    }
    
    function page2cat_add_meta_box($post_ID){
    	global $wpdb, $post_ID, $_REQUEST;
    #	if(isset($_REQUEST['p2c'])):
    #	endif;
    
    	$mypage = $wpdb->get_results("SELECT * FROM {$wpdb->page2cat} WHERE page_ID = '".$post_ID."';",OBJECT);
    	?>
    		<p>Use this page as <a href='edit.php?page=category-pages'>Category Page</a> for these categories.</p>
    	<?php
    	$usedcats = array();
    	if(count($mypage)>0):
    		echo "<ul id='p2c-bind'>";
    		foreach($mypage as $connection):
    	#		print_r($connection);
    			echo "<li><input type='checkbox' checked='checked' value='".$connection->cat_ID."' name='p2c_bind[]'
    			id='p2c".$connection->cat_ID."' /> ".get_cat_name($connection->cat_ID)."</li>
    			";
    			$usedcats[] = $connection->cat_ID;
    		endforeach;
    		echo "</ul>";
    	endif;
    
    		$opt3 = get_option('p2c_use_empty');
    		if($opt3 == "true"): $empty = false; $exclude = "";
    		elseif($opt3 == "false"): $empty = true; $exclude = implode(',',$usedcats);
    		endif;
    
    	$catdef = array('type' => 'post', 'child_of' => 0, 'orderby' => 'name', 'order' => 'ASC', 'exclude' => $exclude,
    					'hide_empty' => $empty, 'include_last_update_time' => false, 'hierarchical' => true, 'pad_counts' => true);
    
    	$others = get_categories($catdef);
    	echo "<div id='p2c-scroller'>";
    	echo "<ul id='p2c-free'>";
    	foreach($others as $cat):
    	#print_r($cat); exit();
    	if($cat->cat_ID == $_REQUEST['p2c']): $flag = "checked='checked'"; else: $flag = ""; endif;
    
    	$has_page = $wpdb->get_var("SELECT count(*) FROM {$wpdb->page2cat} WHERE cat_ID = '".$cat->cat_ID."'");
    	if($has_page == 0):
    	echo "<li><input type='checkbox' name='p2c_bind[]' id='p2c".$cat->cat_ID."' value='".$cat->cat_ID."' ".$flag."/> "
    	."<a class='p2c-catlink' href='../?cat=".$cat->cat_ID."' title='".get_cat_name($cat->cat_ID)." (".$cat->category_count." items inside).'>".get_cat_name($cat->cat_ID)."</a></li>
    	";
    	else:
    #	echo "<li><input type='checkbox' disabled='disabled' name='p2c_bind[]' id='p2c".$cat->cat_ID."' value='".$cat->cat_ID."'/> <span class='p2c-used'>"
    #	.get_cat_name($cat->cat_ID)." </span><span class='p2c-count'>(".$cat->category_count." items)</span></li>
    #	";
    	$nothing = 0;
    	endif;
    	endforeach;
    	echo "</ul>";
    	echo "<br style='clear:both;' />";
    	echo "</div>";
    	?>
    	<?php
    }
    
    // trigger page save/edit and make db relations
    function page2cat_trigger_save($post_ID){
    global $wpdb;
    
    $values = $_POST['p2c_bind'];
    $via = "DELETE FROM {$wpdb->page2cat} WHERE page_ID = '".$_POST['post_ID']."'";
    $result = $wpdb->get_results($via);
    if(count($values) > 0):
    foreach($values as $key=>$cat){
    	if($_POST['post_ID'] != ""):
    	$sql = "INSERT INTO {$wpdb->page2cat} (rel_ID, page_ID, cat_ID) VALUES ('','".$_POST['post_ID']."','".$cat."')";
    	$result = $wpdb->get_results($sql);
    	endif;
    }
    endif;
    }
    
    // trigger page deletion and free db relations
    function page2cat_trigger_delete(){
    	// yes, there's no trigger, actually....
    }
    
    // add the function for neat_trim
    function neat_trim($str, $n, $delim='...') {
    $str = str_replace("\n","",$str);
    $str = strip_tags($str);
      $len = strlen($str);
       if ($len > $n) {
           preg_match('/(.{' . $n . '}.*?)\b/', $str, $matches);
           return rtrim($matches[1]) . $delim;
       }
       else {
           return $str;
       }
    }
    
    /*
    	TODO this whole area needs to be reworked and cleaned up, use what's relevant and what isn't, also need to add pagination for both posts and excerpts
    
    */
    
    // filter the content of a page, check for tag and replace it with a list of posts in the requested category.
    // function heavily inspired from Alex Rabe NextGen Gallery's nggfunctions.php.
    function page2cat_content_catlist($content){
    global $post;
    $excerpt_settings=get_option('p2c_excerpt_settings');
    $post_settings=get_option('p2c_post_settings');
    $excerpt_length=get_option('p2c_excerpt_length');
    $thumbnail_option=get_option('p2c_use_thumbnail');
    $img_class=get_option('p2c_img_class');
    $title_class=get_option('p2c_title_class');
    $thumb_size=get_option('p2c_thumbnail_size');
    
    // Show excerpts
    if($excerpt_settings == "on")
    {
    	if ( stristr( $content, '[catlist' )) {
    		$search = "@(?:<p>)*\s*\[catlist\s*=\s*(\w+|^\+)\]\s*(?:</p>)*@i";
    		if	(preg_match_all($search, $content, $matches)) {
    			if (is_array($matches)) {
    				$title = get_option('p2c_catlist_title');
    				if($title != "") $output = "<h4>".$title."</h4>"; else $output = "";
    				$limit = get_option('p2c_catlist_limit');
    				foreach ($matches[1] as $key =>$v0) {
    					$catposts = get_posts('category='.$v0."&numberposts=".$limit);
    						foreach($catposts as $single):
                                                    $single_post_content = $single->post_content;
    												if($excerpt_length == 0){
    													$excerpt_length = 500;
    												}
    												if($img_class == ""){
    													$img_class = 'alignleft';
    												}
    												if($title_class == ""){
    													$img_class = 'clearBoth';
    												}
    												$excerpt = neat_trim($single_post_content, $excerpt_length);
    												$excerpt .= "<a href='".get_permalink($single->ID)."'>more</a>";
    												if($thumbnail_option != 'false'){
    													// change thumbnail to an actual variable
    													$the_thumb = get_the_post_thumbnail($single->ID, $thumb_size, array('class' => $img_class));
    
    													$output .= "<h2 class='". $title_class ."'><a href='".get_permalink($single->ID)."'>".$single->post_title."</a></h2><p>" . $the_thumb . $excerpt ."</p>";
    												}else{
    													$output .= "<h2 class='" . $title_class . "'><a href='".get_permalink($single->ID)."'>".$single->post_title."</a></h2><p>". $excerpt ."</p>";
    												}
    						endforeach;
    					$search = $matches[0][$key];
    					$replace= $output;
    					$content= str_replace ($search, $replace, $content);
    				}
    			$output .= "";
    			}
    		}
    	}
    
    // Show full posts
    }elseif($post_settings == "on")
    {
    	if ( stristr( $content, '[catlist' )) {
    		$search = "@(?:<p>)*\s*\[catlist\s*=\s*(\w+|^\+)\]\s*(?:</p>)*@i";
    		if	(preg_match_all($search, $content, $matches)) {
    			if (is_array($matches)) {
    				$title = get_option('p2c_catlist_title');
    				if($title != "") $output = "<h4>".$title."</h4>"; else $output = "";
    				$limit = get_option('p2c_catlist_limit');
    				foreach ($matches[1] as $key =>$v0) {
    					$catposts = get_posts('category='.$v0."&numberposts=".$limit);
    						foreach($catposts as $single):
    												if($img_class == ""){
    													$img_class = 'alignleft';
    												}
    												if($title_class == ""){
    													$img_class = 'clearBoth';
    												}
    												if($thumbnail_option != 'false'){
    													$the_thumb = get_the_post_thumbnail($single->ID, $thumb_size, array('class' => $img_class));
    
    						$output .= "<h2 class='".$title_class."'><a href='".get_permalink($single->ID)."'>".$single->post_title."</a></h2><p>" . $the_thumb . wpautop($single->post_content) ."</p>";
    												}else{
    													$output .= "<h2 class='".$title_class."'><a href='".get_permalink($single->ID)."'>".$single->post_title."</a></h2><p>" . wpautop($single->post_content) ."</p>";
    												}
    
    						endforeach;
    					$search = $matches[0][$key];
    					$replace= $output;
    					$content= str_replace ($search, $replace, $content);
    				}
    			$output .= "";
    			}
    		}
    	}
    // show just a list
    }else
    {
    	if ( stristr( $content, '[catlist' )) {
    		$search = "@(?:<p>)*\s*\[catlist\s*=\s*(\w+|^\+)\]\s*(?:</p>)*@i";
    		if	(preg_match_all($search, $content, $matches)) {
    			if (is_array($matches)) {
    				$title = get_option('p2c_catlist_title');
    				if($title != "") $output = "<h4>".$title."</h4>"; else $output = "";
    				$output .= "<ul class='p2c_catlist'>";
    				$limit = get_option('p2c_catlist_limit');
    				foreach ($matches[1] as $key =>$v0) {
    					$catposts = get_posts('category='.$v0."&numberposts=".$limit);
    						foreach($catposts as $single):
    						$output .= "<li><a href='".get_permalink($single->ID)."'>".$single->post_title."</a></li>";
    						endforeach;
    					$search = $matches[0][$key];
    					$replace= $output;
    					$content= str_replace ($search, $replace, $content);
    				}
    			$output .= "</ul>";
    			}
    		}
    	}
    
    }
    return $content;
    }
    
    // add real option page
    function page2cat_options_page(){
    global $wpdb, $styles;
    
    /*
    	TODO we need to add the rest of the options to the p2c_defaults here
    */
    
    $p2c_defaults = array("show_usedpages_yes"=>"","show_usedpages_no"=>"","use_empty_no"=>"", "use_empty_yes"=>"", "catlist_limit"=>"", "catlist_title"=>"", "use_thumbnail_yes" => "", "use_thumbnail_no" => "", "thumbnail_size_thumb" => "", "thumbnail_size_med" => "", "thumbnail_size_lrg" => "");
    
    if(isset($_POST['page2cat_action'])):
    #print_r($_POST); #die();
    	$sane1 = strip_tags(htmlentities($_POST['p2c_catlist_limit']));
    	update_option('p2c_catlist_limit',$sane1);
    	$sane4 = strip_tags(htmlentities($_POST['p2c_catlist_title']));
    	update_option('p2c_catlist_title',$sane4);
    	$sane2 = strip_tags(htmlentities($_POST['p2c_show_used_pages']));
    	update_option('p2c_show_used_pages',$sane2);
    	$sane3 = strip_tags(htmlentities($_POST['p2c_use_empty']));
    	update_option('p2c_use_empty',$sane3);
    	$excerpt_settings = !isset($_POST['excerpt_settings'])? 'off': 'on';
    	update_option('p2c_excerpt_settings', $excerpt_settings);
    	$post_settings = !isset($_POST['post_settings'])? 'off': 'on';
    	update_option('p2c_post_settings', $post_settings)? 'off': 'on';
    	$excerpt_length = strip_tags(htmlentities($_POST['p2c_excerpt_length']));
    	update_option('p2c_excerpt_length',$excerpt_length);
    	$use_thumb = strip_tags(htmlentities($_POST['p2c_use_thumbnail']));
    	update_option('p2c_use_thumbnail', $use_thumb);
    	$img_class = strip_tags(htmlentities($_POST['p2c_img_class']));
    	update_option('p2c_img_class', $img_class);
    	$title_class = strip_tags(htmlentities($_POST['p2c_title_class']));
    	update_option('p2c_title_class', $title_class);
    	$thumbnail_size = strip_tags(htmlentities($_POST['p2c_thumbnail_size']));
    	update_option('p2c_thumbnail_size', $thumbnail_size);
    
    	// Check if our excerpt settings are screwed up and reset if necessary
    	if($excerpt_settings == 'on' && $post_settings == 'on'){
    		echo('<div id="message" class="updated fade"><p><strong>ERROR! You cannot have both Excerpts and Posts set! Setting both to off!</strong></p></div');
    		update_option('p2c_excerpt_settings', 'off');
    		update_option('p2c_post_settings', 'off');
    	}else{
    
    	echo('<div id="message" class="updated fade"><p><strong>Settings saved.</strong></p></div>');
    }
    endif;
    
    $opt3 = get_option('p2c_use_empty');
    if($opt3 == "false"){
    	$p2c_defaults['use_empty_no'] = ' selected="selected"';
    }elseif($opt3 == "true"){
    	$p2c_defaults['use_empty_yes'] = ' selected="selected"';
    }
    
    $opt2 = get_option('p2c_show_used_pages');
    if($opt2 == "false"){
    	$p2c_defaults['show_usedpages_no'] = ' selected="selected"';
    }elseif($opt2 == "true"){
    	$p2c_defaults['show_usedpages_yes'] = ' selected="selected"';
    }
    
    $excerpt_settings = (get_option('p2c_excerpt_settings')=='on') ? 'checked':'';
    $post_settings = (get_option('p2c_post_settings')=='on') ? 'checked':'';
    
    // get the excerpt length
    $excerpt_length = get_option('p2c_excerpt_length');
    
    // get the thumbnail option
    $use_thumb = get_option('p2c_use_thumbnail');
    if($use_thumb == "false"){
    	$p2c_defaults['use_thumbnail_no'] = ' selected="selected"';
    }elseif($use_thumb == "true"){
    	$p2c_defaults['use_thumbnail_yes'] = ' selected="selected"';
    }
    
    // get the thumbnail size option
    $thumbnail_size = get_option('p2c_thumbnail_size');
    if($thumbnail_size == "thumbnail"){
    	$p2c_defaults['thumbnail_size_thumb'] = ' selected="selected"';
    }elseif($thumbnail_size == "medium"){
    	$p2c_defaults['thumbnail_size_med'] = ' selected="selected"';
    }elseif($thumbnail_size == "large"){
    	$p2c_defaults['thumbnail_size_lrg'] = ' selected="selected"';
    }
    
    /*
    	TODO We need to fix this shit and make it standards compliant. Fucking tables
    */
    $p2c_catlist_title = get_option('p2c_catlist_title');
    
    	echo "<div class='wrap'>";
    	echo "<h2>Category Page settings</h2>";
    	echo "<form method='post' name='page2cat_options' accept-charset='utf-8'>";
    
    	echo '
    	<h3>Management settings</h3>
    	<p>These settings let you customize your <a href="edit.php?page=category-pages">Category Page management panel</a>.</p>
    	<table class="form-table">
    	<tr valign="top">
    	<th scope="row">Show empty categories</th>
    	<td>
    	<select name="p2c_use_empty">
    	<option value="false"'.$p2c_defaults['use_empty_no'].' label=" No, thanks. "> No, thanks. </option>
    	<option value="true"'.$p2c_defaults['use_empty_yes'].' label=" Yes, please! "> Yes, please! </option>
    	</select> <small>(Choose whether empty categories are shown or not. )</small>
    	</td>
    	</tr>
    
    	<tr valign="top">
    	<th scope="row">Allow single page sharing</th>
    	<td>
    	<select name="p2c_show_used_pages">
    	<option value="false"'.$p2c_defaults['show_usedpages_no'].' label=" No, thanks. "> No, thanks. </option>
    	<option value="true"'.$p2c_defaults['show_usedpages_yes'].' label=" Yes, please! "> Yes, please! </option>
    	</select> <small>(You can share a single page with more than a category, if you like.)</small>
    	</td>
    	</tr>
    
    	</table>
    
    	<h3><code>[catlist]</code> tag settings</h3>
    	<p>You can use a <em>[catlist=xx]</em> tag in a post/page to show a list of post from a certain category, replacing <em>xx</em> with the category ID.</p>
    	<table class="form-table">
    	<tr valign="top">
    	<th scope="row">Display at most </th>
    	<td>
    	<select name="p2c_catlist_limit">';
    
    	$limits = array(1,2,3,4,5,6,7,8,9,10,15,20,25);
    	foreach($limits as $limit):
    		if(get_option('p2c_catlist_limit') == $limit) $flag = "selected='selected'"; else $flag = "";
    		echo "<option value='".$limit."' name='opt".$limit."' ".$flag.">".$limit."</option>";
    	endforeach;
    
    	echo '</select> posts.
    	</td>
    	</tr>
    
    	<tr valign="top">
    	<th scope="row">Display list title</th>
    	<td><input type="text" name="p2c_catlist_title" value="'.$p2c_catlist_title.'" size="30"/>
    	<small>(Leave empty to show a post list without a title.)</small>
    	</td>
    	</tr>
    	</table>
    
    	<h3>Excerpt or Full Post Settings</h3>
    	<p>You can choose to display full posts or excerpts only by checking one of the boxes. Do not check both as it will error out. Excerpts will be 500 characters for now until I add in another option for it.</p>
    	<table class="form-table">
    	<tr valign="top">
    	<td><input id="check5" type="checkbox" name="excerpt_settings"'.$excerpt_settings.' />
    	<label for="check5">Display only excerpts?</label></td>
    	</tr>
    	<tr valign="top">
    	<td><input id="check6" type="checkbox" name="post_settings"'.$post_settings.' />
    	<label for="check6">Display full posts?</label></td>
    	</tr>
    	<tr valign="top">
    	<td><input type="text" name="p2c_excerpt_length" value="'.$excerpt_length.'" size="30"/>
    	<small>Default is set to 500</small>
    	</td>
    	</tr>
    	<tr>
    	<td><select name="p2c_use_thumbnail">
    	<option value="false"'.$p2c_defaults['use_thumbnail_no'].' label=" No thumbnails. "> No thumbnails. </option>
    	<option value="true"'.$p2c_defaults['use_thumbnail_yes'].' label=" Yes thumbnails! "> Yes thumbnails! </option>
    	</select> <small>(If you select yes you\'ll need to enable post or page thumbnails in your theme.)</small>
    	</td>
    	</tr>
    	<tr>
    	<td><select name="p2c_thumbnail_size">
    	<option value="thumbnail"'.$p2c_defaults['thumbnail_size_thumb'].' label=" Thumbnail "> Thumbnail </option>
    	<option value="medium"'.$p2c_defaults['thumbnail_size_med'].' label=" Medium "> Medium </option>
    	<option value="large"'.$p2c_defaults['thumbnail_size_lrg'].' label=" Large "> Large </option>
    	</select> <small>(You can set the sizes for these within settings->media settings.)</small>
    	</td>
    	</tr>
    	<tr>
    	<td><input type="text" name="p2c_img_class" value="'.$img_class.'" size="30"/>
    	<small>Default is set to alignleft</small>
    	</td>
    	</tr>
    	<td><input type="text" name="p2c_title_class" value="'.$title_class.'" size="30"/>
    	<small>Default is set to clearBoth - css to add to your theme for clearBoth: .clearBoth{clear:both}</small>
    	</td>
    	</tr>
    	</table>
    	';	
    
    	echo '<p class="submit">
    	<input type="hidden" name="page2cat_action" value="update" />
    	<input type="submit" name="update" value="Update Settings" />
    	</p>
    	</fieldset>';
    
    	echo '</form>';
    	echo PIXLINE_FOOTER;
    	echo "</div>";
    }
    
    /*
    	TODO what is this used for and where is it being used? Nowhere. Get rid of it.
    */
    // template function for manual hacks and widgets :-)
    function page2cat_output($cat, $style = 'getpost', $useimg = 1){
    global $wpdb;
    
    	$useimg = get_option('p2c_use_img');
    	$mypage = $wpdb->get_row("SELECT * FROM {$wpdb->page2cat} WHERE cat_ID = '".$cat."';",OBJECT);
    #	print_r($mypage);
    	$pageid = $mypage->page_ID;
    	if($pageid != ""):
    
    	switch($style):
    
    	case 'getpost':
    	?>
    	<div id="category-page-header">
    	<?php
    	$post = $post_temp;
    	$post = get_post($pageid);
    	setup_postdata($post);
    
    	if($post->post_title!=""){
    				?>
    				<div id="p2c-header">
    					<h2><?php echo $post->post_title; ?></h2>
    					<p><?php the_content(); ?></p>
    				</div>
    		<div class="category-page-cleaner"></div>
    	</div>
    	<?php
    	$post = $post_temp;
    	}
    	break;
    
    	case 'widget':
    	?>
    	<div id="category-widget-header">
    	<?php
    	$pagina = "SELECT * FROM {$wpdb->posts} WHERE ID='".$pageid."' AND post_type = 'page';";
    	$mine = $wpdb->get_results($pagina);
    	if($mine[0]->post_title!=""){
    				?>
    				<div id="p2c-header">
    					<!-- h2><?php echo $mine[0]->post_title; ?></h2 -->
    					<p><?php echo wptexturize($mine[0]->post_content,1); ?></p>
    				</div>
    		<div class="category-widget-cleaner"></div>
    	</div>
    	<?php
    	}
    
    	break;
    	case 'inline':
    	default:
    	?>
    	<div id="category-page-header">
    	<?php
    	$pagina = "SELECT * FROM {$wpdb->posts} WHERE ID='".$pageid."' AND post_type = 'page';";
    	$mine = $wpdb->get_results($pagina);
    	if($mine[0]->post_title!=""){
    				?>
    				<div id="p2c-header">
    					<h2><?php echo $mine[0]->post_title; ?></h2>
    					<p><?php echo wptexturize($mine[0]->post_content,1); ?></p>
    				</div>
    		<div class="category-page-cleaner"></div>
    	</div>
    	<?php
    	}
    	break;
    
    	endswitch;
    
    	?>
    	<?php
    	else:
    	echo '<h2 class="pagetitle">Archive for the ‘'.single_cat_title('',false).'’ Category</h2>';
    	endif;
    }
    
    /*
    	FIXME remove this page2cat_init since it's for a metabox, for what the fuck ever reason
    */
    
    // adds sidebox in page write/edit
    function page2cat_init(){
    	if (function_exists('add_meta_box')) {
    		add_meta_box('page2cat','Category Page Options', 'page2cat_add_meta_box', 'page');
    		add_action('admin_head','page2cat_metabox_styles');
    	} else {
    		add_action('dbx_page_sidebar', 'page2cat_add_sidebox');
    		add_action('admin_head','page2cat_sidebox_styles');
    	}
    }
    // install management and options page
    function page2cat_config_page() {
    	if ( function_exists('add_submenu_page') && is_admin()):
    	add_submenu_page('edit.php', __('Category Pages'), __('Category Pages'), 8, 'category-pages', 'page2cat_manage_page');
    	endif;
    	if( function_exists('add_options_page') && is_admin()):
    	add_options_page('Category Pages options','Category Pages',8,'category-page-options','page2cat_options_page');
    	endif;
    }
    
    /*
    	TODO not sure what these are here for - I believe it's for the stupid management menu that doesn't work
    */
    if( is_admin() ):
    	if( preg_match('|page-new.php|i', $_SERVER['REQUEST_URI']) ||
    		preg_match('|page.php|i', $_SERVER['REQUEST_URI']) ||
    		preg_match('|edit.php|i', $_SERVER['REQUEST_URI']) ){
    			add_action('admin_menu', 'page2cat_init');
    	}
    	add_action('admin_menu', 'page2cat_config_page');
    	add_action('save_post','page2cat_trigger_save');
    endif;
    
    add_filter('the_content','page2cat_content_catlist');	// by popular demand :-)
    ?>

    It’d be better to put it into it’s own variable instead. While it makes the code longer, if something changes in wp or something you have the benefit of changing only one thing:

    $the_thumbnail = get_the_post_thumbnail($single->ID, 'thumbnail');
    $output .= $the_thumbnail

    I just added this functionality in though. You can check it out here.

    Thread Starter Pneumonic

    (@pneumonic)

    The dev got back to me and this functionality is now standard in the plugin! So disregard this post and just update your site!

    I think what you’ve done here is what I did here, but your code is much shorter. Although the way I re-wrote it, it gives the user the option to output the content via the admin panel.

    I’ve modified the code to do what you wanthere.

    Thread Starter Pneumonic

    (@pneumonic)

    Alright. Well here’s how to get it to work with valid xhtml and the iphone. Just copy this script and paste it into your smartyoutube.php replacing everything in there with this. I’ve annotated where I made the change and it was actually really simple and it appears that the author already had the idea, but hadn’t implemented it yet. If I have any other bugfixes I’ll post them as well (or any of the things on his todo). Enjoi.

    <?php
    /*
    Plugin Name: Smart Youtube
    Plugin URI: http://www.prelovac.com/vladimir/wordpress-plugins/smart-youtube
    Description: Insert YouTube videos in posts, comments and RSS feeds with ease and full customization.
    Author: Vladimir Prelovac
    Version: 3.3
    Author URI: http://www.prelovac.com/vladimir/
    
    Updates:
    3.3 - Supports migrated blogs from WordPress.com replacing [youtube=youtubeadresss]
    3.2 - Added title to widget, fixed HTML code issue with widget
    3.1.1 - param closed properly for validation
    3.1 - wmode transparent parameter updated to better handle transparancy
    3.0 - Added video template, option to set sidebar video size, fixed sidebar widget code, fixed video syntax issue
    2.8.1 - Display Annotioans added as option
    2.8 - Support for playlists
    2.7.5 - Plugin url updated to use WP_PLUGIN_URL
    2.7.4 - Added option to remove info&ratings
    2.7.3 - Removed annotiations
    2.7 - Supports a sidebar widget for videos
    2.6 - Added option to remove search button
    2.5 - Added DVD quality support (httpvq)
    2.4.1 - Small fixes in embed and rss links
    2.4 - Added support for extra parameters like &start=50 to start the video at 50th second of play
    2.2 - Full xHTML validaiton
    2.1 - Made the application iPhone compatible and allowed full screen
    2.0 - Support for playback high quality YouTube videos
    1.9 - Added video autoplay option
    1.8 - Solved Problem with HTML validation, enabled full video preview in RSS
    1.6 - Solving a problem with wordpress handling special characters
    1.5 - Added new admin interface and more options to control the video
    
    To-Doo:
    - marinas javascript suggestion for hq videos
    - add editor button
    - The plugin places a preview image in the RSS feed which is great, but it links to the video on http://www.youtube.com. I would like to change it so the image links to the blog post so I can generate some traffic on my blog.
    - localization
    - the images appear under the embedded Smart Youtube videos. Is there any way to edit the z-index for Smart Youtube CSS? I
    */
    
    $yte_localversion="2.7.5";
    
    $CustomColors=array (
    	"blank" => array("d6d6d6","f0f0f0"),
    	"storm" => array("3a3a3a","999999"),
    	"iceberg" => array("2b405b","6b8ab6"),
    	"acid" => array("006699","54abd6"),
    	"green" => array("234900","4e9e00"),
    	"orange" => array("e1600f","febd01"),
    	"pink" => array("cc2550","e87a9f"),
    	"purple" => array("402061","9461ca"),
    	"rubyred" => array("5d1719","cd311b")
    );
    
    $wp_yte_plugin_url = defined('WP_PLUGIN_URL') ? trailingslashit(WP_PLUGIN_URL . '/' . dirname(plugin_basename(__FILE__))) : trailingslashit(get_bloginfo('wpurl')) . PLUGINDIR . '/' . dirname(plugin_basename(__FILE__)); 
    
     // Admin Panel
    function yte_add_pages()
    {
    	add_options_page('Smart Youtube options', 'Smart Youtube', 8, __FILE__, 'yte_options_page');
    }
    
    // Options Page
    function yte_options_page()
    {
    	global $yte_localversion;
    	$status=yte_getinfo();
    
    	$theVersion = $status[1];
    	$theMessage = $status[3];	
    
    			if( (version_compare(strval($theVersion), strval($yte_localversion), '>') == 1) )
    			{
    				$msg = 'Latest version available '.' <strong>'.$theVersion.'</strong><br />'.$theMessage;
    				  _e('<div id="message" class="updated fade"><p>' . $msg . '</p></div>');			
    
    			}
    
        // If form was submitted
    	if (isset($_POST['submitted']))
    	{
    		  check_admin_referer('smart-youtube');
    			$disp_img = !isset($_POST['disp_img'])? 'off': 'on';
    			$disp_link = !isset($_POST['disp_link'])? 'off': 'on';
    			$disp_search = !isset($_POST['disp_search'])? 'off': 'on';
    			$disp_ann = !isset($_POST['disp_ann'])? 'off': 'on';
    			$disp_info = !isset($_POST['disp_info'])? 'off': 'on';
    			$valid = !isset($_POST['valid'])? 'off': 'on';
    
    			update_option('smart_yt_img', $disp_img);
    			update_option('smart_yt_link', $disp_link);
    			update_option('smart_yt_valid', $valid);
    			update_option('smart_yt_search', $disp_search);
    			update_option('smart_yt_ann', $disp_ann);
    			update_option('smart_yt_info', $disp_info);			
    
    			$disp_width = (int) ($_POST['disp_width']=="")? '425': $_POST['disp_width'];
    			$disp_height = (int) ($_POST['disp_height']=="")? '344': $_POST['disp_height'];
    
    			update_option('smart_yt_width', $disp_width);
    			update_option('smart_yt_height', $disp_height);
    
    			$disp_widthhq = (int) ($_POST['disp_widthhq']=="")? '480': $_POST['disp_widthhq'];
    			$disp_heighthq = (int) ($_POST['disp_heighthq']=="")? '360': $_POST['disp_heighthq'];
    
    			update_option('smart_yt_widthhq', $disp_widthhq);
    			update_option('smart_yt_heighthq', $disp_heighthq);
    
    			$disp_widthside = (int) ($_POST['disp_widthside']=="")? '150': $_POST['disp_widthside'];
    			$disp_heightside = (int) ($_POST['disp_heightside']=="")? '125': $_POST['disp_heightside'];
    
    			update_option('smart_yt_widthside', $disp_widthside);
    			update_option('smart_yt_heightside', $disp_heightside);
    
    			$disp_rel = !isset($_POST['embedRel'])? '1': $_POST['embedRel'];
    
    			$disp_border = !isset($_POST['embedBorder'])? '0': '1';
    			$disp_color = !isset($_POST['embedColor'])? 'blank': $_POST['embedColor'];
    
    			$disp_autoplay = !isset($_POST['autoplay'])? '0': '1';
    
    			update_option('smart_yt_rel', $disp_rel);			
    
    			update_option('smart_yt_border', $disp_border);
    			update_option('smart_yt_color', $disp_color);
    
    			update_option('smart_yt_autoplay', $disp_autoplay);
    
    			$disp_posts = !isset($_POST['disp_posts'])? 'off': 'on';
    			$disp_comments = !isset($_POST['disp_comments'])? 'off': 'on';
    
    			update_option('smart_yt_posts', $disp_posts);
    			update_option('smart_yt_comments', $disp_comments);
    
    			$disp_template = !isset($_POST['disp_template'])? '{video}': stripslashes(htmlspecialchars($_POST['disp_template']));
    			update_option('smart_yt_template', $disp_template);
    
    			$msg_status = 'Smart Youtube options saved.';
    
    		    // Show message
    		   _e('<div id="message" class="updated fade"><p>' . $msg_status . '</p></div>');
    
    	} 
    
    		// Fetch code from DB
    		$disp_img = (get_option('smart_yt_img')=='on') ? 'checked':'';
    		$disp_link = (get_option('smart_yt_link')=='on') ? 'checked':'';
    		$disp_search = (get_option('smart_yt_search')=='on') ? 'checked':'';
    		$disp_ann = (get_option('smart_yt_ann')=='on') ? 'checked':'';
    		$disp_info = (get_option('smart_yt_info')=='on') ? 'checked':'';
    
    		$valid = (get_option('smart_yt_valid')=='on') ? 'checked':'';
    
    		$disp_width = get_option('smart_yt_width');
    		$disp_height = get_option('smart_yt_height');
    
    		$disp_widthhq = get_option('smart_yt_widthhq');
    		$disp_heighthq = get_option('smart_yt_heighthq');
    
    		$disp_widthside = get_option('smart_yt_widthside');
    		$disp_heightside = get_option('smart_yt_heightside');
    
    		$disp_autoplay = (get_option('smart_yt_autoplay')=='1') ? 'checked':'';
    
    		$disp_rel = (get_option('smart_yt_rel')=='1') ? 'checked':'';
    
    		$disp_rel2=$disp_rel ? "" : "checked";
    		$disp_border = (get_option('smart_yt_border')=='1') ? 'checked':'';
    		$disp_color = get_option('smart_yt_color');
    
    		$disp_posts = (get_option('smart_yt_posts')=='on') ? 'checked' :'' ;
    		$disp_comments = (get_option('smart_yt_comments')=='on') ? 'checked':'';
    
    		$disp_template = wp_specialchars(get_option('smart_yt_template'));
    
    		if ($disp_width=="")
    			$disp_width="425";
    		if ($disp_height=="")
    			$disp_height="355";			
    
    	global $wp_version;
    	global $wp_yte_plugin_url;
    		$embed_img=$wp_yte_plugin_url.'/img/embed_selection-vfl29294.png';
    
    		echo '<script src="' . $wp_yte_plugin_url . '/yt.js" type="text/javascript"></script>' . "\n";
    echo '<style type="text/css">
    #watch-embed-div,
    #watch-url-div{
    border-top:1px solid #CCC;
    font-size:11px;
    }
    #watch-url-div{
    margin:5px 0;
    }
    #watch-url-field{
    font-size:10px;
    width:340px;
    margin-top:2px;
    }
    #watch-embed-div label,
    #watch-url-div label{
    color:#999;
    line-height:18px;
    font-size:12px;
    }
    #watch-embed-div input{
    font-size:10px;
    width:339px;
    margin-top:2px;
    }
    #watch-embed-div #watch-embed-customize{
    font-weight:normal;
    color:#03c;
    }
    #watch-customize-embed-div{
    display:none;
    background-color:white;
    border-top:1px solid #CCC;
    margin-top:5px;
    padding:5px;
    }
    #watch-customize-embed-form{
    display:block;
    width:210px;
    }
    #watch-customize-embed-desc{
    display:block;
    padding:6px;
    }
    #watch-customize-embed-theme{
    display:block;
    clear:both;
    }
    #watch-customize-embed-theme-swatches{
    padding:5px;
    display:block;
    margin-top:5px;
    width:310px;
    height:80px;
    }
    #watch-customize-embed-theme-preview{
    display:block;
    float:right;
    margin:4px 140px;
    background:transparent url('.$embed_img.') no-repeat scroll 0px -23px;
    width:100px;
    height:86px;
    }
    .watch-image-radio-link{
    border:0;
    display:inline-block;
    float:left;
    margin:3px;
    }
    .watch-image-radio-link:hover{
    background-color:#ADD8E6;
    }
    .watch-image-radio-link.radio_selected{
    border:1px solid #000;
    margin:2px;
    }
    .watch-image-radio-link img{
    border:1px solid #fff;
    background-color:#fff;
    padding:0px;
    margin:4px;
    }
    .watch-embed-select{
    width:46px;
    height:23px;
    }
    .watch-embed-iceberg{
    background:transparent url('.$embed_img.') no-repeat scroll 0px 0px;
    }
    .watch-embed-blank{
    background:transparent url('.$embed_img.') no-repeat scroll -46px 0px;
    }
    .watch-embed-acid{
    background:transparent url('.$embed_img.') no-repeat scroll -92px 0px;
    }
    .watch-embed-storm{
    background:transparent url('.$embed_img.') no-repeat scroll -138px 0px;
    }
    .watch-embed-green{
    background:transparent url('.$embed_img.') no-repeat scroll -184px 0px;
    }
    .watch-embed-orange{
    background:transparent url('.$embed_img.') no-repeat scroll -230px 0px;
    }
    .watch-embed-pink{
    background:transparent url('.$embed_img.') no-repeat scroll -276px 0px;
    }
    .watch-embed-purple{
    background:transparent url('.$embed_img.') no-repeat scroll -322px 0px;
    }
    .watch-embed-rubyred{
    background:transparent url('.$embed_img.') no-repeat scroll -368px 0px;
    }
    div#dbx-content a{
    text-decoration:none;
    }
    </style>
    		';
    
        $imgpath=$wp_yte_plugin_url.'/i';
        $actionurl=$_SERVER['REQUEST_URI'];
        $nonce=wp_create_nonce( 'smart-youtube');
        $example=htmlentities('<div style="float:left;margin-right: 10px;">{video}</div>');
        // Configuration Page
    
        echo <<<END
    <div class="wrap" style="max-width:950px !important;">
    	<h2>Smart YouTube</h2>
    
    	<div id="poststuff" style="margin-top:10px;">
    
    	<div id="sideblock" style="float:right;width:220px;margin-left:10px;">
    		 <h2>Information</h2>
    		 <div id="dbx-content" style="text-decoration:none;">
    		  <img src="$imgpath/home.png"><a style="text-decoration:none;" href="http://www.prelovac.com/vladimir/wordpress-plugins/smart-youtube"> Smart Youtube Home</a><br /><br />
    			<img src="$imgpath/rate.png"><a style="text-decoration:none;" href="http://wordpress.org/extend/plugins/smart-youtube/"> Rate this plugin</a><br /><br />
    			<img src="$imgpath/help.png"><a style="text-decoration:none;" href="http://www.prelovac.com/vladimir/forum"> Support and Help</a><br />
    			<p >
    			<a style="text-decoration:none;" href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=2567254&lc=US"><img src="$imgpath/paypal.gif"></a>
    			</p><br />
    			<img src="$imgpath/more.png"><a style="text-decoration:none;" href="http://www.prelovac.com/vladimir/wordpress-plugins"> Cool WordPress Plugins</a><br /><br />
    			<img src="$imgpath/twit.png"><a style="text-decoration:none;" href="http://twitter.com/vprelovac"> Follow updates on Twitter</a><br /><br />
    			<img src="$imgpath/idea.png"><a style="text-decoration:none;" href="http://www.prelovac.com/vladimir/services"> Need a WordPress Expert?</a>
      </div>
     	</div>
    
    	 <div id="mainblock" style="width:710px">
    
    		<div class="dbx-content">
    		 	<form name="yteform" action="$action_url" method="post">
    					<input type="hidden" name="submitted" value="1" />
    					<input type="hidden" id="_wpnonce" name="_wpnonce" value="$nonce" />
    					<h2>Usage</h2>
    
    <p>To use the video in your posts, paste YouTube video URL with <strong>httpv://</strong> (notice the 'v'). </p>
    <p><strong>Important:</strong> The URL should just be copied into your post normally and the letter 'v' added, do not create a clickable link!</p>
    <p>Example: httpv://www.youtube.com/watch?v=OWfksMD4PAg</p>
    <p>If you want to embed high quality video (for videos that have them) use httpvh:// instead (Video High).</p>
    <p>If you want to embed HD Quality (DVD quality 720p) video use httpvhd:// instead (Video High Defintion).</p>
    <p>To embed playlists	use httpvp:// (eg. httpvp://www.youtube.com/view_play_list?p=528026B4F7B34094)</p>
    <p>Smart Youtube also supports migrated blogs from WordPress.com using [youtube=youtubeadresss]</p>
    
    <ul>
    <li>httpv:// - regular video</li>
    <li>httpvh:// - high quality</li>
    <li>httpvhd:// - HD quality</li>
    <li>httpvp:// - playlist</li>
    </ul>
    <h2>Options</h2>
    <p> You can adjust the way your embeded youtube videos behave in the options below.</p>
    <p><strong>Video settings</strong></p>
    
    <div><input id="check3" type="checkbox" name="disp_posts" $disp_posts />
    <label for="check3">Display videos in posts</label></div>
    
    <div><input id="check4" type="checkbox" name="disp_comments" $disp_comments />
    <label for="check4">Display videos in comments</label></div>
    
    <br /><br /><strong>Video Appearence</strong><br /><br />
    <p>Video template. Default is just {video}. <br />
    You can try $example if you want the text to wrap around video.</p>
    <textarea cols="50" id="disp_template" name="disp_template">$disp_template</textarea>
    
    <p>Video width and height in normal mode. Default is 425x344.</p>
    <input id="disp_width"  name="disp_width" value="$disp_width" size="7"/>x<input id="disp_height"  name="disp_height" value="$disp_height" size="7" /><br />
    
    <p>Video width and height in <strong>high quality</strong> mode. Default is 480x360.</p>
    <input id="disp_widthhq"  name="disp_widthhq" value="$disp_widthhq" size="7" />x<input id="disp_heighthq"  name="disp_heighthq" value="$disp_heighthq" size="7" /><br /><br />
    
    <p>Video width and height in <strong>sidebar</strong> mode (regardless of quality). Default is 150x125.</p>
    <input id="disp_widthside"  name="disp_widthside" value="$disp_widthside" size="7" />x<input id="disp_heightside"  name="disp_heightside" value="$disp_heightside" size="7" /><br /><br />
    
     <br />
    		<div id="watch-customize-embed-form">
    			<input type="radio" $disp_rel id="embedCustomization1" name="embedRel" value="1"/>
    			<label for="embedCustomization1">Include related videos</label><br />
    			<input type="radio" $disp_rel2  id="embedCustomization0" name="embedRel" value="0"/>
    			<label for="embedCustomization0">Do not include related videos</label><br />
    		</div>
    		<img id="watch-customize-embed-theme-preview" src="$wp_yte_plugin_url/img/preview_embed_blank_sm.gif"/>
    		<div id="watch-customize-embed-theme-swatches">
    				<a onclick="onChangeColor('blank');  return false;" class="watch-image-radio-link radio_selected" href="#" id="theme_color_blank_img"><img alt="" src="http://s.ytimg.com/yt/img/pixel-vfl73.gif" class="watch-embed-select watch-embed-blank"/></a>
    				<a onclick="onChangeColor('storm');  return false;" class="watch-image-radio-link" href="#" id="theme_color_storm_img"><img alt="" src="http://s.ytimg.com/yt/img/pixel-vfl73.gif" class="watch-embed-select watch-embed-storm"/></a>
    				<a onclick="onChangeColor('iceberg');  return false;" class="watch-image-radio-link " href="#" id="theme_color_iceberg_img"><img alt="" src="http://s.ytimg.com/yt/img/pixel-vfl73.gif" class="watch-embed-select watch-embed-iceberg"/></a>
    				<a onclick="onChangeColor('acid');  return false;" class="watch-image-radio-link" href="#" id="theme_color_acid_img"><img alt="" src="http://s.ytimg.com/yt/img/pixel-vfl73.gif" class="watch-embed-select watch-embed-acid"/></a>
    				<a onclick="onChangeColor('green');  return false;" class="watch-image-radio-link" href="#" id="theme_color_green_img"><img alt="" src="http://s.ytimg.com/yt/img/pixel-vfl73.gif" class="watch-embed-select watch-embed-green"/></a>
    				<a onclick="onChangeColor('orange');  return false;" class="watch-image-radio-link" href="#" id="theme_color_orange_img"><img alt="" src="http://s.ytimg.com/yt/img/pixel-vfl73.gif" class="watch-embed-select watch-embed-orange"/></a>
    				<a onclick="onChangeColor('pink');  return false;" class="watch-image-radio-link" href="#" id="theme_color_pink_img"><img alt="" src="http://s.ytimg.com/yt/img/pixel-vfl73.gif" class="watch-embed-select watch-embed-pink"/></a>
    				<a onclick="onChangeColor('purple');  return false;" class="watch-image-radio-link" href="#" id="theme_color_purple_img"><img alt="" src="http://s.ytimg.com/yt/img/pixel-vfl73.gif" class="watch-embed-select watch-embed-purple"/></a>
    				<a onclick="onChangeColor('rubyred');  return false;" class="watch-image-radio-link" href="#" id="theme_color_rubyred_img"><img alt="" src="http://s.ytimg.com/yt/img/pixel-vfl73.gif" class="watch-embed-select watch-embed-rubyred"/></a>
    				<input id="embedColor" type="hidden" name="embedColor" value="$disp_color">
    				<input id="prevUrl" type="hidden" name="prevUrl" value="$wp_yte_plugin_url/img/">
    		</div>
    			<div style="margin: 0px 0px 0px 4px; clear: both;">
    				<input type="checkbox" onchange="onUpdatePreviewImage();" id="show_border_checkbox" name="embedBorder" $disp_border /><label for="show_border_checkbox"> Show Border</label><br />
    				<input type="checkbox" id="autoplay_checkbox" name="autoplay" $disp_autoplay /><label for="autoplay_checkbox"> Autoplay videos</label><br />
    				<input type="checkbox" id="disp_search" name="disp_search" $disp_search /><label for="disp_search"> Display search box</label><br />
    				<input type="checkbox" id="disp_info" name="disp_info" $disp_info /><label for="disp_info"> Remove Titles & Ratings</label><br />
    				<input type="checkbox" id="disp_ann" name="disp_ann" $disp_ann /><label for="disp_ann"> Remove Annotations</label>
    			</div>
    
    <br />
    <p><strong>xHTML validation</strong></p>
    <p>Enabling the option below will make your YouTube code xHTML valid. But be warned that code may not work in some browsers like iPhone and in feed readers.</p>
    <div><input id="valid" type="checkbox" name="valid" $valid />
    <label for="valid">Enable xHTML Validation</label></div>
    <br />
    
    <br />
    <p><strong>RSS feed options</strong></p>
    <p>Some RSS feed readers like Bloglines will show embeded YouTube videos. Some will not and Smart YouTube allows you to display a video link and a video screenshot instead.</p>
    <p>Smart YouTube will always embed the video but it can not know if the reader supports embeded video or not. So use these additional options at your own likening.</p>
    
    <div><input id="check2" type="checkbox" name="disp_link" $disp_link />
    <label for="check2">Display video link in RSS feed</label></div>
    
    <div><input id="check1" type="checkbox" name="disp_img" $disp_img />
    <label for="check1">Display video preview image in RSS feed</label></div>
    
    <div class="submit"><input type="submit" name="Submit" value="Update options" /></div>
    			</form>
    		</div>
    
    		<br /><br /><h3>&nbsp;</h3>
    	 </div>
    
    	</div>
    
    <h5>a plugin by <a href="http://www.prelovac.com/vladimir/">Vladimir Prelovac</a></h5>
    </div>
    END;
    
    }
    
    // Add Options Page
    add_action('admin_menu', 'yte_add_pages');
    
    function yte_tag($file, $high='v', $time = "", $side = 0) {
    global $CustomColors;
    
    	$playlist=0;	
    
    	$disp_rel = get_option('smart_yt_rel');
    	$disp_border = get_option('smart_yt_border');
    	$disp_color = get_option('smart_yt_color');
    	$autoplay = get_option('smart_yt_autoplay');
    	$disp_search=(get_option('smart_yt_search')=='on') ? "1":"0";
    	$disp_info=(get_option('smart_yt_info')=='on') ? "&showinfo=0":"";
    	$disp_ann=(get_option('smart_yt_ann')=='on') ? "&iv_load_policy=3":"";
    	$template=get_option('smart_yt_template');
    
    	$valid=get_option('smart_yt_valid');
    
    	switch ($high)
    	{
    		case 'v': $high=""; break;
    		case 'vh': $high="&ap=%2526fmt%3D18"; break;
    		case 'vhd': $high="&ap=%2526fmt%3D22"; break;
    		case 'vp': $high=""; $playlist=1; break;
    		default : $high=""; break;
    	}
    
    	$width=$side ? get_option('smart_yt_widthside') : ($high ? get_option('smart_yt_widthhq') : get_option('smart_yt_width'));
    	$height=$side ? get_option('smart_yt_heightside') : ($high ? get_option('smart_yt_heighthq') : get_option('smart_yt_height'));
    
    	if ($width=="")
    		$width=$high!="" ? "480" : "425" ;
    	if ($height=="")
    		$height= $high!="" ? "360" : "344";	
    
    	if ($disp_border)
    		$height+=18;		
    
    	//	if ( strpos($_SERVER['HTTP_USER_AGENT'], "iPhone") || strpos($_SERVER['HTTP_USER_AGENT'], "iPod") )
    		if ($playlist)
    		{
    			$yte_tag = '<!-- Smart Youtube --><span class="youtube"><object width="'.$width.'" height="'.$height.'"><param name="movie" value="'.htmlspecialchars('http://www.youtube.com/p/'.$file.'&rel='.$disp_rel.'&color1='.$CustomColors[$disp_color][0].'&color2='.$CustomColors[$disp_color][1].'&border='.$disp_border.'&fs=1&hl=en&autoplay='.$autoplay.$disp_info.$disp_ann.'&showsearch='.$disp_search, ENT_QUOTES).$high.$time.'" /><param name="allowFullScreen" value="true" /><embed wmode="transparent" src="'.htmlspecialchars('http://www.youtube.com/p/'.$file.'&rel='.$disp_rel.'&color1='.$CustomColors[$disp_color][0].'&color2='.$CustomColors[$disp_color][1].'&border='.$disp_border.'&fs=1&hl=en&autoplay='.$autoplay.$disp_info.$disp_ann.'&showsearch='.$disp_search, ENT_QUOTES).$high.$time.'" type="application/x-shockwave-flash" allowfullscreen="true" width="'.$width.'" height="'.$height.'" ></embed><param name="wmode" value="transparent" /></object></span>';
    		}
    		// This was added to check for iPhone and iPod devices and checks to see if having valid xhtml is on. If valid xhtml is on then the iPhone/iPod will not see the video, so instead we just output the same code that we would if the valid flag was off. This allows us to serve up valid xhtml for our web users and non-valid xhtml to our iPhone/iPod users so they can still enjoy the experience. I personally believe this should be the default, however people who don't care about standards probably wouldn't agree
                    elseif (strpos($_SERVER['HTTP_USER_AGENT'], "iPhone") || strpos($_SERVER['HTTP_USER_AGENT'], "iPod") && ($valid=="on")) {
                                   $yte_tag = '<!-- Smart Youtube --><span class="youtube"><object width="'.$width.'" height="'.$height.'"><param name="movie" value="'.htmlspecialchars('http://www.youtube.com/v/'.$file.'&rel='.$disp_rel.'&color1='.$CustomColors[$disp_color][0].'&color2='.$CustomColors[$disp_color][1].'&border='.$disp_border.'&fs=1&hl=en&autoplay='.$autoplay.$disp_info.$disp_ann.'&showsearch='.$disp_search, ENT_QUOTES).$high.$time.'" /><param name="allowFullScreen" value="true" /><embed wmode="transparent" src="'.htmlspecialchars('http://www.youtube.com/v/'.$file.'&rel='.$disp_rel.'&color1='.$CustomColors[$disp_color][0].'&color2='.$CustomColors[$disp_color][1].'&border='.$disp_border.'&fs=1&hl=en&autoplay='.$autoplay.$disp_info.$disp_ann.'&showsearch='.$disp_search, ENT_QUOTES).$high.$time.'" type="application/x-shockwave-flash" allowfullscreen="true" width="'.$width.'" height="'.$height.'" ></embed><param name="wmode" value="transparent" /></object></span>';
                    }
    		elseif ($valid=="off") {
    				$yte_tag = '<!-- Smart Youtube --><span class="youtube"><object width="'.$width.'" height="'.$height.'"><param name="movie" value="'.htmlspecialchars('http://www.youtube.com/v/'.$file.'&rel='.$disp_rel.'&color1='.$CustomColors[$disp_color][0].'&color2='.$CustomColors[$disp_color][1].'&border='.$disp_border.'&fs=1&hl=en&autoplay='.$autoplay.$disp_info.$disp_ann.'&showsearch='.$disp_search, ENT_QUOTES).$high.$time.'" /><param name="allowFullScreen" value="true" /><embed wmode="transparent" src="'.htmlspecialchars('http://www.youtube.com/v/'.$file.'&rel='.$disp_rel.'&color1='.$CustomColors[$disp_color][0].'&color2='.$CustomColors[$disp_color][1].'&border='.$disp_border.'&fs=1&hl=en&autoplay='.$autoplay.$disp_info.$disp_ann.'&showsearch='.$disp_search, ENT_QUOTES).$high.$time.'" type="application/x-shockwave-flash" allowfullscreen="true" width="'.$width.'" height="'.$height.'" ></embed><param name="wmode" value="transparent" /></object></span>';
    				}
    			else {
    				$yte_tag = '<!-- Smart Youtube --><span class="youtube"><object type="application/x-shockwave-flash" width="'.$width.'" height="'.$height.'" data="'.htmlspecialchars('http://www.youtube.com/v/'.$file.'&rel='.$disp_rel.'&color1='.$CustomColors[$disp_color][0].'&color2='.$CustomColors[$disp_color][1].'&border='.$disp_border.'&fs=1&hl=en&autoplay='.$autoplay.$disp_info.$disp_ann.'&showsearch='.$disp_search, ENT_QUOTES).$high.$time.'"><param name="movie" value="'.htmlspecialchars('http://www.youtube.com/v/'.$file.'&rel='.$disp_rel.'&color1='.$CustomColors[$disp_color][0].'&color2='.$CustomColors[$disp_color][1].'&border='.$disp_border.'&fs=1&hl=en&autoplay='.$autoplay.$disp_info.$disp_ann.'&showsearch='.$disp_search, ENT_QUOTES).$high.$time.'" /><param name="allowFullScreen" value="true" /><param name="wmode" value="transparent" /></object></span>';
    	  }
    
    if (is_feed())
    {
    		if ($high)
    			$high="&fmt=18";
        if (get_option('smart_yt_img')=='on')
        	$yte_tag.='<a href="http://www.youtube.com/watch?v='.$file.$high.'"><img src="http://img.youtube.com/vi/'.$file.'/default.jpg" width="130" height="97" border=0></a>';
        if (get_option('smart_yt_link')=='on')
        	$ytE_tag.='<a href="http://www.youtube.com/watch?v='.$file.$high.'">www.youtube.com/watch?v='.$file.'</a>';
      //  if ( (get_option('smart_yt_link')=='off') && (get_option('smart_yt_img')=='off') )
        //    $yte_tag='http://www.youtube.com/watch?v='.$file;
    }
      $result= str_replace('{video}',  $yte_tag, html_entity_decode($template)); 
    
    	return $result;
    }
    
    function yte_check($the_content, $side=0) {
    	if(strpos($the_content, "httpv")!==FALSE  ) {
    
    		$char_codes = array('×','–');
    		$replacements = array("x", "--");
    	  $the_content=str_replace($char_codes, $replacements, $the_content);
    
    		preg_match_all("/http(v|vh|vhd):\/\/([a-zA-Z0-9\-\_]+\.|)youtube\.com\/watch(\?v\=|\/v\/)([a-zA-Z0-9\-\_]{11})([^<\s]*)/", $the_content, $matches, PREG_SET_ORDER);
    		foreach($matches as $match) { 
    
    			$the_content = preg_replace("/http".$match[1].":\/\/([a-zA-Z0-9\-\_]+\.|)youtube\.com\/watch(\?v\=|\/v\/)([a-zA-Z0-9\-\_]{11})([^\s<]*)/", yte_tag($match[4], $match[1], $match[5], $side), $the_content, 1);
    		}
    
    		preg_match_all("/http(vp):\/\/([a-zA-Z0-9\-\_]+\.|)youtube\.com\/view_play_list(\?p\=|\/v\/)([a-zA-Z0-9\-\_]{16})([^<\s]*)/", $the_content, $matches, PREG_SET_ORDER);
    		foreach($matches as $match) {
    			$the_content = preg_replace("/http".$match[1].":\/\/([a-zA-Z0-9\-\_]+\.|)youtube\.com\/view_play_list(\?p\=|\/v\/)([a-zA-Z0-9\-\_]{16})([^\s<]*)/", yte_tag($match[4], $match[1], $match[5], $side), $the_content, 1);
    		}
    
    	}
    
    	// to work with migrated blogs from WordPress.com replacing [youtube=youtubeadresss]
    	if(strpos($the_content, "[youtube")!==FALSE ) {
    		preg_match_all("/\[youtube\=http:\/\/([a-zA-Z0-9\-\_]+\.|)youtube\.com\/watch(\?v\=|\/v\/)([a-zA-Z0-9\-\_]{11})([^<\s]*)\]/", $the_content, $matches, PREG_SET_ORDER);
    		foreach($matches as $match) {
    			$the_content = preg_replace("/\[youtube\=http:\/\/([a-zA-Z0-9\-\_]+\.|)youtube\.com\/watch(\?v\=|\/v\/)([a-zA-Z0-9\-\_]{11})([^\s<]*)\]/", yte_tag($match[3], '', $match[4], $side), $the_content, 1);
    		}
    	}
    
        return $the_content;
    }
    
    function yte_install(){
      if(get_option('smart_yt_posts' == '') || !get_option('smart_yt_posts')){
        add_option('smart_yt_posts', 'on');
      }
      if(get_option('smart_yt_width' == '') || !get_option('smart_yt_width')){
        add_option('smart_yt_width', '425');
      }
      if(get_option('smart_yt_height' == '') || !get_option('smart_yt_height')){
        add_option('smart_yt_height', '355');
      }
    
       if(get_option('smart_yt_widthhq' == '') || !get_option('smart_yt_widthhq')){
        add_option('smart_yt_widthhq', '480');
      }
      if(get_option('smart_yt_heighthq' == '') || !get_option('smart_yt_heighthq')){
        add_option('smart_yt_heighthq', '360');
      }
    
      if(get_option('smart_yt_widthside' == '') || !get_option('smart_yt_widthside')){
        add_option('smart_yt_widthside', '150');
      }
      if(get_option('smart_yt_heightside' == '') || !get_option('smart_yt_heightside')){
        add_option('smart_yt_heightside', '125');
      }
    
      if(get_option('smart_yt_rel' == '') || !get_option('smart_yt_rel')){
        add_option('smart_yt_rel', '1');
      }
        if(get_option('smart_yt_color' == '') || !get_option('smart_yt_color')){
        add_option('smart_yt_color', 'blank');
      }
    
      if(get_option('smart_yt_link' == '') || !get_option('smart_yt_link')){
        add_option('smart_yt_link', 'on');
      } 
    
       if(get_option('smart_yt_valid' == '') || !get_option('smart_yt_valid')){
        add_option('smart_yt_valid', 'off');
      } 
    
       if(get_option('smart_yt_search' == '') || !get_option('smart_yt_search')){
        add_option('smart_yt_search', 'off');
      }   
    
        if(get_option('smart_yt_info' == '') || !get_option('smart_yt_info')){
        add_option('smart_yt_info', 'on');
      }
    
      if(get_option('smart_yt_ann' == '') || !get_option('smart_yt_ann')){
        add_option('smart_yt_ann', 'on');
      }
    
      if(get_option('smart_yt_template' == '') || !get_option('smart_yt_template')){
        add_option('smart_yt_template', '{video}');
      } 
    
      // register widget
      if (function_exists('register_sidebar_widget'))
    		register_sidebar_widget('Smart YouTube', 'yte_widget');	
    
    	if (function_exists('register_widget_control'))
    		register_widget_control('Smart YouTube', 'yte_widgetcontrol');
    
    }
    
    function yte_widgetcontrol()
    {
    		if ($_REQUEST['submit'])
    		{
    			update_option('smart_yt_wtext', stripslashes(($_REQUEST['yte_text'])));
    			update_option('smart_yt_wtitle', stripslashes(($_REQUEST['yte_title'])));
    		}
    		$text=wp_specialchars(get_option('smart_yt_wtext'));
    		$title=wp_specialchars(get_option('smart_yt_wtitle'));
    		echo 'Title:<br /><input type="text" id="yte_title" name="yte_title" value="'.$title.'" /><br />';
    		echo 'Insert HTML code below. In addition to normal text you may use httpv, httpvh and httpvhd links just like in your posts.<br /><textarea id="text" name="yte_text" rows="10" cols="16" class="widefat">'.$text.'</textarea>';
    		echo '<input type="hidden" id="submit" name="submit" value="1" />';
    }
    
    function yte_widget($args = array() )
    {
    	extract ($args);
    	$text = yte_check((get_option('smart_yt_wtext')), 1);
    	echo $before_widget;
    	echo $before_title.(get_option('smart_yt_wtitle')).$after_title;
    	echo $text;
    	echo $after_widget; 
    
    }
    
    if (isset($_GET['activate']) && $_GET['activate'] == 'true') {
        yte_install();
    }
    
    if (get_option('smart_yt_posts')=='on')  {
    	add_filter('the_content', 'yte_check', 100);
    	add_filter('the_excerpt','yte_check', 100);
    
    }
    if (get_option('smart_yt_comments')=='on') {
    	add_filter('comment_text','yte_check', 100);
    }
    
    add_action( 'plugins_loaded', 'yte_install' );
    
    add_action( 'after_plugin_row', 'yte_check_plugin_version' );
    
    function yte_getinfo()
    {
    		$checkfile = "http://svn.wp-plugins.org/smart-youtube/trunk/smartyoutube.chk";
    		//$checkfile = "http://www.prelovac.com/plugin/smartyoutube.chk";	
    
    		$status=array();
    		return $status;
    		$vcheck = wp_remote_fopen($checkfile);
    
    		if($vcheck)
    		{
    			$version = $yte_localversion;
    
    			$status = explode('@', $vcheck);
    			return $status;
    		}
    }
    
    function yte_check_plugin_version($plugin)
    {
    	global $plugindir,$yte_localversion;
    
     	if( strpos($plugin,'smartyoutube.php')!==false )
     	{
    
    			$status=yte_getinfo();
    
    			$theVersion = $status[1];
    			$theMessage = $status[3];	
    
    			if( (version_compare(strval($theVersion), strval($yte_localversion), '>') == 1) )
    			{
    				$msg = 'Latest version available '.' <strong>'.$theVersion.'</strong><br />'.$theMessage;
    				echo '<td colspan="5" class="plugin-update" style="line-height:1.2em;">'.$msg.'</td>';
    			} else {
    				return;
    			}
    
    	}
    }
    
    ?>
    Thread Starter Pneumonic

    (@pneumonic)

    Alright. So after a bit of tinkering, I’ve actually got it so you can now choose whether you want to include excerpts or full posts within the admin page for the plugin. You can choose one or the other but not both. Right now the default length for excerpts is 500 characters, but I’ll add an option for that to be configurable later. So basically all you need to do is copy this script and paste it over your current page2cat.php file. To do that, just go to plugins -> editor. Next go to Select plugin to edit and choose Category Page and click select. It’ll bring up your page2cat.php file in the editor. Click inside it and then hit ctrl+a (cmd+a) and then hit ctrl+v(cmd+v) and then click update file. It contains all the same functionality of the previous plugin, but adds in the option for excerpts and full posts.

    <?php
    /*
    Plugin Name: Category Page
    Plugin URI: http://pixline.net/wordpress-plugins/category-page-wordpress-plugin/en/
    Description: Use pages as category archive header, or list some posts from a category into a post/page.
    Author: Pixline
    Version: 2.5
    Author URI: http://pixline.net/
    
    Copyright (C) 2008 Paolo Tresso / Pixline (http://pixline.net/)
    
    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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    
    Revisions for excerpts and full posts done by John P. Neumann (john@animateshmanimate.com)
    
    List of Revisions
    
    * added 2 rows to the database named p2c_post_settings and p2c_excerpt_settings
    * added options to admin page for posts and excerpts
    * added code for both posts and settings to be available (although not at the same time)
    * added additional code for settings to be available
    * added the functionality
    * added code to disable both excerpts and posts if they are both checked since that would be stupid
    
    */
    if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) { die('You are not allowed to call this page directly.'); }
    
    define("PAGE2CAT_VERSION","2.5");
    define("PLUGIN_PATH",get_bloginfo('url')."/wp-content/plugins/page2cat/");
    
    define('PIXLINE_FOOTER','<p><hr style="margin-top:50px;height:1px;background:#CCC;border:0px;clear:both;" />
    <strong>
    <a href="http://pixline.net/wordpress-plugins/category-page-wordpress-plugin/en/">Category Page</a></strong> plugin
    <small> |
    <a href="http://talks.pixline.net/forum.php?id=3">Support Forum</a> |
    GPL2&copy; &ge; 2007 <a href="http://pixline.net/about/en/">Paolo Tresso / Pixline</a> |
    If you like this plugin, support its development with a <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=paolo%40pixline%2enet&item_name=Support%20to%20opensource%20projects%20at%20Pixline&no_shipping=1&cn=Something%20to%20say%3f&tax=0&currency_code=EUR&lc=IT&bn=PP%2dDonationsBF&charset=UTF%2d8">small donation</a>.</p>');
    
    $wpdb->page2cat	= $table_prefix . 'page2cat';
    
    ######################################################
    # check version. #
    ######################################################
    
    $p2c_version = get_option('pixline_page2cat_version');
    	register_activation_hook(__FILE__, 'page2cat_install');
    
    // DB installation. usually happen just one time.
    function page2cat_install(){
    global $wpdb, $p2c_version;
    
    if ($version < 6):
    	$query = "
    	CREATE TABLE  <code>&quot;.$wpdb->prefix.&quot;page2cat</code> (
    	 <code>rel_ID</code> BIGINT NOT NULL AUTO_INCREMENT ,
    	 <code>page_ID</code> BIGINT NOT NULL ,
    	 <code>cat_ID</code> BIGINT NOT NULL ,
    	PRIMARY KEY (  <code>rel_ID</code> ) ,
    	INDEX (  <code>page_ID</code> ,  <code>cat_ID</code> )
    	);
    	";
    
    	if(is_file(ABSPATH . 'wp-admin/includes/upgrade.php')){
    		require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    	}elseif(is_file(ABSPATH . 'wp-admin/upgrade-functions.php')){
    		require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
    	}
    
    	if($wpdb->get_var("SHOW TABLES LIKE '".$wpdb->prefix."page2cat'") != $wpdb->prefix."page2cat") {
    	dbDelta($query);
    	delete_option('pixline_page2cat_version');
    	add_option('pixline_page2cat_version', 6);
    	}
    
    update_option('p2c_use_empty','false');
    update_option('p2c_show_used_pages','false');
    update_option('p2c_catlist_limit',5);
    update_option('p2c_catlist_title','');
    update_option('p2c_excerpt_settings','');
    update_option('p2c_post_settings','');
    endif;
    
    delete_option('p2c_use_img');		// deprecated, so we're going to delete it anyway.
    if( !get_option('p2c_use_empty')) 		update_option('p2c_use_empty','false');
    if(!get_option('p2c_show_used_pages')) 	update_option('p2c_show_used_pages','false');
    if(!get_option('p2c_catlist_limit')) 	update_option('p2c_catlist_limit',5);
    if(!get_option('p2c_catlist_title')) 	update_option('p2c_catlist_title','');
    }
    if(!get_option('p2c_excerpt_settings')) update_option('p2c_excerpt_settings','');
    if(!get_option('p2c_post_settings')) update_option('p2c_post_settings','');
    
    ######################################
    # setup management and option panels #
    ######################################
    
    // adds a panel under "manage » category pages"
    // shows actual connections, and allow creations of new ones.
    function page2cat_manage_page(){
    global $wpdb, $wp_db_version;
    
    	#print_r($_POST); #die();
    
    	// multiple delete
    	if( isset($_POST['deleteit']) && !empty($_POST['p2c_reldel'])):
    		foreach($_POST['p2c_reldel'] as $key=>$id):
    			$query = "DELETE FROM {$wpdb->page2cat} WHERE rel_ID = '".$id."' LIMIT 1;";
    			$daje = $wpdb->get_results($query);
    		endforeach;
    	echo '<div id="message" class="updated fade">
    			<p><strong>Some connections deleted.</strong></p></div>';
    	endif;
    
    	// multiple link
    	if( isset($_POST['action']) && $_POST['p2c_linkto'] == true && $_POST['multipageid'] != ""):
    #	print_r($_POST);
    		$pageid = $_POST['multipageid'][0];
    		foreach($_POST['p2c_reladd'] as $key=>$id):
    		if(trim($id)!=""):
    			$query = "INSERT INTO {$wpdb->page2cat} (rel_ID, page_ID, cat_ID) VALUES ('', '".$pageid."', '".$id."');";
    			$daje = $wpdb->get_results($query);
    		endif;
    		endforeach;
    		echo '<div id="message" class="updated fade">
    			<p><strong>Connections created.</strong></p></div>';
    
    	elseif( isset($_POST['action']) && $_POST['p2c_update'] == true):
    #	print_r($_POST); die();
    		$pageid = $_POST['pageid'];
    		foreach($pageid as $cat_id=>$page_id):
    			if(trim($page_id) != ""):
    			$sql = "INSERT INTO {$wpdb->page2cat} (rel_ID, page_ID, cat_ID) VALUES ('', '".$page_id."', '".$cat_id."');";
    			$result = $wpdb->get_results($sql);
    			endif;
    		endforeach;
    		echo('<div id="message" class="updated fade">
    		<p><strong>New Category Page created succesfully.</strong></p></div>');
    	endif;
    
    	// single delete, confirm request
    	if( isset($_REQUEST['p2cdel']) && !isset($_REQUEST['p2c_confirm']) ):
    		$relid = $wpdb->escape($_REQUEST['p2cdel']);
    		echo "<div class='wrap'><h2>Delete this Category &rsaquo; Page relation?</h2>";
    		$opt = $wpdb->get_results("SELECT * FROM {$wpdb->page2cat} WHERE rel_ID = '".$relid."' LIMIT 1;");
    		$catid = $opt[0]->cat_ID;
    		$pageid = $opt[0]->page_ID;
    		$catname = get_cat_name($catid);
    		$page = get_page($pageid);
    		$title = $page->post_title;
    		echo "<form name='p2c_confirm' method='post'>";
    		echo "<p>You are going to delete the relationship between
    		Category <em>".$catname."</em> and Page <em>".$title."</em>. Confirm?</p>";
    		echo '<p>
    		<input type="hidden" name="p2cdel" value="'.$relid.'" />
    		<input type="hidden" name="p2c_confirm" value="true" />
    		<input type="reset" name="revert" value="Cancel" />
    		<input type="submit" name="confirm" value="DELETE &raquo;" />
    		</p></form>';
    		echo "</div>";
    	endif;
    
    	// confirmed, so delete this connection
    	if( isset($_REQUEST['p2cdel']) && $_REQUEST['p2c_confirm'] == 'true'):
    	$relid = $wpdb->escape($_REQUEST['p2cdel']);
    	$myopts = $wpdb->get_results("DELETE FROM {$wpdb->page2cat} WHERE rel_ID = '".$relid."' LIMIT 1;");
    	echo('<div id="message" class="updated fade"><p><strong>You have succesfully deleted a connection.</strong></p></div>');
    	echo "<div class='wrap'><a href='edit.php?page=category-pages'>Back to Category Pages manage page</a></div>";
    	endif;
    
    	/*
    		real pages
    	*/
    	$count_used = $wpdb->get_var("SELECT count(*) FROM {$wpdb->page2cat};");
    
    	if($wp_db_version >= 6124):	// this is WordPress >= 2.3
    	$count_full = $wpdb->get_var("SELECT count(*)
    		FROM {$wpdb->terms} AS t LEFT JOIN {$wpdb->term_taxonomy} AS tt
    		ON t.term_id = tt.term_id WHERE tt.taxonomy='category';");
    
    	$count_noempty = $wpdb->get_var("SELECT count(*)
    		FROM {$wpdb->terms} AS t LEFT JOIN {$wpdb->term_taxonomy} AS tt
    		ON t.term_id = tt.term_id WHERE tt.taxonomy='category' AND tt.count != '0';");
    	else: // WP < 2.3
    	$count_full = $wpdb->get_var("SELECT count(*) FROM {$wpdb->categories};");
    	$count_noempty = $wpdb->get_var("SELECT count(*) FROM {$wpdb->categories}; WHERE category_count != '0';");
    	endif;
    
    	$count_free = $count_full - $count_used;
    	if(get_option('p2c_use_empty') == "false"): $count_usable = $count_noempty - $count_used; else : $count_usable = $count_free; endif;
    
    	// this is the already connected page
    
    	$myopts = $wpdb->get_results("SELECT * FROM {$wpdb->page2cat} ORDER BY page_ID ASC;");
    	$usedcats = array();
    	$usedpages = array();
    
    		if($_REQUEST['view'] == 'new'):
    			$css1 = ''; 	$css2 = ' class="current"';
    			$pagetitle = "<small>New connection</small>";
    		else:
    			$css1 = ' class="current"'; $css2 = '';
    			$pagetitle = "<small>Manage connections</small>";
    		endif;
    
    	if( !isset($_REQUEST['p2cdel'])):
    		echo "<div class='wrap'><h2>Category Pages</h2>";
    		echo '<ul class="subsubsub">
    		<li><a href="edit.php?page=category-pages"'.$css1.'>Manage connections ('.$count_used.')</a> |</li>
    		<li><a href="edit.php?page=category-pages&view=new"'.$css2.'>Free categories ('.$count_usable.'/'.$count_free.')</a></li>
    		</ul>';
    
    if($_REQUEST['view'] != 'new'):
    
    		if(count($myopts) != 0):
    #		echo "<div><p>These categories and these pages are already connected each other. You can view the category page in your website, clicking on the Category name. You can also edit or delete each connection.</p>";
    
    		echo "<div class='tablenav'>";
    		echo "<div class='tablenav-pages'>&nbsp;</div>";
    		echo '<div style="float: left">
    			<form id="p2c_del" name="p2c_del" method="post"/>
    			<input type="hidden" name="page" value="category-pages" />
    			<input type="hidden" name="view" value="'.$_REQUEST['view'].'" />
    			<input type="hidden" name="action" value="p2c_del" />
    			<input type="submit" value="Delete Checked" name="deleteit" class="button-secondary delete" />
    			</div>';
    		echo "<br style='clear:both;' />";
    		echo "</div>";
    
    		echo "<br style='clear:both;' />";
    		echo '
    			';
    		echo "<table class='widefat'>";
    			echo "<thead>";
    			echo "<tr>
    				<th>";
    			if($wp_db_version >= 7098): echo "<input type='checkbox' onclick='checkAll(document.getElementById(\"p2c_del\"));' />" ;
    				else: echo "&nbsp;"; endif;
    			echo "</th>
    			<th>Host <strong>Category</strong></th>
    			<th>Header <strong>Page</strong></th>
    			<th>&nbsp;</th>
    			</tr>";
    			echo "</thead><tbody>";
    		foreach($myopts as $opt):
    			$catid = $opt->cat_ID;
    			$pageid = $opt->page_ID;
    			$catname = get_cat_name($catid);
    			$usedcats[] = $catid;
    			$usedpages[] = $pageid;
    			$page = get_page($pageid);
    			$title = $page->post_title;
    
    		echo "<tr>
    			<td><input type='checkbox' value='".$opt->rel_ID."' name='p2c_reldel[]' class='p2cbox' /></td>
    			<td><strong><a href='../?cat=".$catid."' title='View this Category Page in your website.'>".$catname."</a></strong>
    				<!-- (cat #".$catid.") --></td>
    			<td><strong><a href='page.php?action=edit&post=".$pageid."' title='Edit this page.'>".$title."
    				<!-- (page #".$pageid.") --></td>
    			<td><a href='?page=category-pages&p2cdel=".$opt->rel_ID."' class='delete' title='Delete this connection permanently.'>Delete</a></td>
    			</tr>";
    		endforeach;
    
    		echo "</tbody>";
    		echo "</table>";
    
    		echo "<div class='tablenav'>";
    		echo "<div class='tablenav-pages'>&nbsp;</div>";
    		echo '<div style="float: left">
    			<form name="p2c_del" method="post"/>
    			<input type="hidden" name="page" value="category-pages" />
    			<input type="hidden" name="view" value="'.$_REQUEST['view'].'" />
    			<input type="hidden" name="action" value="p2c_del" />
    			<input type="submit" value="Delete Checked" name="deleteit" class="button-secondary delete" />
    			</form>
    			</div>';
    		echo "<br style='clear:both;' />";
    		echo "</div>";
    
    		else:
    
    		echo "<p>Sorry, no Category &raquo; Page connection available (yet). Maybe you want to <a href='edit.php?page=category-pages&view=new'>create some new connections</a>?</p>";
    		endif;
    
    else:
    // this is the 'new' page
    
    		$usedcats = $wpdb->get_col("SELECT cat_ID FROM {$wpdb->page2cat};");
    #		print_r($usedcats);
    		$opt3 = get_option('p2c_use_empty');
    		if($opt3 == "true"): $empty = false; $excats = ""; elseif($opt3 == "false"): $empty = true; $excats = implode(',',$usedcats); endif;
    
    		$catdef = array('type' => 'post', 'child_of' => 0, 'orderby' => 'name', 'order' => 'ASC',
    		'hide_empty' => $empty, 'include_last_update_time' => false, 'hierarchical' => true,
    		'exclude' => $excats, 'include' => '', 'number' => '', 'pad_counts' => true);
    		$others = get_categories($catdef);
    
    		$used = count($usedcats);
    		$count = count($others);
    
    		if( $count == 0):
    		echo "<p>Sorry, you don't have any usable category (or there are some, but empty; <a href='options-general.php?page=category-page-options'>check your settings</a>).</p>";
    		else:
    #		echo "<h3>New connections</h3>";
    #		echo "<div><p>These categories aren't connected with any page. Here you can setup a connection with an existent page, or create a brand new one.</p>";
    
    		echo "<form id='page2cat_manage' name='page2cat_manage' method='post'>";
    		$pages_already_used = implode(',',$usedpages);
    		if(get_option('p2c_show_used_pages')=='true') $exclude = $pages_already_used; else $exclude ="";
    
    		// wp_dropdown_pages settings (for both boxes in this page)
    		$pre_ddprefs = array('depth' => 0, 'child_of' => 0, 'selected' => 0,
    			'echo' => 0,'name' => 'multipageid[]', 'exclude' => $exclude,
    			'show_option_none' => '(none)');
    
    /*
    		echo "<div class='tablenav'>";
    		echo "<div class='tablenav-pages'>
    			<input type='submit' name='p2c_update' value='Update Category Pages' class='button'/>
    			<br style='clear:both;' />
    			</div>";
    		echo '<div style="float:left;">
    			<input type="hidden" name="page" value="category-pages" />
    			<input type="hidden" name="view" value="'.$_REQUEST['view'].'" />
    			<input type="hidden" name="action" value="p2c_multilink" />
    			Link checked to:
    			'.wp_dropdown_pages($pre_ddprefs).'
    			<input type="submit" value="Link them!" name="p2c_linkto" class="button-secondary" />
    			</div>';
    		echo "<br style='clear:both;'/>&nbsp;<br style='clear:both;' />";
    		echo "</div>";
    */
    			echo "<table class='widefat'>";
    			echo "<thead>";
    			echo "<tr>
    			<th>";
    			if($wp_db_version >= 7098): echo "<input type='checkbox' onclick='checkAll(document.getElementById(\"page2cat_manage\"));' />";
    				else: echo "&nbsp;"; endif;
    			echo "</th>";
    			echo "<th>Host Category</th>
    			<th>Choose Page</th>
    			<th>Create New Page</th>
    			</tr>";
    			echo "</thead><tbody>";
    
    			foreach($others as $otro):
    			switch($wp_db_version):
    			// "7098"=>"2.5",	"6124"=>"2.3.3", "5183"=>"2.2.1", "4773"=>"2.1.3"
    				case ( $wp_db_version < 5183 ):	// WP 2.1.3 and smaller
    				$versioned_catid = $otro->cat_ID;
    				$versioned_catname = $otro->cat_name;
    				$versioned_slug = $otro->category_nicename;
    				$versioned_count = $otro->category_count + $otro->posts_private;
    				break;
    				case ( $wp_db_version >= 5183 ):	// WP 2.2.1 and greater
    				default:
    				$versioned_catid = $otro->term_id;
    				$versioned_catname = $otro->name;
    				$versioned_slug = $otro->category_nicename;
    				$versioned_count = $otro->count;
    				break;
    			endswitch;
    
    			// wp_dropdown_pages settings
    			$ddprefs = array('depth' => 0, 'child_of' => 0, 'selected' => 0,
    				'echo' => 0,'name' => 'pageid['.$versioned_catid.']',
    				'exclude' => $exclude, 'show_option_none' => '(none)');
    
    			$output = "<tr>
    			<td><input type='checkbox' value='".$versioned_catid."' name='p2c_reladd[]' /></td>
    			<td>".$versioned_catname." <!-- (".$versioned_count.") --></td>
    			<td>".wp_dropdown_pages($ddprefs)."</td>";
    			$output .= "<td><a href='page-new.php?p2c=".$versioned_catid."'>Create New</a></td>
    			</tr>";
    
    			$stringhe[$versioned_catname] = $output;
    			endforeach;
    
    			asort($stringhe);
    			reset($stringhe);
    
    			foreach($stringhe as $stringa):
    				echo $stringa;
    			endforeach;
    
    			echo "</tbody>";
    			echo "</table>";
    
    			echo "<div class='tablenav'>";
    			echo "<div style='float:right;'>
    				<input type='submit' name='p2c_update' value='Update Category Pages' class='button'/>
    				</div>";
    			echo '<div style="float:left;">
    				<input type="hidden" name="page" value="category-pages" />
    				<input type="hidden" name="view" value="'.$_REQUEST['view'].'" />
    				<input type="hidden" name="action" value="p2c_multilink" />
    				Link checked to:
    				'.wp_dropdown_pages($pre_ddprefs).'
    				<input type="submit" value="Link them!" name="p2c_linkto" class="button-secondary" />
    				</div>';
    			echo "<br style='clear:both;'/>";
    			echo "</div>";
    endif;
    
    		echo "</form>";
    		endif;
    		echo PIXLINE_FOOTER;
    		echo "</div>";
    	endif;
    }
    
    // adds styles in admin head (WP 2.5+)
    function page2cat_metabox_styles(){
    ?>
    <style type="text/css" media="screen">
    #p2c-scroller{
    	width:100%;
    }
    
    ul#p2c-bind li, ul#p2c-free li{
    	list-style-type:none;
    	width:32%;
    	float:left;
    	font-size:80%;
    }
    
    .p2c-cleaner{
    	clear:both;
    	height:1px;
    }
    .p2c-used{
    	color:#D66;
    	text-decoration:line-through;
    }
    .p2c-catlink{
    	color:#000;
    	text-decoration:none;
    	border-bottom:1px dotted #CCC;
    }
    </style>
    <?php
    wp_enqueue_script('admin-forms');
    }
    
    // adds styles in admin head (WP < 2.5)
    function page2cat_sidebox_styles(){
    ?>
    <style type="text/css" media="screen">
    #p2c-scroller{
    	height:120px;
    	overflow:auto;
    	width:90%;
    	margin:0% 5%;
    }
    
    #p2c-box p{
    	margin:0px;
    	padding:5px;
    	font-size:80%;
    }
    
    ul#p2c-bind, ul#p2c-free,
    ul#p2c-bind li, ul#p2c-free li{
    	margin:0px;
    	padding:0px;
    	list-style-type:none;
    }
    
    ul#p2c-bind{
    	font-size:90%;
    	margin:1% 0%;
    }
    
    ul#p2c-free{
    	font-size:80%;
    	color:#333;
    	margin:2%;
    }
    
    ul#p2c-free li{
    	padding:2px 1px;
    }
    
    .p2c-count{
    	color:#AAA;
    }
    
    .p2c-indent{
    	padding-left:10px;
    }
    
    .p2c-used{
    	color:#D66;
    	text-decoration:line-through;
    }
    
    .p2c-catlink{
    	color:#000;
    	text-decoration:none;
    	border-bottom:1px dotted #CCC;
    }
    
    </style>
    <?php
    }
    
    // adds sidebox in page editing (until WP 2.3x)
    function page2cat_add_sidebox($post_ID){
    ?>
    <fieldset id="p2c-select" class="dbx-box">
    <h3 class="dbx-handle">Category Pages</h3>
    <div class="dbx-content" id="p2c-box">
    	<?php page2cat_add_meta_box($post_ID);	?>
    </div>
    </fieldset>
    <?php
    
    }
    
    function page2cat_add_meta_box($post_ID){
    	global $wpdb, $post_ID, $_REQUEST;
    #	if(isset($_REQUEST['p2c'])):
    #	endif;
    
    	$mypage = $wpdb->get_results("SELECT * FROM {$wpdb->page2cat} WHERE page_ID = '".$post_ID."';",OBJECT);
    	?>
    		<p>Use this page as <a href='edit.php?page=category-pages'>Category Page</a> for these categories.</p>
    	<?php
    	$usedcats = array();
    	if(count($mypage)>0):
    		echo "<ul id='p2c-bind'>";
    		foreach($mypage as $connection):
    	#		print_r($connection);
    			echo "<li><input type='checkbox' checked='checked' value='".$connection->cat_ID."' name='p2c_bind[]'
    			id='p2c".$connection->cat_ID."' /> ".get_cat_name($connection->cat_ID)."</li>
    			";
    			$usedcats[] = $connection->cat_ID;
    		endforeach;
    		echo "</ul>";
    	endif;
    
    		$opt3 = get_option('p2c_use_empty');
    		if($opt3 == "true"): $empty = false; $exclude = "";
    		elseif($opt3 == "false"): $empty = true; $exclude = implode(',',$usedcats);
    		endif;
    
    	$catdef = array('type' => 'post', 'child_of' => 0, 'orderby' => 'name', 'order' => 'ASC', 'exclude' => $exclude,
    					'hide_empty' => $empty, 'include_last_update_time' => false, 'hierarchical' => true, 'pad_counts' => true);
    
    	$others = get_categories($catdef);
    	echo "<div id='p2c-scroller'>";
    	echo "<ul id='p2c-free'>";
    	foreach($others as $cat):
    	#print_r($cat); exit();
    	if($cat->cat_ID == $_REQUEST['p2c']): $flag = "checked='checked'"; else: $flag = ""; endif;
    
    	$has_page = $wpdb->get_var("SELECT count(*) FROM {$wpdb->page2cat} WHERE cat_ID = '".$cat->cat_ID."'");
    	if($has_page == 0):
    	echo "<li><input type='checkbox' name='p2c_bind[]' id='p2c".$cat->cat_ID."' value='".$cat->cat_ID."' ".$flag."/> "
    	."<a class='p2c-catlink' href='../?cat=".$cat->cat_ID."' title='".get_cat_name($cat->cat_ID)." (".$cat->category_count." items inside).'>".get_cat_name($cat->cat_ID)."</a></li>
    	";
    	else:
    #	echo "<li><input type='checkbox' disabled='disabled' name='p2c_bind[]' id='p2c".$cat->cat_ID."' value='".$cat->cat_ID."'/> <span class='p2c-used'>"
    #	.get_cat_name($cat->cat_ID)." </span><span class='p2c-count'>(".$cat->category_count." items)</span></li>
    #	";
    	$nothing = 0;
    	endif;
    	endforeach;
    	echo "</ul>";
    	echo "<br style='clear:both;' />";
    	echo "</div>";
    	?>
    	<?php
    }
    
    // trigger page save/edit and make db relations
    function page2cat_trigger_save($post_ID){
    global $wpdb;
    
    $values = $_POST['p2c_bind'];
    $via = "DELETE FROM {$wpdb->page2cat} WHERE page_ID = '".$_POST['post_ID']."'";
    $result = $wpdb->get_results($via);
    if(count($values) > 0):
    foreach($values as $key=>$cat){
    	if($_POST['post_ID'] != ""):
    	$sql = "INSERT INTO {$wpdb->page2cat} (rel_ID, page_ID, cat_ID) VALUES ('','".$_POST['post_ID']."','".$cat."')";
    	$result = $wpdb->get_results($sql);
    	endif;
    }
    endif;
    }
    
    // trigger page deletion and free db relations
    function page2cat_trigger_delete(){
    	// yes, there's no trigger, actually....
    }
    
    // add the function for neat_trim
    function neat_trim($str, $n, $delim='...') {
    $str = str_replace("\n","",$str);
    //$str = str_replace("\r",",$str);
    $str = strip_tags($str);
      $len = strlen($str);
       if ($len > $n) {
           preg_match('/(.{' . $n . '}.*?)\b/', $str, $matches);
           return rtrim($matches[1]) . $delim;
       }
       else {
           return $str;
       }
    }
    
    // filter the content of a page, check for tag and replace it with a list of posts in the requested category.
    // function heavily inspired from Alex Rabe NextGen Gallery's nggfunctions.php.
    function page2cat_content_catlist($content){
    global $post;
    $excerpt_settings=get_option('p2c_excerpt_settings');
    $post_settings=get_option('p2c_post_settings');
    
    // Show excerpts
    if($excerpt_settings == "on")
    {
    	if ( stristr( $content, '[catlist' )) {
    		$search = "@(?:<p>)*\s*\[catlist\s*=\s*(\w+|^\+)\]\s*(?:</p>)*@i";
    		if	(preg_match_all($search, $content, $matches)) {
    			if (is_array($matches)) {
    				$title = get_option('p2c_catlist_title');
    				if($title != "") $output = "<h4>".$title."</h4>"; else $output = "";
    				$limit = get_option('p2c_catlist_limit');
    				foreach ($matches[1] as $key =>$v0) {
    					$catposts = get_posts('category='.$v0."&numberposts=".$limit);
    						foreach($catposts as $single):
                                                    $single_post_content = $single->post_content;
    												$excerpt_length = 500;
    												$excerpt = neat_trim($single_post_content, $excerpt_length);
    												$excerpt .= "<a href='".get_permalink($single->ID)."'>more</a>";
    												$output .= "<h2><a href='".get_permalink($single->ID)."'>".$single->post_title."</a></h2><p>". $excerpt ."</p>";
    						endforeach;
    					$search = $matches[0][$key];
    					$replace= $output;
    					$content= str_replace ($search, $replace, $content);
    				}
    			$output .= "";
    			}
    		}
    	}
    // Show full posts
    }elseif($post_settings == "on")
    {
    	if ( stristr( $content, '[catlist' )) {
    		$search = "@(?:<p>)*\s*\[catlist\s*=\s*(\w+|^\+)\]\s*(?:</p>)*@i";
    		if	(preg_match_all($search, $content, $matches)) {
    			if (is_array($matches)) {
    				$title = get_option('p2c_catlist_title');
    				if($title != "") $output = "<h4>".$title."</h4>"; else $output = "";
    				$limit = get_option('p2c_catlist_limit');
    				foreach ($matches[1] as $key =>$v0) {
    					$catposts = get_posts('category='.$v0."&numberposts=".$limit);
    						foreach($catposts as $single):
                                                    $single_post_content = $single->post_content;
                                                    $excerpt = $single_post_content;
    						$output .= "<h2><a href='".get_permalink($single->ID)."'>".$single->post_title."</a></h2><p>". $excerpt ."</p>";
    						endforeach;
    					$search = $matches[0][$key];
    					$replace= $output;
    					$content= str_replace ($search, $replace, $content);
    				}
    			$output .= "";
    			}
    		}
    	}
    // show just a list
    }else
    {
    	if ( stristr( $content, '[catlist' )) {
    		$search = "@(?:<p>)*\s*\[catlist\s*=\s*(\w+|^\+)\]\s*(?:</p>)*@i";
    		if	(preg_match_all($search, $content, $matches)) {
    			if (is_array($matches)) {
    				$title = get_option('p2c_catlist_title');
    				if($title != "") $output = "<h4>".$title."</h4>"; else $output = "";
    				$output .= "<ul class='p2c_catlist'>";
    				$limit = get_option('p2c_catlist_limit');
    				foreach ($matches[1] as $key =>$v0) {
    					$catposts = get_posts('category='.$v0."&numberposts=".$limit);
    						foreach($catposts as $single):
    						$output .= "<li><a href='".get_permalink($single->ID)."'>".$single->post_title."</a></li>";
    						endforeach;
    					$search = $matches[0][$key];
    					$replace= $output;
    					$content= str_replace ($search, $replace, $content);
    				}
    			$output .= "</ul>";
    			}
    		}
    	}
    
    }
    return $content;
    }
    
    // add real option page
    function page2cat_options_page(){
    global $wpdb, $styles;
    
    $p2c_defaults = array("show_usedpages_yes"=>"","show_usedpages_no"=>"","use_empty_no"=>"", "use_empty_yes"=>"", "catlist_limit"=>"", "catlist_title"=>"");
    
    if(isset($_POST['page2cat_action'])):
    #print_r($_POST); #die();
    	$sane1 = strip_tags(htmlentities($_POST['p2c_catlist_limit']));
    	update_option('p2c_catlist_limit',$sane1);
    	$sane4 = strip_tags(htmlentities($_POST['p2c_catlist_title']));
    	update_option('p2c_catlist_title',$sane4);
    	$sane2 = strip_tags(htmlentities($_POST['p2c_show_used_pages']));
    	update_option('p2c_show_used_pages',$sane2);
    	$sane3 = strip_tags(htmlentities($_POST['p2c_use_empty']));
    	update_option('p2c_use_empty',$sane3);
    	$excerpt_settings = !isset($_POST['excerpt_settings'])? 'off': 'on';
    	update_option('p2c_excerpt_settings', $excerpt_settings);
    	$post_settings = !isset($_POST['post_settings'])? 'off': 'on';
    	update_option('p2c_post_settings', $post_settings)? 'off': 'on';
    	if($excerpt_settings == $post_settings){
    		echo('<div id="message" class="updated fade"><p><strong>ERROR! You cannot have both Excerpts and Posts set! Setting both to off!</strong></p></div');
    		update_option('p2c_excerpt_settings', 'off');
    		update_option('p2c_post_settings', 'off');
    	}else{
    
    	echo('<div id="message" class="updated fade"><p><strong>Settings saved.</strong></p></div>');
    }
    endif;
    
    $opt3 = get_option('p2c_use_empty');
    if($opt3 == "false"){
    	$p2c_defaults['use_empty_no'] = ' selected="selected"';
    }elseif($opt3 == "true"){
    	$p2c_defaults['use_empty_yes'] = ' selected="selected"';
    }
    
    $opt2 = get_option('p2c_show_used_pages');
    if($opt2 == "false"){
    	$p2c_defaults['show_usedpages_no'] = ' selected="selected"';
    }elseif($opt2 == "true"){
    	$p2c_defaults['show_usedpages_yes'] = ' selected="selected"';
    }
    
    $excerpt_settings = (get_option('p2c_excerpt_settings')=='on') ? 'checked':'';
    $post_settings = (get_option('p2c_post_settings')=='on') ? 'checked':'';
    
    $p2c_catlist_title = get_option('p2c_catlist_title');
    
    	echo "<div class='wrap'>";
    	echo "<h2>Category Page settings</h2>";
    	echo "<form method='post' name='page2cat_options' accept-charset='utf-8'>";
    
    	echo '
    	<h3>Management settings</h3>
    	<p>These settings let you customize your <a href="edit.php?page=category-pages">Category Page management panel</a>.</p>
    	<table class="form-table">
    	<tr valign="top">
    	<th scope="row">Show empty categories</th>
    	<td>
    	<select name="p2c_use_empty">
    	<option value="false"'.$p2c_defaults['use_empty_no'].' label=" No, thanks. "> No, thanks. </option>
    	<option value="true"'.$p2c_defaults['use_empty_yes'].' label=" Yes, please! "> Yes, please! </option>
    	</select> <small>(Choose whether empty categories are shown or not. )</small>
    	</td>
    	</tr>
    
    	<tr valign="top">
    	<th scope="row">Allow single page sharing</th>
    	<td>
    	<select name="p2c_show_used_pages">
    	<option value="false"'.$p2c_defaults['show_usedpages_no'].' label=" No, thanks. "> No, thanks. </option>
    	<option value="true"'.$p2c_defaults['show_usedpages_yes'].' label=" Yes, please! "> Yes, please! </option>
    	</select> <small>(You can share a single page with more than a category, if you like.)</small>
    	</td>
    	</tr>
    
    	</table>
    
    	<h3><code>[catlist]</code> tag settings</h3>
    	<p>You can use a <em>[catlist=xx]</em> tag in a post/page to show a list of post from a certain category, replacing <em>xx</em> with the category ID.</p>
    	<table class="form-table">
    	<tr valign="top">
    	<th scope="row">Display at most </th>
    	<td>
    	<select name="p2c_catlist_limit">';
    
    	$limits = array(1,2,3,4,5,6,7,8,9,10,15,20,25);
    	foreach($limits as $limit):
    		if(get_option('p2c_catlist_limit') == $limit) $flag = "selected='selected'"; else $flag = "";
    		echo "<option value='".$limit."' name='opt".$limit."' ".$flag.">".$limit."</option>";
    	endforeach;
    
    	echo '</select> posts.
    	</td>
    	</tr>
    
    	<tr valign="top">
    	<th scope="row">Display list title</th>
    	<td><input type="text" name="p2c_catlist_title" value="'.$p2c_catlist_title.'" size="30"/>
    	<small>(Leave empty to show a post list without a title.)</small>
    	</td>
    	</tr>
    	</table>
    
    	<h3>Excerpt or Full Post Settings</h3>
    	<p>You can choose to display full posts or excerpts only by checking one of the boxes. Do not check both as it will error out. Excerpts will be 500 characters for now until I add in another option for it.</p>
    	<table class="form-table">
    	<tr valign="top">
    	<td><input id="check5" type="checkbox" name="excerpt_settings"'.$excerpt_settings.' />
    	<label for="check5">Display only excerpts?</label></td>
    	</tr>
    	<tr valign="top">
    	<td><input id="check6" type="checkbox" name="post_settings"'.$post_settings.' />
    	<label for="check6">Display full posts?</label></td>
    	</tr>
    
    	</table>
    
    	';	
    
    	echo '<p class="submit">
    	<input type="hidden" name="page2cat_action" value="update" />
    	<input type="submit" name="update" value="Update Settings" />
    	</p>
    	</fieldset>';
    
    	echo '</form>';
    	echo PIXLINE_FOOTER;
    	echo "</div>";
    }
    
    // template function for manual hacks and widgets :-)
    function page2cat_output($cat, $style = 'getpost', $useimg = 1){
    global $wpdb;
    
    	$useimg = get_option('p2c_use_img');
    	$mypage = $wpdb->get_row("SELECT * FROM {$wpdb->page2cat} WHERE cat_ID = '".$cat."';",OBJECT);
    #	print_r($mypage);
    	$pageid = $mypage->page_ID;
    	if($pageid != ""):
    
    	switch($style):
    
    	case 'getpost':
    	?>
    	<div id="category-page-header">
    	<?php
    	$post = $post_temp;
    	$post = get_post($pageid);
    	setup_postdata($post);
    
    	if($post->post_title!=""){
    				?>
    				<div id="p2c-header">
    					<h2><?php echo $post->post_title; ?></h2>
    					<p><?php the_content(); ?></p>
    				</div>
    		<div class="category-page-cleaner"></div>
    	</div>
    	<?php
    	$post = $post_temp;
    	}
    	break;
    
    	case 'widget':
    	?>
    	<div id="category-widget-header">
    	<?php
    	$pagina = "SELECT * FROM {$wpdb->posts} WHERE ID='".$pageid."' AND post_type = 'page';";
    	$mine = $wpdb->get_results($pagina);
    	if($mine[0]->post_title!=""){
    				?>
    				<div id="p2c-header">
    					<!-- h2><?php echo $mine[0]->post_title; ?></h2 -->
    					<p><?php echo wptexturize($mine[0]->post_content,1); ?></p>
    				</div>
    		<div class="category-widget-cleaner"></div>
    	</div>
    	<?php
    	}
    
    	break;
    	case 'inline':
    	default:
    	?>
    	<div id="category-page-header">
    	<?php
    	$pagina = "SELECT * FROM {$wpdb->posts} WHERE ID='".$pageid."' AND post_type = 'page';";
    	$mine = $wpdb->get_results($pagina);
    	if($mine[0]->post_title!=""){
    				?>
    				<div id="p2c-header">
    					<h2><?php echo $mine[0]->post_title; ?></h2>
    					<p><?php echo wptexturize($mine[0]->post_content,1); ?></p>
    				</div>
    		<div class="category-page-cleaner"></div>
    	</div>
    	<?php
    	}
    	break;
    
    	endswitch;
    
    	?>
    	<?php
    	else:
    	echo '<h2 class="pagetitle">Archive for the ‘'.single_cat_title('',false).'’ Category</h2>';
    	endif;
    }
    
    // adds sidebox in page write/edit
    function page2cat_init(){
    	if (function_exists('add_meta_box')) {
    		add_meta_box('page2cat','Category Page Options', 'page2cat_add_meta_box', 'page');
    		add_action('admin_head','page2cat_metabox_styles');
    	} else {
    		add_action('dbx_page_sidebar', 'page2cat_add_sidebox');
    		add_action('admin_head','page2cat_sidebox_styles');
    	}
    }
    // install management and options page
    function page2cat_config_page() {
    	if ( function_exists('add_submenu_page') && is_admin()):
    	add_submenu_page('edit.php', __('Category Pages'), __('Category Pages'), 8, 'category-pages', 'page2cat_manage_page');
    	endif;
    	if( function_exists('add_options_page') && is_admin()):
    	add_options_page('Category Pages options','Category Pages',8,'category-page-options','page2cat_options_page');
    	endif;
    }
    
    if( is_admin() ):
    	if( preg_match('|page-new.php|i', $_SERVER['REQUEST_URI']) ||
    		preg_match('|page.php|i', $_SERVER['REQUEST_URI']) ||
    		preg_match('|edit.php|i', $_SERVER['REQUEST_URI']) ){
    			add_action('admin_menu', 'page2cat_init');
    	}
    	add_action('admin_menu', 'page2cat_config_page');
    	add_action('save_post','page2cat_trigger_save');
    endif;
    
    add_filter('the_content','page2cat_content_catlist');	// by popular demand :-)
    ?>

    So that’s the modified code. I tried to contact the developer to submit it all to him, but there’s no way to. Also, if it doesn’t seem to work, deactivate it and then reactivate it. This is basically because the new database entries need to be put in and it may or may not do it when you update the file.

    Simple easy, peasy! Any questions just ask!!!

    Thread Starter Pneumonic

    (@pneumonic)

    I apologize, I screwed up. The file you modify is page2cat.php not catlist.php (that was what I named my local file, der). Also, if you’d like to have it display the full contents of your post here’s how:

    replace this:

    $excerpt = neat_trim($single_post_content, 500);

    with this:

    $excerpt = $single_post_content;

    and delete this:

    $excerpt .= "<a href='".get_permalink($single->ID)."'>more</a>";

    Now you’ve got a page that outputs everything on it with no hassles. 🙂 Enjoy.

    Did either of you modify the source code? Because I took a look at the one site and compared it with my own and the only difference that I see between the two is that yours doesn’t have the smart youtube code within a paragraph tag (<p>) and mine does. Let me know. 🙂

    Thread Starter Pneumonic

    (@pneumonic)

    Hey everyone. I figured out how to get it to work with valid xhtml and still output code for the iPhone to work. I’ve emailed Vladimir and if I don’t hear from him in a few days I’ll post the code then, but I want to give him time to respond with whether he’ll take my commit or not. So if I haven’t heard from him by wednesday then I’ll post my code and then it should be fixed for everyone so they can have iPhone goodness while still maintaining valid xhtml. 🙂

Viewing 14 replies - 1 through 14 (of 14 total)