function truncate_at_ellipsis($content)
 {
     $end = '[...]';
     if (sustr::has($content, $end)) {
         $content = sustr::upto($content, $end);
         $content = sustr::rtrim_substr($content, $end);
     }
     return sustr::endwith($content, '[…]');
 }
Example #2
0
 static function is_search_engine_ua($user_agent)
 {
     $ua_keywords = array('Googlebot', 'Yahoo', 'Y!', 'Baiduspider', 'msnbot', 'Yandex', 'Sosospider', 'Teoma', 'sogou spider', 'Scooter', 'AltaVista');
     foreach ($ua_keywords as $keyword) {
         if (sustr::ihas($user_agent, $keyword)) {
             return true;
         }
     }
     return false;
 }
 function head_tag_output()
 {
     $verify = $this->get_supported_search_engines();
     foreach ($verify as $site => $site_data) {
         $name = $site_data['meta_name'];
         //Do we have verification tags? If so, output them.
         if ($value = $this->get_setting($site . '_verify')) {
             if (current_user_can('unfiltered_html') && sustr::startswith(trim($value), '<meta ') && sustr::endswith(trim($value), '/>')) {
                 echo "\t" . trim($value) . "\n";
             } else {
                 $value = su_esc_attr($value);
                 echo "\t<meta name=\"{$name}\" content=\"{$value}\" />\n";
             }
         }
     }
 }
Example #4
0
 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;
     }
 }
 function get_meta_desc()
 {
     global $post;
     $desc = false;
     //If we're viewing the homepage, look for homepage meta data.
     if (is_home()) {
         $desc = $this->get_setting('home_description');
         if (!$desc && $this->get_setting('home_description_tagline_default')) {
             $desc = get_bloginfo('description');
         }
         //If we're viewing a post or page, look for its meta data.
     } elseif (is_singular()) {
         $desc = $this->get_postmeta('description');
         if (!trim($desc) && !post_password_required() && ($format = $this->get_setting('description_posttype_' . get_post_type()))) {
             $auto_excerpt = $post->post_content;
             $auto_excerpt = strip_shortcodes($auto_excerpt);
             $auto_excerpt = str_replace(']]>', ']]&gt;', $auto_excerpt);
             $auto_excerpt = strip_tags($auto_excerpt);
             $auto_excerpt = sustr::truncate($auto_excerpt, 150, '', true);
             $desc = str_replace(array('{excerpt::autogen}', '{excerpt}'), array($auto_excerpt, strip_tags($post->post_excerpt)), $format);
         }
         //If we're viewing a term, look for its meta data.
     } elseif (suwp::is_tax()) {
         global $wp_query;
         $tax_descriptions = $this->get_setting('taxonomy_descriptions');
         $term_id = $wp_query->get_queried_object_id();
         $term_obj = $wp_query->get_queried_object();
         $desc = isset($tax_descriptions[$term_id]) ? $tax_descriptions[$term_id] : '';
         if (!trim($desc) && ($format = $this->get_setting('description_taxonomy_' . $term_obj->taxonomy))) {
             $desc = str_replace(array('{description}'), array($term_obj->description), $format);
         }
     }
     $desc = trim($desc);
     if ($desc) {
         $desc = $this->get_desc_paged($desc);
     }
     $desc = trim($desc);
     $desc = su_esc_attr($desc);
     return $desc;
 }
