/**
  * Create a list of checkboxes that can be used to select additional categories.
  */
 function _generate_additional_categories_checkboxes($override_name = null)
 {
     global $comicpress_manager;
     $additional_categories = array();
     $invalid_ids = array($comicpress_manager->properties['blogcat']);
     foreach ($this->category_tree as $node) {
         $invalid_ids[] = end(explode('/', $node));
     }
     foreach (get_all_category_ids() as $cat_id) {
         if (!in_array($cat_id, $invalid_ids)) {
             $category = get_category($cat_id);
             $additional_categories[strtolower($category->cat_name)] = $category;
         }
     }
     ksort($additional_categories);
     $name = !empty($override_name) ? $override_name : "additional-categories";
     $selected_additional_categories = explode(",", $comicpress_manager->get_cpm_option("cpm-default-additional-categories"));
     $this->category_checkboxes = array();
     if (count($additional_categories) > 0) {
         foreach ($additional_categories as $category) {
             $checked = in_array($category->cat_ID, $selected_additional_categories) ? "checked=\"checked\"" : "";
             $this->category_checkboxes[] = "<label><input id=\"additional-" . $category->cat_ID . "\" type=\"checkbox\" name=\"{$name}[]\" value=\"" . $category->cat_ID . "\" {$checked} /> " . $category->cat_name . "</label><br />";
         }
     }
     return $this->category_checkboxes;
 }
Example #2
0
 function form($instance)
 {
     $default = array('title' => 'Widget Demo', 'number_post' => '5', 'current_category' => '');
     // Gộp các giá trị của $default vào $instance để nó trở thành giá trị mặc định
     $instance = wp_parse_args((array) $instance, $default);
     // Gán giá trị ($instance['title'] cho $title (khởi tạo biến $title))
     $title = esc_attr($instance['title']);
     $number_post = esc_attr($instance['number_post']);
     // Get title
     echo "<p>Title:</p>";
     echo "<p><input type=\"text\" name=\"" . $this->get_field_name('title') . "\" value=\"" . $title . "\" /></p>";
     // Select category
     $all_categories = get_all_category_ids();
     echo "<p>Category:</p>";
     echo "<p><select id=\"" . $this->get_field_id('current_category') . "\" name=\"" . $this->get_field_name('current_category') . "\" >";
     foreach ($all_categories as $category) {
         if ($category == $instance['current_category']) {
             echo "<option value=\"" . $category . "\" selected=\"selected\">" . get_cat_name($category) . "</option>";
         } else {
             echo "<option value=\"" . $category . "\">" . get_cat_name($category) . "</option>";
         }
     }
     echo "</select></p>";
     // Get count
     echo "<p>Show number posts:</p>";
     echo "<p><input type=\"text\" name=\"" . $this->get_field_name('number_post') . "\" value=\"" . $number_post . "\" /></p>";
 }
Example #3
0
 /**
  * Retrieves a unique array of all Category IDs in the database.
  *
  * @package s2Member\Utilities
  * @since 3.5
  *
  * @uses {@link http://codex.wordpress.org/Function_Reference/get_all_category_ids get_all_category_ids()}
  *
  * @return array Unique array of all Category IDs *(as integers)*.
  */
 public static function get_all_category_ids()
 {
     if (is_array($category_ids = get_all_category_ids())) {
         $category_ids = c_ws_plugin__s2member_utils_arrays::force_integers($category_ids);
     }
     return !empty($category_ids) && is_array($category_ids) ? array_unique($category_ids) : array();
 }
Example #4
0
function example_add_dashboard_widgets()
{
    $cat_ids = get_all_category_ids();
    foreach ($cat_ids as $id) {
        $cat = get_category($id);
        wp_add_dashboard_widget($cat->cat_ID, $cat->cat_name, test);
    }
}
Example #5
0
function getCatIdsHomepageDefault()
{
    $catids = get_all_category_ids();
    if (count($catids) > 3) {
        return $catids[0] . ',' . $catids[1] . ',' . $catids[2];
    } else {
        return implode(',', $catids);
    }
}
 public static function get_video_category_link()
 {
     $category_ids = get_all_category_ids();
     foreach ($category_ids as $cat_id) {
         if (!strcmp(get_cat_name($cat_id), "video")) {
             echo get_category_link($cat_id);
         }
     }
 }
Example #7
0
function ooc_swap_out_checkboxes($content)
{
    $content = str_replace('type="checkbox" name="post_category', 'type="radio" name="post_category', $content);
    // for "Most Used" tab
    foreach (get_all_category_ids() as $i) {
        $content = str_replace('id="in-popular-category-' . $i . '" type="checkbox"', 'id="in-popular-category-' . $i . '" type="radio"', $content);
    }
    return $content;
}
 /**
  * Validate get_all_category_ids
  *
  * @expectedDeprecated get_all_category_ids
  */
 function test_get_all_category_ids()
 {
     // create categories
     self::factory()->category->create_many(2);
     // create new taxonomy to ensure not included
     register_taxonomy('test_tax_cat', 'post');
     wp_insert_term("test1", 'test_tax_cat');
     // Validate length is 1 + created due to uncategorized
     $cat_ids = get_all_category_ids();
     $this->assertEquals(3, count($cat_ids));
 }
function find_category_by_name($name)
{
    $cat = null;
    $category_ids = get_all_category_ids();
    foreach ($category_ids as $cat_id) {
        if (!strcmp(get_cat_name($cat_id), "Blog")) {
            $cat = $cat_id;
        }
    }
    return $cat;
}
Example #10
0
function catDropDown($thisCatID)
{
    if ($thisCatID[1] == "0") {
        $thisCatID[1] = 1;
    }
    $category_ids = get_all_category_ids();
    echo '<OPTION  ' . (isset($thisCatID[0]) && is_null($thisCatID[0]) ? 'selected' : '') . '  VALUE=NULL>Not in Use</OPTION>';
    foreach ($category_ids as $cat_id) {
        $cat_name = get_cat_name($cat_id);
        echo '<OPTION  ' . selected(true, in_array($cat_id, $thisCatID), false) . '  VALUE="' . $cat_id . '">' . $cat_name . '</OPTION>';
    }
}
 final function __construct()
 {
     $this->_aOptions = get_option('_syndication');
     if (!empty($this->_aOptions['except_category'])) {
         $this->_aCategory = array_diff(get_all_category_ids(), explode(',', $this->_aOptions['except_category']));
     } else {
         $this->_aCategory = get_all_category_ids();
     }
     $this->_sCategory = implode(',', $this->_aCategory);
     $this->_baseUrl = get_bloginfo('url');
     $this->init();
 }
 /**
  *	Get the categories from blog
  *	@return array ID and category names
  */
 function GetCategories()
 {
     global $wpdb;
     $categories = get_all_category_ids();
     $separator = '|';
     $output = array();
     if ($categories) {
         foreach ($categories as $category) {
             $temp_catname = get_cat_name($category);
             if ($temp_catname !== "Uncategorized") {
                 $output[$category] = $temp_catname;
             }
         }
     } else {
         $output = 'test';
     }
     return $output;
 }
function get_category_children($id, $before = '/', $after = '')
{
    if (0 == $id) {
        return '';
    }
    $chain = '';
    $cat_ids = get_all_category_ids();
    foreach ($cat_ids as $cat_id) {
        if ($cat_id == $id) {
            continue;
        }
        $category = get_category($cat_id);
        if ($category->category_parent == $id) {
            $chain .= $before . $category->cat_ID . $after;
            $chain .= get_category_children($category->cat_ID, $before, $after);
        }
    }
    return $chain;
}
 function form($instance)
 {
     $default = array('number_post_1' => '5', 'current_category_1' => '', 'number_post_2' => '5', 'current_category_2' => '');
     // Initilize default values ($instance)
     $instance = wp_parse_args((array) $instance, $default);
     // Create param, method esc_attr($instance['number_post_1']) : get value number_post_1
     $number_post_1 = esc_attr($instance['number_post_1']);
     $number_post_2 = esc_attr($instance['number_post_2']);
     /* Display column 1  */
     // Select category
     $all_categories = get_all_category_ids();
     echo "<p><strong>COLUMN 1:</strong></p>";
     echo "<p>Category:</p>";
     echo "<p><select id=\"" . $this->get_field_id('current_category_1') . "\" name=\"" . $this->get_field_name('current_category_1') . "\" >";
     foreach ($all_categories as $category) {
         if ($category == $instance['current_category_1']) {
             echo "<option value=\"" . $category . "\" selected=\"selected\">" . get_cat_name($category) . "</option>";
         } else {
             echo "<option value=\"" . $category . "\">" . get_cat_name($category) . "</option>";
         }
     }
     echo "</select></p>";
     // Display number post in a category
     echo "<p>Show number posts:</p>";
     echo "<p><input type=\"text\" name=\"" . $this->get_field_name('number_post_1') . "\" value=\"" . $number_post_1 . "\" /></p>";
     /* Display column 2  */
     // Select category
     echo "<p><strong>COLUMN 2:</strong></p>";
     echo "<p>Category:</p>";
     echo "<p><select id=\"" . $this->get_field_id('current_category_2') . "\" name=\"" . $this->get_field_name('current_category_2') . "\" >";
     foreach ($all_categories as $category) {
         if ($category == $instance['current_category_2']) {
             echo "<option value=\"" . $category . "\" selected=\"selected\">" . get_cat_name($category) . "</option>";
         } else {
             echo "<option value=\"" . $category . "\">" . get_cat_name($category) . "</option>";
         }
     }
     echo "</select></p>";
     // Display number post in a category
     echo "<p>Show number posts:</p>";
     echo "<p><input type=\"text\" name=\"" . $this->get_field_name('number_post_2') . "\" value=\"" . $number_post_2 . "\" /></p>";
 }
Example #15
0
 /**
  * Migrate Level Information for all Content to Database
  * @global object $wpdb
  */
 function MigrateContentLevelData()
 {
     ignore_user_abort(true);
     global $wpdb;
     if (get_option($this->PluginOptionName . '_MigrateContentLevelData') == 1) {
         return;
     }
     // migrate category levels
     $content_types = array('MembershipCategories' => '~CATEGORY', 'MembershipPages' => 'page', 'MembershipPosts' => 'post', 'MembershipComments' => '~COMMENT');
     foreach ($content_types as $Option => $content_type) {
         $data = $this->GetOption($Option);
         foreach ($data as $level => $ids) {
             $ids = array_diff(array_unique(explode(',', $ids)), array('0', ''));
             if (count($ids)) {
                 foreach ($ids as $id) {
                     if (is_numeric($id)) {
                         $wpdb->insert($this->Tables->contentlevels, array('content_id' => $id, 'level_id' => $level, 'type' => $content_type), array('%d', '%s', '%s'));
                     }
                 }
             }
         }
     }
     // category protection
     $ids = array_diff(get_all_category_ids(), explode(',', $this->GetOption('CatProtect')));
     if (count($ids)) {
         foreach ($ids as $id) {
             if (is_numeric($id)) {
                 $wpdb->insert($this->Tables->contentlevels, array('content_id' => $id, 'level_id' => 'Protection', 'type' => '~CATEGORY'), array('%d', '%s', '%s'));
             }
         }
     }
     // category protection
     $ids = array_diff(array_unique(explode(',', $this->GetOption('Protect'))), array('0', ''));
     if (count($ids)) {
         foreach ($ids as $id) {
             if (is_numeric($id)) {
                 $wpdb->insert($this->Tables->contentlevels, array('content_id' => $id, 'level_id' => 'Protection', 'type' => 'post'), array('%d', '%s', '%s'));
             }
         }
     }
     update_option($this->PluginOptionName . '_MigrateContentLevelData', 1);
 }
/**
 * Retrieve category children list separated before and after the term IDs.
 *
 * @since 1.2.0
 *
 * @param int $id Category ID to retrieve children.
 * @param string $before Optional. Prepend before category term ID.
 * @param string $after Optional, default is empty string. Append after category term ID.
 * @param array $visited Optional. Category Term IDs that have already been added.
 * @return string
 */
