示例#1
0
 public function testHasPublished()
 {
     $post = Post::first();
     $post->is_published = true;
     $post->published_at = date('Y-m-d');
     $post->save();
     dd(Post::first()->published_at);
     $this->assertEquals(1, Post::published()->get()->count());
 }
示例#2
0
 public function afterFetch()
 {
     // dodanie walidacji do pól
     foreach ($this->field as $key => $value) {
         $field_config = Yaml::parse($value->code);
         if (empty($field_config['validator']) === false) {
             \Bm\Field\Models\Post::extend(function ($model) use($value, $field_config) {
                 $model->rules[$value->name] = $field_config['validator'];
             });
         }
     }
 }
示例#3
0
文件: Box.php 项目: zrosiak/fields
 /**
  * {@inheritdoc}
  */
 public function onRun()
 {
     $this->category_page = $this->property('categoryPage');
     $this->wide = $this->property('wide') == true;
     $this->type = $this->property('type');
     $this->limit = $this->property('limit');
     $this->subcategories = $this->property('subcategories');
     $this->random = $this->property('random');
     $this->is_promoted = $this->property('is_promoted');
     $this->templates = $this->property('template');
     $this->partial = BoxSetting::find($this->type);
     $this->category = Category::loadCategory($this->category_page);
     $this->posts = BlogPost::getPosts(['post_id' => isset($this->page['post']) ? $this->page['post']->id : null, 'category' => $this->category, 'categories_id' => $this->property('categories_id'), 'limit' => $this->limit, 'template_id' => $this->templates, 'promoted' => $this->is_promoted, 'random' => $this->random, 'subcategories' => $this->subcategories]);
 }
示例#4
0
 /**
  * Run the request filter.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $url = $request->getPathInfo();
     if (strpos('/backend', $url) === false) {
         if (substr($url, 0, 9) === "/download") {
             $path = Config::get('filesystems.disks.local.root', storage_path() . '/app');
             $file = $path . str_replace(["/download", "storage/app/"], "", urldecode($url));
             if (file_exists($file) && is_file($file)) {
                 return response()->download($file);
             }
         } elseif ($url !== "/") {
             $url = Post::checkUrl($url);
         }
     }
     return App::make('Cms\\Classes\\Controller')->run($url);
 }
示例#5
0
文件: Post.php 项目: zrosiak/fields
 /**
  * pobieranie listy postów wg parametrów
  * @param array $params parametry
  * @return Collection
  */
 public static function getPosts(array $params, $query = null)
 {
     extract(array_merge(['post_id' => null, 'category' => null, 'categories_id' => [], 'template_id' => null, 'additional' => [], 'limit' => 0, 'tags' => false, 'post_tags' => [], 'promoted' => false, 'random' => false, 'subcategories' => false, 'category' => null, 'order' => 'published_at DESC', 'pagination' => false, 'posts_per_page' => 10, 'page' => 1], $params));
     $query = $query ?: Post::published()->with('template');
     // post_id
     if ($post_id) {
         $query->where('id', '<>', $post_id);
     }
     // categories_id
     // ustawione na sztywno id kategorii; nadpisują kategorię
     if ($categories_id) {
         $categories_id = is_array($categories_id) ? $categories_id : explode(',', $categories_id);
         $category = Category::find($categories_id);
     } elseif (!$category instanceof Category) {
         // category
         $category = Category::find($category);
     }
     // subcategories
     // pobieranie id podkategorii i kategorii, jeśli subcategories = true
     // w przeciwnym wypadku pobieranie id kategorii
     if ($category && !$categories_id) {
         if ($category instanceof Category) {
             $categories_id = $subcategories ? $category->getSubcategoriesId() : [$category->id];
         } else {
             $categories_id = [];
             foreach ($category as $c) {
                 $categories_id = $categories_id + ($subcategories ? $c->getSubcategoriesId() : [$c->id]);
             }
         }
     }
     // template_id
     if ($template_id) {
         $query->whereIn('template_id', is_array($template_id) ? $template_id : explode(',', $template_id));
     }
     // random
     if ($random) {
         $query->orderByRaw("RANDOM()");
     } else {
         $query->orderByRaw($order);
     }
     // additional
     if ($additional) {
         $additional = is_array($additional) ? $additional : [$additional];
         $key = array_search('variable', $additional);
         if ($key && isset(${$key})) {
             $additional[$key] = ${$key};
         }
         $query->additional($additional);
     }
     // promoted
     if ($promoted) {
         $query->additional(['is_promoted' => '1']);
     }
     // limit
     if ($limit) {
         $query->limit($limit);
     }
     $query->where(function ($q) use($tags, $post_tags, $categories_id, $category) {
         // tags
         if ($tags && $post_tags) {
             $q->whereHas('tags', function ($q) use($post_tags) {
                 $q->whereIn('id', array_fetch($post_tags->toArray(), 'id'));
             });
         }
         // categories
         if ($categories_id) {
             $q->whereIn('category_id', $categories_id);
         }
         // collection
         if (isset($category->collection)) {
             $collection = is_array($category->collection) ? $category->collection : [$category->collection];
             $q->orWhereIn(Db::raw("additional->>'collection'"), array_map('strval', $collection));
         }
     });
     $posts = $pagination ? $query->paginate($posts_per_page, $page) : $query->get();
     return $posts;
 }
