public function run($dotted = 0) { $this->_dotted = $dotted; if (isset($this->_cfg['content'], $this->_cfg['summary']) && $this->_cfg['summary'] != '' && $this->_cfg['content'] != '') { $param = explode(",", $this->_cfg['summary']); $this->_cfg['content'] = $this->beforeCut($this->_cfg['content'], $this->getCut()); foreach ($param as $doing) { $process = explode(":", $doing); switch ($process[0]) { case 'notags': $this->_cfg['content'] = strip_tags($this->_cfg['content']); break; case 'noparser': $this->_cfg['content'] = APIhelpers::sanitarTag($this->_cfg['content']); break; case 'chars': if (!(isset($process[1]) && $process[1] > 0)) { $process[1] = 200; } $this->_cfg['content'] = APIhelpers::mb_trim_word($this->_cfg['content'], $process[1]); break; case 'len': if (!(isset($process[1]) && $process[1] > 0)) { $process[1] = 200; } $this->_cfg['content'] = $this->summary($this->_cfg['content'], $process[1], 50, true, $this->getCut()); break; } } } return $this->dotted($dotted); }
/** * Получение строки из языкового пакета * * @param string $name имя записи в языковом пакете * @param string $def Строка по умолчанию, если запись в языковом пакете не будет обнаружена * @return string строка в соответствии с текущими языковыми настройками */ public function getMsg($name, $def = '') { $out = \APIhelpers::getkey($this->_lang, $name, $def); if (class_exists('evoBabel', false) && isset($this->modx->snippetCache['lang'])) { $msg = $this->modx->runSnippet('lang', array('a' => $name)); if (!empty($msg)) { $out = $msg; } } return $out; }
public function process() { //регистрация без логина, по емейлу if ($this->getField('username') == '') { $this->setField('username', $this->getField('email')); } if ($this->checkSubmitProtection()) { return; } //регистрация со случайным паролем if ($this->getField('password') == '' && !isset($this->rules['password'])) { $this->setField('password', \APIhelpers::genPass($this->getCFGDef('passwordLength', 6))); } $fields = $this->filterFields($this->getFormData('fields'), $this->allowedFields, $this->forbiddenFields); $result = $this->user->create($fields)->save(true); $this->log('Register user', array('data' => $fields, 'result' => $result)); if (!$result) { $this->addMessage($this->lexicon->getMsg('register.registration_failed')); } else { $this->addWebUserToGroups($this->user->getID(), $this->getCFGDef('userGroups')); parent::process(); } }
* DocLister wrapper for SimpleGallery table * * @category snippet * @version 1.0.0 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License (GPL) * @internal @properties * @internal @modx_category Content * @author Pathologic (m@xim.name) */ include_once MODX_BASE_PATH . 'assets/lib/APIHelpers.class.php'; $_prepare = explode(",", $prepare); $prepare = array(); $prepare[] = \APIhelpers::getkey($modx->event->params, 'BeforePrepare', ''); $prepare = array_merge($prepare, $_prepare); $prepare[] = 'DLsgLister::prepare'; $prepare[] = \APIhelpers::getkey($modx->event->params, 'AfterPrepare', ''); $modx->event->params['prepare'] = trim(implode(",", $prepare), ','); $params = array_merge(array("controller" => "onetable", "config" => "sgLister:assets/snippets/simplegallery/config/"), $modx->event->params, array('depth' => '0', 'showParent' => '-1')); if (!class_exists("DLsgLister", false)) { class DLsgLister { public static function prepare(array $data = array(), DocumentParser $modx, $_DL, prepare_DL_Extender $_extDocLister) { $imageField = $_DL->getCfgDef('imageField'); $thumbOptions = $_DL->getCfgDef('thumbOptions'); $thumbSnippet = $_DL->getCfgDef('thumbSnippet'); if (!empty($thumbOptions) && !empty($thumbSnippet)) { $_thumbOptions = json_decode($thumbOptions, true); if (is_array($_thumbOptions)) { foreach ($_thumbOptions as $key => $value) { $postfix = $key == 'default' ? '.' : '_' . $key . '.';
public function toArray($prefix = '', $suffix = '', $sep = '_', $render = true) { $out = array_merge($this->toArrayMain(), $this->toArrayTV($render), array($this->fieldPKName() => $this->getID())); return \APIhelpers::renameKeyArr($out, $prefix, $suffix, $sep); }
/** * Редирект */ public function moveTo($params) { $id = (int) APIHelpers::getkey($params, 'id', 0); $uri = APIHelpers::getkey($params, 'url', ''); if (empty($uri) && !empty($id) || !is_string($uri)) { $uri = $this->makeUrl($id); } $code = (int) APIHelpers::getkey($params, 'code', 0); $addUrl = APIHelpers::getkey($params, 'addUrl', ''); if (is_scalar($addUrl) && $addUrl != '') { $uri .= "?" . $addUrl; } if (APIHelpers::getkey($params, 'validate', false)) { if (isset($this->modx->snippetCache['getPageID'])) { $out = $this->modx->runSnippet('getPageID', compact('uri')); if (empty($out)) { $uri = ''; } } else { $uri = APIhelpers::sanitarTag($uri); } } else { //$modx->sendRedirect($url, 0, 'REDIRECT_HEADER', 'HTTP/1.1 307 Temporary Redirect'); header("Location: " . $uri, true, $code > 0 ? $code : 307); } return $uri; }
public function checkString($value, $minLen = 1, $alph = array(), $mixArray = array(), $debug = false) { return \APIhelpers::checkString($value, $minLen, $alph, $mixArray, $debug); }
/** * Переменовывание элементов массива * * @param $data массив с данными * @param string $prefix префикс ключей * @param string $suffix суффикс ключей * @param string $sep разделитель суффиксов, префиксов и ключей массива * @return array массив с переименованными ключами */ public function renameKeyArr($data, $prefix = '', $suffix = '', $sep = '.') { return APIhelpers::renameKeyArr($data, $prefix, $suffix, $sep); }
if (!defined('MODX_BASE_PATH')) { die('HACK???'); } include_once MODX_BASE_PATH . 'assets/lib/APIHelpers.class.php'; $p =& $modx->event->params; if (!is_array($p)) { $p = array(); } $titleField = APIhelpers::getkey($p, 'titleField', 'pagetitle'); $valueField = APIhelpers::getkey($p, 'valueField', 'id'); $p = array_merge(array('idType' => 'parents', 'valueField' => $valueField, 'titleField' => $titleField, 'api' => implode(",", array($titleField, $valueField)), 'controller' => 'site_content', 'debug' => '0'), $p); $json = $modx->runSnippet("DocLister", $p); $json = jsonHelper::jsonDecode($json, array('assoc' => true)); $out = array(); $nopTitle = APIhelpers::getkey($p, 'addNopTitle'); if ($nopTitle) { $nopValue = APIhelpers::getkey($p, 'addNopValue'); $out[] = $nopTitle . '==' . $nopValue; } foreach ($json as $el) { $out[] = APIhelpers::getkey($el, $titleField) . '==' . APIhelpers::getkey($el, $valueField); } if (APIhelpers::getkey($p, 'debug')) { $key = APIhelpers::getkey($p, 'sysKey', 'dl') . '.debug'; $debugStack = $modx->getPlaceholder($key); if (!empty($debugStack)) { $modx->logEvent(0, 1, $debugStack, 'DocLister [DLValueList]'); } } return implode("||", $out);
<a href="[+url+]" title="[+e.title+]">[+title+]</a> [+dl.submenu+] </li>'); /** * TplDepthN Шаблон пункта меню вложенности N * TplNoChildrenDepthN Шаблон пункта меню вложенности N без дочерних элементов * noChildrenRowTPL Общий шаблон пункта меню без дочерних элементов */ $currentTpl = \APIhelpers::getkey($p, 'TplDepth' . $currentDepth, $currentTpl); $currentNoChildrenTpl = \APIhelpers::getkey($p, 'TplNoChildrenDepth' . $currentDepth); if (empty($currentNoChildrenTpl)) { $currentNoChildrenTpl = \APIhelpers::getkey($p, 'noChildrenRowTPL', $currentTpl); } /** Условия выборки документов для всех уровней */ $p['addWhereList'] = $currentWhere = \APIhelpers::getkey($p, 'addWhereList', 'c.hidemenu = 0'); /** addWhereListN Условия выборки документов N уровня */ $currentWhere = \APIhelpers::getkey($p, 'addWhereList' . $currentDepth, $currentWhere); $p['orderBy'] = $currentOrderBy = \APIhelpers::getkey($p, 'orderBy', 'menuindex ASC, id ASC'); /** orderByN Условия сортировки документов N уровня */ $currentOrderBy = \APIhelpers::getkey($p, 'orderBy' . $currentDepth, $currentOrderBy); /** * Получение prepare сниппетов из параметров BeforePrepare и AfterPrepare * для совмещения с обязательным вызовом DLFixedPrepare::buildMenu метода */ $prepare = \APIhelpers::getkey($p, 'BeforePrepare', ''); $prepare = explode(",", $prepare); $prepare[] = 'DLFixedPrepare::buildMenu'; $prepare[] = \APIhelpers::getkey($p, 'AfterPrepare', ''); $p['prepare'] = trim(implode(",", $prepare), ','); return $modx->runSnippet('DocLister', array_merge(array('idType' => 'parents', 'parents' => \APIhelpers::getkey($p, 'parents', 0)), $p, array('params' => $p, 'tpl' => $currentTpl, 'ownerTPL' => $currentOwnerTpl, 'mainRowTpl' => $currentTpl, 'noChildrenRowTPL' => $currentNoChildrenTpl, 'noneWrapOuter' => '0', 'addWhereList' => $currentWhere, 'orderBy' => $currentOrderBy)));
/** * Группировка документов по первой букве * * [[DLFirstChar? * &documents=`2,4,23,3` * &idType=`documents` * &tpl=`@CODE:[+CharSeparator+][+OnNewChar+]<span class="brand_name"><a href="[+url+]">[+pagetitle+]</a></span><br />` * &tplOnNewChar=`@CODE:<div class="block"><strong class="bukva">[+char+]</strong> ([+total+])</div>` * &tplCharSeparator=`@CODE:</div>` * &orderBy=`BINARY pagetitle ASC` * ]] */ if (!defined('MODX_BASE_PATH')) { die('HACK???'); } include_once MODX_BASE_PATH . 'assets/lib/APIHelpers.class.php'; include_once MODX_BASE_PATH . 'assets/snippets/DocLister/lib/DLFixedPrepare.class.php'; $p =& $modx->event->params; if (!is_array($p)) { $p = array(); } /** * Получение prepare сниппетов из параметров BeforePrepare и AfterPrepare * для совмещения с обязательным вызовом DLFixedPrepare::firstChar метода */ $prepare = \APIhelpers::getkey($p, 'BeforePrepare', ''); $prepare = explode(",", $prepare); $prepare[] = 'DLFixedPrepare::firstChar'; $prepare[] = \APIhelpers::getkey($p, 'AfterPrepare', ''); $p['prepare'] = trim(implode(",", $prepare), ','); return $modx->runSnippet('DocLister', $p);
public function process() { switch ($this->mode) { /** * Задаем хэш, отправляем пользователю ссылку для восстановления пароля */ case "hash": $uid = $this->getField($this->userField); if ($hash = $this->getUserHash($uid)) { $this->setFields($this->user->toArray()); $url = $this->getCFGDef('resetTo', $this->modx->documentIdentifier); $this->setField('reset.url', $this->modx->makeUrl($url, "", "&{$this->uidField}={$this->getField($this->uidField)}&{$this->hashField}={$hash}", 'full')); $this->mailConfig['to'] = $this->user->edit($uid)->get('email'); parent::process(); } else { $this->addMessage($this->lexicon->getMsg('reminder.users_only')); } break; /** * Если пароль не задан, то создаем пароль * Отправляем пользователю письмо с паролем, если указан шаблон такого письма * Если не указан, то запрещаем отправку письма, пароль будет показан на экране */ /** * Если пароль не задан, то создаем пароль * Отправляем пользователю письмо с паролем, если указан шаблон такого письма * Если не указан, то запрещаем отправку письма, пароль будет показан на экране */ case "reset": $uid = $this->getField($this->uidField); $hash = $this->getField($this->hashField); if ($hash && $hash == $this->getUserHash($uid)) { if ($this->getField('password') == '' && !isset($this->rules['password'])) { $this->setField('password', \APIhelpers::genPass($this->getCFGDef('passwordLength', 6))); } $fields = $this->filterFields($this->getFormData('fields'), array('password')); $result = $this->user->edit($uid)->fromArray($fields)->save(true); $this->log('Update password', array('data' => $fields, 'result' => $result)); if (!$result) { $this->addMessage($this->lexicon->getMsg('reminder.update_failed')); } else { $this->setField('newpassword', $this->getField('password')); $this->setFields($this->user->toArray()); if ($this->getCFGDef('resetReportTpl')) { $this->mailConfig['to'] = $this->getField('email'); } parent::process(); } } else { $this->addMessage($this->lexicon->getMsg('reminder.update_failed')); parent::process(); } break; } }
/** * Готовит данные для вывода в шаблон * @param array $fields массив с данными * @param string $suffix добавляет суффикс к имени поля * @param bool $split преобразование массивов в строки * @return array */ public function fieldsToPlaceholders($fields = array(), $suffix = '', $split = false) { $plh = $fields; if (is_array($fields) && !empty($fields)) { foreach ($fields as $field => $value) { $field = array($field, $suffix); $field = implode('.', array_filter($field)); if ($split && is_array($value)) { $arraySplitter = $this->getCFGDef($field . 'Splitter', $this->getCFGDef('arraySplitter', '; ')); $value = implode($arraySplitter, $value); } $plh[$field] = \APIhelpers::e($value); } } if (!empty($this->placeholders)) { $plh = array_merge($plh, $this->placeholders); } return $plh; }
public function getCFGDef($name, $def = null) { return \APIhelpers::getkey($this->_cfg, $name, $def); }
protected final function sanitarTag($data) { return parent::sanitarTag($this->modx->stripTags($data)); }
public function getCFGDef($param, $default = null) { return \APIhelpers::getkey($this->config, $param, $default); }