/** * Class constructor * * @access public */ public function __construct() { parent::__construct(); $this->_title = 'Manage Post'; if ($this->_user['post']) { $this->get_post(); Helper::get_categories($this->_categories, $this->_action_msg, 'post'); $this->get_setting(); $this->get_medias(); if (VPost::action() == 'to_insert') { $this->create(); } elseif (VPost::action() == 'to_update') { $this->update(); } } }
/** * Method that permits to delete one or more comments at a time * * @access private */ private function delete() { if ((isset($_POST['empty']) || VRequest::action() == 'delete') && $this->_user['delete_content']) { if (isset($_POST['empty']) && VPost::comment_status() && in_array(VPost::comment_status(), array('spam', 'trash'))) { $to_delete['table'] = 'comment'; $to_delete['condition_columns'][':status'] = 'comment_status'; $to_delete['condition_values'][':status'] = VPost::comment_status(); $to_delete['value_types'][':status'] = 'str'; $global_result = $this->_db->delete($to_delete); } elseif (VPost::action() == 'delete' && VPost::comment_id()) { $results = array(); $global_result = true; foreach (VPost::comment_id() as $id) { try { $comment = new Comment(); $comment->_id = $id; $comment->delete(); unset($comment); array_push($results, true); } catch (Exception $e) { array_push($results, false); } } foreach ($results as $result) { if ($result !== true) { $global_result = false; } } } elseif (VGet::action() == 'delete' && VGet::comment_id()) { try { $comment = new Comment(); $comment->_id = VGet::comment_id(); $comment->delete(); $global_result = true; } catch (Exception $e) { $global_result = false; } } if (isset($global_result)) { $this->_action_msg = ActionMessages::deleted($global_result); } } elseif ((isset($POST['empty']) || VRequest::action() == 'delete') && $this->_user['delete_content'] === false) { $this->_action_msg = ActionMessages::action_no_perm(); } }
/** * Delete files on hard drive and metadata in database * * @access private */ private function delete() { if (VPost::apply_action(false) && VPost::action() == 'delete' && $this->_user['delete_content']) { if (VPost::album_id()) { try { foreach (VPost::album_id() as $id) { $album = new Media(); $album->_id = $id; $album->read('_permalink'); $to_read['table'] = 'media'; $to_read['columns'] = array('MEDIA_ID'); $to_read['condition_columns'][':id'] = 'media_album'; $to_read['condition_select_types'][':id'] = '='; $to_read['condition_values'][':id'] = $id; $to_read['value_types'][':id'] = 'int'; $ids = $this->_db->read($to_read); if (!empty($ids)) { foreach ($ids as $pid) { $pic = new Media(); $pic->_id = $pid['MEDIA_ID']; $pic->read('_permalink'); $permalink = $pic->_permalink; HandleMedia::delete(PATH . $permalink); $pic->delete(); } } $permalink = $album->_permalink; HandleMedia::delete(PATH . $permalink . 'cover.png'); @rmdir(PATH . $permalink); $album->delete(); $this->_db->query('DELETE FROM `' . DB_PREFIX . 'comment` WHERE comment_rel_id = ' . $id . ' AND comment_rel_type = "media"'); } Session::monitor_activity('deleted ' . count(VPost::album_id()) . ' album(s)'); $result = true; } catch (Exception $e) { $result = $e->getMessage(); } $this->_action_msg = ActionMessages::deleted($result); } } elseif (VGet::action() == 'delete' && VGet::id() && $this->_user['delete_content']) { try { $pic = new Media(); $pic->_id = VGet::id(); $pic->read('_permalink'); $permalink = $pic->_permalink; HandleMedia::delete(PATH . $permalink); $pic->delete(); $this->_db->query('DELETE FROM `' . DB_PREFIX . 'comment` WHERE comment_rel_id = ' . VGet::id() . ' AND comment_rel_type = "media"'); Session::monitor_activity('deleted a picture of an album'); $result = true; } catch (Exception $e) { $result = $e->getMessage(); } $this->_action_msg = ActionMessages::deleted($result); } elseif (VPost::delete_pics(false)) { if (VPost::picture_id()) { try { foreach (VPost::picture_id() as $id) { $pic = new Media(); $pic->_id = $id; $pic->read('_permalink'); $permalink = $pic->_permalink; HandleMedia::delete(PATH . $permalink); $pic->delete(); } Session::monitor_activity('deleted ' . count(VPost::picture_id(array())) . ' picture(s) of an album'); $result = true; } catch (Exception $e) { $result = $e->getMessage(); } } } elseif ((VPost::apply_action(false) && VPost::action() == 'delete' || VGet::action() == 'delete' || VPost::delete_pics(false)) && !$this->_user['delete_content']) { $this->_action_msg = ActionMessages::action_no_perm(); } }