Example #1
0
 /**
  * Constructor
  * @param string $log
  * @throws Exception
  */
 private function __construct($log)
 {
     $this->logName = $log;
     $config = Config::getInstance()->getValue('logs', $log);
     $this->type = !empty($config['type']) ? $config['type'] : self::TYPE_NONE;
     switch ($this->type) {
         case self::TYPE_NONE:
             break;
         case self::TYPE_FILE:
             if (empty($config['file'])) {
                 throw new Exception("Log instance {$log} is defined as file, but filename is not defined");
             }
             if (!empty($config['format'])) {
                 $this->logFormat = $config['format'];
             }
             $this->file = $config['file'];
             break;
         case self::TYPE_ECHO:
             if (!empty($config['format'])) {
                 $this->logFormat = $config['format'];
             }
             break;
         case self::TYPE_MONGO:
             $this->mongo = [];
             $this->mongo['client'] = new \MongoDB\Client(!empty($config['connection']) ? $config['connection'] : self::MONGO_DEFAULT_CONNECTION);
             $scope = !empty($config['scope']) ? $config['scope'] : self::MONGO_DEFAULT_SCOPE;
             $collection = !empty($config['collection']) ? $config['collection'] : self::MONGO_DEFAULT_COLLECTION;
             $this->mongo['collection'] = $this->mongo['client']->{$scope}->{$collection};
             break;
         default:
             throw new Exception("Log type {$this->type} is not implemented");
     }
 }
Example #2
0
 /**
  * Get build
  * @return string
  */
 public static function getBuild()
 {
     static $revision = null;
     if (!is_null($revision)) {
         return $revision;
     }
     if ($revision = Config::getInstance()->get('version')) {
         return $revision;
     }
     // version number
     $revisionArr = [self::VERSION, self::POSTFIX];
     if (Envi::isProduction()) {
         // fw revision
         $fwVer = self::getSVNRev(DIR_FW);
         if ($fwVer !== false) {
             $revisionArr[] = $fwVer;
         } elseif (preg_match('/\\d+/', self::REVISION, $match)) {
             $revisionArr[] = $match[0];
         }
         // site revision
         $siteVer = self::getSVNRev(DIR_ROOT);
         if ($siteVer !== false) {
             $revisionArr[] = $siteVer;
         }
     } else {
         $revisionArr[] = time();
     }
     return $revision = implode('.', $revisionArr);
 }
Example #3
0
 public function savesettingsAjaxAction(\Difra\Param\AjaxString $consumerKey, \Difra\Param\AjaxString $consumerSecret, \Difra\Param\AjaxString $oauthToken, \Difra\Param\AjaxString $oauthSecret, \Difra\Param\AjaxCheckbox $postToTwitter)
 {
     $oAuthArray = ['consumerKey' => $consumerKey->val(), 'consumerSecret' => $consumerSecret->val(), 'accessToken' => $oauthToken->val(), 'accessTokenSecret' => $oauthSecret->val(), 'postToTwitter' => $postToTwitter->val()];
     \Difra\Config::getInstance()->set('oAuth', $oAuthArray);
     \Difra\Ajaxer::refresh();
     \Difra\Ajaxer::notify(\Difra\Locales::getInstance()->getXPath('twitter/adm/oAuth/settingsSaved'));
 }
