コード例 #1
0
 /**
  * @covers wpseo_is_apache()
  */
 public function test_wpseo_is_apache()
 {
     $_SERVER['SERVER_SOFTWARE'] = 'Apache/2.2.22';
     $this->assertTrue(wpseo_is_apache());
     $_SERVER['SERVER_SOFTWARE'] = 'nginx/1.5.11';
     $this->assertFalse(wpseo_is_apache());
 }
コード例 #2
0
 /**
  * Hook that runs after the 'wpseo_redirect' option is updated
  *
  * @param $old_value
  * @param $value
  */
 public function save_redirect_files($old_value, $value)
 {
     // Check if we need to remove the WPSEO redirect entries from the .htacccess file
     $remove_htaccess_entries = false;
     // Check if the 'disable_php_redirect' option set to true/on
     if (null != $value && isset($value['disable_php_redirect']) && 'on' == $value['disable_php_redirect']) {
         // Remove .htaccess entries if the 'separate_file' option is set to true
         if (wpseo_is_apache() && isset($value['separate_file']) && 'on' == $value['separate_file']) {
             $remove_htaccess_entries = true;
         }
         // The 'disable_php_redirect' option is set to true(on) so we need to generate a file.
         // The Redirect Manager will figure out what file needs to be created.
         $redirect_manager = new WPSEO_URL_Redirect_Manager();
         $redirect_manager->save_redirect_file();
     } else {
         if (wpseo_is_apache()) {
             // No settings are set so we should also strip the .htaccess redirect entries in this case
             $remove_htaccess_entries = true;
         }
     }
     // Check if we need to remove the .htaccess redirect entries
     if ($remove_htaccess_entries) {
         // Remove the .htaccess redirect entries
         $redirect_manager = new WPSEO_URL_Redirect_Manager();
         $redirect_manager->clear_htaccess_entries();
     }
 }
コード例 #3
0
 public function add_htaccess_import_block($admin_object)
 {
     // Attemp to load the htaccess file
     $textarea_value = "";
     if (1 || wpseo_is_apache()) {
         if (file_exists(ABSPATH . '.htaccess')) {
             $textarea_value = file_get_contents(ABSPATH . '.htaccess');
         }
     }
     // Display the form
     echo '<form action="" method="post" accept-charset="' . esc_attr(get_bloginfo('charset')) . '">' . PHP_EOL;
     echo wp_nonce_field('wpseo-import', '_wpnonce', true, false);
     echo '<h2>' . __('Import redirects from .htaccess', 'wordpress-seo') . '</h2>' . PHP_EOL;
     echo '<textarea name="htaccess" rows="4" cols="50" style="width:70%; height: 200px;">' . $textarea_value . '</textarea><br/>' . PHP_EOL;
     echo '<input type="submit" class="button-primary" name="import" value="' . __('Import .htaccess', 'wordpress-seo') . '"/>' . PHP_EOL;
     echo '</form>' . PHP_EOL;
 }
コード例 #4
0
 /**
  * Create the redirect file
  */
 public function save_redirect_file()
 {
     // Options
     $options = self::get_options();
     if ('on' == $options['disable_php_redirect']) {
         // Create the correct file object
         $file = null;
         if (wpseo_is_apache()) {
             if ('on' == $options['separate_file']) {
                 $file = new WPSEO_Apache_Redirect_File();
             } else {
                 $file = new WPSEO_Htaccess_Redirect_File();
             }
         } elseif (wpseo_is_nginx()) {
             $file = new WPSEO_Nginx_Redirect_File();
         }
         // Save the file
         if (null !== $file) {
             $file->save_file();
         }
     }
 }
コード例 #5
0
/**
 * Adds tracking parameters for WP SEO settings. Outside of the main class as the class could also be in use in other plugins.
 *
 * @param array $options
 *
 * @return array
 */
