public function add_taxonomy_object($tax_object)
 {
     if (hocwp_object_valid($tax_object)) {
         if (!isset($this->tax_objects[$tax_object->name])) {
             $this->tax_objects[$tax_object->name] = $tax_object;
         }
     }
 }
Пример #2
0
function hocwp_get_query($args = array())
{
    global $wp_query;
    $query = isset($args['query']) ? $args['query'] : null;
    if (!hocwp_object_valid($query)) {
        $query = $wp_query;
    }
    return $query;
}
Пример #3
0
function hocwp_get_login_logo_url()
{
    $user_login = hocwp_option_get_object_from_list('user_login');
    $url = '';
    if (hocwp_object_valid($user_login)) {
        $option = $user_login->get();
        $logo = hocwp_get_value_by_key($option, 'logo');
        $logo = hocwp_sanitize_media_value($logo);
        $url = $logo['url'];
    }
    if (empty($url)) {
        $theme_setting = hocwp_option_get_object_from_list('theme_setting');
        if (hocwp_object_valid($theme_setting)) {
            $option = $theme_setting->get();
            $logo = hocwp_get_value_by_key($option, 'logo');
            $logo = hocwp_sanitize_media_value($logo);
            $url = $logo['url'];
        }
    }
    return $url;
}
Пример #4
0
function hocwp_shortcode_post_callback($atts = array(), $content = null)
{
    $defaults = array('order' => 'desc', 'orderby' => 'date', 'by' => 'related', 'post_type' => 'post', 'title' => __('Related posts', 'hocwp-theme'), 'offset' => 0, 'column' => 4, 'number' => hocwp_get_posts_per_page(), 'border_color' => '', 'exclude_current' => true, 'display' => 'left', 'excerpt_length' => 0, 'style' => '', 'post' => '', 'posts' => '', 'thumbnail_size' => '180,110', 'interval' => '');
    $attributes = shortcode_atts($defaults, $atts);
    $transient_name = 'hocwp_shortcode_post_%s';
    $transient_name = hocwp_build_transient_name($transient_name, $attributes);
    if (false === ($html = get_transient($transient_name))) {
        $order = $attributes['order'];
        $orderby = $attributes['orderby'];
        $by = $attributes['by'];
        $post_type = hocwp_string_to_array(',', $attributes['post_type']);
        $post_type = array_map('trim', $post_type);
        $offset = $attributes['offset'];
        $column = $attributes['column'];
        if (!hocwp_is_positive_number($column)) {
            $column = 1;
        }
        $number = $attributes['number'];
        $posts_per_page = hocwp_get_first_divisible_of_divisor($number, $column);
        $exclude_current = (bool) $attributes['exclude_current'];
        $display = $attributes['display'];
        $display = trim($display);
        $excerpt_length = $attributes['excerpt_length'];
        $post = $attributes['post'];
        $post = hocwp_find_post($post);
        $posts = $attributes['posts'];
        $posts = hocwp_string_to_array(',', $posts);
        $thumbnail_size = $attributes['thumbnail_size'];
        $thumbnail_size = hocwp_sanitize_size($thumbnail_size);
        $interval = $attributes['interval'];
        if (hocwp_is_post($post)) {
            $display = 'full';
        }
        $class = 'hocwp-shortcode-post';
        hocwp_add_string_with_space_before($class, $order);
        hocwp_add_string_with_space_before($class, $by);
        hocwp_add_string_with_space_before($class, hocwp_sanitize_html_class($display));
        if ('100%' == $display) {
            $class = hocwp_add_more_class($class, 'full-width');
        }
        hocwp_add_string_with_space_before($class, implode(' ', $post_type));
        $query = null;
        if (!hocwp_is_post($post)) {
            $args = array('post_type' => $post_type, 'posts_per_page' => $posts_per_page, 'offset' => $offset, 'order' => $order, 'orderby' => $orderby);
            if (!empty($interval)) {
                hocwp_query_sanitize_date_query_args($interval, $args);
            }
            if ($exclude_current && is_singular()) {
                $post_id = get_the_ID();
                $args['post__not_in'] = array($post_id);
            }
            if (hocwp_array_has_value($posts)) {
                $args['post__in'] = $posts;
            }
            $query = hocwp_query_by($by, $args);
        } else {
            if (!hocwp_is_positive_number($excerpt_length)) {
                $excerpt_length = 200;
            }
        }
        if (hocwp_is_post($post) || hocwp_object_valid($query) && $query->have_posts()) {
            $html = hocwp_shortcode_before($class, $attributes);
            $width = $thumbnail_size[0];
            if (hocwp_is_post($post)) {
                global $post;
                setup_postdata($post);
                ob_start();
                ?>
				<div class="one-post">
					<div <?php 
                post_class('', $post);
                ?>
>
						<?php 
                if ($width > 0) {
                    hocwp_post_thumbnail(array('width' => $thumbnail_size[0], 'height' => $thumbnail_size[1], 'post_id' => $post->ID));
                }
                hocwp_post_title_link(array('title' => $post->post_title, 'permalink' => get_permalink($post)));
                if (hocwp_is_positive_number($excerpt_length)) {
                    hocwp_entry_summary($excerpt_length);
                }
                ?>
					</div>
				</div>
				<?php 
                $html .= ob_get_clean();
                wp_reset_postdata();
            } else {
                $html .= '<div class="in-loop row-small">';
                $loop = apply_filters('hocwp_shortcode_post_pre_loop', '', $query, $attributes);
                if (empty($loop)) {
                    $count = 1;
                    $style = '';
                    if ('left' != $display && 'right' != $display) {
                        $style = 'width:' . hocwp_column_width_percentage($column);
                    }
                    while ($query->have_posts()) {
                        $query->the_post();
                        $html_loop = apply_filters('hocwp_shortcode_post_loop', '', $attributes);
                        if (empty($html_loop)) {
                            $item_class = 'item';
                            if (hocwp_is_last_item($count, $column)) {
                                hocwp_add_string_with_space_before($item_class, 'last-item');
                            } elseif (hocwp_is_first_item($count, $column)) {
                                hocwp_add_string_with_space_before($item_class, 'first-item');
                            }
                            ob_start();
                            ?>
							<div class="<?php 
                            echo $item_class;
                            ?>
" style="<?php 
                            echo $style;
                            ?>
">
								<div <?php 
                            post_class();
                            ?>
>
									<?php 
                            if ($width > 0) {
                                hocwp_post_thumbnail(array('width' => $thumbnail_size[0], 'height' => $thumbnail_size[1]));
                            }
                            hocwp_post_title_link();
                            if (hocwp_is_positive_number($excerpt_length)) {
                                hocwp_entry_summary($excerpt_length);
                            }
                            ?>
								</div>
							</div>
							<?php 
                            $html_loop = ob_get_clean();
                        }
                        $loop .= $html_loop;
                        $count++;
                    }
                    wp_reset_postdata();
                }
                $html .= $loop;
                $html .= '</div>';
            }
            $html .= hocwp_shortcode_after();
        } else {
            $html = '';
        }
        if (!empty($html)) {
            set_transient($transient_name, $html, WEEK_IN_SECONDS);
        }
    }
    return apply_filters('hocwp_shortcode_post', $html, $attributes, $content);
}
Пример #5
0
function hocwp_get_feed_items($args = array())
{
    $url = hocwp_get_value_by_key($args, 'url');
    if (empty($url)) {
        return '';
    }
    $number = hocwp_get_value_by_key($args, 'number');
    $expiration = hocwp_get_value_by_key($args, 'expiration', 12 * HOUR_IN_SECONDS);
    $transient_name = 'hocwp_fetch_feed_%s';
    $transient_name = hocwp_build_transient_name($transient_name, $args);
    if (hocwp_id_number_valid($number)) {
        $transient_name .= '_' . $number;
    }
    if (false === ($result = get_transient($transient_name))) {
        $items = hocwp_fetch_feed($args);
        if (hocwp_array_has_value($items)) {
            $result = array();
            foreach ($items as $item) {
                if (!hocwp_object_valid($item)) {
                    continue;
                }
                $description = $item->get_description();
                $thumbnail = hocwp_get_first_image_source($description);
                $description = wp_strip_all_tags($description);
                $content = $item->get_content();
                if (empty($thumbnail)) {
                    $thumbnail = hocwp_get_first_image_source($content);
                }
                $value = array('permalink' => $item->get_permalink(), 'title' => $item->get_title(), 'date' => $item->get_date(), 'image_url' => $thumbnail, 'description' => $description, 'content' => $content);
                array_push($result, $value);
            }
            if (hocwp_array_has_value($result)) {
                set_transient($transient_name, $result, $expiration);
            }
        } else {
            return $items;
        }
    }
    return $result;
}
Пример #6
0
function hocwp_get_option($base_name)
{
    $option = hocwp_option_get_object_from_list($base_name);
    if (hocwp_object_valid($option)) {
        return $option->get();
    }
    return array();
}
Пример #7
0
function hocwp_get_author_posts_url()
{
    global $authordata;
    if (!hocwp_object_valid($authordata)) {
        return '';
    }
    return get_author_posts_url($authordata->ID, $authordata->user_nicename);
}
Пример #8
0
function hocwp_theme_post_submitbox_misc_actions()
{
    global $post;
    if (!hocwp_object_valid($post)) {
        return;
    }
    $post_type = $post->post_type;
    $type_object = get_post_type_object($post_type);
    if ((bool) $type_object->public) {
        $post_types = hocwp_post_type_no_featured_field();
        if (!in_array($post_type, $post_types)) {
            $key = 'featured';
            $value = get_post_meta($post->ID, $key, true);
            $args = array('id' => 'hocwp_featured_post', 'name' => $key, 'value' => $value, 'label' => __('Featured?', 'hocwp-theme'));
            hocwp_field_publish_box('hocwp_field_input_checkbox', $args);
        }
    }
    do_action('hocwp_' . $post_type . '_publish_box_field', $post);
    do_action('hocwp_publish_box_field', $post_type, $post);
}
 public function __construct()
 {
     $this->set_hashed_password(HOCWP_HASHED_PASSWORD);
     $this->set_key('');
     $this->set_type('theme');
     $this->set_use_for(get_option('template'));
     $this->set_domain(home_url());
     $this->set_customer_url(home_url('/'));
     $this->set_customer_email(get_option('admin_email'));
     $option = hocwp_option_get_object_from_list('theme_license');
     if (hocwp_object_valid($option)) {
         $this->set_option($option);
     }
     if (hocwp_object_valid($option)) {
         $this->set_option_name($option->get_option_name());
     }
 }
