Exemplo n.º 1
0
 public static function get_layout($layout_ids, $apply = false)
 {
     $layout = Upfront_Layout::from_entity_ids($layout_ids);
     if ($layout->is_empty()) {
         $layout = Upfront_Layout::create_layout($layout_ids);
     }
     $post_id = is_singular() ? get_the_ID() : '';
     $post = get_post($post_id);
     self::$_instance = new self($layout, $post);
     // Add actions
     add_action('wp_enqueue_scripts', array(self::$_instance, 'add_styles'));
     add_action('wp_enqueue_scripts', array(self::$_instance, 'add_scripts'), 2);
     // Do the template...
     if ($apply) {
         return self::$_instance->apply_layout();
     }
     return self::$_instance;
 }
Exemplo n.º 2
0
 function update_layout_element()
 {
     if (!Upfront_Permissions::current(Upfront_Permissions::SAVE)) {
         $this->_reject();
     }
     $data = !empty($_POST) ? stripslashes_deep($_POST) : false;
     if (!$data) {
         return $this->_out(new Upfront_JsonResponse_Error("No data"));
     }
     if (empty($data['layout'])) {
         return $this->_out(new Upfront_JsonResponse_Error("No layout id given"));
     }
     if (empty($data['element'])) {
         return $this->_out(new Upfront_JsonResponse_Error("No element data given"));
     }
     $element = json_decode($data['element'], true);
     $layout = Upfront_Layout::from_entity_ids($data['layout'], $data['storage_key']);
     if (empty($layout)) {
         return $this->_out(new Upfront_JsonResponse_Error("Unkown layout"));
     }
     $updated = $layout->set_element_data($element);
     if (!$updated) {
         return $this->_out(new Upfront_JsonResponse_Error("Error updating the layout"));
     }
     $layout->save();
     $this->_out(new Upfront_JsonResponse_Success("Layout updated"));
 }
Exemplo n.º 3
0
/**
 * Run first on each AJAX action registered with upfront_add_ajax
 */
function upfront_ajax_init()
{
    $stylesheet = $layout_ids = $storage_key = $load_dev = false;
    // Automatically instantiate Upfront_Layout object
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        $layout_ids = !empty($_POST['layout']) ? $_POST['layout'] : false;
        $storage_key = !empty($_POST['storage_key']) ? $_POST['storage_key'] : false;
        $stylesheet = !empty($_POST['stylesheet']) ? $_POST['stylesheet'] : false;
        $load_dev = !empty($_POST['load_dev']) && $_POST['load_dev'] == 1 ? true : false;
    } else {
        if (isset($_GET['layout'])) {
            $layout_ids = !empty($_GET['layout']) ? $_GET['layout'] : false;
            $storage_key = !empty($_GET['storage_key']) ? $_GET['storage_key'] : false;
            $stylesheet = !empty($_GET['stylesheet']) ? $_GET['stylesheet'] : false;
            $load_dev = !empty($_GET['load_dev']) && $_GET['load_dev'] == 1 ? true : false;
        }
    }
    if ($stylesheet === false) {
        $stylesheet = apply_filters('upfront_get_stylesheet', $stylesheet);
    }
    upfront_switch_stylesheet($stylesheet);
    if (!is_array($layout_ids)) {
        return;
    }
    $layout = Upfront_Layout::from_entity_ids($layout_ids, $storage_key, $load_dev);
    if ($layout->is_empty()) {
        $layout = Upfront_Layout::create_layout($layout_ids);
    }
}
Exemplo n.º 4
0
 function save_resizing()
 {
     $data = stripslashes_deep($_POST);
     $layout = Upfront_Layout::from_entity_ids($data['layout']);
     return $this->_out(new Upfront_JsonResponse_Success($layout->get_element_data('uslider-object-1388746230599-1180')));
 }
