示例#1
0
 public function addsubmitAction()
 {
     $oConfig = new Zend_Config_Ini(APPLICATION_PATH . '/configs/wizytowki.ini', 'wizytowki');
     $oRequest = $this->getRequest();
     $oMimeValidator = new Zend_Validate_File_MimeType('image/jpg, image/jpeg');
     $oMimeValidator->setMessage('Zły format pliku.');
     $oUpload = new Zend_File_Transfer_Adapter_Http();
     $oUpload->addValidator($oMimeValidator);
     $oUpload->getValidator('Upload')->setMessage('Plik jest wymagany.', Zend_Validate_File_Upload::NO_FILE);
     $bWystapilBlad = false;
     if (!$oRequest->getParam('nazwa')) {
         $oRequest->setParam('error_nazwa', 'Nazwa jest wymagana.');
         $bWystapilBlad = $bWystapilBlad || true;
     }
     if (!$oRequest->getParam('body')) {
         $oRequest->setParam('error_body', 'Zawrtosc jest wymagana.');
         $bWystapilBlad = $bWystapilBlad || true;
     }
     if (!$oRequest->getParam('title')) {
         $oRequest->setParam('error_title', 'Autor jest wymagany.');
         $bWystapilBlad = $bWystapilBlad || true;
     }
     if (!$oUpload->isValid('logo')) {
         $aMessages = $oUpload->getMessages();
         $oRequest->setParam('error_logo', current($aMessages));
         $bWystapilBlad = $bWystapilBlad || true;
     }
     if ($bWystapilBlad) {
         return $this->_forward('add');
     }
     $sPagesKatalog = $oConfig->pages->katalog;
     $sPagesNazwa = FileNameManager::getName($sPagesKatalog, $oUpload->getFileName('logo', false));
     $oUpload->addFilter('Rename', $sPagesKatalog . $sPagesNazwa);
     $oUpload->receive('logo');
     ImageTransform::scaleTransformImage($sPagesKatalog . $sPagesNazwa, $oConfig->pages->logo->szerokosc, $oConfig->pages->logo->wysokosc, 75, 1);
     $oReferencja = new Pages();
     try {
         $aDane = array('name' => $oRequest->getParam('nazwa'), 'body' => $oRequest->getParam('body'), 'title' => $oRequest->getParam('title'), 'ref_logo' => $sPagesNazwa);
         $oReferencja->insert($aDane);
     } catch (Exception $e) {
         if ($sPagesNazwa && file_exists($sPagesKatalog . $sPagesNazwa)) {
             unlink($sPagesKatalog . $sPagesNazwa);
         }
         return $this->_forward('admin');
     }
     return $this->_redirect('/');
 }
示例#2
0
function Add()
{
    global $setting;
    if (!$GLOBALS['authentication']) {
        header("Location: index.php?admin=login");
    }
    $results = array();
    $results['pageTitle'] = "Новая запись";
    $results['formAction'] = "add";
    $results['admin'] = true;
    if (isset($_POST['saveChanges'])) {
        // Пользователь получает форму редактирования статьи: сохраняем новую статью
        $article = new Pages();
        $article->storeFormValues($_POST);
        $article->insert();
        //! @todo Проверка в запись БД (Добавить return)
        header("Location: index.php?pages=admin&status=changesSaved");
    } elseif (isset($_POST['cancel'])) {
        // Пользователь сбросид результаты редактирования: возвращаемся к списку статей
        header("Location: index.php?pages=admin");
    } else {
        // Пользователь еще не получил форму редактирования: выводим форму
        $results['article'] = new Pages();
        $results['script'] = "admin/editPages";
        require $setting["SCRIPT_PATH"] . $setting["TEMPLATE_PATH"] . "/include/page.php";
    }
}
示例#3
0
function insertProcess()
{
    $send = Request::get('send');
    $valid = Validator::make(array('send.title' => 'min:1|slashes', 'send.content' => 'min:1', 'send.keywords' => 'slashes', 'send.page_type' => 'slashes', 'send.allowcomment' => 'slashes'));
    if (!$valid) {
        throw new Exception("Error Processing Request: " . Validator::getMessage());
    }
    $friendlyUrl = trim(String::makeFriendlyUrl($send['title']));
    $getData = Pages::get(array('where' => "where friendly_url='{$friendlyUrl}'"));
    if (isset($getData[0]['pageid'])) {
        throw new Exception("This page exists in database.");
    }
    $uploadMethod = Request::get('uploadMethod');
    switch ($uploadMethod) {
        case 'frompc':
            if (Request::hasFile('imageFromPC')) {
                if (Request::isImage('imageFromPC')) {
                    $send['image'] = File::upload('imageFromPC');
                }
            }
            break;
        case 'fromurl':
            if (Request::isImage('imageFromUrl')) {
                $url = Request::get('imageFromUrl');
                $send['image'] = File::upload('uploadFromUrl');
            }
            break;
    }
    if (!($id = Pages::insert($send))) {
        throw new Exception("Error. " . Database::$error);
    }
}