예제 #1
0
 /**
  * Processing edit of a blog.
  *
  * This is a POST callback function.
  *
  * Sets following errors in POST vars:
  * title        - invalid(empty) title.
  * startdate    - wrongly formatted start date.
  * enddate      - wrongly formatted end date.
  * duration     - empty enddate and invalid duration.
  * category     - category is not belonging to user.
  * trip         - trip is not belonging to user.
  * upderror     - error performing db update.
  * tagerror     - error while updating tags.
  */
 public function editProcess($args, $action, $mem_redirect, $mem_resend)
 {
     if (!($member = $this->_model->getLoggedInMember())) {
         return false;
     }
     $userId = $member->id;
     $vars = $args->post;
     if (!isset($vars['id']) || !$this->_model->isUserPost($userId, $vars['id'])) {
         return false;
     }
     if (isset($vars['txt'])) {
         $vars['txt'] = $this->_cleanupText($vars['txt']);
     }
     if (!$this->_validateVars($vars)) {
         return false;
     }
     $post = $this->_model->getPost($vars['id']);
     if (!$post) {
         return false;
     }
     $flags = $post->flags;
     // cannot write sticky blogs currently
     $flags = $flags & ~(int) Blog::FLAG_STICKY;
     if (!isset($vars['vis'])) {
         $vars['vis'] = 'pri';
     }
     switch ($vars['vis']) {
         case 'pub':
             $flags = $flags & ~(int) Blog::FLAG_VIEW_PROTECTED & ~(int) Blog::FLAG_VIEW_PRIVATE;
             break;
         case 'prt':
             $flags = $flags & ~(int) Blog::FLAG_VIEW_PRIVATE | (int) Blog::FLAG_VIEW_PROTECTED;
             break;
         default:
             $flags = $flags & ~(int) Blog::FLAG_VIEW_PROTECTED | (int) Blog::FLAG_VIEW_PRIVATE;
             break;
     }
     $tripId = isset($vars['tr']) && strcmp($vars['tr'], '') != 0 ? (int) $vars['tr'] : false;
     $this->_model->updatePost($post->blog_id, $flags, $tripId);
     // 'Touch' the corresponding trip!
     if ($tripId) {
         $TripModel = new Trip();
         $TripModel->touchTrip($tripId);
     }
     /*// to sql datetime format.
       if ((isset($vars['sty']) && (int)$vars['sty'] != 0) || (isset($vars['stm']) && (int)$vars['stm'] != 0) || (isset($vars['std']) && (int)$vars['std'] != 0)) {
           $start = mktime(0, 0, 0, (int)$vars['stm'], (int)$vars['std'], (int)$vars['sty']);
           $start = date('YmdHis', $start);
       } else {
           $start = false;
       } */
     // to sql datetime format.
     if (isset($vars['date']) && (strlen($vars['date']) <= 10 && strlen($vars['date']) > 8)) {
         list($day, $month, $year) = preg_split('/[\\/.-]/', $vars['date']);
         if (substr($month, 0, 1) == '0') {
             $month = substr($month, 1, 2);
         }
         if (substr($day, 0, 1) == '0') {
             $day = substr($day, 1, 2);
         }
         $start = mktime(0, 0, 0, (int) $month, (int) $day, (int) $year);
         $start = date('YmdHis', $start);
     } else {
         $start = false;
     }
     // Check if the location already exists in our DB and add it if necessary
     if ($vars['geonameid'] && $vars['latitude'] && $vars['longitude'] && $vars['geonamename'] && $vars['geonamecountrycode'] && $vars['admincode']) {
         $geoname_ok = $this->_model->checkGeonamesCache($vars['geonameid']);
     } else {
         $geoname_ok = false;
     }
     $geonameId = $geoname_ok ? $vars['geonameid'] : false;
     $this->_model->updatePostData($post->blog_id, $vars['t'], $vars['txt'], $start, $geonameId);
     if (!$this->_model->updateTags($post->blog_id, explode(',', $vars['tags']))) {
         $vars['errors'] = array('tagerror');
         return false;
     }
     $this->_model->updateBlogToCategory($post->blog_id, $vars['cat']);
     PPostHandler::clearVars();
     return 'blog/edit/' . $post->blog_id . '/finish';
 }