Esempio n. 1
0
function updateProcess($id)
{
    $send = Request::get('send');
    $valid = Validator::make(array('send.title' => 'min:1|slashes', 'send.content' => 'min:1', 'send.keywords' => 'slashes'));
    if (!$valid) {
        throw new Exception("Error Processing Request: " . Validator::getMessage());
    }
    $uploadMethod = Request::get('uploadMethod');
    $loadData = Pages::get(array('where' => "where pageid='{$id}'"));
    if (!isset($loadData[0]['pageid'])) {
        throw new Exception("This page not exists.");
    }
    switch ($uploadMethod) {
        case 'frompc':
            if (Request::hasFile('imageFromPC')) {
                if (Request::isImage('imageFromPC')) {
                    $send['image'] = File::upload('imageFromPC');
                    File::remove($loadData[0]['image']);
                }
            }
            break;
        case 'fromurl':
            if (Request::isImage('imageFromUrl')) {
                $url = Request::get('imageFromUrl');
                $send['image'] = File::upload('uploadFromUrl');
                File::remove($loadData[0]['image']);
            }
            break;
    }
    if (!Pages::update($id, $send)) {
        throw new Exception("Error. " . Database::$error);
    }
}
Esempio n. 2
0
 public function edit($id)
 {
     // find page
     if (($page = Pages::find(array('id' => $id))) === false) {
         return Response::redirect($this->admin_url . '/pages');
     }
     // process post request
     if (Input::method() == 'POST') {
         if (Pages::update($id)) {
             // redirect path
             return Response::redirect($this->admin_url . '/pages/edit/' . $id);
         }
     }
     Template::render('pages/edit', array('page' => $page));
 }
Esempio n. 3
0
 function editAction()
 {
     $this->view->title = "Edit pages";
     $pages = new Pages();
     if ($this->_request->isPost()) {
         Zend_Loader::loadClass('Zend_Filter_StripTags');
         $filter = new Zend_Filter_StripTags();
         $this->view->headScript()->appendFile('/js/tiny_mce/tiny_mce.js', 'text/javascript');
         $id = (int) $this->_request->getPost('id');
         $name = $filter->filter($this->_request->getPost('name'));
         $name = trim($name);
         $body = $filter->filter($this->_request->getPost('body'));
         $body = trim($body);
         $title = trim($filter->filter($this->_request->getPost('title')));
         if ($id !== false) {
             if ($name != '' && $body != '' && $title != '') {
                 $data = array('name' => $name, 'body' => $body, 'title' => $title);
                 $where = 'id = ' . $id;
                 $pages->update($data, $where);
                 $this->_redirect('/admin');
                 return;
             } else {
                 $this->view->pages = $pages->fetchRow('id=' . $id);
             }
         }
     } else {
         // pages id should be $params['$id']
         $id = (int) $this->_request->getParam('id', 0);
         if ($id > 0) {
             $this->view->pages = $pages->fetchRow('id=' . $id);
         }
     }
     // additional view fields required by form
     $this->view->action = 'edit';
     $this->view->buttonText = 'Update';
 }
Esempio n. 4
0
 /**
  * Updates Pages into database.
  *
  * @param Pages $pages
  * @param array $input
  *
  * @return Pages
  */
 public function update($pages, $input)
 {
     $input['url'] = Quarx::convertToURL($input['url']);
     $input['is_published'] = isset($input['is_published']) ? (bool) $input['is_published'] : 0;
     $input['published_at'] = isset($input['published_at']) && !empty($input['published_at']) ? $input['published_at'] : Carbon::now()->format('Y-m-d h:i:s');
     return $pages->update($input);
 }