Esempio n. 1
0
function woo_custom_navigation_sub_items($post_id, $type, $table_name, $output_type, $menu_id = 0, $depth = 0, $depth_counter = 0)
{
    $depth_counter = $depth_counter + 1;
    $parent_id = 0;
    global $wpdb;
    //GET sub menu items
    $woo_custom_nav_menu = $wpdb->get_results("SELECT id,post_id,parent_id,position,custom_title,custom_link,custom_description,menu_icon,link_type,custom_anchor_title,new_window FROM " . $table_name . " WHERE parent_id = '" . $post_id . "' AND menu_id='" . $menu_id . "' ORDER BY position ASC");
    if (empty($woo_custom_nav_menu)) {
    } else {
        ?>
<ul <?php 
        if ($output_type == "backend") {
            ?>
 id="sub-custom-nav" <?php 
        }
        ?>
 >
		<?php 
        $queried_id = 0;
        $type_settings = 'custom';
        global $wp_query;
        if (is_page()) {
            $queried_id = $wp_query->post->ID;
            $type_settings = 'page';
        } elseif (is_category()) {
            $queried_id = $wp_query->query_vars['cat'];
            $type_settings = 'category';
        } else {
        }
        //DISPLAY Loop
        foreach ($woo_custom_nav_menu as $sub_item) {
            //Figure out where the menu item sits
            $counter = $sub_item->position;
            //Prepare Menu Data
            //Category Menu Item
            if ($sub_item->link_type == 'category') {
                $parent_id = $sub_item->parent_id;
                $post_id = $sub_item->post_id;
                if ($sub_item->custom_link == '') {
                    $link = get_category_link($sub_item->post_id);
                } else {
                    $link = $sub_item->custom_link;
                }
                if ($sub_item->custom_title == '') {
                    $title_raw = get_categories('include=' . $sub_item->post_id);
                    //Convert string to UTF-8
                    $str_converted = woo_encoding_convert($title_raw[0]->cat_name);
                    $title = htmlspecialchars($str_converted, ENT_QUOTES, 'UTF-8');
                } else {
                    //Convert string to UTF-8
                    $str_converted = woo_encoding_convert($sub_item->custom_title);
                    $title = htmlspecialchars($str_converted, ENT_QUOTES, 'UTF-8');
                }
                if ($sub_item->custom_description == '') {
                    $description = strip_tags(trim(category_description($sub_item->post_id)));
                } else {
                    $description = trim($sub_item->custom_description);
                }
                $target = '';
            } elseif ($sub_item->link_type == 'page') {
                $parent_id = $sub_item->parent_id;
                $post_id = $sub_item->post_id;
                if ($sub_item->custom_link == '') {
                    $link = get_permalink($sub_item->post_id);
                } else {
                    $link = $sub_item->custom_link;
                }
                if ($sub_item->custom_title == '') {
                    //Convert string to UTF-8
                    $str_converted = woo_encoding_convert(get_the_title($sub_item->post_id));
                    $title = htmlspecialchars($str_converted, ENT_QUOTES, 'UTF-8');
                } else {
                    //Convert string to UTF-8
                    $str_converted = woo_encoding_convert($sub_item->custom_title);
                    $title = htmlspecialchars($str_converted, ENT_QUOTES, 'UTF-8');
                }
                if ($sub_item->custom_description == '') {
                    $description = trim(get_post_meta($sub_item->post_id, 'page-description', true));
                } else {
                    $description = trim($sub_item->custom_description);
                }
                $target = '';
            } else {
                $link = $sub_item->custom_link;
                //Convert string to UTF-8
                $str_converted = woo_encoding_convert($sub_item->custom_title);
                $title = htmlspecialchars($str_converted, ENT_QUOTES, 'UTF-8');
                $parent_id = $sub_item->parent_id;
                $post_id = $sub_item->post_id;
                $description = trim($sub_item->custom_description);
                $target = 'target="_blank"';
            }
            //SET URL protocol
            if (isset($_SERVER['HTTPS'])) {
                if ($_SERVER['HTTPS'] == 'on') {
                    $protocol = 'https';
                } else {
                    $protocol = 'http';
                }
            } else {
                $protocol = 'http';
            }
            $full_web_address = $protocol . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
            if ($queried_id == $sub_item->post_id && $queried_id != 0 && $type_settings == $sub_item->link_type) {
                $li_class = 'class="current_page_item"';
            } else {
                if ($sub_item->custom_link == $full_web_address && $queried_id == 0 && $type_settings == $sub_item->link_type) {
                    $li_class = 'class="current_page_item"';
                } else {
                    if (woo_child_is_current($sub_item->id, $menu_id, $table_name, $queried_id, $type_settings, $full_web_address)) {
                        $li_class = 'class="current_page_parent"';
                    } else {
                        $li_class = '';
                    }
                }
            }
            //SET anchor title
            if (isset($sub_item->custom_anchor_title)) {
                //Convert string to UTF-8
                $str_converted = woo_encoding_convert($sub_item->custom_anchor_title);
                $anchor_title = htmlspecialchars($str_converted, ENT_QUOTES, 'UTF-8');
            } else {
                $anchor_title = $title;
            }
            if (isset($sub_item->new_window)) {
                if ($sub_item->new_window > 0) {
                    $target = 'target="_blank"';
                } else {
                    $target = '';
                }
            }
            //List Items
            //FRONTEND
            if ($output_type == "frontend") {
                ?>
<li <?php 
                echo $li_class;
                ?>
><a title="<?php 
                echo $anchor_title;
                ?>
" href="<?php 
                echo $link;
                ?>
" <?php 
                echo $target;
                ?>
><?php 
                echo $title;
                ?>
</a><?php 
            } elseif ($output_type == "backend") {
                ?>

							<li id="menu-<?php 
                echo esc_attr($counter);
                ?>
" value="<?php 
                echo esc_attr($counter);
                ?>
" <?php 
                echo $li_class;
                ?>
>
							<dl>
							<dt>
								<span class="title"><?php 
                echo esc_html($title);
                ?>
</span>
								<span class="controls">
								<span class="type"><?php 
                echo $sub_item->link_type;
                ?>
</span>
								<a id="edit<?php 
                echo esc_attr($counter);
                ?>
" onclick="edititem(<?php 
                echo $counter;
                ?>
)" value="<?php 
                echo esc_attr($counter);
                ?>
"><img class="edit" alt="Edit Menu Item" title="Edit Menu Item" src="<?php 
                echo get_template_directory_uri();
                ?>
/functions/images/ico-edit.png" /></a>
								<a id="remove<?php 
                echo esc_attr($counter);
                ?>
" onclick="removeitem(<?php 
                echo $counter;
                ?>
)" value="<?php 
                echo esc_attr($counter);
                ?>
"><img class="remove" alt="Remove from Custom Menu" title="Remove from Custom Menu" src="<?php 
                echo get_template_directory_uri();
                ?>
/functions/images/ico-close.png" /></a>
								<a id="view<?php 
                echo esc_attr($counter);
                ?>
" target="_blank" href="<?php 
                echo $link;
                ?>
"><img alt="View Page" title="View Page" src="<?php 
                echo get_template_directory_uri();
                ?>
/functions/images/ico-viewpage.png" /></a>
								</span>
							</dt>
							</dl>
							<a class="hide" href="<?php 
                echo $link;
                ?>
"><?php 
                echo $title;
                ?>
</a>
							<input type="hidden" name="dbid<?php 
                echo esc_attr($counter);
                ?>
" id="dbid<?php 
                echo esc_attr($counter);
                ?>
" value="<?php 
                echo esc_attr($sub_item->id);
                ?>
" />
							<input type="hidden" name="postmenu<?php 
                echo esc_attr($counter);
                ?>
" id="postmenu<?php 
                echo esc_attr($counter);
                ?>
" value="<?php 
                echo esc_attr($post_id);
                ?>
" />
							<input type="hidden" name="parent<?php 
                echo esc_attr($counter);
                ?>
" id="parent<?php 
                echo esc_attr($counter);
                ?>
" value="<?php 
                echo esc_attr($parent_id);
                ?>
" />
							<input type="hidden" name="title<?php 
                echo esc_attr($counter);
                ?>
" id="title<?php 
                echo esc_attr($counter);
                ?>
" value="<?php 
                echo esc_attr($title);
                ?>
" />
							<input type="hidden" name="linkurl<?php 
                echo esc_attr($counter);
                ?>
" id="linkurl<?php 
                echo esc_attr($counter);
                ?>
" value="<?php 
                echo esc_attr($link);
                ?>
" />
							<input type="hidden" name="description<?php 
                echo esc_attr($counter);
                ?>
" id="description<?php 
                echo esc_attr($counter);
                ?>
" value="<?php 
                echo esc_attr($description);
                ?>
" />
							<input type="hidden" name="icon<?php 
                echo esc_attr($counter);
                ?>
" id="icon<?php 
                echo esc_attr($counter);
                ?>
" value="0" />
							<input type="hidden" name="position<?php 
                echo esc_attr($counter);
                ?>
" id="position<?php 
                echo esc_attr($counter);
                ?>
" value="<?php 
                echo esc_attr($counter);
                ?>
" />
							<input type="hidden" name="linktype<?php 
                echo esc_attr($counter);
                ?>
" id="linktype<?php 
                echo esc_attr($counter);
                ?>
" value="<?php 
                echo esc_attr($sub_item->link_type);
                ?>
" />
							<input type="hidden" name="anchortitle<?php 
                echo esc_attr($counter);
                ?>
" id="anchortitle<?php 
                echo esc_attr($counter);
                ?>
" value="<?php 
                echo esc_attr($anchor_title);
                ?>
" />
							<input type="hidden" name="newwindow<?php 
                echo esc_attr($counter);
                ?>
" id="newwindow<?php 
                echo esc_attr($counter);
                ?>
" value="<?php 
                echo esc_attr($sub_item->new_window);
                ?>
" />
							<?php 
            }
            //Do recursion
            if ($depth_counter < $depth || $depth == 0) {
                woo_custom_navigation_sub_items($sub_item->id, $sub_item->link_type, $table_name, $output_type, $menu_id, $depth, $depth_counter);
            }
            ?>
</li>
			<?php 
        }
        ?>
</ul>
	<?php 
    }
    return $parent_id;
}
function woo_custom_navigation_sub_items($post_id, $type, $table_name, $output_type, $menu_id = 0)
{
    $parent_id = 0;
    global $wpdb;
    //GET sub menu items
    $woo_custom_nav_menu = $wpdb->get_results("SELECT id,post_id,parent_id,position,custom_title,custom_link,custom_description,menu_icon,link_type,custom_anchor_title,new_window FROM " . $table_name . " WHERE parent_id = '" . $post_id . "' AND menu_id='" . $menu_id . "' ORDER BY position ASC");
    if (empty($woo_custom_nav_menu)) {
    } else {
        ?>
<ul <?php 
        if ($output_type == "backend") {
            ?>
 id="sub-custom-nav" <?php 
        }
        ?>
 >
		<?php 
        $queried_id = 0;
        global $wp_query;
        if (is_page()) {
            $queried_id = $wp_query->post->ID;
        } elseif (is_category()) {
            $queried_id = $wp_query->query_vars['cat'];
        } else {
        }
        //DISPLAY Loop
        foreach ($woo_custom_nav_menu as $sub_item) {
            //Figure out where the menu item sits
            $counter = $sub_item->position;
            //Prepare Menu Data
            //Category Menu Item
            if ($sub_item->link_type == 'category') {
                $parent_id = $sub_item->parent_id;
                $post_id = $sub_item->post_id;
                if ($sub_item->custom_link == '') {
                    $link = get_category_link($sub_item->post_id);
                } else {
                    $link = $sub_item->custom_link;
                }
                if ($sub_item->custom_title == '') {
                    $title_raw = get_categories('include=' . $sub_item->post_id);
                    $title = htmlentities($title_raw[0]->cat_name);
                } else {
                    $title = htmlentities($sub_item->custom_title);
                }
                if ($sub_item->custom_description == '') {
                    $description = strip_tags(category_description($sub_item->post_id));
                } else {
                    $description = $sub_item->custom_description;
                }
                $target = '';
            } elseif ($sub_item->link_type == 'page') {
                $parent_id = $sub_item->parent_id;
                $post_id = $sub_item->post_id;
                if ($sub_item->custom_link == '') {
                    $link = get_permalink($sub_item->post_id);
                } else {
                    $link = $sub_item->custom_link;
                }
                if ($sub_item->custom_title == '') {
                    $title = htmlentities(get_the_title($sub_item->post_id));
                } else {
                    $title = htmlentities($sub_item->custom_title);
                }
                if ($sub_item->custom_description == '') {
                    $description = get_post_meta($sub_item->post_id, 'page-description', true);
                } else {
                    $description = $sub_item->custom_description;
                }
                $target = '';
            } else {
                $link = $sub_item->custom_link;
                $title = htmlentities($sub_item->custom_title);
                $parent_id = $sub_item->parent_id;
                $post_id = $sub_item->post_id;
                $description = $sub_item->custom_description;
                $target = 'target="_blank"';
            }
            if ($queried_id == $sub_item->post_id) {
                $li_class = 'class="current_page_item"';
            } else {
                $li_class = '';
            }
            //SET anchor title
            if (isset($sub_item->custom_anchor_title)) {
                $anchor_title = htmlentities($sub_item->custom_anchor_title);
            } else {
                $anchor_title = $title;
            }
            if (isset($sub_item->new_window)) {
                if ($sub_item->new_window > 0) {
                    $target = 'target="_blank"';
                }
            }
            //List Items
            //FRONTEND
            if ($output_type == "frontend") {
                ?>
<li <?php 
                echo $li_class;
                ?>
><a title="<?php 
                echo $anchor_title;
                ?>
" href="<?php 
                echo $link;
                ?>
" <?php 
                echo $target;
                ?>
><?php 
                echo $title;
                ?>
</a><?php 
            } elseif ($output_type == "backend") {
                ?>
							<li id="menu-<?php 
                echo $counter;
                ?>
" value="<?php 
                echo $counter;
                ?>
" <?php 
                echo $li_class;
                ?>
>
							<dl>
							<dt>
								<span class="title"><?php 
                echo $title;
                ?>
</span>
								<span class="controls">
								<span class="type"><?php 
                echo $sub_item->link_type;
                ?>
</span>
								<a id="edit<?php 
                echo $counter;
                ?>
" onclick="edititem(<?php 
                echo $counter;
                ?>
)" value="<?php 
                echo $counter;
                ?>
"><img class="edit" alt="Edit Menu Item" title="Edit Menu Item" src="<?php 
                echo get_bloginfo('template_directory');
                ?>
/functions/images/ico-edit.png" /></a> 
								<a id="remove<?php 
                echo $counter;
                ?>
" onclick="removeitem(<?php 
                echo $counter;
                ?>
)" value="<?php 
                echo $counter;
                ?>
"><img class="remove" alt="Remove from Custom Menu" title="Remove from Custom Menu" src="<?php 
                echo get_bloginfo('template_directory');
                ?>
/functions/images/ico-close.png" /></a>
								<a id="view<?php 
                echo $counter;
                ?>
" target="_blank" href="<?php 
                echo $link;
                ?>
"><img alt="View Page" title="View Page" src="<?php 
                echo get_bloginfo('template_directory');
                ?>
/functions/images/ico-viewpage.png" /></a>
								</span>
							</dt>
							</dl>
							<a class="hide" href="<?php 
                echo $link;
                ?>
"><?php 
                echo $title;
                ?>
</a>
							<input type="hidden" name="dbid<?php 
                echo $counter;
                ?>
" id="dbid<?php 
                echo $counter;
                ?>
" value="<?php 
                echo $sub_item->id;
                ?>
" />
							<input type="hidden" name="postmenu<?php 
                echo $counter;
                ?>
" id="postmenu<?php 
                echo $counter;
                ?>
" value="<?php 
                echo $post_id;
                ?>
" />
							<input type="hidden" name="parent<?php 
                echo $counter;
                ?>
" id="parent<?php 
                echo $counter;
                ?>
" value="<?php 
                echo $parent_id;
                ?>
" />
							<input type="hidden" name="title<?php 
                echo $counter;
                ?>
" id="title<?php 
                echo $counter;
                ?>
" value="<?php 
                echo $title;
                ?>
" />
							<input type="hidden" name="linkurl<?php 
                echo $counter;
                ?>
" id="linkurl<?php 
                echo $counter;
                ?>
" value="<?php 
                echo $link;
                ?>
" />
							<input type="hidden" name="description<?php 
                echo $counter;
                ?>
" id="description<?php 
                echo $counter;
                ?>
" value="<?php 
                echo $description;
                ?>
" />
							<input type="hidden" name="icon<?php 
                echo $counter;
                ?>
" id="icon<?php 
                echo $counter;
                ?>
" value="0" />
							<input type="hidden" name="position<?php 
                echo $counter;
                ?>
" id="position<?php 
                echo $counter;
                ?>
" value="<?php 
                echo $counter;
                ?>
" />
							<input type="hidden" name="linktype<?php 
                echo $counter;
                ?>
" id="linktype<?php 
                echo $counter;
                ?>
" value="<?php 
                echo $sub_item->link_type;
                ?>
" />
							<input type="hidden" name="anchortitle<?php 
                echo $counter;
                ?>
" id="anchortitle<?php 
                echo $counter;
                ?>
" value="<?php 
                echo $anchor_title;
                ?>
" />
							<input type="hidden" name="newwindow<?php 
                echo $counter;
                ?>
" id="newwindow<?php 
                echo $counter;
                ?>
" value="<?php 
                echo $sub_item->new_window;
                ?>
" />
							<?php 
            }
            //Do recursion
            woo_custom_navigation_sub_items($sub_item->id, $sub_item->link_type, $table_name, $output_type, $menu_id);
            ?>
</li>
			<?php 
        }
        ?>
</ul>
	<?php 
    }
    return $parent_id;
}