示例#6
0
 public function afterUpdate()
 {
     $original = $this->getOriginal();
     // generowanie url dla podkategorii i artykułów
     if (isset($original['slug']) && $original['slug'] !== $this->slug) {
         $this->getSubcategories()->each(function ($elem) {
             if ($elem->id !== $this->id) {
                 $elem->generateUrl();
             }
             Post::queueUrls(array_fetch($elem->posts->toArray(), 'id'));
         });
     }
 }
示例#7
0
文件: Posts.php 项目: zrosiak/fields
 protected function prepareVars()
 {
     $this->pageParam = $this->paramName('pageNumber');
     $this->noPostsMessage = $this->property('noPostsMessage');
     $this->postPage = $this->property('postPage');
     $this->categoryPage = $this->property('categoryPage');
     $this->categoryParent = $this->property('categoryParent');
     $this->category = BlogCategory::loadCategory($this->categoryPage, $this->categoryParent);
     $this->template = $this->property('template') ?: (empty($this->category->template->partial_category) ? null : $this->category->template->partial_category);
     if (empty($this->category->id) || empty($this->category->template->id) && empty($this->template->id)) {
         return \Response::make($this->controller->run('404'), 404);
     }
     // paginacja domyślnie włączona; 'false' wyłącza
     $this->paginationActive = $this->category->pagination !== 'false' || $this->property('postsPerPage') > 0;
     $this->posts = BlogPost::getPosts(['category' => $this->category, 'categories_id' => $this->property('categories_id'), 'template_id' => $this->property('template_id') ?: $this->category->template_id, 'pagination' => $this->paginationActive, 'posts_per_page' => (int) $this->category->pagination > 0 ? $this->category->pagination : $this->property('postsPerPage'), 'page' => $this->property('pageNumber'), 'subcategories' => $this->property('subcategories'), 'order' => "NULLIF(regexp_replace(additional->>'order', E'\\D', '', 'g'), '')::int NULLS LAST, published_at DESC"]);
     $this->setMeta();
 }
示例#8
0
文件: Posts.php 项目: zrosiak/fields
 /**
  * Przejście do artykułu
  */
 public function onGoto($param = null)
 {
     if (isset($param) && ($post = Post::find($param))) {
         return $post->url;
     }
 }
