예제 #1
0
 /**
  * Init view helpers
  *
  * @return array
  */
 public function getViewHelperConfig()
 {
     return ['invokables' => ['slideshowWidget' => 'Slideshow\\View\\Widget\\SlideshowWidget'], 'factories' => ['slideshowImageUrl' => function () {
         $imagesDir = ApplicationService::getResourcesUrl() . SlideshowBaseModel::getImagesDir();
         return new \Slideshow\View\Helper\SlideshowImageUrl($imagesDir);
     }]];
 }
 /**
  * Init view helpers
  *
  * @return array
  */
 public function getViewHelperConfig()
 {
     return ['invokables' => ['miniPhotoGalleryWidget' => 'MiniPhotoGallery\\View\\Widget\\MiniPhotoGalleryWidget'], 'factories' => ['miniPhotoGalleryImageUrl' => function () {
         $thumbDir = ApplicationService::getResourcesUrl() . MiniPhotoGalleryBaseModel::getThumbnailsDir();
         $imageDir = ApplicationService::getResourcesUrl() . MiniPhotoGalleryBaseModel::getImagesDir();
         return new \MiniPhotoGallery\View\Helper\MiniPhotoGalleryImageUrl($thumbDir, $imageDir);
     }]];
 }
예제 #3
0
 /**
  * Init view helpers
  *
  * @return array
  */
 public function getViewHelperConfig()
 {
     return ['invokables' => ['newsLastNewsWidget' => 'News\\View\\Widget\\NewsLastNewsWidget', 'newsViewWidget' => 'News\\View\\Widget\\NewsViewWidget', 'newsCalendarWidget' => 'News\\View\\Widget\\NewsCalendarWidget', 'newsSimilarNewsWidget' => 'News\\View\\Widget\\NewsSimilarNewsWidget', 'newsListWidget' => 'News\\View\\Widget\\NewsListWidget', 'newsCategoriesWidget' => 'News\\View\\Widget\\NewsCategoriesWidget'], 'factories' => ['newsImageUrl' => function () {
         $thumbDir = ApplicationService::getResourcesUrl() . NewsBaseModel::getThumbnailsDir();
         $imageDir = ApplicationService::getResourcesUrl() . NewsBaseModel::getImagesDir();
         return new \News\View\Helper\NewsImageUrl($thumbDir, $imageDir);
     }]];
 }
예제 #4
0
 /**
  * Resize a resource image
  *
  * @param string $file
  * @param string $path
  * @param integer $width
  * @param integer $height
  * @param string $newPath
  * @param boolean $saveProportions
  * @return void
  */
 public static function resizeResourceImage($file, $path, $width, $height, $newPath = null, $saveProportions = true)
 {
     $filePath = ApplicationService::getResourcesDir() . $path . $file;
     // resize the avatar
     $imagine = new Imagine\Gd\Imagine();
     $size = new Imagine\Image\Box($width, $height);
     $mode = $saveProportions ? Imagine\Image\ImageInterface::THUMBNAIL_INSET : Imagine\Image\ImageInterface::THUMBNAIL_OUTBOUND;
     $imagine->open($filePath)->thumbnail($size, $mode)->save($newPath ? ApplicationService::getResourcesDir() . $newPath . $file : $filePath);
 }
예제 #5
0
 /**
  * Validate FTP system dirs
  *
  * @param $value
  * @param array $context
  * @return boolean
  */
 public function validateFtpSystemDirs($value, array $context = [])
 {
     try {
         $ftpUtility = $this->connectToFtp($value, $context['password']);
         if ($ftpUtility->isDirExists(ApplicationService::getModulePath(false)) && $ftpUtility->isDirExists(basename(APPLICATION_PUBLIC) . '/' . ApplicationService::getLayoutPath(false))) {
             return true;
         }
     } catch (Exception $e) {
         return false;
     }
     return false;
 }
 /**
  * Get form instance
  *
  * @return \Application\Form\ApplicationCustomFormBuilder
  */
 public function getForm()
 {
     // get form builder
     if (!$this->form) {
         // add preview for the image
         if ($this->image) {
             $this->formElements['image']['required'] = false;
             $this->formElements['image']['extra_options']['preview'] = true;
             $this->formElements['image']['extra_options']['file_url'] = ApplicationService::getResourcesUrl() . SlideshowBaseModel::getImagesDir() . $this->image;
         }
         $this->form = new ApplicationCustomFormBuilder($this->formName, $this->formElements, $this->translator, $this->ignoredElements, $this->notValidatedElements, $this->method);
     }
     return $this->form;
 }
