@@ -29,29 +29,29 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | class SmartobjectBasedUrl extends Smartobject\BaseSmartObject |
| 31 | 31 | { |
| 32 | - /** |
|
| 33 | - * SmartobjectBasedUrl constructor. |
|
| 34 | - */ |
|
| 35 | - public function __construct() |
|
| 36 | - { |
|
| 37 | - $this->quickInitVar('caption', XOBJ_DTYPE_TXTBOX, false); |
|
| 38 | - $this->quickInitVar('description', XOBJ_DTYPE_TXTBOX, false); |
|
| 39 | - $this->quickInitVar('url', XOBJ_DTYPE_TXTBOX, false); |
|
| 40 | - } |
|
| 32 | + /** |
|
| 33 | + * SmartobjectBasedUrl constructor. |
|
| 34 | + */ |
|
| 35 | + public function __construct() |
|
| 36 | + { |
|
| 37 | + $this->quickInitVar('caption', XOBJ_DTYPE_TXTBOX, false); |
|
| 38 | + $this->quickInitVar('description', XOBJ_DTYPE_TXTBOX, false); |
|
| 39 | + $this->quickInitVar('url', XOBJ_DTYPE_TXTBOX, false); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @param string $key |
|
| 44 | - * @param string $format |
|
| 45 | - * @return mixed |
|
| 46 | - */ |
|
| 47 | - public function getVar($key, $format = 'e') |
|
| 48 | - { |
|
| 49 | - if (0 === strpos($key, 'url_')) { |
|
| 50 | - return parent::getVar('url', $format); |
|
| 51 | - } elseif (0 === strpos($key, 'caption_')) { |
|
| 52 | - return parent::getVar('caption', $format); |
|
| 53 | - } else { |
|
| 54 | - return parent::getVar($key, $format); |
|
| 55 | - } |
|
| 56 | - } |
|
| 42 | + /** |
|
| 43 | + * @param string $key |
|
| 44 | + * @param string $format |
|
| 45 | + * @return mixed |
|
| 46 | + */ |
|
| 47 | + public function getVar($key, $format = 'e') |
|
| 48 | + { |
|
| 49 | + if (0 === strpos($key, 'url_')) { |
|
| 50 | + return parent::getVar('url', $format); |
|
| 51 | + } elseif (0 === strpos($key, 'caption_')) { |
|
| 52 | + return parent::getVar('caption', $format); |
|
| 53 | + } else { |
|
| 54 | + return parent::getVar($key, $format); |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | 57 | } |
@@ -41,116 +41,116 @@ |
||
| 41 | 41 | */ |
| 42 | 42 | class SmartObjectExport |
| 43 | 43 | { |
| 44 | - public $handler; |
|
| 45 | - public $criteria; |
|
| 46 | - public $fields; |
|
| 47 | - public $format; |
|
| 48 | - public $filename; |
|
| 49 | - public $filepath; |
|
| 50 | - public $options; |
|
| 51 | - public $outputMethods = false; |
|
| 52 | - public $notDisplayFields; |
|
| 44 | + public $handler; |
|
| 45 | + public $criteria; |
|
| 46 | + public $fields; |
|
| 47 | + public $format; |
|
| 48 | + public $filename; |
|
| 49 | + public $filepath; |
|
| 50 | + public $options; |
|
| 51 | + public $outputMethods = false; |
|
| 52 | + public $notDisplayFields; |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Constructor |
|
| 56 | - * |
|
| 57 | - * @param SmartPersistableObjectHandler $objectHandler SmartObjectHandler handling the data we want to export |
|
| 58 | - * @param \CriteriaElement $criteria containing the criteria of the query fetching the objects to be exported |
|
| 59 | - * @param array|bool $fields fields to be exported. If FALSE then all fields will be exported |
|
| 60 | - * @param bool|string $filename name of the file to be created |
|
| 61 | - * @param bool|string $filepath path where the file will be saved |
|
| 62 | - * @param string $format format of the ouputed export. Currently only supports CSV |
|
| 63 | - * @param array|bool $options options of the format to be exported in |
|
| 64 | - */ |
|
| 65 | - public function __construct( |
|
| 66 | - SmartPersistableObjectHandler $objectHandler, |
|
| 67 | - \CriteriaElement $criteria = null, |
|
| 68 | - $fields = false, |
|
| 69 | - $filename = false, |
|
| 70 | - $filepath = false, |
|
| 71 | - $format = 'csv', |
|
| 72 | - $options = false |
|
| 73 | - ) { |
|
| 74 | - $this->handler = $objectHandler; |
|
| 75 | - $this->criteria = $criteria; |
|
| 76 | - $this->fields = $fields; |
|
| 77 | - $this->filename = $filename; |
|
| 78 | - $this->format = $format; |
|
| 79 | - $this->options = $options; |
|
| 80 | - $this->notDisplayFields = false; |
|
| 81 | - } |
|
| 54 | + /** |
|
| 55 | + * Constructor |
|
| 56 | + * |
|
| 57 | + * @param SmartPersistableObjectHandler $objectHandler SmartObjectHandler handling the data we want to export |
|
| 58 | + * @param \CriteriaElement $criteria containing the criteria of the query fetching the objects to be exported |
|
| 59 | + * @param array|bool $fields fields to be exported. If FALSE then all fields will be exported |
|
| 60 | + * @param bool|string $filename name of the file to be created |
|
| 61 | + * @param bool|string $filepath path where the file will be saved |
|
| 62 | + * @param string $format format of the ouputed export. Currently only supports CSV |
|
| 63 | + * @param array|bool $options options of the format to be exported in |
|
| 64 | + */ |
|
| 65 | + public function __construct( |
|
| 66 | + SmartPersistableObjectHandler $objectHandler, |
|
| 67 | + \CriteriaElement $criteria = null, |
|
| 68 | + $fields = false, |
|
| 69 | + $filename = false, |
|
| 70 | + $filepath = false, |
|
| 71 | + $format = 'csv', |
|
| 72 | + $options = false |
|
| 73 | + ) { |
|
| 74 | + $this->handler = $objectHandler; |
|
| 75 | + $this->criteria = $criteria; |
|
| 76 | + $this->fields = $fields; |
|
| 77 | + $this->filename = $filename; |
|
| 78 | + $this->format = $format; |
|
| 79 | + $this->options = $options; |
|
| 80 | + $this->notDisplayFields = false; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * Renders the export |
|
| 85 | - * @param $filename |
|
| 86 | - */ |
|
| 87 | - public function render($filename) |
|
| 88 | - { |
|
| 89 | - $this->filename = $filename; |
|
| 83 | + /** |
|
| 84 | + * Renders the export |
|
| 85 | + * @param $filename |
|
| 86 | + */ |
|
| 87 | + public function render($filename) |
|
| 88 | + { |
|
| 89 | + $this->filename = $filename; |
|
| 90 | 90 | |
| 91 | - $objects = $this->handler->getObjects($this->criteria); |
|
| 92 | - $rows = []; |
|
| 93 | - $columnsHeaders = []; |
|
| 94 | - $firstObject = true; |
|
| 95 | - foreach ($objects as $object) { |
|
| 96 | - $row = []; |
|
| 97 | - foreach ($object->vars as $key => $var) { |
|
| 98 | - if ((!$this->fields || in_array($key, $this->fields)) && !in_array($key, $this->notDisplayFields)) { |
|
| 99 | - if ($this->outputMethods && isset($this->outputMethods[$key]) |
|
| 100 | - && method_exists($object, $this->outputMethods[$key])) { |
|
| 101 | - $method = $this->outputMethods[$key]; |
|
| 102 | - $row[$key] = $object->$method(); |
|
| 103 | - } else { |
|
| 104 | - $row[$key] = $object->getVar($key); |
|
| 105 | - } |
|
| 106 | - if ($firstObject) { |
|
| 107 | - // then set the columnsHeaders array as well |
|
| 108 | - $columnsHeaders[$key] = $var['form_caption']; |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - $firstObject = false; |
|
| 113 | - $rows[] = $row; |
|
| 114 | - unset($row); |
|
| 115 | - } |
|
| 116 | - $data = []; |
|
| 117 | - $data['rows'] = $rows; |
|
| 118 | - $data['columnsHeaders'] = $columnsHeaders; |
|
| 119 | - $smartExportRenderer = new SmartExportRenderer($data, $this->filename, $this->filepath, $this->format, $this->options); |
|
| 120 | - $smartExportRenderer->execute(); |
|
| 121 | - } |
|
| 91 | + $objects = $this->handler->getObjects($this->criteria); |
|
| 92 | + $rows = []; |
|
| 93 | + $columnsHeaders = []; |
|
| 94 | + $firstObject = true; |
|
| 95 | + foreach ($objects as $object) { |
|
| 96 | + $row = []; |
|
| 97 | + foreach ($object->vars as $key => $var) { |
|
| 98 | + if ((!$this->fields || in_array($key, $this->fields)) && !in_array($key, $this->notDisplayFields)) { |
|
| 99 | + if ($this->outputMethods && isset($this->outputMethods[$key]) |
|
| 100 | + && method_exists($object, $this->outputMethods[$key])) { |
|
| 101 | + $method = $this->outputMethods[$key]; |
|
| 102 | + $row[$key] = $object->$method(); |
|
| 103 | + } else { |
|
| 104 | + $row[$key] = $object->getVar($key); |
|
| 105 | + } |
|
| 106 | + if ($firstObject) { |
|
| 107 | + // then set the columnsHeaders array as well |
|
| 108 | + $columnsHeaders[$key] = $var['form_caption']; |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + $firstObject = false; |
|
| 113 | + $rows[] = $row; |
|
| 114 | + unset($row); |
|
| 115 | + } |
|
| 116 | + $data = []; |
|
| 117 | + $data['rows'] = $rows; |
|
| 118 | + $data['columnsHeaders'] = $columnsHeaders; |
|
| 119 | + $smartExportRenderer = new SmartExportRenderer($data, $this->filename, $this->filepath, $this->format, $this->options); |
|
| 120 | + $smartExportRenderer->execute(); |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * Set an array contaning the alternate methods to use instead of the default getVar() |
|
| 125 | - * |
|
| 126 | - * $outputMethods array example: 'uid' => 'getUserName'... |
|
| 127 | - * @param $outputMethods |
|
| 128 | - */ |
|
| 129 | - public function setOuptutMethods($outputMethods) |
|
| 130 | - { |
|
| 131 | - $this->outputMethods = $outputMethods; |
|
| 132 | - } |
|
| 123 | + /** |
|
| 124 | + * Set an array contaning the alternate methods to use instead of the default getVar() |
|
| 125 | + * |
|
| 126 | + * $outputMethods array example: 'uid' => 'getUserName'... |
|
| 127 | + * @param $outputMethods |
|
| 128 | + */ |
|
| 129 | + public function setOuptutMethods($outputMethods) |
|
| 130 | + { |
|
| 131 | + $this->outputMethods = $outputMethods; |
|
| 132 | + } |
|
| 133 | 133 | |
| 134 | - /* |
|
| 134 | + /* |
|
| 135 | 135 | * Set an array of fields that we don't want in export |
| 136 | 136 | */ |
| 137 | - /** |
|
| 138 | - * @param $fields |
|
| 139 | - */ |
|
| 140 | - public function setNotDisplayFields($fields) |
|
| 141 | - { |
|
| 142 | - if (!$this->notDisplayFields) { |
|
| 143 | - if (is_array($fields)) { |
|
| 144 | - $this->notDisplayFields = $fields; |
|
| 145 | - } else { |
|
| 146 | - $this->notDisplayFields = [$fields]; |
|
| 147 | - } |
|
| 148 | - } else { |
|
| 149 | - if (is_array($fields)) { |
|
| 150 | - $this->notDisplayFields = array_merge($this->notDisplayFields, $fields); |
|
| 151 | - } else { |
|
| 152 | - $this->notDisplayFields[] = $fields; |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - } |
|
| 137 | + /** |
|
| 138 | + * @param $fields |
|
| 139 | + */ |
|
| 140 | + public function setNotDisplayFields($fields) |
|
| 141 | + { |
|
| 142 | + if (!$this->notDisplayFields) { |
|
| 143 | + if (is_array($fields)) { |
|
| 144 | + $this->notDisplayFields = $fields; |
|
| 145 | + } else { |
|
| 146 | + $this->notDisplayFields = [$fields]; |
|
| 147 | + } |
|
| 148 | + } else { |
|
| 149 | + if (is_array($fields)) { |
|
| 150 | + $this->notDisplayFields = array_merge($this->notDisplayFields, $fields); |
|
| 151 | + } else { |
|
| 152 | + $this->notDisplayFields[] = $fields; |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | 156 | } |
@@ -29,152 +29,152 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | class SmartobjectLink extends Smartobject\BaseSmartObject |
| 31 | 31 | { |
| 32 | - /** |
|
| 33 | - * SmartobjectLink constructor. |
|
| 34 | - */ |
|
| 35 | - public function __construct() |
|
| 36 | - { |
|
| 37 | - $this->initVar('linkid', XOBJ_DTYPE_INT, '', true); |
|
| 38 | - $this->initVar('date', XOBJ_DTYPE_INT, 0, false, null, '', false, _CO_SOBJECT_LINK_DATE, '', true, true, false); |
|
| 39 | - $this->initVar('from_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_FROM_UID, _CO_SOBJECT_LINK_FROM_UID_DSC); |
|
| 40 | - $this->initVar('from_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_EMAIL, _CO_SOBJECT_LINK_FROM_EMAIL_DSC, true); |
|
| 41 | - $this->initVar('from_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_NAME, _CO_SOBJECT_LINK_FROM_NAME_DSC, true); |
|
| 42 | - $this->initVar('to_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_TO_UID, _CO_SOBJECT_LINK_TO_UID_DSC); |
|
| 43 | - $this->initVar('to_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_EMAIL, _CO_SOBJECT_LINK_TO_EMAIL_DSC, true); |
|
| 44 | - $this->initVar('to_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_NAME, _CO_SOBJECT_LINK_TO_NAME_DSC, true); |
|
| 45 | - $this->initVar('link', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_LINK, _CO_SOBJECT_LINK_LINK_DSC, true); |
|
| 46 | - $this->initVar('subject', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_SUBJECT, _CO_SOBJECT_LINK_SUBJECT_DSC, true); |
|
| 47 | - $this->initVar('body', XOBJ_DTYPE_TXTAREA, '', true, null, '', false, _CO_SOBJECT_LINK_BODY, _CO_SOBJECT_LINK_BODY_DSC); |
|
| 48 | - $this->initVar('mid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_MID, _CO_SOBJECT_LINK_MID_DSC); |
|
| 49 | - $this->initVar('mid_name', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_MID_NAME, _CO_SOBJECT_LINK_MID_NAME_DSC, true); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * returns a specific variable for the object in a proper format |
|
| 54 | - * |
|
| 55 | - * @access public |
|
| 56 | - * @param string $key key of the object's variable to be returned |
|
| 57 | - * @param string $format format to use for the output |
|
| 58 | - * @return mixed formatted value of the variable |
|
| 59 | - */ |
|
| 60 | - public function getVar($key, $format = 's') |
|
| 61 | - { |
|
| 62 | - if ('s' === $format && in_array($key, ['from_uid', 'to_uid', 'date', 'link'])) { |
|
| 63 | - // return call_user_func(array($this, $key)); |
|
| 64 | - return $this->{$key}(); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - return parent::getVar($key, $format); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @return string |
|
| 72 | - */ |
|
| 73 | - public function from_uid() |
|
| 74 | - { |
|
| 75 | - $ret = smart_getLinkedUnameFromId($this->getVar('from_uid', 'e'), 1, null, true); |
|
| 76 | - |
|
| 77 | - return $ret; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @param bool $withContact |
|
| 82 | - * @return string |
|
| 83 | - */ |
|
| 84 | - public function to_uid($withContact = false) |
|
| 85 | - { |
|
| 86 | - $ret = smart_getLinkedUnameFromId($this->getVar('to_uid', 'e'), 1, null, true); |
|
| 87 | - |
|
| 88 | - return $ret; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @return string |
|
| 93 | - */ |
|
| 94 | - public function date() |
|
| 95 | - { |
|
| 96 | - $ret = formatTimestamp($this->getVar('date', 'e')); |
|
| 97 | - |
|
| 98 | - return $ret; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @param bool $full |
|
| 103 | - * @return mixed|string |
|
| 104 | - */ |
|
| 105 | - public function link($full = false) |
|
| 106 | - { |
|
| 107 | - $ret = $this->getVar('link', 'e'); |
|
| 108 | - if ($full) { |
|
| 109 | - $myts = \MyTextSanitizer::getInstance(); |
|
| 110 | - $ret = $myts->displayTarea($ret); |
|
| 111 | - |
|
| 112 | - return $ret; |
|
| 113 | - } else { |
|
| 114 | - $ret = '<a href="' . $ret . '" alt="' . $this->getVar('link', 'e') . '" title="' . $this->getVar('link', 'e') . '">' . _AM_SOBJECT_SENT_LINKS_GOTO . '</a>'; |
|
| 115 | - |
|
| 116 | - return $ret; |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * @return string |
|
| 122 | - */ |
|
| 123 | - public function getViewItemLink() |
|
| 124 | - { |
|
| 125 | - $ret = '<a href="' . SMARTOBJECT_URL . 'admin/link.php?op=view&linkid=' . $this->getVar('linkid') . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'mail_find.png" alt="' . _AM_SOBJECT_SENT_LINK_VIEW . '" title="' . _AM_SOBJECT_SENT_LINK_VIEW . '"></a>'; |
|
| 126 | - |
|
| 127 | - return $ret; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @return string |
|
| 132 | - */ |
|
| 133 | - public function getFromInfo() |
|
| 134 | - { |
|
| 135 | - // check if from_uid represent a user |
|
| 136 | - |
|
| 137 | - if ($this->getVar('from_uid')) { |
|
| 138 | - $user = smart_getLinkedUnameFromId($this->getVar('from_uid')); |
|
| 139 | - if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
|
| 140 | - $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
| 141 | - } |
|
| 142 | - } else { |
|
| 143 | - $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - return $user; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @return array |
|
| 151 | - */ |
|
| 152 | - public function toArray() |
|
| 153 | - { |
|
| 154 | - $ret = parent::toArray(); |
|
| 155 | - $ret['fromInfo'] = $this->getFromInfo(); |
|
| 156 | - $ret['toInfo'] = $this->getToInfo(); |
|
| 157 | - $ret['fullLink'] = $this->link(true); |
|
| 158 | - |
|
| 159 | - return $ret; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * @return string |
|
| 164 | - */ |
|
| 165 | - public function getToInfo() |
|
| 166 | - { |
|
| 167 | - // check if from_uid represent a user |
|
| 168 | - |
|
| 169 | - if ($this->getVar('to_uid')) { |
|
| 170 | - $user = smart_getLinkedUnameFromId($this->getVar('to_uid')); |
|
| 171 | - if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
|
| 172 | - $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
| 173 | - } |
|
| 174 | - } else { |
|
| 175 | - $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - return $user; |
|
| 179 | - } |
|
| 32 | + /** |
|
| 33 | + * SmartobjectLink constructor. |
|
| 34 | + */ |
|
| 35 | + public function __construct() |
|
| 36 | + { |
|
| 37 | + $this->initVar('linkid', XOBJ_DTYPE_INT, '', true); |
|
| 38 | + $this->initVar('date', XOBJ_DTYPE_INT, 0, false, null, '', false, _CO_SOBJECT_LINK_DATE, '', true, true, false); |
|
| 39 | + $this->initVar('from_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_FROM_UID, _CO_SOBJECT_LINK_FROM_UID_DSC); |
|
| 40 | + $this->initVar('from_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_EMAIL, _CO_SOBJECT_LINK_FROM_EMAIL_DSC, true); |
|
| 41 | + $this->initVar('from_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_NAME, _CO_SOBJECT_LINK_FROM_NAME_DSC, true); |
|
| 42 | + $this->initVar('to_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_TO_UID, _CO_SOBJECT_LINK_TO_UID_DSC); |
|
| 43 | + $this->initVar('to_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_EMAIL, _CO_SOBJECT_LINK_TO_EMAIL_DSC, true); |
|
| 44 | + $this->initVar('to_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_NAME, _CO_SOBJECT_LINK_TO_NAME_DSC, true); |
|
| 45 | + $this->initVar('link', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_LINK, _CO_SOBJECT_LINK_LINK_DSC, true); |
|
| 46 | + $this->initVar('subject', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_SUBJECT, _CO_SOBJECT_LINK_SUBJECT_DSC, true); |
|
| 47 | + $this->initVar('body', XOBJ_DTYPE_TXTAREA, '', true, null, '', false, _CO_SOBJECT_LINK_BODY, _CO_SOBJECT_LINK_BODY_DSC); |
|
| 48 | + $this->initVar('mid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_MID, _CO_SOBJECT_LINK_MID_DSC); |
|
| 49 | + $this->initVar('mid_name', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_MID_NAME, _CO_SOBJECT_LINK_MID_NAME_DSC, true); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * returns a specific variable for the object in a proper format |
|
| 54 | + * |
|
| 55 | + * @access public |
|
| 56 | + * @param string $key key of the object's variable to be returned |
|
| 57 | + * @param string $format format to use for the output |
|
| 58 | + * @return mixed formatted value of the variable |
|
| 59 | + */ |
|
| 60 | + public function getVar($key, $format = 's') |
|
| 61 | + { |
|
| 62 | + if ('s' === $format && in_array($key, ['from_uid', 'to_uid', 'date', 'link'])) { |
|
| 63 | + // return call_user_func(array($this, $key)); |
|
| 64 | + return $this->{$key}(); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + return parent::getVar($key, $format); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @return string |
|
| 72 | + */ |
|
| 73 | + public function from_uid() |
|
| 74 | + { |
|
| 75 | + $ret = smart_getLinkedUnameFromId($this->getVar('from_uid', 'e'), 1, null, true); |
|
| 76 | + |
|
| 77 | + return $ret; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @param bool $withContact |
|
| 82 | + * @return string |
|
| 83 | + */ |
|
| 84 | + public function to_uid($withContact = false) |
|
| 85 | + { |
|
| 86 | + $ret = smart_getLinkedUnameFromId($this->getVar('to_uid', 'e'), 1, null, true); |
|
| 87 | + |
|
| 88 | + return $ret; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @return string |
|
| 93 | + */ |
|
| 94 | + public function date() |
|
| 95 | + { |
|
| 96 | + $ret = formatTimestamp($this->getVar('date', 'e')); |
|
| 97 | + |
|
| 98 | + return $ret; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @param bool $full |
|
| 103 | + * @return mixed|string |
|
| 104 | + */ |
|
| 105 | + public function link($full = false) |
|
| 106 | + { |
|
| 107 | + $ret = $this->getVar('link', 'e'); |
|
| 108 | + if ($full) { |
|
| 109 | + $myts = \MyTextSanitizer::getInstance(); |
|
| 110 | + $ret = $myts->displayTarea($ret); |
|
| 111 | + |
|
| 112 | + return $ret; |
|
| 113 | + } else { |
|
| 114 | + $ret = '<a href="' . $ret . '" alt="' . $this->getVar('link', 'e') . '" title="' . $this->getVar('link', 'e') . '">' . _AM_SOBJECT_SENT_LINKS_GOTO . '</a>'; |
|
| 115 | + |
|
| 116 | + return $ret; |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * @return string |
|
| 122 | + */ |
|
| 123 | + public function getViewItemLink() |
|
| 124 | + { |
|
| 125 | + $ret = '<a href="' . SMARTOBJECT_URL . 'admin/link.php?op=view&linkid=' . $this->getVar('linkid') . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'mail_find.png" alt="' . _AM_SOBJECT_SENT_LINK_VIEW . '" title="' . _AM_SOBJECT_SENT_LINK_VIEW . '"></a>'; |
|
| 126 | + |
|
| 127 | + return $ret; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @return string |
|
| 132 | + */ |
|
| 133 | + public function getFromInfo() |
|
| 134 | + { |
|
| 135 | + // check if from_uid represent a user |
|
| 136 | + |
|
| 137 | + if ($this->getVar('from_uid')) { |
|
| 138 | + $user = smart_getLinkedUnameFromId($this->getVar('from_uid')); |
|
| 139 | + if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
|
| 140 | + $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
| 141 | + } |
|
| 142 | + } else { |
|
| 143 | + $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + return $user; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * @return array |
|
| 151 | + */ |
|
| 152 | + public function toArray() |
|
| 153 | + { |
|
| 154 | + $ret = parent::toArray(); |
|
| 155 | + $ret['fromInfo'] = $this->getFromInfo(); |
|
| 156 | + $ret['toInfo'] = $this->getToInfo(); |
|
| 157 | + $ret['fullLink'] = $this->link(true); |
|
| 158 | + |
|
| 159 | + return $ret; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * @return string |
|
| 164 | + */ |
|
| 165 | + public function getToInfo() |
|
| 166 | + { |
|
| 167 | + // check if from_uid represent a user |
|
| 168 | + |
|
| 169 | + if ($this->getVar('to_uid')) { |
|
| 170 | + $user = smart_getLinkedUnameFromId($this->getVar('to_uid')); |
|
| 171 | + if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
|
| 172 | + $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
| 173 | + } |
|
| 174 | + } else { |
|
| 175 | + $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + return $user; |
|
| 179 | + } |
|
| 180 | 180 | } |
@@ -19,18 +19,18 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | class SmartobjectPermissionHandler extends \XoopsObjectHandler |
| 21 | 21 | { |
| 22 | - public $handler; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * SmartobjectPermissionHandler constructor. |
|
| 26 | - * @param \XoopsDatabase $handler |
|
| 27 | - */ |
|
| 28 | - public function __construct($handler) |
|
| 29 | - { |
|
| 30 | - $this->handler = $handler; |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - /* |
|
| 22 | + public $handler; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * SmartobjectPermissionHandler constructor. |
|
| 26 | + * @param \XoopsDatabase $handler |
|
| 27 | + */ |
|
| 28 | + public function __construct($handler) |
|
| 29 | + { |
|
| 30 | + $this->handler = $handler; |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + /* |
|
| 34 | 34 | * Returns permissions for a certain type |
| 35 | 35 | * |
| 36 | 36 | * @param string $type "global", "forum" or "topic" (should perhaps have "post" as well - but I don't know) |
@@ -38,74 +38,74 @@ discard block |
||
| 38 | 38 | * |
| 39 | 39 | * @return array |
| 40 | 40 | */ |
| 41 | - /** |
|
| 42 | - * @param $gperm_name |
|
| 43 | - * @param null $id |
|
| 44 | - * @return array |
|
| 45 | - */ |
|
| 46 | - public function getGrantedGroups($gperm_name, $id = null) |
|
| 47 | - { |
|
| 48 | - static $groups; |
|
| 49 | - |
|
| 50 | - if (!isset($groups[$gperm_name]) || (null !== $id && !isset($groups[$gperm_name][$id]))) { |
|
| 51 | - $smartModule = $this->handler->getModuleInfo(); |
|
| 52 | - //Get group permissions handler |
|
| 53 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 54 | - |
|
| 55 | - //Get groups allowed for an item id |
|
| 56 | - $allowedgroups = $gpermHandler->getGroupIds($gperm_name, $id, $smartModule->getVar('mid')); |
|
| 57 | - $groups[$gperm_name][$id] = $allowedgroups; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - //Return the permission array |
|
| 61 | - return isset($groups[$gperm_name][$id]) ? $groups[$gperm_name][$id] : []; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @param $item_ids_array |
|
| 66 | - * @param bool $gperm_name |
|
| 67 | - * @return array |
|
| 68 | - */ |
|
| 69 | - public function getGrantedGroupsForIds($item_ids_array, $gperm_name = false) |
|
| 70 | - { |
|
| 71 | - static $groups; |
|
| 72 | - |
|
| 73 | - if ($gperm_name) { |
|
| 74 | - if (isset($groups[$gperm_name])) { |
|
| 75 | - return $groups[$gperm_name]; |
|
| 76 | - } |
|
| 77 | - } else { |
|
| 78 | - // if !$gperm_name then we will fetch all permissions in the module so we don't need them again |
|
| 79 | - return $groups; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - $smartModule = $this->handler->getModuleInfo(); |
|
| 83 | - |
|
| 84 | - $criteria = new \CriteriaCompo(); |
|
| 85 | - $criteria->add(new \Criteria('gperm_modid', $smartModule->getVar('mid'))); |
|
| 86 | - |
|
| 87 | - if ($gperm_name) { |
|
| 88 | - $criteria->add(new \Criteria('gperm_name', $gperm_name)); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - //Get group permissions handler |
|
| 92 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 93 | - |
|
| 94 | - $permissionsObj = $gpermHandler->getObjects($criteria); |
|
| 95 | - |
|
| 96 | - foreach ($permissionsObj as $permissionObj) { |
|
| 97 | - $groups[$permissionObj->getVar('gperm_name')][$permissionObj->getVar('gperm_itemid')][] = $permissionObj->getVar('gperm_groupid'); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - //Return the permission array |
|
| 101 | - if ($gperm_name) { |
|
| 102 | - return isset($groups[$gperm_name]) ? $groups[$gperm_name] : []; |
|
| 103 | - } else { |
|
| 104 | - return isset($groups) ? $groups : []; |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /* |
|
| 41 | + /** |
|
| 42 | + * @param $gperm_name |
|
| 43 | + * @param null $id |
|
| 44 | + * @return array |
|
| 45 | + */ |
|
| 46 | + public function getGrantedGroups($gperm_name, $id = null) |
|
| 47 | + { |
|
| 48 | + static $groups; |
|
| 49 | + |
|
| 50 | + if (!isset($groups[$gperm_name]) || (null !== $id && !isset($groups[$gperm_name][$id]))) { |
|
| 51 | + $smartModule = $this->handler->getModuleInfo(); |
|
| 52 | + //Get group permissions handler |
|
| 53 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 54 | + |
|
| 55 | + //Get groups allowed for an item id |
|
| 56 | + $allowedgroups = $gpermHandler->getGroupIds($gperm_name, $id, $smartModule->getVar('mid')); |
|
| 57 | + $groups[$gperm_name][$id] = $allowedgroups; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + //Return the permission array |
|
| 61 | + return isset($groups[$gperm_name][$id]) ? $groups[$gperm_name][$id] : []; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @param $item_ids_array |
|
| 66 | + * @param bool $gperm_name |
|
| 67 | + * @return array |
|
| 68 | + */ |
|
| 69 | + public function getGrantedGroupsForIds($item_ids_array, $gperm_name = false) |
|
| 70 | + { |
|
| 71 | + static $groups; |
|
| 72 | + |
|
| 73 | + if ($gperm_name) { |
|
| 74 | + if (isset($groups[$gperm_name])) { |
|
| 75 | + return $groups[$gperm_name]; |
|
| 76 | + } |
|
| 77 | + } else { |
|
| 78 | + // if !$gperm_name then we will fetch all permissions in the module so we don't need them again |
|
| 79 | + return $groups; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + $smartModule = $this->handler->getModuleInfo(); |
|
| 83 | + |
|
| 84 | + $criteria = new \CriteriaCompo(); |
|
| 85 | + $criteria->add(new \Criteria('gperm_modid', $smartModule->getVar('mid'))); |
|
| 86 | + |
|
| 87 | + if ($gperm_name) { |
|
| 88 | + $criteria->add(new \Criteria('gperm_name', $gperm_name)); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + //Get group permissions handler |
|
| 92 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 93 | + |
|
| 94 | + $permissionsObj = $gpermHandler->getObjects($criteria); |
|
| 95 | + |
|
| 96 | + foreach ($permissionsObj as $permissionObj) { |
|
| 97 | + $groups[$permissionObj->getVar('gperm_name')][$permissionObj->getVar('gperm_itemid')][] = $permissionObj->getVar('gperm_groupid'); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + //Return the permission array |
|
| 101 | + if ($gperm_name) { |
|
| 102 | + return isset($groups[$gperm_name]) ? $groups[$gperm_name] : []; |
|
| 103 | + } else { |
|
| 104 | + return isset($groups) ? $groups : []; |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /* |
|
| 109 | 109 | * Returns permissions for a certain type |
| 110 | 110 | * |
| 111 | 111 | * @param string $type "global", "forum" or "topic" (should perhaps have "post" as well - but I don't know) |
@@ -113,123 +113,123 @@ discard block |
||
| 113 | 113 | * |
| 114 | 114 | * @return array |
| 115 | 115 | */ |
| 116 | - /** |
|
| 117 | - * @param $gperm_name |
|
| 118 | - * @param null $id |
|
| 119 | - * @return array |
|
| 120 | - */ |
|
| 121 | - public function getGrantedItems($gperm_name, $id = null) |
|
| 122 | - { |
|
| 123 | - global $xoopsUser; |
|
| 124 | - static $permissions; |
|
| 125 | - |
|
| 126 | - if (!isset($permissions[$gperm_name]) || (null !== $id && !isset($permissions[$gperm_name][$id]))) { |
|
| 127 | - $smartModule = $this->handler->getModuleInfo(); |
|
| 128 | - |
|
| 129 | - if (is_object($smartModule)) { |
|
| 130 | - |
|
| 131 | - //Get group permissions handler |
|
| 132 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 133 | - |
|
| 134 | - //Get user's groups |
|
| 135 | - $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : [XOOPS_GROUP_ANONYMOUS]; |
|
| 136 | - |
|
| 137 | - //Get all allowed item ids in this module and for this user's groups |
|
| 138 | - $userpermissions = $gpermHandler->getItemIds($gperm_name, $groups, $smartModule->getVar('mid')); |
|
| 139 | - $permissions[$gperm_name] = $userpermissions; |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - //Return the permission array |
|
| 144 | - return isset($permissions[$gperm_name]) ? $permissions[$gperm_name] : []; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * @param $id |
|
| 149 | - */ |
|
| 150 | - public function storeAllPermissionsForId($id) |
|
| 151 | - { |
|
| 152 | - foreach ($this->handler->getPermissions() as $permission) { |
|
| 153 | - $this->saveItem_Permissions($_POST[$permission['perm_name']], $id, $permission['perm_name']); |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * Saves permissions for the selected item |
|
| 159 | - * |
|
| 160 | - * saveItem_Permissions() |
|
| 161 | - * |
|
| 162 | - * @param array $groups : group with granted permission |
|
| 163 | - * @param int $itemid categoryID on which we are setting permissions for Categories and Forums |
|
| 164 | - * @param string $perm_name : name of the permission |
|
| 165 | - * @return bool : TRUE if the no errors occured |
|
| 166 | - */ |
|
| 167 | - |
|
| 168 | - public function saveItem_Permissions($groups, $itemid, $perm_name) |
|
| 169 | - { |
|
| 170 | - $smartModule = $this->handler->getModuleInfo(); |
|
| 171 | - |
|
| 172 | - $result = true; |
|
| 173 | - $module_id = $smartModule->getVar('mid'); |
|
| 174 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 175 | - |
|
| 176 | - // First, if the permissions are already there, delete them |
|
| 177 | - $gpermHandler->deleteByModule($module_id, $perm_name, $itemid); |
|
| 178 | - //echo "itemid: $itemid - perm: $perm_name - modid: $module_id"; |
|
| 179 | - //exit; |
|
| 180 | - // Save the new permissions |
|
| 181 | - |
|
| 182 | - if (count($groups) > 0) { |
|
| 183 | - foreach ($groups as $group_id) { |
|
| 184 | - $gpermHandler->addRight($perm_name, $itemid, $group_id, $module_id); |
|
| 185 | - } |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - return $result; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * Delete all permission for a specific item |
|
| 193 | - * |
|
| 194 | - * deletePermissions() |
|
| 195 | - * |
|
| 196 | - * @param integer $itemid : id of the item for which to delete the permissions |
|
| 197 | - * @param $gperm_name |
|
| 198 | - * @return bool: TRUE if the no errors occured |
|
| 199 | - */ |
|
| 200 | - public function deletePermissions($itemid, $gperm_name) |
|
| 201 | - { |
|
| 202 | - global $xoopsModule; |
|
| 203 | - |
|
| 204 | - $smartModule = smartsection_getModuleInfo(); |
|
| 205 | - |
|
| 206 | - $result = true; |
|
| 207 | - $module_id = $smartModule->getVar('mid'); |
|
| 208 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 209 | - |
|
| 210 | - $gpermHandler->deleteByModule($module_id, $gperm_name, $itemid); |
|
| 211 | - |
|
| 212 | - return $result; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * Checks if the user has access to a specific permission on a given object |
|
| 217 | - * |
|
| 218 | - * @param string $gperm_name name of the permission to test |
|
| 219 | - * @param int $gperm_itemid id of the object to check |
|
| 220 | - * @return boolean: TRUE if user has access, FALSE if not |
|
| 221 | - **/ |
|
| 222 | - public function accessGranted($gperm_name, $gperm_itemid) |
|
| 223 | - { |
|
| 224 | - global $xoopsUser; |
|
| 225 | - |
|
| 226 | - $gperm_groupid = is_object($xoopsUser) ? $xoopsUser->getGroups() : [XOOPS_GROUP_ANONYMOUS]; |
|
| 227 | - $smartModule = $this->handler->getModuleInfo(); |
|
| 228 | - $gperm_modid = $smartModule->getVar('mid'); |
|
| 229 | - |
|
| 230 | - //Get group permissions handler |
|
| 231 | - $gpermHandler = xoops_getHandler('groupperm'); |
|
| 232 | - |
|
| 233 | - return $gpermHandler->checkRight($gperm_name, $gperm_itemid, $gperm_groupid, $gperm_modid); |
|
| 234 | - } |
|
| 116 | + /** |
|
| 117 | + * @param $gperm_name |
|
| 118 | + * @param null $id |
|
| 119 | + * @return array |
|
| 120 | + */ |
|
| 121 | + public function getGrantedItems($gperm_name, $id = null) |
|
| 122 | + { |
|
| 123 | + global $xoopsUser; |
|
| 124 | + static $permissions; |
|
| 125 | + |
|
| 126 | + if (!isset($permissions[$gperm_name]) || (null !== $id && !isset($permissions[$gperm_name][$id]))) { |
|
| 127 | + $smartModule = $this->handler->getModuleInfo(); |
|
| 128 | + |
|
| 129 | + if (is_object($smartModule)) { |
|
| 130 | + |
|
| 131 | + //Get group permissions handler |
|
| 132 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 133 | + |
|
| 134 | + //Get user's groups |
|
| 135 | + $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : [XOOPS_GROUP_ANONYMOUS]; |
|
| 136 | + |
|
| 137 | + //Get all allowed item ids in this module and for this user's groups |
|
| 138 | + $userpermissions = $gpermHandler->getItemIds($gperm_name, $groups, $smartModule->getVar('mid')); |
|
| 139 | + $permissions[$gperm_name] = $userpermissions; |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + //Return the permission array |
|
| 144 | + return isset($permissions[$gperm_name]) ? $permissions[$gperm_name] : []; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * @param $id |
|
| 149 | + */ |
|
| 150 | + public function storeAllPermissionsForId($id) |
|
| 151 | + { |
|
| 152 | + foreach ($this->handler->getPermissions() as $permission) { |
|
| 153 | + $this->saveItem_Permissions($_POST[$permission['perm_name']], $id, $permission['perm_name']); |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * Saves permissions for the selected item |
|
| 159 | + * |
|
| 160 | + * saveItem_Permissions() |
|
| 161 | + * |
|
| 162 | + * @param array $groups : group with granted permission |
|
| 163 | + * @param int $itemid categoryID on which we are setting permissions for Categories and Forums |
|
| 164 | + * @param string $perm_name : name of the permission |
|
| 165 | + * @return bool : TRUE if the no errors occured |
|
| 166 | + */ |
|
| 167 | + |
|
| 168 | + public function saveItem_Permissions($groups, $itemid, $perm_name) |
|
| 169 | + { |
|
| 170 | + $smartModule = $this->handler->getModuleInfo(); |
|
| 171 | + |
|
| 172 | + $result = true; |
|
| 173 | + $module_id = $smartModule->getVar('mid'); |
|
| 174 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 175 | + |
|
| 176 | + // First, if the permissions are already there, delete them |
|
| 177 | + $gpermHandler->deleteByModule($module_id, $perm_name, $itemid); |
|
| 178 | + //echo "itemid: $itemid - perm: $perm_name - modid: $module_id"; |
|
| 179 | + //exit; |
|
| 180 | + // Save the new permissions |
|
| 181 | + |
|
| 182 | + if (count($groups) > 0) { |
|
| 183 | + foreach ($groups as $group_id) { |
|
| 184 | + $gpermHandler->addRight($perm_name, $itemid, $group_id, $module_id); |
|
| 185 | + } |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + return $result; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * Delete all permission for a specific item |
|
| 193 | + * |
|
| 194 | + * deletePermissions() |
|
| 195 | + * |
|
| 196 | + * @param integer $itemid : id of the item for which to delete the permissions |
|
| 197 | + * @param $gperm_name |
|
| 198 | + * @return bool: TRUE if the no errors occured |
|
| 199 | + */ |
|
| 200 | + public function deletePermissions($itemid, $gperm_name) |
|
| 201 | + { |
|
| 202 | + global $xoopsModule; |
|
| 203 | + |
|
| 204 | + $smartModule = smartsection_getModuleInfo(); |
|
| 205 | + |
|
| 206 | + $result = true; |
|
| 207 | + $module_id = $smartModule->getVar('mid'); |
|
| 208 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 209 | + |
|
| 210 | + $gpermHandler->deleteByModule($module_id, $gperm_name, $itemid); |
|
| 211 | + |
|
| 212 | + return $result; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * Checks if the user has access to a specific permission on a given object |
|
| 217 | + * |
|
| 218 | + * @param string $gperm_name name of the permission to test |
|
| 219 | + * @param int $gperm_itemid id of the object to check |
|
| 220 | + * @return boolean: TRUE if user has access, FALSE if not |
|
| 221 | + **/ |
|
| 222 | + public function accessGranted($gperm_name, $gperm_itemid) |
|
| 223 | + { |
|
| 224 | + global $xoopsUser; |
|
| 225 | + |
|
| 226 | + $gperm_groupid = is_object($xoopsUser) ? $xoopsUser->getGroups() : [XOOPS_GROUP_ANONYMOUS]; |
|
| 227 | + $smartModule = $this->handler->getModuleInfo(); |
|
| 228 | + $gperm_modid = $smartModule->getVar('mid'); |
|
| 229 | + |
|
| 230 | + //Get group permissions handler |
|
| 231 | + $gpermHandler = xoops_getHandler('groupperm'); |
|
| 232 | + |
|
| 233 | + return $gpermHandler->checkRight($gperm_name, $gperm_itemid, $gperm_groupid, $gperm_modid); |
|
| 234 | + } |
|
| 235 | 235 | } |
@@ -29,12 +29,12 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | class SmartobjectFile extends Smartobject\BaseSmartObjectBasedUrl |
| 31 | 31 | { |
| 32 | - /** |
|
| 33 | - * SmartobjectFile constructor. |
|
| 34 | - */ |
|
| 35 | - public function __construct() |
|
| 36 | - { |
|
| 37 | - parent::__construct(); |
|
| 38 | - $this->quickInitVar('fileid', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_DIRNAME); |
|
| 39 | - } |
|
| 32 | + /** |
|
| 33 | + * SmartobjectFile constructor. |
|
| 34 | + */ |
|
| 35 | + public function __construct() |
|
| 36 | + { |
|
| 37 | + parent::__construct(); |
|
| 38 | + $this->quickInitVar('fileid', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_DIRNAME); |
|
| 39 | + } |
|
| 40 | 40 | } |
@@ -25,7 +25,6 @@ discard block |
||
| 25 | 25 | * Contains the classes for updating database tables |
| 26 | 26 | * |
| 27 | 27 | * @license GNU |
| 28 | - |
|
| 29 | 28 | */ |
| 30 | 29 | /** |
| 31 | 30 | * SmartDbTable class |
@@ -38,7 +37,7 @@ discard block |
||
| 38 | 37 | */ |
| 39 | 38 | // defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
| 40 | 39 | if (!defined('SMARTOBJECT_ROOT_PATH')) { |
| 41 | - require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'; |
|
| 40 | + require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'; |
|
| 42 | 41 | } |
| 43 | 42 | /** |
| 44 | 43 | * Include the language constants for the SmartObjectDBUpdater |
@@ -46,7 +45,7 @@ discard block |
||
| 46 | 45 | global $xoopsConfig; |
| 47 | 46 | $common_file = SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/smartdbupdater.php'; |
| 48 | 47 | if (!file_exists($common_file)) { |
| 49 | - $common_file = SMARTOBJECT_ROOT_PATH . 'language/english/smartdbupdater.php'; |
|
| 48 | + $common_file = SMARTOBJECT_ROOT_PATH . 'language/english/smartdbupdater.php'; |
|
| 50 | 49 | } |
| 51 | 50 | include $common_file; |
| 52 | 51 | |
@@ -55,501 +54,501 @@ discard block |
||
| 55 | 54 | */ |
| 56 | 55 | class SmartDbTable |
| 57 | 56 | { |
| 58 | - /** |
|
| 59 | - * @var string $_name name of the table |
|
| 60 | - */ |
|
| 61 | - public $_name; |
|
| 62 | - /** |
|
| 63 | - * @var string $_structure structure of the table |
|
| 64 | - */ |
|
| 65 | - public $_structure; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @var array $_data containing valued of each records to be added |
|
| 69 | - */ |
|
| 70 | - public $_data; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @var array $_alteredFields containing fields to be altered |
|
| 74 | - */ |
|
| 75 | - public $_alteredFields; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @var array $_newFields containing new fields to be added |
|
| 79 | - */ |
|
| 80 | - public $_newFields; |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * @var array $_droppedFields containing fields to be dropped |
|
| 84 | - */ |
|
| 85 | - public $_droppedFields; |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @var array $_flagForDrop flag table to drop it |
|
| 89 | - */ |
|
| 90 | - public $_flagForDrop = false; |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @var array $_updatedFields containing fields which values will be updated |
|
| 94 | - */ |
|
| 95 | - public $_updatedFields; |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * @var array $_updatedFields containing fields which values will be updated |
|
| 99 | - */ //felix |
|
| 100 | - public $_updatedWhere; |
|
| 101 | - |
|
| 102 | - public $_existingFieldsArray = false; |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Constructor |
|
| 106 | - * |
|
| 107 | - * @param string $name name of the table |
|
| 108 | - * |
|
| 109 | - */ |
|
| 110 | - public function __construct($name) |
|
| 111 | - { |
|
| 112 | - $this->_name = $name; |
|
| 113 | - $this->_data = []; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Return the table name, prefixed with site table prefix |
|
| 118 | - * |
|
| 119 | - * @return string table name |
|
| 120 | - * |
|
| 121 | - */ |
|
| 122 | - public function name() |
|
| 123 | - { |
|
| 124 | - global $xoopsDB; |
|
| 125 | - |
|
| 126 | - return $xoopsDB->prefix($this->_name); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Checks if the table already exists in the database |
|
| 131 | - * |
|
| 132 | - * @return bool TRUE if it exists, FALSE if not |
|
| 133 | - * |
|
| 134 | - */ |
|
| 135 | - public function exists() |
|
| 136 | - { |
|
| 137 | - return smart_TableExists($this->_name); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @return mixed |
|
| 142 | - */ |
|
| 143 | - public function getExistingFieldsArray() |
|
| 144 | - { |
|
| 145 | - global $xoopsDB; |
|
| 146 | - $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $this->name()); |
|
| 147 | - while (false !== ($existing_field = $xoopsDB->fetchArray($result))) { |
|
| 148 | - $fields[$existing_field['Field']] = $existing_field['Type']; |
|
| 149 | - if ('YES' !== $existing_field['Null']) { |
|
| 150 | - $fields[$existing_field['Field']] .= ' NOT NULL'; |
|
| 151 | - } |
|
| 152 | - if ($existing_field['Extra']) { |
|
| 153 | - $fields[$existing_field['Field']] .= ' ' . $existing_field['Extra']; |
|
| 154 | - } |
|
| 155 | - if (!(null === $existing_field['Default']) |
|
| 156 | - && ($existing_field['Default'] |
|
| 157 | - || '' === $existing_field['Default'] |
|
| 158 | - || 0 == $existing_field['Default'])) { |
|
| 159 | - $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'"; |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - return $fields; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * @param $field |
|
| 168 | - * @return bool |
|
| 169 | - */ |
|
| 170 | - public function fieldExists($field) |
|
| 171 | - { |
|
| 172 | - $existingFields = $this->getExistingFieldsArray(); |
|
| 173 | - |
|
| 174 | - return isset($existingFields[$field]); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Set the table structure |
|
| 179 | - * |
|
| 180 | - * Example: |
|
| 181 | - * |
|
| 182 | - * $table->setStructure("`transactionid` int(11) NOT NULL auto_increment, |
|
| 183 | - * `date` int(11) NOT NULL default '0', |
|
| 184 | - * `status` int(1) NOT NULL default '-1', |
|
| 185 | - * `itemid` int(11) NOT NULL default '0', |
|
| 186 | - * `uid` int(11) NOT NULL default '0', |
|
| 187 | - * `price` float NOT NULL default '0', |
|
| 188 | - * `currency` varchar(100) NOT NULL default '', |
|
| 189 | - * PRIMARY KEY (`transactionid`)"); |
|
| 190 | - * |
|
| 191 | - * @param string $structure table structure |
|
| 192 | - * |
|
| 193 | - */ |
|
| 194 | - public function setStructure($structure) |
|
| 195 | - { |
|
| 196 | - $this->_structure = $structure; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * Return the table structure |
|
| 201 | - * |
|
| 202 | - * @return string table structure |
|
| 203 | - * |
|
| 204 | - */ |
|
| 205 | - public function getStructure() |
|
| 206 | - { |
|
| 207 | - return sprintf($this->_structure, $this->name()); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * Add values of a record to be added |
|
| 212 | - * |
|
| 213 | - * @param string $data values of a record |
|
| 214 | - * |
|
| 215 | - */ |
|
| 216 | - public function setData($data) |
|
| 217 | - { |
|
| 218 | - $this->_data[] = $data; |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * Get the data array |
|
| 223 | - * |
|
| 224 | - * @return array containing the records values to be added |
|
| 225 | - * |
|
| 226 | - */ |
|
| 227 | - public function getData() |
|
| 228 | - { |
|
| 229 | - return $this->_data; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * Use to insert data in a table |
|
| 234 | - * |
|
| 235 | - * @return bool true if success, false if an error occured |
|
| 236 | - * |
|
| 237 | - */ |
|
| 238 | - public function addData() |
|
| 239 | - { |
|
| 240 | - global $xoopsDB; |
|
| 241 | - foreach ($this->getData() as $data) { |
|
| 242 | - $query = sprintf('INSERT INTO %s VALUES (%s)', $this->name(), $data); |
|
| 243 | - $ret = $xoopsDB->query($query); |
|
| 244 | - if (!$ret) { |
|
| 245 | - echo ' ' . sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()) . '<br>'; |
|
| 246 | - } else { |
|
| 247 | - echo ' ' . sprintf(_SDU_MSG_ADD_DATA, $this->name()) . '<br>'; |
|
| 248 | - } |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - return $ret; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * Add a field to be added |
|
| 256 | - * |
|
| 257 | - * @param string $name name of the field |
|
| 258 | - * @param string $properties properties of the field |
|
| 259 | - * @param bool $newname |
|
| 260 | - * @param bool $showerror |
|
| 261 | - */ |
|
| 262 | - public function addAlteredField($name, $properties, $newname = false, $showerror = true) |
|
| 263 | - { |
|
| 264 | - $field['name'] = $name; |
|
| 265 | - $field['properties'] = $properties; |
|
| 266 | - $field['showerror'] = $showerror; |
|
| 267 | - $field['newname'] = $newname; |
|
| 268 | - $this->_alteredFields[] = $field; |
|
| 269 | - } |
|
| 270 | - /** |
|
| 271 | - * Invert values 0 to 1 and 1 to 0 |
|
| 272 | - * |
|
| 273 | - * @param string $name name of the field |
|
| 274 | - * @param $newValue |
|
| 275 | - * @param $oldValue |
|
| 276 | - * @internal param string $old old propertie |
|
| 277 | - * @internal param string $new new propertie |
|
| 278 | - */ //felix |
|
| 279 | - public function addUpdatedWhere($name, $newValue, $oldValue) |
|
| 280 | - { |
|
| 281 | - $field['name'] = $name; |
|
| 282 | - $field['value'] = $newValue; |
|
| 283 | - $field['where'] = $oldValue; |
|
| 284 | - $this->_updatedWhere[] = $field; |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * Add new field of a record to be added |
|
| 289 | - * |
|
| 290 | - * @param string $name name of the field |
|
| 291 | - * @param string $properties properties of the field |
|
| 292 | - * |
|
| 293 | - */ |
|
| 294 | - public function addNewField($name, $properties) |
|
| 295 | - { |
|
| 296 | - $field['name'] = $name; |
|
| 297 | - $field['properties'] = $properties; |
|
| 298 | - $this->_newFields[] = $field; |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * Get fields that need to be altered |
|
| 303 | - * |
|
| 304 | - * @return array fields that need to be altered |
|
| 305 | - * |
|
| 306 | - */ |
|
| 307 | - public function getAlteredFields() |
|
| 308 | - { |
|
| 309 | - return $this->_alteredFields; |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - /** |
|
| 313 | - * Add field for which the value will be updated |
|
| 314 | - * |
|
| 315 | - * @param string $name name of the field |
|
| 316 | - * @param string $value value to be set |
|
| 317 | - * |
|
| 318 | - */ |
|
| 319 | - public function addUpdatedField($name, $value) |
|
| 320 | - { |
|
| 321 | - $field['name'] = $name; |
|
| 322 | - $field['value'] = $value; |
|
| 323 | - $this->_updatedFields[] = $field; |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * Get new fields to be added |
|
| 328 | - * |
|
| 329 | - * @return array fields to be added |
|
| 330 | - * |
|
| 331 | - */ |
|
| 332 | - public function getNewFields() |
|
| 333 | - { |
|
| 334 | - return $this->_newFields; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * Get fields which values need to be updated |
|
| 339 | - * |
|
| 340 | - * @return array fields which values need to be updated |
|
| 341 | - * |
|
| 342 | - */ |
|
| 343 | - public function getUpdatedFields() |
|
| 344 | - { |
|
| 345 | - return $this->_updatedFields; |
|
| 346 | - } |
|
| 347 | - /** |
|
| 348 | - * Get fields which values need to be updated |
|
| 349 | - * |
|
| 350 | - * @return array fields which values need to be updated |
|
| 351 | - * |
|
| 352 | - */ //felix |
|
| 353 | - public function getUpdatedWhere() |
|
| 354 | - { |
|
| 355 | - return $this->_updatedWhere; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * Add values of a record to be added |
|
| 360 | - * |
|
| 361 | - * @param string $name name of the field |
|
| 362 | - * |
|
| 363 | - */ |
|
| 364 | - public function addDroppedField($name) |
|
| 365 | - { |
|
| 366 | - $this->_droppedFields[] = $name; |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * Get fields that need to be dropped |
|
| 371 | - * |
|
| 372 | - * @return array fields that need to be dropped |
|
| 373 | - * |
|
| 374 | - */ |
|
| 375 | - public function getDroppedFields() |
|
| 376 | - { |
|
| 377 | - return $this->_droppedFields; |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * Set the flag to drop the table |
|
| 382 | - * |
|
| 383 | - */ |
|
| 384 | - public function setFlagForDrop() |
|
| 385 | - { |
|
| 386 | - $this->_flagForDrop = true; |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - /** |
|
| 390 | - * Use to create a table |
|
| 391 | - * |
|
| 392 | - * @return bool true if success, false if an error occured |
|
| 393 | - * |
|
| 394 | - */ |
|
| 395 | - public function createTable() |
|
| 396 | - { |
|
| 397 | - global $xoopsDB; |
|
| 398 | - $query = $this->getStructure(); |
|
| 399 | - $query = 'CREATE TABLE `' . $this->name() . '` (' . $query . ") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'"; |
|
| 400 | - //xoops_debug($query); |
|
| 401 | - $ret = $xoopsDB->query($query); |
|
| 402 | - if (!$ret) { |
|
| 403 | - echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 404 | - } else { |
|
| 405 | - echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE, $this->name()) . '<br>'; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - return $ret; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - /** |
|
| 412 | - * Use to drop a table |
|
| 413 | - * |
|
| 414 | - * @return bool true if success, false if an error occured |
|
| 415 | - * |
|
| 416 | - */ |
|
| 417 | - public function dropTable() |
|
| 418 | - { |
|
| 419 | - global $xoopsDB; |
|
| 420 | - $query = sprintf('DROP TABLE %s', $this->name()); |
|
| 421 | - $ret = $xoopsDB->query($query); |
|
| 422 | - if (!$ret) { |
|
| 423 | - echo ' ' . sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 424 | - |
|
| 425 | - return false; |
|
| 426 | - } else { |
|
| 427 | - echo ' ' . sprintf(_SDU_MSG_DROP_TABLE, $this->name()) . '<br>'; |
|
| 428 | - |
|
| 429 | - return true; |
|
| 430 | - } |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - /** |
|
| 434 | - * Use to alter a table |
|
| 435 | - * |
|
| 436 | - * @return bool true if success, false if an error occured |
|
| 437 | - * |
|
| 438 | - */ |
|
| 439 | - public function alterTable() |
|
| 440 | - { |
|
| 441 | - global $xoopsDB; |
|
| 442 | - $ret = true; |
|
| 443 | - |
|
| 444 | - foreach ($this->getAlteredFields() as $alteredField) { |
|
| 445 | - if (!$alteredField['newname']) { |
|
| 446 | - $alteredField['newname'] = $alteredField['name']; |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - $query = sprintf('ALTER TABLE `%s` CHANGE `%s` `%s` %s', $this->name(), $alteredField['name'], $alteredField['newname'], $alteredField['properties']); |
|
| 450 | - $ret = $ret && $xoopsDB->query($query); |
|
| 451 | - if ($alteredField['showerror']) { |
|
| 452 | - if (!$ret) { |
|
| 453 | - echo ' ' . sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 454 | - } else { |
|
| 455 | - echo ' ' . sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()) . '<br>'; |
|
| 456 | - } |
|
| 457 | - } |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - return $ret; |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * Use to add new fileds in the table |
|
| 465 | - * |
|
| 466 | - * @return bool true if success, false if an error occured |
|
| 467 | - * |
|
| 468 | - */ |
|
| 469 | - public function addNewFields() |
|
| 470 | - { |
|
| 471 | - global $xoopsDB; |
|
| 472 | - $ret = true; |
|
| 473 | - foreach ($this->getNewFields() as $newField) { |
|
| 474 | - $query = sprintf('ALTER TABLE `%s` ADD `%s` %s', $this->name(), $newField['name'], $newField['properties']); |
|
| 475 | - //echo $query; |
|
| 476 | - $ret = $ret && $xoopsDB->query($query); |
|
| 477 | - if (!$ret) { |
|
| 478 | - echo ' ' . sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()) . '<br>'; |
|
| 479 | - } else { |
|
| 480 | - echo ' ' . sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()) . '<br>'; |
|
| 481 | - } |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - return $ret; |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * Use to update fields values |
|
| 489 | - * |
|
| 490 | - * @return bool true if success, false if an error occured |
|
| 491 | - * |
|
| 492 | - */ |
|
| 493 | - public function updateFieldsValues() |
|
| 494 | - { |
|
| 495 | - global $xoopsDB; |
|
| 496 | - $ret = true; |
|
| 497 | - foreach ($this->getUpdatedFields() as $updatedField) { |
|
| 498 | - $query = sprintf('UPDATE %s SET %s = %s', $this->name(), $updatedField['name'], $updatedField['value']); |
|
| 499 | - $ret = $ret && $xoopsDB->query($query); |
|
| 500 | - if (!$ret) { |
|
| 501 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 502 | - } else { |
|
| 503 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>'; |
|
| 504 | - } |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - return $ret; |
|
| 508 | - } |
|
| 509 | - /** |
|
| 510 | - * Use to update fields values |
|
| 511 | - * |
|
| 512 | - * @return bool true if success, false if an error occured |
|
| 513 | - * |
|
| 514 | - */ //felix |
|
| 515 | - public function updateWhereValues() |
|
| 516 | - { |
|
| 517 | - global $xoopsDB; |
|
| 518 | - $ret = true; |
|
| 519 | - foreach ($this->getUpdatedWhere() as $updatedWhere) { |
|
| 520 | - $query = sprintf('UPDATE %s SET %s = %s WHERE %s %s', $this->name(), $updatedWhere['name'], $updatedWhere['value'], $updatedWhere['name'], $updatedWhere['where']); |
|
| 521 | - //echo $query."<br>"; |
|
| 522 | - $ret = $ret && $xoopsDB->query($query); |
|
| 523 | - if (!$ret) { |
|
| 524 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 525 | - } else { |
|
| 526 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>'; |
|
| 527 | - } |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - return $ret; |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - /** |
|
| 534 | - * Use to drop fields |
|
| 535 | - * |
|
| 536 | - * @return bool true if success, false if an error occured |
|
| 537 | - * |
|
| 538 | - */ |
|
| 539 | - public function dropFields() |
|
| 540 | - { |
|
| 541 | - global $xoopsDB; |
|
| 542 | - $ret = true; |
|
| 543 | - foreach ($this->getDroppedFields() as $droppedField) { |
|
| 544 | - $query = sprintf('ALTER TABLE %s DROP %s', $this->name(), $droppedField); |
|
| 545 | - $ret = $ret && $xoopsDB->query($query); |
|
| 546 | - if (!$ret) { |
|
| 547 | - echo ' ' . sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 548 | - } else { |
|
| 549 | - echo ' ' . sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()) . '<br>'; |
|
| 550 | - } |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - return $ret; |
|
| 554 | - } |
|
| 57 | + /** |
|
| 58 | + * @var string $_name name of the table |
|
| 59 | + */ |
|
| 60 | + public $_name; |
|
| 61 | + /** |
|
| 62 | + * @var string $_structure structure of the table |
|
| 63 | + */ |
|
| 64 | + public $_structure; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @var array $_data containing valued of each records to be added |
|
| 68 | + */ |
|
| 69 | + public $_data; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @var array $_alteredFields containing fields to be altered |
|
| 73 | + */ |
|
| 74 | + public $_alteredFields; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @var array $_newFields containing new fields to be added |
|
| 78 | + */ |
|
| 79 | + public $_newFields; |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @var array $_droppedFields containing fields to be dropped |
|
| 83 | + */ |
|
| 84 | + public $_droppedFields; |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @var array $_flagForDrop flag table to drop it |
|
| 88 | + */ |
|
| 89 | + public $_flagForDrop = false; |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @var array $_updatedFields containing fields which values will be updated |
|
| 93 | + */ |
|
| 94 | + public $_updatedFields; |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @var array $_updatedFields containing fields which values will be updated |
|
| 98 | + */ //felix |
|
| 99 | + public $_updatedWhere; |
|
| 100 | + |
|
| 101 | + public $_existingFieldsArray = false; |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Constructor |
|
| 105 | + * |
|
| 106 | + * @param string $name name of the table |
|
| 107 | + * |
|
| 108 | + */ |
|
| 109 | + public function __construct($name) |
|
| 110 | + { |
|
| 111 | + $this->_name = $name; |
|
| 112 | + $this->_data = []; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Return the table name, prefixed with site table prefix |
|
| 117 | + * |
|
| 118 | + * @return string table name |
|
| 119 | + * |
|
| 120 | + */ |
|
| 121 | + public function name() |
|
| 122 | + { |
|
| 123 | + global $xoopsDB; |
|
| 124 | + |
|
| 125 | + return $xoopsDB->prefix($this->_name); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Checks if the table already exists in the database |
|
| 130 | + * |
|
| 131 | + * @return bool TRUE if it exists, FALSE if not |
|
| 132 | + * |
|
| 133 | + */ |
|
| 134 | + public function exists() |
|
| 135 | + { |
|
| 136 | + return smart_TableExists($this->_name); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @return mixed |
|
| 141 | + */ |
|
| 142 | + public function getExistingFieldsArray() |
|
| 143 | + { |
|
| 144 | + global $xoopsDB; |
|
| 145 | + $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $this->name()); |
|
| 146 | + while (false !== ($existing_field = $xoopsDB->fetchArray($result))) { |
|
| 147 | + $fields[$existing_field['Field']] = $existing_field['Type']; |
|
| 148 | + if ('YES' !== $existing_field['Null']) { |
|
| 149 | + $fields[$existing_field['Field']] .= ' NOT NULL'; |
|
| 150 | + } |
|
| 151 | + if ($existing_field['Extra']) { |
|
| 152 | + $fields[$existing_field['Field']] .= ' ' . $existing_field['Extra']; |
|
| 153 | + } |
|
| 154 | + if (!(null === $existing_field['Default']) |
|
| 155 | + && ($existing_field['Default'] |
|
| 156 | + || '' === $existing_field['Default'] |
|
| 157 | + || 0 == $existing_field['Default'])) { |
|
| 158 | + $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'"; |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + return $fields; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * @param $field |
|
| 167 | + * @return bool |
|
| 168 | + */ |
|
| 169 | + public function fieldExists($field) |
|
| 170 | + { |
|
| 171 | + $existingFields = $this->getExistingFieldsArray(); |
|
| 172 | + |
|
| 173 | + return isset($existingFields[$field]); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * Set the table structure |
|
| 178 | + * |
|
| 179 | + * Example: |
|
| 180 | + * |
|
| 181 | + * $table->setStructure("`transactionid` int(11) NOT NULL auto_increment, |
|
| 182 | + * `date` int(11) NOT NULL default '0', |
|
| 183 | + * `status` int(1) NOT NULL default '-1', |
|
| 184 | + * `itemid` int(11) NOT NULL default '0', |
|
| 185 | + * `uid` int(11) NOT NULL default '0', |
|
| 186 | + * `price` float NOT NULL default '0', |
|
| 187 | + * `currency` varchar(100) NOT NULL default '', |
|
| 188 | + * PRIMARY KEY (`transactionid`)"); |
|
| 189 | + * |
|
| 190 | + * @param string $structure table structure |
|
| 191 | + * |
|
| 192 | + */ |
|
| 193 | + public function setStructure($structure) |
|
| 194 | + { |
|
| 195 | + $this->_structure = $structure; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * Return the table structure |
|
| 200 | + * |
|
| 201 | + * @return string table structure |
|
| 202 | + * |
|
| 203 | + */ |
|
| 204 | + public function getStructure() |
|
| 205 | + { |
|
| 206 | + return sprintf($this->_structure, $this->name()); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * Add values of a record to be added |
|
| 211 | + * |
|
| 212 | + * @param string $data values of a record |
|
| 213 | + * |
|
| 214 | + */ |
|
| 215 | + public function setData($data) |
|
| 216 | + { |
|
| 217 | + $this->_data[] = $data; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * Get the data array |
|
| 222 | + * |
|
| 223 | + * @return array containing the records values to be added |
|
| 224 | + * |
|
| 225 | + */ |
|
| 226 | + public function getData() |
|
| 227 | + { |
|
| 228 | + return $this->_data; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * Use to insert data in a table |
|
| 233 | + * |
|
| 234 | + * @return bool true if success, false if an error occured |
|
| 235 | + * |
|
| 236 | + */ |
|
| 237 | + public function addData() |
|
| 238 | + { |
|
| 239 | + global $xoopsDB; |
|
| 240 | + foreach ($this->getData() as $data) { |
|
| 241 | + $query = sprintf('INSERT INTO %s VALUES (%s)', $this->name(), $data); |
|
| 242 | + $ret = $xoopsDB->query($query); |
|
| 243 | + if (!$ret) { |
|
| 244 | + echo ' ' . sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()) . '<br>'; |
|
| 245 | + } else { |
|
| 246 | + echo ' ' . sprintf(_SDU_MSG_ADD_DATA, $this->name()) . '<br>'; |
|
| 247 | + } |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + return $ret; |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + /** |
|
| 254 | + * Add a field to be added |
|
| 255 | + * |
|
| 256 | + * @param string $name name of the field |
|
| 257 | + * @param string $properties properties of the field |
|
| 258 | + * @param bool $newname |
|
| 259 | + * @param bool $showerror |
|
| 260 | + */ |
|
| 261 | + public function addAlteredField($name, $properties, $newname = false, $showerror = true) |
|
| 262 | + { |
|
| 263 | + $field['name'] = $name; |
|
| 264 | + $field['properties'] = $properties; |
|
| 265 | + $field['showerror'] = $showerror; |
|
| 266 | + $field['newname'] = $newname; |
|
| 267 | + $this->_alteredFields[] = $field; |
|
| 268 | + } |
|
| 269 | + /** |
|
| 270 | + * Invert values 0 to 1 and 1 to 0 |
|
| 271 | + * |
|
| 272 | + * @param string $name name of the field |
|
| 273 | + * @param $newValue |
|
| 274 | + * @param $oldValue |
|
| 275 | + * @internal param string $old old propertie |
|
| 276 | + * @internal param string $new new propertie |
|
| 277 | + */ //felix |
|
| 278 | + public function addUpdatedWhere($name, $newValue, $oldValue) |
|
| 279 | + { |
|
| 280 | + $field['name'] = $name; |
|
| 281 | + $field['value'] = $newValue; |
|
| 282 | + $field['where'] = $oldValue; |
|
| 283 | + $this->_updatedWhere[] = $field; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * Add new field of a record to be added |
|
| 288 | + * |
|
| 289 | + * @param string $name name of the field |
|
| 290 | + * @param string $properties properties of the field |
|
| 291 | + * |
|
| 292 | + */ |
|
| 293 | + public function addNewField($name, $properties) |
|
| 294 | + { |
|
| 295 | + $field['name'] = $name; |
|
| 296 | + $field['properties'] = $properties; |
|
| 297 | + $this->_newFields[] = $field; |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * Get fields that need to be altered |
|
| 302 | + * |
|
| 303 | + * @return array fields that need to be altered |
|
| 304 | + * |
|
| 305 | + */ |
|
| 306 | + public function getAlteredFields() |
|
| 307 | + { |
|
| 308 | + return $this->_alteredFields; |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * Add field for which the value will be updated |
|
| 313 | + * |
|
| 314 | + * @param string $name name of the field |
|
| 315 | + * @param string $value value to be set |
|
| 316 | + * |
|
| 317 | + */ |
|
| 318 | + public function addUpdatedField($name, $value) |
|
| 319 | + { |
|
| 320 | + $field['name'] = $name; |
|
| 321 | + $field['value'] = $value; |
|
| 322 | + $this->_updatedFields[] = $field; |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + /** |
|
| 326 | + * Get new fields to be added |
|
| 327 | + * |
|
| 328 | + * @return array fields to be added |
|
| 329 | + * |
|
| 330 | + */ |
|
| 331 | + public function getNewFields() |
|
| 332 | + { |
|
| 333 | + return $this->_newFields; |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * Get fields which values need to be updated |
|
| 338 | + * |
|
| 339 | + * @return array fields which values need to be updated |
|
| 340 | + * |
|
| 341 | + */ |
|
| 342 | + public function getUpdatedFields() |
|
| 343 | + { |
|
| 344 | + return $this->_updatedFields; |
|
| 345 | + } |
|
| 346 | + /** |
|
| 347 | + * Get fields which values need to be updated |
|
| 348 | + * |
|
| 349 | + * @return array fields which values need to be updated |
|
| 350 | + * |
|
| 351 | + */ //felix |
|
| 352 | + public function getUpdatedWhere() |
|
| 353 | + { |
|
| 354 | + return $this->_updatedWhere; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + /** |
|
| 358 | + * Add values of a record to be added |
|
| 359 | + * |
|
| 360 | + * @param string $name name of the field |
|
| 361 | + * |
|
| 362 | + */ |
|
| 363 | + public function addDroppedField($name) |
|
| 364 | + { |
|
| 365 | + $this->_droppedFields[] = $name; |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + /** |
|
| 369 | + * Get fields that need to be dropped |
|
| 370 | + * |
|
| 371 | + * @return array fields that need to be dropped |
|
| 372 | + * |
|
| 373 | + */ |
|
| 374 | + public function getDroppedFields() |
|
| 375 | + { |
|
| 376 | + return $this->_droppedFields; |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + /** |
|
| 380 | + * Set the flag to drop the table |
|
| 381 | + * |
|
| 382 | + */ |
|
| 383 | + public function setFlagForDrop() |
|
| 384 | + { |
|
| 385 | + $this->_flagForDrop = true; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * Use to create a table |
|
| 390 | + * |
|
| 391 | + * @return bool true if success, false if an error occured |
|
| 392 | + * |
|
| 393 | + */ |
|
| 394 | + public function createTable() |
|
| 395 | + { |
|
| 396 | + global $xoopsDB; |
|
| 397 | + $query = $this->getStructure(); |
|
| 398 | + $query = 'CREATE TABLE `' . $this->name() . '` (' . $query . ") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'"; |
|
| 399 | + //xoops_debug($query); |
|
| 400 | + $ret = $xoopsDB->query($query); |
|
| 401 | + if (!$ret) { |
|
| 402 | + echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 403 | + } else { |
|
| 404 | + echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE, $this->name()) . '<br>'; |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + return $ret; |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * Use to drop a table |
|
| 412 | + * |
|
| 413 | + * @return bool true if success, false if an error occured |
|
| 414 | + * |
|
| 415 | + */ |
|
| 416 | + public function dropTable() |
|
| 417 | + { |
|
| 418 | + global $xoopsDB; |
|
| 419 | + $query = sprintf('DROP TABLE %s', $this->name()); |
|
| 420 | + $ret = $xoopsDB->query($query); |
|
| 421 | + if (!$ret) { |
|
| 422 | + echo ' ' . sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 423 | + |
|
| 424 | + return false; |
|
| 425 | + } else { |
|
| 426 | + echo ' ' . sprintf(_SDU_MSG_DROP_TABLE, $this->name()) . '<br>'; |
|
| 427 | + |
|
| 428 | + return true; |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * Use to alter a table |
|
| 434 | + * |
|
| 435 | + * @return bool true if success, false if an error occured |
|
| 436 | + * |
|
| 437 | + */ |
|
| 438 | + public function alterTable() |
|
| 439 | + { |
|
| 440 | + global $xoopsDB; |
|
| 441 | + $ret = true; |
|
| 442 | + |
|
| 443 | + foreach ($this->getAlteredFields() as $alteredField) { |
|
| 444 | + if (!$alteredField['newname']) { |
|
| 445 | + $alteredField['newname'] = $alteredField['name']; |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + $query = sprintf('ALTER TABLE `%s` CHANGE `%s` `%s` %s', $this->name(), $alteredField['name'], $alteredField['newname'], $alteredField['properties']); |
|
| 449 | + $ret = $ret && $xoopsDB->query($query); |
|
| 450 | + if ($alteredField['showerror']) { |
|
| 451 | + if (!$ret) { |
|
| 452 | + echo ' ' . sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 453 | + } else { |
|
| 454 | + echo ' ' . sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()) . '<br>'; |
|
| 455 | + } |
|
| 456 | + } |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + return $ret; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + /** |
|
| 463 | + * Use to add new fileds in the table |
|
| 464 | + * |
|
| 465 | + * @return bool true if success, false if an error occured |
|
| 466 | + * |
|
| 467 | + */ |
|
| 468 | + public function addNewFields() |
|
| 469 | + { |
|
| 470 | + global $xoopsDB; |
|
| 471 | + $ret = true; |
|
| 472 | + foreach ($this->getNewFields() as $newField) { |
|
| 473 | + $query = sprintf('ALTER TABLE `%s` ADD `%s` %s', $this->name(), $newField['name'], $newField['properties']); |
|
| 474 | + //echo $query; |
|
| 475 | + $ret = $ret && $xoopsDB->query($query); |
|
| 476 | + if (!$ret) { |
|
| 477 | + echo ' ' . sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()) . '<br>'; |
|
| 478 | + } else { |
|
| 479 | + echo ' ' . sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()) . '<br>'; |
|
| 480 | + } |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + return $ret; |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + /** |
|
| 487 | + * Use to update fields values |
|
| 488 | + * |
|
| 489 | + * @return bool true if success, false if an error occured |
|
| 490 | + * |
|
| 491 | + */ |
|
| 492 | + public function updateFieldsValues() |
|
| 493 | + { |
|
| 494 | + global $xoopsDB; |
|
| 495 | + $ret = true; |
|
| 496 | + foreach ($this->getUpdatedFields() as $updatedField) { |
|
| 497 | + $query = sprintf('UPDATE %s SET %s = %s', $this->name(), $updatedField['name'], $updatedField['value']); |
|
| 498 | + $ret = $ret && $xoopsDB->query($query); |
|
| 499 | + if (!$ret) { |
|
| 500 | + echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 501 | + } else { |
|
| 502 | + echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>'; |
|
| 503 | + } |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + return $ret; |
|
| 507 | + } |
|
| 508 | + /** |
|
| 509 | + * Use to update fields values |
|
| 510 | + * |
|
| 511 | + * @return bool true if success, false if an error occured |
|
| 512 | + * |
|
| 513 | + */ //felix |
|
| 514 | + public function updateWhereValues() |
|
| 515 | + { |
|
| 516 | + global $xoopsDB; |
|
| 517 | + $ret = true; |
|
| 518 | + foreach ($this->getUpdatedWhere() as $updatedWhere) { |
|
| 519 | + $query = sprintf('UPDATE %s SET %s = %s WHERE %s %s', $this->name(), $updatedWhere['name'], $updatedWhere['value'], $updatedWhere['name'], $updatedWhere['where']); |
|
| 520 | + //echo $query."<br>"; |
|
| 521 | + $ret = $ret && $xoopsDB->query($query); |
|
| 522 | + if (!$ret) { |
|
| 523 | + echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 524 | + } else { |
|
| 525 | + echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>'; |
|
| 526 | + } |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + return $ret; |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + /** |
|
| 533 | + * Use to drop fields |
|
| 534 | + * |
|
| 535 | + * @return bool true if success, false if an error occured |
|
| 536 | + * |
|
| 537 | + */ |
|
| 538 | + public function dropFields() |
|
| 539 | + { |
|
| 540 | + global $xoopsDB; |
|
| 541 | + $ret = true; |
|
| 542 | + foreach ($this->getDroppedFields() as $droppedField) { |
|
| 543 | + $query = sprintf('ALTER TABLE %s DROP %s', $this->name(), $droppedField); |
|
| 544 | + $ret = $ret && $xoopsDB->query($query); |
|
| 545 | + if (!$ret) { |
|
| 546 | + echo ' ' . sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()) . ' (' . $xoopsDB->error() . ')<br>'; |
|
| 547 | + } else { |
|
| 548 | + echo ' ' . sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()) . '<br>'; |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + return $ret; |
|
| 553 | + } |
|
| 555 | 554 | } |
@@ -17,65 +17,65 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class SmartPrinterFriendly |
| 19 | 19 | { |
| 20 | - public $_title; |
|
| 21 | - public $_dsc; |
|
| 22 | - public $_content; |
|
| 23 | - public $_tpl; |
|
| 24 | - public $_pageTitle = false; |
|
| 25 | - public $_width = 680; |
|
| 20 | + public $_title; |
|
| 21 | + public $_dsc; |
|
| 22 | + public $_content; |
|
| 23 | + public $_tpl; |
|
| 24 | + public $_pageTitle = false; |
|
| 25 | + public $_width = 680; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * SmartPrinterFriendly constructor. |
|
| 29 | - * @param $content |
|
| 30 | - * @param bool $title |
|
| 31 | - * @param bool $dsc |
|
| 32 | - */ |
|
| 33 | - public function __construct($content, $title = false, $dsc = false) |
|
| 34 | - { |
|
| 35 | - $this->_title = $title; |
|
| 36 | - $this->_dsc = $dsc; |
|
| 37 | - $this->_content = $content; |
|
| 38 | - } |
|
| 27 | + /** |
|
| 28 | + * SmartPrinterFriendly constructor. |
|
| 29 | + * @param $content |
|
| 30 | + * @param bool $title |
|
| 31 | + * @param bool $dsc |
|
| 32 | + */ |
|
| 33 | + public function __construct($content, $title = false, $dsc = false) |
|
| 34 | + { |
|
| 35 | + $this->_title = $title; |
|
| 36 | + $this->_dsc = $dsc; |
|
| 37 | + $this->_content = $content; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - public function render() |
|
| 41 | - { |
|
| 42 | - /** |
|
| 43 | - * @todo move the output to a template |
|
| 44 | - * @todo make the output XHTML compliant |
|
| 45 | - */ |
|
| 40 | + public function render() |
|
| 41 | + { |
|
| 42 | + /** |
|
| 43 | + * @todo move the output to a template |
|
| 44 | + * @todo make the output XHTML compliant |
|
| 45 | + */ |
|
| 46 | 46 | |
| 47 | - require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 47 | + require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 48 | 48 | |
| 49 | - $this->_tpl = new \XoopsTpl(); |
|
| 49 | + $this->_tpl = new \XoopsTpl(); |
|
| 50 | 50 | |
| 51 | - $this->_tpl->assign('smartobject_print_pageTitle', $this->_pageTitle ?: $this->_title); |
|
| 52 | - $this->_tpl->assign('smartobject_print_title', $this->_title); |
|
| 53 | - $this->_tpl->assign('smartobject_print_dsc', $this->_dsc); |
|
| 54 | - $this->_tpl->assign('smartobject_print_content', $this->_content); |
|
| 55 | - $this->_tpl->assign('smartobject_print_width', $this->_width); |
|
| 51 | + $this->_tpl->assign('smartobject_print_pageTitle', $this->_pageTitle ?: $this->_title); |
|
| 52 | + $this->_tpl->assign('smartobject_print_title', $this->_title); |
|
| 53 | + $this->_tpl->assign('smartobject_print_dsc', $this->_dsc); |
|
| 54 | + $this->_tpl->assign('smartobject_print_content', $this->_content); |
|
| 55 | + $this->_tpl->assign('smartobject_print_width', $this->_width); |
|
| 56 | 56 | |
| 57 | - $current_urls = smart_getCurrentUrls(); |
|
| 58 | - $current_url = $current_urls['full']; |
|
| 57 | + $current_urls = smart_getCurrentUrls(); |
|
| 58 | + $current_url = $current_urls['full']; |
|
| 59 | 59 | |
| 60 | - $this->_tpl->assign('smartobject_print_currenturl', $current_url); |
|
| 61 | - $this->_tpl->assign('smartobject_print_url', $this->url); |
|
| 60 | + $this->_tpl->assign('smartobject_print_currenturl', $current_url); |
|
| 61 | + $this->_tpl->assign('smartobject_print_url', $this->url); |
|
| 62 | 62 | |
| 63 | - $this->_tpl->display('db:smartobject_print.tpl'); |
|
| 64 | - } |
|
| 63 | + $this->_tpl->display('db:smartobject_print.tpl'); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * @param $text |
|
| 68 | - */ |
|
| 69 | - public function setPageTitle($text) |
|
| 70 | - { |
|
| 71 | - $this->_pageTitle = $text; |
|
| 72 | - } |
|
| 66 | + /** |
|
| 67 | + * @param $text |
|
| 68 | + */ |
|
| 69 | + public function setPageTitle($text) |
|
| 70 | + { |
|
| 71 | + $this->_pageTitle = $text; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * @param $width |
|
| 76 | - */ |
|
| 77 | - public function setWidth($width) |
|
| 78 | - { |
|
| 79 | - $this->_width = $width; |
|
| 80 | - } |
|
| 74 | + /** |
|
| 75 | + * @param $width |
|
| 76 | + */ |
|
| 77 | + public function setWidth($width) |
|
| 78 | + { |
|
| 79 | + $this->_width = $width; |
|
| 80 | + } |
|
| 81 | 81 | } |
@@ -37,227 +37,227 @@ |
||
| 37 | 37 | */ |
| 38 | 38 | class SmartobjectMemberHandler extends \XoopsMemberHandler |
| 39 | 39 | { |
| 40 | - /** |
|
| 41 | - * constructor |
|
| 42 | - * @param \XoopsDatabase $db |
|
| 43 | - */ |
|
| 44 | - public function __construct(\XoopsDatabase $db) |
|
| 45 | - { |
|
| 46 | - parent::__construct($db); |
|
| 47 | - $this->_uHandler = xoops_getModuleHandler('user', 'smartobject'); |
|
| 48 | - } |
|
| 40 | + /** |
|
| 41 | + * constructor |
|
| 42 | + * @param \XoopsDatabase $db |
|
| 43 | + */ |
|
| 44 | + public function __construct(\XoopsDatabase $db) |
|
| 45 | + { |
|
| 46 | + parent::__construct($db); |
|
| 47 | + $this->_uHandler = xoops_getModuleHandler('user', 'smartobject'); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @param $userObj |
|
| 52 | - * @param bool $groups |
|
| 53 | - * @param bool $notifyUser |
|
| 54 | - * @param bool $password |
|
| 55 | - * @return bool |
|
| 56 | - */ |
|
| 57 | - public function addAndActivateUser($userObj, $groups = false, $notifyUser = true, &$password = false) |
|
| 58 | - { |
|
| 59 | - $email = $userObj->getVar('email'); |
|
| 60 | - if (!$userObj->getVar('email') || '' === $email) { |
|
| 61 | - $userObj->setErrors(_CO_SOBJECT_USER_NEED_EMAIL); |
|
| 50 | + /** |
|
| 51 | + * @param $userObj |
|
| 52 | + * @param bool $groups |
|
| 53 | + * @param bool $notifyUser |
|
| 54 | + * @param bool $password |
|
| 55 | + * @return bool |
|
| 56 | + */ |
|
| 57 | + public function addAndActivateUser($userObj, $groups = false, $notifyUser = true, &$password = false) |
|
| 58 | + { |
|
| 59 | + $email = $userObj->getVar('email'); |
|
| 60 | + if (!$userObj->getVar('email') || '' === $email) { |
|
| 61 | + $userObj->setErrors(_CO_SOBJECT_USER_NEED_EMAIL); |
|
| 62 | 62 | |
| 63 | - return false; |
|
| 64 | - } |
|
| 63 | + return false; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - $password = $userObj->getVar('pass'); |
|
| 67 | - // randomly generating the password if not already set |
|
| 68 | - if ('' === $password) { |
|
| 69 | - $password = substr(md5(uniqid(mt_rand(), 1)), 0, 6); |
|
| 70 | - } |
|
| 71 | - $userObj->setVar('pass', md5($password)); |
|
| 66 | + $password = $userObj->getVar('pass'); |
|
| 67 | + // randomly generating the password if not already set |
|
| 68 | + if ('' === $password) { |
|
| 69 | + $password = substr(md5(uniqid(mt_rand(), 1)), 0, 6); |
|
| 70 | + } |
|
| 71 | + $userObj->setVar('pass', md5($password)); |
|
| 72 | 72 | |
| 73 | - // if no username is set, let's generate one |
|
| 74 | - $unamecount = 20; |
|
| 75 | - $uname = $userObj->getVar('uname'); |
|
| 76 | - if (!$uname || '' === $uname) { |
|
| 77 | - $usernames = $this->genUserNames($email, $unamecount); |
|
| 78 | - $newuser = false; |
|
| 79 | - $i = 0; |
|
| 80 | - while (false === $newuser) { |
|
| 81 | - $crit = new \Criteria('uname', $usernames[$i]); |
|
| 82 | - $count = $this->getUserCount($crit); |
|
| 83 | - if (0 == $count) { |
|
| 84 | - $newuser = true; |
|
| 85 | - } else { |
|
| 86 | - //Move to next username |
|
| 87 | - ++$i; |
|
| 88 | - if ($i == $unamecount) { |
|
| 89 | - //Get next batch of usernames to try, reset counter |
|
| 90 | - $usernames = $this->genUserNames($email, $unamecount); |
|
| 91 | - $i = 0; |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - } |
|
| 73 | + // if no username is set, let's generate one |
|
| 74 | + $unamecount = 20; |
|
| 75 | + $uname = $userObj->getVar('uname'); |
|
| 76 | + if (!$uname || '' === $uname) { |
|
| 77 | + $usernames = $this->genUserNames($email, $unamecount); |
|
| 78 | + $newuser = false; |
|
| 79 | + $i = 0; |
|
| 80 | + while (false === $newuser) { |
|
| 81 | + $crit = new \Criteria('uname', $usernames[$i]); |
|
| 82 | + $count = $this->getUserCount($crit); |
|
| 83 | + if (0 == $count) { |
|
| 84 | + $newuser = true; |
|
| 85 | + } else { |
|
| 86 | + //Move to next username |
|
| 87 | + ++$i; |
|
| 88 | + if ($i == $unamecount) { |
|
| 89 | + //Get next batch of usernames to try, reset counter |
|
| 90 | + $usernames = $this->genUserNames($email, $unamecount); |
|
| 91 | + $i = 0; |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - global $xoopsConfig; |
|
| 97 | + global $xoopsConfig; |
|
| 98 | 98 | |
| 99 | - $configHandler = xoops_getHandler('config'); |
|
| 100 | - $xoopsConfigUser = $configHandler->getConfigsByCat(XOOPS_CONF_USER); |
|
| 101 | - switch ($xoopsConfigUser['activation_type']) { |
|
| 102 | - case 0: |
|
| 103 | - $level = 0; |
|
| 104 | - $mailtemplate = 'smartmail_activate_user.tpl'; |
|
| 105 | - $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_NEED_ACT, $user_email); |
|
| 106 | - break; |
|
| 107 | - case 1: |
|
| 108 | - $level = 1; |
|
| 109 | - $mailtemplate = 'smartmail_auto_activate_user.tpl'; |
|
| 110 | - $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_AUTO_ACT, $user_email); |
|
| 111 | - break; |
|
| 112 | - case 2: |
|
| 113 | - default: |
|
| 114 | - $level = 0; |
|
| 115 | - $mailtemplate = 'smartmail_admin_activate_user.tpl'; |
|
| 116 | - $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_ADMIN_ACT, $user_email); |
|
| 117 | - } |
|
| 99 | + $configHandler = xoops_getHandler('config'); |
|
| 100 | + $xoopsConfigUser = $configHandler->getConfigsByCat(XOOPS_CONF_USER); |
|
| 101 | + switch ($xoopsConfigUser['activation_type']) { |
|
| 102 | + case 0: |
|
| 103 | + $level = 0; |
|
| 104 | + $mailtemplate = 'smartmail_activate_user.tpl'; |
|
| 105 | + $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_NEED_ACT, $user_email); |
|
| 106 | + break; |
|
| 107 | + case 1: |
|
| 108 | + $level = 1; |
|
| 109 | + $mailtemplate = 'smartmail_auto_activate_user.tpl'; |
|
| 110 | + $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_AUTO_ACT, $user_email); |
|
| 111 | + break; |
|
| 112 | + case 2: |
|
| 113 | + default: |
|
| 114 | + $level = 0; |
|
| 115 | + $mailtemplate = 'smartmail_admin_activate_user.tpl'; |
|
| 116 | + $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_ADMIN_ACT, $user_email); |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - $userObj->setVar('uname', $usernames[$i]); |
|
| 120 | - $userObj->setVar('user_avatar', 'blank.gif'); |
|
| 121 | - $userObj->setVar('user_regdate', time()); |
|
| 122 | - $userObj->setVar('timezone_offset', $xoopsConfig['default_TZ']); |
|
| 123 | - $actkey = substr(md5(uniqid(mt_rand(), 1)), 0, 8); |
|
| 124 | - $userObj->setVar('actkey', $actkey); |
|
| 125 | - $userObj->setVar('email', $email); |
|
| 126 | - $userObj->setVar('notify_method', 2); |
|
| 127 | - $userObj->setVar('level', $userObj); |
|
| 119 | + $userObj->setVar('uname', $usernames[$i]); |
|
| 120 | + $userObj->setVar('user_avatar', 'blank.gif'); |
|
| 121 | + $userObj->setVar('user_regdate', time()); |
|
| 122 | + $userObj->setVar('timezone_offset', $xoopsConfig['default_TZ']); |
|
| 123 | + $actkey = substr(md5(uniqid(mt_rand(), 1)), 0, 8); |
|
| 124 | + $userObj->setVar('actkey', $actkey); |
|
| 125 | + $userObj->setVar('email', $email); |
|
| 126 | + $userObj->setVar('notify_method', 2); |
|
| 127 | + $userObj->setVar('level', $userObj); |
|
| 128 | 128 | |
| 129 | - if ($this->insertUser($userObj)) { |
|
| 129 | + if ($this->insertUser($userObj)) { |
|
| 130 | 130 | |
| 131 | - // if $groups=false, Add the user to Registered Users group |
|
| 132 | - if (!$groups) { |
|
| 133 | - $this->addUserToGroup(XOOPS_GROUP_USERS, $userObj->getVar('uid')); |
|
| 134 | - } else { |
|
| 135 | - foreach ($groups as $groupid) { |
|
| 136 | - $this->addUserToGroup($groupid, $userObj->getVar('uid')); |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - } else { |
|
| 140 | - return false; |
|
| 141 | - } |
|
| 131 | + // if $groups=false, Add the user to Registered Users group |
|
| 132 | + if (!$groups) { |
|
| 133 | + $this->addUserToGroup(XOOPS_GROUP_USERS, $userObj->getVar('uid')); |
|
| 134 | + } else { |
|
| 135 | + foreach ($groups as $groupid) { |
|
| 136 | + $this->addUserToGroup($groupid, $userObj->getVar('uid')); |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + } else { |
|
| 140 | + return false; |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - if ($notifyUser) { |
|
| 144 | - // send some notifications |
|
| 145 | - $xoopsMailer = xoops_getMailer(); |
|
| 146 | - $xoopsMailer->useMail(); |
|
| 147 | - $xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/mail_template'); |
|
| 148 | - $xoopsMailer->setTemplate('smartobject_notify_user_added_by_admin.tpl'); |
|
| 149 | - $xoopsMailer->assign('XOOPS_USER_PASSWORD', $password); |
|
| 150 | - $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']); |
|
| 151 | - $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']); |
|
| 152 | - $xoopsMailer->assign('SITEURL', XOOPS_URL . '/'); |
|
| 153 | - $xoopsMailer->assign('NAME', $userObj->getVar('name')); |
|
| 154 | - $xoopsMailer->assign('UNAME', $userObj->getVar('uname')); |
|
| 155 | - $xoopsMailer->setToUsers($userObj); |
|
| 156 | - $xoopsMailer->setFromEmail($xoopsConfig['adminmail']); |
|
| 157 | - $xoopsMailer->setFromName($xoopsConfig['sitename']); |
|
| 158 | - $xoopsMailer->setSubject(sprintf(_CO_SOBJECT_NEW_USER_NOTIFICATION_SUBJECT, $xoopsConfig['sitename'])); |
|
| 143 | + if ($notifyUser) { |
|
| 144 | + // send some notifications |
|
| 145 | + $xoopsMailer = xoops_getMailer(); |
|
| 146 | + $xoopsMailer->useMail(); |
|
| 147 | + $xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/mail_template'); |
|
| 148 | + $xoopsMailer->setTemplate('smartobject_notify_user_added_by_admin.tpl'); |
|
| 149 | + $xoopsMailer->assign('XOOPS_USER_PASSWORD', $password); |
|
| 150 | + $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']); |
|
| 151 | + $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']); |
|
| 152 | + $xoopsMailer->assign('SITEURL', XOOPS_URL . '/'); |
|
| 153 | + $xoopsMailer->assign('NAME', $userObj->getVar('name')); |
|
| 154 | + $xoopsMailer->assign('UNAME', $userObj->getVar('uname')); |
|
| 155 | + $xoopsMailer->setToUsers($userObj); |
|
| 156 | + $xoopsMailer->setFromEmail($xoopsConfig['adminmail']); |
|
| 157 | + $xoopsMailer->setFromName($xoopsConfig['sitename']); |
|
| 158 | + $xoopsMailer->setSubject(sprintf(_CO_SOBJECT_NEW_USER_NOTIFICATION_SUBJECT, $xoopsConfig['sitename'])); |
|
| 159 | 159 | |
| 160 | - if (!$xoopsMailer->send(true)) { |
|
| 161 | - /** |
|
| 162 | - * @todo trap error if email was not sent |
|
| 163 | - */ |
|
| 164 | - $xoopsMailer->getErrors(true); |
|
| 165 | - } |
|
| 166 | - } |
|
| 160 | + if (!$xoopsMailer->send(true)) { |
|
| 161 | + /** |
|
| 162 | + * @todo trap error if email was not sent |
|
| 163 | + */ |
|
| 164 | + $xoopsMailer->getErrors(true); |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - return true; |
|
| 169 | - } |
|
| 168 | + return true; |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - /** |
|
| 172 | - * Generates an array of usernames |
|
| 173 | - * |
|
| 174 | - * @param string $email email of user |
|
| 175 | - * @param int $count number of names to generate |
|
| 176 | - * @return array $names |
|
| 177 | - * @internal param string $name name of user |
|
| 178 | - * @author xHelp Team |
|
| 179 | - * |
|
| 180 | - * @access public |
|
| 181 | - */ |
|
| 182 | - public function genUserNames($email, $count = 20) |
|
| 183 | - { |
|
| 184 | - $name = substr($email, 0, strpos($email, '@')); //Take the email adress without domain as username |
|
| 171 | + /** |
|
| 172 | + * Generates an array of usernames |
|
| 173 | + * |
|
| 174 | + * @param string $email email of user |
|
| 175 | + * @param int $count number of names to generate |
|
| 176 | + * @return array $names |
|
| 177 | + * @internal param string $name name of user |
|
| 178 | + * @author xHelp Team |
|
| 179 | + * |
|
| 180 | + * @access public |
|
| 181 | + */ |
|
| 182 | + public function genUserNames($email, $count = 20) |
|
| 183 | + { |
|
| 184 | + $name = substr($email, 0, strpos($email, '@')); //Take the email adress without domain as username |
|
| 185 | 185 | |
| 186 | - $names = []; |
|
| 187 | - $userid = explode('@', $email); |
|
| 186 | + $names = []; |
|
| 187 | + $userid = explode('@', $email); |
|
| 188 | 188 | |
| 189 | - $basename = ''; |
|
| 190 | - $hasbasename = false; |
|
| 191 | - $emailname = $userid[0]; |
|
| 189 | + $basename = ''; |
|
| 190 | + $hasbasename = false; |
|
| 191 | + $emailname = $userid[0]; |
|
| 192 | 192 | |
| 193 | - $names[] = $emailname; |
|
| 193 | + $names[] = $emailname; |
|
| 194 | 194 | |
| 195 | - if (strlen($name) > 0) { |
|
| 196 | - $name = explode(' ', trim($name)); |
|
| 197 | - if (count($name) > 1) { |
|
| 198 | - $basename = strtolower(substr($name[0], 0, 1) . $name[count($name) - 1]); |
|
| 199 | - } else { |
|
| 200 | - $basename = strtolower($name[0]); |
|
| 201 | - } |
|
| 202 | - $basename = xoops_substr($basename, 0, 60, ''); |
|
| 203 | - //Prevent Duplication of Email Username and Name |
|
| 204 | - if (!in_array($basename, $names)) { |
|
| 205 | - $names[] = $basename; |
|
| 206 | - $hasbasename = true; |
|
| 207 | - } |
|
| 208 | - } |
|
| 195 | + if (strlen($name) > 0) { |
|
| 196 | + $name = explode(' ', trim($name)); |
|
| 197 | + if (count($name) > 1) { |
|
| 198 | + $basename = strtolower(substr($name[0], 0, 1) . $name[count($name) - 1]); |
|
| 199 | + } else { |
|
| 200 | + $basename = strtolower($name[0]); |
|
| 201 | + } |
|
| 202 | + $basename = xoops_substr($basename, 0, 60, ''); |
|
| 203 | + //Prevent Duplication of Email Username and Name |
|
| 204 | + if (!in_array($basename, $names)) { |
|
| 205 | + $names[] = $basename; |
|
| 206 | + $hasbasename = true; |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | - $i = count($names); |
|
| 211 | - $onbasename = 1; |
|
| 212 | - while ($i < $count) { |
|
| 213 | - $num = $this->genRandNumber(); |
|
| 214 | - if ($onbasename < 0 && $hasbasename) { |
|
| 215 | - $names[] = xoops_substr($basename, 0, 58, '') . $num; |
|
| 216 | - } else { |
|
| 217 | - $names[] = xoops_substr($emailname, 0, 58, '') . $num; |
|
| 218 | - } |
|
| 219 | - $i = count($names); |
|
| 220 | - $onbasename = ~$onbasename; |
|
| 221 | - $num = ''; |
|
| 222 | - } |
|
| 210 | + $i = count($names); |
|
| 211 | + $onbasename = 1; |
|
| 212 | + while ($i < $count) { |
|
| 213 | + $num = $this->genRandNumber(); |
|
| 214 | + if ($onbasename < 0 && $hasbasename) { |
|
| 215 | + $names[] = xoops_substr($basename, 0, 58, '') . $num; |
|
| 216 | + } else { |
|
| 217 | + $names[] = xoops_substr($emailname, 0, 58, '') . $num; |
|
| 218 | + } |
|
| 219 | + $i = count($names); |
|
| 220 | + $onbasename = ~$onbasename; |
|
| 221 | + $num = ''; |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | - return $names; |
|
| 225 | - } |
|
| 224 | + return $names; |
|
| 225 | + } |
|
| 226 | 226 | |
| 227 | - /** |
|
| 228 | - * Creates a random number with a specified number of $digits |
|
| 229 | - * |
|
| 230 | - * @param int $digits number of digits |
|
| 231 | - * @return int random number |
|
| 232 | - * @author xHelp Team |
|
| 233 | - * |
|
| 234 | - * @access public |
|
| 235 | - */ |
|
| 236 | - public function genRandNumber($digits = 2) |
|
| 237 | - { |
|
| 238 | - $this->initRand(); |
|
| 239 | - $tmp = []; |
|
| 227 | + /** |
|
| 228 | + * Creates a random number with a specified number of $digits |
|
| 229 | + * |
|
| 230 | + * @param int $digits number of digits |
|
| 231 | + * @return int random number |
|
| 232 | + * @author xHelp Team |
|
| 233 | + * |
|
| 234 | + * @access public |
|
| 235 | + */ |
|
| 236 | + public function genRandNumber($digits = 2) |
|
| 237 | + { |
|
| 238 | + $this->initRand(); |
|
| 239 | + $tmp = []; |
|
| 240 | 240 | |
| 241 | - for ($i = 0; $i < $digits; ++$i) { |
|
| 242 | - $tmp[$i] = (mt_rand() % 9); |
|
| 243 | - } |
|
| 241 | + for ($i = 0; $i < $digits; ++$i) { |
|
| 242 | + $tmp[$i] = (mt_rand() % 9); |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - return implode('', $tmp); |
|
| 246 | - } |
|
| 245 | + return implode('', $tmp); |
|
| 246 | + } |
|
| 247 | 247 | |
| 248 | - /** |
|
| 249 | - * Gives the random number generator a seed to start from |
|
| 250 | - * |
|
| 251 | - * @return void |
|
| 252 | - * |
|
| 253 | - * @access public |
|
| 254 | - */ |
|
| 255 | - public function initRand() |
|
| 256 | - { |
|
| 257 | - static $randCalled = false; |
|
| 258 | - if (!$randCalled) { |
|
| 259 | - mt_srand((double)microtime() * 1000000); |
|
| 260 | - $randCalled = true; |
|
| 261 | - } |
|
| 262 | - } |
|
| 248 | + /** |
|
| 249 | + * Gives the random number generator a seed to start from |
|
| 250 | + * |
|
| 251 | + * @return void |
|
| 252 | + * |
|
| 253 | + * @access public |
|
| 254 | + */ |
|
| 255 | + public function initRand() |
|
| 256 | + { |
|
| 257 | + static $randCalled = false; |
|
| 258 | + if (!$randCalled) { |
|
| 259 | + mt_srand((double)microtime() * 1000000); |
|
| 260 | + $randCalled = true; |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | 263 | } |
@@ -30,48 +30,48 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class SmartobjectCustomtagHandler extends Smartobject\SmartPersistableObjectHandler |
| 32 | 32 | { |
| 33 | - public $objects = false; |
|
| 33 | + public $objects = false; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * SmartobjectCustomtagHandler constructor. |
|
| 37 | - * @param \XoopsDatabase $db |
|
| 38 | - */ |
|
| 39 | - public function __construct(\XoopsDatabase $db) |
|
| 40 | - { |
|
| 41 | - parent::__construct($db, 'customtag', 'customtagid', 'name', 'description', 'smartobject'); |
|
| 42 | - $this->addPermission('view', _CO_SOBJECT_CUSTOMTAG_PERMISSION_VIEW, _CO_SOBJECT_CUSTOMTAG_PERMISSION_VIEW_DSC); |
|
| 43 | - } |
|
| 35 | + /** |
|
| 36 | + * SmartobjectCustomtagHandler constructor. |
|
| 37 | + * @param \XoopsDatabase $db |
|
| 38 | + */ |
|
| 39 | + public function __construct(\XoopsDatabase $db) |
|
| 40 | + { |
|
| 41 | + parent::__construct($db, 'customtag', 'customtagid', 'name', 'description', 'smartobject'); |
|
| 42 | + $this->addPermission('view', _CO_SOBJECT_CUSTOMTAG_PERMISSION_VIEW, _CO_SOBJECT_CUSTOMTAG_PERMISSION_VIEW_DSC); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @return array|bool |
|
| 47 | - */ |
|
| 48 | - public function getCustomtagsByName() |
|
| 49 | - { |
|
| 50 | - if (!$this->objects) { |
|
| 51 | - global $xoopsConfig; |
|
| 45 | + /** |
|
| 46 | + * @return array|bool |
|
| 47 | + */ |
|
| 48 | + public function getCustomtagsByName() |
|
| 49 | + { |
|
| 50 | + if (!$this->objects) { |
|
| 51 | + global $xoopsConfig; |
|
| 52 | 52 | |
| 53 | - $ret = []; |
|
| 53 | + $ret = []; |
|
| 54 | 54 | |
| 55 | - $criteria = new \CriteriaCompo(); |
|
| 55 | + $criteria = new \CriteriaCompo(); |
|
| 56 | 56 | |
| 57 | - $criteria_language = new \CriteriaCompo(); |
|
| 58 | - $criteria_language->add(new \Criteria('language', $xoopsConfig['language'])); |
|
| 59 | - $criteria_language->add(new \Criteria('language', 'all'), 'OR'); |
|
| 60 | - $criteria->add($criteria_language); |
|
| 57 | + $criteria_language = new \CriteriaCompo(); |
|
| 58 | + $criteria_language->add(new \Criteria('language', $xoopsConfig['language'])); |
|
| 59 | + $criteria_language->add(new \Criteria('language', 'all'), 'OR'); |
|
| 60 | + $criteria->add($criteria_language); |
|
| 61 | 61 | |
| 62 | - $smartobjectPermissionsHandler = new SmartObjectPermissionHandler($this); |
|
| 63 | - $granted_ids = $smartobjectPermissionsHandler->getGrantedItems('view'); |
|
| 62 | + $smartobjectPermissionsHandler = new SmartObjectPermissionHandler($this); |
|
| 63 | + $granted_ids = $smartobjectPermissionsHandler->getGrantedItems('view'); |
|
| 64 | 64 | |
| 65 | - if ($granted_ids && count($granted_ids) > 0) { |
|
| 66 | - $criteria->add(new \Criteria('customtagid', '(' . implode(', ', $granted_ids) . ')', 'IN')); |
|
| 67 | - $customtagsObj =& $this->getObjects($criteria, true); |
|
| 68 | - foreach ($customtagsObj as $customtagObj) { |
|
| 69 | - $ret[$customtagObj->getVar('name')] = $customtagObj; |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - $this->objects = $ret; |
|
| 73 | - } |
|
| 65 | + if ($granted_ids && count($granted_ids) > 0) { |
|
| 66 | + $criteria->add(new \Criteria('customtagid', '(' . implode(', ', $granted_ids) . ')', 'IN')); |
|
| 67 | + $customtagsObj =& $this->getObjects($criteria, true); |
|
| 68 | + foreach ($customtagsObj as $customtagObj) { |
|
| 69 | + $ret[$customtagObj->getVar('name')] = $customtagObj; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + $this->objects = $ret; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - return $this->objects; |
|
| 76 | - } |
|
| 75 | + return $this->objects; |
|
| 76 | + } |
|
| 77 | 77 | } |