示例#9
0
 public static function run()
 {
     // komunikaty 5270 9351
     // wiadomości 10
     // wiadomosci z pomorza 4136
     // Regulaminy rozgrywek 127
     // Regulaminy rozgrywek 2452
     // Regulaminy Pomorskiego ZPN 5234
     // Regulaminy 2014/15 6926
     // Regulaminy Piłka Kobieca 2014/15 7249
     ini_set('max_execution_time', 1200);
     $aktualnosci = [0 => 7, 1 => 18, 2 => 19, 3 => 20];
     $aktualnosci_z_pomorza = [0 => 17, 1 => 21, 2 => 22, 3 => 23];
     $tags = [1 => 18, 2 => 19, 3 => 20];
     $komisje = [82 => 53, 83 => 16, 2447 => 54, 4093 => 55, 1842 => 56, 95 => 57, 111 => 58, 7277 => 59, 7912 => 60, 96 => 61, 112 => 62, 97 => 63, 7947 => 65, 98 => 66, 2347 => 67, 117 => 69, 118 => 70, 7958 => 71, 2006 => 72];
     $komunikaty_komisji = [1305 => 83, 109 => 84, 2009 => 91, 110 => 86, 1863 => 77, 1302 => 79, 1320 => 89, 1324 => 88, 108 => 82, 2350 => 87, 101 => 78, 2451 => 75, 1216 => 73, 92 => 74, 7930 => 81];
     $komunikaty_id = array_flip($komunikaty_komisji);
     $wydzialy = [19 => 73, 2 => 74, 53 => 75, 43 => 77, 8 => 78, 6 => 78, 3 => 78, 15 => 79, 12 => 80, 13 => 80, 16 => 82, 11 => 82, 10 => 82, 25 => 83, 26 => 84, 4 => 86, 7 => 86, 9 => 86, 18 => 87, 52 => 87, 19 => 88, 24 => 89, 38 => 90, 21 => 91, 22 => 91, 23 => 91];
     /*
     25  Komisja Piłkarstwa Młodzieżowego - od 01.01.2015 – do komunikatów przy zakładce komisji
     26  Komisja Szkoleniowa Kolegium Sędziów - od 01.01.2015 – do komunikatów przy zakładce komisji
     27  Komisja Kwalifikacji Kolegium Sędziów - od 01.01.2015 – do komunikatów przy zakładce komisji
     28  Komisja Mentorska – Kolegium Sędziów - od 01.01.2015 – do komunikatów przy zakładce komisji
     30  OSSM Gdańsk - od 01.01.2015 – do komunikatów przy zakładce komisji
     31  Kadra im. K. Deyny od 01.06.2015 – do komunikatów przy zakładce komisji
     33  Kadra im. K. Górskiego 01.06.2015 – do komunikatów przy zakładce komisji
     34* Kadra im. W. Smolarka - od 01.06.2015 – do komunikatów przy zakładce komisji
     35  Kadra Juniorek U-13 01.06.2015 – do komunikatów przy zakładce komisji
     36  Kadra Młodziczek U-16 01.06.2015 – do komunikatów przy zakładce komisji
     38  Rada Trenerów 01.01.2015 – do komunikatów przy zakładce komisji
     39  Komisja Odznaczeń i Wyróżnień 01.01.2015 – do komunikatów przy zakładce komisji
     41  PZPN - 01.01.2015 – do komunikatów przy zakładce komisji
     42  Extranet - 01.01.2014 – do komunikatów przy zakładce komisji
     43  Komisja ds. Nagłych 01.01.2015 – do komunikatów przy zakładce komisji
     45  Z podwórka na stadion - 01.08.2014 – do komunikatów przy zakładce komisji
     47  Komunikaty obsad 01.07.2015 – do komunikatów przy zakładce komisji
     48  OSSM Malbork 01.01.2015 – do komunikatów przy zakładce komisji
     49  Warsztaty i szkolenia - 01.07.2014 – do komunikatów przy zakładce komisji
     50  Rozgrywki Junior E i F - 01.07.2015 – do komunikatów przy zakładce komisji
     52  Komisja Piłki Plażowej – PRZENIEŚĆ DO FUTSALU (od stycznia 2015)
     57  Fair_play - 01.01.2015 – do komunikatów przy zakładce biuro Gdańsk
     58  Facebook 01.01.2015 – do komunikatów przy zakładce biuro Gdańsk
     */
     $dzialy = [3 => 57, 4 => 66, 5 => 63, 6 => 136, 7 => 137, 8 => 134, 9 => 135, 10 => 61, 11 => 61, 16 => 61, 14 => 147, 15 => 58, 17 => 69, 18 => 67, 21 => 72, 22 => 18, 23 => 20, 24 => 70, 25 => 62, 26 => 145, 28 => 141, 30 => 123, 31 => 118, 33 => 119, 34 => 120, 35 => 121, 36 => 122, 38 => 71, 41 => 72, 42 => 72, 43 => 56, 45 => 38, 47 => 127, 48 => 124, 49 => 45, 50 => 72, 52 => 67, 57 => 72, 58 => 72];
     $daty = [31 => '2015-06-01 00:00:00', 33 => '2015-06-01 00:00:00', 34 => '2015-06-01 00:00:00', 35 => '2015-06-01 00:00:00', 36 => '2015-06-01 00:00:00', 42 => '2014-06-01 00:00:00', 45 => '2014-08-01 00:00:00', 47 => '2015-07-01 00:00:00', 49 => '2014-07-01 00:00:00', 50 => '2015-07-01 00:00:00'];
     Post::extend(function ($model) {
         //$model->guarded = ['id'];
         $model->throwOnValidation = false;
         $model->rules['title'] = '';
         //'unique:rainlab_blog_posts,title';
         $model->rules['url'] = '';
         $model->rules['slug'] = ['required', 'regex:/^[a-z0-9\\/\\:_\\-\\*\\[\\]\\+\\?\\|]*$/i', 'unique:rainlab_blog_posts,slug'];
     });
     $i = 0;
     DB::rollBack();
     DB::beginTransaction();
     try {
         foreach (ImporterBase::$pzpn_site_content as $content) {
             $date = '2015-01-01 00:00:00';
             if (empty($content['wydzialid']) === false && isset($daty[$content['wydzialid']])) {
                 $date = $daty[$content['wydzialid']];
             }
             if ($content['isfolder'] === '0' && date('Y-m-d H:i:s', $content['publishedon']) >= $date && in_array($content['parent'], [10]) && empty($content['alias']) === false) {
                 $category = isset($dzialy[$content['wydzialid']]) ? $dzialy[$content['wydzialid']] : (isset($aktualnosci[$content['podokreg_id']]) ? $aktualnosci[$content['podokreg_id']] : 17);
                 $html = str_replace('assets/', '/storage/app/media/', $content['content']);
                 $data = ['user_id' => 2, 'title' => $content['pagetitle'], 'slug' => Str::slug($content['alias']), 'excerpt' => str_replace('assets/', '/storage/app/media/', $content['introtext']), 'content' => $html, 'published_at' => date('Y-m-d H:i:s', $content['publishedon']), 'published' => $content['published'] === '1' && $content['deleted'] === '0', 'created_at' => date('Y-m-d H:i:s', $content['createdon']), 'updated_at' => date('Y-m-d H:i:s'), 'content_html' => '', 'template_id' => 1, 'category_id' => $category];
                 $model_post = new Post();
                 $model_post->fill($data);
                 if (!$model_post->validate()) {
                     //dd($model_post->errors());
                     echo 'Błąd - ' . $content['id'], '<br>';
                     continue;
                 } else {
                     $data['url'] = $model_post->getUrl();
                     $post = $model_post->insertGetId($data);
                     if ($post > 0 && $content['podokreg_id'] > 0) {
                         $tag = Db::insert(Db::raw('insert into bedard_blogtags_post_tag values(' . (int) $tags[$content['podokreg_id']] . ',' . $post . ')'));
                     }
                     echo $content['id'], '<br>';
                 }
             }
         }
     } catch (Exception $e) {
         DB::rollBack();
         dd($e);
     }
     DB::commit();
     echo 'Sukces!';
     exit;
     array('id' => '9423', 'type' => 'document', 'contentType' => 'text/html', 'pagetitle' => 'Uchwała nr VIII/124 w sprawie statusu zawodników oraz zasad zmian przynależności klubowej ', 'longtitle' => '', 'description' => 'assets/files/A_2015/Uchwaly/Uchwala nr VIII-124.pdf', 'alias' => 'uchwała-nr-viii124-w-sprawie-statusu-zawodników-oraz-zasad-zmian-przynależności-klubowej1', 'link_attributes' => '', 'published' => '1', 'pub_date' => '0', 'unpub_date' => '0', 'parent' => '9411', 'isfolder' => '0', 'introtext' => '', 'content' => '<p>Uchwała nr VIII/124 w sprawie statusu zawodnik&oacute;w oraz zasad zmian przynależności klubowej .pdf</p>', 'richtext' => '1', 'template' => '5', 'menuindex' => '12', 'searchable' => '1', 'cacheable' => '0', 'createdby' => '1', 'createdon' => '1438635743', 'editedby' => '1', 'editedon' => '1438636045', 'deleted' => '0', 'deletedon' => '0', 'deletedby' => '0', 'publishedon' => '1438635855', 'publishedby' => '1', 'menutitle' => '', 'donthit' => '0', 'haskeywords' => '0', 'hasmetatags' => '0', 'privateweb' => '0', 'privatemgr' => '0', 'content_dispo' => '0', 'hidemenu' => '1', 'podokreg_id' => '0', 'wydzialid' => '0', 'slideron' => '0', 'czy_wazna' => '0');
 }
