diff --git a/class-open-attribute-widget.php b/class-open-attribute-widget.php new file mode 100644 index 0000000..465a223 --- /dev/null +++ b/class-open-attribute-widget.php @@ -0,0 +1,117 @@ + 'OpenAttribute Widget', + 'description' => 'Display a a license for your blog post or entire site in a widget', + 'customize_selective_refresh' => true, + ], + '' + ); + } + + /** + * Echoes the widget content + * + * @return void + */ + public function widget( $args, $instance ) { + if ( ( $instance['openattribute_link'] ) || $instance['openattribute_image'] ) { + global $wp_query; + + if ( is_single() ) { + if ( get_option( 'openattribute_widgetset' ) === '1' ) { + $disable = get_post_meta( $wp_query->posts[0]->ID, 'disable_license' ); + + if ( 'off' === $disable[0] || '' === $disable[0] ) { + $display = true; + + if ( get_option( 'openattribute_blogoverride' ) === '1' ) { + $content = $wp_query->posts[0]->post_content; + $author = explode( 'oaauthor', $content ); + $title = explode( 'oatitle', $content ); + $oashorthand = explode( 'oashorthand', $content ); + + if ( count( $author ) !== 1 ) { + $display = false; + } + + if ( count( $title ) !== 1 ) { + $display = false; + } + + if ( count( $oashorthand ) !== 1 ) { + $display = false; + } + } + + if ( $display ) { + echo $args['before_widget']; + echo $args['before_title']; + echo 'Attribute me'; + echo $args['after_title']; + + if ( $instance['openattribute_image'] ) { + echo ''; + } + + if ( $instance['openattribute_link'] ) { + echo 'Attribute this resource'; + } + + echo $args['after_widget']; + } + } + } + } + } + } + + /** + * Updates a particular instance of a widget + * + * @return array + */ + public function update( $new_instance, $old_instance ) { + $instance = $old_instance; + + $instance['openattribute_link'] = strip_tags( $new_instance['openattribute_link'] ); + $instance['openattribute_image'] = strip_tags( $new_instance['openattribute_image'] ); + + return $instance; + } + + /** + * Outputs the settings update form + * + * @return void + */ + public function form( $instance ) { + ?> +

Tick the respective box if you wish the following to appear in this widget:

+ '; + } else { + echo ' />'; + } + ?> +
+ '; + } else { + echo ' />'; + } + ?> + + "; - - echo "

Information on OpenAttribute

"; - - echo "

Thanks for installing OpenAttribute. You can find out about how to use our wordpress plugin on our OpenAttribute site, where we also have browser plugins.

"; - - echo "

If you'd like to get started straight away - either go to OpenAttribute settings page or start a new blog post and look for the symbol below.

"; - - echo "

"; - - echo "

You can turn this screen off on the OpenAttribute settings page

"; - - echo ""; - - update_option('openattribute_firstrun', 0); - - } + + echo '

Information on OpenAttribute

'; + + echo '

Thanks for installing OpenAttribute. You can find out about how to use our wordpress plugin on our OpenAttribute site, where we also have browser plugins.

'; + + echo "

If you'd like to get started straight away - either go to OpenAttribute settings page or start a new blog post and look for the symbol below.

"; + + echo '

'; + + echo '

You can turn this screen off on the OpenAttribute settings page

'; + + echo ''; + + update_option( 'openattribute_firstrun', 0 ); + + } } function add_openattribute_action() { - + ?> - + - openattribute_iframe.css' type='text/css' media='all' /> -
- -

Adding licensing to your blog post

-

Choose the author for this blog - '', - 'orderby' => 'display_name', - 'order' => 'ASC', - 'multi' => true, - 'show' => 'display_name', - 'name' => 'user', - 'selected' => $current_user->ID, - 'id' => 'user', - 'class' => '', - 'blog_id' => $GLOBALS['blog_id'] + + string = data; + + string = string.split('>' + current_title + '').join(' xmlns:dc="http://purl.org/dc/terms/" property="dc:title">' + title + ''); + + string = string.split('xmlns:cc="http://creativecommons.org/ns#" href="' + current_attribution_url).join('xmlns:cc="http://creativecommons.org/ns#" href="' + attribution_url); + string = string.split(' oaauthor="' + current_author + '">' + current_author + '').join(' oaauthor="' + author + '">' + author + ''); + string = string.split('rel="license" href="' + current_oalicenseurl + '">').join('rel="license" href="' + license_url + '">'); + string = string.split(current_oashorthand + '').join(license_shorthand + ''); + + }else{ + + string = ' ' + title + '' + string += ' by ' + author + ''; + string += ' is licensed under a ' + license_shorthand + '.
'; + string += ' Based on a work at .'; + + } + + + + win.send_to_editor('' + string + ''); + + return true; + + } + + function insert_author(){ + + document.getElementById("author_oa").value = document.getElementById('user').options[document.getElementById('user').selectedIndex].text; + document.getElementById("url_oa").value = "/?author=" + document.getElementById('user').selectedIndex; + + } + + + openattribute_iframe.css' type='text/css' media='all' /> +

+ +

Adding licensing to your blog post

+

Choose the author for this blog + '', + 'orderby' => 'display_name', + 'order' => 'ASC', + 'multi' => true, + 'show' => 'display_name', + 'name' => 'user', + 'selected' => $current_user->ID, + 'id' => 'user', + 'class' => '', + 'blog_id' => $GLOBALS['blog_id'], ); - - wp_dropdown_users( $args ); ?>

Next click to insert the author

+ + wp_dropdown_users( $args ); + ?> +

Next click to insert the author

Now choose a license + + + +