Example #4
0
 public function saveAjaxAction(\Difra\Param\AjaxInt $perpage, \Difra\Param\AjaxString $imgSizes, \Difra\Param\AjaxString $format, \Difra\Param\AjaxCheckbox $waterOn, \Difra\Param\AjaxCheckbox $waterPreviewOn, \Difra\Param\AjaxString $waterText = null, \Difra\Param\AjaxFile $waterFile = null)
 {
     $imgSizes2 = explode("\n", str_replace("\r", '', $imgSizes));
     $imgSizes3 = [];
     foreach ($imgSizes2 as $str) {
         $arr = explode(' ', $str);
         if (sizeof($arr) != 3 or !ctype_alpha($arr[0]) or !ctype_digit($arr[1]) or !ctype_digit($arr[2]) or $arr[0] == 'f' or isset($imgSizes3[$arr[0]]) or !$arr[1] or !$arr[2]) {
             $this->ajax->invalid('imgSizes');
             return;
         }
         $imgSizes3[$arr[0]] = [(int) $arr[1], (int) $arr[2]];
     }
     $conf = \Difra\Config::getInstance();
     $conf->setValue('gallery', 'perpage', $perpage->val());
     $conf->setValue('gallery', 'imgSizes', $imgSizes3);
     $conf->setValue('gallery', 'watermark', $waterOn->val());
     $conf->setValue('gallery', 'waterOnPreview', $waterPreviewOn->val());
     $waterText = !is_null($waterText) ? $waterText->val() : '';
     $conf->setValue('gallery', 'waterText', $waterText);
     $conf->setValue('gallery', 'format', $format->val());
     if (!is_null($waterFile)) {
         $path = DIR_DATA . 'gallery/';
         @mkdir($path, 0777, true);
         file_put_contents($path . 'watermark.png', \Difra\Libs\Images::convert($waterFile->val(), 'png'));
     }
     $this->ajax->notify($this->locale->getXPath('gallery/adm/config/saved'));
 }
Example #5
0
 /**
  * @param \Difra\Controller $controller
  * @param int $catId
  * @param int $page
  * @param array $linkparts
  * @param bool|string $title
  * @param int $cperpage
  * @return mixed
  */
 public function viewCategory(&$controller, $catId, $page, $linkparts, $title = false, $cperpage = 0)
 {
     if (!$cperpage) {
         if (!($perpage = \Difra\Config::getInstance()->getValue('catalog', 'perpage'))) {
             $perpage = 20;
         }
     } else {
         $perpage = $cperpage;
     }
     $catalogNode = $controller->root->appendChild($controller->xml->createElement('CatalogList'));
     $catalog = \Difra\Plugins\Catalog::getInstance();
     $catalogNode->setAttribute('sort', $sort = $catalog->getSort());
     $baseLink = $linkparts ? '/c/' . implode('/', $linkparts) : '/c';
     $list = $catalog->getItemsXML($catalogNode, $catId, true, $page, $perpage, true, true);
     if (!$cperpage) {
         $pages = floor((\Difra\Plugins\Catalog::getInstance()->getItemsCount() - 1) / $perpage) + 1;
         $catalogNode->setAttribute('pages', $pages);
         $catalogNode->setAttribute('current', $page);
         $catalogNode->setAttribute('link', $baseLink);
     }
     if ($title) {
         $title = implode(' → ', $title);
         $controller->root->setAttribute('pageTitle', $title);
     }
     return $list;
 }
Example #6
0
 private function __construct()
 {
     $config = Difra\Config::getInstance()->get('tags');
     if (!empty($config)) {
         $this->modules = $config['modules'];
         $this->maxPt = $config['cloud']['max'];
         $this->minPt = $config['cloud']['min'];
     }
 }
Example #7
0
 /**
  * Возвращает настройки размеров изображений
  * @return array|mixed
  */
 public static function getSizes()
 {
     $sizes = \Difra\Config::getInstance()->getValue('portfolio_settings', 'imgSizes');
     if (!$sizes or empty($sizes)) {
         $sizes = ['small' => [70, 70], 'medium' => [150, 150], 'big' => [500, 500], 'full' => [1200, 800]];
     }
     $sizes['f'] = false;
     return $sizes;
 }