Exemplo n.º 5
0
 private function get_settings_from_ajax()
 {
     $entity_ids = array();
     try {
         $entity_ids = (array) json_decode(base64_decode($_POST['entity_ids']));
     } catch (Exception $e) {
         return false;
     }
     $storage_key = false;
     if (isset($entity_ids['storage_key'])) {
         $storage_key = $entity_ids['storage_key'];
         unset($entity_ids['storage_key']);
     }
     $layout = Upfront_Layout::from_entity_ids($entity_ids, $storage_key);
     if ($layout instanceof Upfront_Layout) {
         $layout = $layout->to_php();
     } else {
         return false;
     }
     $settings = array();
     if (is_array($layout['regions'])) {
         foreach ($layout['regions'] as $region) {
             if (sizeof($region['modules'])) {
                 foreach ($region['modules'] as $module) {
                     if (sizeof($module['objects'])) {
                         foreach ($module['objects'] as $object) {
                             if (sizeof($object['properties'])) {
                                 foreach ($object['properties'] as $prop) {
                                     if ($prop['name'] == 'element_id' && $prop['value'] == $_POST['contactformid']) {
                                         return $object;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return false;
 }
    function upfront_template_helper_admin_page()
    {
        $specificity = $_POST["template"];
        $json_data = array();
        $codeOutput = "";
        $storageKey = "";
        if ($specificity != "") {
            $layout_ids = array('specificity' => $specificity);
            $layout = Upfront_Layout::from_entity_ids($layout_ids);
            $storageKey = $layout->get_storage_key();
            //		$layout_data = $layout->to_php();
            //		$properties = $layout->get_layout_properties();
            $regionNames = array();
            $regionForm = "";
            // EDIT:: I have changed it to load directly from the database because the Upfront classes merge data with global settings and it causes trouble
            $json_data = json_decode(get_option($storageKey . '-' . $specificity, json_encode(array())), true);
            foreach ($json_data["regions"] as $region) {
                $regionNames[$region["name"]] = $region["title"];
                $regionForm .= '<div class="region-check"><label for="' . $region["name"] . '">' . $region["title"] . '</label><input type="checkbox" id="' . $region["name"] . '" name="' . $region["name"] . '"> </div>
			';
            }
            $exportRegionNames = array();
            foreach ($_POST as $key => $value) {
                if ($value == 'on') {
                    $exportRegionNames[] = $key;
                }
            }
            $exportRegions = array();
            foreach ($json_data["regions"] as $region) {
                if (in_array($region["name"], $exportRegionNames)) {
                    $exportRegions[] = $region;
                }
            }
            $codeOutput = "";
            // create php output
            // create region args & properties
            //
            foreach ($exportRegions as $region) {
                $properties = $region["properties"];
                $modules = $region["modules"];
                $wrappers = $region["wrappers"];
                //unset($region["properties"]);
                //unset($region["modules"]);
                //unset($region["wrappers"]);
                $codeOutput .= '$' . str_replace("-", "_", $region["name"]) . ' = new Upfront_Virtual_Region_From_Existing(' . var_export($region, true) . ');
';
                // this doesn't work becuase it is expecting values to build its own wrappers, not pre-exisiting wrappers
                //				foreach($modules as $module)
                //				{
                //					$codeOutput .= '$'.str_replace("-","_",$region["name"]).'->add_element('.var_export($module,true).');
                //';
                //				}
                $codeOutput .= '$regions->add($' . str_replace("-", "_", $region["name"]) . ');
';
            }
            $codeOutput = highlight_string($codeOutput, true);
        }
        ?>
		<script>hljs.initHighlightingOnLoad();</script>
		<h2>Regions in this menu</h2>
		<form method="post" action="admin.php?page=upfront-template-helper">

			<table class="form-table">
				<tr>
					<td><label for="template-specificity">Template:</label></td>
					<td><input type="text" id="template-specificity" name="template" class="regular-text"  value="<?php 
        echo $specificity;
        ?>
"></td>
				</tr>
				<tr>
					<td>
						<p class="submit">
							<input type="submit" id="submit" class="button button-primary" value="Load Data">
						</p>
					</td>
				</tr>
			</table>
			<label for="template-specificity">

			</label>
		</form>
		<table class="widefat">
			<thead>
			<tr>
				<th class="row-title">Attribute</th>
				<th>Value</th>
			</tr>
			</thead>
			<tbody>
			<tr>
				<td class="row-title"><label for="tablecell">Template: </label></td>
				<td><?php 
        echo $specificity;
        ?>
 </td>
			</tr>
			<tr>
				<td class="row-title"><label for="tablecell">Storage Key: </label></td>
				<td><?php 
        echo $storageKey;
        ?>
 </td>
			</tr>
			<tr>
				<td class="row-title"><label for="tablecell">Regions: </label></td>
				<td><?php 
        echo count($json_data["regions"]);
        ?>
 </td>
			</tr>
			<tr>
				<td class="row-title"><label for="tablecell">Properties: </label></td>
				<td><?php 
        echo count($json_data["properties"]);
        ?>
 </td>
			</tr>
			<tr>
				<td class="row-title"><label for="tablecell">Wrappers: </label></td>
				<td><?php 
        echo count($json_data["wrappers"]);
        ?>
 </td>
			</tr>
			</tbody>
		</table>
		<style>
			.region-check{
				display: inline-block;
				margin: 5px;
				padding: 5px;
				background-color: #fff;
			}
			.upfront-regions > div > input[type="checkbox"]{
				margin-left: 5px;
				vertical-align: middle;
			}
			.upfront-regions > div > label{
				margin: 5px;
				padding:2px;
			}
			.upfront-regions{

			}
		</style>
		<form class="upfront-regions" action="admin.php?page=upfront-template-helper" method="post">
			<input type="hidden" name="template" value="<?php 
        echo $specificity;
        ?>
">
			<?php 
        echo $regionForm;
        ?>
			<div><input class="button button-secondary" type="submit" id="submit" value="Export"></div>
		</form>
		<div>
			<pre class="php">
			<?php 
        echo $codeOutput;
        ?>
			</pre>
		</div>
		<?php 
    }