示例#10
0
文件: Post.php 项目: zrosiak/fields
 /**
  * Doczytanie powiązanych postów
  * @return void
  */
 protected function loadRelated()
 {
     if (empty($this->post->template->related) === false) {
         $this->post->categories_id = $this->post->categories->getSubcategoriesId();
         foreach (Yaml::parse($this->post->template->related) as $key => $value) {
             // sprawdzanie czy istnieje wymagany atrybut
             if (isset($value['require']) && !$this->post->{$value['require']}) {
                 continue;
             }
             // przypisanie wartości z posta
             if (isset($value['variable']) && isset($this->post->{$value['variable']})) {
                 $value[$value['variable']] = $this->post->{$value['variable']};
             }
             $this->post->{$key} = isset($value['run']) ? $this->{$value['run']}($this->post, $this->category, $value) : BlogPost::getPosts(['post_id' => $this->post->id, 'categories_id' => empty($this->post->category) ? empty($this->post->communication->id) ? $this->post->categories_id : $this->post->communication->id : $this->post->category, 'tags' => $this->post->tags] + $value);
         }
     }
 }
示例#11
0
 public function getElems($category_id)
 {
     return Post::remember(5)->where('category_id', $category_id)->orderBy('title')->lists('title', 'id');
 }
示例#12
0
文件: Plugin.php 项目: zrosiak/fields
 public function boot()
 {
     $plugin_manager = \System\Classes\PluginManager::instance();
     // Walidacja tablicy
     Validator::extend('arrayed', function ($attribute, $value, $params) {
         foreach ($value as $key => $val) {
             $validation = true;
             for ($i = 1; $i < count($params); $i++) {
                 $validation = $validation && Validator::make($val, [$params[$i] => $params[0]])->fails();
             }
             if ($validation === true) {
                 return false;
             }
         }
         return true;
     });
     // Walidacja numeru telefonu
     Validator::extend('phone', function ($attribute, $value, $parameters) {
         return preg_match('/^(\\+|(00))?(\\([0-9]{2}\\))?([ -]?[0-9]{2,})+$/i', $value) && mb_strlen($value) >= 9 && mb_strlen($value) <= 18;
     });
     /**
      * Rozdzerzenie menu o prawidłowe urle do artykułów
      */
     if ($plugin_manager->hasPlugin('Flynsarmy.Menu')) {
         \Flynsarmy\Menu\Models\Menuitem::extend(function ($model) {
             $model->addDynamicMethod('beforeSave', function () use($model) {
                 $classes = ['Flynsarmy\\Menu\\MenuItemTypes\\BlogPost' => 'rainlab_blog_posts', 'Flynsarmy\\Menu\\MenuItemTypes\\BlogCategory' => 'rainlab_blog_categories'];
                 $column = ['post_id', 'category_id'];
                 if (array_key_exists(post('master_object_class'), $classes)) {
                     $object = Db::table($classes[post('master_object_class')])->find($model->master_object_id);
                     if ($object) {
                         $url = $object->url;
                         $model->url = $url;
                         $model->{$column[array_search(post('master_object_class'), $classes)]} = $model->master_object_id;
                         $model->selected_item_id = $model->selected_item_id ?: $url;
                     }
                 }
                 // usunięcie hosta z urla
                 $model->url = str_replace(\URL::to('/'), '', $model->url);
             });
         });
     }
     // Rozszerzenie pluginu Tags
     if ($plugin_manager->hasPlugin('Bedard.BlogTags')) {
         Tag::extend(function ($model) {
             $model->belongsToMany = ['posts' => ['Bm\\Field\\Models\\Post', 'table' => 'bedard_blogtags_post_tag', 'order' => 'published_at desc']];
         });
         // Extend the model
         Post::extend(function ($model) {
             // Relationship
             $model->belongsToMany['tags'] = ['Bedard\\BlogTags\\Models\\Tag', 'table' => 'bedard_blogtags_post_tag', 'order' => 'name'];
             // getTagboxAttribute()
             $model->addDynamicMethod('getTaglistAttribute', function () use($model) {
                 return $model->tags()->lists('name');
             });
             // setTagboxAttribute()
             $model->addDynamicMethod('setTaglistAttribute', function ($tags) use($model) {
                 $this->tags = $tags;
             });
         });
         // Attach tags to model
         Post::saved(function ($model) {
             if ($this->tags) {
                 $ids = [];
                 foreach ($this->tags as $name) {
                     $create = Tag::firstOrCreate(['name' => $name]);
                     $ids[] = $create->id;
                 }
                 $model->tags()->sync($ids);
             }
         });
     }
     /**
      * Problem z grupowaniem w zarządzaniu grupami
      * @todo usunąć po poprawce w octoberze
      */
     Backend\Models\UserGroup::extend(function ($model) {
         $model->belongsToMany['users_count'] = ['Backend\\Models\\User', 'table' => 'backend_users_groups', 'count' => true, 'key' => 'user_id'];
     });
     /**
      * Rozszerzanie pól bloga
      */
     Event::listen('backend.form.extendFields', function ($form) {
         if ($form->getController() instanceof \Bm\Field\Controllers\Posts && in_array($form->getContext(), ['create', 'update'])) {
             // Nadpisanie pola z tagami
             if (class_exists('\\Bedard\\BlogTags\\Plugin')) {
                 $form->removeField('tagbox');
             }
             // Generowanie pól szablonu
             $form->addTabFields($form->model->generateFields());
             // Ustawianie domyślnej daty publikacji
             $form->data->published_at = $form->data->published_at ?: Carbon::now();
         }
     });
     /**
      * Rozdzerzenie pól menu o id artykułukategorii
      */
     Event::listen('backend.list.extendColumns', function ($widget) {
         if ($widget->getController() instanceof \Flynsarmy\Menu\Controllers\Menus) {
             $widget->addColumns(['post_id' => ['hidden' => true], 'category_id' => ['hidden' => false]]);
         }
     });
     // Rejestracja rozszerzeń Twiga
     Event::listen('cms.page.beforeDisplay', function ($controller, $url, $page) {
         $twig = $controller->getTwig();
         $twig->addExtension(new \Bm\Field\Classes\TwigExcerpt());
         $twig->addExtension(new \Bm\Field\Classes\TwigThumbnail());
         $twig->addExtension(new \Bm\Field\Classes\TwigPostUrl());
         if ($page) {
             // Ustawianie aktywnego urla w menu
             $page->menu_url = empty($page->url) ? '/' : $page->url;
         }
     });
 }
示例#13
0
文件: init.php 项目: zrosiak/fields
<?php

use Bm\Field\Models\Post;
// pobieranie plików
Route::group(['prefix' => 'download'], function () {
    Route::get('{name}', function ($name) {
        $path = Config::get('filesystems.disks.local.root', storage_path() . '/app');
        $file = $path . str_replace("storage/app/", "", urldecode($name));
        if (is_file($file)) {
            return response()->download($file);
        }
    })->where('name', '.*');
});
// artykuły i kategorie
Event::listen('cms.route', function () {
    Route::any('{slug}', function ($slug) {
        return (new Cms\Classes\CmsController())->run(Post::checkUrl("/{$slug}"));
    })->where('slug', '(.*)?');
});