예제 #1
0
파일: Events.php 프로젝트: biggtfish/cms
 /**
  * Create form.
  *
  * @param array  $eventsData Control data.
  * @param string $type       Package type.
  * @param string $link       Back link.
  */
 public function __construct($eventsData, $type, $link = 'admin-packages')
 {
     $this->_eventsData = $eventsData;
     $this->_type = $type;
     $this->_link = $link;
     parent::__construct();
 }
예제 #2
0
 /**
  * Create form.
  *
  * @param AbstractModel|null $entity Entity object.
  */
 public function __construct(AbstractModel $entity = null)
 {
     parent::__construct();
     if (!$entity) {
         $entity = new Role();
     }
     $this->addEntity($entity);
 }
예제 #3
0
파일: Create.php 프로젝트: biggtfish/cms
 /**
  * Create form.
  *
  * @param AbstractModel $entity Entity object.
  */
 public function __construct(AbstractModel $entity = null)
 {
     $this->_currentPageObject = $entity;
     parent::__construct();
     if (!$entity) {
         $entity = new Page();
     }
     $this->addEntity($entity);
 }
예제 #4
0
 /**
  * Create form.
  *
  * @param AbstractModel $entity Entity object.
  */
 public function __construct(AbstractModel $entity = null)
 {
     parent::__construct();
     if (!$entity) {
         $entity = new LanguageTranslation();
         $entity->checked = true;
     }
     $this->addEntity($entity);
 }
예제 #5
0
 /**
  * Validates the form.
  *
  * @param array $data               Data to validate.
  * @param bool  $skipEntityCreation Skip entity creation.
  *
  * @return boolean
  */
 public function isValid($data = null, $skipEntityCreation = false)
 {
     if (!$data) {
         $data = $this->getDI()->getRequest()->getPost();
     }
     if (isset($data['adapter']) && $data['adapter'] == '0') {
         if (empty($data['cacheDir']) || !is_dir($data['cacheDir'])) {
             $this->addError('Files location isn\'t correct!');
             return false;
         }
     }
     return parent::isValid($data, $skipEntityCreation);
 }
예제 #6
0
 /**
  * Get access editing form.
  *
  * @param \stdClass $objectAcl   Acl object with data.
  * @param Role      $currentRole Role object.
  *
  * @return CoreForm
  */
 protected function _getForm($objectAcl, $currentRole)
 {
     $form = new CoreForm();
     if (!empty($objectAcl->actions)) {
         $form->addHtml('header_actions', '<h4>' . $this->di->get('i18n')->_('Actions') . '</h4>');
         foreach ($objectAcl->actions as $action) {
             $form->addCheckbox($action, ucfirst($action), sprintf('ACTION_%s_%s_DESCRIPTION', strtoupper(str_replace('\\', '_', $objectAcl->name)), strtoupper($action)), 1, $this->core->acl()->isAllowed($currentRole->name, $objectAcl->name, $action), 0);
         }
     }
     if (!empty($objectAcl->options)) {
         $form->addHtml('header_options', '<br/><br/><h4>' . $this->di->get('i18n')->_('Options') . '</h4>');
         foreach ($objectAcl->options as $option) {
             $form->addText($option, ucfirst($option), sprintf('OPTION_%s_%s_DESCRIPTION', strtoupper(str_replace('\\', '_', $objectAcl->name)), strtoupper($option)), $this->core->acl()->getAllowedValue($objectAcl->name, $currentRole, $option));
         }
     }
     $form->addFooterFieldSet()->addButton('save')->addButtonLink('cancel', 'Cancel', ['for' => 'admin-access']);
     return $form;
 }
예제 #7
0
파일: Finish.php 프로젝트: biggtfish/cms
 /**
  * Set form validation.
  *
  * @param CoreForm|FieldSet $content Container object.
  *
  * @return void
  */
 protected function _setValidation($content)
 {
     $content->setRequired('username')->setRequired('email')->setRequired('password')->setRequired('repeatPassword')->getValidation()->add('username', new StringLength(['min' => 2]))->add('email', new Email())->add('password', new StringLength(['min' => 6]))->add('repeatPassword', new StringLength(['min' => 6]));
 }
예제 #8
0
파일: Export.php 프로젝트: biggtfish/cms
 /**
  * Form constructor.
  *
  * @param Package    $package Package object.
  * @param null|array $exclude Exclude data.
  */
 public function __construct($package, $exclude = null)
 {
     $this->_package = $package;
     $this->_exclude = $exclude;
     parent::__construct();
 }