예제 #7
0
 /**
  * Clear config cache
  *
  * @return boolean
  */
 public static function clearConfigCache()
 {
     try {
         return ApplicationFileSystem::deleteFiles(ApplicationService::getConfigCachePath());
     } catch (Exception $e) {
         ApplicationErrorLogger::log($e);
     }
     return false;
 }
예제 #8
0
파일: User.php 프로젝트: esase/dream-cms
 /**
  * Get form instance
  *
  * @return \Application\Form\ApplicationCustomFormBuilder
  */
 public function getForm()
 {
     // get form builder
     if (!$this->form) {
         // remove the captcha field
         if (!$this->isCaptchaEnabled) {
             unset($this->formElements['captcha']);
         }
         // skip some required flags
         if ($this->userId) {
             $this->formElements['password']['required'] = false;
             $this->formElements['confirm_password']['required'] = false;
             $this->formElements['avatar']['required'] = false;
         }
         // add preview for the avatar
         if ($this->avatar) {
             $this->formElements['avatar']['extra_options']['preview'] = true;
             $this->formElements['avatar']['extra_options']['file_url'] = ApplicationService::getResourcesUrl() . UserBaseModel::getThumbnailsDir() . $this->avatar;
         }
         // add descriptions params
         $this->formElements['nick_name']['description_params'] = [SettingService::getSetting('user_nickname_min'), SettingService::getSetting('user_nickname_max')];
         // add extra validators
         $this->formElements['slug']['validators'] = [['name' => 'callback', 'options' => ['callback' => [$this, 'validateSlug'], 'message' => 'Display name already used']]];
         $this->formElements['confirm_password']['validators'] = [['name' => 'callback', 'options' => ['callback' => [$this, 'validatePassword'], 'message' => 'Passwords do not match']]];
         $this->formElements['password']['validators'] = [['name' => 'callback', 'options' => ['callback' => [$this, 'validatePassword'], 'message' => 'Passwords do not match']]];
         // validate email
         $this->formElements['email']['validators'] = [['name' => 'callback', 'options' => ['callback' => [$this, 'validateEmail'], 'message' => 'Email already used']]];
         // validate nickname
         $this->formElements['nick_name']['validators'] = [['name' => 'callback', 'options' => ['callback' => [$this, 'validateNickname'], 'message' => 'Nickname already used']]];
         $this->formElements['nick_name']['max_length'] = (int) SettingService::getSetting('user_nickname_max');
         $this->formElements['nick_name']['min_length'] = (int) SettingService::getSetting('user_nickname_min');
         // fill the form with default values
         $this->formElements['time_zone']['values'] = $this->timeZones;
         $this->form = new ApplicationCustomFormBuilder($this->formName, $this->formElements, $this->translator, $this->ignoredElements, $this->notValidatedElements, $this->method);
     }
     return $this->form;
 }
    /**
     * Generate custom active modules config
     *
     * @return void
     */
    protected function generateCustomActiveModulesConfig()
    {
        // get list of custom modules
        $select = $this->select();
        $select->from('application_module')->columns(['name'])->where(['type' => self::MODULE_TYPE_CUSTOM, 'status' => self::MODULE_STATUS_ACTIVE])->order('id');
        $statement = $this->prepareStatementForSqlObject($select);
        $resultSet = new ResultSet();
        $resultSet->initialize($statement->execute());
        $modules = null;
        foreach ($resultSet as $module) {
            $modules .= "'" . $module->name . "',";
        }
        $modules = rtrim($modules, ',');
        $content = <<<CONTENT
<?php

/**
 * EXHIBIT A. Common Public Attribution License Version 1.0
 * The contents of this file are subject to the Common Public Attribution License Version 1.0 (the “License”);
 * you may not use this file except in compliance with the License. You may obtain a copy of the License at
 * http://www.dream-cms.kg/en/license. The License is based on the Mozilla Public License Version 1.1
 * but Sections 14 and 15 have been added to cover use of software over a computer network and provide for
 * limited attribution for the Original Developer. In addition, Exhibit A has been modified to be consistent
 * with Exhibit B. Software distributed under the License is distributed on an “AS IS” basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language
 * governing rights and limitations under the License. The Original Code is Dream CMS software.
 * The Initial Developer of the Original Code is Dream CMS (http://www.dream-cms.kg).
 * All portions of the code written by Dream CMS are Copyright (c) 2014. All Rights Reserved.
 * EXHIBIT B. Attribution Information
 * Attribution Copyright Notice: Copyright 2014 Dream CMS. All rights reserved.
 * Attribution Phrase (not exceeding 10 words): Powered by Dream CMS software
 * Attribution URL: http://www.dream-cms.kg/
 * Graphic Image as provided in the Covered Code.
 * Display of Attribution Information is required in Larger Works which are defined in the CPAL as a work
 * which combines Covered Code or portions thereof with code not governed by the terms of the CPAL.
 */
 return [{$modules}];
CONTENT;
        file_put_contents(ApplicationService::getCustomModuleConfig(), $content);
    }
 /**
  * Membership image url
  *
  * @param string $image
  * @return string
  */
 public function __invoke($image)
 {
     return ApplicationService::getResourcesUrl() . MembershipBaseModel::getImagesDir() . $image;
 }