'. __('Add license') .''; - - return $context . $result; +function openattribute_button( $context ) { + + $icon_url = WP_PLUGIN_URL . '/' . str_replace( basename( __FILE__ ), '', plugin_basename( __FILE__ ) ) . 'openatt.png'; + + $string = get_permalink(); + + $result = '' . __( 'Add license' ) . ''; + + return $context . $result; } function openattribute_register() { - update_option('openattribute_licenses', "http://creativecommons.org/licenses/by/3.0,Creative Commons Attribution CC BY 3.0\nhttp://creativecommons.org/licenses/by-nd/3.0,Creative Commons Attribution-NoDerivatives CC BY-ND 3.0\nhttp://creativecommons.org/licenses/by-nc-sa/3.0,Creative Commons Attribution-NonCommercial-ShareAlike CC BY-NC-SA 3.0 \nhttp://creativecommons.org/licenses/by-sa/3.0,Creative Commons Attribution-ShareAlike CC BY-SA 3.0\nhttp://creativecommons.org/licenses/by-nc/3.0,Creative Commons Attribution-NonCommercial CC BY-NC 3.0\nhttp://creativecommons.org/licenses/by-nc-nd/3.0,Creative Commons Attribution-NonCommercial-NoDerivatives CC BY-NC-ND 3.0\nhttps://creativecommons.org/publicdomain/zero/1.0/,Creative Commons Public Domain Dedication\nhttp://creativecommons.org/licenses/by/4.0,Creative Commons Attribution CC BY 4.0\nhttp://creativecommons.org/licenses/by-nd/4.0,Creative Commons Attribution-NoDerivatives CC BY-ND 4.0\nhttp://creativecommons.org/licenses/by-nc-sa/4.0,Creative Commons Attribution-NonCommercial-ShareAlike CC BY-NC-SA 4.0 \nhttp://creativecommons.org/licenses/by-sa/4.0,Creative Commons Attribution-ShareAlike CC BY-SA 4.0\nhttp://creativecommons.org/licenses/by-nc/4.0,Creative Commons Attribution-NonCommercial CC BY-NC 4.0\nhttp://creativecommons.org/licenses/by-nc-nd/4.0,Creative Commons Attribution-NonCommercial-NoDerivatives CC BY-NC-ND 4.0\n"); - add_option('openattribute_firstrun', 1); - add_option('openattribute_rss', 1); - add_option('openattribute_blogoverride', 1); - add_option('openattribute_buttonset', 1); - add_option('openattribute_linkset', 1); - add_option('openattribute_widgetset', 1); - add_option('openattribute_rdfa', 1); - add_option('openattribute_disable', 1); - add_option('openattribute_site_license', ''); - add_option('openattribute_site_author', ''); - add_option('openattribute_site_attribution_url', ''); - add_option('openattribute_append_content', '1'); - add_option('openattribute_append_footer', '1'); - add_option('openattribute_pre_license_html', '
'); - add_option('openattribute_post_license_html', '
'); - add_option('openattribute_authoroverride',''); - add_option('openattribute_index',0); - add_option('openattribute_indexsingle',0); - add_option('openattribute_postsonly',0); - add_option('openattribute_postsonly',0); - + update_option( 'openattribute_licenses', "http://creativecommons.org/licenses/by/3.0,Creative Commons Attribution CC BY 3.0\nhttp://creativecommons.org/licenses/by-nd/3.0,Creative Commons Attribution-NoDerivatives CC BY-ND 3.0\nhttp://creativecommons.org/licenses/by-nc-sa/3.0,Creative Commons Attribution-NonCommercial-ShareAlike CC BY-NC-SA 3.0 \nhttp://creativecommons.org/licenses/by-sa/3.0,Creative Commons Attribution-ShareAlike CC BY-SA 3.0\nhttp://creativecommons.org/licenses/by-nc/3.0,Creative Commons Attribution-NonCommercial CC BY-NC 3.0\nhttp://creativecommons.org/licenses/by-nc-nd/3.0,Creative Commons Attribution-NonCommercial-NoDerivatives CC BY-NC-ND 3.0\nhttps://creativecommons.org/publicdomain/zero/1.0/,Creative Commons Public Domain Dedication\nhttp://creativecommons.org/licenses/by/4.0,Creative Commons Attribution CC BY 4.0\nhttp://creativecommons.org/licenses/by-nd/4.0,Creative Commons Attribution-NoDerivatives CC BY-ND 4.0\nhttp://creativecommons.org/licenses/by-nc-sa/4.0,Creative Commons Attribution-NonCommercial-ShareAlike CC BY-NC-SA 4.0 \nhttp://creativecommons.org/licenses/by-sa/4.0,Creative Commons Attribution-ShareAlike CC BY-SA 4.0\nhttp://creativecommons.org/licenses/by-nc/4.0,Creative Commons Attribution-NonCommercial CC BY-NC 4.0\nhttp://creativecommons.org/licenses/by-nc-nd/4.0,Creative Commons Attribution-NonCommercial-NoDerivatives CC BY-NC-ND 4.0\n" ); + add_option( 'openattribute_firstrun', 1 ); + add_option( 'openattribute_rss', 1 ); + add_option( 'openattribute_blogoverride', 1 ); + add_option( 'openattribute_buttonset', 1 ); + add_option( 'openattribute_linkset', 1 ); + add_option( 'openattribute_widgetset', 1 ); + add_option( 'openattribute_rdfa', 1 ); + add_option( 'openattribute_disable', 1 ); + add_option( 'openattribute_site_license', '' ); + add_option( 'openattribute_site_author', '' ); + add_option( 'openattribute_site_attribution_url', '' ); + add_option( 'openattribute_append_content', '1' ); + add_option( 'openattribute_append_footer', '1' ); + add_option( 'openattribute_pre_license_html', '
' ); + add_option( 'openattribute_post_license_html', '
' ); + add_option( 'openattribute_authoroverride', '' ); + add_option( 'openattribute_index', 0 ); + add_option( 'openattribute_indexsingle', 0 ); + add_option( 'openattribute_postsonly', 0 ); + add_option( 'openattribute_postsonly', 0 ); + } function openattribute_options_page() { - ?> -
+ ?> +

Open Attribute

-

OpenAttribute is a Wordpress plugin designed to allow users to add reuse licenses into their WordPress sites.

+

OpenAttribute is a WordPress plugin designed to allow users to add reuse licenses into their WordPress sites.

Built to allow users to be as flexible as possible with their licenses, OpenAttribute allows you to attribute your entire site or attribute each post / page individually if required.

On this control panel options for licensing are therefore divided between per page / post and per site options. You can also add any licenses you would like to be able to use

This control panel also has plugin settings to control features such as RSS and attribution buttons

-
-

Attribution appearance settings

-

Here you can set settings for the plugin, these settings can be changed at anytime.

-
Choosing how the visitor sees the attribution
-

- The attribution can appear in two ways (both can be used if you wish). -

-
- " /> -

- As this button. -

-
-
-

- - Attribute this resource - -

-

- As a link such as the one above. -

-
-
- /> If this box is ticked, an Open Attribute "Attribute Me" button will appear on all attributed resources (pages and posts)
- Replace the Open Attribute "Attribute Me" button with a different URL
- /> If this box is ticked, an Open Attribute "Attribute Me" link will appear on all attributed resources (pages and posts)
- /> Display attribution in the widget. In doing this the Widget can be made to appear anywhere your theme supports Widgets
-

-
-
Where will the link / button appear?
-

- Your license can either appear directly at the end of your post or page - or after comments. You can tick both boxes if you prefer. You can use this and insert attribution as text into a page or post's content.

- Using this option is like setting a site license, and so will appear on all content. -

- /> Display the attribution after the blog's content (before comments)
- /> Display the attribution after comments on the blog
+ + + +

Attribution appearance settings

+

Here you can set settings for the plugin, these settings can be changed at anytime.

+
Choosing how the visitor sees the attribution
+

+ The attribution can appear in two ways (both can be used if you wish). +

+
+ +

+ As this button. +

+
+
+

+ + Attribute this resource + +

+

+ As a link such as the one above. +

+
+
+ /> If this box is ticked, an Open Attribute "Attribute Me" button will appear on all attributed resources (pages and posts)
+ Replace the Open Attribute "Attribute Me" button with a different URL
+ /> If this box is ticked, an Open Attribute "Attribute Me" link will appear on all attributed resources (pages and posts)
+ /> Display attribution in the widget. In doing this the Widget can be made to appear anywhere your theme supports Widgets
+

+
+
Where will the link / button appear?
+

+ Your license can either appear directly at the end of your post or page - or after comments. You can tick both boxes if you prefer. You can use this and insert attribution as text into a page or post's content.

+ Using this option is like setting a site license, and so will appear on all content. +

+ /> Display the attribution after the blog's content (before comments)
+ /> Display the attribution after comments on the blog
/> Display attribution on the index page
/> Display attribution on the index page (if multiple posts appear)
/> Display the attribution only on blog posts (not pages)
-
-

Please note the following

-

";?> -

If you insert using this button then the license is added as text to the post / page content itself, and will therefore be displayed where you put it in the page / post. The options above (after content / after comments) will not affect the location for this license.

-
-
-
HTML Options
-

- This section allows you (if you wish) to style how the attribution will appear. -

-

Before
-
-

After
-
-

-
-
Add licensing info to the RSS feeds
-

- Ticking this box will add attribution information to the RSS / RDFa / RSS2 feeds -

- /> If this box is ticked, the license information will be added to the RSS and Atom feeds
-
-
Administrative features
-

- You can allow an author to override a site license with a post / page specific license (inserted using the button shown above), or allow a user to opt out of licensing a specific post / page completely. -

- /> If this box is ticked, if you add a license into the page / post, then the site license will not be displayed
- /> If this box is ticked, a page / post author can opt out of having their work attributed
-
-
The first run page
-

- You can turn off the first run page here. -

- /> If this box is ticked, the "first run" guidance will be displayed
-
-

Add Licenses

-

Please enter the licenses you wish to use below. The format for the license is "URL,text to display on screen". If you wish to use a custom license, perhaps create a page on your blog to hold your licensing info. By default you have been provided with some Creative Commons licenses.

- -

Setup a site license

-

Choose a site license from this list - you can add new licenses in the box above

+
+

Please note the following

+

'; ?> +

If you insert using this button then the license is added as text to the post / page content itself, and will therefore be displayed where you put it in the page / post. The options above (after content / after comments) will not affect the location for this license.

+
+
+
HTML Options
+

+ This section allows you (if you wish) to style how the attribution will appear. +

+

Before
+
+

After
+
+

+
+
Add licensing info to the RSS feeds
+

+ Ticking this box will add attribution information to the RSS / RDFa / RSS2 feeds +

+ /> If this box is ticked, the license information will be added to the RSS and Atom feeds
+
+
Administrative features
+

+ You can allow an author to override a site license with a post / page specific license (inserted using the button shown above), or allow a user to opt out of licensing a specific post / page completely. +

+ /> If this box is ticked, if you add a license into the page / post, then the site license will not be displayed
+ /> If this box is ticked, a page / post author can opt out of having their work attributed
+
+
The first run page
+

+ You can turn off the first run page here. +

+ /> If this box is ticked, the "first run" guidance will be displayed
+
+

Add Licenses

+

Please enter the licenses you wish to use below. The format for the license is "URL,text to display on screen". If you wish to use a custom license, perhaps create a page on your blog to hold your licensing info. By default you have been provided with some Creative Commons licenses.

+ +

Setup a site license

+

Choose a site license from this list - you can add new licenses in the box above

The current license is - + '; + + } + ?> +

The current license is - + -

