作者:schpil
项目:standalon
public function __destruct()
{
/* On efface le model de la base tampon et on vide la base */
$modelFile = APPLICATION_PATH . DS . 'models' . DS . 'Bigdata' . DS . 'models' . DS . Inflector::lower($this->to->db) . DS . ucfirst(Inflector::lower($this->to->table)) . '.php';
File::delete($modelFile);
$this->to->drop();
}
作者:schpil
项目:standalon
public function __construct($db)
{
$this->orm = $db;
$this->db = $db->db();
$this->table = $db->table();
$dir = Config::get('dir.blizz.store', session_save_path());
if (!is_dir($dir)) {
File::mkdir($dir);
}
$dir .= DS . Inflector::urlize(Inflector::uncamelize($this->db));
if (!is_dir($dir)) {
File::mkdir($dir);
}
$this->dir = $dir . DS . Inflector::urlize(Inflector::uncamelize($this->table));
if (!is_dir($this->dir)) {
File::mkdir($this->dir);
}
$file = $this->dir . DS . 'data.db';
$new = false;
if (!is_file($file)) {
File::create($file);
$new = true;
File::put($this->dir . DS . 'age.blizz', '');
}
$link = new SQLite3($file);
Now::set("blizz.link.{$this->db}.{$this->table}", $link);
if ($new) {
$this->init();
}
}
作者:schpil
项目:standalon
public function model($data = [])
{
$view = false;
$db = $this->db;
$table = $this->table;
$modelFile = APPLICATION_PATH . DS . 'models' . DS . 'Mysql' . DS . 'models' . DS . Inflector::lower($db) . DS . ucfirst(Inflector::lower($table)) . '.php';
if (!is_dir(APPLICATION_PATH . DS . 'models' . DS . 'Mysql')) {
File::mkdir(APPLICATION_PATH . DS . 'models' . DS . 'Mysql');
}
if (!is_dir(APPLICATION_PATH . DS . 'models' . DS . 'Mysql' . DS . 'models')) {
File::mkdir(APPLICATION_PATH . DS . 'models' . DS . 'Mysql' . DS . 'models');
}
if (!is_dir(APPLICATION_PATH . DS . 'models' . DS . 'Mysql' . DS . 'models' . DS . Inflector::lower($db))) {
File::mkdir(APPLICATION_PATH . DS . 'models' . DS . 'Mysql' . DS . 'models' . DS . Inflector::lower($db));
}
if (!File::exists($modelFile)) {
File::put($modelFile, str_replace('##class##', ucfirst(Inflector::lower($db)) . ucfirst(Inflector::lower($table)) . 'SQLModel', File::read(__DIR__ . DS . 'dbModel.tpl')));
}
$class = '\\Thin\\' . ucfirst(Inflector::lower($db)) . ucfirst(Inflector::lower($table)) . 'SQLModel';
if (!class_exists($class)) {
require_once $modelFile;
}
$model = $this;
if (true === $view) {
$model = self::instance($db, $table);
}
return new $class($model, $data);
}
作者:schpil
项目:standalon
public function background()
{
$file = realpath(APPLICATION_PATH . DS . '..' . DS . 'public' . DS . 'scripts' . DS . 'schedule.php');
if (File::exists($file)) {
$cmd = 'php ' . $file;
lib('utils')->backgroundTask($cmd);
}
}
作者:schpil
项目:standalon
public function __construct($ns = 'core.cache')
{
if (!is_dir(STORAGE_PATH . DS . 'kit')) {
File::mkdir(STORAGE_PATH . DS . 'kit');
}
$file = STORAGE_PATH . DS . 'kit' . DS . $ns . '.db';
$this->lite = new SQLite3($file);
$q = "CREATE TABLE IF NOT EXISTS content (k VARCHAR PRIMARY KEY, v, ts);";
$this->raw($q);
}
作者:schpil
项目:standalon
public function getOptionsFromMarket($market_id)
{
if (!is_integer($market_id)) {
throw new Exception("market_id must be an integer id.");
}
$file = APPLICATION_PATH . DS . 'models' . DS . 'options' . DS . $market_id . '.php';
if (File::exists($file)) {
$options = (include $file);
return $options;
}
return [];
}
作者:schpil
项目:standalon
public function __construct($db, $table)
{
$file = Config::get('mlite.dir.' . $db, STORAGE_PATH . DS . $db . '.db');
$new = !is_file($file);
if (!is_file($file)) {
File::create($file);
}
$link = new SQLite3($file);
Now::set("lite.link.{$db}.{$table}", $link);
if ($new) {
$q = "CREATE TABLE IF NOT EXISTS infosdb (data_key VARCHAR PRIMARY KEY, data_value);";
$res = $link->exec($q);
}
$this->table = $table;
$this->database = $db;
}
作者:schpil
项目:standalon
/**
*
* @method __construct
*
* @param string
* @param array
*/
public function __construct(array $data = [])
{
$ns = $this->ns = $this->forever();
$file = Config::get('cachemelite.dir.' . $ns, STORAGE_PATH . DS . $ns . '_cache.db');
$new = !is_file($file);
if (!is_file($file)) {
File::create($file);
}
$db = new SQLite3($file);
Now::set("cachemelite.link.{$ns}", $db);
$q = "CREATE TABLE IF NOT EXISTS cachedb (data_key VARCHAR PRIMARY KEY, data_value);";
$res = $this->db->exec($q);
if (!empty($data)) {
foreach ($data as $k => $v) {
$this->set($k, $v);
}
}
}
作者:schpil
项目:standalon
public function read($id, $default = null)
{
$key = $this->key . '::' . $id;
try {
$result = $this->client->getObject(array('Bucket' => $this->bucket, 'Key' => $key));
} catch (NoSuchKeyException $e) {
if (!strstr($id, 'file::')) {
$data = File::read($this->findFile($id));
} else {
$data = File::read(str_replace('thinseparator', '', str_replace('file::', '', $id)));
}
if (strlen($data)) {
$this->write($id, $data);
return $data;
} else {
return $default;
}
}
return $result['Body'];
}
作者:schpil
项目:standalon
public static function dispatch()
{
static::$method = Request::method();
$uri = substr(str_replace('/ws/', '/', $_SERVER['REQUEST_URI']), 1);
$tab = explode('/', $uri);
if (count($tab) < 3) {
Api::forbidden();
}
$namespace = current($tab);
$controller = $tab[1];
$action = $tab[2];
$tab = array_slice($tab, 3);
$count = count($tab);
if (0 < $count && $count % 2 == 0) {
for ($i = 0; $i < $count; $i += 2) {
$_REQUEST[$tab[$i]] = $tab[$i + 1];
}
}
$file = APPLICATION_PATH . DS . 'webservices' . DS . $namespace . DS . $controller . '.php';
if (!File::exists($file)) {
Api::NotFound();
}
require_once $file;
$class = 'Thin\\' . ucfirst($controller) . 'Ws';
$i = new $class();
$methods = get_class_methods($i);
$call = strtolower(static::$method) . ucfirst($action);
if (!Arrays::in($call, $methods)) {
Api::NotFound();
}
if (Arrays::in('init', $methods)) {
$i->init($call);
}
$i->{$call}();
if (Arrays::in('after', $methods)) {
$i->after();
}
}
作者:schpil
项目:standalon
public function read($id, $default = null)
{
$key = $this->key . '::' . $id;
$row = $this->collection->findOne(function ($query) use($key) {
$query->where('key', $key);
});
if ($row) {
return isAke($row, 'value', $default);
} else {
if (!strstr($id, 'file::')) {
$data = File::read($this->findFile($id));
} else {
$data = File::read(str_replace('thinseparator', '', str_replace('file::', '', $id)));
}
if (strlen($data)) {
$this->write($id, $data);
return $data;
} else {
return $default;
}
}
return $default;
}
作者:schpil
项目:standalon
public function csvByZone($address)
{
ini_set('memory_limit', '1024M');
set_time_limit(0);
$file = '/home/gerald/Bureau/' . Inflector::urlize($address) . '_' . date('dmYHis') . '.csv';
touch($file);
$zone = rdb('geo', 'zone')->where(['address', '=i', $address])->first(true);
if ($zone) {
File::append($file, implode(';', ['category', 'name', 'address', 'lat', 'lng', 'altitude', 'zip', 'city', 'phone', 'mail', 'url']) . "\n");
$pivots = $zone->pivots(rdb('geo', 'etablissement')->model())->exec(true);
foreach ($pivots as $pivot) {
$etab = $pivot->etablissement(true);
if ($zone) {
$relations = $etab->pivots(rdb('geo', 'service'))->exec(true);
foreach ($relations as $relation) {
$sp = $relation->service(true);
if ($sp) {
$item = [];
$item['category'] = str_replace([', ', ','], '-', $sp->label);
$item['name'] = str_replace([', ', ','], '-', $etab->name);
$item['address'] = str_replace([', ', ','], '-', $etab->address);
$item['lat'] = str_replace([', ', ','], '.', $etab->lat);
$item['lng'] = str_replace([', ', ','], '.', $etab->lng);
$item['altitude'] = str_replace([', ', ','], '.', $etab->altitude);
$item['zip'] = str_replace([', ', ','], '-', $etab->zip);
$item['city'] = str_replace([', ', ','], '-', $etab->city);
$item['phone'] = str_replace([', ', ','], '-', $etab->phone);
$item['mail'] = str_replace([', ', ','], '-', $etab->mail);
$item['url'] = str_replace([', ', ','], '-', $etab->url);
File::append($file, implode(';', $item) . "\n");
}
}
}
}
}
}
作者:noiki
项目:inov
private function parse($pageConfig, $htmlTemplate, $htmlPage)
{
eval($pageConfig);
$code = str_replace('@@content', $htmlPage, $htmlTemplate);
$code = str_replace(array('{{', '}}'), array('<?php', '?>'), $code);
if (strstr($code, '@@partial')) {
$partials = $this->getPartials($code);
if (count($partials)) {
foreach ($partials as $partial) {
$partialFile = $this->dir . DS . 'partials' . DS . $partial . '.html';
if (File::exists($partialFile)) {
$code = str_replace("@@partial({$partial})", fgc($partialFile), $code);
}
}
}
}
$vars = $this->getVars($code);
$url = container()->getUrlsite();
$assets = '/content/' . SITE_NAME . '/themes/' . $this->theme . '/assets';
if (count($vars)) {
foreach ($vars as $var) {
if (!isset(${$var})) {
$value = CmsConfig::get($var, false);
if (false === $value) {
$value = isAke($_REQUEST, $var, false);
if (false === $value) {
$value = '';
}
}
} else {
$value = ${$var};
}
$code = str_replace("%({$var})%", $value, $code);
}
}
return $code;
}
作者:schpil
项目:standalon
//.........这里部分代码省略.........
$headers[] = \Thin\Html\Helper::display($label);
}
}
$xlsHeader = '';
foreach ($headers as $header) {
$xlsHeader .= str_replace('##value##', $header, $tplHeader);
}
$excel = str_replace('##headers##', $xlsHeader, $excel);
$xlsContent = '';
foreach ($rows as $item) {
$xlsContent .= '<tr>';
foreach ($fields as $field) {
$fieldSettings = isAke($fieldInfos, $field);
$exportable = isAke($fieldSettings, 'is_exportable', true);
if (true === $exportable) {
$value = isAke($item, $field, ' ');
if (Arrays::exists('content_list', $fieldSettings)) {
$closure = $fieldSettings['content_list'];
if (is_callable($closure)) {
$value = call_user_func_array($closure, array($item));
}
}
if (empty($value)) {
$value = ' ';
}
$xlsContent .= str_replace('##value##', \Thin\Html\Helper::display($value), $tplData);
}
}
$xlsContent .= '</tr>';
}
$excel = str_replace('##content##', $xlsContent, $excel);
$name = 'extraction_' . $this->model->db . '_' . $this->model->table . '_' . date('d_m_Y_H_i_s') . '.xlsx';
$file = TMP_PUBLIC_PATH . DS . $name;
File::delete($file);
File::put($file, $excel);
Utils::go(URLSITE . '/tmp/' . $name);
} elseif ('pdf' == $type) {
$pdf = '<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="//fonts.googleapis.com/css?family=Abel" rel="stylesheet" type="text/css" />
<title>Extraction ' . $this->model->db . ' - ' . $this->model->table . '</title>
<style>
*
{
font-family: Abel, ubuntu, verdana, tahoma, arial, sans serif;
font-size: 11px;
}
h1
{
text-transform: uppercase;
font-size: 135%;
}
th
{
font-size: 120%;
color: #fff;
background-color: #394755;
text-transform: uppercase;
}
td
{
border: solid 1px #394755;
}
a, a:visited, a:hover
作者:schpil
项目:thi
public static function run()
{
Request::$route = $route = Utils::get('appDispatch');
container()->setRoute($route);
$render = $route->getRender();
$tplDir = $route->getTemplateDir();
$module = $route->getModule();
$controller = $route->getController();
$action = $route->getAction();
$alert = $route->getAlert();
$page = container()->getPage();
$isCms = !empty($page);
if (!empty($render)) {
$tplMotor = $route->getTemplateMotor();
$tplDir = empty($tplDir) ? APPLICATION_PATH . DS . SITE_NAME . DS . 'app' . DS . 'views' : $tplDir;
$tpl = $tplDir . DS . $render . '.phtml';
if (File::exists($tpl)) {
if ('Twig' == $tplMotor) {
if (!class_exists('Twig_Autoloader')) {
require_once 'Twig/Autoloader.php';
}
$tab = explode(DS, $tpl);
$file = Arrays::last($tab);
$path = repl(DS . $file, '', $tpl);
$loader = new \Twig_Loader_Filesystem($path);
$view = new \Twig_Environment($loader, array('cache' => CACHE_PATH, 'debug' => false, 'charset' => 'utf-8', 'strict_variables' => false));
container()->setView($view);
if ($action instanceof Closure) {
$action($view);
}
$params = null === container()->getViewParams() ? array() : container()->getViewParams();
echo $view->render($file, $params);
/* stats */
if (null === container()->getNoShowStats() && null === $route->getNoShowStats()) {
echo View::showStats();
}
} else {
$view = new View($tpl);
container()->setView($view);
if ($action instanceof Closure) {
$action($view);
}
$view->render();
/* stats */
if (null === container()->getNoShowStats() && null === $route->getNoShowStats()) {
echo View::showStats();
}
}
return;
}
}
$module = Inflector::lower($module);
$controller = Inflector::lower($controller);
$action = Inflector::lower($action);
if (true === container()->getMultiSite()) {
$moduleDir = APPLICATION_PATH . DS . SITE_NAME . DS . 'modules' . DS . $module;
} else {
$moduleDir = APPLICATION_PATH . DS . 'modules' . DS . $module;
}
if (!is_dir($moduleDir)) {
throw new Exception("The module '{$module}' does not exist.");
}
$controllerDir = $moduleDir . DS . 'controllers';
if (!is_dir($controllerDir)) {
throw new Exception("The controller '{$controller}' does not exist.");
}
$controllerFile = $controllerDir . DS . $controller . 'Controller.php';
if (!File::exists($controllerFile)) {
throw new Exception("The controller '{$controllerFile}' does not exist.");
}
require_once $controllerFile;
$controllerClass = 'Thin\\' . $controller . 'Controller';
$controller = new $controllerClass();
$controller->view = new View($route->getView());
if (null !== $alert) {
$controller->view->alert($alert);
}
container()->setController($controller);
$actions = get_class_methods($controllerClass);
if (true === $isCms) {
if (!Arrays::inArray($action, $actions)) {
$action = 'page';
}
}
container()->setAction($action);
if (strstr($action, '-')) {
$words = explode('-', $action);
$newAction = '';
for ($i = 0; $i < count($words); $i++) {
$word = trim($words[$i]);
if ($i > 0) {
$word = ucfirst($word);
}
$newAction .= $word;
}
$action = $newAction;
}
$actionName = $action . 'Action';
if (Arrays::in('init', $actions)) {
$controller->init();
//.........这里部分代码省略.........
作者:schpil
项目:standalon
public function valid()
{
$file = $this->cursor . DS . $this->position . '.php';
return File::exists($file);
}
作者:schpil
项目:standalon
public static function generate($model, $overwrite = false)
{
$file = APPLICATION_PATH . DS . 'models' . DS . 'Crud' . DS . ucfirst(Inflector::camelize($model)) . '.php';
if (!File::exists($file) || $overwrite) {
$db = model($model);
$crud = new Crud($db);
File::delete($file);
$tplModel = fgc(__DIR__ . DS . 'Model.tpl');
$tplField = fgc(__DIR__ . DS . 'Field.tpl');
$fields = $crud->fields();
$singular = ucfirst($model);
$plural = $singular . 's';
$default_order = $crud->pk();
$tplModel = str_replace(array('##singular##', '##plural##', '##default_order##'), array($singular, $plural, $default_order), $tplModel);
$fieldsSection = '';
foreach ($fields as $field) {
if ($field != $crud->pk()) {
$label = substr($field, -3) == '_id' ? ucfirst(str_replace('_id', '', $field)) : ucfirst(Inflector::camelize($field));
$fieldsSection .= str_replace(array('##field##', '##label##'), array($field, $label), $tplField);
}
}
$tplModel = str_replace('##fields##', $fieldsSection, $tplModel);
File::put($file, $tplModel);
}
}
作者:schpil
项目:thi
/**
* Destructor
*
* Delete all files created by syrup component run
*/
function __destruct()
{
$preserveRunFolder = $this->preserveRunFolder;
$fs = new Filesystem();
foreach ($this->files as $file) {
if ($file['preserve']) {
$preserveRunFolder = true;
}
if (File::exists($file['file']) && File::is($file['file']) && true !== $file['preserve']) {
$fs->remove($file['file']);
}
}
if (false === $preserveRunFolder) {
$fs->remove($this->tmpRunFolder);
}
}
作者:schpil
项目:standalon
private function prepare()
{
$results = $collection = [];
$hash = $this->db->getHash();
$this->cursor = $this->db->motor()->getPath() . DS . 'cursors' . DS . $hash;
if (is_dir($this->cursor)) {
$ageCursor = filemtime($this->cursor . DS . '.');
$ageDb = $this->db->getAge();
if ($ageDb < $ageCursor) {
$this->count = count(glob($this->cursor . DS . '*.php', GLOB_NOSORT));
return;
} else {
File::rmdir($this->cursor);
}
}
File::mkdir($this->db->motor()->getPath() . DS . 'cursors');
File::mkdir($this->db->motor()->getPath() . DS . 'cursors' . DS . $hash);
if (empty($this->db->wheres)) {
$ids = $this->db->motor()->ids('datas');
foreach ($ids as $id) {
$results[$id] = [];
}
unset($ids);
} else {
$results = $this->db->results;
}
$this->count = count($results);
if (empty($results)) {
File::rmdir($this->cursor);
return true;
} else {
$index = 0;
foreach ($results as $id => $row) {
if (false !== $id) {
$file = $this->cursor . DS . $index . '.php';
$data = $this->db->motor()->read('datas.' . $id);
File::put($file, "<?php\nreturn " . var_export($data, 1) . ';');
$index++;
}
}
}
}
作者:schpil
项目:standalon
public function getHashFile($hash, $file)
{
if (!is_dir($this->dir . DS . $hash)) {
File::mkdir($this->dir . DS . $hash);
}
return $this->dir . DS . $hash . DS . $file . '.raw';
}