PageRenderTime 52ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/DigitalPaulScholtenProject/DPSP-Platform
PHP | 1534 lines | 397 code | 648 blank | 489 comment | 78 complexity | c0cffae325e912e90e27fb326ab37c6a MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, AGPL-1.0, LGPL-2.1
  1. <?php /*
  2. ================================================================================
  3. Class CommentpressMultisiteAdmin
  4. ================================================================================
  5. AUTHOR: Christian Wach <needle@haystack.co.uk>
  6. --------------------------------------------------------------------------------
  7. NOTES
  8. =====
  9. This class is a wrapper for the majority of database operations.
  10. --------------------------------------------------------------------------------
  11. */
  12. /*
  13. ================================================================================
  14. Class Name
  15. ================================================================================
  16. */
  17. class CommentpressMultisiteAdmin {
  18. /*
  19. ============================================================================
  20. Properties
  21. ============================================================================
  22. */
  23. // parent object reference
  24. var $parent_obj;
  25. // options page
  26. var $options_page;
  27. // options array
  28. var $cpmu_options = array();
  29. /**
  30. * @description: initialises this object
  31. * @param object $parent_obj a reference to the parent object
  32. * @return object
  33. * @todo:
  34. *
  35. */
  36. function __construct( $parent_obj = null ) {
  37. // store reference to "parent" (calling obj, not OOP parent)
  38. $this->parent_obj = $parent_obj;
  39. // init
  40. $this->_init();
  41. // --<
  42. return $this;
  43. }
  44. /**
  45. * PHP 4 constructor
  46. */
  47. function CommentpressMultisiteAdmin( $parent_obj = null ) {
  48. // is this php5?
  49. if ( version_compare( PHP_VERSION, "5.0.0", "<" ) ) {
  50. // call php5 constructor
  51. $this->__construct( $parent_obj );
  52. }
  53. // --<
  54. return $this;
  55. }
  56. /**
  57. * @description: set up all options associated with this object
  58. * @param string $component a component identifier, either 'multisite' or 'buddypress'
  59. * @todo:
  60. *
  61. */
  62. function initialise( $component = 'multisite' ) {
  63. // we always get a multisite request
  64. if ( $component == 'multisite' ) {
  65. // if we don't have our version option...
  66. if ( !$this->option_wpms_exists( 'cpmu_version' ) ) {
  67. // we're activating: add our options...
  68. // add options with default values
  69. $this->options_create();
  70. }
  71. }
  72. // if BuddyPress is enabled, we'll get a request for that too
  73. if ( $component == 'buddypress' ) {
  74. // if we don't have one of our buddypress options...
  75. if ( !$this->option_exists( 'cpmu_bp_force_commentpress' ) ) {
  76. // we're activating: add our options...
  77. // use reset method
  78. $this->options_reset( $component );
  79. }
  80. }
  81. }
  82. /**
  83. * @description: upgrade plugin from 1.0 options to latest set
  84. * @return boolean $result
  85. * @todo:
  86. *
  87. */
  88. function upgrade() {
  89. // init return
  90. $result = false;
  91. // if we have a commentpress install (or we're forcing)
  92. if ( $this->check_upgrade() ) {
  93. /*
  94. --------------------------------------------------------------------
  95. Example of how upgrades work...
  96. --------------------------------------------------------------------
  97. // database object
  98. global $wpdb;
  99. // default
  100. $cpmu_xxxx = '';
  101. // get variables
  102. extract( $_POST );
  103. // New in CPMU 1.0.1 - are we missing the cpmu_xxxx option?
  104. if ( !$this->option_exists( 'cpmu_xxxx' ) ) {
  105. // get choice
  106. $_choice = $wpdb->escape( $cpmu_xxxx );
  107. // add chosen option
  108. $this->option_set( 'cpmu_xxxx', $_choice );
  109. }
  110. */
  111. // save new options
  112. $this->options_save();
  113. // store new version
  114. $this->option_wpms_set( 'cpmu_version', COMMENTPRESS_MU_PLUGIN_VERSION );
  115. }
  116. // --<
  117. return $result;
  118. }
  119. /**
  120. * @description: if needed, destroys all items associated with this object
  121. * @todo:
  122. *
  123. */
  124. function destroy() {
  125. // delete options
  126. $this->options_delete();
  127. }
  128. /**
  129. * @description: uninstalls database modifications
  130. * @todo:
  131. *
  132. */
  133. function uninstall() {
  134. // nothing
  135. }
  136. //##############################################################################
  137. /*
  138. ============================================================================
  139. PUBLIC METHODS
  140. ============================================================================
  141. */
  142. /**
  143. * @description: check for plugin upgrade
  144. * @return boolean $result
  145. * @todo:
  146. *
  147. */
  148. function check_upgrade() {
  149. // init
  150. $result = false;
  151. // get installed version
  152. $_version = $this->option_wpms_get( 'cpmu_version' );
  153. // if we have an install and it's lower than this one
  154. if ( $_version !== false AND version_compare( COMMENTPRESS_MU_PLUGIN_VERSION, $_version, '>' ) ) {
  155. // override
  156. $result = true;
  157. }
  158. // --<
  159. return $result;
  160. }
  161. /**
  162. * @description: create all plugin options
  163. * @todo:
  164. *
  165. */
  166. function options_create() {
  167. // init default options
  168. $this->cpmu_options = array();
  169. // allow plugins to add their own options (we always get options from commentpress_mu)
  170. $this->cpmu_options = apply_filters( 'cpmu_db_options_get_defaults', $this->cpmu_options );
  171. // store options array
  172. add_site_option( 'cpmu_options', $this->cpmu_options );
  173. // store CommentPress Multisite version
  174. add_site_option( 'cpmu_version', COMMENTPRESS_MU_PLUGIN_VERSION );
  175. }
  176. /**
  177. * @description: delete all plugin options
  178. * @todo:
  179. *
  180. */
  181. function options_delete() {
  182. // delete CommentPress Multisite version
  183. delete_site_option( 'cpmu_version' );
  184. // delete CommentPress Multisite options
  185. delete_site_option( 'cpmu_options' );
  186. }
  187. /**
  188. * @description: save the settings set by the administrator
  189. * @return boolean success or failure
  190. * @todo: do more error checking?
  191. *
  192. */
  193. function options_update() {
  194. // database object
  195. global $wpdb;
  196. // init result
  197. $result = false;
  198. // was the form submitted?
  199. if( isset( $_POST['cpmu_submit'] ) ) {
  200. // check that we trust the source of the data
  201. check_admin_referer( 'cpmu_admin_action', 'cpmu_nonce' );
  202. // init vars
  203. $cpmu_upgrade = '0';
  204. $cpmu_reset = '0';
  205. $cpmu_bp_reset = '0';
  206. // get variables
  207. extract( $_POST );
  208. // did we ask to upgrade CommentPress Multisite?
  209. if ( $cpmu_upgrade == '1' ) {
  210. // do upgrade
  211. $this->upgrade();
  212. // --<
  213. return true;
  214. }
  215. // did we ask to reset Multisite?
  216. if ( $cpmu_reset == '1' ) {
  217. // reset Multisite options
  218. $this->options_reset( 'multisite' );
  219. }
  220. // did we ask to reset BuddyPress?
  221. if ( $cpmu_bp_reset == '1' ) {
  222. // reset BuddyPress options
  223. $this->options_reset( 'buddypress' );
  224. }
  225. // did we ask to reset either?
  226. if ( $cpmu_reset == '1' OR $cpmu_bp_reset == '1' ) {
  227. // kick out
  228. return true;
  229. }
  230. // allow other plugins to hook into here
  231. do_action( 'cpmu_db_options_update' );
  232. // save
  233. $this->options_save();
  234. // set flag
  235. $result = true;
  236. }
  237. // --<
  238. return $result;
  239. }
  240. /**
  241. * @description: save options array as WordPress site option
  242. * @todo:
  243. *
  244. */
  245. function options_save() {
  246. // set option
  247. return $this->option_wpms_set( 'cpmu_options', $this->cpmu_options );
  248. }
  249. /**
  250. * @description: reset options
  251. * @param string $component a component identifier, either 'multisite' or 'buddypress'
  252. * @todo:
  253. *
  254. */
  255. function options_reset( $component = 'multisite' ) {
  256. // init default options
  257. $options = array();
  258. // did we get a multisite request?
  259. if ( $component == 'multisite' ) {
  260. // allow plugins to add their own options
  261. $options = apply_filters( 'cpmu_db_options_get_defaults', $options );
  262. }
  263. // did we get a buddypress request?
  264. if ( $component == 'buddypress' ) {
  265. // allow plugins to add their own options
  266. $options = apply_filters( 'cpmu_db_bp_options_get_defaults', $options );
  267. }
  268. // loop
  269. foreach( $options AS $option => $value ) {
  270. // set it
  271. $this->option_set( $option, $value );
  272. }
  273. // store it
  274. $this->options_save();
  275. }
  276. /**
  277. * @description: return existence of a specified option
  278. * @todo:
  279. */
  280. function option_exists( $option_name = '' ) {
  281. // test for null
  282. if ( $option_name == '' ) {
  283. // oops
  284. die( __( 'You must supply an option to option_exists()', 'commentpress-core' ) );
  285. }
  286. // get option with unlikely default
  287. return array_key_exists( $option_name, $this->cpmu_options );
  288. }
  289. /**
  290. * @description: return a value for a specified option
  291. * @todo:
  292. */
  293. function option_get( $option_name = '', $default = false ) {
  294. // test for null
  295. if ( $option_name == '' ) {
  296. // oops
  297. die( __( 'You must supply an option to option_get()', 'commentpress-core' ) );
  298. }
  299. // get option
  300. return ( array_key_exists( $option_name, $this->cpmu_options ) ) ? $this->cpmu_options[ $option_name ] : $default;
  301. }
  302. /**
  303. * @description: sets a value for a specified option
  304. * @todo:
  305. */
  306. function option_set( $option_name = '', $value = '' ) {
  307. // test for null
  308. if ( $option_name == '' ) {
  309. // oops
  310. die( __( 'You must supply an option to option_set()', 'commentpress-core' ) );
  311. }
  312. // test for other than string
  313. if ( !is_string( $option_name ) ) {
  314. // oops
  315. die( __( 'You must supply the option as a string to option_set()', 'commentpress-core' ) );
  316. }
  317. // set option
  318. $this->cpmu_options[ $option_name ] = $value;
  319. }
  320. /**
  321. * @description: deletes a specified option
  322. * @todo:
  323. */
  324. function option_delete( $option_name = '' ) {
  325. // test for null
  326. if ( $option_name == '' ) {
  327. // oops
  328. die( __( 'You must supply an option to option_delete()', 'commentpress-core' ) );
  329. }
  330. // unset option
  331. unset( $this->cpmu_options[ $option_name ] );
  332. }
  333. /**
  334. * @description: return existence of a specified site option
  335. * @todo:
  336. */
  337. function option_wpms_exists( $option_name = '' ) {
  338. // test for null
  339. if ( $option_name == '' ) {
  340. // oops
  341. die( __( 'You must supply an option to option_wpms_exists()', 'commentpress-core' ) );
  342. }
  343. // get option with unlikely default
  344. if ( $this->option_wpms_get( $option_name, 'fenfgehgejgrkj' ) == 'fenfgehgejgrkj' ) {
  345. // no
  346. return false;
  347. } else {
  348. // yes
  349. return true;
  350. }
  351. }
  352. /**
  353. * @description: return a value for a specified site option
  354. * @todo:
  355. */
  356. function option_wpms_get( $option_name = '', $default = false ) {
  357. // test for null
  358. if ( $option_name == '' ) {
  359. // oops
  360. die( __( 'You must supply an option to option_wpms_get()', 'commentpress-core' ) );
  361. }
  362. // get option
  363. return get_site_option( $option_name, $default );
  364. }
  365. /**
  366. * @description: sets a value for a specified site option
  367. * @todo:
  368. */
  369. function option_wpms_set( $option_name = '', $value = '' ) {
  370. // test for null
  371. if ( $option_name == '' ) {
  372. // oops
  373. die( __( 'You must supply an option to option_wpms_set()', 'commentpress-core' ) );
  374. }
  375. // set option
  376. return update_site_option( $option_name, $value );
  377. }
  378. /**
  379. * @description: CommentPress Core initialisation
  380. * @todo:
  381. *
  382. */
  383. function install_commentpress( $context = 'new_blog' ) {
  384. // activate core
  385. commentpress_activate_core();
  386. // access globals
  387. global $commentpress_core, $wpdb;
  388. // run activation hook
  389. $commentpress_core->activate();
  390. // activate ajax
  391. commentpress_activate_ajax();
  392. /*
  393. ------------------------------------------------------------------------
  394. Configure CommentPress Core based on admin page settings
  395. ------------------------------------------------------------------------
  396. */
  397. // TODO: create admin page settings
  398. // TOC = posts
  399. //$commentpress_core->db->option_set( 'cp_show_posts_or_pages_in_toc', 'post' );
  400. // TOC show extended posts
  401. //$commentpress_core->db->option_set( 'cp_show_extended_toc', 1 );
  402. /*
  403. ------------------------------------------------------------------------
  404. Further CommentPress plugins may define Blog Workflows and Type and
  405. enable them to be set in the blog signup form.
  406. ------------------------------------------------------------------------
  407. */
  408. // if we're installing from the wpmu_new_blog filter, then we need to grab
  409. // the extra options below - but if we're installing any other way, we need
  410. // to ignore these, as they override actual values
  411. // use passed value
  412. if ( $context == 'new_blog' ) {
  413. // check for (translation) workflow (checkbox)
  414. if ( isset( $_POST['cp_blog_workflow'] ) ) {
  415. // ensure boolean
  416. $cp_blog_workflow = ( $_POST['cp_blog_workflow'] == '1' ) ? 1 : 0;
  417. // set workflow
  418. $commentpress_core->db->option_set( 'cp_blog_workflow', $cp_blog_workflow );
  419. }
  420. // check for blog type (dropdown)
  421. if ( isset( $_POST['cp_blog_type'] ) ) {
  422. // ensure boolean
  423. $cp_blog_type = intval( $_POST['cp_blog_type'] );
  424. // set blog type
  425. $commentpress_core->db->option_set( 'cp_blog_type', $cp_blog_type );
  426. }
  427. // save
  428. $commentpress_core->db->options_save();
  429. }
  430. /*
  431. ------------------------------------------------------------------------
  432. Set WordPress Internal Configuration
  433. ------------------------------------------------------------------------
  434. */
  435. /*
  436. // allow anonymous commenting (may be overridden)
  437. $anon_comments = 0;
  438. // allow plugin overrides
  439. $anon_comments = apply_filters( 'cp_require_comment_registration', $anon_comments );
  440. // update wp option
  441. update_option( 'comment_registration', $anon_comments );
  442. // add Lorem Ipsum to "Sample Page" if the Network setting is empty?
  443. $first_page = get_site_option( 'first_page' );
  444. // is it empty?
  445. if ( $first_page == '' ) {
  446. // get it & update content, or perhaps delete?
  447. }
  448. */
  449. }
  450. /**
  451. * @description: CommentPress Core deactivation
  452. * @todo:
  453. *
  454. */
  455. function uninstall_commentpress() {
  456. // activate core
  457. commentpress_activate_core();
  458. // access globals
  459. global $commentpress_core, $wpdb;
  460. // run deactivation hook
  461. $commentpress_core->deactivate();
  462. /*
  463. ------------------------------------------------------------------------
  464. Reset WordPress Internal Configuration
  465. ------------------------------------------------------------------------
  466. */
  467. // reset any options set in install_commentpress()
  468. }
  469. /**
  470. * @description: get workflow form data
  471. * @return: keyed array of form data
  472. *
  473. */
  474. function get_workflow_data() {
  475. // init
  476. $return = array();
  477. // off by default
  478. $has_workflow = false;
  479. // init output
  480. $workflow_html = '';
  481. // allow overrides
  482. $has_workflow = apply_filters( 'cp_blog_workflow_exists', $has_workflow );
  483. // if we have workflow enabled, by a plugin, say...
  484. if ( $has_workflow !== false ) {
  485. // define workflow label
  486. $workflow_label = __( 'Enable Custom Workflow', 'commentpress-core' );
  487. // allow overrides
  488. $workflow_label = apply_filters( 'cp_blog_workflow_label', $workflow_label );
  489. // add to return
  490. $return['label'] = $workflow_label;
  491. // define form element
  492. $workflow_element = '<input type="checkbox" value="1" id="cp_blog_workflow" name="cp_blog_workflow" />';
  493. // add to return
  494. $return['element'] = $workflow_element;
  495. }
  496. // --<
  497. return $return;
  498. }
  499. /**
  500. * @description: get blog type form elements
  501. * @return: keyed array of form data
  502. *
  503. */
  504. function get_blogtype_data() {
  505. // init
  506. $return = array();
  507. // assume no types
  508. $types = array();
  509. // but allow overrides for plugins to supply some
  510. $types = apply_filters( 'cp_blog_type_options', $types );
  511. // if we got any, use them
  512. if ( !empty( $types ) ) {
  513. // define blog type label
  514. $type_label = __( 'Document Type', 'commentpress-core' );
  515. // allow overrides
  516. $type_label = apply_filters( 'cp_blog_type_label', $type_label );
  517. // add to return
  518. $return['label'] = $type_label;
  519. // construct options
  520. $type_option_list = array();
  521. $n = 0;
  522. foreach( $types AS $type ) {
  523. $type_option_list[] = '<option value="'.$n.'">'.$type.'</option>';
  524. $n++;
  525. }
  526. $type_options = implode( "\n", $type_option_list );
  527. // add to return
  528. $return['element'] = $type_options;
  529. }
  530. // --<
  531. return $return;
  532. }
  533. //##############################################################################
  534. /*
  535. ============================================================================
  536. PRIVATE METHODS
  537. ============================================================================
  538. */
  539. /*
  540. ---------------------------------------------------------------
  541. Object Initialisation
  542. ---------------------------------------------------------------
  543. */
  544. /**
  545. * @description: object initialisation
  546. * @todo:
  547. *
  548. */
  549. function _init() {
  550. // load options array
  551. $this->cpmu_options = $this->option_wpms_get( 'cpmu_options', $this->cpmu_options );
  552. // if we don't have one
  553. if ( count( $this->cpmu_options ) == 0 ) {
  554. // if not in backend
  555. if ( !is_admin() ) {
  556. // init upgrade
  557. //die( 'CommentPress Multisite upgrade required.' );
  558. }
  559. }
  560. // ----------------------------------------
  561. // optionally load CommentPress Core
  562. // ----------------------------------------
  563. // if we're network-enabled
  564. if ( COMMENTPRESS_PLUGIN_CONTEXT == 'mu_sitewide' ) {
  565. // init
  566. $core_active = false;
  567. // do we have CommentPress Core options?
  568. if ( get_option( 'commentpress_options', false ) ) {
  569. // get them
  570. $_commentpress_options = get_option( 'commentpress_options' );
  571. // if we have "special pages", then the plugin must be active on this blog
  572. if ( isset( $_commentpress_options[ 'cp_special_pages' ] ) ) {
  573. // set flag
  574. $core_active = true;
  575. }
  576. }
  577. // is CommentPress Core active?
  578. if ( $core_active ) {
  579. // activate core
  580. commentpress_activate_core();
  581. // activate ajax
  582. commentpress_activate_ajax();
  583. // modify CommentPress Core settings page
  584. add_filter(
  585. 'cpmu_deactivate_commentpress_element',
  586. array( $this, '_get_deactivate_element' )
  587. );
  588. // hook into CommentPress Core settings page result
  589. add_action(
  590. 'cpmu_deactivate_commentpress',
  591. array( $this, '_disable_core' )
  592. );
  593. } else {
  594. // modify admin menu
  595. add_action( 'admin_menu', array( $this, '_admin_menu' ) );
  596. }
  597. }
  598. }
  599. /**
  600. * @description: appends option to admin menu
  601. * @todo:
  602. *
  603. */
  604. function _admin_menu() {
  605. // sanity check function exists
  606. if ( !function_exists('current_user_can') ) { return; }
  607. // check user permissions
  608. if ( !current_user_can('manage_options') ) { return; }
  609. // enable CommentPress Core, if applicable
  610. $this->_enable_core();
  611. // insert item in relevant menu
  612. $this->options_page = add_options_page(
  613. __( 'CommentPress Core Settings', 'commentpress-core' ),
  614. __( 'CommentPress Core', 'commentpress-core' ),
  615. 'manage_options',
  616. 'commentpress_admin',
  617. array( $this, '_options_page' )
  618. );
  619. //print_r( $this->options_page );die();
  620. // add scripts and styles
  621. //add_action( 'admin_print_scripts-'.$this->options_page, array( $this, 'admin_js' ) );
  622. //add_action( 'admin_print_styles-'.$this->options_page, array( $this, 'admin_css' ) );
  623. //add_action( 'admin_head-'.$this->options_page, array( $this, 'admin_head' ), 50 );
  624. // test if we have a existing pre-3.4 Commentpress instance
  625. if ( commentpress_is_legacy_plugin_active() ) {
  626. // access globals
  627. global $pagenow;
  628. // show on pages other than the CP admin page
  629. if (
  630. $pagenow == 'options-general.php'
  631. AND !empty( $_GET['page'] )
  632. AND 'commentpress_admin' == $_GET['page']
  633. ) {
  634. // we're on our admin page
  635. } else {
  636. // show message
  637. add_action( 'admin_notices', array( $this, '_migrate_alert' ) );
  638. }
  639. }
  640. }
  641. /**
  642. * @description: utility to add a message to admin pages when migration is required
  643. * @todo:
  644. *
  645. */
  646. function _migrate_alert() {
  647. // sanity check function exists
  648. if ( function_exists('current_user_can') ) {
  649. // check user permissions
  650. if ( current_user_can('manage_options') ) {
  651. // show it
  652. echo '<div id="message" class="error"><p>'.__( 'CommentPress Core has detected that a previous version of Commentpress is active on this site. Please visit the <a href="options-general.php?page=commentpress_admin">Settings Page</a> to upgrade.', 'commentpress-core' ).'</p></div>';
  653. }
  654. }
  655. }
  656. /**
  657. * @description: prints plugin options page
  658. * @todo:
  659. *
  660. */
  661. function _options_page() {
  662. // sanity check function exists
  663. if ( !function_exists('current_user_can') ) { return; }
  664. // check user permissions
  665. if ( !current_user_can('manage_options') ) { return; }
  666. // get our admin options page
  667. echo $this->_get_admin_page();
  668. }
  669. /**
  670. * @description: get the Wordpress admin page
  671. * @return string $admin_page
  672. * @todo:
  673. *
  674. */
  675. function _get_admin_page() {
  676. // init
  677. $admin_page = '';
  678. // open div
  679. $admin_page .= '<div class="wrap" id="cpmu_admin_wrapper">'."\n\n";
  680. // get our form
  681. $admin_page .= $this->_get_admin_form();
  682. // close div
  683. $admin_page .= '</div>'."\n\n";
  684. // --<
  685. return $admin_page;
  686. }
  687. /**
  688. * @description: returns the admin form HTML
  689. * @return string $admin_page
  690. * @todo: translation
  691. *
  692. */
  693. function _get_admin_form() {
  694. // sanitise admin page url
  695. $url = $_SERVER['REQUEST_URI'];
  696. $url_array = explode( '&', $url );
  697. if ( $url_array ) { $url = $url_array[0]; }
  698. // init vars
  699. $label = __( 'Activate CommentPress', 'commentpress-core' );
  700. $submit = __( 'Save Changes', 'commentpress-core' );
  701. // test if we have a existing pre-3.4 Commentpress instance
  702. if ( commentpress_is_legacy_plugin_active() ) {
  703. // override vars
  704. $label = __( 'Upgrade to CommentPress Core', 'commentpress-core' );
  705. $submit = __( 'Upgrade', 'commentpress-core' );
  706. }
  707. // define admin page
  708. $admin_page = '
  709. <div class="icon32" id="icon-options-general"><br/></div>
  710. <h2>'.__( 'CommentPress Core Settings', 'commentpress-core' ).'</h2>
  711. <form method="post" action="'.htmlentities( $url.'&updated=true' ).'">
  712. '.wp_nonce_field( 'commentpress_admin_action', 'commentpress_nonce', true, false ).'
  713. '.wp_referer_field( false ).'
  714. <input id="cp_activate" name="cp_activate" value="1" type="hidden" />
  715. <h4>'.__( 'Activation', 'commentpress-core' ).'</h4>
  716. <table class="form-table">
  717. <tr valign="top">
  718. <th scope="row"><label for="cp_activate_commentpress">'.$label.'</label></th>
  719. <td><input id="cp_activate_commentpress" name="cp_activate_commentpress" value="1" type="checkbox" /></td>
  720. </tr>
  721. </table>
  722. <input type="hidden" name="action" value="update" />
  723. <p class="submit">
  724. <input type="submit" name="commentpress_submit" value="'.$submit.'" class="button-primary" />
  725. </p>
  726. </form>'."\n\n\n\n";
  727. // --<
  728. return $admin_page;
  729. }
  730. /**
  731. * @description: get workflow form elements
  732. * @return: form html
  733. *
  734. */
  735. function _get_workflow() {
  736. // init
  737. $workflow_html = '';
  738. // get data
  739. $workflow = $this->get_workflow_data();
  740. // if we have workflow data...
  741. if ( !empty( $workflow ) ) {
  742. // show it
  743. $workflow_html = '
  744. <tr valign="top">
  745. <th scope="row"><label for="cp_blog_workflow">'.$workflow['label'].'</label></th>
  746. <td>'.$workflow['element'].'</td>
  747. </tr>
  748. ';
  749. }
  750. // --<
  751. return $workflow_html;
  752. }
  753. /**
  754. * @description: get blog type form elements
  755. *
  756. */
  757. function _get_blogtype() {
  758. // init
  759. $type_html = '';
  760. // get data
  761. $type = $this->get_blogtype_data();
  762. // if we have type data...
  763. if ( !empty( $type ) ) {
  764. // show it
  765. $type_html = '
  766. <tr valign="top">
  767. <th scope="row"><label for="cp_blog_type">'.$type['label'].'</label></th>
  768. <td><select id="cp_blog_type" name="cp_blog_type">
  769. '.$type['element'].'
  770. </select></td>
  771. </tr>
  772. ';
  773. }
  774. // --<
  775. return $type_html;
  776. }
  777. /**
  778. * @description: enable CommentPress Core
  779. * @todo:
  780. *
  781. */
  782. function _enable_core() {
  783. // database object
  784. global $wpdb;
  785. // was the form submitted?
  786. if( !isset( $_POST[ 'commentpress_submit' ] ) ) { return; }
  787. // check that we trust the source of the data
  788. check_admin_referer( 'commentpress_admin_action', 'commentpress_nonce' );
  789. // init var
  790. $cp_activate_commentpress = 0;
  791. // get vars
  792. extract( $_POST );
  793. // did we ask to activate CommentPress Core?
  794. if ( $cp_activate_commentpress == '1' ) {
  795. // install core, but not from wpmu_new_blog
  796. $this->install_commentpress( 'admin_page' );
  797. // redirect
  798. wp_redirect( $_SERVER[ 'REQUEST_URI' ] );
  799. // --<
  800. exit();
  801. }
  802. }
  803. /**
  804. * @description: get deactivation form element
  805. * @return: form html
  806. *
  807. */
  808. function _get_deactivate_element() {
  809. // define html
  810. return '
  811. <tr valign="top">
  812. <th scope="row"><label for="cp_deactivate_commentpress">'.__( 'Deactivate CommentPress Core', 'commentpress-core' ).'</label></th>
  813. <td><input id="cp_deactivate_commentpress" name="cp_deactivate_commentpress" value="1" type="checkbox" /></td>
  814. </tr>
  815. ';
  816. }
  817. /**
  818. * @description: disable CommentPress Core
  819. * @todo:
  820. *
  821. */
  822. function _disable_core() {
  823. // database object
  824. global $wpdb;
  825. // was the form submitted?
  826. if( !isset( $_POST[ 'commentpress_submit' ] ) ) { return; }
  827. // check that we trust the source of the data
  828. check_admin_referer( 'commentpress_admin_action', 'commentpress_nonce' );
  829. // init var
  830. $cp_deactivate_commentpress = 0;
  831. // get vars
  832. extract( $_POST );
  833. // did we ask to deactivate CommentPress Core?
  834. if ( $cp_deactivate_commentpress == '1' ) {
  835. // uninstall core
  836. $this->uninstall_commentpress();
  837. // redirect
  838. wp_redirect( $_SERVER[ 'REQUEST_URI' ] );
  839. // --<
  840. exit();
  841. }
  842. // --<
  843. return;
  844. }
  845. //##############################################################################
  846. } // class ends
  847. ?>