| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
namespace JP\CC\Admin; |
| 5 |
|
| 6 |
use JP_Content_Control; |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
|
| 13 |
class Assets { |
| 14 |
|
| 15 |
public static function init() { |
| 16 |
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'scripts_styles' ) ); |
| 17 |
} |
| 18 |
|
| 19 |
public static function scripts_styles( $hook ) { |
| 20 |
global $post_type; |
| 21 |
|
| 22 |
// Use minified libraries if SCRIPT_DEBUG is turned off |
| 23 |
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
| 24 |
|
| 25 |
if ( $hook == 'widgets.php' ) { |
| 26 |
wp_enqueue_style( 'jpcc-widget-editor', JP_Content_Control::$URL . 'assets/styles/widget-editor' . $suffix . '.css', null, JP_Content_Control::$VER, false ); |
| 27 |
wp_enqueue_script( 'jpcc-widget-editor', JP_Content_Control::$URL . 'assets/scripts/widget-editor' . $suffix . '.js', array( 'jquery' ), JP_Content_Control::$VER, true ); |
| 28 |
} |
| 29 |
|
| 30 |
if ( $hook == 'settings_page_jp-cc-settings' ) { |
| 31 |
|
| 32 |
if ( Settings::active_tab() == 'restrictions' ) { |
| 33 |
add_action( 'admin_footer', array( __CLASS__, 'js_wp_editor' ) ); |
| 34 |
} |
| 35 |
|
| 36 |
Footer_Templates::init(); |
| 37 |
|
| 38 |
wp_enqueue_style( 'jpcc-settings-page', JP_Content_Control::$URL . 'assets/styles/settings-page' . $suffix . '.css', array( 'editor-buttons' ), JP_Content_Control::$VER, false ); |
| 39 |
wp_enqueue_script( 'jpcc-settings-page', JP_Content_Control::$URL . 'assets/scripts/settings-page' . $suffix . '.js', array( |
| 40 |
'jquery', |
| 41 |
'underscore', |
| 42 |
'wp-util', |
| 43 |
'wplink', |
| 44 |
'jquery-ui-sortable', |
| 45 |
), JP_Content_Control::$VER, true ); |
| 46 |
|
| 47 |
wp_localize_script( 'jpcc-settings-page', 'jp_cc_vars', array( |
| 48 |
'nonce' => wp_create_nonce( 'jp-cc-admin-nonce' ), |
| 49 |
'I10n' => array( |
| 50 |
'tabs' => array( |
| 51 |
'general' => __( 'General', 'content-control' ), |
| 52 |
'protection' => __( 'Protection', 'content-control' ), |
| 53 |
'content' => __( 'Content', 'content-control' ), |
| 54 |
), |
| 55 |
'restrictions' => array( |
| 56 |
'confirm_remove' => __( 'Are you sure you want to delete this restriction?', 'content-control' ), |
| 57 |
), |
| 58 |
'restriction_modal' => array( |
| 59 |
'title' => __( 'Restriction Editor', 'content-control' ), |
| 60 |
'description' => __( 'Use this to modify a restrictions settings.', 'content-control' ), |
| 61 |
), |
| 62 |
'conditions' => array( |
| 63 |
'not_operand' => array( |
| 64 |
'is' => __( 'Is', 'content-control' ), |
| 65 |
'not' => __( 'Not', 'content-control' ), |
| 66 |
), |
| 67 |
), |
| 68 |
'save' => __( 'Save', 'content-control' ), |
| 69 |
'cancel' => __( 'Cancel', 'content-control' ), |
| 70 |
'add' => __( 'Add', 'content-control' ), |
| 71 |
'update' => __( 'Update', 'content-control' ), |
| 72 |
), |
| 73 |
) ); |
| 74 |
|
| 75 |
} |
| 76 |
|
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
/* |
| 81 |
* JavaScript Wordpress editor |
| 82 |
* Author: Ante Primorac |
| 83 |
* Author URI: http://anteprimorac.from.hr |
| 84 |
* Version: 1.1 |
| 85 |
* License: |
| 86 |
* Copyright (c) 2013 Ante Primorac |
| 87 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
| 88 |
* of this software and associated documentation files (the "Software"), to deal |
| 89 |
* in the Software without restriction, including without limitation the rights |
| 90 |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 91 |
* copies of the Software, and to permit persons to whom the Software is |
| 92 |
* furnished to do so, subject to the following conditions: |
| 93 |
* |
| 94 |
* The above copyright notice and this permission notice shall be included in |
| 95 |
* all copies or substantial portions of the Software. |
| 96 |
* |
| 97 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 98 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 99 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 100 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 101 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 102 |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 103 |
* THE SOFTWARE. |
| 104 |
* Usage: |
| 105 |
* server side(WP): |
| 106 |
* js_wp_editor( $settings ); |
| 107 |
* client side(jQuery): |
| 108 |
* $('textarea').wp_editor( options ); |
| 109 |
*/ |
| 110 |
public static function js_wp_editor( $settings = array() ) { |
| 111 |
if ( ! class_exists( '\_WP_Editors' ) ) { |
| 112 |
require( ABSPATH . WPINC . '/class-wp-editor.php' ); |
| 113 |
} |
| 114 |
|
| 115 |
/* |
| 116 |
ob_start(); |
| 117 |
wp_editor( '', 'jp_cc_id' ); |
| 118 |
ob_get_clean(); |
| 119 |
*/ |
| 120 |
$set = \_WP_Editors::parse_settings( 'jp_cc_id', $settings ); |
| 121 |
|
| 122 |
if ( ! current_user_can( 'upload_files' ) ) { |
| 123 |
$set['media_buttons'] = false; |
| 124 |
} |
| 125 |
|
| 126 |
if ( $set['media_buttons'] ) { |
| 127 |
wp_enqueue_style( 'buttons' ); |
| 128 |
wp_enqueue_script( 'thickbox' ); |
| 129 |
wp_enqueue_style( 'thickbox' ); |
| 130 |
wp_enqueue_script( 'media-upload' ); |
| 131 |
wp_enqueue_script( 'wp-embed' ); |
| 132 |
|
| 133 |
$post = get_post( 1 ); |
| 134 |
if ( ! $post && ! empty( $GLOBALS['post_ID'] ) ) { |
| 135 |
$post = $GLOBALS['post_ID']; |
| 136 |
} |
| 137 |
wp_enqueue_media( array( |
| 138 |
'post' => $post, |
| 139 |
) ); |
| 140 |
} |
| 141 |
|
| 142 |
\_WP_Editors::editor_settings( 'jp_cc_id', $set ); |
| 143 |
|
| 144 |
$jp_cc_vars = array( |
| 145 |
'url' => get_home_url(), |
| 146 |
'includes_url' => includes_url(), |
| 147 |
); |
| 148 |
|
| 149 |
wp_localize_script( 'jpcc-settings-page', 'jp_cc_wpeditor_vars', $jp_cc_vars ); |
| 150 |
} |
| 151 |
} |