Example #6
0
 function admin_page_contents()
 {
     $the404s = $this->get_setting('log');
     if (!$this->get_setting('log_enabled', true)) {
         $this->queue_message('warning', __('New 404 errors will not be recorded because 404 logging is disabled on the Settings tab.', 'seo-ultimate'));
     }
     //Are we deleting a 404 entry?
     if ($this->is_action('delete')) {
         if (isset($the404s[$_GET['object']])) {
             unset($the404s[$_GET['object']]);
             $this->queue_message('success', __('The log entry was successfully deleted.', 'seo-ultimate'));
         } else {
             $this->queue_message('error', __('This log entry has already been deleted.', 'seo-ultimate'));
         }
         $this->update_setting('log', $the404s);
         //Are we clearing the whole 404 log?
     } elseif ($this->is_action('clear')) {
         $the404s = array();
         $this->update_setting('log', array());
         $this->queue_message('success', __('The log was successfully cleared.', 'seo-ultimate'));
     }
     if (!count($the404s)) {
         $this->queue_message('success', __('No 404 errors in the log.', 'seo-ultimate'));
     }
     $this->print_messages();
     if (count($the404s)) {
         $this->clear_log_button();
         echo "<div id='su-404s-log-table'>\n";
         $headers = $this->get_admin_table_columns();
         $this->admin_wftable_start();
         uasort($the404s, array(&$this, 'sort_log_callback'));
         foreach ($the404s as $url => $data) {
             $new = $data['is_new'] ? ' su-404s-new-hit' : '';
             $a_url = su_esc_attr($url);
             $ae_url = su_esc_attr(urlencode($url));
             $md5url = md5($url);
             echo "\t<tr id='su-404s-hit-{$md5url}-data' class='su-404s-hit-data{$new}'>\n";
             $this->table_cells(array('actions' => "<span class='su-404s-hit-open'><a href='{$a_url}' target='_blank'><img src='{$this->module_dir_url}hit-open.png' title='" . __('Open URL in new window (will not be logged)', 'seo-ultimate') . "' /></a></span>" . "<span class='su-404s-hit-cache'><a href='http://www.google.com/search?q=cache%3A{$ae_url}' target='_blank'><img src='{$this->module_dir_url}hit-cache.png' title='" . __('Query Google for cached version of URL (opens in new window)', 'seo-ultimate') . "' /></a></span>" . "<span class='su-404s-hit-delete'><a href='" . $this->get_nonce_url('delete', $url) . "'><img src='{$this->module_dir_url}hit-delete.png' title='" . __('Remove this URL from the log', 'seo-ultimate') . "' /></a></span>", 'hit-count' => $data['hit_count'], 'url' => "<attr title='{$a_url}'>" . esc_html(sustr::truncate($url, 100)) . '</attr>', 'last-hit-time' => sprintf(__('%s at %s', 'seo-ultimate'), date_i18n(get_option('date_format'), $data['last_hit_time']), date_i18n(get_option('time_format'), $data['last_hit_time'])), 'referers' => number_format_i18n(count($data['referers'])) . (count($data['referers']) ? " <a href='#' class='su_toggle_hide' data-toggle='su-404s-hit-{$md5url}-referers'><img src='{$this->module_dir_url}hit-details.png' title='" . __('View list of referring URLs', 'seo-ultimate') . "' /></a>" : ''), 'user-agents' => number_format_i18n(count($data['user_agents'])) . (count($data['user_agents']) ? " <a href='#' class='su_toggle_hide' data-toggle='su-404s-hit-{$md5url}-user-agents'><img src='{$this->module_dir_url}hit-details.png' title='" . __('View list of user agents', 'seo-ultimate') . "' /></a>" : '')));
             echo "\t</tr>\n";
             echo "\t<tr class='su-404s-hit-referers{$new}'>\n\t\t<td colspan='" . count($headers) . "'>";
             if (count($data['referers'])) {
                 echo "<div id='su-404s-hit-{$md5url}-referers' class='su-404s-hit-referers-list' style='display:none;'>\n";
                 echo "\t\t\t<div><strong>" . __('Referring URLs', 'seo-ultimate') . "</strong> &mdash; ";
                 echo "<a href='#' class='su_toggle_up' data-toggle='su-404s-hit-{$md5url}-referers'>" . __('Hide list', 'seo-ultimate') . "</a>";
                 echo "</div>\n";
                 echo "\t\t\t<ul>\n";
                 foreach ($data['referers'] as $referer) {
                     $referer = su_esc_attr($referer);
                     //Don't let attacks pass through the referer URLs!
                     echo "\t\t\t\t<li><a href='{$referer}' target='_blank'>{$referer}</a></li>\n";
                 }
                 echo "\t\t\t</ul>\n";
                 echo "\t\t</div>";
             }
             echo "</td>\n\t</tr>\n";
             echo "\t<tr class='su-404s-hit-user-agents{$new}'>\n\t\t<td colspan='" . count($headers) . "'>";
             if (count($data['user_agents'])) {
                 echo "<div id='su-404s-hit-{$md5url}-user-agents' class='su-404s-hit-user-agents-list' style='display:none;'>\n";
                 echo "\t\t\t<div><strong>" . __('User Agents', 'seo-ultimate') . "</strong> &mdash; ";
                 echo "<a href='#' class='su_toggle_up' data-toggle='su-404s-hit-{$md5url}-user-agents'>" . __('Hide list', 'seo-ultimate') . "</a>";
                 echo "</div>\n";
                 echo "\t\t\t<ul>\n";
                 foreach ($data['user_agents'] as $useragent) {
                     $useragent = su_esc_html($useragent);
                     //Don't let attacks pass through the user agent strings!
                     echo "\t\t\t\t<li>{$useragent}</li>\n";
                 }
                 echo "\t\t\t</ul>\n";
                 echo "</td>\n\t</tr>\n";
             }
             echo "\t\t</div>";
             $the404s[$url]['is_new'] = false;
         }
         $this->update_setting('log', $the404s);
         $this->admin_wftable_end();
         echo "</div>\n";
         $this->clear_log_button();
     }
 }
Example #7
0
 function get_title()
 {
     global $wp_query, $wp_locale;
     //Custom post/page title?
     if ($post_title = $this->get_postmeta('title')) {
         return htmlspecialchars($this->get_title_paged($post_title));
     }
     //Custom taxonomy title?
     if (suwp::is_tax()) {
         $tax_titles = $this->get_setting('taxonomy_titles');
         if ($tax_title = $tax_titles[$wp_query->get_queried_object_id()]) {
             return htmlspecialchars($this->get_title_paged($tax_title));
         }
     }
     //Get format
     if (!$this->should_rewrite_title()) {
         return '';
     }
     if (!($format = $this->get_title_format())) {
         return '';
     }
     //Load post/page titles
     $post_id = 0;
     $post_title = '';
     $parent_title = '';
     if (is_singular()) {
         $post = $wp_query->get_queried_object();
         $post_title = strip_tags(apply_filters('single_post_title', $post->post_title, $post));
         $post_id = $post->ID;
         if ($parent = $post->post_parent) {
             $parent = get_post($parent);
             $parent_title = strip_tags(apply_filters('single_post_title', $parent->post_title, $post));
         }
     }
     //Load date-based archive titles
     if ($m = get_query_var('m')) {
         $year = substr($m, 0, 4);
         $monthnum = intval(substr($m, 4, 2));
         $daynum = intval(substr($m, 6, 2));
     } else {
         $year = get_query_var('year');
         $monthnum = get_query_var('monthnum');
         $daynum = get_query_var('day');
     }
     $month = $wp_locale->get_month($monthnum);
     $monthnum = zeroise($monthnum, 2);
     $day = date('jS', mktime(12, 0, 0, $monthnum, $daynum, $year));
     $daynum = zeroise($daynum, 2);
     //Load category titles
     $cat_title = $cat_titles = $cat_desc = '';
     if (is_category()) {
         $cat_title = single_cat_title('', false);
         $cat_desc = category_description();
     } elseif (count($categories = get_the_category())) {
         $cat_titles = su_lang_implode($categories, 'name');
         usort($categories, '_usort_terms_by_ID');
         $cat_title = $categories[0]->name;
         $cat_desc = category_description($categories[0]->term_id);
     }
     if (strlen($cat_title) && $this->get_setting('terms_ucwords', true)) {
         $cat_title = sustr::tclcwords($cat_title);
     }
     //Load tag titles
     $tag_title = $tag_desc = '';
     if (is_tag()) {
         $tag_title = single_tag_title('', false);
         $tag_desc = tag_description();
         if ($this->get_setting('terms_ucwords', true)) {
             $tag_title = sustr::tclcwords($tag_title);
         }
     }
     //Load author titles
     if (is_author()) {
         $author_obj = $wp_query->get_queried_object();
     } elseif (is_singular()) {
         global $authordata;
         $author_obj = $authordata;
     } else {
         $author_obj = null;
     }
     if ($author_obj) {
         $author = array('username' => $author_obj->user_login, 'name' => $author_obj->display_name, 'firstname' => get_the_author_meta('first_name', $author_obj->ID), 'lastname' => get_the_author_meta('last_name', $author_obj->ID), 'nickname' => get_the_author_meta('nickname', $author_obj->ID));
     } else {
         $author = array('username' => '', 'name' => '', 'firstname' => '', 'lastname' => '', 'nickname' => '');
     }
     $variables = array('{blog}' => get_bloginfo('name'), '{tagline}' => get_bloginfo('description'), '{post}' => $post_title, '{page}' => $post_title, '{page_parent}' => $parent_title, '{category}' => $cat_title, '{categories}' => $cat_titles, '{category_description}' => $cat_desc, '{tag}' => $tag_title, '{tag_description}' => $tag_desc, '{tags}' => su_lang_implode(get_the_tags($post_id), 'name', true), '{daynum}' => $daynum, '{day}' => $day, '{monthnum}' => $monthnum, '{month}' => $month, '{year}' => $year, '{author}' => $author['name'], '{author_name}' => $author['name'], '{author_username}' => $author['username'], '{author_firstname}' => $author['firstname'], '{author_lastname}' => $author['lastname'], '{author_nickname}' => $author['nickname'], '{query}' => su_esc_attr(get_search_query()), '{ucquery}' => su_esc_attr(ucwords(get_search_query())), '{url_words}' => $this->get_url_words($_SERVER['REQUEST_URI']));
     $title = str_replace(array_keys($variables), array_values($variables), htmlspecialchars($format));
     return $this->get_title_paged($title);
 }
 function filter_canonical_url_scheme($scheme)
 {
     return sustr::preg_filter('a-z', $scheme);
 }
 /**
  * Explodes a JLSuggest database string into an array with the destination type and the destination ID.
  * 
  * @since 6.0
  * 
  * @param $valstr The database string, e.g. http://example.com or obj_posttype_post/1
  * @return array
  */
 function jlsuggest_value_explode($valstr)
 {
     if (is_array($valstr)) {
         if (count($valstr) == 3) {
             return $valstr;
         }
     } elseif (is_string($valstr)) {
         if (sustr::startswith($valstr, 'obj_')) {
             $valstr = sustr::ltrim_str($valstr, 'obj_');
             $valarr = explode('/', $valstr);
             if (count($valarr) == 2) {
                 $valarr_type = explode('_', $valarr[0], 2);
                 if (count($valarr_type) == 2) {
                     return array($valarr_type[0], $valarr_type[1], $valarr[1]);
                 } else {
                     return array($valarr[0], null, $valarr[1]);
                 }
             } else {
                 return array($valstr, null, null);
             }
         } else {
             return array('url', null, $valstr);
         }
     }
     return array('url', null, '');
 }
 function init()
 {
     if ($this->is_action('su-export')) {
         header('Content-Type: application/octet-stream');
         header('Content-Disposition: attachment; filename="SEO Ultimate Settings (' . date('Y-m-d') . ').dat"');
         $export = array();
         $psdata = (array) get_option('seo_ultimate', array());
         //Module statuses
         $export['modules'] = apply_filters('su_modules_export_array', $psdata['modules']);
         //Module settings
         $modules = array_keys($psdata['modules']);
         $module_settings = array();
         foreach ($modules as $module) {
             if (!$this->plugin->call_module_func($module, 'get_settings_key', $key) || !$key) {
                 $key = $module;
             }
             $msdata = (array) get_option("seo_ultimate_module_{$key}", array());
             if ($msdata) {
                 $module_settings[$key] = $msdata;
             }
         }
         $export['settings'] = apply_filters('su_settings_export_array', $module_settings);
         //Encode
         $export = base64_encode(serialize($export));
         //Output
         echo $export;
         die;
     } elseif ($this->is_action('su-import')) {
         if (strlen($_FILES['settingsfile']['name'])) {
             $file = $_FILES['settingsfile']['tmp_name'];
             if (is_uploaded_file($file)) {
                 $import = base64_decode(file_get_contents($file));
                 if (is_serialized($import)) {
                     $import = unserialize($import);
                     //Module statuses
                     $psdata = (array) get_option('seo_ultimate', array());
                     $psdata['modules'] = array_merge($psdata['modules'], $import['modules']);
                     update_option('seo_ultimate', $psdata);
                     //Module settings
                     $module_settings = apply_filters('su_settings_import_array', $import['settings']);
                     foreach ($module_settings as $key => $module_settings) {
                         $msdata = (array) get_option("seo_ultimate_module_{$key}", array());
                         $msdata = array_merge($msdata, $module_settings);
                         update_option("seo_ultimate_module_{$key}", $msdata);
                     }
                     $this->queue_message('success', __('Settings successfully imported.', 'seo-ultimate'));
                 } else {
                     $this->queue_message('error', __('The uploaded file is not in the proper format. Settings could not be imported.', 'seo-ultimate'));
                 }
             } else {
                 $this->queue_message('error', __('The settings file could not be uploaded successfully.', 'seo-ultimate'));
             }
         } else {
             $this->queue_message('warning', __('Settings could not be imported because no settings file was selected. Please click the &#8220;Browse&#8221; button and select a file to import.', 'seo-ultimate'));
         }
     } elseif ($this->is_action('su-reset')) {
         $psdata = (array) get_option('seo_ultimate', array());
         $modules = array_keys($psdata['modules']);
         foreach ($modules as $module) {
             if (!$this->plugin->call_module_func($module, 'get_settings_key', $key) || !$key) {
                 $key = $module;
             }
             delete_option("seo_ultimate_module_{$key}");
         }
         unset($psdata['modules']);
         update_option('seo_ultimate', $psdata);
         $this->load_default_settings();
     } elseif ($this->is_action('dj-export')) {
         header('Content-Disposition: attachment; filename="Deeplink Juggernaut Content Links (' . date('Y-m-d') . ').csv"');
         $djlinks = $this->get_setting('links', array(), 'autolinks');
         $csv_headers = array('anchor' => 'Anchor', 'to_type' => 'Destination Type', 'to_id' => 'Destination', 'title' => 'Title', 'sitewide_lpa' => 'Site Cap', 'nofollow' => 'Nofollow', 'target' => 'Target');
         if (is_array($djlinks) && count($djlinks)) {
             $djlinks = suarr::key_replace($djlinks, $csv_headers, true, true);
         } else {
             $djlinks = array(array_fill_keys($csv_headers, ''));
         }
         suio::export_csv($djlinks);
         die;
     } elseif ($this->is_action('dj-import')) {
         if (strlen($_FILES['settingsfile']['name'])) {
             $file = $_FILES['settingsfile']['tmp_name'];
             if (is_uploaded_file($file)) {
                 $import = suio::import_csv($file);
                 if ($import === false) {
                     $this->queue_message('error', __('The uploaded file is not in the proper format. Links could not be imported.', 'seo-ultimate'));
                 } else {
                     $import = suarr::key_replace($import, array('Anchor' => 'anchor', 'Destination Type' => 'to_type', 'Destination' => 'to_id', 'URL' => 'to_id', 'Title' => 'title', 'Site Cap' => 'sidewide_lpa', 'Nofollow' => 'nofollow', 'Target' => 'target'), true, true);
                     $import = suarr::value_replace($import, array('No' => false, 'Yes' => true, 'URL' => 'url'), true, false);
                     $djlinks = array();
                     foreach ($import as $link) {
                         //Validate destination type
                         if ($link['to_type'] != 'url' && !sustr::startswith($link['to_type'], 'posttype_') && !sustr::startswith($link['to_type'], 'taxonomy_')) {
                             $link['to_type'] = 'url';
                         }
                         //Validate nofollow
                         if (!is_bool($link['nofollow'])) {
                             $link['nofollow'] = false;
                         }
                         //Validate target
                         $link['target'] = ltrim($link['target'], '_');
                         if (!in_array($link['target'], array('self', 'blank'))) {
                             //Only _self or _blank are supported  right now
                             $link['target'] = 'self';
                         }
                         //Add link!
                         $djlinks[] = $link;
                     }
                     $this->update_setting('links', $djlinks, 'autolinks');
                     $this->queue_message('success', __('Links successfully imported.', 'seo-ultimate'));
                 }
             } else {
                 $this->queue_message('error', __('The CSV file could not be uploaded successfully.', 'seo-ultimate'));
             }
         } else {
             $this->queue_message('warning', __('Links could not be imported because no CSV file was selected. Please click the &#8220;Browse&#8221; button and select a file to import.', 'seo-ultimate'));
         }
     }
 }