예제 #11
0
 /**
  * Get user's base files url
  *
  * @return string
  */
 public static function getUserBaseFilesUrl()
 {
     return ApplicationService::getResourcesUrl() . self::getUserFilesDir();
 }
예제 #12
0
 /**
  * Generate tmp dir
  *
  * @return string
  */
 protected function generateTmpDir()
 {
     return ApplicationService::getTmpPath() . '/' . time() . '_' . $this->generateRandString();
 }
예제 #13
0
 /**
  * Upload layout files
  *
  * @param string $layoutName
  * @param array $layoutConfig
  * @param string $tmpDirName
  * @param string $host
  * @param array $formData
  *      string login required
  *      string password required
  *      array layout required
  * @param boolean $checkInstallConfig
  * @throws Layout\Exception\LayoutException
  * return void
  */
 protected function uploadLayoutFiles($layoutName, array $layoutConfig, $tmpDirName, $host, array $formData, $checkInstallConfig = true)
 {
     $updated = false;
     // get the layout's path
     $layoutPath = !empty($layoutConfig['layout_path']) ? $tmpDirName . '/' . $layoutConfig['layout_path'] : null;
     // check the layout existing
     if ($layoutPath && (!file_exists($layoutPath) || !is_dir($layoutPath))) {
         throw new LayoutException('Cannot define the layout\'s path into the config file');
     }
     $globalLayoutPath = basename(APPLICATION_PUBLIC) . '/' . ApplicationService::getLayoutPath(false) . '/' . $layoutName;
     $localLayoutPath = dirname(APPLICATION_PUBLIC) . '/' . $globalLayoutPath;
     // check the layout install config
     if ($checkInstallConfig) {
         if (!file_exists($layoutPath . '/' . $this->layoutInstallConfig)) {
             throw new LayoutException('Layout not found');
         }
         if (file_exists($localLayoutPath)) {
             throw new LayoutException('Layout already uploaded');
         }
     }
     $ftp = new ApplicationFtpUtility($host, $formData['login'], $formData['password']);
     if ($layoutPath) {
         // upload the layout via FTP
         $ftp->createDirectory($globalLayoutPath, true);
         $ftp->copyDirectory($layoutPath, $globalLayoutPath);
         $updated = true;
     }
     // check modules templates
     if (!empty($layoutConfig['module_path']) && is_array($layoutConfig['module_path'])) {
         $globalModulePath = ApplicationService::getModulePath(false);
         $localModulePath = APPLICATION_ROOT . '/' . $globalModulePath;
         // upload modules templates
         foreach ($layoutConfig['module_path'] as $moduleName => $template) {
             // skip non existing modules
             if (!file_exists($localModulePath . '/' . $moduleName)) {
                 continue;
             }
             $templateDir = $tmpDirName . '/' . $template;
             // check the template existing
             if (!file_exists($templateDir) || !is_dir($templateDir)) {
                 throw new LayoutException('Cannot define the template\'s path into the config file');
             }
             $moduleTemplateDir = $globalModulePath . '/' . $moduleName . '/' . ApplicationService::getModuleViewDir() . '/' . $layoutName;
             $ftp->createDirectory($moduleTemplateDir, true);
             $ftp->copyDirectory($templateDir, $moduleTemplateDir);
             $updated = true;
         }
     }
     if (!$updated) {
         throw new LayoutException('Nothing to update the layout');
     }
 }
 /**
  * Generate custom active modules config
  *
  * @return void
  */
 protected function generateCustomActiveModulesConfig()
 {
     // get list of custom modules
     $select = $this->select();
     $select->from('application_module')->columns(['name'])->where(['type' => self::MODULE_TYPE_CUSTOM, 'status' => self::MODULE_STATUS_ACTIVE])->order('id');
     $statement = $this->prepareStatementForSqlObject($select);
     $resultSet = new ResultSet();
     $resultSet->initialize($statement->execute());
     $modules = null;
     foreach ($resultSet as $module) {
         $modules .= "'" . $module->name . "',";
     }
     file_put_contents(ApplicationService::getCustomModuleConfig(), '<?php return [' . rtrim($modules, ',') . '];');
 }
 /**
  * Get form instance
  *
  * @return \Application\Form\ApplicationCustomFormBuilder
  */
 public function getForm()
 {
     // get form builder
     if (!$this->form) {
         // get list of all ACL roles
         $aclRoles = [];
         foreach (AclService::getAclRoles() as $roleId => $roleName) {
             // skip all system ACL roles
             if (in_array($roleId, [AclBaseModel::DEFAULT_ROLE_ADMIN, AclBaseModel::DEFAULT_ROLE_GUEST, AclBaseModel::DEFAULT_ROLE_MEMBER])) {
                 continue;
             }
             $aclRoles[$roleId] = $roleName;
         }
         $this->formElements['role_id']['values'] = $aclRoles;
         // add preview for the image
         if ($this->image) {
             $this->formElements['image']['required'] = false;
             $this->formElements['image']['extra_options']['preview'] = true;
             $this->formElements['image']['extra_options']['file_url'] = ApplicationService::getResourcesUrl() . MembershipBaseModel::getImagesDir() . $this->image;
         }
         // add extra validators
         $this->formElements['expiration_notification']['validators'] = [['name' => 'callback', 'options' => ['callback' => [$this, 'validateExpirationNotification'], 'message' => 'The expiration notification value  must be less than role\'s lifetime']]];
         $this->form = new ApplicationCustomFormBuilder($this->formName, $this->formElements, $this->translator, $this->ignoredElements, $this->notValidatedElements, $this->method);
     }
     return $this->form;
 }
