public function init() { $this->manager = new Widget_Manager(); $this->oLogManager = new Log_LogsManager(); $this->oLogManager->push('ip', $this->request->getIp()); $this->oLogManager->push('addtime', time()); $this->oLogManager->push('manager_id', $this->manager->id); $this->oLogManager->push('name', $this->manager->name); $this->oLogManager->push('url', $this->request->getServer('REQUEST_URI')); $this->oLogManager->push('referer', $this->request->getReferer() ? $this->request->getReferer() : 'referer'); $this->oLogManager->push('agent', $this->request->getAgent()); $config = @(include Base_Common::$config['config_file']); $appConfig = @(include dirname(dirname(__FILE__)) . '/etc/config.php'); is_array($appConfig) && ($config = $config + $appConfig); $this->config = Base_Config::factory($config); $this->notice = Base_Notice::getInstance(); if ($this->needLogin && !$this->manager->isLogin()) { $this->response->redirect($this->manager->loginUrl); } //@todo:这里的强制修改密码最好能在登录成功的时候执行 if (!$this instanceof ModifyPwdController && !$this instanceof LoginController) { // if($this->manager->reset_password) // { // $this->response->redirect('?ctl=modify.pwd&ac=compel.repwd'); // exit; // } } }
public function action_index() { $id = (int) $this->request->param('id'); Observer::notify('handler_requested', $id); $widget = Widget_Manager::load($id); if ($widget === NULL or !$widget->is_handler()) { $this->go_home(); } $widget->run(); }
public function type() { $widget_types = Widget_Manager::map(); $type = $this->type; foreach ($widget_types as $group => $types) { if (isset($types[$type])) { $type = $types[$type]; } } return $type; }
public function action_forgot() { if ($this->request->method() == Request::POST) { $this->auto_render = FALSE; $widget = Widget_Manager::factory('User_Forgot'); Context::instance()->set('email', Arr::path($this->request->post(), 'forgot.email')); $widget->set_values(array('next_url' => Route::get('user')->uri(array('action' => 'login'))))->on_page_load(); } $this->set_title(__('Forgot password')); $this->template->content = View::factory('system/forgot'); }
/** * * @param string $type * @return Model_Widget_Decorator_Dashboard */ public static function add_widget($type, array $data = NULL, $user_id = NULL) { $widget_settings = Model_User_Meta::get(self::WIDGET_SETTINGS_KEY, array(), $user_id); $widget = Widget_Manager::factory($type); $widget->id = uniqid(); if ($data !== NULL) { $widget->set_values($data); } $widget_settings[$widget->id] = $widget; Model_User_Meta::set(self::WIDGET_SETTINGS_KEY, $widget_settings, $user_id); return $widget; }
public function post_set_template() { $widget_id = (int) $this->param('widget_id', NULL, TRUE); $template = $this->param('template', NULL); $widget = Widget_Manager::load($widget_id); if ($widget !== NULL) { $widget->template = empty($template) ? NULL : $template; Widget_Manager::update($widget); $this->message('Widget template changet to :name', array(':name' => $template)); $this->response(TRUE); return; } $this->response(FALSE); }
public function get_widget_list() { $widget_settings = Model_User_Meta::get(Dashboard::WIDGET_SETTINGS_KEY, array()); $types = Widget_Manager::map('dashboard_widgets'); $attached_types = array(); foreach ($widget_settings as $widget) { $attached_types[$widget->type()] = $widget->is_multiple(); } foreach ($types as $key => $data) { if (Arr::get($attached_types, $key) === FALSE) { unset($types[$key]); } } $this->json = (string) View::factory('dashboard/widgets', array('types' => $types)); }
public function backend_data() { $widgets = Widget_Manager::get_all_widgets(); $select = array(); foreach ($widgets as $id => $widget) { $class = 'Model_Widget_' . $widget['type']; if (!class_exists($class)) { continue; } $class = new ReflectionClass($class); if ($class->isSubclassOf('Model_Widget_Decorator_Pagination')) { $select[$id] = $widget['name']; } } return array('select' => $select); }
/** * * @param array $row * @param integr $fid * @param integer $recurse * @return array */ protected static function _fetch_related_widget($widget, $row, $fid, $recurse, $key = 'ids', $fetch = FALSE) { $widget_id = Arr::get($widget->doc_fetched_widgets, $fid); if (empty($widget_id)) { return NULL; } $widget = Context::instance()->get_widget($widget_id); if (!$widget) { $widget = Widget_Manager::load($widget_id); } if ($widget === NULL) { return array(); } $widget->{$key} = $row[$fid]; if ($fetch === FALSE) { return $widget->get_document($row[$fid], $recurse - 1); } else { return $widget->fetch_data(); } }
/** * * @param array $types * @param integer $ds_id * @return array */ public static function get_related(array $types, $ds_id = NULL) { $db_widgets = Widget_Manager::get_widgets($types); $widgets = array(); foreach ($db_widgets as $id => $widget) { if ($ds_id !== NULL and $ds_id != $widget->ds_id) { continue; } $widgets[$id] = $widget->name; } return $widgets; }
<?php defined('SYSPATH') or die('No direct access allowed.'); /** * Build layout blocks */ $layouts = Model_File_Layout::find_all(); foreach ($layouts as $layout) { $layout->rebuild_blocks(); } /** * Install widgets */ if (class_exists('Widget_Manager')) { $widgets = array(array('type' => 'page_menu', 'data' => array('name' => 'Header menu', 'template' => 'header', 'cache_tags' => 'pages', 'page_id' => 1, 'exclude' => array(6, 4)), 'blocks' => array(1 => 'header', 3 => 'header', 8 => 'header', 6 => 'header', 5 => 'header', 7 => 'header', 9 => 'header', 10 => 'header', 11 => 'header')), array('type' => 'page_breadcrumbs', 'data' => array('name' => 'Breadcrumbs', 'template' => 'bradcrumbs', 'cache_tags' => 'pages'), 'blocks' => array(1 => 'bradcrumbs', 3 => 'bradcrumbs', 8 => 'bradcrumbs', 6 => 'bradcrumbs', 5 => 'bradcrumbs', 7 => 'bradcrumbs', 9 => 'bradcrumbs', 10 => 'bradcrumbs', 11 => 'bradcrumbs')), array('type' => 'html', 'data' => array('name' => 'Footer', 'template' => 'footer'), 'blocks' => array(1 => 'footer', 3 => 'footer', 8 => 'footer', 6 => 'footer', 5 => 'footer', 7 => 'footer', 9 => 'footer', 10 => 'footer', 11 => 'footer')), array('type' => 'html', 'data' => array('name' => 'Sidebar', 'template' => 'sidebar'), 'blocks' => array(1 => 'sidebar', 3 => 'sidebar', 8 => 'sidebar', 6 => 'sidebar', 5 => 'sidebar', 7 => 'sidebar', 9 => 'sidebar', 10 => 'sidebar', 11 => 'sidebar')), array('type' => 'html', 'data' => array('name' => 'Top banner', 'template' => 'top_banner'), 'blocks' => array(1 => 'top_banner')), 'articles_headline' => array('type' => 'page_pages', 'data' => array('name' => 'Articles headline', 'template' => 'archive-headline', 'cache_tags' => 'pages,page_parts,page_tags'), 'blocks' => array(8 => 'body')), array('type' => 'page_pages', 'data' => array('name' => 'Recent entries', 'template' => 'recent-entries', 'caching' => 1, 'cache_lifetime' => 3600, 'cache_tags' => 'pages,page_parts,page_tags', 'header' => 'Recent entries', 'page_id' => 8), 'blocks' => array(3 => 'recent', 8 => 'recent', 6 => 'recent', 5 => 'recent', 7 => 'recent', 9 => 'recent', 10 => 'recent')), array('type' => 'page_pages', 'data' => array('name' => 'Recent entries index page', 'template' => 'recent-entries', 'caching' => 1, 'cache_lifetime' => 3600, 'cache_tags' => 'pages,page_parts,page_tags', 'page_id' => 8), 'blocks' => array(1 => 'extended')), array('type' => 'page_pages', 'data' => array('name' => 'last entry index page', 'template' => 'last-entry', 'caching' => 1, 'cache_lifetime' => 3600, 'cache_tags' => 'pages,page_parts,page_tags', 'page_id' => 8, 'list_size' => 1), 'blocks' => array(1 => 'body')), array('type' => 'page_pages', 'data' => array('name' => 'Recent entries RSS', 'template' => 'recent-entries-rss', 'caching' => 1, 'cache_lifetime' => 3600, 'cache_tags' => 'pages,page_parts,page_tags', 'page_id' => 8), 'blocks' => array(4 => 'body')), array('type' => 'sendmail', 'data' => array('name' => ' Send mail (sender)', 'template' => 'send-mail-template', 'allowed_tags' => '<b><i><u><p>', 'field' => array('source' => array(0 => '0', 1 => '2', 2 => '2', 3 => '2'), 'id' => array(0 => '', 1 => 'subject', 2 => 'email', 3 => 'text'), 'type' => array(0 => '10', 1 => '10', 2 => '10', 3 => '20'), 'validator' => array(0 => '', 1 => 'not_empty', 2 => 'email', 3 => ''), 'error' => array(0 => '', 1 => '', 2 => '', 3 => ''))), 'blocks' => array(12 => 'body')), array('type' => 'html', 'data' => array('name' => 'Send mail (form)', 'template' => 'send-mail-form'), 'blocks' => array(11 => 'body')), array('type' => 'pagination', 'data' => array('name' => 'Постраничная навигация', 'template' => 'paginator', 'related_widget_id' => 8, 'query_key' => 'page', 'related_widget_id' => NULL), 'blocks' => array(8 => 'pagination'))); $installed_widgets = array(); foreach ($widgets as $key => $widget) { if (isset($widget['data']['related_widget_id']) and isset($installed_widgets[$widget['data']['related_widget_id']])) { $widget['data']['related_widget_id'] = $installed_widgets[$widget['data']['related_widget_id']]; } $installed_widgets[$key] = Widget_Manager::install($widget); } }
/** * * @param array $ids * @return \KodiCMS_Sitemap */ public function fetch_widgets(array $ids) { if (empty($ids)) { return $this; } $widget_ids = array_unique(array_values($ids)); $widgets = array(); foreach ($widget_ids as $id) { $widgets[$id] = Widget_Manager::load($id); } foreach ($ids as $id => $widget_id) { if (empty($widgets[$widget_id])) { unset($ids[$id]); continue; } $ids[$id] = $widgets[$widget_id]; } $array = $this->_array; $this->_fetch_widgets($array, $ids); $this->_array = $array; unset($array); return $this; }
*/ Observer::notify('after_page_load'); /** * Блок служит для помещения в него виджета с произволным PHP кодом, * который выполняется после загрузки HTML */ Block::run('POST'); }); Observer::observe('view_page_edit_plugins', function ($page) { $blocks = Widget_Manager::get_blocks_by_layout($page->layout()); echo View::factory('widgets/page/edit', array('page' => $page, 'pages' => Model_Page_Sitemap::get(TRUE)->exclude(array($page->id))->flatten(), 'widgets' => Widget_Manager::get_widgets_by_page($page->id), 'blocks' => Arr::get($blocks, $page->layout()))); }); Observer::observe('page_add_after_save', function ($page) { $post_data = Request::current()->post('widgets'); if (!empty($post_data['from_page_id'])) { Widget_Manager::copy($post_data['from_page_id'], $page->id); } }); Observer::observe('page_edit_after_save', function ($page) { $post_data = Request::current()->post('widget'); if (!is_array($post_data)) { return; } foreach ($post_data as $widget_id => $block) { Widget_Manager::update_location_by_page($page->id, $widget_id, $block); } }); Observer::observe(array('widget_after_delete', 'widget_set_location', 'widget_after_edit', 'widget_after_add'), function () { Cache::instance()->delete_tag('layout_blocks'); }); Route::set('handler', 'handler/<id>', array('id' => '[0-9]+'))->defaults(array('directory' => 'system', 'controller' => 'handler'));
/** * 修改密码执行页面 * @author 陈晓东 */ public function repwdUpdateAction() { /** * 记录日志 */ $log = "修改密码执行页面\n\nServerIp:\n" . $this->request->getServer('SERVER_ADDR') . "\n\nGET:\n" . var_export($_GET, true) . "\n\nPOST:\n" . var_export($_POST, true); $this->oLogManager->push('log', $log); $id = trim($this->request->id); //用户ID $oldpasswd = trim($this->request->oldpasswd); //原密码 $newpasswd = trim($this->request->newpasswd); //新密码 $confirm = trim($this->request->confirm); //确认密码 $Widget_Manager = new Widget_Manager(); $password = $Widget_Manager->getOne($id, 'password'); if ($password != md5($oldpasswd)) { $response = array('errno' => 1); echo json_encode($response); return false; } if ($newpasswd != $confirm) { $response = array('errno' => 2); echo json_encode($response); return false; } if (strlen($newpasswd) < 6 || strlen($newpasswd) > 18) { $response = array('errno' => 3); echo json_encode($response); return false; } $admin = $this->manager->get(); if ($id != $admin['id']) { $response = array('errno' => 4); echo json_encode($response); return false; } $bind['password'] = md5($newpasswd); $res = $this->manager->update($id, $bind); if ($res) { $response = array('errno' => 0); } else { $response = array('errno' => 9); } echo json_encode($response); return true; }
</td> <td class="sys"> <?php echo Form::label('field-' . $field->name . '-checkbox', $field->key); ?> </td> <td> <?php echo HTML::anchor('/backend/hybrid/field/edit/' . $field->id, $field->header, array('target' => '_blank', 'class' => 'popup fancybox.iframe')); ?> </td> <td> <?php $types = $field->widget_types(); if ($types !== NULL and $fetch_widgets === TRUE) { $widgets = Widget_Manager::get_related($field->widget_types(), $field->from_ds); if (isset($widgets[$widget->id])) { unset($widgets[$widget->id]); } if (!empty($widgets)) { $widgets = array(__('--- Not set ---')) + $widgets; $selected = NULL; if (isset($widget->doc_fetched_widgets[$field->id])) { $selected = $widget->doc_fetched_widgets[$field->id]; } echo Form::select('field[' . $field->id . '][fetcher]', $widgets, $selected); } } ?> </td> </tr>
public function get_blocks() { $layout_name = $this->param('layout', NULL); $blocks = Widget_Manager::get_blocks_by_layout($layout_name); $this->response($blocks); }
?> </label></th> <?php } else { ?> <td></td> <th><?php echo $page['title']; ?> </th> <?php } ?> <td> <?php $widgets = Widget_Manager::get_related(array()); if (isset($widgets[$widget->id])) { unset($widgets[$widget->id]); } if (!empty($widgets)) { $widgets = array(__('--- Not set ---')) + $widgets; $selected = Arr::get($widget->fetched_widgets, $page['id']); echo Form::select('fetched_widgets[' . $page['id'] . ']', $widgets, $selected, array('class' => 'form-control')); } ?> </td> </tr> <?php } ?> </tbody>
public function action_template() { $id = (int) $this->request->param('id'); $widget = Widget_Manager::load($id); if (!$widget) { Messages::errors(__('Widget not found!')); $this->go_back(); } Assets::package('ace'); $template = $widget->default_template(); $data = file_get_contents($template); $this->template->content = View::factory('widgets/default_template', array('data' => $data)); }
/** * * @param integer $ds_id * @return array */ public static function clear_cache($ds_id, array $widget_types = array()) { $objects = Widget_Manager::get_widgets($widget_types); $cleared_ids = array(); foreach ($objects as $id => $data) { $widget = Widget_Manager::load($id); if ($widget->ds_id == $ds_id) { $cleared_ids[] = $widget->id; $widget->clear_cache(); } } return $cleared_ids; }
public function fetch_backend_content() { if ($this->ds_id > 0 and !Datasource_Data_Manager::exists($this->ds_id)) { $this->ds_id = 0; Widget_Manager::update($this); } return parent::fetch_backend_content(); }
/** * * @return string */ public function type($as_key = TRUE) { if ($as_key === TRUE) { return $this->_type; } $widget_types = Widget_Manager::map(); $type = $this->_type; foreach ($widget_types as $group => $types) { if (isset($types[$type])) { $type = $types[$type]; } } return $type; }