Exemplo n.º 1
0
 public function executeSave()
 {
     $settings = $this->post('setting', 'ARRAY', []);
     $oms = \Setting::findAll('setting_key');
     foreach ($this->form_cfg as $gk => $group) {
         foreach ($group['settings'] as $key => $options) {
             if (isset($settings[$key])) {
                 //form was set
                 if (isset($oms[$key])) {
                     $om = $oms[$key];
                 } else {
                     $om = new \Setting();
                     $om->setSettingKey($key);
                 }
                 $om->setSettingValue($settings[$key]);
                 $om->save();
             } else {
                 if ($options['control'] == 'checkbox') {
                     if (isset($oms[$key])) {
                         $om = $oms[$key];
                     } else {
                         $om = new \Setting();
                         $om->setSettingKey($key);
                     }
                     $om->setSettingValue('');
                     $om->save();
                 }
             }
             $this->dispatch('onAfterChangeSetting', new CMSBackendEvent($this, ['setting' => $om]));
         }
     }
     Session::getInstance()->setFlash('setting.message', t('Site\'s settings was saved!'));
     $this->redirect($this->createUrl('system_setting'));
 }
Exemplo n.º 2
0
 public function buildPermission()
 {
     if ($user = $this->getUser()) {
         $data = Session::getInstance()->get('auth\\permission');
         if (empty($data)) {
             $data = \Permissions::buildPermission($user);
         }
         Permission::getInstance()->init($data);
     }
 }
Exemplo n.º 3
0
 /**
  * running application
  * @return void
  */
 public function run()
 {
     $this->beforeRun();
     $this->getEventDispatcher()->dispatch('onBeginRequest', new Event($this));
     //Session start
     Session::getInstance()->start();
     $buffer = $this->_loadController();
     $response = Factory::getResponse();
     $response->setBody($buffer);
     $response->send();
     $this->getEventDispatcher()->dispatch('onEndRequest', new Event($this));
     $this->afterRun();
 }
Exemplo n.º 4
0
 public function executeEdit()
 {
     $this->setView('Menu/form');
     if (!($menu = \Menus::retrieveById($this->request()->get('id')))) {
         Session::getInstance()->setFlash('menus.error', t('Menu not fond'));
     }
     $error = array();
     if ($this->request()->isPostRequest()) {
         if ($this->_save($menu, $error)) {
             Session::getInstance()->setFlash('menus.message', t($menu->getName() . ' was saved!'));
             $this->redirect($this->createUrl('menu/default'));
         }
     }
     $this->view()->assign(array('menu' => $menu, 'error' => $error));
     return $this->renderComponent();
 }
Exemplo n.º 5
0
 public function executeEdit()
 {
     $this->setView('Banner/form');
     if (!($banner = \Banner::retrieveById($this->request()->get('id')))) {
         Session::getInstance()->setFlash('banner_error', t('Banner not found'));
         $this->redirect($this->createUrl('banner/default'));
     }
     $message = Session::getInstance()->getFlash('banner');
     $error = array();
     if ($this->request()->isPostRequest()) {
         if ($this->_save($banner, $error)) {
             Session::getInstance()->setFlash('banner', t($banner->getTitle()) . ' was saved');
             $this->redirect($this->createUrl('banner/edit', array('id' => $banner->getId())));
         }
     }
     $this->view()->assign(array('banner' => $banner, 'error' => $error, 'message' => $message, 'upload_max_filesize' => str_replace('M', '', ini_get('upload_max_filesize'))));
     return $this->renderComponent();
 }
Exemplo n.º 6
0
 public function executeEditCf()
 {
     $session = Session::getInstance();
     $cf = \TermCustomFields::retrieveById($this->request()->get('id'));
     $term_id = $this->request()->get('term_id');
     if (!$cf) {
         $session->setFlash('cf_error', t('Custom field not found'));
         $this->redirect($this->createUrl('category/custom_field', array('id' => $term_id)));
     }
     $error = array();
     if ($this->request()->isPostRequest()) {
         $cf->hydrate($this->request()->post('custom_fields', 'ARRAY', array()));
         $acceptValues = explode("\n", $this->request()->post('accept_values'));
         $cf->setAcceptValue(json_encode($acceptValues));
         if ($cf->save()) {
         }
     }
     $formData = (object) $cf->toArray();
     $formData['accept_values'] = implode("\n", json_decode($formData['accept_values']));
     $this->setView('cf_form');
     $this->view()->assign(array('data' => $formData, 'custom_fields' => $cf));
 }
