/** * Last method to run if another methods not found * @param string $action */ public function _action($action) { if ($action == $this->_widgetAction) { $this->preloadWidgets(); $actions = $this->_relativeUri->getPath(); array_shift($actions); $widgetId = array_shift($actions); if ($widget = widgets::get($widgetId, false)) { $widget->setWidgetMode(); $widget->run(); exit; } else { widgets::dump(); echo '<hr />'; var_dump($this->_relativeUri->getPath()); throw new Exception('widget ' . $widgetId . ' not found at ' . $_SERVER['REQUEST_URI']); } //var_dump($this->_relativeUri); } return response::notFound(); }
/** * saves current widget data into the DB config * @param string $old_placeholder * @return boolean */ public function save($old_placeholder = NULL) { //stores $data array as json in the config. We need the placeholder? $save = array('class' => get_class($this), 'created' => time(), 'placeholder' => $this->placeholder, 'data' => $this->data); //since was not loaded we assume is new o generate a new name that doesn't exists if (!$this->loaded) { $this->widget_name = $this->gen_name(); } // save widget to DB $confw = new Model_Config(); $confw->where('group_name', '=', 'widget')->where('config_key', '=', $this->widget_name)->limit(1)->find(); if (!$confw->loaded()) { $confw->group_name = 'widget'; $confw->config_key = $this->widget_name; } $confw->config_value = json_encode($save); try { $confw->save(); //remove from previous placeholder, only if they are different if ($this->placeholder !== $old_placeholder and $old_placeholder !== NULL) { $confp = new Model_Config(); $confp->where('group_name', '=', 'placeholder')->where('config_key', '=', $old_placeholder)->limit(1)->find(); if ($confp->loaded()) { $confp->group_name = 'placeholder'; $confp->config_key = $old_placeholder; //remove the key $wid = json_decode($confp->config_value); $key = array_search($this->widget_name, $wid); if ($key !== FALSE) { unset($wid[$key]); } $confp->config_value = json_encode($wid); $confp->save(); } } //adding the widget to the placeholder //get widgets in the placeholder array $w_placeholders = widgets::get($this->placeholder, TRUE); //if name exists in placeholder don't change anything if (!in_array($this->widget_name, $w_placeholders)) { //if doesnt exists add it to the end and save $w_placeholders[] = $this->widget_name; // save palceholder to DB $confp = new Model_Config(); $confp->where('group_name', '=', 'placeholder')->where('config_key', '=', $this->placeholder)->limit(1)->find(); if (!$confp->loaded()) { $confp->group_name = 'placeholder'; $confp->config_key = $this->placeholder; } $confp->config_value = json_encode($w_placeholders); $confp->save(); } $this->loaded = TRUE; return TRUE; } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } return FALSE; }
<?php defined('SYSPATH') or die('No direct script access.'); ?> <hr> <footer> <div class="row"> <?php foreach (widgets::get('footer') as $widget) { ?> <div class="col-md-3"> <?php echo $widget->render(); ?> </div> <?php } ?> </div> <!--This is the license for Open Classifieds, do not remove --> <div class="center-block"> <p>© <?php if (Theme::get('premium') != 0) { ?> Web Powered by <a href="http://open-classifieds.com?utm_source=<?php echo URL::base(); ?> &utm_medium=oc_footer&utm_campaign=<?php
/** * returns placeholders names + widgets * @param bool $only_names, returns only an array with the placeholders names, if not array with widgets instances * @return array */ public static function get_placeholders($only_names = FALSE) { $placeholders = array(); $list = array_unique(array_merge(widgets::$default_placeholders, widgets::$theme_placeholders)); //This is a forced placeholders for those widgets that we don't want to lose. $list[] = 'inactive'; if ($only_names) { return $list; } //get the widgets for the placeolders foreach ($list as $placeholder) { $placeholders[$placeholder] = widgets::get($placeholder); } return $placeholders; }
<?php defined('SYSPATH') or die('No direct script access.'); ?> <div class="col-md-3 col-sm-12 col-xs-12"> <?php foreach (widgets::get('sidebar') as $widget) { ?> <?php if (get_class($widget) != 'Widget_Contact') { ?> <div class="category_box_title custom_box"> </div> <div class="well custom_box_content" > <?php echo $widget->render(); ?> </div> <?php } else { ?> <?php if (Request::current()->controller() == 'ad' and Request::current()->action() == 'view') { ?> <div class="category_box_title custom_box"> </div> <div class="well custom_box_content" > <?php echo $widget->render(); ?> </div>