PageRenderTime 82ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/DigitalPaulScholtenProject/DPSP-Platform
PHP | 450 lines | 106 code | 174 blank | 170 comment | 28 complexity | 208743cd5e2506935d33fb6373252bf4 MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, AGPL-1.0, LGPL-2.1
  1. <?php /*
  2. --------------------------------------------------------------------------------
  3. Plugin Name: CommentPress Core
  4. Plugin URI: http://www.futureofthebook.org/commentpress/
  5. Description: CommentPress allows readers to comment paragraph by paragraph in the margins of a text. You can use it to annotate, gloss, workshop, debate and more!
  6. Author: Institute for the Future of the Book
  7. Version: 3.4.6
  8. Author URI: http://www.futureofthebook.org
  9. Text Domain: commentpress-core
  10. --------------------------------------------------------------------------------
  11. Special thanks to:
  12. Eddie Tejeda @ http://www.visudo.com for Commentpress 2.0
  13. Mark James for the icons: http://www.famfamfam.com/lab/icons/silk/
  14. --------------------------------------------------------------------------------
  15. */
  16. // -----------------------------------------------------------------------------
  17. // No need to edit below this line
  18. // -----------------------------------------------------------------------------
  19. // set version
  20. define( 'COMMENTPRESS_VERSION', '3.4.6' );
  21. // store reference to this file
  22. if ( !defined( 'COMMENTPRESS_PLUGIN_FILE' ) ) {
  23. define( 'COMMENTPRESS_PLUGIN_FILE', __FILE__ );
  24. }
  25. // store URL to this plugin's directory
  26. if ( !defined( 'COMMENTPRESS_PLUGIN_URL' ) ) {
  27. define( 'COMMENTPRESS_PLUGIN_URL', plugin_dir_url( COMMENTPRESS_PLUGIN_FILE ) );
  28. }
  29. // store PATH to this plugin's directory
  30. if ( !defined( 'COMMENTPRESS_PLUGIN_PATH' ) ) {
  31. define( 'COMMENTPRESS_PLUGIN_PATH', plugin_dir_path( COMMENTPRESS_PLUGIN_FILE ) );
  32. }
  33. /*
  34. --------------------------------------------------------------------------------
  35. Begin by establishing Plugin Context
  36. --------------------------------------------------------------------------------
  37. NOTE: force-activated context is now deprecated
  38. --------------------------------------------------------------------------------
  39. */
  40. // test for multisite location
  41. if ( basename( dirname( COMMENTPRESS_PLUGIN_FILE ) ) == 'mu-plugins' ) {
  42. // directory-based forced activation
  43. if ( !defined( 'COMMENTPRESS_PLUGIN_CONTEXT' ) ) {
  44. define( 'COMMENTPRESS_PLUGIN_CONTEXT', 'mu_forced' );
  45. }
  46. // test for multisite
  47. } elseif ( is_multisite() ) {
  48. // check if our plugin is one of those activated sitewide
  49. $this_plugin = plugin_basename( COMMENTPRESS_PLUGIN_FILE );
  50. // unfortunately, is_plugin_active_for_network() is not yet available so
  51. // we have to do this manually...
  52. // get sitewide plugins
  53. $active_plugins = (array) get_site_option( 'active_sitewide_plugins' );
  54. // is the plugin network activated?
  55. if ( isset( $active_plugins[ $this_plugin ] ) ) {
  56. // yes, network activated
  57. if ( !defined( 'COMMENTPRESS_PLUGIN_CONTEXT' ) ) {
  58. define( 'COMMENTPRESS_PLUGIN_CONTEXT', 'mu_sitewide' );
  59. }
  60. } else {
  61. // optional activation per blog in multisite
  62. if ( !defined( 'COMMENTPRESS_PLUGIN_CONTEXT' ) ) {
  63. define( 'COMMENTPRESS_PLUGIN_CONTEXT', 'mu_optional' );
  64. }
  65. }
  66. } else {
  67. // single user install
  68. if ( !defined( 'COMMENTPRESS_PLUGIN_CONTEXT' ) ) {
  69. define( 'COMMENTPRESS_PLUGIN_CONTEXT', 'standard' );
  70. }
  71. }
  72. //print_r( COMMENTPRESS_PLUGIN_CONTEXT ); die();
  73. /*
  74. --------------------------------------------------------------------------------
  75. Misc Utility Functions
  76. --------------------------------------------------------------------------------
  77. */
  78. /**
  79. * @description: utility to check for presence of vital files
  80. * @param string $filename the name of the CommentPress Core Plugin file
  81. * @return string $filepath absolute path to file
  82. * @todo:
  83. *
  84. */
  85. function commentpress_file_is_present( $filename ) {
  86. // define path to our requested file
  87. $filepath = COMMENTPRESS_PLUGIN_PATH . $filename;
  88. // is our class definition present?
  89. if ( !is_file( $filepath ) ) {
  90. // oh no!
  91. die( 'CommentPress Core Error: file "'.$filepath.'" is missing from the plugin directory.' );
  92. }
  93. // --<
  94. return $filepath;
  95. }
  96. /**
  97. * @description: utility to include the core plugin
  98. * @todo:
  99. *
  100. */
  101. function commentpress_include_core() {
  102. // do we have our class?
  103. if ( !class_exists( 'CommentpressCore' ) ) {
  104. // define filename
  105. $_file = 'commentpress-core/class_commentpress.php';
  106. // get path
  107. $_file_path = commentpress_file_is_present( $_file );
  108. // we're fine, include class definition
  109. require_once( $_file_path );
  110. }
  111. }
  112. /**
  113. * @description: utility to activate the core plugin
  114. * @todo:
  115. *
  116. */
  117. function commentpress_activate_core() {
  118. // declare as global
  119. global $commentpress_core;
  120. // do we have it already?
  121. if ( is_null( $commentpress_core ) ) {
  122. // instantiate it
  123. $commentpress_core = new CommentpressCore;
  124. }
  125. }
  126. /**
  127. * @description: utility to activate the ajax plugin
  128. * @todo:
  129. *
  130. */
  131. function commentpress_activate_ajax() {
  132. // define filename
  133. $_file = 'commentpress-ajax/cp-ajax-comments.php';
  134. // get path
  135. $_file_path = commentpress_file_is_present( $_file );
  136. // we're fine, include ajax file
  137. require_once( $_file_path );
  138. }
  139. /**
  140. * shortcut for debugging
  141. */
  142. function _cpdie( $var ) {
  143. print '<pre>';
  144. print_r( $var );
  145. print '</pre>';
  146. die();
  147. }
  148. /**
  149. * @description: utility to add link to settings page
  150. * @todo:
  151. *
  152. */
  153. function commentpress_plugin_action_links( $links, $file ) {
  154. // add settings link
  155. if ( $file == plugin_basename( dirname( __FILE__ ).'/commentpress-core.php' ) ) {
  156. $links[] = '<a href="options-general.php?page=commentpress_admin">'.__( 'Settings', 'commentpress-core' ).'</a>';
  157. }
  158. // --<
  159. return $links;
  160. }
  161. // add filter for the above
  162. add_filter( 'plugin_action_links', 'commentpress_plugin_action_links', 10, 2 );
  163. /**
  164. * @description: get WP plugin reference by name (since we never know for sure what the enclosing
  165. * directory is called)
  166. * @todo:
  167. *
  168. */
  169. function commentpress_find_plugin_by_name( $plugin_name = '' ) {
  170. // kick out if no param supplied
  171. if ( $plugin_name == '' ) { return false; }
  172. // init path
  173. $path_to_plugin = false;
  174. // get plugins
  175. $plugins = get_plugins();
  176. //print_r( $plugins ); die();
  177. // because the key is the path to the plugin file, we have to find the
  178. // key by iterating over the values (which are arrays) to find the
  179. // plugin with the name we want. Doh!
  180. foreach( $plugins AS $key => $plugin ) {
  181. // is it ours?
  182. if ( $plugin['Name'] == $plugin_name ) {
  183. // now get the key, which is our path
  184. $path_to_plugin = $key;
  185. break;
  186. }
  187. }
  188. // --<
  189. return $path_to_plugin;
  190. }
  191. /**
  192. * @description: test if the old pre-3.4 Commentpress plugin is active
  193. * @todo:
  194. *
  195. */
  196. function commentpress_is_legacy_plugin_active() {
  197. // assume not
  198. $active = false;
  199. // get old options
  200. $old = get_option( 'cp_options', array() );
  201. // test if we have a existing pre-3.4 Commentpress instance
  202. if ( is_array( $old ) AND count( $old ) > 0 ) {
  203. // if we have "special pages", then the plugin must be active on this blog
  204. // NB: do we need to check is_plugin_active() as well (or instead)?
  205. if ( isset( $old[ 'cp_special_pages' ] ) ) {
  206. // set flag
  207. $active = true;
  208. }
  209. }
  210. // --<
  211. return $active;
  212. }
  213. /*
  214. --------------------------------------------------------------------------------
  215. NOTE: in multisite, child themes are registered as broken if the plugin is not
  216. network-enabled. Make sure child themes have instructions.
  217. --------------------------------------------------------------------------------
  218. There are further complex issues when in Multisite:
  219. First scenario:
  220. * if the plugin is NOT initially network-enabled
  221. * but it IS enabled on one or more blogs on the network
  222. * and the plugin in THEN network-enabled
  223. Second scenario:
  224. * if the plugin IS initially network-enabled
  225. * and it IS activated on one or more blogs on the network
  226. * and the plugin in THEN network-disabled
  227. If installs stick to one or the other, then all works as expected.
  228. --------------------------------------------------------------------------------
  229. */
  230. // register our themes directory
  231. register_theme_directory( plugin_dir_path( COMMENTPRESS_PLUGIN_FILE ) . 'themes' );
  232. /*
  233. --------------------------------------------------------------------------------
  234. Include Standalone
  235. --------------------------------------------------------------------------------
  236. */
  237. commentpress_include_core();
  238. /*
  239. --------------------------------------------------------------------------------
  240. Init Standalone
  241. --------------------------------------------------------------------------------
  242. */
  243. // only activate if in standard or mu_optional context
  244. if ( COMMENTPRESS_PLUGIN_CONTEXT == 'standard' OR COMMENTPRESS_PLUGIN_CONTEXT == 'mu_optional' ) {
  245. // CommentPress Core
  246. commentpress_activate_core();
  247. // access global
  248. global $commentpress_core;
  249. //print_r( $commentpress_core ); die();
  250. // activation
  251. register_activation_hook( COMMENTPRESS_PLUGIN_FILE, array( $commentpress_core, 'activate' ) );
  252. // deactivation
  253. register_deactivation_hook( COMMENTPRESS_PLUGIN_FILE, array( $commentpress_core, 'deactivate' ) );
  254. // uninstall uses the 'uninstall.php' method
  255. // see: http://codex.wordpress.org/Function_Reference/register_uninstall_hook
  256. // AJAX Commenting
  257. commentpress_activate_ajax();
  258. }
  259. /*
  260. --------------------------------------------------------------------------------
  261. Init Multisite
  262. --------------------------------------------------------------------------------
  263. */
  264. // have we activated network-wide?
  265. if ( COMMENTPRESS_PLUGIN_CONTEXT == 'mu_sitewide' ) {
  266. // activate multisite plugin
  267. // define filename
  268. $_file = 'commentpress-multisite/commentpress-mu.php';
  269. // get path
  270. $_file_path = commentpress_file_is_present( $_file );
  271. // we're fine, include class definition
  272. require_once( $_file_path );
  273. }