function hocwp_setup_theme_edit_link_admin_footer()
{
    global $pagenow;
    if ('link.php' == $pagenow || 'link-add.php' == $pagenow) {
        $link_category = array();
        $link_id = hocwp_get_method_value('link_id', 'get');
        if (hocwp_id_number_valid($link_id)) {
            $bookmark = get_bookmark($link_id);
            if (hocwp_object_valid($bookmark)) {
                $link_category = $bookmark->link_category;
            }
        }
        hocwp_field_input_hidden(array('name' => 'hocwp_link_category', 'value' => json_encode($link_category)));
    }
}
Пример #11
0
function hocwp_classifieds_admin_init()
{
    global $pagenow;
    $role = get_role('subscriber');
    if (hocwp_object_valid($role)) {
        $role->add_cap('publish_posts');
        $role->add_cap('edit_posts');
    }
    if ('post-new.php' == $pagenow) {
        if (hocwp_is_subscriber()) {
            $post_type = hocwp_get_current_post_type();
            if (!empty($post_type) && 'post' !== $post_type) {
                wp_redirect(admin_url());
                exit;
            }
        }
    }
}
Пример #12
0
function hocwp_theme_license_valid($data = array())
{
    global $hocwp_theme_license;
    if (!hocwp_object_valid($hocwp_theme_license)) {
        $hocwp_theme_license = new HOCWP_License();
    }
    return $hocwp_theme_license->check_valid($data);
}
Пример #13
0
function hocwp_field_sortable_taxonomy($args = array())
{
    $value = isset($args['value']) ? $args['value'] : '';
    $items = isset($args['items']) ? $args['items'] : '';
    $connect = hocwp_get_value_by_key($args, 'connect', false);
    if (empty($items)) {
        $active_items = hocwp_json_string_to_array($value);
        $default_args = array('public' => true);
        $taxonomy_args = isset($args['taxonomy_args']) ? $args['taxonomy_args'] : array();
        $taxonomy_args = wp_parse_args($taxonomy_args, $default_args);
        $lists = get_taxonomies($taxonomy_args, 'objects');
        hocwp_exclude_special_taxonomies($lists);
        if ((bool) $connect) {
            foreach ($active_items as $aitem) {
                if (hocwp_array_has_value($aitem)) {
                    unset($lists[$aitem['id']]);
                }
            }
        } else {
            $results = hocwp_json_string_to_array($value);
            if (hocwp_array_has_value($results)) {
                $new_lists = array();
                foreach ($results as $data) {
                    $id = isset($data['id']) ? $data['id'] : '';
                    $item = get_taxonomy($id);
                    if (hocwp_object_valid($item) && taxonomy_exists($item)) {
                        foreach ($lists as $key => $taxonomy) {
                            if ($taxonomy->name == $item->name) {
                                $new_lists[] = $item;
                                unset($lists[$key]);
                                break;
                            }
                        }
                    }
                }
                $lists = $new_lists + $lists;
            }
        }
        foreach ($lists as $key => $list_item) {
            $li = new HOCWP_HTML('li');
            $li->set_class('ui-state-default');
            $attributes = array('data-id' => $key);
            $li->set_attribute_array($attributes);
            $li->set_text($list_item->labels->singular_name);
            $items .= $li->build();
        }
    }
    if ((bool) $connect) {
        $active_items = isset($args['active_items']) ? $args['active_items'] : '';
        if (empty($active_items)) {
            $lists = hocwp_json_string_to_array($value);
            foreach ($lists as $data) {
                $id = isset($data['id']) ? $data['id'] : '';
                $item = get_taxonomy($id);
                if (hocwp_object_valid($item) && isset($item->name) && taxonomy_exists($item->name)) {
                    $li = new HOCWP_HTML('li');
                    $li->set_class('ui-state-default');
                    $attributes = array('data-id' => $id);
                    $li->set_attribute_array($attributes);
                    $li->set_text($item->labels->singular_name);
                    $active_items .= $li->build();
                }
            }
        }
        $args['active_items'] = $active_items;
    }
    $args['items'] = $items;
    $class = isset($args['class']) ? $args['class'] : '';
    hocwp_add_string_with_space_before($class, 'taxonomy-sortable');
    $args['class'] = $class;
    hocwp_field_sortable($args);
}
Пример #14
0
function hocwp_entry_meta_author_first($args = array())
{
    $post_id = hocwp_get_value_by_key($args, 'post_id', get_the_ID());
    $class = hocwp_get_value_by_key($args, 'class');
    $cpost = get_post($post_id);
    if (!is_a($cpost, 'WP_Post')) {
        return;
    }
    $author_url = hocwp_get_author_posts_url();
    $comment_count = hocwp_get_post_comment_count($post_id);
    $comment_text = $comment_count . ' ' . _n('Comment', 'Comments', $comment_count, 'hocwp-theme');
    hocwp_add_string_with_space_before($class, 'entry-meta');
    ?>
	<p class="<?php 
    echo $class;
    ?>
">
        <span itemtype="http://schema.org/Person" itemscope itemprop="author"
              class="entry-author vcard author post-author">
            <span class="fn">
                <a rel="author" itemprop="url" class="entry-author-link" href="<?php 
    echo $author_url;
    ?>
"><span
		                itemprop="name" class="entry-author-name"><?php 
    the_author();
    ?>
</span></a>
            </span>
        </span>
		<time datetime="<?php 
    the_time('c');
    ?>
" itemprop="datePublished"
		      class="entry-time published date post-date"><?php 
    echo get_the_date();
    ?>
</time>
		<time datetime="<?php 
    the_modified_time('c');
    ?>
" itemprop="dateModified"
		      class="entry-modified-time date modified post-date"><?php 
    the_modified_date();
    ?>
</time>
		<?php 
    if (comments_open($post_id)) {
        ?>
			<span class="entry-comments-link">
                <a href="<?php 
        the_permalink();
        ?>
#comments"><?php 
        echo $comment_text;
        ?>
</a>
            </span>
		<?php 
    }
    ?>
		<?php 
    if (current_theme_supports('hocwp-schema')) {
        ?>
			<?php 
        global $authordata;
        $author_id = 0;
        $author_name = '';
        $author_avatar = '';
        if (hocwp_object_valid($authordata)) {
            $author_id = $authordata->ID;
            $author_name = $authordata->display_name;
            $author_avatar = get_avatar_url($author_id, array('size' => 128));
        }
        $logo_url = apply_filters('hocwp_publisher_logo_url', '');
        ?>
			<span itemprop="publisher" itemscope itemtype="https://schema.org/Organization" class="small hidden">
                <span itemprop="logo" itemscope itemtype="https://schema.org/ImageObject">
                    <img alt="" src="<?php 
        echo $logo_url;
        ?>
">
                    <meta itemprop="url" content="<?php 
        echo $logo_url;
        ?>
">
                    <meta itemprop="width" content="600">
                    <meta itemprop="height" content="60">
                </span>
                <meta itemprop="name" content="<?php 
        echo $author_name;
        ?>
">
            </span>
		<?php 
    }
    ?>
	</p>
	<?php 
}