public function showIndex() { $page = $this->node; $tree = Collector::get('root'); $subTree = Tree::getSubTree($tree, $page); $blocks = null; if ($subTree) { $blocks = $subTree->children; } foreach ($blocks as $index => $block) { $blocks[$block->slug] = $block; unset($blocks[$index]); } if (isset($blocks['reporting'])) { $blocks['reporting']->children = $blocks['reporting']->children->reverse(); $reporting = $blocks['reporting']; } $flatArticles = Cache::tags('j_tree')->rememberForever('about_flat_articles_' . App::getLocale(), function () use($page) { return $page->immediateDescendants()->active()->get(); }); $articles = array(); foreach ($flatArticles as $article) { $articles[$article->slug] = $article; } $pressSections = null; if (isset($articles['press']) && $articles['press']->count()) { $pressSubTree = Tree::getSubTree($tree, $articles['press']); if ($pressSubTree) { $pressSections = $pressSubTree->children; } } return View::make('about.index', compact('page', 'reporting', 'articles', 'pressSections')); }
public static function render($page, $position = '') { $page = !$page ? 'null' : $page; if (Cache::tags('widgets')->has($page . '-' . $position)) { $merged = Cache::tags('widgets')->get($page . '-' . $position); } else { if ($page == 'null') { $merged = Widget::select('id', 'title', 'content', 'path')->active()->global()->wherePosition($position)->orderBy('ordr', 'ASC')->get(); } else { $global = Widget::select('id', 'title', 'content', 'path')->active()->global()->wherePosition($position)->orderBy('ordr', 'ASC')->get(); $specific = $page->widgets()->select('id', 'title', 'content', 'path')->local()->wherePosition($position)->orderBy('ordr', 'ASC')->get(); $merged = $global->merge($specific); } $merged->sortBy('ordr'); Cache::tags('widgets')->forever($page . '-' . $position, $merged); } foreach ($merged as $widget) { if ($widget->path) { if (\View::exists($widget->path)) { echo view($widget->path); } } else { echo str_replace('{{url}}', Request::url(), $widget->content); } } }
public function UserPermissions() { if (Auth::check()) { $user_id = Auth::id(); $cache_key = "user-" . $user_id . "-permissions"; if (Cache::tags('user-permissions')->has($cache_key)) { $permission_array = Cache::tags('user-permissions')->get($cache_key); } else { if (Auth::user()->is_admin) { $raw_permission_array = []; $permission_array = []; $permission_objects = Permission::all(); $user_permissions = DB::table('permission_user')->where('user_id', '=', $user_id)->get(); foreach ($user_permissions as $user_permission) { $permission_id = $user_permission->permission_id; $raw_permission_array[$permission_id] = 1; } foreach ($permission_objects as $permission) { $route_name = $permission->route; $permission_id = $permission->id; if (isset($raw_permission_array[$permission_id])) { $permission_array[$route_name] = $raw_permission_array[$permission_id]; } else { $permission_array[$route_name] = 0; } } } else { $permission_array = false; } Cache::tags('user-permissions')->put($cache_key, $permission_array, 60); } } return $permission_array; }
private function makeSlugUnique($slug) { // if using the cache, check if we have an entry already instead // of querying the database if ($this->use_cache) { $increment = Cache::tags('sluggable')->get($slug); if ($increment === null) { Cache::tags('sluggable')->put($slug, 0, $use_cache); } else { Cache::tags('sluggable')->put($slug, ++$increment, $use_cache); $slug .= $this->separator . $increment; } return $slug; } // no cache, so we need to check directly // find all models where the slug is like the current one $list = $this->getExistingSlugs($slug); // if ... // a) the list is empty // b) our slug isn't in the list // c) our slug is in the list and it's for our model // ... we are okay if (count($list) === 0 || !in_array($slug, $list) || $this->id && array_key_exists($this->id, $list) && $list[$this->id] === $slug) { return $slug; } // map our list to keep only the increments $len = strlen($slug . $this->separator); array_walk($list, function (&$value, $key) use($len) { $value = intval(substr($value, $len)); }); // find the highest increment rsort($list); $increment = reset($list) + 1; return $slug . $this->separator . $increment; }
public function postEdit($id) { if (!$this->checkRoute()) { return Redirect::route('index'); } $title = 'Edit A Modpack Code - ' . $this->site_name; $input = Input::only('code', 'launcher', 'modpack'); $modpackcode = ModpackCode::find($id); $messages = ['unique' => 'A code for this launcher/modpack combination already exists in the database!']; $validator = Validator::make($input, ['code' => 'required|unique:modpack_codes,code,' . $modpackcode->id, 'launcher' => 'required', 'modpack' => 'required'], $messages); if ($validator->fails()) { // TODO this line originally redirects to modpack-code/edit, there's no route for this, is this an error? return Redirect::action('ModpackCodeController@getEdit', [$id])->withErrors($validator)->withInput(); } $modpackcode->code = $input['code']; $modpackcode->modpack_id = $input['modpack']; $modpackcode->launcher_id = $input['launcher']; $modpackcode->last_ip = Request::getClientIp(); $success = $modpackcode->save(); if ($success) { Cache::tags('modpacks')->flush(); Queue::push('BuildCache'); return View::make('modpackcodes.edit', ['title' => $title, 'success' => true, 'modpackcode' => $modpackcode]); } return Redirect::action('ModpackCodeController@getEdit', [$id])->withErrors(['message' => 'Unable to add modpack code.'])->withInput(); }
/** * Update the specified resource in storage. * * @param int $id * * @return Response */ public function update(CategoryRequest $request, $id) { $category = Category::findOrFail($id); $category->update($request->all()); \Cache::tags('categories')->flush(); return redirect('admin/categories/index'); }
public function showMain() { $page = $this->node; $tree = Collector::get('root'); $subTree = Tree::getSubTree($tree, $page); $blocks = null; if ($subTree) { $blocks = $subTree->children; } foreach ($blocks as $index => $block) { $blocks[$block->slug] = $block; unset($blocks[$index]); } $allRates = Cache::tags('rates')->rememberForever('rates_' . App::getLocale(), function () { return Rates::orderPriority()->get(); }); $rates = array(); foreach ($allRates as $i => $rate) { if ($rate['type'] == 1) { $rates['departments'][] = $rate; } else { $rates['cards'][$rate['name_card']][] = $rate; } } $calculatorCredit = new CashCalculator(); // fixme: //$calculatorCredit->setMonthlyIncome(Settings::get('monthly_income_default', 0)); $calculatorCredit->setCreditAmount(Settings::get('credit_amount_default', 100000)); $calculatorCredit->setTerm(Settings::get('term_default', 3)); $calculationsCredit = $calculatorCredit->calculate(); return View::make('index', compact('page', 'blocks', 'rates', 'calculationsCredit')); }
public static function boot() { parent::boot(); Widget::saved(function ($widget) { \Cache::tags('widgets')->flush(); }); }
public function postEdit($id) { if (!$this->checkRoute()) { return Redirect::route('index'); } $title = 'Edit A Modpack Code - ' . $this->site_name; $input = Input::only('name', 'deck', 'description', 'slug'); $modpacktag = ModpackTag::find($id); $messages = ['unique' => 'This modpack tag already exists in the database!']; $validator = Validator::make($input, ['name' => 'required|unique:modpack_tags,name,' . $modpacktag->id, 'deck' => 'required'], $messages); if ($validator->fails()) { return Redirect::action('ModpackTagController@getEdit', [$id])->withErrors($validator)->withInput(); } $modpacktag->name = $input['name']; $modpacktag->deck = $input['deck']; $modpacktag->description = $input['description']; $modpacktag->last_ip = Request::getClientIp(); if ($input['slug'] == '' || $input['slug'] == $modpacktag->slug) { $slug = Str::slug($input['name']); } else { $slug = $input['slug']; } $modpacktag->slug = $slug; $success = $modpacktag->save(); if ($success) { Cache::tags('modpacks')->flush(); Queue::push('BuildCache'); return View::make('tags.modpacks.edit', ['title' => $title, 'success' => true, 'modpacktag' => $modpacktag]); } return Redirect::action('ModpackTagController@getEdit', [$id])->withErrors(['message' => 'Unable to edit modpack code.'])->withInput(); }
public function flush(BasicAPIController $api) { $config = $this->config($api); if ($config['flush']) { \Cache::tags($config['flush_tags'])->flush(); } }
public function showCatalogSecond() { $page = $this->node; $products = Cache::tags('j_tree')->rememberForever('small_business_products_catalog_' . $page->id . '_' . App::getLocale(), function () use($page) { return $page->immediateDescendants()->where('is_active', 'like', '%' . App::getLocale() . '%')->get(); }); return View::make('small-business.catalog_second', compact('page', 'products')); }
public function showCatalogFirst() { $page = $this->node; $products = Cache::tags('j_tree')->rememberForever('financial_products_' . App::getLocale(), function () use($page) { return $page->immediateDescendants()->active()->catalogItems()->get(); }); return View::make('financial.catalog_first', compact('page', 'products')); }
public function getCitiesByRegion() { $idRegion = trim(Input::get('id_region')) ?: 0; $cities = Cache::tags('cities')->rememberForever('cities_region_' . $idRegion . '_' . App::getLocale(), function () use($idRegion) { return City::active()->byRegion($idRegion)->get(); }); $html = View::make('partials.popups.partials.select_city', compact('cities'))->render(); return Response::json(array('status' => true, 'html' => $html)); }
function last_modified($path) { $mtime = Cache::tags('mtime')->get($path, false); if (!$mtime || Config::get('app.debug')) { $mtime = filemtime(public_path() . $path); Cache::tags('mtime')->put($path, $mtime, 5); } return $path . '?' . $mtime; }
/** * @param integer $pageId * @return array|null */ private static final function loadPartsbyPageId($pageId) { if (!array_key_exists($pageId, static::$cached)) { self::$cached[$pageId] = Cache::tags(PagePartModel::table())->remember("pageParts::{$pageId}", Carbon::now()->addHour(1), function () use($pageId) { return PagePartModel::select('name', 'content', 'content_html')->where('page_id', $pageId)->get(); }); } return self::$cached[$pageId]; }
/** * Handle the event. * * @param \App\Events\ModelChanged $event */ public function handle(ModelChanged $event) { if (!taggable()) { // Remove all cache store return \Cache::flush(); } // Remove only cache that has the given tag(s) return \Cache::tags($event->cacheTags)->flush(); }
public function testRelationCache() { $this->model->id = 2; $this->model->setRelation('foo', new EloquentModelStub(['foo' => 2])); $this->model->cacheIdentifierRelation = 'foo'; \Cache::tags('test.1')->forever('testing', 'good'); $this->assertEquals('good', \Cache::tags('test.1')->get('testing')); $this->larabuster->handle($this->model); $this->assertNull(\Cache::tags('test.1')->get('testing')); }
public function clearTaggedCaches() { if (\Config::get('cache.driver') == 'memcached') { $aTags = array(get_called_class()); if ($mxId = $this->getAttribute($this->primaryKey)) { $aTags[] = $mxId; } \Cache::tags($aTags)->flush(); } }
public function getClear() { Cache::tags('launchers')->flush(); Cache::tags('modpacks')->flush(); Cache::tags('modpackmods')->flush(); Cache::tags('modmodpacks')->flush(); Cache::tags('mods')->flush(); Cache::tags('user-permissions')->flush(); echo 'Cache cleared.'; }
public function MessageCheck() { $mobileKey = Input::get('key'); $mobile = '13399857034'; $codeKey = md5($this->getIP() . $mobile); $key = Cache::tags('register', 'code')->get($codeKey); if ($key == $mobileKey) { echo "ok"; } else { echo "false"; } }
protected function clearCache($model) { $model_name = $model->table; Cache::tags($model_name)->flush(); // $ql = DB::getQueryLog(); // $ql = end($ql); // $key = crc32('cache' . $ql['query'] . implode($ql['bindings'])); // Cache::forget($key); // // var_dump('cache cleared', $key, $ql['query']); // var_dump(__FILE__ . __LINE__); }
protected function exportChildren(Path $path) { $children = array(); $pathChildren = $path->getChildren(); foreach ($pathChildren as $child) { $hash = $child->getHash(); $children[] = Cache::tags('paths')->rememberForever($hash, function () use($child) { return $child->export(); }); } return $children; }
public function getClearCache($tag = 'all') { if (!$this->checkRoute()) { return Redirect::route('index'); } if ($tag == 'all') { Cache::flush(); echo "<p>Cleared all cache.</p>"; echo "<p><a href=\"/\">Go Home</a></p>"; } else { Cache::tags($tag)->flush(); echo "<p>Cleared cache with tag: {$tag}.</p>"; echo "<p><a href=\"/\">Go Home</a></p>"; } }
public function handle(BaseCommand $command, $next) { if (!$command->shouldCache()) { return $next($command); } $parameters = serialize(get_object_vars($command)); $parametersHash = md5($parameters); $cacheName = get_class($command) . '|' . $parametersHash; $cacheHash = md5($cacheName); //Return existing cache or create a new one return \Cache::tags($command->getCacheTags())->remember($cacheHash, $command->getCacheTime(), function () use($next, $command) { \Log::info('Caching result for query ' . get_class($command)); return $next($command); }); }
public function testRecountDomainCountsRecache() { \Cache::tags('domains')->flush(); // Recount items in domain $domain = Domain::cache('en'); $domain->recount('comments_total', 'recountComments'); $this->assertTrue($domain->comments_total === '3'); // But in cache have old value. $domain_in_cache = Domain::cache('en'); $this->assertTrue($domain_in_cache->comments_total === '0'); $domain->recache(); // No select query here. $domain = Domain::cache('en'); $this->assertTrue($domain->comments_total === '3'); }
/** * @return \Cache */ protected function _getCache() { if ($this->_oCache == null) { $sClassName = get_class($this->getModel()); $sQuery = $this->getQuery()->toSql(); $sAttributes = serialize($this->getQuery()->getBindings()); $sExtend = ''; if (count(func_get_args()) > 0) { $sExtend = serialize(func_get_args()); } $sCacheKey = $this->_sCacheKey = md5($sQuery . $sAttributes . $sExtend); $aTags = $this->_aCacheTags = array($sClassName, $sCacheKey); $this->_oCache = \Cache::tags($aTags); } return $this->_oCache; }
public function doFilter() { if (!Request::ajax()) { App::abort(404); } $offices = Cache::tags('offices')->rememberForever('map_offices_filter_' . md5(json_encode(Input::all())) . '_' . App::getLocale(), function () { return Office::with('city')->active()->filter(Input::all())->orderBy('id_city', 'asc')->get(); }); $officesMap = Office::getMap($offices); $officesPopupsHtml = ''; $officesListHtml = ''; foreach ($officesMap as $officeMap) { $officesPopupsHtml .= View::make('partials.popups.office_info', compact('officeMap'))->render(); $officesListHtml .= View::make('map.partials.list_item', compact('officeMap'))->render(); } return Response::json(array('status' => true, 'offices' => json_encode($officesMap), 'html' => $officesPopupsHtml, 'html_list' => $officesListHtml)); }
public function saveSettings(Request $request) { $this->validate($request, ['css_style' => 'url|safe_url|max:250', 'contents_per_page' => 'integer|min:1|max:100', 'entries_per_page' => 'integer|min:1|max:100', 'timezone' => 'timezone']); $settings['enter_send'] = Input::get('enter_send') == 'on' ? true : false; $settings['pin_navbar'] = Input::get('pin_navbar') == 'on' ? true : false; $settings['notifications_sound'] = Input::get('notifications_sound') == 'on' ? true : false; $settings['homepage_subscribed'] = Input::get('homepage_subscribed') == 'on' ? true : false; $settings['disable_groupstyles'] = Input::get('disable_groupstyles') == 'on' ? true : false; $settings['css_style'] = Input::get('css_style'); $settings['contents_per_page'] = (int) Input::get('contents_per_page'); $settings['entries_per_page'] = (int) Input::get('entries_per_page'); $settings['timezone'] = Input::get('timezone'); $settings['notifications.auto_read'] = Input::get('notifications.auto_read') == 'on' ? true : false; foreach ($settings as $key => $value) { setting()->set($key, $value); } \Cache::tags(['user.settings', 'u.' . auth()->id()])->flush(); return redirect()->route('user_settings')->with('success_msg', 'Ustawienia zostały zapisane.'); }
public function postAdd() { if (!$this->checkRoute()) { return Redirect::route('index'); } $title = 'Add A Youtube Video / Playlist - ' . $this->site_name; $input = Input::only('url', 'category', 'modpack', 'mod'); $validator = Validator::make($input, ['url' => 'required']); if ($validator->fails()) { return Redirect::action('YoutubeController@getadd')->withErrors($validator)->withInput(); } $youtube = new Youtube(); $processed_url = $this->processURL($input['url']); if (!$processed_url['type']) { return Redirect::action('YoutubeController@getadd')->withErrors(['message' => 'Unable to process URL.'])->withInput(); } $youtube_information = $youtube->getVideoInfo($processed_url['id'], $processed_url['type']); if (!$youtube_information) { return Redirect::action('YoutubeController@getadd')->withErrors(['message' => 'Unable to process Youtube API.'])->withInput(); } $youtube_information = $youtube_information->items[0]; $youtube->type = $processed_url['type']; $youtube->title = $youtube_information->snippet->title; $youtube->youtube_id = $youtube_information->id; $youtube->channel_title = $youtube_information->snippet->channelTitle; $youtube->channel_id = $youtube_information->snippet->channelId; $youtube->thumbnail = $youtube_information->snippet->thumbnails->medium->url; $youtube->category_id = $input['category']; if ($input['modpack']) { $youtube->modpack_id = $input['modpack']; } elseif ($input['mod']) { $youtube->mod_id = $input['mod']; } $youtube->last_ip = Request::getClientIp(); $success = $youtube->save(); if ($success) { Cache::tags('modpacks')->flush(); Cache::tags('mods')->flush(); Queue::push('BuildCache'); return View::make('youtube.add', ['title' => $title, 'success' => true, 'categories' => $this->categories]); } return Redirect::action('YoutubeController@getadd')->withErrors(['message' => 'Unable to add modpack code.'])->withInput(); }
public function doImagesParse($value) { $model = \Config::get('jarboe::images.models.image'); $images = \Cache::tags('j_images', 'jarboe')->rememberForever('j_images', function () use($model) { return $model::all(); }); preg_match_all('~<img[^>]+data-j_images_id="(\\d+)"[^>]*>~', $value, $matches); list($html, $ids) = $matches; $patterns = array(); $replacements = array(); foreach ($ids as $index => $id) { $image = $images->filter(function ($item) use($id) { return $item->id == $id; })->first(); $patterns[] = '~' . preg_quote($html[$index]) . '~'; $replacements[] = $image ? $this->fetchImage($image, $html[$index]) : ''; } return preg_replace($patterns, $replacements, $value); }