/** * Construct the class. * * @return void */ public function __construct($name = null) { $name = is_null($name) ? 'cart' : $name; $this->session = session('cart.' . $name); $this->collection = lib('items'); $this->setCart($name); }
public function getAffiliation($reseller_id, $array = true) { $metiers = Model::Segmentreseller()->where(['reseller_id', '=', (int) $reseller_id])->with('segment'); $out = $marches = []; foreach ($metiers as $metier) { if (isset($metier['segment'])) { switch ($metier['segment']['id']) { case 413: $marches[413] = ['id' => 413, 'name' => $metier['segment']['name']]; $opt_data = lib('forms')->getOptionsMacroData(413); if (isAke($opt_data, 'affiliation_resto', null) == 1) { $marches[413]['name'] = $marches[413]['name'] . ' ' . 'resto'; } elseif (isAke($opt_data, 'affiliation_snack', null) == 1) { $marches[413]['name'] = $marches[413]['name'] . ' ' . 'snack'; } elseif (isAke($opt_data, 'affiliation_vin', null) == 1) { $marches[413]['name'] = $marches[413]['name'] . ' ' . 'vin'; } break; default: $seg = repo('segment')->getFamilyFromItem($metier['segment']['id']); if (isset($seg[0]['id'])) { $marches[$seg[0]['id']] = $seg[0]; } } } } $out['txt'] = ''; $vir = ''; foreach ($marches as $marche) { $out['txt'] = $vir . $marche['name']; $vir = ', '; } $out['tab'] = $marches; return $array ? $out['tab'] : $out['txt']; }
function render(){ $dom = lib('htmldom')->str_get_dom($this->inner); $head = ''; $tabs = ''; $iterator = 1; foreach ( $dom->find('tab') as $tab){ $display = ($iterator==$this->selected)?'block':'none'; $class = ($iterator==$this->selected)?'selected':''; $head .= "<a class='$class' href='javascript:;' onclick=' $(this).parent().find(\"a\").removeClass(\"selected\"); $(this).addClass(\"selected\"); $(this).parent().parent().find(\".tabs_body\ .tab\").hide(); $(this).parent().parent().find(\".tabs_body\ .tab:nth-child($iterator)\").show(); '>$tab->title</a>"; $tabs .= "<div style='display:$display;' class='tab'>$tab</div>"; $iterator++; } ?> <div class="tabs"> <div class="tabs_head"><?=$head?></div> <div class="tabs_body"><?=$tabs?></div> </div> <? }
public function offreout($reseller_id) { $collection = []; $advices = Model::Advice()->where(['table', '=', 'offreout'])->where(['reseller_id', '=', (int) $reseller_id])->where(['created_at', '>', strtotime(Config::get('advice.maxperiod', '-3 month'))])->cursor(); foreach ($advices as $advice) { $account = Model::Account()->find((int) $advice['account_id']); if ($account) { $row = []; $row['id'] = $advice['id']; $row['positive'] = $advice['positive']; $row['negative'] = $advice['negative']; $row['account_id'] = $account->id; $row['firstname'] = $account->firstname; $rates = Model::Advicerate()->where(['advice_id', '=', (int) $advice['id']])->cursor(); $row['rates'] = []; foreach ($rates as $rate) { $category = Model::Adviceratecategory()->find((int) $rate['adviceratecategory_id']); if ($category) { $row['rates'][] = ['rate' => $rate['rate'], 'name' => $category['name'], 'order' => $category['order'], 'ponderation' => $category['ponderation']]; } } if (!empty($row['rates'])) { $row['rates'] = array_values(lib('collection', [$row['rates']])->sortBy('order')->toArray()); } $collection[] = $row; } } // return $collection; return empty($collection) ? [['id' => 1, 'account_id' => 28, 'firstname' => 'Pierre-Emmanuel', 'positive' => "Un accueil digne d'un 4 étoiles.", 'negative' => "Ma table était en plein courant d'air. Pas de pain en rab...", 'rates' => [['name' => 'Qualité', 'rate' => 6, 'ponderation' => 1], ['name' => 'Accueil', 'rate' => 8, 'ponderation' => 1], ['name' => 'Service', 'rate' => 8, 'ponderation' => 1]]], ['id' => 2, 'account_id' => 30, 'firstname' => 'Nicolas', 'positive' => "Très bon sommelier.", 'negative' => "Pas de parking à proximité.", 'rates' => [['name' => 'Qualité', 'rate' => 8, 'ponderation' => 1], ['name' => 'Accueil', 'rate' => 10, 'ponderation' => 1], ['name' => 'Service', 'rate' => 6, 'ponderation' => 1]]]] : $collection; }
public function boot() { spl_autoload_register(function ($class) { lib('middleware')->listen($class); }); return $this; }
function user_create($Username, $Password) { global $pdo; if (user_exists($Username)) { return false; } $stmt = $pdo->prepare(' INSERT INTO `users` ( `username` , `password` ) VALUES ( :username , :password )'); $stmt->bindValue(':username', s($Username)); $stmt->bindValue(':password', user_hash($Password, $Username)); $stmt->execute(); $uid = $pdo->lastInsertId(); $stmt->closeCursor(); // Create a group for the new user lib('Group'); $gid = group_create(s($Username), 'user'); group_add($gid, $uid); return $uid; }
public static function __callStatic($m, $a) { if (!isset(self::$i)) { self::$i = lib('redys', ['blazz.store']); } return call_user_func_array([static::$i, $m], $a); }
function start($lifespan, $name=''){ if ($this->fragment_name!=''){die('Nested fragment cache not supported.');} $x = debug_backtrace(); if($name==''){ $this->fragment_name = md5(lib('uri')->_selfURL().'||'.$x[0]['line']); }else{ $this->fragment_name = $name; } ?><!-- START Fragment <?=$this->fragment_name?>--><? // if file does not exist, make preparations to cache and return true, so segment is executed if(!file_exists($this->fragment_path . $this->fragment_name)){ $this->newly_cached = true; ob_start(); return true; }else{ // cache exists, let's see if it is still valid by checking it's age against the $lifespan variable $fModify = filemtime($this->fragment_path . $this->fragment_name); $fAge = time() - $fModify; if ($fAge > ($lifespan * 60)){ // file is old, let's re-cache $this->newly_cached = true; ob_start(); return true; } // no need to redo return false; } }
public static function getInstance($ns) { if (!isset(self::$collections[$ns])) { self::$collections[$ns] = lib('myiterator'); } return self::$collections[$ns]; }
public function background() { $file = realpath(APPLICATION_PATH . DS . '..' . DS . 'public' . DS . 'scripts' . DS . 'later.php'); if (File::exists($file)) { $cmd = 'php ' . $file; lib('utils')->backgroundTask($cmd); } }
public static function instance($ns = 'core') { $i = isAke(self::$instances, $ns, false); if (!$i) { self::$instances[$ns] = $i = lib('now', [$ns]); } return $i; }
public static function __callStatic($f, $a) { $f = strtolower($f); if (!empty($a)) { return lib($f, $a); } return lib($f); }
function session($name = 'core', $adapter = 'session', $ttl = 3600) { switch ($adapter) { case 'session': return lib('session', [$name]); case 'redis': return RedisSession::instance($name, $ttl); } }
function SignUp($data) { lib("users"); if (is_string($res = CreateUser($data['username'], $data['password'], $data['email']))) { echo "<div class='error'>{$res}</div>" . PHP_EOL; } else { echo "Done. <a href='./'>Login</a> now." . PHP_EOL; } }
private static function config() { Config::set('app.module.dir', __DIR__); Config::set('app.module.dirstorage', __DIR__ . DS . 'storage'); lib('app'); Alias::facade('Run', 'AppLib', 'Thin'); Run::makeInstance(); Config::set('directory.store', STORAGE_PATH); }
/** * 404错误页面 */ public function page_404() { lib()->load('menu')->add('menu', new \ULib\Menu()); header("HTTP/1.1 404 Not Found"); header("Content-Type:text/html; charset=utf-8"); $this->__view('comm/header.php'); $this->__view('home/404.html'); $this->__view('comm/footer.php'); }
public function reset_password($user = NULL, $code = NULL) { lib()->load('UserControl'); $uc = new UserControl(); $this->theme->setTitle("密码重置"); $this->__view("Home/header.php"); $this->__view("Home/reset_password.php", ['user' => $user, 'code' => $code, 'status' => $uc->reset_password_check($user, $code)]); $this->__view("Home/footer.php"); }
private function parseList(&$list) { if (count($list) > 0) { lib()->load('Picture', 'Gallery'); $pic = new Picture(); $g = new Gallery(); $pic->parsePic($list, false); $g->listAddTags($list); } }
public static function instance($context = null) { $context = is_null($context) ? 'core' : $context; $has = Instance::has('ioc', $context); if (true === $has) { return Instance::get('ioc', $context); } else { $instance = lib('container'); return Instance::make('ioc', $context, $instance); } }
public function get($key, $model, $default = null) { if (!is_object($model)) { throw new Exception('the second argument must be a model.'); } $cb = function ($key, $model, $default = null) { $option = Model::Opt()->where(['key', '=', (string) $key])->where(['object_id', '=', (int) $model->id])->where(['object_database', '=', (string) $model->_db->db])->where(['object_table', '=', (string) $model->_db->table])->first(true); return $option ? $option->value : $default; }; return lib('utils')->remember("get.opt.{$model->id}.{$key}." . $model->_db->db . '.' . $model->_db->table, $cb, Model::Opt()->getAge(), [$key, $model, $default]); }
function __construct($g_id, $page = false, $info = NULL) { parent::__construct("gallery_has_comments", "gallery_id", intval($g_id), "gallery"); $this->page = intval($page); $this->action_method = "post_gallery"; $this->router = lib()->using('router'); if (!is_array($info)) { $this->gallery_info = $this->db->get("gallery", ["gallery_comment_status", 'users_id' => 'user_id', 'gallery_title', 'gallery_status'], ['id' => $g_id]); } else { $this->gallery_info = $info; } }
function __construct($post_id, $page = false, $info = NULL) { parent::__construct("posts_has_comments", "posts_id", intval($post_id), "posts"); $this->page = intval($page); $this->action_method = "post_post"; $this->router = lib()->using('router'); if ($info === NULL) { $this->post_info = $this->db->get("posts", ['users_id' => 'user_id', 'post_status', 'post_allow_comment'], ['id' => $post_id]); } else { $this->post_info = $info; } }
public static function __callStatic($method, $args) { $db = Inflector::uncamelize($method); if (fnmatch('*_*', $db)) { list($database, $table) = explode('_', $db, 2); } else { $database = SITE_NAME; $table = $db; } if (empty($args)) { return lib('mysql')->table($table, $database); } }
/** * 添加钩子,并初始化部分信息 */ public function add() { if (!db()->status()) { hook()->add('UriInfo_process', array($this, 'sql_error')); } else { c_lib()->load('cookie')->add('cookie', new \CLib\Cookie(cfg()->get('cookie', 'encode'))); lib()->load('setting', 'user', 'plugin', 'version_hook')->add('setting', new Setting()); lib()->add('user', new User(true)); lib()->add("version_hook", new Version_Hook()); l_h('theme.php'); hook()->add('UriInfo_process', array($this, 'router')); lib()->add('plugin', new Plugin(_BasePath_ . "/ex/plugin")); } }
public function reset() { $this->results = null; $this->totalResults = 0; $this->transactions = 0; $this->selects = []; $this->joinTables = []; $this->wheres = []; $this->groupBys = []; $this->orders = []; $store = lib('arstore', [$this->collection]); Now::set('ardb.store.' . $this->collection, $store); return $this; }
function CreateUser($username, $password, $email, $admin = false) { if (sql("SELECT * from users WHERE username=?", $username)) { return "Username already in use."; } lib("random"); $salt = RandomString(32); $password = md5($salt . $password); $access = $admin === true; $ID = sql("INSERT INTO users (username,password,salt,email,access) VALUES (?,?,?,?,?)", $username, $password, $salt, $email, $access); if (!$ID) { return "Unable to create user."; } sql("INSERT INTO profile (ID,alias) VALUES (?,?)", $ID, $username); return GenerateUserKey($ID, $admin); }
public static function init($cli) { register_shutdown_function(['\\Thin\\Bootstrap', 'finish']); Timer::start(); lib('app'); forever(); $storage_dir = STORAGE_PATH; if (!is_writable(STORAGE_PATH)) { die('Please give 0777 right to ' . STORAGE_PATH); } if (!is_dir(CACHE_PATH)) { File::mkdir(CACHE_PATH); } $dir = APPLICATION_PATH; Config::set('app.module.dir', APPLICATION_PATH); Config::set('mvc.dir', APPLICATION_PATH); Config::set('app.module.dirstorage', $dir . DS . 'storage'); Config::set('app.module.assets', $dir . DS . 'assets'); Config::set('app.module.config', $dir . DS . 'config'); Config::set('dir.raw.store', $storage_dir . DS . 'db'); Config::set('dir.ardb.store', $storage_dir . DS . 'db'); Config::set('dir.ephemere', $storage_dir . DS . 'ephemere'); Config::set('dir.flight.store', $storage_dir . DS . 'flight'); Config::set('dir.flat.store', $storage_dir . DS . 'flat'); Config::set('dir.cache.store', $storage_dir . DS . 'cache'); Config::set('dir.nosql.store', $storage_dir . DS . 'nosql'); Config::set('dir.module.logs', $storage_dir . DS . 'logs'); path('module', $dir); path('pages', $dir . DS . 'app' . DS . 'pages'); path('layouts', $dir . DS . 'app' . DS . 'layouts'); path('store', $storage_dir); path('config', Config::get('app.module.config')); path('cache', CACHE_PATH); loaderProject('entity'); loaderProject('system'); Alias::facade('DB', 'EntityProject', 'Thin'); Alias::facade('System', 'SystemProject', 'Thin'); System::Db()->firstOrCreate(['name' => SITE_NAME]); require_once path('config') . DS . 'application.php'; if (!$cli) { if (fnmatch('*/mytests', $_SERVER['REQUEST_URI'])) { self::tests(); } else { self::router(); } } }
/** * 单独页面 * @param $page */ public function page($page) { if (\ULib\Router::$begin_status) { lib()->load('project', 'menu')->add("project", new \ULib\Project($page, 0)); lib()->add('menu', new \ULib\Menu(true)); set_title(project()->title(), site_title(false)); theme()->header_add("<script>var PM_PAGE_ID = " . project()->id() . ";</script>", 40); theme()->set_desc(project()->desc()); theme()->set_keywords(project()->keywords()); header("Content-Type:text/html; charset=utf-8"); $this->__view('comm/header.php'); $this->__view('project/page.php'); $this->__view('comm/footer.php'); } else { $this->__load_404(); } }
/** * 构造函数 * @param int $pic_id 图片ID * @param int|bool $page 当前页面数 * @param array $info 图片的相关信息 * @throws \Exception */ function __construct($pic_id, $page = false, $info = NULL) { parent::__construct("pictures_has_comments", "pictures_id", intval($pic_id), "pictures"); $this->page = intval($page); $this->action_method = "post_picture"; $this->router = lib()->using('router'); if ($info === NULL) { lib()->load('Picture'); $pic = new Picture(); $this->picture_info = $pic->get_simple_pic($pic_id); } else { $this->picture_info = $info; } if (!isset($this->picture_info['pic_id'])) { throw new \Exception("Picture comment load error."); } }
public function pushToSession($account_id, array $data = []) { $session = Model::Sessionmobile()->firstOrCreate(['account_id' => (int) $account_id]); if ($session) { $session = $session->toArray(); $regid = isAke($session, 'regid', false); $socket_id = isAke($session, 'socket_id', false); // if ($regid) { // $this->send([$regid], $data); // } if ($socket_id) { $io = lib('io'); $data['id'] = $socket_id; $message = $io->emit('bump', $data); } return Timer::get(); } }