Example #1
0
/**
 * Loads an action box css and js assets. Uses wp_enqueue_* api
 * @param  int $mabid ID of the action box
 * @return void
 */
function mab_load_actionbox_assets($mabid)
{
    if (empty($mabid)) {
        return;
    }
    $actionBox = new MAB_ActionBox($mabid);
    $actionBox->loadAssets();
}
Example #2
0
 /**
  * Returns an action box object
  *
  * @param $id ID of the action box to get
  * @return MAB_ActionBox|null null if action box does not exist.
  */
 public static function get($id)
 {
     $mab = new MAB_ActionBox($id);
     if (!$mab->isConfigured()) {
         return null;
     } else {
         return $mab;
     }
 }
Example #3
0
function mab_process_wysija_optin_submit($result, $data)
{
    if (!class_exists('WYSIJA_object')) {
        MAB_Ajax::addMessage(__('MailPoet is not set up properly: WYSIJA_object does not exist.', 'mab'));
        return false;
    }
    if (empty($data['email']) || !is_email($data['email'])) {
        MAB_Ajax::addMessage(__('Invalid email address.', 'mab'));
        return false;
    }
    if (empty($data['lists'])) {
        MAB_Ajax::addMessage(__('Email list is not set.', 'mab'));
        return false;
    }
    $list['list_ids'] = explode(',', $data['lists']);
    $user = array();
    $user['email'] = $data['email'];
    if (!empty($data['fname'])) {
        $user['firstname'] = $data['fname'];
    }
    if (!empty($data['lname'])) {
        $user['lastname'] = $data['lname'];
    }
    $subscriber = array('user' => $user, 'user_list' => $list);
    if (!empty($data['mabid'])) {
        $actionBox = MAB_ActionBox::get($data['mabid']);
        if (!$actionBox) {
            MAB_Ajax::addMessage('Action box does not exist.');
            return false;
        }
    }
    $result = WYSIJA::get('user', 'helper')->addSubscriber($subscriber);
    if (false === $result) {
        MAB_Ajax::addMessage(__('Email signup failed.', 'mab'));
        return false;
    }
    $meta = $actionBox->getMeta();
    if (!empty($meta['optin']['wysija']['success-message'])) {
        MAB_Ajax::addMessage(wp_kses_post($meta['optin']['wysija']['success-message']));
    }
    if (!empty($meta['optin']['redirect'])) {
        return array('redirect' => esc_url($meta['optin']['redirect']));
    }
    return true;
}
Example #4
0
    function widget($args, $instance)
    {
        extract($args);
        $unique_id = $args['widget_id'];
        $title = $instance['title'];
        $action_box_id = isset($instance['actionbox-id']) ? $instance['actionbox-id'] : false;
        $force_stacked = !empty($instance['force-stacked']) ? true : false;
        $textdomain = $this->textdomain;
        ?>
		<?php 
        echo $before_widget;
        ?>
		
		<?php 
        /* If a title was input by the user, display it. */
        if (!empty($title)) {
            echo $before_title . apply_filters('widget_title', $title, $instance, $this->id_base) . $after_title;
        }
        ?>
		
		<div class="mab-inside-wrap">
		<?php 
        if ($action_box_id === false) {
            ?>
			<!-- display notice -->
			Magic Action Box widget not configured correctly. Please select an action box to display from the <a href="<?php 
            echo admin_url('widgets.php');
            ?>
">widgets settings</a>.
		<?php 
        } else {
            ?>
			
			<?php 
            $actionBoxObj = new MAB_ActionBox($action_box_id);
            if ($force_stacked) {
                $actionBoxObj->removeClass('mab-fields-layout-default');
                $actionBoxObj->removeClass('mab-fields-layout-bytwo');
                $actionBoxObj->removeClass('mab-fields-layout-bythree');
                $actionBoxObj->removeClass('mab-fields-layout-byfour');
                $actionBoxObj->addClass('mab-fields-layout-stacked');
            }
            echo $actionBoxObj->getActionBox(null, true);
            ?>
			
		<?php 
        }
        ?>
		</div>
		
		<?php 
        echo $after_widget;
        ?>
		
	<?php 
    }
Example #5
0
	<select id="mab-post-action-box" class="large-text" name="mabpostmeta[post-action-box]" >
		<?php 
$selected_action_box = isset($meta['post-action-box']) ? $meta['post-action-box'] : 'default';
?>
		<option value="none" <?php 
selected($selected_action_box, 'none');
?>
 >Disable</option>
		<option value="default" <?php 
selected($selected_action_box, 'default');
?>
 >Use Default</option>
		<?php 
