PageRenderTime 42ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/code/cake/app/webroot/cp/wp-content/plugins/commentpress-core/commentpress-core/class_commentpress_display.php

https://github.com/DigitalPaulScholtenProject/DPSP-Platform
PHP | 2978 lines | 1327 code | 941 blank | 710 comment | 121 complexity | 3f961c856fd86a3366da1ee811d9374f MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, AGPL-1.0, LGPL-2.1
  1. <?php /*
  2. ================================================================================
  3. Class CommentpressCoreDisplay
  4. ================================================================================
  5. AUTHOR: Christian Wach <needle@haystack.co.uk>
  6. --------------------------------------------------------------------------------
  7. NOTES
  8. =====
  9. --------------------------------------------------------------------------------
  10. */
  11. /*
  12. ================================================================================
  13. Class Name
  14. ================================================================================
  15. */
  16. class CommentpressCoreDisplay {
  17. /*
  18. ============================================================================
  19. Properties
  20. ============================================================================
  21. */
  22. // parent object reference
  23. var $parent_obj;
  24. // database object
  25. var $db;
  26. /**
  27. * @description: initialises this object
  28. * @param object $parent_obj a reference to the parent object
  29. * @return object
  30. * @todo:
  31. *
  32. */
  33. function __construct( $parent_obj ) {
  34. // store reference to parent
  35. $this->parent_obj = $parent_obj;
  36. // store reference to database wrapper (child of calling obj)
  37. $this->db = $this->parent_obj->db;
  38. // init
  39. $this->_init();
  40. // --<
  41. return $this;
  42. }
  43. /**
  44. * @description: PHP 4 constructor
  45. */
  46. function CommentpressCoreDisplay( $parent_obj ) {
  47. // is this php5?
  48. if ( version_compare( PHP_VERSION, "5.0.0", "<" ) ) {
  49. // call php5 constructor
  50. $this->__construct( $parent_obj );
  51. }
  52. // --<
  53. return $this;
  54. }
  55. /**
  56. * @description: if needed, sets up this object
  57. * @todo: work out how to upgrade.
  58. *
  59. */
  60. function activate() {
  61. // force WordPress to regenerate theme directories
  62. search_theme_directories( true );
  63. // get groupblog-set theme, if we have one
  64. $theme = $this->parent_obj->get_groupblog_theme();
  65. // did we get a CommentPress Core one?
  66. if ( $theme !== false ) {
  67. // we're in a groupblog context: BP Groupblog will already have set
  68. // the theme because we're adding our wpmu_new_blog action after it
  69. // --<
  70. return;
  71. }
  72. // test for WP3.4...
  73. if ( function_exists( 'wp_get_themes' ) ) {
  74. // get CommentPress Core theme by default, but allow overrides
  75. $target_theme = apply_filters(
  76. 'cp_forced_theme_slug',
  77. 'commentpress-theme'
  78. );
  79. // get the theme we want
  80. $theme = wp_get_theme(
  81. $target_theme
  82. );
  83. // if we get it...
  84. if ( $theme->exists() ) {
  85. // ignore if not allowed
  86. //if ( is_multisite() AND !$theme->is_allowed() ) { return; }
  87. // activate it
  88. switch_theme(
  89. $theme->get_template(),
  90. $theme->get_stylesheet()
  91. );
  92. }
  93. } else {
  94. // use pre-3.4 logic
  95. $themes = get_themes();
  96. //print_r( $themes ); die();
  97. // get CommentPress Core theme by default, but allow overrides
  98. // NB, the key prior to WP 3.4 is the theme's *name*
  99. $target_theme = apply_filters(
  100. 'cp_forced_theme_name',
  101. 'CommentPress Default Theme'
  102. );
  103. // the key is the theme name
  104. if ( isset( $themes[ $target_theme ] ) ) {
  105. // activate it
  106. switch_theme(
  107. $themes[ $target_theme ]['Template'],
  108. $themes[ $target_theme ]['Stylesheet']
  109. );
  110. }
  111. }
  112. }
  113. /**
  114. * @description: if needed, destroys this object
  115. * @todo:
  116. *
  117. */
  118. function deactivate() {
  119. // test for WP3.4...
  120. if ( function_exists( 'wp_get_theme' ) ) {
  121. // get CommentPress Core theme by default, but allow overrides
  122. $target_theme = apply_filters(
  123. 'cp_restore_theme_slug',
  124. WP_DEFAULT_THEME
  125. );
  126. // get the theme we want
  127. $theme = wp_get_theme(
  128. $target_theme
  129. );
  130. // if we get it...
  131. if ( $theme->exists() ) {
  132. // ignore if not allowed
  133. //if ( is_multisite() AND !$theme->is_allowed() ) { return; }
  134. // activate it
  135. switch_theme(
  136. $theme->get_template(),
  137. $theme->get_stylesheet()
  138. );
  139. }
  140. } else {
  141. // use pre-3.4 logic
  142. $themes = get_themes();
  143. //print_r( $themes ); die();
  144. // get default theme by default, but allow overrides
  145. // NB, the key prior to WP 3.4 is the theme's *name*
  146. $target_theme = apply_filters(
  147. 'cp_restore_theme_name',
  148. WP_DEFAULT_THEME
  149. );
  150. // the key is the theme name
  151. if ( isset( $themes[ $target_theme ] ) ) {
  152. // activate it
  153. switch_theme(
  154. $themes[ $target_theme ]['Template'],
  155. $themes[ $target_theme ]['Stylesheet']
  156. );
  157. }
  158. }
  159. }
  160. //##############################################################################
  161. /*
  162. ============================================================================
  163. PUBLIC METHODS
  164. ============================================================================
  165. */
  166. /**
  167. * @description: enqueue jQuery, jQuery UI and plugins
  168. * @todo:
  169. *
  170. */
  171. function get_jquery() {
  172. // default to minified scripts
  173. $debug_state = '';
  174. // target different scripts when debugging
  175. if ( defined( 'SCRIPT_DEBUG' ) AND SCRIPT_DEBUG === true ) {
  176. // use uncompressed scripts
  177. $debug_state = '.dev';
  178. }
  179. // add our javascript plugin and dependencies
  180. wp_enqueue_script(
  181. 'jquery_commentpress',
  182. plugins_url( 'commentpress-core/assets/js/jquery.commentpress'.$debug_state.'.js', COMMENTPRESS_PLUGIN_FILE ),
  183. array( 'jquery', 'jquery-form', 'jquery-ui-core', 'jquery-ui-resizable' ),
  184. COMMENTPRESS_VERSION // version
  185. );
  186. // add jQuery Scroll-To plugin
  187. wp_enqueue_script(
  188. 'jquery_scrollto',
  189. plugins_url( 'commentpress-core/assets/js/jquery.scrollTo.js', COMMENTPRESS_PLUGIN_FILE ),
  190. array( 'jquery_commentpress' ),
  191. COMMENTPRESS_VERSION // version
  192. );
  193. // add jQuery Cookie plugin (renamed to jquery.biscuit.js because some hosts don't like 'cookie' in the filename)
  194. wp_enqueue_script(
  195. 'jquery_cookie',
  196. plugins_url( 'commentpress-core/assets/js/jquery.biscuit.js', COMMENTPRESS_PLUGIN_FILE ),
  197. array( 'jquery_commentpress' ),
  198. COMMENTPRESS_VERSION // version
  199. );
  200. /*
  201. Prior to WP3.2 (IIRC), jQuery UI has to be added separately, as the built in one was not
  202. sufficiently up-to-date. This is no longer the case, so the independent jQuery UI package
  203. has been removed from CommentPress Core in favour of the built-in one.
  204. */
  205. }
  206. /**
  207. * @description: enqueue our quicktags script
  208. * @todo:
  209. *
  210. */
  211. function get_custom_quicktags() {
  212. // don't bother if the current user lacks permissions
  213. if ( ! current_user_can('edit_posts') AND ! current_user_can('edit_pages') ) {
  214. return;
  215. }
  216. // need access to WP version
  217. global $wp_version;
  218. // there's a new quicktags script in 3.3
  219. if ( version_compare( $wp_version, '3.2.99999', '>=' ) ) {
  220. // add our javascript script and dependencies
  221. wp_enqueue_script(
  222. 'commentpress_custom_quicktags',
  223. plugin_dir_url( COMMENTPRESS_PLUGIN_FILE ) . 'commentpress-core/assets/js/cp_quicktags_3.3.js',
  224. array( 'quicktags' ),
  225. COMMENTPRESS_VERSION, // version
  226. true // in footer
  227. );
  228. } else {
  229. // add our javascript script and dependencies
  230. wp_enqueue_script(
  231. 'commentpress_custom_quicktags',
  232. plugin_dir_url( COMMENTPRESS_PLUGIN_FILE ) . 'commentpress-core/assets/js/cp_quicktags.js',
  233. array( 'quicktags' ),
  234. COMMENTPRESS_VERSION, // version
  235. false // not in footer (but may need to be in WP 3.3)
  236. );
  237. }
  238. }
  239. /**
  240. * @description: get plugin stylesheets
  241. * @return string $styles
  242. * @todo:
  243. *
  244. */
  245. function get_frontend_styles() {
  246. // add jQuery UI stylesheet -> needed for resizable columns
  247. wp_enqueue_style(
  248. 'cp_jquery_ui_base',
  249. plugins_url( 'commentpress-core/assets/css/jquery.ui.css', COMMENTPRESS_PLUGIN_FILE ),
  250. false,
  251. COMMENTPRESS_VERSION, // version
  252. 'all' // media
  253. );
  254. }
  255. /**
  256. * @description: test if TinyMCE is allowed
  257. * @return boolean $allowed
  258. * @todo:
  259. *
  260. */
  261. function is_tinymce_allowed() {
  262. // check option
  263. if (
  264. $this->db->option_exists( 'cp_comment_editor' ) AND
  265. $this->db->option_get( 'cp_comment_editor' ) != '1'
  266. ) {
  267. // --<
  268. return false;
  269. }
  270. // don't return TinyMCE for touchscreens, mobile phones or tablets
  271. if ( $this->db->is_mobile_touch OR $this->db->is_mobile OR $this->db->is_tablet ) {
  272. // --<
  273. return false;
  274. }
  275. // --<
  276. return true;
  277. }
  278. /**
  279. * @description: get built-in TinyMCE scripts from Wordpress Includes directory
  280. * @return string $scripts
  281. * @todo:
  282. *
  283. */
  284. function get_tinymce() {
  285. // check if we can
  286. if ( !$this->is_tinymce_allowed() ) {
  287. // --<
  288. return;
  289. }
  290. // test for wp_editor()
  291. if ( function_exists( 'wp_editor' ) ) {
  292. // don't include anything - this will be done in the comment form template
  293. return;
  294. } else {
  295. // test for WordPress version
  296. global $wp_version;
  297. // for WP 3.2+
  298. if ( version_compare( $wp_version, '3.2', '>=' ) ) {
  299. // don't need settings
  300. $this->_get_tinymce();
  301. } else {
  302. // get site HTTP root
  303. $site_http_root = trailingslashit( get_bloginfo('wpurl') );
  304. // all TinyMCE scripts
  305. $scripts .= '<!-- TinyMCE -->
  306. <script type="text/javascript" src="'.$site_http_root.'wp-includes/js/tinymce/tiny_mce.js"></script>
  307. <script type="text/javascript" src="'.$site_http_root.'wp-includes/js/tinymce/langs/wp-langs-en.js?ver=20081129"></script>
  308. '."\n";
  309. // add our init
  310. $scripts .= $this->_get_tinymce_init();
  311. // out to browser
  312. echo $scripts;
  313. }
  314. }
  315. }
  316. /**
  317. * @description: get help text
  318. * @return HTML $help
  319. * @todo: translation
  320. *
  321. */
  322. function get_help() {
  323. $help = <<<HELPTEXT
  324. <p>For further information about using CommentPress, please refer to the <a href="http://www.futureofthebook.org/commentpress/support/">CommentPress support pages</a> or use one of the links below:</p>
  325. <ul>
  326. <li><a href="http://www.futureofthebook.org/commentpress/support/structuring-your-document/">Structuring your Document</a></li>
  327. <li><a href="http://www.futureofthebook.org/commentpress/support/formatting-your-document/">Formatting Your Document</a></li>
  328. <li><a href="http://www.futureofthebook.org/commentpress/support/using-commentpress/">How to read a CommentPress document</a></li>
  329. </ul>
  330. HELPTEXT;
  331. // --<
  332. return $help;
  333. }
  334. /**
  335. * @description: show the posts and their comment count in a list format
  336. * @todo:
  337. *
  338. */
  339. function list_posts( $params = 'numberposts=-1&order=DESC' ) {
  340. // get all posts
  341. $posts = get_posts( $params );
  342. // have we set the option?
  343. $list_style = $this->db->option_get( 'cp_show_extended_toc' );
  344. //print_r( $list_style ); die();
  345. // if not set or set to 'off'
  346. if ( $list_style === false OR $list_style == '0' ) {
  347. // --------------------------
  348. // old-style undecorated list
  349. // --------------------------
  350. // run through them...
  351. foreach( $posts AS $item ) {
  352. // get comment count for that post
  353. $count = count( $this->db->get_approved_comments( $item->ID ) );
  354. // write list item
  355. echo '<li class="title"><a href="'.get_permalink( $item->ID ).'">'.get_the_title( $item->ID ).' ('.$count.')</a></li>'."\n";
  356. }
  357. } else {
  358. // ------------------------
  359. // new-style decorated list
  360. // ------------------------
  361. // run through them...
  362. foreach( $posts AS $item ) {
  363. // init output
  364. $_html = '';
  365. //print_r( $item ); die();
  366. //setup_postdata( $item );
  367. // get comment count for that post
  368. $count = count( $this->db->get_approved_comments( $item->ID ) );
  369. // compat with Co-Authors Plus
  370. if ( function_exists( 'get_coauthors' ) ) {
  371. // get multiple authors
  372. $authors = get_coauthors( $item->ID );
  373. //print_r( $authors ); die();
  374. // if we get some
  375. if ( !empty( $authors ) ) {
  376. // use the Co-Authors format of "name, name, name & name"
  377. $author_html = '';
  378. // init counter
  379. $n = 1;
  380. // find out how many author we have
  381. $author_count = count( $authors );
  382. // loop
  383. foreach( $authors AS $author ) {
  384. // default to comma
  385. $sep = ', ';
  386. // if we're on the penultimate
  387. if ( $n == ($author_count - 1) ) {
  388. // use ampersand
  389. $sep = __( ' &amp; ', 'commentpress-core' );
  390. }
  391. // if we're on the last, don't add
  392. if ( $n == $author_count ) { $sep = ''; }
  393. // get name
  394. $author_html .= $this->echo_post_author( $author->ID, false );
  395. // and separator
  396. $author_html .= $sep;
  397. // increment
  398. $n++;
  399. // are we showing avatars?
  400. if ( get_option( 'show_avatars' ) ) {
  401. // get avatar
  402. $_html .= get_avatar( $author->ID, $size='32' );
  403. }
  404. }
  405. // add citation
  406. $_html .= '<cite class="fn">'.$author_html.'</cite>'."\n";
  407. // add permalink
  408. $_html .= '<p class="post_activity_date">'.get_the_time('l, F jS, Y', $item->ID).'</p>'."\n";
  409. }
  410. } else {
  411. // get avatar
  412. $author_id = $item->post_author;
  413. // are we showing avatars?
  414. if ( get_option( 'show_avatars' ) ) {
  415. $_html .= get_avatar( $author_id, $size='32' );
  416. }
  417. // add citation
  418. $_html .= '<cite class="fn">'.$this->echo_post_author( $author_id, false ).'</cite>';
  419. // add permalink
  420. $_html .= '<p class="post_activity_date">'.get_the_time('l, F jS, Y', $item->ID).'</p>';
  421. }
  422. // write list item
  423. echo '<li class="title">
  424. <div class="post-identifier">
  425. '.$_html.'
  426. </div>
  427. <a href="'.get_permalink( $item->ID ).'" class="post_activity_link">'.get_the_title( $item->ID ).' ('.$count.')</a>
  428. </li>'."\n";
  429. }
  430. }
  431. }
  432. /**
  433. * @description: show username (with link)
  434. * @todo: remove from theme functions.php?
  435. *
  436. */
  437. function echo_post_author( $author_id, $echo = true ) {
  438. // get author details
  439. $user = get_userdata( $author_id );
  440. // kick out if we don't have a user with that ID
  441. if ( !is_object( $user ) ) { return; }
  442. // access plugin
  443. global $commentpress_core, $post;
  444. // if we have the plugin enabled and it's BP
  445. if ( is_object( $post ) AND is_object( $commentpress_core ) AND $commentpress_core->is_buddypress() ) {
  446. // construct user link
  447. $author = bp_core_get_userlink( $user->ID );
  448. } else {
  449. // link to theme's author page
  450. $link = sprintf(
  451. '%1$s',
  452. esc_html( $user->display_name )
  453. );
  454. $author = apply_filters( 'the_author_posts_link', $link );
  455. }
  456. // if we're echoing
  457. if ( $echo ) {
  458. echo $author;
  459. } else {
  460. return $author;
  461. }
  462. }
  463. /**
  464. * @description: print the posts and their comment count in a list format
  465. * @todo:
  466. *
  467. */
  468. function list_pages() {
  469. /*
  470. Question: do we want to use WP menus? And if so, how?
  471. Currently, we're using wp_list_pages(), so let's try wp_page_menu() first
  472. // If we set the theme to use wp_nav_menu(), we need to register it
  473. register_nav_menu( 'primary', __( 'Primary Menu', 'commentpress-core' ) );
  474. Our navigation menu. If one isn't filled out, wp_nav_menu falls back to
  475. wp_page_menu. The menu assiged to the primary position is the one used. If
  476. none is assigned, the menu with the lowest ID is used.
  477. //wp_nav_menu( array( 'theme_location' => 'primary' ) );
  478. // set list pages defaults
  479. $args = array(
  480. 'sort_column' => 'menu_order, post_title',
  481. 'menu_class' => 'menu',
  482. 'include' => '',
  483. 'exclude' => '',
  484. 'echo' => true,
  485. 'show_home' => false,
  486. 'link_before' => '',
  487. 'link_after' => ''
  488. );
  489. */
  490. // test for custom menu
  491. if ( has_nav_menu( 'toc' ) ) {
  492. // try and use it
  493. wp_nav_menu( array(
  494. 'theme_location' => 'toc',
  495. 'echo' => true,
  496. 'container' => '',
  497. 'items_wrap' => '%3$s',
  498. ) );
  499. return;
  500. }
  501. // get welcome page ID
  502. $welcome_id = $this->db->option_get( 'cp_welcome_page' );
  503. // get front page
  504. $page_on_front = $this->db->option_wp_get( 'page_on_front' );
  505. // print link to title page, if we have one and it's the front page
  506. if ( $welcome_id !== false AND $page_on_front == $welcome_id ) {
  507. // define title page
  508. $title_page_title = get_the_title( $welcome_id );
  509. // allow overrides
  510. $title_page_title = apply_filters( 'cp_title_page_title', $title_page_title );
  511. // echo list item
  512. echo '<li class="page_item page-item-'.$welcome_id.'"><a href="'.get_permalink( $welcome_id ).'">'.$title_page_title.'</a></li>';
  513. }
  514. // get page display option
  515. //$depth = $this->db->option_get( 'cp_show_subpages' );
  516. // ALWAYS write subpages into page, even if they aren't displayed
  517. $depth = 0;
  518. // get pages to exclude
  519. $exclude = $this->db->option_get( 'cp_special_pages' );
  520. // do we have any?
  521. if ( !$exclude ) { $exclude = array(); }
  522. // exclude title page, if we have one
  523. if ( $welcome_id !== false ) { $exclude[] = $welcome_id; }
  524. // set list pages defaults
  525. $defaults = array(
  526. 'depth' => $depth,
  527. 'show_date' => '',
  528. 'date_format' => $this->db->option_get( 'date_format' ),
  529. 'child_of' => 0,
  530. 'exclude' => implode( ',', $exclude ),
  531. 'title_li' => '',
  532. 'echo' => 1,
  533. 'authors' => '',
  534. 'sort_column' => 'menu_order, post_title',
  535. 'link_before' => '',
  536. 'link_after' => '',
  537. 'exclude_tree' => ''
  538. );
  539. // use Wordpress function to echo
  540. wp_list_pages( $defaults );
  541. /*
  542. // The following code manually lists pages, but adds the comment count to the name
  543. // init params
  544. $params = 'sort_column=menu_order';
  545. // exclude the special pages
  546. $params .= '&exclude='.implode( ',', $special );
  547. //echo $params; exit();
  548. // get all pages
  549. $_pages = get_pages( $params );
  550. // run through them...
  551. foreach( $_pages AS $_page ) {
  552. // get comment count for that page
  553. $count = count( $this->db->get_approved_comments( $_page->ID ) );
  554. // write list item
  555. echo '<li class="title"><a href="'.get_page_link( $_page->ID ).'">'.$_page->post_title.' ('.$count.')</a></li>'."\n";
  556. }
  557. */
  558. }
  559. /**
  560. * @description: get the block comment icon
  561. * @param integer $comment_count number of comments
  562. * @param string $text_signature comment text signature
  563. * @param string $block_type either 'auto', 'line' or 'block'
  564. * @param integer $para_num sequnetial commentable block number
  565. * @return string $comment_icon
  566. * @todo:
  567. *
  568. */
  569. function get_comment_icon(
  570. $comment_count,
  571. $text_signature,
  572. $block_type = 'auto',
  573. $para_num = 1
  574. ) { // -->
  575. // reset icon
  576. $icon = null;
  577. // if we have no comments...
  578. if( $comment_count == 0 ) {
  579. // show add comment icon
  580. $icon = 'comment_add.png';
  581. $class = ' no_comments';
  582. } elseif( $comment_count > 0 ) {
  583. // show comments present icon
  584. $icon = 'comment.png';
  585. $class = ' has_comments';
  586. }
  587. // define block title by block type
  588. switch ( $block_type ) {
  589. // ----------------------------
  590. // auto-formatted
  591. // ----------------------------
  592. case 'auto':
  593. default:
  594. // define title text
  595. $title_text = sprintf( _n(
  596. // singular
  597. 'There is %d comment written for this paragraph',
  598. // plural
  599. 'There are %d comments written for this paragraph',
  600. // number
  601. $comment_count,
  602. // domain
  603. 'commentpress-core'
  604. // substitution
  605. ), $comment_count );
  606. // define add comment text
  607. $add_text = sprintf( _n(
  608. // singular
  609. 'Leave a comment on paragraph %d',
  610. // plural
  611. 'Leave a comment on paragraph %d',
  612. // number
  613. $para_num,
  614. // domain
  615. 'commentpress-core'
  616. // substitution
  617. ), $para_num );
  618. break;
  619. // ----------------------------
  620. // line-by-line, eg poetry
  621. // ----------------------------
  622. case 'line':
  623. // define title text
  624. $title_text = sprintf( _n(
  625. // singular
  626. 'There is %d comment written for this line',
  627. // plural
  628. 'There are %d comments written for this line',
  629. // number
  630. $comment_count,
  631. // domain
  632. 'commentpress-core'
  633. // substitution
  634. ), $comment_count );
  635. // define add comment text
  636. $add_text = sprintf( _n(
  637. // singular
  638. 'Leave a comment on line %d',
  639. // plural
  640. 'Leave a comment on line %d',
  641. // number
  642. $para_num,
  643. // domain
  644. 'commentpress-core'
  645. // substitution
  646. ), $para_num );
  647. break;
  648. // ----------------------------
  649. // comment-blocks
  650. // ----------------------------
  651. case 'block':
  652. // define title text
  653. $title_text = sprintf( _n(
  654. // singular
  655. 'There is %d comment written for this block',
  656. // plural
  657. 'There are %d comments written for this block',
  658. // number
  659. $comment_count,
  660. // domain
  661. 'commentpress-core'
  662. // substitution
  663. ), $comment_count );
  664. // define add comment text
  665. $add_text = sprintf( _n(
  666. // singular
  667. 'Leave a comment on block %d',
  668. // plural
  669. 'Leave a comment on block %d',
  670. // number
  671. $para_num,
  672. // domain
  673. 'commentpress-core'
  674. // substitution
  675. ), $para_num );
  676. break;
  677. }
  678. // define small
  679. $small = '<small class="comment_count" title="'.$title_text.'">'.(string) $comment_count.'</small>';
  680. // define HTML for comment icon
  681. $comment_icon = '<span class="commenticonbox"><a class="para_permalink'.$class.'" href="#'.$text_signature.'" title="'.$add_text.'">'.$add_text.'</a> '.$small.'</span>'."\n";
  682. // --<
  683. return $comment_icon;
  684. }
  685. /**
  686. * @description: get the block paragraph icon
  687. * @param integer $comment_count number of comments
  688. * @param string $text_signature comment text signature
  689. * @param string $block_type either 'auto', 'line' or 'block'
  690. * @param integer $para_num sequnetial commentable block number
  691. * @return string $comment_icon
  692. * @todo:
  693. *
  694. */
  695. function get_paragraph_icon(
  696. $comment_count,
  697. $text_signature,
  698. $block_type = 'auto',
  699. $para_num = 1
  700. ) { // -->
  701. // define block title by block type
  702. switch ( $block_type ) {
  703. // ----------------------------
  704. // auto-formatted
  705. // ----------------------------
  706. case 'auto':
  707. default:
  708. // define permalink text
  709. $permalink_text = sprintf( _n(
  710. // singular
  711. 'Permalink for paragraph %d',
  712. // plural
  713. 'Permalink for paragraph %d',
  714. // number
  715. $para_num,
  716. // domain
  717. 'commentpress-core'
  718. // substitution
  719. ), $para_num );
  720. // define paragraph marker
  721. //$para_marker = '<span class="para_marker"><a id="'.$text_signature.'" href="#'.$text_signature.'" title="'.$permalink_text.'">&para; <span>'.(string) $para_num.'</span></a></span>';
  722. $para_marker = '<span class="para_marker"><a id="'.$text_signature.'" href="#'.$text_signature.'" title="'.$permalink_text.'"><span>'.(string) $para_num.'</span></a></span>';//JVDP
  723. break;
  724. // ----------------------------
  725. // line-by-line, eg poetry
  726. // ----------------------------
  727. case 'line':
  728. // define permalink text
  729. $permalink_text = sprintf( _n(
  730. // singular
  731. 'Permalink for line %d',
  732. // plural
  733. 'Permalink for line %d',
  734. // number
  735. $para_num,
  736. // domain
  737. 'commentpress-core'
  738. // substitution
  739. ), $para_num );
  740. // define paragraph marker
  741. $para_marker = '<span class="para_marker"><a id="'.$text_signature.'" href="#'.$text_signature.'" title="'.$permalink_text.'">&para; <span>'.(string) $para_num.'</span></a></span>';
  742. break;
  743. // ----------------------------
  744. // comment-blocks
  745. // ----------------------------
  746. case 'block':
  747. // define permalink text
  748. $permalink_text = sprintf( _n(
  749. // singular
  750. 'Permalink for block %d',
  751. // plural
  752. 'Permalink for block %d',
  753. // number
  754. $para_num,
  755. // domain
  756. 'commentpress-core'
  757. // substitution
  758. ), $para_num );
  759. // define paragraph marker
  760. $para_marker = '<span class="para_marker"><a id="'.$text_signature.'" href="#'.$text_signature.'" title="'.$permalink_text.'">&para; <span>'.(string) $para_num.'</span></a></span>';
  761. break;
  762. }
  763. // define HTML for paragraph icon
  764. $paragraph_icon = $para_marker."\n";
  765. // --<
  766. return $paragraph_icon;
  767. }
  768. /**
  769. * @description: get the content comment icon tag
  770. * @param string $text_signature comment text signature
  771. * @return string $para_tag
  772. * @todo:
  773. *
  774. */
  775. function get_para_tag( $text_signature, $commenticon, $tag = 'p' ) {
  776. // return different stuff for different tags
  777. switch( $tag ) {
  778. case 'ul':
  779. // define list tag
  780. $para_tag = '<'.$tag.' class="textblock" id="textblock-'.$text_signature.'">'.
  781. '<li class="list_commenticon">'.$commenticon.'</li>';
  782. break;
  783. case 'ol':
  784. // define list tag
  785. $para_tag = '<'.$tag.' class="textblock" id="textblock-'.$text_signature.'" start="0">'.
  786. '<li class="list_commenticon">'.$commenticon.'</li>';
  787. break;
  788. // compat with WP Footnotes
  789. case 'ol class="footnotes"':
  790. // define list tag
  791. $para_tag = '<ol class="footnotes textblock" id="textblock-'.$text_signature.'" start="0">'.
  792. '<li class="list_commenticon">'.$commenticon.'</li>';
  793. break;
  794. case 'p':
  795. case 'p style="text-align:left"':
  796. case 'p style="text-align:left;"':
  797. case 'p style="text-align: left"':
  798. case 'p style="text-align: left;"':
  799. // define para tag
  800. $para_tag = '<'.$tag.' class="textblock" id="textblock-'.$text_signature.'">'.$commenticon;
  801. break;
  802. case 'p style="text-align:right"':
  803. case 'p style="text-align:right;"':
  804. case 'p style="text-align: right"':
  805. case 'p style="text-align: right;"':
  806. // define para tag
  807. $para_tag = '<'.$tag.' class="textblock textblock-right" id="textblock-'.$text_signature.'">'.$commenticon;
  808. break;
  809. case 'p style="text-align:center"':
  810. case 'p style="text-align:center;"':
  811. case 'p style="text-align: center"':
  812. case 'p style="text-align: center;"':
  813. // define para tag
  814. $para_tag = '<'.$tag.' class="textblock textblock-center" id="textblock-'.$text_signature.'">'.$commenticon;
  815. break;
  816. case 'p style="text-align:justify"':
  817. case 'p style="text-align:justify;"':
  818. case 'p style="text-align: justify"':
  819. case 'p style="text-align: justify;"':
  820. // define para tag
  821. $para_tag = '<'.$tag.' class="textblock textblock-justify" id="textblock-'.$text_signature.'">'.$commenticon;
  822. break;
  823. case 'p class="notes"':
  824. // define para tag
  825. $para_tag = '<p class="notes textblock" id="textblock-'.$text_signature.'">'.$commenticon;
  826. break;
  827. case 'div':
  828. // define opening tag (we'll close it later)
  829. $para_tag = '<div class="textblock" id="textblock-'.$text_signature.'">'.$commenticon;
  830. break;
  831. case 'span':
  832. // define opening tag (we'll close it later)
  833. $para_tag = '<span class="textblock" id="textblock-'.$text_signature.'">'.$commenticon;
  834. break;
  835. }
  836. /*
  837. print_r( array(
  838. 't' => $text_signature,
  839. 'p' => $para_tag
  840. ) );
  841. */
  842. // --<
  843. return $para_tag;
  844. }
  845. /**
  846. * @description: get the text signature input for the comment form
  847. * @param string $text_sig comment text signature
  848. * @return string $input
  849. * @todo:
  850. *
  851. */
  852. function get_signature_input( $text_sig = '' ) {
  853. // define input tag
  854. $input = '<input type="hidden" name="text_signature" value="'.$text_sig.'" id="text_signature" />';
  855. // --<
  856. return $input;
  857. }
  858. /**
  859. * @description: get the minimise all button
  860. * @param: string $sidebar type of sidebar (comments, toc, activity)
  861. * @return string $tag
  862. * @todo:
  863. *
  864. */
  865. function get_minimise_all_button( $sidebar = 'comments' ) {
  866. switch( $sidebar ) {
  867. case 'comments':
  868. // define minimise button
  869. $tag = '<span id="cp_minimise_all_comments" title="'.__( 'Minimise all Comment Sections', 'commentpress-core' ).'"></span>';
  870. break;
  871. case 'activity':
  872. // define minimise button
  873. $tag = '<span id="cp_minimise_all_activity" title="'.__( 'Minimise all Activity Sections', 'commentpress-core' ).'"></span>';
  874. break;
  875. case 'toc':
  876. // define minimise button
  877. $tag = '<span id="cp_minimise_all_contents" title="'.__( 'Minimise all Contents Sections', 'commentpress-core' ).'"></span>';
  878. break;
  879. }
  880. // --<
  881. return $tag;
  882. }
  883. /**
  884. * @description: get the header minimise button
  885. * @return string $tag
  886. * @todo:
  887. *
  888. */
  889. function get_header_min_link() {
  890. // define minimise button
  891. $link = '<li><a href="#" id="btn_header_min" class="css_btn" title="'.__( 'Minimise Header', 'commentpress-core' ).'">'.__( 'Minimise Header', 'commentpress-core' ).'</a></li>'."\n";
  892. // --<
  893. return $link;
  894. }
  895. /**
  896. * @description: get an image wrapped in a link
  897. * @param: string $src location of image file
  898. * @param: string $url link target
  899. * @return string $tag
  900. * @todo:
  901. *
  902. */
  903. function get_linked_image( $src = '', $url = '' ) {
  904. // init html
  905. $html = '';
  906. // do we have an image?
  907. if ( $src != '' ) {
  908. // construct link
  909. $html .= '<img src="'.$src.'" />';
  910. }
  911. // do we have one?
  912. if ( $url != '' ) {
  913. // construct link around image
  914. $html .= '<a href="'.$url.'">'.$html.'</a>';
  915. }
  916. // --<
  917. return $html;
  918. }
  919. /**
  920. * @description: got the Wordpress admin page
  921. * @return string $admin_page
  922. * @todo:
  923. *
  924. */
  925. function get_admin_page() {
  926. // init
  927. $admin_page = '';
  928. // open div
  929. $admin_page .= '<div class="wrap" id="commentpress_admin_wrapper">'."\n\n";
  930. // get our form
  931. $admin_page .= $this->_get_admin_form();
  932. // close div
  933. $admin_page .= '</div>'."\n\n";
  934. // --<
  935. return $admin_page;
  936. }
  937. //##############################################################################
  938. /*
  939. ============================================================================
  940. PRIVATE METHODS
  941. ============================================================================
  942. */
  943. /*
  944. ----------------------------------------------------------------------------
  945. Object Initialisation
  946. ----------------------------------------------------------------------------
  947. */
  948. /**
  949. * @description: object initialisation
  950. * @todo:
  951. *
  952. */
  953. function _init() {
  954. // moved mobile checks to class_commentpress_db.php so it only loads as needed
  955. // and so that it loads *after* the old Commentpress loads it
  956. }
  957. /**
  958. * @description: returns the admin form HTML
  959. * @return string $admin_page
  960. * @todo: translation
  961. *
  962. */
  963. function _get_admin_form() {
  964. // sanitise admin page url
  965. $url = $_SERVER['REQUEST_URI'];
  966. $url_array = explode( '&', $url );
  967. if ( $url_array ) { $url = $url_array[0]; }
  968. // if we need to upgrade...
  969. if ( $this->db->check_upgrade() ) {
  970. // get upgrade options
  971. $upgrade = $this->_get_upgrade();
  972. // init text
  973. $options_text = '';
  974. // if there are options
  975. if ( $upgrade != '' ) {
  976. $options_text = __( ' The following options have become available in the new version.', 'commentpress-core' );
  977. }
  978. // define admin page
  979. $admin_page = '
  980. <div class="icon32" id="icon-options-general"><br/></div>
  981. <h2>'.__( 'CommentPress Core Upgrade', 'commentpress-core' ).'</h2>
  982. <form method="post" action="'.htmlentities($url.'&updated=true').'">
  983. '.wp_nonce_field( 'commentpress_admin_action', 'commentpress_nonce', true, false ).'
  984. '.wp_referer_field( false ).'
  985. <input id="cp_upgrade" name="cp_upgrade" value="1" type="hidden" />
  986. <h3>'.__( 'Please upgrade CommentPress Core', 'commentpress-core' ).'</h3>
  987. <p>'.__( 'It looks like you are running an older version of CommentPress Core.', 'commentpress-core' ).$options_text.'</p>
  988. <table class="form-table">
  989. '.$upgrade.'
  990. </table>
  991. '.
  992. '<input type="hidden" name="action" value="update" />
  993. <p class="submit">
  994. <input type="submit" name="commentpress_submit" value="'.__( 'Upgrade', 'commentpress-core' ).'" class="button-primary" />
  995. </p>
  996. </form>'."\n\n\n\n";
  997. } else {
  998. // define admin page
  999. $admin_page = '
  1000. <div class="icon32" id="icon-options-general"><br/></div>
  1001. <h2>'.__( 'CommentPress Core Settings', 'commentpress-core' ).'</h2>
  1002. <form method="post" action="'.htmlentities($url.'&updated=true').'">
  1003. '.wp_nonce_field( 'commentpress_admin_action', 'commentpress_nonce', true, false ).'
  1004. '.wp_referer_field( false ).'
  1005. '.
  1006. $this->_get_options().
  1007. '<input type="hidden" name="action" value="update" />
  1008. '.$this->_get_submit().'
  1009. </form>'."\n\n\n\n";
  1010. }
  1011. // --<
  1012. return $admin_page;
  1013. }
  1014. /**
  1015. * @description: returns the CommentPress Core options for the admin form
  1016. * @return string $options
  1017. * @todo:
  1018. *
  1019. */
  1020. function _get_options() {
  1021. // define CommentPress Core theme options
  1022. $options = '
  1023. <h3>'.__( 'Options for CommentPress Core', 'commentpress-core' ).'</h3>
  1024. <p>'.__( 'When the CommentPress Default Theme (or a valid CommentPress Child Theme) is active, the following options modify its behaviour.', 'commentpress-core' ).'</p>
  1025. <h4>'.__( 'Global Options', 'commentpress-core' ).'</h4>
  1026. <table class="form-table">
  1027. '.$this->_get_deactivate().'
  1028. '.$this->_get_reset().'
  1029. '.$this->_get_optional_options().'
  1030. </table>
  1031. <h4>'.__( 'Table of Contents', 'commentpress-core' ).'</h4>
  1032. <p>'.__( 'Choose how you want your Table of Contents to appear and function.<br />
  1033. <strong style="color: red;">NOTE!</strong> When Chapters are Pages, the TOC will always show Sub-Pages, since collapsing the TOC makes no sense in that situation.', 'commentpress-core' ).'</p>
  1034. <table class="form-table">
  1035. '.$this->_get_toc().'
  1036. </table>
  1037. <h4>'.__( 'Page Display Options', 'commentpress-core' ).'</h4>
  1038. <table class="form-table">
  1039. <tr valign="top">
  1040. <th scope="row"><label for="cp_title_visibility">'.__( 'Default page title visibility (can be overridden on individual pages)', 'commentpress-core' ).'</label></th>
  1041. <td><select id="cp_title_visibility" name="cp_title_visibility">
  1042. <option value="show" '.(($this->db->option_get('cp_title_visibility') == 'show') ? ' selected="selected"' : '').'>'.__( 'Show page titles', 'commentpress-core' ).'</option>
  1043. <option value="hide" '.(($this->db->option_get('cp_title_visibility') == 'hide') ? ' selected="selected"' : '').'>'.__( 'Hide page titles', 'commentpress-core' ).'</option>
  1044. </select>
  1045. </td>
  1046. </tr>
  1047. <tr valign="top">
  1048. <th scope="row"><label for="cp_page_meta_visibility">'.__( 'Default page meta visibility (can be overridden on individual pages)', 'commentpress-core' ).'</label></th>
  1049. <td><select id="cp_page_meta_visibility" name="cp_page_meta_visibility">
  1050. <option value="show" '.(($this->db->option_get('cp_page_meta_visibility') == 'show') ? ' selected="selected"' : '').'>'.__( 'Show page meta', 'commentpress-core' ).'</option>
  1051. <option value="hide" '.(($this->db->option_get('cp_page_meta_visibility') == 'hide') ? ' selected="selected"' : '').'>'.__( 'Hide page meta', 'commentpress-core' ).'</option>
  1052. </select>
  1053. </td>
  1054. </tr>
  1055. <tr valign="top">
  1056. <th scope="row"><label for="cp_excerpt_length">'.__( 'Blog excerpt length', 'commentpress-core' ).'</label></th>
  1057. <td><input type="text" id="cp_excerpt_length" name="cp_excerpt_length" value="'.$this->db->option_get('cp_excerpt_length').'" class="small-text" /> '.__( 'words', 'commentpress-core' ).'</td>
  1058. </tr>
  1059. </table>
  1060. <h4>'.__( 'Commenting Options', 'commentpress-core' ).'</h4>
  1061. <table class="form-table">
  1062. '.$this->_get_editor().'
  1063. '.$this->_get_override().'
  1064. </table>
  1065. <h4>'.__( 'Theme Customisation', 'commentpress-core' ).'</h4>
  1066. <p>'.__( 'You can set a custom background colour in <em>Appearance &#8594; Background</em>.<br />
  1067. You can also set a custom header image and header text colour in <em>Appearance &#8594; Header</em>.<br />
  1068. Below are extra options for changing how the theme looks.', 'commentpress-core' ).'</p>
  1069. <table class="form-table">
  1070. <tr valign="top" id="cp_header_bg_colour-row">
  1071. <th scope="row"><label for="cp_header_bg_colour">'.__( 'Header Background Colour', 'commentpress-core' ).'</label></th>
  1072. <td><input type="text" name="cp_header_bg_colour" id="cp_header_bg_colour" value="'.$this->db->option_get('cp_header_bg_colour').'" /><span class="description hide-if-js">'.__( 'If you want to hide header text, add <strong>#blank</strong> as text colour.', 'commentpress-core' ).'</span><input type="button" class="button hide-if-no-js" value="'.__( 'Select a Colour', 'commentpress-core' ).'" id="pickcolor" /><div id="color-picker" style="z-index: 100; background:#eee; border:1px solid #ccc; position:absolute; display:none;"></div></td>
  1073. </tr>
  1074. <tr valign="top">
  1075. <th scope="row"><label for="cp_js_scroll_speed">'.__( 'Scroll speed', 'commentpress-core' ).'</label></th>
  1076. <td><input type="text" id="cp_js_scroll_speed" name="cp_js_scroll_speed" value="'.$this->db->option_get('cp_js_scroll_speed').'" class="small-text" /> '.__( 'milliseconds', 'commentpress-core' ).'</td>
  1077. </tr>
  1078. <tr valign="top">
  1079. <th scope="row"><label for="cp_min_page_width">'.__( 'Minimum page width', 'commentpress-core' ).'</label></th>
  1080. <td><input type="text" id="cp_min_page_width" name="cp_min_page_width" value="'.$this->db->option_get('cp_min_page_width').'" class="small-text" /> '.__( 'pixels', 'commentpress-core' ).'</td>
  1081. </tr>
  1082. '.$this->_get_sidebar().'
  1083. </table>
  1084. ';
  1085. // --<
  1086. return $options;
  1087. }
  1088. /**
  1089. * @description: returns optional options, if defined
  1090. * @return string $html
  1091. * @todo:
  1092. *
  1093. */
  1094. function _get_optional_options() {
  1095. // init
  1096. $html = '';
  1097. // do we have the option to choose blog type (new in 3.3.1)?
  1098. if ( $this->db->option_exists( 'cp_blog_type' ) ) {
  1099. // define no types
  1100. $types = array();
  1101. // allow overrides
  1102. $types = apply_filters( 'cp_blog_type_options', $types );
  1103. // if we get some from a plugin, say...
  1104. if ( !empty( $types ) ) {
  1105. // define title
  1106. $type_title = __( 'Default Text Format', 'commentpress-core' );
  1107. // allow overrides
  1108. $type_title = apply_filters( 'cp_blog_type_label', $type_title );
  1109. // add extra message
  1110. $type_title .= __( ' (can be overridden on individual pages)', 'commentpress-core' );
  1111. // construct options
  1112. $type_option_list = array();
  1113. $n = 0;
  1114. // get existing
  1115. $blog_type = $this->db->option_get( 'cp_blog_type' );
  1116. foreach( $types AS $type ) {
  1117. if ( $n == $blog_type ) {
  1118. $type_option_list[] = '<option value="'.$n.'" selected="selected">'.$type.'</option>';
  1119. } else {
  1120. $type_option_list[] = '<option value="'.$n.'">'.$type.'</option>';
  1121. }
  1122. $n++;
  1123. }
  1124. $type_options = implode( "\n", $type_option_list );
  1125. // define upgrade
  1126. $html .= '
  1127. <tr valign="top">
  1128. <th scope="row"><label for="cp_blog_type">'.$type_title.'</label></th>
  1129. <td><select id="cp_blog_type" name="cp_blog_type">
  1130. '.$type_options.'
  1131. </select>
  1132. </td>
  1133. </tr>
  1134. ';
  1135. }
  1136. }
  1137. // do we have the option to choose blog workflow (new in 3.3.1)?
  1138. if ( $this->db->option_exists( 'cp_blog_workflow' ) ) {
  1139. // off by default
  1140. $has_workflow = false;
  1141. // allow overrides
  1142. $has_workflow = apply_filters( 'cp_blog_workflow_exists', $has_workflow );
  1143. // if we have workflow enabled, by a plugin, say...
  1144. if ( $has_workflow !== false ) {
  1145. // define label
  1146. $workflow_label = __( 'Enable Custom Workflow', 'commentpress-core' );
  1147. // define label
  1148. $workflow_label = apply_filters( 'cp_blog_workflow_label', $workflow_label );
  1149. // add extra message
  1150. $workflow_label .= ' (Not recommended because it is still very experimental)';
  1151. // define upgrade
  1152. $html .= '
  1153. <tr valign="top">
  1154. <th scope="row"><label for="cp_blog_workflow">'.$workflow_label.'</label></th>
  1155. <td><input id="cp_blog_workflow" name="cp_blog_workflow" value="1" type="checkbox" '.( $this->db->option_get('cp_blog_workflow') ? ' checked="checked"' : '' ).' /></td>
  1156. </tr>
  1157. ';
  1158. }
  1159. }
  1160. // --<
  1161. return $html;
  1162. }
  1163. /**
  1164. * @description: returns the upgrade details for the admin form
  1165. * @return string $upgrade
  1166. * @todo:
  1167. *
  1168. */
  1169. function _get_upgrade() {
  1170. // init
  1171. $upgrade = '';
  1172. // do we have the option to choose the default sidebar (new in 3.3.3)?
  1173. if ( !$this->db->option_exists( 'cp_sidebar_default' ) ) {
  1174. // define labels
  1175. $label = __( 'Which sidebar do you want to be active by default? (can be overridden on individual pages)', 'commentpress-core' );
  1176. $contents_label = __( 'Contents', 'commentpress-core' );
  1177. $activity_label = __( 'Activity', 'commentpress-core' );
  1178. $comments_label = __( 'Comments', 'commentpress-core' );
  1179. // define upgrade
  1180. $upgrade .= '
  1181. <tr valign="top">
  1182. <th scope="row"><label for="cp_sidebar_default">'.$label.'</label></th>
  1183. <td><select id="cp_sidebar_default" name="cp_sidebar_default">
  1184. <option value="toc">'.$contents_label.'</option>
  1185. <option value="activity">'.$activity_label.'</option>
  1186. <option value="comments" selected="selected">'.$comments_label.'</option>
  1187. </select>
  1188. </td>
  1189. </tr>
  1190. ';
  1191. }
  1192. // do we have the option to show or hide page meta (new in 3.3.2)?
  1193. if ( !$this->db->option_exists( 'cp_page_meta_visibility' ) ) {
  1194. $meta_label = __( 'Show or hide page meta by default', 'commentpress-core' );
  1195. $meta_show_label = __( 'Show page meta', 'commentpress-core' );
  1196. $meta_hide_label = __( 'Hide page meta', 'commentpress-core' );
  1197. // define upgrade
  1198. $upgrade .= '
  1199. <tr valign="top">
  1200. <th scope="row"><label for="cp_page_meta_visibility">'.$meta_label.'</label></th>
  1201. <td><select id="cp_page_meta_visibility" name="cp_page_meta_visibility">
  1202. <option value="show">'.$meta_show_label.'</option>
  1203. <option value="hide" selected="selected">'.$meta_hide_label.'</option>
  1204. </select>
  1205. </td>
  1206. </tr>
  1207. ';
  1208. }
  1209. // do we have the option to choose blog type (new in 3.3.1)?
  1210. if ( !$this->db->option_exists( 'cp_blog_type' ) ) {
  1211. // define no types
  1212. $types = array();
  1213. // allow overrides
  1214. $types = apply_filters( 'cp_blog_type_options', $types );
  1215. // if we get some from a plugin, say...
  1216. if ( !empty( $types ) ) {
  1217. // define title
  1218. $type_title = __( 'Blog Type', 'commentpress-core' );
  1219. // allow overrides
  1220. $type_title = apply_filters( 'cp_blog_type_label', $type_title );
  1221. // construct options
  1222. $type_option_list = array();
  1223. $n = 0;
  1224. foreach( $types AS $type ) {
  1225. $type_option_list[] = '<option value="'.$n.'">'.$type.'</option>';
  1226. $n++;
  1227. }
  1228. $type_options = implode( "\n", $type_option_list );
  1229. // define upgrade
  1230. $upgrade .= '
  1231. <tr valign="top">
  1232. <th scope="row"><label for="cp_blog_type">'.$type_title.'</label></th>
  1233. <td><select id="cp_blog_type" name="cp_blog_type">
  1234. '.$type_options.'
  1235. </select>
  1236. </td>
  1237. </tr>
  1238. ';
  1239. }
  1240. }
  1241. // do we have the option to choose blog workflow (new in 3.3.1)?
  1242. if ( !$this->db->option_exists( 'cp_blog_workflow' ) ) {
  1243. // off by default
  1244. $has_workflow = false;
  1245. // allow overrides
  1246. $has_workflow = apply_filters( 'cp_blog_workflow_exists', $has_workflow );
  1247. // if we have workflow enabled, by a plugin, say...
  1248. if ( $has_workflow !== false ) {
  1249. // define label
  1250. $workflow_label = __( 'Enable Custom Workflow', 'commentpress-core' );
  1251. // define label
  1252. $workflow_label = apply_filters( 'cp_blog_workflow_label', $workflow_label );
  1253. // define upgrade
  1254. $upgrade .= '
  1255. <tr valign="top">
  1256. <th scope="row"><label for="cp_blog_workflow">'.$workflow_label.'</label></th>
  1257. <td><input id="cp_reset" name="cp_blog_workflow" value="1" type="checkbox" /></td>
  1258. </tr>
  1259. ';
  1260. }
  1261. }
  1262. // do we have the option to choose the TOC layout (new in 3.3)?
  1263. if ( !$this->db->option_exists( 'cp_show_extended_toc' ) ) {
  1264. $extended_label = __( 'Appearance of TOC for posts', 'commentpress-core' );
  1265. $extended_info_label = __( 'Extended information', 'commentpress-core' );
  1266. $extended_title_label = __( 'Just the title', 'commentpress-core' );
  1267. // define upgrade
  1268. $upgrade .= '
  1269. <tr valign="top">
  1270. <th scope="row"><label for="cp_show_extended_toc">'.$extended_label.'</label></th>
  1271. <td><select id="cp_show_extended_toc" name="cp_show_extended_toc">
  1272. <option value="1">'.$extended_info_label.'</option>
  1273. <option value="0" selected="selected">'.$extended_title_label.'</option>
  1274. </select>
  1275. </td>
  1276. </tr>
  1277. ';
  1278. }
  1279. // do we have the option to set the comment editor?
  1280. if ( !$this->db->option_exists( 'cp_comment_editor' ) ) {
  1281. $editor_label = __( 'Comment form editor', 'commentpress-core' );
  1282. $rich_label = __( 'Rich-text Editor', 'commentpress-core' );
  1283. $plain_label = __( 'Plain-text Editor', 'commentpress-core' );
  1284. // define upgrade
  1285. $upgrade .= '
  1286. <tr valign="top">
  1287. <th scope="row"><label for="cp_comment_editor">'.$editor_label.'</label></th>
  1288. <td><select id="cp_comment_editor" name="cp_comment_editor">
  1289. <option value="1" selected="selected">'.$rich_label.'</option>
  1290. <option value="0">'.$plain_label.'</option>
  1291. </select>
  1292. </td>
  1293. </tr>
  1294. ';
  1295. }
  1296. // do we have the option to set the default behaviour?
  1297. if ( !$this->db->option_exists( 'cp_promote_reading' ) ) {
  1298. $behaviour_label = __( 'Default comment form behaviour', 'commentpress-core' );
  1299. $reading_label = __( 'Promote reading', 'commentpress-core' );
  1300. $commenting_label = __( 'Promote commenting', 'commentpress-core' );
  1301. // define upgrade
  1302. $upgrade .= '
  1303. <tr valign="top">
  1304. <th scope="row"><label for="cp_promote_reading">'.$behaviour_label.'</label></th>
  1305. <td><select id="cp_promote_reading" name="cp_promote_reading">
  1306. <option value="1">'.$reading_label.'</option>
  1307. <option value="0" selected="selected">'.$commenting_label.'</option>
  1308. </select>
  1309. </td>
  1310. </tr>
  1311. ';
  1312. }
  1313. // do we have the option to show or hide titles?
  1314. if ( !$this->db->option_exists( 'cp_title_visibility' ) ) {
  1315. // define labels
  1316. $titles_label = __( 'Show or hide page titles by default', 'commentpress-core' );
  1317. $titles_select_show = __( 'Show page titles', 'commentpress-core' );
  1318. $titles_select_hide = __( 'Hide page titles', 'commentpress-core' );
  1319. // define upgrade
  1320. $upgrade .= '
  1321. <tr valign="top">
  1322. <th scope="row"><label for="cp_title_visibility">'.$titles_label.'</label></th>
  1323. <td><select id="cp_title_visibility" name="cp_title_visibility">
  1324. <option value="show" selected="selected">'.$titles_select_show.'</option>
  1325. <option value="hide">'.$titles_select_hide.'</option>
  1326. </select>
  1327. </td>
  1328. </tr>
  1329. ';
  1330. }
  1331. // do we have the option to set the header bg colour?
  1332. if ( !$this->db->option_exists( 'cp_header_bg_colour' ) ) {
  1333. // define labels
  1334. $colour_label = __( 'Header Background Colour', 'commentpress-core' );
  1335. $colour_select_text = __( 'If you want to hide header text, add <strong>#blank</strong> as text colour.', 'commentpress-core' );
  1336. $colour_select_label = __( 'Select a Colour', 'commentpress-core' );
  1337. // define upgrade
  1338. $upgrade .= '
  1339. <tr valign="top" id="cp_header_bg_colour-row">
  1340. <th scope="row"><label for="cp_header_bg_colour">'.$colour_label.'</label></th>
  1341. <td><input type="text" name="cp_header_bg_colour" id="cp_header_bg_colour" value="'.$this->db->header_bg_colour.'" /><span class="description hide-if-js">'.$colour_select_text.'</span><input type="button" class="button hide-if-no-js" value="'.$colour_select_label.'" id="pickcolor" /><div id="color-picker" style="z-index: 100; background:#eee; border:1px solid #ccc; position:absolute; display:none;"></div></td>
  1342. </tr>
  1343. ';
  1344. }
  1345. // do we have the option to set the scroll speed?
  1346. if ( !$this->db->option_exists( 'cp_js_scroll_speed' ) ) {
  1347. // define labels
  1348. $scroll_label = __( 'Scroll speed', 'commentpress-core' );
  1349. $scroll_ms_label = __( 'milliseconds', 'commentpress-core' );
  1350. // define upgrade
  1351. $upgrade .= '
  1352. <tr valign="top">
  1353. <th scope="row"><label for="cp_js_scroll_speed">'.$scroll_label.'</label></th>
  1354. <td><input type="text" id="cp_js_scroll_speed" name="cp_js_scroll_speed" value="'.$this->db->js_scroll_speed.'" class="small-text" /> '.$scroll_ms_label.'</td>
  1355. </tr>
  1356. ';
  1357. }
  1358. // do we have the option to set the minimum page width?
  1359. if ( !$this->db->option_exists( 'cp_min_page_width' ) ) {
  1360. // define labels
  1361. $min_label = __( 'Minimum page width', 'commentpress-core' );
  1362. $min_pix_label = __( 'pixels', 'commentpress-core' );
  1363. // define upgrade
  1364. $upgrade .= '
  1365. <tr valign="top">
  1366. <th scope="row"><label for="cp_min_page_width"></label></th>
  1367. <td><input type="text" id="cp_min_page_width" name="cp_min_page_width" value="'.$this->db->min_page_width.'" class="small-text" /> '.$min_pix_label.'</td>
  1368. </tr>
  1369. ';
  1370. }
  1371. // --<
  1372. return $upgrade;
  1373. }
  1374. /**
  1375. * @description: returns the multisite deactivate button for the admin form
  1376. * @return string $html
  1377. * @todo:
  1378. *
  1379. */
  1380. function _get_deactivate() {
  1381. // do this via a filter, so only the Multisite object returns anything
  1382. return apply_filters( 'cpmu_deactivate_commentpress_element', '' );
  1383. }
  1384. /**
  1385. * @description: returns the reset button for the admin form
  1386. * @return string $reset
  1387. * @todo:
  1388. *
  1389. */
  1390. function _get_reset() {
  1391. // define label
  1392. $label = __( 'Reset options to plugin defaults', 'commentpress-core' );
  1393. // define reset
  1394. $reset = '
  1395. <tr valign="top">
  1396. <th scope="row"><label for="cp_reset">'.$label.'</label></th>
  1397. <td><input id="cp_reset" name="cp_reset" value="1" type="checkbox" /></td>
  1398. </tr>
  1399. ';
  1400. // --<
  1401. return $reset;
  1402. }
  1403. /**
  1404. * @description: returns the rich text editor button for the admin form
  1405. * @return string $editor
  1406. * @todo:
  1407. *
  1408. */
  1409. function _get_editor() {
  1410. // define labels
  1411. $editor_label = __( 'Comment form editor', 'commentpress-core' );
  1412. $rich_label = __( 'Rich-text Editor', 'commentpress-core' );
  1413. $plain_label = __( 'Plain-text Editor', 'commentpress-core' );
  1414. $behaviour_label = __( 'Default comment form behaviour', 'commentpress-core' );
  1415. $reading_label = __( 'Promote reading', 'commentpress-core' );
  1416. $commenting_label = __( 'Promote commenting', 'commentpress-core' );
  1417. // define editor
  1418. $editor = '
  1419. <tr valign="top">
  1420. <th scope="row"><label for="cp_comment_editor">'.$editor_label.'</label></th>
  1421. <td><select id="cp_comment_editor" name="cp_comment_editor">
  1422. <option value="1" '.(($this->db->option_get('cp_comment_editor') == '1') ? ' selected="selected"' : '').'>'.$rich_label.'</option>
  1423. <option value="0" '.(($this->db->option_get('cp_comment_editor') == '0') ? ' selected="selected"' : '').'>'.$plain_label.'</option>
  1424. </select>
  1425. </td>
  1426. </tr>
  1427. <tr valign="top">
  1428. <th scope="row"><label for="cp_promote_reading">'.$behaviour_label.'</label></th>
  1429. <td><select id="cp_promote_reading" name="cp_promote_reading">
  1430. <option value="1" '.(($this->db->option_get('cp_promote_reading') == '1') ? ' selected="selected"' : '').'>'.$reading_label.'</option>
  1431. <option value="0" '.(($this->db->option_get('cp_promote_reading') == '0') ? ' selected="selected"' : '').'>'.$commenting_label.'</option>
  1432. </select>
  1433. </td>
  1434. </tr>
  1435. ';
  1436. // --<
  1437. return $editor;
  1438. }
  1439. /**
  1440. * @description: returns the TOC options for the admin form
  1441. * @return string $editor
  1442. * @todo:
  1443. *
  1444. */
  1445. function _get_toc() {
  1446. // define labels
  1447. $toc_label = __( 'Table of Contents contains', 'commentpress-core' );
  1448. $posts_label = __( 'Posts', 'commentpress-core' );
  1449. $pages_label = __( 'Pages', 'commentpress-core' );
  1450. $chapter_label = __( 'Chapters are', 'commentpress-core' );
  1451. $chapter_pages_label = __( 'Pages', 'commentpress-core' );
  1452. $chapter_headings_label = __( 'Headings', 'commentpress-core' );
  1453. $extended_label = __( 'Appearance of TOC for posts', 'commentpress-core' );
  1454. $extended_info_label = __( 'Extended information', 'commentpress-core' );
  1455. $extended_title_label = __( 'Just the title', 'commentpress-core' );
  1456. // define table of contents options
  1457. $toc = '
  1458. <tr valign="top">
  1459. <th scope="row"><label for="cp_show_posts_or_pages_in_toc">'.$toc_label.'</label></th>
  1460. <td><select id="cp_show_posts_or_pages_in_toc" name="cp_show_posts_or_pages_in_toc">
  1461. <option value="post" '.(($this->db->option_get('cp_show_posts_or_pages_in_toc') == 'post') ? ' selected="selected"' : '').'>'.$posts_label.'</option>
  1462. <option value="page" '.(($this->db->option_get('cp_show_posts_or_pages_in_toc') == 'page') ? ' selected="selected"' : '').'>'.$pages_label.'</option>
  1463. </select>
  1464. </td>
  1465. </tr>
  1466. '.(($this->db->option_get('cp_show_posts_or_pages_in_toc') == 'page') ? '
  1467. <tr valign="top">
  1468. <th scope="row"><label for="cp_toc_chapter_is_page">'.$chapter_label.'</label></th>
  1469. <td><select id="cp_toc_chapter_is_page" name="cp_toc_chapter_is_page">
  1470. <option value="1" '.(($this->db->option_get('cp_toc_chapter_is_page') == '1') ? ' selected="selected"' : '').'>'.$chapter_pages_label.'</option>
  1471. <option value="0" '.(($this->db->option_get('cp_toc_chapter_is_page') == '0') ? ' selected="selected"' : '').'>'.$chapter_headings_label.'</option>
  1472. </select>
  1473. </td>
  1474. </tr>' : '' ).'
  1475. '.(($this->db->option_get('cp_show_posts_or_pages_in_toc') == 'page' AND $this->db->option_get('cp_toc_chapter_is_page') == '0') ? '
  1476. <tr valign="top">
  1477. <th scope="row"><label for="cp_show_subpages">Show Sub-Pages</label></th>
  1478. <td><input id="cp_show_subpages" name="cp_show_subpages" value="1" type="checkbox" '.( $this->db->option_get('cp_show_subpages') ? ' checked="checked"' : '' ).' /></td>
  1479. </tr>' : '' ).'
  1480. <tr valign="top">
  1481. <th scope="row"><label for="cp_show_extended_toc">'.$extended_label.'</label></th>
  1482. <td><select id="cp_show_extended_toc" name="cp_show_extended_toc">
  1483. <option value="1" '.(($this->db->option_get('cp_show_extended_toc') == '1') ? ' selected="selected"' : '').'>'.$extended_info_label.'</option>
  1484. <option value="0" '.(($this->db->option_get('cp_show_extended_toc') == '0') ? ' selected="selected"' : '').'>'.$extended_title_label.'</option>
  1485. </select>
  1486. </td>
  1487. </tr>
  1488. ';
  1489. // --<
  1490. return $toc;
  1491. }
  1492. /**
  1493. * @description: returns the Sidebar options for the admin form
  1494. * @return string $editor
  1495. * @todo:
  1496. *
  1497. */
  1498. function _get_sidebar() {
  1499. // define labels
  1500. $label = __( 'Which sidebar do you want to be active by default? (can be overridden on individual pages)', 'commentpress-core' );
  1501. $contents_label = __( 'Contents', 'commentpress-core' );
  1502. $activity_label = __( 'Activity', 'commentpress-core' );
  1503. $comments_label = __( 'Comments', 'commentpress-core' );
  1504. // get option (but if we haven't got a value, use comments)
  1505. $default = $this->db->option_get( 'cp_sidebar_default', 'comments' );
  1506. // define table of contents options
  1507. $toc = '
  1508. <tr valign="top">
  1509. <th scope="row"><label for="cp_sidebar_default">'.$label.'</label></th>
  1510. <td><select id="cp_sidebar_default" name="cp_sidebar_default">
  1511. <option value="toc" '.(($default == 'contents') ? ' selected="selected"' : '').'>'.$contents_label.'</option>
  1512. <option value="activity" '.(($default == 'activity') ? ' selected="selected"' : '').'>'.$activity_label.'</option>
  1513. <option value="comments" '.(($default == 'comments') ? ' selected="selected"' : '').'>'.$comments_label.'</option>
  1514. </select>
  1515. </td>
  1516. </tr>
  1517. ';
  1518. // --<
  1519. return $toc;
  1520. }
  1521. /**
  1522. * @description: returns the override paragraph commenting button for the admin form
  1523. * @return string $reset
  1524. * @todo:
  1525. *
  1526. */
  1527. function _get_override() {
  1528. // define label
  1529. $label = __( 'Enable "live" comment refreshing (Please note: may cause heavy load on your server)', 'commentpress-core' );
  1530. // define override
  1531. $override = '
  1532. <tr valign="top">
  1533. <th scope="row"><label for="cp_para_comments_live">'.$label.'</label></th>
  1534. <td><input id="cp_para_comments_live" name="cp_para_comments_live" value="1" type="checkbox" '.( ($this->db->option_get('cp_para_comments_live') == '1') ? ' checked="checked"' : '' ).' /></td>
  1535. </tr>
  1536. ';
  1537. // --<
  1538. return $override;
  1539. }
  1540. /**
  1541. * @description: returns the submit button
  1542. * @return string $editor
  1543. * @todo:
  1544. *
  1545. */
  1546. function _get_submit() {
  1547. // define label
  1548. $label = __( 'Save Changes', 'commentpress-core' );
  1549. // define editor
  1550. $submit = '
  1551. <p class="submit">
  1552. <input type="submit" name="commentpress_submit" value="'.$label.'" class="button-primary" />
  1553. </p>
  1554. ';
  1555. // --<
  1556. return $submit;
  1557. }
  1558. /**
  1559. * @description: get admin javascript, copied from wp-includes/custom-header.php
  1560. * @todo:
  1561. *
  1562. */
  1563. function get_admin_js() {
  1564. // print inline js
  1565. echo '
  1566. <script type="text/javascript">
  1567. //<![CDATA[
  1568. var text_objects = ["#cp_header_bg_colour-row"];
  1569. var farbtastic;
  1570. var default_color = "#'.$this->db->option_get_header_bg().'";
  1571. var old_color = null;
  1572. function pickColor(color) {
  1573. jQuery("#cp_header_bg_colour").val(color);
  1574. farbtastic.setColor(color);
  1575. }
  1576. function toggle_text(s) {
  1577. return;
  1578. if (jQuery(s).attr("id") == "showtext" && jQuery("#cp_header_bg_colour").val() != "blank")
  1579. return;
  1580. if (jQuery(s).attr("id") == "hidetext" && jQuery("#cp_header_bg_colour").val() == "blank")
  1581. return;
  1582. if (jQuery("#cp_header_bg_colour").val() == "blank") {
  1583. //Show text
  1584. if (old_color == "#blank")
  1585. old_color = default_color;
  1586. jQuery( text_objects.toString() ).show();
  1587. jQuery("#cp_header_bg_colour").val(old_color);
  1588. pickColor(old_color);
  1589. } else {
  1590. //Hide text
  1591. jQuery( text_objects.toString() ).hide();
  1592. old_color = jQuery("#cp_header_bg_colour").val();
  1593. jQuery("#cp_header_bg_colour").val("blank");
  1594. }
  1595. }
  1596. jQuery(document).ready(function() {
  1597. jQuery("#pickcolor").click(function() {
  1598. jQuery("#color-picker").show();
  1599. });
  1600. jQuery('."'".'input[name="hidetext"]'."'".').click(function() {
  1601. toggle_text(this);
  1602. });
  1603. jQuery("#defaultcolor").click(function() {
  1604. pickColor(default_color);
  1605. jQuery("#cp_header_bg_colour").val(default_color)
  1606. });
  1607. jQuery("#cp_header_bg_colour").keyup(function() {
  1608. var _hex = jQuery("#cp_header_bg_colour").val();
  1609. var hex = _hex;
  1610. if ( hex[0] != "#" )
  1611. hex = "#" + hex;
  1612. hex = hex.replace(/[^#a-fA-F0-9]+/, "");
  1613. if ( hex != _hex )
  1614. jQuery("#cp_header_bg_colour").val(hex);
  1615. if ( hex.length == 4 || hex.length == 7 )
  1616. pickColor( hex );
  1617. });
  1618. jQuery(document).mousedown(function(){
  1619. jQuery("#color-picker").each( function() {
  1620. var display = jQuery(this).css("display");
  1621. if (display == "block")
  1622. jQuery(this).fadeOut(2);
  1623. });
  1624. });
  1625. farbtastic = jQuery.farbtastic("#color-picker", function(color) { pickColor(color); });
  1626. pickColor("#'.$this->db->option_get_header_bg().'");
  1627. '.( ( 'blank' == $this->db->option_get_header_bg() OR '' == $this->db->option_get_header_bg() ) ? 'toggle_text();' : '' ).'
  1628. });
  1629. //]]>
  1630. </script>
  1631. ';
  1632. }
  1633. /**
  1634. * @description: return the javascript to init tinyMCE for WP < 3.2
  1635. * @return string $js
  1636. * @todo:
  1637. *
  1638. */
  1639. function _get_tinymce_init() {
  1640. // base url
  1641. //$_base = trailingslashit( get_bloginfo('wpurl') ).'wp-includes/js/tinymce';
  1642. $_base = includes_url('js/tinymce');
  1643. // locale
  1644. $mce_locale = ( '' == get_locale() ) ? 'en' : strtolower( substr(get_locale(), 0, 2) ); // only ISO 639-1
  1645. // content css
  1646. $_content_css = ''; //trailingslashit( get_bloginfo('wpurl') ).'wp-includes/js/tinymce/wordpress.css';
  1647. // define tinyMCE javascript
  1648. $js = '
  1649. <script type="text/javascript">
  1650. //<![CDATA[
  1651. /**
  1652. * @description: tinyMCE callback function
  1653. * @todo:
  1654. *
  1655. */
  1656. function br_to_nl( element_id, html, body ) {
  1657. // replace brs with newlines
  1658. html = html.replace(/<br\s*\/>/gi, "\n");
  1659. // --<
  1660. return html;
  1661. }
  1662. /**
  1663. * @description: tinyMCE init
  1664. * @todo:
  1665. *
  1666. */
  1667. tinyMCEPreInit = {
  1668. base : "'.$_base.'",
  1669. suffix : "",
  1670. query : "ver=20081129",
  1671. mceInit : {
  1672. mode : "exact",
  1673. editor_selector : "comment",
  1674. width : "100%",
  1675. theme : "advanced",
  1676. theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,bullist,numlist,|,link,unlink,|,removeformat,fullscreen",
  1677. theme_advanced_buttons2 : "",
  1678. theme_advanced_buttons3 : "",
  1679. theme_advanced_toolbar_location : "top",
  1680. theme_advanced_toolbar_align : "left",
  1681. theme_advanced_statusbar_location : "none",
  1682. theme_advanced_resizing : "1",
  1683. theme_advanced_resize_horizontal : false,
  1684. theme_advanced_disable : "code",
  1685. force_p_newlines : "1",
  1686. force_br_newlines : false,
  1687. forced_root_block : "p",
  1688. gecko_spellcheck : true,
  1689. directionality : "ltr",
  1690. save_callback : "br_to_nl",
  1691. entity_encoding : "raw",
  1692. plugins : "safari,fullscreen",
  1693. extended_valid_elements : "a[name|href|title],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style],blockquote[cite],strike,s,del,div[class|style]",
  1694. language : "en"
  1695. },
  1696. go : function() {
  1697. var t = this, sl = tinymce.ScriptLoader, ln = t.mceInit.language, th = t.mceInit.theme, pl = t.mceInit.plugins;
  1698. sl.markDone(t.base + "/langs/" + ln + ".js");
  1699. sl.markDone(t.base + "/themes/" + th + "/langs/" + ln + ".js");
  1700. sl.markDone(t.base + "/themes/" + th + "/langs/" + ln + "_dlg.js");
  1701. tinymce.each(pl.split(","), function(n) {
  1702. if (n && n.charAt(0) != "-") {
  1703. sl.markDone(t.base + "/plugins/" + n + "/langs/" + ln + ".js");
  1704. sl.markDone(t.base + "/plugins/" + n + "/langs/" + ln + "_dlg.js");
  1705. }
  1706. });
  1707. },
  1708. load_ext : function(url,lang) {
  1709. var sl = tinymce.ScriptLoader;
  1710. sl.markDone(url + "/langs/" + lang + ".js");
  1711. sl.markDone(url + "/langs/" + lang + "_dlg.js");
  1712. }
  1713. };
  1714. // load languages, themes and plugins
  1715. tinyMCEPreInit.go();
  1716. // init TinyMCE object
  1717. tinyMCE.init(tinyMCEPreInit.mceInit);
  1718. //]]>
  1719. </script>'."\n\n\n\n";
  1720. // --<
  1721. return $js;
  1722. }
  1723. /**
  1724. * Adds the TinyMCE editor to comment textareas in WP > 3.2
  1725. * Adapted from wp_tiny_mce in /wp-admin/includes/post.php
  1726. *
  1727. * @param mixed $settings optional An array that can add to or overwrite the default TinyMCE settings.
  1728. */
  1729. function _get_tinymce( $settings = false ) {
  1730. global $tinymce_version;
  1731. $baseurl = includes_url('js/tinymce');
  1732. $mce_locale = ( '' == get_locale() ) ? 'en' : strtolower( substr(get_locale(), 0, 2) ); // only ISO 639-1
  1733. /*
  1734. The following filter allows localization scripts to change the languages displayed in the spellchecker's drop-down menu.
  1735. By default it uses Google's spellchecker API, but can be configured to use PSpell/ASpell if installed on the server.
  1736. The + sign marks the default language. More information:
  1737. http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/spellchecker
  1738. */
  1739. $mce_spellchecker_languages = apply_filters('cprc_tinymce_spellchecker_languages', '+English=en,Danish=da,Dutch=nl,Finnish=fi,French=fr,German=de,Italian=it,Polish=pl,Portuguese=pt,Spanish=es,Swedish=sv');
  1740. // default plugins
  1741. $plugins = apply_filters( 'cprc_tinymce_plugins', array( 'spellchecker', 'tabfocus', 'fullscreen', 'safari' ) );
  1742. $ext_plugins = '';
  1743. // default buttons
  1744. $mce_buttons = apply_filters( 'cprc_tinymce_buttons', array('bold', 'italic', 'underline', 'strikethrough', '|', 'link', 'unlink', '|', 'spellchecker', 'removeformat', 'fullscreen') );
  1745. $mce_buttons = implode($mce_buttons, ',');
  1746. // TinyMCE init settings
  1747. $initArray = array (
  1748. 'mode' => 'specific_textareas',
  1749. 'editor_selector' => 'comment',
  1750. 'width' => '99%',
  1751. 'theme' => 'advanced',
  1752. 'theme_advanced_buttons1' => $mce_buttons,
  1753. 'theme_advanced_buttons2' => '',
  1754. 'theme_advanced_buttons3' => '',
  1755. 'theme_advanced_buttons4' => '',
  1756. 'language' => $mce_locale,
  1757. 'spellchecker_languages' => $mce_spellchecker_languages,
  1758. 'theme_advanced_toolbar_location' => 'top',
  1759. 'theme_advanced_toolbar_align' => 'left',
  1760. 'theme_advanced_statusbar_location' => 'none',
  1761. 'theme_advanced_resizing' => true,
  1762. 'theme_advanced_resize_horizontal' => false,
  1763. 'dialog_type' => 'modal',
  1764. 'formats' => "{
  1765. alignleft : [
  1766. {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'left'}},
  1767. {selector : 'img,table', classes : 'alignleft'}
  1768. ],
  1769. aligncenter : [
  1770. {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'center'}},
  1771. {selector : 'img,table', classes : 'aligncenter'}
  1772. ],
  1773. alignright : [
  1774. {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'right'}},
  1775. {selector : 'img,table', classes : 'alignright'}
  1776. ],
  1777. strikethrough : {inline : 'del'}
  1778. }",
  1779. 'relative_urls' => false,
  1780. 'remove_script_host' => false,
  1781. 'convert_urls' => false,
  1782. 'apply_source_formatting' => false,
  1783. 'remove_linebreaks' => true,
  1784. 'gecko_spellcheck' => true,
  1785. 'keep_styles' => false,
  1786. 'entities' => '38,amp,60,lt,62,gt',
  1787. 'accessibility_focus' => true,
  1788. 'tabfocus_elements' => 'major-publishing-actions',
  1789. 'media_strict' => false,
  1790. 'paste_remove_styles' => true,
  1791. 'paste_remove_spans' => true,
  1792. 'paste_strip_class_attributes' => 'all',
  1793. 'paste_text_use_dialog' => true,
  1794. 'extended_valid_elements' => 'a[name|href|title],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style],blockquote[cite],strike,s,del,div[class|style]',
  1795. 'wpeditimage_disable_captions' => '',
  1796. 'wp_fullscreen_content_css' => "$baseurl/plugins/wpfullscreen/css/wp-fullscreen.css",
  1797. 'plugins' => implode( ',', $plugins ),
  1798. );
  1799. // editor styles - applied via filter
  1800. $mce_css = '';
  1801. $mce_css = trim( apply_filters( 'mce_css', $mce_css ), ' ,' );
  1802. if ( ! empty($mce_css) )
  1803. $initArray['content_css'] = $mce_css;
  1804. if ( is_array($settings) )
  1805. $initArray = array_merge($initArray, $settings);
  1806. // For people who really REALLY know what they're doing with TinyMCE
  1807. // You can modify initArray to add, remove, change elements of the config before tinyMCE.init
  1808. // Setting "valid_elements", "invalid_elements" and "extended_valid_elements" can be done through "cprc_tinymce_before_init".
  1809. // Best is to use the default cleanup by not specifying valid_elements, as TinyMCE contains full set of XHTML 1.0.
  1810. $initArray = apply_filters('cprc_tinymce_before_init', $initArray);
  1811. /**
  1812. * Deprecated
  1813. *
  1814. * The tiny_mce_version filter is not needed since external plugins are loaded directly by TinyMCE.
  1815. * These plugins can be refreshed by appending query string to the URL passed to mce_external_plugins filter.
  1816. * 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).
  1817. */
  1818. $version = apply_filters('tiny_mce_version', '');
  1819. $version = 'ver=' . $tinymce_version . $version;
  1820. $language = $initArray['language'];
  1821. if ( 'en' != $language )
  1822. include_once(ABSPATH . WPINC . '/js/tinymce/langs/wp-langs.php');
  1823. $mce_options = '';
  1824. foreach ( $initArray as $k => $v ) {
  1825. if ( is_bool($v) ) {
  1826. $val = $v ? 'true' : 'false';
  1827. $mce_options .= $k . ':' . $val . ', ';
  1828. continue;
  1829. } elseif ( !empty($v) && is_string($v) && ( ('{' == $v{0} && '}' == $v{strlen($v) - 1}) || ('[' == $v{0} && ']' == $v{strlen($v) - 1}) || preg_match('/^\(?function ?\(/', $v) ) ) {
  1830. $mce_options .= $k . ':' . $v . ', ';
  1831. continue;
  1832. }
  1833. $mce_options .= $k . ':"' . $v . '", ';
  1834. }
  1835. $mce_options = rtrim( trim($mce_options), '\n\r,' );
  1836. // not needed
  1837. //do_action('before_wp_tiny_mce', $initArray);
  1838. ?>
  1839. <script type="text/javascript">
  1840. /* <![CDATA[ */
  1841. tinyMCEPreInit = {
  1842. base : "<?php echo $baseurl; ?>",
  1843. suffix : "",
  1844. query : "<?php echo $version; ?>",
  1845. mceInit : {<?php echo $mce_options; ?>},
  1846. load_ext : function(url,lang){var sl=tinymce.ScriptLoader;sl.markDone(url+'/langs/'+lang+'.js');sl.markDone(url+'/langs/'+lang+'_dlg.js');}
  1847. };
  1848. /* ]]> */
  1849. </script>
  1850. <?php
  1851. // ditched compressed version
  1852. echo "<script type='text/javascript' src='$baseurl/tiny_mce.js?$version'></script>\n";
  1853. if ( 'en' != $language && isset($lang) )
  1854. echo "<script type='text/javascript'>\n$lang\n</script>\n";
  1855. else
  1856. echo "<script type='text/javascript' src='$baseurl/langs/wp-langs-en.js?$version'></script>\n";
  1857. ?>
  1858. <script type="text/javascript">
  1859. /* <![CDATA[ */
  1860. <?php
  1861. if ( $ext_plugins )
  1862. echo "$ext_plugins\n";
  1863. ?>
  1864. (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');}});})();
  1865. tinyMCE.init(tinyMCEPreInit.mceInit);
  1866. /* ]]> */
  1867. </script>
  1868. <?php
  1869. // not needed
  1870. //do_action('after_wp_tiny_mce', $initArray);
  1871. }
  1872. //##############################################################################
  1873. } // class ends
  1874. ?>