public function get_all_images($num = 0, $size_name = 'thumbnail', $post_id, $check_dupes = true, $meta_pre = 'og') { if ($this->p->debug->enabled) { $this->p->debug->args(array('num' => $num, 'size_name' => $size_name, 'post_id' => $post_id, 'check_dupes' => $check_dupes, 'meta_pre' => $meta_pre)); } $og_ret = array(); $force_regen = false; // check for an attachment page // is_attachment() only works on the front-end, so check the post_type as well if (!empty($post_id)) { if ((is_attachment($post_id) || get_post_type($post_id) === 'attachment') && wp_attachment_is_image($post_id)) { $og_image = array(); $num_remains = $this->p->media->num_remains($og_ret, $num); $og_image = $this->p->media->get_attachment_image($num_remains, $size_name, $post_id, $check_dupes); // if an attachment is not an image, then use the default image instead if (empty($og_image)) { $num_remains = $this->p->media->num_remains($og_ret, $num); $og_ret = array_merge($og_ret, $this->p->media->get_default_image($num_remains, $size_name)); } else { $og_ret = array_merge($og_ret, $og_image); } return $og_ret; } } if ($this->p->util->force_default_image()) { $num_remains = $this->p->media->num_remains($og_ret, $num); $og_ret = array_merge($og_ret, $this->p->media->get_default_image($num_remains, $size_name)); return $og_ret; // stop here and return the image array } $num_remains = $this->p->media->num_remains($og_ret, $num); if (SucomUtil::is_term_page()) { $term_id = $this->p->util->get_term_object('id'); $og_ret = array_merge($og_ret, $this->p->mods['util']['taxonomy']->get_og_image($num_remains, $size_name, $term_id, $check_dupes, $force_regen, $meta_pre)); if (!$this->p->util->is_maxed($og_ret, $num)) { $num_remains = $this->p->media->num_remains($og_ret, $num); $og_ret = array_merge($og_ret, $this->p->mods['util']['taxonomy']->get_term_images($num_remains, $size_name, $term_id, $check_dupes, $force_regen, $meta_pre)); } } elseif (SucomUtil::is_author_page()) { $author_id = $this->p->util->get_author_object('id'); $og_ret = array_merge($og_ret, $this->p->mods['util']['user']->get_og_image($num_remains, $size_name, $author_id, $check_dupes, $force_regen, $meta_pre)); } else { // check for custom meta, featured, or attached image(s) // allow for empty post_id in order to execute featured/attached image filters for modules $og_ret = array_merge($og_ret, $this->p->media->get_post_images($num_remains, $size_name, $post_id, $check_dupes, $meta_pre)); // check for ngg shortcodes and query vars if ($this->p->is_avail['media']['ngg'] === true && !empty($this->p->mods['media']['ngg']) && !$this->p->util->is_maxed($og_ret, $num)) { if ($this->p->debug->enabled) { $this->p->debug->log('checking for ngg shortcodes and query vars'); } // ngg pre-v2 used query arguments $ngg_query_og_ret = array(); $num_remains = $this->p->media->num_remains($og_ret, $num); if (version_compare($this->p->mods['media']['ngg']->ngg_version, '2.0.0', '<')) { $ngg_query_og_ret = $this->p->mods['media']['ngg']->get_query_images($num_remains, $size_name, $check_dupes); } // if we found images in the query, skip content shortcodes if (count($ngg_query_og_ret) > 0) { if ($this->p->debug->enabled) { $this->p->debug->log(count($ngg_query_og_ret) . ' image(s) returned - skipping additional shortcode images'); } $og_ret = array_merge($og_ret, $ngg_query_og_ret); // if no query images were found, continue with ngg shortcodes in content } elseif (!$this->p->util->is_maxed($og_ret, $num)) { $num_remains = $this->p->media->num_remains($og_ret, $num); $og_ret = array_merge($og_ret, $this->p->mods['media']['ngg']->get_shortcode_images($num_remains, $size_name, $check_dupes)); } } // end of check for ngg shortcodes and query vars // if we haven't reached the limit of images yet, keep going and check the content text if (!$this->p->util->is_maxed($og_ret, $num)) { $num_remains = $this->p->media->num_remains($og_ret, $num); $og_ret = array_merge($og_ret, $this->p->media->get_content_images($num_remains, $size_name, $post_id, $check_dupes)); } } $this->p->util->slice_max($og_ret, $num); return $og_ret; }
public function get_description($textlen = 156, $trailing = '...', $use_post = false, $use_cache = true, $add_hashtags = true, $encode = true, $md_idx = 'og_desc', $src_id = '') { if ($this->p->debug->enabled) { $this->p->debug->mark('render description'); // start timer $this->p->debug->args(array('textlen' => $textlen, 'trailing' => $trailing, 'use_post' => $use_post, 'use_cache' => $use_cache, 'add_hashtags' => $add_hashtags, 'encode' => $encode, 'md_idx' => $md_idx, 'src_id' => $src_id)); } $desc = false; $hashtags = ''; $post_id = 0; $page = ''; if (is_singular() || $use_post !== false) { if (($obj = $this->p->util->get_post_object($use_post)) === false) { if ($this->p->debug->enabled) { $this->p->debug->log('exiting early: invalid object type'); } return $desc; } $post_id = empty($obj->ID) || empty($obj->post_type) ? 0 : $obj->ID; } // skip if no metadata index / key name if (!empty($md_idx)) { if (is_singular() || $use_post !== false) { if (!empty($post_id)) { $desc = $this->p->util->get_mod_options('post', $post_id, array($md_idx, 'og_desc')); } } elseif (SucomUtil::is_term_page()) { $term = $this->p->util->get_term_object(); if (!empty($term->term_id)) { $desc = $this->p->util->get_mod_options('taxonomy', $term->term_id, $md_idx); } } elseif (SucomUtil::is_author_page()) { $author = $this->p->util->get_author_object(); if (!empty($author->ID)) { $desc = $this->p->util->get_mod_options('user', $author->ID, $md_idx); } } if ($this->p->debug->enabled) { if (empty($desc)) { $this->p->debug->log('no custom description found'); } else { $this->p->debug->log('custom description = "' . $desc . '"'); } } } // get seed if no custom meta description if (empty($desc)) { $desc = apply_filters($this->p->cf['lca'] . '_description_seed', '', $use_post, $add_hashtags, $md_idx, $src_id); if (!empty($desc)) { if ($this->p->debug->enabled) { $this->p->debug->log('description seed = "' . $desc . '"'); } } } // remove and save trailing hashtags if (preg_match('/^(.*)(( *#[a-z][a-z0-9\\-]+)+)$/U', $desc, $match)) { $desc = $match[1]; $hashtags = trim($match[2]); } elseif (is_singular() || $use_post !== false) { if (!empty($add_hashtags) && !empty($this->p->options['og_desc_hashtags'])) { $hashtags = $this->get_hashtags($post_id, $add_hashtags); } } if ($this->p->debug->enabled) { $this->p->debug->log('hashtags found = "' . $hashtags . '"'); } // if there's no custom description, and no pre-seed, // then go ahead and generate the description value if (empty($desc)) { // $obj and $post_id are defined above, with the same test, so we should be good if (is_singular() || $use_post !== false) { // use the excerpt, if we have one if (has_excerpt($post_id)) { $desc = $obj->post_excerpt; if (!empty($this->p->options['plugin_filter_excerpt'])) { $filter_removed = apply_filters($this->p->cf['lca'] . '_pre_filter_remove', false, 'get_the_excerpt'); if ($this->p->debug->enabled) { $this->p->debug->log('calling apply_filters(\'get_the_excerpt\')'); } $desc = apply_filters('get_the_excerpt', $desc); if ($filter_removed) { $filter_added = apply_filters($this->p->cf['lca'] . '_post_filter_add', false, 'get_the_excerpt'); } } } elseif ($this->p->debug->enabled) { $this->p->debug->log('no post_excerpt for post_id ' . $post_id); } // if there's no excerpt, then fallback to the content if (empty($desc)) { $desc = $this->get_content($post_id, $use_post, $use_cache, $md_idx, $src_id); } // ignore everything before the first paragraph if true if ($this->p->options['plugin_p_strip']) { if ($this->p->debug->enabled) { $this->p->debug->log('removing all text before the first paragraph'); } $desc = preg_replace('/^.*?<p>/i', '', $desc); // question mark makes regex un-greedy } } elseif (SucomUtil::is_term_page()) { if (is_tag()) { $desc = tag_description(); if (empty($desc)) { $desc = sprintf('Tagged with %s', single_tag_title('', false)); } } elseif (is_category()) { $desc = category_description(); if (empty($desc)) { $desc = sprintf('%s Category', single_cat_title('', false)); } } else { // other taxonomies $term = $this->p->util->get_term_object(); if (!empty($term->description)) { $desc = $term->description; } elseif (!empty($term->name)) { $desc = $term->name . ' Archives'; } } } elseif (SucomUtil::is_author_page()) { $author = $this->p->util->get_author_object(); if (!empty($author->description)) { $desc = $author->description; } elseif (!empty($author->display_name)) { $desc = sprintf('Authored by %s', $author->display_name); } } elseif (is_day()) { $desc = sprintf('Daily Archives for %s', get_the_date()); } elseif (is_month()) { $desc = sprintf('Monthly Archives for %s', get_the_date('F Y')); } elseif (is_year()) { $desc = sprintf('Yearly Archives for %s', get_the_date('Y')); } } // if there's still no description, then fallback to a generic version if (empty($desc)) { if (is_admin() && !empty($obj->post_status) && $obj->post_status == 'auto-draft') { if ($this->p->debug->enabled) { $this->p->debug->log('post_status is auto-draft - using empty description'); } } else { // pass options array to allow fallback if locale option does not exist $key = SucomUtil::get_locale_key('og_site_description', $this->p->options, $post_id); if (!empty($this->p->options[$key])) { if ($this->p->debug->enabled) { $this->p->debug->log('description is empty - custom site description (' . $key . ')'); } $desc = $this->p->options[$key]; } else { if ($this->p->debug->enabled) { $this->p->debug->log('description is empty - using blog description'); } $desc = get_bloginfo('description', 'display'); } } } if ($this->p->debug->enabled) { $this->p->debug->log('description strlen before html cleanup ' . strlen($desc)); } $desc = $this->p->util->cleanup_html_tags($desc, true, $this->p->options['plugin_use_img_alt']); $desc = apply_filters($this->p->cf['lca'] . '_description_pre_limit', $desc); if ($textlen > 0) { if (!empty($add_hashtags) && !empty($hashtags)) { $textlen = $textlen - strlen($hashtags) - 1; } if ($this->p->debug->enabled) { $this->p->debug->log('description strlen before limit length ' . strlen($desc) . ' (limiting to ' . $textlen . ' chars)'); } $desc = $this->p->util->limit_text_length($desc, $textlen, $trailing, false); // don't run cleanup_html_tags() } elseif ($this->p->debug->enabled) { $this->p->debug->log('description limit text length skipped'); } if (!empty($add_hashtags) && !empty($hashtags)) { $desc .= ' ' . $hashtags; } if ($encode === true) { $desc = wp_encode_emoji(htmlentities($desc, ENT_QUOTES, get_bloginfo('charset'), false)); } // double_encode = false if ($this->p->debug->enabled) { $this->p->debug->mark('render description'); } // stop timer return apply_filters($this->p->cf['lca'] . '_description', $desc, $use_post, $add_hashtags, $md_idx, $src_id); }
public function add_plugin_image_sizes($id = false, $sizes = array(), $filter = true, $mod = false) { /* * Allow various plugin extensions to provide their image names, labels, etc. * The first dimension array key is the option name prefix by default. * You can also include the width, height, crop, crop_x, and crop_y values. * * Array ( * [rp_img] => Array ( * [name] => richpin * [label] => Rich Pin Image Dimensions * ) * [og_img] => Array ( * [name] => opengraph * [label] => Open Graph Image Dimensions * ) * ) */ if ($filter === true) { $sizes = apply_filters($this->p->cf['lca'] . '_plugin_image_sizes', $sizes, $id, $mod); } $meta_opts = array(); if ($mod === false) { if (SucomUtil::is_post_page(false)) { $mod = 'post'; } elseif (SucomUtil::is_term_page()) { $mod = 'taxonomy'; } elseif (SucomUtil::is_author_page()) { $mod = 'user'; } elseif ($this->p->debug->enabled) { $this->p->debug->log('module type could not be determined'); } } if (is_object($id)) { $obj = $id; // could be WP_Object or post/term/user object $id = false; if ($mod === 'post') { $id = empty($obj->ID) || empty($obj->post_type) ? $this->get_post_object(false, 'id') : $obj->ID; } elseif ($mod === 'taxonomy') { $id = empty($obj->term_id) ? $this->get_term_object('id') : $obj->term_id; } elseif ($mod === 'user') { $id = empty($obj->ID) ? $this->get_author_object('id') : $obj->ID; } } elseif (empty($id)) { if ($mod === 'post') { $id = $this->get_post_object(false, 'id'); } elseif ($mod === 'taxonomy') { $id = $this->get_term_object('id'); } elseif ($mod === 'user') { $id = $this->get_author_object('id'); } } if (empty($mod)) { if ($this->p->debug->enabled) { $this->p->debug->log('no module defined'); } } elseif (empty($id)) { if ($this->p->debug->enabled) { $this->p->debug->log('no object id defined'); } } else { $meta_opts = $this->get_mod_options($mod, $id); } foreach ($sizes as $opt_prefix => $size_info) { if (!is_array($size_info)) { $save_name = empty($size_info) ? $opt_prefix : $size_info; $size_info = array('name' => $save_name, 'label' => $save_name); } elseif (!empty($size_info['prefix'])) { // allow for alternate option prefix $opt_prefix = $size_info['prefix']; } foreach (array('width', 'height', 'crop', 'crop_x', 'crop_y') as $key) { if (isset($size_info[$key])) { // prefer existing info from filters continue; } elseif (isset($meta_opts[$opt_prefix . '_' . $key])) { // use post meta if available $size_info[$key] = $meta_opts[$opt_prefix . '_' . $key]; } elseif (isset($this->p->options[$opt_prefix . '_' . $key])) { // current plugin settings $size_info[$key] = $this->p->options[$opt_prefix . '_' . $key]; } else { if (!isset($def_opts)) { // only read once if necessary $def_opts = $this->p->opt->get_defaults(); } $size_info[$key] = $def_opts[$opt_prefix . '_' . $key]; // fallback to default value } if ($key === 'crop') { // make sure crop is true or false $size_info[$key] = empty($size_info[$key]) ? false : true; } } if ($size_info['width'] > 0 && $size_info['height'] > 0) { // preserve compatibility with older wordpress versions, use true or false when possible if ($size_info['crop'] === true && ($size_info['crop_x'] !== 'center' || $size_info['crop_y'] !== 'center')) { global $wp_version; if (!version_compare($wp_version, 3.9, '<')) { $size_info['crop'] = array($size_info['crop_x'], $size_info['crop_y']); } } // allow custom function hooks to make changes if ($filter === true) { $size_info = apply_filters($this->p->cf['lca'] . '_size_info_' . $size_info['name'], $size_info, $id, $mod); } // a lookup array for image size labels, used in image size error messages $this->size_labels[$this->p->cf['lca'] . '-' . $size_info['name']] = $size_info['label']; add_image_size($this->p->cf['lca'] . '-' . $size_info['name'], $size_info['width'], $size_info['height'], $size_info['crop']); if ($this->p->debug->enabled) { $this->p->debug->log('image size ' . $this->p->cf['lca'] . '-' . $size_info['name'] . ' ' . $size_info['width'] . 'x' . $size_info['height'] . (empty($size_info['crop']) ? '' : ' crop ' . $size_info['crop_x'] . '/' . $size_info['crop_y']) . ' added'); } } } }
public function get_mod_obj($id, $mod = 'post') { $obj = false; if (empty($id) || empty($mod)) { if (!empty($id)) { $mod = 'post'; } elseif (SucomUtil::is_post_page(false)) { $mod = 'post'; } elseif (SucomUtil::is_term_page()) { $mod = 'taxonomy'; } elseif (SucomUtil::is_author_page()) { $mod = 'user'; } } if (isset($this->p->mods['util'][$mod])) { $obj =& $this->p->mods['util'][$mod]; if (empty($id)) { switch ($mod) { case 'post': $id = $this->get_post_object(false, 'id'); break; case 'taxonomy': $id = $this->get_term_object('id'); break; case 'author': $id = $this->get_author_object('id'); break; } } } return array($id, $obj); }