get_results("show tables like '{$wpdb->prefix}term_taxonomy'")) > 0; $awm_post_res = AWM_get_post_restrictions(); $awm_cats_to_avoid = ""; if (get_option('AWM_excluded_cats_'.$awm_t)!='') { $awm_cats_ids = get_option('AWM_excluded_cats_'.$awm_t); $awm_cats_ids = str_replace(' ', '', $awm_cats_ids); $awm_cats_ids = (array)explode(',', $awm_cats_ids); for ($awm_i=0; $awm_iget_results(" SELECT t.term_id as category_ID, t.name as cat_name, tt.parent as category_parent FROM {$wpdb->prefix}terms t, {$wpdb->prefix}term_taxonomy tt WHERE tt.taxonomy = 'category' AND t.term_id = tt.term_id $awm_cats_to_avoid GROUP BY category_ID ORDER BY category_parent, cat_name"); $awm_recent = (array)$wpdb->get_results(" SELECT p.ID, p.post_title, tt.term_id FROM {$wpdb->prefix}posts p, {$wpdb->prefix}term_taxonomy tt, {$wpdb->prefix}term_relationships tr WHERE p.post_type='post' AND tr.object_id=p.ID AND tt.term_taxonomy_id=tr.term_taxonomy_id AND tt.taxonomy='category' $awm_post_res $awm_cats_to_avoid ORDER BY tt.term_id, p.post_date DESC"); } else { $awm_cats = (array)$wpdb->get_results(" SELECT cat_ID as category_ID, cat_name, category_parent FROM {$wpdb->prefix}categories GROUP BY cat_ID ORDER BY category_parent, cat_name"); $awm_recent = array(); } if ($awm_isXML) { if (get_option('AWM_categories_ms_'.$awm_t)=='sub') $awm_xml_out .= "categories".get_option('AWM_categories_name_'.$awm_t).""; $awm_xml_out .= AWM_create_dynamic_menu__categories_step($awm_t,$awm_ic,$awm_parentgroup,$awm_cats,$awm_depth,0,$awm_recent,true); if (get_option('AWM_categories_ms_'.$awm_t)=='sub') $awm_xml_out .= ""; return $awm_xml_out; } else { if (get_option('AWM_categories_ms_'.$awm_t)=='sub') { echo "item0=".$awm_parentgroup.".newItem('style=".$awm_m."_'+(wplevel==0?'main_item_style':'sub_item_style')+';itemid=".($awm_ic++).";text0=".str_replace("'","\'",get_option('AWM_categories_name_'.$awm_t))."');\n"; echo "wpsubMenu0=item0.newGroup('style=".$awm_m."_'+(wplevel==0?'sub_group_style':'sub_group_plus_style')+((typeof(wphf_".$awm_m.")=='object')?((wplevel)==0?wphf_".$awm_m."[0]:wphf_".$awm_m."[1]):''));\n"; $awm_depth++; $awm_parentgroup = "wpsubMenu0"; } return AWM_create_dynamic_menu__categories_step($awm_t,$awm_ic,$awm_parentgroup,$awm_cats,$awm_depth,0,$awm_recent,false); } } function AWM_cat_has_kids($awm_id, $awm_cats) { for ($awm_i=0; $awm_icategory_parent==$awm_id) return true; } return false; } function AWM_create_dynamic_menu__categories_step($awm_t, $awm_ic, $awm_parentgroup, $awm_cats, $awm_depth, $awm_group, $awm_recent, $awm_isXML) { $awm_m = get_option('AWM_menu_name_'.$awm_t); $awm_xml_out = ""; for ($awm_i=0; $awm_icategory_parent==$awm_group) { if ($awm_isXML) $awm_xml_out .= "cat_".$awm_cats[$awm_i]->category_ID."".$awm_cats[$awm_i]->cat_name."".get_category_link($awm_cats[$awm_i]->category_ID).""; else echo "item".$awm_depth."=".$awm_parentgroup.".newItem('style=".$awm_m."_'+((wplevel+$awm_depth)==0?'main_item_style':((wplevel+$awm_depth)==1?'sub_item_style':'sub_item_plus_style'))+';itemid=".($awm_ic++).";text0=".str_replace("'","\'",$awm_cats[$awm_i]->cat_name).";url=".get_category_link($awm_cats[$awm_i]->category_ID)."');\n"; if (AWM_cat_has_kids($awm_cats[$awm_i]->category_ID, $awm_cats)) { if ($awm_isXML) { $awm_xml_out .= AWM_create_dynamic_menu__categories_step($awm_t, $awm_ic, "wpsubMenu".$awm_depth, $awm_cats, $awm_depth+1, $awm_cats[$awm_i]->category_ID, $awm_recent, true); } else { echo "wpsubMenu".$awm_depth."=item".$awm_depth.".newGroup('style=".$awm_m."_'+((wplevel+$awm_depth)==0?'sub_group_style':'sub_group_plus_style')+((typeof(wphf_".$awm_m.")=='object')?((wplevel+$awm_depth)==0?wphf_".$awm_m."[0]:wphf_".$awm_m."[1]):''));\n"; $awm_ic = AWM_create_dynamic_menu__categories_step($awm_t, $awm_ic, "wpsubMenu".$awm_depth, $awm_cats, $awm_depth+1, $awm_cats[$awm_i]->category_ID, $awm_recent, false); } } elseif (get_option('AWM_categories_subitems_'.$awm_t)) { $awm_j=$awm_counter=0; while ($awm_jterm_id!=$awm_cats[$awm_i]->category_ID) $awm_j++; if ($awm_recent[$awm_j]->term_id==$awm_cats[$awm_i]->category_ID) { if (!$awm_isXML) echo "wpsubMenuRec=item".$awm_depth.".newGroup('style=".$awm_m."_'+((wplevel+$awm_depth)==0?'sub_group_style':'sub_group_plus_style')+((typeof(wphf_".$awm_m.")=='object')?((wplevel+$awm_depth)==0?wphf_".$awm_m."[0]:wphf_".$awm_m."[1]):''));\n"; while ($awm_jterm_id==$awm_cats[$awm_i]->category_ID && $awm_counter++category_ID."_it".$awm_recent[$awm_j]->ID."".$awm_recent[$awm_j]->post_title."".get_permalink($awm_recent[$awm_j]->ID).""; else echo "item".($awm_depth+1)."=wpsubMenuRec.newItem('style=".$awm_m."_'+((wplevel+$awm_depth)==0?'sub_item_style':'sub_item_plus_style')+';itemid=".($awm_ic++).";text0=".str_replace("'","\'",$awm_recent[$awm_j]->post_title).";url=".get_permalink($awm_recent[$awm_j]->ID)."');\n"; $awm_j++; } } } if ($awm_isXML) $awm_xml_out .= ""; } } if ($awm_isXML) return $awm_xml_out; else return $awm_ic; } /* * Create the menu from existing */ function AWM_create_existing_dynamic_menu($awm_t, $awm_parentgroup, $awm_ic, $awm_isXML) { $awm_depth = 0; $awm_m = get_option('AWM_menu_name_'.$awm_t); $awm_term_id = get_option('AWM_use_custom_menu_id_'.$awm_t); $awm_xml_out = ""; $menu_items = wp_get_nav_menu_items( $awm_term_id ); // print_r($menu_items); if ($awm_term_id==-1) return $awm_isXML?"":$awm_ic; else return AWM_create_existing_dynamic_menu__step($awm_t, $awm_ic, $awm_parentgroup, $menu_items, $awm_depth, 0, $awm_recent, $awm_isXML); } function AWM_existing_has_kids($awm_id, $menu_items) { for ($awm_i=0; $awm_imenu_item_parent==$awm_id) return true; } return false; } function AWM_create_existing_dynamic_menu__step($awm_t, $awm_ic, $awm_parentgroup, $menu_items, $awm_depth, $awm_group, $awm_recent, $awm_isXML) { $awm_m = get_option('AWM_menu_name_'.$awm_t); $awm_xml_out = ""; for ($awm_i=0; $awm_imenu_item_parent==$awm_group) { if ($awm_isXML) $awm_xml_out .= "page_".$menu_items[$awm_i]->ID."".$menu_items[$awm_i]->title."".$menu_items[$awm_i]->url.""; else echo "item".$awm_depth."=".$awm_parentgroup.".newItem('style=".$awm_m."_'+((wplevel+$awm_depth)==0?'main_item_style':((wplevel+$awm_depth)==1?'sub_item_style':'sub_item_plus_style'))+';itemid=".($awm_ic++).";text0=".str_replace("'","\'",$menu_items[$awm_i]->title).";url=".$menu_items[$awm_i]->url."');\n"; if (AWM_existing_has_kids($menu_items[$awm_i]->menu_item_parent, $menu_items)) { if ($awm_isXML) { $awm_xml_out .= AWM_create_existing_dynamic_menu__step($awm_t, $awm_ic, "wpsubMenu".$awm_depth, $menu_items, $awm_depth+1, $menu_items[$awm_i]->ID, $awm_recent, true); } else { echo "wpsubMenu".$awm_depth."=item".$awm_depth.".newGroup('style=".$awm_m."_'+((wplevel+$awm_depth)==0?'sub_group_style':'sub_group_plus_style')+((typeof(wphf_".$awm_m.")=='object')?((wplevel+$awm_depth)==0?wphf_".$awm_m."[0]:wphf_".$awm_m."[1]):''));\n"; $awm_ic = AWM_create_existing_dynamic_menu__step($awm_t, $awm_ic, "wpsubMenu".$awm_depth, $menu_items, $awm_depth+1, $menu_items[$awm_i]->ID, $awm_recent, false); } } if ($awm_isXML) $awm_xml_out .= ""; } } if ($awm_isXML) return $awm_xml_out; else return $awm_ic; } /* * Create the posts menu */ function AWM_create_dynamic_menu__posts($awm_t, $awm_parentgroup, $awm_ic, $awm_isXML) { $awm_m = get_option('AWM_menu_name_'.$awm_t); $awm_xml_out = ""; global $wpdb; if (get_option('AWM_posts_ids_'.$awm_t)=="") return $awm_ic; $awm_post_res = AWM_get_post_restrictions(); $awm_posts_to_display = ""; $awm_posts_ids = get_option('AWM_posts_ids_'.$awm_t); $awm_posts_ids = str_replace(' ', '', $awm_posts_ids); $awm_posts_ids = (array)explode(',', $awm_posts_ids); for ($awm_i=0; $awm_iget_results(" SELECT ID, post_title FROM {$wpdb->prefix}posts p WHERE post_status = 'publish' AND post_type = 'post' $awm_post_res $awm_posts_to_display ORDER BY post_date DESC "); if (count($awm_posts)>0) { if ($awm_isXML) { if (get_option('AWM_posts_ms_'.$awm_t)=='sub') $awm_xml_out .= "posts".get_option('AWM_posts_name_'.$awm_t).""; for ($awm_i=0; $awm_iID."".$awm_posts[$awm_i]->post_title."".get_permalink($awm_posts[$awm_i]->ID).""; if (get_option('AWM_posts_ms_'.$awm_t)=='sub') $awm_xml_out .= ""; } else { if (get_option('AWM_posts_ms_'.$awm_t)=='sub') { echo "item0=".$awm_parentgroup.".newItem('style=".$awm_m."_'+((wplevel+$awm_depth)==0?'main_item_style':((wplevel+$awm_depth)==1?'sub_item_style':'sub_item_plus_style'))+';itemid=".($awm_ic++).";text0=".str_replace("'","\'",get_option('AWM_posts_name_'.$awm_t))."');\n"; echo "wpsubMenu0=item0.newGroup('style=".$awm_m."_'+((wplevel+$awm_depth)==0?'sub_group_style':'sub_group_plus_style'))+((typeof(wphf_".$awm_m.")=='object')?((wplevel+$awm_depth)==0?wphf_".$awm_m."[0]:wphf_".$awm_m."[1]):''));\n"; $awm_depth++; $awm_parentgroup = "wpsubMenu0"; } for ($awm_i=0; $awm_ipost_title).";url=".get_permalink($awm_posts[$awm_i]->ID)."');\n"; } } if ($awm_isXML) return $awm_xml_out; else return $awm_ic; } function AWM_create_dynamic_menu__pages($awm_t, $awm_parentgroup, $awm_ic, $awm_isXML) { $awm_depth = 0; $awm_m = get_option('AWM_menu_name_'.$awm_t); $awm_xml_out = ""; global $wpdb; $awm_post_res = AWM_get_post_restrictions(); $awm_pages_to_avoid = ""; if (get_option('AWM_excluded_pages_'.$awm_t)!='') { $awm_posts_ids = get_option('AWM_excluded_pages_'.$awm_t); $awm_posts_ids = str_replace(' ', '', $awm_posts_ids); $awm_posts_ids = (array)explode(',', $awm_posts_ids); for ($awm_i=0; $awm_iget_results(" SELECT post_title, ID, post_parent FROM {$wpdb->prefix}posts p WHERE post_type = 'page' AND post_status = 'publish' $awm_post_res $awm_pages_to_avoid ORDER BY post_parent, post_date ASC "); if ($awm_isXML) { if (get_option('AWM_pages_ms_'.$awm_t)=='sub') $awm_xml_out .= "pages".get_option('AWM_pages_name_'.$awm_t).""; $awm_xml_out .= AWM_create_dynamic_menu__pages_step($awm_t, $awm_ic, $awm_parentgroup, $awm_pages, $awm_depth, 0, $awm_recent, true); if (get_option('AWM_pages_ms_'.$awm_t)=='sub') $awm_xml_out .= ""; return $awm_xml_out; } else { if (get_option('AWM_pages_ms_'.$awm_t)=='sub') { echo "item0=".$awm_m.".newItem('style=".$awm_m."_'+((wplevel+$awm_depth)==0?'main_item_style':((wplevel+$awm_depth)==1?'sub_item_style':'sub_item_plus_style'))+';itemid=".($awm_ic++).";text0=".str_replace("'","\'",get_option('AWM_pages_name_'.$awm_t))."');\n"; echo "wpsubMenu0=item0.newGroup('style=".$awm_m."_'+((wplevel+$awm_depth)==0?'sub_group_style':'sub_group_plus_style')+((typeof(wphf_".$awm_m.")=='object')?((wplevel+$awm_depth)==0?wphf_".$awm_m."[0]:wphf_".$awm_m."[1]):''));\n"; $awm_depth++; $awm_parentgroup = "wpsubMenu0"; } return AWM_create_dynamic_menu__pages_step($awm_t, $awm_ic, $awm_parentgroup, $awm_pages, $awm_depth, 0, $awm_recent, false); } } function AWM_page_has_kids($awm_id, $awm_pages) { for ($awm_i=0; $awm_ipost_parent==$awm_id) return true; return false; } function AWM_create_dynamic_menu__pages_step($awm_t, $awm_ic, $awm_parentgroup, $awm_pages, $awm_depth, $awm_group, $awm_recent, $awm_isXML) { $awm_m = get_option('AWM_menu_name_'.$awm_t); $awm_xml_out = ""; for ($awm_i=0; $awm_ipost_parent==$awm_group) { if ($awm_isXML) $awm_xml_out .= "page_".$awm_pages[$awm_i]->ID."".$awm_pages[$awm_i]->post_title."".get_permalink($awm_pages[$awm_i]->ID).""; else echo "item".$awm_depth."=".$awm_parentgroup.".newItem('style=".$awm_m."_'+((wplevel+$awm_depth)==0?'main_item_style':((wplevel+$awm_depth)==1?'sub_item_style':'sub_item_plus_style'))+';itemid=".($awm_ic++).";text0=".str_replace("'","\'",$awm_pages[$awm_i]->post_title).";url=".get_permalink($awm_pages[$awm_i]->ID)."');\n"; if (AWM_page_has_kids($awm_pages[$awm_i]->ID, $awm_pages)) { if ($awm_isXML) { $awm_xml_out .= AWM_create_dynamic_menu__pages_step($awm_t, $awm_ic, "wpsubMenu".$awm_depth, $awm_pages, $awm_depth+1, $awm_pages[$awm_i]->ID, $awm_recent, true); } else { echo "\n\nwpsubMenu".$awm_depth."=item".$awm_depth.".newGroup('style=".$awm_m."_'+((wplevel+$awm_depth)==0?'sub_group_style':'sub_group_plus_style')+((typeof(wphf_".$awm_m.")=='object')?((wplevel+$awm_depth)==0?wphf_".$awm_m."[0]:wphf_".$awm_m."[1]):''));\n\n\n"; $awm_ic = AWM_create_dynamic_menu__pages_step($awm_t, $awm_ic, "wpsubMenu".$awm_depth, $awm_pages, $awm_depth+1, $awm_pages[$awm_i]->ID, $awm_recent, false); } } if ($awm_isXML) $awm_xml_out .= ""; } } if ($awm_isXML) return $awm_xml_out; else return $awm_ic; } function AWM_get_post_restrictions() { $awm_pass_check = ''; if (get_option('AWM_hide_protected_'.$awm_t)) { $awm_pass_check = " AND p.post_password = '' "; } $awm_future_check = ''; if (get_option('AWM_hide_future_'.$awm_t)) { $awm_future_check = " AND p.post_status != 'future' "; } return $awm_pass_check.$awm_future_check; } function AWM_create_menu_structure($awm_t) { $awm_ic = 1000; $awm_xml_out = ""; $awm_xml_out .="".get_option('AWM_menu_type_'.$awm_t).""; if (get_option('AWM_use_custom_menu_'.$awm_t)) { // if user wants a custom menu $awm_xml_out .= AWM_create_existing_dynamic_menu($awm_t, "", $awm_ic, true); } else { // else use the other options if (get_option('AWM_include_home_'.$awm_t)) { // include home $awm_xml_out .= "home0Home".get_bloginfo('url').""; } if (get_option('AWM_pages_'.$awm_t)) { $awm_xml_out .= AWM_create_dynamic_menu__pages($awm_t, "", $awm_ic, true); } if (get_option('AWM_posts_'.$awm_t)) { $awm_xml_out .= AWM_create_dynamic_menu__posts($awm_t, "", $awm_ic, true); } if (get_option('AWM_categories_'.$awm_t)) { $awm_xml_out .= AWM_create_dynamic_menu__categories($awm_t, "", $awm_ic, true); } } $awm_xml_out .= ""; $awm_xml_out = str_replace("<","<",$awm_xml_out); $awm_xml_out = str_replace(">",">",$awm_xml_out); return $awm_xml_out; } ?>