", $before_text);
}
}
}
}
else {
// HTML Select format processing
if( isset($item['tok']) ) {
if( $item['tok'] == 's' ) {
// Start a form with a select
$forms[$form_id] .= NAVT_FE::mk_form($sNavGroupName, $form_id, $in+2, $style_flags, $select_size);
$form_open = 1; // form is open
}
elseif( $item['tok'] == 'e' ) {
$forms[$form_id] .= NAVT_FE::end_form($in+2);
$form_open = 0; // form is closed
$form_id++; // advance the form number
}
else {
// just one of the items
$nav_item = $item['tok'];
if( is_array($nav_item) ) {
$forms[$form_id] .= NAVT_FE::mk_html_select($nav_item, $in+4, $style_flags);
}
}
}
}
}// end for
//
// Final stages
//
// select item(s)
if( $is_select ) {
if( $form_open ) {
$forms[$form_id] .= NAVT_FE::end_form($in+1);
}
// if the select is to be wrapped in a 'ul' or 'ol' then it must be inside an 'li'
$is_ul = strpos($before_text, '
\n";
}
break;
}
case TYPE_ELINK: {
$dd_option = _indentt($in) . "\n";
break;
}
}// end switch item type
}
return($dd_option);
}
/**
* Creates a form for use with dropdown menus
*
* @param string $sGroupName
* @param integer $num
* @param integer $in
* @return returns a HTML
statement
*/
function end_form($in) {
navt_write_debug(NAVT_MAP, sprintf("%s::%s \n", __CLASS__, __FUNCTION__));
$html = _indentt($in+1) . "\n";
$html .= _indentt($in) . "\n";
return($html);
}
/**
* Examines the content of a page or post
*
* WordPress callback function (@see Word Press add_action('the_content')
*
* @param string $content - post or page content
* @since 95.38
*/
function the_content_wpcb($content) {
// syntax: [NAVT group=groupname, title=heading title] ]
// , title= is optional
$pattern = '/\[\s*NAVT\s*group\s*=\s*[a-z0-9]+\s*(\]|\s*,\s*title\s*=.+\])/im';
$matched = array();
if(! preg_match_all($pattern, $content, $matched, PREG_SET_ORDER)) {
return $content;
}
else {
$replacement = array();
foreach( $matched as $idx => $match ) {
foreach( $match as $nidx => $value ) {
if( $nidx == 0 ) {
// save the content to be replaced
$replacement[$idx]['content_string'] = $value;
$m = array();
$pattern = '/\s*group\s*=\s*[a-z0-9]+(\s*|,|\])/i'; // group=
if( preg_match($pattern, $value, $m) ) {
// isolate the group name
$str = preg_replace('/\s+/', '', $m[0]); // strip spaces
$group = preg_replace('/group=/' , '', $str); // remove 'group='
}
}
else {
// *may* contain a title - may not
$title = '';
$pattern = '/,\s*title\s*=.+/i';
if( preg_match($pattern, $value, $m) ) {
// isolate the title
$str = preg_replace('/,\s*title\s*=\s*/i', '', $m[0]); // remove 'title='
$str = preg_replace('/\]/i', '', $str); // remove the last ']'
$title = trim($str); // trim it on both ends
}
}
}
// save these
$replacement[$idx]['group'] = $group;
$replacement[$idx]['title'] = $title;
}
$new_content = $content;
foreach( $replacement as $idx => $arr ) {
// get the navigation group and replace the post/page contents
$text = navt_getlist($arr['group'], 0, $arr['title']);
$text = "
$text
";
$new_content = str_replace($arr['content_string'], $text, $new_content);
}
$content = $new_content;
}
return($content);
}
/**
* Returns a number representing the hierarchy of a page
*
* @param integer $id
* @param integer $level - hierarchy value (0 = top level)
* @return integer - hierarchy level
*/
function get_page_level($id, $level=0) {
$this_level = $level;
$pg = get_page($id);
if( $pg->post_parent != 0 ) {
$this_level++;
$this_level = NAVT_FE::get_page_level($pg->post_parent, $this_level);
}
return($this_level);
}
/**
* Returns a number representing the hierarchy of a category
*
* @param integer $id - category id
* @param integer $level - hierarchy value (0 = top level)
* @return integer - hierarchy level
*/
function get_category_level($id, $level=0) {
$this_level = $level;
$cat = get_category($id);
if( $cat->category_parent != 0) {
$this_level++;
$this_level = NAVT_FE::get_category_level($cat->category_parent, $this_level);
}
return($this_level);
}
/**
* Routine that does some rudimentatry checking of a user avatar
*
* @param string - avatar url
* @return boolean - 1 = url meets requirement, 0 - bad url or bad image file
*/
function check_avatar($avatar_url) {
// Parse the given url
$arr = parse_url($avatar_url);
$hasCorrectMime = 0;
if( !empty($arr['path']) ) {
$pi = pathinfo($arr['path']);
if( !empty($pi['basename']) && !empty($pi['extension'])) {
$ft = wp_check_filetype(trim($pi['basename']));
if(!empty($ft['type'])) {
$hasCorrectMime = (strstr($ft['type'], 'image') != false) ? 1: 0;
}
}
}
return($hasCorrectMime);
}
/**
* Returns a css class related to a user's wp role
*
* @param integer $user_id
* @return string - css class
*/
function get_userlevel_class($user_id) {
global $wpdb;
$level = intval(get_usermeta($user_id, $wpdb->prefix . 'user_level'), 10);
if( $level > 8 ) $class = 'administrator';
elseif( $level > 4 && $level < 8 ) $class = 'editor';
elseif( $level > 1 && $level < 5 ) $class = 'author';
elseif( $level == 1 ) 'contributor';
else $class = 'subscriber';
return($class);
}
/**
* Returns group 'style' information
*
* @param string $name - name of group
* @param array $cfg - the group configuration array
* @return integer $css_rules
*/
function set_style_flags($name, $cfg) {
return( intval($cfg[$name]['options'],10) & 0xffff );
}
/**
* Returns group 'HTML select' setting
*
* @param string $name - name of group
* @param array $cfg - the group configuration array
* @return boolean 1 if group is built using HTML select, 0 (zero) otherwise
*/
function is_html_select($name, $cfg) {
$options = intval($cfg[$name]['options'],10);
return(($options & HAS_DD_OPTION) ? 1: 0);
}
/**
* Returns group 'privacy' setting
*
* @param string $name - name of group
* @param array $cfg - the group configuration array
* @return boolean 1 if group is private, 0 (zero) otherwise
*/
function is_private_group($name, $cfg) {
$options = intval($cfg[$name]['options'],10);
navt_write_debug(NAVT_GEN, sprintf("%s::%s group private: %s\n", __CLASS__, __FUNCTION__, ($options & ISPRIVATE)));
return(($options & ISPRIVATE) ? 1: 0);
}
/**
* Returns 'page folding' setting
*
* @param string $name - name of group
* @param array $cfg - the group configuration array
* @return boolean 1 if group uses page folding, 0 (zero) otherwise
*/
function use_pagefolding($name, $cfg) {
$options = intval($cfg[$name]['options'],10);
return(($options & PAGE_FOLDING) ? 1: 0);
}
/**
* Returns 'page return' setting
*
* @param string $name - name of group
* @param array $cfg - the group configuration array
* @return boolean 1 if set to true, 0 (zero) otherwise
*/
function get_page_return($name, $cfg) {
$options = intval($cfg[$name]['options'],10);
return(($options & ADD_PAGE_RETURN) ? 1: 0);
}
/**
* Returns 'breadcrumb' setting
*
* @param string $name - name of group
* @param array $cfg - the group configuration array
* @return boolean 1 if set to true, 0 (zero) otherwise
*/
function use_breadcrumbs($name, $cfg) {
$options = intval($cfg[$name]['options'],10);
return(($options & ADD_BREADCRUMBS) ? 1: 0);
}
/**
* Returns the select box size for select menus
*
* @param string $name - name of group
* @param array $cfg - the group configuration array
* @return integer - selection size
*/
function get_select_size($name, $cfg) {
return( intval( $cfg[$name]['select_size'], 10 ) );
}
/**
* Returns the user defined UL class
*
* @param string $name - name of group
* @param array $cfg - the group configuration array
* @return string - user class
*/
function get_user_ul_class($name, $cfg) {
return( $cfg[$name]['css']['ul'] );
}
/**
* Returns the user defined UL class
*
* @param string $name - name of group
* @param array $cfg - the group configuration array
* @return string - user class
*/
function get_user_li_class($name, $cfg) {
return( $cfg[$name]['css']['li'] );
}
/**
* Determines whether or not the group can be displayed on the current web page
*
* @param string $name - name of group
* @param array $cfg - the group configuration array
* @return boolean 1 group can be displayed, 0 (zero) otherwise
*/
function can_display($name, $cfg) {
global $post, $wp_query;
$qo = $wp_query->get_queried_object();
$rc = 0;
$show_on = (intval($cfg[$name]['display']['show_on'], 10) & 0xffff);
$page_ids = $cfg[$name]['display']['pages']['ids'];
$post_ids = $cfg[$name]['display']['posts']['ids'];
$on_selected_pages = $cfg[$name]['display']['pages']['on_selected'];
$on_selected_posts = $cfg[$name]['display']['posts']['on_selected'];
if(( is_home() && ($show_on & SHOW_ON_HOME) ) || ( is_archive() && ($show_on & SHOW_ON_ARCHIVES) ) ||
( is_search() && ($show_on & SHOW_ON_SEARCH) ) || ( is_404() && ($show_on & SHOW_ON_ERROR) )) {
$rc = 1;
}
elseif( is_page() && ($show_on & SHOW_ON_PAGES) ) {
if( $show_on & SET_ON_PAGES ) {
if( ($on_selected_pages == 'show' && isset($page_ids[$post->ID])) ||
($on_selected_pages == 'hide' && !isset($page_ids[$post->ID])) ) {
// show or hide on specific pages
$rc = 1;
}
}
else {
// show on all pages
$rc = 1;
}
}
elseif( is_single() && ($show_on & SHOW_ON_POSTS) ) {
if( $show_on & SET_ON_POSTS ) {
if( ($on_selected_posts == 'show' && isset($post_ids[$post->ID])) ||
($on_selected_posts == 'hide' && !isset($post_ids[$post->ID])) ) {
// show or hide on specific posts
$rc = 1;
}
}
else {
// show on all posts
$rc = 1;
}
}
navt_write_debug(NAVT_GEN, sprintf("%s::%s can display: %s\n", __CLASS__, __FUNCTION__, $rc));
return($rc);
}
/**
* Determines what categories to exclude
*
* @param array - current menu map
* @return array - returns an array of categories to exclude
*/
function get_exclusions( $map_array ) {
$exc_array = array();
navt_write_debug(NAVT_WPHOOKS, sprintf("%s::%s\n", __CLASS__, __FUNCTION__));
if( is_array($map_array) ) {
foreach($map_array as $itm) {
if( $itm[GRP] == ID_DEFAULT_GROUP ) {
continue;
}
// category ?
if( $itm[TYP] == TYPE_CAT ) {
$opts = (intval($itm[OPT],10));
$id = $itm[IDN];
$user_is_logged_in = is_user_logged_in();
$is_private = ($opts & ISPRIVATE);
$show_in_list = ($opts & SHOW_IN_LIST);
$exclude_this = 1; // normally excluded
$exclude_this = ($show_in_list) ? 0: $exclude_this;
$exclude_this = ($is_private && !$user_is_logged_in ) ? 1: $exclude_this;
if( !$exclude_this ) {
$category = get_category($id);
$parent = $category->category_parent;
if( $parent != 0 ) {
$exclude_this = (in_array($parent, $exc_array)) ? 1: 0;
}
}
if( ($exclude_this) && (!in_array($id, $exc_array)) ) {
$exc_array[] = $id;
}
else {
//navt_write_debug(NAVT_WPHOOKS, sprintf("\tallowing category '%s'\n: ", $itm[TTL]));
}
}
}// end for
}// end if
navt_write_debug(NAVT_WPHOOKS, sprintf("%s::%s exclusion array\n", __CLASS__, __FUNCTION__), $exc_array);
return( $exc_array );
}// end function
/**
* sets a css class (or classes) for an item based on the selected
* options for the group.
*
* @param integer $style_flags - rules
* @param string $navt_style - default NAVT classes for the item
* @return string - the classes to be applied
*/
function set_item_class($style_flags, $tag, $navt_class='', $user_class='', $wp_class='') {
navt_write_debug(NAVT_GEN, sprintf("%s::%s style_flags: 0x%04x, tag: <%s>, navt classes: %s, user classes: %s, wp classes: %s\n",
__CLASS__, __FUNCTION__, $style_flags, $tag, $navt_class, $user_class, $wp_class));
$rc = $css = '';
$style_flags = (intval($style_flags,10) & 0xffff);
if( $style_flags & USE_WP_DEFAULTS ) {
$css .= (!isBlank($wp_class) ? $wp_class: '');
}
elseif( $style_flags & USE_NAVT_DEFAULTS ) {
$css .= (!isBlank($navt_class) ? $navt_class: '');
}
elseif( $style_flags & HAS_NOSTYLE ) {
}
$css = trim($css);
// user classes are added to anything that occurred above
if( $style_flags & USE_USER_CLASSES ) {
$css .= (!isBlank($user_class) ? (!isBlank($css) ? " $user_class" : $user_class) : '');
}
if( !isBlank($css) ) {
$rc = sprintf("class='%s'", $css);
}
return($rc);
}
/**
* Attach the plugin to the user's theme
*
*/
function wp_head_wpcb() {
// get groups
$gcfg = NAVT::get_option(GCONFIG);
$selector = array();
foreach( $gcfg as $key => $group_data ) {
navt_write_debug(NAVT_GEN, sprintf("%s::%s group: %s\n", __CLASS__, __FUNCTION__, $key), $group_data);
$options = intval($gcfg[$key]['options'], 10) & 0xffff;
if( $options & HAS_XPATH ) {
$html = navt_getlist($key, false);
if( $html != '' ) {
$html = str_replace("\r", "", $html);
$html = str_replace("\n", "", $html);
$html = trim($html);
$html = $gcfg[$key]['selector']['before'] . $html . $gcfg[$key]['selector']['after'];
$selector[$key] = array('xpath' => $gcfg[$key]['selector']['xpath'],
'option' => intval($gcfg[$key]['selector']['option']) & 0xffff,
'html' => $html);
}
}
}
if( count($selector) > 0 ) {
echo "\n"; wp_print_scripts('navt_theme');
navt_write_debug(NAVT_GEN, sprintf("%s::%s selectors:\n", __CLASS__, __FUNCTION__), $selector);
?>