Name, $br->Version)); } /** * Load the language domain */ navt_loadtext_domain(); /** * Initialize the plugin for the backend */ NAVT::install_check(); NAVT::register_scripts(); /** * Determine which page is being loaded */ $uri = $_SERVER['REQUEST_URI']; /** * Add header information to NAVT List page */ if( stristr($uri, 'navt.php') != false ) { add_action('admin_print_scripts', array('NAVT', 'navt_list_page'), 1); } elseif( stristr($uri, 'plugins.php') != false ) { add_action('admin_print_scripts', array('NAVT', 'plugin_page'), 1); } else { /** * Add header information to the backend header for * certain backend pages */ if((stristr($uri,'page.php') !== false) || (stristr($uri, 'plugins.php') !== false) || (stristr($uri, 'categories.php') !== false) || (stristr($uri, 'user-edit.php') !== false) ) { add_action('admin_print_scripts', array('NAVT', 'admin_head'), 1); } } /** * Set hooks for posts */ navt_write_debug(NAVT_INIT, sprintf("%s::%s - setting callbacks\n", __CLASS__, __FUNCTION__)); add_action('save_post', array('NAVT_BE', 'save_post_wpcb'), 10, 2); add_action('delete_post', array('NAVT_BE', 'delete_post_wpcb')); /** * Set hooks for user profiles */ add_action('profile_update', array('NAVT_BE', 'profile_update_wpcb')); add_action('user_register', array('NAVT_BE', 'user_register_wpcb')); add_action('delete_user', array('NAVT_BE', 'delete_user_wpcb')); /** * Set hooks for categories */ add_action('created_category', array('NAVT_BE', 'created_category_wpcb')); // @since 95.30 add_action('edited_category', array('NAVT_BE', 'edited_category_wpcb')); // @since 95.30 add_action('delete_category', array('NAVT_BE', 'delete_category_wpcb')); /** * Admin menu */ add_action('admin_menu', array('NAVT', 'admin_menu_wpcb'), 10); /** * category exclusions */ add_filter('list_terms_exclusions', array('NAVT_BE', 'list_terms_exclusions_wpcb')); /** * Content filer hook */ add_filter('the_content', array('NAVT_FE','the_content_wpcb')); /** * Attach the plugin to the theme */ add_action('wp_head', array('NAVT_FE', 'wp_head_wpcb')); }// end function /** * Registered callback function - adds the plugin options to the Management submenu * * @see Word Press function add_action('admin_menu') * @since 95.40 - moved plugin admin from plugin page to the bottom of the list page * this is because WordPress MU can block plugin page access by users. * */ function admin_menu_wpcb() { // Add this menu item to the "Manage" menu to manage menus if ( function_exists('add_management_page') ) { // requires admin privedges add_management_page('Menu Management', 'NAVT Lists', 8, __FILE__, array('NAVT', 'configure')); } }// end function /** * Registered Word Press callback that displays plugins administration page */ function configure() { // includes the option-form script include(NAVT_PLUGINPATH . '/app/navt-display.php'); }// end function /** * Registered WordPress callback that adds css and script information to the admin page header. */ function navt_list_page() { wp_print_scripts(array('navt_admin')); ?> = 9542) ) { // .95.30 adds ext field // .95.42 adds ex2 field navt_write_debug(NAVT_INIT, sprintf("%s::%s 9452+ conversion\n", __CLASS__, __FUNCTION__)); $new_map = array(); $old_map = NAVT::load_map(); for( $idx = 0; $idx < count($old_map); $idx++ ) { $ttl = $old_map[$idx][TTL]; $nme = $old_map[$idx][NME]; $ttl = str_replace('"', "'", $ttl); // convert double quotes to single $nme = (isBlank($nme)) ? $ttl: $nme; // make sure this is not empty $nme = str_replace('"', "'", $nme); // convert double quotes to single $grp = strtoupper($old_map[$idx][GRP]); // forces names to upper case $new_map = array( GRP => $grp, TYP => $old_map[$idx][TYP], IDN => $old_map[$idx][IDN], TTL => $ttl, NME => $nme, OPT => $old_map[$idx][OPT], EXT => $old_map[$idx][EXT], LVL => '0', EX2 => ''); } // Update the map and the installed version id NAVT::update_option(SERIALIZED_MAP, $new_map); $navt_map = ''; } /** * For versions prior to .96 */ if( ($installed_version < 96000) && ($this_version >= 96000) ) { navt_write_debug(NAVT_INIT, sprintf("%s::%s 96000+ conversion\n",__CLASS__, __FUNCTION__)); $map = NAVT::load_map(); $avatar = NAVT::get_url() . '/' . IMG_AVATAR; $assets = array(); // indexed by item type and idn $config = array(); // indexed by group and css selector id $group_options = array(); // indexed by group name $assets[TYPE_ELINK][ELINKIDN] = array( TYP => TYPE_ELINK, IDN => ELINKIDN, TTL => 'http://', NME => ELINKTXT, OPT => '0', EXT => '', LVL => '0', EX2 => ''); $assets[TYPE_SEP][SEPIDN] = array( TYP => TYPE_SEP, IDN => SEPIDN, TTL => DIVIDERTXT, NME => DIVIDERTXT, OPT => '0', EXT => '', LVL => '0', EX2 => ''); $assets[TYPE_LINK][HOMEIDN] = array( TYP => TYPE_LINK, IDN => HOMEIDN, TTL => HOMETXT, NME => HOMETXT, OPT => '0', EXT => '', LVL => '0', EX2 => ''); $assets[TYPE_LINK][LOGINIDN] = array( TYP => TYPE_LINK, IDN => LOGINIDN, TTL => LOGINTXT, NME => LOGINTXT, OPT => '0', EXT => '', LVL => '0', EX2 => ''); // Create the 'asset' array - // contains each wp asset for( $idx = 0; $idx < count($map); $idx++ ) { if( $map[$idx][TYP] === TYPE_PAGE || $map[$idx][TYP] === TYPE_CAT || $map[$idx][TYP] === TYPE_AUTHOR ) { $opt = '0'; $ext = ''; if( TYPE_AUTHOR === $map[$idx][TYP] ) { $opt = (SHOW_AVATAR | USE_DEF_AVATAR); $ext = $avatar; } elseif( TYPE_PAGE === $map[$idx][TYP] ) { $is_draft = (( intval($map[$idx][OPT], 10) & ISDRAFTPAGE ) ? 1: 0); if($is_draft) { $opt = ISDRAFTPAGE; } } // indexed by type and idn $assets[ $map[$idx][TYP] ][ $map[$idx][IDN] ] = array( TYP => $map[$idx][TYP], IDN => $map[$idx][IDN], TTL => $map[$idx][TTL], NME => $map[$idx][NME], OPT => $opt, LVL => '0', EXT => $ext, EX2 => '' ); } } // Create the 'config' array - // contains each configured item $seq = 1000; for( $idx = 0; $idx < count($map); $idx++ ) { $grp = $map[$idx][GRP]; if( $grp != ID_DEFAULT_GROUP ) { $item = $map[$idx]; $id = NAVT::make_id($item, $seq++); $opt = intval($item[OPT], 10); if(!array_key_exists($grp, $group_options) ) { // add group to the group options array $group_options[strtolower($grp)] = NAVT::mk_group_config(); } if($opt & HAS_DD_OPTION) { if( !($group_options[strtolower($grp)]['options'] & HAS_DD_OPTION) ) { // move this option to the group $group_options[strtolower($grp)]['options'] |= HAS_DD_OPTION; } // remove this option from the item $opt -= HAS_DD_OPTION; } if($opt & HAS_NOSTYLE) { if( !($group_options[strtolower($grp)]['options'] & HAS_NOSTYLE) ) { // move this option to the group $group_options[strtolower($grp)]['options'] |= HAS_NOSTYLE; } // remove this option from the item $opt -= HAS_NOSTYLE; } // indexed by group and id $config[strtolower($grp)][ $id ] = array( GRP => strtolower($grp), TYP => $item[TYP], IDN => $item[IDN], TTL => $item[TTL], NME => $item[NME], OPT => $opt, LVL => $item[LVL], EXT => $item[EXT], EX2 => $item[EX2]); } } navt_write_debug(NAVT_INIT, sprintf("%s::%s assets\n",__CLASS__, __FUNCTION__), $assets); navt_write_debug(NAVT_INIT, sprintf("%s::%s group options\n",__CLASS__, __FUNCTION__), $group_options); navt_write_debug(NAVT_INIT, sprintf("%s::%s config\n",__CLASS__, __FUNCTION__), $config); NAVT::update_option(ICONFIG, $config); NAVT::update_option(ASSETS, $assets); NAVT::update_option(GCONFIG, $group_options); NAVT::delete_option(SERIALIZED_MAP); // no going back now $navt_map = ''; } navt_write_debug(NAVT_INIT, sprintf("%s::%s - end\n",__CLASS__, __FUNCTION__)); return; } /** * Create a default group configuration * * @return array */ function mk_group_config() { return( array( 'options' => USE_NAVT_DEFAULTS, 'select_size' => 1, 'css' => array('ulid' => '' , 'ul' => '', 'li' => '', 'licurrent' => '', 'liparent' => '', 'liparent_active' => ''), 'selector' => array('xpath' => '', 'before' => '', 'after' => '', 'option' => 0), 'display' => array( 'show_on' => (SHOW_ON_HOME | SHOW_ON_ARCHIVES | SHOW_ON_SEARCH | SHOW_ON_ERROR | SHOW_ON_PAGES | SHOW_ON_POSTS), 'posts' => array('on_selected' => 'show', 'ids' => array()), 'pages' => array('on_selected' => 'show', 'ids' => array()) )) ); } /** * Returns the version last saved in the data options * * @return integer */ function get_installed_version() { $ver = NAVT::get_option(VERSIONID); if( empty($ver) || $ver === false ) { $ver = 1; } else { $ver = str_replace('.', '', $ver); } return(intval($ver, 10)); } /** * Uninstalls the plugin - removes the plugin options from the database */ function uninstall() { navt_write_debug(NAVT_INIT, sprintf("%s::%s - start\n", __CLASS__, __FUNCTION__)); NAVT::delete_option(SERIALIZED_MAP); /* depreciated */ NAVT::delete_option(LASTMODIFIED); NAVT::delete_option(SCHEME); NAVT::delete_option(VERSIONID); NAVT::delete_option(VERCHECK); NAVT::delete_option(DEF_ADD_GROUP); NAVT::delete_option(INSTALLED); NAVT::delete_option(TIPS); /* depreciated */ NAVT::delete_option(ASSETS); NAVT::delete_option(ICONFIG); NAVT::delete_option(GCONFIG); navt_write_debug(NAVT_INIT, sprintf("%s::%s - end\n", __CLASS__, __FUNCTION__)); }// end function /** * register scripts used by this plugin */ function register_scripts() { navt_write_debug(NAVT_INIT, sprintf("%s::%s - start\n", __CLASS__, __FUNCTION__)); $url = NAVT::get_url(); $jquery_ui_lib = '/js/jquery-ui'; $jquery_plugins = '/js/plugins'; wp_deregister_script('jquery'); wp_register_script('jquery121', $url . '/js/jquery.js', array(), '1.2.1'); wp_register_script('json', $url . '/js/json.js', array(), '2.0'); wp_register_script('rc_js', $url . '/js/rc.js', array('jquery121'), '1.92'); wp_register_script('navt_options_js', $url . '/js/navtoptions.js', array('jquery121')); // plugins wp_register_script('jquery_dim_ui', $url . $jquery_plugins . '/jquery.dimensions.js', array('jquery121'), '1.0'); wp_register_script('jquery_modal', $url . $jquery_plugins . '/jquery.modal.js', array('jquery_dim_ui'), '1.1.1'); // ui wp_register_script('jquery_mouse_ui', $url . $jquery_ui_lib . '/ui.mouse.js', array('jquery_modal'), '1.0'); wp_register_script('jquery_drag_ui', $url . $jquery_ui_lib . '/ui.draggable.js', array('jquery_mouse_ui'), '1.0'); wp_register_script('jquery_drop_ui', $url . $jquery_ui_lib . '/ui.droppable.js', array('jquery_drag_ui'), '1.0'); wp_register_script('jquery_sort_ui', $url . $jquery_ui_lib . '/ui.sortable.js', array('jquery_drop_ui'), '1.0'); wp_register_script('navt_admin', $url . '/js/navtadmin.js.php', array('jquery_sort_ui', 'rc_js', 'json'), SCRIPTVERS); navt_write_debug(NAVT_INIT, sprintf("%s::%s - end\n", __CLASS__, __FUNCTION__)); } /** * Computes this plugin's url * * @return string URL */ function get_url() { global $navt_root_dir; return $navt_root_dir; }// end function /** * Creates the run time configuration array from the ICONFIG array stored * in the database. * * @return array menu map */ function load_map() { global $navt_map; $installed_version = NAVT::get_installed_version(); navt_write_debug(NAVT_INIT, sprintf("%s::%s\n", __CLASS__, __FUNCTION__)); if( !is_array($navt_map) || !count($navt_map) ) { if( $installed_version < 96000 ) { $navt_map = NAVT::get_option(SERIALIZED_MAP); } else { // get the configuration data and convert it $groups = NAVT::get_option(ICONFIG); if( is_array($groups) ) { foreach( $groups as $group => $members) { foreach($members as $member ) { $navt_map[] = array( GRP => $group, TYP => $member[TYP], IDN => $member[IDN], TTL => $member[TTL], NME => $member[NME], OPT => $member[OPT], EXT => $member[EXT], LVL => $member[LVL], EX2 => $member[EX2]); } } } else { navt_write_debug(NAVT_INIT, sprintf("%s::%s - no configuration\n", __CLASS__, __FUNCTION__)); } } } //navt_write_debug(NAVT_INIT, sprintf("%s::%s version: %s\n", __CLASS__, __FUNCTION__, $installed_version), $navt_map); return($navt_map); } /** * Builds the assets configuration from the currently defined pages, categories and users * * @return array * @version .96 */ function build_assets() { $assets = array(); navt_write_debug(NAVT_INIT, sprintf("%s::%s - start\n", __CLASS__, __FUNCTION__)); /** * Add default assets * @since .96.00 */ $assets[TYPE_ELINK][ELINKIDN] = array( TYP => TYPE_ELINK, IDN => ELINKIDN, TTL => 'http://', NME => ELINKTXT, OPT => '0', EXT => '', LVL => '0', EX2 => ''); $assets[TYPE_SEP][SEPIDN] = array( TYP => TYPE_SEP, IDN => SEPIDN, TTL => DIVIDERTXT, NME => DIVIDERTXT, OPT => '0', EXT => '', LVL => '0', EX2 => ''); $assets[TYPE_LINK][HOMEIDN] = array( TYP => TYPE_LINK, IDN => HOMEIDN, TTL => HOMETXT, NME => HOMETXT, OPT => '0', EXT => '', LVL => '0', EX2 => ''); $assets[TYPE_LINK][LOGINIDN] = array( TYP => TYPE_LINK, IDN => LOGINIDN, TTL => LOGINTXT, NME => LOGINTXT, OPT => '0', EXT => '', LVL => '0', EX2 => ''); // Build a new map from the database information $all_page_ids = get_all_page_ids(); // @since 95.30 $all_cat_ids = get_all_category_ids(); // @since 95.30 $users = get_users_of_blog(); /** Create the controls for each author * @since updated in .96 */ foreach($users as $user) { $u = get_userdata($user->user_id); $avatar = NAVT::get_url() . '/' . IMG_AVATAR; $opt = (SHOW_AVATAR | USE_DEF_AVATAR); $nme = ( isBlank($u->display_name) ? $u->user_login : $u->display_name); navt_write_debug(NAVT_INIT, sprintf("%s::%s USER\n", __CLASS__, __FUNCTION__), $u); // Set options $assets[TYPE_AUTHOR][$user->user_id] = array( TYP => TYPE_AUTHOR, IDN => $user->user_id, TTL => $u->user_login, NME => $nme, OPT => $opt, EXT => $avatar, LVL => '0', EX2 => ''); } /** * Create the controls for each static page * @since .96.00 */ if($all_page_ids) { foreach($all_page_ids as $id) { $post = get_post($id); if(is_object($post) && $post->post_type == 'page') { $ttl = str_replace('"', "'", $post->post_title); $opt = (($post->post_status == 'draft') ? ISDRAFTPAGE: '0'); $assets[TYPE_PAGE][$id] = array(TYP => TYPE_PAGE, IDN => $id, TTL => $ttl, NME => $ttl, OPT => $opt, EXT => '',LVL => '0', EX2 => ''); } } }// end if /** * Create the controls for each category * @since .96.00 */ if($all_cat_ids) { foreach($all_cat_ids as $id) { $cat = get_category($id); // @since 95.30 $ttl = str_replace('"', "'", $cat->cat_name); $assets[TYPE_CAT][$id] = array(TYP => TYPE_CAT, IDN => $id, TTL => $ttl, NME => $ttl, OPT => '0', EXT => '',LVL => '0', EX2 => ''); } }// end if navt_write_debug(NAVT_INIT, sprintf("%s::%s assets\n", __CLASS__, __FUNCTION__), $assets); navt_write_debug(NAVT_INIT, sprintf("%s::%s - end\n", __CLASS__, __FUNCTION__)); return($assets); }// end function /** * Returns the value of the option identified by 'key' * Calls the Word Press function by the same name * * @param string_type $key * @return mixed value of key */ function get_option($key) { return(get_option($key)); } /** * Adds the key/Value and description to the database * Calls the Word Press function by the same name * * @param string $key * @param mixed $value * @param string $description of option */ function add_option($key, $value, $description=NULL) { add_option($key, $value, $description); } /** * Updates the value of 'key' in the database * Calls the Word Press function by the same name * * @param string $key * @param mixed $value of key */ function update_option($key, $value) { global $navt_map; if( $key == SERIALIZED_MAP ) { $navt_map = $value; } update_option($key, $value); } /** * Deletes the option identified by 'key' from the database * Calls the Word Press function by the same name * * @param string $key */ function delete_option($key) { delete_option($key); } /** * Build a HTML dropdown list containing the navigation groups * * @param string $curgrp - currently selected group * @param string $selector_id - selector id used for the select statement * @param int $in - indentation level * @param int $exclude_default - exclude the default gorup * @param int $add_none - add 'none' to the option list * @return string - HTML select statement with options * @since .95.30 */ function build_group_dropdown($curgrp, $selector_id='', $in=3, $exclude_default=0, $add_none=0) { $dd = ''; $gcfg = NAVT::get_option(GCONFIG); if(is_array($gcfg) ) { $id = (isBlank($selector_id) ? 'group-select': $selector_id); $dd = "\n"._indentt($in)."\n"; } return($dd); } /** * Truncates text to $n length and adds an elipse * * @param string $text * @param integer $numb */ function truncate($text, $n) { // source: www.kigoobe.com if (strlen($text) > $n) { $text = substr($text, 0, ($n-3)); //$text = substr($text,0, strrpos($text," ")); $text .= '...'; } navt_write_debug(NAVT_GEN, sprintf("%s::%s truncated to: %s\n", __CLASS__, __FUNCTION__, $text)); return $text; } /** * Builds a HTML select containing the available avatars */ function build_avatar_list($options_only=1, $set_to_disabled=0, $id='avatars', $picked='', $in=0) { $html = ''; $url = NAVT::get_url(); $path = NAVT_PLUGINPATH . AVATAR_IMAGES . '/'; $files = NAVT::files_scan($path, array('png','gif','jpg','jpeg','bmp'), 1, false); $state = $set_to_disabled ? "disabled='disabled'":''; if( count($files) > 0 ) { if(!$options_only) { $html = sprintf("%s', _indentt($in)); } } return($html); } /** * Scan for files to be included in th * * @param string $path - where to begin the search * @param string $ext - type of file to search for, false == everything * @param integer $depth - depth of search * @param boolean $relative - true = scan is relative * @return array $files - array of files */ function files_scan($path, $ext = false, $depth = 1, $relative = true) { $files = array(); // Scan for all matching files NAVT::_files_scan($path, '', $ext, $depth, $relative, $files); return $files; } /** * Returns an array of filenames scanned in a directory * * @param string $base_path - where to begin the search * @param string $path - directory path * @param string $ext - type of file to search for * @param integer $depth - depth of search * @param boolean $relative - true = scan is relative * @param array $files - array of files */ function _files_scan($base_path, $path, $ext, $depth, $relative, &$files) { if (!empty($ext)) { if (!is_array($ext)) { $ext = array($ext); } $ext_match = implode('|', $ext); } // Open the directory if(($dir = @dir($base_path . $path)) !== false) { // Get all the files while(($file = $dir->read()) !== false) { // Construct an absolute & relative file path $file_path = $path . $file; $file_full_path = $base_path . $file_path; // If this is a directory, and the depth of scan is greater than 1 then scan it if(is_dir($file_full_path) and $depth > 1 and !($file == '.' or $file == '..')) { NAVT::_files_scan($base_path, $file_path . '/', $ext, $depth - 1, $relative, $files); // If this is a matching file then add it to the list } elseif(is_file($file_full_path) and (empty($ext) or preg_match('/\.(' . $ext_match . ')$/i', $file))) { $files[] = $relative ? $file_path : $file_full_path; } } // Close the directory $dir->close(); } } /** * create a unique selector id * * @param array $item * @return string - selector id * @since version .96 */ function make_id($item, $seq='') { $id = 'a'.SEP.$item[TYP].SEP.$item[IDN]; if( $seq != '' ) { $id .= '--'.$seq; } return($id); } /** * Returns a qualified group name * * @param string $n * @return string - cleaned string */ function clean_group_name($n) { $n = trim($n); $n = attribute_escape(strip_tags($n)); $n = sanitize_title_with_dashes($n); $n = stripslashes($n); $n = substr($n, 0, 10); // limit to 10 characters return($n); } /** * Returns a clean item alias * * @param string $n - cleaned string */ function clean_item_alias($n) { $n = trim($n); $n = attribute_escape(strip_tags($n)); $n = stripslashes($n); return($n); } /** * Adds the NAVT uninstall and reset rows to the NAVT plugin on the plugins page * * How hard is this? * @param string - name of the plugin */ function after_plugin_row_wpcb($plugin_name) { $is_navt = (( stristr($plugin_name, 'navt.php') === FALSE ) ? 0: 1); navt_write_debug(NAVT_GEN, sprintf("%s - %s, is_navt: %s\n", __FUNCTION__, $plugin_name, $is_navt)); if( $is_navt ) { $uninstall_url = NAVT::get_url() . "/app/navt_utl.php?navt_action=uninstall&plugin=$plugin_name&_wpnonce=@once@"; $reset_url = NAVT::get_url() . "/app/navt_utl.php?navt_action=reset"; $t[0] = __(" - Sets all NAVT created database options to their default values. This will cause any previously created Navigation Groups to be removed."); $t[1] = __(" - Removes all NAVT created database options and automatically deactivates the plugin."); $html = "
Uninstall/Reset NAVT Plugin Options
"; echo $html; } } /** * Ruturns a HOME page navigation item */ function make_home_link() { return(array(TYP => TYPE_LINK, IDN => HOMEIDN, TTL => HOMETXT, NME => HOMETXT, OPT => '0', EXT => '', LVL => '0', EX2 => '')); } }// end class NAVT /** * Test for an empty string * * @param string $string * @return boolean 1 = blank, 0 = not blank */ function isBlank($str) { $ret = 1; // assume it is blank if (!empty($str) && ($str != '')) { for ($i = 0; $i < strlen($str); $i++) { $c = substr($str, $i, 1); if ($c != " " ) { $ret = 0; } } } return($ret); } /** * Returns a string of spaces for HTML indentation * * @param integer $howmany_tabs- the number of indentation tabs to generate * @return string the indentation string */ function _indentt($howmany_tabs, $tabstring=' ') { $o = ''; for($x = 0; $x < $howmany_tabs; $x++ ) $o .= $tabstring; return($o); } /** * Returns a comma delineated string containing the names * of all the menu groups. */ function navt_getAllLists() { $gp = array(); $gcfg = NAVT::get_option(GCONFIG); // group configurations foreach( $gcfg as $group => $group_data ) { $gp[] = $group; } $out = ( count($gp) != 0 ) ? implode(',' , $gp) : null; return($out); } /** * Load localization file * */ function navt_loadtext_domain() { $locale = (( get_locale() == '' ) ? 'en_US' : $locale); $mofile = NAVT_PLUGINPATH . "/app/lang/navt-$locale.mo"; load_textdomain('navt_domain', $mofile); navt_write_debug(NAVT_INIT, sprintf("locale %s, mo: %s\n", $locale, $mofile)); } function navt_output_url() { echo(NAVT::get_url()); } @include('navt-extensions.php'); add_action( 'after_plugin_row', array('NAVT', 'after_plugin_row_wpcb'), 2, 1); add_action('init', array('NAVT', 'init')); ?>