* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) * @author Richard Griffith <*****@*****.**> * @author trabis <*****@*****.**> */ use Xmf\Debug; use Xmf\Highlighter; use Xmf\Metagen; use Xmf\Request; use Xmf\Module\Permission; use Xmf\Module\Session; include dirname(dirname(__DIR__)) . '/mainfile.php'; $xoops = Xoops::getInstance(); $xoops->header(); // work with session data in our module context echo '<h2>Session demo</h2><h4>Toggle a session variable</h4>'; $sessionHelper = new Session(); if ($sessionHelper) { $var = $sessionHelper->get('fred'); if ($var) { echo sprintf('Clearing session variable value of "%s"', $var) . '<br />'; $sessionHelper->destroy(); } else { $var = date('Y-m-d H:i:s'); echo sprintf('Session variable not set. Setting as: %s', $var) . '<br />'; $sessionHelper->set('fred', $var); } } echo '<h2>Permission demo</h2>'; $permissionHelper = new Permission(); if ($permissionHelper) { // this is the name and item we are going to work with
*/ /** * @copyright 2014 XOOPS Project (http://xoops.org) * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) * @author Richard Griffith <*****@*****.**> */ use Xoops\Core\Request; use Xmf\Module\Session; include dirname(dirname(__DIR__)) . '/mainfile.php'; $xoops = \Xoops::getInstance(); $xoops->header(); $dir = basename(__DIR__); $helper = $xoops->getModuleHelper($dir); $config_test_dir = $helper->getConfig('test_dir'); $test_dir = $config_test_dir; $sessionHelper = new Session(); if ($sessionHelper) { $var = $sessionHelper->get('test_dir'); if ($var) { $test_dir = $var; } } // if this is a post operation get our test_dir, save it and redirect to app if ('GET' == Request::getMethod()) { $var = Request::getVar('test_dir', '', $hash = 'GET'); if (!empty($var)) { launchApp($var); } } // if this is a post operation get our test_dir, save it and redirect to app if ('POST' == Request::getMethod()) {
function _clearEditSessionVars($id) { $id = (int) $id; $session = new Session(); $session->del("publisher_editMime_{$id}"); $session->del("publisher_editMimeErr_{$id}"); }
/** * @param bool $another * @param bool $withRedirect * @param $itemObj * * @return bool|string */ public static function uploadFile($another = false, $withRedirect = true, &$itemObj) { $xoops = Xoops::getInstance(); $publisher = Publisher::getInstance(); $itemid = isset($_POST['itemid']) ? (int) $_POST['itemid'] : 0; $uid = $xoops->isUser() ? $xoops->user->getVar('uid') : 0; $session = new Session(); $session->set('publisher_file_filename', isset($_POST['item_file_name']) ? $_POST['item_file_name'] : ''); $session->set('publisher_file_description', isset($_POST['item_file_description']) ? $_POST['item_file_description'] : ''); $session->set('publisher_file_status', isset($_POST['item_file_status']) ? (int) $_POST['item_file_status'] : 1); $session->set('publisher_file_uid', $uid); $session->set('publisher_file_itemid', $itemid); if (!is_object($itemObj)) { $itemObj = $publisher->getItemHandler()->get($itemid); } $fileObj = $publisher->getFileHandler()->create(); $fileObj->setVar('name', isset($_POST['item_file_name']) ? $_POST['item_file_name'] : ''); $fileObj->setVar('description', isset($_POST['item_file_description']) ? $_POST['item_file_description'] : ''); $fileObj->setVar('status', isset($_POST['item_file_status']) ? (int) $_POST['item_file_status'] : 1); $fileObj->setVar('uid', $uid); $fileObj->setVar('itemid', $itemObj->getVar('itemid')); $fileObj->setVar('datesub', time()); // Get available mimetypes for file uploading $allowed_mimetypes = $publisher->getMimetypeHandler()->getArrayByType(); // TODO : display the available mimetypes to the user $errors = array(); /* @var $fileObj PublisherFile */ if ($publisher->getConfig('perm_upload') && is_uploaded_file($_FILES['item_upload_file']['tmp_name'])) { if (!($ret = $fileObj->checkUpload('item_upload_file', $allowed_mimetypes, $errors))) { $errorstxt = implode('<br />', $errors); $message = sprintf(_CO_PUBLISHER_MESSAGE_FILE_ERROR, $errorstxt); if ($withRedirect) { $xoops->redirect("file.php?op=mod&itemid=" . $itemid, 5, $message); } else { return $message; } } } // Storing the file if (!$fileObj->store($allowed_mimetypes)) { if ($withRedirect) { $xoops->redirect("file.php?op=mod&itemid=" . $fileObj->getVar('itemid'), 3, _CO_PUBLISHER_FILEUPLOAD_ERROR . self::formatErrors($fileObj->getErrors())); } else { return _CO_PUBLISHER_FILEUPLOAD_ERROR . self::formatErrors($fileObj->getErrors()); } } if ($withRedirect) { $redirect_page = $another ? 'file.php' : 'item.php'; $xoops->redirect($redirect_page . "?op=mod&itemid=" . $fileObj->getVar('itemid'), 2, _CO_PUBLISHER_FILEUPLOAD_SUCCESS); } return true; }