public static function combine($type, $files, $compress = false) { $root = panel::instance()->roots()->assets() . DS . $type; $cache = new Media($root . DS . 'panel.' . $type); $media = new Collection(array_map(function ($file) use($root) { return new Media($root . DS . str_replace('/', DS, $file)); }, $files)); // get the max modification date $modified = max($media->pluck('modified')); if (is_writable($root) and (!$cache->exists() or $cache->modified() < $modified)) { $cache->remove(); $content = ''; foreach ($media as $asset) { $content .= $asset->read() . PHP_EOL; } if ($compress) { $content = static::compress($content); } f::write($root . DS . 'panel.' . $type, $content); } if ($cache->exists()) { return $type(panel()->urls()->{$type}() . '/panel.' . $type . '?v=' . panel()->version()); } return $type(array_map(function ($item) use($type) { return 'panel/assets/' . $type . '/' . $item; }, $files)); }
public function postStore($id = null) { // ---------------------------------------- HANDLE REQUEST ---------------------------------------- // handle id if (!is_null($id)) { $data = $this->model->findorfail($id); } else { $data = $this->model->newInstance(); } // ---------------------------------------- CHECK TAG ---------------------------------------- $tags_in_db = \App\Tag::whereIn('tag', Input::get('tags'))->get(); if (!$tags_in_db) { $tags_in_db = new Collection(); } foreach (Input::get('tags') as $x) { if (!$tags_in_db->where('tag', $x)->first()->id) { $new_tag = new \App\Tag(['tag' => $x]); if (!$new_tag->save()) { dd($new_tag->getErrors()); } $tags_in_db->push($new_tag); } } // ---------------------------------------- HANDLE SAVE ---------------------------------------- $input = Input::all(); if (!empty($input['published_at'])) { $input['published_at'] = \Carbon\Carbon::createFromFormat('d/m/Y H:i', $input['published_at'])->format('Y-m-d H:i:s'); } else { $input['published_at'] = null; } unset($input['longlat']); $input['tag_ids'] = $tags_in_db->pluck('id')->toArray(); $data->fill($input); if ($data->save()) { if (!$this->save_required_images($data, $input)) { return redirect()->back()->withInput()->withErrors($data->getErrors()); } return redirect()->route('admin.' . $this->view_name . '.show', ['id' => $data->id])->with('alert_success', '"' . $data->{$data->getNameField()} . '" has been saved successfully'); } else { return redirect()->back()->withInput()->withErrors($data->getErrors()); } }
/** * Removed unused items from the admin nav */ function app_clean_admin_nav() { global $menu; // Use regex to match b/c some items will have numbers suffixed (e.g. Comments 1) $remove_titles = array('/Comments/i'); $items = array_combine(array_keys($menu), Collection::pluck($menu, 0)); foreach ($items as $id => $title) { foreach ($remove_titles as $regex) { if (!preg_match($regex, $title)) { continue; } unset($menu[$id]); break; } if (!array_key_exists($id, $menu)) { continue; } } }
/** * Zippify the arrays. They must have the same number of elements. * @param array @arrays * @return array */ public static function zippy($arrays) { foreach ($arrays as $k => $array) { $arrays[$k] = array_values($array); } $out = array(); $high_keys = array_keys($arrays); $keys = array_keys(current($arrays)); foreach ($keys as $k) { $out[] = array_combine($high_keys, Collection::pluck($arrays, $k)); } return $out; }