Example #11
0
 /**
  * Sorts an array of arrays by using a given array key to locate string values in the second-level arrays and sorting the first-level array accordingly.
  * Reverse length sorting is used. (Longest strings are first, shortest strings last.)
  * 
  * @param array $arr Passed by reference
  * @param string $valuekey The array key used to access the string values by which the arrays in $arr are to be sorted
  */
 static function vklrsort(&$arr, $valuekey)
 {
     $valuekey = sustr::preg_filter('A-Za-z0-9 ', $valuekey);
     uasort($arr, create_function('$a,$b', 'return strlen($b["' . $valuekey . '"]) - strlen($a["' . $valuekey . '"]);'));
 }
Example #12
0
 static function permalink_mode()
 {
     if (strlen($struct = get_option('permalink_structure'))) {
         if (sustr::startswith($struct, '/index.php/')) {
             return SUWP_INDEX_PERMALINKS;
         } else {
             return SUWP_PRETTY_PERMALINKS;
         }
     } else {
         return SUWP_QUERY_PERMALINKS;
     }
 }
 function postmeta_fields($fields, $screen)
 {
     if (!current_user_can('manage_options')) {
         return $fields;
     }
     $post_id = suwp::get_post_id();
     $post = get_post($post_id);
     if (!$post) {
         return $fields;
     }
     $content = $post->post_content;
     $alias_dir = $this->get_setting('alias_dir', 'go');
     if ($content && preg_match_all('@ href=["\']([^#][^"\']+)["\']@', $content, $matches)) {
         $urls = array_unique($matches[1]);
         $html = "<tr valign='top'>\n<th scope='row' class='su'>" . __('Link Masks:', 'seo-ultimate') . "</th>\n<td>\n";
         $html .= "<table class='widefat'><thead>\n";
         $headers = array(__('URL', 'seo-ultimate'), '', __('Mask URL', 'seo-ultimate'));
         foreach ($headers as $header) {
             $html .= "<th>{$header}</th>\n";
         }
         $html .= "</thead>\n<tbody>";
         $aliases = $this->get_setting('aliases', array());
         $post_aliases = array();
         foreach ($aliases as $id => $alias) {
             if (empty($alias['posts']) || in_array($post->ID, $alias['posts'])) {
                 $post_aliases[$alias['from']] = array('id' => $id, 'to' => $alias['to']);
             }
         }
         foreach ($urls as $url) {
             $a_url = su_esc_attr($url);
             $un_h_url = htmlspecialchars_decode($url);
             $ht_url = esc_html(sustr::truncate($url, 30));
             if (isset($post_aliases[$url])) {
                 $url_key = $url;
             } elseif (isset($post_aliases[$un_h_url])) {
                 $url_key = $un_h_url;
             } else {
                 $url_key = false;
             }
             $alias_to = '';
             $alias_id = uniqid('', true);
             if ($url_key) {
                 if (isset($post_aliases[$url_key]['to'])) {
                     $alias_to = $post_aliases[$url_key]['to'];
                 }
                 if (isset($post_aliases[$url_key]['id'])) {
                     $alias_id = $post_aliases[$url_key]['id'];
                 }
             }
             $a_alias_to = esc_attr($alias_to);
             $html .= "<tr><td><a href='{$a_url}' title='{$a_url}' target='_blank'>{$ht_url}</a><input type='hidden' name='_su_aliases[{$alias_id}][from]' value='{$a_url}' /></td>\n<td>&rArr;</td><td>/{$alias_dir}/<input type='text' name='_su_aliases[{$alias_id}][to]' value='{$a_alias_to}' /></td></tr>\n";
         }
         $html .= "</tbody>\n</table>\n";
         $html .= '<p><small>' . __('You can stop search engines from following a link by typing in a mask for its URL.', 'seo-ultimate') . "</small></p>\n";
         $html .= "</td>\n</tr>\n";
         $fields['links'][100]['aliases'] = $html;
     }
     return $fields;
 }
 function nobase_rewrite_rules($rules)
 {
     $rules = array();
     $tax_name = sustr::rtrim_str(current_filter(), '_rewrite_rules');
     $tax_obj = get_taxonomy($tax_name);
     wp_cache_flush();
     //Otherwise get_terms() won't include the term just added
     $terms = get_terms($tax_name);
     if ($terms && !is_wp_error($terms)) {
         foreach ($terms as $term_obj) {
             $term_slug = suwp::get_term_slug($term_obj);
             if ($tax_obj->query_var && is_string($tax_obj->query_var)) {
                 $url_start = "index.php?{$tax_obj->query_var}=";
             } else {
                 $url_start = "index.php?taxonomy={$tax_name}&term=";
             }
             if ($this->get_setting('add_rule_if_conflict', true) || get_page_by_path($term_slug) === null) {
                 $rules['(' . $term_slug . ')/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$'] = $url_start . '$matches[1]&feed=$matches[2]';
                 $rules['(' . $term_slug . ')/page/?([0-9]{1,})/?$'] = $url_start . '$matches[1]&paged=$matches[2]';
                 $rules['(' . $term_slug . ')/?$'] = $url_start . '$matches[1]';
             }
         }
     }
     global $wp_rewrite;
     $old_base = $wp_rewrite->get_extra_permastruct($tax_name);
     $old_base = str_replace("%{$tax_name}%", '(.+)', $old_base);
     $old_base = trim($old_base, '/');
     $rules[$old_base . '$'] = 'index.php?su_term_redirect=$matches[1]';
     return $rules;
 }
