} } $data = $_POST; $data['post'] = $_POST; $data['email'] = $email; $data['text'] = $text; $data['name'] = $persona; $data['schema'] = View::getSchema(); $data['host'] = View::getHost(); $data['org'] = @$_POST['org']; $data['phone'] = @$_POST['phone']; $data['ip'] = $_SERVER['REMOTE_ADDR']; $data['ref'] = $_SERVER['HTTP_REFERER']; $data['browser'] = $_SERVER['HTTP_USER_AGENT']; $data['time'] = date("F j, Y, g:i a"); $maildir = Path::resolve('~.contacts/'); if (!is_dir($maildir)) { mkdir($maildir); } $mdata = array(); $p = explode(',', $data['email']); $mdata['email_from'] = $p[0]; $mdata['subject'] = 'Сообщение через форму контактов ' . $_SERVER['HTTP_HOST']; if (trim(mb_strtolower($data['name'])) == 'itlife') { $data['text'] = print_r($mdata, true) . "\n\n" . $data['text']; $mdata['subject'] = 'ПРОВЕРОЧНОЕ ' . $mdata['subject']; $mdata['testmail'] = true; } else { $mdata['testmail'] = false; session_start(); if (empty($_SESSION['submit_time'])) {
function autoedit_takepath($file = false) { $takepath = Path::resolve('!admin_takefiles/'); if ($file === false) { return $takepath; } $file = autoedit_theme($file); $path = $takepath . preg_replace('/[\\/\\\\\\*]/', '_', Path::tofs($file)) . '.js'; return $path; }
return Ans::ret($ans); } } elseif ($type == 'takeshow') { $takepath = autoedit_takepath(); $list = array(); array_map(function ($file) use(&$list, $takepath) { if ($file == '.' || $file == '..') { return; } $list[] = Path::toutf($file); }, scandir($takepath)); $files = array(); if ($list) { foreach ($list as $file) { $d = Load::loadJSON($takepath . $file); $d['path'] = Path::resolve($d['path']); $d['modified'] = filemtime(Path::theme($d['path'])); preg_match("/\\.([a-zA-Z]+)\$/", $d['path'], $match); $d['ext'] = strtolower($match[1]); $files[] = $d; } } $ans['files'] = $files; } elseif ($type == 'takefile') { if ($submit) { $take = (bool) $_GET['take']; $ans['take'] = $take; $file = autoedit_theme($id); $file = Path::toutf($file); if (!$file) { $ans['noaction'] = true;
/** * Удалить (true) или очистить дирректорию (false) * **/ public static function fullrmdir($delfile, $ischild = false) { if (!static::$conf['fs']) { throw new \Exception('Work with filesystem forbbiden conf.path.fs'); } if (!$delfile) { throw new Exception('Нужно указать существующий путь до папки для удаления'); } $delfile = Path::resolve($delfile); if (file_exists($delfile)) { if (!$delfile) { throw new Exception('Удалить корневую папку нельзя'); } if (is_dir($delfile)) { $handle = opendir($delfile); while ($filename = readdir($handle)) { if ($filename != '.' && $filename != '..') { $src = $delfile . $filename; if (is_dir($src)) { $src .= '/'; } $r = static::fullrmdir($src, true); if (!$r) { return false; } } } closedir($handle); if ($ischild) { //Once::clear('Path::theme', array(Path::resolve($delfile))); //Once::clear('Path::theme', array($delfile)); return rmdir($delfile); } return true; } else { //Once::clear('Path::theme', array(Path::resolve($delfile))); //Once::clear('Path::theme', array($delfile)); return unlink($delfile); } } return true; }
public static function addFiles($root, &$pos, $dir = false) { $props = array('producer', 'article'); if (!isset($pos['images'])) { $pos['images'] = array(); } if (!isset($pos['texts'])) { $pos['texts'] = array(); } if (!isset($pos['files'])) { $pos['files'] = array(); } if (!$dir) { $dir = array(); $pth = Path::resolve($root); if (Each::forr($props, function &($name) use(&$dir, &$pos) { $rname = Sequence::right($name); $val = Sequence::get($pos, $rname); if (!$val) { return true; } $dir[] = $val; $r = null; return $r; })) { return; } if ($dir) { $dir = implode('/', $dir) . '/'; $dir = $pth . $dir; } else { $dir = $pth; } } else { $dir = $root . $dir; } $dir = Path::theme($dir); if (!$dir) { return false; } if (is_dir($dir)) { $paths = glob($dir . '*'); } elseif (is_file($dir)) { $paths = array($dir); $p = Load::srcInfo($dir); $dir = $p['folder']; } Each::forr($paths, function &($p) use(&$pos, $dir) { $d = explode('/', $p); $name = array_pop($d); $n = mb_strtolower($name); $fd = Load::nameInfo($n); $ext = $fd['ext']; //if(!$ext)return; if (!is_file($dir . $name)) { return; } //$name=preg_replace('/\.\w{0,4}$/','',$name); /*$p=pathinfo($p); $name=$p['basename']; $ext=strtolower($p['extension']);*/ if ($name[0] == '.') { return; } $dir = Path::pretty($dir); $name = Path::toutf($dir . $name); $im = array('png', 'gif', 'jpg'); $te = array('html', 'tpl', 'mht', 'docx'); if (in_array($ext, $im)) { $pos['images'][] = $name; } else { if (in_array($ext, $te)) { $pos['texts'][] = $name; } else { if ($ext != 'db') { $pos['files'][] = $name; } } } $r = null; return $r; }); $pos['images'] = array_unique($pos['images']); $pos['texts'] = array_unique($pos['texts']); $pos['files'] = array_unique($pos['files']); }
public static function optipng($data, $id) { if (!Imager::$conf['optipng']) { return $data; } $src = Path::resolve(Imager::$conf['cache']) . 'opti.' . $id . '.png'; file_put_contents($src, $data); if (Imager::$conf['optipng'] === true) { $o = 2; } else { $o = (int) Imager::$conf['optipng']; } exec('optipng ' . $src . ' -o' . $o . ' -out ' . $src . '.res.png'); $data = file_get_contents($src . '.res.png'); unlink($src . '.res.png'); return $data; }
$conf = Config::get('subscribe'); if (empty($_REQUEST['email'])) { return Ans::err($ans, $conf['msg']); } if (strlen($_REQUEST['email']) > 1000) { return Ans::err($ans, 'Слишком много данных. ' . $conf['msg']); } $email = strip_tags($_REQUEST['email']); $email = trim($email); $email = Path::encode($email); $agent = $_SERVER['HTTP_USER_AGENT']; $ip = $_SERVER['REMOTE_ADDR']; session_start(); if (empty($_SESSION['submit_time'])) { $_SESSION['submit_time'] = 0; } if (time() - $_SESSION['submit_time'] < 60) { return Ans::err($ans, 'Письмо уже отправлено! Новое сообщение можно будет отправить через 1 минуту!'); } $_SESSION['submit_time'] = time(); $data = array('email' => $email, 'agent' => $agent, 'ip' => $ip, 'host' => $_SERVER['HTTP_HOST']); $body = Template::parse('-subscribe/subscribe.mail.tpl', $data); Mail::toAdmin('Запрос ' . $data['host'] . ' ' . $email, 'noreplay@' . $data['host'], $body); $src = Path::resolve('~.subscribe.json'); $subs = Load::loadJSON($src); if (!$subs) { $subs = array(); } $subs[$email] = date('d.m.Y'); file_put_contents($src, Load::json_encode($subs)); return Ans::ret($ans, 'Ваша заявка принята');
if ($dir) { if (!Path::$conf['fs']) { throw new \Exception('Filesystem protected by Path::$conf[fs]=false set it on true'); } foreach (glob($dir . '*.*') as $filename) { @unlink($filename); } } } } public static function &memcache() { return Once::exec('Mem::memcache', function () { $conf = Mem::$conf; if ($conf['type'] != 'mem') { return false; } if (!class_exists('Memcache')) { return false; } if (!$conf['memcache']) { return false; } $infra_mem = new \Memcache(); $infra_mem->connect($conf['memcache']['host'], $conf['memcache']['port']) or die('Could not connect'); return $infra_mem; }); } } Mem::$conf = array('type' => 'fs', 'memcache' => array('host' => 'localhost', 'port' => 23), 'cache' => Path::resolve('!mem/'));