Exemplo n.º 7
0
 public function __construct($options = array())
 {
     $this->imagePath = dirname(__FILE__);
     if (is_array($options) && sizeof($options) > 0) {
         foreach ($options as $prop => $val) {
             $this->{$prop} = $val;
         }
     }
     $this->imageBgColor = $this->initColor($this->imageBgColor, '#ffffff');
     $this->textColor = $this->initColor($this->textColor, '#616161');
     $this->lineColor = $this->initColor($this->lineColor, '#616161');
     $this->noiseColor = $this->initColor($this->noiseColor, '#616161');
     if (is_null($this->ttfFile)) {
         $this->ttfFile = $this->imagePath . '/AHGBold.ttf';
     }
     if (is_null($this->perturbation) || !is_numeric($this->perturbation)) {
         $this->perturbation = 0.75;
     }
     if (is_null($this->_noExit)) {
         $this->_noExit = false;
     }
     if (is_null($this->_sendHeaders)) {
         $this->_sendHeaders = true;
     }
     Session::getInstance()->start();
 }
Exemplo n.º 8
0
 public function executeEdit()
 {
     $post = \Posts::retrieveById($this->request()->get('id'));
     $taxonomy = $this->request()->get('taxonomy');
     if (!$post) {
         Session::getInstance()->setFlash('post_error', t('Post not found'));
         $this->redirect($this->createUrl('post/default', array('taxonomy' => $taxonomy)));
     }
     if (null == $taxonomy) {
         $taxonomy = $post->getTaxonomy();
     }
     $error = array();
     if ($this->request()->isPostRequest()) {
         if ($this->_save($post, $error)) {
             Session::getInstance()->setFlash('post_message', t($post->getTitle() . ' was saved'));
             $this->redirect($this->createUrl('post/default', array('taxonomy' => $taxonomy)));
         }
     }
     $images = \PostPeer::getPostImg($post->getId());
     $files = \PostPeer::getPostAttachments($post->getId());
     //Hydrate
     $jsData = $post->toArray();
     $jsData['images'] = [];
     foreach ($images as $img) {
         $t = $img->toArray();
         $t['thumb_url'] = $img->getThumbs(96, 96);
         $t['url'] = $img->getUrl();
         $jsData['images'][] = $t;
     }
     $jsData['files'] = [];
     foreach ($files as $f) {
         $jsData['files'] = $f->toArray();
     }
     $this->document()->addJsVar('post', $jsData);
     //JS URL
     $this->document()->addJsVar('img_upload_url', $this->createUrl('post_img/upload'));
     $this->document()->addJsVar('img_remove_url', $this->createUrl('post_img/remove'));
     $this->document()->addJsVar('img_set_main_url', $this->createUrl('post_img/make_star'));
     $this->document()->addJsVar('img_update_url', $this->createUrl('post_img/update'));
     $this->setView('Post/form');
     $this->view()->assign(array('post' => $post, 'taxonomy' => $taxonomy, 'error' => $error, 'page_title' => t('Edit ' . $post->getTitle())));
     return $this->renderComponent();
 }
Exemplo n.º 9
0
 /**
  * set session
  */
 public function setSession(\Users $user)
 {
     Session::set('auth', array('id' => $user->getId()));
 }
Exemplo n.º 10
0
 /**
  * get Cookie handler
  *
  * @return \Flywheel\Storage\Cookie
  */
 public static function getCookie()
 {
     if (!isset(self::$_registry['cookie'])) {
         \Flywheel\Session\Session::getInstance()->start();
         $class = self::$_classesList['Cookie'];
         self::$_registry['cookie'] = new $class(ConfigHandler::get('session', false));
     }
     return self::$_registry['cookie'];
 }
Exemplo n.º 11
0
 public function executeEdit()
 {
     $this->setView('User/form');
     $user = \Users::retrieveById($this->request()->get('id'));
     $session = Session::getInstance();
     if (!$user) {
         $session->setFlash('warning', 'user not found');
         $this->redirect($this->createUrl('user'));
     }
     $new_pass = '';
     $error = array();
     $message = $session->getFlash('message');
     if ($this->request()->isPostRequest()) {
         if ($new_pass = $this->request()->post('new_password')) {
             //set new password
             if ($new_pass != $this->request()->post('confirm_password')) {
                 $error['users.new_password'] = t('Password not match!');
             } else {
                 $user->setPassword(\Users::hashPassword($new_pass));
             }
         }
         $user->hydrate($this->request()->post('user', 'ARRAY'));
         if ($this->_save($user, $error)) {
             $message = t("Save successful!");
         }
     }
     $this->view()->assign('user', $user);
     $this->view()->assign('error', $error);
     $this->view()->assign('message', $message);
     $this->view()->assign('page_title', t('Edit user ' . $user->username));
     $this->document()->title .= t('Edit user ' . $user->username);
     $this->view()->assign('new_password', $new_pass);
     return $this->renderComponent();
 }
