From b4ab1bdcf77fe8ee90539f374421f13a67a7de9f Mon Sep 17 00:00:00 2001 From: Pavel Date: Sat, 19 Dec 2015 17:39:01 +0500 Subject: [PATCH 01/19] =?UTF-8?q?*=20The=20structure=20of=20the=20package?= =?UTF-8?q?=20has=20changed.=20+=20src=20=E2=86=92=20Response:=20A=20new?= =?UTF-8?q?=20helper=20class=20recommended=20to=20be=20used=20as=20a=20ske?= =?UTF-8?q?leton=20for=20the=20response=20to=20a=20client=20request.=20+?= =?UTF-8?q?=20src=20=E2=86=92=20Response=20=E2=86=92=20Response=5Fv02:=20A?= =?UTF-8?q?=20new=20concrete=20realization=20of=20the=20abstract=20?= =?UTF-8?q?=E2=80=9CResponse=E2=80=9D=20class.=20+=20ddTools=20=E2=86=92?= =?UTF-8?q?=20getResponse:=20A=20new=20method=20to=20return=20a=20proper?= =?UTF-8?q?=20instance=20of=20the=20=E2=80=9CResponse=E2=80=9D=20class.=20?= =?UTF-8?q?*=20composer.json:=20the=20=E2=80=9Cautoload=E2=80=9D=20section?= =?UTF-8?q?=20has=20been=20updated.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 5 +- modx.ddtools.class.php | 16 ++++++ src/Response.php | 66 ++++++++++++++++++++++++ src/Response/Response_v02.php | 96 +++++++++++++++++++++++++++++++++++ 4 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 src/Response.php create mode 100644 src/Response/Response_v02.php diff --git a/composer.json b/composer.json index 6e13bd2..183708c 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,9 @@ "dd/composer-plugin-modxevo-library-ddtools-installer": "~1.0" }, "autoload": { - "files": ["modx.ddtools.class.php"] + "files": ["modx.ddtools.class.php"], + "psr-4": { + "DDTools\\": "src/" + } } } \ No newline at end of file diff --git a/modx.ddtools.class.php b/modx.ddtools.class.php index a129ad2..b25270c 100644 --- a/modx.ddtools.class.php +++ b/modx.ddtools.class.php @@ -1305,6 +1305,22 @@ public static function generateRandomString($length = 8, $chars = 'abcdefghijklm return $string; } + + /** + * getResponse + * @version 1.0 (2015-12-19) + * + * @desc Returns a proper instance of the “Response” class recommended to be used as response to an HTTP request + */ + public static function getResponse(){ + $output = false; + + if(class_exists('\DDTools\Response\Response_v02')){ + $output = new \DDTools\Response\Response_v02(); + } + + return $output; + } } if(isset($modx)){ diff --git a/src/Response.php b/src/Response.php new file mode 100644 index 0000000..a35a642 --- /dev/null +++ b/src/Response.php @@ -0,0 +1,66 @@ +meta. + * + * @param $meta + * + * @return bool + */ + public function setMeta($meta){ + $output = false; + + if($this->validateMeta()){ + $this->meta = $meta; + $output = true; + } + + return $output; + } + + /** + * toArray + * + * Converts this object to array. + * + * @return array + */ + public function toArray(){ + return array( + 'meta' => $this->meta, + 'data' => $this->data + ); + } + + /** + * toJSON + * + * Converts this object to JSON string. + * + * @return string + */ + public function toJSON(){ + return json_encode($this->toArray()); + } + + public function __toString(){ + return $this->toJSON(); + } +} \ No newline at end of file diff --git a/src/Response/Response_v02.php b/src/Response/Response_v02.php new file mode 100644 index 0000000..2913f69 --- /dev/null +++ b/src/Response/Response_v02.php @@ -0,0 +1,96 @@ +meta. + * + * @var array + */ + protected static $allowedMetaKeys = array( + 'code', 'eTag', 'success', 'message' + ); + + /** + * allowedMetaMessageKeys + * + * Allowed keys in $this->meta['message']. + * + * @var array + */ + protected static $allowedMetaMessageKeys = array( + 'content', 'title' + ); + + /** + * validateMeta + * + * $meta - is an array of meta data. The method excludes any values passed in $meta except “code”, “eTag”, “success”, + * and “message”. $meta['code'] and $meta['success'] are required. If defined, $meta['message'] must be an associative array with content + * and, optionally, with a title. + * + * Examples: + * + * ```php + * $meta = array( + * "code" => 200, // REQUIRED + * "success" => true // REQUIRED + * ); + * + * $meta = array( + * "code" => 201, // REQUIRED + * "success" => true, // REQUIRED + * "message" => array( + * "content" => "You have successfully signed up. You will be redirected to your account in a moment.", // REQUIRED + * "title" => "Success!" + * ) + * ); + * ``` + * + * @return bool + */ + public function validateMeta(){ + $output = false; + + if( + //code is set and int + isset($this->meta['code']) && is_int($this->meta['code']) && + //success is set and bool + isset($this->meta['success']) && is_bool($this->meta['success']) && + ( + //message is not set + !isset($this->meta['message']) || + ( + //message is set and contains content + is_array($this->meta['message']) && isset($this->meta['content']) + ) + ) + ){ + if( + //there is no diff between meta keys and allowed meta keys + !count(array_diff(array_keys($this->meta), static::$allowedMetaKeys)) && + ( + //message is not set + !isset($this->meta['message']) || + //there is no diff between meta message keys and allowed meta message keys + !count(array_diff(array_keys($this->meta['message']), static::$allowedMetaMessageKeys)) + ) + ){ + $output = true; + } + } + + return $output; + } +} \ No newline at end of file From fd7a2307d5c333c1d924b1c2fdaef782a0916e0c Mon Sep 17 00:00:00 2001 From: Pavel Date: Sat, 19 Dec 2015 17:42:42 +0500 Subject: [PATCH 02/19] =?UTF-8?q?*=20composer.json:=20the=20=E2=80=9Ccompo?= =?UTF-8?q?ser-plugin-modxevo-library-ddtools-installer=E2=80=9D=20was=20u?= =?UTF-8?q?pdated.=20The=20library=20now=20requires=201.0.4=20or=20newer.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 183708c..e7c42ed 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "license": "MIT", "require": { "php": ">=5.3.0", - "dd/composer-plugin-modxevo-library-ddtools-installer": "~1.0" + "dd/composer-plugin-modxevo-library-ddtools-installer": "^1.0.4" }, "autoload": { "files": ["modx.ddtools.class.php"], From 24f4d33b964b74e4f66a58cce742af216ea1fa96 Mon Sep 17 00:00:00 2001 From: Pavel Date: Sat, 19 Dec 2015 18:29:22 +0500 Subject: [PATCH 03/19] =?UTF-8?q?*=20ddTools=20=E2=86=92=20getResponse:=20?= =?UTF-8?q?The=20method=20now=20returns=20the=20newest=20version=20of=20Re?= =?UTF-8?q?sponse=20by=20default.=20But=20it=20will=20be=20possible=20to?= =?UTF-8?q?=20get=20an=20instance=20of=20any=20version=20in=20the=20future?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modx.ddtools.class.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/modx.ddtools.class.php b/modx.ddtools.class.php index b25270c..605906e 100644 --- a/modx.ddtools.class.php +++ b/modx.ddtools.class.php @@ -1310,13 +1310,22 @@ public static function generateRandomString($length = 8, $chars = 'abcdefghijklm * getResponse * @version 1.0 (2015-12-19) * + * @param string $version - the required version of Response. + * * @desc Returns a proper instance of the “Response” class recommended to be used as response to an HTTP request + * + * @return bool|DDTools\Response */ - public static function getResponse(){ + public static function getResponse($version = null){ $output = false; - if(class_exists('\DDTools\Response\Response_v02')){ - $output = new \DDTools\Response\Response_v02(); + switch($version){ + case null: + case '0.2': + if(class_exists('\DDTools\Response\Response_v02')){ + $output = new \DDTools\Response\Response_v02(); + } + break; } return $output; From d67c27b9141c73113e5a215e2175a79afd3f60ea Mon Sep 17 00:00:00 2001 From: Pavel Date: Sat, 19 Dec 2015 18:43:04 +0500 Subject: [PATCH 04/19] =?UTF-8?q?+=20Response:=20Added=20a=20getter=20for?= =?UTF-8?q?=20=E2=80=9Cmeta=E2=80=9D.=20+=20Response:=20Added=20a=20getter?= =?UTF-8?q?=20and=20setter=20for=20=E2=80=9Cdata=E2=80=9D.=20*=20Response?= =?UTF-8?q?=20=E2=86=92=20toArray:=20The=20method=20now=20doesn't=20return?= =?UTF-8?q?=20$this->data=20if=20it=20is=20null.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Response.php | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/src/Response.php b/src/Response.php index a35a642..874be19 100644 --- a/src/Response.php +++ b/src/Response.php @@ -35,6 +35,39 @@ public function setMeta($meta){ return $output; } + /** + * getMeta + * + * Getter for $this->meta + * + * @return null|array + */ + public function getMeta(){ + return $this->meta; + } + + /** + * setData + * + * Setter for $this->data. + * + * @param $data + */ + public function setData($data){ + $this->data = $data; + } + + /** + * getData + * + * Getter for $this->data. + * + * @return mixed + */ + public function getData(){ + return $this->data; + } + /** * toArray * @@ -43,10 +76,15 @@ public function setMeta($meta){ * @return array */ public function toArray(){ - return array( - 'meta' => $this->meta, - 'data' => $this->data + $output = array( + 'meta' => $this->meta ); + + if(isset($this->data)){ + $output['data'] = $this->data; + } + + return $output; } /** From 8d2c48b791ee70d73d2cc8da39bb854abedf26e8 Mon Sep 17 00:00:00 2001 From: Pavel Date: Sat, 19 Dec 2015 18:51:11 +0500 Subject: [PATCH 05/19] =?UTF-8?q?*=20ddTools=20=E2=86=92=20getResponse:=20?= =?UTF-8?q?A=20log=20message=20was=20added.=20It=20emerges=20when=20the=20?= =?UTF-8?q?class=20of=20the=20required=20instance=20is=20unreachable.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modx.ddtools.class.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modx.ddtools.class.php b/modx.ddtools.class.php index 605906e..fe872f3 100644 --- a/modx.ddtools.class.php +++ b/modx.ddtools.class.php @@ -1317,6 +1317,7 @@ public static function generateRandomString($length = 8, $chars = 'abcdefghijklm * @return bool|DDTools\Response */ public static function getResponse($version = null){ + global $modx; $output = false; switch($version){ @@ -1324,6 +1325,13 @@ public static function getResponse($version = null){ case '0.2': if(class_exists('\DDTools\Response\Response_v02')){ $output = new \DDTools\Response\Response_v02(); + }else{ + $modx->logEvent( + 1, + 2, + "

The class \DDTools\Response\Response_v02 is unreachable. Perhaps, you are not using the Composer autoload file. Please, check the way you include ddTools, it should be like this 'require_once(\$modx->config['base_path'].'vendor/autoload.php')'

", + __METHOD__.': \DDTools\Response\Response_v02' + ); } break; } From 17103749259dad6e95d4ed3632eb16b55270c6de Mon Sep 17 00:00:00 2001 From: Pavel Date: Sat, 19 Dec 2015 20:10:36 +0500 Subject: [PATCH 06/19] =?UTF-8?q?*=20Response=20and=20Response=5Fv02:=20$m?= =?UTF-8?q?eta=20is=20now=20properly=20passed=20to=20the=20=E2=80=9Cvalida?= =?UTF-8?q?teMeta=E2=80=9D=20method.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Response.php | 6 ++++-- src/Response/Response_v02.php | 18 +++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Response.php b/src/Response.php index 874be19..a4d0990 100644 --- a/src/Response.php +++ b/src/Response.php @@ -11,9 +11,11 @@ abstract class Response * * Validates the “meta” part of a response. * + * @param $meta + * * @return bool */ - abstract public function validateMeta(); + abstract public function validateMeta(array $meta); /** * setMeta @@ -27,7 +29,7 @@ abstract public function validateMeta(); public function setMeta($meta){ $output = false; - if($this->validateMeta()){ + if($this->validateMeta($meta)){ $this->meta = $meta; $output = true; } diff --git a/src/Response/Response_v02.php b/src/Response/Response_v02.php index 2913f69..09d4dab 100644 --- a/src/Response/Response_v02.php +++ b/src/Response/Response_v02.php @@ -36,7 +36,7 @@ class Response_v02 extends Response /** * validateMeta * - * $meta - is an array of meta data. The method excludes any values passed in $meta except “code”, “eTag”, “success”, + * @param array $meta - is an array of meta data. The method excludes any values passed in $meta except “code”, “eTag”, “success”, * and “message”. $meta['code'] and $meta['success'] are required. If defined, $meta['message'] must be an associative array with content * and, optionally, with a title. * @@ -60,31 +60,31 @@ class Response_v02 extends Response * * @return bool */ - public function validateMeta(){ + public function validateMeta(array $meta){ $output = false; if( //code is set and int - isset($this->meta['code']) && is_int($this->meta['code']) && + isset($meta['code']) && is_int($meta['code']) && //success is set and bool - isset($this->meta['success']) && is_bool($this->meta['success']) && + isset($meta['success']) && is_bool($meta['success']) && ( //message is not set - !isset($this->meta['message']) || + !isset($meta['message']) || ( //message is set and contains content - is_array($this->meta['message']) && isset($this->meta['content']) + is_array($meta['message']) && isset($meta['content']) ) ) ){ if( //there is no diff between meta keys and allowed meta keys - !count(array_diff(array_keys($this->meta), static::$allowedMetaKeys)) && + !count(array_diff(array_keys($meta), static::$allowedMetaKeys)) && ( //message is not set - !isset($this->meta['message']) || + !isset($meta['message']) || //there is no diff between meta message keys and allowed meta message keys - !count(array_diff(array_keys($this->meta['message']), static::$allowedMetaMessageKeys)) + !count(array_diff(array_keys($meta['message']), static::$allowedMetaMessageKeys)) ) ){ $output = true; From befd50ce53b3ba3cefd74d560fb0c56bf190ed80 Mon Sep 17 00:00:00 2001 From: Pavel Date: Sat, 19 Dec 2015 20:33:14 +0500 Subject: [PATCH 07/19] =?UTF-8?q?*=20Response=5Fv02=20=E2=86=92=20validate?= =?UTF-8?q?Meta:=20Fixed=20an=20error=20within=20the=20message=20content?= =?UTF-8?q?=20check.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Response/Response_v02.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Response/Response_v02.php b/src/Response/Response_v02.php index 09d4dab..6fa817f 100644 --- a/src/Response/Response_v02.php +++ b/src/Response/Response_v02.php @@ -73,7 +73,7 @@ public function validateMeta(array $meta){ !isset($meta['message']) || ( //message is set and contains content - is_array($meta['message']) && isset($meta['content']) + is_array($meta['message']) && isset($meta['message']['content']) ) ) ){ From 1f2962d34e02921f13f1950c440f53c107eacebc Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Wed, 23 Dec 2015 12:21:15 +0500 Subject: [PATCH 08/19] * Minor changes: The order of method declarations was changed. --- modx.ddtools.class.php | 235 +++++++++++++++++++++-------------------- 1 file changed, 118 insertions(+), 117 deletions(-) diff --git a/modx.ddtools.class.php b/modx.ddtools.class.php index fe872f3..cee17f2 100644 --- a/modx.ddtools.class.php +++ b/modx.ddtools.class.php @@ -65,30 +65,6 @@ class ddTools { 'document_groups' => '' ); - /** - * screening - * @version 1.0 (2012-03-21) - * - * @desc Screening chars in string. - * - * @param $str {string} - String to screening. @required - * - * @return {string} - Экранированная строка. - */ - public static function screening($str){ - $str = str_replace("\r\n", ' ', $str); - $str = str_replace("\n", ' ', $str); - $str = str_replace("\r", ' ', $str); - $str = str_replace(chr(9), ' ', $str); - $str = str_replace(' ', ' ', $str); - $str = str_replace('[+', '\[\+', $str); - $str = str_replace('+]', '\+\]', $str); - $str = str_replace("'", "\'", $str); - $str = str_replace('"', '\"', $str); - - return $str; - } - /** * explodeAssoc * @version 1.1.1 (2013-07-11) @@ -222,6 +198,124 @@ public static function sort2dArray($array, $sortBy, $sortDir = 1, $i = 0){ return array_merge($arrLeft, $arrCent, $arrRight); } + /** + * parseFileNameVersion + * @version 1.1 (2013-10-10) + * + * @desc Parses a file path and gets its name, version & extension. + * + * @param $file {string; array} - String of file path or result array of pathinfo() function. @required + * + * @return {array: associative} - Array of: 'name' {string} => File name; 'version' => File version; 'extension' => File extension. + */ + public static function parseFileNameVersion($file){ + //Если сразу передали массив + if (is_array($file)){ + //Просто запоминаем его + $fileinfo = $file; + //А также запоминаем строку + $file = $fileinfo['dirname'].'/'.$fileinfo['basename']; + //Если передали строку + }else{ + //Получаем необходимые данные + $fileinfo = pathinfo($file); + } + + //Fail by default + $result = array( + 'name' => strtolower($file), + 'version' => '0', + 'extension' => !$fileinfo['extension'] ? '' : $fileinfo['extension'] + ); + + //Try to get file version [0 — full name, 1 — script name, 2 — version, 3 — all chars after version] + preg_match('/(\D*?)-?(\d(?:\.\d+)*(?:-?[A-Za-z])*)(.*)/', $fileinfo['basename'], $match); + + //If not fail + if (count($match) >= 4){ + $result['name'] = strtolower($match[1]); + $result['version'] = strtolower($match[2]); + } + + return $result; + } + + /** + * removeDir + * @version 1.0 (2013-03-09) + * + * @desc Removes a required folder with all contents recursively. + * + * @param $dir {string} - Path to the directory, that should removed. @required + * + * @return {boolean} + */ + public static function removeDir($dir){ + //Если не существует, ок + if (!file_exists($dir)){return true;} + + //Получаем файлы в директории + $files = array_diff(scandir($dir), array('.','..')); + + foreach ($files as $file){ + //Если это папка, обработаем её + if (is_dir("$dir/$file")){ + self::removeDir("$dir/$file"); + }else{ + unlink("$dir/$file"); + } + } + + return rmdir($dir); + } + + /** + * generateRandomString + * @version 1.0 (2012-02-13) + * + * @desc Generate random string with necessary length. + * + * @param $length {integer} - Length of output string. Default: 8. + * @param $chars {string} - Chars to generate. Default: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789'. + * + * @return {string} + */ + public static function generateRandomString($length = 8, $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789'){ + $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789'; + $numChars = strlen($chars); + $string = ''; + + for ($i = 0; $i < $length; $i++){ + $string .= substr($chars, rand(1, $numChars) - 1, 1); + } + + return $string; + } + + /** + * screening + * @version 1.0 (2012-03-21) + * + * @desc Screening chars in string. + * + * @param $str {string} - String to screening. @required + * + * @return {string} - Экранированная строка. + */ + public static function screening($str){ + $str = str_replace("\r\n", ' ', $str); + $str = str_replace("\n", ' ', $str); + $str = str_replace("\r", ' ', $str); + $str = str_replace(chr(9), ' ', $str); + $str = str_replace(' ', ' ', $str); + $str = str_replace('[+', '\[\+', $str); + $str = str_replace('+]', '\+\]', $str); + $str = str_replace("'", "\'", $str); + $str = str_replace('"', '\"', $str); + + return $str; + } + /** * parseText * @version 1.1 (2012-03-21) @@ -952,48 +1046,6 @@ public static function getDocumentChildrenTVarOutput($parentid = 0, $tvidnames = } } - /** - * parseFileNameVersion - * @version 1.1 (2013-10-10) - * - * @desc Parses a file path and gets its name, version & extension. - * - * @param $file {string; array} - String of file path or result array of pathinfo() function. @required - * - * @return {array: associative} - Array of: 'name' {string} => File name; 'version' => File version; 'extension' => File extension. - */ - public static function parseFileNameVersion($file){ - //Если сразу передали массив - if (is_array($file)){ - //Просто запоминаем его - $fileinfo = $file; - //А также запоминаем строку - $file = $fileinfo['dirname'].'/'.$fileinfo['basename']; - //Если передали строку - }else{ - //Получаем необходимые данные - $fileinfo = pathinfo($file); - } - - //Fail by default - $result = array( - 'name' => strtolower($file), - 'version' => '0', - 'extension' => !$fileinfo['extension'] ? '' : $fileinfo['extension'] - ); - - //Try to get file version [0 — full name, 1 — script name, 2 — version, 3 — all chars after version] - preg_match('/(\D*?)-?(\d(?:\.\d+)*(?:-?[A-Za-z])*)(.*)/', $fileinfo['basename'], $match); - - //If not fail - if (count($match) >= 4){ - $result['name'] = strtolower($match[1]); - $result['version'] = strtolower($match[2]); - } - - return $result; - } - /** * regEmptyClientScript * @version 1.0.1 (2013-03-12) @@ -1255,57 +1307,6 @@ public static function sendMail($to, $text, $from = 'info@divandesign.biz', $sub return $result; } - /** - * removeDir - * @version 1.0 (2013-03-09) - * - * @desc Removes a required folder with all contents recursively. - * - * @param $dir {string} - Path to the directory, that should removed. @required - * - * @return {boolean} - */ - public static function removeDir($dir){ - //Если не существует, ок - if (!file_exists($dir)){return true;} - - //Получаем файлы в директории - $files = array_diff(scandir($dir), array('.','..')); - - foreach ($files as $file){ - //Если это папка, обработаем её - if (is_dir("$dir/$file")){ - self::removeDir("$dir/$file"); - }else{ - unlink("$dir/$file"); - } - } - - return rmdir($dir); - } - - /** - * generateRandomString - * @version 1.0 (2012-02-13) - * - * @desc Generate random string with necessary length. - * - * @param $length {integer} - Length of output string. Default: 8. - * @param $chars {string} - Chars to generate. Default: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789'. - * - * @return {string} - */ - public static function generateRandomString($length = 8, $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789'){ - $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789'; - $numChars = strlen($chars); - $string = ''; - for ($i = 0; $i < $length; $i++){ - $string .= substr($chars, rand(1, $numChars) - 1, 1); - } - - return $string; - } - /** * getResponse * @version 1.0 (2015-12-19) From a17cd58d0a3bb604f2ddcfbc1a4999223d934961 Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Wed, 23 Dec 2015 14:01:24 +0500 Subject: [PATCH 09/19] =?UTF-8?q?+=20The=20=E2=80=9CddTools::copyDir?= =?UTF-8?q?=E2=80=9D=20method=20was=20added.=20Copies=20a=20required=20fol?= =?UTF-8?q?der=20with=20all=20contents=20recursively.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modx.ddtools.class.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/modx.ddtools.class.php b/modx.ddtools.class.php index cee17f2..aec678f 100644 --- a/modx.ddtools.class.php +++ b/modx.ddtools.class.php @@ -240,6 +240,42 @@ public static function parseFileNameVersion($file){ return $result; } + /** + * copyDir + * @version 1.0 (2015-12-23) + * + * @desc Copies a required folder with all contents recursively. + * + * @param $sourceDir {string} - Path to the directory, that should copied. @required + * @param $dectinationDir {string} - The destination path. @required + * + * @return {boolean} — Returns true on success or false on failure. + */ + public static function copyDir($sourceDir, $dectinationDir){ + //Допишем папкам недостающие '/' при необходимости + if (substr($sourceDir, -1) != '/'){$sourceDir .= '/';} + if (substr($dectinationDir, -1) != '/'){$dectinationDir .= '/';} + + //Проверяем существование + if (!file_exists($sourceDir)){return false;} + //Если папки назначения нет, создадим её + if (!file_exists($dectinationDir)){mkdir($dectinationDir);} + + //Получаем файлы в директории + $files = array_diff(scandir($sourceDir), array('.', '..')); + + foreach ($files as $file){ + //Если это папка, обработаем её + if (is_dir($sourceDir.$file)){ + self::copyDir($sourceDir.$file, $dectinationDir.$file); + }else{ + copy($sourceDir.$file, $dectinationDir.$file); + } + } + + return true; + } + /** * removeDir * @version 1.0 (2013-03-09) From 5ddd04ec158df3d8e234570877122f120d50fc91 Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Wed, 23 Dec 2015 16:16:22 +0500 Subject: [PATCH 10/19] =?UTF-8?q?*=20The=20=E2=80=9CddTools::copyDir?= =?UTF-8?q?=E2=80=9D=20method=20was=20updated=20to=201.0.1:=20=09*=20The?= =?UTF-8?q?=20=E2=80=9CdectinationDir=E2=80=9D=20parameter=20was=20renamed?= =?UTF-8?q?=20as=20=E2=80=9CdestinationDir=E2=80=9D.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modx.ddtools.class.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/modx.ddtools.class.php b/modx.ddtools.class.php index aec678f..e8dea12 100644 --- a/modx.ddtools.class.php +++ b/modx.ddtools.class.php @@ -242,24 +242,24 @@ public static function parseFileNameVersion($file){ /** * copyDir - * @version 1.0 (2015-12-23) + * @version 1.0.1 (2015-12-23) * * @desc Copies a required folder with all contents recursively. * * @param $sourceDir {string} - Path to the directory, that should copied. @required - * @param $dectinationDir {string} - The destination path. @required + * @param $destinationDir {string} - The destination path. @required * * @return {boolean} — Returns true on success or false on failure. */ - public static function copyDir($sourceDir, $dectinationDir){ + public static function copyDir($sourceDir, $destinationDir){ //Допишем папкам недостающие '/' при необходимости if (substr($sourceDir, -1) != '/'){$sourceDir .= '/';} - if (substr($dectinationDir, -1) != '/'){$dectinationDir .= '/';} + if (substr($destinationDir, -1) != '/'){$destinationDir .= '/';} //Проверяем существование if (!file_exists($sourceDir)){return false;} //Если папки назначения нет, создадим её - if (!file_exists($dectinationDir)){mkdir($dectinationDir);} + if (!file_exists($destinationDir)){mkdir($destinationDir);} //Получаем файлы в директории $files = array_diff(scandir($sourceDir), array('.', '..')); @@ -267,9 +267,9 @@ public static function copyDir($sourceDir, $dectinationDir){ foreach ($files as $file){ //Если это папка, обработаем её if (is_dir($sourceDir.$file)){ - self::copyDir($sourceDir.$file, $dectinationDir.$file); + self::copyDir($sourceDir.$file, $destinationDir.$file); }else{ - copy($sourceDir.$file, $dectinationDir.$file); + copy($sourceDir.$file, $destinationDir.$file); } } From a692a0785ae70dddf7d313771db1a27b00713f23 Mon Sep 17 00:00:00 2001 From: Pavel Date: Thu, 24 Dec 2015 17:27:06 +0500 Subject: [PATCH 11/19] * composer.json: The library now depends on "dd/composer-plugin-modxevo-library-ddtools-installer": "^1.0.5-alpha1". --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e7c42ed..845d430 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "license": "MIT", "require": { "php": ">=5.3.0", - "dd/composer-plugin-modxevo-library-ddtools-installer": "^1.0.4" + "dd/composer-plugin-modxevo-library-ddtools-installer": "^1.0.5-alpha1" }, "autoload": { "files": ["modx.ddtools.class.php"], From 890a18910e4c042d2a85193c78afb595a2539de4 Mon Sep 17 00:00:00 2001 From: Pavel Date: Thu, 24 Dec 2015 17:36:34 +0500 Subject: [PATCH 12/19] * composer.json: "dd/composer-plugin-modxevo-library-ddtools-installer": "^1.0.5-alpha1" has been replaced with "dd/composer-plugin-modxevo-library-ddtools-installer": "1.0.5-alpha1". --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 845d430..a6fd069 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "license": "MIT", "require": { "php": ">=5.3.0", - "dd/composer-plugin-modxevo-library-ddtools-installer": "^1.0.5-alpha1" + "dd/composer-plugin-modxevo-library-ddtools-installer": "1.0.5-alpha1" }, "autoload": { "files": ["modx.ddtools.class.php"], From ff783befbcd919b11d7c1fa823b5e6591f01cd60 Mon Sep 17 00:00:00 2001 From: Pavel Date: Thu, 24 Dec 2015 17:41:27 +0500 Subject: [PATCH 13/19] * composer.json: added "minimum-stability": "dev". --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a6fd069..d4ff17b 100644 --- a/composer.json +++ b/composer.json @@ -7,8 +7,9 @@ "license": "MIT", "require": { "php": ">=5.3.0", - "dd/composer-plugin-modxevo-library-ddtools-installer": "1.0.5-alpha1" + "dd/composer-plugin-modxevo-library-ddtools-installer": "1.0.5-alpha1", }, + "minimum-stability": "dev", "autoload": { "files": ["modx.ddtools.class.php"], "psr-4": { From b9dd770bd63294a9d69cf58da5cccc2b8cf67f48 Mon Sep 17 00:00:00 2001 From: Pavel Date: Thu, 24 Dec 2015 17:45:44 +0500 Subject: [PATCH 14/19] * composer.json: Deleted a trailing comma. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d4ff17b..9734d8c 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "license": "MIT", "require": { "php": ">=5.3.0", - "dd/composer-plugin-modxevo-library-ddtools-installer": "1.0.5-alpha1", + "dd/composer-plugin-modxevo-library-ddtools-installer": "1.0.5-alpha1" }, "minimum-stability": "dev", "autoload": { From d050985bbdaf01263407074b9f89a5fada328f64 Mon Sep 17 00:00:00 2001 From: Pavel Date: Fri, 25 Dec 2015 09:42:07 +0500 Subject: [PATCH 15/19] * getDocuments: User access options are now completely ignored while retrieving. It's done because the method is supposed to be a low level implementation, so it's implied that a structure of a higher level will be dealing with user access. --- modx.ddtools.class.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/modx.ddtools.class.php b/modx.ddtools.class.php index e8dea12..8a935f3 100644 --- a/modx.ddtools.class.php +++ b/modx.ddtools.class.php @@ -699,17 +699,10 @@ public static function getDocuments($ids = array(), $published = 'all', $deleted $published = ($published !== 'all') ? "AND sc.published = '{$published}'" : ''; $deleted = ($deleted !== 'all') ? "AND sc.deleted = '{$deleted}'" : ''; - // get document groups for current user - if ($docgrp = $modx->getUserDocGroups()){ - $docgrp = implode(',', $docgrp); - } - - $access = ($modx->isFrontend() ? 'sc.privateweb=0' : '1="'.$_SESSION['mgrRole'].'" OR sc.privatemgr=0').(!$docgrp ? '' : ' OR dg.document_group IN ('.$docgrp.')'); - $result = $modx->db->select( "DISTINCT {$fields}", self::$tables['site_content']." sc LEFT JOIN ".self::$tables['document_groups']." dg on dg.document = sc.id", - "(sc.id IN (".implode(',', $ids).") {$published} {$deleted} {$where}) AND ({$access}) GROUP BY sc.id", + "(sc.id IN (".implode(',', $ids).") {$published} {$deleted} {$where}) GROUP BY sc.id", ($sort ? "{$sort} {$dir}" : ""), $limit ); From 1974c1403d1b2026d6b1e1a692ef555634c64bb6 Mon Sep 17 00:00:00 2001 From: Pavel Date: Fri, 25 Dec 2015 09:56:58 +0500 Subject: [PATCH 16/19] * composer.json: The package now depends on "dd/composer-plugin-modxevo-library-ddtools-installer": "1.0.5-alpha2". - composer.json: Removed minimum stability. --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 9734d8c..d820089 100644 --- a/composer.json +++ b/composer.json @@ -7,9 +7,8 @@ "license": "MIT", "require": { "php": ">=5.3.0", - "dd/composer-plugin-modxevo-library-ddtools-installer": "1.0.5-alpha1" + "dd/composer-plugin-modxevo-library-ddtools-installer": "1.0.5-alpha2" }, - "minimum-stability": "dev", "autoload": { "files": ["modx.ddtools.class.php"], "psr-4": { From e03e224e86e7c0457561fab7fab522ec605756a9 Mon Sep 17 00:00:00 2001 From: Pavel Date: Fri, 25 Dec 2015 10:26:59 +0500 Subject: [PATCH 17/19] https://github.com/DivanDesign/MODXEvo.library.ddTools/issues/3 * updateDocument: mysql_info was replaced with mysqli_info. --- modx.ddtools.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modx.ddtools.class.php b/modx.ddtools.class.php index 8a935f3..2a6dc12 100644 --- a/modx.ddtools.class.php +++ b/modx.ddtools.class.php @@ -608,7 +608,7 @@ public static function updateDocument($id = 0, $update = array(), $where = ''){ ); //Проверяем сколько строк нашлось при обновлении - preg_match('/Rows matched: (\d+)/', mysql_info(), $updatedRows); + preg_match('/Rows matched: (\d+)/', mysqli_info($modx->db->conn), $updatedRows); //Если ничего не обновилось (не нашлось) if ($updatedRows[1] == 0){ From 2e4025ad22ceca30599bdcab6f30d1b5be387827 Mon Sep 17 00:00:00 2001 From: Pavel Date: Fri, 25 Dec 2015 10:27:51 +0500 Subject: [PATCH 18/19] * The package is now depends on "dd/composer-plugin-modxevo-library-ddtools-installer": "1.0.5". --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d820089..f7a534b 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "license": "MIT", "require": { "php": ">=5.3.0", - "dd/composer-plugin-modxevo-library-ddtools-installer": "1.0.5-alpha2" + "dd/composer-plugin-modxevo-library-ddtools-installer": "1.0.5" }, "autoload": { "files": ["modx.ddtools.class.php"], From 845ebc3ee7be9adef6d5e1a4c3bb38082a6dff48 Mon Sep 17 00:00:00 2001 From: Pavel Date: Fri, 25 Dec 2015 10:34:06 +0500 Subject: [PATCH 19/19] Prerelease 0.15 --- modx.ddtools.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modx.ddtools.class.php b/modx.ddtools.class.php index 2a6dc12..7c27655 100644 --- a/modx.ddtools.class.php +++ b/modx.ddtools.class.php @@ -1,11 +1,11 @@