Skip to content
This repository has been archived by the owner on Mar 8, 2021. It is now read-only.

Commit

Permalink
Merge pull request #3 from evolution-cms/develop
Browse files Browse the repository at this point in the history
1
  • Loading branch information
scorN17 authored Jan 12, 2018
2 parents 14b64c0 + d327ad0 commit c7120bf
Show file tree
Hide file tree
Showing 41 changed files with 249 additions and 1,594 deletions.
13 changes: 9 additions & 4 deletions assets/lib/APIHelpers.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ public static function mb_trim_word($html, $len, $encoding = 'UTF-8')
}

/**
* @param mixed $data
* @param string $key
* @param mixed $default null
* Получение значения по ключу из массива, либо возврат значения по умолчанию
*
* @param mixed $data массив
* @param string $key ключ массива
* @param mixed $default null значение по умолчанию
* @param Closure $validate null функция дополнительной валидации значения (должна возвращать true или false)
* @return mixed
*/
public static function getkey($data, $key, $default = null)
Expand All @@ -68,7 +71,9 @@ public static function getkey($data, $key, $default = null)
if (is_array($data) && (is_int($key) || is_string($key)) && $key !== '' && array_key_exists($key, $data)) {
$out = $data[$key];
}

if (!empty($validate) && is_callable($validate)) {
$out = (($validate($out) === true) ? $out : $default);
}
return $out;
}

Expand Down
35 changes: 17 additions & 18 deletions assets/lib/Helpers/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
include_once(MODX_BASE_PATH . 'assets/lib/APIHelpers.class.php');
require_once(MODX_BASE_PATH . "assets/snippets/DocLister/lib/jsonHelper.class.php");

use jsonHelper;
use APIhelpers;

class Config
{
private $_cfg = array();
Expand All @@ -15,7 +18,7 @@ public function __construct($cfg = array())
if ($cfg) {
$this->setConfig($cfg);
}
$this->fs = \Helpers\FS::getInstance();
$this->fs = FS::getInstance();
}

/**
Expand Down Expand Up @@ -60,7 +63,7 @@ public function loadConfig($name)

if ($this->fs->checkFile($configFile)) {
$json = file_get_contents(MODX_BASE_PATH . $configFile);
$config = array_merge($config, \jsonHelper::jsonDecode($json, array('assoc' => true), true));
$config = array_merge($config, jsonHelper::jsonDecode($json, array('assoc' => true), true));
}
}

Expand Down Expand Up @@ -102,7 +105,7 @@ public function setConfig($cfg, $overwrite = false)
*/
public function getCFGDef($name, $def = null)
{
return \APIhelpers::getkey($this->_cfg, $name, $def);
return APIhelpers::getkey($this->_cfg, $name, $def);
}

