public static function delete_article($articleid) { $db = cmsms()->GetDb(); //Now remove the article $query = "DELETE FROM " . cms_db_prefix() . "module_news WHERE news_id = ?"; $db->Execute($query, array($articleid)); // Delete it from the custom fields $query = 'DELETE FROM ' . cms_db_prefix() . 'module_news_fieldvals WHERE news_id = ?'; $db->Execute($query, array($articleid)); // delete any files... $config = cmsms()->GetConfig; $p = cms_join_path($config['uploads_path'], 'news', 'id', $articleid); if (is_dir($p)) { recursive_delete($p); } news_admin_ops::delete_static_route($articleid); //Update search index $mod = cms_utils::get_module('News'); $module = cms_utils::get_module('Search'); if ($module != FALSE) { $module->DeleteWords($mod->GetName(), $articleid, 'article'); } @$mod->SendEvent('NewsArticleDeleted', array('news_id' => $articleid)); // put mention into the admin log audit($articleid, 'News: ' . $articleid, 'Article deleted'); }
public function testRecursiveDelete() { $path = $this->path; recursive_delete($path); if (!is_dir('test/a/')) { $this->skip("WARN: dir not present, shouldn't have been removed yet"); } recursive_delete($path, true); $this->assertFalse(file_exists($path)); $this->assertFalse(file_exists($path . '/a')); }
/** * Delete a file or recursively delete a directory * * @param string $str Path to file or directory */ function recursive_delete($str) { if (is_file($str)) { return @unlink($str); } elseif (is_dir($str)) { $scan = glob(rtrim($str, '/') . '/*'); foreach ($scan as $index => $path) { recursive_delete($path); } return @rmdir($str); } }
function recursive_delete($ftp, $path) { $files = ftp_rawlist($ftp, $path); foreach ($files as $file) { $i = explode(' ', $file); $filename = $i[count($i) - 1]; if (strpos($file, '<DIR>') !== false) { recursive_delete($ftp, $path . '/' . $filename); } else { if (!ftp_delete($ftp, $path . '/' . $filename)) { return false; } } } if (!ftp_rmdir($ftp, $path)) { return false; } return true; }
function recursive_delete($deletedir) { global $return; if (is_dir($deletedir)) { $handle = opendir($deletedir); while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != "..") { $ext = pathinfo($entry, PATHINFO_EXTENSION); $path = $deletedir . '/' . $entry; if (!is_dir($path)) { unlink($path); $return['deleted files'][] = $path; } else { recursive_delete($path); } } } closedir($handle); rmdir($deletedir); $return['deleted dirs'][] = $deletedir; } else { $return[$deletedir] = 'does not exist'; } }
protected function copy_conf() { $this->write_progress("\tCopying Config"); //make a backup of the config if (file_exists($this->global_settings->switch_conf_dir())) { $this->backup_dir($this->global_settings->switch_conf_dir(), 'fusionpbx_switch_config'); recursive_delete($this->global_settings->switch_conf_dir()); } //make sure the conf directory exists if (!is_dir($this->global_settings->switch_conf_dir())) { if (!mkdir($this->global_settings->switch_conf_dir(), 0774, true)) { throw new Exception("Failed to create the switch conf directory '" . $this->global_settings->switch_conf_dir() . "'. "); } } //copy resources/templates/conf to the freeswitch conf dir if (file_exists('/usr/share/examples/fusionpbx/resources/templates/conf')) { $src_dir = "/usr/share/examples/fusionpbx/resources/templates/conf"; } else { $src_dir = $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/resources/templates/conf"; } $dst_dir = $this->global_settings->switch_conf_dir(); if (is_readable($dst_dir)) { recursive_copy($src_dir, $dst_dir); unset($src_dir, $dst_dir); } $fax_dir = join(DIRECTORY_SEPARATOR, array($this->global_settings->switch_storage_dir(), 'fax')); if (!is_readable($fax_dir)) { mkdir($fax_dir, 0777, true); } $voicemail_dir = join(DIRECTORY_SEPARATOR, array($this->global_settings->switch_storage_dir(), 'voicemail')); if (!is_readable($voicemail_dir)) { mkdir($voicemail_dir, 0777, true); } //create the dialplan/default.xml for single tenant or dialplan/domain.xml if (file_exists($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/app/dialplan")) { $dialplan = new dialplan(); $dialplan->domain_uuid = $this->domain_uuid; $dialplan->domain = $this->domain_name; $dialplan->switch_dialplan_dir = join(DIRECTORY_SEPARATOR, array($this->global_settings->switch_conf_dir(), "/dialplan")); $dialplan->restore_advanced_xml(); if ($this->_debug) { print_r($dialplan->result, $message); $this->write_debug($message); } } //write the xml_cdr.conf.xml file if (file_exists($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/app/xml_cdr")) { xml_cdr_conf_xml(); } //write the switch.conf.xml file if (file_exists($this->global_settings->switch_conf_dir())) { switch_conf_xml(); } }
} if ($action == 'showpostinstall') { // this is probably dead code now if (isset($gCms->modules[$module])) { $modinstance =& $gCms->modules[$module]['object']; if ($modinstance->InstallPostMessage() != FALSE) { @ob_start(); echo $modinstance->InstallPostMessage(); $content = @ob_get_contents(); @ob_end_clean(); echo $themeObject->ShowMessage($content); } } } if ($action == 'remove') { $result = recursive_delete($config['root_path'] . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $module); if (!$result) { echo '<div class="pagecontainer">'; echo '<p class="pageheader">' . lang('moduleerrormessage', array($module)) . '</p>'; echo lang('cantremovefiles'); echo "</div>"; echo '<p class="pageback"><a class="pageback" href="' . $thisurl . '">« ' . lang('back') . '</a></p>'; include_once "footer.php"; } else { redirect($thisurl); } } if ($action == 'upgrade') { $modops =& $gCms->GetModuleOperations(); $result = $modops->UpgradeModule($module, $_GET['oldversion'], $_GET['newversion']); if (!$result) {
// Check that the news belongs to the same project $gr = db_query("SELECT group_id FROM news_bytes WHERE forum_id=" . db_ei($forum_id)); if (db_result($gr, 0, 'group_id') == $group_id) { // authorized to delete the message $authorized_to_delete_message = true; } } else { if ($message_group_id == $group_id) { // the message belongs to this group's forums $authorized_to_delete_message = true; } } if ($authorized_to_delete_message) { //delete monitor settings on the corresponding thread, before deleting the message forum_thread_delete_monitor($forum_id, $msg_id); $feedback .= $Language->getText('forum_admin_index', 'msgs_del', recursive_delete($msg_id, $forum_id)); } else { $feedback .= ' ' . $Language->getText('forum_admin_index', 'msg_not_in_group') . ' '; } } else { $feedback .= ' ' . $Language->getText('forum_admin_index', 'msg_not_found') . ' '; } } } else { if ($request->existAndNonEmpty('add_forum')) { /* Adding forums to this group */ $vMonitored = new Valid_WhiteList('is_monitored', array(0, 1)); $vMonitored->required(); if ($request->valid($vForumName) && $request->valid($vDescription) && $request->valid($vIsPublic) && $request->valid($vMonitored)) {
$thumbtype = $tmp[2]; $thumbext = @image_type_to_extension($thumbtype); $fnameext = strrchr($row['upload_name'], '.'); $fname = substr($row['upload_name'], 0, strlen($row['upload_name']) - strlen($fnameext)); $thumbname = 'thumb_' . $fname . $thumbext; $newthumb = cms_join_path($dir, $thumbname); // rename thumbnail files @rename($oldthumb, $newthumb); @unlink($oldthumb); // update the database $db->Execute($updatequery, array($thumbname, $row['upload_id'])); } // remove the .thumbs directory for each category for ($i = 0; $i < count($categories); $i++) { $dir = cms_join_path($config['uploads_path'], $categories[$i]['uploads_category_path'], '.thumbs'); recursive_delete($dir); } case '1.4': case '1.4.1': $db =& $this->GetDb(); $dict = NewDataDictionary($db); $sqlarray = $dict->AddColumnSQL(cms_db_prefix() . "module_uploads_categories", "upload_category_deletable I"); $dict->ExecuteSQLArray($sqlarray); case '1.5': case '1.5.1': // sendfile form template $fn = dirname(__FILE__) . '/templates/orig_sendfileform_template.tpl'; if (file_exists($fn)) { $template = @file_get_contents($fn); $this->SetPreference('sendfileform_sysdefault', $template); $this->SetTemplate('sendfileform_default', $template);
protected function copy_conf() { //send a message $this->write_progress("\tCopying Config"); //make a backup of the config if (file_exists($this->global_settings->switch_conf_dir())) { $this->backup_dir($this->global_settings->switch_conf_dir(), 'fusionpbx_switch_config'); recursive_delete($this->global_settings->switch_conf_dir()); } //make sure the conf directory exists if (!is_dir($this->global_settings->switch_conf_dir())) { if (!mkdir($this->global_settings->switch_conf_dir(), 02770, true)) { throw new Exception("Failed to create the switch conf directory '" . $this->global_settings->switch_conf_dir() . "'. "); } } //copy resources/templates/conf to the freeswitch conf dir if (file_exists('/usr/share/examples/fusionpbx/resources/templates/conf')) { $src_dir = "/usr/share/examples/fusionpbx/resources/templates/conf"; } else { $src_dir = $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/resources/templates/conf"; } $dst_dir = $this->global_settings->switch_conf_dir(); if (is_readable($dst_dir)) { recursive_copy($src_dir, $dst_dir); unset($src_dir, $dst_dir); } $fax_dir = join(DIRECTORY_SEPARATOR, array($this->global_settings->switch_storage_dir(), 'fax')); if (!is_readable($fax_dir)) { mkdir($fax_dir, 02770, true); } $voicemail_dir = join(DIRECTORY_SEPARATOR, array($this->global_settings->switch_storage_dir(), 'voicemail')); if (!is_readable($voicemail_dir)) { mkdir($voicemail_dir, 02770, true); } //write the xml_cdr.conf.xml file if (file_exists($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/app/xml_cdr")) { xml_cdr_conf_xml(); } //write the switch.conf.xml file if (file_exists($this->global_settings->switch_conf_dir())) { switch_conf_xml(); } }
/** * A function to recursively delete all files and folders in a directory * synonymous with rm -r * * @param string The directory name * @return boolean */ function recursive_delete($dirname) { // all subdirectories and contents: if (is_dir($dirname)) { $dir_handle = opendir($dirname); } while ($file = readdir($dir_handle)) { if ($file != "." && $file != "..") { if (!is_dir($dirname . "/" . $file)) { if (!@unlink($dirname . "/" . $file)) { closedir($dir_handle); return false; } } else { recursive_delete($dirname . "/" . $file); } } } closedir($dir_handle); if (!@rmdir($dirname)) { return false; } return true; }
if ($group_id && user_ismember($group_id, 'F2')) { if ($post_changes) { /* Update the DB to reflect the changes */ if ($delete) { /* Deleting messages or threads */ /* Get this forum_id, checking to make sure this forum is in this group */ $sql = "SELECT forum.group_forum_id FROM forum,forum_group_list WHERE forum.group_forum_id=forum_group_list.group_forum_id " . "AND forum_group_list.group_id='{$group_id}' AND forum.msg_id='{$msg_id}'"; $result = db_query($sql); if (db_numrows($result) > 0) { $feedback .= recursive_delete($msg_id, db_result($result, 0, 'group_forum_id')) . " messages deleted "; } else { $feedback .= " Message not found or message is not in your group "; } } else { if ($add_forum) { /* Adding forums to this group */ forum_create_forum($group_id, $forum_name, $is_public, 1, $description); } else { if ($change_status) { /* Change a forum to public/private */ if ($send_all_posts_to) {
// 'media' is the odd one out in going to parent_templates, the rest just go to templates. if ($toplevel == "media") { $destination = $xerte_module_path . "xerte/parent_templates/" . $folder . "/{$toplevel}/"; } foreach ($files_to_move as $file) { @rename($file, $destination . $file); } // Now remove all the (media|thumbs|common|models) files. recursive_delete($toplevel_src_path, true); } $template_src = $temp_dir . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR; rename($template_src . "template.rlt", $xerte_module_path . "xerte/parent_templates/" . $folder . "/" . $folder . ".rlt"); rename($template_src . "template.xml", $xerte_module_path . "xerte/templates/" . $folder . "/data.xml"); rename($template_src . "template.xwd", $xerte_module_path . "xerte/parent_templates/" . $folder . "/data.xwd"); // Remove anything now left. recursive_delete($temp_dir, true); if ($_POST['folder'] == "") { /* * No folder was posted, so add records to the database id. */ _debug("Adding template to database ({$folder}/ {$desc}/ {$name} etc)"); $prefix = $xerte_toolkits_site->database_table_prefix; $sql = "INSERT INTO {$prefix}originaltemplatedetails \n (template_framework, template_name, description, date_uploaded, display_name, display_id, access_rights, active)\n VALUES (?,?,?,?,?,?,?,?)"; $parameters = array('xerte', $folder, $desc, date('Y-m-d'), $name, '0', '', 'false'); $ok = db_query($sql, $parameters); if ($ok) { receive_message($_SESSION['toolkits_logon_username'], "USER", "SUCCESS", "Folder creation succeeded for " . $_SESSION['toolkits_logon_username'], "Folder creation succeeded for " . $_SESSION['toolkits_logon_username']); echo IMPORT_TEMPLATE_FOLDER_CREATE . "****"; _debug("template saved to db ok; import presumably ok."); } else { receive_message($_SESSION['toolkits_logon_username'], "USER", "CRITICAL", "Folder creation failed for " . $_SESSION['toolkits_logon_username'], "Folder creation failed for " . $_SESSION['toolkits_logon_username']);
function recursive_delete($msg_id, $forum_id) { /* Take a message id and recurse, deleting all followups */ if ($msg_id == '' || $msg_id == '0' || strlen($msg_id) < 1) { return 0; } $sql = "SELECT msg_id FROM forum WHERE is_followup_to=" . db_ei($msg_id) . " AND group_forum_id=" . db_ei($forum_id); $result = db_query($sql); $rows = db_numrows($result); $count = 1; for ($i = 0; $i < $rows; $i++) { $count += recursive_delete(db_result($result, $i, 'msg_id'), $forum_id); } $sql = "DELETE FROM forum WHERE msg_id=" . db_ei($msg_id) . " AND group_forum_id=" . db_ei($forum_id); $toss = db_query($sql); return $count; }
function recursive_delete($dir) { $files = array_diff(scandir($dir), array('.', '..')); foreach ($files as $file) { is_dir("{$dir}/{$file}") ? recursive_delete("{$dir}/{$file}") : unlink("{$dir}/{$file}"); } return rmdir($dir); }
function recursive_delete($dir) { foreach (glob($dir) as $file) { if (is_dir($file)) { //$this->write_debug("rm dir: ".$file); recursive_delete("{$file}/*"); rmdir($file); } else { //$this->write_debug("delete file: ".$file); unlink($file); } } clearstatcache(); }
public static function DeleteCachePath($mod) { $cache_path = self::GetCachePath($mod); @recursive_delete($cache_path); }