function wpseo_tracking_additions($options)
{
    if (function_exists('curl_version')) {
        $curl = curl_version();
    } else {
        $curl = null;
    }
    $opt = WPSEO_Options::get_all();
    $options['wpseo'] = array('xml_sitemaps' => $opt['enablexmlsitemap'] === true ? 1 : 0, 'force_rewrite' => $opt['forcerewritetitle'] === true ? 1 : 0, 'opengraph' => $opt['opengraph'] === true ? 1 : 0, 'twitter' => $opt['twitter'] === true ? 1 : 0, 'strip_category_base' => $opt['stripcategorybase'] === true ? 1 : 0, 'on_front' => get_option('show_on_front'), 'wmt_alexa' => !empty($opt['alexaverify']) ? 1 : 0, 'wmt_bing' => !empty($opt['msverify']) ? 1 : 0, 'wmt_google' => !empty($opt['googleverify']) ? 1 : 0, 'wmt_pinterest' => !empty($opt['pinterestverify']) ? 1 : 0, 'wmt_yandex' => !empty($opt['yandexverify']) ? 1 : 0, 'permalinks_clean' => $opt['cleanpermalinks'] == 1 ? 1 : 0, 'site_db_charset' => DB_CHARSET, 'webserver_apache' => wpseo_is_apache() ? 1 : 0, 'webserver_apache_version' => function_exists('apache_get_version') ? apache_get_version() : 0, 'webserver_nginx' => wpseo_is_nginx() ? 1 : 0, 'webserver_server_software' => $_SERVER['SERVER_SOFTWARE'], 'webserver_gateway_interface' => $_SERVER['GATEWAY_INTERFACE'], 'webserver_server_protocol' => $_SERVER['SERVER_PROTOCOL'], 'php_version' => phpversion(), 'php_max_execution_time' => ini_get('max_execution_time'), 'php_memory_limit' => ini_get('memory_limit'), 'php_open_basedir' => ini_get('open_basedir'), 'php_bcmath_enabled' => extension_loaded('bcmath') ? 1 : 0, 'php_ctype_enabled' => extension_loaded('ctype') ? 1 : 0, 'php_curl_enabled' => extension_loaded('curl') ? 1 : 0, 'php_curl_version_a' => phpversion('curl'), 'php_curl' => !is_null($curl) ? $curl['version'] : 0, 'php_dom_enabled' => extension_loaded('dom') ? 1 : 0, 'php_dom_version' => phpversion('dom'), 'php_filter_enabled' => extension_loaded('filter') ? 1 : 0, 'php_mbstring_enabled' => extension_loaded('mbstring') ? 1 : 0, 'php_mbstring_version' => phpversion('mbstring'), 'php_pcre_enabled' => extension_loaded('pcre') ? 1 : 0, 'php_pcre_version' => phpversion('pcre'), 'php_pcre_with_utf8_a' => @preg_match('/^.{1}$/u', 'ñ', $UTF8_ar), 'php_pcre_with_utf8_b' => defined('PREG_BAD_UTF8_ERROR'), 'php_spl_enabled' => extension_loaded('spl') ? 1 : 0);
    return $options;
}
コード例 #6
0
    /**
     * Function that outputs the redirect page
     */
    public static function display()
    {
        global $wpseo_admin_pages;
        // Check if there's an old URL set
        $old_url = '';
        if (isset($_GET['old_url'])) {
            $old_url = urldecode($_GET['old_url']);
        }
        // Get the redirect types
        $redirect_types = WPSEO_Redirect_Manager::get_redirect_types();
        // Admin header
        $wpseo_admin_pages->admin_header(false, 'yoast_wpseo_redirects_options', 'wpseo_redirects');
        ?>
		<h2 class="nav-tab-wrapper" id="wpseo-tabs">
			<a class="nav-tab" id="tab-url-tab" href="#top#tab-url"><?php 
        _e('Redirects', 'wordpress-seo');
        ?>
</a>
			<a class="nav-tab" id="tab-regex-tab" href="#top#tab-regex"><?php 
        _e('Regex Redirects', 'wordpress-seo');
        ?>
</a>
			<a class="nav-tab" id="settings-tab" href="#top#settings"><?php 
        _e('Settings', 'wordpress-seo');
        ?>
</a>
		</h2>

		<div class="tabwrapper>">
			<div id="tab-url" class="wpseotab redirect-table-tab">
				<?php 
        // Add new redirect HTML
        echo "<form class='wpseo-new-redirect-form' method='post'>\n";
        echo "<div class='wpseo_redirects_new'>\n";
        //				echo "<h2>" . __( 'Add New Redirect', 'wordpress-seo' ) . "</h2>\n";
        echo "<label class='textinput' for='wpseo_redirects_new_old'>" . __('Old URL', 'wordpress-seo') . "</label>\n";
        echo "<input type='text' class='textinput' name='wpseo_redirects_new_old' id='wpseo_redirects_new_old' value='", esc_url($old_url) . "' />\n";
        echo "<br class='clear'/>\n";
        echo "<label class='textinput' for='wpseo_redirects_new_new'>" . __('New URL', 'wordpress-seo') . "</label>\n";
        echo "<input type='text' class='textinput' name='wpseo_redirects_new_new' id='wpseo_redirects_new_new' value='' />\n";
        echo "<br class='clear'/>\n";
        echo "<label class='textinput' for='wpseo_redirects_new_type'>" . __('Type', 'wordpress-seo') . "</label>\n";
        // Redirect type select element
        echo "<select name='wpseo_redirects_new_type' id='wpseo_redirects_new_type' class='select'>" . PHP_EOL;
        // Loop through the redirect types
        if (count($redirect_types) > 0) {
            foreach ($redirect_types as $type => $desc) {
                echo "<option value='" . $type . "'>" . $desc . "</option>" . PHP_EOL;
            }
        }
        echo "</select>" . PHP_EOL;
        echo '<img src="' . plugins_url('images/question-mark.png', WPSEO_FILE) . '" class="yoast_help" style="margin:17px 0 0 5px" alt="' . __(sprintf('The redirect type is de HTTP response code send to the browser telling the browser what type of redirect is served.<br/><br/>Read <a href=\'%s\'>this page</a> for more info.', 'http://kb.yoast.com/article/121-redirect-types/#utm_source=wordpress-seo-premium-redirects&amp;utm_medium=inline-help&amp;utm_campaign=redirect-types'), 'wordpress-seo') . '">';
        echo "<br class='clear'/>\n";
        echo "<a href='javascript:;' class='button-primary'>" . __('Add Redirect', 'wordpress-seo') . "</a>\n";
        echo "</div>\n";
        echo "</form>\n";
        echo "<p class='desc'>&nbsp;</p>\n";
        // Open <form>
        echo "<form id='url' class='wpseo-redirects-table-form' method='post' action=''>\n";
        // AJAX nonce
        echo "<input type='hidden' class='wpseo_redirects_ajax_nonce' value='" . wp_create_nonce('wpseo-redirects-ajax-security') . "' />\n";
        // The list table
        $list_table = new WPSEO_Redirect_Table('URL');
        $list_table->prepare_items();
        $list_table->search_box(__('Search', 'wordpress-seo'), 'wpseo-redirect-search');
        $list_table->display();
        // Close <form>
        echo "</form>\n";
        ?>
			</div>
			<div id="tab-regex" class="wpseotab redirect-table-tab">
				<?php 
        // Add new redirect HTML
        echo "<p>" . sprintf(__('Regex Redirects are extremely powerful redirects. You should only use them if you know what you are doing.<br />If you don\'t know what Regular Expressions (REGEX) are, please refer to %1$sour knowledge base%2$s.', 'wordpress-seo'), '<a href="http://kb.yoast.com/article/142-what-are-regex-redirects" target="_blank">', '</a>') . "</p>\n";
        echo "<form class='wpseo-new-redirect-form' method='post'>\n";
        echo "<div class='wpseo_redirects_new'>\n";
        //				echo "<h2>" . __( 'Add New Regex Redirect', 'wordpress-seo' ) . "</h2>\n";
        echo "<label class='textinput' for='wpseo_redirects_new_old'>" . __('REGEX', 'wordpress-seo') . "</label>\n";
        echo "<input type='text' class='textinput' name='wpseo_redirects_new_old' id='wpseo_redirects_new_old' value='{$old_url}' />\n";
        echo "<br class='clear'/>\n";
        echo "<label class='textinput' for='wpseo_redirects_new_new'>" . __('URL', 'wordpress-seo') . "</label>\n";
        echo "<input type='text' class='textinput' name='wpseo_redirects_new_new' id='wpseo_redirects_new_new' value='' />\n";
        echo "<br class='clear'/>\n";
        echo "<label class='textinput' for='wpseo_redirects_new_type'>" . __('Type', 'wordpress-seo') . "</label>\n";
        // Redirect type select element
        echo "<select name='wpseo_redirects_new_type' id='wpseo_redirects_new_type' class='select'>" . PHP_EOL;
        // Loop through the redirect types
        if (count($redirect_types) > 0) {
            foreach ($redirect_types as $key => $desc) {
                echo "<option value='" . $key . "'>" . $desc . "</option>" . PHP_EOL;
            }
        }
        echo "</select>" . PHP_EOL;
        echo '<img src="' . plugins_url('images/question-mark.png', WPSEO_FILE) . '" class="yoast_help" style="margin:17px 0 0 5px" alt="' . __(sprintf('The redirect type is de HTTP response code send to the browser telling the browser what type of redirect is served.<br/><br/>Read <a href=\'%s\'>this page</a> for more info.', 'http://kb.yoast.com/article/121-redirect-types/#utm_source=wordpress-seo-premium-redirects&amp;utm_medium=inline-help&amp;utm_campaign=redirect-types'), 'wordpress-seo') . '">';
        echo "<br class='clear'/>\n";
        echo "<a href='javascript:;' class='button-primary'>" . __('Add Regex Redirect', 'wordpress-seo') . "</a>\n";
        echo "</div>\n";
        echo "</form>\n";
        echo "<p class='desc'>&nbsp;</p>\n";
        // Open <form>
        echo "<form id='regex' class='wpseo-redirects-table-form' method='post' action=''>\n";
        // AJAX nonce
        echo "<input type='hidden' class='wpseo_redirects_ajax_nonce' value='" . wp_create_nonce('wpseo-redirects-ajax-security') . "' />\n";
        // The list table
        $list_table = new WPSEO_Redirect_Table('REGEX');
        $list_table->prepare_items();
        $list_table->search_box(__('Search', 'wordpress-seo'), 'wpseo-redirect-search');
        $list_table->display();
        // Close <form>
        echo "</form>\n";
        ?>
			</div>
			<div id="settings" class="wpseotab">
				<?php 
        // Get redirect options
        $redirect_options = WPSEO_Redirect_Manager::get_options();
        // Do file checks
        if ('on' == $redirect_options['disable_php_redirect']) {
            $file_write_error = false;
            if (wpseo_is_apache()) {
                if ('on' == $redirect_options['separate_file']) {
                    if (file_exists(WPSEO_Redirect_File_Manager::get_file_path())) {
                        echo '<div style="margin: 5px 0; padding: 3px 10px; background-color: #ffffe0; border: 1px solid #E6DB55; border-radius: 3px">';
                        echo '<p>' . __("As you're on Apache, you should add the following include to the website httpd config file:", 'wordpress-seo') . '</p>';
                        echo '<pre>Include ' . WPSEO_Redirect_File_Manager::get_file_path() . '</pre>';
                        echo '</div>';
                    } else {
                        $file_write_error = true;
                    }
                } else {
                    if (!is_writable(WPSEO_Redirect_File_Manager::get_htaccess_file_path())) {
                        echo "<div class='error'><p><b>" . __("We're unable to save the redirects to your .htaccess file, please make the file writable.", 'wordpress-seo') . "</b></p></div>\n";
                    }
                }
            } else {
                if (wpseo_is_nginx()) {
                    if (file_exists(WPSEO_Redirect_File_Manager::get_file_path())) {
                        echo '<div style="margin: 5px 0; padding: 3px 10px; background-color: #ffffe0; border: 1px solid #E6DB55; border-radius: 3px">';
                        echo '<p>' . __("As you're on NGINX, you should add the following include to the website Nginx config file:", 'wordpress-seo') . '</p>';
                        echo '<pre>include ' . WPSEO_Redirect_File_Manager::get_file_path() . ';</pre>';
                        echo '</div>';
                    } else {
                        $file_write_error = true;
                    }
                }
            }
            if ($file_write_error) {
                echo "<div class='error'><p><b>" . __(sprintf("We're unable to save the redirect file to %s", WPSEO_Redirect_File_Manager::get_file_path()), 'wordpress-seo') . "</b></p></div>\n";
            }
        }
        ?>
				<h2>Redirect Settings</h2>

				<form action="<?php 
        echo admin_url('options.php');
        ?>
" method="post">
					<?php 
        settings_fields('yoast_wpseo_redirect_options');
        $wpseo_admin_pages->currentoption = 'wpseo_redirect';
        if (wpseo_is_apache()) {
            echo $wpseo_admin_pages->checkbox('disable_php_redirect', __('Disable PHP redirects', 'wordpress-seo'));
            echo '<p class="desc">' . __("Write redirects to the .htaccess file. Make sure the .htaccess file is writable!", 'wordpress-seo') . '</p>';
            echo $wpseo_admin_pages->checkbox('separate_file', __('Generate a separate redirect file', 'wordpress-seo'));
            echo '<p class="desc">' . __("By default we write the redirects to your .htaccess file, check this if you want a the redirects written to a separate file. Only check this option if you know what your doing!", 'wordpress-seo') . '</p>';
        } else {
            echo $wpseo_admin_pages->checkbox('disable_php_redirect', __('Disable PHP redirects', 'wordpress-seo'));
            echo '<p class="desc">' . __("WordPress SEO will generate redirect files that can be included in your website configuration, you can disable PHP redirect if this is done correctly. Only check this option if you know what your doing!", 'wordpress-seo') . '</p>';
        }
        ?>
					<p class="submit">
						<input type="submit" name="submit" id="submit" class="button button-primary" value="<?php 
        _e('Save Changes', 'wordpress-seo');
        ?>
">
					</p>
				</form>
			</div>
		</div>
		<br class="clear">
		<?php 
        // Admin footer
        $wpseo_admin_pages->admin_footer(false);
    }