Changeset 475708
- Timestamp:
- 12/15/2011 05:37:24 AM (14 years ago)
- Location:
- wordpress-wiki-plugin/trunk
- Files:
-
- 1 added
- 3 edited
-
css/style.css (modified) (2 diffs)
-
readme.txt (modified) (1 diff)
-
wiki.php (modified) (1 diff)
-
wordpress-wiki-plugin.php (added)
Legend:
- Unmodified
- Added
- Removed
-
wordpress-wiki-plugin/trunk/css/style.css
r382610 r475708 37 37 border-width: 1px 1px 0 1px !important; 38 38 padding-bottom: 0.1em !important; 39 margin: 0 0.5em0 0 !important;39 margin: 0 5px 0 0 !important; 40 40 color: #333 !important; 41 41 background: #efefef !important; … … 43 43 44 44 .incsub_wiki_tabs .right li { 45 margin: 0 0 0 0.5em!important;45 margin: 0 0 0 5px !important; 46 46 } 47 47 -
wordpress-wiki-plugin/trunk/readme.txt
r411786 r475708 92 92 == Changelog == 93 93 94 = 1.0.7 = 95 * WordPress 3.3 compatibility 96 * More minor improvements 97 94 98 = 1.0.6 = 95 99 * Remove update notifier -
wordpress-wiki-plugin/trunk/wiki.php
r411786 r475708 1 <?php2 /*3 Plugin Name: Wiki4 Plugin URI: http://premium.wpmudev.org/project/wiki5 Description: Add a wiki to your blog6 Author: S H Mohanjith (Incsub)7 WDP ID: 2258 Version: 1.0.69 Stable tag: trunk10 Author URI: http://premium.wpmudev.org11 */12 /**13 * @global object $wiki Convenient access to the chat object14 */15 global $wiki;16 17 /**18 * Wiki object (PHP4 compatible)19 *20 * Add a wiki to your blog21 *22 * @since 1.0.023 * @author S H Mohanjith <[email protected]>24 */25 class Wiki {26 /**27 * @todo Update version number for new releases28 *29 * @var string $current_version Current version30 */31 var $current_version = '1.0.5';32 /**33 * @var string $translation_domain Translation domain34 */35 var $translation_domain = 'wiki';36 37 var $db_prefix = '';38 39 /**40 * @var array $_options Consolidated options41 */42 var $_options = array();43 44 /**45 * Get the table name with prefixes46 *47 * @global object $wpdb48 * @param string $table Table name49 * @return string Table name complete with prefixes50 */51 function tablename($table) {52 global $wpdb;53 // We use a single table for all chats accross the network54 return $wpdb->base_prefix.'wiki_'.$table;55 }56 57 /**58 * Initializing object59 *60 * Plugin register actions, filters and hooks.61 */62 function Wiki() {63 global $wpdb;64 65 // Activation deactivation hooks66 register_activation_hook(__FILE__, array(&$this, 'install'));67 register_deactivation_hook(__FILE__, array(&$this, 'uninstall'));68 69 // Actions70 add_action('init', array(&$this, 'init'), 0);71 add_action('init', array(&$this, 'post_action'));72 add_action('wp_head', array(&$this, 'output_css'));73 add_action('wp_head', array(&$this, 'output_js'), 0);74 75 add_action('admin_print_styles-settings_page_wiki', array(&$this, 'admin_styles'));76 add_action('admin_print_scripts-settings_page_wiki', array(&$this, 'admin_scripts'));77 78 add_action('add_meta_boxes_incsub_wiki', array(&$this, 'meta_boxes') );79 add_action('wp_insert_post', array(&$this, 'save_wiki_meta'), 10, 2 );80 81 add_filter('admin_menu', array(&$this, 'admin_menu'));82 83 add_action('widgets_init', array(&$this, 'widgets_init'));84 add_action('pre_post_update', array(&$this, 'send_notifications'), 50, 1);85 add_action('template_redirect', array(&$this, 'load_templates') );86 87 add_filter('post_type_link', array(&$this, 'post_type_link'), 10, 3);88 add_filter('name_save_pre', array(&$this, 'name_save'));89 // add_filter('the_content', array(&$this, 'the_content'));90 add_filter('role_has_cap', array(&$this, 'role_has_cap'), 10, 3);91 add_filter('user_has_cap', array(&$this, 'user_has_cap'), 10, 3);92 93 add_filter('get_edit_post_link', array(&$this, 'get_edit_post_link'));94 add_filter('comments_open', array(&$this, 'comments_open'), 10, 1);95 96 add_filter('rewrite_rules_array', array(&$this, 'add_rewrite_rules'));97 add_action('option_rewrite_rules', array(&$this, 'check_rewrite_rules'));98 99 add_filter('user_can_richedit', array(&$this, 'user_can_richedit'));100 101 // White list the options to make sure non super admin can save wiki options102 // add_filter('whitelist_options', array(&$this, 'whitelist_options'));103 104 if ( !empty($wpdb->base_prefix) ) {105 $this->db_prefix = $wpdb->base_prefix;106 } else {107 $this->db_prefix = $wpdb->prefix;108 }109 110 $this->_options['default'] = get_option('wiki_default', array('slug' => 'wiki'));111 }112 113 function load_templates() {114 global $wp_query;115 116 if ($wp_query->is_single && $wp_query->query_vars['post_type'] == 'incsub_wiki') {117 //check for custom theme templates118 $wiki_name = get_query_var('incsub_wiki');119 $wiki_id = (int) $wp_query->get_queried_object_id();120 $templates = array();121 122 if ( $product_name ) {123 $templates[] = "incsub_wiki-$wiki_name.php";124 }125 126 if ( $product_id ) {127 $templates[] = "incsub_wiki-$wiki_id.php";128 }129 $templates[] = "incsub_wiki.php";130 131 if ($this->wiki_template = locate_template($templates)) {132 add_filter('template_include', array(&$this, 'custom_template') );133 } else {134 //otherwise load the page template and use our own theme135 $wp_query->is_single = null;136 $wp_query->is_page = 1;137 add_filter('the_content', array(&$this, 'theme'), 99 );138 }139 $this->is_wiki_page = true;140 }141 }142 143 function custom_template() {144 return $this->wiki_template;145 }146 147 function user_can_richedit($wp_rich_edit) {148 global $post;149 150 if ($post->post_type) {151 return true;152 }153 return $wp_rich_edit;154 }155 156 function add_rewrite_rules($rules){157 $settings = get_option('incsub_wiki_settings');158 159 $new_rules = array();160 161 $new_rules[$this->_options['default']['slug'].'/(.+?)/?$'] = 'index.php?incsub_wiki=$matches[1]';162 163 return array_merge($new_rules, $rules);164 }165 166 function check_rewrite_rules($value) {167 //prevent an infinite loop168 if ( ! post_type_exists( 'incsub_wiki' ) )169 return;170 171 if (!is_array($value))172 $value = array();173 174 $array_key = $this->_options['default']['slug'].'/(.+?)';175 if ( !array_key_exists($array_key, $value) ) {176 $this->flush_rewrite();177 }178 }179 180 function flush_rewrite() {181 global $wp_rewrite;182 $wp_rewrite->flush_rules();183 }184 185 function comments_open($open) {186 global $post, $incsub_tab_check;187 188 if ($post->post_type == 'incsub_wiki' && $_REQUEST['action'] != 'discussion') {189 if ($incsub_tab_check == 0 && !isset($_POST['submit'])) {190 return false;191 }192 }193 return $open;194 }195 196 /**197 * Rename $_POST data from form names to DB post columns.198 *199 * Manipulates $_POST directly.200 *201 * @package WordPress202 * @since 2.6.0203 *204 * @param bool $update Are we updating a pre-existing post?205 * @param array $post_data Array of post data. Defaults to the contents of $_POST.206 * @return object|bool WP_Error on failure, true on success.207 */208 function _translate_postdata( $update = false, $post_data = null ) {209 if ( empty($post_data) )210 $post_data = &$_POST;211 212 if ( $update )213 $post_data['ID'] = (int) $post_data['post_ID'];214 $post_data['post_content'] = isset($post_data['content']) ? $post_data['content'] : '';215 $post_data['post_excerpt'] = isset($post_data['excerpt']) ? $post_data['excerpt'] : '';216 $post_data['post_parent'] = isset($post_data['parent_id'])? $post_data['parent_id'] : '';217 if ( isset($post_data['trackback_url']) )218 $post_data['to_ping'] = $post_data['trackback_url'];219 220 if ( !isset($post_data['user_ID']) )221 $post_data['user_ID'] = $GLOBALS['user_ID'];222 223 if (!empty ( $post_data['post_author_override'] ) ) {224 $post_data['post_author'] = (int) $post_data['post_author_override'];225 } else {226 if (!empty ( $post_data['post_author'] ) ) {227 $post_data['post_author'] = (int) $post_data['post_author'];228 } else {229 $post_data['post_author'] = (int) $post_data['user_ID'];230 }231 }232 233 $ptype = get_post_type_object( $post_data['post_type'] );234 if ( isset($post_data['user_ID']) && ($post_data['post_author'] != $post_data['user_ID']) ) {235 if ( !current_user_can( $ptype->cap->edit_others_posts ) ) {236 if ( 'page' == $post_data['post_type'] ) {237 return new WP_Error( 'edit_others_pages', $update ?238 __( 'You are not allowed to edit pages as this user.' ) :239 __( 'You are not allowed to create pages as this user.' )240 );241 } else {242 return new WP_Error( 'edit_others_posts', $update ?243 __( 'You are not allowed to edit posts as this user.' ) :244 __( 'You are not allowed to post as this user.' )245 );246 }247 }248 }249 250 // What to do based on which button they pressed251 if ( isset($post_data['saveasdraft']) && '' != $post_data['saveasdraft'] )252 $post_data['post_status'] = 'draft';253 if ( isset($post_data['saveasprivate']) && '' != $post_data['saveasprivate'] )254 $post_data['post_status'] = 'private';255 if ( isset($post_data['publish']) && ( '' != $post_data['publish'] ) && ( !isset($post_data['post_status']) || $post_data['post_status'] != 'private' ) )256 $post_data['post_status'] = 'publish';257 if ( isset($post_data['advanced']) && '' != $post_data['advanced'] )258 $post_data['post_status'] = 'draft';259 if ( isset($post_data['pending']) && '' != $post_data['pending'] )260 $post_data['post_status'] = 'pending';261 262 if ( isset( $post_data['ID'] ) )263 $post_id = $post_data['ID'];264 else265 $post_id = false;266 $previous_status = $post_id ? get_post_field( 'post_status', $post_id ) : false;267 268 // Posts 'submitted for approval' present are submitted to $_POST the same as if they were being published.269 // Change status from 'publish' to 'pending' if user lacks permissions to publish or to resave published posts.270 if ( isset($post_data['post_status']) && ('publish' == $post_data['post_status'] && !current_user_can( $ptype->cap->publish_posts )) )271 if ( $previous_status != 'publish' || !current_user_can( 'edit_post', $post_id ) )272 $post_data['post_status'] = 'pending';273 274 if ( ! isset($post_data['post_status']) )275 $post_data['post_status'] = $previous_status;276 277 if (!isset( $post_data['comment_status'] ))278 $post_data['comment_status'] = 'closed';279 280 if (!isset( $post_data['ping_status'] ))281 $post_data['ping_status'] = 'closed';282 283 foreach ( array('aa', 'mm', 'jj', 'hh', 'mn') as $timeunit ) {284 if ( !empty( $post_data['hidden_' . $timeunit] ) && $post_data['hidden_' . $timeunit] != $post_data[$timeunit] ) {285 $post_data['edit_date'] = '1';286 break;287 }288 }289 290 if ( !empty( $post_data['edit_date'] ) ) {291 $aa = $post_data['aa'];292 $mm = $post_data['mm'];293 $jj = $post_data['jj'];294 $hh = $post_data['hh'];295 $mn = $post_data['mn'];296 $ss = $post_data['ss'];297 $aa = ($aa <= 0 ) ? date('Y') : $aa;298 $mm = ($mm <= 0 ) ? date('n') : $mm;299 $jj = ($jj > 31 ) ? 31 : $jj;300 $jj = ($jj <= 0 ) ? date('j') : $jj;301 $hh = ($hh > 23 ) ? $hh -24 : $hh;302 $mn = ($mn > 59 ) ? $mn -60 : $mn;303 $ss = ($ss > 59 ) ? $ss -60 : $ss;304 $post_data['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );305 $post_data['post_date_gmt'] = get_gmt_from_date( $post_data['post_date'] );306 }307 308 return $post_data;309 }310 311 /**312 * Update an existing post with values provided in $_POST.313 *314 * @since 1.5.0315 *316 * @param array $post_data Optional.317 * @return int Post ID.318 */319 function edit_post( $post_data = null ) {320 321 if ( empty($post_data) )322 $post_data = &$_POST;323 324 $post_ID = (int) $post_data['post_ID'];325 326 $ptype = get_post_type_object($post_data['post_type']);327 328 if ( !current_user_can( $ptype->cap->edit_post, $post_ID ) ) {329 if ( 'page' == $post_data['post_type'] )330 wp_die( __('You are not allowed to edit this page.' ));331 else332 wp_die( __('You are not allowed to edit this post.' ));333 }334 335 // Autosave shouldn't save too soon after a real save336 if ( 'autosave' == $post_data['action'] ) {337 $post =& get_post( $post_ID );338 $now = time();339 $then = strtotime($post->post_date_gmt . ' +0000');340 $delta = AUTOSAVE_INTERVAL / 2;341 if ( ($now - $then) < $delta )342 return $post_ID;343 }344 345 $post_data = $this->_translate_postdata( true, $post_data );346 $post_data['post_status'] = 'publish';347 if ( is_wp_error($post_data) )348 wp_die( $post_data->get_error_message() );349 if ( 'autosave' != $post_data['action'] && 'auto-draft' == $post_data['post_status'] )350 $post_data['post_status'] = 'draft';351 352 if ( isset($post_data['visibility']) ) {353 switch ( $post_data['visibility'] ) {354 case 'public' :355 $post_data['post_password'] = '';356 break;357 case 'password' :358 unset( $post_data['sticky'] );359 break;360 case 'private' :361 $post_data['post_status'] = 'private';362 $post_data['post_password'] = '';363 unset( $post_data['sticky'] );364 break;365 }366 }367 368 // Post Formats369 if ( current_theme_supports( 'post-formats' ) && isset( $post_data['post_format'] ) ) {370 $formats = get_theme_support( 'post-formats' );371 if ( is_array( $formats ) ) {372 $formats = $formats[0];373 if ( in_array( $post_data['post_format'], $formats ) ) {374 set_post_format( $post_ID, $post_data['post_format'] );375 } elseif ( '0' == $post_data['post_format'] ) {376 set_post_format( $post_ID, false );377 }378 }379 }380 // print_r($post_data); exit();381 // Meta Stuff382 if ( isset($post_data['meta']) && $post_data['meta'] ) {383 foreach ( $post_data['meta'] as $key => $value ) {384 if ( !$meta = get_post_meta_by_id( $key ) )385 continue;386 if ( $meta->post_id != $post_ID )387 continue;388 update_meta( $key, $value['key'], $value['value'] );389 }390 }391 392 if ( isset($post_data['deletemeta']) && $post_data['deletemeta'] ) {393 foreach ( $post_data['deletemeta'] as $key => $value ) {394 if ( !$meta = get_post_meta_by_id( $key ) )395 continue;396 if ( $meta->post_id != $post_ID )397 continue;398 delete_meta( $key );399 }400 }401 402 // add_meta( $post_ID );403 404 update_post_meta( $post_ID, '_edit_last', $GLOBALS['current_user']->ID );405 406 wp_update_post( $post_data );407 408 // Reunite any orphaned attachments with their parent409 if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) )410 $draft_ids = array();411 if ( $draft_temp_id = (int) array_search( $post_ID, $draft_ids ) )412 _relocate_children( $draft_temp_id, $post_ID );413 414 $this->set_post_lock( $post_ID, $GLOBALS['current_user']->ID );415 416 if ( current_user_can( $ptype->cap->edit_others_posts ) ) {417 if ( ! empty( $post_data['sticky'] ) )418 stick_post( $post_ID );419 else420 unstick_post( $post_ID );421 }422 423 return $post_ID;424 }425 426 function post_action() {427 global $post;428 429 switch ($_REQUEST['action']) {430 case 'editpost':431 if (wp_verify_nonce($_POST['_wpnonce'], "wiki-editpost_{$_POST['post_ID']}")) {432 $post_id = $this->edit_post($_POST);433 wp_redirect(get_permalink($post_id));434 exit();435 }436 break;437 }438 }439 440 function theme($content) {441 global $post;442 443 $new_content = '<div class="incsub_wiki incsub_wiki_single">';444 $new_content .= '<div class="incsub_wiki_tabs incsub_wiki_tabs_top">' . $this->tabs() . '<div class="incsub_wiki_clear"></div></div>';445 446 $revision_id = isset($_REQUEST['revision'])?absint($_REQUEST['revision']):0;447 $left = isset($_REQUEST['left'])?absint($_REQUEST['left']):0;448 $right = isset($_REQUEST['right'])?absint($_REQUEST['right']):0;449 $action = isset($_REQUEST['action'])?$_REQUEST['action']:'view';450 451 switch ($_REQUEST['action']) {452 case 'discussion':453 break;454 case 'edit':455 set_include_path(get_include_path().PATH_SEPARATOR.ABSPATH.'wp-admin');456 457 $post_type_object = get_post_type_object($post->post_type);458 459 $p = $post;460 461 if ( empty($post->ID) )462 wp_die( __('You attempted to edit an item that doesn’t exist. Perhaps it was deleted?') );463 464 if ( !current_user_can($post_type_object->cap->edit_post, $post_id) )465 wp_die( __('You are not allowed to edit this item.') );466 467 if ( 'trash' == $post->post_status )468 wp_die( __('You can’t edit this item because it is in the Trash. Please restore it and try again.') );469 470 if ( null == $post_type_object )471 wp_die( __('Unknown post type.') );472 473 $post_type = $post->post_type;474 475 if ( $last = $this->check_post_lock( $post->ID ) ) {476 add_action('admin_notices', '_admin_notice_post_locked' );477 } else {478 $this->set_post_lock( $post->ID );479 wp_enqueue_script('autosave');480 }481 482 $title = $post_type_object->labels->edit_item;483 $post = $this->post_to_edit($post_id);484 485 $new_content .= $this->get_edit_form();486 break;487 case 'restore':488 if ( !$revision = wp_get_post_revision( $revision_id ) )489 break;490 if ( !current_user_can( 'edit_post', $revision->post_parent ) )491 break;492 if ( !$post = get_post( $revision->post_parent ) )493 break;494 495 // Revisions disabled and we're not looking at an autosave496 if ( ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') ) && !wp_is_post_autosave( $revision ) ) {497 $redirect = get_permalink().'?action=edit';498 break;499 }500 501 check_admin_referer( "restore-post_$post->ID|$revision->ID" );502 503 wp_restore_post_revision( $revision->ID );504 $redirect = add_query_arg( array( 'message' => 5, 'revision' => $revision->ID ), get_permalink().'?action=edit' );505 break;506 case 'diff':507 if ( !$left_revision = get_post( $left ) ) {508 break;509 }510 if ( !$right_revision = get_post( $right ) ) {511 break;512 }513 514 /*if ( !current_user_can( 'read_post', $left_revision->ID ) || !current_user_can( 'read_post', $right_revision->ID ) ) {515 break;516 }*/517 518 // If we're comparing a revision to itself, redirect to the 'view' page for that revision or the edit page for that post519 if ( $left_revision->ID == $right_revision->ID ) {520 $redirect = get_edit_post_link( $left_revision->ID );521 include( ABSPATH . 'wp-admin/js/revisions-js.php' );522 break;523 }524 525 // Don't allow reverse diffs?526 if ( strtotime($right_revision->post_modified_gmt) < strtotime($left_revision->post_modified_gmt) ) {527 $redirect = add_query_arg( array( 'left' => $right, 'right' => $left ) );528 break;529 }530 531 if ( $left_revision->ID == $right_revision->post_parent ) // right is a revision of left532 $post =& $left_revision;533 elseif ( $left_revision->post_parent == $right_revision->ID ) // left is a revision of right534 $post =& $right_revision;535 elseif ( $left_revision->post_parent == $right_revision->post_parent ) // both are revisions of common parent536 $post = get_post( $left_revision->post_parent );537 else538 break; // Don't diff two unrelated revisions539 540 if ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') ) { // Revisions disabled541 if (542 // we're not looking at an autosave543 ( !wp_is_post_autosave( $left_revision ) && !wp_is_post_autosave( $right_revision ) )544 ||545 // we're not comparing an autosave to the current post546 ( $post->ID !== $left_revision->ID && $post->ID !== $right_revision->ID )547 ) {548 $redirect = get_permalink().'?action=edit';549 break;550 }551 }552 553 if (554 // They're the same555 $left_revision->ID == $right_revision->ID556 ||557 // Neither is a revision558 ( !wp_get_post_revision( $left_revision->ID ) && !wp_get_post_revision( $right_revision->ID ) )559 ) {560 break;561 }562 563 $post_title = '<a href="' . get_permalink().'?action=edit' . '">' . get_the_title() . '</a>';564 $h2 = sprintf( __( 'Compare Revisions of “%1$s”' ), $post_title );565 $title = __( 'Revisions' );566 567 $left = $left_revision->ID;568 $right = $right_revision->ID;569 case 'history':570 $args = array( 'format' => 'form-table', 'parent' => false, 'right' => $right, 'left' => $left );571 if ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') ) {572 $args['type'] = 'autosave';573 }574 575 if (!isset($h2)) {576 $post_title = '<a href="' . get_permalink().'?action=edit' . '">' . get_the_title() . '</a>';577 $revisions = wp_get_post_revisions( $post->ID );578 $revision = array_shift($revisions);579 $revision_title = wp_post_revision_title( $revision, false );580 $h2 = sprintf( __( 'Revision for “%1$s” created on %2$s' ), $post_title, $revision_title );581 }582 583 $new_content .= '<h3 class="long-header">'.$h2.'</h3>';584 $new_content .= '<table class="form-table ie-fixed">';585 $new_content .= '<col class="th" />';586 587 if ( 'diff' == $action ) :588 $new_content .= '<tr id="revision">';589 $new_content .= '<th scope="row"></th>';590 $new_content .= '<th scope="col" class="th-full">';591 $new_content .= '<span class="alignleft">'.sprintf( __('Older: %s', $this->translation_domain), wp_post_revision_title( $left_revision, false ) ).'</span>';592 $new_content .= '<span class="alignright">'.sprintf( __('Newer: %s', $this->translation_domain), wp_post_revision_title( $right_revision, false ) ).'</span>';593 $new_content .= '</th>';594 $new_content .= '</tr>';595 endif;596 597 // use get_post_to_edit filters?598 $identical = true;599 foreach ( _wp_post_revision_fields() as $field => $field_title ) :600 if ( 'diff' == $action ) {601 $left_content = apply_filters( "_wp_post_revision_field_$field", $left_revision->$field, $field );602 $right_content = apply_filters( "_wp_post_revision_field_$field", $right_revision->$field, $field );603 if ( !$rcontent = wp_text_diff( $left_content, $right_content ) )604 continue; // There is no difference between left and right605 $identical = false;606 } else {607 add_filter( "_wp_post_revision_field_$field", 'htmlspecialchars' );608 $rcontent = apply_filters( "_wp_post_revision_field_$field", $revision->$field, $field );609 }610 $new_content .= '<tr id="revision-field-<?php echo $field; ?>">';611 $new_content .= '<th scope="row">'.esc_html( $field_title ).'</th>';612 $new_content .= '<td><div class="pre">'.$rcontent.'</div></td>';613 $new_content .= '</tr>';614 endforeach;615 616 if ( 'diff' == $action && $identical ) :617 $new_content .= '<tr><td colspan="2"><div class="updated"><p>'.__( 'These revisions are identical.', $this->translation_domain ). '</p></div></td></tr>';618 endif;619 620 $new_content .= '</table>';621 622 $new_content .= '<br class="clear" />';623 $new_content .= '<div class="incsub_wiki_revisions">' . $this->list_post_revisions( $post, $args ) . '</div>';624 $redirect = false;625 break;626 default:627 $top = "";628 629 $crumbs = array();630 foreach($post->ancestors as $parent_pid) {631 $parent_post = get_post($parent_pid);632 633 $crumbs[] = '<a href="'.get_permalink($parent_pid).'" class="incsub_wiki_crumbs">'.$parent_post->post_title.'</a>';634 }635 636 $crumbs[] = '<span class="incsub_wiki_crumbs">'.$post->post_title.'</span>';637 638 sort($crumbs);639 640 $top .= join(get_option("incsub_meta_seperator", " > "), $crumbs);641 642 $children = get_children('post_parent='.$post->ID.'&post_type=incsub_wiki');643 644 $crumbs = array();645 foreach($children as $child) {646 $crumbs[] = '<a href="'.get_permalink($child->ID).'" class="incsub_wiki_crumbs">'.$child->post_title.'</a>';647 }648 649 $bottom = "<h3>".__('Sub Wikis', $this->translation_domain) . "</h3> <ul><li>";650 651 $bottom .= join("</li><li>", $crumbs);652 653 if (count($crumbs) == 0) {654 $bottom = "";655 } else {656 $bottom .= "</li></ul>";657 }658 659 $revisions = wp_get_post_revisions($post->ID);660 661 if (current_user_can('edit_wiki')) {662 $bottom .= '<div class="incsub_wiki-meta">';663 if (is_array($revisions) && count($revisions) > 0) {664 $revision = array_shift($revisions);665 }666 $bottom .= '</div>';667 }668 669 $notification_meta = get_post_custom($post->ID, array('incsub_wiki_email_notification' => 'enabled'));670 671 if ($notification_meta['incsub_wiki_email_notification'][0] == 'enabled' && !$this->is_subscribed()) {672 if (is_user_logged_in()) {673 $bottom .= '<div class="incsub_wiki-subscribe"><a href="'.wp_nonce_url(add_query_arg(array('post_id' => $post->ID, 'subscribe' => 1)), "wiki-subscribe-wiki_$post->ID" ).'">'.__('Notify me of changes', $this->translation_domain).'</a></div>';674 } else {675 if (!empty($_COOKIE['incsub_wiki_email'])) {676 $user_email = $_COOKIE['incsub_wiki_email'];677 } else {678 $user_email = "";679 }680 $bottom .= '<div class="incsub_wiki-subscribe">'.681 '<form action="" method="post">'.682 '<label>'.__('E-mail', $this->translation_domain).': <input type="text" name="email" id="email" value="'.$user_email.'" /></label> '.683 '<input type="hidden" name="post_id" id="post_id" value="'.$post->ID.'" />'.684 '<input type="submit" name="subscribe" id="subscribe" value="'.__('Notify me of changes', $this->translation_domain).'" />'.685 '<input type="hidden" name="_wpnonce" id="_wpnonce" value="'.wp_create_nonce("wiki-subscribe-wiki_$post->ID").'" />'.686 '</form>'.687 '</div>';688 }689 }690 $new_content = '<div class="incsub_wiki_top">' . $top . '</div>'. $new_content;691 $new_content .= '<div class="incsub_wiki_content">' . $content . '</div>';692 $new_content .= '<div class="incsub_wiki_bottom">' . $bottom . '</div>';693 $redirect = false;694 }695 696 $new_content .= '</div>';697 698 if ( !comments_open() ) {699 $new_content .= '<style type="text/css">'.700 '#comments { display: none; }'.701 '</style>';702 } else {703 $new_content .= '<style type="text/css">'.704 '.hentry { margin-bottom: 5px; }'.705 '</style>';706 }707 708 // Empty post_type means either malformed object found, or no valid parent was found.709 if ( !$redirect && empty($post->post_type) ) {710 $redirect = 'edit.php';711 }712 713 if ( !empty($redirect) ) {714 echo '<script type="text/javascript">'.715 'window.location = "'.$redirect.'";'.716 '</script>';717 exit;718 }719 720 return $new_content;721 }722 723 /**724 * Default post information to use when populating the "Write Post" form.725 *726 * @since 2.0.0727 *728 * @param string $post_type A post type string, defaults to 'post'.729 * @return object stdClass object containing all the default post data as attributes730 */731 function get_default_post_to_edit( $post_type = 'post', $create_in_db = false, $parent_id = 0 ) {732 global $wpdb;733 734 $post_title = '';735 if ( !empty( $_REQUEST['post_title'] ) )736 $post_title = esc_html( stripslashes( $_REQUEST['post_title'] ));737 738 $post_content = '';739 if ( !empty( $_REQUEST['content'] ) )740 $post_content = esc_html( stripslashes( $_REQUEST['content'] ));741 742 $post_excerpt = '';743 if ( !empty( $_REQUEST['excerpt'] ) )744 $post_excerpt = esc_html( stripslashes( $_REQUEST['excerpt'] ));745 746 if ( $create_in_db ) {747 // Cleanup old auto-drafts more than 7 days old748 $old_posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) > post_date" );749 foreach ( (array) $old_posts as $delete )750 wp_delete_post( $delete, true ); // Force delete751 $post_id = wp_insert_post( array( 'post_parent' => $parent_id, 'post_title' => __( 'Auto Draft' ), 'post_type' => $post_type, 'post_status' => 'auto-draft' ) );752 $post = get_post( $post_id );753 if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) && get_option( 'default_post_format' ) )754 set_post_format( $post, get_option( 'default_post_format' ) );755 } else {756 $post->ID = 0;757 $post->post_author = '';758 $post->post_date = '';759 $post->post_date_gmt = '';760 $post->post_password = '';761 $post->post_type = $post_type;762 $post->post_status = 'draft';763 $post->to_ping = '';764 $post->pinged = '';765 $post->comment_status = get_option( 'default_comment_status' );766 $post->ping_status = get_option( 'default_ping_status' );767 $post->post_pingback = get_option( 'default_pingback_flag' );768 $post->post_category = get_option( 'default_category' );769 $post->page_template = 'default';770 $post->post_parent = 0;771 $post->menu_order = 0;772 }773 774 $post->post_content = apply_filters( 'default_content', $post_content, $post );775 $post->post_title = apply_filters( 'default_title', $post_title, $post );776 $post->post_excerpt = apply_filters( 'default_excerpt', $post_excerpt, $post );777 $post->post_name = '';778 779 return $post;780 }781 782 function enqueue_comment_hotkeys_js() {783 if ( 'true' == get_user_option( 'comment_shortcuts' ) )784 wp_enqueue_script( 'jquery-table-hotkeys' );785 }786 787 /**788 * Get an existing post and format it for editing.789 *790 * @since 2.0.0791 *792 * @param unknown_type $id793 * @return unknown794 */795 function post_to_edit( $id ) {796 $post = get_post( $id, OBJECT, 'edit' );797 798 if ( $post->post_type == 'page' )799 $post->page_template = get_post_meta( $id, '_wp_page_template', true );800 return $post;801 }802 803 /**804 * Check to see if the post is currently being edited by another user.805 *806 * @since 2.5.0807 *808 * @param int $post_id ID of the post to check for editing809 * @return bool|int False: not locked or locked by current user. Int: user ID of user with lock.810 */811 function check_post_lock( $post_id ) {812 if ( !$post = get_post( $post_id ) )813 return false;814 815 if ( !$lock = get_post_meta( $post->ID, '_edit_lock', true ) )816 return false;817 818 $lock = explode( ':', $lock );819 $time = $lock[0];820 $user = isset( $lock[1] ) ? $lock[1] : get_post_meta( $post->ID, '_edit_last', true );821 822 $time_window = apply_filters( 'wp_check_post_lock_window', AUTOSAVE_INTERVAL * 2 );823 824 if ( $time && $time > time() - $time_window && $user != get_current_user_id() )825 return $user;826 return false;827 }828 829 /**830 * Mark the post as currently being edited by the current user831 *832 * @since 2.5.0833 *834 * @param int $post_id ID of the post to being edited835 * @return bool Returns false if the post doesn't exist of there is no current user836 */837 function set_post_lock( $post_id ) {838 if ( !$post = get_post( $post_id ) )839 return false;840 if ( 0 == ($user_id = get_current_user_id()) )841 return false;842 843 $now = time();844 $lock = "$now:$user_id";845 846 update_post_meta( $post->ID, '_edit_lock', $lock );847 }848 849 function get_edit_form() {850 global $post;851 852 $xcontent = '<h3>'.__('Edit', $this->translation_domain).'</h3>';853 $xcontent .= '<form action="'.get_permalink().'" method="post">';854 if (isset($_REQUEST['eaction']) && $_REQUEST['eaction'] == 'create') {855 $edit_post = $this->get_default_post_to_edit($post->post_type, true, $post->ID);856 $xcontent .= '<input type="hidden" name="parent_id" id="parent_id" value="'.$post->ID.'" />';857 $xcontent .= '<input type="hidden" name="original_publish" id="original_publish" value="Publish" />';858 $xcontent .= '<input type="hidden" name="publish" id="publish" value="Publish" />';859 } else {860 $edit_post = $post;861 $xcontent .= '<input type="hidden" name="parent_id" id="parent_id" value="'.$edit_post->post_parent.'" />';862 $xcontent .= '<input type="hidden" name="original_publish" id="original_publish" value="Update" />';863 }864 $xcontent .= '<input type="hidden" name="post_type" id="post_type" value="'.$edit_post->post_type.'" />';865 $xcontent .= '<input type="hidden" name="post_ID" id="wiki_id" value="'.$edit_post->ID.'" />';866 $xcontent .= '<input type="hidden" name="post_status" id="wiki_id" value="published" />';867 $xcontent .= '<input type="hidden" name="comment_status" id="comment_status" value="open" />';868 $xcontent .= '<input type="hidden" name="action" id="wiki_action" value="editpost" />';869 $xcontent .= '<div><input type="text" name="post_title" id="wiki_title" value="'.$edit_post->post_title.'" class="incsub_wiki_title" size="30" /></div>';870 $xcontent .= '<div><textarea tabindex="2" name="content" id="wiki_content" class="incusb_wiki_tinymce" cols="40" rows="10" >'.$edit_post->post_content.'</textarea></div>';871 $xcontent .= '<input type="hidden" name="_wpnonce" id="_wpnonce" value="'.wp_create_nonce("wiki-editpost_{$edit_post->ID}").'" />';872 873 if (is_user_logged_in()) {874 $xcontent .= $this->get_meta_form();875 }876 $xcontent .= '<div class="incsub_wiki_clear">';877 $xcontent .= '<input type="submit" name="save" id="btn_save" value="'.__('Save', $this->translation_domain).'" /> ';878 $xcontent .= '<a href="'.get_permalink().'?action=edit">'.__('Cancel', $this->translation_domain).'</a>';879 $xcontent .= '</div>';880 $xcontent .= '</form>';881 882 $wiki_admin = new WikiAdmin();883 884 $wiki_admin->tiny_mce(true, array("editor_selector" => "incusb_wiki_tinymce"));885 886 return $xcontent;887 }888 889 function get_meta_form() {890 global $post;891 892 $content = '';893 894 $content .= '<div class="incsub_wiki_meta_box">'.$this->notifications_meta_box(false).'</div>';895 896 return $content;897 }898 899 function tabs() {900 global $post, $incsub_tab_check;901 902 $incsub_tab_check = 1;903 904 $classes['page'] = array('incsub_wiki_link_page');905 $classes['discussion'] = array('incsub_wiki_link_discussion');906 $classes['history'] = array('incsub_wiki_link_history');907 $classes['edit'] = array('incsub_wiki_link_edit');908 $classes['advanced_edit'] = array('incsub_wiki_link_advanced_edit');909 $classes['create'] = array('incsub_wiki_link_create');910 911 if (!isset($_REQUEST['action'])) {912 $classes['page'][] = 'current';913 }914 if (isset($_REQUEST['action'])) {915 switch ($_REQUEST['action']) {916 case 'page':917 $classes['page'][] = 'current';918 break;919 case 'discussion':920 $classes['discussion'][] = 'current';921 break;922 case 'restore':923 case 'diff':924 case 'history':925 $classes['history'][] = 'current';926 break;927 case 'edit':928 if (isset($_REQUEST['eaction']) && $_REQUEST['eaction'] == 'create')929 $classes['create'][] = 'current';930 else931 $classes['edit'][] = 'current';932 break;933 }934 }935 936 $seperator = (preg_match('/\?/i', get_permalink()) > 0)? '&' : '?';937 938 $tabs = '<ul class="left">';939 $tabs .= '<li class="'.join(' ', $classes['page']).'" ><a href="'.get_permalink().'" >' . __('Page', $this->translation_domain) . '</a></li>';940 if (comments_open()) {941 $tabs .= '<li class="'.join(' ', $classes['discussion']).'" ><a href="'.get_permalink().$seperator.'action=discussion" >' . __('Discussion', $this->translation_domain) . '</a></li>';942 }943 $tabs .= '<li class="'.join(' ', $classes['history']).'" ><a href="'.get_permalink().$seperator.'action=history" >' . __('History', $this->translation_domain) . '</a></li>';944 $tabs .= '</ul>';945 946 $post_type_object = get_post_type_object( $post->post_type );947 948 if (current_user_can($post_type_object->cap->edit_post, $post->ID)) {949 $tabs .= '<ul class="right">';950 $tabs .= '<li class="'.join(' ', $classes['edit']).'" ><a href="'.get_permalink().$seperator.'action=edit" >' . __('Edit', $this->translation_domain) . '</a></li>';951 if (is_user_logged_in()) {952 $tabs .= '<li class="'.join(' ', $classes['advanced_edit']).'" ><a href="'.get_edit_post_link().'" >' . __('Advanced', $this->translation_domain) . '</a></li>';953 }954 $tabs .= '<li class="'.join(' ', $classes['create']).'"><a href="'.get_permalink().$seperator.'action=edit&eaction=create">'.__('Create new', $this->translation_domain).'</a></li>';955 $tabs .= '</ul>';956 }957 958 $incsub_tab_check = 0;959 960 return $tabs;961 }962 963 function get_edit_post_link($url, $id = 0, $context = 'display') {964 global $post;965 return $url;966 }967 968 /**969 * Display list of a post's revisions.970 *971 * Can output either a UL with edit links or a TABLE with diff interface, and972 * restore action links.973 *974 * Second argument controls parameters:975 * (bool) parent : include the parent (the "Current Revision") in the list.976 * (string) format : 'list' or 'form-table'. 'list' outputs UL, 'form-table'977 * outputs TABLE with UI.978 * (int) right : what revision is currently being viewed - used in979 * form-table format.980 * (int) left : what revision is currently being diffed against right -981 * used in form-table format.982 *983 * @package WordPress984 * @subpackage Post_Revisions985 * @since 2.6.0986 *987 * @uses wp_get_post_revisions()988 * @uses wp_post_revision_title()989 * @uses get_edit_post_link()990 * @uses get_the_author_meta()991 *992 * @todo split into two functions (list, form-table) ?993 *994 * @param int|object $post_id Post ID or post object.995 * @param string|array $args See description {@link wp_parse_args()}.996 * @return null997 */998 function list_post_revisions( $post_id = 0, $args = null ) {999 if ( !$post = get_post( $post_id ) )1000 return;1001 1002 $content = '';1003 $defaults = array( 'parent' => false, 'right' => false, 'left' => false, 'format' => 'list', 'type' => 'all' );1004 extract( wp_parse_args( $args, $defaults ), EXTR_SKIP );1005 switch ( $type ) {1006 case 'autosave' :1007 if ( !$autosave = wp_get_post_autosave( $post->ID ) )1008 return;1009 $revisions = array( $autosave );1010 break;1011 case 'revision' : // just revisions - remove autosave later1012 case 'all' :1013 default :1014 if ( !$revisions = wp_get_post_revisions( $post->ID ) )1015 return;1016 break;1017 }1018 1019 // print_r($revisions);1020 1021 /* translators: post revision: 1: when, 2: author name */1022 $titlef = _x( '%1$s by %2$s', 'post revision' );1023 1024 if ( $parent )1025 array_unshift( $revisions, $post );1026 1027 $rows = '';1028 $class = false;1029 $can_edit_post = current_user_can( 'edit_wiki', $post->ID );1030 foreach ( $revisions as $revision ) {1031 /*if ( !current_user_can( 'read_post', $revision->ID ) )1032 continue;*/1033 if ( 'revision' === $type && wp_is_post_autosave( $revision ) )1034 continue;1035 1036 $date = wp_post_revision_title( $revision, false );1037 $name = get_the_author_meta( 'display_name', $revision->post_author );1038 1039 if ( 'form-table' == $format ) {1040 if ( $left )1041 $left_checked = $left == $revision->ID ? ' checked="checked"' : '';1042 else1043 $left_checked = $right_checked ? ' checked="checked"' : ''; // [sic] (the next one)1044 1045 $right_checked = $right == $revision->ID ? ' checked="checked"' : '';1046 1047 $class = $class ? '' : " class='alternate'";1048 1049 if ( $post->ID != $revision->ID && $can_edit_post && current_user_can( 'read_post', $revision->ID ) )1050 $actions = '<a href="' . wp_nonce_url( add_query_arg( array( 'revision' => $revision->ID, 'action' => 'restore' ) ), "restore-post_$post->ID|$revision->ID" ) . '">' . __( 'Restore' ) . '</a>';1051 else1052 $actions = ' ';1053 1054 $rows .= "<tr$class>\n";1055 $rows .= "\t<td style='white-space: nowrap' scope='row'><input type='radio' name='left' value='{$revision->ID}' {$left_checked} /></td>\n";1056 $rows .= "\t<td style='white-space: nowrap' scope='row'><input type='radio' name='right' value='{$revision->ID}' {$right_checked} /></td>\n";1057 $rows .= "\t<td>$date</td>\n";1058 $rows .= "\t<td>$name</td>\n";1059 $rows .= "\t<td class='action-links'>$actions</td>\n";1060 $rows .= "</tr>\n";1061 } else {1062 $title = sprintf( $titlef, $date, $name );1063 $rows .= "\t<li>$title</li>\n";1064 }1065 }1066 if ( 'form-table' == $format ) :1067 $content .= '<form action="'.get_permalink().'" method="get">';1068 $content .= '<div class="tablenav">';1069 $content .= '<div class="alignleft">';1070 $content .= '<input type="submit" class="button-secondary" value="'.esc_attr( 'Compare Revisions' ).'" />';1071 $content .= '<input type="hidden" name="action" value="diff" />';1072 $content .= '<input type="hidden" name="post_type" value="'.esc_attr($post->post_type).'" />';1073 $content .= '</div>';1074 $content .= '</div>';1075 $content .= '<br class="clear" />';1076 $content .= '<table class="widefat post-revisions" cellspacing="0" id="post-revisions">';1077 $content .= '<col /><col /><col style="width: 33%" /><col style="width: 33%" /><col style="width: 33%" />';1078 $content .= '<thead>';1079 $content .= '<tr>';1080 $content .= '<th scope="col">'._x( 'Old', 'revisions column name', $this->translation_domain ).'</th>';1081 $content .= '<th scope="col">'._x( 'New', 'revisions column name', $this->translation_domain ).'</th>';1082 $content .= '<th scope="col">'._x( 'Date Created', 'revisions column name', $this->translation_domain ).'</th>';1083 $content .= '<th scope="col">'.__( 'Author', $this->translation_domain, $this->translation_domain ).'</th>';1084 $content .= '<th scope="col" class="action-links">'.__( 'Actions', $this->translation_domain ).'</th>';1085 $content .= '</tr>';1086 $content .= '</thead>';1087 $content .= '<tbody>';1088 $content .= $rows;1089 $content .= '</tbody>';1090 $content .= '</table>';1091 $content .= '</form>';1092 else :1093 $content .= "<ul class='post-revisions'>\n";1094 $content .= $rows;1095 $content .= "</ul>";1096 endif;1097 return $content;1098 }1099 1100 function user_has_cap($allcaps, $caps = null, $args = null) {1101 global $current_user, $blog_id, $post;1102 1103 $capable = false;1104 1105 if (preg_match('/(_wiki|_wikis)/i', join($caps, ',')) > 0) {1106 if (in_array('administrator', $current_user->roles)) {1107 foreach ($caps as $cap) {1108 $allcaps[$cap] = 1;1109 }1110 return $allcaps;1111 }1112 foreach ($caps as $cap) {1113 $capable = false;1114 switch ($cap) {1115 case 'read_wiki':1116 $capable = true;1117 break;1118 case 'edit_others_wikis':1119 case 'edit_published_wikis':1120 case 'edit_wikis':1121 case 'edit_wiki':1122 if (current_user_can('edit_posts')) {1123 $capable = true;1124 }1125 break;1126 default:1127 if (isset($args[1]) && isset($args[2])) {1128 if (current_user_can(preg_replace('/_wiki/i', '_post', $cap), $args[1], $args[2])) {1129 $capable = true;1130 }1131 } else if (isset($args[1])) {1132 if (current_user_can(preg_replace('/_wiki/i', '_post', $cap), $args[1])) {1133 $capable = true;1134 }1135 } else if (current_user_can(preg_replace('/_wiki/i', '_post', $cap))) {1136 $capable = true;1137 }1138 break;1139 }1140 1141 if ($capable) {1142 $allcaps[$cap] = 1;1143 }1144 }1145 }1146 return $allcaps;1147 }1148 1149 function role_has_cap($capabilities, $cap, $name) {1150 // nothing to do1151 }1152 1153 /**1154 * Activation hook1155 *1156 * Create tables if they don't exist and add plugin options1157 *1158 * @see http://codex.wordpress.org/Function_Reference/register_activation_hook1159 *1160 * @global object $wpdb1161 */1162 function install() {1163 global $wpdb;1164 1165 /**1166 * WordPress database upgrade/creation functions1167 */1168 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');1169 1170 // Get the correct character collate1171 if ( ! empty($wpdb->charset) )1172 $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";1173 if ( ! empty($wpdb->collate) )1174 $charset_collate .= " COLLATE $wpdb->collate";1175 1176 // Setup the subscription table1177 $sql_main =1178 "CREATE TABLE `" . $this->db_prefix . "wiki_subscriptions` (1179 `ID` bigint(20) unsigned NOT NULL auto_increment,1180 `blog_id` bigint(20) NOT NULL,1181 `wiki_id` bigint(20) NOT NULL,1182 `user_id` bigint(20),1183 `email` VARCHAR(255),1184 PRIMARY KEY (`ID`)1185 ) ENGINE=MyISAM;";1186 1187 dbDelta($sql_main);1188 1189 // Default chat options1190 $this->_options['default'] = get_option('wiki_default', array('slug' => 'wiki'));1191 1192 if (!is_array($this->_options['default'])) {1193 $this->_options['default'] = array('slug' => 'wiki');1194 }1195 1196 update_option('wiki_default', $this->_options['default']);1197 }1198 1199 /**1200 * Add the admin menus1201 *1202 * @see http://codex.wordpress.org/Adding_Administration_Menus1203 */1204 function admin_menu() {1205 $page = add_submenu_page('edit.php?post_type=incsub_wiki', __('Wiki Settings', $this->translation_domain), __('Wiki Settings', $this->translation_domain), 'manage_options', 'incsub_wiki', array(&$this, 'options_page'));1206 add_action( 'admin_print_scripts-' . $page, array(&$this, 'admin_script_settings') );1207 add_action( 'admin_print_styles-' . $page, array(&$this, 'admin_css_settings') );1208 }1209 1210 function admin_script_settings() {1211 // Nothing to do1212 }1213 1214 function admin_css_settings() {1215 // Nothing to do1216 }1217 1218 function options_page() {1219 if(!current_user_can('manage_options')) {1220 echo "<p>" . __('Nice Try...', $this->translation_domain) . "</p>"; //If accessed properly, this message doesn't appear.1221 return;1222 }1223 if (wp_verify_nonce($_POST['_wpnonce'], 'incsub_wiki-update-options')) {1224 $this->_options['default']['slug'] = $_POST['wiki_default']['slug'];1225 update_option('wiki_default', $this->_options['default']);1226 wp_redirect('edit.php?post_type=incsub_wiki&page=incsub_wiki&incsub_wiki_settings_saved=1');1227 }1228 if ($_GET['incsub_wiki_settings_saved'] == 1) {1229 echo '<div class="updated fade"><p>'.__('Settings saved.', $this->translation_domain).'</p></div>';1230 }1231 ?>1232 <div class="wrap">1233 <h2><?php _e('Wiki Settings', $this->translation_domain); ?></h2>1234 <form method="post" action="edit.php?post_type=incsub_wiki&page=incsub_wiki">1235 <?php wp_nonce_field('incsub_wiki-update-options'); ?>1236 <table>1237 <tr valign="top">1238 <td><label for="incsub_wiki-slug"><?php _e('Wiki Slug', $this->translation_domain); ?></label> </td>1239 <td> /<input type="text" size="20" id="incsub_wiki-slug" name="wiki_default[slug]" value="<?php print $this->_options['default']['slug']; ?>" /></td>1240 </tr>1241 </table>1242 1243 <p class="submit">1244 <input type="submit" name="submit_settings" value="<?php _e('Save Changes', $this->translation_domain) ?>" />1245 </p>1246 </form>1247 1248 <div style="-moz-border-radius: 5px;-khtml-border-radius: 5px;-webkit-border-radius: 5px;border-radius: 5px;border: 1px solid #F6C600;background-color: #FFFFC4;padding: 5px 20px;margin: 5px 0px 10px;font-size: 110%;">1249 <h3><a href="https://premium.wpmudev.org/subscribe/">Join WPMU DEV now to download over 300 plugins, themes and videos - and get and the best WordPress support on the web!</a></h3>1250 <div class="vzaar_media_player" style="float:left;margin-left:50px;">1251 <object id="video" type="application/x-shockwave-flash" data="http://view.vzaar.com/572452.flashplayer" height="284" width="486"><param name="movie" value="http://view.vzaar.com/572452.flashplayer"><param name="allowScriptAccess" value="always"><param name="allowFullScreen" value="true"><param name="wmode" value="transparent"><param name="flashvars" value="border=none"><embed src="http://view.vzaar.com/572452.flashplayer" type="application/x-shockwave-flash" wmode="transparent" allowscriptaccess="always" allowfullscreen="true" flashvars="border=none" height="284" width="486"><video src="http://view.vzaar.com/572452.mobile" poster="http://view.vzaar.com/572452.image" controls="controls" onclick="this.play();" height="720" width="1280"></video></object>1252 </div>1253 1254 <div style="float:left;margin-left:50px;">1255 <h3>As a member of WPMU DEV you get:</h3>1256 <ul>1257 <li><strong>Unlimited</strong> use of our 300+ plugins & themes, forever!</li>1258 <li>Over 35 white label video manuals for you, your users and clients</li>1259 <li>Upgrades and support <strong>guaranteed</strong></li>1260 <li>Helpful<strong> live chat</strong> and <strong>support forums</strong></li>1261 <li>Access to all new plugins & themes</li>1262 <li>New feature development requests</li>1263 <li>Full access to WPMU Jobs</li>1264 <li>Comprehensive manuals & eBooks</li>1265 <li>It's like having your own personal developer!</li>1266 </ul>1267 </div>1268 <div style="margin-left:50px;clear:both;"><a href="https://premium.wpmudev.org/join/"><img title="Click Here To Find Out More..." src="http://premium.wpmudev.org/wp-content/themes/wp-wpmudev/images/promo.png" alt="Click here to find out more" height="179" width="848"></a></div>1269 </div>1270 1271 </div>1272 <?php1273 }1274 1275 /**1276 * Deactivation hook1277 *1278 * @see http://codex.wordpress.org/Function_Reference/register_deactivation_hook1279 *1280 * @global object $wpdb1281 */1282 function uninstall() {1283 global $wpdb;1284 // Nothing to do1285 }1286 1287 /**1288 * Initialize the plugin1289 *1290 * @see http://codex.wordpress.org/Plugin_API/Action_Reference1291 * @see http://adambrown.info/p/wp_hooks/hook/init1292 */1293 function init() {1294 global $wpdb, $wp_rewrite, $current_user, $blog_id;1295 1296 if (preg_match('/mu\-plugin/', PLUGINDIR) > 0) {1297 load_muplugin_textdomain($this->translation_domain, dirname(plugin_basename(__FILE__)).'/languages');1298 } else {1299 load_plugin_textdomain($this->translation_domain, false, dirname(plugin_basename(__FILE__)).'/languages');1300 }1301 1302 wp_register_script('incsub_wiki_js', plugins_url('wordpress-wiki-plugin/js/wiki-utils.js'), null, $this->current_version);1303 1304 $labels = array(1305 'name' => __('Wikis', $this->translation_domain),1306 'singular_name' => __('Wiki', $this->translation_domain),1307 'add_new' => __('Add WIki', $this->translation_domain),1308 'add_new_item' => __('Add New Wiki', $this->translation_domain),1309 'edit_item' => __('Edit Wiki', $this->translation_domain),1310 'new_item' => __('New Wiki', $this->translation_domain),1311 'view_item' => __('View Wiki', $this->translation_domain),1312 'search_items' => __('Search Wiki', $this->translation_domain),1313 'not_found' => __('No Wiki found', $this->translation_domain),1314 'not_found_in_trash' => __('No wikis found in Trash', $this->translation_domain),1315 'menu_name' => __('Wikis', $this->translation_domain)1316 );1317 1318 $supports = array( 'title', 'editor', 'author', 'revisions', 'comments', 'page-attributes');1319 1320 register_post_type( 'incsub_wiki',1321 array(1322 'labels' => $labels,1323 'public' => true,1324 'show_ui' => true,1325 'publicly_queryable' => true,1326 'capability_type' => 'wiki',1327 'hierarchical' => true,1328 'map_meta_cap' => true,1329 'query_var' => true,1330 'supports' => $supports,1331 'rewrite' => false1332 )1333 );1334 1335 $wiki_structure = '/'.$this->_options['default']['slug'].'/%wiki%';1336 1337 $wp_rewrite->add_rewrite_tag("%wiki%", '(.+?)', "incsub_wiki=");1338 $wp_rewrite->add_permastruct('incsub_wiki', $wiki_structure, false);1339 1340 if (isset($_REQUEST['subscribe']) && wp_verify_nonce($_REQUEST['_wpnonce'], "wiki-subscribe-wiki_{$_REQUEST['post_id']}")) {1341 if (isset($_REQUEST['email'])) {1342 if ($wpdb->insert("{$this->db_prefix}wiki_subscriptions",1343 array('blog_id' => $blog_id,1344 'wiki_id' => $_REQUEST['post_id'],1345 'email' => $_REQUEST['email']))) {1346 setcookie('incsub_wiki_email', $_REQUEST['email'], time()+3600*24*365, '/');1347 wp_redirect(get_permalink($_REQUEST['post_id']));1348 exit();1349 }1350 } else if (is_user_logged_in()){1351 if ($wpdb->insert("{$this->db_prefix}wiki_subscriptions",1352 array('blog_id' => $blog_id,1353 'wiki_id' => $_REQUEST['post_id'],1354 'user_id' => $current_user->ID))) {1355 wp_redirect(get_permalink($_REQUEST['post_id']));1356 exit();1357 }1358 }1359 }1360 1361 if (isset($_GET['action']) && $_GET['action'] == 'cancel-wiki-subscription') {1362 if ($wpdb->query("DELETE FROM {$this->db_prefix}wiki_subscriptions WHERE ID = ".intval($_GET['sid']).";")) {1363 wp_redirect(get_option('siteurl'));1364 exit();1365 }1366 }1367 }1368 1369 /**1370 * Output CSS1371 */1372 function output_css() {1373 echo '<link rel="stylesheet" href="' . plugins_url('wordpress-wiki-plugin/css/style.css') . '" type="text/css" />';1374 }1375 1376 function output_js() {1377 wp_enqueue_script('utils');1378 }1379 1380 function is_subscribed() {1381 global $wpdb, $current_user, $post;1382 1383 if (is_user_logged_in()) {1384 if ($wpdb->get_var("SELECT ID FROM {$this->db_prefix}wiki_subscriptions WHERE wiki_id = {$post->ID} AND user_id = {$current_user->ID}") > 0) {1385 return true;1386 }1387 } else if ($wpdb->get_var("SELECT ID FROM {$this->db_prefix}wiki_subscriptions WHERE wiki_id = {$post->ID} AND email = '{$_COOKIE['incsub_wiki_email']}'") > 0) {1388 return true;1389 }1390 1391 return false;1392 }1393 1394 function meta_boxes() {1395 global $post, $current_user;1396 1397 if ($post->post_author == $current_user->ID || current_user_can('edit_posts')) {1398 add_meta_box('incsub-wiki-notifications', __('Wiki E-mail Notifications', $this->translation_domain), array(&$this, 'notifications_meta_box'), 'incsub_wiki', 'side');1399 }1400 }1401 1402 function post_type_link($permalink, $post_id, $leavename) {1403 $post = get_post($post_id);1404 1405 $rewritecode = array(1406 '%wiki%',1407 );1408 1409 if ($post->post_type == 'incsub_wiki' && '' != $permalink) {1410 1411 $ptype = get_post_type_object($post->post_type);1412 1413 if ($ptype->hierarchical) {1414 $uri = get_page_uri($post);1415 $uri = untrailingslashit($uri);1416 $uri = strrev( stristr( strrev( $uri ), '/' ) );1417 $uri = untrailingslashit($uri);1418 1419 if (!empty($uri)) {1420 $uri .= '/';1421 $permalink = str_replace('%wiki%', "{$uri}%wiki%", $permalink);1422 }1423 }1424 1425 $rewritereplace = array(1426 ($post->post_name == "")?$post->id:$post->post_name1427 );1428 $permalink = str_replace($rewritecode, $rewritereplace, $permalink);1429 } else {1430 // if they're not using the fancy permalink option1431 }1432 1433 return $permalink;1434 }1435 1436 function name_save($post_name) {1437 if ($_POST['post_type'] == 'incsub_wiki' && empty($post_name)) {1438 $post_name = $_POST['post_title'];1439 }1440 1441 return $post_name;1442 }1443 1444 function notifications_meta_box($echo = true) {1445 global $post;1446 $settings = get_option('incsub_wiki_settings');1447 $meta = get_post_custom($post->ID);1448 if ($meta == array()) {1449 $meta = array('incsub_wiki_email_notification' => array('enabled'));1450 }1451 $content = '';1452 $content .= '<input type="hidden" name="incsub_wiki_notifications_meta" value="1" />';1453 $content .= '<div class="alignleft">';1454 $content .= '<label><input type="checkbox" name="incsub_wiki_email_notification" value="enabled" '.(($meta["incsub_wiki_email_notification"][0] == "")?'':'checked="checked"').' /> '.__('Enable e-mail notifications', $this->translation_domain).'</label>';1455 $content .= '</div>';1456 $content .= '<div class="clear"></div>';1457 1458 if ($echo) {1459 echo $content;1460 }1461 return $content;1462 }1463 1464 function save_wiki_meta($post_id, $post = null) {1465 //skip quick edit1466 if ( defined('DOING_AJAX') )1467 return;1468 1469 if ( $post->post_type == "incsub_wiki" && isset( $_POST['incsub_wiki_notifications_meta'] ) ) {1470 $meta = get_post_custom($post_id);1471 1472 update_post_meta($post_id, 'incsub_wiki_email_notification', $_POST['incsub_wiki_email_notification']);1473 1474 //for any other plugin to hook into1475 do_action( 'incsub_wiki_save_notifications_meta', $post_id, $meta );1476 }1477 }1478 1479 function widgets_init() {1480 register_widget('WikiWidget');1481 }1482 1483 function send_notifications($post_id) {1484 global $wpdb;1485 // We do autosaves manually with wp_create_post_autosave()1486 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )1487 return;1488 1489 if ( !$post = get_post( $post_id, ARRAY_A ) )1490 return;1491 1492 if ( $post['post_type'] != 'incsub_wiki' || !post_type_supports($post['post_type'], 'revisions') )1493 return;1494 1495 // all revisions and (possibly) one autosave1496 $revisions = wp_get_post_revisions($post_id, array( 'order' => 'ASC' ));1497 1498 $revision = array_pop($revisions);1499 1500 $post = get_post($post_id);1501 1502 $cancel_url = get_option('siteurl') . '?action=cancel-wiki-subscription&sid=';1503 $admin_email = get_option('admin_email');1504 $post_title = $post->post_title;1505 $post_content = $post->post_content;1506 $post_url = get_permalink($post_id);1507 1508 $revisions = wp_get_post_revisions($post->ID);1509 $revision = array_shift($revisions);1510 1511 $revert_url = wp_nonce_url(add_query_arg(array('revision' => $revision->ID), admin_url('revision.php')), "restore-post_$post->ID|$revision->ID" );1512 1513 //cleanup title1514 $blog_name = get_option('blogname');1515 $post_title = strip_tags($post_title);1516 //cleanup content1517 $post_content = strip_tags($post_content);1518 //get excerpt1519 $post_excerpt = $post_content;1520 if (strlen($post_excerpt) > 255) {1521 $post_excerpt = substr($post_excerpt,0,252) . '...';1522 }1523 1524 $wiki_notification_content = array();1525 $wiki_notification_content['user'] = "Dear Subscriber,1526 1527 POST_TITLE was changed1528 1529 You can read the Wiki page in full here: POST_URL1530 1531 EXCERPT1532 1533 Thanks,1534 BLOGNAME1535 1536 Cancel subscription: CANCEL_URL";1537 1538 $wiki_notification_content['author'] = "Dear Author,1539 1540 POST_TITLE was changed1541 1542 You can read the Wiki page in full here: POST_URL1543 You can revert the changes: REVERT_URL1544 1545 EXCERPT1546 1547 Thanks,1548 BLOGNAME1549 1550 Cancel subscription: CANCEL_URL";1551 1552 //format notification text1553 foreach ($wiki_notification_content as $key => $content) {1554 $wiki_notification_content[$key] = str_replace("BLOGNAME",$blog_name,$wiki_notification_content[$key]);1555 $wiki_notification_content[$key] = str_replace("POST_TITLE",$post_title,$wiki_notification_content[$key]);1556 $wiki_notification_content[$key] = str_replace("EXCERPT",$post_excerpt,$wiki_notification_content[$key]);1557 $wiki_notification_content[$key] = str_replace("POST_URL",$post_url,$wiki_notification_content[$key]);1558 $wiki_notification_content[$key] = str_replace("REVERT_URL",$revert_url,$wiki_notification_content[$key]);1559 $wiki_notification_content[$key] = str_replace("\'","'",$wiki_notification_content[$key]);1560 }1561 1562 $query = "SELECT * FROM " . $this->db_prefix . "wiki_subscriptions WHERE wiki_id = {$post->ID}";1563 $subscription_emails = $wpdb->get_results( $query, ARRAY_A );1564 1565 if (count($subscription_emails) > 0){1566 foreach ($subscription_emails as $subscription_email){1567 $loop_notification_content = $wiki_notification_content['user'];1568 1569 $loop_notification_content = $wiki_notification_content['user'];1570 1571 if ($subscription_email['user_id'] > 0) {1572 if ($subscription_email['user_id'] == $post->post_author) {1573 $loop_notification_content = $wiki_notification_content['author'];1574 }1575 $user = get_userdata($subscription_email['user_id']);1576 $subscription_to = $user->user_email;1577 } else {1578 $subscription_to = $subscription_email['email'];1579 }1580 1581 $loop_notification_content = str_replace("CANCEL_URL",$cancel_url . $subscription_email['ID'],$loop_notification_content);1582 $subject_content = $blog_name . ': ' . __('Wiki Page Changes', $this->translation_domain);1583 $from_email = $admin_email;1584 $message_headers = "MIME-Version: 1.0\n" . "From: " . $blog_name . " <{$from_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";1585 wp_mail($subscription_to, $subject_content, $loop_notification_content, $message_headers);1586 }1587 }1588 }1589 }1590 1591 class WikiWidget extends WP_Widget {1592 1593 /**1594 * @var string $translation_domain Translation domain1595 */1596 var $translation_domain = 'wiki';1597 1598 function WikiWidget() {1599 $widget_ops = array( 'description' => __('Display Wiki Pages', $this->translation_domain) );1600 $control_ops = array( 'title' => __('Wiki', $this->translation_domain), 'hierarchical' => 'yes' );1601 $this->WP_Widget( 'incsub_wiki', __('Wiki', $this->translation_domain), $widget_ops, $control_ops );1602 }1603 1604 function widget($args, $instance) {1605 global $wpdb, $current_site, $post, $wiki_tree;1606 1607 extract($args);1608 1609 $options = $instance;1610 1611 $title = apply_filters('widget_title', empty($instance['title']) ? __('Wiki', $this->translation_domain) : $instance['title'], $instance, $this->id_base);1612 1613 ?>1614 <?php echo $before_widget; ?>1615 <?php echo $before_title . $title . $after_title; ?>1616 <?php1617 $wiki_posts = get_posts('post_parent=0&post_type=incsub_wiki&order_by=menu_order');1618 ?>1619 <ul>1620 <?php1621 foreach ($wiki_posts as $wiki) {1622 ?>1623 <li><a href="<?php print get_permalink($wiki->ID); ?>" class="<?php print ($wiki->ID == $post->ID)?'current':''; ?>" ><?php print $wiki->post_title; ?></a>1624 <?php print $this->_print_sub_wikis($wiki); ?>1625 </li>1626 <?php1627 }1628 ?>1629 </ul>1630 <br />1631 <?php echo $after_widget; ?>1632 <?php1633 }1634 1635 function _print_sub_wikis($wiki) {1636 global $post;1637 1638 $sub_wikis = get_posts('post_parent='.$wiki->ID.'&post_type=incsub_wiki&order_by=menu_order');1639 ?>1640 <ul>1641 <?php1642 foreach ($sub_wikis as $sub_wiki) {1643 ?>1644 <li><a href="<?php print get_permalink($sub_wiki->ID); ?>" class="<?php print ($sub_wiki->ID == $post->ID)?'current':''; ?>" ><?php print $sub_wiki->post_title; ?></a>1645 <?php print $this->_print_sub_wikis($sub_wiki); ?>1646 </li>1647 <?php1648 }1649 ?>1650 </ul>1651 <?php1652 }1653 1654 function update($new_instance, $old_instance) {1655 $instance = $old_instance;1656 $new_instance = wp_parse_args( (array) $new_instance, array( 'title' => __('Wiki', $this->translation_domain), 'hierarchical' => 'yes') );1657 $instance['title'] = strip_tags($new_instance['title']);1658 $instance['hierarchical'] = $new_instance['hierarchical'];1659 1660 return $instance;1661 }1662 1663 function form($instance) {1664 $instance = wp_parse_args( (array) $instance, array( 'title' => __('Wiki', $this->translation_domain), 'hierarchical' => 'yes'));1665 $options = array('title' => strip_tags($instance['title']), 'hierarchical' => $instance['hierarchical']);1666 1667 ?>1668 <div style="text-align:left">1669 <label for="<?php echo $this->get_field_id('title'); ?>" style="line-height:35px;display:block;"><?php _e('Title', $this->translation_domain); ?>:<br />1670 <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $options['title']; ?>" type="text" style="width:95%;" />1671 </label>1672 <label for="<?php echo $this->get_field_id('hierarchical'); ?>" style="line-height:35px;display:block;"><?php _e('Only top level', $this->translation_domain); ?>:<br />1673 <select id="<?php echo $this->get_field_id('hierarchical'); ?>" name="<?php echo $this->get_field_name('hierarchical'); ?>" >1674 <option value="no" <?php if ($options['hierarchical'] == 'no'){ echo 'selected="selected"'; } ?> ><?php _e('Yes', $this->translation_domain); ?></option>1675 <option value="yes" <?php if ($options['hierarchical'] == 'yes'){ echo 'selected="selected"'; } ?> ><?php _e('No', $this->translation_domain); ?></option>1676 </select>1677 </label>1678 <input type="hidden" name="wiki-submit" id="wiki-submit" value="1" />1679 </div>1680 <?php1681 }1682 }1683 1684 class WikiAdmin {1685 /**1686 * Adds the TinyMCE editor used on the Write and Edit screens.1687 *1688 * @package WordPress1689 * @since 2.7.01690 *1691 * TinyMCE is loaded separately from other Javascript by using wp-tinymce.php. It outputs concatenated1692 * and optionaly pre-compressed version of the core and all default plugins. Additional plugins are loaded1693 * directly by TinyMCE using non-blocking method. Custom plugins can be refreshed by adding a query string1694 * to the URL when queueing them with the mce_external_plugins filter.1695 *1696 * @param bool $teeny optional Output a trimmed down version used in Press This.1697 * @param mixed $settings optional An array that can add to or overwrite the default TinyMCE settings.1698 */1699 function tiny_mce( $teeny = false, $settings = false ) {1700 global $concatenate_scripts, $compress_scripts, $tinymce_version, $editor_styles;1701 1702 if ( ! user_can_richedit() )1703 return;1704 1705 $baseurl = includes_url('js/tinymce');1706 1707 $mce_locale = ( '' == get_locale() ) ? 'en' : strtolower( substr(get_locale(), 0, 2) ); // only ISO 639-11708 1709 /*1710 The following filter allows localization scripts to change the languages displayed in the spellchecker's drop-down menu.1711 By default it uses Google's spellchecker API, but can be configured to use PSpell/ASpell if installed on the server.1712 The + sign marks the default language. More information:1713 http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/spellchecker1714 */1715 $mce_spellchecker_languages = apply_filters('mce_spellchecker_languages', '+English=en,Danish=da,Dutch=nl,Finnish=fi,French=fr,German=de,Italian=it,Polish=pl,Portuguese=pt,Spanish=es,Swedish=sv');1716 1717 if ( $teeny ) {1718 $plugins = apply_filters( 'teeny_mce_plugins', array('inlinepopups', 'fullscreen', 'wordpress', 'wplink', 'wpdialogs') );1719 $ext_plugins = '';1720 } else {1721 $plugins = array( 'inlinepopups', 'spellchecker', 'paste', 'wordpress', 'fullscreen', 'wpeditimage', 'wpgallery', 'tabfocus', 'wplink', 'wpdialogs' );1722 1723 /*1724 The following filter takes an associative array of external plugins for TinyMCE in the form 'plugin_name' => 'url'.1725 It adds the plugin's name to TinyMCE's plugins init and the call to PluginManager to load the plugin.1726 The url should be absolute and should include the js file name to be loaded. Example:1727 array( 'myplugin' => 'http://my-site.com/wp-content/plugins/myfolder/mce_plugin.js' )1728 If the plugin uses a button, it should be added with one of the "$mce_buttons" filters.1729 */1730 $mce_external_plugins = apply_filters('mce_external_plugins', array());1731 1732 $ext_plugins = '';1733 if ( ! empty($mce_external_plugins) ) {1734 1735 /*1736 The following filter loads external language files for TinyMCE plugins.1737 It takes an associative array 'plugin_name' => 'path', where path is the1738 include path to the file. The language file should follow the same format as1739 /tinymce/langs/wp-langs.php and should define a variable $strings that1740 holds all translated strings.1741 When this filter is not used, the function will try to load {mce_locale}.js.1742 If that is not found, en.js will be tried next.1743 */1744 $mce_external_languages = apply_filters('mce_external_languages', array());1745 $loaded_langs = array();1746 $strings = '';1747 if ( ! empty($mce_external_languages) ) {1748 foreach ( $mce_external_languages as $name => $path ) {1749 if ( @is_file($path) && @is_readable($path) ) {1750 include_once($path);1751 $ext_plugins .= $strings . "\n";1752 $loaded_langs[] = $name;1753 }1754 }1755 }1756 1757 foreach ( $mce_external_plugins as $name => $url ) {1758 if ( is_ssl() ) $url = str_replace('http://', 'https://', $url);1759 $plugins[] = '-' . $name;1760 $plugurl = dirname($url);1761 $strings = $str1 = $str2 = '';1762 if ( ! in_array($name, $loaded_langs) ) {1763 $path = str_replace( WP_PLUGIN_URL, '', $plugurl );1764 $path = WP_PLUGIN_DIR . $path . '/langs/';1765 if ( function_exists('realpath') )1766 $path = trailingslashit( realpath($path) );1767 if ( @is_file($path . $mce_locale . '.js') )1768 $strings .= @file_get_contents($path . $mce_locale . '.js') . "\n";1769 if ( @is_file($path . $mce_locale . '_dlg.js') )1770 $strings .= @file_get_contents($path . $mce_locale . '_dlg.js') . "\n";1771 if ( 'en' != $mce_locale && empty($strings) ) {1772 if ( @is_file($path . 'en.js') ) {1773 $str1 = @file_get_contents($path . 'en.js');1774 $strings .= preg_replace( '/([\'"])en\./', '$1' . $mce_locale . '.', $str1, 1 ) . "\n";1775 }1776 if ( @is_file($path . 'en_dlg.js') ) {1777 $str2 = @file_get_contents($path . 'en_dlg.js');1778 $strings .= preg_replace( '/([\'"])en\./', '$1' . $mce_locale . '.', $str2, 1 ) . "\n";1779 }1780 }1781 if ( ! empty($strings) )1782 $ext_plugins .= "\n" . $strings . "\n";1783 }1784 $ext_plugins .= 'tinyMCEPreInit.load_ext("' . $plugurl . '", "' . $mce_locale . '");' . "\n";1785 $ext_plugins .= 'tinymce.PluginManager.load("' . $name . '", "' . $url . '");' . "\n";1786 }1787 }1788 }1789 1790 if ( $teeny ) {1791 $mce_buttons = apply_filters( 'teeny_mce_buttons', array('bold, italic, underline, blockquote, separator, strikethrough, bullist, numlist,justifyleft, justifycenter, justifyright, undo, redo, link, unlink, fullscreen') );1792 $mce_buttons = implode($mce_buttons, ',');1793 $mce_buttons_2 = $mce_buttons_3 = $mce_buttons_4 = '';1794 } else {1795 $mce_buttons = apply_filters('mce_buttons', array('bold', 'italic', 'strikethrough', '|', 'bullist', 'numlist', 'blockquote', '|', 'justifyleft', 'justifycenter', 'justifyright', '|', 'link', 'unlink', 'wp_more', '|', 'spellchecker', 'fullscreen', 'wp_adv' ));1796 $mce_buttons = implode($mce_buttons, ',');1797 $mce_buttons_2 = array( 'formatselect', 'underline', 'justifyfull', 'forecolor', '|', 'pastetext', 'pasteword', 'removeformat', '|', 'charmap', '|', 'outdent', 'indent', '|', 'undo', 'redo', 'wp_help' );1798 $mce_buttons_2 = apply_filters('mce_buttons_2', $mce_buttons_2);1799 $mce_buttons_2 = implode($mce_buttons_2, ',');1800 $mce_buttons_3 = apply_filters('mce_buttons_3', array());1801 $mce_buttons_3 = implode($mce_buttons_3, ',');1802 $mce_buttons_4 = apply_filters('mce_buttons_4', array());1803 $mce_buttons_4 = implode($mce_buttons_4, ',');1804 }1805 $no_captions = (bool) apply_filters( 'disable_captions', '' );1806 1807 // TinyMCE init settings1808 $initArray = array (1809 'mode' => 'specific_textareas',1810 'editor_selector' => 'theEditor',1811 'width' => '100%',1812 'theme' => 'advanced',1813 'skin' => 'wp_theme',1814 'theme_advanced_buttons1' => $mce_buttons,1815 'theme_advanced_buttons2' => $mce_buttons_2,1816 'theme_advanced_buttons3' => $mce_buttons_3,1817 'theme_advanced_buttons4' => $mce_buttons_4,1818 'language' => $mce_locale,1819 'spellchecker_languages' => $mce_spellchecker_languages,1820 'theme_advanced_toolbar_location' => 'top',1821 'theme_advanced_toolbar_align' => 'left',1822 'theme_advanced_statusbar_location' => 'bottom',1823 'theme_advanced_resizing' => true,1824 'theme_advanced_resize_horizontal' => false,1825 'dialog_type' => 'modal',1826 'formats' => "{1827 alignleft : [1828 {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'left'}},1829 {selector : 'img,table', classes : 'alignleft'}1830 ],1831 aligncenter : [1832 {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'center'}},1833 {selector : 'img,table', classes : 'aligncenter'}1834 ],1835 alignright : [1836 {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'right'}},1837 {selector : 'img,table', classes : 'alignright'}1838 ],1839 strikethrough : {inline : 'del'}1840 }",1841 'relative_urls' => false,1842 'remove_script_host' => false,1843 'convert_urls' => false,1844 'apply_source_formatting' => false,1845 'remove_linebreaks' => true,1846 'gecko_spellcheck' => true,1847 'entities' => '38,amp,60,lt,62,gt',1848 'accessibility_focus' => true,1849 'tabfocus_elements' => 'major-publishing-actions',1850 'media_strict' => false,1851 'paste_remove_styles' => true,1852 'paste_remove_spans' => true,1853 'paste_strip_class_attributes' => 'all',1854 'paste_text_use_dialog' => true,1855 'wpeditimage_disable_captions' => $no_captions,1856 'plugins' => implode( ',', $plugins ),1857 );1858 1859 if ( ! empty( $editor_styles ) && is_array( $editor_styles ) ) {1860 $mce_css = array();1861 $style_uri = get_stylesheet_directory_uri();1862 if ( ! is_child_theme() ) {1863 foreach ( $editor_styles as $file )1864 $mce_css[] = "$style_uri/$file";1865 } else {1866 $style_dir = get_stylesheet_directory();1867 $template_uri = get_template_directory_uri();1868 $template_dir = get_template_directory();1869 foreach ( $editor_styles as $file ) {1870 if ( file_exists( "$template_dir/$file" ) )1871 $mce_css[] = "$template_uri/$file";1872 if ( file_exists( "$style_dir/$file" ) )1873 $mce_css[] = "$style_uri/$file";1874 }1875 }1876 $mce_css = implode( ',', $mce_css );1877 } else {1878 $mce_css = '';1879 }1880 $mce_css = trim( apply_filters( 'mce_css', $mce_css ), ' ,' );1881 if ( ! empty($mce_css) )1882 $initArray['content_css'] = $mce_css;1883 if ( is_array($settings) )1884 $initArray = array_merge($initArray, $settings);1885 // For people who really REALLY know what they're doing with TinyMCE1886 // You can modify initArray to add, remove, change elements of the config before tinyMCE.init1887 // Setting "valid_elements", "invalid_elements" and "extended_valid_elements" can be done through "tiny_mce_before_init".1888 // Best is to use the default cleanup by not specifying valid_elements, as TinyMCE contains full set of XHTML 1.0.1889 if ( $teeny ) {1890 $initArray = apply_filters('teeny_mce_before_init', $initArray);1891 } else {1892 $initArray = apply_filters('tiny_mce_before_init', $initArray);1893 }1894 if ( empty($initArray['theme_advanced_buttons3']) && !empty($initArray['theme_advanced_buttons4']) ) {1895 $initArray['theme_advanced_buttons3'] = $initArray['theme_advanced_buttons4'];1896 $initArray['theme_advanced_buttons4'] = '';1897 }1898 if ( ! isset($concatenate_scripts) )1899 script_concat_settings();1900 $language = $initArray['language'];1901 $compressed = $compress_scripts && $concatenate_scripts && isset($_SERVER['HTTP_ACCEPT_ENCODING'])1902 && false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'gzip');1903 /**1904 * Deprecated1905 *1906 * The tiny_mce_version filter is not needed since external plugins are loaded directly by TinyMCE.1907 * These plugins can be refreshed by appending query string to the URL passed to mce_external_plugins filter.1908 * If the plugin has a popup dialog, a query string can be added to the button action that opens it (in the plugin's code).1909 */1910 $version = apply_filters('tiny_mce_version', '');1911 $version = 'ver=' . $tinymce_version . $version;1912 if ( 'en' != $language )1913 include_once(ABSPATH . WPINC . '/js/tinymce/langs/wp-langs.php');1914 1915 $mce_options = '';1916 foreach ( $initArray as $k => $v ) {1917 if ( is_bool($v) ) {1918 $val = $v ? 'true' : 'false';1919 $mce_options .= $k . ':' . $val . ', ';1920 continue;1921 } elseif ( !empty($v) && is_string($v) && ( '{' == $v{0} || '[' == $v{0} ) ) {1922 $mce_options .= $k . ':' . $v . ', ';1923 continue;1924 }1925 $mce_options .= $k . ':"' . $v . '", ';1926 }1927 1928 $mce_options = rtrim( trim($mce_options), '\n\r,' ); ?>1929 1930 <script type="text/javascript">1931 /* <![CDATA[ */1932 tinyMCEPreInit = {1933 base : "<?php echo $baseurl; ?>",1934 suffix : "",1935 query : "<?php echo $version; ?>",1936 mceInit : {<?php echo $mce_options; ?>},1937 load_ext : function(url,lang){var sl=tinymce.ScriptLoader;sl.markDone(url+'/langs/'+lang+'.js');sl.markDone(url+'/langs/'+lang+'_dlg.js');}1938 };1939 /* ]]> */1940 </script>1941 <?php1942 if ( $compressed )1943 echo "<script type='text/javascript' src='$baseurl/wp-tinymce.php?c=1&$version'></script>\n";1944 else1945 echo "<script type='text/javascript' src='$baseurl/tiny_mce.js?$version'></script>\n";1946 1947 if ( 'en' != $language && isset($lang) )1948 echo "<script type='text/javascript'>\n$lang\n</script>\n";1949 else1950 echo "<script type='text/javascript' src='$baseurl/langs/wp-langs-en.js?$version'></script>\n";1951 ?>1952 <script type="text/javascript">1953 /* <![CDATA[ */1954 <?php1955 if ( $ext_plugins )1956 echo "$ext_plugins\n";1957 1958 if ( ! $compressed ) {1959 ?>1960 (function(){var t=tinyMCEPreInit,sl=tinymce.ScriptLoader,ln=t.mceInit.language,th=t.mceInit.theme,pl=t.mceInit.plugins;sl.markDone(t.base+'/langs/'+ln+'.js');sl.markDone(t.base+'/themes/'+th+'/langs/'+ln+'.js');sl.markDone(t.base+'/themes/'+th+'/langs/'+ln+'_dlg.js');tinymce.each(pl.split(','),function(n){if(n&&n.charAt(0)!='-'){sl.markDone(t.base+'/plugins/'+n+'/langs/'+ln+'.js');sl.markDone(t.base+'/plugins/'+n+'/langs/'+ln+'_dlg.js');}});})();1961 <?php } ?>1962 tinyMCE.init(tinyMCEPreInit.mceInit);1963 /* ]]> */1964 </script>1965 <?php1966 1967 // Load additional inline scripts based on active plugins.1968 if ( in_array( 'wpdialogs', $plugins ) ) {1969 wp_print_scripts( array( 'wpdialogs-popup' ) );1970 wp_print_styles('wp-jquery-ui-dialog');1971 }1972 }1973 1974 function tiny_mce_preload_dialogs() { ?>1975 <div id="preloaded-dialogs" style="display:none;">1976 <?php do_action('tiny_mce_preload_dialogs'); ?>1977 </div>1978 <?php1979 }1980 }1981 1982 $wiki = new Wiki();
Note: See TracChangeset
for help on using the changeset viewer.