PageRenderTime 34ms CodeModel.GetById 20ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/wordpress-seo/admin/views/tool-file-editor.php

https://bitbucket.org/carloskikea/helpet
PHP | 241 lines | 194 code | 26 blank | 21 comment | 29 complexity | 1b85a0724887b2162a2b23954e19a70d MD5 | raw file
  1<?php
  2/**
  3 * WPSEO plugin file.
  4 *
  5 * @package WPSEO\Admin
  6 */
  7
  8if ( ! defined( 'WPSEO_VERSION' ) ) {
  9	header( 'Status: 403 Forbidden' );
 10	header( 'HTTP/1.1 403 Forbidden' );
 11	exit();
 12}
 13
 14$robots_file    = get_home_path() . 'robots.txt';
 15$ht_access_file = get_home_path() . '.htaccess';
 16
 17if ( isset( $_POST['create_robots'] ) ) {
 18	if ( ! current_user_can( 'edit_files' ) ) {
 19		$die_msg = sprintf(
 20			/* translators: %s expands to robots.txt. */
 21			__( 'You cannot create a %s file.', 'wordpress-seo' ),
 22			'robots.txt'
 23		);
 24		die( esc_html( $die_msg ) );
 25	}
 26
 27	check_admin_referer( 'wpseo_create_robots' );
 28
 29	ob_start();
 30	error_reporting( 0 );
 31	do_robots();
 32	$robots_content = ob_get_clean();
 33
 34	$f = fopen( $robots_file, 'x' );
 35	fwrite( $f, $robots_content );
 36}
 37
 38if ( isset( $_POST['submitrobots'] ) ) {
 39	if ( ! current_user_can( 'edit_files' ) ) {
 40		$die_msg = sprintf(
 41			/* translators: %s expands to robots.txt. */
 42			__( 'You cannot edit the %s file.', 'wordpress-seo' ),
 43			'robots.txt'
 44		);
 45		die( esc_html( $die_msg ) );
 46	}
 47
 48	check_admin_referer( 'wpseo-robotstxt' );
 49
 50	if ( file_exists( $robots_file ) ) {
 51		$robotsnew = stripslashes( $_POST['robotsnew'] );
 52		if ( is_writable( $robots_file ) ) {
 53			$f = fopen( $robots_file, 'w+' );
 54			fwrite( $f, $robotsnew );
 55			fclose( $f );
 56			$msg = sprintf(
 57				/* translators: %s expands to robots.txt. */
 58				__( 'Updated %s', 'wordpress-seo' ),
 59				'robots.txt'
 60			);
 61		}
 62	}
 63}
 64
 65if ( isset( $_POST['submithtaccess'] ) ) {
 66	if ( ! current_user_can( 'edit_files' ) ) {
 67		$die_msg = sprintf(
 68			/* translators: %s expands to ".htaccess". */
 69			__( 'You cannot edit the %s file.', 'wordpress-seo' ),
 70			'.htaccess'
 71		);
 72		die( esc_html( $die_msg ) );
 73	}
 74
 75	check_admin_referer( 'wpseo-htaccess' );
 76
 77	if ( file_exists( $ht_access_file ) ) {
 78		$ht_access_new = stripslashes( $_POST['htaccessnew'] );
 79		if ( is_writeable( $ht_access_file ) ) {
 80			$f = fopen( $ht_access_file, 'w+' );
 81			fwrite( $f, $ht_access_new );
 82			fclose( $f );
 83		}
 84	}
 85}
 86
 87if ( isset( $msg ) && ! empty( $msg ) ) {
 88	echo '<div id="message" class="updated fade"><p>', esc_html( $msg ), '</p></div>';
 89}
 90
 91if ( is_multisite() ) {
 92	$action_url = network_admin_url( 'admin.php?page=wpseo_files' );
 93}
 94else {
 95	$action_url = admin_url( 'admin.php?page=wpseo_tools&tool=file-editor' );
 96}
 97
 98echo '<br><br>';
 99$helpcenter_tab = new WPSEO_Option_Tab( 'bulk-editor', __( 'Bulk editor', 'wordpress-seo' ),
100	array( 'video_url' => WPSEO_Shortlinker::get( 'https://yoa.st/screencast-tools-file-editor' ) ) );
101
102$helpcenter = new WPSEO_Help_Center( 'bulk-editor', $helpcenter_tab, WPSEO_Utils::is_yoast_seo_premium() );
103$helpcenter->localize_data();
104$helpcenter->mount();
105
106// N.B.: "robots.txt" is a fixed file name and should not be translatable.
107echo '<h2>robots.txt</h2>';
108
109
110if ( ! file_exists( $robots_file ) ) {
111	if ( is_writable( get_home_path() ) ) {
112		echo '<form action="', esc_url( $action_url ), '" method="post" id="robotstxtcreateform">';
113		wp_nonce_field( 'wpseo_create_robots', '_wpnonce', true, true );
114		echo '<p>';
115		printf(
116			/* translators: %s expands to robots.txt. */
117			esc_html__( 'You don\'t have a %s file, create one here:', 'wordpress-seo' ),
118			'robots.txt'
119		);
120		echo '</p>';
121
122		printf(
123			'<input type="submit" class="button" name="create_robots" value="%s">',
124			sprintf(
125				/* translators: %s expands to robots.txt. */
126				esc_attr__( 'Create %s file', 'wordpress-seo' ),
127				'robots.txt'
128			)
129		);
130		echo '</form>';
131	}
132	else {
133		echo '<p>';
134		printf(
135			/* translators: %s expands to robots.txt. */
136			esc_html__( 'If you had a %s file and it was editable, you could edit it from here.', 'wordpress-seo' ),
137			'robots.txt'
138		);
139		echo '</p>';
140	}
141}
142else {
143	$f = fopen( $robots_file, 'r' );
144
145	$content = '';
146	if ( filesize( $robots_file ) > 0 ) {
147		$content = fread( $f, filesize( $robots_file ) );
148	}
149
150	if ( ! is_writable( $robots_file ) ) {
151		echo '<p><em>';
152		printf(
153			/* translators: %s expands to robots.txt. */
154			esc_html__( 'If your %s were writable, you could edit it from here.', 'wordpress-seo' ),
155			'robots.txt'
156		);
157		echo '</em></p>';
158		echo '<textarea class="large-text code" disabled="disabled" rows="15" name="robotsnew">', esc_textarea( $content ), '</textarea><br/>';
159	}
160	else {
161		echo '<form action="', esc_url( $action_url ), '" method="post" id="robotstxtform">';
162		wp_nonce_field( 'wpseo-robotstxt', '_wpnonce', true, true );
163		echo '<p><label for="robotsnew" class="yoast-inline-label">';
164		printf(
165			/* translators: %s expands to robots.txt. */
166			esc_html__( 'Edit the content of your %s:', 'wordpress-seo' ),
167			'robots.txt'
168		);
169		echo '</label></p>';
170		echo '<textarea class="large-text code" rows="15" name="robotsnew" id="robotsnew">', esc_textarea( $content ), '</textarea><br/>';
171		printf(
172			'<div class="submit"><input class="button" type="submit" name="submitrobots" value="%s" /></div>',
173			sprintf(
174				/* translators: %s expands to robots.txt. */
175				esc_attr__( 'Save changes to %s', 'wordpress-seo' ),
176				'robots.txt'
177			)
178		);
179		echo '</form>';
180	}
181}
182if ( ( isset( $_SERVER['SERVER_SOFTWARE'] ) && stristr( $_SERVER['SERVER_SOFTWARE'], 'nginx' ) === false ) ) {
183
184	echo '<h2>';
185	printf(
186		/* translators: %s expands to ".htaccess". */
187		esc_html__( '%s file', 'wordpress-seo' ),
188		'.htaccess'
189	);
190	echo '</h2>';
191
192	if ( file_exists( $ht_access_file ) ) {
193		$f = fopen( $ht_access_file, 'r' );
194
195		$contentht = '';
196		if ( filesize( $ht_access_file ) > 0 ) {
197			$contentht = fread( $f, filesize( $ht_access_file ) );
198		}
199
200		if ( ! is_writable( $ht_access_file ) ) {
201			echo '<p><em>';
202			printf(
203				/* translators: %s expands to ".htaccess". */
204				esc_html__( 'If your %s were writable, you could edit it from here.', 'wordpress-seo' ),
205				'.htaccess'
206			);
207			echo '</em></p>';
208			echo '<textarea class="large-text code" disabled="disabled" rows="15" name="robotsnew">', esc_textarea( $contentht ), '</textarea><br/>';
209		}
210		else {
211			echo '<form action="', esc_url( $action_url ), '" method="post" id="htaccessform">';
212			wp_nonce_field( 'wpseo-htaccess', '_wpnonce', true, true );
213			echo '<p><label for="htaccessnew" class="yoast-inline-label">';
214			printf(
215				/* translators: %s expands to ".htaccess". */
216				esc_html__( 'Edit the content of your %s:', 'wordpress-seo' ),
217				'.htaccess'
218			);
219			echo '</label></p>';
220			echo '<textarea class="large-text code" rows="15" name="htaccessnew" id="htaccessnew">', esc_textarea( $contentht ), '</textarea><br/>';
221			printf(
222				'<div class="submit"><input class="button" type="submit" name="submithtaccess" value="%s" /></div>',
223				sprintf(
224					/* translators: %s expands to ".htaccess". */
225					esc_attr__( 'Save changes to %s', 'wordpress-seo' ),
226					'.htaccess'
227				)
228			);
229			echo '</form>';
230		}
231	}
232	else {
233		echo '<p>';
234		printf(
235			/* translators: %s expands to ".htaccess". */
236			esc_html__( 'If you had a %s file and it was editable, you could edit it from here.', 'wordpress-seo' ),
237			'.htaccess'
238		);
239		echo '</p>';
240	}
241}