/** * generate archive links by month and year * * @return array */ public function archive() { $posts = Page::published()->where('type', 1)->where('published_at', '<', Carbon::now()->startOfMonth())->get()->groupBy(function ($item) { return $item->published_at->formatLocalized('%B %Y'); }); $retVal = []; $key = 0; foreach ($posts as $archmonth => $item) { $retVal[$key]['link'] = url(\Config::get('tok3-publisher.default_route', 'publisher') . '/archive/' . $item[0]->published_at->formatLocalized('%Y-%m')); $retVal[$key]['txt'] = $archmonth . ' (' . count($item) . ')'; ++$key; } return $retVal; }
public function boot() { require __DIR__ . '/Http/routes.php'; $this->loadViewsFrom(__DIR__ . '/views', 'tok3-publisher'); $this->publishes([__DIR__ . '/config/publisher.php' => config_path('tok3-publisher.php')], 'package.php'); $this->publishes([__DIR__ . '/views' => base_path('resources/views/vendor/tok3-publisher')], 'views'); $this->publishes([__DIR__ . '/migrations' => $this->app->databasePath() . '/migrations'], 'migrations'); $this->publishes([__DIR__ . '/seeds' => base_path('database/seeds')], 'views'); // Model event when deleting page delete all images associated with Page::deleting(function ($page) { if (count($page->images) > 0) { foreach ($page->images as $image) { unlink(\Config::get('tok3-publisher.images_dir', 'images/tok3-publisher/') . $image->name); } } }); }
/** * sitemap mh :-) */ public function sitemap() { $pages = Page::published()->get(); echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; return view('tok3-publisher::sitemap', compact('pages')); }
/** * /* * Syncronize tags * * @param Page $page * @param array $tags */ private function syncTags(Page $page, array $tags) { foreach ($tags as $tag_id) { if (!is_numeric($tag_id)) { //$newTag = $tag_id; $newTag = substr($tag_id, 3); if (strlen($newTag) >= 3) { $new_tag = Tag::create(['slug' => str_slug(str_replace('_', ' ', $newTag)), 'name' => str_replace('_', ' ', $newTag), 3]); $tag_id = $new_tag->id; $allTagIds[] = $tag_id; } } else { $allTagIds[] = $tag_id; } } $page->tags()->sync($allTagIds); }