Esempio n. 1
0
 /**
  * @param $id
  */
 public static function clearEditSessionVars($id)
 {
     $id = (int) $id;
     $session =& PublisherSession::getInstance();
     $session->del("publisher_editMime_{$id}");
     $session->del("publisher_editMimeErr_{$id}");
 }
Esempio n. 2
0
/**
 * @param bool $another
 * @param bool $withRedirect
 * @param  $itemObj
 * @return bool|string
 */
function publisher_uploadFile($another = false, $withRedirect = true, &$itemObj)
{
    include_once PUBLISHER_ROOT_PATH . '/class/uploader.php';
    global $publisher_isAdmin, $xoopsUser;
    $publisher = PublisherPublisher::getInstance();
    $itemid = isset($_POST['itemid']) ? intval($_POST['itemid']) : 0;
    $uid = is_object($xoopsUser) ? $xoopsUser->uid() : 0;
    $session = PublisherSession::getInstance();
    $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']) ? intval($_POST['item_file_status']) : 1);
    $session->set('publisher_file_uid', $uid);
    $session->set('publisher_file_itemid', $itemid);
    if (!is_object($itemObj)) {
        $itemObj = $publisher->getHandler('item')->get($itemid);
    }
    $fileObj = $publisher->getHandler('file')->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']) ? intval($_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->getHandler('mimetype')->getArrayByType();
    // TODO : display the available mimetypes to the user
    $errors = array();
    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) {
                redirect_header("file.php?op=mod&itemid=" . $itemid, 5, $message);
            } else {
                return $message;
            }
        }
    }
    // Storing the file
    if (!$fileObj->store($allowed_mimetypes)) {
        if ($withRedirect) {
            redirect_header("file.php?op=mod&itemid=" . $fileObj->itemid(), 3, _CO_PUBLISHER_FILEUPLOAD_ERROR . publisher_formatErrors($fileObj->getErrors()));
            exit;
        } else {
            return _CO_PUBLISHER_FILEUPLOAD_ERROR . publisher_formatErrors($fileObj->getErrors());
        }
    }
    if ($withRedirect) {
        $redirect_page = $another ? 'file.php' : 'item.php';
        redirect_header($redirect_page . "?op=mod&itemid=" . $fileObj->itemid(), 2, _CO_PUBLISHER_FILEUPLOAD_SUCCESS);
    } else {
        return true;
    }
}
Esempio n. 3
0
/**
 * @param  bool        $another
 * @param  bool        $withRedirect
 * @param              $itemObj
 * @return bool|string
 */
function publisherUploadFile($another = false, $withRedirect = true, &$itemObj)
{
    include_once PUBLISHER_ROOT_PATH . '/class/uploader.php';
    //    global $publisherIsAdmin;
    $publisher =& PublisherPublisher::getInstance();
    $itemId = XoopsRequest::getInt('itemid', 0, 'POST');
    $uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->uid() : 0;
    $session =& PublisherSession::getInstance();
    $session->set('publisher_file_filename', XoopsRequest::getString('item_file_name', '', 'POST'));
    $session->set('publisher_file_description', XoopsRequest::getString('item_file_description', '', 'POST'));
    $session->set('publisher_file_status', XoopsRequest::getInt('item_file_status', 1, 'POST'));
    $session->set('publisher_file_uid', $uid);
    $session->set('publisher_file_itemid', $itemId);
    if (!is_object($itemObj)) {
        $itemObj =& $publisher->getHandler('item')->get($itemId);
    }
    $fileObj =& $publisher->getHandler('file')->create();
    $fileObj->setVar('name', XoopsRequest::getString('item_file_name', '', 'POST'));
    $fileObj->setVar('description', XoopsRequest::getString('item_file_description', '', 'POST'));
    $fileObj->setVar('status', XoopsRequest::getInt('item_file_status', 1, 'POST'));
    $fileObj->setVar('uid', $uid);
    $fileObj->setVar('itemid', $itemObj->getVar('itemid'));
    $fileObj->setVar('datesub', time());
    // Get available mimetypes for file uploading
    $allowedMimetypes =& $publisher->getHandler('mimetype')->getArrayByType();
    // TODO : display the available mimetypes to the user
    $errors = array();
    if ($publisher->getConfig('perm_upload') && is_uploaded_file($_FILES['item_upload_file']['tmp_name'])) {
        if (!($ret = $fileObj->checkUpload('item_upload_file', $allowedMimetypes, $errors))) {
            $errorstxt = implode('<br />', $errors);
            $message = sprintf(_CO_PUBLISHER_MESSAGE_FILE_ERROR, $errorstxt);
            if ($withRedirect) {
                redirect_header('file.php?op=mod&itemid=' . $itemId, 5, $message);
            } else {
                return $message;
            }
        }
    }
    // Storing the file
    if (!$fileObj->store($allowedMimetypes)) {
        //        if ($withRedirect) {
        //            redirect_header("file.php?op=mod&itemid=" . $fileObj->itemid(), 3, _CO_PUBLISHER_FILEUPLOAD_ERROR . publisherFormatErrors($fileObj->getErrors()));
        //            exit;
        //        }
        try {
            if ($withRedirect) {
                throw new Exception(_CO_PUBLISHER_FILEUPLOAD_ERROR . publisherFormatErrors($fileObj->getErrors()));
            }
        } catch (Exception $e) {
            redirect_header('file.php?op=mod&itemid=' . $fileObj->itemid(), 3, _CO_PUBLISHER_FILEUPLOAD_ERROR . publisherFormatErrors($fileObj->getErrors()));
        }
        //    } else {
        //        return _CO_PUBLISHER_FILEUPLOAD_ERROR . publisherFormatErrors($fileObj->getErrors());
    }
    if ($withRedirect) {
        $redirectPage = $another ? 'file.php' : 'item.php';
        redirect_header($redirectPage . '?op=mod&itemid=' . $fileObj->itemid(), 2, _CO_PUBLISHER_FILEUPLOAD_SUCCESS);
    } else {
        return true;
    }
    return null;
}
Esempio n. 4
0
function _clearEditSessionVars($id)
{
    $id = intval($id);
    $session = PublisherSession::getInstance();
    $session->del("publisher_editMime_{$id}");
    $session->del("publisher_editMimeErr_{$id}");
}