Example #15
0
 /**
  * Converts an array into a CSV file and outputs it.
  * 
  * @param array $csv The array to convert and output
  * 
  * @return bool Whether or not the conversion was successful
  */
 function print_csv($csv)
 {
     if (!is_array($csv) || !count($csv) || !is_array($csv[0])) {
         return false;
     }
     $headers = array_keys($csv[0]);
     array_unshift($csv, array_combine($headers, $headers));
     foreach ($csv as $row) {
         $csv_row = array();
         foreach ($headers as $header) {
             $csv_row[$header] = $row[$header];
             if (sustr::has($csv_row[$header], ',')) {
                 $csv_row[$header] = '"' . $csv_row[$header] . '"';
             }
         }
         echo implode(',', $csv_row) . "\r\n";
     }
     return true;
 }
 function admin_page_contents()
 {
     echo "\n<p>";
     _e('The Content Links section of Deeplink Juggernaut lets you automatically link a certain word or phrase in your post/page content to a URL you specify.', 'seo-ultimate');
     echo "</p>\n";
     $links = $this->get_setting('links', array());
     $num_links = count($links);
     if ($this->is_action('update')) {
         $links = array();
         $guid = stripslashes($_POST['_link_guid']);
         for ($i = 0; $i <= $num_links; $i++) {
             $anchor = stripslashes($_POST["link_{$i}_anchor"]);
             $to = stripslashes($_POST["link_{$i}_to"]);
             if (sustr::startswith($to, 'obj_')) {
                 $to = sustr::ltrim_str($to, 'obj_');
                 $to = explode('/', $to);
                 if (count($to) == 2) {
                     $to_type = $to[0];
                     $to_id = $to[1];
                 } else {
                     $to_type = $to[0];
                     $to_id = null;
                 }
             } else {
                 $to_type = 'url';
                 $to_id = $to;
             }
             $title = stripslashes($_POST["link_{$i}_title"]);
             $dampen_sitewide_lpa = sustr::preg_filter('0-9', strval($_POST["link_{$i}_dampen_sitewide_lpa"]));
             $dampen_sitewide_lpa = $dampen_sitewide_lpa === '' ? false : intval($dampen_sitewide_lpa);
             $sitewide_lpa = isset($_POST["link_{$i}_sitewide_lpa"]) ? sustr::preg_filter('0-9', strval($_POST["link_{$i}_sitewide_lpa"])) : '';
             $sitewide_lpa = $sitewide_lpa === '' ? false : intval($sitewide_lpa);
             $target = empty($_POST["link_{$i}_target"]) ? 'self' : 'blank';
             $nofollow = isset($_POST["link_{$i}_nofollow"]) ? intval($_POST["link_{$i}_nofollow"]) == 1 : false;
             $delete = isset($_POST["link_{$i}_delete"]) ? intval($_POST["link_{$i}_delete"]) == 1 : false;
             if (!$delete && (strlen($anchor) || $to_id)) {
                 $links[] = compact('anchor', 'to_type', 'to_id', 'title', 'dampen_sitewide_lpa', 'sitewide_lpa', 'nofollow', 'target');
             }
         }
         $this->update_setting('links', $links);
         $num_links = count($links);
     }
     $this->legacy_sitewide_lpa_in_use = false;
     foreach ($links as $link) {
         if (isset($link['sitewide_lpa']) && $link['sitewide_lpa']) {
             $this->legacy_sitewide_lpa_in_use = true;
             break;
         }
     }
     if ($this->legacy_sitewide_lpa_in_use) {
         $this->print_message('warning', __('<strong>Functionality Change Notice:</strong> The &#8220;Site Cap&#8221; feature (which allowed you set a per-link sitewide quantity limit) has been replaced with a more efficient &#8220;Dampener&#8221; feature that lets you reduce autolinking frequency by a percentage. Although the Site Cap feature has been replaced, we retained the &#8220;Site Cap&#8221; column for you in the table below, since it looks like you&#8217;ve used the Site Cap feature in the past. We retained the column to help you remember which links used the old feature, so that you know to which links to apply the new &#8220;Dampener&#8221; feature. Once you&#8217;re done migrating the Site Cap values to Dampener percentages, just clear the &#8220;Site Cap&#8221; boxes to make those boxes (and this message) go away.', 'seo-ultimate'));
     }
     $guid = substr(md5(time()), 0, 10);
     if ($num_links > 0) {
         $this->admin_subheader(__('Edit Existing Links', 'seo-ultimate'));
         $this->content_links_form($guid, 0, $links);
     }
     $this->admin_subheader(__('Add a New Link', 'seo-ultimate'));
     $this->content_links_form($guid, $num_links, array(array()), false);
 }
Example #17
0
 function wildcards_to_regex($wcstr)
 {
     $wcstr = sustr::preg_escape($wcstr, '@');
     $wcstr = str_replace('\\*', '.*', $wcstr);
     $regex = "@^{$wcstr}\$@i";
     $regex = str_replace(array('@^.*', '.*$@i'), array('@', '@i'), $regex);
     return $regex;
 }
 function autolink_footer($args = array())
 {
     if ($this->already_outputted) {
         return;
     }
     extract(wp_parse_args($args, array('footer_link_section_format' => $this->get_setting('footer_link_section_format', '{links}'), 'footer_link_format' => $this->get_setting('footer_link_format', '{link}'), 'footer_link_sep' => $this->get_setting('footer_link_sep', ' | '))), EXTR_SKIP);
     $links = $this->get_setting('footer_links', array());
     suarr::vksort($links, 'anchor');
     $link_html = array();
     foreach ($links as $link_data) {
         if (isset($link_data['from']) && count($link_data['from'])) {
             $from = $link_data['from'][0];
         } else {
             $from = array('');
         }
         $from_match_children = isset($link_data['from_match_children']) && $link_data['from_match_children'];
         $from_match_negative = isset($link_data['from_match_negative']) && $link_data['from_match_negative'];
         if (!isset($link_data['to'])) {
             $link_data['to'] = '';
         }
         list($from_genus, $from_type, $from_id) = $this->jlsuggest_value_explode($from);
         $is_from = $from_match_negative;
         switch ($from_genus) {
             case 'posttype':
                 $post_ids = array($from_id);
                 if ($from_match_children) {
                     $post_ids[] = wp_get_post_parent_id($from_id);
                 }
                 //Requires WordPress 3.1
                 foreach ($post_ids as $post_id) {
                     if (is_single($post_id) || is_page($post_id)) {
                         $is_from = !$from_match_negative;
                         break;
                     }
                 }
                 break;
             case 'taxonomy':
                 if (suwp::is_tax($from_type, $from_id) || $from_match_children && is_singular() && has_term($from_id, $from_type)) {
                     $is_from = !$from_match_negative;
                 }
                 break;
             case 'home':
                 if (is_home()) {
                     $is_from = !$from_match_negative;
                 }
                 break;
             case 'author':
                 if (is_author($from_id) || $from_match_children && is_singular() && get_the_author_meta('id') == $from_id) {
                     $is_from = !$from_match_negative;
                 }
                 break;
             case 'url':
                 if ($from_id) {
                     if (suurl::equal(suurl::current(), $from_id) || $from_match_children && sustr::startswith(suurl::current(), $from_id)) {
                         $is_from = !$from_match_negative;
                     }
                 } else {
                     $is_from = true;
                 }
                 //No "from" restriction
                 break;
         }
         if (!$is_from) {
             continue;
         }
         $h_anchor = esc_html($link_data['anchor']);
         $rel = $link_data['nofollow'] ? ' rel="nofollow"' : '';
         $target = $link_data['target'] == 'blank' ? ' target="_blank"' : '';
         $title = strlen($a_titletext = su_esc_attr($link_data['title'])) ? " title=\"{$a_titletext}\"" : '';
         $a_url = su_esc_attr($this->jlsuggest_value_to_url($link_data['to']));
         if (strlen(trim($h_anchor)) && strlen(trim((string) $a_url)) && $a_url != 'http://') {
             $link_html[] = str_replace('{link}', "<a href=\"{$a_url}\"{$title}{$rel}{$target}>{$h_anchor}</a>", $footer_link_format);
         }
     }
     echo str_replace('{links}', implode($footer_link_sep, $link_html), $footer_link_section_format);
 }