/**
Expand All @@ -114,22 +117,18 @@ public function getCFGDef($name, $def = null)
*/
public function loadArray($arr, $sep = ',')
{

if (is_scalar($arr)) {
$out = \jsonHelper::jsonDecode($arr, array('assoc' => true));
if (!is_array($out)) {
if ($sep) {
$out = array_filter(explode($sep, $arr));
} else {
$out = array();
switch(gettype($arr)){
case 'string':
$out = jsonHelper::jsonDecode($arr, array('assoc' => true));
if (!is_array($out)) {
$out = $sep ? array_filter(explode($sep, $arr)) : array();
}
}

return $out;
} elseif (is_array($arr)) {
return $arr;
} else {
return array();
break;
case 'array':
break;
default:
$out = array();
}
return $out;
}
}
12 changes: 7 additions & 5 deletions assets/lib/Helpers/FS.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function checkDir($path)

/**
* @param $file
* @param bool $format
* @param bool|array $format
* @return int|string
*/
public function fileSize($file, $format = false)
Expand All @@ -152,12 +152,14 @@ public function fileSize($file, $format = false)
if ($this->checkFile($file)) {
$out = filesize(MODX_BASE_PATH . $this->relativePath($file));
}
if ($format) {
$types = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');

if($format === true) $format = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
if (is_array($format)) {
$size = $out > 0 ? floor(log($out, 1024)) : 0;
$out = number_format($out / pow(1024, $size), 2, '.', ',') . ' ' . $types[$size];
$type = isset($format[$size]) ? ' '.$format[$size] : '';
$out = number_format($out / pow(1024, $size), 2, '.', ',') . $type;
}

return $out;
}

Expand Down
2 changes: 1 addition & 1 deletion assets/lib/Helpers/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function toQueue($report)
$this->Subject = $this->modx->removeSanitizeSeed($this->mail->Subject);
try {
$result = $this->mail->preSend() && $this->saveMessage();
} catch (\Exception $e) {
} catch (\phpmailerException $e) {
$this->mail->SetError($e->getMessage());

$result = false;
Expand Down
2 changes: 1 addition & 1 deletion assets/snippets/DocLister/config/core/sitemap.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"idType": "documents",
"ignoreEmpty": 1,
"addWhereList": "c.published = 1 AND c.deleted=0 AND c.searchable=1 AND c.type='document'",
"selectFields": "id,editedon,createdon,type",
"selectFields": "c.id,c.editedon,c.createdon,c.type",
"dateSource":"",
"tpl": "@CODE:\n<url>\n\t<loc>[+e.url+]</loc>\n\t<lastmod>[+date+]</lastmod>\n\t<changefreq>[+update+]</changefreq>\n\t<priority>[+priority+]</priority>\n</url>",
"tvList": "sitemap_changefreq,sitemap_priority",
Expand Down
2 changes: 1 addition & 1 deletion assets/snippets/DocLister/core/DocLister.abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public function __construct($modx, $cfg = array(), $startTime = null)
case 'parents':
default:
$cfg['idType'] = "parents";
if (($IDs = $this->getCFGDef('parents')) === null) {
if (($IDs = $this->getCFGDef('parents', '')) === '') {
$IDs = $this->getCurrentMODXPageID();
}
break;
Expand Down
23 changes: 21 additions & 2 deletions assets/snippets/DocLister/core/extender/paginate.extender.inc
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ class paginate_DL_Extender extends extDocLister
*/
private function renderPages($mode = '')
{
$currentPage = $this->currentPage();
$p = $this->reverse ? new DLpaginateReversed : new DLpaginate;
$p->nextT = $this->DocLister->getChunkByParam('TplNextP', '@CODE:<a href="[+link+]">[%paginate.next%] ></a>');
$p->prevT = $this->DocLister->getChunkByParam('TplPrevP', '@CODE:<a href="[+link+]">< [%paginate.prev%]</a>');
Expand All @@ -211,13 +212,13 @@ class paginate_DL_Extender extends extDocLister
$p->limit($this->DocLister->getCFGDef("pageLimit", 1)); //show page count
$p->adjacents($this->DocLister->getCFGDef("pageAdjacents", 4));
$p->target($this->getUrl());
$p->currentPage($this->currentPage());
$p->currentPage($currentPage);

switch (true) {
case ($mode == 'offset' && $this->totalPage() > 1):
$display = $this->DocLister->getCFGDef('display', 0);
$offset = $this->reverse ? $this->totalPage() * $display - $this->count : 0;
if ($this->currentPage() == 1) {
if ($currentPage == 1) {
$this->DocLister->config->setConfig(array('display'=>$display - $offset));
}
$p->setMode('offset', array(
Expand All @@ -228,6 +229,24 @@ class paginate_DL_Extender extends extDocLister
$p->parameterName($this->getRequestName('page'));
break;
}
if ($this->DocLister->getCFGDef('paginationMeta', 0)) {
$nextPage = $prevPage = 0;
if ($this->reverse) {
$currentPage = $this->totalPage() + 1 - $currentPage;
}
if ($currentPage > 1) {
$prevPage = $currentPage - 1;
}
if ($currentPage < $this->totalPage()) {
$nextPage = $currentPage + 1;
}
if ($nextPage) {
$this->modx->regClientStartupHTMLBlock('<link rel="next" href="' . $p->get_pagenum_link($nextPage) . '">');
}
if ($prevPage) {
$this->modx->regClientStartupHTMLBlock('<link rel="prev" href="' . $p->get_pagenum_link($prevPage) . '">');
}
}

return $p->getOutput();
}
Expand Down
2 changes: 1 addition & 1 deletion assets/snippets/DocLister/lib/DLTemplate.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public function getTemplate($id)
* @param bool $parseDocumentSource render html template via DocumentParser::parseDocumentSource()
* @return string html template with data without placeholders
*/
public function parseChunk($name, $data, $parseDocumentSource = false)
public function parseChunk($name, $data = array(), $parseDocumentSource = false)
{
$out = $this->getChunk($name);
if ($this->twigEnabled && ($out != '') && ($twig = $this->getTwig($name, $out))) {
Expand Down
2 changes: 1 addition & 1 deletion assets/snippets/FormLister/core/FormLister.abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function __construct(\DocumentParser $modx, $cfg = array())
$this->config->loadConfig($cfg['config']);
}
$this->config->setConfig($cfg);
if (isset($cfg['debug'])) {
if (isset($cfg['debug']) && $cfg['debug'] > 0) {
$this->debug = new Debug($modx, array(
'caller' => 'FormLister\\\\' . $cfg['controller']
));
Expand Down
23 changes: 16 additions & 7 deletions assets/snippets/FormLister/core/controller/Activate.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ public function __construct(\DocumentParser $modx, $cfg = array())
}
$userField = $this->getCFGDef('userField', 'email');
$this->userField = $userField;
if (!isset($_REQUEST['formid']) && !isset($_REQUEST[$userField]) && (isset($_REQUEST['hash']) && !empty($_REQUEST['hash']) && isset($_REQUEST['id']) && !empty($_REQUEST['id']))) {
$uidName = $this->getCFGDef('uidName', $this->user->fieldPKName());
if (!isset($_REQUEST['formid']) && !isset($_REQUEST[$userField]) && (isset($_REQUEST['hash']) && !empty($_REQUEST['hash']) && isset($_REQUEST[$uidName]) && !empty($_REQUEST[$uidName]))) {
$this->setField('hash', $_REQUEST['hash']);
$this->setField('id', (int)$_REQUEST['id']);
$this->setField('id', (int)$_REQUEST[$uidName]);
$this->mode = 'activate';
}
$this->log('Activate mode is ' . $this->mode);
Expand Down Expand Up @@ -83,7 +84,7 @@ public function getUserHash($uid)
$hash = false;
} else {
$userdata = $this->user->edit($uid)->toArray();
$hash = $userdata['id'] && $userdata['logincount'] < 0 ? md5(json_encode($userdata)) : false;
$hash = $this->user->getID() && $userdata['logincount'] < 0 ? md5(json_encode($userdata)) : false;
}

return $hash;
Expand All @@ -101,16 +102,24 @@ public function process()
case "hash":
$uid = $this->getField($this->userField);
$password = $this->getField('password');
if (($hash = $this->getUserHash($uid)) && ($password && $this->user->get('password') == $this->user->getPassword($password))) {
if (
($hash = $this->getUserHash($uid))
&& (
empty($password)
|| ($this->user->get('password') == $this->user->getPassword($password))
)
) {
$this->setFields($this->user->toArray());
if (!$password) {
if (empty($password)) {
$password = \APIhelpers::genPass($this->getCFGDef('passwordLength', 6));
$this->user->set('password', $password)->save(true);
$this->setField('user.password', $password);
$hash = $this->getUserHash($uid);
}
$url = $this->getCFGDef('activateTo', $this->modx->config['site_start']);
$url = $this->getCFGDef('activateTo', isset($this->modx->documentIdentifier) && $this->modx->documentIdentifier > 0 ? $this->modx->documentIdentifier : $this->config['site_start']);
$uidName = $this->getCFGDef('uidName', $this->user->fieldPKName());
$this->setField('activate.url', $this->modx->makeUrl($url, "",
http_build_query(array('id' => $this->getField('id'), 'hash' => $hash)),
http_build_query(array($uidName => $this->getField('id'), 'hash' => $hash)),
'full'));
$this->mailConfig['to'] = $this->user->get('email');
parent::process();
Expand Down
6 changes: 4 additions & 2 deletions assets/snippets/FormLister/core/controller/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static function uniqueEmail($fl, $value)
{
$result = true;
if (!is_null($fl->user) && ($fl->user->get("email") !== $value)) {
$fl->user->set('email', $value);
$fl->user->set('email', strtolower($value));
$result = $fl->user->checkUnique('web_user_attributes', 'email', 'internalKey');
}

Expand All @@ -108,7 +108,7 @@ public static function uniqueUsername($fl, $value)
{
$result = true;
if (!is_null($fl->user) && ($fl->user->get("email") !== $value)) {
$fl->user->set('username', $value);
$fl->user->set('username', strtolower($value));
$result = $fl->user->checkUnique('web_users', 'username');
}

Expand Down Expand Up @@ -141,6 +141,8 @@ public function process()
}
}
$fields = $this->filterFields($this->getFormData('fields'), $this->allowedFields, $this->forbiddenFields);
$fields['username'] = strtolower($fields['username']);
$fields['email'] = strtolower($fields['email']);
$result = $this->user->fromArray($fields)->save(true);
$this->log('Update profile', array('data' => $fields, 'result' => $result));
if ($result) {
Expand Down
17 changes: 9 additions & 8 deletions assets/snippets/FormLister/core/controller/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,22 @@ public function process()
if (!$result) {
$this->addMessage($this->lexicon->getMsg('register.registration_failed'));
} else {
$this->user->close();
$userdata = $this->user->edit($result)->toArray();
$this->setFields($userdata);
$this->setField('user.password',$password);
$this->runPrepare('preparePostProcess');
if ($checkActivation) {
$fields = $this->user->edit($result)->toArray();
$hash = md5(json_encode($fields));
$hash = md5(json_encode($userdata));
$uidName = $this->getCFGDef('uidName', $this->user->fieldPKName());
$query = http_build_query(array(
'id' => $result,
$uidName => $result,
'hash' => $hash
));
$url = $this->getCFGDef('activateTo',$this->modx->config['site_start']);
$this->setField('activate.url', $this->modx->makeUrl($url, "",
$this->setField('activate.url', $this->modx->makeUrl($url, '',
$query, 'full'));
}
$this->user->close();
$this->setFields($this->user->edit($result)->toArray());
$this->setField('user.password',$password);
$this->runPrepare('preparePostProcess');
parent::process();
}
}
Expand Down
14 changes: 8 additions & 6 deletions assets/snippets/FormLister/core/controller/Reminder.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ public function __construct(\DocumentParser $modx, $cfg = array())
$this->log('Lexicon loaded', array('lexicon' => $lang));
}
$hashField = $this->getCFGDef('hashField', 'hash');
$uidField = $this->getCFGDef('uidField', 'id');
$uidField = $this->getCFGDef('uidField', $this->user->fieldPKName());
$uidName = $this->getCFGDef('uidName', $uidField);
$userField = $this->getCFGDef('userField', 'email');
$this->hashField = $hashField;
$this->uidField = $uidField;
$this->userField = $userField;
if ((isset($_REQUEST[$hashField]) && !empty($_REQUEST[$hashField])) && (isset($_REQUEST[$uidField]) && !empty($_REQUEST[$uidField]))) {
if ((isset($_REQUEST[$hashField]) && !empty($_REQUEST[$hashField])) && (isset($_REQUEST[$uidName]) && !empty($_REQUEST[$uidName]))) {
$this->setFields($_REQUEST);
$this->mode = 'reset';
$this->config->setConfig(array(
Expand Down Expand Up @@ -75,7 +76,7 @@ public function render()
public function renderReset()
{
$hash = $this->getField($this->hashField);
$uid = $this->getField($this->uidField);
$uid = $this->getField($this->getCFGDef('uidName', $this->uidField));
if ($hash && $hash == $this->getUserHash($uid)) {
if ($this->getCFGDef('resetTpl')) {
$this->setField('user.hash', $hash);
Expand Down Expand Up @@ -116,7 +117,7 @@ public function getUserHash($uid)
$hash = false;
} else {
$userdata = $this->user->edit($uid)->toArray();
$hash = $userdata['id'] ? md5(json_encode($userdata)) : false;
$hash = $this->user->getID() ? md5(json_encode($userdata)) : false;
}

return $hash;
Expand All @@ -135,9 +136,10 @@ public function process()
$uid = $this->getField($this->userField);
if ($hash = $this->getUserHash($uid)) {
$this->setFields($this->user->toArray());
$url = $this->getCFGDef('resetTo', $this->modx->config['site_start']);
$url = $this->getCFGDef('resetTo', isset($this->modx->documentIdentifier) && $this->modx->documentIdentifier > 0 ? $this->modx->documentIdentifier : $this->config['site_start']);
$uidName = $this->getCFGDef('uidName', $this->uidField);
$this->setField('reset.url', $this->modx->makeUrl($url, "",
http_build_query(array($this->uidField => $this->getField($this->uidField),
http_build_query(array($uidName => $this->getField($this->uidField),
$this->hashField => $hash
)),
'full'));
Expand Down
Loading

0 comments on commit c7120bf

Please sign in to comment.