コード例 #1
0
ファイル: slugs.php プロジェクト: quinntron/greendot
 function optimize_slug($slug)
 {
     //If no slug exists, start off with the post title
     if (empty($slug) && isset($_POST['post_title'])) {
         $slug = $_POST['post_title'];
     }
     //Prepare the title and the words for comparison
     $slug = sustr::tolower(stripslashes($slug));
     $words = sustr::tolower(stripslashes($this->get_setting('words_to_remove')));
     //Remove the stopwords from the slug
     $newslug = implode("-", array_diff(explode(" ", $slug), suarr::explode_lines($words)));
     //Make sure we haven't removed too much!
     if (empty($newslug)) {
         return $slug;
     } else {
         return $newslug;
     }
 }
コード例 #2
0
 function save_post_autolinks($false, $value, $metakey, $post)
 {
     if ($post->post_type == 'revision') {
         return true;
     }
     $links = $this->get_setting('links', array());
     $new_links = array();
     $keep_anchors = array();
     $others_anchors = array();
     $new_anchors = suarr::explode_lines($value);
     $new_anchors = array_map('trim', $new_anchors);
     array_filter($new_anchors);
     if (count($new_anchors)) {
         foreach ($links as $link_data) {
             if ($link_data['to_type'] == 'posttype_' . $post->post_type && $link_data['to_id'] == $post->ID) {
                 if (in_array($link_data['anchor'], $new_anchors)) {
                     $keep_anchors[] = $link_data['anchor'];
                     $new_links[] = $link_data;
                 }
             } else {
                 $others_anchors[] = $link_data['anchor'];
                 $new_links[] = $link_data;
             }
         }
         $anchors_to_add = array_diff($new_anchors, $keep_anchors, $others_anchors);
         if (count($anchors_to_add)) {
             foreach ($anchors_to_add as $anchor_to_add) {
                 if (trim($anchor_to_add)) {
                     $new_links[] = array('anchor' => $anchor_to_add, 'to_type' => 'posttype_' . $post->post_type, 'to_id' => $post->ID, 'title' => '', 'nofollow' => false, 'target' => 'self');
                 }
             }
         }
         $this->update_setting('links', $new_links);
     }
     return true;
 }
コード例 #3
0
 function log_hit($hit)
 {
     if ($hit['status_code'] == 404) {
         if ($this->get_setting('restrict_logging', true)) {
             if (!($this->get_setting('log_spiders', true) && suweb::is_search_engine_ua($hit['user_agent'])) && !($this->get_setting('log_errors_with_referers', true) && strlen($hit['referer']))) {
                 return $hit;
             }
         }
         $exceptions = suarr::explode_lines($this->get_setting('exceptions', ''));
         foreach ($exceptions as $exception) {
             if (preg_match(sustr::wildcards_to_regex($exception), $hit['url'])) {
                 return $hit;
             }
         }
         $l = $this->get_setting('log', array());
         $max_log_size = absint(sustr::preg_filter('0-9', strval($this->get_setting('max_log_size', 100))));
         while (count($l) > $max_log_size) {
             array_pop($l);
         }
         $u = $hit['url'];
         if (!isset($l[$u])) {
             $l[$u] = array();
             $l[$u]['hit_count'] = 0;
             $l[$u]['is_new'] = isset($hit['is_new']) ? $hit['is_new'] : true;
             $l[$u]['referers'] = array();
             $l[$u]['user_agents'] = array();
             $l[$u]['last_hit_time'] = 0;
         }
         $l[$u]['hit_count']++;
         if (!$l[$u]['is_new'] && $hit['is_new']) {
             $l[$u]['is_new'] = true;
         }
         if ($hit['time'] > $l[$u]['last_hit_time']) {
             $l[$u]['last_hit_time'] = $hit['time'];
         }
         if (strlen($hit['referer']) && !in_array($hit['referer'], $l[$u]['referers'])) {
             $l[$u]['referers'][] = $hit['referer'];
         }
         if (strlen($hit['user_agent']) && !in_array($hit['user_agent'], $l[$u]['user_agents'])) {
             $l[$u]['user_agents'][] = $hit['user_agent'];
         }
         $this->update_setting('log', $l);
     }
     return $hit;
 }
コード例 #4
0
ファイル: meta-keywords.php プロジェクト: quinntron/greendot
 function head_tag_output()
 {
     global $post;
     $kw = false;
     //If we're viewing the homepage, look for homepage meta data.
     if (is_home()) {
         $kw = $this->get_setting('home_keywords');
         //If we're viewing a post or page...
     } elseif (is_singular()) {
         //...look for its meta data
         $kw = $this->get_postmeta('keywords');
         //...and add default values
         if ($posttypename = get_post_type()) {
             $taxnames = get_object_taxonomies($posttypename);
             foreach ($taxnames as $taxname) {
                 if ($this->get_setting("auto_keywords_posttype_{$posttypename}_tax_{$taxname}", false)) {
                     $terms = get_the_terms(0, $taxname);
                     $terms = suarr::flatten_values($terms, 'name');
                     $terms = implode(',', $terms);
                     $kw .= ',' . $terms;
                 }
             }
             if ($this->get_setting("auto_keywords_posttype_{$posttypename}_words", false)) {
                 $words = preg_split("/[\\s+]/", strip_tags($post->post_content), null, PREG_SPLIT_NO_EMPTY);
                 $words = array_count_values($words);
                 arsort($words);
                 $words = array_filter($words, array(&$this, 'filter_word_counts'));
                 $words = array_keys($words);
                 $stopwords = suarr::explode_lines($this->get_setting('words_to_remove', array(), 'slugs'));
                 $stopwords = array_map(array('sustr', 'tolower'), $stopwords);
                 $words = array_map(array('sustr', 'tolower'), $words);
                 $words = array_diff($words, $stopwords);
                 $words = array_slice($words, 0, $this->get_setting("auto_keywords_posttype_{$posttypename}_words_value"));
                 $words = implode(',', $words);
                 $kw .= ',' . $words;
             }
         }
         //If we're viewing a term, look for its meta data.
     } elseif (suwp::is_tax()) {
         global $wp_query;
         $tax_keywords = $this->get_setting('taxonomy_keywords');
         $term_id = $wp_query->get_queried_object_id();
         if (isset($tax_keywords[$term_id])) {
             $kw = $tax_keywords[$term_id];
         } else {
             $kw = '';
         }
     }
     if ($globals = $this->get_setting('global_keywords')) {
         if (strlen($kw)) {
             $kw .= ',';
         }
         $kw .= $globals;
     }
     $kw = str_replace(array("\r\n", "\n"), ',', $kw);
     $kw = explode(',', $kw);
     $kw = array_map('trim', $kw);
     //Remove extra spaces from beginning/end of keywords
     $kw = array_filter($kw);
     //Remove blank keywords
     $kw = suarr::array_unique_i($kw);
     //Remove duplicate keywords
     $kw = implode(',', $kw);
     //Do we have keywords? If so, output them.
     if ($kw) {
         $kw = su_esc_attr($kw);
         echo "\t<meta name=\"keywords\" content=\"{$kw}\" />\n";
     }
 }