| 1 | <?php |
||||
| 2 | //------------------------------------------------------------------------- |
||||
| 3 | // OVIDENTIA http://www.ovidentia.org |
||||
| 4 | // Ovidentia is free software; you can redistribute it and/or modify |
||||
| 5 | // it under the terms of the GNU General Public License as published by |
||||
| 6 | // the Free Software Foundation; either version 2, or (at your option) |
||||
| 7 | // any later version. |
||||
| 8 | // |
||||
| 9 | // This program is distributed in the hope that it will be useful, but |
||||
| 10 | // WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||||
| 12 | // See the GNU General Public License for more details. |
||||
| 13 | // |
||||
| 14 | // You should have received a copy of the GNU General Public License |
||||
| 15 | // along with this program; if not, write to the Free Software |
||||
| 16 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
||||
| 17 | // USA. |
||||
| 18 | //------------------------------------------------------------------------- |
||||
| 19 | /** |
||||
| 20 | * @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL) |
||||
| 21 | * @copyright Copyright (c) 2009 by CANTICO ({@link http://www.cantico.fr}) |
||||
| 22 | */ |
||||
| 23 | |||||
| 24 | use Capwelton\LibApp\Func_App; |
||||
| 25 | use Capwelton\Widgets\Widgets\Helpers\WidgetAction; |
||||
|
0 ignored issues
–
show
|
|||||
| 26 | |||||
| 27 | require_once $GLOBALS['babInstallPath'].'utilit/urlincl.php'; |
||||
| 28 | |||||
| 29 | /** |
||||
| 30 | * Translates the string. |
||||
| 31 | * |
||||
| 32 | * @param string $str |
||||
| 33 | * @return string |
||||
| 34 | */ |
||||
| 35 | function app_translate($str) |
||||
| 36 | { |
||||
| 37 | $translation = bab_translate($str, 'LibApp'); |
||||
| 38 | |||||
| 39 | return $translation; |
||||
| 40 | } |
||||
| 41 | |||||
| 42 | /** |
||||
| 43 | * Translates all the string in an array and returns a new array. |
||||
| 44 | * |
||||
| 45 | * @param array $arr |
||||
| 46 | * @return array |
||||
| 47 | */ |
||||
| 48 | function app_translateArray($arr) |
||||
| 49 | { |
||||
| 50 | $newarr = $arr; |
||||
| 51 | |||||
| 52 | foreach ($newarr as &$str) { |
||||
| 53 | $str = app_translate($str); |
||||
| 54 | } |
||||
| 55 | return $newarr; |
||||
| 56 | } |
||||
| 57 | |||||
| 58 | |||||
| 59 | |||||
| 60 | /** |
||||
| 61 | * Instanciates the App factory. |
||||
| 62 | * |
||||
| 63 | * @return Func_App |
||||
| 64 | */ |
||||
| 65 | function app_App() |
||||
| 66 | { |
||||
| 67 | return bab_functionality::getOriginal('App'); |
||||
|
0 ignored issues
–
show
The method
getOriginal() does not exist on bab_functionality. It seems like you code against a sub-type of bab_functionality such as Capwelton\LibApp\Func_App.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 68 | } |
||||
| 69 | |||||
| 70 | |||||
| 71 | /** |
||||
| 72 | * Instanciates the Newsletter factory. |
||||
| 73 | * |
||||
| 74 | * @return Func_Newsletter |
||||
| 75 | */ |
||||
| 76 | /*function app_Newsletter() |
||||
| 77 | { |
||||
| 78 | return bab_functionality::get('Newsletter'); |
||||
| 79 | }*/ |
||||
| 80 | |||||
| 81 | |||||
| 82 | /** |
||||
| 83 | * Instanciates the MailingList factory. |
||||
| 84 | * |
||||
| 85 | * @return Func_MailingList |
||||
|
0 ignored issues
–
show
The type
Func_MailingList was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 86 | */ |
||||
| 87 | function app_MailingList() |
||||
| 88 | { |
||||
| 89 | return bab_functionality::getOriginal('MailingList'); |
||||
| 90 | } |
||||
| 91 | |||||
| 92 | |||||
| 93 | |||||
| 94 | function app_addPageInfo($message) |
||||
| 95 | { |
||||
| 96 | $_SESSION['app_msginfo'][] = $message; |
||||
| 97 | } |
||||
| 98 | |||||
| 99 | |||||
| 100 | /** |
||||
| 101 | * Redirects to the specified url or action. |
||||
| 102 | * This function makes the current script die. |
||||
| 103 | * |
||||
| 104 | * @param WidgetAction|string $url |
||||
| 105 | */ |
||||
| 106 | function app_redirect($url, $message = null) |
||||
| 107 | { |
||||
| 108 | global $babBody; |
||||
| 109 | |||||
| 110 | if (null === $url) { |
||||
|
0 ignored issues
–
show
|
|||||
| 111 | $script = '<script type="text/javascript">'; |
||||
| 112 | if (isset($message)) { |
||||
| 113 | $script .= 'alert("' . bab_toHtml($message, BAB_HTML_JS) . '");'; |
||||
| 114 | } |
||||
| 115 | $script .= 'history.back();'; |
||||
| 116 | $script .= '</script>'; |
||||
| 117 | |||||
| 118 | die($script); |
||||
|
0 ignored issues
–
show
|
|||||
| 119 | } |
||||
| 120 | |||||
| 121 | if ($url instanceof WidgetAction) { |
||||
| 122 | $url = $url->url(); |
||||
| 123 | } |
||||
| 124 | if (!empty($babBody->msgerror)) { |
||||
| 125 | $url .= '&msgerror=' . urlencode($babBody->msgerror); |
||||
| 126 | } |
||||
| 127 | if (isset($message)) { |
||||
| 128 | $lines = explode("\n", $message); |
||||
| 129 | foreach ($lines as $line) { |
||||
| 130 | app_addPageInfo($line); |
||||
| 131 | } |
||||
| 132 | } |
||||
| 133 | |||||
| 134 | header('Location: ' . $url); |
||||
| 135 | die; |
||||
| 136 | } |
||||
| 137 | |||||
| 138 | |||||
| 139 | |||||
| 140 | |||||
| 141 | |||||
| 142 | /** |
||||
| 143 | * create or validate a rewriten name |
||||
| 144 | * @param string $name |
||||
| 145 | */ |
||||
| 146 | function app_getRewriteName($rewriteName) |
||||
| 147 | { |
||||
| 148 | $rewriteName = bab_removeDiacritics($rewriteName); |
||||
| 149 | $rewriteName = strtolower($rewriteName); |
||||
| 150 | $rewriteName = str_replace(array(' ', '/'), '-', $rewriteName); |
||||
| 151 | $rewriteName = preg_replace('/[^-0-9A-Za-z]/', '', $rewriteName); |
||||
| 152 | $rewriteName = preg_replace('/[-]+/', '-', $rewriteName); |
||||
| 153 | $rewriteName = trim($rewriteName, '- '); |
||||
| 154 | |||||
| 155 | return $rewriteName; |
||||
| 156 | } |
||||
| 157 | |||||
| 158 | |||||
| 159 | |||||
| 160 | /** |
||||
| 161 | * Upload file error to string |
||||
| 162 | * @return string |
||||
| 163 | */ |
||||
| 164 | function app_fileUploadError($error) |
||||
| 165 | { |
||||
| 166 | switch($error) { |
||||
| 167 | case UPLOAD_ERR_OK: |
||||
| 168 | return null; |
||||
| 169 | |||||
| 170 | case UPLOAD_ERR_INI_SIZE: |
||||
| 171 | return app_translate('The uploaded file exceeds the upload_max_filesize directive.'); |
||||
| 172 | |||||
| 173 | case UPLOAD_ERR_FORM_SIZE: |
||||
| 174 | return app_translate('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.'); |
||||
| 175 | |||||
| 176 | case UPLOAD_ERR_PARTIAL: |
||||
| 177 | return app_translate('The uploaded file was only partially uploaded.'); |
||||
| 178 | |||||
| 179 | case UPLOAD_ERR_NO_FILE: |
||||
| 180 | return app_translate('No file was uploaded.'); |
||||
| 181 | |||||
| 182 | case UPLOAD_ERR_NO_TMP_DIR: // since PHP 4.3.10 and PHP 5.0.3 |
||||
| 183 | return app_translate('Missing a temporary folder.'); |
||||
| 184 | |||||
| 185 | case UPLOAD_ERR_CANT_WRITE: // since php 5.1.0 |
||||
| 186 | return app_translate('Failed to write file to disk.'); |
||||
| 187 | |||||
| 188 | default : |
||||
| 189 | return app_translate('Unknown File Error.'); |
||||
| 190 | } |
||||
| 191 | } |
||||
| 192 | |||||
| 193 | |||||
| 194 | |||||
| 195 | |||||
| 196 | |||||
| 197 | /** |
||||
| 198 | * Fix datetime submited from a separated datePicker and timePicker |
||||
| 199 | * @param array $dateTime |
||||
| 200 | * @param bool $ignoreTime |
||||
| 201 | * |
||||
| 202 | * @return string |
||||
| 203 | */ |
||||
| 204 | function app_fixDateTime(Array $dateTime, $ignoreTime) |
||||
| 205 | { |
||||
| 206 | $W = bab_Widgets(); |
||||
| 207 | $date = $W->DatePicker()->getISODate($dateTime['date']); |
||||
| 208 | |||||
| 209 | if (!$date || '0000-00-00' === $date) { |
||||
| 210 | return '0000-00-00 00:00:00'; |
||||
| 211 | } |
||||
| 212 | |||||
| 213 | $hour = $dateTime['time']; |
||||
| 214 | |||||
| 215 | if (5 === mb_strlen($hour)) { |
||||
| 216 | $hour .= ':00'; |
||||
| 217 | } |
||||
| 218 | |||||
| 219 | if ($ignoreTime || empty($hour) || 8 !== mb_strlen($hour)) { |
||||
| 220 | $hour = '00:00:00'; |
||||
| 221 | } |
||||
| 222 | |||||
| 223 | return $date.' '.$hour; |
||||
| 224 | } |
||||
| 225 | |||||
| 226 | |||||
| 227 | |||||
| 228 | /** |
||||
| 229 | * @param mixed $value |
||||
| 230 | * @return string |
||||
| 231 | * @deprecated Use bab_json_encode() |
||||
| 232 | */ |
||||
| 233 | function app_json_encode($a) |
||||
| 234 | { |
||||
| 235 | return bab_json_encode($a); |
||||
| 236 | } |
||||
| 237 | |||||
| 238 | /** |
||||
| 239 | * |
||||
| 240 | * @return bab_registry |
||||
| 241 | */ |
||||
| 242 | function app_getRegistry() |
||||
| 243 | { |
||||
| 244 | $registry = bab_getRegistryInstance(); |
||||
| 245 | |||||
| 246 | $registry->changeDirectory('/LibApp'); |
||||
| 247 | |||||
| 248 | return $registry; |
||||
| 249 | } |
||||
| 250 | |||||
| 251 | /** |
||||
| 252 | * Returns an url suitable for displaying an image |
||||
| 253 | * @param bab_Path $photoPath The bab_Path to the image |
||||
| 254 | * @param int $width The width in pixel of the wanted image |
||||
| 255 | * @param int $height The height in pixel of the wanted image |
||||
| 256 | * |
||||
| 257 | * @return string |
||||
| 258 | */ |
||||
| 259 | function app_getResizedImageUrl($photoPath, $width = 300, $height = 300) |
||||
| 260 | { |
||||
| 261 | /** @var $T Func_Thumbnailer */ |
||||
| 262 | $T = @bab_functionality::get('Thumbnailer'); |
||||
| 263 | |||||
| 264 | $imageUrl = ''; |
||||
| 265 | |||||
| 266 | if ($T) { |
||||
|
0 ignored issues
–
show
|
|||||
| 267 | if (!empty($photoPath)) { |
||||
| 268 | $T->setSourceFile($photoPath->toString()); |
||||
| 269 | $T->setResizeMode(Func_Thumbnailer::KEEP_ASPECT_RATIO); |
||||
|
0 ignored issues
–
show
The type
Func_Thumbnailer was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 270 | } |
||||
| 271 | $imageUrl = $T->getThumbnail($width, $height); |
||||
| 272 | } |
||||
| 273 | |||||
| 274 | return $imageUrl; |
||||
| 275 | } |
||||
| 276 | |||||
| 277 | function app_utf8Decode($input){ |
||||
| 278 | if(is_array($input)){ |
||||
| 279 | $return = array(); |
||||
| 280 | foreach($input as $k=>$v){ |
||||
| 281 | $return[utf8_decode($k)] = app_utf8Decode($v); |
||||
| 282 | } |
||||
| 283 | }else{ |
||||
| 284 | return utf8_decode($input); |
||||
| 285 | } |
||||
| 286 | return $return; |
||||
| 287 | } |
||||
| 288 | |||||
| 289 | function app_utf8Encode($input){ |
||||
| 290 | if(is_array($input)){ |
||||
| 291 | $return = array(); |
||||
| 292 | foreach($input as $k=>$v){ |
||||
| 293 | $return[app_utf8Encode($k)] = app_utf8Encode($v); |
||||
| 294 | } |
||||
| 295 | }else{ |
||||
| 296 | return utf8_encode($input); |
||||
| 297 | } |
||||
| 298 | return $return; |
||||
| 299 | } |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths