public function run($binded_id = false) { if (!$this->request->isAjax()) { cmsCore::error404(); } if (!$binded_id) { cmsCore::error404(); } $template = cmsTemplate::getInstance(); $widgets_model = cmsCore::getModel('widgets'); $widget = $widgets_model->getWidgetBinding($binded_id); cmsCore::loadWidgetLanguage($widget['name'], $widget['controller']); $form = cmsCore::getWidgetOptionsForm($widget['name'], $widget['controller'], $widget['options']); return $template->render('widgets_settings', array('form' => $form, 'widget' => $widget, 'errors' => false)); }
public function run() { if (!$this->request->isAjax()) { cmsCore::error404(); } $widget_id = $this->request->get('widget_id', 0); $page_id = $this->request->get('page_id', 0); $position = $this->request->get('position', ''); $template = $this->request->get('template', ''); $tpls = cmsCore::getTemplates(); if (!$template || !in_array($template, $tpls)) { $template = cmsConfig::get('template'); } $widgets_model = cmsCore::getModel('widgets'); $widget = $widgets_model->getWidget($widget_id); $binded_id = $widgets_model->addWidgetBinding($widget, $page_id, $position, $template); $bind_widget = $widgets_model->getWidgetBinding($binded_id); cmsCore::loadWidgetLanguage($bind_widget['name'], $bind_widget['controller']); $form = cmsCore::getWidgetOptionsForm($bind_widget['name'], $bind_widget['controller'], false, $bind_widget['template']); $data = $form->parse(new cmsRequest($bind_widget)); $widgets_model->updateWidgetBinding($binded_id, $data); $this->cms_template->renderJSON(array('error' => !(bool) $binded_id, 'id' => $binded_id)); }
public function run() { if (!$this->request->isAjax()) { cmsCore::error404(); } if (!$this->request->has('id')) { cmsCore::error404(); } $template = cmsTemplate::getInstance(); $widgets_model = cmsCore::getModel('widgets'); $widget_id = $this->request->get('id'); $widget = $widgets_model->getWidgetBinding($widget_id); cmsCore::loadWidgetLanguage($widget['name'], $widget['controller']); $form = cmsCore::getWidgetOptionsForm($widget['name'], $widget['controller'], false); $widget = $form->parse($this->request, true); $errors = $form->validate($this, $widget); if (!$errors) { $widgets_model->updateWidgetBinding($widget_id, $widget); $template->renderJSON(array('errors' => false, 'callback' => 'widgetUpdated')); } if ($errors) { $template->renderJSON(array('errors' => $errors)); } }
public function runWidget($widget) { $user = cmsUser::getInstance(); $is_user_view = $user->isInGroups($widget['groups_view']); $is_user_hide = !empty($widget['groups_hide']) && $user->isInGroups($widget['groups_hide']) && !$user->is_admin; if ($is_user_hide) { return false; } if (!$is_user_view) { return false; } $path = 'system/' . cmsCore::getWidgetPath($widget['name'], $widget['controller']); $file = $path . '/widget.php'; cmsCore::includeFile($file); cmsCore::loadWidgetLanguage($widget['name'], $widget['controller']); $class = 'widget' . ($widget['controller'] ? string_to_camel('_', $widget['controller']) : '') . string_to_camel('_', $widget['name']); $widget_object = new $class($widget); $cache_key = "widgets.{$widget['id']}"; $cache = cmsCache::getInstance(); if (!$widget_object->isCacheable() || false === ($result = $cache->get($cache_key))) { $result = call_user_func_array(array($widget_object, 'run'), array()); if ($result) { // Отдельно кешируем имя шаблона виджета, поскольку оно могло быть // изменено внутри виджета, а в кеш у нас попадает только тот массив // который возвращается кодом виджета (без самих свойств $widget_object) $result['_wd_template'] = $widget_object->getTemplate(); } $cache->set($cache_key, $result); } if ($result === false) { return false; } if (isset($result['_wd_template'])) { $widget_object->setTemplate($result['_wd_template']); } cmsTemplate::getInstance()->renderWidget($widget_object, $result); }