Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge beta branch into master.

  • Loading branch information...
commit b2e7583e6247877ba848affb67c8da90558c8f77 2 parents 5ef54b6 + 433f7f2
Michael Sisk authored
Showing with 17,347 additions and 13,508 deletions.
  1. +174 −0 -/css/admin-special.css
  2. BIN  -/img/transcript-small.png
  3. BIN  -/img/transcript.png
  4. BIN  -/img/twitter.png
  5. BIN  -/img/webcomic-small.png
  6. BIN  -/img/webcomic.png
  7. +69 −0 -/js/admin-config.js
  8. +14 −0 -/js/admin-legacy.js
  9. +26 −0 -/js/admin-media.js
  10. +49 −0 -/js/admin-meta.js
  11. +27 −0 -/js/admin-pages.js
  12. +33 −0 -/js/admin-posts.js
  13. +14 −0 -/js/admin-terms.js
  14. +48 −0 -/js/admin-transcripts.js
  15. +10 −0 -/js/dropdown.js
  16. +30 −0 -/js/dynamic.js
  17. +9 −0 -/js/shortcuts.js
  18. +13 −0 -/library/jquery.bbq.js
  19. +917 −0 -/library/oauth.php
  20. +263 −0 -/library/twitter.php
  21. +1 −0  -/log/index.php
  22. +568 −0 -/php/admin.php
  23. +115 −0 -/php/commerce.php
  24. +1,280 −0 -/php/config.php
  25. +1,028 −0 -/php/help.php
  26. +53 −0 -/php/integrate/dynamic.php
  27. +14 −0 -/php/integrate/feed.php
  28. +34 −0 -/php/integrate/loop_end.php
  29. +87 −0 -/php/integrate/loop_start.php
  30. +43 −0 -/php/integrate/the_content.php
  31. +7 −0 -/php/integrate/the_excerpt.php
  32. +1,202 −0 -/php/legacy.php
  33. +425 −0 -/php/media.php
  34. +295 −0 -/php/pages.php
  35. +764 −0 -/php/posts.php
  36. +1,093 −0 -/php/shortcodes.php
  37. +5,561 −0 -/php/tags.php
  38. +410 −0 -/php/taxonomy.php
  39. +550 −0 -/php/transcripts.php
  40. +22 −0 -/php/upgrade.php
  41. +57 −0 -/php/users.php
  42. +837 −0 -/php/widgets.php
  43. +59 −6 readme.md
  44. +53 −29 readme.txt
  45. +0 −282 webcomic-includes/admin-walker.php
  46. +0 −4,424 webcomic-includes/admin.php
  47. BIN  webcomic-includes/icon-small.png
  48. BIN  webcomic-includes/icon.png
  49. +0 −70 webcomic-includes/metabox.js
  50. +0 −215 webcomic-includes/mgs-core.php
  51. +0 −32 webcomic-includes/scripts.js
  52. +0 −50 webcomic-includes/tags-legacy.php
  53. +0 −106 webcomic-includes/tags.php
  54. +0 −77 webcomic-includes/template-purchase-print.php
  55. +0 −35 webcomic-includes/template-transcripts.php
  56. +0 −33 webcomic-includes/template-verify-age.php
  57. +0 −31 webcomic-includes/template-verify-fail.php
  58. +0 −275 webcomic-includes/walker.php
  59. +0 −743 webcomic-includes/widgets.php
  60. +1,093 −3,754 webcomic.php
  61. +0 −3,346 webcomic.pot