Example #8
0
 /**
  * Возвращает XML со всеми комментариями по всем описанным в конфиге модулям
  * @param \DOMElement $node
  */
 public function getAllCommentsXML($node)
 {
     $modules = \Difra\Config::getInstance()->get('comments');
     if (empty($modules)) {
         $node->appendChild($node->ownerDocument->createElement('empty'));
         return;
     }
     $db = \Difra\MySQL::getInstance();
     foreach ($modules['modules'] as $module) {
         $moduleXML = $node->appendChild($node->ownerDocument->createElement($module . '_comments'));
         $moduleXML->setAttribute('module', $module);
         // забираем комментарии по модулю
         $query = '';
         switch ($module) {
             case 'albums':
                 $query = "SELECT c.`id`, c.`text`, c.`reply_id`, DATE_FORMAT( c.`date`, '%T %d-%m-%Y' ) as `date`,\n\t\t\t\t\t\t\t\tuf.`value` AS `nickname`, bp.`link` AS `post_link`, bp.`name` AS `title`, g.`domain`,\n\t\t\t\t\t\t\t\tbp.`id` AS `post_id`\n\t\t\t\t\t\t\tFROM `albums_comments` c\n\t\t\t\t\t\t\tLEFT JOIN `users_fields` AS `uf` ON uf.`id`=c.`user` AND uf.`name`='nickname'\n\t\t\t\t\t\t\tLEFT JOIN `albums` AS `bp` ON bp.`id`=c.`parent_id`\n\t\t\t\t\t\t\tLEFT JOIN `groups` AS `g` ON g.`id`=bp.`group_id`\n\t\t\t\t\t\t\tORDER BY c.`date` DESC";
                 break;
             case 'blogs':
                 $query = "SELECT c.`id`, c.`user`, c.`text`, c.`reply_id`, bp.`title`, b.`user` `post_owner`, b.`group`,\n\t\t\t\t\t\t\t\tg.`domain`, of.`value` AS `owner_nickname`, bp.`link` AS `post_link`, bp.`id` AS `post_id`,\n\t\t\t\t\t\t\t\tDATE_FORMAT( c.`date`, '%T %d-%m-%Y' ) as `date`, uf.`value` AS `nickname`\n\t\t\t\t\t\t\tFROM `blogs_comments` `c`\n\t\t\t\t\t\t\tLEFT JOIN `users_fields` AS `uf` ON uf.`id`=c.`user` AND uf.`name`='nickname'\n\t\t\t\t\t\t\tLEFT JOIN `blogs_posts` AS `bp` ON bp.`id`=c.`parent_id`\n\t\t\t\t\t\t\tLEFT JOIN `blogs` AS `b` ON b.`id`=bp.`blog`\n\t\t\t\t\t\t\tLEFT JOIN `groups` AS `g` ON g.`id`=b.`group`\n\t\t\t\t\t\t\tLEFT JOIN `users_fields` AS `of` ON of.`id`=b.`user` AND of.`name`='nickname'\n\t\t\t\t\t\t\tORDER BY c.`date` DESC";
                 break;
             case 'catalog':
                 $query = "SELECT c.`id`, c.`text`, c.`reply_id`, DATE_FORMAT( c.`date`, '%T %d-%m-%Y' ) as `date`,\n\t\t\t\t\t\t\t\tuf.`value` AS `nickname`, bp.`name` AS `title`\n\t\t\t\t\t\t\tFROM `catalog_comments` c\n\t\t\t\t\t\t\tLEFT JOIN `users_fields` AS `uf` ON uf.`id`=c.`user` AND uf.`name`='nickname'\n\t\t\t\t\t\t\tLEFT JOIN `catalog_items` AS `bp` ON bp.`id`=c.`parent_id`\n\t\t\t\t\t\t\tORDER BY c.`date` DESC";
                 break;
         }
         $res = $db->fetch($query);
         foreach ($res as $data) {
             /** @var $itemNode \DOMElement */
             $itemNode = $moduleXML->appendChild($node->ownerDocument->createElement('item'));
             $itemNode->setAttribute('id', $data['id']);
             $itemNode->setAttribute('nickname', $data['nickname']);
             $itemNode->setAttribute('date', $data['date']);
             $itemNode->setAttribute('text', $data['text']);
             $itemNode->setAttribute('reply_id', $data['reply_id']);
             $itemNode->setAttribute('title', $data['title']);
             $link = 'http://';
             switch ($module) {
                 case 'blogs':
                     if ($data['domain'] != '') {
                         // ссылка на блог группы
                         $link .= $data['domain'] . '.' . \Difra\Site::getInstance()->getMainhost() . '/' . $data['post_id'] . '/' . rawurlencode($data['post_link']) . '/#comment' . $data['id'];
                     } else {
                         // ссылка на блог юзера
                         $link .= \Difra\Site::getInstance()->getMainhost() . '/blogs/' . $data['owner_nickname'] . '/' . $data['post_id'] . '/' . rawurldecode($data['post_link']) . '/#comment' . $data['id'];
                     }
                     break;
                 case 'albums':
                     $link = 'http://' . $data['domain'] . '.' . \Difra\Site::getInstance()->getMainhost() . '/album/' . rawurldecode($data['post_link']) . '/#comment' . $data['id'];
                     break;
                 case 'catalog':
                     $link = 'http://' . \Difra\Site::getInstance()->getMainhost() . '/c/';
                     break;
             }
             $itemNode->setAttribute('parentLink', $link);
         }
     }
 }