Choose an author name to display for this site
Choose an author name to display for this site
+ '', - 'orderby' => 'display_name', - 'order' => 'ASC', - 'multi' => true, - 'show' => 'display_name', - 'name' => 'user', - 'id' => 'user', - 'class' => '', - 'blog_id' => $GLOBALS['blog_id'] - ); - - wp_dropdown_users( $args ); - - ?>or enter a name

-

Do you wish to use a URL for this author (called an attribution url)" type="text" size="50" name="oa_url" />

+ 'show_option_all' => '', + 'orderby' => 'display_name', + 'order' => 'ASC', + 'multi' => true, + 'show' => 'display_name', + 'name' => 'user', + 'id' => 'user', + 'class' => '', + 'blog_id' => $GLOBALS['blog_id'], + ); + + wp_dropdown_users( $args ); + ?> + or enter a name

+

Do you wish to use a URL for this author (called an attribution url)

/> If this box is ticked, the author of the page / post will be attributed.
-

- - -

+

+ + +

- - "; - + } else { + if ( ! current_user_can( 'edit_post', $post_id ) ) { + return $post_id; } - + } + + if ( isset( $_POST['disable_license'] ) && 'on' === $_POST['disable_license'] ) { + update_post_meta( $post_id, 'disable_license', 'on' ); + } else { + update_post_meta( $post_id, 'disable_license', 'off' ); + } } -function openattribute_add_disable_menu($output){ +function openattribute_disable_menu() { + $disable_license = null; - if(get_option('openattribute_disable')==1){ - - add_meta_box( 'openattribute_id', 'OpenAttribute',"openattribute_disable_menu","post","normal","high"); - - } - - $meta = get_post_meta($_GET['post'], 'disable_license'); - - if($meta[0]=="on"){ - - add_meta_box( 'openattribute_id', 'OpenAttribute',"openattribute_disable_menu","post","normal","high"); - - } - + wp_nonce_field( plugin_basename( __FILE__ ), 'openattribute_noncename' ); + + if ( isset( $_GET['post'] ) ) { + $disable_license = get_post_meta( $_GET['post'], 'disable_license', true ); + } + + if ( 'on' === $disable_license ) { + $checked = 'checked'; + } else { + $checked = ''; + } + + if ( ( 1 == get_option( 'openattribute_disable' ) ) || ( 'on' === $disable_license ) ) { + echo "To disable attribution for this post please tick this box "; + } } -function openattribute_add_license_content($output){ +function openattribute_add_disable_menu( $output ) { + $disable_license = null; + + if ( get_option( 'openattribute_disable' ) == 1 ) { + add_meta_box( 'openattribute_id', 'OpenAttribute', 'openattribute_disable_menu', 'post', 'normal', 'high' ); + } + if ( isset( $_GET['post'] ) ) { + $disable_license = get_post_meta( $_GET['post'], 'disable_license', true ); + } + + if ( 'on' === $disable_license ) { + add_meta_box( 'openattribute_id', 'OpenAttribute', 'openattribute_disable_menu', 'post', 'normal', 'high' ); + } +} + +function openattribute_add_license_content( $output ) { global $wp_query, $post; - global $wp_query,$post; - - $indexposts = get_option('openattribute_index'); - $indexsingle = get_option('openattribute_indexsingle'); - $postsonly = get_option('openattribute_postsonly'); - + + $indexposts = get_option( 'openattribute_index' ); + $indexsingle = get_option( 'openattribute_indexsingle' ); + $postsonly = get_option( 'openattribute_postsonly' ); + + $site_license_url = ''; + $display_first = false; - - if(is_home()&&$indexposts){ - - if(is_single()){ - + + if ( is_home() && $indexposts ) { + if ( is_single() ) { $display_first = true; - - }else if($indexsingle){ - + } elseif ( $indexsingle ) { $display_first = true; - } - - }else if(is_page()&&$postsonly){ - + } elseif ( is_page() && $postsonly ) { $display_first = true; - - }else if(is_single()){ - + } elseif ( is_single() ) { $display_first = true; - } - - if($display_first){ - - if(get_option('openattribute_append_content')==1){ - - $disable = get_post_meta($wp_query->posts[0]->ID, 'disable_license'); - - if($disable[0]=="off"||$disable[0]==""){ - + + if ( $display_first ) { + if ( get_option( 'openattribute_append_content' ) == 1 ) { + $disable = get_post_meta( $wp_query->posts[0]->ID, 'disable_license' ); + + if ( $disable[0] == 'off' || $disable[0] == '' ) { $display = true; - - if(get_option('openattribute_blogoverride')==1){ - - $author = explode("oaauthor",$output); - $title = explode("oatitle",$output); - $oashorthand = explode("oalicense",$output); - - if(count($author)!=1){ - + + if ( get_option( 'openattribute_blogoverride' ) == 1 ) { + $author = explode( 'oaauthor', $output ); + $title = explode( 'oatitle', $output ); + $oashorthand = explode( 'oalicense', $output ); + + if ( count( $author ) != 1 ) { $display = false; - } - - if(count($title)!=1){ - + + if ( count( $title ) != 1 ) { $display = false; - } - - if(count($oashorthand)!=1){ - + + if ( count( $oashorthand ) != 1 ) { $display = false; - } - } - - if($display_first){ - - $author = get_option('openattribute_site_author'); - $site_license = get_option('openattribute_site_license'); - $site_attribution_url = get_option('openattribute_site_attribution_url'); - $licenses = get_option('openattribute_licenses'); - - if(get_option('openattribute_authoroverride')==1){ - - $author = get_the_author_meta("display_name"); - $site_attribution_url = get_the_author_meta("user_url"); - + + if ( $display_first ) { + $author = get_option( 'openattribute_site_author' ); + $site_license = get_option( 'openattribute_site_license' ); + $site_attribution_url = get_option( 'openattribute_site_attribution_url' ); + $licenses = get_option( 'openattribute_licenses' ); + + if ( get_option( 'openattribute_authoroverride' ) == 1 ) { + $author = get_the_author_meta( 'display_name' ); + $site_attribution_url = get_the_author_meta( 'user_url' ); } - - $data_licenses = explode("\n",$licenses); - - while($license = array_shift($data_licenses)){ - - $pair = explode(",",$license); - - if(trim($pair[1])==trim($site_license)){ - + + $data_licenses = explode( "\n", $licenses ); + + while ( $license = array_shift( $data_licenses ) ) { + $pair = explode( ',', $license ); + + if ( isset( $pair[1] ) && trim( $pair[1] ) == trim( $site_license ) ) { $site_license_url = $pair[0]; - } - } - - $license_data .= stripslashes(get_option('openattribute_pre_license_html')); - - if(get_option('openattribute_buttonset')==1){ - - $license_data .= '
'; - - if(get_option("openattribute_altlink")!=""){ - $license_data .= ''; - }else{ - $license_data .= ''; + + $license_data = stripslashes( get_option( 'openattribute_pre_license_html' ) ); + + if ( get_option( 'openattribute_buttonset' ) == 1 ) { + $license_data .= '
'; + + if ( get_option( 'openattribute_altlink' ) != '' ) { + $license_data .= ''; + } else { + $license_data .= ''; } - $license_data .= '
'; - - } - - $license_data .= '' . the_title( '', '', 0 ) . ' / ' . get_bloginfo( "name" ) . ''; - $license_data .= ' by ' . $author . ''; - $license_data .= ' is licensed under a ' . $site_license . ''; - $license_data .= get_option('openattribute_post_license_html'); - - $output .= $license_data; - + + $license_data .= '
'; + } + + $license_data .= '' . the_title( '', '', 0 ) . ' / ' . get_bloginfo( 'name' ) . ''; + $license_data .= ' by ' . $author . ''; + $license_data .= ' is licensed under a ' . $site_license . ''; + $license_data .= get_option( 'openattribute_post_license_html' ); + + $output .= $license_data; } - } - } - } - + return $output; } -function openattribute_add_license_footer($content){ +function openattribute_add_license_footer( $content ) { global $wp_query,$post; - - $indexposts = get_option('openattribute_index'); - $indexsingle = get_option('openattribute_indexsingle'); - $postsonly = get_option('openattribute_postsonly'); - + + $indexposts = get_option( 'openattribute_index' ); + $indexsingle = get_option( 'openattribute_indexsingle' ); + $postsonly = get_option( 'openattribute_postsonly' ); + $display_first = false; - - if(is_home()&&$indexposts){ - - if(is_single()){ - + + if ( is_home() && $indexposts ) { + + if ( is_single() ) { + $display_first = true; - - }else if($indexsingle){ - + + } elseif ( $indexsingle ) { + $display_first = true; - + } - - }else if(is_page()&&$postsonly){ - + } elseif ( is_page() && $postsonly ) { + $display_first = true; - - }else if(is_single()){ - + + } elseif ( is_single() ) { + $display_first = true; - + } - - if($display_first){ - - if(get_option('openattribute_append_footer')==1){ - - $disable = get_post_meta($wp_query->posts[0]->ID, 'disable_license'); - - if($disable[0]=="off"||$disable[0]==""){ - + + if ( $display_first ) { + + if ( get_option( 'openattribute_append_footer' ) == 1 ) { + + $disable = get_post_meta( $wp_query->posts[0]->ID, 'disable_license' ); + + if ( $disable[0] == 'off' || $disable[0] == '' ) { + $display = true; - - if(get_option('openattribute_blogoverride')==1){ - + + if ( get_option( 'openattribute_blogoverride' ) == 1 ) { + $content = $wp_query->posts[0]->post_content; - - $author = explode("oaauthor",$content); - $title = explode("oatitle",$content); - $oashorthand = explode("oashorthand",$content); - - if(count($author)!=1){ - + + $author = explode( 'oaauthor', $content ); + $title = explode( 'oatitle', $content ); + $oashorthand = explode( 'oashorthand', $content ); + + if ( count( $author ) != 1 ) { + $display = false; - + } - - if(count($title)!=1){ - + + if ( count( $title ) != 1 ) { + $display = false; - + } - - if(count($oashorthand)!=1){ - + + if ( count( $oashorthand ) != 1 ) { + $display = false; - + } - } - - if($display){ - - get_option('openattribute_buttonset'); - $author = get_option('openattribute_site_author'); - $site_license = get_option('openattribute_site_license'); - $site_attribution_url = get_option('openattribute_site_attribution_url'); - $licenses = get_option('openattribute_licenses'); - - if(get_option('openattribute_authoroverride')==1){ - - $author = get_the_author_meta("display_name"); - $site_attribution_url = get_the_author_meta("user_url"); - + + if ( $display ) { + + get_option( 'openattribute_buttonset' ); + $author = get_option( 'openattribute_site_author' ); + $site_license = get_option( 'openattribute_site_license' ); + $site_attribution_url = get_option( 'openattribute_site_attribution_url' ); + $licenses = get_option( 'openattribute_licenses' ); + + if ( get_option( 'openattribute_authoroverride' ) == 1 ) { + + $author = get_the_author_meta( 'display_name' ); + $site_attribution_url = get_the_author_meta( 'user_url' ); + } - - $data_licenses = explode("\n",$licenses); - - while($license = array_shift($data_licenses)){ - - $pair = explode(",",$license); - - if(trim($pair[1])==trim($site_license)){ - + + $data_licenses = explode( "\n", $licenses ); + + while ( $license = array_shift( $data_licenses ) ) { + + $pair = explode( ',', $license ); + + if ( trim( $pair[1] ) == trim( $site_license ) ) { + $site_license_url = $pair[0]; - + } - } - - if($display_first){ - - $license_data .= stripslashes(get_option('openattribute_pre_license_html')); - - if(get_option('openattribute_buttonset')==1){ - - $license_data .= '
'; - - if(get_option("openattribute_altlink")!=""){ - $license_data .= ''; - }else{ - $license_data .= ''; + + if ( $display_first ) { + + $license_data = stripslashes( get_option( 'openattribute_pre_license_html' ) ); + + if ( get_option( 'openattribute_buttonset' ) == 1 ) { + + $license_data .= '
'; + + if ( get_option( 'openattribute_altlink' ) != '' ) { + $license_data .= ''; + } else { + $license_data .= ''; } - $license_data .= '
'; - - } - - $license_data .= '' . the_title( '', '', 0 ) . ' / ' . get_bloginfo( "name" ) . ''; - $license_data .= ' by ' . $author . ''; - $license_data .= ' is licensed under a ' . $site_license . ''; - $license_data .= get_option('openattribute_post_license_html'); - - $output .= $license_data; - - echo $output; - - } - + $license_data .= '
'; + + } + + $license_data .= '' . the_title( '', '', 0 ) . ' / ' . get_bloginfo( 'name' ) . ''; + $license_data .= ' by ' . $author . ''; + $license_data .= ' is licensed under a ' . $site_license . ''; + $license_data .= get_option( 'openattribute_post_license_html' ); + + $output = $license_data; + + echo $output; + + } } - } - } - } } -function openattribute_add_license_header(){ - +function openattribute_add_license_header() { global $post; - $indexposts = get_option('openattribute_index'); - $indexsingle = get_option('openattribute_indexsingle'); - $postsonly = get_option('openattribute_postsonly'); - + $disable = null; + + $indexposts = get_option( 'openattribute_index' ); + $indexsingle = get_option( 'openattribute_indexsingle' ); + $postsonly = get_option( 'openattribute_postsonly' ); + $display_first = false; - - if(is_home()&&$indexposts){ - - if(is_single()){ - + + if ( is_home() && $indexposts ) { + if ( is_single() ) { $display_first = true; - - }else if($indexsingle){ - + } elseif ( $indexsingle ) { $display_first = true; - } - - }else if(is_page()&&$postsonly){ - + } elseif ( is_page() && $postsonly ) { $display_first = true; - - }else if(is_single()){ - + } elseif ( is_single() ) { $display_first = true; - } - - if($display_first){ - - if((get_option('openattribute_append_footer')==1)||(get_option('openattribute_append_content')==1)||(get_option('openattribute_widgetset')==1)){ - - if($disable[0]==""){ - - $disable = get_post_meta($_GET['page_id'], 'disable_license'); - + + if ( $display_first ) { + if ( ( get_option( 'openattribute_append_footer' ) == 1 ) || ( get_option( 'openattribute_append_content' ) == 1 ) || ( get_option( 'openattribute_widgetset' ) == 1 ) ) { + if ( isset( $_GET['page_id'] ) ) { + $disable = get_post_meta( $_GET['page_id'], 'disable_license' ); } - - if($disable[0]=="off"||$disable[0]==""){ - + + if ( $disable[0] == 'off' || $disable[0] == '' ) { $display = true; - - if($display){ - - if((get_option('openattribute_buttonset')==1)||(get_option('openattribute_linkset')==1)||(get_option('openattribute_widgetset')==1)){ - - $author = get_option('openattribute_site_author'); - $site_license = get_option('openattribute_site_license'); - $site_attribution_url = get_option('openattribute_site_attribution_url'); - $licenses = get_option('openattribute_licenses'); - - $data_licenses = explode("\n",$licenses); - - while($license = array_shift($data_licenses)){ - - $pair = explode(",",$license); - - if(trim($pair[1])==trim($site_license)){ - + + if ( $display ) { + if ( ( get_option( 'openattribute_buttonset' ) == 1 ) || ( get_option( 'openattribute_linkset' ) == 1 ) || ( get_option( 'openattribute_widgetset' ) == 1 ) ) { + $author = get_option( 'openattribute_site_author' ); + $site_license = get_option( 'openattribute_site_license' ); + $site_attribution_url = get_option( 'openattribute_site_attribution_url' ); + $licenses = get_option( 'openattribute_licenses' ); + + $data_licenses = explode( "\n", $licenses ); + + while ( $license = array_shift( $data_licenses ) ) { + $pair = explode( ',', $license ); + + if ( isset( $pair[1] ) && trim( $pair[1] ) == trim( $site_license ) ) { $site_license_url = $pair[0]; - } - } - - if($display_first){ - + + if ( $display_first ) { echo ''; - - if(!isset($site_attribution_url)){ - + echo ' }'; + + if ( empty( $site_attribution_url ) ) { $site_attribution_url = site_url(); - } - - if(!isset($site_license_url)){ - + + if ( empty( $site_license_url ) ) { $site_license_url = $site_license; - } - - $license_data = ''; - - echo $license_data; - - } - - } - + + $license_data = ''; + + echo $license_data; + } + } } - } - } - } - } -function openattribute_rdf_ns(){ +function openattribute_rdf_ns() { - if(get_option('openattribute_site_license')!=""){ + if ( get_option( 'openattribute_site_license' ) != '' ) { echo 'xmlns:cc="http://creativecommons.org/ns#" '; - + } } -function openattribute_rdf_head(){ - - if(get_option('openattribute_site_license')!=""){ - - echo ''; - - } -} - -function openattribute_rss2_head(){ - - if(get_option('openattribute_site_license')!=""){ - - echo '' . get_option('openattribute_site_license') . ''; - echo '' . get_option('openattribute_site_license') . ''; - - } +function openattribute_rdf_head() { + + if ( get_option( 'openattribute_site_license' ) != '' ) { + + echo ''; + + } +} + +function openattribute_rss2_head() { + + if ( get_option( 'openattribute_site_license' ) != '' ) { + + echo '' . get_option( 'openattribute_site_license' ) . ''; + echo '' . get_option( 'openattribute_site_license' ) . ''; + + } } function openattribute_atom_head() { - if(get_option('openattribute_site_license')!=""){ - - echo ''; - - } + if ( get_option( 'openattribute_site_license' ) != '' ) { + + echo ''; + + } } -function openattribute_augment_feed($content) { - - if(get_option('openattribute_site_license')!=""){ - - if(get_option('openattribute_blogoverride')==0){ - - echo '' . get_option('openattribute_site_license') . ''; - echo '' . get_option('openattribute_site_license') . ''; - - }else{ +function openattribute_augment_feed( $content ) { + + if ( get_option( 'openattribute_site_license' ) != '' ) { + + if ( get_option( 'openattribute_blogoverride' ) == 0 ) { + + echo '' . get_option( 'openattribute_site_license' ) . ''; + echo '' . get_option( 'openattribute_site_license' ) . ''; + + } else { - $display = true; - - $content = $wp_query->post->post_content; - - if(get_option('openattribute_blogoverride')==1){ - - $author = explode("oaauthor",$content); - $title = explode("oatitle",$content); - $oashorthand = explode("oashorthand",$content); - - if(count($author)!=1){ - - $display = false; - - } - - if(count($title)!=1){ - - $display = false; - - } - - if(count($oashorthand)!=1){ - - $display = false; - - } - - if($display){ - - $data=explode("oalicenseurl=\"",$content); - - if(count($data)!=1){ - - $license = explode("\"",$data[0]); - - echo '' . $license[0] . ''; - echo '' . $license[0] . ''; - - } - - } - - } - - } - - }else{ - - $content = $wp_query->post->post_content; $display = true; - - $author = explode("oaauthor",$content); - $title = explode("oatitle",$content); - $oashorthand = explode("oashorthand",$content); - - if(count($author)!=1){ - - $display = false; - - } - - if(count($title)!=1){ - - $display = false; - - } - - if(count($oashorthand)!=1){ - - $display = false; - - } - - if($display){ - - $data=explode("oalicenseurl=\"",$content); - - if(count($data)!=1){ - - $license = explode("\"",$data[0]); - - echo '' . $license[0] . ''; - echo '' . $license[0] . ''; - + + $content = $wp_query->post->post_content; + + if ( get_option( 'openattribute_blogoverride' ) == 1 ) { + + $author = explode( 'oaauthor', $content ); + $title = explode( 'oatitle', $content ); + $oashorthand = explode( 'oashorthand', $content ); + + if ( count( $author ) != 1 ) { + + $display = false; + + } + + if ( count( $title ) != 1 ) { + + $display = false; + + } + + if ( count( $oashorthand ) != 1 ) { + + $display = false; + + } + + if ( $display ) { + + $data = explode( 'oalicenseurl="', $content ); + + if ( count( $data ) != 1 ) { + + $license = explode( '"', $data[0] ); + + echo '' . $license[0] . ''; + echo '' . $license[0] . ''; + + } } - } - } - - } - - function openattribute_stylesheet(){ - - echo ' '; - - } - - function openattribute_widget(){ + } else { + + $content = $wp_query->post->post_content; + $display = true; + + $author = explode( 'oaauthor', $content ); + $title = explode( 'oatitle', $content ); + $oashorthand = explode( 'oashorthand', $content ); + + if ( count( $author ) != 1 ) { - register_widget('OpenAttributeWidget'); - + $display = false; + + } + + if ( count( $title ) != 1 ) { + + $display = false; + + } + + if ( count( $oashorthand ) != 1 ) { + + $display = false; + + } + + if ( $display ) { + + $data = explode( 'oalicenseurl="', $content ); + + if ( count( $data ) != 1 ) { + + $license = explode( '"', $data[0] ); + + echo '' . $license[0] . ''; + echo '' . $license[0] . ''; + + } + } } +} + +function openattribute_stylesheet() { + + echo ' '; + +} + +function openattribute_widget() { + register_widget( 'Open_Attribute_Widget' ); +}; + // Modifications to feeds -; -add_action('rss_head', 'openattribute_rss2_head'); -add_action('rss2_head', 'openattribute_rss2_head'); -add_action('atom_head', 'openattribute_atom_head'); -add_action('rss2_ns', 'openattribute_rdf_ns'); -add_action('rdf_ns', 'openattribute_rdf_ns'); -add_action('rdf_header', 'openattribute_rdf_head'); -add_action("atom_entry","openattribute_augment_feed"); -add_action("rdf_item","openattribute_augment_feed"); -add_action("rss2_item","openattribute_augment_feed"); -add_action("rss_item","openattribute_augment_feed"); + +add_action( 'rss_head', 'openattribute_rss2_head' ); +add_action( 'rss2_head', 'openattribute_rss2_head' ); +add_action( 'atom_head', 'openattribute_atom_head' ); +add_action( 'rss2_ns', 'openattribute_rdf_ns' ); +add_action( 'rdf_ns', 'openattribute_rdf_ns' ); +add_action( 'rdf_header', 'openattribute_rdf_head' ); +add_action( 'atom_entry', 'openattribute_augment_feed' ); +add_action( 'rdf_item', 'openattribute_augment_feed' ); +add_action( 'rss2_item', 'openattribute_augment_feed' ); +add_action( 'rss_item', 'openattribute_augment_feed' ); // Admin options on wp-admin side of things -add_action('admin_init', 'openattribute_register' ); -add_action('admin_menu', 'openattribute_menu_option'); -add_action('admin_head', 'openattribute_postform'); -add_action('admin_notices', 'openattribute_firstrun'); +add_action( 'admin_init', 'openattribute_register' ); +add_action( 'admin_menu', 'openattribute_menu_option' ); +add_action( 'admin_head', 'openattribute_postform' ); +add_action( 'admin_notices', 'openattribute_firstrun' ); // Code for the insert into blog function for non-site licenses. -add_filter('media_buttons_context', 'openattribute_button'); -add_filter('media_upload_openattribute', 'add_openattribute_action'); +add_filter( 'media_buttons_context', 'openattribute_button' ); +add_filter( 'media_upload_openattribute', 'add_openattribute_action' ); // Code to handle blog specific licensing -add_action("add_meta_boxes", "openattribute_add_disable_menu" ); -add_action('save_post', 'openattribute_save_post'); +add_action( 'add_meta_boxes', 'openattribute_add_disable_menu' ); +add_action( 'save_post', 'openattribute_save_post' ); // Code to display site licenses -add_action("the_content", 'openattribute_add_license_content'); -add_action('get_footer', 'openattribute_add_license_footer'); +add_action( 'the_content', 'openattribute_add_license_content' ); +add_action( 'get_footer', 'openattribute_add_license_footer' ); // // The footer attribution may appear neater if you use wp_footer over get_footer @@ -1512,19 +1352,14 @@ function openattribute_widget(){ //add_action('wp_footer', 'openattribute_add_license_footer'); // -add_action('loop_start', 'openattribute_add_license_header'); +add_action( 'loop_start', 'openattribute_add_license_header' ); // Load pop up for style sheet -add_action('wp_head', 'openattribute_stylesheet'); +add_action( 'wp_head', 'openattribute_stylesheet' ); // Load the Widget code - -include "openattribute_widget.php"; +require 'class-open-attribute-widget.php'; // Widget register - -add_action('widgets_init', 'openattribute_widget'); - - -?> +add_action( 'widgets_init', 'openattribute_widget' ); diff --git a/openattribute_widget.php b/openattribute_widget.php deleted file mode 100644 index 50656c0..0000000 --- a/openattribute_widget.php +++ /dev/null @@ -1,138 +0,0 @@ - 'OpenAttribute Widget', - 'description' => 'Display a a license for your blog post or entire site in a widget' - ); - - $this->WP_Widget('openattribute_widget', 'OpenAttribute Widget', $widgetSettings, ''); - - } - - function widget($args, $instance){ - - if(($instance['openattribute_link']) || $instance['openattribute_image']){ - - global $wp_query; - - if(is_single()){ - - if(get_option('openattribute_widgetset')==1){ - - $disable = get_post_meta($wp_query->posts[0]->ID, 'disable_license'); - - if($disable[0]=="off"||$disable[0]==""){ - - $display = true; - - if(get_option('openattribute_blogoverride')==1){ - - $content = $wp_query->posts[0]->post_content; - - $author = explode("oaauthor",$content); - $title = explode("oatitle",$content); - $oashorthand = explode("oashorthand",$content); - - if(count($author)!=1){ - - $display = false; - - } - - if(count($title)!=1){ - - $display = false; - - } - - if(count($oashorthand)!=1){ - - $display = false; - - } - - } - - if($display){ - - echo $args['before_widget']; - echo $args['before_title']; - echo "Attribute me"; - echo $args['after_title']; - - if($instance['openattribute_image']){ - - echo ""; - - } - - if($instance['openattribute_link']){ - - echo "Attribute this resource"; - - } - - echo $args['after_widget']; - - } - } - } - - } - - } - - } - - public function update($new_instance, $old_instance) { - - print_r($new_instance); - - $instance = $old_instance; - - $instance['openattribute_link'] = strip_tags($new_instance['openattribute_link']); - - $instance['openattribute_image'] = strip_tags($new_instance['openattribute_image']); - - return $instance; - - } - - function form($instance) { - - ?>

