www.wp-plugins-themes.com)
Version: 1.5
Author: Koledole
Author URI: http://www.wp-plugins-themes.com
*/
/*
Plugin Name: Icons-Category-Page
Plugin Name: Icons-Category-Page
*/
/* Copyright 2009, Vas Pro (email: koledole@gmail.com),
www.wp-plugins-themes.com - custom wp-plugins development & WordPress solutions.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Getting Ajax requests
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$action = $_POST['ajax_action'];
if ( isset($action) ) {
if (!function_exists ('adebug')) {
function adebug() {
$var = func_get_args();
echo "
";
print_r ( $var );
echo "
";
}
}
switch ( $action ) :
case 'delete-image-from-htmltable' : // adebug($_POST); die();
$path_icon = $_POST['file_name_dir'] . '/' . $_POST['file_name']; // get file path icon
$name_parts = pathinfo($path_icon); // generate ralimg path
$ext = $name_parts['extension'];
$file_name_only = trim( substr( $name_parts['basename'], 0, -(1 + strlen($ext)) ) );
$file_name_only = trim( substr( $file_name_only , 0, -( strlen($_POST['fileicon_size'])) ) );
$path = $_POST['file_name_dir'] . '/' . $file_name_only . '.' . $ext ;
if (file_exists($path)) unlink( $path );
if (file_exists($path_icon)) unlink( $path_icon );
?>
array( $args ) ) ;
}
function remove_cp_filter($filter_type, $filter) {
global $wpdev_cp_filter;
if ( isset($wpdev_cp_filter[$filter_type]) ) {
for ($i = 0; $i < count($wpdev_cp_filter[$filter_type]); $i++) {
if ( $wpdev_cp_filter[$filter_type][$i][0] == $filter ) {
$wpdev_cp_filter[$filter_type][$i] = null;
return;
}
}
}
}
function apply_cp_filter($filter_type) {
global $wpdev_cp_filter;
$args = array();
for ( $a = 1; $a < func_num_args(); $a++ )
$args[] = func_get_arg($a);
$value = $args[0];
if ( is_array($wpdev_cp_filter) )
if ( isset($wpdev_cp_filter[$filter_type]) )
foreach ($wpdev_cp_filter[$filter_type] as $filter) {
$filter_func = array_shift($filter);
$parameter = $args;
$value = call_user_func_array($filter_func,$parameter );
}
return $value;
}
function make_cp_action($action_type) {
global $wpdev_cp_action;
$args = array();
for ( $a = 1; $a < func_num_args(); $a++ )
$args[] = func_get_arg($a);
//$value = $args[0];
if ( is_array($wpdev_cp_action) )
if ( isset($wpdev_cp_action[$action_type]) )
foreach ($wpdev_cp_action[$action_type] as $action) {
$action_func = array_shift($action);
$parameter = $action;
call_user_func_array($action_func,$args );
}
}
function add_cp_action($action_type, $action) {
global $wpdev_cp_action;
$args = array();
if ( is_array($action) && 1 == count($action) && is_object($action[0]) ) // array(&$this)
$args[] =& $action[0];
else
$args[] = $action;
for ( $a = 2; $a < func_num_args(); $a++ )
$args[] = func_get_arg($a);
if ( is_array($wpdev_cp_action) )
if ( is_array($wpdev_cp_action[$action_type]) )
$wpdev_cp_action[$action_type][]= $args;
else
$wpdev_cp_action[$action_type]= array($args);
else
$wpdev_cp_action = array( $action_type => array( $args ) ) ;
}
function remove_cp_action($action_type, $action) {
global $wpdev_cp_action;
if ( isset($wpdev_cp_action[$action_type]) ) {
for ($i = 0; $i < count($wpdev_cp_action[$action_type]); $i++) {
if ( $wpdev_cp_action[$action_type][$i][0] == $action ) {
$wpdev_cp_action[$action_type][$i] = null;
return;
}
}
}
}
if (!function_exists ('debuge')) {
function debuge() {
$numargs = func_num_args();
$var = func_get_args();
$makeexit = is_bool($var[count($var)-1])?$var[count($var)-1]:false;
echo "
';
exit;
}
}
}
// Get header info from this file, just for compatibility with WordPress 2.8 and older versions.
function get_file_data_mc_wpdev( $file, $default_headers, $context = '' ) {
// We don't need to write to the file, so just open for reading.
$fp = fopen( $file, 'r' );
// Pull only the first 8kiB of the file in.
$file_data = fread( $fp, 8192 );
// PHP will close file handle, but we are good citizens.
fclose( $fp );
if( $context != '' ) {
$extra_headers = array();//apply_filters( "extra_$context".'_headers', array() );
$extra_headers = array_flip( $extra_headers );
foreach( $extra_headers as $key=>$value ) {
$extra_headers[$key] = $key;
}
$all_headers = array_merge($extra_headers, $default_headers);
} else {
$all_headers = $default_headers;
}
foreach ( $all_headers as $field => $regex ) {
preg_match( '/' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, ${$field});
if ( !empty( ${$field} ) )
${$field} = trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', ${$field}[1] ));
else
${$field} = '';
}
$file_data = compact( array_keys( $all_headers ) );
return $file_data;
}
function wpdev_cp_define_static() {
$default_headers = array(
'Name' => 'Plugin Name',
'PluginURI' => 'Plugin URI',
'Version' => 'Version',
'Description' => 'Description',
'Author' => 'Author',
'AuthorURI' => 'Author URI',
'TextDomain' => 'Text Domain',
'DomainPath' => 'Domain Path'
);
$plugin_data = get_file_data_mc_wpdev( __FILE__, $default_headers, 'plugin' );
if ( $plugin_data['Name'] == 'Icons-Category-Page') $isPublic = 1;
else $isPublic = 0;
if (!defined('WPDEV_CP_VERSION')) define('WPDEV_CP_VERSION', $plugin_data['Version'] ); // 0.1
if (!defined('WPDEV_CP_PUBLIC_VERSION')) define('WPDEV_CP_PUBLIC_VERSION', $isPublic ); // 0
if (!defined('WP_CONTENT_DIR')) define('WP_CONTENT_DIR', ABSPATH . 'wp-content'); // Z:\home\test.emsphere.info\www/wp-content
if (!defined('WP_CONTENT_URL')) define('WP_CONTENT_URL', get_option('siteurl') . '/wp-content'); // http://test.emsphere.info/wp-content
if (!defined('WP_PLUGIN_DIR')) define('WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins'); // Z:\home\test.emsphere.info\www/wp-content/plugins
if (!defined('WP_PLUGIN_URL')) define('WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins'); // http://test.emsphere.info/wp-content/plugins
if (!defined('WPDEV_CP_PLUGIN_FILENAME')) define('WPDEV_CP_PLUGIN_FILENAME', basename( __FILE__ ) ); // Icons-Category-Page.php
if (!defined('WPDEV_CP_PLUGIN_DIRNAME')) define('WPDEV_CP_PLUGIN_DIRNAME', plugin_basename(dirname(__FILE__)) ); // Icons-Category-Page
if (!defined('WPDEV_CP_PLUGIN_DIR')) define('WPDEV_CP_PLUGIN_DIR', WP_PLUGIN_DIR.'/'.WPDEV_CP_PLUGIN_DIRNAME ); // Z:\home\test.emsphere.info\www/wp-content/plugins/Icons-Category-Page
if (!defined('WPDEV_CP_PLUGIN_URL')) define('WPDEV_CP_PLUGIN_URL', WP_PLUGIN_URL.'/'.WPDEV_CP_PLUGIN_DIRNAME ); // http://test.emsphere.info/wp-content/plugins/Icons-Category-Page
//if ( ! loadLocale() ) { loadLocale('en_US'); } //loadLocale('ru_RU'); // Localization
if (file_exists(WPDEV_CP_PLUGIN_DIR. '/include/wpdev-pro.php')) {
require_once(WPDEV_CP_PLUGIN_DIR. '/include/wpdev-pro.php' );
}
}
wpdev_cp_define_static();
if (!class_exists('wpdev_compose')) {
class wpdev_compose {
var $flash_uploader;
var $icons_url;
var $icons_dir;
var $is_dir_exist;
var $menu;
var $wpdev_cp_pro;
function wpdev_compose() {
$this->menu = false;
$this->icons_dir = ABSPATH . get_option('wpdev_mc_icon_dir');
$this->icons_url = get_option('siteurl') . '/' . get_option('wpdev_mc_icon_dir');
$this->is_dir_exist = $this->wpdev_mk_dir($this->icons_dir);
if ( ! $this->loadLocale() ) $this->loadLocale('en_EN');
if ( class_exists('wpdev_cp_pro')) {
$this->wpdev_cp_pro = new wpdev_cp_pro();
}
else {
$this->wpdev_cp_pro = false;
}
add_action('admin_menu', array(&$this,'add_new_admin_menu'));
add_action('wp_head',array(&$this, 'client_side_print_compose_head'));
add_action( 'wp_footer', array(&$this,'wp_footer') );
add_filter('plugin_action_links', array(&$this, 'plugin_links'), 10, 2 );
// Reassign icons for client side
add_filter('wp_list_pages', array(&$this, 'wp_list_pages_icons'), 10, 1 );
add_filter('wp_list_categories', array(&$this, 'wp_list_categories_icons'), 10, 1 );
//User action for showing menu and submenu
add_action('wpdev_menu',array(&$this, 'wpdev_show_menu'));
add_action('wpdev_submenu',array(&$this, 'wpdev_show_submenu'));
add_action('wpdev_memo',array(&$this, 'wpdev_show_memo'),10,2);
register_activation_hook( __FILE__, array(&$this,'wpdev_compose_activate' ));
register_deactivation_hook( __FILE__, array(&$this,'wpdev_compose_deactivate' ));
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ADMIN MENU SECTIONS ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function add_new_admin_menu() {
$users_roles = array('subscriber','subscriber','subscriber' );
for ($i = 0 ; $i < count($users_roles) ; $i++) {
if ( $users_roles[$i] == 'administrator' ) $users_roles[$i] = 10;
if ( $users_roles[$i] == 'editor' ) $users_roles[$i] = 7;
if ( $users_roles[$i] == 'author' ) $users_roles[$i] = 2;
if ( $users_roles[$i] == 'contributor' ) $users_roles[$i] = 1;
if ( $users_roles[$i] == 'subscriber') $users_roles[$i] = 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// M A I N B O O K I N G
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (! WPDEV_CP_PUBLIC_VERSION) {
$pagehook1 = add_object_page( __('Menu compouser'), __('Site Menu'), $users_roles[0],
__FILE__ . 'wpdev-cp', array(&$this, 'on_show_cp_page_menucompouser'), WPDEV_CP_PLUGIN_URL . '/img/Sidebar-Photos-16x16.png' );
add_action("admin_print_scripts-" . $pagehook1 , array( &$this, 'on_add_admin_js_files'));
$reference_for_submenu = 'wpdev-cp';
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// I C O N S
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (WPDEV_CP_PUBLIC_VERSION) {
$pagehook2 = add_object_page(__('Uploading icons for pages and categories', 'wpdev-booking'), __('Icons', 'wpdev-booking'), $users_roles[1],
__FILE__ .'wpdev-cp-icons', array(&$this, 'on_show_cp_page_icons'), WPDEV_CP_PLUGIN_URL . '/img/Sidebar-Photos-16x16.png' );
$reference_for_submenu = 'wpdev-cp-icons';
} else {
$pagehook2 = add_submenu_page(__FILE__ . $reference_for_submenu,__('Uploading icons for pages and categories', 'wpdev-booking'), __('Icons', 'wpdev-booking'), $users_roles[1],
__FILE__ .'wpdev-cp-icons', array(&$this, 'on_show_cp_page_icons') );
}
add_action("admin_print_scripts-" . $pagehook2 , array( &$this, 'on_add_admin_js_files'));
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// S E T T I N G S
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$pagehook3 = add_submenu_page(__FILE__ . $reference_for_submenu,__('Menu compouser settings', 'wpdev-booking'), __('Settings', 'wpdev-booking'), $users_roles[2],
__FILE__ .'wpdev-cp-option', array(&$this, 'on_show_cp_settings') );
add_action("admin_print_scripts-" . $pagehook3 , array( &$this, 'on_add_admin_js_files'));
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
global $submenu, $menu; // Change Title of the Main menu inside of submenu
$submenu[plugin_basename( __FILE__ ) . 'wpdev-cp'][0][0] = __('Menu compouser');
}
//Menu compouser
function on_show_cp_page_menucompouser() {
$this->on_show_page_adminmenu('wpdev-cp','/img/shared-pictures-128x128.png', __('Menu compouser'),1);
}
//Icons
function on_show_cp_page_icons() {
$this->on_show_page_adminmenu('wpdev-cp-icons','/img/Sidebar-Photos-256x256_1.png', __('Uploading icons for pages and categories'),2);
}
//Settings
function on_show_cp_settings() {
$this->on_show_page_adminmenu('wpdev-cp-option','/img/Developer-128x128.png', __('Settings'),3);
}
//Show content
function on_show_page_adminmenu($html_id, $icon, $title, $content_type) {
?>
' ; ?>
content_of_compose_menu_page();
break;
case 2: $this->content_of_icons_page();
break;
case 3: $this->content_of_settings_page();
break;
default: break;
} ?>
'.__("Settings").'';
array_unshift($links, $settings_link);
}
return $links;
}
// Load locale
function loadLocale($locale = '') { // Load locale, if not so the load en_EN default locale from folder "languages" files like "this_file_file_name-ru_RU.po" and "this_file_file_name-ru_RU.mo"
if ( empty( $locale ) ) $locale = get_locale();
if ( !empty( $locale ) ) {
//Filenames like this "microstock-photo-ru_RU.po", "microstock-photo-de_DE.po" at folder "languages"
$mofile = WPDEV_CP_PLUGIN_DIR .'languages/'.str_replace('.php','',WPDEV_CP_PLUGIN_FILENAME).'-'.$locale.'.mo';
return load_textdomain(str_replace('.php','',WPDEV_CP_PLUGIN_FILENAME), $mofile);
} return
false;
}
//Get array of menu and selected item inside of one array
function get_menu_array() {
if ($this->menu !== false) return $this->menu; // caching result
$top_menu = explode('|', get_option('wpdev_mc_menu_content'));
$top_menu_label = explode('|', get_option('wpdev_mc_menu_hints'));
$top_menu_links = explode('|', get_option('wpdev_mc_menu_links'));
$top_submenu_id = explode('|', get_option('wpdev_mc_submenu_id'));
$menu_array = array();
$slct = false;
// Function for multi array sorting
function array_sort_by_property($array, $key) {
if(empty ($array)) return $array;
$final_sorted_array = array();
$key_array = array();
for ($i = 0 ; $i < count($array) ; $i++) {
$key_array[$i] = $array[$i]->{$key};
}
asort($key_array);
foreach ($key_array as $key_num => $value) {
array_push($final_sorted_array, $array[ $key_num] );
}
return $final_sorted_array;
}
for ($i = 0 ; $i < count($top_menu) ; $i++) {
// C H I L D S ///////////////////////////////////////////////////////////////////////////////////////////////////////////
$my_childs = array();
$top_subm_id = explode ('=', $top_submenu_id[$i] );
if ($top_subm_id[0] == 'cat') { // C A T E G O R Y S U B M E N U /////////////////////////////////////////////////////
$categorys = get_categories('hide_empty=0&child_of='.$top_subm_id[1]);
$ii=0;
$ic=count($categorys);
$my_class ='';
$categorys = array_sort_by_property($categorys,'term_order');
if ($ic > 0) {
$perma_real = 'http://' . $_SERVER['HTTP_HOST'] .$_SERVER['REQUEST_URI'] ;
global $post; // If showing right now POST so then get URLs from the Category.
$cats_links = array();
if ( get_permalink($post->ID) == $perma_real) {
$cats_id = wp_get_post_categories($post->ID);
foreach ($cats_id as $c_id) {
$cats_links[]=get_category_link($c_id);
}
}
for ($ii = 0 ; $ii < $ic ; $ii++) {
$category = $categorys[$ii];
$my_class = '';
$perma_load = get_category_link($category->term_id);
if ($ii == $ic-1) $my_class = ' class="last_submenu" ';
if ( str_replace('/','',$perma_load) == str_replace('/','',$perma_real) ) {
$my_class = ' class="selected" ';
$slct = $i;
}
else { // Check URLS according posts if its showing now, compare real URL to urls of categories where can be post
foreach ($cats_links as $perma_real) {
if ( str_replace('/','',$perma_load) == str_replace('/','',$perma_real) ) {
$my_class = ' class="selected" ';
$slct = $i;
}
}
}
$my_childs[] =array(
'class' => $my_class,
'link' => get_category_link($category->term_id),
'icon' => $category->term_icon, // 'cat-'.$category->slug.'.jpg', // Need to think and set goog name
'title' => $category->name
);
}
}
} elseif( ($top_subm_id[0] == 'page') || ($top_subm_id[0] == 'pages') ) { // P A G E S S U B M E N U ///////////////////////////////////////////////////////
if ($top_subm_id[0] == 'page')
$pages = get_pages( array('child_of' => $top_subm_id[1], 'sort_column' => 'menu_order') );
else
$pages = get_pages( array('child_of' => -1, 'sort_column' => 'menu_order', 'include' => $top_subm_id[1]) );
$ii=0;
$ic=count($pages);
$my_class ='';
for ($ii = 0 ; $ii < $ic ; $ii++) {
$page = $pages[$ii];
$my_class = '';
$perma_load = get_page_link($page->ID);
$perma_real = 'http://' . $_SERVER['HTTP_HOST'] .$_SERVER['REQUEST_URI'] ;
if ($ii == $ic-1) $my_class = ' class="last_submenu" ';
if ( str_replace('/','',$perma_load) == str_replace('/','',$perma_real) ) {
$my_class = ' class="selected" ';
$slct = $i;
}
$my_childs[] =array(
'class' => $my_class,
'link' => get_page_link($page->ID),
'icon' => $page->post_icon, // 'page-'.$page->post_name.'.jpg', // Need to think and set goog name
'title' => $page->post_title
);
}
}
// L I N K S /////////////////////////////////////////////////////////////////////////////////////////////////////////////
if( strpos( $top_menu_links[$i] , ':') === false)
$link_url = get_option('home') . '/' . $top_menu_links[$i] ;
else
$link_url = $top_menu_links[$i] ;
// check if right now atadress bar this link
$perma_real = 'http://' . $_SERVER['HTTP_HOST'] .$_SERVER['REQUEST_URI'] ;
if ( str_replace('/','',$link_url) == str_replace('/','',$perma_real) ) {
$slct = $i;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$menu_array[]=array(
'title' => $top_menu[$i],
'hint' => $top_menu_label[$i],
'link' => "href='" . $link_url . "'",
$top_subm_id[0] => $top_subm_id[1],
'childs' => $my_childs
);
}
if ($slct !== false) {
$menu_array_selected = $menu_array[$slct];
$menu_array_selected['selected_num'] = $slct;
}
$result = array('menu' => $menu_array, 'selected' =>$menu_array_selected);
$this->menu = $result;
//debugebg( $result , true );
return $result;
}
// Make Dir in cickle
function wpdev_mk_dir($path, $mode = 0777) {
if (DIRECTORY_SEPARATOR == '/')
$path=str_replace('\\','/',$path);
else
$path=str_replace('/','\\',$path);
if ( is_dir($path) || empty($path) ) return true; // Check if directory already exists
if ( is_file($path) ) return false; // Ensure a file does not already exist with the same name
$dirs = explode(DIRECTORY_SEPARATOR , $path);
$count = count($dirs);
$path = $dirs[0];
for ($i = 1; $i < $count; ++$i) {
if ($dirs[$i] !="") {
$path .= DIRECTORY_SEPARATOR . $dirs[$i];
if ( !is_dir($path) && ( strpos($_SERVER['DOCUMENT_ROOT'],$path)===false ) ) {
if (!is_dir($path) && !mkdir($path, $mode)) return false;
}
}
}
return true;
}
// A D M I N S I D E /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// H E A D
// add hook for printing scripts only at this plugin page
function on_add_admin_js_files() {
wp_print_scripts( array( 'sack' ));
add_action('admin_head', array(&$this, 'head_print_js_css' ), 1); // Write inline scripts and CSS at HEAD
}
// Print NOW admin J a v a S cr i p t & C S S
function head_print_js_css() {
if (! is_admin()) wp_print_scripts('jquery');
do_action('wpdev_cp_js_define_variables');
// S T Y L E S //////////////////////////////////////////////////////////////////////////////////////// ?>
';
?>
';
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// M E N U C O M P O U S E R
function content_of_compose_menu_page() {
?>
|
on_save_changes();
switch ($_GET['tab']) {
case 'compouse':
$this->write_content_of_compose_menu_page();
break;
case 'submenu':
$this->write_content_of_compose_sub_menu_page();
break;
default:
$this->write_content_of_compose_menu_page();
break;
}
}
// CONTENT OF THE ADMIN PAGE
function write_content_of_compose_menu_page () {
?>
write_content_of_compose_sub_menu_page();
}
// CONTENT OF THE ADMIN PAGE
function write_content_of_compose_sub_menu_page () {
?>
|
|
|
dirList($this->icons_dir .'/');
switch ($_GET['tab']) {
case 'page':
$this->write_pages_table($files);
break;
case 'category':
$this->write_category_table($files);
break;
case 'add_icons':
$this->write_add_icons();
$this->write_delete_icons_page($files);
break;
case 'settings':
$this->write_icons_settings();
break;
default:
$this->write_add_icons();
$this->write_delete_icons_page($files);
break;
}
}
function write_icons_settings() {
?>
\n";
echo $output;
if ( count($row['childs']) > 0 )
$this->write_rows($row['childs'], $files, $class, $depth . ' - ');
}
}
// Get category array from wordpress native structure -- Huge functions which is have correct work but I think need some optimisation
function get_category_tree() {
$cats = get_categories('hide_empty=0');
$cats_id=array();
$cats_work = array();
$cats_sort = array();
// make temp work arrays
foreach ($cats as $cat) {
$cats_id[ $cat->term_id ] = $cat->parent;
$cats_work[$cat->term_id] = $cat;
$cats_sort[$cat->term_id] = $cat->term_order;
}
//Sorting array based on values
asort($cats_sort);
// Recursive function for Gets array of all childs ID from specific node in order from childest to root
function get_tree_node($key, $cats_id) {
if ($cats_id[ $key ] == 0 ) return array(0);
else {
$my_node = get_tree_node( $cats_id[ $key ], $cats_id);
array_push( $my_node, $cats_id[ $key ] );
return $my_node;
}
}
// Here we are get for each elamnt - pathes from root to childest node
// Gets array of all childs ID
$cats_fin = array();
foreach ($cats_id as $key=>$value) {
$cats_fin[$key] = get_tree_node($key , $cats_id);
}/**/
// transform childs array in string format line
foreach ($cats_fin as $key=>$value) {
$temp_node = '';
foreach ($value as $v) $temp_node .= $v;
$cats_fin[$key] = $temp_node;
}/**/
// this is function is needed for sorting array with strings node. At top will be longest node, its need for start working with childes yoang node
// Its primary order function based on parents
function sort_max_length($a,$b) {
if ( strlen($a) == strlen($b) ) return 0;
return ( strlen($a) < strlen($b) ) ? 1 : -1;
}
// Sort array
uasort($cats_fin, 'sort_max_length');
$new_sort_fin_array = array();
$order = 0;
$last_string = '';
// Create here work archive for future sorting by 2 collumns
foreach ($cats_fin as $key => $value) {
// Here we are checking if we take other parent path node
if ( strlen($value) != strlen($last_string) ) $order++;
array_push($new_sort_fin_array,array('id' => $key, 'data' => $value, 'order' => $order, 'sub_order' => $cats_sort[$key]));
$last_string = $value;
}
// Function for multi array sorting
function array_sort_by_2keys($array, $key, $key2) {
if(empty ($array)) return $array;
function get_non_exist_2nd_key($final_sorted_array_keys, $idx1, $idx2) {
if ( isset($final_sorted_array_keys[$idx1][$idx2] ) ) {
$idx2++;
return get_non_exist_2nd_key($final_sorted_array_keys, $idx1, $idx2);
} else return ($idx2);
}
$final_sorted_array = $key_array = $key_array_real = $final_sorted_array_keys = array();
for ($i = 0 ; $i < count($array) ; $i++) {
$key_array[$i] = $array[$i][$key];
}
asort($key_array); // Sort primary keys
for ($i = 0 ; $i < count($array) ; $i++) {
$key2_array[$i] = $array[$i][$key2];
}
asort($key2_array); // sort secondary keys
foreach ($array as $key_num => $value) {
$final_sorted_array_keys[ $key_array[$key_num] ][ get_non_exist_2nd_key($final_sorted_array_keys, $key_array[$key_num], $key2_array[$key_num]) ] = $key_num;
//$final_sorted_array_keys[ $key_array[$key_num] ][ $key2_array[$key_num] ] = $key_num;
} // create multi array with 2 keys
ksort($final_sorted_array_keys); // sort key array by 1st key
foreach ($final_sorted_array_keys as $key_num => $value) {
ksort($final_sorted_array_keys[$key_num]);
} // sort key array by 2nd key
foreach ($final_sorted_array_keys as $key_num => $value) {
foreach ($value as $key_num2 => $value_real) {
array_push($key_array_real, $value_real);
}
} // create one array with indeses innormal sort order
foreach ($key_array_real as $key_num => $value) { // create sorted array
array_push($final_sorted_array, $array[ $value] );
}
return $final_sorted_array;
}
$new_sort_fin_array = array_sort_by_2keys($new_sort_fin_array,'order','sub_order');
// create here Final ordered array by parents and by sort order
$cats_fin = array();
foreach ($new_sort_fin_array as $key => $item) {
$cats_fin[$item['id']] = $item['data'];
}
$ik = array();
$wa = array();
//generate temp array with index and keys and final work array whch will be return
foreach ($cats_fin as $key => $value) {
array_push($ik,$key) ; // here we cerate order in which we willwork with ID
$wa[$key] = array( 'childs' => array() , 'object' => $cats_work[$key] ) ;
}
// Go throug sorted array from longest node to root And
// set active node as child to his parent if node has parent
for($i=0; $i< count( $ik )-1; $i++) {
for($j = $i+1; $jparent == $ik[$j] ) {
$wa[ $ik[$j] ]['childs'][ $ik[$i] ] = $wa[ $ik[$i] ];
unset( $wa[ $ik[$i] ]);
break;
}
}
}
//debug1($wa,0);/**/
return $wa;
}
// Insert images inside of standard categories
function wp_list_categories_icons($output) {
$my_childs = array();
$categorys = get_categories('hide_empty=0&child_of=0');
$ii=0;
$ic=count($categorys);
$my_class ='';
if ($ic > 0) {
for ($ii = 0 ; $ii < $ic ; $ii++) {
$category = $categorys[$ii];
$my_class = '';
$perma_load = get_category_link($category->term_id);
$perma_real = 'http://' . $_SERVER['HTTP_HOST'] .$_SERVER['REQUEST_URI'] ;
if ($ii == $ic-1) $my_class = ' class="last_submenu" ';
if ( str_replace('/','',$perma_load) == str_replace('/','',$perma_real) ) {
$my_class = ' class="selected" ';
$slct = $i;
}
$my_childs[] =array(
'class' => $my_class,
'link' => get_category_link($category->term_id),
'icon' => $category->term_icon, // 'cat-'.$category->slug.'.jpg', // Need to think and set goog name
'title' => $category->name
);
}
}
foreach ($my_childs as $pg) {
if (! empty ($pg['icon']) ) {
$pos = strpos($output, '"' . $pg['link'] . '"'); // Get position of link inside output
if ( $pos !== false) {
$pos = strpos($output, '>' ,$pos); // Get position of end of A attribute
$afterImg = $beforeImg = '';
$pos = apply_cp_filter('wpdev_pos_img_category',$pos, $output);
$beforeImg = apply_cp_filter('wpdev_before_img_category','');
$afterImg = apply_cp_filter('wpdev_after_img_category','');
if ( $pos !== false) {
$pos++;
$output = substr($output, 0, $pos) . $beforeImg . ''. $afterImg . substr($output, $pos); //Insert icon
}
}
}
}
return $output;
}
// Get array of images - icons inside of this directory
function dirList ($directory) {
// create an array to hold directory list
$results = array();
// create a handler for the directory
$handler = opendir($directory);
// keep going until all files in directory have been read
while ($file = readdir($handler)) {
// if $file isn't this directory or its parent,
// add it to the results array
if ( $file != '.' &&
$file != '..'
//&& ( strpos($file, '-'. get_option( 'wpdev_mc_icon_size_w' ) . 'x' . get_option( 'wpdev_mc_icon_size_h' ) ) !== false )
)
$results[] = $file;
}
// tidy up: close the handler
closedir($handler);
// done!
return $results;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// S E T T I N G S
// Content of settings page
function content_of_settings_page() {
if ( isset( $_POST['Submit'] ) ) {
$wpdev_mc_icon_dir = $_POST['wpdev_mc_icon_dir']; /*
$client_cal_count = $_POST['client_cal_count'];
$start_day_weeek = $_POST['start_day_weeek'];
$cal_position = $_POST['cal_position']; /**/
$wpdev_mc_del_on_deactive = $_POST['wpdev_mc_del_on_deactive']; // check
$wpdev_copyright = $_POST['wpdev_mc_copyright']; // check
$wpdev_mc_icon_size_w = $_POST['wpdev_mc_icon_size_w'];
$wpdev_mc_icon_size_h = $_POST['wpdev_mc_icon_size_h'];
$wpdev_mc_icon_crop = $_POST['wpdev_mc_icon_crop']; // check
////////////////////////////////////////////////////////////////////////////////////////////////////////////
if ( get_option( 'wpdev_mc_icon_dir' ) !== false ) update_option( 'wpdev_mc_icon_dir' , $wpdev_mc_icon_dir );
else add_option('wpdev_mc_icon_dir' , $wpdev_mc_icon_dir );
////////////////////////////////////////////////////////////////////////////////////////////////////////////
if ( get_option( 'wpdev_mc_icon_size_w' ) !== false ) update_option( 'wpdev_mc_icon_size_w' , $wpdev_mc_icon_size_w );
else add_option('wpdev_mc_icon_size_w' , $wpdev_mc_icon_size_w );
////////////////////////////////////////////////////////////////////////////////////////////////////////////
if ( get_option( 'wpdev_mc_icon_size_h' ) !== false ) update_option( 'wpdev_mc_icon_size_h' , $wpdev_mc_icon_size_h );
else add_option('wpdev_mc_icon_size_h' , $wpdev_mc_icon_size_h );
////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (isset( $wpdev_mc_icon_crop )) $wpdev_mc_icon_crop = 'On';
else $wpdev_mc_icon_crop = 'Off';
if ( get_option( 'wpdev_mc_icon_crop' ) !== false ) update_option('wpdev_mc_icon_crop' , $wpdev_mc_icon_crop );
else add_option('wpdev_mc_icon_crop' , $wpdev_mc_icon_crop );
////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (isset( $wpdev_mc_del_on_deactive )) $wpdev_mc_del_on_deactive = 'On';
else $wpdev_mc_del_on_deactive = 'Off';
if ( get_option( 'wpdev_mc_is_delete_on_deactive' ) !== false ) update_option('wpdev_mc_is_delete_on_deactive' , $wpdev_mc_del_on_deactive );
else add_option('wpdev_mc_is_delete_on_deactive' , $wpdev_mc_del_on_deactive );
////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (isset( $wpdev_copyright )) $wpdev_copyright = 'On';
else $wpdev_copyright = 'Off';
if ( get_option( 'wpdev_mc_copyright' ) !== false ) update_option( 'wpdev_mc_copyright' , $wpdev_copyright );
else add_option('wpdev_mc_copyright' , $wpdev_copyright );
} else {
$wpdev_mc_icon_dir = get_option( 'wpdev_mc_icon_dir' );
$wpdev_mc_del_on_deactive = get_option( 'wpdev_mc_is_delete_on_deactive' ); // check
$wpdev_copyright = get_option( 'wpdev_mc_copyright' ); // check
$wpdev_mc_icon_size_w = get_option( 'wpdev_mc_icon_size_w' );
$wpdev_mc_icon_size_h = get_option( 'wpdev_mc_icon_size_h' );
$wpdev_mc_icon_crop = get_option( 'wpdev_mc_icon_crop' ); // check
}
?>
head_print_js_css();
// wp_print_scripts( array( 'sack' )); // Define custom A J A X respond at Client side
}
////////////////////////////////////////////////////////////////////
//Get string of menu for showing
function get_menu() {
$top_menu = $this->get_menu_array();
$i=0;
$ic=count($top_menu['menu']);
$menu_line = '
' ;
}
// Get string of submenu to show
function get_submenu() {
$top_menu = $this->get_menu_array();
$my_submenu = '';
if (! empty($top_menu['selected'])) { // cehck if show submenu at entered link
if ( count($top_menu['selected']['childs']) > 0 ) { // check if some childs of submenu here
$blgsd = get_bloginfo('stylesheet_directory'); //TODO: SET DIRECTORY TO ICONS
$my_submenu .= '