Example #9
0
 public function editAction(\Difra\Param\AnyInt $id)
 {
     $cat = \Difra\Plugins\Catalog\Category::get($id->val());
     /** @var \DOMElement $editNode */
     $editNode = $this->root->appendChild($this->xml->createElement('CatalogCategoriesEdit'));
     Catalog::getInstance()->getCategoriesListXML($editNode);
     $cat->getXML($editNode);
     $conf = \Difra\Config::getInstance()->get('catalog');
     $editNode->setAttribute('maxdepth', $conf['maxdepth']);
 }
Example #10
0
 public function settingsAction()
 {
     $node = $this->root->appendChild($this->xml->createElement('news-settings'));
     $settings = \Difra\Config::getInstance()->get('news_settings');
     if (!empty($settings)) {
         foreach ($settings as $k => $value) {
             $node->setAttribute($k, $value);
         }
     }
 }
Example #11
0
 /**
  * Получаем конфиг авторизации OAuth
  * @throws Exception
  */
 private function _getConfig()
 {
     $config = Config::getInstance()->get('oAuth');
     if (empty($config)) {
         throw new Exception('No OAuth config.');
     }
     $this->consumerKey = $config['consumerKey'];
     $this->consumerSecret = $config['consumerSecret'];
     $this->accessToken = $config['accessToken'];
     $this->accessTokenSecret = $config['accessTokenSecret'];
 }
Example #12
0
 /**
  * Постинг сообщения в твиттер
  * @param $text
  * @return Twitter|null
  * @throws Exception
  */
 public static function post($text)
 {
     $onOff = Config::getInstance()->getValue('oAuth', 'postToTwitter');
     if (!$onOff) {
         throw new Exception('Missing oAuth/postToTwitter');
     }
     $requestFields = ['status' => $text];
     $twitter = new self();
     $twitter->_performRequest($requestFields);
     return $twitter;
 }
Example #13
0
 /**
  * Set locale
  * @param $locale
  */
 public static function setLocale($locale = false)
 {
     if (!$locale) {
         if ($configLocale = Config::getInstance()->get('locale')) {
             $locale = $configLocale;
         }
     }
     self::$locale = $locale ?: 'ru_RU';
     setlocale(LC_ALL, [self::$locale . '.UTF-8', self::$locale . '.utf8']);
     setlocale(LC_NUMERIC, ['en_US.UTF-8', 'en_US.utf8']);
 }
Example #14
0
 public static function addAnalyticsXML()
 {
     if (\Difra\View::$instance == 'adm') {
         return;
     }
     if (!($id = \Difra\Config::getInstance()->getValue('ga', 'id'))) {
         return;
     }
     $controller = \Difra\Controller::getInstance();
     /** @var \DOMElement $analyticsNode */
     $analyticsNode = $controller->footer->appendChild($controller->xml->createElement('analytics'));
     $analyticsNode->setAttribute('id', $id);
 }
Example #15
0
 /**
  * Constructor
  * @throws Exception
  */
 private function __construct()
 {
     // create output XML
     $this->xml = new \DOMDocument();
     $this->realRoot = $this->xml->appendChild($this->xml->createElement('root'));
     // generate page layout
     $layout = Config::getInstance()->get('layout') ?: ['content', 'header', 'footer'];
     if (!in_array('content', $layout)) {
         throw new Exception('Layout has no \'content\' element');
     }
     foreach ($layout as $element) {
         $this->elements[$element] = $this->realRoot->appendChild($this->xml->createElement($element));
     }
 }
