@@ -8,25 +8,25 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | interface ISessionStorage |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * @param string |
|
| 13 | - * @param mixed |
|
| 14 | - * @return self |
|
| 15 | - */ |
|
| 16 | - function set($name, $value); |
|
| 17 | - |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * @param string |
|
| 21 | - * @return mixed |
|
| 22 | - */ |
|
| 23 | - function get($name); |
|
| 24 | - |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @param string |
|
| 28 | - * @return self |
|
| 29 | - */ |
|
| 30 | - function remove($name); |
|
| 11 | + /** |
|
| 12 | + * @param string |
|
| 13 | + * @param mixed |
|
| 14 | + * @return self |
|
| 15 | + */ |
|
| 16 | + function set($name, $value); |
|
| 17 | + |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * @param string |
|
| 21 | + * @return mixed |
|
| 22 | + */ |
|
| 23 | + function get($name); |
|
| 24 | + |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @param string |
|
| 28 | + * @return self |
|
| 29 | + */ |
|
| 30 | + function remove($name); |
|
| 31 | 31 | |
| 32 | 32 | } |
@@ -12,75 +12,75 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class SessionStorage extends Github\Sanity implements ISessionStorage |
| 14 | 14 | { |
| 15 | - const SESSION_KEY = 'milo.github-api'; |
|
| 16 | - |
|
| 17 | - /** @var string */ |
|
| 18 | - private $sessionKey; |
|
| 19 | - |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @param string |
|
| 23 | - */ |
|
| 24 | - public function __construct($sessionKey = self::SESSION_KEY) |
|
| 25 | - { |
|
| 26 | - $this->sessionKey = $sessionKey; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @param string |
|
| 32 | - * @param mixed |
|
| 33 | - * @return self |
|
| 34 | - */ |
|
| 35 | - public function set($name, $value) |
|
| 36 | - { |
|
| 37 | - if ($value === NULL) { |
|
| 38 | - return $this->remove($name); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - $this->check(__METHOD__); |
|
| 42 | - $_SESSION[$this->sessionKey][$name] = $value; |
|
| 43 | - |
|
| 44 | - return $this; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @param string |
|
| 50 | - * @return mixed |
|
| 51 | - */ |
|
| 52 | - public function get($name) |
|
| 53 | - { |
|
| 54 | - $this->check(__METHOD__); |
|
| 55 | - |
|
| 56 | - return isset($_SESSION[$this->sessionKey][$name]) |
|
| 57 | - ? $_SESSION[$this->sessionKey][$name] |
|
| 58 | - : NULL; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @param string |
|
| 64 | - * @return self |
|
| 65 | - */ |
|
| 66 | - public function remove($name) |
|
| 67 | - { |
|
| 68 | - $this->check(__METHOD__); |
|
| 69 | - |
|
| 70 | - unset($_SESSION[$this->sessionKey][$name]); |
|
| 71 | - |
|
| 72 | - return $this; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @param string |
|
| 78 | - */ |
|
| 79 | - private function check($method) |
|
| 80 | - { |
|
| 81 | - if (!isset($_SESSION)) { |
|
| 82 | - trigger_error("Start session before using $method().", E_USER_WARNING); |
|
| 83 | - } |
|
| 84 | - } |
|
| 15 | + const SESSION_KEY = 'milo.github-api'; |
|
| 16 | + |
|
| 17 | + /** @var string */ |
|
| 18 | + private $sessionKey; |
|
| 19 | + |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @param string |
|
| 23 | + */ |
|
| 24 | + public function __construct($sessionKey = self::SESSION_KEY) |
|
| 25 | + { |
|
| 26 | + $this->sessionKey = $sessionKey; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @param string |
|
| 32 | + * @param mixed |
|
| 33 | + * @return self |
|
| 34 | + */ |
|
| 35 | + public function set($name, $value) |
|
| 36 | + { |
|
| 37 | + if ($value === NULL) { |
|
| 38 | + return $this->remove($name); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + $this->check(__METHOD__); |
|
| 42 | + $_SESSION[$this->sessionKey][$name] = $value; |
|
| 43 | + |
|
| 44 | + return $this; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @param string |
|
| 50 | + * @return mixed |
|
| 51 | + */ |
|
| 52 | + public function get($name) |
|
| 53 | + { |
|
| 54 | + $this->check(__METHOD__); |
|
| 55 | + |
|
| 56 | + return isset($_SESSION[$this->sessionKey][$name]) |
|
| 57 | + ? $_SESSION[$this->sessionKey][$name] |
|
| 58 | + : NULL; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @param string |
|
| 64 | + * @return self |
|
| 65 | + */ |
|
| 66 | + public function remove($name) |
|
| 67 | + { |
|
| 68 | + $this->check(__METHOD__); |
|
| 69 | + |
|
| 70 | + unset($_SESSION[$this->sessionKey][$name]); |
|
| 71 | + |
|
| 72 | + return $this; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @param string |
|
| 78 | + */ |
|
| 79 | + private function check($method) |
|
| 80 | + { |
|
| 81 | + if (!isset($_SESSION)) { |
|
| 82 | + trigger_error("Start session before using $method().", E_USER_WARNING); |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | 86 | } |
@@ -13,89 +13,89 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class Helpers |
| 15 | 15 | { |
| 16 | - private static $jsonMessages = [ |
|
| 17 | - JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded', |
|
| 18 | - JSON_ERROR_STATE_MISMATCH => 'Syntax error, malformed JSON', |
|
| 19 | - JSON_ERROR_CTRL_CHAR => 'Unexpected control character found', |
|
| 20 | - JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON', |
|
| 21 | - JSON_ERROR_UTF8 => 'Invalid UTF-8 sequence', |
|
| 22 | - ]; |
|
| 23 | - |
|
| 24 | - |
|
| 25 | - /** @var Http\IClient */ |
|
| 26 | - private static $client; |
|
| 27 | - |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @param mixed |
|
| 31 | - * @return string |
|
| 32 | - * |
|
| 33 | - * @throws JsonException |
|
| 34 | - */ |
|
| 35 | - public static function jsonEncode($value) |
|
| 36 | - { |
|
| 37 | - if (PHP_VERSION_ID < 50500) { |
|
| 38 | - set_error_handler(function($severity, $message) { // needed to receive 'recursion detected' error |
|
| 39 | - restore_error_handler(); |
|
| 40 | - throw new JsonException($message); |
|
| 41 | - }); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - $json = json_encode($value, JSON_UNESCAPED_UNICODE); |
|
| 45 | - |
|
| 46 | - if (PHP_VERSION_ID < 50500) { |
|
| 47 | - restore_error_handler(); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - if ($error = json_last_error()) { |
|
| 51 | - $message = isset(static::$jsonMessages[$error]) |
|
| 52 | - ? static::$jsonMessages[$error] |
|
| 53 | - : (PHP_VERSION_ID >= 50500 ? json_last_error_msg() : 'Unknown error'); |
|
| 54 | - |
|
| 55 | - throw new JsonException($message, $error); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - $json = str_replace(array("\xe2\x80\xa8", "\xe2\x80\xa9"), array('\u2028', '\u2029'), $json); |
|
| 59 | - return $json; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @param mixed |
|
| 65 | - * @return string |
|
| 66 | - * |
|
| 67 | - * @throws JsonException |
|
| 68 | - */ |
|
| 69 | - public static function jsonDecode($json, $assoc = false) |
|
| 70 | - { |
|
| 71 | - $json = (string) $json; |
|
| 72 | - if (!preg_match('##u', $json)) { |
|
| 73 | - throw new JsonException('Invalid UTF-8 sequence', 5); // PECL JSON-C |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - $value = json_decode($json, $assoc, 512, (defined('JSON_C_VERSION') && PHP_INT_SIZE > 4) ? 0 : JSON_BIGINT_AS_STRING); |
|
| 77 | - |
|
| 78 | - if ($value === NULL && $json !== '' && strcasecmp($json, 'null')) { // '' does not clear json_last_error() |
|
| 79 | - $error = json_last_error(); |
|
| 80 | - throw new JsonException(isset(static::$jsonMessages[$error]) ? static::$jsonMessages[$error] : 'Unknown error', $error); |
|
| 81 | - } |
|
| 82 | - return $value; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * @param bool |
|
| 88 | - * @return Http\IClient |
|
| 89 | - */ |
|
| 90 | - public static function createDefaultClient($newInstance = FALSE) |
|
| 91 | - { |
|
| 92 | - if (self::$client === NULL || $newInstance) { |
|
| 93 | - self::$client = extension_loaded('curl') |
|
| 94 | - ? new Http\CurlClient |
|
| 95 | - : new Http\StreamClient; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - return self::$client; |
|
| 99 | - } |
|
| 16 | + private static $jsonMessages = [ |
|
| 17 | + JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded', |
|
| 18 | + JSON_ERROR_STATE_MISMATCH => 'Syntax error, malformed JSON', |
|
| 19 | + JSON_ERROR_CTRL_CHAR => 'Unexpected control character found', |
|
| 20 | + JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON', |
|
| 21 | + JSON_ERROR_UTF8 => 'Invalid UTF-8 sequence', |
|
| 22 | + ]; |
|
| 23 | + |
|
| 24 | + |
|
| 25 | + /** @var Http\IClient */ |
|
| 26 | + private static $client; |
|
| 27 | + |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @param mixed |
|
| 31 | + * @return string |
|
| 32 | + * |
|
| 33 | + * @throws JsonException |
|
| 34 | + */ |
|
| 35 | + public static function jsonEncode($value) |
|
| 36 | + { |
|
| 37 | + if (PHP_VERSION_ID < 50500) { |
|
| 38 | + set_error_handler(function($severity, $message) { // needed to receive 'recursion detected' error |
|
| 39 | + restore_error_handler(); |
|
| 40 | + throw new JsonException($message); |
|
| 41 | + }); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + $json = json_encode($value, JSON_UNESCAPED_UNICODE); |
|
| 45 | + |
|
| 46 | + if (PHP_VERSION_ID < 50500) { |
|
| 47 | + restore_error_handler(); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + if ($error = json_last_error()) { |
|
| 51 | + $message = isset(static::$jsonMessages[$error]) |
|
| 52 | + ? static::$jsonMessages[$error] |
|
| 53 | + : (PHP_VERSION_ID >= 50500 ? json_last_error_msg() : 'Unknown error'); |
|
| 54 | + |
|
| 55 | + throw new JsonException($message, $error); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + $json = str_replace(array("\xe2\x80\xa8", "\xe2\x80\xa9"), array('\u2028', '\u2029'), $json); |
|
| 59 | + return $json; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @param mixed |
|
| 65 | + * @return string |
|
| 66 | + * |
|
| 67 | + * @throws JsonException |
|
| 68 | + */ |
|
| 69 | + public static function jsonDecode($json, $assoc = false) |
|
| 70 | + { |
|
| 71 | + $json = (string) $json; |
|
| 72 | + if (!preg_match('##u', $json)) { |
|
| 73 | + throw new JsonException('Invalid UTF-8 sequence', 5); // PECL JSON-C |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + $value = json_decode($json, $assoc, 512, (defined('JSON_C_VERSION') && PHP_INT_SIZE > 4) ? 0 : JSON_BIGINT_AS_STRING); |
|
| 77 | + |
|
| 78 | + if ($value === NULL && $json !== '' && strcasecmp($json, 'null')) { // '' does not clear json_last_error() |
|
| 79 | + $error = json_last_error(); |
|
| 80 | + throw new JsonException(isset(static::$jsonMessages[$error]) ? static::$jsonMessages[$error] : 'Unknown error', $error); |
|
| 81 | + } |
|
| 82 | + return $value; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @param bool |
|
| 88 | + * @return Http\IClient |
|
| 89 | + */ |
|
| 90 | + public static function createDefaultClient($newInstance = FALSE) |
|
| 91 | + { |
|
| 92 | + if (self::$client === NULL || $newInstance) { |
|
| 93 | + self::$client = extension_loaded('curl') |
|
| 94 | + ? new Http\CurlClient |
|
| 95 | + : new Http\StreamClient; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + return self::$client; |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | 101 | } |
@@ -31,96 +31,96 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class RepositoriesHandler extends \XoopsPersistableObjectHandler |
| 33 | 33 | { |
| 34 | - /** |
|
| 35 | - * Constructor |
|
| 36 | - * |
|
| 37 | - * @param \XoopsDatabase $db |
|
| 38 | - */ |
|
| 39 | - public function __construct(\XoopsDatabase $db) |
|
| 40 | - { |
|
| 41 | - parent::__construct($db, 'wggithub_repositories', Repositories::class, 'repo_id', 'repo_name'); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @param bool $isNew |
|
| 46 | - * |
|
| 47 | - * @return object |
|
| 48 | - */ |
|
| 49 | - public function create($isNew = true) |
|
| 50 | - { |
|
| 51 | - return parent::create($isNew); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * retrieve a field |
|
| 56 | - * |
|
| 57 | - * @param int $i field id |
|
| 58 | - * @param null fields |
|
| 59 | - * @return mixed reference to the {@link Get} object |
|
| 60 | - */ |
|
| 61 | - public function get($i = null, $fields = null) |
|
| 62 | - { |
|
| 63 | - return parent::get($i, $fields); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * get inserted id |
|
| 68 | - * |
|
| 69 | - * @param null |
|
| 70 | - * @return int reference to the {@link Get} object |
|
| 71 | - */ |
|
| 72 | - public function getInsertId() |
|
| 73 | - { |
|
| 74 | - return $this->db->getInsertId(); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Get Count Repositories in the database |
|
| 79 | - * @param int $start |
|
| 80 | - * @param int $limit |
|
| 81 | - * @param string $sort |
|
| 82 | - * @param string $order |
|
| 83 | - * @return int |
|
| 84 | - */ |
|
| 85 | - public function getCountRepositories($start = 0, $limit = 0, $sort = 'repo_id ASC, repo_name', $order = 'ASC') |
|
| 86 | - { |
|
| 87 | - $crCountRepositories = new \CriteriaCompo(); |
|
| 88 | - $crCountRepositories = $this->getRepositoriesCriteria($crCountRepositories, $start, $limit, $sort, $order); |
|
| 89 | - return $this->getCount($crCountRepositories); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Get All Repositories in the database |
|
| 94 | - * @param int $start |
|
| 95 | - * @param int $limit |
|
| 96 | - * @param string $sort |
|
| 97 | - * @param string $order |
|
| 98 | - * @return array |
|
| 99 | - */ |
|
| 100 | - public function getAllRepositories($start = 0, $limit = 0, $sort = 'repo_id ASC, repo_name', $order = 'ASC') |
|
| 101 | - { |
|
| 102 | - $crAllRepositories = new \CriteriaCompo(); |
|
| 103 | - $crAllRepositories = $this->getRepositoriesCriteria($crAllRepositories, $start, $limit, $sort, $order); |
|
| 104 | - return $this->getAll($crAllRepositories); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Get Criteria Repositories |
|
| 109 | - * @param $crRepositories |
|
| 110 | - * @param int $start |
|
| 111 | - * @param int $limit |
|
| 112 | - * @param string $sort |
|
| 113 | - * @param string $order |
|
| 114 | - * @return int |
|
| 115 | - */ |
|
| 116 | - private function getRepositoriesCriteria($crRepositories, $start, $limit, $sort, $order) |
|
| 117 | - { |
|
| 118 | - $crRepositories->setStart($start); |
|
| 119 | - $crRepositories->setLimit($limit); |
|
| 120 | - $crRepositories->setSort($sort); |
|
| 121 | - $crRepositories->setOrder($order); |
|
| 122 | - return $crRepositories; |
|
| 123 | - } |
|
| 34 | + /** |
|
| 35 | + * Constructor |
|
| 36 | + * |
|
| 37 | + * @param \XoopsDatabase $db |
|
| 38 | + */ |
|
| 39 | + public function __construct(\XoopsDatabase $db) |
|
| 40 | + { |
|
| 41 | + parent::__construct($db, 'wggithub_repositories', Repositories::class, 'repo_id', 'repo_name'); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @param bool $isNew |
|
| 46 | + * |
|
| 47 | + * @return object |
|
| 48 | + */ |
|
| 49 | + public function create($isNew = true) |
|
| 50 | + { |
|
| 51 | + return parent::create($isNew); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * retrieve a field |
|
| 56 | + * |
|
| 57 | + * @param int $i field id |
|
| 58 | + * @param null fields |
|
| 59 | + * @return mixed reference to the {@link Get} object |
|
| 60 | + */ |
|
| 61 | + public function get($i = null, $fields = null) |
|
| 62 | + { |
|
| 63 | + return parent::get($i, $fields); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * get inserted id |
|
| 68 | + * |
|
| 69 | + * @param null |
|
| 70 | + * @return int reference to the {@link Get} object |
|
| 71 | + */ |
|
| 72 | + public function getInsertId() |
|
| 73 | + { |
|
| 74 | + return $this->db->getInsertId(); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Get Count Repositories in the database |
|
| 79 | + * @param int $start |
|
| 80 | + * @param int $limit |
|
| 81 | + * @param string $sort |
|
| 82 | + * @param string $order |
|
| 83 | + * @return int |
|
| 84 | + */ |
|
| 85 | + public function getCountRepositories($start = 0, $limit = 0, $sort = 'repo_id ASC, repo_name', $order = 'ASC') |
|
| 86 | + { |
|
| 87 | + $crCountRepositories = new \CriteriaCompo(); |
|
| 88 | + $crCountRepositories = $this->getRepositoriesCriteria($crCountRepositories, $start, $limit, $sort, $order); |
|
| 89 | + return $this->getCount($crCountRepositories); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Get All Repositories in the database |
|
| 94 | + * @param int $start |
|
| 95 | + * @param int $limit |
|
| 96 | + * @param string $sort |
|
| 97 | + * @param string $order |
|
| 98 | + * @return array |
|
| 99 | + */ |
|
| 100 | + public function getAllRepositories($start = 0, $limit = 0, $sort = 'repo_id ASC, repo_name', $order = 'ASC') |
|
| 101 | + { |
|
| 102 | + $crAllRepositories = new \CriteriaCompo(); |
|
| 103 | + $crAllRepositories = $this->getRepositoriesCriteria($crAllRepositories, $start, $limit, $sort, $order); |
|
| 104 | + return $this->getAll($crAllRepositories); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Get Criteria Repositories |
|
| 109 | + * @param $crRepositories |
|
| 110 | + * @param int $start |
|
| 111 | + * @param int $limit |
|
| 112 | + * @param string $sort |
|
| 113 | + * @param string $order |
|
| 114 | + * @return int |
|
| 115 | + */ |
|
| 116 | + private function getRepositoriesCriteria($crRepositories, $start, $limit, $sort, $order) |
|
| 117 | + { |
|
| 118 | + $crRepositories->setStart($start); |
|
| 119 | + $crRepositories->setLimit($limit); |
|
| 120 | + $crRepositories->setSort($sort); |
|
| 121 | + $crRepositories->setOrder($order); |
|
| 122 | + return $crRepositories; |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | 125 | /** |
| 126 | 126 | * Update table repositories |
@@ -32,96 +32,96 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | class Logs extends \XoopsObject |
| 34 | 34 | { |
| 35 | - /** |
|
| 36 | - * Constructor |
|
| 37 | - * |
|
| 38 | - * @param null |
|
| 39 | - */ |
|
| 40 | - public function __construct() |
|
| 41 | - { |
|
| 42 | - $this->initVar('log_id', XOBJ_DTYPE_INT); |
|
| 35 | + /** |
|
| 36 | + * Constructor |
|
| 37 | + * |
|
| 38 | + * @param null |
|
| 39 | + */ |
|
| 40 | + public function __construct() |
|
| 41 | + { |
|
| 42 | + $this->initVar('log_id', XOBJ_DTYPE_INT); |
|
| 43 | 43 | $this->initVar('log_type', XOBJ_DTYPE_INT); |
| 44 | - $this->initVar('log_details', XOBJ_DTYPE_TXTBOX); |
|
| 45 | - $this->initVar('log_result', XOBJ_DTYPE_TXTAREA); |
|
| 46 | - $this->initVar('log_datecreated', XOBJ_DTYPE_INT); |
|
| 47 | - $this->initVar('log_submitter', XOBJ_DTYPE_INT); |
|
| 48 | - } |
|
| 44 | + $this->initVar('log_details', XOBJ_DTYPE_TXTBOX); |
|
| 45 | + $this->initVar('log_result', XOBJ_DTYPE_TXTAREA); |
|
| 46 | + $this->initVar('log_datecreated', XOBJ_DTYPE_INT); |
|
| 47 | + $this->initVar('log_submitter', XOBJ_DTYPE_INT); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @static function &getInstance |
|
| 52 | - * |
|
| 53 | - * @param null |
|
| 54 | - */ |
|
| 55 | - public static function getInstance() |
|
| 56 | - { |
|
| 57 | - static $instance = false; |
|
| 58 | - if (!$instance) { |
|
| 59 | - $instance = new self(); |
|
| 60 | - } |
|
| 61 | - } |
|
| 50 | + /** |
|
| 51 | + * @static function &getInstance |
|
| 52 | + * |
|
| 53 | + * @param null |
|
| 54 | + */ |
|
| 55 | + public static function getInstance() |
|
| 56 | + { |
|
| 57 | + static $instance = false; |
|
| 58 | + if (!$instance) { |
|
| 59 | + $instance = new self(); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * The new inserted $Id |
|
| 65 | - * @return inserted id |
|
| 66 | - */ |
|
| 67 | - public function getNewInsertedIdLogs() |
|
| 68 | - { |
|
| 69 | - $newInsertedId = $GLOBALS['xoopsDB']->getInsertId(); |
|
| 70 | - return $newInsertedId; |
|
| 71 | - } |
|
| 63 | + /** |
|
| 64 | + * The new inserted $Id |
|
| 65 | + * @return inserted id |
|
| 66 | + */ |
|
| 67 | + public function getNewInsertedIdLogs() |
|
| 68 | + { |
|
| 69 | + $newInsertedId = $GLOBALS['xoopsDB']->getInsertId(); |
|
| 70 | + return $newInsertedId; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * @public function getForm |
|
| 75 | - * @param bool $action |
|
| 76 | - * @return \XoopsThemeForm |
|
| 77 | - */ |
|
| 78 | - public function getFormLogs($action = false) |
|
| 79 | - { |
|
| 80 | - $helper = \XoopsModules\Wggithub\Helper::getInstance(); |
|
| 81 | - if (!$action) { |
|
| 82 | - $action = $_SERVER['REQUEST_URI']; |
|
| 83 | - } |
|
| 84 | - // Title |
|
| 85 | - $title = $this->isNew() ? \sprintf(_AM_WGGITHUB_LOG_ADD) : \sprintf(_AM_WGGITHUB_LOG_EDIT); |
|
| 86 | - // Get Theme Form |
|
| 87 | - \xoops_load('XoopsFormLoader'); |
|
| 88 | - $form = new \XoopsThemeForm($title, 'form', $action, 'post', true); |
|
| 89 | - $form->setExtra('enctype="multipart/form-data"'); |
|
| 73 | + /** |
|
| 74 | + * @public function getForm |
|
| 75 | + * @param bool $action |
|
| 76 | + * @return \XoopsThemeForm |
|
| 77 | + */ |
|
| 78 | + public function getFormLogs($action = false) |
|
| 79 | + { |
|
| 80 | + $helper = \XoopsModules\Wggithub\Helper::getInstance(); |
|
| 81 | + if (!$action) { |
|
| 82 | + $action = $_SERVER['REQUEST_URI']; |
|
| 83 | + } |
|
| 84 | + // Title |
|
| 85 | + $title = $this->isNew() ? \sprintf(_AM_WGGITHUB_LOG_ADD) : \sprintf(_AM_WGGITHUB_LOG_EDIT); |
|
| 86 | + // Get Theme Form |
|
| 87 | + \xoops_load('XoopsFormLoader'); |
|
| 88 | + $form = new \XoopsThemeForm($title, 'form', $action, 'post', true); |
|
| 89 | + $form->setExtra('enctype="multipart/form-data"'); |
|
| 90 | 90 | |
| 91 | 91 | $logTypeSelect = new \XoopsFormSelect(_AM_WGGITHUB_LOG_TYPE, 'log_type', $this->getVar('log_type')); |
| 92 | 92 | $logTypeSelect->addOption(Constants::LOG_TYPE_NONE, _AM_WGGITHUB_LOG_TYPE_NONE); |
| 93 | 93 | $logTypeSelect->addOption(Constants::LOG_TYPE_UPDATE_START, _AM_WGGITHUB_LOG_TYPE_UPDATE_START); |
| 94 | 94 | $logTypeSelect->addOption(Constants::LOG_TYPE_UPDATE_END, _AM_WGGITHUB_LOG_TYPE_UPDATE_END); |
| 95 | 95 | $form->addElement($logTypeSelect); |
| 96 | - // Form Text logDetails |
|
| 97 | - $form->addElement(new \XoopsFormText(_AM_WGGITHUB_LOG_DETAILS, 'log_details', 50, 255, $this->getVar('log_details')), true); |
|
| 98 | - // Form Text logResult |
|
| 96 | + // Form Text logDetails |
|
| 97 | + $form->addElement(new \XoopsFormText(_AM_WGGITHUB_LOG_DETAILS, 'log_details', 50, 255, $this->getVar('log_details')), true); |
|
| 98 | + // Form Text logResult |
|
| 99 | 99 | $form->addElement(new \XoopsFormTextArea(_AM_WGGITHUB_LOG_RESULT, 'log_result', $this->getVar('log_result', 'e'), 4, 47)); |
| 100 | - // Form Text Date Select logDatecreated |
|
| 101 | - $logDatecreated = $this->isNew() ?: $this->getVar('log_datecreated'); |
|
| 102 | - $form->addElement(new \XoopsFormTextDateSelect(_AM_WGGITHUB_LOG_DATECREATED, 'log_datecreated', '', $logDatecreated)); |
|
| 103 | - // Form Select User reqSubmitter |
|
| 104 | - $form->addElement(new \XoopsFormSelectUser(_AM_WGGITHUB_LOG_SUBMITTER, 'log_submitter', false, $this->getVar('log_submitter'))); |
|
| 105 | - // To Save |
|
| 106 | - $form->addElement(new \XoopsFormHidden('op', 'save')); |
|
| 107 | - $form->addElement(new \XoopsFormButtonTray('', _SUBMIT, 'submit', '', false)); |
|
| 108 | - return $form; |
|
| 109 | - } |
|
| 100 | + // Form Text Date Select logDatecreated |
|
| 101 | + $logDatecreated = $this->isNew() ?: $this->getVar('log_datecreated'); |
|
| 102 | + $form->addElement(new \XoopsFormTextDateSelect(_AM_WGGITHUB_LOG_DATECREATED, 'log_datecreated', '', $logDatecreated)); |
|
| 103 | + // Form Select User reqSubmitter |
|
| 104 | + $form->addElement(new \XoopsFormSelectUser(_AM_WGGITHUB_LOG_SUBMITTER, 'log_submitter', false, $this->getVar('log_submitter'))); |
|
| 105 | + // To Save |
|
| 106 | + $form->addElement(new \XoopsFormHidden('op', 'save')); |
|
| 107 | + $form->addElement(new \XoopsFormButtonTray('', _SUBMIT, 'submit', '', false)); |
|
| 108 | + return $form; |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * Get Values |
|
| 113 | - * @param null $keys |
|
| 114 | - * @param null $format |
|
| 115 | - * @param null $maxDepth |
|
| 116 | - * @return array |
|
| 117 | - */ |
|
| 118 | - public function getValuesLogs($keys = null, $format = null, $maxDepth = null) |
|
| 119 | - { |
|
| 111 | + /** |
|
| 112 | + * Get Values |
|
| 113 | + * @param null $keys |
|
| 114 | + * @param null $format |
|
| 115 | + * @param null $maxDepth |
|
| 116 | + * @return array |
|
| 117 | + */ |
|
| 118 | + public function getValuesLogs($keys = null, $format = null, $maxDepth = null) |
|
| 119 | + { |
|
| 120 | 120 | $helper = \XoopsModules\Wggithub\Helper::getInstance(); |
| 121 | 121 | $utility = new \XoopsModules\Wggithub\Utility(); |
| 122 | 122 | $editorMaxchar = $helper->getConfig('editor_maxchar'); |
| 123 | - $ret = $this->getValues($keys, $format, $maxDepth); |
|
| 124 | - $ret['id'] = $this->getVar('log_id'); |
|
| 123 | + $ret = $this->getValues($keys, $format, $maxDepth); |
|
| 124 | + $ret['id'] = $this->getVar('log_id'); |
|
| 125 | 125 | $ret['type'] = $this->getVar('log_type'); |
| 126 | 126 | switch ($ret['type']) { |
| 127 | 127 | case Constants::LOG_TYPE_NONE: |
@@ -139,26 +139,26 @@ discard block |
||
| 139 | 139 | break; |
| 140 | 140 | } |
| 141 | 141 | $ret['type_text'] = $type_text; |
| 142 | - $ret['details'] = $this->getVar('log_details'); |
|
| 142 | + $ret['details'] = $this->getVar('log_details'); |
|
| 143 | 143 | $ret['result'] = \strip_tags($this->getVar('log_result', 'e')); |
| 144 | 144 | $ret['result_short'] = $utility::truncateHtml($ret['result'], $editorMaxchar); |
| 145 | - $ret['datecreated'] = \formatTimestamp($this->getVar('log_datecreated'), 'm'); |
|
| 146 | - $ret['submitter'] = \XoopsUser::getUnameFromId($this->getVar('log_submitter')); |
|
| 147 | - return $ret; |
|
| 148 | - } |
|
| 145 | + $ret['datecreated'] = \formatTimestamp($this->getVar('log_datecreated'), 'm'); |
|
| 146 | + $ret['submitter'] = \XoopsUser::getUnameFromId($this->getVar('log_submitter')); |
|
| 147 | + return $ret; |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - /** |
|
| 151 | - * Returns an array representation of the object |
|
| 152 | - * |
|
| 153 | - * @return array |
|
| 154 | - */ |
|
| 155 | - public function toArrayRequests() |
|
| 156 | - { |
|
| 157 | - $ret = []; |
|
| 158 | - $vars = $this->getVars(); |
|
| 159 | - foreach (\array_keys($vars) as $var) { |
|
| 160 | - $ret[$var] = $this->getVar('"{$var}"'); |
|
| 161 | - } |
|
| 162 | - return $ret; |
|
| 163 | - } |
|
| 150 | + /** |
|
| 151 | + * Returns an array representation of the object |
|
| 152 | + * |
|
| 153 | + * @return array |
|
| 154 | + */ |
|
| 155 | + public function toArrayRequests() |
|
| 156 | + { |
|
| 157 | + $ret = []; |
|
| 158 | + $vars = $this->getVars(); |
|
| 159 | + foreach (\array_keys($vars) as $var) { |
|
| 160 | + $ret[$var] = $this->getVar('"{$var}"'); |
|
| 161 | + } |
|
| 162 | + return $ret; |
|
| 163 | + } |
|
| 164 | 164 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | interface Constants |
| 30 | 30 | { |
| 31 | - // Constants for tables |
|
| 31 | + // Constants for tables |
|
| 32 | 32 | public const TABLE_SETTINGS = 0; |
| 33 | 33 | public const TABLE_REPOSITORIES = 1; |
| 34 | 34 | public const TABLE_DIRECTORIES = 2; |
@@ -39,17 +39,17 @@ discard block |
||
| 39 | 39 | public const DIRECTORY_TYPE_USER = 1; |
| 40 | 40 | public const DIRECTORY_TYPE_ORG = 2; |
| 41 | 41 | |
| 42 | - // Constants for status |
|
| 43 | - public const STATUS_NONE = 0; |
|
| 42 | + // Constants for status |
|
| 43 | + public const STATUS_NONE = 0; |
|
| 44 | 44 | public const STATUS_NEW = 1; |
| 45 | 45 | public const STATUS_UPDATED = 2; |
| 46 | - public const STATUS_UPTODATE = 3; |
|
| 46 | + public const STATUS_UPTODATE = 3; |
|
| 47 | 47 | |
| 48 | - // Constants for permissions |
|
| 49 | - public const PERM_GLOBAL_NONE = 0; |
|
| 50 | - public const PERM_GLOBAL_VIEW = 1; |
|
| 51 | - public const PERM_GLOBAL_READ = 2; |
|
| 52 | - public const PERM_README_UPDATE = 3; |
|
| 48 | + // Constants for permissions |
|
| 49 | + public const PERM_GLOBAL_NONE = 0; |
|
| 50 | + public const PERM_GLOBAL_VIEW = 1; |
|
| 51 | + public const PERM_GLOBAL_READ = 2; |
|
| 52 | + public const PERM_README_UPDATE = 3; |
|
| 53 | 53 | |
| 54 | 54 | // Constants for log type |
| 55 | 55 | public const LOG_TYPE_NONE = 0; |
@@ -31,96 +31,96 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class LogsHandler extends \XoopsPersistableObjectHandler |
| 33 | 33 | { |
| 34 | - /** |
|
| 35 | - * Constructor |
|
| 36 | - * |
|
| 37 | - * @param \XoopsDatabase $db |
|
| 38 | - */ |
|
| 39 | - public function __construct(\XoopsDatabase $db) |
|
| 40 | - { |
|
| 41 | - parent::__construct($db, 'wggithub_logs', Logs::class, 'log_id', 'log_detail'); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @param bool $isNew |
|
| 46 | - * |
|
| 47 | - * @return object |
|
| 48 | - */ |
|
| 49 | - public function create($isNew = true) |
|
| 50 | - { |
|
| 51 | - return parent::create($isNew); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * retrieve a field |
|
| 56 | - * |
|
| 57 | - * @param int $i field id |
|
| 58 | - * @param null fields |
|
| 59 | - * @return mixed reference to the {@link Get} object |
|
| 60 | - */ |
|
| 61 | - public function get($i = null, $fields = null) |
|
| 62 | - { |
|
| 63 | - return parent::get($i, $fields); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * get inserted id |
|
| 68 | - * |
|
| 69 | - * @param null |
|
| 70 | - * @return int reference to the {@link Get} object |
|
| 71 | - */ |
|
| 72 | - public function getInsertId() |
|
| 73 | - { |
|
| 74 | - return $this->db->getInsertId(); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Get Count Logs in the database |
|
| 79 | - * @param int $start |
|
| 80 | - * @param int $limit |
|
| 81 | - * @param string $sort |
|
| 82 | - * @param string $order |
|
| 83 | - * @return int |
|
| 84 | - */ |
|
| 85 | - public function getCountLogs($start = 0, $limit = 0, $sort = 'log_id', $order = 'ASC') |
|
| 86 | - { |
|
| 87 | - $crCountLogs = new \CriteriaCompo(); |
|
| 88 | - $crCountLogs = $this->getLogsCriteria($crCountLogs, $start, $limit, $sort, $order); |
|
| 89 | - return $this->getCount($crCountLogs); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Get All Logs in the database |
|
| 94 | - * @param int $start |
|
| 95 | - * @param int $limit |
|
| 96 | - * @param string $sort |
|
| 97 | - * @param string $order |
|
| 98 | - * @return array |
|
| 99 | - */ |
|
| 100 | - public function getAllLogs($start = 0, $limit = 0, $sort = 'log_id', $order = 'ASC') |
|
| 101 | - { |
|
| 102 | - $crAllLogs = new \CriteriaCompo(); |
|
| 103 | - $crAllLogs = $this->getLogsCriteria($crAllLogs, $start, $limit, $sort, $order); |
|
| 104 | - return $this->getAll($crAllLogs); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Get Criteria Logs |
|
| 109 | - * @param $crLogs |
|
| 110 | - * @param int $start |
|
| 111 | - * @param int $limit |
|
| 112 | - * @param string $sort |
|
| 113 | - * @param string $order |
|
| 114 | - * @return int |
|
| 115 | - */ |
|
| 116 | - private function getLogsCriteria($crLogs, $start, $limit, $sort, $order) |
|
| 117 | - { |
|
| 118 | - $crLogs->setStart($start); |
|
| 119 | - $crLogs->setLimit($limit); |
|
| 120 | - $crLogs->setSort($sort); |
|
| 121 | - $crLogs->setOrder($order); |
|
| 122 | - return $crLogs; |
|
| 123 | - } |
|
| 34 | + /** |
|
| 35 | + * Constructor |
|
| 36 | + * |
|
| 37 | + * @param \XoopsDatabase $db |
|
| 38 | + */ |
|
| 39 | + public function __construct(\XoopsDatabase $db) |
|
| 40 | + { |
|
| 41 | + parent::__construct($db, 'wggithub_logs', Logs::class, 'log_id', 'log_detail'); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @param bool $isNew |
|
| 46 | + * |
|
| 47 | + * @return object |
|
| 48 | + */ |
|
| 49 | + public function create($isNew = true) |
|
| 50 | + { |
|
| 51 | + return parent::create($isNew); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * retrieve a field |
|
| 56 | + * |
|
| 57 | + * @param int $i field id |
|
| 58 | + * @param null fields |
|
| 59 | + * @return mixed reference to the {@link Get} object |
|
| 60 | + */ |
|
| 61 | + public function get($i = null, $fields = null) |
|
| 62 | + { |
|
| 63 | + return parent::get($i, $fields); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * get inserted id |
|
| 68 | + * |
|
| 69 | + * @param null |
|
| 70 | + * @return int reference to the {@link Get} object |
|
| 71 | + */ |
|
| 72 | + public function getInsertId() |
|
| 73 | + { |
|
| 74 | + return $this->db->getInsertId(); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Get Count Logs in the database |
|
| 79 | + * @param int $start |
|
| 80 | + * @param int $limit |
|
| 81 | + * @param string $sort |
|
| 82 | + * @param string $order |
|
| 83 | + * @return int |
|
| 84 | + */ |
|
| 85 | + public function getCountLogs($start = 0, $limit = 0, $sort = 'log_id', $order = 'ASC') |
|
| 86 | + { |
|
| 87 | + $crCountLogs = new \CriteriaCompo(); |
|
| 88 | + $crCountLogs = $this->getLogsCriteria($crCountLogs, $start, $limit, $sort, $order); |
|
| 89 | + return $this->getCount($crCountLogs); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Get All Logs in the database |
|
| 94 | + * @param int $start |
|
| 95 | + * @param int $limit |
|
| 96 | + * @param string $sort |
|
| 97 | + * @param string $order |
|
| 98 | + * @return array |
|
| 99 | + */ |
|
| 100 | + public function getAllLogs($start = 0, $limit = 0, $sort = 'log_id', $order = 'ASC') |
|
| 101 | + { |
|
| 102 | + $crAllLogs = new \CriteriaCompo(); |
|
| 103 | + $crAllLogs = $this->getLogsCriteria($crAllLogs, $start, $limit, $sort, $order); |
|
| 104 | + return $this->getAll($crAllLogs); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Get Criteria Logs |
|
| 109 | + * @param $crLogs |
|
| 110 | + * @param int $start |
|
| 111 | + * @param int $limit |
|
| 112 | + * @param string $sort |
|
| 113 | + * @param string $order |
|
| 114 | + * @return int |
|
| 115 | + */ |
|
| 116 | + private function getLogsCriteria($crLogs, $start, $limit, $sort, $order) |
|
| 117 | + { |
|
| 118 | + $crLogs->setStart($start); |
|
| 119 | + $crLogs->setLimit($limit); |
|
| 120 | + $crLogs->setSort($sort); |
|
| 121 | + $crLogs->setOrder($order); |
|
| 122 | + return $crLogs; |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | 125 | /** |
| 126 | 126 | * Update table requests |