예제 #16
0
 /**
  * Init view helpers
  */
 public function getViewHelperConfig()
 {
     return ['invokables' => ['userLoginWidget' => 'User\\View\\Widget\\UserLoginWidget', 'userRegisterWidget' => 'User\\View\\Widget\\UserRegisterWidget', 'userActivateWidget' => 'User\\View\\Widget\\UserActivateWidget', 'userForgotWidget' => 'User\\View\\Widget\\UserForgotWidget', 'userPasswordResetWidget' => 'User\\View\\Widget\\UserPasswordResetWidget', 'userDeleteWidget' => 'User\\View\\Widget\\UserDeleteWidget', 'userInfoWidget' => 'User\\View\\Widget\\UserInfoWidget', 'userAvatarWidget' => 'User\\View\\Widget\\UserAvatarWidget', 'userDashboardWidget' => 'User\\View\\Widget\\UserDashboardWidget', 'userDashboardUserInfoWidget' => 'User\\View\\Widget\\UserDashboardUserInfoWidget', 'userEditWidget' => 'User\\View\\Widget\\UserEditWidget', 'userDashboardAdministrationWidget' => 'User\\View\\Widget\\UserDashboardAdministrationWidget'], 'factories' => ['userAvatarUrl' => function () {
         $thumbDir = ApplicationService::getResourcesUrl() . UserBaseModel::getThumbnailsDir();
         $avatarDir = ApplicationService::getResourcesUrl() . UserBaseModel::getAvatarsDir();
         return new \User\View\Helper\UserAvatarUrl($thumbDir, $avatarDir);
     }, 'userMenu' => function () {
         $userMenu = $this->serviceLocator->get('Application\\Model\\ModelManager')->getInstance('User\\Model\\UserMenu');
         return new \User\View\Helper\UserMenu($userMenu->getMenu());
     }, 'userIdentity' => function () {
         return new \User\View\Helper\UserIdentity(UserIdentityService::getCurrentUserIdentity());
     }, 'userIsGuest' => function () {
         return new \User\View\Helper\UserIsGuest(UserIdentityService::isGuest());
     }]];
 }