Example #16
0
 public function saveAjaxAction(\Difra\Param\AjaxInt $category, \Difra\Param\AjaxString $name, \Difra\Param\AjaxCheckbox $visible, \Difra\Param\AjaxInt $id = null, \Difra\Param\AjaxFloat $price = null, \Difra\Param\AjaxSafeHTML $description = null, \Difra\Param\AjaxData $ext = null, \Difra\Param\AjaxFile $mainImage = null, \Difra\Param\AjaxFiles $images = null)
 {
     $ext = $ext ? $ext->val() : null;
     $allowNoImage = \Difra\Config::getInstance()->getValue('catalog', 'allownoimage');
     if ($id) {
         \Difra\Plugins\Catalog::getInstance()->updateItem($id, $name, $category, $visible, $price, $description, $ext);
     } else {
         if (!$mainImage && $allowNoImage != 1) {
             $this->ajax->required('mainImage');
             return;
         }
         \Difra\Plugins\Catalog::getInstance()->addItem($name, $category, $visible, $price, $description, $ext, $mainImage, $images);
     }
     $this->ajax->redirect('/adm/catalog/items/category/' . $category);
 }
Example #17
0
 /**
  * Constructor
  */
 public function __construct()
 {
     $this->config = Config::getInstance()->get('db');
     if (empty($this->config['hostname'])) {
         $this->config['hostname'] = '';
     }
     if (empty($this->config['username'])) {
         $this->config['username'] = Envi::getSubsite();
     }
     if (empty($this->config['password'])) {
         $this->config['password'] = '';
     }
     if (empty($this->config['database'])) {
         $this->config['database'] = Envi::getSubsite();
     }
 }
Example #18
0
 public function saveAjaxAction(\Difra\Param\AjaxString $imgSizes)
 {
     $imgSizes2 = explode("\n", str_replace("\r", '', $imgSizes));
     $imgSizes3 = [];
     foreach ($imgSizes2 as $str) {
         $arr = explode(' ', $str);
         if (sizeof($arr) != 3 or !ctype_alpha($arr[0]) or !ctype_digit($arr[1]) or !ctype_digit($arr[2]) or $arr[0] == 'f' or isset($imgSizes3[$arr[0]]) or !$arr[1] or !$arr[2]) {
             $this->ajax->invalid('imgSizes');
             $this->ajax->notify(\Difra\Locales::getInstance()->getXPath('portfolio/adm/notify/badImageSizes'));
             return;
         }
         $imgSizes3[$arr[0]] = [(int) $arr[1], (int) $arr[2]];
         $Config = \Difra\Config::getInstance();
         $Config->setValue('portfolio_settings', 'imgSizes', $imgSizes3);
     }
     $this->ajax->notify(\Difra\Locales::getInstance()->getXPath('portfolio/adm/notify/settingSaved'));
     $this->ajax->refresh();
 }
Example #19
0
 /**
  * Get configuration
  * @return mixed
  */
 private static function &getConfig()
 {
     static $cfg = null;
     if (!is_null($cfg)) {
         return $cfg;
     }
     $cfg = Config::getInstance()->get('db');
     //        // generate default config + backwards compatibility
     //        if (empty($cfg) or empty($cfg['default'])) {
     //            $cfg['default'] = [];
     //        }
     //        $keys = ['type', 'hostname', 'database', 'username', 'password'];
     //        foreach ($keys as $key) {
     //            if (!isset($cfg['default'][$key])) {
     //                if (isset($cfg[$key])) {
     //                    $cfg['default'][$key] = $cfg[$key];
     //                    unset($cfg[$key]);
     //                } else {
     //                    switch ($key) {
     //                        case 'type':
     //                            $cfg['default']['type'] = 'mysql';
     //                            break;
     //                        case 'database':
     //                        case 'username':
     //                            $cfg['default'][$key] = Envi::getSubsite();
     //                            break;
     //                        default:
     //                            $cfg['default'][$key] = '';
     //                    }
     //                }
     //            }
     //        }
     //
     //        // add missing keys from default config
     //        foreach ($cfg as $name => &$conf) {
     //            foreach ($keys as $key) {
     //                $conf['name'] = $name;
     //                if (!isset($conf[$key])) {
     //                    $conf[$key] = $cfg['default'][$key];
     //                }
     //            }
     //        }
     return $cfg;
 }