function get_category_children( $id, $before = '/', $after = '', $visited = array() ) {
	if ( 0 == $id )
		return '';

	$chain = '';
	/** TODO: consult hierarchy */
	$cat_ids = get_all_category_ids();
	foreach ( (array) $cat_ids as $cat_id ) {
		if ( $cat_id == $id )
			continue;

		$category = get_category( $cat_id );
		if ( is_wp_error( $category ) )
			return $category;
		if ( $category->parent == $id && !in_array( $category->term_id, $visited ) ) {
			$visited[] = $category->term_id;
			$chain .= $before.$category->term_id.$after;
			$chain .= get_category_children( $category->term_id, $before, $after );
		}
	}
	return $chain;
}
function get_category_children($id, $before = '/', $after = '')
{
    if (0 == $id) {
        return '';
    }
    $chain = '';
    // TODO: consult hierarchy
    $cat_ids = get_all_category_ids();
    foreach ($cat_ids as $cat_id) {
        if ($cat_id == $id) {
            continue;
        }
        $category = get_category($cat_id);
        if (is_wp_error($category)) {
            return $category;
        }
        if ($category->parent == $id) {
            $chain .= $before . $category->term_id . $after;
            $chain .= get_category_children($category->term_id, $before, $after);
        }
    }
    return $chain;
}
 function form($instance)
 {
     $default = array('number_post' => '5', 'current_category' => '');
     // Initilize default values ($instance)
     $instance = wp_parse_args((array) $instance, $default);
     // Create param, method esc_attr($instance['number_post']) : get value number_post
     $number_post = esc_attr($instance['number_post']);
     // Select category
     $all_categories = get_all_category_ids();
     echo "<p>Category:</p>";
     echo "<p><select id=\"" . $this->get_field_id('current_category') . "\" name=\"" . $this->get_field_name('current_category') . "\" >";
     foreach ($all_categories as $category) {
         if ($category == $instance['current_category']) {
             echo "<option value=\"" . $category . "\" selected=\"selected\">" . get_cat_name($category) . "</option>";
         } else {
             echo "<option value=\"" . $category . "\">" . get_cat_name($category) . "</option>";
         }
     }
     echo "</select></p>";
     // Get count
     echo "<p>Show number posts:</p>";
     echo "<p><input type=\"text\" name=\"" . $this->get_field_name('number_post') . "\" value=\"" . $number_post . "\" /></p>";
 }
 function printCategorySelect($selected_id)
 {
     // Get list of category id and names
     $cat_ids = get_all_category_ids();
     foreach ($cat_ids as $cat) {
         $name = get_cat_name($cat);
         if ($selected_id == $cat) {
             $selected = "selected='selected'";
         } else {
             $selected = "";
         }
         echo "  <option value='" . $cat . "' " . $selected . " >" . $name . "</option>\n";
     }
 }
Example #20
0
/**
 * Retrieve category children list separated before and after the term IDs.
 *
 * @since 1.2.0
 * @deprecated 2.8.0 Use get_term_children()
 * @see get_term_children()
 *
 * @param int $id Category ID to retrieve children.
 * @param string $before Optional. Prepend before category term ID.
 * @param string $after Optional, default is empty string. Append after category term ID.
 * @param array $visited Optional. Category Term IDs that have already been added.
 * @return string
 */
function get_category_children($id, $before = '/', $after = '', $visited = array())
{
    _deprecated_function(__FUNCTION__, '2.8.0', 'get_term_children()');
    if (0 == $id) {
        return '';
    }
    $chain = '';
    /** TODO: consult hierarchy */
    $cat_ids = get_all_category_ids();
    foreach ((array) $cat_ids as $cat_id) {
        if ($cat_id == $id) {
            continue;
        }
        $category = get_category($cat_id);
        if (is_wp_error($category)) {
            return $category;
        }
        if ($category->parent == $id && !in_array($category->term_id, $visited)) {
            $visited[] = $category->term_id;
            $chain .= $before . $category->term_id . $after;
            $chain .= get_category_children($category->term_id, $before, $after);
        }
    }
    return $chain;
}
Example #21
0
 function ajax_acf_location($options = array())
 {
     // defaults
     $defaults = array('key' => null, 'value' => null, 'param' => null);
     // Is AJAX call?
     if (isset($_POST['action']) && $_POST['action'] == "acf_location") {
         $options = array_merge($defaults, $_POST);
     } else {
         $options = array_merge($defaults, $options);
     }
     // some case's have the same outcome
     if ($options['param'] == "page_parent") {
         $options['param'] = "page";
     }
     $choices = array();
     $optgroup = false;
     switch ($options['param']) {
         case "post_type":
             $choices = get_post_types(array('public' => true));
             unset($choices['attachment']);
             break;
         case "page":
             $pages = get_pages(array('numberposts' => -1, 'post_type' => 'page', 'sort_column' => 'menu_order', 'order' => 'ASC', 'post_status' => array('publish', 'private', 'draft', 'inherit', 'future'), 'suppress_filters' => false));
             foreach ($pages as $page) {
                 $title = '';
                 $ancestors = get_ancestors($page->ID, 'page');
                 if ($ancestors) {
                     foreach ($ancestors as $a) {
                         $title .= '- ';
                     }
                 }
                 $title .= apply_filters('the_title', $page->post_title, $page->ID);
                 // status
                 if ($page->post_status != "publish") {
                     $title .= " ({$page->post_status})";
                 }
                 $choices[$page->ID] = $title;
             }
             break;
         case "page_type":
             $choices = array('parent' => __("Parent Page", 'acf'), 'child' => __("Child Page", 'acf'));
             break;
         case "page_template":
             $choices = array('default' => __("Default Template", 'acf'));
             $templates = get_page_templates();
             foreach ($templates as $k => $v) {
                 $choices[$v] = $k;
             }
             break;
         case "post":
             $posts = get_posts(array('numberposts' => '-1', 'post_status' => array('publish', 'private', 'draft', 'inherit', 'future'), 'suppress_filters' => false));
             foreach ($posts as $post) {
                 $title = apply_filters('the_title', $post->post_title, $post->ID);
                 // status
                 if ($post->post_status != "publish") {
                     $title .= " ({$post->post_status})";
                 }
                 $choices[$post->ID] = $title;
             }
             break;
         case "post_category":
             $category_ids = get_all_category_ids();
             foreach ($category_ids as $cat_id) {
                 $cat_name = get_cat_name($cat_id);
                 $choices[$cat_id] = $cat_name;
             }
             break;
         case "post_format":
             $choices = get_post_format_strings();
             break;
         case "user_type":
             global $wp_roles;
             $choices = $wp_roles->get_names();
             break;
         case "options_page":
             $choices = array(__('Options', 'acf') => __('Options', 'acf'));
             $custom = apply_filters('acf_register_options_page', array());
             if (!empty($custom)) {
                 $choices = array();
                 foreach ($custom as $c) {
                     $choices[$c['slug']] = $c['title'];
                 }
             }
             break;
         case "taxonomy":
             $choices = $this->parent->get_taxonomies_for_select(array('simple_value' => true));
             $optgroup = true;
             break;
         case "ef_taxonomy":
             $choices = array('all' => __('All', 'acf'));
             $taxonomies = get_taxonomies(array('public' => true), 'objects');
             foreach ($taxonomies as $taxonomy) {
                 $choices[$taxonomy->name] = $taxonomy->labels->name;
             }
             // unset post_format (why is this a public taxonomy?)
             if (isset($choices['post_format'])) {
                 unset($choices['post_format']);
             }
             break;
         case "ef_user":
             global $wp_roles;
             $choices = array_merge(array('all' => __('All', 'acf')), $wp_roles->get_names());
             break;
         case "ef_media":
             $choices = array('all' => __('All', 'acf'));
             break;
     }
     $this->parent->create_field(array('type' => 'select', 'name' => 'location[rules][' . $options['key'] . '][value]', 'value' => $options['value'], 'choices' => $choices, 'optgroup' => $optgroup));
     // ajax?
     if (isset($_POST['action']) && $_POST['action'] == "acf_location") {
         die;
     }
 }