예제 #9
0
파일: FileForm.php 프로젝트: biggtfish/cms
 /**
  * Check form validation and transform image if valid.
  *
  * @param array|null $data               Form data.
  * @param bool       $skipEntityCreation Skip entity creation.
  *
  * @throws \Engine\Exception
  * @return bool
  */
 public function isValid($data = null, $skipEntityCreation = false)
 {
     $isValid = parent::isValid($data, $skipEntityCreation);
     if ($isValid) {
         foreach ($this->_transformations as $field => $transform) {
             $file = $this->getFiles($field);
             if (!$file) {
                 continue;
             }
             $adapterClass = 'Phalcon\\Image\\Adapter\\' . $transform['adapter'];
             unset($transform['adapter']);
             if (!class_exists($adapterClass)) {
                 throw new Exception(sprintf('Image adapter "%s" does not exists.', $adapterClass));
             }
             $adapter = new $adapterClass($file->getTempName());
             foreach ($transform as $option => $values) {
                 if (!is_array($values)) {
                     $values = [$values];
                 }
                 call_user_func_array([$adapter, $option], $values);
             }
             $fileName = $file->getTempName() . '.' . pathinfo($file->getName(), PATHINFO_EXTENSION);
             if (!$adapter->save($fileName)) {
                 $this->getDI()->getLogger()->error(sprintf('Can not transform image. Form: "%s", Field: "%s".', get_class($this), $field));
             } else {
                 rename($fileName, $file->getTempName());
             }
         }
     }
     return $isValid;
 }
예제 #10
0
파일: Create.php 프로젝트: biggtfish/cms
 /**
  * Validates the form.
  *
  * @param array $data               Data to validate.
  * @param bool  $skipEntityCreation Skip entity creation.
  *
  * @return boolean
  */
 public function isValid($data = null, $skipEntityCreation = true)
 {
     if (!$data) {
         $data = $this->getDI()->getRequest()->getPost();
     }
     // Check package location.
     $packageManager = new Manager();
     $path = $packageManager->getPackageLocation($data['type']);
     if (!is_writable($path)) {
         $this->addError('Can not create package. Package location isn\'t writable: ' . $path);
         $this->setValues($data);
         return false;
     }
     // Also check that config file is writable.
     if (!is_writable(ROOT_PATH . Config::CONFIG_PATH)) {
         $this->addError('Configuration file isn\'t writable...');
         $this->setValues($data);
         return false;
     }
     if (isset($data['type']) && $data['type'] == 'widget' && !$this->hasEntity('widget')) {
         $this->addEntity(new WidgetModel(), 'widget');
     }
     if (!parent::isValid($data, $skipEntityCreation)) {
         return false;
     }
     // Check package existence.
     $id = $this->getEntity()->id;
     $condition = "type='{$data['type']}' AND name='{$data['name']}'" . ($id ? " AND id!='{$id}'" : '');
     if (Package::findFirst($condition)) {
         $this->addError('Package with that name already exist!');
         return false;
     }
     // Check widget existence.
     if ($this->hasEntity('widget')) {
         $name = ucfirst($data['name']);
         $id = $this->getEntity('widget')->id;
         $condition = "module='{$data['module']}' AND name='{$name}'" . ($id ? " AND id!='{$id}'" : '');
         if (WidgetModel::findFirst($condition)) {
             $this->addError('Widget with that name already exist!');
             return false;
         }
     }
     return true;
 }
예제 #11
0
 /**
  * Set widget data.
  *
  * @param CoreForm $form    Form object.
  * @param Package  $package Package object.
  * @param array    $data    Post data.
  *
  * @return void
  */
 protected function _setWidgetData(CoreForm $form, Package $package, $data)
 {
     if (!$form->hasEntity('widget')) {
         return;
     }
     $widget = $form->getEntity('widget');
     $widget->name = ucfirst($widget->name);
     $widget->admin_form = $widget->admin_form == 'form_class' ? $data['form_class'] : $widget->admin_form;
     $widget->description = !empty($data['description']) ? $data['description'] : ucfirst($widget->name) . ' widget.';
     $widget->save();
     /**
      * Setup dependency.
      */
     if ($widget->module) {
         $package->data = ['module' => $widget->module, 'widget_id' => $widget->id];
         $module = $this->_getPackage(Manager::PACKAGE_TYPE_MODULE, $widget->module);
         $module->addData('widgets', ['name' => $widget->name, 'module' => $module->name, 'description' => $widget->description, 'is_paginated' => $widget->is_paginated, 'is_acl_controlled' => $widget->is_acl_controlled, 'admin_form' => $widget->admin_form, 'enabled' => (bool) $widget->enabled], true);
         $module->save();
         $dependency = new PackageDependency();
         $dependency->package_id = $package->id;
         $dependency->dependency_id = $module->id;
         $dependency->save();
     } else {
         $package->addData('widget_id', $widget->id);
     }
     $package->save();
 }
