/core/admin/page_album_modules/loader.php
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
- <?php
- /**
- * BP-MEDIA SCREEN RENDERING CLASS "ADMIN-> ALBUM MODULES"
- * Generates the admin screen "Album Modules" page. Handles form submissions. Updates global config variable and
- * stored settings in database when parameters are changed.
- *
- * @version 0.1.9
- * @since 0.1.9
- * @package BP-Media
- * @subpackage Admin
- * @license GPL v2.0
- * @link http://code.google.com/p/buddypress-media/
- *
- * ========================================================================================================
- */
- // Prevent hackers from directly calling this page
- if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) {
- die('You are not allowed to call this page directly.');
- }
- // Include all of the admin base page base classes
- // ===============================================================================================
- $base_page_classes = glob( BPM_PATH_BASE .'/core/album_modules/admin_base/*.php');
- foreach ( $base_page_classes as $path ){
- if( file_exists($path) ){
- include_once ($path);
- }
- }
- // ============================================================================================================ //
- class BPM_admin_page_albumModules extends BPM_admin_page_base {
- /**
- * Listens for form submission and triggers form processor function
- *
- * @version 0.1.9
- * @since 0.1.9
- */
- function __construct() {
- $this->filepath = admin_url() . 'admin.php?page=' . $_GET['page'];
- $this->page = $_GET['page'];
- }
- /**
- * Enqueues the selected tab's scripts in the page header
- *
- * @version 0.1.9
- * @since 0.1.9
- */
- public function enqueueScripts() {
- // Load scripts used by all tabs on this page
- // ======================================================
- wp_enqueue_script( 'bpm-adminNotifier');
- global $bpm;
- $bpm->albumModules->loadAdminScripts();
- }
- /**
- * Enqueues the selected tab's styles in the page header
- *
- * @version 0.1.9
- * @since 0.1.9
- */
- public function enqueueStyles() {
- // Load styles used by all tabs on this page
- // ======================================================
- wp_enqueue_style( 'bpm-admin', BPM_URL_CORE .'/admin/css/bpm.admin.css', false, '2.8.1', 'screen' );
- wp_enqueue_style( 'bpm-tabs-v', BPM_URL_CORE .'/admin/css/bpm.tabs.v.css', false, '2.5.0', 'screen' );
- wp_enqueue_style( 'bpm-ui-base', BPM_URL_LIB .'/jquery/ui/css/jquery.ui.base.css', false, '2.8.1', 'screen');
- wp_enqueue_style( 'bpm-ui-theme', BPM_URL_CORE .'/admin/css/bpm.ui.theme.css', false, '2.8.1', 'screen' );
- wp_enqueue_style( 'bpm-album-modules', BPM_URL_CORE .'/admin/css/bpm.album.modules.css', false, '2.8.1', 'screen' );
- global $bpm;
- $bpm->albumModules->loadAdminStyles();
- }
- /**
- * Processes module configuration settings while preventing one module from overwriting another module's settings.
- *
- * Accepts data from a submitted admin settings form. Uses variables list in hidden 'page_options' form field
- * to determine which fields to load from the form. Updates each $bp->bpa->options['media_module'settings'][$module_class][$option]
- * on the form in the global $bp->bpa->options variable, then writes the $bp->bpa->options variable to the database.
- *
- * @TODO Add error checking, sanitizing eg: $value = sanitize_option($option, $value), etc. At present bad
- * user input can crash the plugin and damage the database.
- * @version 0.1.9
- * @since 0.1.9
- */
- function processor() {
- global $bpm;
- // CASE 1 - User is updating an album module's configuration settings
- // =================================================================================================================
- if ( isset($_POST['updateoption']) ) {
- check_admin_referer('bpm_admin_settings');
- if( current_user_can('install_plugins') ){
- // Save options and show user if update was successful
-
- try {
-
- $bpm->config->processHTMLForm($_POST);
-
- ?>
- <script type="text/javascript">
- jQuery(document).ready(function(){
- jQuery.bpm_admin_notify.add({
- title: "<?php _e("Settings Updated", "bp-media"); ?>",
- text: "<?php _e("BP-Media has updated the album module's settings", "bp-media"); ?>",
- image: "<?php echo BPM_URL_CORE . '/admin/css/images/bpm_admin_notify_success.png' ?>"
- });
- });
- </script>
- <?php
-
- }
- catch (BPM_exception $fail) {
-
- ?>
- <script type="text/javascript">
- jQuery(document).ready(function(){
- jQuery.bpm_admin_notify.add({
- title: "<?php _e("Update Error", "bp-media"); ?>",
- text: "<?php _e("Error updating the album module's settings", "bp-media"); ?>",
- image: "<?php echo BPM_URL_CORE . '/admin/css/images/bpm_admin_notify_fail.png' ?>"
- });
- });
- </script>
- <?php
- }
- }
- else {
- die("You do not have security clearance to do this");
- }
- }
- // CASE 2 - User is updating a album module's configuration settings
- // =================================================================================================================
- elseif( isset($_POST['admin_ajax_form']) ) {
- check_admin_referer('bpm_admin_ajax');
- $media_modules = BPM_Multimedia::get_registered_media_modules();
- $module_class = trim($_POST['module_class']);
- // Check that the media module class posted in the form actually exists
- if( in_array($module_class, $media_modules) ) {
- call_user_func(array($module_class,'admin_ajaxForm'));
- }
- else {
- echo "You are attempting to save AJAX form data for a media module that is not currently loaded\n";
- BPM_debug::dump($_POST);
- die;
- }
- }
- // CASE 3 - User is enabling, disabling, or resetting a album module
- // =================================================================================================================
- elseif( isset($_GET['bpm_action']) ){ ;
- check_admin_referer('bpm_admin_settings');
- if( $_GET['bpm_action'] == 'activate'){
- $san = new BPM_sanitize();
- $module_slug = $san->slug($_GET['module'], null, $valid);
- if($valid){
- $activate_ok = $bpm->albumModules->activateBySlug($module_slug);
- }
- if($valid && $activate_ok){
- ?>
- <script type="text/javascript">
- jQuery(document).ready(function(){
- jQuery.bpm_admin_notify.add({
- title: "<?php _e("Album Module Activated", "bp-media"); ?>",
- text: "<?php _e("BP-Media has successfully activated the album module.", "bp-media"); ?>",
- image: "<?php echo BPM_URL_CORE . '/admin/css/images/bpm_admin_notify_success.png' ?>"
- });
- });
- </script>
- <?php
- }
- else {
- ?>
- <script type="text/javascript">
- jQuery(document).ready(function(){
- jQuery.bpm_admin_notify.add({
- title: "<?php _e("Album Module Error", "bp-media"); ?>",
- text: "<?php _e("Error activating the album module.", "bp-media"); ?>",
- image: "<?php echo BPM_URL_CORE . '/admin/css/images/bpm_admin_notify_fail.png' ?>"
- });
- });
- </script>
- <?php
- }
- }
- if( $_GET['bpm_action'] == 'deactivate'){
- $san = new BPM_sanitize();
- $module_slug = $san->slug($_GET['module'], null, $valid);
- if($valid){
- $activate_ok = $bpm->albumModules->deactivateBySlug($module_slug);
- }
- if($valid && $activate_ok){
- ?>
- <script type="text/javascript">
- jQuery(document).ready(function(){
- jQuery.bpm_admin_notify.add({
- title: "<?php _e("Album Module Dectivated", "bp-media"); ?>",
- text: "<?php _e("BP-Media has successfully deactivated the album module.", "bp-media"); ?>",
- image: "<?php echo BPM_URL_CORE . '/admin/css/images/bpm_admin_notify_success.png' ?>"
- });
- });
- </script>
- <?php
- }
- else {
- ?>
- <script type="text/javascript">
- jQuery(document).ready(function(){
- jQuery.bpm_admin_notify.add({
- title: "<?php _e("Album Module Error", "bp-media"); ?>",
- text: "<?php _e("Error deactivating the album module.", "bp-media"); ?>",
- image: "<?php echo BPM_URL_CORE . '/admin/css/images/bpm_admin_notify_fail.png' ?>"
- });
- });
- </script>
- <?php
- }
- }
- if( $_GET['bpm_action'] == 'reset'){
- }
- }
- }
- /**
- * Renders all tabs on the admin screen "Content" page
- *
- * Prints the jQuery configuration code to the HTML stream. Uses entries in the $tabs array to iterate through
- * the tab rendering functions inside the class. Each tab rendering function writes HTML for one tab to the
- * HTML stream, encapsulated for jQuery.
- *
- * @version 0.1.9
- * @since 0.1.9
- */
- function render() {
- global $bp, $bpm;
- // If a form is submitted with data, run the processor function.
- if ( !empty($_POST) || isset($_GET['bpm_action']) ){
- $this->processor();
- }
- $selected_module = $bpm->albumModules->getSelectedModule();
- $album_modules = $bpm->albumModules->getAdminModules();
- ?>
- <script type="text/javascript">
- jQuery(document).ready(function(){
- <?php // Adds row-striping to our tables ////////////////////////// ?>
- jQuery('table.form-table tbody tr:even').addClass('alt');
- });
- </script>
- <div class="bpm_header_small"></div>
- <div class="tabs_v">
- <div class="bpm_section_intro">
- <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>
- <div class="title">
- <?php _e('Album Modules',"bp-media") ?>
- </div>
- <div class="details">
- <?php _e("Album modules control the structure, content, and layout of user albums.They can
- hold one (or many) media types, and can be set to let different classes of users upload different numbers and types
- of media items to their albums. Module designers can add arbitrary screens to handle tasks like item
- 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") ?>
- </div>
- </div>
- <div class="parent_panel">
- <ul class="parent_nav">
- <?php
- // Build the navigation tabs
- foreach($album_modules as $album_module) {
- // Handle no module being selected, which happens on the first load of the admin page.
- if(!$selected_module){
- $selected_module = $album_module->getSlug();
- }
- if($album_module->getSlug() == $selected_module){
- $class = "tab_selected";
- $active_module = $album_module;
- }
- else {
- $class = "tab_default";
- }
- echo "\n\t\t<li class='" . $class . "'><a href='admin.php?page=bpm-album-modules&module=" . $album_module->getSlug() . "'>" . $album_module->getName() . "</a></li>";
- }
- unset($album_module);
- ?>
- </ul>
- <div id="<?php echo $active_module->getSlug();?>" class="module_panel" >
- <!-- Begin module header -->
- <div class="bpm_module_header">
- <div class ="icon">
- <img src='<?php echo $active_module->getIconPath() ?>' width='75' height='75' />
- </div>
- <div class="admin">
- <div class="title_block">
- <div class="title"><?php echo $active_module->getName() ?></div>
- </div>
- <div class="description">
- <?php echo $active_module->getDesc() ?>
- </div>
- <div class="footer">
- <span class="item"> <?php echo $active_module->getVersion() ?></span>
- <span class="spacer">|</span>
- <span class="item"> <?php echo $active_module->getAuthor() ?></span>
- <span class="spacer">|</span>
- <span class="item"> <?php echo $active_module->getSite() ?></span>
- </div>
- </div>
- </div>
- <?php
- $module_data = $bpm->albumModules->getBySlug($active_module->getSlug());
- if($module_data['active'] == true) {
- ?>
- <div class="bpm_module_status">
- <div class="message">
- <div class="icon_working"></div>
- <div class="text">Active</div>
- </div>
- <div class="detail">Module is available to users</div>
- </div>
- <?php
- }
- else {
- ?>
- <div class="bpm_module_status">
- <div class="message">
- <div class="icon_deactivated"></div>
- <div class="text">Deactivated</div>
- </div>
- <div class="detail">Module deactivated by admin</div>
- </div>
- <?php
- }
- ?>
- <div class="bpm_module_control">
- <div class="actions">
- <?php
- if($module_data['active'] == true) {
- ?>
- <a class="action"
- title="<?php _e("Make this module unavailable to users, and remove its page from the site", "bp-media"); ?>"
- href="<?php echo wp_nonce_url( $this->filepath . "&bpm_action=deactivate&module=" . $active_module->getSlug(), 'bpm_admin_settings'); ?>"
- >
- <?php _e("Deactivate Module", "bp-media"); ?>
- </a>
- <a class="action"
- title="<?php _e("Delete all uploaded content and reset configuration to default values"); ?>"
- href="<?php echo wp_nonce_url( $this->filepath . "&bpm_action=reset&module=" . $active_module->getSlug(), 'bpm_admin_settings'); ?>"
- >
- <?php _e("Reset Module", "bp-media"); ?>
- </a>
- <?php
- }
- else {
- ?>
- <a class="action"
- title="<?php _e("Make this module available for use", "bp-media"); ?>"
- href="<?php echo wp_nonce_url( $this->filepath . "&bpm_action=activate&module=" . $active_module->getSlug(), 'bpm_admin_settings'); ?>"
- >
- <?php _e("Activate Module", "bp-media"); ?>
- </a>
- <a class="action"
- title="<?php _e("Delete all uploaded content and completely remove this module from the system"); ?>"
- href="<?php echo wp_nonce_url( $this->filepath . "&bpm_action=reset&module=" . $active_module->getSlug(), 'bpm_admin_settings'); ?>"
- >
- <?php _e("Delete Module", "bp-media"); ?>
- </a>
- <?php
- }
- ?>
- </div>
- </div>
- <!-- End module header -->
- <!-- Begin module config page -->
- <div class="bpa_module_body">
- <?php echo $active_module->adminConfigPage() ?>
- </div>
- <!-- End module config page -->
- </div>
- </div>
- </div>
- <div class="bpm_footer"></div>
- <?php
- }
- } // End of class BPM_admin_page_albumModules
- ?>