Example #22
0
 /**
  * Returns array of detected URLs for theme templates
  *
  * @param string $theme_name
  * @return array
  */
 function get_theme_urls($theme_name)
 {
     $urls = array();
     $theme = w3tc_get_theme($theme_name);
     if ($theme && isset($theme['Template Files'])) {
         $front_page_template = false;
         if (get_option('show_on_front') == 'page') {
             $front_page_id = get_option('page_on_front');
             if ($front_page_id) {
                 $front_page_template_file = get_post_meta($front_page_id, '_wp_page_template', true);
                 if ($front_page_template_file) {
                     $front_page_template = basename($front_page_template_file, '.php');
                 }
             }
         }
         $home_url = w3_get_home_url();
         $template_files = (array) $theme['Template Files'];
         $mime_types = get_allowed_mime_types();
         $custom_mime_types = array();
         foreach ($mime_types as $mime_type) {
             list($type1, $type2) = explode('/', $mime_type);
             $custom_mime_types = array_merge($custom_mime_types, array($type1, $type2, $type1 . '_' . $type2));
         }
         foreach ($template_files as $template_file) {
             $link = false;
             $template = basename($template_file, '.php');
             /**
              * Check common templates
              */
             switch (true) {
                 /**
                  * Handle home.php or index.php or front-page.php
                  */
                 case !$front_page_template && $template == 'home':
                 case !$front_page_template && $template == 'index':
                 case !$front_page_template && $template == 'front-page':
                     /**
                      * Handle custom home page
                      */
                 /**
                  * Handle custom home page
                  */
                 case $template == $front_page_template:
                     $link = $home_url . '/';
                     break;
                     /**
                      * Handle 404.php
                      */
                 /**
                  * Handle 404.php
                  */
                 case $template == '404':
                     $permalink = get_option('permalink_structure');
                     if ($permalink) {
                         $link = sprintf('%s/%s/', $home_url, '404_test');
                     } else {
                         $link = sprintf('%s/?p=%d', $home_url, 999999999);
                     }
                     break;
                     /**
                      * Handle search.php
                      */
                 /**
                  * Handle search.php
                  */
                 case $template == 'search':
                     $link = sprintf('%s/?s=%s', $home_url, 'search_test');
                     break;
                     /**
                      * Handle date.php or archive.php
                      */
                 /**
                  * Handle date.php or archive.php
                  */
                 case $template == 'date':
                 case $template == 'archive':
                     $posts = get_posts(array('numberposts' => 1, 'orderby' => 'rand'));
                     if (is_array($posts) && count($posts)) {
                         $time = strtotime($posts[0]->post_date);
                         $link = get_day_link(date('Y', $time), date('m', $time), date('d', $time));
                     }
                     break;
                     /**
                      * Handle author.php
                      */
                 /**
                  * Handle author.php
                  */
                 case $template == 'author':
                     $author_id = false;
                     if (function_exists('get_users')) {
                         $users = get_users();
                         if (is_array($users) && count($users)) {
                             $user = current($users);
                             $author_id = $user->ID;
                         }
                     } else {
                         $author_ids = get_author_user_ids();
                         if (is_array($author_ids) && count($author_ids)) {
                             $author_id = $author_ids[0];
                         }
                     }
                     if ($author_id) {
                         $link = get_author_posts_url($author_id);
                     }
                     break;
                     /**
                      * Handle category.php
                      */
                 /**
                  * Handle category.php
                  */
                 case $template == 'category':
                     $category_ids = get_all_category_ids();
                     if (is_array($category_ids) && count($category_ids)) {
                         $link = get_category_link($category_ids[0]);
                     }
                     break;
                     /**
                      * Handle tag.php
                      */
                 /**
                  * Handle tag.php
                  */
                 case $template == 'tag':
                     $term_ids = get_terms('post_tag', 'fields=ids');
                     if (is_array($term_ids) && count($term_ids)) {
                         $link = get_term_link($term_ids[0], 'post_tag');
                     }
                     break;
                     /**
                      * Handle taxonomy.php
                      */
                 /**
                  * Handle taxonomy.php
                  */
                 case $template == 'taxonomy':
                     $taxonomy = '';
                     if (isset($GLOBALS['wp_taxonomies']) && is_array($GLOBALS['wp_taxonomies'])) {
                         foreach ($GLOBALS['wp_taxonomies'] as $wp_taxonomy) {
                             if (!in_array($wp_taxonomy->name, array('category', 'post_tag', 'link_category'))) {
                                 $taxonomy = $wp_taxonomy->name;
                                 break;
                             }
                         }
                     }
                     if ($taxonomy) {
                         $terms = get_terms($taxonomy, array('number' => 1));
                         if (is_array($terms) && count($terms)) {
                             $link = get_term_link($terms[0], $taxonomy);
                         }
                     }
                     break;
                     /**
                      * Handle attachment.php
                      */
                 /**
                  * Handle attachment.php
                  */
                 case $template == 'attachment':
                     $attachments = get_posts(array('post_type' => 'attachment', 'numberposts' => 1, 'orderby' => 'rand'));
                     if (is_array($attachments) && count($attachments)) {
                         $link = get_attachment_link($attachments[0]->ID);
                     }
                     break;
                     /**
                      * Handle single.php
                      */
                 /**
                  * Handle single.php
                  */
                 case $template == 'single':
                     $posts = get_posts(array('numberposts' => 1, 'orderby' => 'rand'));
                     if (is_array($posts) && count($posts)) {
                         $link = get_permalink($posts[0]->ID);
                     }
                     break;
                     /**
                      * Handle page.php
                      */
                 /**
                  * Handle page.php
                  */
                 case $template == 'page':
                     $pages_ids = get_all_page_ids();
                     if (is_array($pages_ids) && count($pages_ids)) {
                         $link = get_page_link($pages_ids[0]);
                     }
                     break;
                     /**
                      * Handle comments-popup.php
                      */
                 /**
                  * Handle comments-popup.php
                  */
                 case $template == 'comments-popup':
                     $posts = get_posts(array('numberposts' => 1, 'orderby' => 'rand'));
                     if (is_array($posts) && count($posts)) {
                         $link = sprintf('%s/?comments_popup=%d', $home_url, $posts[0]->ID);
                     }
                     break;
                     /**
                      * Handle paged.php
                      */
                 /**
                  * Handle paged.php
                  */
                 case $template == 'paged':
                     global $wp_rewrite;
                     if ($wp_rewrite->using_permalinks()) {
                         $link = sprintf('%s/page/%d/', $home_url, 1);
                     } else {
                         $link = sprintf('%s/?paged=%d', 1);
                     }
                     break;
                     /**
                      * Handle author-id.php or author-nicename.php
                      */
                 /**
                  * Handle author-id.php or author-nicename.php
                  */
                 case preg_match('~^author-(.+)$~', $template, $matches):
                     if (is_numeric($matches[1])) {
                         $link = get_author_posts_url($matches[1]);
                     } else {
                         $link = get_author_posts_url(null, $matches[1]);
                     }
                     break;
                     /**
                      * Handle category-id.php or category-slug.php
                      */
                 /**
                  * Handle category-id.php or category-slug.php
                  */
                 case preg_match('~^category-(.+)$~', $template, $matches):
                     if (is_numeric($matches[1])) {
                         $link = get_category_link($matches[1]);
                     } else {
                         $term = get_term_by('slug', $matches[1], 'category');
                         if (is_object($term)) {
                             $link = get_category_link($term->term_id);
                         }
                     }
                     break;
                     /**
                      * Handle tag-id.php or tag-slug.php
                      */
                 /**
                  * Handle tag-id.php or tag-slug.php
                  */
                 case preg_match('~^tag-(.+)$~', $template, $matches):
                     if (is_numeric($matches[1])) {
                         $link = get_tag_link($matches[1]);
                     } else {
                         $term = get_term_by('slug', $matches[1], 'post_tag');
                         if (is_object($term)) {
                             $link = get_tag_link($term->term_id);
                         }
                     }
                     break;
                     /**
                      * Handle taxonomy-taxonomy-term.php
                      */
                 /**
                  * Handle taxonomy-taxonomy-term.php
                  */
                 case preg_match('~^taxonomy-(.+)-(.+)$~', $template, $matches):
                     $link = get_term_link($matches[2], $matches[1]);
                     break;
                     /**
                      * Handle taxonomy-taxonomy.php
                      */
                 /**
                  * Handle taxonomy-taxonomy.php
                  */
                 case preg_match('~^taxonomy-(.+)$~', $template, $matches):
                     $terms = get_terms($matches[1], array('number' => 1));
                     if (is_array($terms) && count($terms)) {
                         $link = get_term_link($terms[0], $matches[1]);
                     }
                     break;
                     /**
                      * Handle MIME_type.php
                      */
                 /**
                  * Handle MIME_type.php
                  */
                 case in_array($template, $custom_mime_types):
                     $posts = get_posts(array('post_mime_type' => '%' . $template . '%', 'post_type' => 'attachment', 'numberposts' => 1, 'orderby' => 'rand'));
                     if (is_array($posts) && count($posts)) {
                         $link = get_permalink($posts[0]->ID);
                     }
                     break;
                     /**
                      * Handle single-posttype.php
                      */
                 /**
                  * Handle single-posttype.php
                  */
                 case preg_match('~^single-(.+)$~', $template, $matches):
                     $posts = get_posts(array('post_type' => $matches[1], 'numberposts' => 1, 'orderby' => 'rand'));
                     if (is_array($posts) && count($posts)) {
                         $link = get_permalink($posts[0]->ID);
                     }
                     break;
                     /**
                      * Handle page-id.php or page-slug.php
                      */
                 /**
                  * Handle page-id.php or page-slug.php
                  */
                 case preg_match('~^page-(.+)$~', $template, $matches):
                     if (is_numeric($matches[1])) {
                         $link = get_permalink($matches[1]);
                     } else {
                         $posts = get_posts(array('pagename' => $matches[1], 'post_type' => 'page', 'numberposts' => 1));
                         if (is_array($posts) && count($posts)) {
                             $link = get_permalink($posts[0]->ID);
                         }
                     }
                     break;
                     /**
                      * Try to handle custom template
                      */
                 /**
                  * Try to handle custom template
                  */
                 default:
                     $posts = get_posts(array('pagename' => $template, 'post_type' => 'page', 'numberposts' => 1));
                     if (is_array($posts) && count($posts)) {
                         $link = get_permalink($posts[0]->ID);
                     }
                     break;
             }
             if ($link && !is_wp_error($link)) {
                 $urls[$template] = $link;
             }
         }
     }
     return $urls;
 }
/**
 * Show the config editor.
 */
