wp-plugin-dev-classes
11 years ago
class-admin-external-links.php
11 years ago
class-wp-external-links.php
11 years ago
phpQuery.php
11 years ago
class-admin-external-links.php
666 lines
| 1 | <?php defined( 'ABSPATH' ) OR die( 'No direct access.' ); |
| 2 | if ( ! class_exists( 'Admin_External_Links' ) ): |
| 3 | |
| 4 | /** |
| 5 | * Class Admin_External_Links |
| 6 | * @category WordPress Plugins |
| 7 | */ |
| 8 | final class Admin_External_Links { |
| 9 | |
| 10 | /** |
| 11 | * Options to be saved and their default values |
| 12 | * @var array |
| 13 | */ |
| 14 | public $save_options = array( |
| 15 | 'meta' => array( |
| 16 | 'version' => NULL, |
| 17 | ), |
| 18 | 'main' => array( |
| 19 | 'target' => '_none', |
| 20 | 'filter_page' => 1, |
| 21 | 'filter_posts' => 1, |
| 22 | 'filter_comments' => 1, |
| 23 | 'filter_widgets' => 1, |
| 24 | 'ignore' => '//twitter.com/share', |
| 25 | ), |
| 26 | 'seo' => array( |
| 27 | 'external' => 1, |
| 28 | 'nofollow' => 1, |
| 29 | 'overwrite_follow' => 0, |
| 30 | 'title' => '%title%', |
| 31 | 'use_js' => 1, |
| 32 | 'load_in_footer' => 1, |
| 33 | ), |
| 34 | 'style' => array( |
| 35 | 'class_name' => 'ext-link', |
| 36 | 'icon' => 0, |
| 37 | 'image_no_icon' => 1, |
| 38 | 'no_icon_class' => 'no-ext-icon', |
| 39 | 'no_icon_same_window' => 0, |
| 40 | ), |
| 41 | 'extra' => array( |
| 42 | 'fix_js' => 0, |
| 43 | 'phpquery' => 0, |
| 44 | 'filter_excl_sel' => '.excl-ext-link', |
| 45 | ), |
| 46 | 'screen' => array( |
| 47 | 'menu_position' => NULL, |
| 48 | ), |
| 49 | ); |
| 50 | |
| 51 | /** |
| 52 | * Meta box page object |
| 53 | * @var WP_Meta_Box_Page |
| 54 | */ |
| 55 | public $meta_box_page = NULL; |
| 56 | |
| 57 | /** |
| 58 | * Ajax form object |
| 59 | * @var WP_Ajax_Option_Form |
| 60 | */ |
| 61 | public $form = NULL; |
| 62 | static public $staticForm = NULL; |
| 63 | |
| 64 | |
| 65 | /** |
| 66 | * Constructor |
| 67 | */ |
| 68 | public function __construct() { |
| 69 | $this->check_version_update(); |
| 70 | |
| 71 | // set meta box page |
| 72 | $this->meta_box_page = new WP_Meta_Box_Page_01(); |
| 73 | |
| 74 | // set ajax forms (also used by front-end) |
| 75 | $this->form = new WP_Option_Forms_01( WP_EXTERNAL_LINKS_KEY, $this->save_options ); |
| 76 | self::$staticForm = $this->form; |
| 77 | |
| 78 | // init admin |
| 79 | add_action( 'admin_init', array( $this, 'admin_init' ) ); |
| 80 | |
| 81 | if ( is_admin() ) { |
| 82 | // set options for add_page_method |
| 83 | $menu_pos = $this->form->set_current_option( 'screen' )->value( 'menu_position' ); |
| 84 | |
| 85 | // init meta box page |
| 86 | $this->meta_box_page->init( |
| 87 | // settings |
| 88 | array( |
| 89 | 'page_title' => $this->__( 'WP External Links' ), |
| 90 | 'menu_title' => $this->__( 'External Links' ), |
| 91 | 'page_slug' => strtolower( WP_EXTERNAL_LINKS_KEY ), |
| 92 | 'add_page_method' => ( ! empty( $menu_pos ) AND $menu_pos != 'admin.php' ) ? 'add_submenu_page' : 'add_menu_page', |
| 93 | 'parent_slug' => ( ! empty( $menu_pos ) AND $menu_pos != 'admin.php' ) ? $menu_pos : NULL, |
| 94 | 'column_widths' => array( |
| 95 | 1 => array( 99 ), |
| 96 | 2 => array( 69, 29 ), |
| 97 | ), |
| 98 | 'icon_url' => plugins_url( 'images/icon-wp-external-links-16.png', WP_EXTERNAL_LINKS_FILE ), |
| 99 | ), |
| 100 | // load callback |
| 101 | array( $this, 'call_load_meta_box' ) |
| 102 | ); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Initialize Admin |
| 108 | */ |
| 109 | public function admin_init() { |
| 110 | // set uninstall hook |
| 111 | register_uninstall_hook( WP_EXTERNAL_LINKS_FILE, array( 'Admin_External_Links', 'call_uninstall' ) ); |
| 112 | |
| 113 | // load text domain for translations |
| 114 | load_plugin_textdomain( WP_EXTERNAL_LINKS_KEY, FALSE, dirname( plugin_basename( WP_EXTERNAL_LINKS_FILE ) ) . '/lang/' ); |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Add to head of Admin page |
| 119 | */ |
| 120 | public function admin_head() { |
| 121 | echo <<< style |
| 122 | <style type="text/css"> |
| 123 | /* WP External Links */ |
| 124 | .postbox-container { margin-left:1%; } |
| 125 | .tooltip-help { text-decoration: none; } |
| 126 | .tipsy { padding: 5px; } |
| 127 | .tipsy-inner { padding: 5px 8px 4px 8px; color: white; max-width: 200px; text-align: center; text-shadow: 0 -1px 0 #333; |
| 128 | border-top:1px solid #808080; border-botom:1px solid #6d6d6d; -webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px; |
| 129 | background-color:#777; background-image:-ms-linear-gradient(bottom,#6d6d6d,#808080); background-image:-moz-linear-gradient(bottom,#6d6d6d,#808080); background-image:-o-linear-gradient(bottom,#6d6d6d,#808080); background-image:-webkit-gradient(linear,left bottom,left top,from(#6d6d6d),to(#808080)); background-image:-webkit-linear-gradient(bottom,#6d6d6d,#808080); background-image:linear-gradient(bottom,#6d6d6d,#808080); |
| 130 | } |
| 131 | .tipsy-north { background-position: top center; } |
| 132 | .tipsy-south { background-position: bottom center; } |
| 133 | .tipsy-east { background-position: right center; } |
| 134 | .tipsy-west { background-position: center bottom; } |
| 135 | <style> |
| 136 | style; |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Translate text in current domain |
| 141 | * @param string $text |
| 142 | * @return string |
| 143 | */ |
| 144 | public function __( $text ) { |
| 145 | return translate( $text, WP_EXTERNAL_LINKS_KEY ); |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Translate text in current domain |
| 150 | * @param string $text |
| 151 | * @return string |
| 152 | */ |
| 153 | public function _e( $text ) { |
| 154 | echo translate( $text, WP_EXTERNAL_LINKS_KEY ); |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * Load meta box action |
| 159 | */ |
| 160 | public function call_load_meta_box( $meta_box ) { |
| 161 | add_action( 'admin_head', array($this, 'admin_head') ); |
| 162 | |
| 163 | // add filters |
| 164 | $meta_box->add_title_filter( array( $this, 'call_page_title' ) ) |
| 165 | ->add_contextual_help_filter( array( $this, 'call_contextual_help' ) ); |
| 166 | |
| 167 | // add meta boxes |
| 168 | // add_meta_box( $title, $callback, $context = 'normal', $id = NULL, $priority = 'default', $callback_args = NULL ) |
| 169 | $meta_box->add_meta_box( $this->__( 'General Settings' ), array( $this, 'call_box_general_settings' ), 1 ) |
| 170 | ->add_meta_box( $this->__( 'SEO Settings' ), array( $this, 'call_box_seo_settings' ), 1 ) |
| 171 | ->add_meta_box( $this->__( 'Style Settings' ), array( $this, 'call_box_style_settings' ), 1 ) |
| 172 | ->add_meta_box( $this->__( 'Extra Settings' ), array( $this, 'call_box_extra_settings' ), 1 ) |
| 173 | ->add_meta_box( $this->__( 'Admin Settings' ), array( $this, 'call_box_admin_settings' ), 1 ) |
| 174 | //->add_meta_box( $this->__( 'About this Plugin' ), array( $this, 'call_box_about' ), 2 ) |
| 175 | ->add_meta_box( $this->__( 'Other Plugins' ), array( $this, 'call_box_other_plugins' ), 2 ); |
| 176 | |
| 177 | // scripts |
| 178 | wp_enqueue_script( 'admin-wp-external-links', plugins_url( '/js/admin-wp-external-links.js', WP_EXTERNAL_LINKS_FILE ), array( 'jquery', 'postbox' ), WP_EXTERNAL_LINKS_VERSION, true ); |
| 179 | } |
| 180 | |
| 181 | /** |
| 182 | * Contextual_help (callback) |
| 183 | * @param string $content |
| 184 | * @return string |
| 185 | */ |
| 186 | public function call_contextual_help( $content ) { |
| 187 | $help = ''; |
| 188 | $help .= $this->meta_box_page->get_ob_callback( array( $this, 'call_box_about' ) ); |
| 189 | return $help . $content; |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * Add icon to page title |
| 194 | * @return string |
| 195 | */ |
| 196 | public function call_page_title( $title ) { |
| 197 | // when updated set the update message |
| 198 | if ( isset($_GET[ 'settings-updated' ]) && $_GET[ 'settings-updated' ] == 'true' ) { |
| 199 | $title .= '<div class="updated settings-error" id="setting-error-settings_updated">' |
| 200 | . '<p><strong>' . __( 'Settings saved.' ) .'</strong></p>' |
| 201 | . '</div>'; |
| 202 | } |
| 203 | |
| 204 | $title = '<div class="icon32" id="icon-options-custom" style="background:url( '. plugins_url( 'images/icon-wp-external-links-32.png', WP_EXTERNAL_LINKS_FILE ) .' ) no-repeat 50% 50%"><br></div>' |
| 205 | . $title; |
| 206 | |
| 207 | return $title; |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * Meta Box: General Settings |
| 212 | */ |
| 213 | public function call_box_general_settings() { |
| 214 | echo $this->form->set_current_option( 'main' )->open_form(); |
| 215 | ?> |
| 216 | <fieldset class="options"> |
| 217 | <table class="form-table"> |
| 218 | <tr> |
| 219 | <th style="width:250px;"><?php $this->_e( 'Open external links in...' ) ?> |
| 220 | <?php echo $this->tooltip_help( 'Specify the target (window or tab) for opening external links.' ) ?></th> |
| 221 | <td class="target_external_links"> |
| 222 | <label><?php echo $this->form->radio( 'target', '_none', array( 'class' => 'field_target' ) ); ?> |
| 223 | <span><?php $this->_e( 'Same window or tab (<code>_none</code>)' ) ?></span></label> |
| 224 | <?php echo $this->tooltip_help( 'Open in current window or tab, when framed in the same frame.' ) ?> |
| 225 | <br/> |
| 226 | <label><?php echo $this->form->radio( 'target', '_blank', array( 'class' => 'field_target' ) ); ?> |
| 227 | <span><?php $this->_e( 'New window or tab (<code>_blank</code>)' ) ?></span></label> |
| 228 | <?php echo $this->tooltip_help( 'Open every external link in a new window or tab.' ) ?> |
| 229 | <br style="margin-bottom:15px;" /> |
| 230 | <label><?php echo $this->form->radio( 'target', '_top', array( 'class' => 'field_target' ) ); ?> |
| 231 | <span><?php $this->_e( 'Topmost frame (<code>_top</code>)' ) ?></span></label> |
| 232 | <?php echo $this->tooltip_help( 'Open in current window or tab, when framed in the topmost frame.' ) ?> |
| 233 | <br/> |
| 234 | <label><?php echo $this->form->radio( 'target', '_new', array( 'class' => 'field_target' ) ); ?> |
| 235 | <span><?php $this->_e( 'Seperate window or tab (<code>_new</code>)' ) ?></span></label> |
| 236 | <?php echo $this->tooltip_help( 'Open new window the first time and use this window for each external link.' ) ?> |
| 237 | </td> |
| 238 | </tr> |
| 239 | <tr> |
| 240 | <th style="width:250px;"><?php $this->_e( 'Apply plugin settings on...' ) ?> |
| 241 | <?php echo $this->tooltip_help( 'Choose contents for applying settings to external links.' ) ?></th> |
| 242 | <td> |
| 243 | <label><?php echo $this->form->checkbox( 'filter_page', 1 ); ?> |
| 244 | <span><?php $this->_e( 'All contents' ) ?></span> <span class="description"><?php $this->_e('(the whole <code><body></code>)') ?></span></label> |
| 245 | <br/> <label><?php echo $this->form->checkbox( 'filter_posts', 1 ); ?> |
| 246 | <span><?php $this->_e( 'Post contents' ) ?></span></label> |
| 247 | <br/> <label><?php echo $this->form->checkbox( 'filter_comments', 1 ); ?> |
| 248 | <span><?php $this->_e( 'Comments' ) ?></span></label> |
| 249 | <br/> <label><?php echo $this->form->checkbox( 'filter_widgets', 1 ); ?> |
| 250 | <span><?php |
| 251 | if ( self::check_widget_content_filter() ): |
| 252 | $this->_e( 'All widgets' ); |
| 253 | echo $this->tooltip_help( 'Applied to all widgets by using the "widget_content" filter of the Widget Logic plugin' ); |
| 254 | else: |
| 255 | $this->_e( 'All text widgets' ); |
| 256 | echo $this->tooltip_help( 'Only the text widget will be applied. To apply to all widget you should select "All contents" option.' ); |
| 257 | endif; |
| 258 | ?></span></label> |
| 259 | </td> |
| 260 | </tr> |
| 261 | <tr> |
| 262 | <th><?php $this->_e( 'Ignore links (URL) containing...' ) ?> |
| 263 | <?php echo $this->tooltip_help( 'This plugin will completely ignore links that contain one of the given texts in the URL. Use enter to seperate each text. This check is not case sensitive.' ) ?></th> |
| 264 | <td><label><?php echo $this->form->textarea( 'ignore' ); ?> |
| 265 | <span class="description"><?php _e( 'Be as specific as you want, f.e.: <code>twitter.com</code> or <code>https://twitter.com</code>. Seperate each by an enter.' ) ?></span></label> |
| 266 | </td> |
| 267 | </tr> |
| 268 | </table> |
| 269 | </fieldset> |
| 270 | |
| 271 | <?php |
| 272 | echo $this->form->submit(); |
| 273 | echo $this->form->close_form(); |
| 274 | } |
| 275 | |
| 276 | /** |
| 277 | * Meta Box: SEO Settings |
| 278 | */ |
| 279 | public function call_box_seo_settings() { |
| 280 | echo $this->form->set_current_option( 'seo' )->open_form(); |
| 281 | ?> |
| 282 | <fieldset class="options"> |
| 283 | <table class="form-table"> |
| 284 | <tr> |
| 285 | <th style="width:250px;"><?php $this->_e( 'Add to <code>rel</code>-attribute' ) ?> |
| 286 | <?php echo $this->tooltip_help( 'Set values for the "rel"-atribute of external links.' ) ?></th> |
| 287 | <td><label><?php echo $this->form->checkbox( 'nofollow', 1 ); ?> |
| 288 | <span><?php $this->_e( 'Add <code>"nofollow"</code> to external links' ) ?></span></label> |
| 289 | <?php echo $this->tooltip_help( 'Add "nofollow" to the "rel"-attribute of external links (unless link already has "follow").' ) ?> |
| 290 | <br/> <label><?php echo $this->form->checkbox( 'overwrite_follow', 1 ); ?> |
| 291 | <span><?php $this->_e( 'Also apply to external links containing <code>"follow"</code>' ) ?></span></label> |
| 292 | <?php echo $this->tooltip_help( 'Also change external links with "follow" to "nofollow".' ) ?> |
| 293 | |
| 294 | <br/><br/> |
| 295 | <label><?php echo $this->form->checkbox( 'external', 1 ); ?> |
| 296 | <span><?php $this->_e( 'Add <code>"external"</code>' ) ?></span></label> |
| 297 | <?php echo $this->tooltip_help( 'Add "external" to the "rel"-attribute of external links.' ) ?> |
| 298 | </td> |
| 299 | </tr> |
| 300 | <tr> |
| 301 | <th><?php $this->_e( 'Set <code>title</code>-attribute' ) ?> |
| 302 | <?php echo $this->tooltip_help( 'Set title attribute for external links. Use %title% for the original title value.' ) ?></th> |
| 303 | <td><label><?php echo $this->form->text( 'title' ); ?> |
| 304 | <br/><span class="description"><?php _e( 'Use <code>%title%</code> for the original title value.' ) ?></span></label></td> |
| 305 | </tr> |
| 306 | <tr> |
| 307 | <th><?php $this->_e( 'Use JavaScript method' ) ?> |
| 308 | <?php echo $this->tooltip_help( 'Enable this option to use the JavaScript method for opening links, which prevents adding target attribute in the HTML code.' ) ?></label> |
| 309 | </th> |
| 310 | <td> |
| 311 | <label><?php echo $this->form->checkbox( 'use_js', 1, array( 'class' => 'field_use_js' ) ); ?> |
| 312 | <span><?php $this->_e( 'Use JavaScript for opening links' ) ?></span> <span class="description"><?php $this->_e( '(valid xhtml strict)' ) ?></span> |
| 313 | <br/> |
| 314 | <label><?php echo $this->form->checkbox( 'load_in_footer', 1, array( 'class' => 'load_in_footer' ) ); ?> |
| 315 | <span><?php $this->_e( 'Load JS file in footer' ) ?></span> |
| 316 | </td> |
| 317 | </tr> |
| 318 | </table> |
| 319 | </fieldset> |
| 320 | <?php |
| 321 | echo $this->form->submit(); |
| 322 | echo $this->form->close_form(); |
| 323 | } |
| 324 | |
| 325 | /** |
| 326 | * Meta Box: Style Settings |
| 327 | */ |
| 328 | public function call_box_style_settings() { |
| 329 | echo $this->form->set_current_option( 'style' )->open_form(); |
| 330 | ?> |
| 331 | <fieldset class="options"> |
| 332 | <table class="form-table"> |
| 333 | <tr> |
| 334 | <th style="width:250px;"><?php $this->_e( 'Set icon for external link' ) ?> |
| 335 | <?php echo $this->tooltip_help( 'Set an icon that wll be shown for external links. See example on the right side.' ) ?></th> |
| 336 | <td> |
| 337 | <div> |
| 338 | <div style="width:15%;float:left"> |
| 339 | <label><?php echo $this->form->radio( 'icon', 0 ); ?> |
| 340 | <span><?php $this->_e( 'No icon' ) ?></span></label> |
| 341 | <?php for ( $x = 1; $x <= 20; $x++ ): ?> |
| 342 | <br/> |
| 343 | <label title="<?php echo sprintf( $this->__( 'Icon %1$s: choose this icon to show for all external links or add the class \'ext-icon-%1$s\' to a specific link.' ), $x ) ?>"> |
| 344 | <?php echo $this->form->radio( 'icon', $x ); ?> |
| 345 | <img src="<?php echo plugins_url('images/ext-icons/ext-icon-'. $x .'.png', WP_EXTERNAL_LINKS_FILE) ?>" /></label> |
| 346 | <?php if ( $x % 5 == 0 ): ?> |
| 347 | </div> |
| 348 | <div style="width:15%;float:left"> |
| 349 | <?php endif; ?> |
| 350 | <?php endfor; ?> |
| 351 | </div> |
| 352 | <div style="width:29%;float:left;"><span class="description"><?php $this->_e( 'Example:' ) ?></span> |
| 353 | <br/><img src="<?php echo plugins_url( 'images/link-icon-example.png', WP_EXTERNAL_LINKS_FILE ) ?>" /> |
| 354 | </div> |
| 355 | <br style="clear:both" /> |
| 356 | </div> |
| 357 | </td> |
| 358 | </tr> |
| 359 | <tr> |
| 360 | <th><?php $this->_e( 'Skip images' ) ?> |
| 361 | <?php echo $this->tooltip_help( 'Don\'t show icon for external links containing images.' ) ?></th> |
| 362 | <td><label><?php echo $this->form->checkbox( 'image_no_icon', 1 ); ?> |
| 363 | <span><?php $this->_e( 'No icon for extenal links with images' ) ?></span></label> |
| 364 | </td> |
| 365 | </tr> |
| 366 | <tr> |
| 367 | <th style="width:250px;"><?php $this->_e( 'Set no-icon class' ) ?> |
| 368 | <?php echo $this->tooltip_help( 'Set this class for links, that should not have the external link icon.' ) ?></th> |
| 369 | <td><label><?php echo $this->form->text( 'no_icon_class', array( 'class' => '' ) ); ?></label> |
| 370 | <br/><label><?php echo $this->form->checkbox( 'no_icon_same_window', 1 ); ?> |
| 371 | <span><?php $this->_e( 'Always open links with no-icon class in same window or tab' ) ?></span></label> |
| 372 | <?php echo $this->tooltip_help( 'When enabled external links containing the no-icon class will always be opened in the current window or tab. No matter which target is set.' ) ?> |
| 373 | </td> |
| 374 | </tr> |
| 375 | <tr> |
| 376 | <th><?php $this->_e( 'Add to <code>class</code>-attribute' ) ?> |
| 377 | <?php echo $this->tooltip_help( 'Add one or more extra classes to the external links, seperated by a space. It is optional, else just leave field blank.' ) ?></th> |
| 378 | <td><label><?php echo $this->form->text( 'class_name' ); ?></label></td> |
| 379 | </tr> |
| 380 | </table> |
| 381 | </fieldset> |
| 382 | <?php |
| 383 | echo $this->form->submit(); |
| 384 | echo $this->form->close_form(); |
| 385 | } |
| 386 | |
| 387 | /** |
| 388 | * Meta Box: Extra Settings |
| 389 | */ |
| 390 | public function call_box_extra_settings() { |
| 391 | echo $this->form->set_current_option( 'extra' )->open_form(); |
| 392 | ?> |
| 393 | <fieldset class="options"> |
| 394 | <table class="form-table"> |
| 395 | <tr> |
| 396 | <th style="width:250px;"><?php $this->_e( 'Solving problems' ) ?> |
| 397 | <?php echo $this->tooltip_help( 'Some options to try when a problem occurs. These options can also cause other problems, so be carefull.' ) ?></th> |
| 398 | <td><label><?php echo $this->form->checkbox( 'fix_js', 1 ); ?> |
| 399 | <span><?php $this->_e( 'Replacing <code></a></code> with <code><\/a></code> in JavaScript code.' ) ?></span></label> |
| 400 | <?php echo $this->tooltip_help( 'By replacing </a> with <\/a> in JavaScript code these tags will not be processed by the plugin.' ) ?> |
| 401 | </td> |
| 402 | </tr> |
| 403 | <tr> |
| 404 | <th style="width:250px;"><?php $this->_e( 'Use phpQuery library' ) ?> |
| 405 | <?php echo $this->tooltip_help( 'Using phpQuery library for manipulating links. This option is experimental.' ) ?></th> |
| 406 | <td><label><?php echo $this->form->checkbox( 'phpquery', 1 ); ?> |
| 407 | <span><?php $this->_e( 'Use phpQuery for parsing document.' ) ?></span> |
| 408 | <span class="description">(Test it first!)</span></label> |
| 409 | </td> |
| 410 | </tr> |
| 411 | <tr class="filter_excl_sel" <?php echo ( $this->form->value( 'phpquery' ) ) ? '' : 'style="display:none;"'; ?>> |
| 412 | <th><?php $this->_e( 'Do NOT apply settings on...' ) ?> |
| 413 | <?php echo $this->tooltip_help( 'The external links of these selection will be excluded for the settings of this plugin. Define the selection by using CSS selectors.' ) ?></th> |
| 414 | <td><label><?php echo $this->form->textarea( 'filter_excl_sel' ); ?> |
| 415 | <span class="description"><?php _e( 'Define selection by using CSS selectors, f.e.: <code>.excl-ext-link, .entry-title, #comments-title</code> (look <a href="http://code.google.com/p/phpquery/wiki/Selectors" target="_blank">here</a> for available selectors).' ) ?></span></label> |
| 416 | </td> |
| 417 | </tr> |
| 418 | </table> |
| 419 | </fieldset> |
| 420 | <?php |
| 421 | echo $this->form->submit(); |
| 422 | echo $this->form->close_form(); |
| 423 | } |
| 424 | |
| 425 | /** |
| 426 | * Meta Box: Extra Settings |
| 427 | */ |
| 428 | public function call_box_admin_settings() { |
| 429 | echo $this->form->set_current_option( 'screen' )->open_form(); |
| 430 | ?> |
| 431 | <fieldset class="options"> |
| 432 | <table class="form-table"> |
| 433 | <tr> |
| 434 | <th><?php $this->_e('Admin menu position') ?> |
| 435 | <?php echo $this->tooltip_help( 'Change the menu position of this plugin in "Screen Options".' ) ?></th> |
| 436 | <td><label> |
| 437 | <?php |
| 438 | echo $this->form->select( 'menu_position', array( |
| 439 | 'admin.php' => 'Main menu', |
| 440 | 'index.php' => $this->__( 'Subitem of Dashboard' ), |
| 441 | 'edit.php' => $this->__( 'Subitem of Posts' ), |
| 442 | 'upload.php' => $this->__( 'Subitem of Media' ), |
| 443 | 'link-manager.php' => $this->__( 'Subitem of Links' ), |
| 444 | 'edit.php?post_type=page' => $this->__( 'Subitem of Pages' ), |
| 445 | 'edit-comments.php' => $this->__( 'Subitem of Comments' ), |
| 446 | 'themes.php' => $this->__( 'Subitem of Appearance' ), |
| 447 | 'plugins.php' => $this->__( 'Subitem of Plugins' ), |
| 448 | 'users.php' => $this->__( 'Subitem of Users' ), |
| 449 | 'tools.php' => $this->__( 'Subitem of Tools' ), |
| 450 | 'options-general.php' => $this->__( 'Subitem of Settings' ), |
| 451 | )); |
| 452 | ?> |
| 453 | </label></td> |
| 454 | </tr> |
| 455 | </table> |
| 456 | </fieldset> |
| 457 | <?php |
| 458 | echo $this->form->submit(); |
| 459 | echo $this->form->close_form(); |
| 460 | } |
| 461 | |
| 462 | /** |
| 463 | * Meta Box: About... |
| 464 | */ |
| 465 | public function call_box_about() { |
| 466 | ?> |
| 467 | <h4><img src="<?php echo plugins_url( 'images/icon-wp-external-links-16.png', WP_EXTERNAL_LINKS_FILE ) ?>" width="16" height="16" /> <?php $this->_e( 'WP External Links' ) ?></h4> |
| 468 | <div> |
| 469 | <p><?php printf( $this->__( 'Current version: <strong>%1$s</strong>' ), WP_EXTERNAL_LINKS_VERSION ) ?></p> |
| 470 | <p><?php $this->_e( 'Manage external links on your site: open in new window/tab, set link icon, add "external", add "nofollow" and more.' ) ?></p> |
| 471 | <p><a href="http://www.freelancephp.net/contact/" target="_blank"><?php $this->_e( 'Questions or suggestions?' ) ?></a></p> |
| 472 | <p><?php $this->_e( 'If you like this plugin please send your rating at WordPress.org.' ) ?></p> |
| 473 | <p><?php _e( 'More info' ) ?>: <a href="http://wordpress.org/extend/plugins/wp-external-links/" target="_blank">WordPress.org</a> | <a href="http://www.freelancephp.net/wp-external-links-plugin/" target="_blank">FreelancePHP.net</a></p> |
| 474 | </div> |
| 475 | <?php |
| 476 | } |
| 477 | |
| 478 | /** |
| 479 | * Meta Box: Other Plugins |
| 480 | */ |
| 481 | public function call_box_other_plugins() { |
| 482 | ?> |
| 483 | <h4><img src="<?php echo plugins_url( 'images/icon-email-encoder-bundle-16.png', WP_EXTERNAL_LINKS_FILE ); ?>" width="16" height="16" /> Email Encoder Bundle</h4> |
| 484 | <div> |
| 485 | <?php if ( is_plugin_active( 'email-encoder-bundle/email-encoder-bundle.php' ) ): ?> |
| 486 | <p><?php $this->_e( 'This plugin is already activated.' ) ?> <a href="<?php echo get_bloginfo( 'url' ) ?>/wp-admin/options-general.php?page=email-encoder-bundle/email-encoder-bundle.php"><?php $this->_e( 'Settings' ) ?></a></p> |
| 487 | <?php elseif( file_exists( WP_PLUGIN_DIR . '/email-encoder-bundle/email-encoder-bundle.php' ) ): ?> |
| 488 | <p><a href="<?php echo get_bloginfo( 'url' ) ?>/wp-admin/plugins.php?plugin_status=inactive"><?php $this->_e( 'Activate this plugin.' ) ?></a></p> |
| 489 | <?php else: ?> |
| 490 | <p><a href="<?php echo get_bloginfo( 'url' ) ?>/wp-admin/plugin-install.php?tab=search&type=term&s=Email+Encoder+Bundle+freelancephp&plugin-search-input=Search+Plugins"><?php $this->_e( 'Get this plugin now' ) ?></a></p> |
| 491 | <?php endif; ?> |
| 492 | |
| 493 | <p><?php $this->_e( 'Protect email addresses on your site from spambots and being used for spamming by using one of the encoding methods.' ) ?></p> |
| 494 | <p><?php _e( 'More info' ) ?>: <a href="http://wordpress.org/extend/plugins/email-encoder-bundle/" target="_blank">WordPress.org</a> | <a href="http://www.freelancephp.net/email-encoder-php-class-wp-plugin/" target="_blank">FreelancePHP.net</a></p> |
| 495 | </div> |
| 496 | |
| 497 | <?php echo $this->hr(); ?> |
| 498 | |
| 499 | <h4><img src="<?php echo plugins_url( 'images/icon-wp-mailto-links-16.png', WP_EXTERNAL_LINKS_FILE ); ?>" width="16" height="16" /> WP Mailto Links</h4> |
| 500 | <div> |
| 501 | <?php if ( is_plugin_active( 'wp-mailto-links/wp-mailto-links.php' ) ): ?> |
| 502 | <p><?php $this->_e( 'This plugin is already activated.' ) ?> <a href="<?php echo get_bloginfo( 'url' ) ?>/wp-admin/options-general.php?page=wp-mailto-links/wp-mailto-links.php"><?php $this->_e( 'Settings' ) ?></a></p> |
| 503 | <?php elseif( file_exists( WP_PLUGIN_DIR . '/wp-mailto-links/wp-mailto-links.php' ) ): ?> |
| 504 | <p><a href="<?php echo get_bloginfo( 'url' ) ?>/wp-admin/plugins.php?plugin_status=inactive"><?php $this->_e( 'Activate this plugin.' ) ?></a></p> |
| 505 | <?php else: ?> |
| 506 | <p><a href="<?php echo get_bloginfo( 'url' ) ?>/wp-admin/plugin-install.php?tab=search&type=term&s=WP+Mailto+Links+freelancephp&plugin-search-input=Search+Plugins"><?php $this->_e( 'Get this plugin now' ) ?></a></p> |
| 507 | <?php endif; ?> |
| 508 | |
| 509 | <p><?php $this->_e( 'Manage mailto links on your site and protect emails from spambots, set mail icon and more.' ) ?></p> |
| 510 | <p><?php _e( 'More info' ) ?>: <a href="http://wordpress.org/extend/plugins/wp-mailto-links/" target="_blank">WordPress.org</a> | <a href="http://www.freelancephp.net/wp-mailto-links-plugin/" target="_blank">FreelancePHP.net</a></p> |
| 511 | </div> |
| 512 | <?php |
| 513 | } |
| 514 | |
| 515 | /** |
| 516 | * Activation callback |
| 517 | */ |
| 518 | public function check_version_update() { |
| 519 | // check for version |
| 520 | $meta = get_option( 'wp_external_links-meta' ); |
| 521 | if ( $meta[ 'version' ] == WP_EXTERNAL_LINKS_VERSION ) |
| 522 | return; |
| 523 | |
| 524 | // set new version |
| 525 | $meta[ 'version' ] = WP_EXTERNAL_LINKS_VERSION; |
| 526 | update_option( 'wp_external_links-meta', $meta ); |
| 527 | $this->save_options['meta'] = $meta; |
| 528 | |
| 529 | // check for upgrading saved options to v1.00 |
| 530 | $old_options = get_option( 'WP_External_Links_options' ); |
| 531 | |
| 532 | if ( ! empty( $old_options ) ) { |
| 533 | $new_options = $this->save_options; |
| 534 | |
| 535 | $new_options[ 'main' ][ 'target' ] = $old_options[ 'target' ]; |
| 536 | $new_options[ 'main' ][ 'filter_page' ] = $old_options[ 'filter_whole_page' ]; |
| 537 | $new_options[ 'main' ][ 'filter_posts' ] = $old_options[ 'filter_posts' ]; |
| 538 | $new_options[ 'main' ][ 'filter_comments' ] = $old_options[ 'filter_comments' ]; |
| 539 | $new_options[ 'main' ][ 'filter_widgets' ] = $old_options[ 'filter_widgets' ]; |
| 540 | $new_options[ 'seo' ][ 'external' ] = $old_options[ 'external' ]; |
| 541 | $new_options[ 'seo' ][ 'nofollow' ] = $old_options[ 'nofollow' ]; |
| 542 | $new_options[ 'seo' ][ 'use_js' ] = $old_options[ 'use_js' ]; |
| 543 | $new_options[ 'style' ][ 'class_name' ] = $old_options[ 'class_name' ]; |
| 544 | $new_options[ 'style' ][ 'icon' ] = $old_options[ 'icon' ]; |
| 545 | $new_options[ 'style' ][ 'no_icon_class' ] = $old_options[ 'no_icon_class' ]; |
| 546 | $new_options[ 'style' ][ 'no_icon_same_window' ] = $old_options[ 'no_icon_same_window' ]; |
| 547 | |
| 548 | // save new format option values |
| 549 | update_option( 'wp_external_links-main', $new_options[ 'main' ] ); |
| 550 | update_option( 'wp_external_links-seo', $new_options[ 'seo' ] ); |
| 551 | update_option( 'wp_external_links-style', $new_options[ 'style' ] ); |
| 552 | |
| 553 | // delete old format option values |
| 554 | delete_option( 'WP_External_Links_options' ); |
| 555 | } |
| 556 | |
| 557 | // upgrade to v1.20 |
| 558 | // $upgrade_main = get_option( 'wp_external_links-main' ); |
| 559 | // |
| 560 | // if ( ! isset( $upgrade_main[ 'ignore' ] ) ) { |
| 561 | // $upgrade_main[ 'ignore' ] = $this->save_options[ 'main' ][ 'ignore' ]; |
| 562 | // update_option( 'wp_external_links-main', $upgrade_main ); |
| 563 | // } |
| 564 | |
| 565 | // upgrade to v1.30 |
| 566 | if ( WP_EXTERNAL_LINKS_VERSION == '1.30' ) { |
| 567 | $new_options = $this->save_options; |
| 568 | $general = get_option( 'wp_external_links-general' ); |
| 569 | $style = get_option( 'wp_external_links-style' ); |
| 570 | |
| 571 | if ( isset( $general[ 'target' ] ) ) $new_options[ 'main' ][ 'target' ] = $general[ 'target' ]; |
| 572 | $new_options[ 'main' ][ 'filter_page' ] = ( isset( $general[ 'filter_page' ] ) ) ? $general[ 'filter_page' ] : 0; |
| 573 | $new_options[ 'main' ][ 'filter_posts' ] = ( isset( $general[ 'filter_posts' ] ) ) ? $general[ 'filter_posts' ] : 0; |
| 574 | $new_options[ 'main' ][ 'filter_comments' ] = ( isset( $general[ 'filter_comments' ] ) ) ? $general[ 'filter_comments' ] : 0; |
| 575 | $new_options[ 'main' ][ 'filter_widgets' ] = ( isset( $general[ 'filter_widgets' ] ) ) ? $general[ 'filter_widgets' ] : 0; |
| 576 | if ( isset( $general[ 'ignore' ] ) ) $new_options[ 'main' ][ 'ignore' ] = $general[ 'ignore' ]; |
| 577 | |
| 578 | $new_options[ 'seo' ][ 'external' ] = ( isset( $general[ 'external' ] ) ) ? $general[ 'external' ] : 0; |
| 579 | $new_options[ 'seo' ][ 'nofollow' ] = ( isset( $general[ 'nofollow' ] ) ) ? $general[ 'nofollow' ] : 0; |
| 580 | $new_options[ 'seo' ][ 'use_js' ] = ( isset( $general[ 'use_js' ] ) ) ? $general[ 'use_js' ] : 0; |
| 581 | if ( isset( $general[ 'title' ] ) ) $new_options[ 'seo' ][ 'title' ] = $general[ 'title' ]; |
| 582 | |
| 583 | if ( isset( $general[ 'class_name' ] ) ) $new_options[ 'style' ][ 'class_name' ] = $general[ 'class_name' ]; |
| 584 | |
| 585 | if ( isset( $style[ 'icon' ] ) ) $new_options[ 'style' ][ 'icon' ] = $style[ 'icon' ]; |
| 586 | if ( isset( $style[ 'no_icon_class' ] ) ) $new_options[ 'style' ][ 'no_icon_class' ] = $style[ 'no_icon_class' ]; |
| 587 | $new_options[ 'style' ][ 'no_icon_same_window' ] = ( isset( $style[ 'no_icon_same_window' ] ) ) ? $style[ 'no_icon_same_window' ] : 0; |
| 588 | |
| 589 | $new_options[ 'extra' ][ 'fix_js' ] = ( isset( $general[ 'fix_js' ] ) ) ? $general[ 'fix_js' ] : 0; |
| 590 | $new_options[ 'extra' ][ 'phpquery' ] = ( isset( $general[ 'phpquery' ] ) ) ? $general[ 'phpquery' ] : 0; |
| 591 | if ( isset( $general[ 'filter_excl_sel' ] ) ) $new_options[ 'extra' ][ 'filter_excl_sel' ] = $general[ 'filter_excl_sel' ]; |
| 592 | |
| 593 | // save new format option values |
| 594 | update_option( 'wp_external_links-main', $new_options[ 'main' ] ); |
| 595 | update_option( 'wp_external_links-seo', $new_options[ 'seo' ] ); |
| 596 | update_option( 'wp_external_links-style', $new_options[ 'style' ] ); |
| 597 | update_option( 'wp_external_links-extra', $new_options[ 'extra' ] ); |
| 598 | |
| 599 | // delete old format |
| 600 | delete_option( 'wp_external_links-general' ); |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | /** |
| 605 | * Method for test purpuses |
| 606 | */ |
| 607 | public function __options($values = null) { |
| 608 | if (class_exists('Test_WP_Mailto_Links') && constant('WP_DEBUG') === true) { |
| 609 | if ($values !== null) { |
| 610 | $this->set_options($values); |
| 611 | } |
| 612 | |
| 613 | return $this->options; |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | /** |
| 618 | * Uninstall callback |
| 619 | */ |
| 620 | static public function call_uninstall() { |
| 621 | self::$staticForm->delete_options(); |
| 622 | } |
| 623 | |
| 624 | /** |
| 625 | * Set tooltip help |
| 626 | * @param string $text |
| 627 | * @return string |
| 628 | */ |
| 629 | public function tooltip_help( $text ) { |
| 630 | $text = $this->__( $text ); |
| 631 | $text = htmlentities( $text ); |
| 632 | |
| 633 | $html = '<a href="#" class="tooltip-help" title="'. $text .'"><sup>(?)</sup></a>'; |
| 634 | return $html; |
| 635 | } |
| 636 | |
| 637 | /** |
| 638 | * Get html seperator |
| 639 | * @return string |
| 640 | */ |
| 641 | protected function hr() { |
| 642 | return '<hr style="border:1px solid #FFF; border-top:1px solid #EEE;" />'; |
| 643 | } |
| 644 | |
| 645 | |
| 646 | /** |
| 647 | * Check if widget_content filter is available (Widget Logic Plugin) |
| 648 | * @return boolean |
| 649 | * @static |
| 650 | */ |
| 651 | public static function check_widget_content_filter() { |
| 652 | // set widget_content filter of Widget Logic plugin |
| 653 | $widget_logic_opts = get_option( 'widget_logic' ); |
| 654 | |
| 655 | if ( function_exists( 'widget_logic_expand_control' ) AND is_array( $widget_logic_opts ) AND key_exists( 'widget_logic-options-filter', $widget_logic_opts ) ) |
| 656 | return ( $widget_logic_opts[ 'widget_logic-options-filter' ] == 'checked' ); |
| 657 | |
| 658 | return FALSE; |
| 659 | } |
| 660 | |
| 661 | } // End Admin_External_Links Class |
| 662 | |
| 663 | endif; |
| 664 | |
| 665 | /* ommit PHP closing tag, to prevent unwanted whitespace at the end of the parts generated by the included files */ |
| 666 |