';
+
+if($_REQUEST['view'] != 'new'):
+
+ if(count($myopts) != 0):
+# echo "
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.
";
+
+ echo "
";
+ echo "
";
+ echo '
+
+
+
+
+
+
';
+ echo "
";
+ echo "
";
+
+ echo "
";
+ echo '
+ ';
+ echo "
";
+
+ echo "
";
+ echo "
";
+ echo '
+
+
+
+
+
+
+
';
+ echo "
";
+ echo "
";
+
+ else:
+
+ echo "
Sorry, no Category » Page connection available (yet). Maybe you want to create some new connections ?
";
+ 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 "
Sorry, you don't have any usable category (or there are some, but empty; check your settings ).
";
+ else:
+# echo "
New connections ";
+# echo "
These categories aren't connected with any page. Here you can setup a connection with an existent page, or create a brand new one.
";
+
+ echo "
";
+ endif;
+ echo PIXLINE_FOOTER;
+ echo "
";
+ endif;
+}
+
+// adds styles in admin head (WP 2.5+)
+function page2cat_metabox_styles(){
+?>
+
+
+
+
+
+Category Pages
+
+
+
+
+get_results("SELECT * FROM {$wpdb->page2cat} WHERE page_ID = '".$post_ID."';",OBJECT);
+ ?>
+
Use this page as Category Page for these categories.
+ 0):
+ echo "
";
+ 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 "
";
+ ?>
+ 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....
+}
+
+// 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;
+ if ( stristr( $content, '[catlist' )) {
+ $search = "@(?:
)*\s*\[catlist\s*=\s*(\w+|^\+)\]\s*(?:
)*@i";
+ if (preg_match_all($search, $content, $matches)) {
+ if (is_array($matches)) {
+ $title = get_option('p2c_catlist_title');
+ if($title != "") $output = "
".$title." "; else $output = "";
+ $output .= "
";
+ $limit = get_option('p2c_catlist_limit');
+ foreach ($matches[1] as $key =>$v0) {
+ $catposts = get_posts('category='.$v0."&numberposts=".$limit);
+ foreach($catposts as $single):
+ $output .= "".$single->post_title." ";
+ endforeach;
+ $search = $matches[0][$key];
+ $replace= $output;
+ $content= str_replace ($search, $replace, $content);
+ }
+ $output .= " ";
+ }
+ }
+ }
+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);
+ echo('
');
+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"';
+}
+
+$p2c_catlist_title = get_option('p2c_catlist_title');
+
+
+ echo "
";
+ echo "
Category Page settings ";
+ echo "
';
+ echo PIXLINE_FOOTER;
+ echo "
";
+}
+
+// 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':
+ ?>
+
+
+
+
+
+
+ '.single_cat_title('',false).'';
+ 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 :-)
+?>