Skip to content
Permalink
Browse files

update DocLister

  • Loading branch information...
Dmi3yy committed Aug 24, 2017
1 parent 94f4396 commit 6061996046a2eee1aa1fe3e2a7a285e9c9230a1d
9 assets/lib/Helpers/Config.php 100755 → 100644
@@ -86,10 +86,10 @@ public function getConfig()
* @param array $cfg массив настроек
* @return int результат сохранения настроек
*/
public function setConfig($cfg)
public function setConfig($cfg, $overwrite = false)
{
if (is_array($cfg)) {
$this->_cfg = array_merge($this->_cfg, $cfg);
$this->_cfg = $overwrite ? $cfg : array_merge($this->_cfg, $cfg);
$ret = count($this->_cfg);
} else {
$ret = false;
@@ -98,6 +98,11 @@ public function setConfig($cfg)
return $ret;
}
/**
* @param $name
* @param null $def
* @return mixed
*/
public function getCFGDef($name, $def = null)
{
return \APIhelpers::getkey($this->_cfg, $name, $def);
@@ -292,7 +292,7 @@ public function relativePath($path, $owner = null)
}
$path = str_replace('\\', '/', $path);
if (!(empty($path) || !is_scalar($path)) && !preg_match("/^http(s)?:\/\/\w+/", $path)) {
$path = trim(preg_replace("#^" . preg_quote($owner) . "#", '', $path), '/');
$path = trim(preg_replace("#^" . preg_quote($owner) . "#", '', $path), DIRECTORY_SEPARATOR);
} else {
$path = '';
}
134 assets/lib/Helpers/Mailer.php 100755 → 100644
@@ -1,6 +1,7 @@
<?php namespace Helpers;
include_once(MODX_BASE_PATH . 'assets/lib/APIHelpers.class.php');
include_once(MODX_MANAGER_PATH . 'includes/extenders/modxmailer.class.inc.php');
/**
* Class Mailer
@@ -15,7 +16,7 @@ class Mailer
protected $modx = null;
public $config = array();
protected $debug = false;
protected $queuePath = 'assets/cache/mail/';
/**
* Mailer constructor.
@@ -26,10 +27,11 @@ class Mailer
public function __construct(\DocumentParser $modx, $cfg, $debug = false)
{
$this->modx = $modx;
$modx->loadExtension('MODxMailer');
$this->mail = $modx->mail;
$this->mail = new \MODxMailer();
$this->mail->init($modx);
$this->config = $cfg;
$this->debug = $debug;
$this->applyMailConfig();
}
/**
@@ -88,15 +90,7 @@ public function send($report)
return false;
}
$this->mail->IsHTML($this->getCFGDef('isHtml', 1));
$this->mail->From = $this->getCFGDef('from', $this->modx->config['site_name']);
$this->mail->FromName = $this->getCFGDef('fromName', $this->modx->config['emailsender']);
$this->mail->Subject = $this->getCFGDef('subject');
$this->mail->Body = $report;
$this->addAddressToMailer("replyTo", $this->getCFGDef('replyTo'));
$this->addAddressToMailer("to", $this->getCFGDef('to'));
$this->addAddressToMailer("cc", $this->getCFGDef('cc'));
$this->addAddressToMailer("bcc", $this->getCFGDef('bcc'));
$result = $this->mail->send();
if ($result) {
@@ -107,6 +101,124 @@ public function send($report)
return $result;
}
/**
* @param $report
* @return bool
*/
public function toQueue($report)
{
//если отправлять некуда или незачем, то делаем вид, что отправили
if (!$this->getCFGDef('to') || $this->getCFGDef('noemail')) {
return true;
} elseif (empty($report)) {
return false;
}
$this->mail->Body = $report;
$this->Body = $this->modx->removeSanitizeSeed($this->mail->Body);
$this->Subject = $this->modx->removeSanitizeSeed($this->mail->Subject);
try {
$result = $this->mail->preSend() && $this->saveMessage();
} catch (\phpmailerException $e) {
$this->mail->SetError($e->getMessage());
$result = false;
}
if ($result) {
$this->mail->ClearAllRecipients();
$this->mail->ClearAttachments();
$result = $this->getFileName();
}
return $result;
}
/**
* @param string $path
* @return bool
*/
public function setQueuePath($path = '') {
if (!empty($path)) {
$this->queuePath = $path;
return true;
} else {
return false;
}
}
/**
* @return mixed
*/
protected function saveMessage()
{
$data = serialize(array(
"header" => $this->mail->getMIMEHeader(),
"body" => $this->mail->getMIMEBody(),
"config" => $this->config
));
$file = $this->getFileName();
$dir = MODX_BASE_PATH . $this->queuePath;
if (!is_dir($dir)) {
@mkdir($dir);
}
$result = @file_put_contents($dir . $file, $data) !== false;
if ($result) {
$result = $file;
}
return $result;
}
/**
* @return string
*/
protected function getFileName() {
return $this->mail->getMessageID() . '.eml';
}
/**
* @param $file
* @return bool
*/
public function fromQueue($file)
{
$result = false;
$dir = MODX_BASE_PATH . $this->queuePath;
if (file_exists($dir . $file) && is_readable($dir . $file)) {
$message = unserialize(file_get_contents($dir . $file));
$this->config = $message['config'];
$this->applyMailConfig();
$this->mail->setMIMEHeader($message['header'])->setMIMEBody($message['body']);
unset($message);
$result = $this->mail->postSend();
if ($result) {
$this->mail->setMIMEBody()->setMIMEHeader();
@unlink($dir . $file);
}
}
return $result;
}
/**
* @return $this
*/
protected function applyMailConfig()
{
$this->mail->IsHTML($this->getCFGDef('isHtml', 1));
$this->mail->From = $this->getCFGDef('from', $this->modx->config['emailsender']);
$this->mail->FromName = $this->getCFGDef('fromName', $this->modx->config['site_name']);
$this->mail->Subject = $this->getCFGDef('subject');
$this->addAddressToMailer("replyTo", $this->getCFGDef('replyTo'));
$this->addAddressToMailer("to", $this->getCFGDef('to'));
$this->addAddressToMailer("cc", $this->getCFGDef('cc'));
$this->addAddressToMailer("bcc", $this->getCFGDef('bcc'));
return $this;
}
/**
* @param string $param
* @param mixed $default
@@ -186,6 +186,25 @@ public function getDefaultFields()
return $this->default_field;
}
/**
* @param $value
* @return int|mixed|string
*/
protected function getTime($value)
{
$value = trim($value);
if (!empty($value)) {
if (!is_numeric($value)) {
$value = (int)strtotime($value);
}
if (!empty($value)) {
$value += $this->modxConfig('server_offset_time');
}
}
return $value;
}
/**
* @param string $name
* @param null $default
@@ -11,33 +11,35 @@ class modManagers extends MODxAPI
*/
protected $default_field = array(
'user' => array(
'username' => "",
'password' => "",
'username' => '',
'password' => '',
),
'attribute' => array(
'fullname' => "",
'fullname' => '',
'role' => 0,
'email' => "",
'phone' => "",
'mobilephone' => "",
'email' => '',
'phone' => '',
'mobilephone' => '',
'blocked' => 0,
'blockeduntil' => 0,
'blockedafter' => 0,
'logincount' => 0,
'lastlogin' => 0,
'thislogin' => 0,
'failedlogincount' => 0,
'sessionid' => "",
'sessionid' => '',
'dob' => 0,
'gender' => "",
'country' => "",
'state' => "",
'city' => "",
'street' => "",
'zip' => "",
'fax' => "",
'photo' => "",
'comment' => ""
'gender' => 0,
'country' => '',
'state' => '',
'city' => '',
'street' => '',
'zip' => '',
'fax' => '',
'photo' => '',
'comment' => '',
'createdon' => 0,
'editedon' => 0
),
'hidden' => array(
'internalKey'
@@ -97,6 +99,18 @@ protected function findUser($data)
return $find;
}
/**
* @param array $data
* @return $this
*/
public function create($data = array())
{
parent::create($data);
$this->set('createdon', time());
return $this;
}
/**
* @param $id
* @return $this
@@ -111,6 +125,7 @@ public function edit($id)
if (!$find = $this->findUser($id)) {
$this->id = null;
} else {
$this->set('editedon', time());
$result = $this->query("
SELECT * from {$this->makeTable('user_attributes')} as attribute
LEFT JOIN {$this->makeTable('manager_users')} as user ON user.id=attribute.internalKey
@@ -149,6 +164,10 @@ public function set($key, $value)
session_regenerate_id(false);
$value = session_id();
break;
case 'editedon':
case 'createdon':
$value = $this->getTime($value);
break;
}
$this->field[$key] = $value;
}
@@ -434,25 +434,6 @@ protected function findUserBy($data)
return $find;
}
/**
* @param $value
* @return int|mixed|string
*/
protected function getTime($value)
{
$value = trim($value);
if (!empty($value)) {
if (!is_numeric($value)) {
$value = (int)strtotime($value);
}
if (!empty($value)) {
$value += $this->modxConfig('server_offset_time');
}
}
return $value;
}
/**
* @param array $data
* @return $this

0 comments on commit 6061996

Please sign in to comment.
You can’t perform that action at this time.