Example #20
0
 /**
  * Registration form submit (registration page version)
  * @param AjaxCheckbox $accept
  * @param AjaxCheckbox $redirect
  * @param AjaxString|null $email
  * @param AjaxString|null $password1
  * @param AjaxString|null $password2
  * @param AjaxString|null $login
  * @param AjaxString|null $capcha
  * @throws Exception
  */
 public function submitAjaxAction(AjaxCheckbox $accept, AjaxCheckbox $redirect, AjaxString $email = null, AjaxString $password1 = null, AjaxString $password2 = null, AjaxString $login = null, AjaxString $capcha = null)
 {
     $register = new Users\Register();
     $register->setEmail($email);
     $register->setLogin($login);
     $register->setPassword1($password1);
     $register->setPassword2($password2);
     $register->setCaptcha($capcha);
     if (!$register->validate()) {
         $register->callAjaxerEvents();
         return;
     }
     // EULA
     if (!$accept->val() and \Difra\Config::getInstance()->getValue('auth', 'eula')) {
         $this->root->appendChild($this->xml->createElement('eula'));
         Ajaxer::display(View::render($this->xml, 'auth-ajax', true));
         return;
     }
     $register->register();
     $this->afterSuccess();
 }
Example #21
0
 public function saveAjaxAction(\Difra\Param\AjaxInt $maxdepth, \Difra\Param\AjaxInt $perpage, \Difra\Param\AjaxString $imgSizes, \Difra\Param\AjaxCheckbox $hideempty, \Difra\Param\AjaxCheckbox $allownoimage, \Difra\Param\AjaxCheckbox $usescale)
 {
     $imgSizes2 = explode("\n", str_replace("\r", '', $imgSizes));
     $imgSizes3 = [];
     foreach ($imgSizes2 as $str) {
         $arr = explode(' ', $str);
         if (sizeof($arr) != 3 or !ctype_alpha($arr[0]) or !ctype_digit($arr[1]) or !ctype_digit($arr[2]) or $arr[0] == 'f' or isset($imgSizes3[$arr[0]]) or !$arr[1] or !$arr[2]) {
             $this->ajax->invalid('imgSizes');
             return;
         }
         $imgSizes3[$arr[0]] = [(int) $arr[1], (int) $arr[2]];
     }
     $conf = \Difra\Config::getInstance();
     $conf->setValue('catalog', 'maxdepth', $maxdepth->val());
     $conf->setValue('catalog', 'perpage', $perpage->val());
     $conf->setValue('catalog', 'hideempty', $hideempty->val());
     $conf->setValue('catalog', 'imgSizes', $imgSizes3);
     $conf->setValue('catalog', 'allownoimage', $allownoimage->val());
     $conf->setValue('catalog', 'usescale', $usescale->val());
     $this->ajax->notify($this->locale->getXPath('catalog/adm/config/saved'));
 }
Example #22
0
 public function indexAction(\Difra\Param\AnyInt $id = null, \Difra\Param\NamedInt $page = null)
 {
     if (!is_null($id)) {
         /** @var \DOMElement $albumNode */
         $albumNode = $this->root->appendChild($this->xml->createElement('GalleryAlbum'));
         $album = \Difra\Plugins\Gallery\Album::get($id->val());
         if (!$album->load()) {
             throw new \Difra\View\HttpError(404);
         }
         $album->getXML($albumNode);
         $albumNode->setAttribute('id', $id);
         $sizesNode = $albumNode->appendChild($this->xml->createElement('sizes'));
         $album->getSizesXML($sizesNode);
         $Locale = \Difra\Locales::getInstance();
         $pageTitle = $Locale->getXPath('gallery/title-album') . $Locale->getXPath('gallery/arrow') . $album->getName();
         $this->root->setAttribute('pageTitle', $pageTitle);
     } else {
         $perpage = \Difra\Config::getInstance()->getValue('gallery', 'perpage');
         $listNode = $this->root->appendChild($this->xml->createElement('GalleryList'));
         \Difra\Plugins\Gallery::getInstance()->getAlbumsListXML($listNode, true, $page ? $page->val() : 1, $perpage ? $perpage : 20);
         $this->root->setAttribute('pageTitle', \Difra\Locales::getInstance()->getXPath('gallery/title'));
     }
 }
