PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/core/admin/page_album_modules/loader.php

http://buddypress-media.googlecode.com/
PHP | 547 lines | 304 code | 170 blank | 73 comment | 35 complexity | ac3ef35a44831562c468b1203773f325 MD5 | raw file
Possible License(s): AGPL-1.0, Apache-2.0, GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * BP-MEDIA SCREEN RENDERING CLASS "ADMIN-> ALBUM MODULES"
  4. * Generates the admin screen "Album Modules" page. Handles form submissions. Updates global config variable and
  5. * stored settings in database when parameters are changed.
  6. *
  7. * @version 0.1.9
  8. * @since 0.1.9
  9. * @package BP-Media
  10. * @subpackage Admin
  11. * @license GPL v2.0
  12. * @link http://code.google.com/p/buddypress-media/
  13. *
  14. * ========================================================================================================
  15. */
  16. // Prevent hackers from directly calling this page
  17. if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) {
  18. die('You are not allowed to call this page directly.');
  19. }
  20. // Include all of the admin base page base classes
  21. // ===============================================================================================
  22. $base_page_classes = glob( BPM_PATH_BASE .'/core/album_modules/admin_base/*.php');
  23. foreach ( $base_page_classes as $path ){
  24. if( file_exists($path) ){
  25. include_once ($path);
  26. }
  27. }
  28. // ============================================================================================================ //
  29. class BPM_admin_page_albumModules extends BPM_admin_page_base {
  30. /**
  31. * Listens for form submission and triggers form processor function
  32. *
  33. * @version 0.1.9
  34. * @since 0.1.9
  35. */
  36. function __construct() {
  37. $this->filepath = admin_url() . 'admin.php?page=' . $_GET['page'];
  38. $this->page = $_GET['page'];
  39. }
  40. /**
  41. * Enqueues the selected tab's scripts in the page header
  42. *
  43. * @version 0.1.9
  44. * @since 0.1.9
  45. */
  46. public function enqueueScripts() {
  47. // Load scripts used by all tabs on this page
  48. // ======================================================
  49. wp_enqueue_script( 'bpm-adminNotifier');
  50. global $bpm;
  51. $bpm->albumModules->loadAdminScripts();
  52. }
  53. /**
  54. * Enqueues the selected tab's styles in the page header
  55. *
  56. * @version 0.1.9
  57. * @since 0.1.9
  58. */
  59. public function enqueueStyles() {
  60. // Load styles used by all tabs on this page
  61. // ======================================================
  62. wp_enqueue_style( 'bpm-admin', BPM_URL_CORE .'/admin/css/bpm.admin.css', false, '2.8.1', 'screen' );
  63. wp_enqueue_style( 'bpm-tabs-v', BPM_URL_CORE .'/admin/css/bpm.tabs.v.css', false, '2.5.0', 'screen' );
  64. wp_enqueue_style( 'bpm-ui-base', BPM_URL_LIB .'/jquery/ui/css/jquery.ui.base.css', false, '2.8.1', 'screen');
  65. wp_enqueue_style( 'bpm-ui-theme', BPM_URL_CORE .'/admin/css/bpm.ui.theme.css', false, '2.8.1', 'screen' );
  66. wp_enqueue_style( 'bpm-album-modules', BPM_URL_CORE .'/admin/css/bpm.album.modules.css', false, '2.8.1', 'screen' );
  67. global $bpm;
  68. $bpm->albumModules->loadAdminStyles();
  69. }
  70. /**
  71. * Processes module configuration settings while preventing one module from overwriting another module's settings.
  72. *
  73. * Accepts data from a submitted admin settings form. Uses variables list in hidden 'page_options' form field
  74. * to determine which fields to load from the form. Updates each $bp->bpa->options['media_module'settings'][$module_class][$option]
  75. * on the form in the global $bp->bpa->options variable, then writes the $bp->bpa->options variable to the database.
  76. *
  77. * @TODO Add error checking, sanitizing eg: $value = sanitize_option($option, $value), etc. At present bad
  78. * user input can crash the plugin and damage the database.
  79. * @version 0.1.9
  80. * @since 0.1.9
  81. */
  82. function processor() {
  83. global $bpm;
  84. // CASE 1 - User is updating an album module's configuration settings
  85. // =================================================================================================================
  86. if ( isset($_POST['updateoption']) ) {
  87. check_admin_referer('bpm_admin_settings');
  88. if( current_user_can('install_plugins') ){
  89. // Save options and show user if update was successful
  90. try {
  91. $bpm->config->processHTMLForm($_POST);
  92. ?>
  93. <script type="text/javascript">
  94. jQuery(document).ready(function(){
  95. jQuery.bpm_admin_notify.add({
  96. title: "<?php _e("Settings Updated", "bp-media"); ?>",
  97. text: "<?php _e("BP-Media has updated the album module's settings", "bp-media"); ?>",
  98. image: "<?php echo BPM_URL_CORE . '/admin/css/images/bpm_admin_notify_success.png' ?>"
  99. });
  100. });
  101. </script>
  102. <?php
  103. }
  104. catch (BPM_exception $fail) {
  105. ?>
  106. <script type="text/javascript">
  107. jQuery(document).ready(function(){
  108. jQuery.bpm_admin_notify.add({
  109. title: "<?php _e("Update Error", "bp-media"); ?>",
  110. text: "<?php _e("Error updating the album module's settings", "bp-media"); ?>",
  111. image: "<?php echo BPM_URL_CORE . '/admin/css/images/bpm_admin_notify_fail.png' ?>"
  112. });
  113. });
  114. </script>
  115. <?php
  116. }
  117. }
  118. else {
  119. die("You do not have security clearance to do this");
  120. }
  121. }
  122. // CASE 2 - User is updating a album module's configuration settings
  123. // =================================================================================================================
  124. elseif( isset($_POST['admin_ajax_form']) ) {
  125. check_admin_referer('bpm_admin_ajax');
  126. $media_modules = BPM_Multimedia::get_registered_media_modules();
  127. $module_class = trim($_POST['module_class']);
  128. // Check that the media module class posted in the form actually exists
  129. if( in_array($module_class, $media_modules) ) {
  130. call_user_func(array($module_class,'admin_ajaxForm'));
  131. }
  132. else {
  133. echo "You are attempting to save AJAX form data for a media module that is not currently loaded\n";
  134. BPM_debug::dump($_POST);
  135. die;
  136. }
  137. }
  138. // CASE 3 - User is enabling, disabling, or resetting a album module
  139. // =================================================================================================================
  140. elseif( isset($_GET['bpm_action']) ){ ;
  141. check_admin_referer('bpm_admin_settings');
  142. if( $_GET['bpm_action'] == 'activate'){
  143. $san = new BPM_sanitize();
  144. $module_slug = $san->slug($_GET['module'], null, $valid);
  145. if($valid){
  146. $activate_ok = $bpm->albumModules->activateBySlug($module_slug);
  147. }
  148. if($valid && $activate_ok){
  149. ?>
  150. <script type="text/javascript">
  151. jQuery(document).ready(function(){
  152. jQuery.bpm_admin_notify.add({
  153. title: "<?php _e("Album Module Activated", "bp-media"); ?>",
  154. text: "<?php _e("BP-Media has successfully activated the album module.", "bp-media"); ?>",
  155. image: "<?php echo BPM_URL_CORE . '/admin/css/images/bpm_admin_notify_success.png' ?>"
  156. });
  157. });
  158. </script>
  159. <?php
  160. }
  161. else {
  162. ?>
  163. <script type="text/javascript">
  164. jQuery(document).ready(function(){
  165. jQuery.bpm_admin_notify.add({
  166. title: "<?php _e("Album Module Error", "bp-media"); ?>",
  167. text: "<?php _e("Error activating the album module.", "bp-media"); ?>",
  168. image: "<?php echo BPM_URL_CORE . '/admin/css/images/bpm_admin_notify_fail.png' ?>"
  169. });
  170. });
  171. </script>
  172. <?php
  173. }
  174. }
  175. if( $_GET['bpm_action'] == 'deactivate'){
  176. $san = new BPM_sanitize();
  177. $module_slug = $san->slug($_GET['module'], null, $valid);
  178. if($valid){
  179. $activate_ok = $bpm->albumModules->deactivateBySlug($module_slug);
  180. }
  181. if($valid && $activate_ok){
  182. ?>
  183. <script type="text/javascript">
  184. jQuery(document).ready(function(){
  185. jQuery.bpm_admin_notify.add({
  186. title: "<?php _e("Album Module Dectivated", "bp-media"); ?>",
  187. text: "<?php _e("BP-Media has successfully deactivated the album module.", "bp-media"); ?>",
  188. image: "<?php echo BPM_URL_CORE . '/admin/css/images/bpm_admin_notify_success.png' ?>"
  189. });
  190. });
  191. </script>
  192. <?php
  193. }
  194. else {
  195. ?>
  196. <script type="text/javascript">
  197. jQuery(document).ready(function(){
  198. jQuery.bpm_admin_notify.add({
  199. title: "<?php _e("Album Module Error", "bp-media"); ?>",
  200. text: "<?php _e("Error deactivating the album module.", "bp-media"); ?>",
  201. image: "<?php echo BPM_URL_CORE . '/admin/css/images/bpm_admin_notify_fail.png' ?>"
  202. });
  203. });
  204. </script>
  205. <?php
  206. }
  207. }
  208. if( $_GET['bpm_action'] == 'reset'){
  209. }
  210. }
  211. }
  212. /**
  213. * Renders all tabs on the admin screen "Content" page
  214. *
  215. * Prints the jQuery configuration code to the HTML stream. Uses entries in the $tabs array to iterate through
  216. * the tab rendering functions inside the class. Each tab rendering function writes HTML for one tab to the
  217. * HTML stream, encapsulated for jQuery.
  218. *
  219. * @version 0.1.9
  220. * @since 0.1.9
  221. */
  222. function render() {
  223. global $bp, $bpm;
  224. // If a form is submitted with data, run the processor function.
  225. if ( !empty($_POST) || isset($_GET['bpm_action']) ){
  226. $this->processor();
  227. }
  228. $selected_module = $bpm->albumModules->getSelectedModule();
  229. $album_modules = $bpm->albumModules->getAdminModules();
  230. ?>
  231. <script type="text/javascript">
  232. jQuery(document).ready(function(){
  233. <?php // Adds row-striping to our tables ////////////////////////// ?>
  234. jQuery('table.form-table tbody tr:even').addClass('alt');
  235. });
  236. </script>
  237. <div class="bpm_header_small"></div>
  238. <div class="tabs_v">
  239. <div class="bpm_section_intro">
  240. <div class="icon"><img src="<?php echo BPM_URL_CORE . '/admin/page_album_modules/album_modules_icon.png' ?>" alt="Album Modules" width="64" height="64" /></div>
  241. <div class="title">
  242. <?php _e('Album Modules',"bp-media") ?>
  243. </div>
  244. <div class="details">
  245. <?php _e("Album modules control the structure, content, and layout of user albums.They can
  246. hold one (or many) media types, and can be set to let different classes of users upload different numbers and types
  247. of media items to their albums. Module designers can add arbitrary screens to handle tasks like item
  248. rating, multi-stage uploads, and selling content. See the <a href='http://code.google.com/p/buddypress-media/wiki/AlbumModules'>Album Modules</a> wiki page.","bp-media") ?>
  249. </div>
  250. </div>
  251. <div class="parent_panel">
  252. <ul class="parent_nav">
  253. <?php
  254. // Build the navigation tabs
  255. foreach($album_modules as $album_module) {
  256. // Handle no module being selected, which happens on the first load of the admin page.
  257. if(!$selected_module){
  258. $selected_module = $album_module->getSlug();
  259. }
  260. if($album_module->getSlug() == $selected_module){
  261. $class = "tab_selected";
  262. $active_module = $album_module;
  263. }
  264. else {
  265. $class = "tab_default";
  266. }
  267. echo "\n\t\t<li class='" . $class . "'><a href='admin.php?page=bpm-album-modules&module=" . $album_module->getSlug() . "'>" . $album_module->getName() . "</a></li>";
  268. }
  269. unset($album_module);
  270. ?>
  271. </ul>
  272. <div id="<?php echo $active_module->getSlug();?>" class="module_panel" >
  273. <!-- Begin module header -->
  274. <div class="bpm_module_header">
  275. <div class ="icon">
  276. <img src='<?php echo $active_module->getIconPath() ?>' width='75' height='75' />
  277. </div>
  278. <div class="admin">
  279. <div class="title_block">
  280. <div class="title"><?php echo $active_module->getName() ?></div>
  281. </div>
  282. <div class="description">
  283. <?php echo $active_module->getDesc() ?>
  284. </div>
  285. <div class="footer">
  286. <span class="item"> <?php echo $active_module->getVersion() ?></span>
  287. <span class="spacer">|</span>
  288. <span class="item"> <?php echo $active_module->getAuthor() ?></span>
  289. <span class="spacer">|</span>
  290. <span class="item"> <?php echo $active_module->getSite() ?></span>
  291. </div>
  292. </div>
  293. </div>
  294. <?php
  295. $module_data = $bpm->albumModules->getBySlug($active_module->getSlug());
  296. if($module_data['active'] == true) {
  297. ?>
  298. <div class="bpm_module_status">
  299. <div class="message">
  300. <div class="icon_working"></div>
  301. <div class="text">Active</div>
  302. </div>
  303. <div class="detail">Module is available to users</div>
  304. </div>
  305. <?php
  306. }
  307. else {
  308. ?>
  309. <div class="bpm_module_status">
  310. <div class="message">
  311. <div class="icon_deactivated"></div>
  312. <div class="text">Deactivated</div>
  313. </div>
  314. <div class="detail">Module deactivated by admin</div>
  315. </div>
  316. <?php
  317. }
  318. ?>
  319. <div class="bpm_module_control">
  320. <div class="actions">
  321. <?php
  322. if($module_data['active'] == true) {
  323. ?>
  324. <a class="action"
  325. title="<?php _e("Make this module unavailable to users, and remove its page from the site", "bp-media"); ?>"
  326. href="<?php echo wp_nonce_url( $this->filepath . "&bpm_action=deactivate&module=" . $active_module->getSlug(), 'bpm_admin_settings'); ?>"
  327. >
  328. <?php _e("Deactivate Module", "bp-media"); ?>
  329. </a>
  330. <a class="action"
  331. title="<?php _e("Delete all uploaded content and reset configuration to default values"); ?>"
  332. href="<?php echo wp_nonce_url( $this->filepath . "&bpm_action=reset&module=" . $active_module->getSlug(), 'bpm_admin_settings'); ?>"
  333. >
  334. <?php _e("Reset Module", "bp-media"); ?>
  335. </a>
  336. <?php
  337. }
  338. else {
  339. ?>
  340. <a class="action"
  341. title="<?php _e("Make this module available for use", "bp-media"); ?>"
  342. href="<?php echo wp_nonce_url( $this->filepath . "&bpm_action=activate&module=" . $active_module->getSlug(), 'bpm_admin_settings'); ?>"
  343. >
  344. <?php _e("Activate Module", "bp-media"); ?>
  345. </a>
  346. <a class="action"
  347. title="<?php _e("Delete all uploaded content and completely remove this module from the system"); ?>"
  348. href="<?php echo wp_nonce_url( $this->filepath . "&bpm_action=reset&module=" . $active_module->getSlug(), 'bpm_admin_settings'); ?>"
  349. >
  350. <?php _e("Delete Module", "bp-media"); ?>
  351. </a>
  352. <?php
  353. }
  354. ?>
  355. </div>
  356. </div>
  357. <!-- End module header -->
  358. <!-- Begin module config page -->
  359. <div class="bpa_module_body">
  360. <?php echo $active_module->adminConfigPage() ?>
  361. </div>
  362. <!-- End module config page -->
  363. </div>
  364. </div>
  365. </div>
  366. <div class="bpm_footer"></div>
  367. <?php
  368. }
  369. } // End of class BPM_admin_page_albumModules
  370. ?>