');
// escape HTML with WordPress function
$arr_tag_a = array(
'href' => array(),
'title' => array(),
'class' => array(),
'style' => array()
);
$arr_tag_usual = array(
'title' => array(),
'class' => array(),
'style' => array()
);
$arr = array(
'a' => $arr_tag_a,
'br' => $arr_tag_usual,
'strong' => $arr_tag_usual,
'b' => $arr_tag_usual,
'em' => $arr_tag_usual,
'i' => $arr_tag_usual,
'ul' => $arr_tag_usual,
'li' => $arr_tag_usual,
'h1' => $arr_tag_usual,
'h2' => $arr_tag_usual,
'h3' => $arr_tag_usual,
'h4' => $arr_tag_usual,
'h5' => $arr_tag_usual,
'h6' => $arr_tag_usual,
'p' => $arr_tag_usual,
);
return wp_kses($str, $arr);
}
/***************************************************************
* Manage the option
***************************************************************/
/**
* Fonction de callback
*
* @param array $matches
*/
function wsp_manage_option( array $matches = array() ) {
global $the_post_id;
if (isset($matches[1])) {
$key = strtolower( $matches[1] );
switch ($key) {
// Get the title of the post
case 'title':
return get_the_title($the_post_id);
break;
// Get the URL of the post
case 'permalink':
return get_permalink($the_post_id);
break;
// Get the year of the post
case 'year':
return get_the_time('Y', $the_post_id);
break;
// Get the month of the post
case 'monthnum':
return get_the_time('m', $the_post_id);
break;
// Get the day of the post
case 'day':
return get_the_time('d', $the_post_id);
break;
// Get the day of the post
case 'hour':
return get_the_time('H', $the_post_id);
break;
// Get the day of the post
case 'minute':
return get_the_time('i', $the_post_id);
break;
// Get the day of the post
case 'second':
return get_the_time('s', $the_post_id);
break;
// Get the day of the post
case 'post_id':
return $the_post_id;
break;
// Get the day of the post
case 'category':
$categorie_info = get_the_category($the_post_id);
if (!empty($categorie_info)) {
$categorie_info = current($categorie_info);
//return print_r($categorie_info,1);
return (isset($categorie_info->name) ? $categorie_info->name : '');
}
return '';
break;
// default value
default:
if (isset($matches[0])) {
return $matches[0];
}
return false;
break;
}
}
return false;
}
/***************************************************************
* Tabs
***************************************************************/
/**
* Get the current tab
*
* @return Ambigous '.esc_html__('Powered by "WP Sitemap Page"', 'wp-sitemap-page').'
'.esc_html__('Pages', 'wp-sitemap-page').'
'."\n";
}
$return .= ''."\n";
$return .= $list_pages;
$return .= '
'."\n";
// return content
return apply_filters( 'wsp_pages_return', $return );
}
/**
* Return list of posts in the categories
*
* @param bool $is_title_displayed
* @param bool $display_nofollow
* @param bool $display_post_only_once
* @param bool $is_category_title_wording_displayed
* @param array $wsp_exclude_pages
* @param str $sort_categories
* @param str $sort
* @param str $order
* @return str $return
*/
function wsp_return_content_type_post( $is_title_displayed=true, $display_nofollow=false, $display_post_only_once=true, $is_category_title_wording_displayed=true,
$wsp_exclude_pages=array(), $sort_categories=null, $sort=null, $order=null ) {
// init
$return = '';
// args
$args = array();
// change the sort order
if ($sort_categories!==null) {
$args['orderby'] = $sort_categories;
}
// Get the categories
$cats = get_categories( $args );
// check it's not empty
if (empty($cats)) {
return '';
}
// Get the categories
$cats = wsp_generate_multi_array($cats);
// add content
if ($is_title_displayed==true) {
$return .= ''.esc_html__('Posts by category', 'wp-sitemap-page').'
'."\n";
}
$return .= wsp_html_from_multi_array($cats, true, $display_post_only_once, $is_category_title_wording_displayed,
$display_nofollow, $wsp_exclude_pages, $sort, $order);
// return content
return apply_filters( 'wsp_posts_return', $return );
}
/**
* Return list of posts in the categories
*
* @param bool $is_title_displayed
* @return str $return
*/
function wsp_return_content_type_categories( $is_title_displayed=true, $display_nofollow=false, $sort=null ) {
// init
$return = '';
// args
$args = array();
// change the sort order
if ($sort!==null) {
$args['orderby'] = $sort;
}
// Get the categories
$cats = get_categories( $args );
// check it's not empty
if (empty($cats)) {
return '';
}
// display a nofollow attribute ?
$attr_nofollow = ($display_nofollow==true ? ' rel="nofollow"' : '');
// add content
if ($is_title_displayed==true) {
$return .= ''.esc_html__('Categories', 'wp-sitemap-page').'
'."\n";
}
$return .= ''."\n";
foreach ($cats as $cat) {
$return .= "\t".'
'."\n";
// return content
return apply_filters( 'wsp_categories_return', $return );
}
/**
* Return list of posts in the categories
*
* @param bool $is_title_displayed
* @return str $return
*/
function wsp_return_content_type_tag($is_title_displayed=true, $display_nofollow=false) {
// init
$return = '';
// args
$args = array();
// Get the categories
$posttags = get_tags( $args );
// check it's not empty
if (empty($posttags)) {
return '';
}
// display a nofollow attribute ?
$attr_nofollow = ($display_nofollow==true ? ' rel="nofollow"' : '');
// add content
if ($is_title_displayed==true) {
$return .= ''.esc_html__('Tags', 'wp-sitemap-page').'
'."\n";
}
$return .= ''."\n";
// return content
return apply_filters( 'wsp_tags_return', $return );
}
/**
* Return list of archives
*
* @param bool $is_title_displayed
* @return str $return
*/
function wsp_return_content_type_archive($is_title_displayed=true, $display_nofollow=false) {
// init
$return = '';
// define the way the pages should be displayed
$args = array();
$args['echo'] = 0;
// get data
$list_archives = wp_get_archives($args);
// check it's not empty
if (empty($list_archives)) {
return '';
}
// display a nofollow attribute ?
$attr_nofollow = ($display_nofollow==true ? ' rel="nofollow"' : '');
// add content
if ($is_title_displayed==true) {
$return .= ''.esc_html__('Archives', 'wp-sitemap-page').'
'."\n";
}
$return .= ''."\n";
$return .= $list_archives;
$return .= '
'."\n";
// return content
return apply_filters( 'wsp_archives_return', $return );
}
/**
* Return list of authors
*
* @param bool $is_title_displayed
* @param bool $display_nofollow
* @param text $sort
* @return str $return
*/
function wsp_return_content_type_author( $is_title_displayed=true, $display_nofollow=false, $sort=null ) {
// init
$return = '';
// define the way the pages should be displayed
$args = array();
$args['echo'] = 0;
// change the sort order
if ($sort!==null) {
$args['orderby'] = $sort;
}
// get data
$list_authors = wp_list_authors($args);
// check it's not empty
if (empty($list_authors)) {
return '';
}
// display a nofollow attribute ?
$attr_nofollow = ($display_nofollow==true ? ' rel="nofollow"' : '');
// add content
if ($is_title_displayed==true) {
$return .= ''.esc_html__('Authors', 'wp-sitemap-page').'
'."\n";
}
$return .= ''."\n";
// return content
return apply_filters( 'wsp_authors_return', $return );
}
/**
* Return list of all other custom post type
*
* @param bool $is_title_displayed
* @param bool $display_nofollow
* @param str $wsp_exclude_pages
* @return str $return
*/
function wsp_return_content_type_cpt_lists( $is_title_displayed=true, $display_nofollow=false, $wsp_exclude_pages='' ) {
// init
$return = '';
// define the main arguments
$args = array(
'public' => true,
'_builtin' => false
);
// Get the CPT (Custom Post Type)
$post_types = get_post_types( $args, 'names' );
// check it's not empty
if (empty($post_types)) {
return '';
}
// list all the CPT
foreach ( $post_types as $post_type ) {
// extract CPT object
$cpt = get_post_type_object( $post_type );
// Is this CPT already excluded ?
$wsp_exclude_cpt = wsp_esc_to_keep_0_or_1(get_option('wsp_exclude_cpt_'.$cpt->name));
if ( empty($wsp_exclude_cpt) ) {
$return .= wsp_return_content_type_cpt_items( $is_title_displayed, $display_nofollow, $cpt, $post_type, $wsp_exclude_pages );
}
}
// return content
return $return;
}
/**
* Return list of all other custom post type
*
* @param bool $is_title_displayed
* @param bool $display_nofollow
* @param str $cpt
* @param str $post_type
* @param str $wsp_exclude_pages
* @param str $sort
* @return str $return
*/
function wsp_return_content_type_cpt_items( $is_title_displayed=true, $display_nofollow=false, $cpt='', $post_type='', $wsp_exclude_pages='', $sort=null ) {
// init
$return = '';
// List the pages
$list_pages = '';
// define the way the pages should be displayed
$args = array();
$args['post_type'] = $post_type;
$args['posts_per_page'] = 999999;
$args['suppress_filters'] = 0;
// exclude some pages ?
if (!empty($wsp_exclude_pages)) {
$args['exclude'] = $wsp_exclude_pages;
}
// change the sort order
if ($sort!==null) {
$args['orderby'] = $sort;
}
// Query to get the current custom post type
$posts_cpt = get_posts( $args );
// display a nofollow attribute ?
$attr_nofollow = ($display_nofollow==true ? ' rel="nofollow"' : '');
// List all the results
if ( !empty($posts_cpt) ) {
foreach( $posts_cpt as $post_cpt ) {
$list_pages .= '' . $cpt->label . '
'."\n";
}
$return .= ''."\n";
$return .= $list_pages;
$return .= '
'."\n";
}
// return content
return apply_filters( 'wsp_cpts_return', $return );
}
/**
* Return list of all other custom post type
*
* @param bool $is_title_displayed
* @param bool $display_nofollow
* @param str $wsp_exclude_pages
* @return str $return
*/
function wsp_return_content_type_taxonomies_lists($is_title_displayed=true, $display_nofollow=false, $wsp_exclude_pages='') {
// init
$return = '';
$args = array(
'public' => true,
'_builtin' => false
);
$taxonomies_names = get_taxonomies( $args );
// check it's not empty
if (empty($taxonomies_names)) {
return '';
}
// list all the taxonomies
foreach ( $taxonomies_names as $taxonomy_name ) {
// Extract
$taxonomy_obj = get_taxonomy( $taxonomy_name );
// Is this taxonomy already excluded ?
$wsp_exclude_taxonomy = wsp_esc_to_keep_0_or_1(get_option('wsp_exclude_taxonomy_'.$taxonomy_name));
if ( empty($wsp_exclude_taxonomy) ) {
$return .= wsp_return_content_type_taxonomy_items( $is_title_displayed, $display_nofollow, $taxonomy_obj, $wsp_exclude_taxonomy );
}
}
// return content
return $return;
}
/**
* Return list of all other taxonomies
*
* @param bool $is_title_displayed
* @param bool $display_nofollow
* @param object $taxonomy_obj
* @param str $wsp_exclude_pages
* @return str $return
*/
function wsp_return_content_type_taxonomy_items( $is_title_displayed=true, $display_nofollow=false, $taxonomy_obj=null, $wsp_exclude_pages='' ) {
// init
$return = '';
// List the pages
$list_pages = '';
// get some data
$taxonomy_name = $taxonomy_obj->name;
$taxonomy_label = $taxonomy_obj->label;
// init variable to get terms of a taxonomy
$taxonomies = array( $taxonomy_name );
$args = array();
// get the terms of this taxonomy
$terms = get_terms($taxonomies, $args);
// display a nofollow attribute ?
$attr_nofollow = ($display_nofollow==true ? ' rel="nofollow"' : '');
// List all the results
if ( !empty($terms) ) {
foreach( $terms as $terms_obj ) {
$list_pages .= '' . $taxonomy_label . '
'."\n";
}
$return .= ''."\n";
$return .= $list_pages;
$return .= '
'."\n";
}
// return content
return apply_filters( 'wsp_taxonomies_return', $return );
}
/**
* Generate a multidimensional array from a simple linear array using a recursive function
*
* @param array $arr
* @param int $parent
* @return array $pages
*/
function wsp_generate_multi_array( array $arr = array() , $parent = 0 ) {
// check if not empty
if (empty($arr)) {
return array();
}
$pages = array();
// go through the array
foreach($arr as $k => $page) {
if ($page->parent == $parent) {
$page->sub = isset($page->sub) ? $page->sub : wsp_generate_multi_array($arr, $page->cat_ID);
$pages[] = $page;
}
}
return $pages;
}
/**
* Display the multidimensional array using a recursive function
*
* @param array $nav
* @param bool $useUL
* @param bool $display_post_only_once
* @param bool $display_nofollow
* @param array $wsp_exclude_pages
* @param text $sort
* @param text $order
* @return str $html
*/
function wsp_html_from_multi_array( array $nav = array() , $useUL = true, $display_post_only_once = true, $is_category_title_wording_displayed = true,
$display_nofollow = false, $wsp_exclude_pages = array(), $sort=null, $order=null ) {
// check if not empty
if (empty($nav)) {
return '';
}
$html = '';
if ($useUL === true) {
$html .= ''."\n";
}
// display a nofollow attribute ?
$attr_nofollow = ($display_nofollow==true ? ' rel="nofollow"' : '');
// List all the categories
foreach ($nav as $page) {
// define category link
$category_link = ''.esc_html($page->name).'';
// define the text to display for the title of the category
if ($is_category_title_wording_displayed) {
$category_link_display = esc_html__('Category: ', 'wp-sitemap-page').$category_link;
} else {
$category_link_display = $category_link;
}
$html .= "\t".'
'."\n";
}
return $html;
}
/**
* Display the multidimensional array using a recursive function
*
* @param int $cat_id
* @param bool $display_post_only_once
* @param bool $display_nofollow
* @param array $wsp_exclude_pages
* @param text $sort
* @param text $order
* @return str $html
*/
function wsp_display_post_by_cat( $cat_id, $display_post_only_once=true, $display_nofollow=false, $wsp_exclude_pages=array(), $sort=null, $order=null ) {
global $the_post_id;
// init
$html = '';
// define the way the pages should be displayed
$args = array();
$args['numberposts'] = 999999;
$args['cat'] = $cat_id;
// exclude some pages ?
if (!empty($wsp_exclude_pages)) {
$args['exclude'] = $wsp_exclude_pages;
}
// change the sort order
if ($sort!==null) {
$args['orderby'] = $sort;
}
if ($order!==null) {
$args['order'] = $order;
}
// List of posts for this category
$the_posts = get_posts( $args );
// check if not empty
if (empty($the_posts)) {
return '';
}
// display a nofollow attribute ?
$attr_nofollow = ($display_nofollow==true ? ' rel="nofollow"' : '');
// determine the code to place in the textarea
$wsp_posts_by_category = get_option('wsp_posts_by_category');
if ( $wsp_posts_by_category === false ) {
// this option does not exists
$wsp_posts_by_category = sprintf(__('{title} ({monthnum}/{day}/{year})', 'wp-sitemap-page'), $attr_nofollow);
// save this option
add_option( 'wsp_posts_by_category', $wsp_posts_by_category );
}
// remove every HTML tag except the and some others
$wsp_posts_by_category = wsp_esc_some_html_tags($wsp_posts_by_category);
// list the posts
foreach ( $the_posts as $the_post ) {
// Display the line of a post
$get_category = get_the_category($the_post->ID);
// Display the post only if it is on the deepest category
if ( $display_post_only_once==false || ($display_post_only_once==true && $get_category[0]->cat_ID == $cat_id) ) {
// get post ID
$the_post_id = $the_post->ID;
// replace the ID by the real value
$html .= "\t\t".'';
}
if ( !empty($post_by_cat) ) {
$html .= $post_by_cat;
}
if ( !empty($category_recursive) ) {
$html .= $category_recursive;
}
if ( !empty($post_by_cat) || !empty($category_recursive) ) {
$html .= '
';
}
$html .= '