Example #23
0
 private function _setSettings()
 {
     $settings = \Difra\Config::getInstance()->get('typograph');
     if ($settings) {
         // установка настроек типографирования
         if (isset($settings['spaceAfterShortWord'])) {
             $this->spaceAfterShortWord = $settings['spaceAfterShortWord'];
         }
         if (isset($settings['lengthShortWord'])) {
             $this->lengthShortWord = $settings['lengthShortWord'];
         }
         if (isset($settings['spaceBeforeLastWord'])) {
             $this->spaceBeforeLastWord = $settings['spaceBeforeLastWord'];
         }
         if (isset($settings['lengthLastWord'])) {
             $this->lengthLastWord = $settings['lengthLastWord'];
         }
         if (isset($settings['spaceAfterNum'])) {
             $this->spaceAfterNum = $settings['spaceAfterNum'];
         }
         if (isset($settings['spaceBeforeParticles'])) {
             $this->spaceBeforeParticles = $settings['spaceBeforeParticles'];
         }
         if (isset($settings['delRepeatSpace'])) {
             $this->delRepeatSpace = $settings['delRepeatSpace'];
         }
         if (isset($settings['delSpaceBeforePunctuation'])) {
             $this->delSpaceBeforePunctuation = $settings['delSpaceBeforePunctuation'];
         }
         if (isset($settings['delSpaceBeforeProcent'])) {
             $this->delSpaceBeforeProcent = $settings['delSpaceBeforeProcent'];
         }
         if (isset($settings['doReplaceBefore'])) {
             $this->doReplaceBefore = $settings['doReplaceBefore'];
         }
         if (isset($settings['doReplaceAfter'])) {
             $this->doReplaceAfter = $settings['doReplaceAfter'];
         }
         if (isset($settings['doMacros'])) {
             $this->doMacros = $settings['doMacros'];
         }
     }
 }
Example #24
0
 /**
  * Возвращает в xml все анонсы событий
  * @param \DOMNode $node
  * @param bool $onlyVisible
  * @param bool $withArchive
  * @param null $perPage
  * @throws Exception
  */
 public function getAllEventsXML($node, $onlyVisible = false, $withArchive = false, $perPage = null)
 {
     if (!is_null($perPage)) {
         $perPageLimit = intval($perPage);
     } else {
         $perPageLimit = Config::getInstance()->getValue('announcements', 'perPage');
     }
     if (empty($perPageLimit) || $perPageLimit == 0) {
         throw new Exception('No page limit! Reconfigure Announcements plugin.');
     }
     $events = Announcements\Announcement::getAll($onlyVisible, $withArchive, $perPageLimit);
     if (!empty($events)) {
         foreach ($events as $object) {
             $object->getXML($node);
         }
     }
 }
Example #25
0
 /**
  * Disable plugin in configuration
  * @param string $name
  * @return bool
  */
 public static function turnOff($name)
 {
     $config = Config::getInstance();
     $conf = $config->get('plugins');
     if (isset($conf[$name])) {
         unset($conf[$name]);
         $config->set('plugins', $conf);
     }
     if (false !== ($k = array_search($name, $conf))) {
         unset($conf[$k]);
         $config->set('plugins', $conf);
     }
     return $config->save();
 }
Example #26
0
 private function getSettings()
 {
     $rssSettings = \Difra\Config::getInstance()->get('rss');
     if (!empty($rssSettings)) {
         foreach ($rssSettings as $key => $value) {
             if ($value !== '') {
                 $this->settings[$key] = $value;
             }
         }
     }
 }
Example #27
0
 /**
  * Get e-mail for notifications
  * @return string|null
  */
 public static function getNotificationMail()
 {
     return Config::getInstance()->getValue('email', 'errors');
 }
Example #28
0
 /**
  * Добавление изображения
  * @param string|\Difra\Param\AjaxFile $image
  * @param bool $main
  * @throws \Difra\Exception
  */
 public function addImage($image, $main = false)
 {
     $path = DIR_DATA . 'catalog/items/';
     @mkdir($path, 0777, true);
     $this->save();
     $this->load();
     $useScaleAndCrop = \Difra\Config::getInstance()->getValue('catalog', 'usescale');
     try {
         $rawImg = Images::data2image($image);
     } catch (\Difra\Exception $ex) {
         throw new \Difra\Exception('Bad image format.');
     }
     $db = MySQL::getInstance();
     $db->query('INSERT INTO `catalog_images` SET ' . "`item`='" . $db->escape($this->id) . "'," . "`main`=" . ($main ? '1' : '0'));
     $imgId = $db->getLastId();
     foreach ($this->imgSizes as $k => $size) {
         if ($size) {
             if (is_null($useScaleAndCrop) || intval($useScaleAndCrop) == 0) {
                 $newImg = Images::createThumbnail($rawImg, $size[0], $size[1], 'png');
             } else {
                 $newImg = Images::scaleAndCrop($rawImg, $size[0], $size[1], 'png');
             }
         } else {
             $newImg = Images::convert($rawImg, 'png');
         }
         if (file_put_contents($path . $imgId . $k . '.png', $newImg) === false) {
             throw new \Difra\Exception('Can\'t save image file.');
         }
     }
 }