Exemplo n.º 12
0
 public function executeForm()
 {
     if (!$this->isAllowed(PERMISSION_ROLE_EDIT)) {
         return $this->raise403(t("You don't have permission"));
     }
     $id = $this->get('id');
     if ($id) {
         if (!($role = \Roles::retrieveById($id))) {
             return $this->raise404(t('Role not found!'));
         }
     } else {
         $role = new \Roles();
     }
     $is_new = $role->isNew();
     $session = Session::getInstance();
     $error = [];
     if ($this->request()->isPostRequest()) {
         if ($this->_save($role, $error)) {
             $session->setFlash('role', ['type' => 'SUCCESS', 'message' => t('Save successful!')]);
             $this->redirect($this->createUrl('role/default'));
         }
     }
     $this->dispatch($is_new ? 'onBeforeAddRole' : 'onBeforeEditRole', new CMSBackendEvent($this, ['role' => $role]));
     $this->setView('role/form');
     $this->view()->assign(['role' => $role, 'error' => $error]);
     return $this->renderComponent();
 }
Exemplo n.º 13
0
 public function executeEdit()
 {
     $this->setView('Items/form');
     $id = $this->get('id');
     if (!$id || !($item = \Items::retrieveById($id))) {
         return $this->raise403(t('Item not found'));
     }
     $error = [];
     $message = Session::getInstance()->getFlash('item_frm');
     //submit
     if ($this->request()->isPostRequest()) {
         $is_new = $item->isNew();
         $data = $this->post('item', 'ARRAY', []);
         $data['regular_price'] = floatval(str_replace(',', '.', str_replace('.', '', @$data['regular_price'])));
         $data['sale_price'] = floatval(str_replace(',', '.', str_replace('.', '', @$data['sale_price'])));
         $data['description'] = Sanitize::stripScripts($data['description']);
         //save images
         /*$images_post = $this->post('item_images', 'ARRAY', []);
                     $imgs = [];
                     $main_img_found = false;
                     $first_key = '';
                     $index = 0;
                     foreach($images_post as $file_name => $img_data) {
                         if ($index == 0) {
                             $first_key = $file_name;
                         }
                         $main_img_found = $img_data['main'];
                         $imgs[$file_name] = $img_data;
                         $index++;
                     }
         
                     if(!$main_img_found) {
                         $imgs[$first_key]['main'] = true;
                     }*/
         $item->hydrate($data);
         $is_draft = $item->isDraft();
         //            $item->setImgs(json_encode($imgs));
         if ($item->isDraft()) {
             $item->setIsDraft(false);
             $item->setPublicTime(new DateTime());
         }
         if (empty($error)) {
             if ($item->save()) {
                 Session::getInstance()->setFlash('item_frm', $item->getName() . ' was saved!');
                 $this->dispatch($is_new ? 'onAfterCreateItems' : 'onAfterUpdateItems', new CMSBackendEvent($this, ['item' => $item]));
                 $this->redirect($this->createUrl('items/edit', ['id' => $item->getId()]));
             } elseif (!$item->isValid()) {
                 $item->setIsDraft($is_draft);
                 foreach ($item->getValidationFailures() as $fail) {
                     $error[$fail->getColumn(false)] = t($fail->getMessage());
                 }
             }
         }
     }
     $item_data = $item->toArray();
     $item_img = $item->getImages();
     foreach ($item_img as &$img) {
         $img['url'] = rtrim($this->document()->getBaseUrl(), '/') . preg_replace('/(\\/+)/', '/', '/../' . $img['path']);
         $img['thumb_url'] = \Items::getImgThumbFromPath($img['path'], 52);
     }
     $item_data['imgs'] = $item_img;
     //js url
     $this->document()->addJsVar('upload_url', $this->createUrl('items/upload'));
     $this->document()->addJsVar('remove_img_url', $this->createUrl('items/remove_img'));
     $this->document()->addJsVar('set_main_img_url', $this->createUrl('items/set_main_image'));
     $this->document()->addJsVar('item', $item_data);
     $this->view()->assign(['item' => $item, 'error' => $error, 'message' => $message]);
     return $this->renderComponent();
 }