mambax7 /
gwiki
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * wizard.php - wiki page creation wizard |
||
| 4 | * |
||
| 5 | * @copyright Copyright © 2013 geekwright, LLC. All rights reserved. |
||
| 6 | * @license gwiki/docs/license.txt GNU General Public License (GPL) |
||
| 7 | * @since 1.0 |
||
| 8 | * @author Richard Griffith <[email protected]> |
||
| 9 | * @package gwiki |
||
| 10 | */ |
||
| 11 | include __DIR__ . '/../../mainfile.php'; |
||
| 12 | $GLOBALS['xoopsOption']['template_main'] = 'gwiki_wizard.tpl'; |
||
| 13 | include XOOPS_ROOT_PATH . '/header.php'; |
||
| 14 | include_once __DIR__ . '/include/functions.php'; |
||
| 15 | include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
| 16 | global $wikiPage, $xoopsDB; |
||
| 17 | |||
| 18 | $token = 0; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @param $params |
||
| 22 | */ |
||
| 23 | function redirect_to_edit($params) |
||
| 24 | { |
||
| 25 | global $xoopsLogger, $wikiPage; |
||
| 26 | |||
| 27 | $url = XOOPS_URL . '/modules/' . $wikiPage->getWikiDir() . '/edit.php#wikipage'; |
||
| 28 | |||
| 29 | $_SESSION['gwikiwizard'] = serialize($params); |
||
| 30 | |||
| 31 | redirect_header($url, 1, _MD_GWIKI_WIZARD_FORWARDING); |
||
| 32 | exit; |
||
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @return bool |
||
| 37 | */ |
||
| 38 | function obtainPage() |
||
| 39 | { |
||
| 40 | global $wikiPage, $xoopsTpl, $token; |
||
| 41 | |||
| 42 | $wikiPage = new GwikiPage; |
||
| 43 | $prefixes = $wikiPage->getUserNamespaces(true); |
||
| 44 | if ($prefixes) { |
||
| 45 | $options = array(); |
||
| 46 | foreach ($prefixes as $p) { |
||
| 47 | $options[$p['prefix_id']] = $p['prefix']; |
||
| 48 | } |
||
| 49 | } else { |
||
| 50 | $err_message = _MD_GWIKI_NO_PAGE_PERMISSION; |
||
| 51 | redirect_header('index.php', 2, $err_message); |
||
| 52 | } |
||
| 53 | |||
| 54 | $page = ''; |
||
| 55 | |||
| 56 | $form = new XoopsThemeForm(_MD_GWIKI_WIZARD_NEWPAGE_PROMPT, 'gwizardform', 'wizard.php', 'POST', $token); |
||
| 57 | |||
| 58 | $form_ns_select = new XoopsFormSelect(_MD_GWIKI_WIZARD_PICK_NAMESPACE, 'nsid'); //, [mixed $value = null], [int $size = 1], [bool $multiple = false] ) |
||
| 59 | $form_ns_select->addOptionArray($options); |
||
|
0 ignored issues
–
show
|
|||
| 60 | $form->addElement($form_ns_select); |
||
| 61 | |||
| 62 | $form->addElement(new XoopsFormText(_MD_GWIKI_WIZARD_PAGE_NAME, 'page', 20, 120, $page)); |
||
| 63 | |||
| 64 | $btn_tray = new XoopsFormElementTray('', ' ', 'gwizardformtray'); |
||
| 65 | $submit_btn = new XoopsFormButton('', 'wikiwizard_submit', _MD_GWIKI_WIZARD_CONTINUE, 'submit'); |
||
| 66 | // $submit_btn->setExtra("onclick='prepForSubmit();'"); |
||
| 67 | $btn_tray->addElement($submit_btn); |
||
| 68 | |||
| 69 | $cancel_btn = new XoopsFormButton('', 'wikiwizard_cancel', _MD_GWIKI_WIZARD_CANCEL, 'button'); |
||
| 70 | $cancel_btn->setExtra(' onclick="document.location.href=\'index.php\';"'); |
||
| 71 | $btn_tray->addElement($cancel_btn); |
||
| 72 | |||
| 73 | $form->addElement($btn_tray); |
||
| 74 | |||
| 75 | $form->assign($xoopsTpl); |
||
| 76 | |||
| 77 | return true; |
||
| 78 | } |
||
| 79 | |||
| 80 | function obtainImportText() |
||
| 81 | { |
||
| 82 | global $wikiPage, $xoopsTpl, $token; |
||
| 83 | |||
| 84 | $form = new XoopsThemeForm(_MD_GWIKI_IMPORT_TEXT_TITLE, 'gwizardform', 'wizard.php', 'POST', $token); |
||
| 85 | $form->setExtra(' enctype="multipart/form-data" '); |
||
| 86 | |||
| 87 | $caption = _MD_GWIKI_IMPORT_TEXT_FILE; |
||
| 88 | $form->addElement(new XoopsFormFile($caption, 'import_file', $wikiPage->getMaxUploadSize()), false); |
||
| 89 | $form->addElement(new XoopsFormLabel('', _MD_GWIKI_IMPORT_TEXT_FORM_DESC, 'instructions')); |
||
| 90 | |||
| 91 | $btn_tray = new XoopsFormElementTray('', ' ', 'gwizardformtray'); |
||
| 92 | $submit_btn = new XoopsFormButton('', 'wikiwizard_submit', _MD_GWIKI_WIZARD_CONTINUE, 'submit'); |
||
| 93 | // $submit_btn->setExtra("onclick='prepForSubmit();'"); |
||
| 94 | $btn_tray->addElement($submit_btn); |
||
| 95 | |||
| 96 | $cancel_btn = new XoopsFormButton('', 'wikiwizard_cancel', _MD_GWIKI_WIZARD_CANCEL, 'button'); |
||
| 97 | $cancel_btn->setExtra(" onclick='history.back();'"); |
||
| 98 | $btn_tray->addElement($cancel_btn); |
||
| 99 | |||
| 100 | $form->addElement($btn_tray); |
||
| 101 | $form->addElement(new XoopsFormHidden('page', $wikiPage->keyword)); |
||
| 102 | $form->addElement(new XoopsFormHidden('op', 'doimporttext')); |
||
| 103 | |||
| 104 | $form->assign($xoopsTpl); |
||
| 105 | } |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @param $page |
||
| 109 | * @param $dir |
||
| 110 | * |
||
| 111 | * @return bool |
||
| 112 | */ |
||
| 113 | function doImportText($page, $dir) |
||
| 114 | { |
||
| 115 | $import = ''; |
||
| 116 | $pathname = XOOPS_ROOT_PATH . '/uploads/' . $dir . '/'; |
||
| 117 | View Code Duplication | if (isset($_POST['xoops_upload_file'][0])) { |
|
| 118 | $filekey = $_POST['xoops_upload_file'][0]; |
||
| 119 | if (isset($_FILES[$filekey]) && !$_FILES[$filekey]['error']) { |
||
| 120 | $zapus = array(' ', '/', '\\'); |
||
|
0 ignored issues
–
show
$zapus is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 121 | $filename = tempnam($pathname, 'IMPORTTEXT_'); |
||
| 122 | if (move_uploaded_file($_FILES[$filekey]['tmp_name'], $filename)) { |
||
| 123 | $import = file_get_contents($filename); |
||
| 124 | unlink($filename); |
||
| 125 | } else { |
||
| 126 | return false; |
||
| 127 | } |
||
| 128 | } |
||
| 129 | } |
||
| 130 | if (empty($import)) { |
||
| 131 | return false; |
||
| 132 | } |
||
| 133 | |||
| 134 | if (!empty($import)) { |
||
| 135 | $params = array( |
||
| 136 | 'page' => $page, |
||
| 137 | 'op' => 'preview', |
||
| 138 | 'body' => $import |
||
| 139 | ); |
||
| 140 | |||
| 141 | redirect_to_edit($params); |
||
| 142 | exit; |
||
| 143 | } |
||
| 144 | |||
| 145 | return false; |
||
| 146 | } |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @param string $import_html |
||
| 150 | */ |
||
| 151 | function obtainImportHTML($import_html = '') |
||
| 152 | { |
||
| 153 | global $wikiPage, $xoopsTpl, $token; |
||
| 154 | |||
| 155 | $form = new XoopsThemeForm(_MD_GWIKI_IMPORT_HTML_TITLE, 'gwizardform', 'wizard.php', 'POST', $token); |
||
| 156 | $form->setExtra(' enctype="multipart/form-data" '); |
||
| 157 | |||
| 158 | $caption = _MD_GWIKI_IMPORT_HTML_FILE; |
||
| 159 | $form->addElement(new XoopsFormFile($caption, 'import_file', $wikiPage->getMaxUploadSize()), false); |
||
| 160 | $form->addElement(new XoopsFormLabel('', _MD_GWIKI_IMPORT_HTML_FORM_DESC, 'instructions')); |
||
| 161 | |||
| 162 | $form->addElement(new XoopsFormTextArea(_MD_GWIKI_IMPORT_HTML_TEXT, 'import_html', htmlspecialchars($import_html), 10, 40)); |
||
| 163 | $btn_tray = new XoopsFormElementTray('', ' ', 'gwizardformtray'); |
||
| 164 | $submit_btn = new XoopsFormButton('', 'wikiwizard_submit', _MD_GWIKI_WIZARD_CONTINUE, 'submit'); |
||
| 165 | // $submit_btn->setExtra("onclick='prepForSubmit();'"); |
||
| 166 | $btn_tray->addElement($submit_btn); |
||
| 167 | |||
| 168 | $cancel_btn = new XoopsFormButton('', 'wikiwizard_cancel', _MD_GWIKI_WIZARD_CANCEL, 'button'); |
||
| 169 | $cancel_btn->setExtra(" onclick='history.back();'"); |
||
| 170 | $btn_tray->addElement($cancel_btn); |
||
| 171 | |||
| 172 | $form->addElement($btn_tray); |
||
| 173 | $form->addElement(new XoopsFormHidden('page', $wikiPage->keyword)); |
||
| 174 | $form->addElement(new XoopsFormHidden('op', 'doimporthtml')); |
||
| 175 | |||
| 176 | $form->assign($xoopsTpl); |
||
| 177 | } |
||
| 178 | |||
| 179 | /** |
||
| 180 | * @param $out |
||
| 181 | * @param DOMNode $domNode |
||
| 182 | * @param $nest |
||
| 183 | * @param $lt |
||
| 184 | * @param $ld |
||
| 185 | * @param $nop |
||
| 186 | */ |
||
| 187 | function showDOMNode(&$out, DOMNode $domNode, $nest, $lt, $ld, $nop) |
||
| 188 | { |
||
| 189 | foreach ($domNode->childNodes as $node) { |
||
| 190 | switch ($node->nodeName) { |
||
| 191 | case 'a': |
||
| 192 | $h = $node->getAttribute('href'); |
||
| 193 | $h = str_replace(array("\n", "\r"), '', $h); |
||
| 194 | if (!empty($h)) { |
||
| 195 | $out .= '[[' . $h . '|'; |
||
| 196 | if ($node->hasChildNodes()) { |
||
| 197 | showDOMNode($out, $node, $nest + 1, $lt, $ld, 1); |
||
| 198 | } |
||
| 199 | $out .= ' ]]'; |
||
| 200 | } |
||
| 201 | break; |
||
| 202 | case 'img': |
||
| 203 | $out .= '{{' . $node->getAttribute('src'); |
||
| 204 | $alt = trim($node->getAttribute('alt')); |
||
| 205 | if (!empty($alt)) { |
||
| 206 | $out .= '|' . $alt; |
||
| 207 | } |
||
| 208 | if ($node->hasChildNodes()) { |
||
| 209 | showDOMNode($out, $node, $nest + 1, $lt, $ld, $nop); |
||
| 210 | } |
||
| 211 | $out .= '}}'; |
||
| 212 | break; |
||
| 213 | View Code Duplication | case 'p': |
|
| 214 | if ($ld < 1) { |
||
| 215 | $out .= "\n\n"; |
||
| 216 | } |
||
| 217 | if ($node->hasChildNodes()) { |
||
| 218 | showDOMNode($out, $node, $nest + 1, $lt, $ld, $nop); |
||
| 219 | } |
||
| 220 | break; |
||
| 221 | View Code Duplication | case 'div': |
|
| 222 | $out .= "\n\n"; |
||
| 223 | if ($node->hasChildNodes()) { |
||
| 224 | showDOMNode($out, $node, $nest + 1, $lt, $ld, $nop); |
||
| 225 | } |
||
| 226 | $out .= "\n\n"; |
||
| 227 | break; |
||
| 228 | View Code Duplication | case 'blockquote': |
|
| 229 | $out .= "\n> "; |
||
| 230 | if ($node->hasChildNodes()) { |
||
| 231 | showDOMNode($out, $node, $nest + 1, $lt, $ld, $nop); |
||
| 232 | } |
||
| 233 | break; |
||
| 234 | View Code Duplication | case 'pre': |
|
| 235 | $out .= "\n{{{\n"; |
||
| 236 | if ($node->hasChildNodes()) { |
||
| 237 | showDOMNode($out, $node, $nest + 1, $lt, $ld, 0); |
||
| 238 | } |
||
| 239 | $out .= "\n}}}\n"; |
||
| 240 | break; |
||
| 241 | View Code Duplication | case 'ul': |
|
| 242 | $out .= "\n"; |
||
| 243 | if ($node->hasChildNodes()) { |
||
| 244 | showDOMNode($out, $node, $nest + 1, '*', $ld + 1, $nop); |
||
| 245 | } |
||
| 246 | $out .= "\n"; |
||
| 247 | break; |
||
| 248 | View Code Duplication | case 'ol': |
|
| 249 | $out .= "\n"; |
||
| 250 | if ($node->hasChildNodes()) { |
||
| 251 | showDOMNode($out, $node, $nest + 1, '#', $ld + 1, $nop); |
||
| 252 | } |
||
| 253 | $out .= "\n"; |
||
| 254 | break; |
||
| 255 | case 'li': |
||
| 256 | $out .= "\n"; |
||
| 257 | if ($ld === 0) { |
||
| 258 | $ld = 1; |
||
| 259 | } |
||
| 260 | if ($lt === '#') { |
||
| 261 | for ($i = 1; $i <= $ld; ++$i) { |
||
| 262 | $out .= '#'; |
||
| 263 | } |
||
| 264 | } else { |
||
| 265 | for ($i = 1; $i <= $ld; ++$i) { |
||
| 266 | $out .= '*'; |
||
| 267 | } |
||
| 268 | } |
||
| 269 | $out .= ' '; |
||
| 270 | if ($node->hasChildNodes()) { |
||
| 271 | showDOMNode($out, $node, $nest + 1, $lt, $ld, 1); |
||
| 272 | } |
||
| 273 | break; |
||
| 274 | View Code Duplication | case 'h1': |
|
| 275 | $out .= "\n= " . $node->getAttribute('href'); |
||
| 276 | if ($node->hasChildNodes()) { |
||
| 277 | showDOMNode($out, $node, $nest + 1, $lt, $ld, 1); |
||
| 278 | } |
||
| 279 | $out .= "\n"; |
||
| 280 | break; |
||
| 281 | View Code Duplication | case 'h2': |
|
| 282 | $out .= "\n== " . $node->getAttribute('href'); |
||
| 283 | if ($node->hasChildNodes()) { |
||
| 284 | showDOMNode($out, $node, $nest + 1, $lt, $ld, 1); |
||
| 285 | } |
||
| 286 | $out .= "\n"; |
||
| 287 | break; |
||
| 288 | View Code Duplication | case 'h3': |
|
| 289 | $out .= "\n=== " . $node->getAttribute('href'); |
||
| 290 | if ($node->hasChildNodes()) { |
||
| 291 | showDOMNode($out, $node, $nest + 1, $lt, $ld, $nop); |
||
| 292 | } |
||
| 293 | $out .= "\n"; |
||
| 294 | break; |
||
| 295 | View Code Duplication | case 'h4': |
|
| 296 | $out .= "\n=== " . $node->getAttribute('href'); |
||
| 297 | if ($node->hasChildNodes()) { |
||
| 298 | showDOMNode($out, $node, $nest + 1, $lt, $ld, $nop); |
||
| 299 | } |
||
| 300 | $out .= "\n"; |
||
| 301 | break; |
||
| 302 | View Code Duplication | case 'h5': |
|
| 303 | $out .= "\n===== " . $node->getAttribute('href'); |
||
| 304 | if ($node->hasChildNodes()) { |
||
| 305 | showDOMNode($out, $node, $nest + 1, $lt, $ld, $nop); |
||
| 306 | } |
||
| 307 | $out .= "\n"; |
||
| 308 | break; |
||
| 309 | case 'b': |
||
| 310 | View Code Duplication | case 'strong': |
|
| 311 | $out .= '**'; |
||
| 312 | if ($node->hasChildNodes()) { |
||
| 313 | showDOMNode($out, $node, $nest + 1, $lt, $ld, $nop); |
||
| 314 | } |
||
| 315 | $out .= '**'; |
||
| 316 | break; |
||
| 317 | case 'i': |
||
| 318 | View Code Duplication | case 'em': |
|
| 319 | $out .= '//'; |
||
| 320 | if ($node->hasChildNodes()) { |
||
| 321 | showDOMNode($out, $node, $nest + 1, $lt, $ld, $nop); |
||
| 322 | } |
||
| 323 | $out .= '//'; |
||
| 324 | break; |
||
| 325 | View Code Duplication | case 'u': |
|
| 326 | $out .= '__'; |
||
| 327 | if ($node->hasChildNodes()) { |
||
| 328 | showDOMNode($out, $node, $nest + 1, $lt, $ld, $nop); |
||
| 329 | } |
||
| 330 | $out .= '__'; |
||
| 331 | break; |
||
| 332 | case 'br': |
||
| 333 | $out .= '\\\\'; |
||
| 334 | break; |
||
| 335 | case 'hr': |
||
| 336 | $out .= "\n----\n"; |
||
| 337 | break; |
||
| 338 | View Code Duplication | case 'tr': |
|
| 339 | if ($node->hasChildNodes()) { |
||
| 340 | showDOMNode($out, $node, $nest + 1, $lt, $ld, $nop); |
||
| 341 | } |
||
| 342 | $out .= "|\n"; |
||
| 343 | break; |
||
| 344 | View Code Duplication | case 'td': |
|
| 345 | $out .= '|'; |
||
| 346 | if ($node->hasChildNodes()) { |
||
| 347 | showDOMNode($out, $node, $nest + 1, $lt, $ld, 1); |
||
| 348 | } |
||
| 349 | break; |
||
| 350 | View Code Duplication | case 'th': |
|
| 351 | $out .= '|='; |
||
| 352 | if ($node->hasChildNodes()) { |
||
| 353 | showDOMNode($out, $node, $nest + 1, $lt, $ld, 1); |
||
| 354 | } |
||
| 355 | break; |
||
| 356 | case '#text': |
||
| 357 | if ($nop) { |
||
| 358 | $out .= str_replace(array("\n", "\r", ' '), ' ', $node->nodeValue); |
||
| 359 | } else { |
||
| 360 | $out .= $node->nodeValue; |
||
| 361 | } |
||
| 362 | break; |
||
| 363 | default: |
||
| 364 | if ($node->hasChildNodes()) { |
||
| 365 | showDOMNode($out, $node, $nest + 1, $lt, $ld, $nop); |
||
| 366 | } |
||
| 367 | break; |
||
| 368 | } |
||
| 369 | } |
||
| 370 | } |
||
| 371 | |||
| 372 | /** |
||
| 373 | * @param $page |
||
| 374 | * @param $import_html |
||
| 375 | * @param $dir |
||
| 376 | * |
||
| 377 | * @return bool |
||
| 378 | */ |
||
| 379 | function doImportHTML($page, $import_html, $dir) |
||
| 380 | { |
||
| 381 | $import = ''; |
||
| 382 | $pathname = XOOPS_ROOT_PATH . '/uploads/' . $dir . '/'; |
||
| 383 | View Code Duplication | if (isset($_POST['xoops_upload_file'][0])) { |
|
| 384 | $filekey = $_POST['xoops_upload_file'][0]; |
||
| 385 | if (isset($_FILES[$filekey]) && !$_FILES[$filekey]['error']) { |
||
| 386 | $zapus = array(' ', '/', '\\'); |
||
|
0 ignored issues
–
show
$zapus is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 387 | $filename = tempnam($pathname, 'IMPORTHTML_'); |
||
| 388 | if (move_uploaded_file($_FILES[$filekey]['tmp_name'], $filename)) { |
||
| 389 | $import = file_get_contents($filename); |
||
| 390 | unlink($filename); |
||
| 391 | } else { |
||
| 392 | return false; |
||
| 393 | } |
||
| 394 | } |
||
| 395 | } |
||
| 396 | if (empty($import) && !empty($import_html)) { |
||
| 397 | $import = $import_html; |
||
| 398 | } |
||
| 399 | |||
| 400 | if (!empty($import)) { |
||
| 401 | // the "--" mark is common in text, but gets interpreted as strike |
||
| 402 | //$search = "#(?<=\s)(-{2})(?=\s)#"; |
||
| 403 | //$replace = "~\\1"; |
||
| 404 | //$import=preg_replace($search, $replace, $import); |
||
| 405 | |||
| 406 | $doc = new DOMDocument(); |
||
| 407 | $doc->loadHTML($import); |
||
| 408 | $domlist = $doc->getElementsByTagName('body'); |
||
| 409 | $out = ''; |
||
| 410 | foreach ($domlist as $node) { |
||
| 411 | showDOMNode($out, $node, 0, '', 0, 1); |
||
| 412 | } |
||
| 413 | |||
| 414 | $params = array( |
||
| 415 | 'page' => $page, |
||
| 416 | 'op' => 'preview', |
||
| 417 | 'body' => $out |
||
| 418 | ); |
||
| 419 | |||
| 420 | redirect_to_edit($params); |
||
| 421 | exit; |
||
| 422 | } |
||
| 423 | |||
| 424 | return false; |
||
| 425 | } |
||
| 426 | |||
| 427 | /** |
||
| 428 | * @param $page |
||
| 429 | * @param $templatename |
||
| 430 | * |
||
| 431 | * @return bool |
||
| 432 | */ |
||
| 433 | function doTemplate($page, $templatename) |
||
| 434 | { |
||
| 435 | global $wikiPage, $xoopsDB; |
||
| 436 | |||
| 437 | $p = $wikiPage->getPage($templatename); |
||
| 438 | if ($p) { |
||
| 439 | $params = array( |
||
| 440 | 'page' => $page, |
||
| 441 | 'op' => 'preview', |
||
| 442 | 'body' => $p['body'] |
||
| 443 | ); |
||
| 444 | |||
| 445 | redirect_to_edit($params); |
||
| 446 | } |
||
| 447 | redirect_header(XOOPS_URL . "/modules/{$wikiPage->getWikiDir()}/wizard.php?page={$page}", 2, _MD_GWIKI_PAGENOTFOUND); |
||
| 448 | |||
| 449 | return false; |
||
| 450 | } |
||
| 451 | |||
| 452 | function doGallery() |
||
| 453 | { |
||
| 454 | global $wikiPage, $xoopsDB; |
||
| 455 | |||
| 456 | $page = $wikiPage->keyword; |
||
| 457 | |||
| 458 | $params = array( |
||
| 459 | 'page' => $page, |
||
| 460 | 'op' => 'preview', |
||
| 461 | 'body' => '{gallery}' |
||
| 462 | ); |
||
| 463 | |||
| 464 | redirect_to_edit($params); |
||
| 465 | } |
||
| 466 | |||
| 467 | /** |
||
| 468 | * @param $page |
||
| 469 | * @param $templatename |
||
| 470 | * |
||
| 471 | * @return bool |
||
| 472 | */ |
||
| 473 | function doCopy($page, $templatename) |
||
| 474 | { |
||
| 475 | global $wikiPage, $xoopsDB; |
||
| 476 | |||
| 477 | $p = $wikiPage->getPage($templatename); |
||
| 478 | if ($p) { |
||
| 479 | $params = array( |
||
| 480 | 'page' => $page, |
||
| 481 | 'op' => 'preview', |
||
| 482 | 'body' => $p['body'], |
||
| 483 | 'title' => $p['title'], |
||
| 484 | 'display_keyword' => $page, |
||
| 485 | 'parent_page' => $p['parent_page'], |
||
| 486 | 'page_set_home' => $p['page_set_home'], |
||
| 487 | 'page_set_order' => '', |
||
| 488 | 'meta_description' => $p['meta_description'], |
||
| 489 | 'meta_keywords' => $p['meta_keywords'], |
||
| 490 | 'show_in_index' => '1', |
||
| 491 | 'leave_inactive' => '0' |
||
| 492 | ); |
||
| 493 | |||
| 494 | redirect_to_edit($params); |
||
| 495 | } |
||
| 496 | redirect_header(XOOPS_URL . "/modules/{$wikiPage->getWikiDir()}/wizard.php?page={$page}", 2, _MD_GWIKI_PAGENOTFOUND); |
||
| 497 | |||
| 498 | return false; |
||
| 499 | } |
||
| 500 | |||
| 501 | /** |
||
| 502 | * @param $keyword_like |
||
| 503 | * |
||
| 504 | * @return array|bool |
||
| 505 | */ |
||
| 506 | function getPagesLike($keyword_like) |
||
| 507 | { |
||
| 508 | global $wikiPage, $xoopsDB; |
||
| 509 | |||
| 510 | $pages = false; |
||
| 511 | |||
| 512 | if (!empty($keyword_like)) { |
||
| 513 | $q_keyword = $wikiPage->escapeForDB($keyword_like . '%'); |
||
| 514 | |||
| 515 | $sql = 'SELECT keyword, display_keyword FROM ' . $xoopsDB->prefix('gwiki_pages'); |
||
| 516 | $sql .= " WHERE keyword like '{$q_keyword}'"; |
||
| 517 | $sql .= ' AND active = 1'; |
||
| 518 | $sql .= ' ORDER BY display_keyword '; |
||
| 519 | $pages = array(); |
||
| 520 | $result = $xoopsDB->query($sql); |
||
| 521 | while ($myrow = $xoopsDB->fetchArray($result)) { |
||
| 522 | $pages[$myrow['keyword']] = $myrow['display_keyword']; |
||
| 523 | } |
||
| 524 | } |
||
| 525 | |||
| 526 | return $pages; |
||
| 527 | } |
||
| 528 | |||
| 529 | /** |
||
| 530 | * @return bool |
||
| 531 | */ |
||
| 532 | function galleryForm() |
||
| 533 | { |
||
| 534 | global $wikiPage, $xoopsTpl, $xoopsModuleConfig; |
||
| 535 | |||
| 536 | $page = $wikiPage->keyword; |
||
| 537 | $title = _MD_GWIKI_WIZARD_GALLERY_SELECT; |
||
| 538 | $body = array(); |
||
| 539 | $body[] = '<div class="wikiimagedetail">'; |
||
| 540 | $body[] = '<form id="wikieditimg_form" action="ajaximgedit.php" method="POST" enctype="multipart/form-data">'; |
||
| 541 | $body[] = '<input type="hidden" id="MAX_FILE_SIZE" name="MAX_FILE_SIZE" value="' . $wikiPage->getMaxUploadSize() . '" />'; |
||
| 542 | $body[] = '<input type="hidden" id="page" name="page" value="' . $page . '" />'; |
||
| 543 | $body[] = '<div id="wikieditimg_dd">'; |
||
| 544 | // $body[] = '<img name="wikieditimg_img" id="wikieditimg_img" class="wikieditimg" src="assets/images/blank.png" /><br>'; |
||
| 545 | $body[] = '<span id="wikieditimg_dd_msg">' . _MD_GWIKI_IMAGES_DROPHERE . '</span>'; |
||
| 546 | $body[] = '<div id="gwikiimgform_nofiledrag">' . _MD_GWIKI_IMAGES_PICKFILE . '<input type="file" id="wikieditimg_fileselect" name="fileselect[]" multiple="multiple"/></div>'; |
||
| 547 | $body[] = '<div id="wikieditimg_progress"></div>'; |
||
| 548 | $body[] = '</div>'; |
||
| 549 | $body[] = '</form>'; |
||
| 550 | $body[] = '</div>'; |
||
| 551 | $body[] = '<form id="gwizardform" name="gwizardform" action="wizard.php" method="POST">'; |
||
| 552 | $body[] = '<table class="wikiwizard_table">'; |
||
| 553 | $body[] = '<tr><td></td><td><hr /></td></tr>'; |
||
| 554 | $body[] = '<tr><td> </td><td>'; |
||
| 555 | $body[] = '<input type="hidden" name="page" value="' . $page . '">'; |
||
| 556 | $body[] = '<input type="hidden" name="op" value="addgallery">'; |
||
| 557 | $body[] = '<input type="submit" class="formButton" name="wikiwizard_submit" id="wikiwizard_submit" value="' . _MD_GWIKI_WIZARD_CONTINUE . '" />'; |
||
| 558 | $body[] = '<input type="button" class="formButton" name="wikiwizard_cancel" id="wikiwizard_cancel" value="' . _MD_GWIKI_WIZARD_CANCEL . '" onclick="document.location.href=\'wizard.php\';" />'; |
||
| 559 | $body[] = '</td></tr>'; |
||
| 560 | $body[] = '</table>'; |
||
| 561 | $body[] = '</form>'; |
||
| 562 | |||
| 563 | $xoopsTpl->assign('body', implode("\n", $body)); |
||
| 564 | $xoopsTpl->assign('title', $title); |
||
| 565 | |||
| 566 | return true; |
||
| 567 | } |
||
| 568 | |||
| 569 | /** |
||
| 570 | * @return bool |
||
| 571 | */ |
||
| 572 | function chooseWizard() |
||
| 573 | { |
||
| 574 | global $wikiPage, $xoopsTpl, $xoopsModuleConfig; |
||
| 575 | |||
| 576 | $wizopts = array(); |
||
| 577 | |||
| 578 | $template_namespace = $xoopsModuleConfig['template_namespace']; |
||
| 579 | if (!empty($template_namespace)) { |
||
| 580 | $templates = getPagesLike($template_namespace); |
||
| 581 | if ($templates) { |
||
| 582 | $wizopts[] = array( |
||
| 583 | 'name' => 'template', |
||
| 584 | 'title' => _MD_GWIKI_WIZARD_TEMPLATE_TITLE, |
||
| 585 | 'description' => _MD_GWIKI_WIZARD_TEMPLATE_DESC, |
||
| 586 | 'options' => array( |
||
| 587 | array('type' => 'select', 'prompt' => '', 'name' => 'templatename', 'values' => $templates) |
||
| 588 | ) |
||
| 589 | ); |
||
| 590 | } |
||
| 591 | } |
||
| 592 | |||
| 593 | $wizopts[] = array( |
||
| 594 | 'name' => 'copy', |
||
| 595 | 'title' => _MD_GWIKI_WIZARD_COPY_TITLE, |
||
| 596 | 'description' => _MD_GWIKI_WIZARD_COPY_DESC, |
||
| 597 | 'options' => array( |
||
| 598 | array('type' => 'text', 'prompt' => _MD_GWIKI_WIZARD_COPY_PAGE, 'name' => 'copykeyword', 'values' => '') |
||
| 599 | ) |
||
| 600 | ); |
||
| 601 | |||
| 602 | $wizopts[] = array( |
||
| 603 | 'name' => 'importhtml', |
||
| 604 | 'title' => _MD_GWIKI_WIZARD_HTML_TITLE, |
||
| 605 | 'description' => _MD_GWIKI_WIZARD_HTML_DESC, |
||
| 606 | 'options' => null |
||
| 607 | ); |
||
| 608 | |||
| 609 | $wizopts[] = array( |
||
| 610 | 'name' => 'importtext', |
||
| 611 | 'title' => _MD_GWIKI_WIZARD_TEXT_TITLE, |
||
| 612 | 'description' => _MD_GWIKI_WIZARD_TEXT_DESC, |
||
| 613 | 'options' => null |
||
| 614 | ); |
||
| 615 | |||
| 616 | $wizopts[] = array( |
||
| 617 | 'name' => 'gallery', |
||
| 618 | 'title' => _MD_GWIKI_WIZARD_GALLERY_TITLE, |
||
| 619 | 'description' => _MD_GWIKI_WIZARD_GALLERY_DESC, |
||
| 620 | 'options' => null |
||
| 621 | ); |
||
| 622 | |||
| 623 | $page = $wikiPage->keyword; |
||
| 624 | $title = _MD_GWIKI_WIZARD_OPTIONS_TITLE; |
||
| 625 | $body = array(); |
||
| 626 | $body[] = '<form id="gwizardform" name="gwizardform" action="wizard.php" method="POST">'; |
||
| 627 | $body[] = '<table class="wikiwizard_table">'; |
||
| 628 | foreach ($wizopts as $i => $opt) { |
||
| 629 | $rid = 'radio_id_' . $opt['name']; |
||
| 630 | $body[] = '<tr><td> </td><td><span class="wikiwizard_formcaption">' . $opt['title'] . '</span></td></tr>'; |
||
| 631 | $body[] = '<tr><td> <input type="radio" name="op" id="' . $rid . '" value="' . $opt['name'] . '"></td><td>' . $opt['description'] . '</td></tr>'; |
||
| 632 | if (!empty($opt['options'])) { |
||
| 633 | foreach ($opt['options'] as $value) { |
||
| 634 | switch ($value['type']) { |
||
| 635 | case 'select': |
||
| 636 | $body[] = '<tr><td>' . $value['prompt'] . '</td><td><select name="' . $value['name'] . '" id="' . $value['name'] . '" onchange="setRadioButton(\'' . $rid . '\');">'; |
||
| 637 | foreach ($value['values'] as $n => $v) { |
||
|
0 ignored issues
–
show
|
|||
| 638 | $body[] = '<option value="' . $n . '">' . $v . '</option>'; |
||
| 639 | } |
||
| 640 | $body[] = '</select></td></tr>'; |
||
| 641 | break; |
||
| 642 | case 'text': |
||
| 643 | $body[] = '<tr><td> </td><td>' . $value['prompt'] . ' <input name="' . $value['name'] . '" id="' . $value['name'] . '" value="' . $value['values'] |
||
| 644 | . '" onchange="setRadioButton(\'' . $rid . '\');"></td></tr>'; |
||
| 645 | break; |
||
| 646 | default: |
||
| 647 | break; |
||
| 648 | } |
||
| 649 | } |
||
| 650 | } |
||
| 651 | $body[] = '<tr><td></td><td><hr /></td></tr>'; |
||
| 652 | } |
||
| 653 | $body[] = '<tr><td> </td><td>'; |
||
| 654 | $body[] = '<input type="hidden" name="page" value="' . $page . '">'; |
||
| 655 | $body[] = '<input type="submit" class="formButton" name="wikiwizard_submit" id="wikiwizard_submit" value="' . _MD_GWIKI_WIZARD_CONTINUE . '" />'; |
||
| 656 | $body[] = '<input type="button" class="formButton" name="wikiwizard_cancel" id="wikiwizard_cancel" value="' . _MD_GWIKI_WIZARD_CANCEL . '" onclick="document.location.href=\'wizard.php\';" />'; |
||
| 657 | $body[] = '</td></tr>'; |
||
| 658 | $body[] = '</table>'; |
||
| 659 | $body[] = '</form>'; |
||
| 660 | |||
| 661 | $xoopsTpl->assign('body', implode("\n", $body)); |
||
| 662 | $xoopsTpl->assign('title', $title); |
||
| 663 | |||
| 664 | return true; |
||
| 665 | } |
||
| 666 | |||
| 667 | $page = ''; |
||
| 668 | if (isset($_GET['page'])) { |
||
| 669 | $page = cleaner($_GET['page']); |
||
| 670 | } |
||
| 671 | if (isset($_POST['page'])) { |
||
| 672 | $page = cleaner($_POST['page']); |
||
| 673 | } |
||
| 674 | // namespace id (prefix_id) is set by newpage block, turn it into a full page name |
||
| 675 | if (isset($_REQUEST['nsid'])) { |
||
| 676 | $page = $wikiPage->makeKeywordFromPrefix((int)$_REQUEST['nsid'], $page); |
||
| 677 | } |
||
| 678 | |||
| 679 | $op = ''; |
||
| 680 | if (isset($_POST['op'])) { |
||
| 681 | $op = cleaner($_POST['op']); |
||
| 682 | } |
||
| 683 | $import_html = ''; |
||
| 684 | if (isset($_POST['import_html'])) { |
||
| 685 | $import_html = cleaner($_POST['import_html']); |
||
| 686 | } |
||
| 687 | $templatename = ''; |
||
| 688 | if (isset($_POST['templatename'])) { |
||
| 689 | $templatename = cleaner($_POST['templatename']); |
||
| 690 | } |
||
| 691 | $copykeyword = ''; |
||
| 692 | if (isset($_POST['copykeyword'])) { |
||
| 693 | $copykeyword = cleaner($_POST['copykeyword']); |
||
| 694 | } |
||
| 695 | if (empty($page)) { |
||
| 696 | $pageX = false; |
||
| 697 | $op = 'page'; |
||
| 698 | $mayEdit = false; |
||
| 699 | } else { |
||
| 700 | $pageX = $wikiPage->getPage($page); |
||
| 701 | $mayEdit = $wikiPage->checkEdit(); |
||
| 702 | if (!$mayEdit) { |
||
| 703 | $err_message = _MD_GWIKI_NO_PAGE_PERMISSION; |
||
| 704 | redirect_header("index.php?page=$page", 2, $err_message); |
||
| 705 | } |
||
| 706 | } |
||
| 707 | |||
| 708 | if ($pageX) { |
||
| 709 | $pageX['author'] = $wikiPage->getUserName($wikiPage->uid); |
||
| 710 | $pageX['revisiontime'] = date($wikiPage->dateFormat, $pageX['lastmodified']); |
||
| 711 | $pageX['mayEdit'] = $mayEdit; |
||
| 712 | $pageX['pageFound'] = true; |
||
| 713 | View Code Duplication | } else { |
|
| 714 | $pageX = array(); |
||
| 715 | $uid = $xoopsUser ? $xoopsUser->getVar('uid') : 0; |
||
| 716 | $pageX['uid'] = $uid; |
||
| 717 | $pageX['author'] = $wikiPage->getUserName($uid); |
||
| 718 | $pageX['revisiontime'] = date($wikiPage->dateFormat); |
||
| 719 | $pageX['mayEdit'] = $mayEdit; |
||
| 720 | $pageX['keyword'] = $page; |
||
| 721 | $pageX['pageFound'] = false; |
||
| 722 | } |
||
| 723 | |||
| 724 | $dir = basename(__DIR__); |
||
| 725 | $pageX['moddir'] = $dir; |
||
| 726 | $pageX['modpath'] = XOOPS_ROOT_PATH . '/modules/' . $dir; |
||
| 727 | $pageX['modurl'] = XOOPS_URL . '/modules/' . $dir; |
||
| 728 | $pageX['ineditor'] = false; |
||
| 729 | |||
| 730 | switch ($op) { |
||
| 731 | case 'page': |
||
| 732 | obtainPage(); |
||
| 733 | break; |
||
| 734 | case 'importtext': |
||
| 735 | obtainImportText(); |
||
| 736 | break; |
||
| 737 | case 'doimporttext': |
||
| 738 | doImportText($page, $dir); |
||
| 739 | obtainImportText(); // if we come back, we failed so try again |
||
| 740 | break; |
||
| 741 | case 'importhtml': |
||
| 742 | obtainImportHTML($import_html); |
||
| 743 | break; |
||
| 744 | case 'doimporthtml': |
||
| 745 | doImportHTML($page, $import_html, $dir); |
||
| 746 | obtainImportHTML($import_html); // if we come back, we failed so try again |
||
| 747 | break; |
||
| 748 | case 'template': |
||
| 749 | doTemplate($page, $templatename); |
||
| 750 | chooseWizard(); |
||
| 751 | break; |
||
| 752 | case 'copy': |
||
| 753 | doCopy($page, $copykeyword); |
||
| 754 | chooseWizard(); |
||
| 755 | break; |
||
| 756 | case 'gallery': |
||
| 757 | galleryForm(); |
||
| 758 | break; |
||
| 759 | case 'addgallery': |
||
| 760 | doGallery(); |
||
| 761 | break; |
||
| 762 | default: |
||
| 763 | chooseWizard(); |
||
| 764 | break; |
||
| 765 | } |
||
| 766 | |||
| 767 | $title = _MD_GWIKI_WIZARD; |
||
| 768 | $xoopsTpl->assign('xoops_pagetitle', $title); |
||
| 769 | $xoopsTpl->assign('gwiki', $pageX); |
||
| 770 | |||
| 771 | if (!empty($err_message)) { |
||
| 772 | $xoopsTpl->assign('err_message', $err_message); |
||
| 773 | } |
||
| 774 | if (!empty($message)) { |
||
| 775 | $xoopsTpl->assign('message', $message); |
||
| 776 | } |
||
| 777 | |||
| 778 | $xoTheme->addStylesheet(XOOPS_URL . '/modules/gwiki/assets/css/module.css'); |
||
| 779 | |||
| 780 | include XOOPS_ROOT_PATH . '/footer.php'; |
||
| 781 |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: