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";
             }
         }
     }
 }
 /**
  * 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'));
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * If the given string begins with the given prefix, the prefix is removed.
  * 
  * @param string $str The string of which the provided prefix should be trimmed if located.
  * @param string $totrim The prefix that should be trimmed if found.
  * @return string The possibly-trimmed string.
  */
 function ltrim_str($str, $totrim)
 {
     if (strlen($str) > strlen($totrim) && sustr::startswith($str, $totrim)) {
         return substr($str, strlen($totrim));
     }
     return $str;
 }
 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);
 }
 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);
 }
Ejemplo n.º 7
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 apply_markup($content)
 {
     //Single items only
     if (!is_singular() || !in_the_loop()) {
         return $content;
     }
     //Get the current type
     $type = $this->get_postmeta('rich_snippet_type');
     if (!strlen($type) || $type == 'none') {
         return $content;
     }
     //Get the current format
     $format = 'so';
     //Get tag templates for the current format
     $formats = $this->get_supported_snippet_formats();
     //Get data for the current type
     $types = $this->get_supported_snippet_types();
     $type_data = $types[$type];
     //Cycle through the current type's properties
     $append = '';
     $num_properties = 0;
     $supervalue_regex = '';
     foreach ($type_data['properties'] as $property => $property_data) {
         //Get the property tags
         $tag = is_array($property_data['tags']) ? $property_data['tags'][$format] : $property_data['tags'];
         if (isset($property_data['hidden_tags'])) {
             $hidden_tag = is_array($property_data['hidden_tags']) ? $property_data['hidden_tags'][$format] : $property_data['hidden_tags'];
         } else {
             $hidden_tag = $tag;
         }
         if (isset($property_data['properties']) && is_array($property_data['properties']) && count($property_data['properties'])) {
             $subproperty_regex_pieces = array();
             $subproperty_hidden_markedup_values = array();
             foreach ($property_data['properties'] as $subproperty => $subproperty_data) {
                 //Get the subproperty tags
                 $subproperty_tag = is_array($subproperty_data['tags']) ? $subproperty_data['tags'][$format] : $subproperty_data['tags'];
                 if (isset($subproperty_data['hidden_tags'])) {
                     $subproperty_hidden_tag = is_array($subproperty_data['hidden_tags']) ? $subproperty_data['hidden_tags'][$format] : $subproperty_data['hidden_tags'];
                 } else {
                     $subproperty_hidden_tag = $subproperty_tag;
                 }
                 $subproperty_value = strval($this->get_postmeta("rich_snippet_{$type}_{$property}_{$subproperty}"));
                 if ($subproperty_value) {
                     $subproperty_hidden_markedup_values[] = $this->add_tags($subproperty_value, $subproperty_hidden_tag, $formats[$format]['hidden_property_tags_template']);
                     $subproperty_regex_pieces[] = sustr::preg_escape($subproperty_value);
                 }
             }
             /*$supervalue_regex = implode('(<br ?/?>|\s|,)*?', $subproperty_regex_pieces);*/
             $supervalue_regex = implode('|', $subproperty_regex_pieces);
             $supervalue_regex = "({$supervalue_regex})";
             $supervalue_regex = array_fill(0, count($subproperty_regex_pieces), $supervalue_regex);
             $supervalue_regex = implode('(<br ?/?>|\\s|.){0,20}', $supervalue_regex);
             $this->apply_subproperty_markup_args = array('format' => $format, 'type' => $type, 'property' => $property, 'property_tag' => $tag, 'property_tag_template' => $formats[$format]['property_tags_template'], 'subproperties' => $property_data['properties']);
             $count = 0;
             $content = preg_replace_callback("%({$supervalue_regex})%", array(&$this, 'apply_subproperty_markup'), $content, 1, $count);
             if ($count == 0) {
                 if (count($subproperty_hidden_markedup_values)) {
                     $append .= $this->add_tags(implode($subproperty_hidden_markedup_values), $tag, $formats[$format]['property_tags_template'], false);
                     $num_properties++;
                 }
             } else {
                 $num_properties++;
             }
         } else {
             //Get the current value for this property
             $value = strval($this->get_postmeta("rich_snippet_{$type}_{$property}"));
             if (strlen($value)) {
                 if (sustr::startswith($value, 'obj_') && isset($property_data['jlsuggest']) && $property_data['jlsuggest']) {
                     $value = $this->jlsuggest_value_to_url($value, true);
                 }
             } else {
                 //If a value is not set, look for a value-generating function
                 if (isset($property_data['value_function'])) {
                     $valfunc = (array) $property_data['value_function'];
                     if (is_callable($valfunc[0])) {
                         $valfunc_args = isset($valfunc[1]) ? (array) $valfunc[1] : array();
                         $value = call_user_func_array($valfunc[0], $valfunc_args);
                     }
                 }
             }
             //If still no value, skip this property
             if (!strlen($value)) {
                 continue;
             }
             //Add property tags to the value
             $markedup_value = $this->add_tags($value, $tag, $formats[$format]['property_tags_template']);
             $hidden_markedup_value = $this->add_tags($value, $hidden_tag, $formats[$format]['hidden_property_tags_template']);
             //Apply a value format to visible values if provided
             if (isset($property_data['value_format'])) {
                 $values = array_values(sustr::batch_replace('%s', $value, $property_data['value_format']));
                 $markedup_values = array_values(sustr::batch_replace('%s', $markedup_value, $property_data['value_format']));
             } else {
                 $values = array($value);
                 $markedup_values = array($markedup_value);
             }
             //Is the value in the content, and are we allowed to search/replace the content for this value?
             $count = 0;
             if (empty($property_data['always_hidden'])) {
                 for ($i = 0; $i < count($values); $i++) {
                     $content = sustr::htmlsafe_str_replace($values[$i], $markedup_values[$i], $content, 1, $count);
                     if ($count > 0) {
                         break;
                     }
                 }
             }
             if ($count == 0) {
                 $append .= $hidden_markedup_value;
             }
             $num_properties++;
         }
     }
     if (isset($type_data['content_tags'])) {
         $content_tag = is_array($type_data['content_tags']) ? $type_data['content_tags'][$format] : $type_data['content_tags'];
         $content = $this->add_tags($content, $content_tag, $formats[$format]['property_tags_template'], false);
     }
     if ($num_properties) {
         $type_tag = is_array($type_data['tags']) ? $type_data['tags'][$format] : $type_data['tags'];
         $content = $this->add_tags("{$content}<div>{$append}</div>", $type_tag, $formats[$format]['item_tags_template'], false);
         if ($this->get_setting('mark_code', true, 'settings')) {
             $content .= "\n\n<!-- " . sprintf(__('Schema.org markup generated by %1$s (%2$s)', 'seo-ultimate'), SU_PLUGIN_NAME, SU_PLUGIN_URI) . " -->\n\n";
         }
     }
     //Return filtered content
     return $content;
 }