Example #29
0
 public function getXML($node)
 {
     if (!$this->load()) {
         return false;
     }
     static $hideEmpty = -1;
     if ($hideEmpty == -1) {
         $hideEmpty = \Difra\Config::getInstance()->getValue('catalog', 'hideempty');
     }
     $node->setAttribute('id', $this->id);
     $node->setAttribute('name', $this->name);
     $node->setAttribute('visible', $this->visible ? '1' : '0');
     $node->setAttribute('parent', $this->parent ? $this->parent : '0');
     $node->setAttribute('link', $this->getFullLink());
     if ($hideEmpty) {
         $node->setAttribute('empty', $this->empty ? '1' : '0');
         $node->setAttribute('emptyHidden', $this->emptyHidden ? '1' : '0');
     }
     return true;
 }
Example #30
0
 /**
  * Save typograph settings
  * @param \Difra\Param\AjaxCheckbox $spaceAfterShortWord
  * @param \Difra\Param\AjaxInt $lengthShortWord
  * @param \Difra\Param\AjaxCheckbox $spaceBeforeLastWord
  * @param \Difra\Param\AjaxInt $lengthLastWord
  * @param \Difra\Param\AjaxCheckbox $spaceAfterNum
  * @param \Difra\Param\AjaxCheckbox $spaceBeforeParticles
  * @param \Difra\Param\AjaxCheckbox $delRepeatSpace
  * @param \Difra\Param\AjaxCheckbox $delSpaceBeforePunctuation
  * @param \Difra\Param\AjaxCheckbox $delSpaceBeforeProcent
  * @param \Difra\Param\AjaxCheckbox $doReplaceBefore
  * @param \Difra\Param\AjaxCheckbox $doReplaceAfter
  * @param \Difra\Param\AjaxCheckbox $doMacros
  */
 public function saveAjaxAction(\Difra\Param\AjaxCheckbox $spaceAfterShortWord, \Difra\Param\AjaxInt $lengthShortWord, \Difra\Param\AjaxCheckbox $spaceBeforeLastWord, \Difra\Param\AjaxInt $lengthLastWord, \Difra\Param\AjaxCheckbox $spaceAfterNum, \Difra\Param\AjaxCheckbox $spaceBeforeParticles, \Difra\Param\AjaxCheckbox $delRepeatSpace, \Difra\Param\AjaxCheckbox $delSpaceBeforePunctuation, \Difra\Param\AjaxCheckbox $delSpaceBeforeProcent, \Difra\Param\AjaxCheckbox $doReplaceBefore, \Difra\Param\AjaxCheckbox $doReplaceAfter, \Difra\Param\AjaxCheckbox $doMacros)
 {
     $settingsArray = ['spaceAfterShortWord' => $spaceAfterShortWord->val(), 'lengthShortWord' => $lengthShortWord->val(), 'spaceBeforeLastWord' => $spaceBeforeLastWord->val(), 'lengthLastWord' => $lengthLastWord->val(), 'spaceAfterNum' => $spaceAfterNum->val(), 'spaceBeforeParticles' => $spaceBeforeParticles->val(), 'delRepeatSpace' => $delRepeatSpace->val(), 'delSpaceBeforePunctuation' => $delSpaceBeforePunctuation->val(), 'delSpaceBeforeProcent' => $delSpaceBeforeProcent->val(), 'doReplaceBefore' => $doReplaceBefore->val(), 'doReplaceAfter' => $doReplaceAfter->val(), 'doMacros' => $doMacros->val()];
     \Difra\Config::getInstance()->set('typograph', $settingsArray);
     $this->ajax->notify(\Difra\Locales::getInstance()->getXPath('adm/typograph/saved'));
 }