//Get action boxes available
$action_boxes_obj = get_posts(array('numberposts' => -1, 'orderby' => 'title date', 'post_type' => $MabBase->get_post_type()));
foreach (MAB_ActionBox::getAll() as $action_box) {
    ?>
			<option value="<?php 
    echo $action_box->ID;
    ?>
" <?php 
    selected($selected_action_box, $action_box->ID);
    ?>
 ><?php 
    echo $action_box->post_title;
    ?>
</option>
		<?php 
}
?>
	</select>
Example #6
0
 function debugBox($post)
 {
     $actionBox = MAB_ActionBox::get($post->ID);
     if (is_null($actionBox)) {
         $data['meta'] = array();
     } else {
         $data['meta'] = $actionBox->getMeta();
     }
     $filename = 'metaboxes/debug.php';
     echo MAB_Utils::getView($filename, $data);
 }
Example #7
0
 function displayStyleSettingsPage()
 {
     global $mabStyleKey;
     $MabBase = MAB();
     $MabDesign = MAB('design');
     $data = array();
     $key = isset($_GET['mab-style-key']) ? absint($_GET['mab-style-key']) : null;
     $mabStyleKey = $key;
     if ($key !== null && $this->isValidStyleKey($key)) {
         //edit a style
         $style = $MabDesign->getConfiguredStyle($key);
         $action = 'edit';
     } else {
         //add new style
         $style = $MabDesign->getDefaultSettings();
         $action = 'add';
     }
     //TODO: add reset?
     $data['key'] = $key;
     $data['settings'] = $style;
     $data['action'] = $action;
     $data['actionboxes'] = MAB_ActionBox::getAll();
     $data['base-styles'] = ProsulumMabDesign::baseStyles();
     $filename = $this->getSettingsViewTemplate('style-settings');
     $output = ProsulumMabCommon::getView($filename, $data);
     echo $output;
 }
Example #8
0
 /**
  * Use to dynamically load action boxes via ajax
  * @return array['result'] the action box HTML
  *         array['msgs'] Any messages
  *         array['css'] array of css objects
  *         array['js'] array of js objects
  */
 public function getActionBox()
 {
     $resultArray = array('html' => '', 'error' => false, 'css' => array(), 'js' => array());
     $this->log('AJAX request payload: ' . print_r($_GET, true), 'debug');
     if (empty($_GET['id'])) {
         self::addMessage(__('ID is invalid.', 'mab'));
         $resultArray['error'] = true;
         $resultArray['msgs'] = $this->getMessages();
         self::response($resultArray);
     }
     $result = array();
     $id = $_GET['id'];
     $actionBox = MAB_ActionBox::get($id);
     // action box does not exist
     if (is_null($actionBox)) {
         $resultArray['error'] = true;
         self::addMessage('Action box does not exist with ID ' . $id);
         $resultArray['msgs'] = $this->getMessages();
         self::response($resultArray);
     }
     $html = $actionBox->getActionBox();
     // action box is empty? respond but do not set error
     if (empty($html)) {
         self::response($resultArray);
     }
     $resultArray['html'] = $html;
     /**
      * The following is possible because we are doing ajax.
      * No other script/styles is enqueued
      */
     global $wp_styles, $wp_scripts;
     $actionBox->loadAssets();
     // this will fill $wp_styles and $wp_scripts
     $wp_styles->all_deps($wp_styles->queue);
     $wp_scripts->all_deps($wp_scripts->queue);
     $styles = array();
     $scripts = array();
     $jsToIgnore = array('jquery', 'jquery-migrate', 'jquery-core');
     $cssToIgnore = array();
     $wp_styles->do_concat = true;
     foreach ($wp_styles->to_do as $style) {
         if (in_array($style, $cssToIgnore)) {
             continue;
         }
         $cssObj = $wp_styles->registered[$style];
         $wp_styles->print_html = '';
         $wp_styles->do_item($style);
         $cssObj->html = trim($wp_styles->print_html);
         $styles[] = $cssObj;
     }
     $wp_scripts->do_concat = true;
     foreach ($wp_scripts->to_do as $script) {
         if (in_array($script, $jsToIgnore)) {
             continue;
         }
         $jsObj = $wp_scripts->registered[$script];
         $wp_scripts->print_html = '';
         $wp_scripts->do_item($script);
         $jsObj->html = trim($wp_scripts->print_html);
         $scripts[] = $jsObj;
     }
     $resultArray['css'] = $styles;
     $resultArray['js'] = $scripts;
     self::response($resultArray);
 }