function plugin_attach_action() { global $vars, $_attach_messages; // Backward compatible if (isset($vars['openfile'])) { $vars['file'] = $vars['openfile']; $vars['pcmd'] = 'open'; } if (isset($vars['delfile'])) { $vars['file'] = $vars['delfile']; $vars['pcmd'] = 'delete'; } $pcmd = isset($vars['pcmd']) ? $vars['pcmd'] : ''; $refer = isset($vars['refer']) ? $vars['refer'] : ''; $pass = isset($vars['pass']) ? $vars['pass'] : NULL; $page = isset($vars['page']) ? $vars['page'] : ''; if ($refer != '' && is_pagename($refer)) { if (in_array($pcmd, array('info', 'open', 'list'))) { check_readable($refer); } else { check_editable($refer); } } // Dispatch if (isset($_FILES['attach_file'])) { // Upload return attach_upload($_FILES['attach_file'], $refer, $pass); } else { switch ($pcmd) { case 'delete': /*FALLTHROUGH*/ /*FALLTHROUGH*/ case 'freeze': case 'unfreeze': if (PKWK_READONLY) { die_message('PKWK_READONLY prohibits editing'); } } switch ($pcmd) { case 'info': return attach_info(); case 'delete': return attach_delete(); case 'open': return attach_open(); case 'list': return attach_list(); case 'freeze': return attach_freeze(TRUE); case 'unfreeze': return attach_freeze(FALSE); case 'rename': return attach_rename(); case 'upload': return attach_showform(); } if ($page == '' || !is_page($page)) { return attach_list(); } else { return attach_showform(); } } }
function attach_showform() { global $vars, $_attach_messages, $_string; if (Auth::check_role('safemode')) { die_message($_string['prohibit']); } $page = isset($vars['page']) ? $vars['page'] : null; if (empty($page)) { Utility::dieMessage('Page name is not defined'); } $isEditable = Factory::Wiki($page)->isEditable(); $vars['refer'] = $page; $html = array(); if (!IS_AJAX) { $attach_list = attach_list($page); $html[] = '<p><small>[<a href="' . Router::get_cmd_uri('attach', null, null, array('pcmd' => 'list')) . '">' . $_attach_messages['msg_listall'] . '</a>]</small></p>'; if ($isEditable) { $html[] = '<h2>' . str_replace('$1', $page, $_attach_messages['msg_upload']) . '</h2>' . "\n"; $html[] = attach_form($page); } $html[] = '<h2>' . str_replace('$1', $page, $_attach_messages['msg_listpage']) . '</h2>' . "\n"; $html[] = $attach_list['body']; } else { $html[] = '<div class="tabs" role="application">'; $html[] = '<ul role="tablist">'; if ($isEditable) { $html[] = '<li role="tab"><a href="' . Router::get_cmd_uri('attach', null, null, array('pcmd' => 'form', 'refer' => $page)) . '">' . str_replace('$1', $_attach_messages['msg_thispage'], $_attach_messages['msg_upload']) . '</a></li>'; } $html[] = '<li role="tab"><a href="' . Router::get_cmd_uri('attach', null, null, array('pcmd' => 'list', 'refer' => $page)) . '">' . str_replace('$1', $_attach_messages['msg_thispage'], $_attach_messages['msg_listpage']) . '</a></li>'; $html[] = '</ul>'; $html[] = '</div>'; } return array('msg' => $_attach_messages['msg_upload'], 'body' => join("\n", $html)); }