コード例 #1
0
 function get_current_settings($override = '')
 {
     global $post;
     if ($this->disabled == true) {
         return array();
     }
     // This is useful for when we call a filter to prevent infinite loops
     $meta = array();
     if ($override) {
         $meta[] = $override;
     } else {
         if (is_admin()) {
             $meta[] = $this->get_post_settings(isset($_GET['post']) ? intval($_GET['post']) : 0);
         } else {
             if (!is_admin()) {
                 $meta[] = get_option('headspace_global');
             }
             // We don't get this in admin mode as it will affect our settings
             // Decide what kind of page we're on
             // Note that on the home page we want headspace_home settings when outside the loop, but post settings inside
             if (is_single() || is_page() || (is_front_page() || is_home() || is_archive() || is_search()) && in_the_loop()) {
                 if (is_attachment()) {
                     $meta[] = get_option('headspace_attachment');
                 }
                 if (is_page()) {
                     $meta[] = get_option('headspace_page');
                 } else {
                     $meta[] = get_option('headspace_post');
                 }
                 if (!empty($post->ID)) {
                     $meta[] = $this->get_post_settings($post->ID);
                 }
             } else {
                 if (is_404()) {
                     $meta[] = get_option('headspace_404');
                 } else {
                     if (is_category()) {
                         $meta[] = get_option('headspace_category');
                         $meta[] = get_option('headspace_cat_' . intval(get_query_var('cat')));
                     } else {
                         if (is_author()) {
                             $meta[] = get_option('headspace_author');
                         } else {
                             if (is_home()) {
                                 $meta[] = get_option('headspace_home');
                             } else {
                                 if (is_front_page()) {
                                     $meta[] = get_option('headspace_front');
                                 } else {
                                     if (is_search()) {
                                         $meta[] = get_option('headspace_search');
                                     } else {
                                         if (is_tag()) {
                                             $meta[] = get_option('headspace_tags');
                                         } else {
                                             if (is_archive()) {
                                                 if (is_tax()) {
                                                     $taxonomy = get_query_var('taxonomy');
                                                     $specific_taxonomy_settings = get_option('headspace_taxonomy_' . $taxonomy);
                                                     $generic_taxonomy_settings = get_option('headspace_taxonomy');
                                                     // Settings for a specific taxonomy override general ones
                                                     foreach ((array) $specific_taxonomy_settings as $key => $value) {
                                                         if (!empty($value)) {
                                                             $generic_taxonomy_settings[$key] = $value;
                                                         }
                                                     }
                                                     $meta[] = $generic_taxonomy_settings;
                                                 } else {
                                                     $meta[] = get_option('headspace_archive');
                                                 }
                                             } else {
                                                 if (strpos($_SERVER['REQUEST_URI'], 'wp-login.php') !== false) {
                                                     $meta[] = get_option('headspace_login');
                                                 } else {
                                                     if (is_feed()) {
                                                         // Remove title from RSS
                                                         if (is_array($meta) && isset($meta[0]) && isset($meta[0]['page_title'])) {
                                                             unset($meta[0]['page_title']);
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $meta = array_filter($meta);
     // Do we merge the settings?
     $options = $this->get_options();
     if ($options['inherit'] !== true && count($meta) > 1) {
         $meta = array($meta[count($meta) - 1]);
     }
     // Merge the settings together
     $merged = array();
     foreach ($meta as $item) {
         if (!empty($item) && is_array($item)) {
             foreach ($item as $key => $value) {
                 if (!empty($value)) {
                     $merged[$key] = $value;
                 }
             }
         }
     }
     $meta = $merged;
     if (!$override && !is_admin()) {
         // Replace any inline tags
         if (count($meta) > 0) {
             foreach ($meta as $key => $value) {
                 $meta[$key] = HS_InlineTags::replace($value, $post);
             }
         }
         $meta = array_filter($meta);
     }
     $this->meta = $meta;
     return $this->meta;
 }
コード例 #2
0
 static function replace($value, $post)
 {
     if (is_array($value) || is_object($value)) {
         return $value;
     }
     global $wp_query, $wp_locale;
     $replace_with = '';
     // We can only replace inline post tags when given a post
     if (is_object($post)) {
         $userData = get_userdata($post->post_author);
         $tags = '';
         if (function_exists('the_tags')) {
             if (is_tag()) {
                 $tags = single_tag_title(false, '');
             } else {
                 $items = get_the_tags($post->ID);
                 if ($items) {
                     foreach ($items as $tag) {
                         $tags[] = $tag->name;
                     }
                     $tags = implode(', ', $tags);
                 }
             }
         }
         if (is_day()) {
             $date = get_the_time('F jS, Y');
         } else {
             if (is_month()) {
                 $date = get_the_time('F, Y');
             } else {
                 if (is_year()) {
                     $date = get_the_time('Y');
                 } else {
                     $date = $post->post_date;
                 }
             }
         }
         $replace_with = array($date, $post->post_title, $post->post_modified, $post->ID, $userData->display_name, $post->post_author, $tags, $_SERVER['REQUEST_URI']);
     } else {
         if (is_author()) {
             global $posts;
             $userData = get_userdata($posts[0]->post_author);
             $replace_with = array('', '', '', '', $userData->display_name, $posts[0]->post_author);
         } else {
             if (is_archive()) {
                 $m = get_query_var('m');
                 $year = get_query_var('year');
                 $monthnum = get_query_var('monthnum');
                 $day = get_query_var('day');
                 $date = '';
                 // If there's a month
                 if (!empty($m)) {
                     $my_year = substr($m, 0, 4);
                     $my_month = $wp_locale->get_month(substr($m, 4, 2));
                     $my_day = intval(substr($m, 6, 2));
                     $date = "{$my_year}" . ($my_month ? "{$sep} {$my_month}" : "") . ($my_day ? "{$sep} {$my_day}" : "");
                 }
                 if (!empty($year)) {
                     if (!empty($monthnum)) {
                         $date .= " {$sep} " . $wp_locale->get_month($monthnum);
                     }
                     if (!empty($day)) {
                         $date .= " {$sep} " . zeroise($day, 2);
                     }
                     $date .= ' ' . $year;
                 }
                 $replace_with = array($date, '', '', '', '', '', '', $_SERVER['REQUEST_URI']);
             } else {
                 if (function_exists('is_tag') && is_tag()) {
                     $replace_with = array('', '', '', '', '', '', single_tag_title('', false));
                 }
             }
         }
     }
     $search_for = array("%%date%%", "%%title%%", "%%modified%%", "%%id%%", "%%name%%", "%%userid%%", '%%tag%%', '%%url%%');
     // Replace post values
     $value = str_replace($search_for, $replace_with, $value);
     // Replace static values
     $value = str_replace('%%searchphrase%%', isset($wp_query->query_vars['s']) ? strip_tags($wp_query->query_vars['s']) : '', $value);
     $value = str_replace('%%currentdate%%', date(get_option('date_format')), $value);
     $value = str_replace('%%currenttime%%', date(get_option('time_format')), $value);
     $value = str_replace('%%currentyear%%', date('Y'), $value);
     global $headspace2;
     $headspace2->ugly_hack = true;
     $value = str_replace('%%sitename%%', get_bloginfo('blogname'), $value);
     $headspace2->ugly_hack = false;
     if (is_object($wp_locale)) {
         $value = str_replace('%%currentmonth%%', $wp_locale->get_month(date('n')), $value);
     } else {
         $value = str_replace('%%currentmonth%%', date('F'), $value);
     }
     // These need extra work so we only do it if necessary
     if (strpos($value, '%%excerpt%%') !== false) {
         $value = str_replace('%%excerpt%%', HS_InlineTags::get_excerpt($post, true), $value);
     }
     if (strpos($value, '%%excerpt_only%%') !== false) {
         $value = str_replace('%%excerpt_only%%', HS_InlineTags::get_excerpt($post, false), $value);
     }
     if (strpos($value, '%%category%%') !== false) {
         $value = str_replace('%%category%%', HS_InlineTags::get_category($post), $value);
     }
     if (strpos($value, '%%category_description%%') !== false) {
         $value = str_replace('%%category_description%%', HS_InlineTags::get_category_description($post), $value);
     }
     if (strpos($value, '%%tag_description%%') !== false) {
         $value = str_replace('%%tag_description%%', HS_InlineTags::get_tag_description($post), $value);
     }
     if (strpos($value, '%%term_description%%') !== false) {
         $value = str_replace('%%term_description%%', HS_InlineTags::get_term_description(), $value);
     }
     if (strpos($value, '%%term_title%%') !== false) {
         $value = str_replace('%%term_title%%', HS_InlineTags::get_term_title(), $value);
     }
     if (strpos($value, '%%page%%') !== false) {
         $value = str_replace('%%page%%', HS_InlineTags::get_page($post), $value);
     }
     if (strpos($value, '%%pagenumber%%') !== false) {
         $value = str_replace('%%pagenumber%%', HS_InlineTags::get_page($post, 'number'), $value);
     }
     if (strpos($value, '%%pagetotal%%') !== false) {
         $value = str_replace('%%pagetotal%%', HS_InlineTags::get_page($post, 'total'), $value);
     }
     if (strpos($value, '%%caption%%') !== false) {
         $value = str_replace('%%caption%%', $post->post_excerpt, $value);
     }
     return $value;
 }