public static function dispatch() { $pathInfo = self::getPathInfo(); foreach (self::$_routingTable as $key => $route) { if (preg_match($route['regx'], $pathInfo, $matches)) { self::$current = $key; try { $params = NULL; if (!empty($route['param'])) { unset($matches[0]); $params = array_combine($route['param'], $matches); } $widget = Widget::widget($route['widget'], NULL, $params); if (isset($route['action'])) { $method = $route['action']; $widget->{$method}(); } return; } catch (Exception $e) { if (404 == $e->getCode()) { Widget::destory($route['widget']); continue; } throw $e; } } } /** 载入路由异常支持 */ throw new HandleException("Path '{$pathInfo}' not found", 404); }
/** * Renders the frontend widget * * @param array $args Options provided at registration * @param array $data Database values provided in backend */ public function widget($args, $data) { $defaults = array('title' => 'Instagram', 'columns' => 2, 'username' => null, 'limit' => 4, 'before_content' => '', 'after_content' => ''); $data = array_merge($defaults, $data); // fetch feed $data['results'] = $this->getFeed($data['username'], $data['limit']); parent::widget($args, $data); }
/** * Renders the frontend social widget * * This widget uses a combination of theme options and widget settings. * * @param array $args Options provided at registration * @param array $data Database values provided in backend */ public function widget($args, $data) { $defaults = array('title' => null, 'twitter_limit' => null); $data = array_merge($defaults, $data); $twitteruser = $this->theme->options('twitter_user'); $twitterterm = $this->theme->options('twitter_search'); $facebookUser = $this->theme->options('facebook_user'); $tweets = $this->getTweets($twitterterm, $data['twitter_limit']); if (!empty($facebookUser)) { $facebookResults = $this->getFacebook($facebookUser); } else { $facebookResults = array(); } $this->theme->set(compact('tweets', 'facebookResults', 'facebookUser')); parent::widget($args, $data); }
/** * Renders the frontend core widget * * This widget uses the widget settings to pull CORE events. If those settings * are not defined, it falls back to the CORE meta for the page. If that isn't * defined, nothing is rendered. * * @param array $args Options provided at registration * @param array $data Database values provided in backend */ public function widget($args, $data) { global $post; $events = array(); $defaults = array('core_campus_id' => null, 'core_id' => null, 'core_involvement_id' => null, 'limit' => 0); $data = array_merge($defaults, $data); if (empty($data['core_id']) && empty($data['core_involvement_id'])) { $metadata = $this->theme->metaToData($post->ID); // If $metadata['limit'] not 0 or a positive integer ignore it if (!($metadata['limit'] === 0 || $metadata['limit'] > 0)) { $metadata['limit'] = $data['limit']; } $data = array_merge($data, $metadata); } if (empty($data['core_campus_id']) && empty($data['core_id']) && empty($data['core_involvement_id'])) { return; } // build url $endpoint = $this->getCoreCalendarEndpoint(); if (!empty($data['core_campus_id'])) { $endpoint .= '/Campus:' . $data['core_campus_id']; } if (!empty($data['core_id'])) { $endpoint .= '/Ministry:' . $data['core_id']; } if (!empty($data['core_involvement_id'])) { $endpoint .= '/Involvement:' . $data['core_involvement_id']; } $start = strtotime('now'); if (!empty($data['start_date'])) { $start = strtotime($data['start_date']); } $end = strtotime('+60 days', $start); if (!empty($data['end_date'])) { $end = strtotime($data['end_date']); } $endpoint .= '/full.json?start=' . $start . '&end=' . $end; $this->theme->set('url', $endpoint); $this->theme->set('limit', $data['limit']); parent::widget($args, $data); }
/** * Handle the shortcode * * @param array $attr Array of the attributes to the short code, none is expected * @param string $content The content enclosed in the shortcode, none is expected * * @return string An HTML of the "widget" based on its settings, actual or customized * */ function shortcode($attr, $content = null) { if (is_singular()) { $instance = shortcode_settings(); if (is_array($instance)) { $widget = new Widget(); $widget->number = 'shortcode-' . get_the_ID(); // needed to make a unique id for the widget html element ob_start(); $widget->widget(array('before_widget' => '', 'after_widget' => '', 'before_title' => '', 'after_title' => ''), $instance); $ret = ob_get_clean(); $ret = '<div id="' . WIDGET_BASE_ID . '-' . $widget->number . '" class="' . WIDGET_BASE_ID . '-shortcode">' . $ret . '</div>'; return $ret; } } return ''; }
/** * Renders the frontend widget * * This widget uses the widget settings to create a grid of images. * * @param array $args Options provided at registration * @param array $data Database values provided in backend */ public function widget($args, $data) { $defaults = array('columns' => 2, 'images' => array(), 'image_links' => array(), 'before_content' => '', 'after_content' => ''); $data = array_merge($defaults, $data); parent::widget($args, $data); }
<?php include_once "config.php"; Widget::widget('Init'); Router::dispatch();
public function widget($widget_name, $params = null, $return = false) { ob_start(); $widget = new Widget(); $widget->widget($widget_name, $params); $my_widget = ob_get_contents(); ob_clean(); if (!$return) { cout($my_widget); } else { return $my_widget; } }