예제 #12
0
 /**
  * Widget options.
  *
  * @return void
  *
  * @Route("/widget-options", methods={"GET", "POST"}, name="admin-pages-widget-options")
  */
 public function widgetOptionsAction()
 {
     $widgetIndex = $this->request->get('widget_index', 'int', -1);
     if ($widgetIndex != '0' && intval($widgetIndex) == 0) {
         $widgetIndex = -1;
     }
     $currentPageWidgets = $this->session->get('admin-pages-manage', []);
     if ($widgetIndex == -1) {
         $widgetIndex = $this->session->get('admin-pages-widget-index');
         $currentPageWidgets[$widgetIndex] = ['widget_index' => $widgetIndex, 'id' => 0, 'layout' => $this->request->get('layout', 'string', 'middle'), 'widget_id' => $this->request->get('widget_id', 'int'), 'params' => []];
     }
     if (empty($currentPageWidgets[$widgetIndex])) {
         return;
     }
     $widgetData = $currentPageWidgets[$widgetIndex];
     $id = $widgetData['id'];
     $widgetParams = $widgetData['params'];
     $widgetParams['content_id'] = $id;
     $widget_id = $widgetData['widget_id'];
     $widgetMetadata = Widget::findFirstById($widget_id);
     $form = new CoreForm();
     // building widget form
     $adminForm = $widgetMetadata->admin_form;
     if (empty($adminForm)) {
         $form->addText('title');
     } elseif ($adminForm == 'action') {
         $widgetName = $widgetMetadata->name;
         if ($widgetMetadata->module !== null) {
             $widgetClass = '\\' . ucfirst($widgetMetadata->module) . '\\Widget\\' . $widgetName . '\\Controller';
         } else {
             $widgetClass = '\\Widget\\' . $widgetName . '\\Controller';
         }
         $widgetController = new $widgetClass();
         $widgetController->setDefaults($widgetName, ucfirst($widgetMetadata->module), $widgetParams);
         $widgetController->prepare();
         $form = $widgetController->adminAction();
     } else {
         $form = new $adminForm();
     }
     if ($widgetMetadata->is_paginated == 1) {
         $form->addText('count', 'Items count', null, 10);
         $form->setOrder('count', 1000);
     }
     if ($widgetMetadata->is_acl_controlled == 1) {
         $form->addMultiSelect('roles', 'Roles', null, Role::find(), null, ['using' => ['id', 'name']]);
         $form->setOrder('roles[]', 1001);
     }
     // set form values
     if (!empty($widgetParams)) {
         $form->setValues($widgetParams);
     }
     if (!$this->request->isPost() || !$form->isValid()) {
         $this->view->form = $form;
         $this->view->id = $id;
         $this->view->name = $widgetMetadata->name;
         return;
     }
     $currentPageWidgets[$widgetIndex]['params'] = $form->getValues();
     $this->resolveModal(['hide' => true, 'customJs' => 'setEditedWidgetIndex(' . $widgetIndex . ');']);
     $this->session->set('admin-pages-manage', $currentPageWidgets);
     $this->session->set('admin-pages-widget-index', ++$widgetIndex);
 }
예제 #13
0
    /**
     * Admin action for editing widget options through admin panel.
     *
     * @return CoreForm
     */
    public function adminAction()
    {
        $form = new CoreForm();
        $form->addText('title');
        // Adding additional html for language selector support.
        $languageSelectorHtml = '
                <style type="text/css">
                    form .form_elements > div{
                        min-height: auto !important;
                        padding-top: 0px !important;
                    }

                    form .form_elements > div:nth-last-child(2){
                        padding-top: 10px !important;
                    }
                </style>
                <script type="text/javascript">
                     var defaultLanguage = "%s";
                     $(document).ready(function(){
                        $("#html_block_language").change(function(){
                            $("#cke_html_"+$(this).val()).closest(".form_element_container").show();
                            $(".cke").not("#cke_html_"+$(this).val()).closest(".form_element_container").hide();
                        });

                        // Hide inactive.
                        $("textarea").not("#html_"+defaultLanguage).closest(".form_element_container").hide();
                        setTimeout(
                            function(){
                                $(".cke").not("#cke_html_"+defaultLanguage).closest(".form_element_container").hide();
                            }, 200);
                    });
                </script>
                <div class="form_element_container" style="float: left;">
                    <div class="form_label">
                        <label for="title">%s</label>
                    </div>
                    <div class="form_element">
                        <select id="html_block_language" style="width: 120px;">
                            %s
                        </select>
                    </div>
                </div>
                ';
        // Creating languages boxes.
        $languages = Language::find();
        $languageHtmlItems = '';
        $defaultLanguage = Settings::getSetting('system_default_language', 'en');
        if ($defaultLanguage == 'auto') {
            $defaultLanguage = 'en';
        }
        $elements = [];
        foreach ($languages as $language) {
            $selectedLanguage = '';
            if ($language->language == $defaultLanguage) {
                $selectedLanguage = 'selected="selected"';
            }
            $elementName = 'html_' . $language->language;
            $elements[$elementName] = 'HTML (' . strtoupper($language->language) . ')';
            $languageHtmlItems .= '<option ' . $selectedLanguage . ' value=' . $language->language . '>' . $language->name . '</option>';
        }
        $languageSelectorHtml = sprintf($languageSelectorHtml, $defaultLanguage, $this->di->get('i18n')->_('HTML block, for:'), $languageHtmlItems);
        // Adding created html to form.
        $form->addHtml('html_language', $languageSelectorHtml);
        foreach ($elements as $elementName => $elementTitle) {
            $form->addCkEditor($elementName, $elementTitle);
        }
        $form->addHtml('separator');
        return $form;
    }