Changeset 1527063
- Timestamp:
- 11/02/2016 11:47:48 PM (9 years ago)
- Location:
- hypothesis
- Files:
-
- 6 added
- 2 deleted
- 6 edited
- 1 copied
-
tags/0.4.8 (copied) (copied from hypothesis/trunk)
-
tags/0.4.8/composer.json (added)
-
tags/0.4.8/composer.lock (added)
-
tags/0.4.8/formgen.php (deleted)
-
tags/0.4.8/hypothesis.php (modified) (13 diffs)
-
tags/0.4.8/js/sidebaropen.js (modified) (2 diffs)
-
tags/0.4.8/phpcs.xml (added)
-
tags/0.4.8/readme.txt (modified) (1 diff)
-
trunk/composer.json (added)
-
trunk/composer.lock (added)
-
trunk/formgen.php (deleted)
-
trunk/hypothesis.php (modified) (13 diffs)
-
trunk/js/sidebaropen.js (modified) (2 diffs)
-
trunk/phpcs.xml (added)
-
trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
hypothesis/tags/0.4.8/hypothesis.php
r1431925 r1527063 2 2 /** 3 3 * @package Hypothesis 4 * @version 0.4. 54 * @version 0.4.8 5 5 */ 6 6 7 /* 7 8 Plugin Name: Hypothesis … … 9 10 Description: Hypothesis is an open platform for the collaborative evaluation of knowledge. This plugin embeds the necessary scripts in your Wordpress site to enable any user to use Hypothesis without installing any extensions. 10 11 Author: The Hypothesis Project and contributors 11 Version: 0.4. 712 Version: 0.4.8 12 13 Author URI: http://hypothes.is/ 13 14 */ 14 15 15 // Exit if called directly 16 defined( 'ABSPATH' ) or die ( 'Cannot access pages directly.' );17 18 19 // From https://codex.wordpress.org/Creating_Options_Pages 20 class HypothesisSettingsPage 21 {16 // Exit if called directly. 17 defined( 'ABSPATH' ) or die( 'Cannot access pages directly.' ); 18 19 /** 20 * Create settings page (see https://codex.wordpress.org/Creating_Options_Pages) 21 */ 22 class HypothesisSettingsPage { 22 23 /** 23 24 * Holds the values to be used in the fields callbacks 25 * 26 * @var array 24 27 */ 25 28 private $options; 26 29 27 30 /** 31 * Holds the posttypes to be used in the fields callbacks 32 * 33 * @var array 34 */ 35 private $posttypes; 36 37 /** 28 38 * Start up 29 39 */ 30 public function __construct() 31 { 40 public function __construct() { 32 41 add_action( 'admin_menu', array( $this, 'add_plugin_page' ) ); 33 42 add_action( 'admin_init', array( $this, 'page_init' ) ); … … 37 46 * Add options page 38 47 */ 39 public function add_plugin_page() 40 { 41 // This page will be under "Settings" 48 public function add_plugin_page() { 42 49 add_options_page( 43 ' Settings Admin',50 'Hypothesis Settings', 44 51 'Hypothesis', 45 52 'manage_options', … … 50 57 51 58 /** 59 * Return an array of post type slugs and corresponding plural display names for options page. 60 * 61 * @returns array 62 */ 63 public static function get_posttypes() { 64 return apply_filters('hypothesis_supported_posttypes', array( 65 'post' => 'posts', 66 'page' => 'pages', 67 ) ); 68 } 69 70 /** 52 71 * Options page callback 53 72 */ 54 public function create_admin_page() 55 { 56 // Set class property 57 $this->options = get_option( 'wp_hypothesis_options' ); 58 include ( 'formgen.php' ); 59 } 73 public function create_admin_page() { 74 // Set class property. 75 $this->options = get_option( 'wp_hypothesis_options' ); ?> 76 <div class="wrap"> 77 <form method="post" action="options.php"> 78 <?php 79 settings_fields( 'hypothesis_option_group' ); 80 do_settings_sections( 'hypothesis-setting-admin' ); 81 submit_button(); 82 ?> 83 </form> 84 </div> 85 <?php } 60 86 61 87 /** 62 88 * Register and add settings 63 89 */ 64 public function page_init() 65 { 90 public function page_init() { 91 $posttypes = $this->get_posttypes(); 92 66 93 register_setting( 67 ' my_option_group', // Option group68 'wp_hypothesis_options', // Option name 69 array( $this, 'sanitize' ) // Sanitize 94 'hypothesis_option_group', // Option group. 95 'wp_hypothesis_options', // Option name. 96 array( $this, 'sanitize' ) // Sanitize callback. 70 97 ); 71 98 … … 74 101 */ 75 102 add_settings_section( 76 ' setting_section_id2', // ID77 'Hypothesis Settings', // Title 78 array( $this, ' print_section_info' ), // Callback79 'hypothesis-setting-admin' // Page 103 'hypothesis_settings_section', // ID. 104 'Hypothesis Settings', // Title. 105 array( $this, 'settings_section_info' ), // Callback. 106 'hypothesis-setting-admin' // Page. 80 107 ); 81 108 … … 85 112 array( $this, 'highlights_on_by_default_callback' ), 86 113 'hypothesis-setting-admin', 87 ' setting_section_id2'114 'hypothesis_settings_section' 88 115 ); 89 116 … … 93 120 array( $this, 'sidebar_open_by_default_callback' ), 94 121 'hypothesis-setting-admin', 95 ' setting_section_id2'122 'hypothesis_settings_section' 96 123 ); 97 124 … … 101 128 array( $this, 'serve_pdfs_with_via_default_callback' ), 102 129 'hypothesis-setting-admin', 103 ' setting_section_id2'130 'hypothesis_settings_section' 104 131 ); 105 132 106 133 /** 107 134 * Content Settings 108 * Control which pages / posts Hypothesis is loaded on.135 * Control which pages / posts / custom post types Hypothesis is loaded on. 109 136 */ 110 137 add_settings_section( 111 ' setting_section_id', // ID112 'Content Settings', // Title 113 array( $this, ' print_section_info2' ), // Callback114 'hypothesis-setting-admin' // Page 115 ); 116 138 'hypothesis_content_section', // ID. 139 'Content Settings', // Title. 140 array( $this, 'content_section_info' ), // Callback. 141 'hypothesis-setting-admin' // Page. 142 ); 143 117 144 add_settings_field( 118 145 'allow-on-front-page', … … 120 147 array( $this, 'allow_on_front_page_callback' ), 121 148 'hypothesis-setting-admin', 122 ' setting_section_id'149 'hypothesis_content_section' 123 150 ); 124 151 … … 128 155 array( $this, 'allow_on_blog_page_callback' ), 129 156 'hypothesis-setting-admin', 130 ' setting_section_id'131 ); 132 133 add_settings_field(134 'allow-on-posts',135 'Allow on posts',136 array( $this, 'allow_on_posts_callback' ),137 'hypothesis-setting-admin',138 'setting_section_id'139 ); 140 141 add_settings_field(142 'allow-on-pages',143 'Allow on pages',144 array( $this, 'allow_on_pages_callback' ),145 'hypothesis-setting-admin',146 'setting_section_id'147 );148 149 add_settings_field(150 'post_ids_show_h', // ID151 'Allow on posts (list of comma-separated post ids, no spaces)', // Title152 array( $this, 'post_ids_show_h_callback' ), // Callback 153 'hypothesis-setting-admin', // Page154 'setting_section_id' // Section155 );156 157 add_settings_field(158 'page_ids_show_h', // ID159 'Allow on pages (list of comma-separated page ids, no spaces)', // Title160 array( $this, 'page_ids_show_h_callback' ), // Callback161 'hypothesis-setting-admin', // Page162 'setting_section_id' // Section163 );164 165 add_settings_field(166 'post_ids_override', // ID 167 'Disallow on posts (list of comma-separated post ids, no spaces)', // Title168 a rray( $this, 'post_ids_override_callback' ), // Callback169 'hypothesis-setting-admin', // Page170 'setting_section_id' // Section171 );172 173 add_settings_field(174 'page_ids_override', // ID175 'Disallow on pages (list of comma-separated page ids, no spaces)', // Title176 array( $this, 'page_ids_override_callback' ), // Callback177 'hypothesis-setting-admin', // Page178 'setting_section_id' // Section179 );157 'hypothesis_content_section' 158 ); 159 160 foreach ( $posttypes as $slug => $name ) { 161 if ( 'post' === $slug ) { 162 $slug = 'posts'; 163 } elseif ( 'page' === $slug ) { 164 $slug = 'pages'; 165 } 166 167 add_settings_field( 168 "allow-on-$slug", 169 "Allow on $name", 170 array( $this, 'allow_on_posttype_callback' ), 171 'hypothesis-setting-admin', 172 'hypothesis_content_section', 173 array( 174 $slug, 175 $name, 176 ) 177 ); 178 } 179 180 foreach ( $posttypes as $slug => $name ) { 181 add_settings_field( 182 $slug . '_ids_show_h', // ID. 183 "Allow on specific $name (list of comma-separated $slug IDs, no spaces)", // Title. 184 array( $this, 'posttype_ids_show_h_callback' ), // Callback. 185 'hypothesis-setting-admin', // Page. 186 'hypothesis_content_section', // Section. 187 array( 188 $slug, 189 $name, 190 ) 191 ); 192 } 193 194 foreach ( $posttypes as $slug => $name ) { 195 add_settings_field( 196 $slug . '_ids_override', // ID. 197 "Disallow on specific $name (list of comma-separated $slug IDs, no spaces)", // Title. 198 array( $this, 'posttype_ids_override_callback' ), // Callback. 199 'hypothesis-setting-admin', // Page. 200 'hypothesis_content_section', // Section. 201 array( 202 $slug, 203 $name, 204 ) 205 ); 206 } 180 207 } 181 208 … … 183 210 * Sanitize each setting field as needed 184 211 * 185 * @param array $input Contains all settings fields as array keys 186 */ 187 public function sanitize( $input ) 188 {212 * @param array $input Contains all settings fields as array keys. 213 */ 214 public function sanitize( $input ) { 215 $posttypes = $this->get_posttypes(); 189 216 $new_input = array(); 190 217 191 if( isset( $input['highlights-on-by-default'] ) ) 192 $new_input['highlights-on-by-default'] = absint($input['highlights-on-by-default']); 193 // else $new_input['highlights-on-by-default'] = 1; 194 195 if( isset( $input['sidebar-open-by-default'] ) ) 196 $new_input['sidebar-open-by-default'] = absint($input['sidebar-open-by-default']); 197 198 if( isset( $input['serve-pdfs-with-via'] ) ) 199 $new_input['serve-pdfs-with-via'] = absint($input['serve-pdfs-with-via']); 200 201 if( isset( $input['allow-on-blog-page'] ) ) 202 $new_input['allow-on-blog-page'] = absint($input['allow-on-blog-page']); 203 204 if( isset( $input['allow-on-front-page'] ) ) 205 $new_input['allow-on-front-page'] = absint($input['allow-on-front-page']); 206 207 if( isset( $input['allow-on-posts'] ) ) 208 $new_input['allow-on-posts'] = absint($input['allow-on-posts']); 209 210 if( isset( $input['allow-on-pages'] ) ) 211 $new_input['allow-on-pages'] = absint($input['allow-on-pages']); 212 213 if( isset( $input['post_ids_show_h'] ) ) 214 $new_input['post_ids_show_h'] = explode(',', esc_attr($input['post_ids_show_h'])); 215 216 if( isset( $input['page_ids_show_h'] ) ) 217 $new_input['page_ids_show_h'] = explode(',', esc_attr($input['page_ids_show_h'])); 218 219 if( isset( $input['post_ids_override'] ) ) 220 $new_input['post_ids_override'] = explode(',', esc_attr($input['post_ids_override'])); 221 222 if( isset( $input['page_ids_override'] ) ) 223 $new_input['page_ids_override'] = explode(',', esc_attr($input['page_ids_override'])); 218 if ( isset( $input['highlights-on-by-default'] ) ) { 219 $new_input['highlights-on-by-default'] = absint( $input['highlights-on-by-default'] ); 220 } 221 222 if ( isset( $input['sidebar-open-by-default'] ) ) { 223 $new_input['sidebar-open-by-default'] = absint( $input['sidebar-open-by-default'] ); 224 } 225 226 if ( isset( $input['serve-pdfs-with-via'] ) ) { 227 $new_input['serve-pdfs-with-via'] = absint( $input['serve-pdfs-with-via'] ); 228 } 229 230 if ( isset( $input['allow-on-blog-page'] ) ) { 231 $new_input['allow-on-blog-page'] = absint( $input['allow-on-blog-page'] ); 232 } 233 234 if ( isset( $input['allow-on-front-page'] ) ) { 235 $new_input['allow-on-front-page'] = absint( $input['allow-on-front-page'] ); 236 } 237 238 foreach ( $posttypes as $slug => $name ) { 239 if ( 'post' === $slug ) { // Adjust for backwards compatibility. 240 $slug = 'posts'; 241 } elseif ( 'page' === $slug ) { 242 $slug = 'pages'; 243 } 244 245 if ( isset( $input[ "allow-on-$slug" ] ) ) { 246 $new_input[ "allow-on-$slug" ] = absint( $input[ "allow-on-$slug" ] ); 247 } 248 249 if ( 'posts' === $slug ) { // Adjust for backwards compatibility. 250 $slug = 'post'; 251 } elseif ( 'pages' === $slug ) { 252 $slug = 'page'; 253 } 254 255 if ( isset( $input[ $slug . '_ids_show_h' ] ) ) { 256 $new_input[ $slug . '_ids_show_h' ] = explode( ',', esc_attr( $input[ $slug . '_ids_show_h' ] ) ); 257 } 258 259 if ( isset( $input[ $slug . '_ids_override' ] ) ) { 260 $new_input[ $slug . '_ids_override' ] = explode( ',', esc_attr( $input[ $slug . '_ids_override' ] ) ); 261 } 262 } 224 263 225 264 return $new_input; … … 229 268 * Print the Hypothesis Settings section text 230 269 */ 231 public function print_section_info() 232 { 233 print 'Customize Hypothesis defaults and behavior below:'; 270 public function settings_section_info() { 271 print 'Customize Hypothesis defaults and behavior.'; 234 272 } 235 273 … … 237 275 * Print the Content Settings section text 238 276 */ 239 public function print_section_info2() 240 { 241 print 'Control which pages Hypothesis is loaded on below:'; 242 } 243 244 /** 245 * HYPOTHESIS SETTINGS Callbacks 246 * These get the settings option array for a setting and print one of its values. 247 * They are used to set various defaults for the Hypothesis application. 248 */ 249 250 public function highlights_on_by_default_callback() 251 { 252 printf( 253 '<input type="checkbox" id="highlights-on-by-default" name="wp_hypothesis_options[highlights-on-by-default]" value="1" '.checked( isset($this->options["highlights-on-by-default"]) ? $this->options["highlights-on-by-default"]: null, 1, false ).'/>', 254 isset( $this->options['highlights-on-by-default'] ) ? esc_attr( $this->options['highlights-on-by-default']) : 0 255 ); 256 } 257 258 public function sidebar_open_by_default_callback() 259 { 260 printf( 261 '<input type="checkbox" id="sidebar-open-by-default" name="wp_hypothesis_options[sidebar-open-by-default]" value="1" '.checked( isset($this->options["sidebar-open-by-default"]) ? $this->options["sidebar-open-by-default"]: null, 1, false ).'/>', 262 isset( $this->options['sidebar-open-by-default'] ) ? esc_attr( $this->options['sidebar-open-by-default']) : 0 263 ); 264 } 265 266 public function serve_pdfs_with_via_default_callback() 267 { 268 printf( 269 '<input type="checkbox" id="serve-pdfs-with-via" name="wp_hypothesis_options[serve-pdfs-with-via]" value="1" '.checked( isset($this->options["serve-pdfs-with-via"]) ? $this->options["serve-pdfs-with-via"]: null, 1, false ).'/>', 270 isset( $this->options['serve-pdfs-with-via'] ) ? esc_attr( $this->options['serve-pdfs-with-via']) : 0 271 ); 272 } 273 274 /** 275 * CONTENT SETTINGS Callbacks 276 * These get the settings option array for a setting and print one of its values. 277 * They are used to determine what pages Hypothesis is loaded on. 278 */ 279 public function allow_on_blog_page_callback() 280 { 281 printf( 282 '<input type="checkbox" id="allow-on-blog-page" name="wp_hypothesis_options[allow-on-blog-page]" value="1" '.checked( isset($this->options["allow-on-blog-page"]) ? $this->options["allow-on-blog-page"]: null, 1, false ).'/>', 283 isset( $this->options['allow-on-blog-page'] ) ? esc_attr( $this->options['allow-on-blog-page']) : 0 284 ); 285 } 286 287 public function allow_on_front_page_callback() 288 { 289 printf( 290 '<input type="checkbox" id="allow-on-front-page" name="wp_hypothesis_options[allow-on-front-page]" value="1" 291 '.checked( isset($this->options["allow-on-front-page"]) ? $this->options["allow-on-front-page"]: null, 1, false ).' />', 292 isset( $this->options['allow-on-front-page'] ) ? esc_attr( $this->options['allow-on-front-page']) : 0 293 ); 294 } 295 296 public function allow_on_posts_callback() 297 { 298 printf( 299 '<input type="checkbox" id="allow-on-posts" name="wp_hypothesis_options[allow-on-posts]" value="1" 300 '.checked( isset($this->options["allow-on-posts"]) ? $this->options["allow-on-posts"]: null, 1, false ).' />', 301 isset( $this->options['allow-on-posts'] ) ? esc_attr( $this->options['allow-on-posts']) : 0 302 ); 303 } 304 305 public function allow_on_pages_callback() 306 { 307 printf( 308 '<input type="checkbox" id="allow-on-pages" name="wp_hypothesis_options[allow-on-pages]" value="1" 309 '.checked( isset($this->options["allow-on-pages"]) ? $this->options["allow-on-pages"]: null, 1, false ).' />', 310 isset( $this->options['allow-on-pages'] ) ? esc_attr( $this->options['allow-on-pages']) : 0 311 ); 312 } 313 314 public function page_ids_show_h_callback() 315 { 316 printf( 317 '<input type="text" id="page_ids_show_h" name="wp_hypothesis_options[page_ids_show_h]" value="%s" />', 318 isset( $this->options['page_ids_show_h'] ) ? esc_attr( implode(',', $this->options['page_ids_show_h'])) : '' 319 ); 320 } 321 322 public function post_ids_show_h_callback() 323 { 324 printf( 325 '<input type="text" id="post_ids_show_h" name="wp_hypothesis_options[post_ids_show_h]" value="%s" />', 326 isset( $this->options['post_ids_show_h'] ) ? esc_attr( implode(',', $this->options['post_ids_show_h'])) : '' 327 ); 328 } 329 330 public function post_ids_override_callback() 331 { 332 printf( 333 '<input type="text" id="post_ids_override" name="wp_hypothesis_options[post_ids_override]" value="%s" />', 334 isset( $this->options['post_ids_override'] ) ? esc_attr( implode(',', $this->options['post_ids_override'])) : '' 335 ); 336 } 337 338 public function page_ids_override_callback() 339 { 340 printf( 341 '<input type="text" id="page_ids_override" name="wp_hypothesis_options[page_ids_override]" value="%s" />', 342 isset( $this->options['page_ids_override'] ) ? esc_attr( implode(',',$this->options['page_ids_override'])) : '' 277 public function content_section_info() { 278 print 'Control where Hypothesis is loaded.'; 279 } 280 281 /** 282 * Callback for 'highlights-on-by-default'. 283 */ 284 public function highlights_on_by_default_callback() { 285 $val = isset( $this->options['highlights-on-by-default'] ) ? esc_attr( $this->options['highlights-on-by-default'] ) : 0; 286 287 printf( 288 '<input type="checkbox" id="highlights-on-by-default" name="wp_hypothesis_options[highlights-on-by-default]" value="1" %s/>', 289 checked( $val, 1, false ) 290 ); 291 } 292 293 /** 294 * Callback for 'sidebar-open-by-default'. 295 */ 296 public function sidebar_open_by_default_callback() { 297 $val = isset( $this->options['sidebar-open-by-default'] ) ? esc_attr( $this->options['sidebar-open-by-default'] ) : 0; 298 printf( 299 '<input type="checkbox" id="sidebar-open-by-default" name="wp_hypothesis_options[sidebar-open-by-default]" value="1" %s/>', 300 checked( $val, 1, false ) 301 ); 302 } 303 304 /** 305 * Callback for 'serve-pdfs-with-via'. 306 */ 307 public function serve_pdfs_with_via_default_callback() { 308 $val = isset( $this->options['serve-pdfs-with-via'] ) ? esc_attr( $this->options['serve-pdfs-with-via'] ) : 0; 309 printf( 310 '<input type="checkbox" id="serve-pdfs-with-via" name="wp_hypothesis_options[serve-pdfs-with-via]" value="1" %s/>', 311 checked( $val, 1, false ) 312 ); 313 } 314 315 /** 316 * Callback for 'allow_on_blog_page'. 317 */ 318 public function allow_on_blog_page_callback() { 319 $val = isset( $this->options['allow-on-blog-page'] ) ? esc_attr( $this->options['allow-on-blog-page'] ) : 0; 320 printf( 321 '<input type="checkbox" id="allow-on-blog-page" name="wp_hypothesis_options[allow-on-blog-page]" value="1" %s/>', 322 checked( $val, 1, false ) 323 ); 324 } 325 326 /** 327 * Callback for 'allow-on-front-page'. 328 */ 329 public function allow_on_front_page_callback() { 330 $val = isset( $this->options['allow-on-front-page'] ) ? esc_attr( $this->options['allow-on-front-page'] ) : 0; 331 printf( 332 '<input type="checkbox" id="allow-on-front-page" name="wp_hypothesis_options[allow-on-front-page]" value="1" %s/>', 333 checked( $val, 1, false ) 334 ); 335 } 336 337 /** 338 * Callback for 'allow-on-<posttype>'. 339 */ 340 public function allow_on_posttype_callback( $args ) { 341 $slug = $args[0]; 342 $val = isset( $this->options[ "allow-on-$slug" ] ) ? esc_attr( $this->options[ "allow-on-$slug" ] ) : 0; 343 344 printf( 345 '<input type="checkbox" id="allow-on-%s" name="wp_hypothesis_options[allow-on-%s]" value="1" %s/>', 346 esc_attr( $slug ), 347 esc_attr( $slug ), 348 checked( $val, 1, false ) 349 ); 350 } 351 352 /** 353 * Callback for '<posttype>_ids_show_h'. 354 * 355 * @param array $args An arry containing the post type slug and the post type name (plural). 356 */ 357 public function posttype_ids_show_h_callback( $args ) { 358 $slug = $args[0]; 359 $val = isset( $this->options[ $slug . '_ids_show_h' ] ) ? esc_attr( implode( ',', $this->options[ $slug . '_ids_show_h' ] ) ) : ''; 360 361 printf( 362 '<input type="text" id="%s_ids_show_h" name="wp_hypothesis_options[%s_ids_show_h]" value="%s" />', 363 esc_attr( $slug ), 364 esc_attr( $slug ), 365 esc_attr( $val ) 366 ); 367 } 368 369 /** 370 * Callback for '<posttype>_ids_override'. 371 * 372 * @param array $args An arry containing the post type slug and the post type name (plural). 373 */ 374 public function posttype_ids_override_callback( $args ) { 375 $slug = $args[0]; 376 $val = isset( $this->options[ $slug . '_ids_override' ] ) ? esc_attr( implode( ',', $this->options[ $slug . '_ids_override' ] ) ) : ''; 377 378 printf( 379 '<input type="text" id="%s_ids_override" name="wp_hypothesis_options[%s_ids_override]" value="%s" />', 380 esc_attr( $slug ), 381 esc_attr( $slug ), 382 esc_attr( $val ) 343 383 ); 344 384 } 345 385 } 346 386 347 if ( is_admin() )387 if ( is_admin() ) { 348 388 $hypothesis_settings_page = new HypothesisSettingsPage(); 349 389 } 350 390 351 391 /** 352 392 * Add Hypothesis based on conditions set in the plugin settings. 353 393 */ 354 add_action('wp', 'add_hypothesis'); 355 356 function add_hypothesis($param) { 394 add_action( 'wp', 'add_hypothesis' ); 395 396 /** 397 * Wrapper for the primary Hypothesis wp_enqueue call. 398 */ 399 function enqueue_hypothesis() { 400 wp_enqueue_script( 'hypothesis', 'https://hypothes.is/embed.js', array(), false, true ); 401 } 402 403 /** 404 * Add Hypothesis script(s) to front end. 405 */ 406 function add_hypothesis() { 357 407 $options = get_option( 'wp_hypothesis_options' ); 358 359 // Set defaults if we $options is not set yet. 360 if (empty($options)): 408 $posttypes = HypothesisSettingsPage::get_posttypes(); 409 410 // Set defaults if we $options is not set yet. 411 if ( empty( $options ) ) : 361 412 $defaults = array( 362 'highlights-on-by-default' => 1,413 'highlights-on-by-default' => 1, 363 414 ); 364 415 add_option( 'wp_hypothesis_options', $defaults ); 365 416 endif; 366 417 367 // otherwise highlighting is on by default418 // Otherwise highlighting is on by default. 368 419 wp_enqueue_script( 'nohighlights', '/wp-content/plugins/hypothesis/js/nohighlights.js', '', false, true ); 369 420 370 371 // Embed options 372 if (isset($options['highlights-on-by-default'])): 421 // Embed options. 422 if ( isset( $options['highlights-on-by-default'] ) ) : 373 423 wp_enqueue_script( 'showhighlights', '/wp-content/plugins/hypothesis/js/showhighlights.js', '', false, true ); 374 424 endif; 375 425 376 if ( isset($options['sidebar-open-by-default'])):426 if ( isset( $options['sidebar-open-by-default'] ) ) : 377 427 wp_enqueue_script( 'sidebaropen', '/wp-content/plugins/hypothesis/js/sidebaropen.js', '', false, true ); 378 428 endif; 379 429 380 if ( isset($options['serve-pdfs-with-via'])):430 if ( isset( $options['serve-pdfs-with-via'] ) ) : 381 431 wp_enqueue_script( 'pdfs-with-via', '/wp-content/plugins/hypothesis/js/via-pdf.js', '', false, true ); 382 432 endif; 383 433 384 385 // Content settings 386 if (isset($options['allow-on-blog-page']) && is_home()): 387 wp_enqueue_script( 'hypothesis', '//hypothes.is/embed.js', '', false, true ); 388 389 elseif (isset($options['allow-on-front-page']) && is_front_page()): 390 wp_enqueue_script( 'hypothesis', '//hypothes.is/embed.js', '', false, true ); 391 392 elseif (isset($options['post_ids_show_h']) && is_single($options['post_ids_show_h'])): 393 wp_enqueue_script( 'hypothesis', '//hypothes.is/embed.js', '', false, true ); 394 395 elseif (isset($options['page_ids_show_h']) && is_page($options['page_ids_show_h'])): 396 wp_enqueue_script( 'hypothesis', '//hypothes.is/embed.js', '', false, true ); 397 398 elseif (isset($options['allow-on-posts']) && is_single()): 399 if (isset($options['post_ids_override']) && is_single($options['post_ids_override'])); 400 else 401 wp_enqueue_script( 'hypothesis', '//hypothes.is/embed.js', '', false, true ); 402 403 elseif (isset($options['allow-on-pages']) && is_page() && !is_front_page() && !is_home()): 404 if (isset($options['page_ids_override']) && is_page($options['page_ids_override'])); 405 else 406 wp_enqueue_script( 'hypothesis', '//hypothes.is/embed.js', '', false, true ); 407 endif; 434 // Content settings. 435 $enqueue = false; 436 437 if ( is_front_page() && isset( $options['allow-on-front-page'] ) ) { 438 enqueue_hypothesis(); 439 } elseif ( is_home() && isset( $options['allow-on-blog-page'] ) ) { 440 enqueue_hypothesis(); 441 } 442 443 foreach ( $posttypes as $slug => $name ) { 444 if ( 'page' !== $slug ) { 445 $posttype = $slug; 446 if ( 'post' === $slug ) { 447 $slug = 'posts'; // Backwards compatibility. 448 } 449 if ( isset( $options[ "allow-on-$slug" ] ) && is_singular( $posttype ) ) { // Check if Hypothesis is allowed on this post type. 450 if ( isset( $options[ $posttype . '_ids_override' ] ) && ! is_single( $options[ $posttype . '_ids_override' ] ) ) { // Make sure this post isn't in the override list if it exists. 451 enqueue_hypothesis(); 452 } 453 } elseif ( ! isset( $options[ "allow-on-$slug" ] ) && isset( $options[ $posttype . '_ids_show_h' ] ) && is_single( $options[ $posttype . '_ids_show_h' ] ) ) { // Check if Hypothesis is allowed on this specific post. 454 enqueue_hypothesis(); 455 } 456 } elseif ( 'page' === $slug ) { 457 if ( isset( $options['allow-on-pages'] ) && is_page() && ! is_front_page() && ! is_home() ) { // Check if Hypothesis is allowed on pages (and that we aren't on a special page). 458 if ( isset( $options['page_ids_override'] ) && ! is_page( $options['page_ids_override'] ) ) { // Make sure this page isn't in the override list if it exists. 459 enqueue_hypothesis(); 460 } 461 } elseif ( ! isset( $options['allow-on-pages'] ) && isset( $options['page_ids_show_h'] ) && is_page( $options['page_ids_show_h'] ) ) { // Check if Hypothesis is allowed on this specific page. 462 enqueue_hypothesis(); 463 } 464 } 465 } 408 466 } 409 410 ?> -
hypothesis/tags/0.4.8/js/sidebaropen.js
r1431925 r1527063 5 5 return { 6 6 showHighlights: true, 7 firstRun: true7 openSidebar: true 8 8 } 9 9 } … … 11 11 window.hypothesisConfig = function () { 12 12 return { 13 firstRun: true13 openSidebar: true 14 14 } 15 15 } -
hypothesis/tags/0.4.8/readme.txt
r1431925 r1527063 1 1 === Plugin Name === 2 Contributors: timmmmyboy, BigBlueHat, jakehartnell2 Contributors: timmmmyboy, BigBlueHat, JakeHartnell 3 3 Tags: hypothesis, annotation, comments 4 4 Requires at least: 3.0.1 5 5 Tested up to: 4.3 6 Stable tag: 0.4. 76 Stable tag: 0.4.5 7 7 License: BSD 8 8 License URI: http://opensource.org/licenses/BSD-2-Clause -
hypothesis/trunk/hypothesis.php
r1431925 r1527063 2 2 /** 3 3 * @package Hypothesis 4 * @version 0.4. 54 * @version 0.4.8 5 5 */ 6 6 7 /* 7 8 Plugin Name: Hypothesis … … 9 10 Description: Hypothesis is an open platform for the collaborative evaluation of knowledge. This plugin embeds the necessary scripts in your Wordpress site to enable any user to use Hypothesis without installing any extensions. 10 11 Author: The Hypothesis Project and contributors 11 Version: 0.4. 712 Version: 0.4.8 12 13 Author URI: http://hypothes.is/ 13 14 */ 14 15 15 // Exit if called directly 16 defined( 'ABSPATH' ) or die ( 'Cannot access pages directly.' );17 18 19 // From https://codex.wordpress.org/Creating_Options_Pages 20 class HypothesisSettingsPage 21 {16 // Exit if called directly. 17 defined( 'ABSPATH' ) or die( 'Cannot access pages directly.' ); 18 19 /** 20 * Create settings page (see https://codex.wordpress.org/Creating_Options_Pages) 21 */ 22 class HypothesisSettingsPage { 22 23 /** 23 24 * Holds the values to be used in the fields callbacks 25 * 26 * @var array 24 27 */ 25 28 private $options; 26 29 27 30 /** 31 * Holds the posttypes to be used in the fields callbacks 32 * 33 * @var array 34 */ 35 private $posttypes; 36 37 /** 28 38 * Start up 29 39 */ 30 public function __construct() 31 { 40 public function __construct() { 32 41 add_action( 'admin_menu', array( $this, 'add_plugin_page' ) ); 33 42 add_action( 'admin_init', array( $this, 'page_init' ) ); … … 37 46 * Add options page 38 47 */ 39 public function add_plugin_page() 40 { 41 // This page will be under "Settings" 48 public function add_plugin_page() { 42 49 add_options_page( 43 ' Settings Admin',50 'Hypothesis Settings', 44 51 'Hypothesis', 45 52 'manage_options', … … 50 57 51 58 /** 59 * Return an array of post type slugs and corresponding plural display names for options page. 60 * 61 * @returns array 62 */ 63 public static function get_posttypes() { 64 return apply_filters('hypothesis_supported_posttypes', array( 65 'post' => 'posts', 66 'page' => 'pages', 67 ) ); 68 } 69 70 /** 52 71 * Options page callback 53 72 */ 54 public function create_admin_page() 55 { 56 // Set class property 57 $this->options = get_option( 'wp_hypothesis_options' ); 58 include ( 'formgen.php' ); 59 } 73 public function create_admin_page() { 74 // Set class property. 75 $this->options = get_option( 'wp_hypothesis_options' ); ?> 76 <div class="wrap"> 77 <form method="post" action="options.php"> 78 <?php 79 settings_fields( 'hypothesis_option_group' ); 80 do_settings_sections( 'hypothesis-setting-admin' ); 81 submit_button(); 82 ?> 83 </form> 84 </div> 85 <?php } 60 86 61 87 /** 62 88 * Register and add settings 63 89 */ 64 public function page_init() 65 { 90 public function page_init() { 91 $posttypes = $this->get_posttypes(); 92 66 93 register_setting( 67 ' my_option_group', // Option group68 'wp_hypothesis_options', // Option name 69 array( $this, 'sanitize' ) // Sanitize 94 'hypothesis_option_group', // Option group. 95 'wp_hypothesis_options', // Option name. 96 array( $this, 'sanitize' ) // Sanitize callback. 70 97 ); 71 98 … … 74 101 */ 75 102 add_settings_section( 76 ' setting_section_id2', // ID77 'Hypothesis Settings', // Title 78 array( $this, ' print_section_info' ), // Callback79 'hypothesis-setting-admin' // Page 103 'hypothesis_settings_section', // ID. 104 'Hypothesis Settings', // Title. 105 array( $this, 'settings_section_info' ), // Callback. 106 'hypothesis-setting-admin' // Page. 80 107 ); 81 108 … … 85 112 array( $this, 'highlights_on_by_default_callback' ), 86 113 'hypothesis-setting-admin', 87 ' setting_section_id2'114 'hypothesis_settings_section' 88 115 ); 89 116 … … 93 120 array( $this, 'sidebar_open_by_default_callback' ), 94 121 'hypothesis-setting-admin', 95 ' setting_section_id2'122 'hypothesis_settings_section' 96 123 ); 97 124 … … 101 128 array( $this, 'serve_pdfs_with_via_default_callback' ), 102 129 'hypothesis-setting-admin', 103 ' setting_section_id2'130 'hypothesis_settings_section' 104 131 ); 105 132 106 133 /** 107 134 * Content Settings 108 * Control which pages / posts Hypothesis is loaded on.135 * Control which pages / posts / custom post types Hypothesis is loaded on. 109 136 */ 110 137 add_settings_section( 111 ' setting_section_id', // ID112 'Content Settings', // Title 113 array( $this, ' print_section_info2' ), // Callback114 'hypothesis-setting-admin' // Page 115 ); 116 138 'hypothesis_content_section', // ID. 139 'Content Settings', // Title. 140 array( $this, 'content_section_info' ), // Callback. 141 'hypothesis-setting-admin' // Page. 142 ); 143 117 144 add_settings_field( 118 145 'allow-on-front-page', … … 120 147 array( $this, 'allow_on_front_page_callback' ), 121 148 'hypothesis-setting-admin', 122 ' setting_section_id'149 'hypothesis_content_section' 123 150 ); 124 151 … … 128 155 array( $this, 'allow_on_blog_page_callback' ), 129 156 'hypothesis-setting-admin', 130 ' setting_section_id'131 ); 132 133 add_settings_field(134 'allow-on-posts',135 'Allow on posts',136 array( $this, 'allow_on_posts_callback' ),137 'hypothesis-setting-admin',138 'setting_section_id'139 ); 140 141 add_settings_field(142 'allow-on-pages',143 'Allow on pages',144 array( $this, 'allow_on_pages_callback' ),145 'hypothesis-setting-admin',146 'setting_section_id'147 );148 149 add_settings_field(150 'post_ids_show_h', // ID151 'Allow on posts (list of comma-separated post ids, no spaces)', // Title152 array( $this, 'post_ids_show_h_callback' ), // Callback 153 'hypothesis-setting-admin', // Page154 'setting_section_id' // Section155 );156 157 add_settings_field(158 'page_ids_show_h', // ID159 'Allow on pages (list of comma-separated page ids, no spaces)', // Title160 array( $this, 'page_ids_show_h_callback' ), // Callback161 'hypothesis-setting-admin', // Page162 'setting_section_id' // Section163 );164 165 add_settings_field(166 'post_ids_override', // ID 167 'Disallow on posts (list of comma-separated post ids, no spaces)', // Title168 a rray( $this, 'post_ids_override_callback' ), // Callback169 'hypothesis-setting-admin', // Page170 'setting_section_id' // Section171 );172 173 add_settings_field(174 'page_ids_override', // ID175 'Disallow on pages (list of comma-separated page ids, no spaces)', // Title176 array( $this, 'page_ids_override_callback' ), // Callback177 'hypothesis-setting-admin', // Page178 'setting_section_id' // Section179 );157 'hypothesis_content_section' 158 ); 159 160 foreach ( $posttypes as $slug => $name ) { 161 if ( 'post' === $slug ) { 162 $slug = 'posts'; 163 } elseif ( 'page' === $slug ) { 164 $slug = 'pages'; 165 } 166 167 add_settings_field( 168 "allow-on-$slug", 169 "Allow on $name", 170 array( $this, 'allow_on_posttype_callback' ), 171 'hypothesis-setting-admin', 172 'hypothesis_content_section', 173 array( 174 $slug, 175 $name, 176 ) 177 ); 178 } 179 180 foreach ( $posttypes as $slug => $name ) { 181 add_settings_field( 182 $slug . '_ids_show_h', // ID. 183 "Allow on specific $name (list of comma-separated $slug IDs, no spaces)", // Title. 184 array( $this, 'posttype_ids_show_h_callback' ), // Callback. 185 'hypothesis-setting-admin', // Page. 186 'hypothesis_content_section', // Section. 187 array( 188 $slug, 189 $name, 190 ) 191 ); 192 } 193 194 foreach ( $posttypes as $slug => $name ) { 195 add_settings_field( 196 $slug . '_ids_override', // ID. 197 "Disallow on specific $name (list of comma-separated $slug IDs, no spaces)", // Title. 198 array( $this, 'posttype_ids_override_callback' ), // Callback. 199 'hypothesis-setting-admin', // Page. 200 'hypothesis_content_section', // Section. 201 array( 202 $slug, 203 $name, 204 ) 205 ); 206 } 180 207 } 181 208 … … 183 210 * Sanitize each setting field as needed 184 211 * 185 * @param array $input Contains all settings fields as array keys 186 */ 187 public function sanitize( $input ) 188 {212 * @param array $input Contains all settings fields as array keys. 213 */ 214 public function sanitize( $input ) { 215 $posttypes = $this->get_posttypes(); 189 216 $new_input = array(); 190 217 191 if( isset( $input['highlights-on-by-default'] ) ) 192 $new_input['highlights-on-by-default'] = absint($input['highlights-on-by-default']); 193 // else $new_input['highlights-on-by-default'] = 1; 194 195 if( isset( $input['sidebar-open-by-default'] ) ) 196 $new_input['sidebar-open-by-default'] = absint($input['sidebar-open-by-default']); 197 198 if( isset( $input['serve-pdfs-with-via'] ) ) 199 $new_input['serve-pdfs-with-via'] = absint($input['serve-pdfs-with-via']); 200 201 if( isset( $input['allow-on-blog-page'] ) ) 202 $new_input['allow-on-blog-page'] = absint($input['allow-on-blog-page']); 203 204 if( isset( $input['allow-on-front-page'] ) ) 205 $new_input['allow-on-front-page'] = absint($input['allow-on-front-page']); 206 207 if( isset( $input['allow-on-posts'] ) ) 208 $new_input['allow-on-posts'] = absint($input['allow-on-posts']); 209 210 if( isset( $input['allow-on-pages'] ) ) 211 $new_input['allow-on-pages'] = absint($input['allow-on-pages']); 212 213 if( isset( $input['post_ids_show_h'] ) ) 214 $new_input['post_ids_show_h'] = explode(',', esc_attr($input['post_ids_show_h'])); 215 216 if( isset( $input['page_ids_show_h'] ) ) 217 $new_input['page_ids_show_h'] = explode(',', esc_attr($input['page_ids_show_h'])); 218 219 if( isset( $input['post_ids_override'] ) ) 220 $new_input['post_ids_override'] = explode(',', esc_attr($input['post_ids_override'])); 221 222 if( isset( $input['page_ids_override'] ) ) 223 $new_input['page_ids_override'] = explode(',', esc_attr($input['page_ids_override'])); 218 if ( isset( $input['highlights-on-by-default'] ) ) { 219 $new_input['highlights-on-by-default'] = absint( $input['highlights-on-by-default'] ); 220 } 221 222 if ( isset( $input['sidebar-open-by-default'] ) ) { 223 $new_input['sidebar-open-by-default'] = absint( $input['sidebar-open-by-default'] ); 224 } 225 226 if ( isset( $input['serve-pdfs-with-via'] ) ) { 227 $new_input['serve-pdfs-with-via'] = absint( $input['serve-pdfs-with-via'] ); 228 } 229 230 if ( isset( $input['allow-on-blog-page'] ) ) { 231 $new_input['allow-on-blog-page'] = absint( $input['allow-on-blog-page'] ); 232 } 233 234 if ( isset( $input['allow-on-front-page'] ) ) { 235 $new_input['allow-on-front-page'] = absint( $input['allow-on-front-page'] ); 236 } 237 238 foreach ( $posttypes as $slug => $name ) { 239 if ( 'post' === $slug ) { // Adjust for backwards compatibility. 240 $slug = 'posts'; 241 } elseif ( 'page' === $slug ) { 242 $slug = 'pages'; 243 } 244 245 if ( isset( $input[ "allow-on-$slug" ] ) ) { 246 $new_input[ "allow-on-$slug" ] = absint( $input[ "allow-on-$slug" ] ); 247 } 248 249 if ( 'posts' === $slug ) { // Adjust for backwards compatibility. 250 $slug = 'post'; 251 } elseif ( 'pages' === $slug ) { 252 $slug = 'page'; 253 } 254 255 if ( isset( $input[ $slug . '_ids_show_h' ] ) ) { 256 $new_input[ $slug . '_ids_show_h' ] = explode( ',', esc_attr( $input[ $slug . '_ids_show_h' ] ) ); 257 } 258 259 if ( isset( $input[ $slug . '_ids_override' ] ) ) { 260 $new_input[ $slug . '_ids_override' ] = explode( ',', esc_attr( $input[ $slug . '_ids_override' ] ) ); 261 } 262 } 224 263 225 264 return $new_input; … … 229 268 * Print the Hypothesis Settings section text 230 269 */ 231 public function print_section_info() 232 { 233 print 'Customize Hypothesis defaults and behavior below:'; 270 public function settings_section_info() { 271 print 'Customize Hypothesis defaults and behavior.'; 234 272 } 235 273 … … 237 275 * Print the Content Settings section text 238 276 */ 239 public function print_section_info2() 240 { 241 print 'Control which pages Hypothesis is loaded on below:'; 242 } 243 244 /** 245 * HYPOTHESIS SETTINGS Callbacks 246 * These get the settings option array for a setting and print one of its values. 247 * They are used to set various defaults for the Hypothesis application. 248 */ 249 250 public function highlights_on_by_default_callback() 251 { 252 printf( 253 '<input type="checkbox" id="highlights-on-by-default" name="wp_hypothesis_options[highlights-on-by-default]" value="1" '.checked( isset($this->options["highlights-on-by-default"]) ? $this->options["highlights-on-by-default"]: null, 1, false ).'/>', 254 isset( $this->options['highlights-on-by-default'] ) ? esc_attr( $this->options['highlights-on-by-default']) : 0 255 ); 256 } 257 258 public function sidebar_open_by_default_callback() 259 { 260 printf( 261 '<input type="checkbox" id="sidebar-open-by-default" name="wp_hypothesis_options[sidebar-open-by-default]" value="1" '.checked( isset($this->options["sidebar-open-by-default"]) ? $this->options["sidebar-open-by-default"]: null, 1, false ).'/>', 262 isset( $this->options['sidebar-open-by-default'] ) ? esc_attr( $this->options['sidebar-open-by-default']) : 0 263 ); 264 } 265 266 public function serve_pdfs_with_via_default_callback() 267 { 268 printf( 269 '<input type="checkbox" id="serve-pdfs-with-via" name="wp_hypothesis_options[serve-pdfs-with-via]" value="1" '.checked( isset($this->options["serve-pdfs-with-via"]) ? $this->options["serve-pdfs-with-via"]: null, 1, false ).'/>', 270 isset( $this->options['serve-pdfs-with-via'] ) ? esc_attr( $this->options['serve-pdfs-with-via']) : 0 271 ); 272 } 273 274 /** 275 * CONTENT SETTINGS Callbacks 276 * These get the settings option array for a setting and print one of its values. 277 * They are used to determine what pages Hypothesis is loaded on. 278 */ 279 public function allow_on_blog_page_callback() 280 { 281 printf( 282 '<input type="checkbox" id="allow-on-blog-page" name="wp_hypothesis_options[allow-on-blog-page]" value="1" '.checked( isset($this->options["allow-on-blog-page"]) ? $this->options["allow-on-blog-page"]: null, 1, false ).'/>', 283 isset( $this->options['allow-on-blog-page'] ) ? esc_attr( $this->options['allow-on-blog-page']) : 0 284 ); 285 } 286 287 public function allow_on_front_page_callback() 288 { 289 printf( 290 '<input type="checkbox" id="allow-on-front-page" name="wp_hypothesis_options[allow-on-front-page]" value="1" 291 '.checked( isset($this->options["allow-on-front-page"]) ? $this->options["allow-on-front-page"]: null, 1, false ).' />', 292 isset( $this->options['allow-on-front-page'] ) ? esc_attr( $this->options['allow-on-front-page']) : 0 293 ); 294 } 295 296 public function allow_on_posts_callback() 297 { 298 printf( 299 '<input type="checkbox" id="allow-on-posts" name="wp_hypothesis_options[allow-on-posts]" value="1" 300 '.checked( isset($this->options["allow-on-posts"]) ? $this->options["allow-on-posts"]: null, 1, false ).' />', 301 isset( $this->options['allow-on-posts'] ) ? esc_attr( $this->options['allow-on-posts']) : 0 302 ); 303 } 304 305 public function allow_on_pages_callback() 306 { 307 printf( 308 '<input type="checkbox" id="allow-on-pages" name="wp_hypothesis_options[allow-on-pages]" value="1" 309 '.checked( isset($this->options["allow-on-pages"]) ? $this->options["allow-on-pages"]: null, 1, false ).' />', 310 isset( $this->options['allow-on-pages'] ) ? esc_attr( $this->options['allow-on-pages']) : 0 311 ); 312 } 313 314 public function page_ids_show_h_callback() 315 { 316 printf( 317 '<input type="text" id="page_ids_show_h" name="wp_hypothesis_options[page_ids_show_h]" value="%s" />', 318 isset( $this->options['page_ids_show_h'] ) ? esc_attr( implode(',', $this->options['page_ids_show_h'])) : '' 319 ); 320 } 321 322 public function post_ids_show_h_callback() 323 { 324 printf( 325 '<input type="text" id="post_ids_show_h" name="wp_hypothesis_options[post_ids_show_h]" value="%s" />', 326 isset( $this->options['post_ids_show_h'] ) ? esc_attr( implode(',', $this->options['post_ids_show_h'])) : '' 327 ); 328 } 329 330 public function post_ids_override_callback() 331 { 332 printf( 333 '<input type="text" id="post_ids_override" name="wp_hypothesis_options[post_ids_override]" value="%s" />', 334 isset( $this->options['post_ids_override'] ) ? esc_attr( implode(',', $this->options['post_ids_override'])) : '' 335 ); 336 } 337 338 public function page_ids_override_callback() 339 { 340 printf( 341 '<input type="text" id="page_ids_override" name="wp_hypothesis_options[page_ids_override]" value="%s" />', 342 isset( $this->options['page_ids_override'] ) ? esc_attr( implode(',',$this->options['page_ids_override'])) : '' 277 public function content_section_info() { 278 print 'Control where Hypothesis is loaded.'; 279 } 280 281 /** 282 * Callback for 'highlights-on-by-default'. 283 */ 284 public function highlights_on_by_default_callback() { 285 $val = isset( $this->options['highlights-on-by-default'] ) ? esc_attr( $this->options['highlights-on-by-default'] ) : 0; 286 287 printf( 288 '<input type="checkbox" id="highlights-on-by-default" name="wp_hypothesis_options[highlights-on-by-default]" value="1" %s/>', 289 checked( $val, 1, false ) 290 ); 291 } 292 293 /** 294 * Callback for 'sidebar-open-by-default'. 295 */ 296 public function sidebar_open_by_default_callback() { 297 $val = isset( $this->options['sidebar-open-by-default'] ) ? esc_attr( $this->options['sidebar-open-by-default'] ) : 0; 298 printf( 299 '<input type="checkbox" id="sidebar-open-by-default" name="wp_hypothesis_options[sidebar-open-by-default]" value="1" %s/>', 300 checked( $val, 1, false ) 301 ); 302 } 303 304 /** 305 * Callback for 'serve-pdfs-with-via'. 306 */ 307 public function serve_pdfs_with_via_default_callback() { 308 $val = isset( $this->options['serve-pdfs-with-via'] ) ? esc_attr( $this->options['serve-pdfs-with-via'] ) : 0; 309 printf( 310 '<input type="checkbox" id="serve-pdfs-with-via" name="wp_hypothesis_options[serve-pdfs-with-via]" value="1" %s/>', 311 checked( $val, 1, false ) 312 ); 313 } 314 315 /** 316 * Callback for 'allow_on_blog_page'. 317 */ 318 public function allow_on_blog_page_callback() { 319 $val = isset( $this->options['allow-on-blog-page'] ) ? esc_attr( $this->options['allow-on-blog-page'] ) : 0; 320 printf( 321 '<input type="checkbox" id="allow-on-blog-page" name="wp_hypothesis_options[allow-on-blog-page]" value="1" %s/>', 322 checked( $val, 1, false ) 323 ); 324 } 325 326 /** 327 * Callback for 'allow-on-front-page'. 328 */ 329 public function allow_on_front_page_callback() { 330 $val = isset( $this->options['allow-on-front-page'] ) ? esc_attr( $this->options['allow-on-front-page'] ) : 0; 331 printf( 332 '<input type="checkbox" id="allow-on-front-page" name="wp_hypothesis_options[allow-on-front-page]" value="1" %s/>', 333 checked( $val, 1, false ) 334 ); 335 } 336 337 /** 338 * Callback for 'allow-on-<posttype>'. 339 */ 340 public function allow_on_posttype_callback( $args ) { 341 $slug = $args[0]; 342 $val = isset( $this->options[ "allow-on-$slug" ] ) ? esc_attr( $this->options[ "allow-on-$slug" ] ) : 0; 343 344 printf( 345 '<input type="checkbox" id="allow-on-%s" name="wp_hypothesis_options[allow-on-%s]" value="1" %s/>', 346 esc_attr( $slug ), 347 esc_attr( $slug ), 348 checked( $val, 1, false ) 349 ); 350 } 351 352 /** 353 * Callback for '<posttype>_ids_show_h'. 354 * 355 * @param array $args An arry containing the post type slug and the post type name (plural). 356 */ 357 public function posttype_ids_show_h_callback( $args ) { 358 $slug = $args[0]; 359 $val = isset( $this->options[ $slug . '_ids_show_h' ] ) ? esc_attr( implode( ',', $this->options[ $slug . '_ids_show_h' ] ) ) : ''; 360 361 printf( 362 '<input type="text" id="%s_ids_show_h" name="wp_hypothesis_options[%s_ids_show_h]" value="%s" />', 363 esc_attr( $slug ), 364 esc_attr( $slug ), 365 esc_attr( $val ) 366 ); 367 } 368 369 /** 370 * Callback for '<posttype>_ids_override'. 371 * 372 * @param array $args An arry containing the post type slug and the post type name (plural). 373 */ 374 public function posttype_ids_override_callback( $args ) { 375 $slug = $args[0]; 376 $val = isset( $this->options[ $slug . '_ids_override' ] ) ? esc_attr( implode( ',', $this->options[ $slug . '_ids_override' ] ) ) : ''; 377 378 printf( 379 '<input type="text" id="%s_ids_override" name="wp_hypothesis_options[%s_ids_override]" value="%s" />', 380 esc_attr( $slug ), 381 esc_attr( $slug ), 382 esc_attr( $val ) 343 383 ); 344 384 } 345 385 } 346 386 347 if ( is_admin() )387 if ( is_admin() ) { 348 388 $hypothesis_settings_page = new HypothesisSettingsPage(); 349 389 } 350 390 351 391 /** 352 392 * Add Hypothesis based on conditions set in the plugin settings. 353 393 */ 354 add_action('wp', 'add_hypothesis'); 355 356 function add_hypothesis($param) { 394 add_action( 'wp', 'add_hypothesis' ); 395 396 /** 397 * Wrapper for the primary Hypothesis wp_enqueue call. 398 */ 399 function enqueue_hypothesis() { 400 wp_enqueue_script( 'hypothesis', 'https://hypothes.is/embed.js', array(), false, true ); 401 } 402 403 /** 404 * Add Hypothesis script(s) to front end. 405 */ 406 function add_hypothesis() { 357 407 $options = get_option( 'wp_hypothesis_options' ); 358 359 // Set defaults if we $options is not set yet. 360 if (empty($options)): 408 $posttypes = HypothesisSettingsPage::get_posttypes(); 409 410 // Set defaults if we $options is not set yet. 411 if ( empty( $options ) ) : 361 412 $defaults = array( 362 'highlights-on-by-default' => 1,413 'highlights-on-by-default' => 1, 363 414 ); 364 415 add_option( 'wp_hypothesis_options', $defaults ); 365 416 endif; 366 417 367 // otherwise highlighting is on by default418 // Otherwise highlighting is on by default. 368 419 wp_enqueue_script( 'nohighlights', '/wp-content/plugins/hypothesis/js/nohighlights.js', '', false, true ); 369 420 370 371 // Embed options 372 if (isset($options['highlights-on-by-default'])): 421 // Embed options. 422 if ( isset( $options['highlights-on-by-default'] ) ) : 373 423 wp_enqueue_script( 'showhighlights', '/wp-content/plugins/hypothesis/js/showhighlights.js', '', false, true ); 374 424 endif; 375 425 376 if ( isset($options['sidebar-open-by-default'])):426 if ( isset( $options['sidebar-open-by-default'] ) ) : 377 427 wp_enqueue_script( 'sidebaropen', '/wp-content/plugins/hypothesis/js/sidebaropen.js', '', false, true ); 378 428 endif; 379 429 380 if ( isset($options['serve-pdfs-with-via'])):430 if ( isset( $options['serve-pdfs-with-via'] ) ) : 381 431 wp_enqueue_script( 'pdfs-with-via', '/wp-content/plugins/hypothesis/js/via-pdf.js', '', false, true ); 382 432 endif; 383 433 384 385 // Content settings 386 if (isset($options['allow-on-blog-page']) && is_home()): 387 wp_enqueue_script( 'hypothesis', '//hypothes.is/embed.js', '', false, true ); 388 389 elseif (isset($options['allow-on-front-page']) && is_front_page()): 390 wp_enqueue_script( 'hypothesis', '//hypothes.is/embed.js', '', false, true ); 391 392 elseif (isset($options['post_ids_show_h']) && is_single($options['post_ids_show_h'])): 393 wp_enqueue_script( 'hypothesis', '//hypothes.is/embed.js', '', false, true ); 394 395 elseif (isset($options['page_ids_show_h']) && is_page($options['page_ids_show_h'])): 396 wp_enqueue_script( 'hypothesis', '//hypothes.is/embed.js', '', false, true ); 397 398 elseif (isset($options['allow-on-posts']) && is_single()): 399 if (isset($options['post_ids_override']) && is_single($options['post_ids_override'])); 400 else 401 wp_enqueue_script( 'hypothesis', '//hypothes.is/embed.js', '', false, true ); 402 403 elseif (isset($options['allow-on-pages']) && is_page() && !is_front_page() && !is_home()): 404 if (isset($options['page_ids_override']) && is_page($options['page_ids_override'])); 405 else 406 wp_enqueue_script( 'hypothesis', '//hypothes.is/embed.js', '', false, true ); 407 endif; 434 // Content settings. 435 $enqueue = false; 436 437 if ( is_front_page() && isset( $options['allow-on-front-page'] ) ) { 438 enqueue_hypothesis(); 439 } elseif ( is_home() && isset( $options['allow-on-blog-page'] ) ) { 440 enqueue_hypothesis(); 441 } 442 443 foreach ( $posttypes as $slug => $name ) { 444 if ( 'page' !== $slug ) { 445 $posttype = $slug; 446 if ( 'post' === $slug ) { 447 $slug = 'posts'; // Backwards compatibility. 448 } 449 if ( isset( $options[ "allow-on-$slug" ] ) && is_singular( $posttype ) ) { // Check if Hypothesis is allowed on this post type. 450 if ( isset( $options[ $posttype . '_ids_override' ] ) && ! is_single( $options[ $posttype . '_ids_override' ] ) ) { // Make sure this post isn't in the override list if it exists. 451 enqueue_hypothesis(); 452 } 453 } elseif ( ! isset( $options[ "allow-on-$slug" ] ) && isset( $options[ $posttype . '_ids_show_h' ] ) && is_single( $options[ $posttype . '_ids_show_h' ] ) ) { // Check if Hypothesis is allowed on this specific post. 454 enqueue_hypothesis(); 455 } 456 } elseif ( 'page' === $slug ) { 457 if ( isset( $options['allow-on-pages'] ) && is_page() && ! is_front_page() && ! is_home() ) { // Check if Hypothesis is allowed on pages (and that we aren't on a special page). 458 if ( isset( $options['page_ids_override'] ) && ! is_page( $options['page_ids_override'] ) ) { // Make sure this page isn't in the override list if it exists. 459 enqueue_hypothesis(); 460 } 461 } elseif ( ! isset( $options['allow-on-pages'] ) && isset( $options['page_ids_show_h'] ) && is_page( $options['page_ids_show_h'] ) ) { // Check if Hypothesis is allowed on this specific page. 462 enqueue_hypothesis(); 463 } 464 } 465 } 408 466 } 409 410 ?> -
hypothesis/trunk/js/sidebaropen.js
r1431925 r1527063 5 5 return { 6 6 showHighlights: true, 7 firstRun: true7 openSidebar: true 8 8 } 9 9 } … … 11 11 window.hypothesisConfig = function () { 12 12 return { 13 firstRun: true13 openSidebar: true 14 14 } 15 15 } -
hypothesis/trunk/readme.txt
r1431925 r1527063 1 1 === Plugin Name === 2 Contributors: timmmmyboy, BigBlueHat, jakehartnell2 Contributors: timmmmyboy, BigBlueHat, JakeHartnell 3 3 Tags: hypothesis, annotation, comments 4 4 Requires at least: 3.0.1 5 5 Tested up to: 4.3 6 Stable tag: 0.4. 76 Stable tag: 0.4.5 7 7 License: BSD 8 8 License URI: http://opensource.org/licenses/BSD-2-Clause
Note: See TracChangeset
for help on using the changeset viewer.