예제 #17
0
 /**
  * Upload a resource file
  *
  * @param integer|string $objectId
  * @param array $file
  *      string name
  *      string type
  *      string tmp_name
  *      integer error
  *      integer size
  * @param string $path
  * @param boolean $addSalt
  * @param integer $saltLength
  * @return string|boolean
  */
 public static function uploadResourceFile($objectId, $file, $path, $addSalt = true, $saltLength = 5)
 {
     $fileInfo = pathinfo($file['name']);
     $salt = $addSalt ? '_' . SlugUtility::generateRandomSlug($saltLength) : null;
     $fileName = $objectId . $salt . (!empty($fileInfo['extension']) ? '.' . strtolower($fileInfo['extension']) : null);
     $basePath = ApplicationService::getResourcesDir() . $path;
     if (is_writable($basePath)) {
         if (true === ($result = move_uploaded_file($file['tmp_name'], $basePath . $fileName))) {
             @chmod($basePath . $fileName, self::DEFAULT_FILE_PERMISSIONS);
             return $fileName;
         }
     }
     return false;
 }
예제 #18
0
 /**
  * Get form instance
  *
  * @return \Application\Form\ApplicationCustomFormBuilder
  */
 public function getForm()
 {
     // get form builder
     if (!$this->form) {
         // add extra validators
         $this->formElements['slug']['validators'] = [['name' => 'callback', 'options' => ['callback' => [$this, 'validateSlug'], 'message' => 'Display name already used']]];
         // get categories
         $categories = NewsService::getAllNewsCategories();
         $this->formElements['categories']['values'] = $categories;
         if (!$categories) {
             unset($this->formElements['categories']);
         }
         // add preview for the image
         if ($this->newsImage) {
             $this->formElements['image']['extra_options']['preview'] = true;
             $this->formElements['image']['extra_options']['file_url'] = ApplicationService::getResourcesUrl() . NewsAdministrationModel::getThumbnailsDir() . $this->newsImage;
         }
         $this->form = new ApplicationCustomFormBuilder($this->formName, $this->formElements, $this->translator, $this->ignoredElements, $this->notValidatedElements, $this->method);
     }
     return $this->form;
 }