/** * Method that permits to delete one or more categories * * @access private */ private function delete() { if (VPost::delete(false) && $this->_user['delete_content']) { if (VPost::category_id()) { try { foreach (VPost::category_id() as $id) { $cat = new Category(); $cat->_id = $id; $cat->read('_name'); $cat->read('_type'); $type = $cat->_type; if ($this->check_usage($id, $type)) { throw new Exception('Can\'t delete ' . $cat->_name . ' because it\'s used!'); } $cat->delete(); $this->check_empty($type); } Session::monitor_activity('deleted ' . count(VPost::category_id()) . ' category(ies)'); $result = true; } catch (Exception $e) { $result = $e->getMessage(); } $this->_action_msg = ActionMessages::deleted($result); } } elseif (VGet::action() == 'delete' && VGet::id()) { try { $cat = new Category(); $cat->_id = VGet::id(); $cat->read('_name'); $cat->read('_type'); $type = $cat->_type; if ($this->check_usage(VGet::id(), $type)) { throw new Exception('Can\'t delete ' . ucwords($cat->_name) . ' because it\'s used!'); } $cat->delete(); $this->check_empty($type); Session::monitor_activity('deleted a category'); $result = true; } catch (Exception $e) { $result = $e->getMessage(); } $this->_action_msg = ActionMessages::deleted($result); } elseif ((VPost::delete(false) || VGet::action() == 'delete' && VGet::id()) && !$this->_user['delete_content']) { $this->_action_msg = ActionMessages::action_no_perm(); } }
/** * Create a new user * * @access private */ private function create() { if ($this->check_post_data()) { try { $to_read['table'] = 'user'; $to_read['columns'] = array('USER_ID'); $to_read['condition_columns'][':u'] = 'user_username'; $to_read['condition_select_types'][':u'] = 'LIKE'; $to_read['condition_values'][':u'] = $this->_new_user->_username; $to_read['value_types'][':u'] = 'str'; $user = $this->_db->read($to_read); if (!empty($user)) { throw new Exception('Username already used!'); } $this->_new_user->create(); Session::monitor_activity('added a new member: ' . $this->_new_user->_username); if ($this->_new_user->_result_action === true && VPost::send_pwd(false)) { $to = $this->_new_user->_email; $subject = 'Your password for ' . WS_NAME; $message = 'This is your password: '******'Location: index.php?ns=users&ctl=manage'); } elseif ($this->_new_user->_result_action === true) { header('Location: index.php?ns=users&ctl=manage'); } } catch (Exception $e) { $this->_action_msg = ActionMessages::custom_wrong($e->getMessage()); } } }
/** * Delete selected posts * * @access private */ private function delete() { if ((VRequest::action() == 'delete' && VRequest::id() || VPost::delete(false) || VPost::empty_trash(false)) && $this->_user['delete_content']) { try { $post = new Post(); if (VGet::action() == 'delete' && VGet::id()) { $post->_id = VGet::id(); $post->delete(); $this->_db->query('DELETE FROM `' . DB_PREFIX . 'comment` WHERE comment_rel_id = ' . VGet::id() . ' AND comment_rel_type = "post"'); $result = $post->_result_action; } elseif (VPost::delete(false)) { foreach (VPost::post_id() as $id) { $post->_id = $id; $post->delete(); $this->_db->query('DELETE FROM `' . DB_PREFIX . 'comment` WHERE comment_rel_id = ' . $id . ' AND comment_rel_type = "post"'); } $result = $post->_result_action; } elseif (VPost::empty_trash(false)) { $to_read['table'] = 'post'; $to_read['columns'] = array('POST_ID'); $to_read['condition_columns'][':s'] = 'post_status'; $to_read['condition_select_types'][':s'] = '='; $to_read['condition_values'][':s'] = 'trash'; $to_read['value_types'][':s'] = 'str'; $posts = $this->_db->read($to_read); foreach ($posts as $post) { $this->_db->query('DELETE FROM `' . DB_PREFIX . 'comment` WHERE comment_rel_id = ' . $post['POST_ID'] . ' AND comment_rel_type = "post"'); } $to_delete['table'] = 'post'; $to_delete['condition_columns'][':status'] = 'post_status'; $to_delete['condition_values'][':status'] = 'trash'; $to_delete['value_types'][':status'] = 'str'; $result = $this->_db->delete($to_delete); } Session::monitor_activity('deleted post(s)'); $this->_action_msg = ActionMessages::deleted($result); } catch (Exception $e) { $this->_action_msg = ActionMessages::custom_wrong($e->getMessage()); } } elseif ((VRequest::action() == 'delete' && VRequest::id() || VPost::delete(false) || VPost::empty_trash(false)) && $this->_user['delete_content'] === false) { $this->_action_msg = ActionMessages::action_no_perm(); } }
/** * Move uploaded files to the right place and insert metadata in the database * * @access private */ private function create() { if (VPost::upload(false)) { try { $path = 'content/' . date('Y/m/'); $img = new HandleMedia(); $img->load_upload('file'); $name = Helper::remove_accent($img->_name); $mime = $img->_mime; if (file_exists(PATH . $path . $name)) { throw new Exception('The file "' . $name . '" already exists'); } $img->save(PATH . $path . $name); if (substr($mime, 0, 5) == 'image') { $img->thumb(150, 0); $img->thumb(300, 0); $img->thumb(1000, 0); $this->_media->_status = 'draft'; } elseif (substr($mime, 0, 5) == 'video') { $this->_media->_status = 'publish'; } $this->_media->_name = $name; $this->_media->_type = $mime; $this->_media->_author = $this->_user['user_id']; $this->_media->_allow_comment = 'closed'; $this->_media->_permalink = $path . $name; $this->_media->_album = 0; $this->_media->create(); Session::monitor_activity('has uploaded a file named: ' . $this->_media->_name); if (substr($mime, 0, 5) == 'video') { header('Location: index.php?ns=media&ctl=manage&type=video'); } else { header('Location: index.php?ns=media&ctl=manage'); } } catch (Exception $e) { $this->_action_msg = ActionMessages::custom_wrong($e->getMessage()); } } elseif (VPost::create_album(false) && $this->_user['album_photo']) { if (!VPost::name()) { $this->_action_msg = ActionMessages::custom_wrong('Album name missing'); } else { try { $name = VPost::name(); $path = 'content/albums/' . Helper::slug($name) . '/'; if (file_exists(PATH . $path)) { throw new Exception('The album "' . $name . '" already exists'); } $this->_media->_name = $name; $this->_media->_type = 'album'; $this->_media->_author = $this->_user['user_id']; $this->_media->_status = 'draft'; $this->_media->_permalink = $path; $this->_media->_description = stripslashes(VPost::description()); $this->_media->_category = implode(',', VPost::cat(array())); $this->_media->_allow_comment = VPost::allow_comment('closed'); $this->_media->_album = 0; $img = new HandleMedia(); $img->load_upload('cover'); $img->save(PATH . $path . 'cover.png'); $img->thumb(150, 0); $img->thumb(300, 0); $img->thumb(1000, 0); $this->_media->create(); Session::monitor_activity('created an album named: ' . $this->_media->_name); header('Location: index.php?ns=media&ctl=albums&action=edit&id=' . $this->_media->_id); } catch (Exception $e) { $this->_action_msg = ActionMessages::custom_wrong($e->getMessage()); } } } elseif (VPost::link_alien(false)) { if (!VPost::name() || !VPost::embed_code()) { $this->_action_msg = ActionMessages::custom_wrong('There\'s missing informations'); } else { try { $this->_media->_name = VPost::name(); $this->_media->_type = 'alien'; $this->_media->_author = $this->_user['user_id']; $this->_media->_status = 'draft'; $this->_media->_allow_comment = 'closed'; $this->_media->_permalink = Helper::slug(VPost::name()); $this->_media->_embed_code = VPost::embed_code(); $this->_media->_album = 0; $this->_media->create(); Session::monitor_activity('linked a new video named: ' . $this->_media->_name); header('Location: index.php?ns=media&ctl=manage&type=video'); } catch (Exception $e) { $this->_action_msg = ActionMessages::custom_wrong($e->getMessage()); } } } elseif (VPost::register_video(false)) { try { if (!file_exists(PATH . VPost::url())) { throw new Exception('Video not found'); } if (!VPost::mime()) { throw new Exception('Video mime type missing'); } $this->_media->_name = VPost::name(); $this->_media->_type = VPost::mime(); $this->_media->_author = $this->_user['user_id']; $this->_media->_status = 'publish'; $this->_media->_allow_comment = 'closed'; $this->_media->_permalink = VPost::url(); $this->_media->_album = 0; $this->_media->create(); Session::monitor_activity('registered a new video named: ' . $this->_media->_name); header('Location: index.php?ns=media&ctl=manage&action=edit&type=video&id=' . $this->_media->_id); } catch (Exception $e) { $this->_action_msg = ActionMessages::custom_wrong($e->getMessage()); } } }
/** * Create new link * * @access private */ private function create() { if ($this->_user['settings']) { if ($this->check_post_data()) { try { $this->_link->create(); Session::monitor_activity('created a new link'); header('Location: index.php?ns=links&ctl=manage'); } catch (Exception $e) { $this->_action_msg = ActionMessages::custom_wrong($e->getMessage()); } } } else { $this->_action_msg = ActionMessages::action_no_perm(); } }
/** * Update an existing post * * @access private */ private function update() { if ($this->check_post_data()) { try { $old = new Post(); $old->_id = $this->_post->_id; $old->read('_status'); //if post move from draft to published, creation date is updated if ($old->_status == 'draft' && $this->_post->_status == 'publish') { $this->_post->_date = date('Y-m-d H:i:s'); $this->_post->update('_date', 'str'); } $this->_post->update('_title', 'str'); $this->_post->update('_content', 'str'); $this->_post->update('_allow_comment', 'str'); $this->_post->update('_date', 'str'); $this->_post->update('_status', 'str'); $this->_post->update('_tags', 'str'); $this->_post->update('_category', 'str'); if ($this->_post->_status == 'publish') { $this->_post->_updated = 'yes'; $this->_post->_update_author = $this->_user['user_id']; $this->_post->update('_updated', 'str'); $this->_post->update('_update_author', 'int'); } $this->_action_msg = ActionMessages::post_update(true); Session::monitor_activity('updated the post "' . $this->_post->_title . '" (status: ' . $this->_post->_status . ')'); } catch (Exception $e) { $this->_action_msg = ActionMessages::post_update(ucfirst($e->getMessage())); } } $this->_action = 'to_update'; }
/** * Update default page setting * * @access private */ private function update() { if (VPost::update(false)) { try { $array = array('type' => '', 'view' => ''); if ($this->_setting->_data['type'] != VPost::type()) { $array['view'] = 'all'; } else { $array['view'] = VPost::view(); } $array['type'] = VPost::type(); $this->_setting->_data = json_encode($array); $this->_setting->update('_data', 'str'); $this->_setting->_data = json_decode($this->_setting->_data, true); Session::monitor_activity('changed default page setting'); $result = true; } catch (Exception $e) { $result = $e->getMessage(); } $this->_action_msg = ActionMessages::updated($result); } }
/** * Delete links * * @access private */ private function delete() { if (VPost::delete(false) && VPost::link_id() && $this->_user['delete_content']) { try { foreach (VPost::link_id() as $id) { $link = new Link(); $link->_id = $id; $link->delete(); $this->_action_msg = ActionMessages::deleted($link->_result_action); } Session::monitor_activity('deleted ' . count(VPost::link_id()) . ' link(s)'); } catch (Exception $e) { $this->_action_msg = ActionMessages::custom_wrong($e->getMessage()); } } elseif (VGet::action() == 'delete' && VGet::id() && $this->_user['delete_content']) { try { $link = new Link(); $link->_id = Vget::id(); $link->delete(); Session::monitor_activity('deleted a link'); $this->_action_msg = ActionMessages::deleted($link->_result_action); } catch (Exception $e) { $this->_action_msg = ActionMessages::custom_wrong($e->getMessage()); } } elseif ((VPost::delete(false) || VGet::action() == 'delete') && $this->_user['delete_content'] === false) { $this->_action_msg = ActionMessages::action_no_perm(); } }
/** * Delete medias from database and on hard drive * * @access private */ private function delete() { if ($this->_user['delete_content'] && VPost::delete(false) && VPost::media_id()) { $results = array(); $global_result = true; foreach (VPost::media_id() as $id) { try { $media = new Media(); $media->_id = $id; $media->read('_permalink'); $path = $media->_permalink; $media->delete(); unset($media); HandleMedia::delete(PATH . $path); $this->_db->query('DELETE FROM `' . DB_PREFIX . 'comment` WHERE comment_rel_id = ' . $id . ' AND comment_rel_type = "media"'); if (VPost::type() == 'alien') { $to_update['table'] = 'media'; $to_update['columns'] = array(':attach' => 'media_attachment'); $to_update['condition_columns'] = array(':ca' => 'media_attachment'); $to_update['column_values'] = array(':attach' => null, ':ca' => $id); $to_update['value_types'] = array(':attach' => 'null', ':ca' => 'int'); $this->_db->update($to_update); } array_push($results, true); } catch (Exception $e) { array_push($results, false); } } foreach ($results as $result) { if ($result !== true) { $global_result = false; } } Session::monitor_activity('deleted ' . count(VPost::media_id()) . ' file(s)'); $this->_action_msg = ActionMessages::deleted($global_result); } elseif ($this->_user['delete_content'] && VGet::action() == 'delete' && VGet::id()) { try { $media = new Media(); $media->_id = VGet::id(); $media->read('_permalink'); $path = $media->_permalink; $media->delete(); unset($media); HandleMedia::delete(PATH . $path); $this->_db->query('DELETE FROM `' . DB_PREFIX . 'comment` WHERE comment_rel_id = ' . VGet::id() . ' AND comment_rel_type = "media"'); if (VGet::type() == 'alien') { $to_update['table'] = 'media'; $to_update['columns'] = array(':attach' => 'media_attachment'); $to_update['condition_columns'] = array(':ca' => 'media_attachment'); $to_update['column_values'] = array(':attach' => null, ':ca' => VGet::id()); $to_update['value_types'] = array(':attach' => 'null', ':ca' => 'int'); $this->_db->update($to_update); } Session::monitor_activity('deleted a file'); $result = true; } catch (Exception $e) { error_log($e->getMessage(), 0); $result = false; } $this->_action_msg = ActionMessages::deleted($result); } elseif (!$this->_user['delete_content'] && (VPost::delete(false) || VGet::action() == 'delete')) { $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(); } }