Example #19
0
 function sanitize_twitter_handle($value)
 {
     if (strpos($value, '/') === false) {
         $handle = ltrim($value, '@');
     } else {
         $url_parts = explode('/', $value);
         $handle = array_pop($url_parts);
     }
     $handle = sustr::preg_filter('a-zA-Z0-9_', $handle);
     $handle = trim($handle);
     if ($handle) {
         $handle = "@{$handle}";
     }
     return $handle;
 }
 function do_installation()
 {
     if (!isset($_POST['version'])) {
         return false;
     }
     $nv = sustr::preg_filter('0-9a-zA-Z .', $_POST['version']);
     if (!strlen($nv)) {
         return false;
     }
     //Don't allow downgrading to anything below the minimum limit
     if (version_compare(SU_DOWNGRADE_LIMIT, $nv, '>')) {
         return;
     }
     switch (version_compare($nv, SU_VERSION)) {
         case -1:
             //Downgrade
             $title = __('Downgrade to SEO Ultimate %s', 'seo-ultimate');
             if (!$this->current_user_can_downgrade()) {
                 wp_die(__('You do not have sufficient permissions to downgrade plugins on this site.', 'seo-ultimate'));
                 return;
             }
             break;
         case 0:
             //Reinstall
             $title = __('Reinstall SEO Ultimate %s', 'seo-ultimate');
             if (!$this->current_user_can_reinstall()) {
                 wp_die(__('You do not have sufficient permissions to reinstall plugins on this site.', 'seo-ultimate'));
                 return;
             }
             break;
         case 1:
             //Upgrade
             $title = __('Upgrade to SEO Ultimate %s', 'seo-ultimate');
             if (!$this->current_user_can_upgrade()) {
                 wp_die(__('You do not have sufficient permissions to upgrade plugins on this site.', 'seo-ultimate'));
                 return;
             }
             break;
         default:
             return;
     }
     $title = sprintf($title, $nv);
     $nonce = 'su-install-plugin';
     $plugin = 'seo-ultimate/seo-ultimate.php';
     $url = 'update.php?action=upgrade-plugin&plugin=' . $plugin;
     include_once $this->plugin->plugin_dir_path . 'plugin/class.su-installer.php';
     $upgrader = new SU_Installer(new SU_Installer_Skin(compact('title', 'nonce', 'url', 'plugin')));
     $upgrader->upgrade($plugin, SU_VERSION, $nv);
     return true;
 }
 /**
  * Outputs a JSON-encoded list of posts and terms on the blog.
  * 
  * @since 6.0
  */
 function jlsuggest_autocomplete()
 {
     if (!function_exists('json_encode')) {
         die;
     }
     if (!current_user_can('manage_options')) {
         die;
     }
     $items = array();
     $include = empty($_GET['types']) ? array() : explode(',', $_GET['types']);
     if ((!$include || in_array('home', $include)) && sustr::ihas($_GET['q'], 'home')) {
         $items[] = array('text' => __('Home', 'seo-ultimate'), 'isheader' => true);
         $items[] = array('text' => __('Blog Homepage', 'seo-ultimate'), 'value' => 'obj_home', 'selectedtext' => __('Blog Homepage', 'seo-ultimate'));
     }
     $posttypeobjs = get_post_types(array('public' => true), 'objects');
     foreach ($posttypeobjs as $posttypeobj) {
         if ($include && !in_array('posttype', $include) && !in_array('posttype_' . $posttypeobj->name, $include)) {
             continue;
         }
         $stati = get_available_post_statuses($posttypeobj->name);
         suarr::remove_value($stati, 'auto-draft');
         $stati = implode(',', $stati);
         $posts = get_posts(array('orderby' => 'title', 'order' => 'ASC', 'post_status' => $stati, 'numberposts' => -1, 'post_type' => $posttypeobj->name, 'post_mime_type' => isset($_GET['post_mime_type']) ? $_GET['post_mime_type'] : '', 'sentence' => 1, 's' => $_GET['q']));
         if (count($posts)) {
             $items[] = array('text' => $posttypeobj->labels->name, 'isheader' => true);
             foreach ($posts as $post) {
                 $items[] = array('text' => $post->post_title, 'value' => 'obj_posttype_' . $posttypeobj->name . '/' . $post->ID, 'selectedtext' => $post->post_title . '<span class="type">&nbsp;&mdash;&nbsp;' . $posttypeobj->labels->singular_name . '</span>');
             }
         }
     }
     $taxonomyobjs = suwp::get_taxonomies();
     foreach ($taxonomyobjs as $taxonomyobj) {
         if ($include && !in_array('taxonomy', $include) && !in_array('taxonomy_' . $posttypeobj->name, $include)) {
             continue;
         }
         $terms = get_terms($taxonomyobj->name, array('search' => $_GET['q']));
         if (count($terms)) {
             $items[] = array('text' => $taxonomyobj->labels->name, 'isheader' => true);
             foreach ($terms as $term) {
                 $items[] = array('text' => $term->name, 'value' => 'obj_taxonomy_' . $taxonomyobj->name . '/' . $term->term_id, 'selectedtext' => $term->name . '<span class="type"> &mdash; ' . $taxonomyobj->labels->singular_name . '</span>');
             }
         }
     }
     if (!$include || in_array('author', $include)) {
         $authors = get_users(array('search' => $_GET['q'], 'fields' => array('ID', 'user_login')));
         if (count($authors)) {
             $items[] = array('text' => __('Author Archives', 'seo-ultimate'), 'isheader' => true);
             foreach ($authors as $author) {
                 $items[] = array('text' => $author->user_login, 'value' => 'obj_author/' . $author->ID, 'selectedtext' => $author->user_login . '<span class="type"> &mdash; ' . __('Author', 'seo-ultimate') . '</span>');
             }
         }
     }
     if ($this->module_exists('internal-link-aliases') && (!$include || in_array('internal-link-alias', $include))) {
         $aliases = $this->get_setting('aliases', array(), 'internal-link-aliases');
         $alias_dir = $this->get_setting('alias_dir', 'go', 'internal-link-aliases');
         if (is_array($aliases) && count($aliases)) {
             $header_outputted = false;
             foreach ($aliases as $alias_id => $alias) {
                 if ($alias['to']) {
                     $h_alias_to = su_esc_html($alias['to']);
                     $to_rel_url = "/{$alias_dir}/{$h_alias_to}/";
                     if (strpos($alias['from'], $_GET['q']) !== false || strpos($to_rel_url, $_GET['q']) !== false) {
                         if (!$header_outputted) {
                             $items[] = array('text' => __('Link Masks', 'seo-ultimate'), 'isheader' => true);
                             $header_outputted = true;
                         }
                         $items[] = array('text' => $to_rel_url, 'value' => 'obj_internal-link-alias/' . $alias_id, 'selectedtext' => $to_rel_url . '<span class="type"> &mdash; ' . __('Link Mask', 'seo-ultimate') . '</span>');
                     }
                 }
             }
         }
     }
     echo json_encode($items);
     die;
 }
 function apply_subproperty_markup($matches)
 {
     if (empty($matches[1])) {
         return '';
     }
     $content = $matches[1];
     extract($this->apply_subproperty_markup_args, EXTR_SKIP);
     foreach ($subproperties as $subproperty => $subproperty_data) {
         //Get the subproperty tags
         $subproperty_tag = is_array($subproperty_data['tags']) ? $subproperty_data['tags'][$format] : $subproperty_data['tags'];
         $subproperty_value = strval($this->get_postmeta("rich_snippet_{$type}_{$property}_{$subproperty}"));
         if ($subproperty_value) {
             $subproperty_markedup_value = $this->add_tags($subproperty_value, $subproperty_tag, $property_tag_template);
             $content = sustr::htmlsafe_str_replace($subproperty_value, $subproperty_markedup_value, $content, 1, $count);
         }
     }
     $content = $this->add_tags($content, $property_tag, $property_tag_format, false);
     return $content;
 }