/** * Запуск валидации * * @param mixed $sValue Данные для валидации * * @return bool|string */ public function validate($sValue) { if (is_array($sValue)) { return $this->getMessage(E::ModuleLang()->Get('validate_tags_empty', null, false), 'msg', array('min' => $this->min, 'max' => $this->max)); } if ($this->allowEmpty && $this->isEmpty($sValue)) { return true; } $aTags = explode($this->sep, trim($sValue, "\r\n\t\v .")); $aTagsNew = array(); $aTagsNewLow = array(); foreach ($aTags as $sTag) { $sTag = trim($sTag, "\r\n\t\v ."); $iLength = mb_strlen($sTag, 'UTF-8'); if ($iLength >= $this->min and $iLength <= $this->max and !in_array(mb_strtolower($sTag, 'UTF-8'), $aTagsNewLow)) { $aTagsNew[] = $sTag; $aTagsNewLow[] = mb_strtolower($sTag, 'UTF-8'); } } $iCount = count($aTagsNew); if ($iCount > $this->count) { return $this->getMessage(E::ModuleLang()->Get('validate_tags_count_more', null, false), 'msg', array('count' => $this->count)); } elseif (!$iCount) { return $this->getMessage(E::ModuleLang()->Get('validate_tags_empty', null, false), 'msg', array('min' => $this->min, 'max' => $this->max)); } /** * Если проверка от сущности, то возвращаем обновленное значение */ if ($this->oEntityCurrent) { $this->setValueOfCurrentEntity($this->sFieldCurrent, join($this->sep, $aTagsNew)); } return true; }
protected function SubmitComment() { /** * Проверям авторизован ли пользователь */ if (!E::ModuleUser()->IsAuthorization()) { E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('need_authorization'), E::ModuleLang()->Get('error')); return; } $xResult = E::Module('PluginMagicrules\\Rule')->CheckRuleAction('create_comment', $this->oUserCurrent); if (true === $xResult) { $xResult = E::Module('PluginMagicrules\\Rule')->CheckRuleCreateAction('comment', $this->oUserCurrent); } if (true === $xResult) { return parent::SubmitComment(); } else { if (is_string($xResult)) { E::ModuleMessage()->AddErrorSingle($xResult, E::ModuleLang()->Get('attention')); return; } else { E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('plugin.magicrules.check_rule_action_error'), E::ModuleLang()->Get('attention')); return; } } }
/** * Валидация пользователя * * @param string $sValue Значение * @param array $aParams Параметры * * @return bool */ public function ValidateTarget($sValue, $aParams) { if (($oUserTarget = E::ModuleUser()->GetUserById($sValue)) && $this->getUserId() != $oUserTarget->getId()) { return true; } return E::ModuleLang()->Get('user_note_target_error'); }
public function SetSecurityKey() { $sCode = parent::SetSecurityKey(); // LS-compatible E::ModuleViewer()->Assign('LIVESTREET_SECURITY_KEY', $sCode); return $sCode; }
/** * @param string $sKeyString * @param string $sKeyName * * @return int */ public function Verify($sKeyString, $sKeyName = null) { $iResult = 0; if (empty($sKeyString)) { $iResult = static::ERR_KEYSTRING_EMPTY; } elseif (!is_string($sKeyString)) { $iResult = static::ERR_KEYSTRING_NOT_STR; } else { if (!$sKeyName) { $sKeyName = $this->sKeyName; } $sSavedString = E::ModuleSession()->Get($sKeyName); // issue#342. При регистрации метод вызывается несколько раз в том // числе и при проверки формы аяксом при первой проверке значение // капчи сбрасывается и в дальнейшем проверка не проходит. Сброс капчи // теперь происходит только после успешной регистрации // E::ModuleSession()->Drop($sKeyName); if (empty($sSavedString) || !is_string($sSavedString)) { $iResult = static::ERR_KEYSTRING_NOT_DEFINED; } elseif ($sSavedString != $sKeyString) { $iResult = static::ERR_KEYSTRING_NOT_VALID; } } return $iResult; }
public function InjectProfileLink() { $sTemplatePath = Plugin::GetTemplatePath(__CLASS__) . 'inject_profile_link.tpl'; if (E::ModuleViewer()->TemplateExists($sTemplatePath)) { return E::ModuleViewer()->Fetch($sTemplatePath); } }
/** * Плагин для смарти * Запускает хуки из шаблона на выполнение * * @param array $aParams * @param Smarty $oSmarty * * @return string */ function smarty_function_hook($aParams, &$oSmarty) { if (empty($aParams['run'])) { trigger_error('Hook: missing "run" parametr', E_USER_WARNING); return; } $sReturn = ''; if (strpos($aParams['run'], ',')) { $aHooks = F::Array_Str2Array($aParams['run']); unset($aParams['run']); foreach ($aHooks as $sHook) { $aParams['run'] = $sHook; $sReturn .= smarty_function_hook($aParams, $oSmarty); } } else { $sHookName = 'template_' . strtolower($aParams['run']); unset($aParams['run']); $aResultHook = E::ModuleHook()->Run($sHookName, $aParams); if (array_key_exists('template_result', $aResultHook)) { $sReturn = join('', $aResultHook['template_result']); } if (!empty($aParams['assign'])) { $oSmarty->assign($aParams['assign'], $sReturn); $sReturn = ''; } } return $sReturn; }
/** * Plugin for Smarty * Display widget group * * @param array $aParams * @param Smarty_Internal_Template $oSmartyTemplate * * @return string */ function smarty_function_wgroup_show($aParams, $oSmartyTemplate) { if (isset($aParams['name'])) { if (!isset($aParams['group'])) { $aParams['group'] = $aParams['name']; } elseif (!isset($aParams['widget'])) { $aParams['widget'] = $aParams['name']; } } if (!isset($aParams['group'])) { $sError = 'Parameter "group" does not define in {wgroup_show ...} function'; if ($oSmartyTemplate->template_resource) { $sError .= ' (template: ' . $oSmartyTemplate->template_resource . ')'; } trigger_error($sError, E_USER_WARNING); return null; } $sWidgetGroup = $aParams['group']; $aWidgets = E::ModuleViewer()->GetWidgets(); $sResult = ''; if (isset($aWidgets[$sWidgetGroup])) { if (!function_exists('smarty_function_widget')) { F::IncludeFile('function.widget.php'); } foreach ($aWidgets[$sWidgetGroup] as $oWidget) { $sResult .= smarty_function_widget(array('object' => $oWidget), $oSmartyTemplate); } } return $sResult; }
public function EventRegistration() { /** @var ModuleCaptcha_EntityCaptcha $oCaptcha */ $oCaptcha = E::ModuleCaptcha()->GetCaptcha(); $oCaptcha->Display(); exit; }
/** * Деактивация плагина * @return bool */ public function Deactivate() { $oMenu = E::ModuleMenu()->GetMenu('user'); $oMenu->RemoveItemById('plugin.menutest.my_menu', true); E::ModuleMenu()->SaveMenu($oMenu); return true; }
/** * @param string $sType * @param bool $bClear * * @throws Exception */ public function loadConfig($sType = 'default', $bClear = true) { if ($bClear) { $this->tagsRules = array(); } $aConfig = C::Get('qevix.' . $sType); if (is_array($aConfig)) { foreach ($aConfig as $sMethod => $aExec) { if ($sMethod == 'cfgSetAutoReplace') { $this->aAutoReplace = $aExec; continue; } foreach ($aExec as $aParams) { call_user_func_array(array($this, $sMethod), $aParams); } } // * Хардкодим некоторые параметры unset($this->entities1['&']); // разрешаем в параметрах символ & if (C::Get('view.noindex') && isset($this->tagsRules['a'])) { $this->cfgSetTagParamDefault('a', 'rel', 'nofollow', true); } } if (C::Get('module.text.char.@')) { $this->cfgSetSpecialCharCallback('@', array(E::ModuleText(), 'CallbackTagAt')); } if ($aData = C::Get('module.text.autoreplace')) { $this->aAutoReplace = array(array_keys($aData), array_values($aData)); } }
/** * Plugin for Smarty * * @param array $aParams * @param Smarty_Internal_Template $oSmartyTemplate * * @return string|null */ function smarty_function_widget_template($aParams, $oSmartyTemplate) { if (!isset($aParams['name'])) { trigger_error('Parameter "name" does not define in {widget ...} function', E_USER_WARNING); return null; } $sWidgetName = $aParams['name']; $aWidgetParams = isset($aParams['params']) ? $aParams['params'] : array(); $oEngine = Engine::getInstance(); // Проверяем делигирование $sTemplate = E::ModulePlugin()->GetDelegate('template', $sWidgetName); if ($sTemplate) { if ($aWidgetParams) { foreach ($aWidgetParams as $sKey => $sVal) { $oSmartyTemplate->assign($sKey, $sVal); } if (!isset($aWidgetParams['params'])) { /* LS-compatible */ $oSmartyTemplate->assign('params', $aWidgetParams); } $oSmartyTemplate->assign('aWidgetParams', $aWidgetParams); } $sResult = $oSmartyTemplate->fetch($sTemplate); } else { $sResult = null; } return $sResult; }
/** * Выполняется при завершении работы экшена * */ public function EventShutdown() { /** * Загружаем в шаблон необходимые переменные */ E::ModuleViewer()->Assign('sMenuHeadItemSelect', $this->sMenuHeadItemSelect); }
/** * Список опубликованых топиков в открытых блогах (с кешированием) * * @param int $iPage * * @return array */ public function getTopicsForSitemap($iPage = 0) { $sCacheKey = "sitemap_topics_{$iPage}_" . C::Get('plugin.sitemap.items_per_page'); if (false === ($aData = E::ModuleCache()->Get($sCacheKey))) { $aFilter = $this->GetNamedFilter('sitemap'); $aTopics = E::ModuleTopic()->GetTopicsByFilter($aFilter, $iPage, C::Get('plugin.sitemap.items_per_page'), array('blog' => array('owner' => array()))); $aData = array(); $iIndex = 0; $aPriority = F::Array_Str2Array(C::Get('plugin.sitemap.type.topics.priority')); $nPriority = sizeof($aPriority) ? reset($aPriority) : null; $aChangeFreq = F::Array_Str2Array(C::Get('plugin.sitemap.type.topics.changefreq')); $sChangeFreq = sizeof($aChangeFreq) ? reset($aChangeFreq) : null; /** @var ModuleTopic_EntityTopic $oTopic */ foreach ($aTopics['collection'] as $oTopic) { if ($aPriority) { if (isset($aPriority[$iIndex])) { $nPriority = $aPriority[$iIndex]; } } if ($aChangeFreq) { if (isset($aChangeFreq[$iIndex])) { $sChangeFreq = $aChangeFreq[$iIndex]; } } $aData[] = E::ModuleSitemap()->GetDataForSitemapRow($oTopic->getLink(), $oTopic->getDateLastMod(), $sChangeFreq, $nPriority); $iIndex += 1; } // тег 'blog_update' т.к. при редактировании блога его тип может измениться // с открытого на закрытый или наоборот E::ModuleCache()->Set($aData, $sCacheKey, array('topic_new', 'topic_update', 'blog_update'), C::Get('plugin.sitemap.type.topics.cache_lifetime')); } return $aData; }
public function getComments($iTopicId, $iPageNum, $iPageSize) { $sCacheKey = 'api_topic_' . $iTopicId; $oTopic = E::ModuleCache()->GetTmp($sCacheKey); if (!$oTopic) { $oTopic = E::ModuleTopic()->GetTopicById($iTopicId); } if (!$oTopic || !($oBlog = $oTopic->getBlog())) { return array(); } $oBlogType = $oBlog->GetBlogType(); if ($oBlogType) { $bCloseBlog = !$oBlog->CanReadBy(E::User()); } else { // if blog type not defined then it' open blog $bCloseBlog = false; } if ($bCloseBlog) { return array(); } $aComments = E::ModuleComment()->GetCommentsByTargetId($oTopic, 'topic', $iPageNum, $iPageSize); $aResult = array('total' => $oTopic->getCountComment(), 'list' => array()); foreach ($aComments['comments'] as $oComment) { $aResult['list'][] = $oComment->getApiData(); } return $aResult; }
/** * Saves file in storage * * @param string $sFile * @param string $sDestination * * @return bool|ModuleUploader_EntityItem */ public function Store($sFile, $sDestination = null) { if (!$sDestination) { $oUser = E::ModuleUser()->GetUserCurrent(); if (!$oUser) { return false; } $sDestination = E::ModuleUploader()->GetUserFileDir($oUser->getId()); } if ($sDestination) { $sMimeType = ModuleImg::MimeType($sFile); $bIsImage = strpos($sMimeType, 'image/') === 0; $iUserId = E::UserId(); $sExtension = F::File_GetExtension($sFile, true); if (substr($sDestination, -1) == '/') { $sDestinationDir = $sDestination; } else { $sDestinationDir = dirname($sDestination) . '/'; } $sUuid = ModuleMresource::CreateUuid('file', $sFile, md5_file($sFile), $iUserId); $sDestination = $sDestinationDir . $sUuid . '.' . $sExtension; if ($sStoredFile = E::ModuleUploader()->Move($sFile, $sDestination, true)) { $oStoredItem = E::GetEntity('Uploader_Item', array('storage' => 'file', 'uuid' => $sUuid, 'original_filename' => basename($sFile), 'url' => $this->Dir2Url($sStoredFile), 'file' => $sStoredFile, 'user_id' => $iUserId, 'mime_type' => $sMimeType, 'is_image' => $bIsImage)); return $oStoredItem; } } return false; }
/** * @param string $sType * @param bool $bClear * * @throws Exception */ public function loadConfig($sType = 'default', $bClear = true) { if ($bClear) { $this->tagsRules = array(); } $aConfig = C::Get('jevix.' . $sType); if (is_array($aConfig)) { foreach ($aConfig as $sMethod => $aExec) { foreach ($aExec as $aParams) { if (in_array(strtolower($sMethod), array_map('strtolower', array('cfgSetTagCallbackFull', 'cfgSetTagCallback')))) { if (isset($aParams[1][0]) && $aParams[1][0] == '_this_') { $aParams[1][0] = E::ModuleText(); } } call_user_func_array(array($this, $sMethod), $aParams); } } // * Хардкодим некоторые параметры unset($this->entities1['&']); // разрешаем в параметрах символ & if (C::Get('view.noindex') && isset($this->tagsRules['a'])) { $this->cfgSetTagParamDefault('a', 'rel', 'nofollow', true); } } }
/** * Запуск обработки */ public function Exec() { // Статистика кто, где и т.п. $aPeopleStats = E::ModuleUser()->GetStatUsers(); // Загружаем переменные в шаблон E::ModuleViewer()->Assign('aPeopleStats', $aPeopleStats); }
public static function Init($sFuncStats) { if (!self::IsAvailable()) { return false; } $oCache = new Zend_Cache_Backend_File(array('cache_dir' => C::Get('sys.cache.dir'), 'file_name_prefix' => E::ModuleCache()->GetCachePrefix(), 'read_control_type' => 'crc32', 'hashed_directory_level' => C::Get('sys.cache.directory_level'), 'read_control' => true, 'file_locking' => true)); return new self($oCache, $sFuncStats); }
public function __get($sName) { // LS compatibility if ($sName === 'oEngine') { $this->oEngine = E::getInstance(); } return $this->oEngine; }
/** * Инициализация плагина */ public function Init() { $this->Viewer_Assign("sTemplatePathEstheme", Plugin::GetTemplatePath(__CLASS__)); E::ModuleViewer()->AppendStyle(Plugin::GetTemplateDir(__CLASS__) . "assets/css/style.min.css"); E::ModuleViewer()->AppendScript(Plugin::GetTemplateDir(__CLASS__) . "assets/js/develop/jquery.color.js"); E::ModuleViewer()->AppendScript(Plugin::GetTemplateDir(__CLASS__) . "assets/js/develop/colorPicker.js"); E::ModuleViewer()->AppendScript(Plugin::GetTemplateDir(__CLASS__) . "assets/js/develop/esTheme.js"); }
/** * Initialize a new session for a user, such as for a login. * Registers a listener for the `error` event to reset the session to its initial state. */ public static function start() { session_start(); self::$reset = $_SESSION; E::listen('error', function () { self::reset(); }); }
public function Init() { E::ModuleViewer()->AppendStyle(Plugin::GetTemplateDir(__CLASS__) . "assets/css/style.css"); // Добавление своего CSS E::ModuleViewer()->AppendScript(Plugin::GetTemplateDir(__CLASS__) . "assets/js/script.js"); // Добавление своего JS //E::ModuleViewer()->AddMenu('blog',Plugin::GetTemplateDir(__CLASS__).'menu.blog.tpl'); // например, задаем свой вид меню }
public function GetUserProfileStats($xUser) { $aUserPublicationStats = parent::GetUserProfileStats($xUser); $iCountTopicsSandbox = E::ModuleTopic()->GetCountTopicsSandboxByUser($xUser); $aUserPublicationStats['count_sandbox'] = $iCountTopicsSandbox; $aUserPublicationStats['count_created'] += $iCountTopicsSandbox; return $aUserPublicationStats; }
public function testRender() { $form = new Form(); $tags = $form->addTags('tags')->setDefaultValue(NULL); $this->assertStringEqualsFile(E::dumpedFile('tagsNull'), $tags->getControl()); $tags = $form->addTags('tagsTwo')->setDefaultValue(array('tag', 'one', 'two')); $this->assertStringEqualsFile(E::dumpedFile('tagsRender'), $tags->getControl()); }
public function EventShutdown() { parent::EventShutdown(); if ($this->oCurrentBlog) { $iCountSandboxBlogNew = E::ModuleTopic()->GetCountTopicsSandboxNew(array('blog_id' => $this->oCurrentBlog->getId())); E::ModuleViewer()->Assign('iCountSandboxBlogNew', $iCountSandboxBlogNew); } }
public function AddVote(ModuleVote_EntityVote $oVote) { $bResult = parent::AddVote($oVote); if ($bResult) { E::Module('PluginMagicrules\\Rule')->CheckForCreateBlockVote($oVote); } return $bResult; }
protected static function theDefaultEIsAvailable() { try { $e = E::getById(self::$theDefaultE->id); return true; } catch (NotFoundException $ex) { return false; } }
function main() { $a = new A(); $b = new B(); $c = new C(); B::test($a); C::test($b); E::test($c); }
public function getLangText($sTextTemplate, $sLang = NULL) { return preg_replace_callback('~(\\{\\{\\S*\\}\\})~', function ($sTextTemplatePart) { $sTextTemplatePart = array_shift($sTextTemplatePart); if (!is_null($sText = E::ModuleLang()->Get(substr($sTextTemplatePart, 2, strlen($sTextTemplatePart) - 4)))) { return $sText; } return $sTextTemplatePart; }, $sTextTemplate); }