/** * Get setting * * @param $name * @return mixed */ function setting($name) { $settings = Cache::rememberForever('settings', function () { return Setting::select('name', 'value')->get(); }); return $settings->where('name', $name)->first(); }
/** * Display a listing of the resource. * * @return Response */ public function index() { $json = \Cache::rememberForever('categories_json', function () { return ['data' => ['categories' => Category::categoryAsc()->get()]]; }); return \Response::json($json); }
protected function setupReports($view) { $reportsCount = Cache::rememberForever('reportsCount', function () { return Report::count(); }); $view->with('reportsCount', $reportsCount); }
public static function getOrderBy() { $tagsOrderBy = Cache::rememberForever('tagsOrderBy', function () { return ['id', 'asc']; }); return $tagsOrderBy; }
public function index() { $gioithieu = Cache::rememberForever('gioithieu_cache', function () { return $this->model->gioithieu(); }); return View::make('pages.gioithieu')->with(compact('gioithieu')); }
public function middleOfTheWorld() { $tour = Cache::rememberForever('middleOfTheWorld', function () { return Tour::first(); }); //$tour = Tour::first(); return View::make('tours.middle-of-the-world', compact('tour')); }
function profileImage($id, $width = 128, $height = 128) { $image = \Cache::rememberForever("userprofile-{$id}-{$width}-x-{$height}", function () use($id, $width, $height) { $img = DataSource::keystone_exec("_layouts/StPeters.Keystone/_shared/avatarhandler.ashx?id={$id}&w={$width}&h={$height}"); return $img; }); return \Response::make($image, 200, array('content-type' => 'image/jpg')); }
public function index() { $contact = Cache::rememberForever('contact_cache', function () { return $this->model->contact(); }); $map = $this->model->contact_map(); $map = json_decode($map); return View::make('pages.lienhe')->with(compact('contact', 'map')); }
public function compose(View $view) { if (!config('administr.hasLanguages')) { return; } $languages = \Cache::rememberForever('languages_list', function () { return Language::pluck('code', 'id'); }); $view->with('languages', $languages); }
/** * Cache a closure forever. * * @param string $key * @param \Closure $next * * @return \Closure */ function zedx_cache($key, Closure $next) { if (!env('APP_CACHE', true)) { return $next(); } return Cache::rememberForever("zx-{$key}", function () use($next) { \Log::info('yes'); return $next(); }); }
public function loadCategories() { $categories = null; if (\Cache::has(Category::cache_key)) { $categories = \Cache::get(Category::cache_key); } else { $categories = \Cache::rememberForever(Category::cache_key, function () { return Category::lists('title', 'slug'); }); } \View::share('app_categories', $categories); }
protected function names() { $cache_id = 'emoji-names'; $loader = function () { $dir = app('path.public') . self::PATH; foreach (glob($dir . '/*.png') as $file) { $names[] = pathinfo($file, PATHINFO_FILENAME); } return $names; }; if ('production' == App::environment()) { return Cache::rememberForever($cache_id, $loader); } else { return call_user_func($loader); } }
/** * Gets or sets the site configuration data * * @access public * @param string $group * @param array $newData * @return stdClass|bool */ public static function config($group = '', $newData = FALSE) { // Get a config value if ($newData === FALSE) { $config = Cache::rememberForever('site.config', function () { $config = Config::get('default'); if (Schema::hasTable('config')) { $siteConfig = Site::all(); if (!is_null($siteConfig)) { foreach ($siteConfig as $item) { $config[$item['group']]->{$item}['key'] = $item['value']; } } } return $config; }); return empty($group) ? (object) $config : $config[$group]; } else { $site = static::config('general'); // Get the tags that have HTML content $htmlKeys = preg_split('/\\||,/', $site->htmlKeys); // Update the new config values in the DB foreach ($newData as $key => $value) { // Check for and strip HTML content if (in_array($key, $htmlKeys)) { $value = strip_tags($value, $site->allowedTags); } // Save config data if (!empty($key) and !starts_with($key, '_')) { $key = camel_case($key); // Get the existing value of the config $config = static::query(); $config->where('group', $group); $config->where('key', $key); // Do an UPSERT, i.e. if the value exists, update it. // If it doesn't, insert it. if ($config->count() > 0) { $config->update(array('value' => $value)); } else { $config->insert(array('group' => $group, 'key' => $key, 'value' => $value)); } } } Cache::flush(); return TRUE; } }
function globalParams($key = null, $default = false) { $params = []; try { $params = Cache::rememberForever('global_params', function () { if (!Schema::hasTable('settings')) { return collect(); } return Setting::get(); }); $params = $params->groupBy('site_id')->toArray(); } catch (\Exception $e) { } $siteId = site()->id; $params = isset($params[$siteId]) ? collect($params[$siteId])->pluck('value', 'key') : []; if ($key == null) { return $params; } return isset($params[$key]) ? $params[$key] : $default; }
protected static function createInstance() { if (config('app.debug') && !config('trans.cache_on_debug')) { \Cache::forget('po_cache'); } return \Cache::rememberForever('po_cache', function () { $basePath = config('trans.translations_path'); $locales = config('trans.supported_locales'); $translator = new SymfonyTranslator(config('app.locale')); $translator->addLoader('po', new PoFileLoader()); $translator->setFallbackLocales([config('app.locale')]); foreach ($locales as $locale) { $path = base_path($basePath . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . 'LC_MESSAGES'); $file = $path . DIRECTORY_SEPARATOR . 'messages.po'; if (file_exists($file)) { $translator->addResource('po', $file, $locale); $translator->getCatalogue($locale); } } return $translator; }); }
public function load($namespace, $group, $locale) { if ($this->isLoaded($namespace, $group, $locale)) { return; } // If a Namespace is give the Filesystem will be used // otherwise we'll use our database. // This will allow legacy support. if (!self::isNamespaced($namespace)) { // If debug is off then cache the result forever to ensure high performance. if (!\Config::get('app.debug') || \Config::get('translation-db.minimal')) { $that = $this; $lines = \Cache::rememberForever('__translations.' . $locale . '.' . $group, function () use($that, $locale, $group, $namespace) { return $this->database->load($locale, $group, $namespace); }); } else { $lines = $this->database->load($locale, $group, $namespace); } } else { $lines = $this->loader->load($locale, $group, $namespace); } $this->loaded[$namespace][$group][$locale] = $lines; }
<?php if (Schema::hasTable('options')) { return Cache::rememberForever('options', function () { $get_options = Option::all(); $options = array(); foreach ($get_options as $option) { $options[$option->key] = $option->value; } return $options; }); } // If the table doesnt exist we return a empty array return array();
public function cacheRememberForever(Closure $callback, $key = null) { return \Cache::rememberForever($this->getCacheKey($key), $callback); }
/** * Accept 2 digit alpha-code. Pass in the country to be extra sure you get the right name returned. * TODO: caching to make this fetch speedy speedy * * @param string $stateA2 * @param string $countryA2 defaults to 'US' * @return $string full state/province name */ public static function stateName($stateA2, $countryA2 = 'CA') { if (strlen($stateA2) != 2 || strlen($countryA2) != 2) { throw new InvalidValueException(); } if (empty($countryA2)) { return State::byCode($code)->firstOrFail()->name; } return Cache::rememberForever('addresses.' . $countryA2 . '.' . $stateA2 . '.state_name', function () use($stateA2, $countryA2) { return State::byCountry($countryA2)->byCode($stateA2)->firstOrFail()->name; }); }
/** * feed * * @return Response */ public function feed() { if ('production' == App::environment()) { $atom = Cache::rememberForever('atom', function () { return Feed::generate(); }); } else { $atom = Feed::generate(); } return Response::make($atom, 200, ['content-type' => 'application/xml', 'charset' => 'utf-8']); }
/** * @return boolean */ public static function adminExists() { return \Cache::rememberForever('admin_exists', function () { return static::whereIsActive(1)->whereIsSysAdmin(1)->exists(); }); }
public function initCache() { // !!! DATABASE CACHE !!! //Cache Model::Menu //Cache::forget('DB_Menu'); /*Cache::rememberForever('DB_Menu', function() { return Menu::where('parent_id','=',0)->orderBy('order','ASC')->get(); });*/ //Cache Model::Locale Cache::rememberForever('DB_LocaleFrontEnable', function () { //Get all data in database $locales = Locale::where('enable', '=', 1)->where('is_publish', '=', 1)->get(); //Preapre data to extract by id $data = array(); foreach ($locales as $l) { $data[] = $l->id; } return $data; }); //Cache Model::Nav Cache::rememberForever('DB_Nav', function () { return Nav::where('parent_id', '=', 0)->orderBy('order', 'ASC')->get(); }); //Cache Model::Resource('name') Cache::rememberForever('DB_AdminResourceName', function () { //Get all data in database $resources = Resource::where('in_admin_ui', '=', 1)->get(); //Preapre data to extract by id $data = array(); foreach ($resources as $r) { $data[$r->id] = $r->name; } return $data; }); Cache::rememberForever('DB_AdminResource', function () { //Get all data in database return Resource::where('in_admin_ui', '=', 1)->get(); }); Cache::rememberForever('DB_AdminResourceNavigable', function () { //Get all data in database return Resource::where('navigable', '=', 1)->where('in_admin_ui', '=', 1)->get(); }); // Get all Locales enableds in the table Cache::rememberForever('DB_LocalesEnabled', function () { return Locale::where('enable', 1)->where('is_publish', 1)->get(); }); Cache::rememberForever('DB_AdminBlockTypes', function () { //Get all data in database return BlockType::all(); }); //Cache Model::Mosaique('name') //Cache::forget('DB_Mosaique'); /*Cache::rememberForever('DB_Mosaique', function() { //Get all data in database return Mosaique::all(); });*/ //Cache Model::Option Cache::rememberForever('DB_Option', function () { return Option::all(); }); //Cache Model::Urls Cache::rememberForever('DB_Urls', function () { $data = DB::select(' SELECT translations.i18n_id , translations.text , translations.locale_id FROM translations INNER JOIN i18n_types ON i18n_types.name = ? INNER JOIN i18n ON i18n.i18n_type_id = i18n_types.id AND translations.i18n_id = i18n.id ', array('url')); //$data = Translation::i18n()->where('i18n_type_id','=',I18nType::where('name','=','url')->first()->id)->get $datas = array(); foreach ($data as $d) { $datas[] = array('i18n_id' => $d->i18n_id, 'url' => $d->text, 'locale_id' => $d->locale_id); } return $datas; }); }
Route::post('activate/FirstLink', ['as' => '1stlinkactivation', 'uses' => 'CodeController@activateFirstLink']); // after first link is activated dont show anymore this url to them Route::post('signup', ['as' => 'signup', 'uses' => 'Auth\\AuthController@create']); // Route::get('{link?}', ['as' => 'links', 'uses' => 'LinkController@getRefLink']); Route::get('activeSponsor/{id}', function ($id) { $id = App\Link::where('id', $id)->firstOrFail()->activeSponsor($id); return $id; }); // Route::get('code/all', ['as' => 'codeall', 'uses' => 'CodeController@index']); Route::get('code/{linkID}/{PINCODE}', ['as' => 'code', 'uses' => 'CodeController@attachLink']); // Update user account data // Route::put('profile', ['as' => 'profile/update', 'uses' => 'UserController@update']); // Not working yet Route::get('/vue', function () { return view('vue'); }); Route::get('api/users', function () { $value = Cache::rememberForever('users', function () { return \App\Profile::latest()->take(50)->select('display_name', 'created_at')->get(); // Should Only Fetch the Users Display Name! }); return $value = Cache::pull('users'); }); //Route::post('api/users', function(){ // App\User::create(Request::all()); //}); // Route::get('getCookie', function () { return view('welcome'); }); //Route::get('/activate/{code}', 'Auth\AuthController@activateAccount Route::get('{link?}', ['as' => 'reflink', 'uses' => 'LinkController@showRefLink']);
/** * Fetches available expiration times for a paste * * @static * @param string $category * @param bool $csv * @return array */ public static function getExpiration($category = 'create', $csv = FALSE) { // Current user ID for role based expiration options $user = Auth::check() ? Auth::user()->id : 0; // Fetch/update expiration times in cache return Cache::rememberForever("expire.{$category}.{$user}.{$csv}", function () use($category, $csv) { $times = array(); // Populate the expiration times foreach (Config::get('expire') as $time => $properties) { // First property represents the label $label = $properties[0]; // Second property represents whether the expire time // is enabled or not $condition = $properties[1]; // Add the expire time if condition evaluates to true if ($condition) { $times[$time] = Lang::get("{$category}.{$label}"); } } // Do we just want CSV? if ($csv) { $times = implode(',', array_keys($times)); } return $times; }); }
public function nationalDays($cache_flag = true) { if (func_num_args() == 3) { $cache_flag = func_get_arg(2); } $cache_key = 'japanese_national_days_' . date('Y'); if (!$cache_flag && \Cache::has($cache_key)) { \Cache::forget($cache_key); } return \Cache::rememberForever($cache_key, function () { $html = file_get_contents('https://calendar.google.com/calendar/ical/' . urlencode('*****@*****.**') . '/public/full.ics'); $lines = explode("\n", $html); $national_days = []; $date = $day_name = ''; foreach ($lines as $index => $line) { if (preg_match('#^([\\w-]+);?(.*?):(.*)$#i', $line, $matches)) { $key = trim($matches[1]); $value = trim($matches[3]); if ($key == 'DTSTART') { $date = $value; } else { if ($key == 'SUMMARY') { $day_name = $value; } else { if ($key == 'END' && $value == 'VEVENT') { if (!empty($date) && !empty($day_name)) { $dt = Carbon::parse($date); $national_days[$dt->format('Y-m-d')] = $day_name; } $date = $day_name = ''; } } } } } ksort($national_days); return $national_days; }); }
Route::get('sanpham/edit/{danhmuc_id}/{sp_id}', array('as' => 'admin.sanpham.edit', 'uses' => 'SanphamController@edit'))->where(['danhmuc_id' => '[0-9]+', 'sp_id' => '[0-9]+']); Route::post('sanpham/edit/{sp_id}', array('as' => 'admin.sanpham.update', 'uses' => 'SanphamController@updatesanpham'))->where(['sp_id' => '[0-9]+']); Route::post('sanpham/status', array('as' => 'admin.sanpham.status', 'uses' => 'SanphamController@status')); Route::get('sanpham/delete/{id}', array('as' => 'admin.sanpham.delete', 'uses' => 'SanphamController@delete'))->where('id', '[0-9]+'); Route::post('sanpham/deleteAll', array('as' => 'admin.sanpham.deleteAll', 'uses' => 'SanphamController@deleteAll')); Route::post('sanpham/khuyenmai', array('as' => 'admin.sanpham.khuyenmai', 'uses' => 'SanphamController@khuyenmai')); Route::post('sanpham/order', array('as' => 'admin.sanpham.order', 'uses' => 'SanphamController@order')); // CUSTOMER Route::get('customer/delete/{id}', array('as' => 'admin.customer.delete', 'uses' => 'CustomerController@delete'))->where('id', '[0-9]+'); Route::post('customer/deleteAll', array('as' => 'admin.customer.deleteAll', 'uses' => 'CustomerController@deleteAll')); Route::resource('customer', 'CustomerController'); // SUPPORT Route::get('support/delete/{id}', array('as' => 'admin.support.delete', 'uses' => 'SupporterController@delete'))->where('id', '[0-9]+'); Route::post('support/deleteAll', array('as' => 'admin.support.deleteAll', 'uses' => 'SupporterController@deleteAll')); Route::post('support/order', array('as' => 'admin.support.order', 'uses' => 'SupporterController@order')); Route::post('support/status', array('as' => 'admin.support.status', 'uses' => 'SupporterController@status')); Route::resource('support', 'SupporterController'); }); View::composer('admin::layouts.sidebar', function ($view) { $danhmuc = \Cache::rememberForever('danhmuc-cache', function () { return lienhoa\models\Danhmuc::where('status', 1)->orderBy('order', 'ASC')->get(); }); $view->with(compact('danhmuc')); }); View::composer('admin::layouts.header', function ($view) { // $customer = lienhoa\models\Customer::where('xem',0)->orderBy('id','DESC')->take(5)->get(); $customer = \Cache::rememberForever('customer', function () { return lienhoa\models\Customer::where('xem', 0)->orderBy('id', 'DESC')->take(5)->get(); }); $view->with(compact('customer')); });
<?php /* |-------------------------------------------------------------------------- | View Composers |-------------------------------------------------------------------------- */ View::composer('layouts.default.nav', function ($view) { // Info (cached until a page is edited) $pageMenu = Cache::rememberForever('pageMenu', function () { $pages = Zeropingheroes\Lanager\Domain\Pages\Page::whereNull('parent_id')->where('published', true)->orderBy(DB::raw('ISNULL(position)'))->get(); if ($pages->count()) { foreach ($pages as $page) { $menuItems[] = ['title' => $page['title'], 'link' => URL::route('pages.show', $page->id)]; } $menuItems[] = ['title' => 'All Pages', 'link' => URL::route('pages.index')]; } else { $menuItems = []; // TODO: deal with no pages better } return $menuItems; }); $view->with('info', $pageMenu); // Links $view->with('links', Config::get('lanager/links')); });
public static function getReplyToEmail($user) { return Cache::rememberForever('replyToEmail_' . $user->id, function () use($user) { return $user->email; }); }
public function getAllResources() { $model = $this->getModel(); if (!\Cache::has('site.resources')) { $resources = \Cache::rememberForever('site.resources', function () use($model) { return $model->where('key', 'like', 'resource%')->get(); }); return $resources; } $value = \Cache::get('site.resources', function () use($model) { return $model->where('key', 'like', 'resource%')->get(); }); return $value; }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit() { $user = User::find(Sentry::getuser()->id); $timezones = Cache::rememberForever('timezones', function () { static $regions = array(DateTimeZone::AFRICA, DateTimeZone::AMERICA, DateTimeZone::ANTARCTICA, DateTimeZone::ASIA, DateTimeZone::ATLANTIC, DateTimeZone::AUSTRALIA, DateTimeZone::EUROPE, DateTimeZone::INDIAN, DateTimeZone::PACIFIC); $timezones = array(); foreach ($regions as $region) { $timezones = array_merge($timezones, DateTimeZone::listIdentifiers($region)); } $timezone_offsets = array(); foreach ($timezones as $timezone) { $tz = new DateTimeZone($timezone); $timezone_offsets[$timezone] = $tz->getOffset(new DateTime()); } // sort timezone by offset asort($timezone_offsets); $timezone_list = array(); foreach ($timezone_offsets as $timezone => $offset) { $offset_prefix = $offset < 0 ? '-' : '+'; $offset_formatted = gmdate('H:i', abs($offset)); $pretty_offset = "UTC{$offset_prefix}{$offset_formatted}"; $timezone_list[$timezone] = "{$timezone} ({$pretty_offset}) "; } return $timezone_list; }); Cache::forget('timezones'); $user_games = $user->userGame()->lists('game_id'); $key = 'events' . Sentry::getUser()->id; Cache::forget($key); return View::make('user.edit_user', array('user' => $user, 'timezones' => $timezones, 'user_games' => $user_games)); }