public static function delete($path) { if (_is_dir($path)) { return false; } $err = !@_unlink($path); return $err; }
public function delete() { $Register = Register::getInstance(); $attachClass = $Register['ModManager']->getModelNameFromModule('loadsAttaches'); $commentsClass = $Register['ModManager']->getModelNameFromModule('Comments'); $addContentClass = $Register['ModManager']->getModelNameFromModule('loadsAddContent'); $attachesModel = new $attachClass(); $commentsModel = new $commentsClass(); $addContentModel = new $addContentClass(); $attachesModel->deleteByParentId($this->id); $commentsModel->deleteByParentId($this->id, array('module' => 'loads')); $addContentModel->deleteByParentId($this->id); if (file_exists(ROOT . '/sys/files/loads/' . $this->download)) { _unlink(ROOT . '/sys/files/loads/' . $this->download); } $Register['DB']->delete('loads', array('id' => $this->id)); $Register['URL']->removeOldTmpFiles($this, 'loads'); }
function deleteAttach($module, $entity_id, $attachNum) { $Register = Register::getInstance(); $attachModelClass = $Register['ModManager']->getModelNameFromModule($module . 'Attaches'); $attachModel = new $attachModelClass(); $attaches = $attachModel->getCollection(array('entity_id' => $entity_id, 'attach_number' => $attachNum), array()); if (count($attaches) > 0 && is_array($attaches)) { foreach ($attaches as $attach) { if (!empty($attach)) { $filePath = ROOT . '/sys/files/' . $module . '/' . $attach->getFilename(); if (file_exists($filePath)) { _unlink($filePath); } $attach->delete(); } } } return true; }
public function delete_attach($id) { $this->counter = false; if (!$this->ACL->turn(array($this->module, 'delete_attaches'), false)) { $this->showAjaxResponse(array('errors' => __('Permission denied'), 'result' => '0')); } if (empty($_SESSION['user']['id'])) { $this->showAjaxResponse(array()); } $user_id = $_SESSION['user']['id']; $attachModel = $this->Register['ModManager']->getModelInstance($this->module . 'Attaches'); $attach = $attachModel->getById($id); $errors = ''; if ($user_id !== $attach->getUser_id()) { $errors .= '<li>' . __('Permission denied') . '</li>'; } if (!empty($errors)) { $this->showAjaxResponse(array('result' => '0', 'errors' => $this->Register['DocParser']->wrapErrors($errors))); } if ($attach) { $filename = $attach->getFilename(); if (!empty($filename) && file_exists(ROOT . '/sys/files/' . $this->module . '/' . $filename)) { _unlink(ROOT . '/sys/files/' . $this->module . '/' . $filename); } $attach->delete(); } $this->showAjaxResponse(array('result' => '1')); }
function _unlink($path) { if (is_dir($path)) { $files = glob(rtrim($path, '/\\') . '/*'); if (is_array($files) && count($files)) { foreach ($files as $file) { _unlink($file); } } rmdir($path); } else { if (is_file($path)) { unlink($path); } } }
<?php /*-----------------------------------------------\ | | | @Author: Andrey Brykin (Drunya) | | @Email: drunyacoder@gmail.com | | @Site: http://atomx.net | | @Version: 1.4 | | @Project: CMS | | @package CMS AtomX | | @subpackege Admin Panel module | | @copyright ©Andrey Brykin 2010-2013 | \-----------------------------------------------*/ /*-----------------------------------------------\ | | | any partial or not partial extension | | CMS AtomX,without the consent of the | | author, is illegal | |------------------------------------------------| | Любое распространение | | CMS AtomX или ее частей, | | без согласия автора, является не законным | \-----------------------------------------------*/ include_once '../sys/boot.php'; include_once ROOT . '/admin/inc/adm_boot.php'; $_SESSION['message'] = __('Cache is cleared'); $Register['Cache']->clean(); $Snippets = new AtmSnippets(); $Snippets->cleanCahe(); _unlink(ROOT . '/sys/cache/templates/'); redirect('/admin');
public function install($filename) { $src = ROOT . '/sys/tmp/' . $filename; $dest = ROOT . '/sys/tmp/install_plugin/'; Zip::extractZip($src, $dest); if (!file_exists($dest)) { $this->errors = __('Some error occurred'); return false; } $tmp_plugin_path = glob($dest . '*', GLOB_ONLYDIR); $tmp_plugin_path = $tmp_plugin_path[0]; $plugin_basename = substr(strrchr($tmp_plugin_path, '/'), 1); $plugin_path = ROOT . '/sys/plugins/' . $plugin_basename; copyr($dest, ROOT . '/sys/plugins/', 0755); $this->files = getDirFiles($plugin_path); if (file_exists($plugin_path . '/config.dat')) { $config = json_decode(file_get_contents($plugin_path . '/config.dat'), true); include_once $plugin_path . '/index.php'; $className = $config['className']; $obj = new $className(null); if (method_exists($obj, 'install')) { $obj->install(); } } _unlink($src); _unlink($dest); return true; }
} else { die("ERROR: Unrecognized argument: {$arg}\n"); } } else { $args[] = $arg; } } function _unlink($loc) { file_exists($loc) && unlink($loc); } if ($clean) { _unlink('cache/nodes'); _unlink('cache/resources'); _unlink('cache/' . ($outfile ? $outfile : 'api') . '.json'); _unlink('cache/' . ($outfile ? $outfile : 'api') . '.xml'); } $files = dojo_get_files($args); $nodes = new Freezer('cache', 'nodes'); $resources = new Freezer('cache', 'resources'); print "=== PARSING FILES ===\n"; flush(); foreach ($files as $set) { list($namespace, $file) = $set; if (!$namespaces[$namespace]) { $namespaces[$namespace] = true; } $ctime = dojo_get_file_time($namespace, $file); if ($ctime == $resources->open($namespace . '%' . $file, null)) { continue; }
public static function index() { $Register = Register::getInstance(); //ip if (!empty($_SERVER['REMOTE_ADDR'])) { $ip = $_SERVER['REMOTE_ADDR']; } else { $ip = !empty($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : '00.00.00.00'; } if (mb_strlen($ip) > 20 || !preg_match('#^\\d+\\.\\d+\\.\\d+\\.\\d+$#', $ip)) { $ip = '00.00.00.00'; } if (!file_exists(ROOT . '/sys/logs/counter_ips' . date("Y-m-d"))) { $counter_tmp_dirs = glob(ROOT . '/sys/logs/counter_ips*'); if (!empty($counter_tmp_dirs) && is_array($counter_tmp_dirs)) { foreach ($counter_tmp_dirs as $dir) { _unlink($dir); } } mkdir(ROOT . '/sys/logs/counter_ips' . date("Y-m-d"), 0777, true); } if (!file_exists(ROOT . '/sys/logs/counter_ips' . date("Y-m-d") . '/' . $ip . '.dat')) { $inc_ip = 1; $file = fopen(ROOT . '/sys/logs/counter_ips' . date("Y-m-d") . '/' . $ip . '.dat', 'w'); fclose($file); } else { $inc_ip = 0; } //visits from other sites if (!empty($_SERVER['HTTP_REFERER']) && !preg_match('#^http://' . $_SERVER['SERVER_NAME'] . '#', $_SERVER['HTTP_REFERER'])) { $other_site_view = 1; } else { $other_site_view = 0; } //user agent and bot identification $other_bot = 0; $yandex_bot = 0; $google_bot = 0; if (empty($_SERVER["HTTP_USER_AGENT"])) { $other_bot = 1; } else { if (strstr($_SERVER["HTTP_USER_AGENT"], "Yandex")) { $yandex_bot = 1; } elseif (strstr($_SERVER["HTTP_USER_AGENT"], "Googlebot")) { $google_bot = 1; } else { if (strstr($_SERVER["HTTP_USER_AGENT"], "StackRambler") || strstr($_SERVER["HTTP_USER_AGENT"], "Scooter") || strstr($_SERVER["HTTP_USER_AGENT"], "Fast") || strstr($_SERVER["HTTP_USER_AGENT"], "infoseek") || strstr($_SERVER["HTTP_USER_AGENT"], "YahooBot") || strstr($_SERVER["HTTP_USER_AGENT"], "aport") || strstr($_SERVER["HTTP_USER_AGENT"], "slurp") || strstr($_SERVER["HTTP_USER_AGENT"], "architextspider") || strstr($_SERVER["HTTP_USER_AGENT"], "lycos") || strstr($_SERVER["HTTP_USER_AGENT"], "grabber") || strstr(strtolower($_SERVER["HTTP_USER_AGENT"]), "bot") || strstr(strtolower($_SERVER["HTTP_USER_AGENT"]), "spider")) { $other_bot = 1; } } } //referer $referer = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; //check coocie if (isset($_COOKIE['counter']) || (!empty($other_bot) || !empty($yandex_bot) || !empty($google_bot))) { $cookie = 0; } else { $cookie = 1; //cookie die in 23:59:59 this day $curdate = date("n,j,Y"); $curdate = explode(',', $curdate); $timestamp = mktime(23, 59, 59, $curdate[0], $curdate[1], $curdate[2]); setcookie('counter', md5($ip), $timestamp, '/'); } $view = !empty($other_bot) || !empty($yandex_bot) || !empty($google_bot) ? 0 : 1; touchDir(ROOT . '/sys/logs/counter/', 0777); $tmp_datafile = ROOT . '/sys/logs/counter/' . date("Y-m-d") . '.dat'; if (file_exists($tmp_datafile) && is_readable($tmp_datafile)) { $stats = unserialize(file_get_contents($tmp_datafile)); $stats['views'] = $stats['views'] + $view; $stats['cookie'] = $stats['cookie'] + $cookie; $stats['ips'] = $stats['ips'] + $inc_ip; $stats['yandex_bot_views'] = $stats['yandex_bot_views'] + $yandex_bot; $stats['google_bot_views'] = $stats['google_bot_views'] + $google_bot; $stats['other_bot_views'] = $stats['other_bot_views'] + $other_bot; $stats['other_site_visits'] = $stats['other_site_visits'] + $other_site_view; } else { $stats = array('views' => 1, 'cookie' => 1, 'ips' => 1, 'yandex_bot_views' => $yandex_bot, 'google_bot_views' => $google_bot, 'other_bot_views' => $other_bot, 'other_site_visits' => $other_site_view); } $f = fopen($tmp_datafile, 'w+'); flock($f, LOCK_EX); fwrite($f, serialize($stats)); flock($f, LOCK_UN); fclose($f); //statistics data for counter image if (!file_exists(ROOT . '/sys/logs/overal_stats.dat')) { StatisticsModule::_updateOveralHits(); } $overal = unserialize(file_get_contents(ROOT . '/sys/logs/overal_stats.dat')); if (!isset($overal['hits'])) { $overal['hits'] = StatisticsModule::_updateOveralHits(); } $all_hits = (int) $overal['hits'] + $stats['views']; $hosts = $stats['cookie']; $hits = $stats['views']; //write into data base and delete file (one time in day) $tmp_files = glob(ROOT . '/sys/logs/counter/*.dat'); if (!empty($tmp_files) && count($tmp_files) > 1) { foreach ($tmp_files as $file) { $date = substr(strrchr($file, '/'), 1, 10); if ($date === date("Y-m-d")) { continue; } StatisticsModule::_writeIntoDataBase($date); unlink($file); StatisticsModule::_deleteOveralKey('hits'); } } self::viewCounter($all_hits, $hits, $hosts); //who online touchDir(ROOT . '/sys/logs/counter_online/'); $path = ROOT . '/sys/logs/counter_online/online.dat'; $users = array(); $guests = array(); $online_users = array(); if (file_exists($path) && is_readable($path)) { $data = unserialize(file_get_contents($path)); $users = !empty($data['users']) ? $data['users'] : array(); $guests = !empty($data['guests']) ? $data['guests'] : array(); } foreach ($users as $key => $user) { if ($user['expire'] < time()) { unset($users[$key]); break; } // online users list if (strstr($key, 'bot')) { $online_users[] = '<span class="botname">' . h($user['name']) . '</span>'; continue; } $color = ''; if (isset($user['status'])) { $group_info = $Register['ACL']->get_user_group($user['status']); if (!empty($group_info['color'])) { $color = 'color:#' . $group_info['color'] . ';'; } } $online_users[] = get_link(h($user['name']), getProfileUrl($key), array('style' => $color)); } foreach ($guests as $key => $guest) { if ($guest['expire'] < time()) { unset($guests[$key]); } } $_SESSION['online_users_list'] = count($online_users) ? implode(', ', $online_users) : ''; // Max users online in one time $all_online = intval(count($users) + count($guests)); if (!empty($overal['max_users_online']) && is_numeric($overal['max_users_online'])) { if ($overal['max_users_online'] < $all_online) { StatisticsModule::_updateOveralHits(array('max_users_online', 'max_users_online_date'), array($all_online, date("Y-m-d"))); } } else { StatisticsModule::_updateOveralHits(array('max_users_online', 'max_users_online_date'), array($all_online, date("Y-m-d"))); } if (empty($_SERVER['HTTP_USER_AGENT'])) { $_SERVER["HTTP_USER_AGENT"] = ''; } if (!empty($_SESSION['user']['id'])) { $users[$_SESSION['user']['id']] = array('expire' => time() + $Register['Config']->read('time_on_line') * 60, 'name' => $_SESSION['user']['name'], 'status' => $_SESSION['user']['status']); } else { if (strstr($_SERVER["HTTP_USER_AGENT"], "StackRambler")) { $users['bot_rambler'] = array('expire' => time() + $Register['Config']->read('time_on_line') * 60, 'name' => 'Rambler[bot]'); } else { if (strstr($_SERVER["HTTP_USER_AGENT"], "YahooBot")) { $users['bot_yahoo'] = array('expire' => time() + $Register['Config']->read('time_on_line') * 60, 'name' => 'Yahoo[bot]'); } else { if (strstr($_SERVER["HTTP_USER_AGENT"], "Yandex")) { $users['bot_yandex'] = array('expire' => time() + $Register['Config']->read('time_on_line') * 60, 'name' => 'Yandex[bot]'); } else { if (strstr($_SERVER["HTTP_USER_AGENT"], "Googlebot")) { $users['bot_google'] = array('expire' => time() + $Register['Config']->read('time_on_line') * 60, 'name' => 'Google[bot]'); } else { $guests[$ip] = array('expire' => time() + $Register['Config']->read('time_on_line') * 60); } } } } } file_put_contents($path, serialize(array('users' => $users, 'guests' => $guests))); return; }
public function delete_attach($id) { $this->counter = false; if (!$this->ACL->turn(array($this->module, 'edit_products'), false)) { $this->showAjaxResponse(array('errors' => __('Permission denied'), 'result' => '0')); } if (empty($_SESSION['user']['id'])) { $this->showAjaxResponse(array()); } $attachModel = $this->Register['ModManager']->getModelInstance($this->module . 'Attaches'); $attach = $attachModel->getById($id); $errors = ''; if (!empty($errors)) { $this->showAjaxResponse(array('result' => '0', 'errors' => $this->Register['DocParser']->wrapErrors($errors))); } if ($attach) { $filename = $attach->getFilename(); if (!empty($filename) && file_exists(ROOT . '/sys/files/' . $this->module . '/' . $filename)) { _unlink(ROOT . '/sys/files/' . $this->module . '/' . $filename); } if ($attach->getIs_main() == 1) { $new_main = $attachModel->getFirst(array('id != ' + $id, 'entity_id' => $attach->getEntity_id())); if ($new_main) { $new_main->setIs_main('1')->save(); } } $attach->delete(); if ($this->Log) { $this->Log->write('delete attach(' . $this->module . ')', 'id(' . $id . ')'); } } $this->showAjaxResponse(array('result' => '1')); }
function rmdir_recursive($path) { $path = substr($path, -1) == '/' || substr($path, -1) == '\\' ? $path : $path . '/'; $files = filelist($path, 1, 0, 'all'); $files = !is_array($files) ? array() : $files; //First delete the files only foreach ($files as $k => $v) { @chmod($k, 0777); if (file_exists($k) && is_file($k) && @filetype($k) == "file") { @_unlink($k); } } @clearstatcache(); $folders = filelist($path, 1, 1, 'all'); $folders = !is_array($folders) ? array() : $folders; @krsort($folders); //Now Delete the FOLDERS foreach ($folders as $k => $v) { @chmod($k, 0777); if (is_dir($k)) { @_rmdir($k); } } @_rmdir($path); @clearstatcache(); }
/** * * Validate data and update record into * Data Base. If an errors, redirect user to add form * and show error message where speaks as not to admit * errors in the future * */ public function update($id = null) { $id = (int) $id; if ($id < 1) { redirect('/' . $this->module . '/'); } $target = $this->Model->getById($id); if (!$target) { redirect('/' . $this->module . '/'); } //turn access if (!$this->ACL->turn(array($this->module, 'edit_materials'), false) && (!empty($_SESSION['user']['id']) && $target->getAuthor_id() == $_SESSION['user']['id'] && $this->ACL->turn(array($this->module, 'edit_mine_materials'), false)) === false) { return $this->showInfoMessage(__('Permission denied'), '/' . $this->module . '/'); } $errors = $this->Register['Validate']->check($this->Register['action']); // Check additional fields if an exists. // This must be doing after define $error variable. if (is_object($this->AddFields)) { try { $_addFields = $this->AddFields->checkFields(); } catch (Exception $e) { $errors[] = $this->AddFields->getErrors(); } } $valobj = $this->Register['Validate']; $fields = array('description', 'tags', 'sourse', 'sourse_email', 'sourse_site', 'download_url', 'download_url_size'); $fields_settings = $this->Register['Config']->read('fields', $this->module); foreach ($fields as $field) { if (empty($_POST[$field]) && in_array($field, $fields_settings)) { ${$field} = null; } else { ${$field} = trim($_POST[$field]); } } // Обрезаем переменные до длины, указанной в параметре maxlength тега input $title = trim(mb_substr($_POST['title'], 0, 128)); $editLoad = trim($_POST['mainText']); $in_cat = intval($_POST['cats_selector']); $commented = !empty($_POST['commented']) ? 1 : 0; $available = !empty($_POST['available']) ? 1 : 0; if (!$this->ACL->turn(array($this->module, 'record_comments_management'), false)) { $commented = '1'; } if (!$this->ACL->turn(array($this->module, 'hide_material'), false)) { $available = '1'; } // Preview if (isset($_POST['viewMessage'])) { $_SESSION['viewMessage'] = array_merge(array('title' => null, 'mainText' => null, 'in_cat' => $in_cat, 'description' => null, 'tags' => null, 'sourse' => null, 'sourse_email' => null, 'sourse_site' => null, 'download_url' => null, 'download_url_size' => null, 'commented' => null, 'available' => null), $_POST); redirect('/' . $this->module . '/edit_form/' . $id); } if (!empty($in_cat)) { $sectionsModel = $this->Register['ModManager']->getModelInstance($this->module . 'Categories'); $category = $sectionsModel->getById($in_cat); if (!$category) { $errors[] = __('Can not find category'); } } // Delete attached file if an exists and we get flag from editor if (!empty($_POST['delete_file']) || !empty($_FILES['attach_file']['name'])) { if ($target->getDownload() && file_exists($this->attached_files_path . $target->getDownload())) { _unlink($this->attached_files_path . $target->getDownload()); } } // Errors if (!empty($errors)) { $_SESSION['FpsForm'] = array_merge(array('title' => null, 'mainText' => null, 'description' => null, 'tags' => null, 'sourse' => null, 'sourse_email' => null, 'in_cat' => $in_cat, 'sourse_site' => null, 'download_url' => null, 'download_url_size' => null, 'commented' => null, 'available' => null), $_POST); $_SESSION['FpsForm']['errors'] = $errors; redirect('/' . $this->module . '/edit_form/' . $id); } //Проверяем прикрепленный файл... $file = ''; if (!empty($_FILES['attach_file']['name'])) { $file = $this->__saveFile($_FILES['attach_file']); } downloadAttaches($this->module, $id); // Auto tags generation if (empty($tags)) { $TagGen = new MetaTags(); $tags = $TagGen->getTags($editLoad); $tags = !empty($tags) && is_array($tags) ? implode(',', array_keys($tags)) : ''; } $max_lenght = Config::read('max_lenght', $this->module); $editLoad = mb_substr($editLoad, 0, $max_lenght); // Запрос на обновление новости $data = array('id' => $id, 'title' => $title, 'main' => $editLoad, 'category_id' => $in_cat, 'description' => $description, 'tags' => $tags, 'sourse' => $sourse, 'sourse_email' => $sourse_email, 'sourse_site' => $sourse_site, 'download_url' => $download_url, 'download_url_size' => $download_url_size, 'commented' => $commented, 'available' => $available); if (!empty($file)) { $data['download'] = $file; } $target($data); $target->save(); // Save additional fields if they is active if (is_object($this->AddFields)) { $this->AddFields->save($id, $_addFields); } //clear cache $this->Cache->clean(CACHE_MATCHING_TAG, array('record_id_' . $id, 'module_' . $this->module)); $this->DB->cleanSqlCache(); if ($this->Log) { $this->Log->write('editing ' . $this->module, 'ent. id(' . $id . ')'); } return $this->showInfoMessage(__('Operation is successful'), getReferer()); }