/** * Delete category content * * @return array */ private function _delete_cat_content() { $this->db->sql_transaction('begin'); // Before we remove anything we make sure we are able to adjust the post counts later. ;) $sql = 'SELECT link_id, link_banner FROM ' . DIR_LINK_TABLE . ' WHERE link_cat = ' . (int) $this->cat_id; $result = $this->db->sql_query($sql); $link_ids = array(); while ($row = $this->db->sql_fetchrow($result)) { $link_ids[] = $row['link_id']; if ($row['link_banner'] && !preg_match('/^(http:\\/\\/|https:\\/\\/|ftp:\\/\\/|ftps:\\/\\/|www\\.).+/si', $row['link_banner'])) { $banner_img = $this->dir_helper->get_banner_path(basename($row['link_banner'])); if (file_exists($banner_img)) { @unlink($banner_img); } } } $this->db->sql_freeresult($result); if (sizeof($link_ids)) { // Delete links datas $link_datas_ary = array(DIR_COMMENT_TABLE => 'comment_link_id', DIR_VOTE_TABLE => 'vote_link_id'); foreach ($link_datas_ary as $table => $field) { $this->db->sql_query("DELETE FROM {$table} WHERE " . $this->db->sql_in_set($field, $link_ids)); } } // Delete cats datas $cat_datas_ary = array(DIR_LINK_TABLE => 'link_cat', DIR_WATCH_TABLE => 'cat_id'); foreach ($cat_datas_ary as $table => $field) { $this->db->sql_query("DELETE FROM {$table} WHERE {$field} = " . (int) $this->cat_id); } $this->db->sql_transaction('commit'); return array(); }
/** * Get orphan banners * * @param bool $delete True if we want to delete banners, else false * @return null|int Number of orphan files, else null */ private function _orphan_files($delete = false) { $banner_path = $this->dir_helper->get_banner_path(); $imglist = filelist($banner_path); $physical_files = $logical_files = $orphan_files = array(); if (!empty($imglist[''])) { $imglist = array_values($imglist); $imglist = $imglist[0]; foreach ($imglist as $img) { $physical_files[] = $img; } $sql = 'SELECT link_banner FROM ' . DIR_LINK_TABLE . ' WHERE link_banner <> \'\''; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { if (!preg_match('/^(http:\\/\\/|https:\\/\\/|ftp:\\/\\/|ftps:\\/\\/|www\\.).+/si', $row['link_banner'])) { $logical_files[] = basename($row['link_banner']); } } $this->db->sql_freeresult($result); $orphan_files = array_diff($physical_files, $logical_files); } if (!$delete) { return sizeof($orphan_files); } $dh = @opendir($banner_path); while (($file = readdir($dh)) !== false) { if (in_array($file, $orphan_files)) { @unlink($this->dir_helper->get_banner_path($file)); } } }
/** * Delete a banner from server * * @param string $file The file's name * @return bool True if delete success, else false */ private function _banner_delete($file) { if (file_exists($this->dir_helper->get_banner_path($file))) { @unlink($this->dir_helper->get_banner_path($file)); return true; } return false; }
/** * Disapprove action * * @return null */ private function _action_disapproved() { foreach ($this->links_data as $row) { if ($row['link_banner'] && !preg_match('/^(http:\\/\\/|https:\\/\\/|ftp:\\/\\/|ftps:\\/\\/|www\\.).+/si', $row['link_banner'])) { $banner_img = $this->dir_helper->get_banner_path(basename($row['link_banner'])); if (file_exists($banner_img)) { @unlink($banner_img); } } $sql = 'DELETE FROM ' . DIR_LINK_TABLE . ' WHERE link_id = ' . (int) $row['link_id']; $this->db->sql_query($sql); } }
/** * Display a banner * * @param string $banner_img Path to banner file * @return Response object */ public function return_banner($banner_img) { if (!function_exists('file_gc')) { include $this->root_path . 'includes/functions_download.' . $this->php_ext; } $file_path = $this->dir_helper->get_banner_path($banner_img); if (@file_exists($file_path) && @is_readable($file_path)) { $response = new BinaryFileResponse($file_path); $response->setContentDisposition('inline', $banner_img); // Without fileinfo extension, Symfony is unable to guess the mime type if (!extension_loaded('fileinfo')) { $image_data = @getimagesize($file_path); $response->headers->set('Content-Type', image_type_to_mime_type($image_data[2])); } } else { $response = new Response(); $response->setStatusCode(404); } file_gc(false); return $response; }