View
174 -/css/admin-special.css
@@ -0,0 +1,174 @@
+@-moz-keyframes thanks {
+ 0% { color: #00acdc; }
+ 25% { color: #cadb2a; }
+ 50% { color: #f68a1f; }
+ 75% { color: #b72367; }
+ 100% { color: #00acdc; }
+}
+
+@-ms-keyframes thanks {
+ 0% { color: #00acdc; }
+ 25% { color: #cadb2a; }
+ 50% { color: #f68a1f; }
+ 75% { color: #b72367; }
+ 100% { color: #00acdc; }
+}
+
+@-o-keyframes thanks {
+ 0% { color: #00acdc; }
+ 25% { color: #cadb2a; }
+ 50% { color: #f68a1f; }
+ 75% { color: #b72367; }
+ 100% { color: #00acdc; }
+}
+
+@-webkit-keyframes thanks {
+ 0% { color: #00acdc; }
+ 25% { color: #cadb2a; }
+ 50% { color: #f68a1f; }
+ 75% { color: #b72367; }
+ 100% { color: #00acdc; }
+}
+
+@keyframes thanks {
+ 0% { color: #00acdc; }
+ 25% { color: #cadb2a; }
+ 50% { color: #f68a1f; }
+ 75% { color: #b72367; }
+ 100% { color: #00acdc; }
+}
+
+@-moz-keyframes fadein {
+ 0% { opacity: 0; }
+ 100% { opacity: 1; }
+}
+
+@-ms-keyframes fadein {
+ 0% { opacity: 0; }
+ 100% { opacity: 1; }
+}
+
+@-o-keyframes fadein {
+ 0% { opacity: 0; }
+ 100% { opacity: 1; }
+}
+
+@-webkit-keyframes fadein {
+ 0% { opacity: 0; }
+ 100% { opacity: 1; }
+}
+
+@keyframes fadein {
+ 0% { opacity: 0; }
+ 100% { opacity: 1; }
+}
+
+.updated.webcomic {
+ -moz-animation: fadein 1.5s;
+ -ms-animation: fadein 1.5s;
+ -o-animation: fadein 1.5s;
+ -webkit-animation: fadein 1.5s;
+ animation: fadein 1.5s;
+ background: none;
+ border: 0;
+ border-radius: 0;
+}
+
+.updated.webcomic a {
+ background: -moz-linear-gradient( #fff, #eee );
+ background: -ms-linear-gradient( #fff, #eee );
+ background: -o-linear-gradient( #fff, #eee );
+ background: -webkit-linear-gradient( #fff, #eee );
+ background: linear-gradient( #fff, #eee );
+ border-radius: .5em;
+ border-style: solid;
+ border-width: 0 thin thick;
+ box-shadow: 0 .12em .25em rgba( 0, 0, 0, .25 );
+ color: #00acdc;
+ display: inline-block;
+ font: 200%/2.5 'Maven Pro', sans-serif;
+ padding: 0 1em;
+ position: relative;
+ text-shadow: 0 .1em .1em #fff;
+ -moz-transition: all .25s ease-in-out;
+ -ms-transition: all .25s ease-in-out;
+ -o-transition: all .25s ease-in-out;
+ -webkit-transition: all .25s ease-in-out;
+ transition: all .25s ease-in-out;
+}
+
+.updated.webcomic a:focus,
+.updated.webcomic a:hover {
+ -moz-animation: thanks 4s infinite;
+ -ms-animation: thanks 4s infinite;
+ -o-animation: thanks 4s infinite;
+ -webkit-animation: thanks 4s infinite;
+ animation: thanks 4s infinite;
+}
+
+.updated.webcomic a:active {
+ -moz-transform: scale( .95 );
+ -ms-transform: scale( .95 );
+ -o-transform: scale( .95 );
+ -webkit-transform: scale( .95 );
+ transform: scale( .95 );
+}
+
+
+.updated.webcomic b,
+.updated.webcomic b:after,
+.updated.webcomic b:before {
+ bottom: .25em;
+ content: '\2764';
+ color: #b72367;
+ display: block;
+ font-size: larger;
+ font-style: normal;
+ left: -.5em;
+ position: absolute;
+ text-shadow: none;
+ -moz-transform: rotate( 10deg );
+ -ms-transform: rotate( 10deg );
+ -o-transform: rotate( 10deg );
+ -webkit-transform: rotate( 10deg );
+ transform: rotate( 10deg );
+}
+
+.updated.webcomic b:before {
+ color: #cadb2a;
+ font-size: 65%;
+ bottom: -.75em;
+ left: .25em;
+}
+
+.updated.webcomic b:after {
+ color: #f68a1f;
+ font-size: 75%;
+ bottom: -.25em;
+ left: .9em;
+ -moz-transform: rotate( -20deg );
+ -ms-transform: rotate( -20deg );
+ -o-transform: rotate( -20deg );
+ -webkit-transform: rotate( -20deg );
+ transform: rotate( -20deg );
+}
+
+.updated.webcomic a:hover b,
+.updated.webcomic a:hover b:after,
+.updated.webcomic a:hover b:before {
+ color: inherit;
+}
+
+.updated.webcomic.legacy b:after,
+.updated.webcomic.legacy b:before {
+ content: '\2605';
+}
+
+.updated.webcomic.legacy b:after {
+ bottom: -.5em;
+}
+
+.updated.webcomic.legacy b:before {
+ bottom: -1.15em;
+ left: .5em;
+}
View
BIN  -/img/transcript-small.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  -/img/transcript.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  -/img/twitter.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  -/img/webcomic-small.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  -/img/webcomic.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
69 -/js/admin-config.js
@@ -0,0 +1,69 @@
+/** Update collection slug previews. */
+function webcomic_slug_preview( url ) {
+ jQuery( function( $ ) {
+ $( '#webcomic_slugs_archive,#webcomic_slugs_webcomic,#webcomic_slugs_storyline,#webcomic_slugs_character' ).on( 'change', function() {
+ $.getJSON( url, {
+ slug: $( this ).val(),
+ preview: '#' + $( this ).attr( 'id' ),
+ collection: $( '[name=webcomic_collection]' ).val(),
+ webcomic_admin_ajax: 'WebcomicConfig::ajax_slug_preview'
+ }, function( data ) {
+ $( data.container ).val( data.slug ).siblings( '.description' ).children( 'b' ).html( data.slug )
+ } );
+ } );
+ } );
+}
+
+/** Enable or disable print defaults. */
+function webcomic_commerce_defaults( url ) {
+ jQuery( function( $ ) {
+ $( '#webcomic_commerce_business' ).on( 'change', function() {
+ $.getJSON( url, {
+ business: $( this ).val(),
+ webcomic_admin_ajax: 'WebcomicConfig::ajax_commerce_defaults'
+ }, function ( data ) {
+ if ( data.clear ) {
+ $( '#webcomic_commerce_prints,#webcomic_commerce_originals' ).removeAttr( 'disabled' ).siblings( 'span' ).removeClass( 'description' );
+ } else {
+ $( '#webcomic_commerce_prints,#webcomic_commerce_originals' ).removeAttr( 'checked' ).attr( 'disabled', true ).siblings( 'span' ).addClass( 'description' );
+ }
+ } );
+ } ).trigger( 'change' );
+ } );
+}
+
+/** Update Twitter authorized account. */
+function webcomic_twitter_account( url ) {
+ jQuery( function( $ ) {
+ $( '#webcomic_twitter_consumer_key,#webcomic_twitter_consumer_secret' ).on( 'change', function() {
+ $.get( url, {
+ consumer_key: $( '#webcomic_twitter_consumer_key' ).val(),
+ consumer_secret: $( '#webcomic_twitter_consumer_secret' ).val(),
+ collection: $( '[name=webcomic_collection]' ).val(),
+ webcomic_admin_ajax: 'WebcomicConfig::ajax_twitter_account'
+ }, function ( data ) {
+ $( '#webcomic_twitter_account' ).html( data );
+ } );
+ } );
+ } );
+}
+
+/** Toggle collection setting sections. */
+jQuery( function( $ ) {
+ $( '.wrap h3' ).css( {
+ 'border-top': 'thin solid #dfdfdf',
+ color: '#21759b',
+ cursor: 'pointer',
+ padding: '.5em 0 0'
+ } ).next().hide();
+
+ $( '.wrap h3:first' ).next().show();
+
+
+ $( '.wrap h3' ).on( 'mouseenter', function() { $( this ).css( 'color', '#d54e21' ); } );
+ $( '.wrap h3' ).on( 'mouseleave', function() { $( this ).css( 'color', '#21759b' ); } );
+
+ $( '.wrap h3' ).on( 'click', function() {
+ $( this ).next().toggle();
+ } );
+} );
View
14 -/js/admin-legacy.js
@@ -0,0 +1,14 @@
+/** Automatically continue legacy upgrades. */
+function webcomic_auto_upgrade( c ) {
+ jQuery( function( $ ) {
+ setTimeout( function() {
+ $( '.webcomic-auto #upgrade_legacy' ).trigger( 'click' );
+ }, 5000 );
+
+ $( '.webcomic-auto #upgrade_legacy' ).on( 'click', function() {
+ $( this ).hide();
+
+ $( '.webcomic-auto-message' ).html( c );
+ } );
+ } );
+}
View
26 -/js/admin-media.js
@@ -0,0 +1,26 @@
+/** Warn if no selected days match the start date. */
+function webcomic_generator( warning ) {
+ jQuery( function( $ ) {
+ $( 'form' ).on( 'submit', function() {
+ var v = $( 'input[name="webcomic_generate_start"]' ).val().split( '-' ),
+ d = new Date( v[ 0 ], parseInt( v[ 1 ] ) - 1, v[ 2 ] ),
+ x = false,
+ d1 = d2 = 0;
+
+ $.each( $( 'input[name="webcomic_generate_days[]"]:checked' ), function( i, e ) {
+ d1 = parseInt( $( e ).val() );
+ d2 = parseInt( d.getDay() );
+
+ if ( d1 === d2 || ( 7 === d1 && 0 === d2 ) ) {
+ x = true;
+
+ return false;
+ }
+ } );
+
+ if ( !x ) {
+ return window.confirm( warning );
+ }
+ } );
+ } );
+}
View
49 -/js/admin-meta.js
@@ -0,0 +1,49 @@
+/** Refresh the webcomic media meta box. */
+function webcomic_media_meta( url ) {
+ jQuery( function( $ ) {
+ $( document ).on( 'mousedown', '#TB_overlay,#TB_closeWindowButton', function() {
+
+ setTimeout( function() {
+ $.get( url, {
+ post: $( '#post_ID' ).val(),
+ webcomic_admin_ajax: 'WebcomicPosts::ajax_media_preview'
+ }, function( data ) {
+ $( '#webcomic_media_preview' ).html( data );
+ } );
+ }, 500 );
+ } );
+ } );
+}
+
+/** Dynamically update the price preview for prints. */
+function webcomic_prints_meta( currency, sold ) {
+ jQuery( function( $ ) {
+ $( '#webcomic_commerce_adjust_prices_domestic,#webcomic_commerce_adjust_shipping_domestic' ).on( 'change', function() {
+ calculate_total( 'domestic' );
+ } );
+
+ $( '#webcomic_commerce_adjust_prices_international,#webcomic_commerce_adjust_shipping_international' ).on( 'change', function() {
+ calculate_total( 'international' );
+ } );
+
+ $( '#webcomic_commerce_adjust_prices_original,#webcomic_commerce_adjust_shipping_original' ).on( 'change', function() {
+ calculate_total( 'original' );
+ } );
+
+ $( '#webcomic_commerce_original_available' ).on( 'click', function() {
+ calculate_total( 'original' );
+ } );
+
+ function calculate_total( id ) {
+ var total;
+
+ if ( 'original' === id && !$( '#webcomic_commerce_original_available' ).attr( 'checked' ) ) {
+ $( '#webcomic_original_total' ).html( sold );
+ } else {
+ total = ( parseFloat( $( '#webcomic_commerce_' + id + '_price' ).html() ) * ( 1 + ( parseFloat( $( '#webcomic_commerce_adjust_prices_' + id ).val() ) * .01 ) ) ) + ( parseFloat( $( '#webcomic_commerce_' + id + '_shipping' ).html() ) * ( 1 + ( parseFloat( $( '#webcomic_commerce_adjust_shipping_' + id ).val() ) * .01 ) ) );
+
+ $( '#webcomic_' + id + '_total' ).html( total.toFixed( 2 ) + ' ' + currency );
+ }
+ }
+ } );
+}
View
27 -/js/admin-pages.js
@@ -0,0 +1,27 @@
+/** Update meta data values in the quick edit box for pages. */
+function webcomic_page_quick_edit( url ) {
+ jQuery( function( $ ) {
+ $( document ).on( 'click', 'a.editinline', function() {
+ $.getJSON( url, {
+ post: $( this ).parents( 'tr' ).attr( 'id' ).substr( 5, $( this ).parents( 'tr' ).attr( 'id' ).length ),
+ webcomic_admin_ajax: 'WebcomicPages::ajax_quick_edit'
+ }, function ( data ) {
+ $( '#webcomic_page_collection' ).val( data.collection );
+ } );
+ } );
+ } );
+}
+
+/** Save meta data values from the quick edit box for pages. */
+function webcomic_page_quick_save( url ) {
+ jQuery( function( $ ) {
+ $( '.save' ).on( 'click', function() {
+ $.get( url, {
+ post: $( this ).parents( 'tr' ).attr( 'id' ).substr( 5, $( this ).parents( 'tr' ).attr( 'id' ).length ),
+ collection: $( '#webcomic_page_collection' ).val(),
+ webcomic_page_inline_save: $( '#webcomic_page_inline_save' ).val(),
+ webcomic_admin_ajax: 'WebcomicPages::ajax_quick_save'
+ } );
+ } );
+ } );
+}
View
33 -/js/admin-posts.js
@@ -0,0 +1,33 @@
+/** Update meta data values in the quick edit box for webcomic posts. */
+function webcomic_quick_edit( url ) {
+ jQuery( function( $ ) {
+ $( document ).on( 'click', 'a.editinline', function() {
+ $.getJSON( url, {
+ post: $( this ).parents( 'tr' ).attr( 'id' ).substr( 5, $( this ).parents( 'tr' ).attr( 'id' ).length ),
+ webcomic_admin_ajax: 'WebcomicPosts::ajax_quick_edit'
+ }, function ( data ) {
+ $( '#webcomic_prints' ).attr( 'checked', data.prints ).attr( 'disabled', data.prints_disabled );
+ $( '#webcomic_original' ).attr( 'checked', data.original );
+ $( '#webcomic_transcripts' ).attr( 'checked', data.transcripts );
+
+ // select page collection
+ } );
+ } );
+ } );
+}
+
+/** Save meta data values from the quick edit box for webcomic posts. */
+function webcomic_quick_save( url ) {
+ jQuery( function( $ ) {
+ $( '.save' ).on( 'click', function() {
+ $.get( url, {
+ post: $( this ).parents( 'tr' ).attr( 'id' ).substr( 5, $( this ).parents( 'tr' ).attr( 'id' ).length ),
+ prints: $( '#webcomic_prints:checked' ).val() ? 1 : 0,
+ original: $( '#webcomic_original:checked' ).val() ? 1 : 0,
+ transcripts: $( '#webcomic_transcripts:checked' ).val() ? 1 : 0,
+ webcomic_inline_save: $( '#webcomic_inline_save' ).val(),
+ webcomic_admin_ajax: 'WebcomicPosts::ajax_quick_save'
+ } );
+ } );
+ } );
+}
View
14 -/js/admin-terms.js
@@ -0,0 +1,14 @@
+/**
+ * Modify the add/edit tag forms to disable AJAX submission and
+ * accept file uploads. Also disable AJAX deletion of storylines.
+ */
+function webcomic_edit_terms( taxonomy ) {
+ jQuery( function( $ ) {
+ $( '#addtag,#edittag' ).attr( 'enctype', 'multipart/form-data' );
+ $( '#submit' ).attr( 'id', 'webcomic-submit' );
+
+ if ( 'storyline' === taxonomy ) {
+ $( 'a.delete-tag' ).removeClass( 'delete-tag' ).addClass( 'webcomic-delete-term' );
+ }
+ } );
+}
View
48 -/js/admin-transcripts.js
@@ -0,0 +1,48 @@
+/**
+ * Handle updating the post list (when the collection is changed)
+ * and the webcomic preview (when the post is changed).
+ */
+function webcomic_transcript_meta( url ) {
+ jQuery( function( $ ) {
+ $( '#webcomic_collection' ).attr( 'disabled', false ).on( 'change', function() {
+ $.get( url, {
+ collection: $( '#webcomic_collection' ).val(),
+ parent: $( '#webcomic_parent' ).val(),
+ webcomic_admin_ajax: 'WebcomicTranscripts::ajax_posts'
+ }, function( data ) {
+ $( '#webcomic_post_list' ).html( data );
+ $( '#webcomic_post' ).trigger( 'change' );
+ } );
+ } );
+
+ $( '#webcomic_author_add' ).on( 'click', function() {
+ var key = ( new Date() ).getTime();
+
+ $( '#webcomic_author_table tbody' ).append( '<tr><td><button class="delete">-</button></td><td><input type="text" name="webcomic_author_new[' + key + '][name]"></td><td><input type="email" name="webcomic_author_new[' + key + '][email]"></td><td><input type="url" name="webcomic_author_new[' + key + '][url]"></td><td><input type="text" name="webcomic_author_new[' + key + '][ip]"></td><td><input type="text" name="webcomic_author_new[' + key + '][time]"></td></tr>' );
+
+ return false;
+ } );
+
+ $( document ).on( 'click', '#webcomic_author_table .delete', function() {
+ $( this ).parents( 'tr' ).remove();
+
+ return false;
+ } );
+
+ $( document ).on( 'change', '#webcomic_post', function() {
+ $.get( url, {
+ parent: $( '#webcomic_post' ).val() ? $( '#webcomic_post' ).val() : 0,
+ webcomic_admin_ajax: 'WebcomicTranscripts::ajax_post_transcripts'
+ }, function( data ) {
+ $( '#webcomic_post_transcripts' ).html( data );
+ } );
+
+ $.get( url, {
+ post: $( '#webcomic_post' ).val() ? $( '#webcomic_post' ).val() : 0,
+ webcomic_admin_ajax: 'WebcomicTranscripts::ajax_preview'
+ }, function( data ) {
+ $( '#webcomic_post_preview' ).html( data );
+ } );
+ } );
+ } );
+}
View
10 -/js/dropdown.js
@@ -0,0 +1,10 @@
+/** Enable webcomic dropdown navigation. */
+jQuery( function( $ ) {
+ $( 'select.webcomic-terms,select.webcomic-collections,select.webcomic-transcript-terms' ).on( 'change', function() {
+ var url = $( this ).find( 'option:selected' ).data( 'webcomic-url' );
+
+ if ( url ) {
+ window.location.href = url;
+ }
+ } );
+} );
View
30 -/js/dynamic.js
@@ -0,0 +1,30 @@
+/** Enable dynamic webcomic navigation. */
+jQuery( function( $ ) {
+ /**
+ * Update any anchors with a webcomic-dynamic data attribute inside
+ * of a container with a webcomic-container data attribute.
+ */
+ function update_hyperlinks( c ) {
+ var container = typeof c !== 'undefined' ? '[data-webcomic-container="' + c + '"]' : '[data-webcomic-container]';
+
+ $( container + ' [data-webcomic-dynamic][href]' ).each( function ( i, e ) {
+ var hash = $( e ).data( 'webcomic-dynamic' ) + '/' + $( e ).parents( container ).data( 'webcomic-container' );
+
+ $( e ).data( 'webcomic-permalink', $( e ).attr( 'href' ) );
+ $( e ).attr( 'href', $.param.fragment( window.location.href, hash, 2 ) ).attr( 'data-webcomic-dynamic', hash );
+ } );
+ } update_hyperlinks();
+
+ /** Handle dynamic webcomic navigation. */
+ $( window ).on( 'hashchange', function() {
+ if ( $.param.fragment() && 0 !== $.param.fragment().indexOf( '0' ) ) {
+ var container = $.param.fragment().substr( $.param.fragment().lastIndexOf( '/' ) + 1, $.param.fragment().length );
+
+ $.get( $( 'a[data-webcomic-dynamic="' + $.param.fragment() + '"]' ).data( 'webcomic-permalink' ), { webcomic_dynamic: container }, function( data ) {
+ $( '[data-webcomic-container="' + container + '"]' ).html( data ).fadeIn( 'fast' );
+
+ update_hyperlinks( container );
+ } );
+ }
+ } ).trigger( 'hashchange' );
+} );
View
9 -/js/shortcuts.js
@@ -0,0 +1,9 @@
+/** Handle keyboard shortcut navigation. */
+jQuery( function( $ ) {
+ $.hotkeys.add( 'right', function() { if ( $( '.next-webcomic-link' ).attr( 'href' ) ) { window.location.href = $( '.next-webcomic-link' ).attr( 'href' ); } } );
+ $.hotkeys.add( 'left', function() { if ( $( '.previous-webcomic-link' ).attr( 'href' ) ) { window.location.href = $( '.previous-webcomic-link' ).attr( 'href' ); } } );
+ $.hotkeys.add( 'shift+right', function() { if ( $( '.last-webcomic-link' ).attr( 'href' ) ) { window.location.href = $( '.last-webcomic-link' ).attr( 'href' ); } } );
+ $.hotkeys.add( 'shift+left', function() { if ( $( '.first-webcomic-link' ).attr( 'href' ) ) { window.location.href = $( '.first-webcomic-link' ).attr( 'href' ); } } );
+ $.hotkeys.add( 'shift+up', function() { if ( $( '.purchase-webcomic-link' ).attr( 'href' ) ) { window.location.href = $( '.purchase-webcomic-link' ).attr( 'href' ); } } );
+ $.hotkeys.add( 'shift+down', function() { if ( $( '.random-webcomic-link' ).attr( 'href' ) ) { window.location.href = $( '.random-webcomic-link' ).attr( 'href' ); } } );
+} );
View
13 -/library/jquery.bbq.js
@@ -0,0 +1,13 @@
+/**
+ * jQuery BBQ: Back Button & Query Library - v1.2.1 - 2/17/2010
+ * http://benalman.com/projects/jquery-bbq-plugin/
+ *
+ * jQuery hashchange event - v1.2 - 2/11/2010
+ * http://benalman.com/projects/jquery-hashchange-plugin/
+ *
+ * Copyright 2010 "Cowboy" Ben Alman
+ * Dual licensed under the MIT and GPL licenses.
+ * http://benalman.com/about/license/
+ */
+(function($,p){var i,m=Array.prototype.slice,r=decodeURIComponent,a=$.param,c,l,v,b=$.bbq=$.bbq||{},q,u,j,e=$.event.special,d="hashchange",A="querystring",D="fragment",y="elemUrlAttr",g="location",k="href",t="src",x=/^.*\?|#.*$/g,w=/^.*\#/,h,C={};function E(F){return typeof F==="string"}function B(G){var F=m.call(arguments,1);return function(){return G.apply(this,F.concat(m.call(arguments)))}}function n(F){return F.replace(/^[^#]*#?(.*)$/,"$1")}function o(F){return F.replace(/(?:^[^?#]*\?([^#]*).*$)?.*/,"$1")}function f(H,M,F,I,G){var O,L,K,N,J;if(I!==i){K=F.match(H?/^([^#]*)\#?(.*)$/:/^([^#?]*)\??([^#]*)(#?.*)/);J=K[3]||"";if(G===2&&E(I)){L=I.replace(H?w:x,"")}else{N=l(K[2]);I=E(I)?l[H?D:A](I):I;L=G===2?I:G===1?$.extend({},I,N):$.extend({},N,I);L=a(L);if(H){L=L.replace(h,r)}}O=K[1]+(H?"#":L||!K[1]?"?":"")+L+J}else{O=M(F!==i?F:p[g][k])}return O}a[A]=B(f,0,o);a[D]=c=B(f,1,n);c.noEscape=function(G){G=G||"";var F=$.map(G.split(""),encodeURIComponent);h=new RegExp(F.join("|"),"g")};c.noEscape(",/");$.deparam=l=function(I,F){var H={},G={"true":!0,"false":!1,"null":null};$.each(I.replace(/\+/g," ").split("&"),function(L,Q){var K=Q.split("="),P=r(K[0]),J,O=H,M=0,R=P.split("]["),N=R.length-1;if(/\[/.test(R[0])&&/\]$/.test(R[N])){R[N]=R[N].replace(/\]$/,"");R=R.shift().split("[").concat(R);N=R.length-1}else{N=0}if(K.length===2){J=r(K[1]);if(F){J=J&&!isNaN(J)?+J:J==="undefined"?i:G[J]!==i?G[J]:J}if(N){for(;M<=N;M++){P=R[M]===""?O.length:R[M];O=O[P]=M<N?O[P]||(R[M+1]&&isNaN(R[M+1])?{}:[]):J}}else{if($.isArray(H[P])){H[P].push(J)}else{if(H[P]!==i){H[P]=[H[P],J]}else{H[P]=J}}}}else{if(P){H[P]=F?i:""}}});return H};function z(H,F,G){if(F===i||typeof F==="boolean"){G=F;F=a[H?D:A]()}else{F=E(F)?F.replace(H?w:x,""):F}return l(F,G)}l[A]=B(z,0);l[D]=v=B(z,1);$[y]||($[y]=function(F){return $.extend(C,F)})({a:k,base:k,iframe:t,img:t,input:t,form:"action",link:k,script:t});j=$[y];function s(I,G,H,F){if(!E(H)&&typeof H!=="object"){F=H;H=G;G=i}return this.each(function(){var L=$(this),J=G||j()[(this.nodeName||"").toLowerCase()]||"",K=J&&L.attr(J)||"";L.attr(J,a[I](K,H,F))})}$.fn[A]=B(s,A);$.fn[D]=B(s,D);b.pushState=q=function(I,F){if(E(I)&&/^#/.test(I)&&F===i){F=2}var H=I!==i,G=c(p[g][k],H?I:{},H?F:2);p[g][k]=G+(/#/.test(G)?"":"#")};b.getState=u=function(F,G){return F===i||typeof F==="boolean"?v(F):v(G)[F]};b.removeState=function(F){var G={};if(F!==i){G=u();$.each($.isArray(F)?F:arguments,function(I,H){delete G[H]})}q(G,2)};e[d]=$.extend(e[d],{add:function(F){var H;function G(J){var I=J[D]=c();J.getState=function(K,L){return K===i||typeof K==="boolean"?l(I,K):l(I,L)[K]};H.apply(this,arguments)}if($.isFunction(F)){H=F;return G}else{H=F.handler;F.handler=G}}})})(jQuery,this);
+(function($,i,b){var j,k=$.event.special,c="location",d="hashchange",l="href",f=$.browser,g=document.documentMode,h=f.msie&&(g===b||g<8),e="on"+d in i&&!h;function a(m){m=m||i[c][l];return m.replace(/^[^#]*#?(.*)$/,"$1")}$[d+"Delay"]=100;k[d]=$.extend(k[d],{setup:function(){if(e){return false}$(j.start)},teardown:function(){if(e){return false}$(j.stop)}});j=(function(){var m={},r,n,o,q;function p(){o=q=function(s){return s};if(h){n=$('<iframe src="javascript:0"/>').hide().insertAfter("body")[0].contentWindow;q=function(){return a(n.document[c][l])};o=function(u,s){if(u!==s){var t=n.document;t.open().close();t[c].hash="#"+u}};o(a())}}m.start=function(){if(r){return}var t=a();o||p();(function s(){var v=a(),u=q(t);if(v!==t){o(t=v,u);$(i).trigger(d)}else{if(u!==t){i[c][l]=i[c][l].replace(/#.*/,"")+"#"+u}}r=setTimeout(s,$[d+"Delay"])})()};m.stop=function(){if(!n){r&&clearTimeout(r);r=0}};return m})()})(jQuery,this);
View
917 -/library/oauth.php
@@ -0,0 +1,917 @@
+<?php
+/** MIT License
+ *
+ * Copyright (c) 2007 Andy Smith
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/* Generic exception class
+ */
+class OAuthException extends Exception {}
+
+class OAuthConsumer {
+ public $key;
+ public $secret;
+
+ function __construct($key, $secret, $callback_url=NULL) {
+ $this->key = $key;
+ $this->secret = $secret;
+ $this->callback_url = $callback_url;
+ }
+
+ function __toString() {
+ return "OAuthConsumer[key=$this->key,secret=$this->secret]";
+ }
+}
+
+class OAuthToken {
+ // access tokens and request tokens
+ public $key;
+ public $secret;
+
+ /**
+ * key = the token
+ * secret = the token secret
+ */
+ function __construct($key, $secret) {
+ $this->key = $key;
+ $this->secret = $secret;
+ }
+
+ /**
+ * generates the basic string serialization of a token that a server
+ * would respond to request_token and access_token calls with
+ */
+ function to_string() {
+ return "oauth_token=" .
+ OAuthUtil::urlencode_rfc3986($this->key) .
+ "&oauth_token_secret=" .
+ OAuthUtil::urlencode_rfc3986($this->secret);
+ }
+
+ function __toString() {
+ return $this->to_string();
+ }
+}
+
+/**
+ * A class for implementing a Signature Method
+ * See section 9 ("Signing Requests") in the spec
+ */
+abstract class OAuthSignatureMethod {
+ /**
+ * Needs to return the name of the Signature Method (ie HMAC-SHA1)
+ * @return string
+ */
+ abstract public function get_name();
+
+ /**
+ * Build up the signature
+ * NOTE: The output of this function MUST NOT be urlencoded.
+ * the encoding is handled in OAuthRequest when the final
+ * request is serialized
+ * @param OAuthRequest $request
+ * @param OAuthConsumer $consumer
+ * @param OAuthToken $token
+ * @return string
+ */
+ abstract public function build_signature($request, $consumer, $token);
+
+ /**
+ * Verifies that a given signature is correct
+ * @param OAuthRequest $request
+ * @param OAuthConsumer $consumer
+ * @param OAuthToken $token
+ * @param string $signature
+ * @return bool
+ */
+ public function check_signature($request, $consumer, $token, $signature) {
+ $built = $this->build_signature($request, $consumer, $token);
+
+ // Check for zero length, although unlikely here
+ if (strlen($built) == 0 || strlen($signature) == 0) {
+ return false;
+ }
+
+ if (strlen($built) != strlen($signature)) {
+ return false;
+ }
+
+ // Avoid a timing leak with a (hopefully) time insensitive compare
+ $result = 0;
+ for ($i = 0; $i < strlen($signature); $i++) {
+ $result |= ord($built{$i}) ^ ord($signature{$i});
+ }
+
+ return $result == 0;
+ }
+}
+
+/**
+ * The HMAC-SHA1 signature method uses the HMAC-SHA1 signature algorithm as defined in [RFC2104]
+ * where the Signature Base String is the text and the key is the concatenated values (each first
+ * encoded per Parameter Encoding) of the Consumer Secret and Token Secret, separated by an '&'
+ * character (ASCII code 38) even if empty.
+ * - Chapter 9.2 ("HMAC-SHA1")
+ */
+class OAuthSignatureMethod_HMAC_SHA1 extends OAuthSignatureMethod {
+ function get_name() {
+ return "HMAC-SHA1";
+ }
+
+ public function build_signature($request, $consumer, $token) {
+ $base_string = $request->get_signature_base_string();
+ $request->base_string = $base_string;
+
+ $key_parts = array(
+ $consumer->secret,
+ ($token) ? $token->secret : ""
+ );
+
+ $key_parts = OAuthUtil::urlencode_rfc3986($key_parts);
+ $key = implode('&', $key_parts);
+
+ return base64_encode(hash_hmac('sha1', $base_string, $key, true));
+ }
+}
+
+/**
+ * The PLAINTEXT method does not provide any security protection and SHOULD only be used
+ * over a secure channel such as HTTPS. It does not use the Signature Base String.
+ * - Chapter 9.4 ("PLAINTEXT")
+ */
+class OAuthSignatureMethod_PLAINTEXT extends OAuthSignatureMethod {
+ public function get_name() {
+ return "PLAINTEXT";
+ }
+
+ /**
+ * oauth_signature is set to the concatenated encoded values of the Consumer Secret and
+ * Token Secret, separated by a '&' character (ASCII code 38), even if either secret is
+ * empty. The result MUST be encoded again.
+ * - Chapter 9.4.1 ("Generating Signatures")
+ *
+ * Please note that the second encoding MUST NOT happen in the SignatureMethod, as
+ * OAuthRequest handles this!
+ */
+ public function build_signature($request, $consumer, $token) {
+ $key_parts = array(
+ $consumer->secret,
+ ($token) ? $token->secret : ""
+ );
+
+ $key_parts = OAuthUtil::urlencode_rfc3986($key_parts);
+ $key = implode('&', $key_parts);
+ $request->base_string = $key;
+
+ return $key;
+ }
+}
+
+/**
+ * The RSA-SHA1 signature method uses the RSASSA-PKCS1-v1_5 signature algorithm as defined in
+ * [RFC3447] section 8.2 (more simply known as PKCS#1), using SHA-1 as the hash function for
+ * EMSA-PKCS1-v1_5. It is assumed that the Consumer has provided its RSA public key in a
+ * verified way to the Service Provider, in a manner which is beyond the scope of this
+ * specification.
+ * - Chapter 9.3 ("RSA-SHA1")
+ */
+abstract class OAuthSignatureMethod_RSA_SHA1 extends OAuthSignatureMethod {
+ public function get_name() {
+ return "RSA-SHA1";
+ }
+
+ // Up to the SP to implement this lookup of keys. Possible ideas are:
+ // (1) do a lookup in a table of trusted certs keyed off of consumer
+ // (2) fetch via http using a url provided by the requester
+ // (3) some sort of specific discovery code based on request
+ //
+ // Either way should return a string representation of the certificate
+ protected abstract function fetch_public_cert(&$request);
+
+ // Up to the SP to implement this lookup of keys. Possible ideas are:
+ // (1) do a lookup in a table of trusted certs keyed off of consumer
+ //
+ // Either way should return a string representation of the certificate
+ protected abstract function fetch_private_cert(&$request);
+
+ public function build_signature($request, $consumer, $token) {
+ $base_string = $request->get_signature_base_string();
+ $request->base_string = $base_string;
+
+ // Fetch the private key cert based on the request
+ $cert = $this->fetch_private_cert($request);
+
+ // Pull the private key ID from the certificate
+ $privatekeyid = openssl_get_privatekey($cert);
+
+ // Sign using the key
+ $ok = openssl_sign($base_string, $signature, $privatekeyid);
+
+ // Release the key resource
+ openssl_free_key($privatekeyid);
+
+ return base64_encode($signature);
+ }
+
+ public function check_signature($request, $consumer, $token, $signature) {
+ $decoded_sig = base64_decode($signature);
+
+ $base_string = $request->get_signature_base_string();
+
+ // Fetch the public key cert based on the request
+ $cert = $this->fetch_public_cert($request);
+
+ // Pull the public key ID from the certificate
+ $publickeyid = openssl_get_publickey($cert);
+
+ // Check the computed signature against the one passed in the query
+ $ok = openssl_verify($base_string, $decoded_sig, $publickeyid);
+
+ // Release the key resource
+ openssl_free_key($publickeyid);
+
+ return $ok == 1;
+ }
+}
+
+class OAuthRequest {
+ protected $parameters;
+ protected $http_method;
+ protected $http_url;
+ // for debug purposes
+ public $base_string;
+ public static $version = '1.0';
+ public static $POST_INPUT = 'php://input';
+
+ function __construct($http_method, $http_url, $parameters=NULL) {
+ $parameters = ($parameters) ? $parameters : array();
+ $parameters = array_merge( OAuthUtil::parse_parameters(parse_url($http_url, PHP_URL_QUERY)), $parameters);
+ $this->parameters = $parameters;
+ $this->http_method = $http_method;
+ $this->http_url = $http_url;
+ }
+
+
+ /**
+ * attempt to build up a request from what was passed to the server
+ */
+ public static function from_request($http_method=NULL, $http_url=NULL, $parameters=NULL) {
+ $scheme = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on")
+ ? 'http'
+ : 'https';
+ $http_url = ($http_url) ? $http_url : $scheme .
+ '://' . $_SERVER['SERVER_NAME'] .
+ ':' .
+ $_SERVER['SERVER_PORT'] .
+ $_SERVER['REQUEST_URI'];
+ $http_method = ($http_method) ? $http_method : $_SERVER['REQUEST_METHOD'];
+
+ // We weren't handed any parameters, so let's find the ones relevant to
+ // this request.
+ // If you run XML-RPC or similar you should use this to provide your own
+ // parsed parameter-list
+ if (!$parameters) {
+ // Find request headers
+ $request_headers = OAuthUtil::get_headers();
+
+ // Parse the query-string to find GET parameters
+ $parameters = OAuthUtil::parse_parameters($_SERVER['QUERY_STRING']);
+
+ // It's a POST request of the proper content-type, so parse POST
+ // parameters and add those overriding any duplicates from GET
+ if ($http_method == "POST"
+ && isset($request_headers['Content-Type'])
+ && strstr($request_headers['Content-Type'],
+ 'application/x-www-form-urlencoded')
+ ) {
+ $post_data = OAuthUtil::parse_parameters(
+ file_get_contents(self::$POST_INPUT)
+ );
+ $parameters = array_merge($parameters, $post_data);
+ }
+
+ // We have a Authorization-header with OAuth data. Parse the header
+ // and add those overriding any duplicates from GET or POST
+ if (isset($request_headers['Authorization']) && substr($request_headers['Authorization'], 0, 6) == 'OAuth ') {
+ $header_parameters = OAuthUtil::split_header(
+ $request_headers['Authorization']
+ );
+ $parameters = array_merge($parameters, $header_parameters);
+ }
+
+ }
+
+ return new OAuthRequest($http_method, $http_url, $parameters);
+ }
+
+ /**
+ * pretty much a helper function to set up the request
+ */
+ public static function from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters=NULL) {
+ $parameters = ($parameters) ? $parameters : array();
+ $defaults = array("oauth_version" => OAuthRequest::$version,
+ "oauth_nonce" => OAuthRequest::generate_nonce(),
+ "oauth_timestamp" => OAuthRequest::generate_timestamp(),
+ "oauth_consumer_key" => $consumer->key);
+ if ($token)
+ $defaults['oauth_token'] = $token->key;
+
+ $parameters = array_merge($defaults, $parameters);
+
+ return new OAuthRequest($http_method, $http_url, $parameters);
+ }
+
+ public function set_parameter($name, $value, $allow_duplicates = true) {
+ if ($allow_duplicates && isset($this->parameters[$name])) {
+ // We have already added parameter(s) with this name, so add to the list
+ if (is_scalar($this->parameters[$name])) {
+ // This is the first duplicate, so transform scalar (string)
+ // into an array so we can add the duplicates
+ $this->parameters[$name] = array($this->parameters[$name]);
+ }
+
+ $this->parameters[$name][] = $value;
+ } else {
+ $this->parameters[$name] = $value;
+ }
+ }
+
+ public function get_parameter($name) {
+ return isset($this->parameters[$name]) ? $this->parameters[$name] : null;
+ }
+
+ public function get_parameters() {
+ return $this->parameters;
+ }
+
+ public function unset_parameter($name) {
+ unset($this->parameters[$name]);
+ }
+
+ /**
+ * The request parameters, sorted and concatenated into a normalized string.
+ * @return string
+ */
+ public function get_signable_parameters() {
+ // Grab all parameters
+ $params = $this->parameters;
+
+ // Remove oauth_signature if present
+ // Ref: Spec: 9.1.1 ("The oauth_signature parameter MUST be excluded.")
+ if (isset($params['oauth_signature'])) {
+ unset($params['oauth_signature']);
+ }
+
+ return OAuthUtil::build_http_query($params);
+ }
+
+ /**
+ * Returns the base string of this request
+ *
+ * The base string defined as the method, the url
+ * and the parameters (normalized), each urlencoded
+ * and the concated with &.
+ */
+ public function get_signature_base_string() {
+ $parts = array(
+ $this->get_normalized_http_method(),
+ $this->get_normalized_http_url(),
+ $this->get_signable_parameters()
+ );
+
+ $parts = OAuthUtil::urlencode_rfc3986($parts);
+
+ return implode('&', $parts);
+ }
+
+ /**
+ * just uppercases the http method
+ */
+ public function get_normalized_http_method() {
+ return strtoupper($this->http_method);
+ }
+
+ /**
+ * parses the url and rebuilds it to be
+ * scheme://host/path
+ */
+ public function get_normalized_http_url() {
+ $parts = parse_url($this->http_url);
+
+ $scheme = (isset($parts['scheme'])) ? $parts['scheme'] : 'http';
+ $port = (isset($parts['port'])) ? $parts['port'] : (($scheme == 'https') ? '443' : '80');
+ $host = (isset($parts['host'])) ? strtolower($parts['host']) : '';
+ $path = (isset($parts['path'])) ? $parts['path'] : '';
+
+ if (($scheme == 'https' && $port != '443')
+ || ($scheme == 'http' && $port != '80')) {
+ $host = "$host:$port";
+ }
+ return "$scheme://$host$path";
+ }
+
+ /**
+ * builds a url usable for a GET request
+ */
+ public function to_url() {
+ $post_data = $this->to_postdata();
+ $out = $this->get_normalized_http_url();
+ if ($post_data) {
+ $out .= '?'.$post_data;
+ }
+ return $out;
+ }
+
+ /**
+ * builds the data one would send in a POST request
+ */
+ public function to_postdata() {
+ return OAuthUtil::build_http_query($this->parameters);
+ }
+
+ /**
+ * builds the Authorization: header
+ */
+ public function to_header($realm=null) {
+ $first = true;
+ if($realm) {
+ $out = 'Authorization: OAuth realm="' . OAuthUtil::urlencode_rfc3986($realm) . '"';
+ $first = false;
+ } else
+ $out = 'Authorization: OAuth';
+
+ $total = array();
+ foreach ($this->parameters as $k => $v) {
+ if (substr($k, 0, 5) != "oauth") continue;
+ if (is_array($v)) {
+ throw new OAuthException('Arrays not supported in headers');
+ }
+ $out .= ($first) ? ' ' : ',';
+ $out .= OAuthUtil::urlencode_rfc3986($k) .
+ '="' .
+ OAuthUtil::urlencode_rfc3986($v) .
+ '"';
+ $first = false;
+ }
+ return $out;
+ }
+
+ public function __toString() {
+ return $this->to_url();
+ }
+
+
+ public function sign_request($signature_method, $consumer, $token) {
+ $this->set_parameter(
+ "oauth_signature_method",
+ $signature_method->get_name(),
+ false
+ );
+ $signature = $this->build_signature($signature_method, $consumer, $token);
+ $this->set_parameter("oauth_signature", $signature, false);
+ }
+
+ public function build_signature($signature_method, $consumer, $token) {
+ $signature = $signature_method->build_signature($this, $consumer, $token);
+ return $signature;
+ }
+
+ /**
+ * util function: current timestamp
+ */
+ private static function generate_timestamp() {
+ return time();
+ }
+
+ /**
+ * util function: current nonce
+ */
+ private static function generate_nonce() {
+ $mt = microtime();
+ $rand = mt_rand();
+
+ return md5($mt . $rand); // md5s look nicer than numbers
+ }
+}
+
+class OAuthServer {
+ protected $timestamp_threshold = 300; // in seconds, five minutes
+ protected $version = '1.0'; // hi blaine
+ protected $signature_methods = array();
+
+ protected $data_store;
+
+ function __construct($data_store) {
+ $this->data_store = $data_store;
+ }
+
+ public function add_signature_method($signature_method) {
+ $this->signature_methods[$signature_method->get_name()] =
+ $signature_method;
+ }
+
+ // high level functions
+
+ /**
+ * process a request_token request
+ * returns the request token on success
+ */
+ public function fetch_request_token(&$request) {
+ $this->get_version($request);
+
+ $consumer = $this->get_consumer($request);
+
+ // no token required for the initial token request
+ $token = NULL;
+
+ $this->check_signature($request, $consumer, $token);
+
+ // Rev A change
+ $callback = $request->get_parameter('oauth_callback');
+ $new_token = $this->data_store->new_request_token($consumer, $callback);
+
+ return $new_token;
+ }
+
+ /**
+ * process an access_token request
+ * returns the access token on success
+ */
+ public function fetch_access_token(&$request) {
+ $this->get_version($request);
+
+ $consumer = $this->get_consumer($request);
+
+ // requires authorized request token
+ $token = $this->get_token($request, $consumer, "request");
+
+ $this->check_signature($request, $consumer, $token);
+
+ // Rev A change
+ $verifier = $request->get_parameter('oauth_verifier');
+ $new_token = $this->data_store->new_access_token($token, $consumer, $verifier);
+
+ return $new_token;
+ }
+
+ /**
+ * verify an api call, checks all the parameters
+ */
+ public function verify_request(&$request) {
+ $this->get_version($request);
+ $consumer = $this->get_consumer($request);
+ $token = $this->get_token($request, $consumer, "access");
+ $this->check_signature($request, $consumer, $token);
+ return array($consumer, $token);
+ }
+
+ // Internals from here
+ /**
+ * version 1
+ */
+ private function get_version(&$request) {
+ $version = $request->get_parameter("oauth_version");
+ if (!$version) {
+ // Service Providers MUST assume the protocol version to be 1.0 if this parameter is not present.
+ // Chapter 7.0 ("Accessing Protected Ressources")
+ $version = '1.0';
+ }
+ if ($version !== $this->version) {
+ throw new OAuthException("OAuth version '$version' not supported");
+ }
+ return $version;
+ }
+
+ /**
+ * figure out the signature with some defaults
+ */
+ private function get_signature_method($request) {
+ $signature_method = $request instanceof OAuthRequest
+ ? $request->get_parameter("oauth_signature_method")
+ : NULL;
+
+ if (!$signature_method) {
+ // According to chapter 7 ("Accessing Protected Ressources") the signature-method
+ // parameter is required, and we can't just fallback to PLAINTEXT
+ throw new OAuthException('No signature method parameter. This parameter is required');
+ }
+
+ if (!in_array($signature_method,
+ array_keys($this->signature_methods))) {
+ throw new OAuthException(
+ "Signature method '$signature_method' not supported " .
+ "try one of the following: " .
+ implode(", ", array_keys($this->signature_methods))
+ );
+ }
+ return $this->signature_methods[$signature_method];
+ }
+
+ /**
+ * try to find the consumer for the provided request's consumer key
+ */
+ private function get_consumer($request) {
+ $consumer_key = $request instanceof OAuthRequest
+ ? $request->get_parameter("oauth_consumer_key")
+ : NULL;
+
+ if (!$consumer_key) {
+ throw new OAuthException("Invalid consumer key");
+ }
+
+ $consumer = $this->data_store->lookup_consumer($consumer_key);
+ if (!$consumer) {
+ throw new OAuthException("Invalid consumer");
+ }
+
+ return $consumer;
+ }
+
+ /**
+ * try to find the token for the provided request's token key
+ */
+ private function get_token($request, $consumer, $token_type="access") {
+ $token_field = $request instanceof OAuthRequest
+ ? $request->get_parameter('oauth_token')
+ : NULL;
+
+ $token = $this->data_store->lookup_token(
+ $consumer, $token_type, $token_field
+ );
+ if (!$token) {
+ throw new OAuthException("Invalid $token_type token: $token_field");
+ }
+ return $token;
+ }
+
+ /**
+ * all-in-one function to check the signature on a request
+ * should guess the signature method appropriately
+ */
+ private function check_signature($request, $consumer, $token) {
+ // this should probably be in a different method
+ $timestamp = $request instanceof OAuthRequest
+ ? $request->get_parameter('oauth_timestamp')
+ : NULL;
+ $nonce = $request instanceof OAuthRequest
+ ? $request->get_parameter('oauth_nonce')
+ : NULL;
+
+ $this->check_timestamp($timestamp);
+ $this->check_nonce($consumer, $token, $nonce, $timestamp);
+
+ $signature_method = $this->get_signature_method($request);
+
+ $signature = $request->get_parameter('oauth_signature');
+ $valid_sig = $signature_method->check_signature(
+ $request,
+ $consumer,
+ $token,
+ $signature
+ );
+
+ if (!$valid_sig) {
+ throw new OAuthException("Invalid signature");
+ }
+ }
+
+ /**
+ * check that the timestamp is new enough
+ */
+ private function check_timestamp($timestamp) {
+ if( ! $timestamp )
+ throw new OAuthException(
+ 'Missing timestamp parameter. The parameter is required'
+ );
+
+ // verify that timestamp is recentish
+ $now = time();
+ if (abs($now - $timestamp) > $this->timestamp_threshold) {
+ throw new OAuthException(
+ "Expired timestamp, yours $timestamp, ours $now"
+ );
+ }
+ }
+
+ /**
+ * check that the nonce is not repeated
+ */
+ private function check_nonce($consumer, $token, $nonce, $timestamp) {
+ if( ! $nonce )
+ throw new OAuthException(
+ 'Missing nonce parameter. The parameter is required'
+ );
+
+ // verify that the nonce is uniqueish
+ $found = $this->data_store->lookup_nonce(
+ $consumer,
+ $token,
+ $nonce,
+ $timestamp
+ );
+ if ($found) {
+ throw new OAuthException("Nonce already used: $nonce");
+ }
+ }
+
+}
+
+class OAuthDataStore {
+ function lookup_consumer($consumer_key) {
+ // implement me
+ }
+
+ function lookup_token($consumer, $token_type, $token) {
+ // implement me
+ }
+
+ function lookup_nonce($consumer, $token, $nonce, $timestamp) {
+ // implement me
+ }
+
+ function new_request_token($consumer, $callback = null) {
+ // return a new token attached to this consumer
+ }
+
+ function new_access_token($token, $consumer, $verifier = null) {
+ // return a new access token attached to this consumer
+ // for the user associated with this token if the request token
+ // is authorized
+ // should also invalidate the request token
+ }
+
+}
+
+class OAuthUtil {
+ public static function urlencode_rfc3986($input) {
+ if (is_array($input)) {
+ return array_map(array('OAuthUtil', 'urlencode_rfc3986'), $input);
+ } else if (is_scalar($input)) {
+ return str_replace(
+ '+',
+ ' ',
+ str_replace('%7E', '~', rawurlencode($input))
+ );
+ } else {
+ return '';
+ }
+}
+
+
+ // This decode function isn't taking into consideration the above
+ // modifications to the encoding process. However, this method doesn't
+ // seem to be used anywhere so leaving it as is.
+ public static function urldecode_rfc3986($string) {
+ return urldecode($string);
+ }
+
+ // Utility function for turning the Authorization: header into
+ // parameters, has to do some unescaping
+ // Can filter out any non-oauth parameters if needed (default behaviour)
+ // May 28th, 2010 - method updated to tjerk.meesters for a speed improvement.
+ // see http://code.google.com/p/oauth/issues/detail?id=163
+ public static function split_header($header, $only_allow_oauth_parameters = true) {
+ $params = array();
+ if (preg_match_all('/('.($only_allow_oauth_parameters ? 'oauth_' : '').'[a-z_-]*)=(:?"([^"]*)"|([^,]*))/', $header, $matches)) {
+ foreach ($matches[1] as $i => $h) {
+ $params[$h] = OAuthUtil::urldecode_rfc3986(empty($matches[3][$i]) ? $matches[4][$i] : $matches[3][$i]);
+ }
+ if (isset($params['realm'])) {
+ unset($params['realm']);
+ }
+ }
+ return $params;
+ }
+
+ // helper to try to sort out headers for people who aren't running apache
+ public static function get_headers() {
+ if (function_exists('apache_request_headers')) {
+ // we need this to get the actual Authorization: header
+ // because apache tends to tell us it doesn't exist
+ $headers = apache_request_headers();
+
+ // sanitize the output of apache_request_headers because
+ // we always want the keys to be Cased-Like-This and arh()
+ // returns the headers in the same case as they are in the
+ // request
+ $out = array();
+ foreach ($headers AS $key => $value) {
+ $key = str_replace(
+ " ",
+ "-",
+ ucwords(strtolower(str_replace("-", " ", $key)))
+ );
+ $out[$key] = $value;
+ }
+ } else {
+ // otherwise we don't have apache and are just going to have to hope
+ // that $_SERVER actually contains what we need
+ $out = array();
+ if( isset($_SERVER['CONTENT_TYPE']) )
+ $out['Content-Type'] = $_SERVER['CONTENT_TYPE'];
+ if( isset($_ENV['CONTENT_TYPE']) )
+ $out['Content-Type'] = $_ENV['CONTENT_TYPE'];
+
+ foreach ($_SERVER as $key => $value) {
+ if (substr($key, 0, 5) == "HTTP_") {
+ // this is chaos, basically it is just there to capitalize the first
+ // letter of every word that is not an initial HTTP and strip HTTP
+ // code from przemek
+ $key = str_replace(
+ " ",
+ "-",
+ ucwords(strtolower(str_replace("_", " ", substr($key, 5))))
+ );
+ $out[$key] = $value;
+ }
+ }
+ }
+ return $out;
+ }
+
+ // This function takes a input like a=b&a=c&d=e and returns the parsed
+ // parameters like this
+ // array('a' => array('b','c'), 'd' => 'e')
+ public static function parse_parameters( $input ) {
+ if (!isset($input) || !$input) return array();
+
+ $pairs = explode('&', $input);
+
+ $parsed_parameters = array();
+ foreach ($pairs as $pair) {
+ $split = explode('=', $pair, 2);
+ $parameter = OAuthUtil::urldecode_rfc3986($split[0]);
+ $value = isset($split[1]) ? OAuthUtil::urldecode_rfc3986($split[1]) : '';
+
+ if (isset($parsed_parameters[$parameter])) {
+ // We have already recieved parameter(s) with this name, so add to the list
+ // of parameters with this name
+
+ if (is_scalar($parsed_parameters[$parameter])) {
+ // This is the first duplicate, so transform scalar (string) into an array
+ // so we can add the duplicates
+ $parsed_parameters[$parameter] = array($parsed_parameters[$parameter]);
+ }
+
+ $parsed_parameters[$parameter][] = $value;
+ } else {
+ $parsed_parameters[$parameter] = $value;
+ }
+ }
+ return $parsed_parameters;
+ }
+
+ public static function build_http_query($params) {
+ if (!$params) return '';
+
+ // Urlencode both keys and values
+ $keys = OAuthUtil::urlencode_rfc3986(array_keys($params));
+ $values = OAuthUtil::urlencode_rfc3986(array_values($params));
+ $params = array_combine($keys, $values);
+
+ // Parameters are sorted by name, using lexicographical byte value ordering.
+ // Ref: Spec: 9.1.1 (1)
+ uksort($params, 'strcmp');
+
+ $pairs = array();
+ foreach ($params as $parameter => $value) {
+ if (is_array($value)) {
+ // If two or more parameters share the same name, they are sorted by their value
+ // Ref: Spec: 9.1.1 (1)
+ // June 12th, 2010 - changed to sort because of issue 164 by hidetaka
+ sort($value, SORT_STRING);
+ foreach ($value as $duplicate_value) {
+ $pairs[] = $parameter . '=' . $duplicate_value;
+ }
+ } else {
+ $pairs[] = $parameter . '=' . $value;
+ }
+ }
+ // For each parameter, the name is separated from the corresponding value by an '=' character (ASCII code 61)
+ // Each name-value pair is separated by an '&' character (ASCII code 38)
+ return implode('&', $pairs);
+ }
+}
+
+?>
View
263 -/library/twitter.php
@@ -0,0 +1,263 @@
+<?php
+/** MIT License
+ *
+ * Copyright (c) 2009 Abraham Williams - http://abrah.am - abraham@poseurte.ch
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+require_once 'oauth.php';
+
+/**
+ * Twitter OAuth class
+ */
+class TwitterOAuth {
+ /* Contains the last HTTP status code returned. */
+ public $http_code;
+ /* Contains the last API call. */
+ public $url;
+ /* Set up the API root URL. */
+ public $host = "https://api.twitter.com/1/";
+ /* Set timeout default. */
+ public $timeout = 30;
+ /* Set connect timeout. */
+ public $connecttimeout = 30;
+ /* Verify SSL Cert. */
+ public $ssl_verifypeer = FALSE;
+ /* Respons format. */
+ public $format = 'json';
+ /* Decode returned json data. */
+ public $decode_json = TRUE;
+ /* Contains the last HTTP headers returned. */
+ public $http_info;
+ /* Set the useragnet. */
+ public $useragent = 'TwitterOAuth v0.2.0-beta2';
+ /* Immediately retry the API call if the response was not successful. */
+ //public $retry = TRUE;
+
+
+
+
+ /**
+ * Set API URLS
+ */
+ function accessTokenURL() { return 'https://api.twitter.com/oauth/access_token'; }
+ function authenticateURL() { return 'https://api.twitter.com/oauth/authenticate'; }
+ function authorizeURL() { return 'https://api.twitter.com/oauth/authorize'; }
+ function requestTokenURL() { return 'https://api.twitter.com/oauth/request_token'; }
+
+ /**
+ * Debug helpers
+ */
+ function lastStatusCode() { return $this->http_status; }
+ function lastAPICall() { return $this->last_api_call; }
+
+ /**
+ * construct TwitterOAuth object
+ */
+ function __construct($consumer_key, $consumer_secret, $oauth_token = NULL, $oauth_token_secret = NULL) {
+ $this->sha1_method = new OAuthSignatureMethod_HMAC_SHA1();
+ $this->consumer = new OAuthConsumer($consumer_key, $consumer_secret);
+ if (!empty($oauth_token) && !empty($oauth_token_secret)) {
+ $this->token = new OAuthConsumer($oauth_token, $oauth_token_secret);
+ } else {
+ $this->token = NULL;
+ }
+ }
+
+
+ /**
+ * Get a request_token from Twitter
+ *
+ * @returns a key/value array containing oauth_token and oauth_token_secret
+ */
+ function getRequestToken($oauth_callback = NULL) {
+ $parameters = array();
+ if (!empty($oauth_callback)) {
+ $parameters['oauth_callback'] = $oauth_callback;
+ }
+ $request = $this->oAuthRequest($this->requestTokenURL(), 'GET', $parameters);
+ $token = OAuthUtil::parse_parameters($request);
+ $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
+ return $token;
+ }
+
+ /**
+ * Get the authorize URL
+ *
+ * @returns a string
+ */
+ function getAuthorizeURL($token, $sign_in_with_twitter = TRUE) {
+ if (is_array($token)) {
+ $token = $token['oauth_token'];
+ }
+ if (empty($sign_in_with_twitter)) {
+ return $this->authorizeURL() . "?oauth_token={$token}";
+ } else {
+ return $this->authenticateURL() . "?oauth_token={$token}";
+ }
+ }
+
+ /**
+ * Exchange request token and secret for an access token and
+ * secret, to sign API calls.
+ *
+ * @returns array("oauth_token" => "the-access-token",
+ * "oauth_token_secret" => "the-access-secret",
+ * "user_id" => "9436992",
+ * "screen_name" => "abraham")
+ */
+ function getAccessToken($oauth_verifier = FALSE) {
+ $parameters = array();
+ if (!empty($oauth_verifier)) {
+ $parameters['oauth_verifier'] = $oauth_verifier;
+ }
+ $request = $this->oAuthRequest($this->accessTokenURL(), 'GET', $parameters);
+ $token = OAuthUtil::parse_parameters($request);
+ $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
+ return $token;
+ }
+
+ /**
+ * One time exchange of username and password for access token and secret.
+ *
+ * @returns array("oauth_token" => "the-access-token",
+ * "oauth_token_secret" => "the-access-secret",
+ * "user_id" => "9436992",
+ * "screen_name" => "abraham",
+ * "x_auth_expires" => "0")
+ */
+ function getXAuthToken($username, $password) {
+ $parameters = array();
+ $parameters['x_auth_username'] = $username;
+ $parameters['x_auth_password'] = $password;
+ $parameters['x_auth_mode'] = 'client_auth';
+ $request = $this->oAuthRequest($this->accessTokenURL(), 'POST', $parameters);
+ $token = OAuthUtil::parse_parameters($request);
+ $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
+ return $token;
+ }
+
+ /**
+ * GET wrapper for oAuthRequest.
+ */
+ function get($url, $parameters = array()) {
+ $response = $this->oAuthRequest($url, 'GET', $parameters);
+ if ($this->format === 'json' && $this->decode_json) {
+ return json_decode($response);
+ }
+ return $response;
+ }
+
+ /**
+ * POST wrapper for oAuthRequest.
+ */
+ function post($url, $parameters = array()) {
+ $response = $this->oAuthRequest($url, 'POST', $parameters);
+ if ($this->format === 'json' && $this->decode_json) {
+ return json_decode($response);
+ }
+ return $response;
+ }
+
+ /**
+ * DELETE wrapper for oAuthReqeust.
+ */
+ function delete($url, $parameters = array()) {
+ $response = $this->oAuthRequest($url, 'DELETE', $parameters);
+ if ($this->format === 'json' && $this->decode_json) {
+ return json_decode($response);
+ }
+ return $response;
+ }
+
+ /**
+ * Format and sign an OAuth / API request
+ */
+ function oAuthRequest($url, $method, $parameters) {
+ if (strrpos($url, 'https://') !== 0 && strrpos($url, 'http://') !== 0) {
+ $url = "{$this->host}{$url}.{$this->format}";
+ }
+ $request = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, $method, $url, $parameters);
+ $request->sign_request($this->sha1_method, $this->consumer, $this->token);
+ switch ($method) {
+ case 'GET':
+ return $this->http($request->to_url(), 'GET');
+ default:
+ return $this->http($request->get_normalized_http_url(), $method, $request->to_postdata());
+ }
+ }
+
+ /**
+ * Make an HTTP request
+ *
+ * @return API results
+ */
+ function http($url, $method, $postfields = NULL) {
+ $this->http_info = array();
+ $ci = curl_init();
+ /* Curl settings */
+ curl_setopt($ci, CURLOPT_USERAGENT, $this->useragent);
+ curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout);
+ curl_setopt($ci, CURLOPT_TIMEOUT, $this->timeout);
+ curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);
+ curl_setopt($ci, CURLOPT_HTTPHEADER, array('Expect:'));
+ curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer);
+ curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader'));
+ curl_setopt($ci, CURLOPT_HEADER, FALSE);
+
+ switch ($method) {
+ case 'POST':
+ curl_setopt($ci, CURLOPT_POST, TRUE);
+ if (!empty($postfields)) {
+ curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);
+ }
+ break;
+ case 'DELETE':
+ curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');
+ if (!empty($postfields)) {
+ $url = "{$url}?{$postfields}";
+ }
+ }
+
+ curl_setopt($ci, CURLOPT_URL, $url);
+ $response = curl_exec($ci);
+ $this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
+ $this->http_info = array_merge($this->http_info, curl_getinfo($ci));
+ $this->url = $url;
+ curl_close ($ci);
+ return $response;
+ }
+
+ /**
+ * Get the header info to store.
+ */
+ function getHeader($ch, $header) {
+ $i = strpos($header, ':');
+ if (!empty($i)) {
+ $key = str_replace('-', '_', strtolower(substr($header, 0, $i)));
+ $value = trim(substr($header, $i + 2));
+ $this->http_header[$key] = $value;
+ }
+ return strlen($header);
+ }
+}
View
1  -/log/index.php
@@ -0,0 +1 @@
+<?php die;
View
568 -/php/admin.php
<
@@ -0,0 +1,568 @@
+<?php
+/** Contains the WebcomicAdmin class.
+ *
+ * @package Webcomic
+ */
+
+/** Handle general administrative tasks.
+ *
+ * @package Webcomic
+ */
+class WebcomicAdmin extends Webcomic {
+ /** Register hooks and istantiate the administrative classes.
+ *
+ * @uses Webcomic::$dir
+ * @uses Webcomic::$config
+ * @uses Webcomic::__construct()
+ * @uses WebcomicAdmin::activate()
+ * @uses WebcomicAdmin::deactivate()
+ * @uses WebcomicAdmin::admin_init()
+ * @uses WebcomicAdmin::admin_head()
+ * @uses WebcomicAdmin::admin_notices()
+ * @uses WebcomicAdmin::admin_enqueue_scripts()
+ * @uses WebcomicAdmin::plugin_row_meta()
+ * @uses WebcomicAdmin::plugin_action_links()
+ * @uses WebcomicPosts
+ * @uses WebcomicUsers
+ * @uses WebcomicMedia
+ * @uses WebcomicConfig
+ * @uses WebcomicTaxonomy
+ * @uses WebcomicTranscripts
+ * @uses WebcomicLegacy
+ */
+ public function __construct() {
+ parent::__construct();
+
+ register_activation_hook( self::$dir . 'webcomic.php', array( $this, 'activate' ) );
+ register_deactivation_hook( self::$dir . 'webcomic.php', array( $this, 'deactivate' ) );
+
+ if ( self::$config and version_compare( self::$config[ 'version' ], '4x', '>=' ) ) {
+ add_action( 'admin_init', array( $this, 'admin_init' ) );
+ add_action( 'admin_head', array( $this, 'admin_head' ) );
+ add_action( 'admin_notices', array( $this, 'admin_notices' ) );
+ add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
+
+ add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 3 );
+ add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 4 );
+
+ require_once self::$dir . '-/php/posts.php'; new WebcomicPosts;
+ require_once self::$dir . '-/php/pages.php'; new WebcomicPages;
+ require_once self::$dir . '-/php/users.php'; new WebcomicUsers;
+ require_once self::$dir . '-/php/media.php'; new WebcomicMedia;
+ require_once self::$dir . '-/php/config.php'; new WebcomicConfig;
+ require_once self::$dir . '-/php/commerce.php'; new WebcomicCommerce;
+ require_once self::$dir . '-/php/taxonomy.php'; new WebcomicTaxonomy;
+ require_once self::$dir . '-/php/transcripts.php'; new WebcomicTranscripts;
+
+ if ( !empty( self::$config[ 'legacy' ] ) ) {
+ require_once self::$dir . '-/php/legacy.php'; new WebcomicLegacy;
+ }
+ }
+ }
+
+ /** Activation hook.
+ *
+ * If no configuration exists or a legacy configuration is detected
+ * we load the default configuration (saving legacy configurations
+ * to 'webcomic_legacy' as necessary), schedule the
+ * webcomic_buffer_alert event, and flush rewrite rules. If an
+ * existing modern configuration exists but is older than the
+ * internal version we run an upgrade.
+ *
+ * @uses Webcomic::$config
+ * @uses Webcomic::$version
+ * @uses WebcomicUpgrade
+ * @hook webcomic.php
+ */
+ public function activate() {
+ if ( !self::$config or version_compare( self::$config[ 'version' ], '4x', '<' ) ) {
+ $name = __( 'Untitled Webcomic', 'webcomic' );
+ $slug = sanitize_title( $name );
+ $legacy = self::$config ? self::$config : get_option( 'webcomic_version' );
+
+ self::$config = array(
+ 'version' => self::$version,
+ 'increment' => 2,
+ 'thanks' => true,
+ 'convert' => false,
+ 'dynamic' => false,
+ 'integrate' => false,
+ 'shortcuts' => false,
+ 'uninstall' => false,
+ 'sizes' => array(),
+ 'terms' => array(),
+ 'collections' => array(
+ 'webcomic1' => array(
+ 'id' => 'webcomic1',
+ 'name' => $name,
+ 'image' => 0,
+ 'theme' => '',
+ 'updated' => 0,
+ 'supports' => array( 'title', 'editor', 'author', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions' ),
+ 'taxonomies' => array(),
+ 'description' => '',
+ 'feeds' => array(
+ 'hook' => true,
+ 'size' => 'thumbnail',
+ 'main' => true
+ ),
+ 'slugs' => array(
+ 'name' => $slug,
+ 'archive' => $slug,
+ 'webcomic' => $slug,
+ 'storyline' => "{$slug}-storyline",
+ 'character' => "{$slug}-character"
+ ),
+ 'buffer' => array(
+ 'hook' => true,
+ 'days' => 7,
+ 'email' => get_bloginfo( 'admin_email' )
+ ),
+ 'access' => array(
+ 'byage' => false,
+ 'byrole' => false,
+ 'age' => 18,
+ 'roles' => array( '!' )
+ ),
+ 'twitter' => array(
+ 'format' => __( '%collection-name has updated! %site-url', 'webcomic' ),
+ 'oauth_token' => '',
+ 'oauth_secret' => '',
+ 'consumer_key' => '',
+ 'consumer_secret' => '',
+ 'request_token' => '',
+ 'request_secret' => ''
+ ),
+ 'commerce' => array(
+ 'business' => '',
+ 'currency' => 'USD',
+ 'prints' => false,
+ 'originals' => false,
+ 'method' => '_xclick',
+ 'donation' => 0,
+ 'price' => array(
+ 'domestic' => 6,
+ 'international' => 9,
+ 'original' => 12
+ ),
+ 'shipping' => array(
+ 'domestic' => 4,
+ 'international' => 6,
+ 'original' => 8
+ ),
+ 'total' => array(
+ 'domestic' => 10,
+ 'international' => 15,
+ 'original' => 20
+ )
+ ),
+ 'transcripts' => array(
+ 'open' => true,
+ 'languages' => array( '!' ),
+ 'permission' => 'register',
+ 'notify' => array(
+ 'hook' => true,
+ 'email' => get_bloginfo( 'admin_email' )
+ )
+ )
+ )
+ )
+ );
+
+ if ( is_array( $legacy ) ) {
+ delete_option( 'webcomic_options' );
+
+ self::$config[ 'legacy' ] = self::$config[ 'legacy_notice' ] = 3;
+ } else if ( $legacy ) {
+ self::$config[ 'legacy' ] = self::$config[ 'legacy_notice' ] = version_compare( $legacy, '2', '>=' ) ? 2 : 1;
+
+ $legacy_config = array(
+ 'webcomic_version' => $legacy,
+ 'comic_category' => get_option( 'comic_category' ),
+ 'comic_directory' => get_option( 'comic_directory' ),
+ 'comic_current_chaper' => get_option( 'comic_current_chapter' ),
+ 'comic_secure_names' => get_option( 'comic_secure_names' ),
+ 'comic_feed' => get_option( 'comic_feed' ),
+ 'comic_feed_size' => get_option( 'comic_feed_size' ),
+ 'comic_large_size_w' => get_option( 'comic_large_size_w' ),
+ 'comic_large_size_h' => get_option( 'comic_large_size_h' ),
+ 'comic_medium_size_w' => get_option( 'comic_medium_size_w' ),
+ 'comic_medium_size_h' => get_option( 'comic_medium_size_h' )
+ );
+
+ delete_option( 'webcomic_version' );
+ delete_option( 'comic_category' );
+ delete_option( 'comic_directory' );
+ delete_option( 'comic_current_chapter' );
+ delete_option( 'comic_secure_names' );
+ delete_option( 'comic_feed' );
+ delete_option( 'comic_feed_size' );
+ delete_option( 'comic_large_size_w' );
+ delete_option( 'comic_large_size_h' );
+ delete_option( 'comic_medium_size_w' );
+ delete_option( 'comic_medium_size_h' );
+
+ if ( 2 === self::$config[ 'legacy' ] ) {
+ $legacy_config = array_merge( $legacy_config, array(
+ 'comic_buffer' => get_option( 'comic_buffer' ),
+ 'comic_thumb_crop' => get_option( 'comic_thumb_crop' ),
+ 'comic_buffer_alert' => get_option( 'comic_buffer_alert' ),
+ 'comic_secure_paths' => get_option( 'comic_secure_paths' ),
+ 'comic_thumb_size_w' => get_option( 'comic_thumb_size_w' ),
+ 'comic_thumb_size_h' => get_option( 'comic_thumb_size_h' ),
+ 'comic_keyboard_shortcuts' => get_option( 'comic_keyboard_shortcuts' ),
+ 'comic_transcripts_allowed' => get_option( 'comic_transcripts_allowed' ),
+ 'comic_transcripts_required' => get_option( 'comic_transcripts_required' ),
+ 'comic_transcripts_loggedin' => get_option( 'comic_transcripts_loggedin' )
+ ) );
+
+ delete_option( 'comic_buffer' );
+ delete_option( 'comic_thumb_crop' );
+ delete_option( 'comic_buffer_alert' );
+ delete_option( 'comic_secure_paths' );
+ delete_option( 'comic_thumb_size_w' );
+ delete_option( 'comic_thumb_size_h' );
+ delete_option( 'comic_keyboard_shortcuts' );
+ delete_option( 'comic_transcripts_allowed' );
+ delete_option( 'comic_transcripts_required' );
+ delete_option( 'comic_transcripts_loggedin' );
+ } else {
+ $legacy_config = array_merge( $legacy_config, array(
+ 'comic_auto_post' => get_option( 'comic_auto_post' ),
+ 'comic_name_format' => get_option( 'comic_name_format' ),
+ 'comic_thumbnail_crop' => get_option( 'comic_thumbnail_crop' ),
+ 'comic_name_format_date' => get_option( 'comic_name_format_date' ),
+ 'comic_thumbnail_size_w' => get_option( 'comic_thumbnail_size_w' ),
+ 'comic_thumbnail_size_h' => get_option( 'comic_thumbnail_size_h' )
+ ) );
+
+ delete_option( 'comic_auto_post' );
+ delete_option( 'comic_name_format' );
+ delete_option( 'comic_thumbnail_crop' );
+ delete_option( 'comic_name_format_date' );
+ delete_option( 'comic_thumbnail_size_w' );
+ delete_option( 'comic_thumbnail_size_h' );
+ }
+ }
+
+ if ( $legacy ) {
+ delete_option( 'webcomic_legacy' );
+
+ update_option( 'webcomic_legacy', $legacy_config, '', 'no' );
+ }
+
+ add_option( 'webcomic_options', self::$config );
+
+ wp_schedule_event( ( integer ) current_time( 'timestamp' ), 'daily', 'webcomic_buffer_alert' );
+
+ flush_rewrite_rules();
+ } else if ( version_compare( self::$config[ 'version' ], self::$version, '<' ) ) {
+ require_once self::$dir . '-/php/upgrade.php'; new WebcomicUpgrade;
+ }
+ }
+
+ /** Deactivation hook.
+ *
+ * Flushes rewrite rules when deactivated. If the uninstall option
+ * has been set we also need to do delete all webcomics,
+ * transcripts, storylines, characters, and languages. If a legacy
+ * configuration exists it will be reloaded. If the convert option
+ * has been set we run Webcomic::save_collection() on each
+ * collection and convert languages into tags.
+ *
+ * @uses Webcomic::$config
+ * @uses WebcomicAdmin::save_collection()
+ * @hook webcomic.php
+ */
+ public function deactivate() {
+ global $wpdb;
+
+ if ( self::$config[ 'uninstall' ] ) {
+ $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key = 'webcomic_birthday'" );
+
+ if ( self::$config[ 'convert' ] ) {
+ $language_cache = array();
+
+ foreach ( array_keys( self::$config[ 'collections' ] ) as $k ) {
+ self::save_collection( $k );
+ }
+
+ foreach ( get_terms( 'webcomic_language', array( 'get' => 'all' ) ) as $language ) {
+ if ( $tag = ( integer ) $wpdb->get_var( $wpdb->prepare( "SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE term_id = %d AND taxonomy = 'post_tag'", $language->term_id ) ) ) {
+ $values = array();
+ $objects = get_objects_in_term( $language->term_id, $language->taxonomy );
+ $language_cache[] = $language->term_id;
+
+ foreach ( $objects as $object ) {
+ $values[] = $wpdb->prepare( '( %d, %d, %d ) ', $object, $tag, 0 );
+
+ clean_post_cache( $object );
+ }
+
+ if ( $values ) {
+ $wpdb->query( sprintf( "INSERT INTO {$wpdb->term_relationships} ( object_id, term_taxonomy_id, term_order ) VALUES %s ON DUPLICATE KEY UPDATE term_order = VALUES( term_order )", join( ',', $values ) ) );
+
+ $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->term_relationships} WHERE term_taxonomy_id = %d", $language->term_id ) );
+
+ $wpdb->update( $wpdb->term_taxonomy, array( 'count' => $count ), array( 'term_id' => $language->term_id, 'taxonomy' => 'post_tag' ) );
+ }
+
+ wp_delete_term( $language->term_id, $language->taxonomy );
+
+ continue;
+ }
+
+ $wpdb->update( $wpdb->term_taxonomy, array( 'taxonomy' => 'post_tag' ), array( 'term_id' => $language->term_id, 'taxonomy' => $language->taxonomy ) );
+ }
+
+ if ( $language_cache = array_unique( array_values( $language_cache ) ) ) {
+ clean_term_cache( $language_cache, 'post_tag' );
+ }
+ } else {
+ $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key = 'webcomic_collection'" );
+
+ $post_types = array( 'webcomic_transcript' );
+ $taxonomies = array( 'webcomic_language' );
+
+ foreach ( array_keys( self::$config[ 'collections' ] ) as $k ) {
+ $post_types[] = $k;
+ $taxonomies[] = "{$k}_storyline";
+ $taxonomies[] = "{$k}_character";
+ }
+
+ foreach ( get_terms( $taxonomies, array( 'get' => 'all' ) ) as $term ) {
+ wp_delete_term( $term->term_id, $term->taxonomy );
+ }
+
+ foreach ( get_posts( array( 'numberposts' => -1, 'post_type' => $post_types, 'post_status' => get_post_stati() ) ) as $p ) {
+ wp_delete_post( $p->ID, true );
+ }
+ }
+
+ wp_clear_scheduled_hook( 'webcomic_buffer_alert' );
+
+ delete_option( 'webcomic_options' );
+
+ if ( $legacy = get_option( 'webcomic_legacy' ) ) {
+ if ( 3 === self::$config[ 'legacy' ] ) {
+ add_option( 'webcomic_options', $legacy );
+ } else {
+ add_option( 'webcomic_version', $legacy[ 'webcomic_version' ] );
+ add_option( 'comic_category', $legacy[ 'comic_category' ] );
+ add_option( 'comic_directory', $legacy[ 'comic_directory' ] );
+ add_option( 'comic_current_chapter', $legacy[ 'comic_current_chapter' ] );
+ add_option( 'comic_secure_names', $legacy[ 'comic_secure_names' ] );
+ add_option( 'comic_feed', $legacy[ 'comic_feed' ] );
+ add_option( 'comic_feed_size', $legacy[ 'comic_feed_size' ] );
+ add_option( 'comic_large_size_w', $legacy[ 'comic_large_size_w' ] );
+ add_option( 'comic_large_size_h', $legacy[ 'comic_large_size_h' ] );
+ add_option( 'comic_medium_size_w', $legacy[ 'comic_medium_size_w' ] );
+ add_option( 'comic_medium_size_h', $legacy[ 'comic_medium_size_h' ] );
+
+ if ( 2 === self::$config[ 'legacy' ] ) {
+ add_option( 'comic_buffer', $legacy[ 'comic_buffer' ] );
+ add_option( 'comic_thumb_crop', $legacy[ 'comic_thumb_crop' ] );
+ add_option( 'comic_buffer_alert', $legacy[ 'comic_buffer_alert' ] );
+ add_option( 'comic_secure_paths', $legacy[ 'comic_secure_paths' ] );
+ add_option( 'comic_thumb_size_w', $legacy[ 'comic_thumb_size_w' ] );
+ add_option( 'comic_thumb_size_h', $legacy[ 'comic_thumb_size_h' ] );
+ add_option( 'comic_keyboard_shortcuts', $legacy[ 'comic_keyboard_shortcuts' ] );
+ add_option( 'comic_transcripts_allowed', $legacy[ 'comic_transcripts_allowed' ] );
+ add_option( 'comic_transcripts_required', $legacy[ 'comic_transcripts_required' ] );
+ add_option( 'comic_transcripts_loggedin', $legacy[ 'comic_transcripts_loggedin' ] );
+ } else {
+ add_option( 'comic_auto_post', $legacy[ 'comic_auto_post' ] );
+ add_option( 'comic_name_format', $legacy[ 'comic_name_format' ] );
+ add_option( 'comic_thumbnail_crop', $legacy[ 'comic_thumbnail_crop' ] );
+ add_option( 'comic_name_format_date', $legacy[ 'comic_name_format_date' ] );
+ add_option( 'comic_thumbnail_size_w', $legacy[ 'comic_thumbnail_size_w' ] );
+ add_option( 'comic_thumbnail_size_h', $legacy[ 'comic_thumbnail_size_h' ] );
+ }
+ }
+
+ delete_option( 'webcomic_legacy' );
+ }
+ }
+
+ flush_rewrite_rules();
+ }
+
+ /** Handle dynamic requests.
+ *
+ * Dynamic request must have a 'webcomic_admin_ajax' value that is a
+ * valid callback in the form of a static class method, like
+ * 'Webcomic::method'.
+ *
+ * @hook admin_init
+ */
+ public function admin_init() {
+ if ( isset( $_GET[ 'webcomic_admin_ajax' ] ) and isset( $_SERVER[ 'HTTP_X_REQUESTED_WITH' ] ) and 'xmlhttprequest' === strtolower( $_SERVER[ 'HTTP_X_REQUESTED_WITH' ] ) ) {
+ call_user_func_array( explode( '::', $_GET[ 'webcomic_admin_ajax' ] ), $_GET );
+
+ die;
+ }
+ }
+
+ /** Add contextual help and change the post type icon.
+ *
+ * @uses Webcomic::$dir
+ * @uses Webcomic::$url
+ * @uses WebcomicHelp
+ * @hook admin_head
+ */
+ public function admin_head() {
+ $screen = get_current_screen();
+
+ if ( preg_match( '/^(page|options-media|tools_page_webcomic-commerce|tools_page_webcomic-upgrader|media_page_webcomic-generator|settings_page_webcomic-options|(edit-)?webcomic_(transcript|language)|(webcomic\d+_page_|edit-)?webcomic\d+(-options|_storyline|_character)?)$/', $screen->id ) ) {
+ require_once self::$dir . '-/php/help.php';
+
+ new WebcomicHelp( $screen );
+
+ if ( preg_match( '/^(edit-)?webcomic_(transcript|language)$/', $screen->id ) ) {
+ echo '<style>#icon-edit{background:url("', self::$url, '-/img/transcript.png")}</style>';;
+ } else if ( preg_match( '/^(edit-)?webcomic\d+(_storyline|_character)?$/', $screen->id ) ) {
+ echo '<style>#icon-edit{background:url("', self::$url, '-/img/webcomic.png")}</style>';
+ }