XoopsModules25x /
xoopstube
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * Module: XoopsTube |
||
| 5 | * |
||
| 6 | * You may not change or alter any portion of this comment or credits |
||
| 7 | * of supporting developers from this source code or any supporting source code |
||
| 8 | * which is considered copyrighted (c) material of the original comment or credit authors. |
||
| 9 | * |
||
| 10 | * PHP version 5 |
||
| 11 | * |
||
| 12 | * @category Module |
||
| 13 | * @package Xoopstube |
||
| 14 | * @author XOOPS Development Team |
||
| 15 | * @copyright 2001-2016 XOOPS Project (http://xoops.org) |
||
| 16 | * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
||
| 17 | * @link http://xoops.org/ |
||
| 18 | * @since 1.0.6 |
||
| 19 | */ |
||
| 20 | class FileList |
||
| 21 | { |
||
| 22 | public $filelist = array(); |
||
| 23 | |||
| 24 | public $value; |
||
| 25 | public $selected; |
||
| 26 | public $path = 'uploads'; |
||
| 27 | public $size; |
||
| 28 | public $emptySelect; |
||
| 29 | public $type; |
||
| 30 | public $prefix; |
||
| 31 | public $suffix; |
||
| 32 | public $noSelection; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * fileList::construct() |
||
| 36 | * |
||
| 37 | * @param string $path |
||
| 38 | * @param null $value |
||
| 39 | * @param string $selected |
||
| 40 | * @param integer $size |
||
| 41 | * |
||
| 42 | * @internal param int $emptySelect |
||
| 43 | * @internal param int $type |
||
| 44 | * @internal param string $prefix |
||
| 45 | * @internal param string $suffix |
||
| 46 | * @return \fileList |
||
|
0 ignored issues
–
show
|
|||
| 47 | */ |
||
| 48 | public function __construct($path = 'uploads', $value = null, $selected = '', $size = 1) |
||
| 49 | { |
||
| 50 | $this->value = $value; |
||
| 51 | $this->selection = $selected; |
||
| 52 | $this->size = (int)$size; |
||
| 53 | |||
| 54 | $pathToCheck = XOOPS_ROOT_PATH . "/{$path}"; |
||
| 55 | if (!is_dir($pathToCheck) && false === @mkdir("$pathToCheck", 0777)) { |
||
| 56 | XoopsErrorHandler_HandleError(E_USER_WARNING, $pathToCheck . _AM_XOOPSTUBE_DOESNOTEXIST, __FILE__, __LINE__); |
||
| 57 | |||
| 58 | return false; |
||
| 59 | } |
||
| 60 | $this->path = $path; |
||
| 61 | |||
| 62 | return true; |
||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * SpotList::setNoSelection() |
||
| 67 | * |
||
| 68 | * @param integer $value |
||
| 69 | * |
||
| 70 | * @return void |
||
| 71 | */ |
||
| 72 | |||
| 73 | public function setEmptySelect($value = 0) |
||
| 74 | { |
||
| 75 | $this->emptySelect = ((int)$value !== 1) ? 0 : 1; |
||
| 76 | } |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @param int $value |
||
| 80 | */ |
||
| 81 | public function setNoSelection($value = 0) |
||
| 82 | { |
||
| 83 | $this->noSelection = ((int)$value !== 1) ? 0 : 1; |
||
| 84 | } |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @param string $value |
||
| 88 | */ |
||
| 89 | public function setPrefix($value = '') |
||
| 90 | { |
||
| 91 | $this->prefix = ((string)$value) !== '' ? (string)$value : ''; |
||
| 92 | } |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @param string $value |
||
| 96 | */ |
||
| 97 | public function setSuffix($value = '') |
||
| 98 | { |
||
| 99 | $this->suffix = ((string)$value) !== '' ? (string)$value : ''; |
||
| 100 | } |
||
| 101 | |||
| 102 | /** |
||
| 103 | * @param string $value |
||
| 104 | */ |
||
| 105 | public function setListType($value = 'images') |
||
| 106 | { |
||
| 107 | $this->type = (string)strtolower($value); |
||
| 108 | } |
||
| 109 | |||
| 110 | /** |
||
| 111 | * SpotList::showSelection() |
||
| 112 | * |
||
| 113 | * @return string |
||
| 114 | */ |
||
| 115 | View Code Duplication | public function &showSelection() |
|
| 116 | { |
||
| 117 | $ret = "<select size='" . $this->size() . "' name='$this->value()'>"; |
||
| 118 | if ($this->emptySelect) { |
||
| 119 | $ret .= "<option value='" . $this->value() . "'>----------------------</option>"; |
||
| 120 | } |
||
| 121 | foreach ($this->filelist as $content) { |
||
| 122 | $optSelected = ''; |
||
| 123 | |||
| 124 | if ($content[0] == $this->isSelected()) { |
||
| 125 | $optSelected = "selected='selected'"; |
||
| 126 | } |
||
| 127 | $ret .= "<option value='" . $content . "' $optSelected>" . $content . '</option>'; |
||
| 128 | } |
||
| 129 | $ret .= '</select>'; |
||
| 130 | |||
| 131 | return $ret; |
||
| 132 | } |
||
| 133 | |||
| 134 | /** |
||
| 135 | * SpotList::getListTypeAsArray() |
||
| 136 | * |
||
| 137 | * @return array |
||
| 138 | */ |
||
| 139 | public function &getListTypeAsArray() |
||
| 140 | { |
||
| 141 | $filelist = array(); |
||
| 142 | switch (trim($this->type)) { |
||
| 143 | case 'images': |
||
| 144 | $types = '[.gif|.jpg|.png]'; |
||
| 145 | if ($this->noSelection) { |
||
| 146 | $this->filelist[0] = _AM_XOOPSTUBE_NOIMAGE; |
||
| 147 | } |
||
| 148 | break; |
||
| 149 | case 'media': |
||
| 150 | $types = '[.aac|.flv|.mp3|.mp4|.swf]'; |
||
| 151 | if ($this->noSelection) { |
||
| 152 | $this->filelist[0] = _AM_XOOPSTUBE_NOVIDEO; |
||
| 153 | } |
||
| 154 | break; |
||
| 155 | |||
| 156 | case 'html': |
||
| 157 | $types = '[.htm|.tpl|.html|.xhtml|.php|.php3|.phtml|.txt]'; |
||
| 158 | if ($this->noSelection) { |
||
| 159 | $this->filelist[0] = _AM_XOOPSTUBE_NOSELECT; |
||
| 160 | } |
||
| 161 | break; |
||
| 162 | |||
| 163 | default: |
||
| 164 | $types = ''; |
||
| 165 | if ($this->noSelection) { |
||
| 166 | $this->filelist[0] = _AM_XOOPSTUBE_NOFILESELECT; |
||
| 167 | } |
||
| 168 | break; |
||
| 169 | } |
||
| 170 | |||
| 171 | if ('/' === substr($this->path, -1)) { |
||
| 172 | $this->path = substr($this->path, 0, -1); |
||
| 173 | } |
||
| 174 | |||
| 175 | $_full_path = XOOPS_ROOT_PATH . "/{$this->path}"; |
||
| 176 | |||
| 177 | if (is_dir($_full_path) && $handle = opendir($_full_path)) { |
||
| 178 | while (false !== ($file = readdir($handle))) { |
||
| 179 | if (!preg_match("/^[.]{1,2}$/", $file) && preg_match("/$types$/i", $file) && is_file($_full_path . '/' . $file)) { |
||
| 180 | if ('blank.gif' === strtolower($file)) { |
||
| 181 | continue; |
||
| 182 | } |
||
| 183 | $file = $this->prefix . $file; |
||
| 184 | $this->filelist[$file] = $file; |
||
| 185 | } |
||
| 186 | } |
||
| 187 | closedir($handle); |
||
| 188 | asort($this->filelist); |
||
| 189 | reset($this->filelist); |
||
| 190 | } |
||
| 191 | |||
| 192 | return $this->filelist; |
||
| 193 | } |
||
| 194 | |||
| 195 | /** |
||
| 196 | * @return null |
||
| 197 | */ |
||
| 198 | public function value() |
||
| 199 | { |
||
| 200 | return $this->value; |
||
| 201 | } |
||
| 202 | |||
| 203 | public function isSelected() |
||
| 204 | { |
||
| 205 | return $this->selected; |
||
| 206 | } |
||
| 207 | |||
| 208 | /** |
||
| 209 | * @return string |
||
| 210 | */ |
||
| 211 | public function paths() |
||
| 212 | { |
||
| 213 | return $this->path; |
||
| 214 | } |
||
| 215 | |||
| 216 | /** |
||
| 217 | * @return int |
||
| 218 | */ |
||
| 219 | public function size() |
||
| 220 | { |
||
| 221 | return $this->size; |
||
| 222 | } |
||
| 223 | |||
| 224 | public function isEmptySelect() |
||
| 225 | { |
||
| 226 | return $this->emptySelect; |
||
| 227 | } |
||
| 228 | |||
| 229 | public function getType() |
||
| 230 | { |
||
| 231 | return $this->type; |
||
| 232 | } |
||
| 233 | |||
| 234 | public function getPrefix() |
||
| 235 | { |
||
| 236 | return $this->prefix; |
||
| 237 | } |
||
| 238 | |||
| 239 | public function getSuffix() |
||
| 240 | { |
||
| 241 | return $this->suffix; |
||
| 242 | } |
||
| 243 | } |
||
| 244 |
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.