| 1 |
<?php |
| 2 |
|
| 3 |
// Exit if accessed directly |
| 4 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 5 |
|
| 6 |
class Vimeography_Init extends Vimeography { |
| 7 |
public function __construct() { |
| 8 |
add_action( 'init', array($this, 'vimeography_load_text_domain') ); |
| 9 |
add_action( 'init', array($this, 'vimeography_written_block_robots') ); |
| 10 |
add_action( 'init', array($this, 'vimeography_add_gallery_helper') ); |
| 11 |
|
| 12 |
add_action( 'wp_head', array( $this, 'output_referrer_tag' ) ); |
| 13 |
add_action( 'admin_head', array( $this, 'output_referrer_tag') ); |
| 14 |
} |
| 15 |
|
| 16 |
/** |
| 17 |
* Adds a referrer policy to the user's site so that |
| 18 |
* Vimeo videos with a domain restriction are aware |
| 19 |
* of this domain name being the referring domain. |
| 20 |
* |
| 21 |
* @return void |
| 22 |
*/ |
| 23 |
public function output_referrer_tag() { |
| 24 |
$enable = apply_filters( 'vimeography.privacy.enable_referrer', false ); |
| 25 |
|
| 26 |
if ( $enable ) { |
| 27 |
echo '<meta name="referrer" content="origin">'; |
| 28 |
} |
| 29 |
|
| 30 |
return; |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
/** |
| 35 |
* Localization |
| 36 |
* @return [type] [description] |
| 37 |
*/ |
| 38 |
public function vimeography_load_text_domain() { |
| 39 |
load_plugin_textdomain('vimeography', false, dirname( VIMEOGRAPHY_BASENAME ) . '/languages/'); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Writes to the user's ACTUAL robots.txt file (if it exists) to block directories. |
| 44 |
* |
| 45 |
* @access public |
| 46 |
* @return void |
| 47 |
*/ |
| 48 |
public function vimeography_written_block_robots() { |
| 49 |
// Let's check if the user has a custom robots.txt file. |
| 50 |
if ( file_exists( ABSPATH . '/robots.txt' ) ) { |
| 51 |
// See if our rule already exists inside of it. |
| 52 |
$robotstxt = file_get_contents( ABSPATH . '/robots.txt' ); |
| 53 |
$blocked_asset_path = str_ireplace( site_url(), '', VIMEOGRAPHY_ASSETS_URL ); |
| 54 |
|
| 55 |
$disallow_value = $blocked_asset_path === false ? "true" : "false"; |
| 56 |
|
| 57 |
if ( strpos( $robotstxt, 'Disallow: ' . $disallow_value ) ) { |
| 58 |
// Write our rule. |
| 59 |
$robotstxt .= "\nDisallow: " . $blocked_asset_path."\n"; |
| 60 |
file_put_contents(ABSPATH . '/robots.txt', $robotstxt); |
| 61 |
} |
| 62 |
} |
| 63 |
return TRUE; |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* [vimeography_add_gallery_helper description] |
| 68 |
* @return [type] [description] |
| 69 |
*/ |
| 70 |
public function vimeography_add_gallery_helper() { |
| 71 |
if ( in_array(VIMEOGRAPHY_CURRENT_PAGE, array('post.php', 'page.php', 'page-new.php', 'post-new.php')) ) { |
| 72 |
add_action('admin_footer', array(&$this, 'vimeography_add_mce_popup')); |
| 73 |
} |
| 74 |
|
| 75 |
if ( get_user_option('rich_editing') == 'true' ) { |
| 76 |
add_filter( 'mce_external_plugins', array(&$this, 'vimeography_add_editor_plugin' )); |
| 77 |
add_filter( 'mce_buttons', array(&$this, 'vimeography_register_editor_button') ); |
| 78 |
} |
| 79 |
return TRUE; |
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* Action target that displays the popup to insert a form to a post/page. |
| 84 |
* |
| 85 |
* @access public |
| 86 |
* @return void |
| 87 |
*/ |
| 88 |
public function vimeography_add_mce_popup() { |
| 89 |
$mustache = new Mustache_Engine( |
| 90 |
array( |
| 91 |
'loader' => new Mustache_Loader_FilesystemLoader(VIMEOGRAPHY_PATH . 'lib/admin/templates'), |
| 92 |
) |
| 93 |
); |
| 94 |
require_once VIMEOGRAPHY_PATH . 'lib/admin/controllers/vimeography/mce.php'; |
| 95 |
$view = new Vimeography_MCE; |
| 96 |
$template = $mustache->loadTemplate('vimeography/mce'); |
| 97 |
echo $template->render($view); |
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
* [vimeography_add_editor_plugin description] |
| 102 |
* @param [type] $plugin_array [description] |
| 103 |
* @return [type] [description] |
| 104 |
*/ |
| 105 |
public function vimeography_add_editor_plugin( $plugin_array ) { |
| 106 |
$plugin_array['vimeography'] = VIMEOGRAPHY_URL . 'lib/admin/assets/js/mce.js'; |
| 107 |
return $plugin_array; |
| 108 |
} |
| 109 |
|
| 110 |
/** |
| 111 |
* [vimeography_register_editor_button description] |
| 112 |
* @param [type] $buttons [description] |
| 113 |
* @return [type] [description] |
| 114 |
*/ |
| 115 |
public function vimeography_register_editor_button($buttons) { |
| 116 |
array_push( $buttons, "|", "vimeography" ); |
| 117 |
return $buttons; |
| 118 |
} |
| 119 |
|
| 120 |
} |
| 121 |
|