Advertisement
Guest User

Map.php

a guest
Mar 4th, 2015
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.36 KB | None | 0 0
  1. <?php
  2.  
  3. // +----------------------------------------------------------------------+
  4. // | Copyright Incsub (http://incsub.com/) |
  5. // | Based on an original by Donncha (http://ocaoimh.ie/) |
  6. // +----------------------------------------------------------------------+
  7. // | This program is free software; you can redistribute it and/or modify |
  8. // | it under the terms of the GNU General Public License, version 2, as |
  9. // | published by the Free Software Foundation. |
  10. // | |
  11. // | This program is distributed in the hope that it will be useful, |
  12. // | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  13. // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
  14. // | GNU General Public License for more details. |
  15. // | |
  16. // | You should have received a copy of the GNU General Public License |
  17. // | along with this program; if not, write to the Free Software |
  18. // | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, |
  19. // | MA 02110-1301 USA |
  20. // +----------------------------------------------------------------------+
  21.  
  22. /**
  23. * Renders map domain tab page.
  24. *
  25. * @category Domainmap
  26. * @package Render
  27. * @subpackage Site
  28. *
  29. * @since 4.0.0
  30. */
  31. class Domainmap_Render_Site_Map extends Domainmap_Render_Site {
  32.  
  33. function __construct($tabs, $active, $data){
  34. parent::__construct($tabs, $active, $data);
  35. $this->_save_excluded_pages();
  36. }
  37. /**
  38. * Determines whether ability to map multi domains is enabled or not.
  39. *
  40. * @since 4.0.3
  41. *
  42. * @static
  43. * @return boolean TRUE if multi domains mapping enabled, otherwise FALSE.
  44. */
  45. public static function _is_multi_enabled() {
  46. return defined( 'DOMAINMAPPING_ALLOWMULTI' ) && filter_var( DOMAINMAPPING_ALLOWMULTI, FILTER_VALIDATE_BOOLEAN );
  47. }
  48.  
  49. /**
  50. * Renders instructions how to configure DNS records.
  51. *
  52. * @since 4.0.0
  53. *
  54. * @access private
  55. */
  56. private function _render_instructions() {
  57. if ( trim( $this->map_instructions ) != '' ) {
  58. ?><p class="domainmapping-info"><?php echo $this->map_instructions ?></p><?php
  59. return;
  60. }
  61.  
  62. $descriptions = array();
  63. $descriptions[] = __( 'If your domain name includes a sub-domain such as "blog" then you can add a CNAME for that hostname in your DNS pointing at this blog URL.', 'domainmap' );
  64.  
  65. $map_ipaddress = isset( $this->map_ipaddress ) ? trim( $this->map_ipaddress ) : '';
  66. if ( !empty( $map_ipaddress ) ) {
  67. if ( strpos( $map_ipaddress, ',' ) ) {
  68. $descriptions[] = __( 'If you want to redirect a domain you will need to add multiple DNS "A" records pointing at the IP addresses of this server: ', 'domainmap' ) . "<strong>{$map_ipaddress}</strong>";
  69. } else {
  70. $descriptions[] = __( 'If you want to redirect a domain you will need to add a DNS "A" record pointing at the IP address of this server: ', 'domainmap' ) . "<strong>{$map_ipaddress}</strong>";
  71. }
  72. }
  73.  
  74. ?><p class="domainmapping-info"><?php echo implode( '<br>', $descriptions ) ?></p><?php
  75. }
  76.  
  77. /**
  78. * Renders tab content.
  79. *
  80. * @since 4.0.0
  81. *
  82. * @access protected
  83. */
  84. protected function _render_tab() {
  85.  
  86. $schema = ( defined( 'DM_FORCE_PROTOCOL_ON_MAPPED_DOMAIN' ) && DM_FORCE_PROTOCOL_ON_MAPPED_DOMAIN && is_ssl() ) ? 'https' : 'http';
  87. $form_class = count( $this->domains ) > 0 && !self::_is_multi_enabled() ? ' domainmapping-form-hidden' : '';
  88. $admin_ajax = esc_url( admin_url( 'admin-ajax.php' ) );
  89.  
  90. $mapping = get_option( 'domainmap_frontend_mapping', 'mapped' );
  91. $mapping_types = array(
  92. 'user' => __( 'disabled and entered domain should be used', 'domainmap' ),
  93. 'mapped' => __( 'directed to mapped (primary) domain', 'domainmap' ),
  94. 'original' => __( 'directed to original domain', 'domainmap' ),
  95. );
  96.  
  97. $this->_render_instructions();
  98.  
  99. ?><div class="domainmapping-domains domainmapping-box">
  100. <h3>
  101. <?php _e( 'Domain(s) mapped to', 'domainmap' ) ?>
  102. <span class="domainmapping-origin"><?php echo $schema ?>://<?php echo esc_html( $this->origin->domain . $this->origin->path ) ?></span>
  103. </h3>
  104. <div class="domainmapping-domains-wrapper domainmapping-box-content<?php echo $form_class ?>">
  105. <div class="domainmapping-locker"></div>
  106. <ul class="domainmapping-domains-list">
  107. <li>
  108. <span class="domainmapping-mapped"><?php _e( 'Mapped domain', 'domainmap' ) ?></span>
  109. <span class="domainmapping-map-state"><?php _e( 'Health status', 'domainmap' ) ?></span>
  110. <span class="domainmapping-map-remove"><?php _e( 'Actions', 'domainmap' ) ?></span>
  111. </li>
  112. <?php foreach( $this->domains as $row ) : ?>
  113. <?php self::render_mapping_row( $row ) ?>
  114. <?php endforeach; ?>
  115. <li class="domainmapping-form">
  116. <form id="domainmapping-front-mapping" action="<?php echo $admin_ajax ?>" method="post">
  117. <?php wp_nonce_field( Domainmap_Plugin::ACTION_CHANGE_FRONTEND_REDIRECT, 'nonce' ) ?>
  118. <input type="hidden" name="action" value="<?php echo Domainmap_Plugin::ACTION_CHANGE_FRONTEND_REDIRECT ?>">
  119. <span><?php esc_html_e( 'Front end redirect should be', 'domainmap' ) ?></span>
  120. <select name="mapping">
  121. <?php foreach ( $mapping_types as $key => $label ) : ?>
  122. <option value="<?php echo $key ?>"<?php selected( $key, $mapping ) ?>><?php echo esc_html( $label ) ?></option>
  123. <?php endforeach; ?>
  124. </select>
  125. </form>
  126. <form id="domainmapping-form-map-domain" action="<?php echo $admin_ajax ?>" method="post">
  127. <?php wp_nonce_field( Domainmap_Plugin::ACTION_MAP_DOMAIN, 'nonce' ) ?>
  128. <input type="hidden" name="action" value="<?php echo Domainmap_Plugin::ACTION_MAP_DOMAIN ?>">
  129. <select type="text" name="scheme" class="domainmapping-input-prefix">
  130. <option value="0">http://</option>
  131. <option value="1">https://</option>
  132. <option value="2"><?php _e("Force none", domain_map::Text_Domain); ?></option>
  133. </select>
  134. <div class="domainmapping-controls-wrapper">
  135. <input type="text" class="domainmapping-input-domain" autofocus name="domain">
  136. </div>
  137. <input type="text" class="domainmapping-input-sufix" readonly disabled value="/">
  138. <button type="submit" class="button button-primary domainmapping-button dashicons-before dashicons-admin-site"><?php _e( 'Map domain', 'domainmap' ) ?></button>
  139. <i class="icon-globe icon-white"></i>
  140. <div class="domainmapping-clear"></div>
  141. </form>
  142. </li>
  143. </ul>
  144. <br/>
  145.  
  146. </div>
  147.  
  148. </div>
  149.  
  150.  
  151.  
  152. <?php
  153.  
  154. }
  155.  
  156. /**
  157. * Renders domain mapping row.
  158. *
  159. * @since 4.0.0
  160. *
  161. * @static
  162. * @access public
  163. * @global stdClass $current_site Current site object.
  164. * @param object $row The mapped domain name.
  165. * @param string $schema The current schema.
  166. */
  167. public static function render_mapping_row( $row, $schema = false ) {
  168. global $current_site;
  169.  
  170. if ( !$schema ) {
  171. switch( Domainmap_Module::force_ssl_on_mapped_domain( $row->domain ) ){
  172. case 1:
  173. $schema = 'https';
  174. break;
  175. case 2:
  176. $schema = '<del>http</del>';
  177. break;
  178. default:
  179. $schema = 'http';
  180. break;
  181. }
  182. }
  183.  
  184. $multi = self::_is_multi_enabled();
  185. $admin_ajax = admin_url( 'admin-ajax.php' ) ;
  186.  
  187. $remove_link = esc_url( add_query_arg( array(
  188. 'action' => Domainmap_Plugin::ACTION_UNMAP_DOMAIN,
  189. 'nonce' => wp_create_nonce( Domainmap_Plugin::ACTION_UNMAP_DOMAIN ),
  190. 'domain' => $row->domain,
  191. ), $admin_ajax ) );
  192.  
  193. $toggle_scheme_link = esc_url( add_query_arg( array(
  194. 'action' => Domainmap_Plugin::ACTION_TOGGLE_SCHEME,
  195. 'nonce' => wp_create_nonce( Domainmap_Plugin::ACTION_TOGGLE_SCHEME ),
  196. 'domain' => $row->domain,
  197. ), $admin_ajax ) );
  198. // if multi domains mapping enabled, then add ability to select primary domain
  199. if ( $multi ) {
  200. $primary_class = $row->is_primary == 1 ? 'dashicons-star-filled' : 'dashicons-star-empty';
  201. $select_primary = esc_url( add_query_arg( array(
  202. 'action' => Domainmap_Plugin::ACTION_SELECT_PRIMARY_DOMAIN,
  203. 'nonce' => wp_create_nonce( Domainmap_Plugin::ACTION_SELECT_PRIMARY_DOMAIN ),
  204. 'domain' => $row->domain,
  205. ), $admin_ajax ) );
  206. $deselect_primary = esc_url( add_query_arg( array(
  207. 'action' => Domainmap_Plugin::ACTION_DESELECT_PRIMARY_DOMAIN,
  208. 'nonce' => wp_create_nonce( Domainmap_Plugin::ACTION_DESELECT_PRIMARY_DOMAIN ),
  209. 'domain' => $row->domain,
  210. ), $admin_ajax ) );
  211.  
  212. }
  213.  
  214. ?><li>
  215. <a class="domainmapping-map-toggle-scheme dashicons-before dashicons-admin-network" href="#" data-href="<?php echo esc_url( $toggle_scheme_link ) ?>" title="<?php _e( 'Toggle forced schema', 'domainmap' ) ?>"></a>
  216.  
  217. <a class="domainmapping-mapped" href="<?php echo strip_tags($schema) ?>://<?php echo $row->domain?>" target="_blank" title="<?php _e( 'Go to this domain', 'domainmap' ) ?>">
  218. <?php echo $schema ?>://<?php echo Domainmap_Punycode::decode( $row->domain ) ?>
  219. </a>
  220.  
  221. <?php self::render_health_column( $row->domain ) ?>
  222. <a class="domainmapping-map-remove dashicons-before dashicons-trash" href="#" data-href="<?php echo esc_url( $remove_link ) ?>" title="<?php _e( 'Remove the domain', 'domainmap' ) ?>"></a>
  223. <?php if ( $multi ) : ?>
  224. <a class="domainmapping-map-primary dashicons-before <?php echo $primary_class ?>" href="#" data-select-href="<?php echo $select_primary ?>" data-deselect-href="<?php echo $deselect_primary ?>" title="<?php _e( 'Select as primary domain', 'domainmap' ) ?>"></a>
  225. <?php endif; ?>
  226. </li><?php
  227. }
  228.  
  229. /**
  230. * Renders health check status column.
  231. *
  232. * @since 4.0.0
  233. *
  234. * @static
  235. * @access public
  236. * @param string $domain The domain name.
  237. */
  238. public static function render_health_column( $domain ) {
  239. $health_link = add_query_arg( array(
  240. 'action' => Domainmap_Plugin::ACTION_HEALTH_CHECK,
  241. 'nonce' => wp_create_nonce( Domainmap_Plugin::ACTION_HEALTH_CHECK ),
  242. 'domain' => $domain,
  243. ), admin_url( 'admin-ajax.php' ) );
  244.  
  245. $health = get_site_transient( "domainmapping-{$domain}-health" );
  246.  
  247. $health_message = __( 'needs revalidation', 'domainmap' );
  248. $health_class = ' domainmapping-need-revalidate';
  249. if ( $health !== false ) {
  250. if ( $health ) {
  251. $health_class = ' domainmapping-valid-domain';
  252. $health_message = __( 'valid', 'domainmap' );
  253. } else {
  254. $health_class = ' domainmapping-invalid-domain';
  255. $health_message = __( 'invalid', 'domainmap' );
  256. }
  257. }
  258.  
  259. ?><a class="domainmapping-map-state<?php echo $health_class ?>" href="<?php echo $health_link ?>" title="<?php _e( 'Refresh health status', 'domainmap' ) ?>"><?php
  260. echo $health_message
  261. ?></a><?php
  262. }
  263.  
  264.  
  265. /**
  266. * Renders excluded pages list
  267. *
  268. * @since 4.3.0
  269. *
  270. */
  271. private function _render_excluded_pages(){
  272.  
  273. /**
  274. * @param $page WP_Post
  275. */
  276. ?>
  277.  
  278. <h3 title="<?php _e("Pages selected here will not be mapped and can optionally force https", domain_map::Text_Domain); ?>">
  279. <span class="dashicons-before dashicons-admin-comments"></span>
  280. <?php _e("Excluded pages: ", domain_map::Text_Domain); ?>
  281. <span class="description">
  282. <?php _e('Pages selected here will not be mapped and can optionally force https, If you set the domain to use https, the following "force/unforce SSL will be ignored" ', domain_map::Text_Domain); ?>
  283. </span>
  284. </h3>
  285. <br/>
  286. <?php
  287. $table = new Domainmap_Table_ExcludedPages_Listing();
  288. $table->prepare_items();
  289. $table->display();
  290. ?>
  291. <form method="post" id="dm_save_excluded_pages_form" action="<?php echo add_query_arg( 'noheader', 'true' ) ?>">
  292. <input type="hidden" name="page" value="domainmapping"/>
  293. <input type="hidden" name="paged" value="<?php echo isset( $_REQUEST['paged'] ) ? $_REQUEST['paged'] : "" ?>"/>
  294. <?php wp_nonce_field("save-exluded-pages", "_save-exluded-pages"); ?>
  295. <input type="hidden" name="dm_excluded_pages" id="dm_exluded_pages_hidden_field" value="<?php echo Domainmap_Module_Mapping::get_excluded_pages(); ?>"/>
  296. <input type="hidden" name="dm_ssl_forced_pages" id="dm_ssl_forced_pages_hidden_field" value="<?php echo Domainmap_Module_Mapping::get_ssl_forced_pages(); ?>"/>
  297.  
  298. <h4 class="domain-mapping-or-urls-title">
  299. <?php _e('Add page urls bellow to have excluded:', domain_map::Text_Domain); ?>
  300. </h4>
  301. <textarea name="dm_excluded_page_urls" id="dm_excluded_page_urls" rows="4"> <?php echo esc_html(Domainmap_Module_Mapping::get_excluded_page_urls()); ?></textarea>
  302. <p class="description">
  303. <?php _e('Please enter absolute URLs (starting with http:// or https://), URLs should be comma separated', domain_map::Text_Domain); ?>
  304. </p>
  305. <br/>
  306. <br/>
  307. <h4 class="domain-mapping-or-urls-title">
  308. <?php _e('Add page urls bellow to force https:', domain_map::Text_Domain); ?>
  309. </h4>
  310. <textarea name="dm_ssl_forced_page_urls" id="dm_ssl_forced_page_urls" rows="4"> <?php echo esc_html(Domainmap_Module_Mapping::get_ssl_forced_page_urls()); ?></textarea>
  311. <p class="description">
  312. <?php _e('Please enter absolute URLs (starting with http:// or https://), URLs should be comma separated', domain_map::Text_Domain); ?>
  313. </p>
  314. <?php submit_button( __( 'Save excluded pages', domain_map::Text_Domain ), 'primary', "dm-save-exluded-pages", false, array( 'id' => 'save-exluded-pages' ) ); ?>
  315. </form>
  316. <?php
  317.  
  318. }
  319.  
  320. /**
  321. * Updates excluded pages
  322. *
  323. * @since 4.3.0
  324. */
  325. private function _save_excluded_pages() {
  326. if( isset( $_POST['dm-save-exluded-pages'] ) && wp_verify_nonce($nonce = filter_input( INPUT_POST, "_save-exluded-pages" ), "save-exluded-pages") ){
  327. update_option( "dm_excluded_pages", strip_tags($_POST['dm_excluded_pages']) );
  328. update_option( "dm_ssl_forced_pages", strip_tags($_POST['dm_ssl_forced_pages']) );
  329. update_option( "dm_excluded_page_urls", strip_tags($_POST['dm_excluded_page_urls']) );
  330. update_option( "dm_ssl_forced_page_urls", strip_tags($_POST['dm_ssl_forced_page_urls']) );
  331. if ( filter_input( INPUT_GET, 'noheader', FILTER_VALIDATE_BOOLEAN ) ) {
  332. wp_safe_redirect( add_query_arg( array( 'noheader' => false, 'saved' => 'true' ) ) );
  333. exit;
  334. }
  335. }
  336.  
  337. }
  338.  
  339. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement