Page Links To - Version 2.9.8

Version Description

  • Added a Russian translation
  • Maintain a reference to WordPress' jQuery version
  • Modernize build tools
Download this release

Release Info

Developer markjaquith
Plugin Icon wp plugin Page Links To
Version 2.9.8
Comparing to
See all releases

Code changes from version 2.9.6 to 2.9.8

bin/install-wp-tests.sh DELETED
@@ -1,79 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- if [ $# -lt 3 ]; then
4
- echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version]"
5
- exit 1
6
- fi
7
-
8
- DB_NAME=$1
9
- DB_USER=$2
10
- DB_PASS=$3
11
- DB_HOST=${4-localhost}
12
- WP_VERSION=${5-latest}
13
-
14
- WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib}
15
- WP_CORE_DIR=/tmp/wordpress/
16
-
17
- set -ex
18
-
19
- install_wp() {
20
- mkdir -p $WP_CORE_DIR
21
-
22
- if [ $WP_VERSION == 'latest' ]; then
23
- local ARCHIVE_URL='https://github.com/WordPress/WordPress/archive/master.tar.gz'
24
- else
25
- local ARCHIVE_NAME="wordpress-$WP_VERSION"
26
- local ARCHIVE_URL="http://wordpress.org/${ARCHIVE_NAME}.tar.gz"
27
- fi
28
-
29
- wget -nv -O /tmp/wordpress.tar.gz $ARCHIVE_URL
30
- tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR
31
-
32
- wget -nv -O $WP_CORE_DIR/wp-content/db.php https://raw.github.com/markoheijnen/wp-mysqli/master/db.php
33
- }
34
-
35
- install_test_suite() {
36
- # portable in-place argument for both GNU sed and Mac OSX sed
37
- if [[ $(uname -s) == 'Darwin' ]]; then
38
- local ioption='-i .bak'
39
- else
40
- local ioption='-i'
41
- fi
42
-
43
- # set up testing suite
44
- mkdir -p $WP_TESTS_DIR
45
- cd $WP_TESTS_DIR
46
- svn co --quiet http://develop.svn.wordpress.org/trunk/tests/phpunit/includes/
47
-
48
- wget -nv -O wp-tests-config.php http://develop.svn.wordpress.org/trunk/wp-tests-config-sample.php
49
- sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR':" wp-tests-config.php
50
- sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" wp-tests-config.php
51
- sed $ioption "s/yourusernamehere/$DB_USER/" wp-tests-config.php
52
- sed $ioption "s/yourpasswordhere/$DB_PASS/" wp-tests-config.php
53
- sed $ioption "s|localhost|${DB_HOST}|" wp-tests-config.php
54
- }
55
-
56
- install_db() {
57
- # parse DB_HOST for port or socket references
58
- local PARTS=(${DB_HOST//\:/ })
59
- local DB_HOSTNAME=${PARTS[0]};
60
- local DB_SOCK_OR_PORT=${PARTS[1]};
61
- local EXTRA=""
62
-
63
- if ! [ -z $DB_HOSTNAME ] ; then
64
- if [[ "$DB_SOCK_OR_PORT" =~ ^[0-9]+$ ]] ; then
65
- EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
66
- elif ! [ -z $DB_SOCK_OR_PORT ] ; then
67
- EXTRA=" --socket=$DB_SOCK_OR_PORT"
68
- elif ! [ -z $DB_HOSTNAME ] ; then
69
- EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
70
- fi
71
- fi
72
-
73
- # create database
74
- mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
75
- }
76
-
77
- install_wp
78
- install_test_suite
79
- install_db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
js/new-tab.coffee CHANGED
@@ -1,13 +1,28 @@
1
  # Grab the right copy of jQuery. Plugins and themes that
2
  # enqueue a custom version of jQuery can go to hell.
3
  do (window) ->
4
- jQ = window.jQueryWP or window.jQuery
5
- jQ ($) ->
6
- if ( typeof $.fn.on is 'function' )
7
- $( 'body' ).on 'click', 'a', (e) ->
8
- i = $ this
9
- i.attr( 'target', '_blank' ) if $.inArray( i.attr('href'), pltNewTabURLs ) > -1
10
- else
11
- # You know what? If you're loading a copy of jQuery that doesn't
12
- # support `.on()`, FUCK YOU and the donkey you rode in on.
13
- console?.log 'Page Links To: Some other code has overridden the WordPress copy of jQuery. This is bad. Because of this, Page Links To cannot open links in a new window.'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  # Grab the right copy of jQuery. Plugins and themes that
2
  # enqueue a custom version of jQuery can go to hell.
3
  do (window) ->
4
+ $ = window.jQueryWP or window.jQuery
5
+
6
+ # Makes an anchor element open in a new tab
7
+ newTab = (el) ->
8
+ $el = $ el
9
+ $el
10
+ .attr 'href', $el.attr('href').replace /#new_tab/, ''
11
+ .attr 'target', '_blank'
12
+
13
+ # Attach click handler immediately
14
+ if typeof $.fn.on is 'function'
15
+ $ document
16
+ .on 'click', 'a[href$="#new_tab"]', (e) ->
17
+ newTab @
18
+ else
19
+ console?.log 'Page Links To: Some other code
20
+ has overridden the WordPress copy of jQuery. This
21
+ is bad. Because of this, Page Links To cannot open
22
+ links in a new window.'
23
+
24
+ # On document ready, transform all new tab anchors
25
+ $ ->
26
+ $ 'a[href$="#new_tab"]'
27
+ .each (i, el) ->
28
+ newTab el
js/new-tab.js DELETED
@@ -1,2 +0,0 @@
1
- // Generated by CoffeeScript 1.6.3
2
- (function(){(function(e){var t;t=e.jQueryWP||e.jQuery;return t(function(e){return typeof e.fn.on=="function"?e("body").on("click","a",function(t){var n;n=e(this);if(e.inArray(n.attr("href"),pltNewTabURLs)>-1)return n.attr("target","_blank")}):typeof console!="undefined"&&console!==null?console.log("Page Links To: Some other code has overridden the WordPress copy of jQuery. This is bad. Because of this, Page Links To cannot open links in a new window."):void 0})})(window)}).call(this);
 
 
js/new-tab.min.js ADDED
@@ -0,0 +1,2 @@
 
 
1
+ (function(){!function(a){var b,c;return b=a.jQueryWP||a.jQuery,c=function(a){var c;return c=b(a),c.attr("href",c.attr("href").replace(/#new_tab/,"")).attr("target","_blank")},"function"==typeof b.fn.on?b(document).on("click",'a[href$="#new_tab"]',function(a){return c(this)}):"undefined"!=typeof console&&null!==console&&console.log("Page Links To: Some other code has overridden the WordPress copy of jQuery. This is bad. Because of this, Page Links To cannot open links in a new window."),b(function(){return b('a[href$="#new_tab"]').each(function(a,b){return c(b)})})}(window)}).call(this);
2
+ //# sourceMappingURL=new-tab.min.js.map
js/new-tab.min.js.map ADDED
@@ -0,0 +1 @@
 
1
+ {"version":3,"sources":["new-tab.js"],"names":["window","$","newTab","jQueryWP","jQuery","el","$el","attr","replace","fn","on","document","e","this","console","log","each","i","call"],"mappings":"CAAA,YACE,SAAUA,GACR,GAAIC,GAAGC,CAgBP,OAfAD,GAAID,EAAOG,UAAYH,EAAOI,OAC9BF,EAAS,SAASG,GAChB,GAAIC,EAEJ,OADAA,GAAML,EAAEI,GACDC,EAAIC,KAAK,OAAQD,EAAIC,KAAK,QAAQC,QAAQ,WAAY,KAAKD,KAAK,SAAU,WAE5D,kBAAZN,GAAEQ,GAAGC,GACdT,EAAEU,UAAUD,GAAG,QAAS,sBAAuB,SAASE,GACtD,MAAOV,GAAOW,QAGO,mBAAZC,UAAuC,OAAZA,SACpCA,QAAQC,IAAI,8JAGTd,EAAE,WACP,MAAOA,GAAE,uBAAuBe,KAAK,SAASC,EAAGZ,GAC/C,MAAOH,GAAOG,QAGjBL,UAEFkB,KAAKL","file":"new-tab.min.js"}
js/page-links-to.js DELETED
@@ -1,2 +0,0 @@
1
- // Generated by CoffeeScript 1.6.1
2
- (function(){jQuery(function(e){var t,n;n=e("#cws-links-to-custom-section");t=e("input[type=radio]","#page-links-to");t.filter('input[value="wp"]').prop("checked")&&n.fadeTo(1,0).hide();return t.change(function(){return e(this).val()==="wp"?n.fadeTo("fast",0,function(){return e(this).slideUp()}):n.slideDown("fast",function(){return e(this).fadeTo("fast",1,function(){var t;t=e("#cws-links-to");return t.focus().val(t.val())})})})})}).call(this);
 
 
js/page-links-to.min.js ADDED
@@ -0,0 +1,2 @@
 
 
1
+ (function(){jQuery(function(a){var b,c;return c=a("#cws-links-to-custom-section"),b=a("input[type=radio]","#page-links-to"),b.filter('input[value="wp"]').prop("checked")&&c.fadeTo(1,0).hide(),b.change(function(){return"wp"===a(this).val()?c.fadeTo("fast",0,function(){return a(this).slideUp()}):c.slideDown("fast",function(){return a(this).fadeTo("fast",1,function(){var b;return b=a("#cws-links-to"),b.focus().val(b.val())})})})})}).call(this);
2
+ //# sourceMappingURL=page-links-to.min.js.map
js/page-links-to.min.js.map ADDED
@@ -0,0 +1 @@
 
1
+ {"version":3,"sources":["page-links-to.js"],"names":["jQuery","$","input","section","filter","prop","fadeTo","hide","change","this","val","slideUp","slideDown","i","focus","call"],"mappings":"CAAA,WACEA,OAAO,SAASC,GACd,GAAIC,GAAOC,CAMX,OALAA,GAAUF,EAAE,gCACZC,EAAQD,EAAE,oBAAqB,kBAC3BC,EAAME,OAAO,qBAAqBC,KAAK,YACzCF,EAAQG,OAAO,EAAG,GAAGC,OAEhBL,EAAMM,OAAO,WAClB,MAAsB,OAAlBP,EAAEQ,MAAMC,MACHP,EAAQG,OAAO,OAAQ,EAAG,WAC/B,MAAOL,GAAEQ,MAAME,YAGVR,EAAQS,UAAU,OAAQ,WAC/B,MAAOX,GAAEQ,MAAMH,OAAO,OAAQ,EAAG,WAC/B,GAAIO,EAEJ,OADAA,GAAIZ,EAAE,iBACCY,EAAEC,QAAQJ,IAAIG,EAAEH,iBAOhCK,KAAKN","file":"page-links-to.min.js"}
languages/page-links-to-ru_RU.mo ADDED
Binary file
languages/page-links-to-ru_RU.po ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: Page-Links-To\n"
4
+ "Report-Msgid-Bugs-To: http://wordpress.org/tag/page-links-to\n"
5
+ "POT-Creation-Date: 2013-06-08 17:42:50+00:00\n"
6
+ "PO-Revision-Date: 2014-02-09 22:12+0400\n"
7
+ "Last-Translator: Vadim Bogaiskov <vadim.bogaiskov@gmail.com>\n"
8
+ "Language-Team: <vadim.bogaiskov@gmail.com>\n"
9
+ "Language: ru\n"
10
+ "MIME-Version: 1.0\n"
11
+ "Content-Type: text/plain; charset=UTF-8\n"
12
+ "Content-Transfer-Encoding: 8bit\n"
13
+ "X-Generator: Poedit 1.6.4\n"
14
+ "X-Poedit-KeywordsList: _e;__\n"
15
+ "X-Poedit-Basepath: .\n"
16
+ "Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
17
+ "%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
18
+ "X-Poedit-SearchPath-0: .\n"
19
+ "X-Poedit-SearchPath-1: ..\n"
20
+
21
+ #: page-links-to.php:209
22
+ msgctxt "Meta box title"
23
+ msgid "Page Links To"
24
+ msgstr "Ссылка Страницы"
25
+
26
+ #: page-links-to.php:228
27
+ msgid "Point this content to:"
28
+ msgstr "Страница ссылается на:"
29
+
30
+ #: page-links-to.php:229
31
+ msgid "Its normal WordPress URL"
32
+ msgstr "Обычный URL WordPress"
33
+
34
+ #: page-links-to.php:230
35
+ msgid "A custom URL"
36
+ msgstr "Пользовательский URL"
37
+
38
+ #: page-links-to.php:233
39
+ msgid "Open this link in a new tab"
40
+ msgstr "Открыть ссылку в новом окне"
41
+
42
+ #: page-links-to.php:492
43
+ msgid ""
44
+ "<strong>Note</strong>: This content is pointing to a custom URL. Use the "
45
+ "&#8220;Page Links To&#8221; box to change this behavior."
46
+ msgstr ""
47
+ "<strong>Примечание</strong>: Эта страница указывает на пользовательский "
48
+ "URL. Используйте поле &#8220;Страница ссылается на&#8221;, если захотите "
49
+ "изменить это."
50
+
51
+ #. Plugin Name of the plugin/theme
52
+ msgid "Page Links To"
53
+ msgstr "Ссылка Страницы"
54
+
55
+ #. Plugin URI of the plugin/theme
56
+ msgid "http://txfx.net/wordpress-plugins/page-links-to/"
57
+ msgstr "http://txfx.net/wordpress-plugins/page-links-to/"
58
+
59
+ #. Description of the plugin/theme
60
+ msgid ""
61
+ "Allows you to point WordPress pages or posts to a URL of your choosing. "
62
+ "Good for setting up navigational links to non-WP sections of your site or to "
63
+ "off-site resources."
64
+ msgstr ""
65
+ "Позволяет перенаправлять страницы или записи WordPress на выбранный Вами "
66
+ "адрес. Подходит для создания навигационных ссылки на не-WP разделы Вашего "
67
+ "сайта, или за пределы ресурса."
68
+
69
+ #. Author of the plugin/theme
70
+ msgid "Mark Jaquith"
71
+ msgstr "Mark Jaquith"
72
+
73
+ #. Author URI of the plugin/theme
74
+ msgid "http://coveredwebservices.com/"
75
+ msgstr "http://coveredwebservices.com/"
76
+
77
+ #~ msgid "An alternate URL"
78
+ #~ msgstr "Альтернативный URL"
page-links-to.php CHANGED
@@ -3,14 +3,14 @@
3
  Plugin Name: Page Links To
4
  Plugin URI: http://txfx.net/wordpress-plugins/page-links-to/
5
  Description: Allows you to point WordPress pages or posts to a URL of your choosing. Good for setting up navigational links to non-WP sections of your site or to off-site resources.
6
- Version: 2.9.6
7
  Author: Mark Jaquith
8
  Author URI: http://coveredwebservices.com/
9
  Text Domain: page-links-to
10
  Domain Path: /languages
11
  */
12
 
13
- /* Copyright 2005-2013 Mark Jaquith
14
 
15
  This program is free software; you can redistribute it and/or modify
16
  it under the terms of the GNU General Public License as published by
@@ -36,10 +36,9 @@ class CWS_PageLinksTo extends WP_Stack_Plugin {
36
  const TARGETS_CACHE_KEY = 'plt_cache__targets';
37
  const LINK_META_KEY = '_links_to';
38
  const TARGET_META_KEY = '_links_to_target';
39
- const VERSION = 'txfx_plt_schema_version';
40
  const FILE = __FILE__;
41
-
42
- var $targets_on_this_page = array();
43
 
44
  function __construct() {
45
  self::$instance = $this;
@@ -72,12 +71,14 @@ class CWS_PageLinksTo extends WP_Stack_Plugin {
72
 
73
  // Non-standard priority hooks
74
  $this->hook( 'do_meta_boxes', 20 );
75
- $this->hook( 'wp_footer', 19 );
76
  $this->hook( 'wp_enqueue_scripts', 'start_buffer', -9999 );
 
 
77
  $this->hook( 'wp_head', 'end_buffer', 9999 );
78
 
79
  // Non-standard callback hooks
80
- $this->hook( 'load-post.php', 'load_post' );
 
81
 
82
  // Standard hooks
83
  $this->hook( 'wp_list_pages' );
@@ -88,8 +89,8 @@ class CWS_PageLinksTo extends WP_Stack_Plugin {
88
  $this->hook( 'plugin_row_meta' );
89
 
90
  // Metadata validation grants users editing privileges for our custom fields
91
- register_meta('post', self::LINK_META_KEY, null, '__return_true');
92
- register_meta('post', self::TARGET_META_KEY, null, '__return_true');
93
  }
94
 
95
  /**
@@ -100,19 +101,21 @@ class CWS_PageLinksTo extends WP_Stack_Plugin {
100
  function maybe_upgrade() {
101
  // In earlier versions, the meta keys were stored without a leading underscore.
102
  // Since then, underscore has been codified as the standard for "something manages this" post meta.
103
- if ( get_option( self::VERSION ) < 3 ) {
104
  global $wpdb;
105
  $total_affected = 0;
106
  foreach ( array( '', '_target', '_type' ) as $meta_key ) {
107
  $meta_key = 'links_to' . $meta_key;
108
  $affected = $wpdb->update( $wpdb->postmeta, array( 'meta_key' => '_' . $meta_key ), compact( 'meta_key' ) );
109
- if ( $affected )
110
  $total_affected += $affected;
 
111
  }
112
  // Only flush the cache if something changed
113
- if ( $total_affected > 0 )
114
  wp_cache_flush();
115
- if ( update_option( self::VERSION, 3 ) ) {
 
116
  $this->flush_links_cache();
117
  $this->flush_targets_cache();
118
  }
@@ -120,11 +123,33 @@ class CWS_PageLinksTo extends WP_Stack_Plugin {
120
  }
121
 
122
  /**
123
- * Enqueues jQuery, if we think we are going to need it
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  */
125
- function wp_footer() {
126
- if ( count( $this->targets_on_this_page ) )
127
- wp_enqueue_script( 'jquery' );
128
  }
129
 
130
  /**
@@ -137,11 +162,14 @@ class CWS_PageLinksTo extends WP_Stack_Plugin {
137
  /**
138
  * Collects the buffer, and injects a `jQueryWP` JS object as a
139
  * copy of `jQuery`, so that dumb themes and plugins can't hurt it
 
 
140
  */
141
  function buffer_callback( $content ) {
142
  $pattern = "#wp-includes/js/jquery/jquery\.js\?ver=([^']+)'></script>#";
143
- if ( preg_match( $pattern, $content ) )
144
  $content = preg_replace( $pattern, '$0<script>jQueryWP = jQuery;</script>', $content );
 
145
  return $content;
146
  }
147
 
@@ -171,8 +199,9 @@ class CWS_PageLinksTo extends WP_Stack_Plugin {
171
  */
172
  function get_post_meta( $post_id, $key ) {
173
  $meta = get_post_meta( absint( $post_id ), $key, true );
174
- if ( '' === $meta )
175
  return false;
 
176
  return $meta;
177
  }
178
 
@@ -245,8 +274,9 @@ class CWS_PageLinksTo extends WP_Stack_Plugin {
245
  // PLT UI in their post type.
246
  $plt_post_types = apply_filters( 'page-links-to-post-types', array_keys( get_post_types( array('show_ui' => true ) ) ) );
247
 
248
- if ( in_array( $page, $plt_post_types ) && 'advanced' === $context )
249
  add_meta_box( 'page-links-to', _x( 'Page Links To', 'Meta box title', 'page-links-to'), array( $this, 'meta_box' ), $page, 'advanced', 'low' );
 
250
  }
251
 
252
  /**
@@ -273,7 +303,7 @@ class CWS_PageLinksTo extends WP_Stack_Plugin {
273
  <p><input name="cws_links_to" type="text" style="width:75%" id="cws-links-to" value="<?php echo esc_attr( $url ); ?>" /></p>
274
  <p><label for="cws-links-to-new-tab"><input type="checkbox" name="cws_links_to_new_tab" id="cws-links-to-new-tab" value="_blank" <?php checked( (bool) $this->get_target( $post->ID ) ); ?>> <?php _e( 'Open this link in a new tab', 'page-links-to' ); ?></label></p>
275
  </div>
276
- <script src="<?php echo trailingslashit( plugin_dir_url( self::FILE ) ) . 'js/page-links-to.js?v=4'; ?>"></script>
277
  <?php
278
  }
279
 
@@ -318,8 +348,9 @@ class CWS_PageLinksTo extends WP_Stack_Plugin {
318
  function clean_url( $url ) {
319
  $url = trim( $url );
320
  // Starts with 'www.'. Probably a mistake. So add 'http://'.
321
- if ( 0 === strpos( $url, 'www.' ) )
322
  $url = 'http://' . $url;
 
323
  return $url;
324
  }
325
 
@@ -377,10 +408,12 @@ class CWS_PageLinksTo extends WP_Stack_Plugin {
377
  * @return bool whether the flush happened
378
  */
379
  function flush_links_if( $condition ) {
380
- if ( ! $condition )
 
 
 
381
  return false;
382
- $this->flush_links_cache();
383
- return true;
384
  }
385
 
386
  /**
@@ -390,10 +423,12 @@ class CWS_PageLinksTo extends WP_Stack_Plugin {
390
  * @return bool whether the flush happened
391
  */
392
  function flush_targets_if( $condition ) {
393
- if ( ! $condition )
 
 
 
394
  return false;
395
- $this->flush_targets_cache();
396
- return true;
397
  }
398
 
399
  /**
@@ -418,17 +453,6 @@ class CWS_PageLinksTo extends WP_Stack_Plugin {
418
  delete_transient( self::TARGETS_CACHE_KEY );
419
  }
420
 
421
- /**
422
- * Logs that a target=_blank PLT item has been used, so we know to trigger footer JS
423
- *
424
- * @param int|WP_Post $post post ID or object
425
- */
426
- function log_target( $post ) {
427
- $post = get_post( $post );
428
- $this->targets_on_this_page[$post->ID] = true;
429
- $this->hook( 'wp_footer', 'targets_in_new_window_via_js_footer', 999 );
430
- }
431
-
432
  /**
433
  * Filter for Post links
434
  *
@@ -443,8 +467,9 @@ class CWS_PageLinksTo extends WP_Stack_Plugin {
443
 
444
  if ( $meta_link ) {
445
  $link = esc_url( $meta_link );
446
- if ( $this->get_target( $post->ID ) )
447
- $this->log_target( $post->ID );
 
448
  }
449
 
450
  return $link;
@@ -456,11 +481,10 @@ class CWS_PageLinksTo extends WP_Stack_Plugin {
456
  function template_redirect() {
457
  $link = $this->get_redirect();
458
 
459
- if ( ! $link )
460
- return;
461
-
462
- wp_redirect( $link, 301 );
463
- exit;
464
  }
465
 
466
  /**
@@ -469,11 +493,9 @@ class CWS_PageLinksTo extends WP_Stack_Plugin {
469
  * @return string|bool the redirection URL, or false
470
  */
471
  function get_redirect() {
472
- if ( ! is_singular() )
473
- return false;
474
-
475
- if ( ! get_queried_object_id() )
476
  return false;
 
477
 
478
  $link = $this->get_link( get_queried_object_id() );
479
 
@@ -511,12 +533,16 @@ class CWS_PageLinksTo extends WP_Stack_Plugin {
511
  foreach( array_keys( $targets ) as $targeted_id )
512
  $targets_by_url[$links[$targeted_id]] = true;
513
 
514
- if ( ! $links )
515
  return $pages;
 
516
 
517
  $this_url = ( is_ssl() ? 'https' : 'http' ) . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
518
 
519
  foreach ( (array) $links as $id => $page ) {
 
 
 
520
  if ( str_replace( 'http://www.', 'http://', $this_url ) === str_replace( 'http://www.', 'http://', $page ) || ( is_home() && str_replace( 'http://www.', 'http://', trailingslashit( get_bloginfo( 'url' ) ) ) === str_replace( 'http://www.', 'http://', trailingslashit( $page ) ) ) ) {
521
  $highlight = true;
522
  $current_page = esc_url( $page );
@@ -525,7 +551,7 @@ class CWS_PageLinksTo extends WP_Stack_Plugin {
525
 
526
  if ( count( $targets_by_url ) ) {
527
  foreach ( array_keys( $targets_by_url ) as $p ) {
528
- $p = esc_url( $p );
529
  $pages = str_replace( '<a href="' . $p . '"', '<a href="' . $p . '" target="_blank"', $pages );
530
  }
531
  }
@@ -546,8 +572,9 @@ class CWS_PageLinksTo extends WP_Stack_Plugin {
546
  function wp_nav_menu_objects( $items ) {
547
  $new_items = array();
548
  foreach ( $items as $item ) {
549
- if ( isset( $item->object_id ) && $this->get_target( $item->object_id ) )
550
  $item->target = '_blank';
 
551
  $new_items[] = $item;
552
  }
553
  return $new_items;
@@ -557,9 +584,8 @@ class CWS_PageLinksTo extends WP_Stack_Plugin {
557
  * Hooks in as a post is being loaded for editing and conditionally adds a notice
558
  */
559
  function load_post() {
560
- if ( isset( $_GET['post'] ) ) {
561
- if ( $this->get_link( (int) $_GET['post'] ) )
562
- $this->hook( 'admin_notices', 'notify_of_external_link' );
563
  }
564
  }
565
 
@@ -570,37 +596,6 @@ class CWS_PageLinksTo extends WP_Stack_Plugin {
570
  ?><div class="updated"><p><?php _e( '<strong>Note</strong>: This content is pointing to a custom URL. Use the &#8220;Page Links To&#8221; box to change this behavior.', 'page-links-to' ); ?></p></div><?php
571
  }
572
 
573
- /**
574
- * Return a JS file as a string
575
- *
576
- * Takes a plugin-relative path to a CS-produced JS file
577
- * and returns its second line (no CS comment line)
578
- * @param string $path plugin-relative path to CoffeeScript-produced JS file
579
- * @return string the JS string
580
- */
581
- function inline_coffeescript( $path ) {
582
- $inline_script = file_get_contents( trailingslashit( plugin_dir_path( self::FILE ) ) . $path );
583
- $inline_script = explode( "\n", $inline_script );
584
- return $inline_script[1];
585
- }
586
-
587
- /**
588
- * Adds inline JS to the footer to handle "open in new tab" links
589
- */
590
- function targets_in_new_window_via_js_footer() {
591
- $target_ids = $this->targets_on_this_page;
592
- $target_urls = array();
593
- foreach ( array_keys( $target_ids ) as $id ) {
594
- $link = $this->get_link( $id );
595
- if ( $link )
596
- $target_urls[$link] = true;
597
- }
598
- $targets = array_keys( $target_urls );
599
- if ( $targets ) {
600
- ?><script>var pltNewTabURLs = <?php echo json_encode( $targets ) . ';' . $this->inline_coffeescript( 'js/new-tab.js' ); ?></script><?php
601
- }
602
- }
603
-
604
  /**
605
  * Adds a GitHub link to the plugin meta
606
  *
@@ -614,8 +609,27 @@ class CWS_PageLinksTo extends WP_Stack_Plugin {
614
  $links,
615
  array( '<a href="https://github.com/markjaquith/page-links-to" target="_blank">GitHub</a>' )
616
  );
 
 
617
  }
618
- return $links;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
619
  }
620
  }
621
 
3
  Plugin Name: Page Links To
4
  Plugin URI: http://txfx.net/wordpress-plugins/page-links-to/
5
  Description: Allows you to point WordPress pages or posts to a URL of your choosing. Good for setting up navigational links to non-WP sections of your site or to off-site resources.
6
+ Version: 2.9.8
7
  Author: Mark Jaquith
8
  Author URI: http://coveredwebservices.com/
9
  Text Domain: page-links-to
10
  Domain Path: /languages
11
  */
12
 
13
+ /* Copyright 2005-2017 Mark Jaquith
14
 
15
  This program is free software; you can redistribute it and/or modify
16
  it under the terms of the GNU General Public License as published by
36
  const TARGETS_CACHE_KEY = 'plt_cache__targets';
37
  const LINK_META_KEY = '_links_to';
38
  const TARGET_META_KEY = '_links_to_target';
39
+ const VERSION_KEY = 'txfx_plt_schema_version';
40
  const FILE = __FILE__;
41
+ const CSS_JS_VERSION = '2.9.8';
 
42
 
43
  function __construct() {
44
  self::$instance = $this;
71
 
72
  // Non-standard priority hooks
73
  $this->hook( 'do_meta_boxes', 20 );
 
74
  $this->hook( 'wp_enqueue_scripts', 'start_buffer', -9999 );
75
+ $this->hook( 'wp_enqueue_scripts' );
76
+ $this->hook( 'wp_enqueue_scripts', 'jquery_protection', 9999 );
77
  $this->hook( 'wp_head', 'end_buffer', 9999 );
78
 
79
  // Non-standard callback hooks
80
+ $this->hook( 'load-post.php', 'load_post' );
81
+ $this->hook( 'wp_default_scripts', 'log_jquery' );
82
 
83
  // Standard hooks
84
  $this->hook( 'wp_list_pages' );
89
  $this->hook( 'plugin_row_meta' );
90
 
91
  // Metadata validation grants users editing privileges for our custom fields
92
+ register_meta( 'post', self::LINK_META_KEY, null, '__return_true' );
93
+ register_meta( 'post', self::TARGET_META_KEY, null, '__return_true' );
94
  }
95
 
96
  /**
101
  function maybe_upgrade() {
102
  // In earlier versions, the meta keys were stored without a leading underscore.
103
  // Since then, underscore has been codified as the standard for "something manages this" post meta.
104
+ if ( get_option( self::VERSION_KEY ) < 3 ) {
105
  global $wpdb;
106
  $total_affected = 0;
107
  foreach ( array( '', '_target', '_type' ) as $meta_key ) {
108
  $meta_key = 'links_to' . $meta_key;
109
  $affected = $wpdb->update( $wpdb->postmeta, array( 'meta_key' => '_' . $meta_key ), compact( 'meta_key' ) );
110
+ if ( $affected ) {
111
  $total_affected += $affected;
112
+ }
113
  }
114
  // Only flush the cache if something changed
115
+ if ( $total_affected > 0 ) {
116
  wp_cache_flush();
117
+ }
118
+ if ( update_option( self::VERSION_KEY, 3 ) ) {
119
  $this->flush_links_cache();
120
  $this->flush_targets_cache();
121
  }
123
  }
124
 
125
  /**
126
+ * Logs data about core's jQuery
127
+ */
128
+ public function log_jquery( $wp_scripts ) {
129
+ $this->jquery = $wp_scripts->registered['jquery'];
130
+ $this->jquery_core = $wp_scripts->registered['jquery-core'];
131
+ }
132
+
133
+ /**
134
+ * Prevents jQuery from being incorrectly overwritten
135
+ */
136
+ public function jquery_protection() {
137
+ global $wp_scripts;
138
+
139
+ if ( $wp_scripts->registered['jquery-core'] !== $this->jquery_core ) {
140
+ $wp_scripts->registered['jquery-core'] = $this->jquery_core;
141
+ }
142
+
143
+ if ( $wp_scripts->registered['jquery'] !== $this->jquery ) {
144
+ $wp_scripts->registered['jquery'] = $this->jquery;
145
+ }
146
+ }
147
+
148
+ /**
149
+ * Enqueues front end scripts
150
  */
151
+ function wp_enqueue_scripts() {
152
+ wp_enqueue_script( 'page-links-to', $this->get_url() . 'js/new-tab.min.js', array( 'jquery' ), self::CSS_JS_VERSION, true );
 
153
  }
154
 
155
  /**
162
  /**
163
  * Collects the buffer, and injects a `jQueryWP` JS object as a
164
  * copy of `jQuery`, so that dumb themes and plugins can't hurt it
165
+ *
166
+ * @return string the modified buffer
167
  */
168
  function buffer_callback( $content ) {
169
  $pattern = "#wp-includes/js/jquery/jquery\.js\?ver=([^']+)'></script>#";
170
+ if ( preg_match( $pattern, $content ) ) {
171
  $content = preg_replace( $pattern, '$0<script>jQueryWP = jQuery;</script>', $content );
172
+ }
173
  return $content;
174
  }
175
 
199
  */
200
  function get_post_meta( $post_id, $key ) {
201
  $meta = get_post_meta( absint( $post_id ), $key, true );
202
+ if ( '' === $meta ) {
203
  return false;
204
+ }
205
  return $meta;
206
  }
207
 
274
  // PLT UI in their post type.
275
  $plt_post_types = apply_filters( 'page-links-to-post-types', array_keys( get_post_types( array('show_ui' => true ) ) ) );
276
 
277
+ if ( in_array( $page, $plt_post_types ) && 'advanced' === $context ) {
278
  add_meta_box( 'page-links-to', _x( 'Page Links To', 'Meta box title', 'page-links-to'), array( $this, 'meta_box' ), $page, 'advanced', 'low' );
279
+ }
280
  }
281
 
282
  /**
303
  <p><input name="cws_links_to" type="text" style="width:75%" id="cws-links-to" value="<?php echo esc_attr( $url ); ?>" /></p>
304
  <p><label for="cws-links-to-new-tab"><input type="checkbox" name="cws_links_to_new_tab" id="cws-links-to-new-tab" value="_blank" <?php checked( (bool) $this->get_target( $post->ID ) ); ?>> <?php _e( 'Open this link in a new tab', 'page-links-to' ); ?></label></p>
305
  </div>
306
+ <script src="<?php echo $this->get_url() . 'js/page-links-to.min.js?v=' . self::CSS_JS_VERSION; ?>"></script>
307
  <?php
308
  }
309
 
348
  function clean_url( $url ) {
349
  $url = trim( $url );
350
  // Starts with 'www.'. Probably a mistake. So add 'http://'.
351
+ if ( 0 === strpos( $url, 'www.' ) ) {
352
  $url = 'http://' . $url;
353
+ }
354
  return $url;
355
  }
356
 
408
  * @return bool whether the flush happened
409
  */
410
  function flush_links_if( $condition ) {
411
+ if ( $condition ) {
412
+ $this->flush_links_cache();
413
+ return true;
414
+ } else {
415
  return false;
416
+ }
 
417
  }
418
 
419
  /**
423
  * @return bool whether the flush happened
424
  */
425
  function flush_targets_if( $condition ) {
426
+ if ( $condition ) {
427
+ $this->flush_targets_cache();
428
+ return true;
429
+ } else {
430
  return false;
431
+ }
 
432
  }
433
 
434
  /**
453
  delete_transient( self::TARGETS_CACHE_KEY );
454
  }
455
 
 
 
 
 
 
 
 
 
 
 
 
456
  /**
457
  * Filter for Post links
458
  *
467
 
468
  if ( $meta_link ) {
469
  $link = esc_url( $meta_link );
470
+ if ( ! is_admin() && $this->get_target( $post->ID ) ) {
471
+ $link .= '#new_tab';
472
+ }
473
  }
474
 
475
  return $link;
481
  function template_redirect() {
482
  $link = $this->get_redirect();
483
 
484
+ if ( $link ) {
485
+ wp_redirect( $link, 301 );
486
+ exit;
487
+ }
 
488
  }
489
 
490
  /**
493
  * @return string|bool the redirection URL, or false
494
  */
495
  function get_redirect() {
496
+ if ( ! is_singular() || ! get_queried_object_id() ) {
 
 
 
497
  return false;
498
+ }
499
 
500
  $link = $this->get_link( get_queried_object_id() );
501
 
533
  foreach( array_keys( $targets ) as $targeted_id )
534
  $targets_by_url[$links[$targeted_id]] = true;
535
 
536
+ if ( ! $links ) {
537
  return $pages;
538
+ }
539
 
540
  $this_url = ( is_ssl() ? 'https' : 'http' ) . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
541
 
542
  foreach ( (array) $links as $id => $page ) {
543
+ if ( isset( $targets_by_url[$page] ) ) {
544
+ $page .= '#new_tab';
545
+ }
546
  if ( str_replace( 'http://www.', 'http://', $this_url ) === str_replace( 'http://www.', 'http://', $page ) || ( is_home() && str_replace( 'http://www.', 'http://', trailingslashit( get_bloginfo( 'url' ) ) ) === str_replace( 'http://www.', 'http://', trailingslashit( $page ) ) ) ) {
547
  $highlight = true;
548
  $current_page = esc_url( $page );
551
 
552
  if ( count( $targets_by_url ) ) {
553
  foreach ( array_keys( $targets_by_url ) as $p ) {
554
+ $p = esc_url( $p . '#new_tab' );
555
  $pages = str_replace( '<a href="' . $p . '"', '<a href="' . $p . '" target="_blank"', $pages );
556
  }
557
  }
572
  function wp_nav_menu_objects( $items ) {
573
  $new_items = array();
574
  foreach ( $items as $item ) {
575
+ if ( isset( $item->object_id ) && $this->get_target( $item->object_id ) ) {
576
  $item->target = '_blank';
577
+ }
578
  $new_items[] = $item;
579
  }
580
  return $new_items;
584
  * Hooks in as a post is being loaded for editing and conditionally adds a notice
585
  */
586
  function load_post() {
587
+ if ( isset( $_GET['post'] ) && $this->get_link( (int) $_GET['post'] ) ) {
588
+ $this->hook( 'admin_notices', 'notify_of_external_link' );
 
589
  }
590
  }
591
 
596
  ?><div class="updated"><p><?php _e( '<strong>Note</strong>: This content is pointing to a custom URL. Use the &#8220;Page Links To&#8221; box to change this behavior.', 'page-links-to' ); ?></p></div><?php
597
  }
598
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
599
  /**
600
  * Adds a GitHub link to the plugin meta
601
  *
609
  $links,
610
  array( '<a href="https://github.com/markjaquith/page-links-to" target="_blank">GitHub</a>' )
611
  );
612
+ } else {
613
+ return $links;
614
  }
615
+ }
616
+
617
+ /**
618
+ * Returns the URL of this plugin's directory
619
+ *
620
+ * @return string this plugin's directory URL
621
+ */
622
+ public function get_url() {
623
+ return plugin_dir_url( self::FILE );
624
+ }
625
+
626
+ /**
627
+ * Returns the filesystem path of this plugin's directory
628
+ *
629
+ * @return string this plugin's directory filesystem path
630
+ */
631
+ public function get_path() {
632
+ return plugin_dir_path( self::FILE );
633
  }
634
  }
635
 
phpunit.xml DELETED
@@ -1,14 +0,0 @@
1
- <phpunit
2
- bootstrap="tests/bootstrap.php"
3
- backupGlobals="false"
4
- colors="true"
5
- convertErrorsToExceptions="true"
6
- convertNoticesToExceptions="true"
7
- convertWarningsToExceptions="true"
8
- >
9
- <testsuites>
10
- <testsuite>
11
- <directory prefix="test-" suffix=".php">./tests/</directory>
12
- </testsuite>
13
- </testsuites>
14
- </phpunit>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -1,13 +1,13 @@
1
  === Page Links To ===
2
 
3
- [![Build Status](https://travis-ci.org/markjaquith/page-links-to.png?branch=master)](https://travis-ci.org/markjaquith/page-links-to)
4
 
5
  Contributors: markjaquith
6
  Donate link: http://txfx.net/wordpress-plugins/donate
7
  Tags: page, redirect, link, external link, repoint
8
  Requires at least: 3.9.2
9
- Tested up to: 4.2
10
- Stable tag: 2.9.6
11
 
12
  Lets you make a WordPress page (or other content type) link to an external URL of your choosing, instead of its WordPress URL.
13
 
@@ -63,6 +63,11 @@ You can contribute (or report bugs) on [Github](https://github.com/markjaquith/p
63
 
64
  == Changelog ==
65
 
 
 
 
 
 
66
  = 2.9.6 =
67
  * Fixed an issue with redirects that have `@` in the URL
68
  * Fixed issues with setting and displaying custom URLs for attachments
1
  === Page Links To ===
2
 
3
+ [![Build Status](https://travis-ci.org/markjaquith/page-links-to.svg?branch=master)](https://travis-ci.org/markjaquith/page-links-to)
4
 
5
  Contributors: markjaquith
6
  Donate link: http://txfx.net/wordpress-plugins/donate
7
  Tags: page, redirect, link, external link, repoint
8
  Requires at least: 3.9.2
9
+ Tested up to: 4.7.2
10
+ Stable tag: 2.9.8
11
 
12
  Lets you make a WordPress page (or other content type) link to an external URL of your choosing, instead of its WordPress URL.
13
 
63
 
64
  == Changelog ==
65
 
66
+ = 2.9.8 =
67
+ * Added a Russian translation
68
+ * Maintain a reference to WordPress' jQuery version
69
+ * Modernize build tools
70
+
71
  = 2.9.6 =
72
  * Fixed an issue with redirects that have `@` in the URL
73
  * Fixed issues with setting and displaying custom URLs for attachments
tests/bootstrap.php DELETED
@@ -1,27 +0,0 @@
1
- <?php
2
-
3
- $_tests_dir = getenv('WP_TESTS_DIR');
4
- if ( !$_tests_dir ) $_tests_dir = '/tmp/wordpress-tests-lib';
5
-
6
- require_once $_tests_dir . '/includes/functions.php';
7
-
8
- function _manually_load_plugin() {
9
- require dirname( __FILE__ ) . '/../page-links-to.php';
10
- }
11
- tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
12
-
13
- require $_tests_dir . '/includes/bootstrap.php';
14
-
15
- class CWS_PLT_TestCase extends WP_UnitTestCase {
16
- function plugin() {
17
- return CWS_PageLinksTo::$instance;
18
- }
19
-
20
- function set_post( $key, $value ) {
21
- $_POST[$key] = $_REQUEST[$key] = addslashes( $value );
22
- }
23
-
24
- function unset_post( $key ) {
25
- unset( $_POST[$key], $_REQUEST[$key] );
26
- }
27
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
tests/test-admin.php DELETED
@@ -1,9 +0,0 @@
1
- <?php
2
-
3
- class CWS_PLT_Test_Admin extends CWS_PLT_TestCase {
4
- function test_plugin_row_meta() {
5
- $metas = apply_filters( 'plugin_row_meta', array( 'one', 'two' ), plugin_basename( CWS_PageLinksTo::FILE ) );
6
- $this->assertEquals( 3, count( $metas ) );
7
- $this->assertContains( 'GitHub', array_pop( $metas ) );
8
- }
9
- }
 
 
 
 
 
 
 
 
 
tests/test-default-options.php DELETED
@@ -1,7 +0,0 @@
1
- <?php
2
-
3
- class CWS_PLT_Test_Default_Options extends CWS_PLT_TestCase {
4
- function test_schema_option() {
5
- $this->assertEquals( 3, get_option( CWS_PageLinksTo::VERSION ) );
6
- }
7
- }
 
 
 
 
 
 
 
tests/test-filtering.php DELETED
@@ -1,41 +0,0 @@
1
- <?php
2
-
3
- class CWS_PLT_Test_Filtering extends CWS_PLT_TestCase {
4
- function test_get_permalink_filter() {
5
- $post_id = $this->factory->post->create( array( 'post_type' => 'post' ) );
6
- $this->assertTrue( $this->plugin()->set_link( $post_id, 'http://example.com/' ) );
7
- $this->assertEquals( 'http://example.com/', get_permalink( $post_id ) );
8
- }
9
-
10
- function test_wp_list_posts_filter() {
11
- $post_id = $this->factory->post->create( array( 'post_type' => 'page' ) );
12
- $this->assertTrue( $this->plugin()->set_link( $post_id, 'http://example.com/' ) );
13
- $this->assertTrue( $this->plugin()->set_link_new_tab( $post_id ) );
14
- ob_start();
15
- wp_list_pages();
16
- $wp_list_pages = ob_get_clean();
17
- $this->assertContains( 'target="_blank"', $wp_list_pages );
18
- }
19
-
20
- function test_nav_menu_items_filter() {
21
- $post_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_status' => 'publish' ) );
22
- $post = get_post( $post_id );
23
- $this->assertTrue( $this->plugin()->set_link( $post_id, 'http://example.com/' ) );
24
- $this->assertTrue( $this->plugin()->set_link_new_tab( $post_id ) );
25
-
26
- // Need a user with sufficient permissions because wp_insert_post() is not low level enough — WTF?
27
- $user_id = $this->factory->user->create( array( 'role' => 'editor' ) );
28
- wp_set_current_user( $user_id );
29
- $menu_id = wp_create_nav_menu( 'plt' );
30
- $this->assertInternalType( 'int', $menu_id, "Menu creation failed" );
31
- $item_id = wp_update_nav_menu_item( $menu_id, 0, array(
32
- 'menu-item-object-id' => $post_id,
33
- 'menu-item-object' => $post->post_type,
34
- 'menu-item-type' => 'post_type',
35
- 'menu-item-status' => 'publish',
36
- ));
37
- $wp_nav_menu = wp_nav_menu( array( 'echo' => false, 'menu' => $menu_id, 'fallback_cb' => false ) );
38
- $this->assertInternalType( 'string', $wp_nav_menu, 'Menu is empty' );
39
- $this->assertContains( 'target="_blank"', $wp_nav_menu );
40
- }
41
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
tests/test-js.php DELETED
@@ -1,14 +0,0 @@
1
- <?php
2
-
3
- class CWS_PLT_Test_JS extends CWS_PLT_TestCase {
4
- function test_footer_js() {
5
- $post_id = $this->factory->post->create( array( 'post_type' => 'post' ) );
6
- $this->assertTrue( $this->plugin()->set_link( $post_id, 'http://example.com/' ) );
7
- $this->assertTrue( $this->plugin()->set_link_new_tab( $post_id ) );
8
- $this->assertEquals( 'http://example.com/', get_permalink( $post_id ) );
9
- ob_start();
10
- $this->plugin()->targets_in_new_window_via_js_footer();
11
- $footer_js = ob_get_clean();
12
- $this->assertContains( 'example.com', $footer_js );
13
- }
14
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
tests/test-redirection.php DELETED
@@ -1,31 +0,0 @@
1
- <?php
2
-
3
- class CWS_PLT_Test_Redirection extends CWS_PLT_TestCase {
4
- function test_get_permalink_filter() {
5
- $post_id = $this->factory->post->create( array( 'post_type' => 'post' ) );
6
- $this->assertTrue( $this->plugin()->set_link( $post_id, 'http://example.com/' ) );
7
- query_posts( array( 'p' => $post_id ) );
8
- $this->assertEquals( 'http://example.com/', $this->plugin()->get_redirect() );
9
- }
10
-
11
- function test_host_relative_redirect() {
12
- $post_id = $this->factory->post->create( array( 'post_type' => 'post' ) );
13
- $this->plugin()->set_link( $post_id, '/foo' );
14
- query_posts( array( 'p' => $post_id ) );
15
- $this->assertEquals( get_option( 'home' ) . '/foo', $this->plugin()->get_redirect() );
16
- }
17
-
18
- function test_protocol_relative_redirect() {
19
- $post_id = $this->factory->post->create( array( 'post_type' => 'post' ) );
20
- $this->plugin()->set_link( $post_id, '//example.com/foo' );
21
- query_posts( array( 'p' => $post_id ) );
22
- $this->assertEquals( (is_ssl() ? 'https:' : 'http:' ) . '//example.com/foo', $this->plugin()->get_redirect() );
23
- }
24
-
25
- function test_redirection_with_asperand() {
26
- $post_id = $this->factory->post->create( array( 'post_type' => 'post' ) );
27
- $this->assertTrue( $this->plugin()->set_link( $post_id, 'http://example.com/@test' ) );
28
- query_posts( array( 'p' => $post_id ) );
29
- $this->assertEquals( 'http://example.com/%40test', $this->plugin()->get_redirect() );
30
- }
31
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
tests/test-saving.php DELETED
@@ -1,135 +0,0 @@
1
- <?php
2
-
3
- class CWS_PLT_Test_Saving extends CWS_PLT_TestCase {
4
- function test_get_links() {
5
- $this->assertEquals( array(), $this->plugin()->get_links() );
6
- $post_id = $this->factory->post->create( array( 'post_type' => 'post' ) );
7
- $this->assertTrue( $this->plugin()->set_link( $post_id, 'http://example.com/' ) );
8
- $this->assertEquals( array( $post_id => 'http://example.com/' ), $this->plugin()->get_links() );
9
- $this->assertTrue( $this->plugin()->delete_link( $post_id ) );
10
- $this->assertEquals( array(), $this->plugin()->get_links() );
11
- }
12
-
13
- function test_get_targets() {
14
- $this->assertEquals( array(), $this->plugin()->get_targets() );
15
- $post_id = $this->factory->post->create( array( 'post_type' => 'post' ) );
16
- $this->assertTrue( $this->plugin()->set_link( $post_id, 'http://example.com/' ) );
17
- $this->assertTrue( $this->plugin()->set_link_new_tab( $post_id ) );
18
- $this->assertEquals( array( $post_id => true ), $this->plugin()->get_targets() );
19
- $this->assertTrue( $this->plugin()->set_link_same_tab( $post_id ) );
20
- $this->assertEquals( array(), $this->plugin()->get_targets() );
21
- }
22
-
23
- function test_setting_and_updating_url() {
24
- $post_id = $this->factory->post->create( array( 'post_type' => 'post' ) );
25
- $this->assertTrue( $this->plugin()->set_link( $post_id, 'http://example.com/' ) );
26
- $this->assertEquals( 'http://example.com/', $this->plugin()->get_link( $post_id ) );
27
- // This update changes nothing, so should return false
28
- $this->assertFalse( $this->plugin()->set_link( $post_id, 'http://example.com/' ) );
29
- $this->assertTrue( $this->plugin()->set_link( $post_id, 'http://example.com/updated' ) );
30
- $this->assertEquals( 'http://example.com/updated', $this->plugin()->get_link( $post_id ) );
31
- }
32
-
33
- function test_deleting_url() {
34
- $post_id = $this->factory->post->create( array( 'post_type' => 'post' ) );
35
- $this->assertTrue( $this->plugin()->set_link( $post_id, 'http://example.com/' ) );
36
- $this->assertTrue( $this->plugin()->delete_link( $post_id ) );
37
- $this->assertFalse( $this->plugin()->get_link( $post_id ) );
38
- }
39
-
40
- function test_setting_new_tab() {
41
- $post_id = $this->factory->post->create( array( 'post_type' => 'post' ) );
42
- $this->assertTrue( $this->plugin()->set_link( $post_id, 'http://example.com/' ) );
43
- $this->assertFalse( $this->plugin()->get_target( $post_id ) );
44
- $this->assertTrue( $this->plugin()->set_link_new_tab( $post_id ) );
45
- $this->assertTrue( $this->plugin()->get_target( $post_id ) );
46
- // This update changes nothing, so should return false
47
- $this->assertFalse( $this->plugin()->set_link_new_tab( $post_id ) );
48
- $this->assertTrue( $this->plugin()->set_link_same_tab( $post_id ) );
49
- // This update changes nothing, so should return false
50
- $this->assertFalse( $this->plugin()->set_link_same_tab( $post_id ) );
51
- $this->assertFalse( $this->plugin()->get_target( $post_id ) );
52
- }
53
-
54
- function test_deleting_url_also_deletes_target() {
55
- $post_id = $this->factory->post->create( array( 'post_type' => 'post' ) );
56
- $this->assertTrue( $this->plugin()->set_link( $post_id, 'http://example.com/' ) );
57
- $this->assertTrue( $this->plugin()->set_link_new_tab( $post_id ) );
58
- $this->assertTrue( $this->plugin()->get_target( $post_id ) );
59
- $this->assertTrue( $this->plugin()->delete_link( $post_id ) );
60
- $this->assertFalse( $this->plugin()->get_target( $post_id ) );
61
- }
62
-
63
- function test_updating_attachment() {
64
- $user_id = $this->factory->user->create( array( 'role' => 'editor' ) );
65
- wp_set_current_user( $user_id );
66
- $post_id = $this->factory->post->create( array( 'post_type' => 'attachment', 'post_author' => $user_id ) );
67
-
68
- $this->set_post( '_cws_plt_nonce', wp_create_nonce( 'cws_plt_' . $post_id ) );
69
-
70
- // example.org in same window
71
- $this->set_post( 'cws_links_to_choice', 'custom' );
72
- $this->set_post( 'cws_links_to', 'http://example.org/' );
73
- $this->unset_post( 'cws_links_to_new_tab' );
74
- $this->plugin()->edit_attachment( $post_id );
75
- $this->assertEquals( 'http://example.org/', $this->plugin()->get_link( $post_id ) );
76
- }
77
-
78
- function test_updating_post() {
79
- $user_id = $this->factory->user->create( array( 'role' => 'editor' ) );
80
- wp_set_current_user( $user_id );
81
- $post_id = $this->factory->post->create( array( 'post_type' => 'post', 'post_author' => $user_id ) );
82
-
83
- $this->set_post( '_cws_plt_nonce', wp_create_nonce( 'cws_plt_' . $post_id ) );
84
-
85
- // example.org in same window
86
- $this->set_post( 'cws_links_to_choice', 'custom' );
87
- $this->set_post( 'cws_links_to', 'http://example.org/' );
88
- $this->unset_post( 'cws_links_to_new_tab' );
89
- $this->plugin()->save_post( $post_id );
90
- $this->assertEquals( 'http://example.org/', $this->plugin()->get_link( $post_id ) );
91
- $this->assertFalse( $this->plugin()->get_target( $post_id ) );
92
-
93
- // example.com in new window
94
- $this->set_post( 'cws_links_to_choice', 'custom' );
95
- $this->set_post( 'cws_links_to', 'http://example.com/' );
96
- $this->set_post( 'cws_links_to_new_tab', '_blank' );
97
- $this->plugin()->save_post( $post_id );
98
- $this->assertEquals( 'http://example.com/', $this->plugin()->get_link( $post_id ) );
99
- $this->assertTrue( $this->plugin()->get_target( $post_id ) );
100
-
101
- // WP link selected
102
- $this->set_post( 'cws_links_to_choice', 'wp' );
103
- $this->set_post( 'cws_links_to', 'http://example.com/' );
104
- $this->set_post( 'cws_links_to_new_tab', '_blank' );
105
- $this->plugin()->save_post( $post_id );
106
- $this->assertFalse( $this->plugin()->get_link( $post_id ) );
107
- $this->assertFalse( $this->plugin()->get_target( $post_id ) );
108
-
109
- // No radio selected, but link provided
110
- $this->unset_post( 'cws_links_to_choice' );
111
- $this->set_post( 'cws_links_to', 'http://example.com/link-no-radio' );
112
- $this->set_post( 'cws_links_to_new_tab', '_blank' );
113
- $this->plugin()->save_post( $post_id );
114
- $this->assertEquals( 'http://example.com/link-no-radio', $this->plugin()->get_link( $post_id ) );
115
- $this->assertTrue( $this->plugin()->get_target( $post_id ) );
116
-
117
- // New post
118
- $post_id = $this->factory->post->create( array( 'post_type' => 'post', 'post_author' => $user_id ) );
119
-
120
- // Nonce missing
121
- $this->unset_post( '_cws_plt_nonce' );
122
- $this->set_post( 'cws_links_to_choice', 'custom' );
123
- $this->set_post( 'cws_links_to', 'http://example.com/nonce-test' );
124
- $this->set_post( 'cws_links_to_new_tab', '_blank' );
125
- $this->plugin()->save_post( $post_id );
126
- $this->assertFalse( $this->plugin()->get_link( $post_id ) );
127
- $this->assertFalse( $this->plugin()->get_target( $post_id ) );
128
-
129
- // Nonce wrong
130
- $this->set_post( '_cws_plt_nonce', wp_create_nonce( 'WRONG_INPUT' ) );
131
- $this->plugin()->save_post( $post_id );
132
- $this->assertFalse( $this->plugin()->get_link( $post_id ) );
133
- $this->assertFalse( $this->plugin()->get_target( $post_id ) );
134
- }
135
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
tests/test-utils.php DELETED
@@ -1,18 +0,0 @@
1
- <?php
2
-
3
- class CWS_PLT_Test_Utils extends CWS_PLT_TestCase {
4
- function test_clean_url() {
5
- foreach ( array(
6
- 'http://example.com/' => 'http://example.com/',
7
- ' http://example.com/ ' => 'http://example.com/',
8
- 'www.example.com/' => 'http://www.example.com/',
9
- ' www.example.com/' => 'http://www.example.com/',
10
- ) as $in => $out ) {
11
- $this->assertEquals( $out, $this->plugin()->clean_url( $in ) );
12
- }
13
- }
14
-
15
- function test_inline_coffeescript() {
16
- $this->assertNotContains( 'CoffeeScript', $this->plugin()->inline_coffeescript( 'js/new-tab.js' ) );
17
- }
18
- }