Tick the respective box if you wish the following to appear in this widget:

- "; - - }else{ - - echo " />"; - - } - ?> -
- "; - - }else{ - - echo " />"; - - } - ?> - \ No newline at end of file diff --git a/readme.txt b/readme.txt index cbc6920..b5e6e87 100644 --- a/readme.txt +++ b/readme.txt @@ -2,10 +2,10 @@ Contributors: OpenAttribute, pgogy, barlas Tags: attribution, licensing, creative commons, openattribute, mozilla, drumbeat, copyright, recognition, post, pages Requires at least: 3.0.0 -Tested up to: 4.3 +Tested up to: 4.9.7 Stable tag: 1 -Allows a user to add licensing and attribution information into a blog post / WordPress powered site. +Allows a user to add licensing and attribution information into a blog post / WordPress powered site. == Description == @@ -19,12 +19,20 @@ This section describes how to install the plugin and get it working. e.g. -1. Upload the contents of the zip (including the folder - called 'openattribute-for-wordpress') to the `/wp-content/plugins/` directory +1. Upload the contents of the zip (including the folder - called 'openattribute') to the `/wp-content/plugins/` directory 2. Activate the plugin through the 'Plugins' menu in WordPress 3. Visit the settings page for the plugin - No other configuration is required. == Changelog == += 1.1.0 = +Change WP_Widget to call __construct() instead of old PHP 4 constructors +Implement multiple isset() checks to ensure we don't access unidentified indexes +Add support to the widget for the WordPress customiser +Update code format to match some WordPress core conventions +Change openattribute_widget.php to class-openattribute-widget.php +Change plugin folder name to be openattribute instead of openattribute-for-wordpress, matching the main plugin file as per WordPress recommended naming conventions + = 1 = Fixed licence listing bug. Thanks to Phil Barker @@ -72,4 +80,4 @@ We are a new plugin - so no questions so far. Perhaps try http://openattribute.c == Upgrade Notice == -None exist so far \ No newline at end of file +None exist so far