function cpm_manager_edit_config()
{
    global $cpm_config, $wpmu_version;
    include 'cp_configuration_options.php';
    $max_depth = 3;
    $max_depth_message = false;
    $max_directories = 256;
    $folders_to_ignore = implode("|", array('wp-content', 'wp-includes', 'wp-admin'));
    $folder_stack = glob(CPM_DOCUMENT_ROOT . '/*');
    if ($folder_stack === false) {
        $folder_stack = array();
    }
    $found_folders = array();
    while (count($folder_stack) > 0) {
        $file = array_shift($folder_stack);
        if (is_dir($file)) {
            $root_file = substr($file, strlen(CPM_DOCUMENT_ROOT) + 1);
            if (preg_match("#({$folders_to_ignore})\$#", $root_file) == 0) {
                if (count(explode("/", $root_file)) <= $max_depth) {
                    $found_folders[] = $root_file;
                    $files = glob($file . "/*");
                    if (is_array($files)) {
                        $folder_stack = array_merge($folder_stack, $files);
                    }
                } else {
                    if (!$max_depth_message) {
                        $cpm_config->messages[] = sprintf(__("I went %s levels deep in my search for comic directories. Are you sure you have your site set up correctly?", 'comicpress-manager'), $max_depth);
                        $max_depth_message = true;
                    }
                }
            }
        }
        if (count($found_folders) == $max_directories) {
            $cpm_config->messages[] = sprintf(__("I found over %s directories from your site root. Are you sure you have your site set up correctly?", 'comicpress-manager'), $max_directories);
            break;
        }
    }
    sort($found_folders);
    ob_start();
    ?>

  <form action="" method="post" id="config-editor">
    <input type="hidden" name="action" value="update-config" />

    <table class="form-table">
      <?php 
    foreach ($comicpress_configuration_options as $field_info) {
        $no_wpmu = false;
        extract($field_info);
        //       $ok = ($wpmu_version) ? ($no_wpmu !== true) : true;
        $ok = true;
        if ($ok) {
            $description = " <em>(" . $description . ")</em>";
            $config_id = isset($field_info['variable_name']) ? $field_info['variable_name'] : $field_info['id'];
            switch ($type) {
                case "category":
                    ?>
              <tr>
                <th scope="row"><?php 
                    echo $name;
                    ?>
:</th>
                <td><select name="<?php 
                    echo $config_id;
                    ?>
" title="<?php 
                    _e('All possible WordPress categories', 'comicpress-manager');
                    ?>
">
                               <?php 
                    foreach (get_all_category_ids() as $cat_id) {
                        $category = get_category($cat_id);
                        ?>
                                 <option value="<?php 
                        echo $category->cat_ID;
                        ?>
"
                                         <?php 
                        echo $cpm_config->properties[$config_id] == $cat_id ? " selected" : "";
                        ?>
><?php 
                        echo $category->cat_name;
                        ?>
</option>
                               <?php 
                    }
                    ?>
                             </select><?php 
                    echo $description;
                    ?>
</td>
              </tr>
              <?php 
                    break;
                case "folder":
                    $directory_found_in_list = in_array($cpm_config->properties[$config_id], $found_folders);
                    ?>
              <tr>
                <th scope="row"><?php 
                    echo $name;
                    ?>
:</th>
                <td class="config-field">
                  <input type="radio" name="folder-<?php 
                    echo $config_id;
                    ?>
" id="folder-s-<?php 
                    echo $config_id;
                    ?>
" value="select" <?php 
                    echo $directory_found_in_list ? "checked" : "";
                    ?>
/> <label for="folder-s-<?php 
                    echo $config_id;
                    ?>
">Select directory from a list</label><br />
                  <div id="folder-select-<?php 
                    echo $config_id;
                    ?>
">
                    <select title="<?php 
                    _e("List of possible folders at the root of your site", 'comicpress-manager');
                    ?>
" name="select-<?php 
                    echo $config_id;
                    ?>
" id="<?php 
                    echo $config_id;
                    ?>
">
                    <?php 
                    foreach ($found_folders as $file) {
                        ?>
                        <option <?php 
                        echo $file == $cpm_config->properties[$config_id] ? " selected" : "";
                        ?>
 value="<?php 
                        echo $file;
                        ?>
"><?php 
                        echo $file;
                        ?>
</option>
                      <?php 
                    }
                    ?>
                    </select><?php 
                    echo $description;
                    ?>
                  </div>

                  <input type="radio" name="folder-<?php 
                    echo $config_id;
                    ?>
" id="folder-e-<?php 
                    echo $config_id;
                    ?>
" value="enter" <?php 
                    echo !$directory_found_in_list ? "checked" : "";
                    ?>
/> <label for="folder-e-<?php 
                    echo $config_id;
                    ?>
">Enter in my directory name</label><br />
                  <div id="folder-enter-<?php 
                    echo $config_id;
                    ?>
">
                    <input type="text" name="enter-<?php 
                    echo $config_id;
                    ?>
" value="<?php 
                    echo $cpm_config->properties[$config_id];
                    ?>
" />
                  </div>
                  <script type="text/javascript">
                    var folder_handler_<?php 
                    echo $config_id;
                    ?>
 = function() {
                      if ($("folder-e-<?php 
                    echo $config_id;
                    ?>
").checked) {
                        $("folder-select-<?php 
                    echo $config_id;
                    ?>
").hide();
                        $("folder-enter-<?php 
                    echo $config_id;
                    ?>
").show();
                      } else {
                        $("folder-select-<?php 
                    echo $config_id;
                    ?>
").show();
                        $("folder-enter-<?php 
                    echo $config_id;
                    ?>
").hide();
                      }
                    };

                    ["s", "e"].each(function(w) {
                      Event.observe("folder-" + w + "-<?php 
                    echo $config_id;
                    ?>
", 'change', folder_handler_<?php 
                    echo $config_id;
                    ?>
);
                    });

                    folder_handler_<?php 
                    echo $config_id;
                    ?>
();
                  </script>
                </td>
              </tr>
              <?php 
                    break;
                case "integer":
                    ?>
              <tr>
                <th scope="row"><?php 
                    echo $name;
                    ?>
:</th>
                <td><input type="text" name="<?php 
                    echo $config_id;
                    ?>
" size="20" value="<?php 
                    echo $cpm_config->properties[$config_id];
                    ?>
" /><?php 
                    echo $description;
                    ?>
</td>
              </tr>
              <?php 
                    break;
            }
        }
    }
    ?>
      <?php 
    if (!$wpmu_version) {
        ?>
        <?php 
        $all_comic_folders_found = true;
        foreach (array('' . 'rss_', 'archive_') as $folder_name) {
            if (!file_exists(CPM_DOCUMENT_ROOT . '/' . $cpm_config->properties["{$folder_name}comic_folder"])) {
                $all_comic_folders_found = false;
                break;
            }
        }
        if (!$all_comic_folders_found) {
            ?>
            <tr>
              <td colspan="2">
                <p><?php 
            _e("<strong>Create your comics, archive, or RSS folders first</strong>, then reload this page and use the dropdowns to select the target folder. If ComicPress Manager can't automatically find your folders, you can enter the folder names into the dropdowns.", 'comicpress-manager');
            ?>
</p>
              </td>
            </tr>
          <?php 
        }
        ?>
        <?php 
        if (!$cpm_config->is_wp_options) {
            ?>
          <tr>
            <th scope="row"><label for="just-show-config"><?php 
            _e("Don't try to write my config out; just display it", 'comicpress-manager');
            ?>
</label></th>
            <td>
              <input type="checkbox" name="just-show-config" id="just-show-config" value="yes" />
              <label for="just-show-config"><em>(if you're having problems writing to your config from ComicPress Manager, check this box)</em></label>
            </td>
          </tr>
        <?php 
        }
        ?>
      <?php 
    }
    ?>
      <tr>
        <td colspan="2" align="center">
          <input class="button update-config" type="submit" value="<?php 
    _e("Update Config", 'comicpress-manager');
    ?>
" />
        </td>
      </tr>
    </table>
  </form>

  <?php 
    return ob_get_clean();
}
Example #24
0
 function find_included_cats($instance)
 {
     //instance of current width
     $cat_ids = get_all_category_ids();
     $included = array();
     foreach ($cat_ids as $cat_id) {
         $key = "cat_id_" . $cat_id;
         if (array_key_exists($key, $instance) && $instance[$key] == "yes") {
             $included[] = $cat_id;
         }
     }
     return $included;
 }
Example #25
0
 function ajax_render_location($options = array())
 {
     // defaults
     $defaults = array('group_id' => 0, 'rule_id' => 0, 'value' => null, 'param' => null);
     $is_ajax = false;
     if (isset($_POST['nonce']) && wp_verify_nonce($_POST['nonce'], 'acf_nonce')) {
         $is_ajax = true;
     }
     // Is AJAX call?
     if ($is_ajax) {
         $options = array_merge($defaults, $_POST);
     } else {
         $options = array_merge($defaults, $options);
     }
     // vars
     $choices = array();
     // some case's have the same outcome
     if ($options['param'] == "page_parent") {
         $options['param'] = "page";
     }
     switch ($options['param']) {
         case "post_type":
             // all post types except attachment
             $choices = apply_filters('acf/get_post_types', array(), array('attachment'));
             break;
         case "page":
             $post_type = 'page';
             $posts = get_posts(array('posts_per_page' => -1, 'post_type' => $post_type, 'orderby' => 'menu_order title', 'order' => 'ASC', 'post_status' => 'any', 'suppress_filters' => false, 'update_post_meta_cache' => false));
             if ($posts) {
                 // sort into hierachial order!
                 if (is_post_type_hierarchical($post_type)) {
                     $posts = get_page_children(0, $posts);
                 }
                 foreach ($posts as $page) {
                     $title = '';
                     $ancestors = get_ancestors($page->ID, 'page');
                     if ($ancestors) {
                         foreach ($ancestors as $a) {
                             $title .= '- ';
                         }
                     }
                     $title .= apply_filters('the_title', $page->post_title, $page->ID);
                     // status
                     if ($page->post_status != "publish") {
                         $title .= " ({$page->post_status})";
                     }
                     $choices[$page->ID] = $title;
                 }
                 // foreach($pages as $page)
             }
             break;
         case "page_type":
             $choices = array('front_page' => __("Front Page", 'acf'), 'posts_page' => __("Posts Page", 'acf'), 'top_level' => __("Top Level Page (parent of 0)", 'acf'), 'parent' => __("Parent Page (has children)", 'acf'), 'child' => __("Child Page (has parent)", 'acf'));
             break;
         case "page_template":
             $choices = array('default' => __("Default Template", 'acf'));
             $templates = get_page_templates();
             foreach ($templates as $k => $v) {
                 $choices[$v] = $k;
             }
             break;
         case "post":
             $post_types = get_post_types();
             unset($post_types['page'], $post_types['attachment'], $post_types['revision'], $post_types['nav_menu_item'], $post_types['acf']);
             if ($post_types) {
                 foreach ($post_types as $post_type) {
                     $posts = get_posts(array('numberposts' => '-1', 'post_type' => $post_type, 'post_status' => array('publish', 'private', 'draft', 'inherit', 'future'), 'suppress_filters' => false));
                     if ($posts) {
                         $choices[$post_type] = array();
                         foreach ($posts as $post) {
                             $title = apply_filters('the_title', $post->post_title, $post->ID);
                             // status
                             if ($post->post_status != "publish") {
                                 $title .= " ({$post->post_status})";
                             }
                             $choices[$post_type][$post->ID] = $title;
                         }
                         // foreach($posts as $post)
                     }
                     // if( $posts )
                 }
                 // foreach( $post_types as $post_type )
             }
             // if( $post_types )
             break;
         case "post_category":
             $category_ids = get_all_category_ids();
             foreach ($category_ids as $cat_id) {
                 $cat_name = get_cat_name($cat_id);
                 $choices[$cat_id] = $cat_name;
             }
             break;
         case "post_format":
             $choices = get_post_format_strings();
             break;
         case "post_status":
             $choices = array('publish' => __('Publish', 'acf'), 'pending' => __('Pending Review', 'acf'), 'draft' => __('Draft', 'acf'), 'future' => __('Future', 'acf'), 'private' => __('Private', 'acf'), 'inherit' => __('Revision', 'acf'), 'trash' => __('Trash', 'acf'));
             break;
         case "user_type":
             global $wp_roles;
             $choices = $wp_roles->get_names();
             if (is_multisite()) {
                 $choices['super_admin'] = __('Super Admin', 'acf');
             }
             break;
         case "taxonomy":
             $choices = array();
             $simple_value = true;
             $choices = apply_filters('acf/get_taxonomies_for_select', $choices, $simple_value);
             break;
         case "ef_taxonomy":
             $choices = array('all' => __('All', 'acf'));
             $taxonomies = get_taxonomies(array('public' => true), 'objects');
             foreach ($taxonomies as $taxonomy) {
                 $choices[$taxonomy->name] = $taxonomy->labels->name;
             }
             // unset post_format (why is this a public taxonomy?)
             if (isset($choices['post_format'])) {
                 unset($choices['post_format']);
             }
             break;
         case "ef_user":
             global $wp_roles;
             $choices = array_merge(array('all' => __('All', 'acf')), $wp_roles->get_names());
             break;
         case "ef_media":
             $choices = array('all' => __('All', 'acf'));
             break;
     }
     // allow custom location rules
     $choices = apply_filters('acf/location/rule_values/' . $options['param'], $choices);
     // create field
     do_action('acf/create_field', array('type' => 'select', 'name' => 'location[' . $options['group_id'] . '][' . $options['rule_id'] . '][value]', 'value' => $options['value'], 'choices' => $choices));
     // ajax?
     if ($is_ajax) {
         die;
     }
 }
	function &get_posts() {
		global $wpdb, $pagenow, $user_ID;

		do_action('pre_get_posts', array(&$this));

		// Shorthand.
		$q = $this->query_vars;	

		// First let's clear some variables
		$whichcat = '';
		$whichauthor = '';
		$whichpage = '';
		$result = '';
		$where = '';
		$limits = '';
		$distinct = '';
		$join = '';

		if ( !isset($q['posts_per_page']) || $q['posts_per_page'] == 0 )
			$q['posts_per_page'] = get_settings('posts_per_page');
		if ( !isset($q['what_to_show']) )
			$q['what_to_show'] = get_settings('what_to_show');
		if ( isset($q['showposts']) && $q['showposts'] ) {
			$q['showposts'] = (int) $q['showposts'];
			$q['posts_per_page'] = $q['showposts'];
		}
		if ( (isset($q['posts_per_archive_page']) && $q['posts_per_archive_page'] != 0) && ($this->is_archive || $this->is_search) )
			$q['posts_per_page'] = $q['posts_per_archive_page'];
		if ( !isset($q['nopaging']) ) {
			if ($q['posts_per_page'] == -1) {
				$q['nopaging'] = true;
			} else {
				$q['nopaging'] = false;
			}
		}
		if ( $this->is_feed ) {
			$q['posts_per_page'] = get_settings('posts_per_rss');
			$q['what_to_show'] = 'posts';
		}

		if (isset($q['page'])) {
			$q['page'] = trim($q['page'], '/');
			$q['page'] = (int) $q['page'];
			$q['page'] = abs($q['page']);
		}
	
		$add_hours = intval(get_settings('gmt_offset'));
		$add_minutes = intval(60 * (get_settings('gmt_offset') - $add_hours));
		$wp_posts_post_date_field = "post_date"; // "DATE_ADD(post_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)";

		// If a month is specified in the querystring, load that month
		if ( (int) $q['m'] ) {
			$q['m'] = '' . preg_replace('|[^0-9]|', '', $q['m']);
			$where .= ' AND YEAR(post_date)=' . substr($q['m'], 0, 4);
			if (strlen($q['m'])>5)
				$where .= ' AND MONTH(post_date)=' . substr($q['m'], 4, 2);
			if (strlen($q['m'])>7)
				$where .= ' AND DAYOFMONTH(post_date)=' . substr($q['m'], 6, 2);
			if (strlen($q['m'])>9)
				$where .= ' AND HOUR(post_date)=' . substr($q['m'], 8, 2);
			if (strlen($q['m'])>11)
				$where .= ' AND MINUTE(post_date)=' . substr($q['m'], 10, 2);
			if (strlen($q['m'])>13)
				$where .= ' AND SECOND(post_date)=' . substr($q['m'], 12, 2);
		}

		if ( (int) $q['hour'] ) {
			$q['hour'] = '' . intval($q['hour']);
			$where .= " AND HOUR(post_date)='" . $q['hour'] . "'";
		}

		if ( (int) $q['minute'] ) {
			$q['minute'] = '' . intval($q['minute']);
			$where .= " AND MINUTE(post_date)='" . $q['minute'] . "'";
		}

		if ( (int) $q['second'] ) {
			$q['second'] = '' . intval($q['second']);
			$where .= " AND SECOND(post_date)='" . $q['second'] . "'";
		}

		if ( (int) $q['year'] ) {
			$q['year'] = '' . intval($q['year']);
			$where .= " AND YEAR(post_date)='" . $q['year'] . "'";
		}

		if ( (int) $q['monthnum'] ) {
			$q['monthnum'] = '' . intval($q['monthnum']);
			$where .= " AND MONTH(post_date)='" . $q['monthnum'] . "'";
		}

		if ( (int) $q['day'] ) {
			$q['day'] = '' . intval($q['day']);
			$where .= " AND DAYOFMONTH(post_date)='" . $q['day'] . "'";
		}

		// Compat.  Map subpost to attachment.
		if ( '' != $q['subpost'] )
			$q['attachment'] = $q['subpost'];
		if ( '' != $q['subpost_id'] )
			$q['attachment_id'] = $q['subpost_id'];

		if ('' != $q['name']) {
			$q['name'] = sanitize_title($q['name']);
			$where .= " AND post_name = '" . $q['name'] . "'";
		} else if ('' != $q['pagename']) {
			$q['pagename'] = str_replace('%2F', '/', urlencode(urldecode($q['pagename'])));
			$page_paths = '/' . trim($q['pagename'], '/');
			$q['pagename'] = sanitize_title(basename($page_paths));
			$q['name'] = $q['pagename'];
			$page_paths = explode('/', $page_paths);
			foreach($page_paths as $pathdir)
				$page_path .= ($pathdir!=''?'/':'') . sanitize_title($pathdir);
				
			$all_page_ids = get_all_page_ids();
			$reqpage = 0;
			if (is_array($all_page_ids)) { foreach ( $all_page_ids as $page_id ) {
				$page = get_page($page_id);
				if ( $page->fullpath == $page_path ) {
					$reqpage = $page_id;
					break;
				}
			} }
			
			$where .= " AND (ID = '$reqpage')";
		} elseif ('' != $q['attachment']) {
			$q['attachment'] = str_replace('%2F', '/', urlencode(urldecode($q['attachment'])));
			$attach_paths = '/' . trim($q['attachment'], '/');
			$q['attachment'] = sanitize_title(basename($attach_paths));
			$q['name'] = $q['attachment'];
			$where .= " AND post_name = '" . $q['attachment'] . "'";
		}

		if ( (int) $q['w'] ) {
			$q['w'] = ''.intval($q['w']);
			$where .= " AND WEEK(post_date, 1)='" . $q['w'] . "'";
		}

		if ( intval($q['comments_popup']) )
			$q['p'] = intval($q['comments_popup']);

		// If a attachment is requested by number, let it supercede any post number.
		if ( ($q['attachment_id'] != '') && (intval($q['attachment_id']) != 0) )
			$q['p'] = (int) $q['attachment_id'];

		// If a post number is specified, load that post
		if (($q['p'] != '') && intval($q['p']) != 0) {
			$q['p'] =  (int) $q['p'];
			$where = ' AND ID = ' . $q['p'];
		}

		if (($q['page_id'] != '') && (intval($q['page_id']) != 0)) {
			$q['page_id'] = intval($q['page_id']);
			$q['p'] = $q['page_id'];
			$where = ' AND ID = '.$q['page_id'];
		}

		// If a search pattern is specified, load the posts that match
		if (!empty($q['s'])) {
			$q['s'] = addslashes_gpc($q['s']);
			$search = ' AND (';
			$q['s'] = preg_replace('/, +/', ' ', $q['s']);
			$q['s'] = str_replace(',', ' ', $q['s']);
			$q['s'] = str_replace('"', ' ', $q['s']);
			$q['s'] = trim($q['s']);
			if ($q['exact']) {
				$n = '';
			} else {
				$n = '%';
			}
			if (!$q['sentence']) {
				$s_array = explode(' ',$q['s']);
				$q['search_terms'] = $s_array;
				$search .= '((post_title LIKE \''.$n.$s_array[0].$n.'\') OR (post_content LIKE \''.$n.$s_array[0].$n.'\'))';
				for ( $i = 1; $i < count($s_array); $i = $i + 1) {
					$search .= ' AND ((post_title LIKE \''.$n.$s_array[$i].$n.'\') OR (post_content LIKE \''.$n.$s_array[$i].$n.'\'))';
				}
				$search .= ' OR (post_title LIKE \''.$n.$q['s'].$n.'\') OR (post_content LIKE \''.$n.$q['s'].$n.'\')';
				$search .= ')';
			} else {
				$search = ' AND ((post_title LIKE \''.$n.$q['s'].$n.'\') OR (post_content LIKE \''.$n.$q['s'].$n.'\'))';
			}
		}

		// Category stuff

		if ((empty($q['cat'])) || ($q['cat'] == '0') || 
				// Bypass cat checks if fetching specific posts
				( $this->is_single || $this->is_page )) {
			$whichcat='';
		} else {
			$q['cat'] = ''.urldecode($q['cat']).'';
			$q['cat'] = addslashes_gpc($q['cat']);
			if (stristr($q['cat'],'-')) {
				// Note: if we have a negative, we ignore all the positives. It must
				// always mean 'everything /except/ this one'. We should be able to do
				// multiple negatives but we don't :-(
				$eq = '!=';
				$andor = 'AND';
				$q['cat'] = explode('-',$q['cat']);
				$q['cat'] = intval($q['cat'][1]);
			} else {
				$eq = '=';
				$andor = 'OR';
			}
			$join = " LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id) ";
			$cat_array = preg_split('/[,\s]+/', $q['cat']);
			$whichcat .= ' AND (category_id '.$eq.' '.intval($cat_array[0]);
			$whichcat .= get_category_children($cat_array[0], ' '.$andor.' category_id '.$eq.' ');
			for ($i = 1; $i < (count($cat_array)); $i = $i + 1) {
				$whichcat .= ' '.$andor.' category_id '.$eq.' '.intval($cat_array[$i]);
				$whichcat .= get_category_children($cat_array[$i], ' '.$andor.' category_id '.$eq.' ');
			}
			$whichcat .= ')';
			if ($eq == '!=') {
				$q['cat'] = '-'.$q['cat']; // Put back the knowledge that we are excluding a category.
			}
		}

		// Category stuff for nice URIs

		global $cache_categories;
		if ('' != $q['category_name']) {
			$cat_paths = '/' . trim(urldecode($q['category_name']), '/');
			$q['category_name'] = sanitize_title(basename($cat_paths));
			$cat_paths = explode('/', $cat_paths);
			foreach($cat_paths as $pathdir)
				$cat_path .= ($pathdir!=''?'/':'') . sanitize_title($pathdir);

			$all_cat_ids = get_all_category_ids();
			$q['cat'] = 0; $partial_match = 0;
			foreach ( $all_cat_ids as $cat_id ) {
				$cat = get_category($cat_id);
				if ( $cat->fullpath == $cat_path ) {
					$q['cat'] = $cat_id;
					break;
				} elseif ( $cat->category_nicename == $q['category_name'] ) {
					$partial_match = $cat_id;
				}
			}
			
			//if we don't match the entire hierarchy fallback on just matching the nicename
			if (!$q['cat'] && $partial_match) {
				$q['cat'] = $partial_match;
			}			

			$tables = ", $wpdb->post2cat, $wpdb->categories";
			$join = " LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id) LEFT JOIN $wpdb->categories ON ($wpdb->post2cat.category_id = $wpdb->categories.cat_ID) ";
			$whichcat = " AND (category_id = '" . $q['cat'] . "'";
			$whichcat .= get_category_children($q['cat'], " OR category_id = ");
			$whichcat .= ")";
		}

		// Author/user stuff

		if ((empty($q['author'])) || ($q['author'] == '0')) {
			$whichauthor='';
		} else {
			$q['author'] = ''.urldecode($q['author']).'';
			$q['author'] = addslashes_gpc($q['author']);
			if (stristr($q['author'], '-')) {
				$eq = '!=';
				$andor = 'AND';
				$q['author'] = explode('-', $q['author']);
				$q['author'] = ''.intval($q['author'][1]);
			} else {
				$eq = '=';
				$andor = 'OR';
			}
			$author_array = preg_split('/[,\s]+/', $q['author']);
			$whichauthor .= ' AND (post_author '.$eq.' '.intval($author_array[0]);
			for ($i = 1; $i < (count($author_array)); $i = $i + 1) {
				$whichauthor .= ' '.$andor.' post_author '.$eq.' '.intval($author_array[$i]);
			}
			$whichauthor .= ')';
		}

		// Author stuff for nice URIs

		if ('' != $q['author_name']) {
			if (stristr($q['author_name'],'/')) {
				$q['author_name'] = explode('/',$q['author_name']);
				if ($q['author_name'][count($q['author_name'])-1]) {
					$q['author_name'] = $q['author_name'][count($q['author_name'])-1];#no trailing slash
				} else {
					$q['author_name'] = $q['author_name'][count($q['author_name'])-2];#there was a trailling slash
				}
			}
			$q['author_name'] = sanitize_title($q['author_name']);
			$q['author'] = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_nicename='".$q['author_name']."'");
			$whichauthor .= ' AND (post_author = '.intval($q['author']).')';
		}
		
		$where .= $search.$whichcat.$whichauthor;

		if ((empty($q['order'])) || ((strtoupper($q['order']) != 'ASC') && (strtoupper($q['order']) != 'DESC'))) {
			$q['order']='DESC';
		}

		// Order by
		if (empty($q['orderby'])) {
			$q['orderby']='date '.$q['order'];
		} else {
			// Used to filter values
			$allowed_keys = array('author', 'date', 'category', 'title', 'modified');
			$q['orderby'] = urldecode($q['orderby']);
			$q['orderby'] = addslashes_gpc($q['orderby']);
			$orderby_array = explode(' ',$q['orderby']);
			if (!in_array($orderby_array[0],$allowed_keys)) {
				$orderby_array[0] = 'date';
			}
			$q['orderby'] = $orderby_array[0].' '.$q['order'];
			if (count($orderby_array)>1) {
				for ($i = 1; $i < (count($orderby_array)); $i = $i + 1) {
					// Only allow certain values for safety
					if (in_array($orderby_array[$i],$allowed_keys)) {
						$q['orderby'] .= ',post_'.$orderby_array[$i].' '.$q['order'];
					}
				}
			}
		}

		$now = gmdate('Y-m-d H:i:59');
		
		//only select past-dated posts, except if a logged in user is viewing a single: then, if they
		//can edit the post, we let them through
		if ($pagenow != 'post.php' && $pagenow != 'edit.php' && !($this->is_single && $user_ID)) {
			$where .= " AND post_date_gmt <= '$now'";
			$distinct = 'DISTINCT';
		}

		if ( $this->is_attachment ) {
			$where .= " AND (post_status = 'attachment')";
		} elseif ($this->is_page) {
			$where .= " AND (post_status = 'static')";
		} elseif ($this->is_single) {
			$where .= " AND (post_status != 'static')";
		} else {
			$where .= " AND (post_status = 'publish'";

			if (isset($user_ID) && ('' != intval($user_ID)))
				$where .= " OR post_author = $user_ID AND post_status != 'draft' AND post_status != 'static')";
			else
				$where .= ')';				
		}

		if (! $this->is_attachment )
			$where .= " AND post_status != 'attachment'";

		// Apply filters on where and join prior to paging so that any
		// manipulations to them are reflected in the paging by day queries.
		$where = apply_filters('posts_where', $where);
		$join = apply_filters('posts_join', $join);

		// Paging
		if (empty($q['nopaging']) && ! $this->is_single && ! $this->is_page) {
			$page = abs(intval($q['paged']));
			if (empty($page)) {
				$page = 1;
			}

			if (($q['what_to_show'] == 'posts')) {
				$q['offset'] = abs(intval($q['offset']));
				if ( empty($q['offset']) ) {
					$pgstrt = '';
					$pgstrt = (intval($page) -1) * $q['posts_per_page'] . ', ';
					$limits = 'LIMIT '.$pgstrt.$q['posts_per_page'];
				} else { // we're ignoring $page and using 'offset'
					$pgstrt = $q['offset'] . ', ';
					$limits = 'LIMIT ' . $pgstrt . $q['posts_per_page'];
				}
			} elseif ($q['what_to_show'] == 'days') {
				$startrow = $q['posts_per_page'] * (intval($page)-1);
				$start_date = $wpdb->get_var("SELECT max(post_date) FROM $wpdb->posts $join WHERE (1=1) $where GROUP BY year(post_date), month(post_date), dayofmonth(post_date) ORDER BY post_date DESC LIMIT $startrow,1");
				$endrow = $startrow + $q['posts_per_page'] - 1;
				$end_date = $wpdb->get_var("SELECT min(post_date) FROM $wpdb->posts $join WHERE (1=1) $where GROUP BY year(post_date), month(post_date), dayofmonth(post_date) ORDER BY post_date DESC LIMIT $endrow,1");

				if ($page > 1) {
					$where .= " AND post_date >= '$end_date' AND post_date <= '$start_date'";
				} else {
					$where .= " AND post_date >= '$end_date'";
				}
			}
		}

		// Apply post-paging filters on where and join.  Only plugins that
		// manipulate paging queries should use these hooks.
		$where = apply_filters('posts_where_paged', $where);
		$groupby = " $wpdb->posts.ID ";
		$groupby = apply_filters('posts_groupby', $groupby);
		$join = apply_filters('posts_join_paged', $join);
		$orderby = "post_" . $q['orderby'];
		$orderby = apply_filters('posts_orderby', $orderby); 
		$request = " SELECT $distinct * FROM $wpdb->posts $join WHERE 1=1" . $where . " GROUP BY " . $groupby . " ORDER BY " . $orderby . " $limits";
		$this->request = apply_filters('posts_request', $request);

		$this->posts = $wpdb->get_results($this->request);

		// Check post status to determine if post should be displayed.
		if ( !empty($this->posts) && $this->is_single ) {
			$status = get_post_status($this->posts[0]);
			if ( ('publish' != $status) && ('static' != $status) ) {
				if ( ! (isset($user_ID) && ('' != intval($user_ID))) ) {
					// User must be logged in to view unpublished posts.
					$this->posts = array();
				} else {
					if ('draft' == $status) {
						// User must have edit permissions on the draft to preview.
						if (! current_user_can('edit_post', $this->posts[0]->ID)) {
							$this->posts = array();
						} else {
							$this->is_preview = true;
							$this->posts[0]->post_date = current_time('mysql');
						}
					} else {
						if (! current_user_can('read_post', $this->posts[0]->ID))
							$this->posts = array();
					}
				}
			} else {
				if (mysql2date('U', $this->posts[0]->post_date_gmt) > mysql2date('U', $now)) { //it's future dated
					$this->is_preview = true;
					if (!current_user_can('edit_post', $this->posts[0]->ID)) {
						$this->posts = array ( );
					}
				}
			}
		}

		update_post_caches($this->posts);

		$this->posts = apply_filters('the_posts', $this->posts);
		$this->post_count = count($this->posts);
		if ($this->post_count > 0) {
			$this->post = $this->posts[0];
		}
		
		// Save any changes made to the query vars.
		$this->query_vars = $q;
		return $this->posts;
	}
Example #27
0
 /**
 Sends an email notification of a new post
 */
 function publish($post, $preview = '')
 {
     if (!$post) {
         return $post;
     }
     if ($this->s2_mu) {
         global $switched;
         if ($switched) {
             return;
         }
     }
     if ($preview == '') {
         // we aren't sending a Preview to the current user so carry out checks
         $s2mail = get_post_meta($post->ID, '_s2mail', true);
         if (isset($_POST['s2_meta_field']) && $_POST['s2_meta_field'] == 'no' || strtolower(trim($s2mail)) == 'no') {
             return $post;
         }
         // are we doing daily digests? If so, don't send anything now
         if ($this->subscribe2_options['email_freq'] != 'never') {
             return $post;
         }
         // is the current post of a type that should generate a notification email?
         // uses s2_post_types filter to allow for custom post types in WP 3.0
         if ($this->subscribe2_options['pages'] == 'yes') {
             $s2_post_types = array('page', 'post');
         } else {
             $s2_post_types = array('post');
         }
         $s2_post_types = apply_filters('s2_post_types', $s2_post_types);
         if (!in_array($post->post_type, $s2_post_types)) {
             return $post;
         }
         // Are we sending notifications for password protected posts?
         if ($this->subscribe2_options['password'] == "no" && $post->post_password != '') {
             return $post;
         }
         // Is the post assigned to a format for which we should not be sending posts
         $post_format = get_post_format($post->ID);
         $excluded_formats = explode(',', $this->subscribe2_options['exclude_formats']);
         if ($post_format !== false && in_array($post_format, $excluded_formats)) {
             return $post;
         }
         $s2_taxonomies = apply_filters('s2_taxonomies', array('category'));
         $post_cats = wp_get_object_terms($post->ID, $s2_taxonomies, array('fields' => 'ids'));
         $check = false;
         // is the current post assigned to any categories
         // which should not generate a notification email?
         foreach (explode(',', $this->subscribe2_options['exclude']) as $cat) {
             if (in_array($cat, $post_cats)) {
                 $check = true;
             }
         }
         if ($check) {
             // hang on -- can registered users subscribe to
             // excluded categories?
             if ('0' == $this->subscribe2_options['reg_override']) {
                 // nope? okay, let's leave
                 return $post;
             }
         }
         // Are we sending notifications for Private posts?
         // Action is added if we are, but double check option and post status
         if ($this->subscribe2_options['private'] == "yes" && $post->post_status == 'private') {
             // don't send notification to public users
             $check = true;
         }
         // lets collect our subscribers
         if (!$check) {
             // if this post is assigned to an excluded
             // category, or is a private post then
             // don't send public subscribers a notification
             $public = $this->get_public();
         }
         if ($post->post_type == 'page') {
             $post_cats_string = get_all_category_ids();
         } else {
             $post_cats_string = implode(',', $post_cats);
         }
         $registered = $this->get_registered("cats={$post_cats_string}");
         // do we have subscribers?
         if (empty($public) && empty($registered)) {
             // if not, no sense doing anything else
             return $post;
         }
     } else {
         // make sure we prime the taxonomy variable for preview posts
         $s2_taxonomies = apply_filters('s2_taxonomies', array('category'));
     }
     // we set these class variables so that we can avoid
     // passing them in function calls a little later
     $this->post_title = "<a href=\"" . get_permalink($post->ID) . "\">" . html_entity_decode($post->post_title, ENT_QUOTES) . "</a>";
     $this->permalink = get_permalink($post->ID);
     $this->post_date = get_the_time(get_option('date_format'));
     $this->post_time = get_the_time();
     $author = get_userdata($post->post_author);
     $this->authorname = html_entity_decode(apply_filters('the_author', $author->display_name), ENT_QUOTES);
     // do we send as admin, or post author?
     if ('author' == $this->subscribe2_options['sender']) {
         // get author details
         $user =& $author;
         $this->myemail = $user->user_email;
         $this->myname = html_entity_decode($user->display_name, ENT_QUOTES);
     } elseif ('blogname' == $this->subscribe2_options['sender']) {
         $this->myemail = get_option('admin_email');
         $this->myname = html_entity_decode(get_option('blogname'), ENT_QUOTES);
     } else {
         // get admin details
         $user = $this->get_userdata($this->subscribe2_options['sender']);
         $this->myemail = $user->user_email;
         $this->myname = html_entity_decode($user->display_name, ENT_QUOTES);
     }
     $this->post_cat_names = implode(', ', wp_get_object_terms($post->ID, $s2_taxonomies, array('fields' => 'names')));
     $this->post_tag_names = implode(', ', wp_get_post_tags($post->ID, array('fields' => 'names')));
     // Get email subject
     $subject = html_entity_decode(stripslashes(wp_kses($this->substitute($this->subscribe2_options['notification_subject']), '')));
     // Get the message template
     $mailtext = apply_filters('s2_email_template', $this->subscribe2_options['mailtext']);
     $mailtext = stripslashes($this->substitute($mailtext));
     $plaintext = $post->post_content;
     if (function_exists('strip_shortcodes')) {
         $plaintext = strip_shortcodes($plaintext);
     }
     $plaintext = preg_replace('|<s[^>]*>(.*)<\\/s>|Ui', '', $plaintext);
     $plaintext = preg_replace('|<strike[^>]*>(.*)<\\/strike>|Ui', '', $plaintext);
     $plaintext = preg_replace('|<del[^>]*>(.*)<\\/del>|Ui', '', $plaintext);
     $gallid = '[gallery id="' . $post->ID . '"';
     $content = str_replace('[gallery', $gallid, $post->post_content);
     // remove the autoembed filter to remove iframes from notification emails
     if (get_option('embed_autourls')) {
         global $wp_embed;
         $priority = has_filter('the_content', array(&$wp_embed, 'autoembed'));
         if ($priority !== false) {
             remove_filter('the_content', array(&$wp_embed, 'autoembed'), $priority);
         }
     }
     $content = apply_filters('the_content', $content);
     $content = str_replace("]]>", "]]&gt", $content);
     $excerpt = $post->post_excerpt;
     if ('' == $excerpt) {
         // no excerpt, is there a <!--more--> ?
         if (false !== strpos($plaintext, '<!--more-->')) {
             list($excerpt, $more) = explode('<!--more-->', $plaintext, 2);
             // strip leading and trailing whitespace
             $excerpt = strip_tags($excerpt);
             $excerpt = trim($excerpt);
         } else {
             // no <!--more-->, so grab the first 55 words
             $excerpt = strip_tags($plaintext);
             $words = explode(' ', $excerpt, $this->excerpt_length + 1);
             if (count($words) > $this->excerpt_length) {
                 array_pop($words);
                 array_push($words, '[...]');
                 $excerpt = implode(' ', $words);
             }
         }
     }
     $html_excerpt = $post->post_excerpt;
     if ('' == $html_excerpt) {
         // no excerpt, is there a <!--more--> ?
         if (false !== strpos($content, '<!--more-->')) {
             list($html_excerpt, $more) = explode('<!--more-->', $content, 2);
             // balance HTML tags and then strip leading and trailing whitespace
             $html_excerpt = trim(balanceTags($html_excerpt, true));
         } else {
             // no <!--more-->, so grab the first 55 words
             $words = explode(' ', $content, $this->excerpt_length + 1);
             if (count($words) > $this->excerpt_length) {
                 array_pop($words);
                 array_push($words, '[...]');
                 $html_excerpt = implode(' ', $words);
                 // balance HTML tags and then strip leading and trailing whitespace
                 $html_excerpt = trim(balanceTags($html_excerpt, true));
             } else {
                 $html_excerpt = $content;
             }
         }
     }
     // remove excess white space from with $excerpt and $plaintext
     $excerpt = preg_replace('|[ ]+|', ' ', $excerpt);
     $plaintext = preg_replace('|[ ]+|', ' ', $plaintext);
     // prepare mail body texts
     $excerpt_body = str_replace("{POST}", $excerpt, $mailtext);
     $full_body = str_replace("{POST}", strip_tags($plaintext), $mailtext);
     $html_body = str_replace("\r\n", "<br />\r\n", $mailtext);
     $html_body = str_replace("{POST}", $content, $html_body);
     $html_excerpt_body = str_replace("\r\n", "<br />\r\n", $mailtext);
     $html_excerpt_body = str_replace("{POST}", $html_excerpt, $html_excerpt_body);
     if ($preview != '') {
         $this->myemail = $preview;
         $this->myname = __('Plain Text Excerpt Preview', 'subscribe2');
         $this->mail(array($preview), $subject, $excerpt_body);
         $this->myname = __('Plain Text Full Preview', 'subscribe2');
         $this->mail(array($preview), $subject, $full_body);
         $this->myname = __('HTML Excerpt Preview', 'subscribe2');
         $this->mail(array($preview), $subject, $html_excerpt_body, 'html');
         $this->myname = __('HTML Full Preview', 'subscribe2');
         $this->mail(array($preview), $subject, $html_body, 'html');
     } else {
         // first we send plaintext summary emails
         $registered = $this->get_registered("cats={$post_cats_string}&format=excerpt&author={$post->post_author}");
         if (empty($registered)) {
             $recipients = (array) $public;
         } elseif (empty($public)) {
             $recipients = (array) $registered;
         } else {
             $recipients = array_merge((array) $public, (array) $registered);
         }
         $recipients = apply_filters('s2_send_plain_excerpt_suscribers', $recipients, $post->ID);
         $this->mail($recipients, $subject, $excerpt_body);
         // next we send plaintext full content emails
         $recipients = $this->get_registered("cats={$post_cats_string}&format=post&author={$post->post_author}");
         $recipients = apply_filters('s2_send_plain_fullcontent_suscribers', $recipients, $post->ID);
         $this->mail($recipients, $subject, $full_body);
         // next we send html excerpt content emails
         $recipients = $this->get_registered("cats={$post_cats_string}&format=html_excerpt&author={$post->post_author}");
         $recipients = apply_filters('s2_send_html_excerpt_suscribers', $recipients, $post->ID);
         $this->mail($recipients, $subject, $html_excerpt_body, 'html');
         // finally we send html full content emails
         $recipients = $this->get_registered("cats={$post_cats_string}&format=html&author={$post->post_author}");
         $recipients = apply_filters('s2_send_html_fullcontent_suscribers', $recipients, $post->ID);
         $this->mail($recipients, $subject, $html_body, 'html');
     }
 }
Example #28
0
<?php

$category_ids = get_all_category_ids();
if ($category_ids) {
    $cat_css = ' <style> ';
    $cat_js = ' <script> ';
    foreach ($category_ids as $cat_id) {
        $cat_color = get_tax_meta($cat_id, 'pego_category_color');
        if ($cat_color != '') {
            $cat_css .= ' .main-menu .sf-menu > li.menu-cat-item-' . $cat_id . ' > a  { border-top: 5px solid ' . $cat_color . '; } ';
            $cat_css .= ' .main-menu .sf-menu > li.menu-cat-item-' . $cat_id . ' > a:hover, .main-menu  .sf-menu > li.menu-cat-item-' . $cat_id . ' > a:focus, .main-menu .sf-menu > li.menu-cat-item-' . $cat_id . '.sfHover > a,
			
			.main-menu .sf-menu > li.menu-cat-item-' . $cat_id . '.sfHover .submenu_1  
			 { background-color: ' . $cat_color . '; color: #fff; } ';
            $cat_css .= ' .main-menu ul.sf-menu  li.menu-cat-item-' . $cat_id . '.current-menu-item > a,
						  .main-menu ul.sf-menu > li.menu-cat-item-' . $cat_id . '.current-menu-parent > a, 
						  .main-menu ul.sf-menu.cat-color-' . $cat_id . ' > li.menu-cat-item-' . $cat_id . '.current-menu-ancestor > a,
						  .main-menu .sf-menu > li.menu-cat-item-' . $cat_id . ' > a:focus
						  						  { background-color: ' . $cat_color . '; } ';
            //$cat_css .= ' .main-menu .sf-menu > li.menu-cat-item-'.$cat_id.'.sfHover > a { background-color: #fff; color: #000; } ';
            $cat_css .= ' .category-' . $cat_id . ' .main-menu .sf-menu  { border-color: ' . $cat_color . '; } ';
            $cat_css .= ' .category-' . $cat_id . ' .vc_progress_bar .vc_single_bar.bar_blue .vc_bar  { background-color: ' . $cat_color . '; } ';
            $cat_css .= ' .category-' . $cat_id . ' .review-average  { background-color: ' . $cat_color . '; } ';
            $cat_css .= ' .main-menu ul.sf-menu.cat-color-' . $cat_id . ' { border-color: ' . $cat_color . '; } ';
            $cat_css .= ' .category-color-' . $cat_id . ' { color: ' . $cat_color . '; } ';
            $cat_css .= ' .category-bg-color-' . $cat_id . ' { background-color: ' . $cat_color . ' !important; } ';
            $cat_css .= ' .category-hover-color-' . $cat_id . ':hover { color: ' . $cat_color . ' !important; } ';
            $cat_js .= ' 	jQuery(document).ready(function(){
							jQuery(".main-menu .sf-menu > li.menu-cat-item-' . $cat_id . ' > a, .main-menu .sf-menu > li.menu-cat-item-' . $cat_id . ' > .submenu_1").hover(function(){
									jQuery(".main-menu .sf-menu").addClass("cat-color-' . $cat_id . '");
								},function(){
Example #29
0
function ljxp_post($post_id, $bulk = false)
{
    global $wpdb, $tags, $cats;
    // tags/cats are going to be filtered thru an external function
    $options = ljxp_get_options();
    $errors = array();
    $post =& get_post($post_id);
    // Get postmeta overrides
    $privacy = get_post_meta($post->ID, 'ljxp_privacy', true);
    if (isset($privacy) && !empty($privacy)) {
        $options['privacy'] = $privacy;
        $options['privacy_private'] = $privacy;
        if ($privacy == 'groups') {
            $options['allowmask_public'] = get_post_meta($post->ID, 'ljxp_friendsgroups', true);
            $options['allowmask_private'] = get_post_meta($post->ID, 'ljxp_friendsgroups', true);
        }
    }
    $comments = get_post_meta($post->ID, 'ljxp_comments', true);
    if (isset($comments) && !empty($comments)) {
        $options['comments'] = $comments;
    }
    if ($options['comments'] == 2) {
        $options['comments'] = 0;
    }
    $options['userpic'] = get_post_meta($post->ID, 'ljxp_userpic', true);
    if (!is_array($options['skip_cats'])) {
        $options['skip_cats'] = array();
    }
    $options['copy_cats'] = array_diff(get_all_category_ids(), $options['skip_cats']);
    // If the post was manually set to not be crossposted, or nothing was set and the default is not to crosspost,
    // or it's private and the default is not to crosspost private posts, give up now
    if (0 == $options['crosspost'] || get_post_meta($post->ID, 'no_lj', true) || 'private' == $post->post_status && $options['privacy_private'] == 'no_lj') {
        $errors['nopost'] = 'This post was set to not crosspost.';
        return $post->ID;
    }
    // If the post shows up in the forbidden category list and it has been
    // crossposted before (so the forbidden category list must have changed),
    // delete the post. Otherwise, just give up now
    $do_crosspost = 0;
    $postcats = wp_get_post_categories($post->ID);
    foreach ($postcats as $cat) {
        if (in_array($cat, $options['copy_cats'])) {
            $do_crosspost = 1;
            break;
            // decision made and cannot be altered, fly on
        } else {
            $errors['nocats'] = 'This post was not in any of the right categories, so it was not crossposted.';
        }
    }
    if (!$do_crosspost) {
        return ljxp_delete($post->ID);
    }
    // And create our connection
    $client = new IXR_Client($options['host'], '/interface/xmlrpc');
    //$client->debug = true;
    // Get the challenge string
    // Using challenge for the most security. Allows pwd hash to be stored instead of pwd
    if (!$client->query('LJ.XMLRPC.getchallenge')) {
        $errors[$client->getErrorCode()] = $client->getErrorMessage();
    }
    // And retrieve the challenge string
    $response = $client->getResponse();
    $challenge = $response['challenge'];
    // Insert the name of the page we're linking back to based on the options set
    if (empty($options['custom_name_on'])) {
        $blogName = get_bloginfo('name');
    } else {
        $blogName = $options['custom_name'];
    }
    // Tagging and categorizing — for LJ tags
    // Not to be moved down: the else case of custom header is using $cats and $tags
    $cats = array();
    $tags = array();
    $cats = wp_get_post_categories($post->ID, array('fields' => 'all'));
    $tags = wp_get_post_tags($post->ID, array('fields' => 'all'));
    // Need advice on merging all ( /\ and \/ ) this code
    // convert retrieved objects to arrays of (term_id => name) pairs
    $modify = create_function('$f, $n, $obj', 'global $$f; $p = &$$f; unset($p[$n]); $p[$obj->term_id] = $obj->name;');
    if (count($tags) > 0) {
        array_map($modify, array_fill(0, count($tags), 'tags'), array_keys($tags), array_values($tags));
    }
    if (count($cats) > 0) {
        array_map($modify, array_fill(0, count($cats), 'cats'), array_keys($cats), array_values($cats));
    }
    switch ($options['tag']) {
        case 0:
            // pass
            break;
        case 1:
            $cat_string = implode(", ", $cats);
            break;
        case 2:
            $cat_string = implode(", ", $tags);
            break;
        case 3:
            $cat_string = implode(", ", array_unique(array_merge($cats, $tags)));
            break;
    }
    if ($options['custom_header'] == '') {
        $postHeader = '<p><small>';
        // If the post is not password protected, follow standard procedure
        if (!$post->post_password) {
            $postHeader .= __('Originally published at', 'lj-xp');
            $postHeader .= ' <a href="' . get_permalink($post->ID) . '">';
            $postHeader .= $blogName;
            $postHeader .= '</a>.';
        } else {
            $postHeader .= __('This post is password protected. You can read it at', 'lj-xp');
            $postHeader .= ' <a href="' . get_permalink($post->ID) . '">';
            $postHeader .= $blogName;
            $postHeader .= '</a>, ';
            $postHeader .= __('where it was originally posted', 'lj-xp');
            $postHeader .= '.';
        }
        // Depending on whether comments or allowed or not, alter the header appropriately
        if ($options['comments']) {
            $postHeader .= sprintf(__(' You can comment here or <a href="%s">there</a>.', 'lj-xp'), get_permalink($post->ID) . '#comments');
        } else {
            $postHeader .= sprintf(__(' Please leave any <a href="%s">comments</a> there.', 'lj-xp'), get_permalink($post->ID) . '#comments');
        }
        $postHeader .= '</small></p>';
    } else {
        $postHeader = $options['custom_header'];
        // find [author]
        $author = get_userdata($post->post_author);
        $author = $author->display_name;
        // pre-post formatting for tags and categories
        $htags = '';
        $hcats = '';
        foreach ($tags as $_term_id => $_name) {
            $htags[] = '<a href="' . get_tag_link($_term_id) . '" rel="bookmark">' . $_name . '</a>';
        }
        foreach ($cats as $_term_id => $_name) {
            $hcats[] = '<a href="' . get_category_link($_term_id) . '" rel="bookmark">' . $_name . '</a>';
        }
        $htags = implode(', ', (array) $htags);
        $hcats = implode(', ', (array) $hcats);
        $find = array('[blog_name]', '[blog_link]', '[permalink]', '[comments_link]', '[comments_count]', '[tags]', '[categories]', '[author]');
        $replace = array($blogName, get_option('home'), get_permalink($post->ID), get_permalink($post->ID) . '#comments', lj_comments($post->ID), $htags, $hcats, $author);
        $postHeader = str_replace($find, $replace, $postHeader);
        $postHeader = apply_filters('ljxp_post_header', $postHeader, $post->ID);
    }
    // $the_event will eventually be passed to the LJ XML-RPC server.
    $the_event = "";
    // and if the post isn't password protected, we need to put together the
    // actual post
    if (!$post->post_password) {
        if ($options['content'] == 'excerpt') {
            $excerpt = $post->post_excerpt;
            if (empty($excerpt)) {
                // cloned from wp_trim_excerpt()
                $excerpt = $post->post_content;
                $excerpt = strip_shortcodes($excerpt);
                $excerpt = apply_filters('the_content', $excerpt);
                $excerpt = str_replace(']]>', ']]&gt;', $excerpt);
                $excerpt = strip_tags($excerpt);
                $excerpt_length = apply_filters('excerpt_length', 55);
                $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
                $words = preg_split("/[\n\r\t ]+/", $excerpt, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
                if (count($words) > $excerpt_length) {
                    array_pop($words);
                    $excerpt = implode(' ', $words);
                    $excerpt = $excerpt . $excerpt_more;
                } else {
                    $excerpt = implode(' ', $words);
                }
            }
            $excerpt = apply_filters('the_excerpt', $excerpt);
            $the_event = apply_filters('ljxp_pre_process_excerpt', $excerpt);
        } else {
            // and if there's no <!--more--> tag, we can spit it out and go on our merry way
            // after we fix [gallery] IDs, which now happens in the ljxp_inline_gallery filter
            $the_content = $post->post_content;
            add_filter('post_gallery', 'ljxp_inline_gallery', 9, 2);
            $the_content = apply_filters('the_content', $the_content);
            $the_content = str_replace(']]>', ']]&gt;', $the_content);
            $the_content = ljxp_fix_relative_links($the_content);
            $the_content = apply_filters('ljxp_pre_process_post', $the_content);
            remove_filter('post_gallery', 'ljxp_inline_gallery', 9, 2);
            if (strpos($the_content, "<!--more") === false) {
                $the_event .= $the_content;
            } else {
                $content = explode("<!--more", $the_content, 2);
                $split_content = explode("-->", $content[1], 2);
                $content[1] = $split_content[1];
                $more_text = trim($split_content[0]);
                if (empty($more_text)) {
                    $more_text = $options['cut_text'];
                }
                $the_event .= $content[0];
                switch ($options['more']) {
                    case "copy":
                        $the_event .= $content[1];
                        break;
                    case "link":
                        $the_event .= sprintf('<p><a href="%s#more-%s">', get_permalink($post->ID), $post->ID) . $more_text . '</a></p>';
                        break;
                    case "lj-cut":
                        $the_event .= '<lj-cut text="' . $more_text . '">' . $content[1] . '</lj-cut>';
                        break;
                }
            }
        }
    }
    // Either prepend or append the header to $the_event, depending on the
    // config setting
    // Remember that 0 is at the top, 1 at the bottom
    if ($options['header_loc']) {
        $the_event .= $postHeader;
    } else {
        $the_event = $postHeader . $the_event;
    }
    // Get a timestamp for retrieving dates later
    $date = strtotime($post->post_date);
    $args = array('username' => $options['username'], 'auth_method' => 'challenge', 'auth_challenge' => $challenge, 'auth_response' => md5($challenge . $options['password']), 'ver' => '1', 'event' => $the_event, 'subject' => apply_filters('the_title', $post->post_title), 'year' => date('Y', $date), 'mon' => date('n', $date), 'day' => date('j', $date), 'hour' => date('G', $date), 'min' => date('i', $date), 'props' => array('opt_nocomments' => $options['comments'] == 1 ? 0 : 1, 'opt_preformatted' => true, 'opt_backdated' => $bulk, 'taglist' => $options['tag'] != 0 ? $cat_string : '', 'picture_keyword' => !empty($options['userpic']) ? $options['userpic'] : ''), 'usejournal' => !empty($options['community']) ? $options['community'] : $options['username']);
    // Set the privacy level according to the settings
    if (!isset($privacy) || empty($privacy)) {
        $privacy = $options['privacy'];
    }
    $allowmask = $options['allowmask_public'];
    if ($post->post_status == 'private') {
        $privacy = $options['privacy_private'];
        $allowmask = $options['allowmask_private'];
    }
    switch ($privacy) {
        case "public":
            $args['security'] = 'public';
            break;
        case "private":
            $args['security'] = 'private';
            break;
        case "friends":
            $args['security'] = 'usemask';
            $args['allowmask'] = 1 << 0;
            break;
        case "groups":
            $args['security'] = 'usemask';
            $bits = 0;
            if (isset($allowmask) && is_array($allowmask)) {
                foreach ($allowmask as $groupID) {
                    $bits += 1 << $groupID;
                }
            }
            $args['allowmask'] = $bits;
            break;
        default:
            $args['security'] = $privacy;
            break;
    }
    // Assume this is a new post
    $method = 'LJ.XMLRPC.postevent';
    // But check to see if there's an LJ post associated with our WP post
    if (get_post_meta($post->ID, 'ljID', true)) {
        // If there is, add the itemid attribute and change from posting to editing
        $args['itemid'] = get_post_meta($post->ID, 'ljID', true);
        $method = 'LJ.XMLRPC.editevent';
    }
    // And awaaaayyy we go!
    if (!$client->query($method, $args)) {
        $errors[$client->getErrorCode()] = $client->getErrorMessage();
    }
    $response = $client->getResponse();
    // If we were making a new post on LJ, we need the itemid for future reference
    if ('LJ.XMLRPC.postevent' == $method) {
        $ljID = add_post_meta($post->ID, 'ljID', $response['itemid'], true);
    }
    // grab the URL either way
    if (!empty($response['url'])) {
        $ljURL = add_post_meta($post->ID, 'ljURL', $response['url'], true);
    }
    // If there were errors, store them
    update_option('ljxp_error_notice', $errors);
    // If you don't return this, other plugins and hooks won't work
    return $post->ID;
}
function popup_content()
{
    ?>

	<script>
		function insert_code() {
			var id = jQuery("#add_id").val();
			var bnt_cat = jQuery("#add_cat").val();
			var t_length = jQuery("#add_ptl").val();
			var post_type = jQuery("#add_post_type").val();
			var title = jQuery("#add_title").val();
			var show_posts = jQuery("#add_posts").val();
			var bgcolor = jQuery("#add_tbg").val();
			var tbgcolor = jQuery("#add_bg").val();

			var bnt_speed = jQuery("#add_speed").val();
			var bnt_direction = jQuery("#add_dire").val();
			var bnt_interval = jQuery("#add_dura").val();
			var bnt_buttons = jQuery("#add_btn").val();


			var border_width = jQuery("#add_bw").val();
			var border_color = jQuery("#add_bc").val();
			var border_style = jQuery("#add_bs").val();
			var border_radius = jQuery("#add_br").val();
			var date_color = jQuery("#add_dc").val();
			var controls_btn_bg = jQuery("#add_cbb").val();
			var show_date = jQuery("#add_shd").val();
	 
			window.send_to_editor('[breaking_news_ticker id="' + id + '" t_length="' + t_length + '" bnt_cat="' + bnt_cat + '" post_type="' + post_type + '" title="' + title + '"  show_posts="' + show_posts + '" tbgcolor="'+ tbgcolor +'" bgcolor="'+ bgcolor +'" bnt_speed="' + bnt_speed + '" bnt_direction="' + bnt_direction + '" bnt_interval="' + bnt_interval + '" border_width="' + border_width + '" border_color="' + border_color + '" border_style="' + border_style + '" border_radius="' + border_radius + '" show_date="' + show_date + '" date_color="' + date_color + '" controls_btn_bg="' + controls_btn_bg + '" bnt_buttons="' + bnt_buttons + '"]');
		}

	</script>

	<div id="bnt_popup_container" style="display:none;">
		<div class="popup-inner">
		<h2> Shortcode Generator</h2>
	      	<div class="popup-form">
		      	<div class="form-left">
		        	
		        	<div class="input">
			        	<label for="add_id">Shortcode Id</label>
			        	<input type="text" onkeypress='return event.charCode >= 48 && event.charCode <= 57' id="add_id" value="1"><br/>
			        	<span>Use a unique Id. Ex: 1, 99, 999</span>
			        </div>

			        <div class="input">
			        	<label for="add_ptl">Post Title length</label>
			        	<input type="text" onkeypress='return event.charCode >= 48 && event.charCode <= 57' id="add_ptl" value="35"><br/>
			        	<span>Ex: 35, 40</span>
			        </div>

			        <div class="input">
			        	<label for="add_cat">Post Category</label>
			        	<select id="add_cat" multiple>
  						<option value="" selected="selected">All Category</option>
							<?php 
    $category_ids = get_all_category_ids();
    foreach ($category_ids as $cat_id) {
        $cat_name = get_cat_name($cat_id);
        ?>
  						
  						<option value="<?php 
        echo $cat_id;
        ?>
"><?php 
        echo $cat_name;
        ?>
</option>

						<?php 
    }
    ?>
			        	</select>
			        	<span>Ex: up, down</span>
			        </div>

			        <div class="input">
			        	<label for="add_post_type">Post Type</label>
			        	<select id="add_post_type">
							<?php 
    $args = array('public' => true);
    $output = 'names';
    // names or objects, note names is the default
    $operator = 'and';
    // 'and' or 'or'
    $bnt_post_types = get_post_types($args, $output, $operator);
    foreach ($bnt_post_types as $bnt_post_type) {
        ?>
  						
  						<option value="<?php 
        echo $bnt_post_type;
        ?>
"><?php 
        echo $bnt_post_type;
        ?>
</option>

						<?php 
    }
    ?>
			        	</select>
			        	<span>Ex: up, down</span>
			        </div>

			        <div class="input">
			        	<label for="add_posts">Display Posts</label>
			        	<input type="text" onkeypress='return event.charCode >= 48 && event.charCode <= 57' id="add_posts" value="5"><br/>
			        	<span>Enter the maximum number of posts. Default: 5</span>
			        </div>
			        
			        <div class="input">
			        	<label for="add_shd">Date Show/Hide</label>
			        	<select id="add_shd" name="add_shd">
			        		<option value="show">Show</option>
			        		<option value="hide">Hide</option>
			        	</select>
			        	<span>Ex: show, hide</span>
			        </div>

		        </div>

		        <div class="form-center">
		        	<div class="input">
			        	<label for="add_title">Ticker Title</label>
			        	<input id="add_title" value="Breaking News"><br/>
			        	<span>Ex: Breaking News, Latest Posts</span>
			        </div>

		        	<div class="input">
			        	<label for="add_tbg">Title Background Color</label>
			        	<input id="add_tbg" value="333333"><br/>
			        	<span>Ex: FFFFFF, DDDDDD [more details: <a href="http://www.colorpicker.com/" target="_blank">click here</a>]</span>
			        </div>

			        <div class="input">
			        	<label for="add_bg">Ticker Background Color</label>
			        	<input id="add_bg" value="222222"><br/>
			        	<span>Ex: 222222, 333333 [more details: <a href="http://www.colorpicker.com/" target="_blank">click here</a>]</span>
			        </div>

		        	<div class="input">
			        	<label for="add_bw">Border Width</label>
			        	<input type="text" onkeypress='return event.charCode >= 48 && event.charCode <= 57' id="add_bw" value="0"><br/>
			        	<span>Ex: 5, 10</span>
			        </div>
			        <div class="input">
			        	<label for="add_bc">Border Color</label>
			        	<input id="add_bc" value="222222"><br/>
			        	<span>Ex: 222222, 333333 [more details: <a href="http://www.colorpicker.com/" target="_blank">click here</a>]</span>
			        </div>

			        <div class="input">
			        	<label for="add_dc">Date Color</label>
			        	<input id="add_dc" value="b23737"><br/>
			        	<span>Ex: 222222, 333333 [more details: <a href="http://www.colorpicker.com/" target="_blank">click here</a>]</span>
			        </div>

			        <div class="input">
			        	<label for="add_cbb">Controls Button Background</label>
			        	<input id="add_cbb" value="dd3333"><br/>
			        	<span>Ex: 222222, 333333 [more details: <a href="http://www.colorpicker.com/" target="_blank">click here</a>]</span>
			        </div>

		        </div>

		        <div class="form-right">
		        	<div class="input">
			        	<label for="add_speed">Ticker Speed</label>
			        	<input type="text" onkeypress='return event.charCode >= 48 && event.charCode <= 57' id="add_speed" value="500"><br/>
			        	<span>Ex: 400, 500, 600</span>
			        </div>

			        <div class="input">
			        	<label for="add_dire">Ticker Direction</label>
			        	<select id="add_dire" name="add_dire">
			        		<option value="up">Up</option>
			        		<option value="down">Down</option>
			        	</select>
			        	<span>Ex: up, down</span>
			        </div>

			        <div class="input">
			        	<label for="add_dura">Ticker Duration</label>
			        	<input type="text" onkeypress='return event.charCode >= 48 && event.charCode <= 57' id="add_dura" value="3000"><br/>
			        	<span>Ex: 2000, 3000</span>
			        </div>

			        <div class="input">
			        	<label for="add_btn">Ticker Buttons</label>
			        	<select id="add_btn" name="add_btn">
			        		<option value="on">ON</option>
			        		<option value="off">OFF</option>
			        	</select>
			        	<span>Ex: on, off</span>
			        </div>

			         <div class="input">
			        	<label for="add_bs">Border Style</label>
			        	<select id="add_bs" name="add_bs">
			        		<option value='solid'>Solid</option>
			        		<option value="dotted">Dotted</option>
			        		<option value="dashed">Dashed</option>
			        		<option value="double">Double</option>
			        	</select>
			        	<span>Ex: solid, dotted</span>
			        </div>

			        <div class="input">
			        	<label for="add_br">Border Radius</label>
			        	<input type="text" onkeypress='return event.charCode >= 48 && event.charCode <= 57' id="add_br" value="0"><br/>
			        	<span>Ex: 5, 10</span>
			        </div>

		        </div>

	        </div>

	        <div>
	        	<input type="button" class="button-primary input-btn" value="Generate ShortCode" onclick="insert_code();">
	            <a class="button" style="color:#bbb;" href="#" onclick="tb_remove(); return false;">Cancel</a>
	         </div>
         </div>

	</div> <!-- end pupup container -->

	<?php 
}