Пример #1
0
 public function go()
 {
     //$feed = file_get_contents($_SERVER['DOCUMENT_ROOT'].'/_add-ons/wordpress/wp_posts.xml');
     //$items = simplexml_load_string($feed);
     $posts_object = simplexml_load_file($_SERVER['DOCUMENT_ROOT'] . '/_add-ons/wordpress/roobottom_old_posts.xml');
     $posts = object_to_array($posts_object);
     $yaml_path = $_SERVER['DOCUMENT_ROOT'] . '/_content/01-blog/';
     foreach ($posts['table'] as $post) {
         if ($post['column'][8] == "publish") {
             $slug = Slug::make($post['column'][5]);
             $slug = preg_replace('/[^a-z\\d]+/i', '-', $slug);
             if (substr($slug, -1) == '-') {
                 $slug = substr($slug, 0, -1);
             }
             $date = date('Y-m-d-Hi', strtotime($post['column'][3]));
             $file = $date . "-" . $slug . ".md";
             if (!File::exists($yaml_path . $file)) {
                 $yaml = [];
                 $yaml['title'] = $post['column'][5];
                 $content = $post['column'][4];
                 $markdown = new HTML_To_Markdown($content, array('header_style' => 'atx'));
                 File::put($yaml_path . $file, YAML::dump($yaml) . '---' . "\n" . $markdown);
             }
             echo $slug . "-" . $date;
             echo "<br/><hr/><br/>";
         }
     }
     return "ok";
 }
 public function generateMarkerSlug()
 {
     $markers = Marker::all();
     foreach ($markers as $marker) {
         $marker->slug = \Slug::make($marker->name);
         $marker->save();
     }
 }
 /**
  * Returns the URL for a given $taxonomy and $taxonomy_slug
  *
  * @param string  $folder  Folder to use
  * @param string  $taxonomy  Taxonomy to use
  * @param string  $taxonomy_slug  Taxonomy slug to use
  * @return string
  */
 public static function getURL($folder, $taxonomy, $taxonomy_slug)
 {
     $url = Config::getSiteRoot() . '/' . $folder . '/' . $taxonomy . '/';
     $url .= Config::getTaxonomySlugify() ? Slug::make($taxonomy_slug) : $taxonomy_slug;
     // if taxonomies are not case-sensitive, make it lowercase
     if (!Config::getTaxonomyCaseSensitive()) {
         $url = strtolower($url);
     }
     return Path::tidy($url);
 }
 public function run()
 {
     Category::create(['title' => 'Офисная бумага', 'alias' => Slug::make('Офисная бумага', '-'), 'image' => 'https://placeimg.com/640/480/tech', 'description' => 'бумага бумага бумага бумага ']);
     Category::create(['title' => 'Ризография', 'alias' => Slug::make('Ризография', '-'), 'image' => 'https://placeimg.com/640/480/tech', 'description' => 'ручки ручки ручки ручки ручки ручки ручки ']);
     Category::create(['title' => 'Картрижди', 'alias' => Slug::make('Картрижди', '-'), 'image' => 'https://placeimg.com/640/480/tech', 'description' => ' техника техника техника техника']);
     $category = Category::create(['title' => 'Канцтовары', 'alias' => Slug::make('Канцтовары', '-'), 'image' => 'https://placeimg.com/640/480/tech', 'description' => ' техника техника техника техника']);
     Category::create(['title' => 'Бумага для заметок', 'alias' => Slug::make('Бумага для заметок', '-'), 'image' => 'https://placeimg.com/640/480/tech', 'description' => ' техника техника техника техника', 'parent_id' => $category->id]);
     Category::create(['title' => 'Дыроколы', 'alias' => Slug::make('Дыроколы', '-'), 'image' => 'https://placeimg.com/640/480/tech', 'description' => ' техника техника техника техника', 'parent_id' => $category->id]);
     Category::create(['title' => 'Ежедневники', 'alias' => Slug::make('Ежедневники', '-'), 'image' => 'https://placeimg.com/640/480/tech', 'description' => ' техника техника техника техника', 'parent_id' => $category->id]);
     Category::create(['title' => 'Полиграфические материалы', 'alias' => Slug::make('Полиграфические материалы', '-'), 'image' => 'https://placeimg.com/640/480/tech', 'description' => ' техника техника техника техника']);
     Category::create(['title' => 'Офисная техника', 'alias' => Slug::make('Офисная техника', '-'), 'image' => 'https://placeimg.com/640/480/tech', 'description' => ' техника техника техника техника']);
 }
Пример #5
0
 public function update($id)
 {
     $category = $this->category->find($id);
     if (Input::get('slug') === "") {
         Input::merge(['slug' => \Slug::make(Input::get('name'))]);
     }
     $category->fill(Input::all());
     if ($category->updateUniques()) {
         return Redirect::route('admin.works.categories.index')->with('success', Lang::get('admin/blogs/messages.create.success'));
     } else {
         return Redirect::back()->withInput(['only' => []])->withErrors($category->errors());
     }
 }
Пример #6
0
 public function update($id)
 {
     $news = $this->news->find($id);
     if (Input::get('slug') === "") {
         Input::merge(['slug' => \Slug::make(Input::get('title'))]);
     }
     $news->fill(Input::all());
     if ($news->updateUniques()) {
         return Redirect::route('admin.news.edit', $news->id)->with('success', Lang::get('admin/news/messages.create.success'));
     } else {
         return Redirect::back()->withInput()->withErrors($news->errors());
     }
 }
Пример #7
0
 public static function setForObject($object)
 {
     $slug_source = Slug::source($object->id);
     $instances = DB::table($object->name)->get();
     $slugs = [];
     foreach ($instances as $instance) {
         if ($slug_source === null) {
             $slug = Slug::make($instance->created_at->format('Y-m-d'), $slugs);
         } else {
             $slug = Slug::make($instance->{$slug_source}, $slugs);
         }
         DB::table($object->name)->where('id', $instance->id)->update(['slug' => $slug]);
         $slugs[] = $slug;
     }
 }
Пример #8
0
 /**
  * Заносим в БД новую категорию, после проверки ввода
  * @param AdminCategoryRequest $request
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postCreate(AdminCategoryRequest $request)
 {
     $data = $request->all();
     //Если алиас не задан, то генерируем его
     if (!$request->has('alias')) {
         $data['alias'] = \Slug::make($request->input('title'));
     }
     //Проверяем есть ли такой же алиас в БД
     if ($this->model->where('alias', '=', $data['alias'])->first()) {
         //Алиас такой существует, выводим ошибку
         return redirect()->back()->with('error', 'Такой алиас существует!!!');
     }
     //Создаем новую запись в БД
     $this->model->create($data);
     return redirect()->route('admin.category.index')->with('success', 'Категория создана!');
 }
Пример #9
0
 public function update($id)
 {
     $work = $this->work->find($id);
     if (Input::get('slug') === "") {
         Input::merge(['slug' => \Slug::make(Input::get('title'))]);
     }
     $work->fill(Input::all());
     $work->need_big_preview = Input::get('need_big_preview');
     if ($work->updateUniques()) {
         if (Input::get('categories')) {
             $work->categories()->sync(Input::get('categories'));
         }
         return Redirect::route('admin.works.edit', $work->id)->with('success', Lang::get('admin/works/messages.create.success'));
     } else {
         return Redirect::back()->withInput()->withErrors($work->errors());
     }
 }
Пример #10
0
 /**
  * Обработка данных из формы и сохранение в БД
  * @param AdminArticleRequest $request
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postCreate(AdminArticleRequest $request)
 {
     $data = $request->all();
     //Если алиас не задан, то генерируем его
     if (!$request->has('alias')) {
         $data['alias'] = \Slug::make($request->input('title'));
         //Проверяем есть ли такой же алиас в БД
         if ($this->model->where('alias', '=', $data['alias'])->first()) {
             //Алиас такой существует, выводим ошибку
             return redirect()->back()->with('error', 'Такой алиас существует!!!');
         }
     }
     $data['user_id'] = $request->user()->id;
     //Создаем запись в БД
     $this->model->create($data);
     return redirect()->route('admin.article.index')->with('success', 'Материал добавлен!');
 }
Пример #11
0
 public function update($id)
 {
     $post = $this->post->find($id);
     if (Input::get('slug') === "") {
         Input::merge(['slug' => \Slug::make(Input::get('title'))]);
     }
     $post->fill(Input::all());
     if ($post->updateUniques()) {
         if (Input::get('rubrics')) {
             $post->rubrics()->sync(Input::get('rubrics'));
         }
         if (Input::get('tags')) {
             $post->retag(explode(",", Input::get('tags')));
         }
         return Redirect::route('admin.blogs.edit', $post->id)->with('success', Lang::get('admin/blogs/messages.create.success'));
     } else {
         return Redirect::back()->withInput()->withErrors($post->errors());
     }
 }
Пример #12
0
 public function run()
 {
     $faker = Faker::create();
     $title = $faker->sentence();
     News::create(['created_at' => $faker->date($format = 'Y-m-d', $max = 'now'), 'title' => $title, 'alias' => Slug::make($title, '-'), 'body' => $faker->text($maxNbChars = 800), 'image' => '/public/files/Фото для сайта/Фото на новости/thumb-up.jpeg']);
     foreach (range(1, 22) as $index) {
         $title = $faker->sentence();
         News::create(['created_at' => $faker->date($format = 'Y-m-d', $max = 'now'), 'title' => $title, 'alias' => Slug::make($title, '-'), 'body' => $faker->text($maxNbChars = 800), 'image' => $faker->imageUrl($width = 640, $height = 480)]);
         // foreach(range(1, 10) as $cindex)
         // {
         //     Comment::create([
         //         'created_at' => $faker->date($format = 'Y-m-d', $max = 'now'),
         //         'author' => $faker->name,
         //         'body' => $faker->text($maxNbChars = 200),
         //         'news_id' => $index,
         //     ]);
         // }
     }
 }
Пример #13
0
 /**
  * Cleans up a file name
  *
  * @param string  $path  Path and file name to clean up
  * @return string
  */
 public static function cleanFilename($path)
 {
     $extension = self::getExtension($path);
     $path = str_replace('.' . $extension, '', $path);
     return Slug::make($path) . '.' . $extension;
 }
Пример #14
0
     Route::get('/import/import/{table}', 'ImportController@import');
     Route::get('/import/drop/{table}', 'ImportController@drop');
 });
 # All authenticated users
 Route::group(array('before' => 'user'), function () {
     Route::get('/', array('as' => 'home', 'uses' => 'ObjectController@index'));
     Route::get('/logout', 'LoginController@getLogout');
     Route::post('/upload/image', 'FileController@image');
     # Test routes
     Route::get('/schema/save', 'ObjectController@saveSchema');
     Route::get('/schema/load', 'ObjectController@loadSchema');
     Route::get('/image/test', 'FileController@test');
     Route::get('/slug/test', function () {
         $phrases = ['', 'and', 'this is a normal test', 'this is a really really really long test because it\'s amazing and great and am i at 50 YET???'];
         foreach ($phrases as $phrase) {
             echo '<p>' . $phrase . ' becomes <em>' . Slug::make($phrase, ['', 'normal-test', 'normal-test-1']) . '</em></p>';
         }
     });
     Route::get('/slug/object/{object_id}', function ($object_id) {
         $object = DB::table(DB_OBJECTS)->find($object_id);
         Slug::setForObject($object);
         die('object was ' . $object->name);
     });
     Route::get('cleanup', function () {
         FieldController::cleanup();
         FileController::findOrphans();
         FileController::cleanup();
     });
     # Complex instance routing, optionally with linked_id for related objects
     Route::get('/{object_name}/delete/{instance_id}', 'InstanceController@delete');
     Route::get('/{object_name}', 'InstanceController@index');
Пример #15
0
 public function showRecipiesByMarkerBySlug($slug)
 {
     if ($marker = Marker::where('slug', '=', $slug)->first()) {
         $recipies = $marker->recipies;
         $recipies = $recipies->filter(function ($item) {
             return $item->postStatus_id == 3;
         });
         $title = CmsOption::getValue('Название сайта') . ' | ' . $marker->name;
         $metaOptions = ['marker' => $marker];
         Session::put('recipies', $recipies);
         Session::put('marker', $marker);
         Session::put('typepage', 'bymarker');
         if ($marker->slug == '') {
             $markerslug = \Slug::make($marker->name);
         } else {
             $markerslug = $marker->slug;
         }
         return view('recipieGrid', ['recipies' => $recipies, 'title' => $title, 'page_title' => $marker->name, 'metaOptions' => $metaOptions]);
     }
 }
Пример #16
0
 public function testWithNoTransliterate()
 {
     $slug = Slug::make('essai Français')->setTransliterate(false);
     $good_slug = 'essai-français';
     $this->assertEquals($good_slug, $slug);
 }
Пример #17
0
 public function waresImportStore()
 {
     if (Input::hasFile('importFile')) {
         $file = Input::file('importFile');
         $filePath = public_path('uploads/imports/' . date('Y/m/d'));
         $fileName = Str::random('3') . $file->getClientOriginalName();
         $file->move($filePath, $fileName);
         $excel = Excel::load("{$filePath}/{$fileName}", function ($reader) {
         })->get();
         foreach ($excel as $item) {
             $ware = Ware::where('article', $item->sku)->first();
             if (!$ware) {
                 $ware = new Ware();
                 $ware->slug = Slug::make($item->name) . Str::random(8);
             }
             $ware->article = $item->sku;
             $ware->slug = Slug::make($item->name);
             $ware->title = $item->name;
             $ware->price = $item->list_price;
             $ware->discount = $item->sell_price;
             $ware->save();
         }
         return 'ok';
     }
 }
Пример #18
0
Файл: helper.php Проект: nob/joi
 /**
  * slugify
  * Converts a string from normal-format to slug-format
  *
  * credit: http://sourcecookbook.com/en/recipes/8/function-to-slugify-strings-in-php
  *
  * @deprecated  Use Slug::make() instead
  *
  * @param string  $text  String to convert
  * @return string
  */
 public static function slugify($text)
 {
     Log::warn("Use of Statamic_Helper::slugify() is deprecated. Use Slug::make() instead.", "core", "Statamic_Helper");
     return Slug::make($text);
 }
Пример #19
0
 /**
  * Vérification des champs modifiable et
  * Slugification des champs à slugifier
  * @param  array $fields
  * @return array
  */
 private function getFillandSlug($fields)
 {
     // verification des champs modifiable
     foreach ($fields as $key => $value) {
         // unset not fillable
         if (!in_array($key, $this->fillable)) {
             unset($fields[$key]);
         }
         // slug
         if (in_array($key, $this->slugs)) {
             $key_slug = array_search($key, $this->slugs);
             if (empty($fields[$key_slug]) || !isset($fields[$key_slug])) {
                 $fields[$key_slug] = \Slug::make($fields[$key]);
             }
         }
     }
     return $fields;
 }
 /**
  * Gets a list of taxonomy values by type
  *
  * @param string  $type  Taxonomy type to retrieve
  * @return TaxonomySet
  */
 public static function getTaxonomiesByType($type)
 {
     self::loadCache();
     $data = array();
     // taxonomy type doesn't exist, return empty
     if (!isset(self::$cache['taxonomies'][$type])) {
         return new TaxonomySet(array());
     }
     $url_root = Config::getSiteRoot() . $type;
     $values = self::$cache['taxonomies'][$type];
     $slugify = Config::getTaxonomySlugify();
     // what we need
     // - name
     // - count of related content
     // - related
     foreach ($values as $key => $parts) {
         $set = array();
         $prepared_key = $slugify ? Slug::make($key) : rawurlencode($key);
         foreach ($parts['files'] as $url) {
             if (!isset(self::$cache['urls'][$url])) {
                 continue;
             }
             $set[$url] = self::$cache["content"][self::$cache['urls'][$url]['folder']][self::$cache['urls'][$url]['file']]['data'];
         }
         $data[$key] = array('content' => new ContentSet($set), 'name' => $parts['name'], 'url' => $url_root . '/' . $prepared_key, 'slug' => $type . '/' . $prepared_key);
         $data[$key]['count'] = $data[$key]['content']->count();
     }
     return new TaxonomySet($data);
 }
Пример #21
0
Файл: Parser.php Проект: nob/joi
 /**
  * Takes a dot-notated key and finds the value for it in the given
  * array or object.
  *
  * @param  string       $key     Dot-notated key to find
  * @param  array|object $data    Array or object to search
  * @param  mixed        $default Default value to use if not found
  * @return mixed
  */
 protected function getVariable($key, $data, $default = null)
 {
     $modifiers = null;
     if (strpos($key, "|") === false) {
     } else {
         $parts = explode("|", $key);
         $key = $parts[0];
         $modifiers = array_splice($parts, 1);
     }
     if (strpos($key, $this->scopeGlue) === false) {
         $parts = explode('.', $key);
     } else {
         $parts = explode($this->scopeGlue, $key);
     }
     foreach ($parts as $key_part) {
         if (is_array($data)) {
             if (!array_key_exists($key_part, $data)) {
                 return $default;
             }
             $data = $data[$key_part];
         } elseif (is_object($data)) {
             if (!isset($data->{$key_part})) {
                 return $default;
             }
             $data = $data->{$key_part};
         } else {
             return $default;
         }
     }
     if ($modifiers) {
         foreach ($modifiers as $mod) {
             if (strpos($mod, ":") === false) {
                 $modifier_name = $mod;
                 $modifier_params = array();
             } else {
                 $parts = explode(":", $mod);
                 $modifier_name = $parts[0];
                 $modifier_params = array_splice($parts, 1);
             }
             if ($modifier_name == 'trim') {
                 $data = trim($data);
             } elseif ($modifier_name == 'img') {
                 $data = '<img src="' . \Path::toAsset($data) . '" />';
             } elseif ($modifier_name == 'link') {
                 if (filter_var($data, FILTER_VALIDATE_EMAIL)) {
                     // email address
                     $data = '<a href="mailto:' . $data . '" />' . $data . '</a>';
                 } else {
                     $data = '<a href="' . $data . '" />' . $data . '</a>';
                 }
             } elseif ($modifier_name == 'upper') {
                 $data = strtoupper($data);
             } else {
                 if ($modifier_name == 'lower') {
                     $data = strtolower($data);
                 } else {
                     if ($modifier_name == 'slugify') {
                         $data = \Slug::make($data);
                     } else {
                         if ($modifier_name == 'deslugify') {
                             $data = trim(preg_replace('~[-_]~', ' ', $data), " ");
                         } else {
                             if ($modifier_name == 'title') {
                                 $data = ucwords($data);
                             } else {
                                 if ($modifier_name == 'format') {
                                     $data = date($modifier_params[0], $data);
                                 } else {
                                     if ($modifier_name == 'format_number') {
                                         $decimals = isset($modifier_params[0]) ? $modifier_params[0] : 0;
                                         $data = number_format($data, $decimals);
                                     } else {
                                         if ($modifier_name == 'in_future') {
                                             $data = \Date::resolve($data) > time() ? "true" : "";
                                         } else {
                                             if ($modifier_name == 'in_past') {
                                                 $data = \Date::resolve($data) < time() ? "true" : "";
                                             } else {
                                                 if ($modifier_name == 'markdown') {
                                                     $data = Markdown($data);
                                                 } else {
                                                     if ($modifier_name == 'textile') {
                                                         $textile = new \Textile();
                                                         $data = $textile->TextileThis($data);
                                                     } else {
                                                         if ($modifier_name == 'length') {
                                                             if (is_array($data)) {
                                                                 $data = count($data);
                                                             } else {
                                                                 $data = strlen($data);
                                                             }
                                                         } else {
                                                             if ($modifier_name == 'scramble') {
                                                                 $data = str_shuffle($data);
                                                             } else {
                                                                 if ($modifier_name == 'word_count') {
                                                                     $data = str_word_count($data);
                                                                 } else {
                                                                     if ($modifier_name == 'obfuscate') {
                                                                         $data = \HTML::obfuscateEmail($data);
                                                                     } else {
                                                                         if ($modifier_name == 'rot13') {
                                                                             $data = str_rot13($data);
                                                                         } else {
                                                                             if ($modifier_name == 'urlencode') {
                                                                                 $data = urlencode($data);
                                                                             } else {
                                                                                 if ($modifier_name == 'urldecode') {
                                                                                     $data = urldecode($data);
                                                                                 } else {
                                                                                     if ($modifier_name == 'striptags') {
                                                                                         $data = strip_tags($data);
                                                                                     } else {
                                                                                         if ($modifier_name == '%') {
                                                                                             $divisor = isset($modifier_params[0]) ? $modifier_params[0] : 1;
                                                                                             $data = $data % $divisor;
                                                                                         } else {
                                                                                             if ($modifier_name == 'empty') {
                                                                                                 $data = \Helper::isEmptyArray($data) ? "true" : "";
                                                                                             } else {
                                                                                                 if ($modifier_name == 'not_empty') {
                                                                                                     $data = !\Helper::isEmptyArray($data) ? "true" : "";
                                                                                                 } else {
                                                                                                     if ($modifier_name == 'numeric') {
                                                                                                         $data = is_numeric($data) ? "true" : "";
                                                                                                     } else {
                                                                                                         if ($modifier_name == 'repeat') {
                                                                                                             $multiplier = isset($modifier_params[0]) ? $modifier_params[0] : 1;
                                                                                                             $data = str_repeat($data, $multiplier);
                                                                                                         } else {
                                                                                                             if ($modifier_name == 'reverse') {
                                                                                                                 $data = strrev($data);
                                                                                                             } else {
                                                                                                                 if ($modifier_name == 'round') {
                                                                                                                     $precision = isset($modifier_params[0]) ? (int) $modifier_params[0] : 0;
                                                                                                                     $data = round((double) $data, $precision);
                                                                                                                 } else {
                                                                                                                     if ($modifier_name == 'floor') {
                                                                                                                         $data = floor((double) $data);
                                                                                                                     } else {
                                                                                                                         if ($modifier_name == 'ceil') {
                                                                                                                             $data = ceil((double) $data);
                                                                                                                         } else {
                                                                                                                             if ($modifier_name == '+') {
                                                                                                                                 if (isset($modifier_params[0])) {
                                                                                                                                     $number = $modifier_params[0];
                                                                                                                                     $data = $data + $number;
                                                                                                                                 }
                                                                                                                             } else {
                                                                                                                                 if ($modifier_name == '-') {
                                                                                                                                     if (isset($modifier_params[0])) {
                                                                                                                                         $number = $modifier_params[0];
                                                                                                                                         $data = $data - $number;
                                                                                                                                     }
                                                                                                                                 } else {
                                                                                                                                     if ($modifier_name == '*') {
                                                                                                                                         if (isset($modifier_params[0])) {
                                                                                                                                             $number = $modifier_params[0];
                                                                                                                                             $data = $data * $number;
                                                                                                                                         }
                                                                                                                                     } else {
                                                                                                                                         if ($modifier_name == '/') {
                                                                                                                                             if (isset($modifier_params[0])) {
                                                                                                                                                 $number = $modifier_params[0];
                                                                                                                                                 $data = $data / $number;
                                                                                                                                             }
                                                                                                                                         } else {
                                                                                                                                             if ($modifier_name == '^') {
                                                                                                                                                 if (isset($modifier_params[0])) {
                                                                                                                                                     $exp = $modifier_params[0];
                                                                                                                                                     $data = pow($data, $exp);
                                                                                                                                                 }
                                                                                                                                             } else {
                                                                                                                                                 if ($modifier_name == 'sqrt') {
                                                                                                                                                     $data = sqrt($data);
                                                                                                                                                 } else {
                                                                                                                                                     if ($modifier_name == 'abs') {
                                                                                                                                                         $data = abs($data);
                                                                                                                                                     } else {
                                                                                                                                                         if ($modifier_name == 'log') {
                                                                                                                                                             $base = isset($modifier_params[0]) ? (int) $modifier_params[0] : M_E;
                                                                                                                                                             $data = log($data, $base);
                                                                                                                                                         } else {
                                                                                                                                                             if ($modifier_name == 'log10') {
                                                                                                                                                                 $data = log10($data);
                                                                                                                                                             } else {
                                                                                                                                                                 if ($modifier_name == 'deg2rad') {
                                                                                                                                                                     $data = deg2rad($data);
                                                                                                                                                                 } else {
                                                                                                                                                                     if ($modifier_name == 'rad2deg') {
                                                                                                                                                                         $data = rad2deg($data);
                                                                                                                                                                     } else {
                                                                                                                                                                         if ($modifier_name == 'sin') {
                                                                                                                                                                             $data = sin($data);
                                                                                                                                                                         } else {
                                                                                                                                                                             if ($modifier_name == 'asin') {
                                                                                                                                                                                 $data = asin($data);
                                                                                                                                                                             } else {
                                                                                                                                                                                 if ($modifier_name == 'cos') {
                                                                                                                                                                                     $data = cos($data);
                                                                                                                                                                                 } else {
                                                                                                                                                                                     if ($modifier_name == 'acos') {
                                                                                                                                                                                         $data = acos($data);
                                                                                                                                                                                     } else {
                                                                                                                                                                                         if ($modifier_name == 'tan') {
                                                                                                                                                                                             $data = tan($data);
                                                                                                                                                                                         } else {
                                                                                                                                                                                             if ($modifier_name == 'atan') {
                                                                                                                                                                                                 $data = atan($data);
                                                                                                                                                                                             } else {
                                                                                                                                                                                                 if ($modifier_name == 'decbin') {
                                                                                                                                                                                                     $data = decbin($data);
                                                                                                                                                                                                 } else {
                                                                                                                                                                                                     if ($modifier_name == 'dechex') {
                                                                                                                                                                                                         $data = dechex($data);
                                                                                                                                                                                                     } else {
                                                                                                                                                                                                         if ($modifier_name == 'decoct') {
                                                                                                                                                                                                             $data = decoct($data);
                                                                                                                                                                                                         } else {
                                                                                                                                                                                                             if ($modifier_name == 'hexdec') {
                                                                                                                                                                                                                 $data = hexdec($data);
                                                                                                                                                                                                             } else {
                                                                                                                                                                                                                 if ($modifier_name == 'octdec') {
                                                                                                                                                                                                                     $data = octdec($data);
                                                                                                                                                                                                                 } else {
                                                                                                                                                                                                                     if ($modifier_name == 'bindec') {
                                                                                                                                                                                                                         $data = bindec((string) $data);
                                                                                                                                                                                                                     } else {
                                                                                                                                                                                                                         if ($modifier_name == 'distance_in_mi_from') {
                                                                                                                                                                                                                             if (!isset($modifier_params[0])) {
                                                                                                                                                                                                                                 return 'Unknown';
                                                                                                                                                                                                                             }
                                                                                                                                                                                                                             if (!preg_match(\Pattern::COORDINATES, $data, $point_1_matches)) {
                                                                                                                                                                                                                                 return 'Unknown';
                                                                                                                                                                                                                             }
                                                                                                                                                                                                                             if (!preg_match(\Pattern::COORDINATES, $modifier_params[0], $point_2_matches)) {
                                                                                                                                                                                                                                 return 'Unknown';
                                                                                                                                                                                                                             }
                                                                                                                                                                                                                             $point_1 = array($point_1_matches[1], $point_1_matches[2]);
                                                                                                                                                                                                                             $point_2 = array($point_2_matches[1], $point_2_matches[2]);
                                                                                                                                                                                                                             $distance = \Math::getDistanceInKilometers($point_1, $point_2);
                                                                                                                                                                                                                             $data = \Math::convertKilometersToMiles($distance);
                                                                                                                                                                                                                         } else {
                                                                                                                                                                                                                             if ($modifier_name == 'distance_in_km_from') {
                                                                                                                                                                                                                                 if (!isset($modifier_params[0])) {
                                                                                                                                                                                                                                     return 'Unknown';
                                                                                                                                                                                                                                 }
                                                                                                                                                                                                                                 if (!preg_match(\Pattern::COORDINATES, $data, $point_1_matches)) {
                                                                                                                                                                                                                                     return 'Unknown';
                                                                                                                                                                                                                                 }
                                                                                                                                                                                                                                 if (!preg_match(\Pattern::COORDINATES, $modifier_params[0], $point_2_matches)) {
                                                                                                                                                                                                                                     return 'Unknown';
                                                                                                                                                                                                                                 }
                                                                                                                                                                                                                                 $point_1 = array($point_1_matches[1], $point_1_matches[2]);
                                                                                                                                                                                                                                 $point_2 = array($point_2_matches[1], $point_2_matches[2]);
                                                                                                                                                                                                                                 $data = \Math::getDistanceInKilometers($point_1, $point_2);
                                                                                                                                                                                                                             } else {
                                                                                                                                                                                                                                 if ($modifier_name == 'smartypants') {
                                                                                                                                                                                                                                     $data = SmartyPants($data, 2);
                                                                                                                                                                                                                                 } else {
                                                                                                                                                                                                                                     if ($modifier_name == 'widont') {
                                                                                                                                                                                                                                         // thanks to Shaun Inman for inspriation here
                                                                                                                                                                                                                                         // http://www.shauninman.com/archive/2008/08/25/widont_2_1_1
                                                                                                                                                                                                                                         // if there are content tags
                                                                                                                                                                                                                                         if (preg_match("/<\\/(?:p|li|h1|h2|h3|h4|h5|h6|figcaption)>/ism", $data)) {
                                                                                                                                                                                                                                             $data = preg_replace("/(?<!<[p|li|h1|h2|h3|h4|h5|h6|div|figcaption])([^\\s])[ \t]+([^\\s]+(?:<\\/(?:p|li|h1|h2|h3|h4|h5|h6|div|figcaption)>))\$/im", "\$1&nbsp;\$2", rtrim($data));
                                                                                                                                                                                                                                             // otherwise
                                                                                                                                                                                                                                         } else {
                                                                                                                                                                                                                                             $data = preg_replace("/([^\\s])\\s+([^\\s]+)\\s*\$/im", "\$1&nbsp;\$2", rtrim($data));
                                                                                                                                                                                                                                         }
                                                                                                                                                                                                                                     } elseif ($modifier_name == 'backspace') {
                                                                                                                                                                                                                                         if (!is_array($data) && isset($modifier_params[0]) && $modifier_params[0] > 0) {
                                                                                                                                                                                                                                             $data = substr($data, 0, -$modifier_params[0]);
                                                                                                                                                                                                                                         }
                                                                                                                                                                                                                                     } else {
                                                                                                                                                                                                                                         if ($modifier_name == 'truncate') {
                                                                                                                                                                                                                                             $length = 30;
                                                                                                                                                                                                                                             $hellip = "&hellip;";
                                                                                                                                                                                                                                             if (sizeof($modifier_params) > 0) {
                                                                                                                                                                                                                                                 $length = (int) $modifier_params[0];
                                                                                                                                                                                                                                             } else {
                                                                                                                                                                                                                                                 if (isset($modifier_params[1])) {
                                                                                                                                                                                                                                                     $hellip = (int) $modifier_params[1];
                                                                                                                                                                                                                                                 }
                                                                                                                                                                                                                                             }
                                                                                                                                                                                                                                             if (strlen($data) > $length) {
                                                                                                                                                                                                                                                 $data = substr($data, 0, $length) . $hellip;
                                                                                                                                                                                                                                             }
                                                                                                                                                                                                                                         }
                                                                                                                                                                                                                                     }
                                                                                                                                                                                                                                 }
                                                                                                                                                                                                                             }
                                                                                                                                                                                                                         }
                                                                                                                                                                                                                     }
                                                                                                                                                                                                                 }
                                                                                                                                                                                                             }
                                                                                                                                                                                                         }
                                                                                                                                                                                                     }
                                                                                                                                                                                                 }
                                                                                                                                                                                             }
                                                                                                                                                                                         }
                                                                                                                                                                                     }
                                                                                                                                                                                 }
                                                                                                                                                                             }
                                                                                                                                                                         }
                                                                                                                                                                     }
                                                                                                                                                                 }
                                                                                                                                                             }
                                                                                                                                                         }
                                                                                                                                                     }
                                                                                                                                                 }
                                                                                                                                             }
                                                                                                                                         }
                                                                                                                                     }
                                                                                                                                 }
                                                                                                                             }
                                                                                                                         }
                                                                                                                     }
                                                                                                                 }
                                                                                                             }
                                                                                                         }
                                                                                                     }
                                                                                                 }
                                                                                             }
                                                                                         }
                                                                                     }
                                                                                 }
                                                                             }
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $data;
 }
Пример #22
0
 public static function get_content_meta($slug, $folder = null, $raw = false, $parse = true)
 {
     $app = \Slim\Slim::getInstance();
     $site_root = Config::getSiteRoot();
     $content_root = Config::getContentRoot();
     $content_type = Config::getContentType();
     $file = $folder ? "{$content_root}/{$folder}/{$slug}.{$content_type}" : "{$content_root}/{$slug}.{$content_type}";
     $file = Path::tidy($file);
     $meta_raw = File::exists($file) ? file_get_contents($file) : '';
     if (Pattern::endsWith($meta_raw, "---")) {
         $meta_raw .= "\n";
         # prevent parse failure
     }
     # Parse YAML Front Matter
     if (strpos($meta_raw, "---") === false) {
         $meta = self::loadYamlCached($meta_raw);
         if (is_array($meta)) {
             $meta = array_merge($meta, $app->config);
         }
         $meta['content'] = "";
         if ($raw) {
             $meta['content_raw'] = "";
         }
     } else {
         list($yaml, $content) = preg_split("/\n---/", $meta_raw, 2, PREG_SPLIT_NO_EMPTY);
         $meta = self::loadYamlCached($yaml);
         if ($raw) {
             $meta['content_raw'] = $content;
         }
         // Parse the content if necessary
         //$meta['content'] = $parse ? Content::parse($content, $meta) : $content;
         $meta['content'] = $content;
     }
     if (File::exists($file)) {
         $meta['last_modified'] = filemtime($file);
     }
     if (!$raw) {
         $meta['homepage'] = Config::getSiteRoot();
         $meta['raw_url'] = Request::getResourceURI();
         $meta['page_url'] = Request::getResourceURI();
         # Is date formatted correctly?
         if (Config::getEntryTimestamps() && Slug::isDateTime($slug)) {
             $datetimestamp = Slug::getTimestamp($slug);
             $datestamp = Slug::getTimestamp($slug);
             $meta['datetimestamp'] = $datetimestamp;
             $meta['datestamp'] = $datestamp;
             $meta['date'] = Date::format(Config::getDateFormat(), $datestamp);
             $meta['time'] = Date::format(Config::getTimeFormat(), $datetimestamp);
             $meta['page_url'] = preg_replace(Pattern::DATETIME, '', $meta['page_url']);
             # clean url override
         } elseif (Slug::isDate($slug)) {
             $datestamp = Slug::getTimestamp($slug);
             $meta['datestamp'] = $datestamp;
             $meta['date'] = Date::format(Config::getDateFormat(), $datestamp);
             $meta['page_url'] = preg_replace(Pattern::DATE, '', $meta['page_url']);
             # clean url override
         } elseif (Slug::isNumeric($slug)) {
             $meta['numeric'] = Slug::getOrderNumber($slug);
         }
         $meta['permalink'] = Path::tidy(Config::getSiteURL() . '/' . $meta['page_url']);
         $taxonomy_slugify = isset($app->config['_taxonomy_slugify']) && $app->config['_taxonomy_slugify'];
         # Jam it all together, brother.
         # @todo: functionize/abstract this method for more flexibility and readability
         foreach ($meta as $key => $value) {
             if (!is_array($value) && Taxonomy::isTaxonomy($key)) {
                 $value = array($value);
                 $meta[$key] = $value;
             }
             if (is_array($value)) {
                 $list = array();
                 $url_list = array();
                 $i = 1;
                 $total_results = count($meta[$key]);
                 foreach ($meta[$key] as $k => $v) {
                     $url = null;
                     if (Taxonomy::isTaxonomy($key) && !is_array($v)) {
                         // DO NOT DO numerical regex replace on the actual taxonomy item
                         $url = Path::tidy(strtolower($site_root . '/' . $folder . '/' . $key));
                         $url = preg_replace(Pattern::NUMERIC, '', $url);
                         if ($taxonomy_slugify) {
                             $url .= "/" . strtolower(Slug::make($v));
                         } else {
                             $url .= "/" . strtolower($v);
                         }
                         $list[] = array('name' => $v, 'count' => $i, 'url' => $url, 'total_results' => $total_results, 'first' => $i == 1 ? true : false, 'last' => $i == $total_results ? true : false);
                         $url_list[] = '<a href="' . $url . '">' . $v . '</a>';
                     } elseif (!is_array($v)) {
                         $list[] = array('name' => $v, 'count' => $i, 'url' => $url, 'total_results' => $total_results, 'first' => $i == 1 ? true : false, 'last' => $i == $total_results ? true : false);
                     }
                     // account for known structure
                     // -
                     //   name: something
                     //   url: http://example.com
                     if (is_array($v) && isset($v['name']) && isset($v['url'])) {
                         $url_list[] = '<a href="' . $v['url'] . '">' . $v['name'] . '</a>';
                     }
                     $i++;
                 }
                 if (isset($url) || count($url_list)) {
                     $meta[$key . '_url_list'] = implode(', ', $url_list);
                     $meta[$key . '_spaced_url_list'] = join(" ", $url_list);
                     $meta[$key . '_ordered_url_list'] = "<ol><li>" . join("</li><li>", $url_list) . "</li></ol>";
                     $meta[$key . '_unordered_url_list'] = "<ul><li>" . join("</li><li>", $url_list) . "</li></ul>";
                     $meta[$key . '_sentence_url_list'] = Helper::makeSentenceList($url_list);
                     $meta[$key . '_ampersand_sentence_url_list'] = Helper::makeSentenceList($url_list, "&", false);
                 }
                 if (isset($meta[$key][0]) && !is_array($meta[$key][0])) {
                     $meta[$key . '_list'] = implode(', ', $meta[$key]);
                     $meta[$key . '_option_list'] = implode('|', $meta[$key]);
                     $meta[$key . '_spaced_list'] = implode(' ', $meta[$key]);
                     $meta[$key . '_ordered_list'] = "<ol><li>" . join("</li><li>", $meta[$key]) . "</li></ol>";
                     $meta[$key . '_unordered_list'] = "<ul><li>" . join("</li><li>", $meta[$key]) . "</li></ul>";
                     $meta[$key . '_sentence_list'] = Helper::makeSentenceList($meta[$key]);
                     $meta[$key . '_ampersand_sentence_list'] = Helper::makeSentenceList($meta[$key], "&", false);
                     $meta[$key] = $list;
                 }
             }
         }
     }
     return $meta;
 }
Пример #23
0
 |
 | Let's create or update this file.
 |
 */
 $file_content = File::buildContent($publish_data['yaml'], $publish_data['content']);
 File::put(Path::assemble(BASE_PATH, $file), $file_content);
 /*
 |--------------------------------------------------------------------------
 | Rename/move file
 |--------------------------------------------------------------------------
 |
 | If the slug changed we'll need to rename the file accordingly.
 |
 */
 if (!isset($form_data['new'])) {
     $new_slug = $form_data['meta']['slug'] === '/' ? '/' : Slug::make($form_data['meta']['slug']);
     // Date Entry
     if ($form_data['type'] == 'date') {
         // With Timestamps
         if (Config::getEntryTimestamps()) {
             $new_timestamp = $form_data['meta']['publish-time'];
             $new_datestamp = $form_data['meta']['publish-date'];
             $new_file = Path::assemble($content_root, dirname($path), $status_prefix . $new_datestamp . "-" . $new_timestamp . "-" . $new_slug . "." . $content_type);
             // Without Timestamps
         } else {
             $new_datestamp = $form_data['meta']['publish-date'];
             $new_file = Path::assemble($content_root, dirname($path), $status_prefix . $new_datestamp . "-" . $new_slug . "." . $content_type);
         }
         // Numerical Entry
     } elseif ($form_data['type'] == 'number') {
         $new_numeric = $form_data['meta']['publish-numeric'];
Пример #24
0
 /**
  * Converts string from special characters to URL friendly string
  *
  * @param string $string String co covert
  * @param string $separator Separator to replace spaces
  * @param null $emptyValue Return value if target result is empty
  *
  * @return string URL friendly string
  */
 public static function slug($string, $separator = '-', $emptyValue = null)
 {
     return Slug::make($string, $separator, $emptyValue);
 }
 public function user_agent()
 {
     $slugify = $this->fetchParam("slugify", TRUE, NULL, FALSE, TRUE);
     $user_agent = $this->getBrowserInfo()['browser_ua'];
     if ($slugify) {
         return Slug::make($user_agent);
     } else {
         return $user_agent;
     }
 }
 public function createPhotoCollection()
 {
     $yaml_path = $_SERVER['DOCUMENT_ROOT'] . '/_content/photos/';
     $files = glob($yaml_path . '*.{md,collection}', GLOB_BRACE);
     $arr_files = [];
     //put each file into an array
     foreach ($files as $file) {
         if (basename($file) != "page.md") {
             $temp = array('date' => substr(basename($file), 0, 10), 'time' => substr(basename($file), 11, 4), 'hour' => substr(basename($file), 11, 2), 'file' => basename($file));
             $arr_files[] = $temp;
         }
     }
     //now split these into more arrays, grouped by date.
     //this is where we're loosing a file
     $last_date = $arr_files[0]['date'];
     $arr_groups = [];
     $i = 0;
     foreach ($arr_files as $file) {
         if ($last_date != $file['date']) {
             $i++;
         }
         $arr_groups[$i][] = $file;
         $last_date = $file['date'];
     }
     reset($arr_groups);
     //now further split this into similar times (+ or - 2 hours of eachother)
     $last_time = $arr_groups[0][0]['hour'];
     foreach ($arr_groups as $group) {
         if (count($group) > 1) {
             $last_time = $group[0]['hour'];
             foreach ($group as $item) {
                 $max = $last_time + 2;
                 $min = $last_time - 2;
                 if ($min < $item['hour'] && $item['hour'] > $max) {
                     $i++;
                 }
                 $time_groups[$i][] = $item;
                 $last_time = $item['hour'];
             }
             $i++;
         }
     }
     //now write out these groups into new YAML files.
     foreach ($time_groups as $times) {
         $YAML_arr = [];
         $images_arr = [];
         $i = 0;
         if (count($times) > 1) {
             foreach ($times as $item) {
                 //convert this array into the -images part of the YAML
                 $images_arr[] = YAML::parseFile($yaml_path . $item['file']);
                 $i++;
             }
             $YAML_arr['title'] = $images_arr[0]['title'];
             $YAML_arr['cover'] = $images_arr[0]['image'];
             $YAML_arr['first_time'] = $times[0]['time'];
             $YAML_arr['last_time'] = $times[$i - 1]['time'];
             $YAML_arr['images'] = $images_arr;
             $slug = Slug::make($images_arr[0]['flickr_id']);
             $file = $times[0]['date'] . "-" . $times[0]['time'] . "-" . $slug . ".md";
             if (!File::exists($yaml_path . "collections/" . $file)) {
                 File::put($yaml_path . "collections/" . $file, YAML::dump($YAML_arr) . '---' . "\n");
                 foreach ($times as $item) {
                     $arhive_file = $archive_file = preg_replace('"\\.md$"', '.collection', $item['file']);
                     if (File::exists($yaml_path . $item['file'])) {
                         rename($yaml_path . $item['file'], $yaml_path . $archive_file);
                     }
                 }
             }
         }
     }
     return true;
 }
Пример #27
0
 public function update($object_name, $instance_id, $linked_id = false)
 {
     $object = DB::table(DB_OBJECTS)->where('name', $object_name)->first();
     $fields = DB::table(DB_FIELDS)->where('object_id', $object->id)->where('visibility', '<>', 'hidden')->get();
     //metadata
     $updates = array('updated_at' => new DateTime(), 'updated_by' => Auth::user()->id);
     //run loop through the fields
     foreach ($fields as $field) {
         if ($field->type == 'checkboxes') {
             # Figure out schema
             $object_column = self::getKey($object->name);
             $remote_column = self::getKey($field->related_object_id);
             # Clear old values
             DB::table($field->name)->where($object_column, $instance_id)->delete();
             # Loop through and save all the checkboxes
             if (Input::has($field->name)) {
                 foreach (Input::get($field->name) as $related_id) {
                     DB::table($field->name)->insert(array($object_column => $instance_id, $remote_column => $related_id));
                 }
             }
         } elseif ($field->type == 'images') {
             # Unset any old file associations (will get cleaned up after this loop)
             DB::table(DB_FILES)->where('field_id', $field->id)->where('instance_id', $instance_id)->update(array('instance_id' => null));
             # Create new associations
             $file_ids = explode(',', Input::get($field->name));
             $precedence = 0;
             foreach ($file_ids as $file_id) {
                 DB::table(DB_FILES)->where('id', $file_id)->update(array('instance_id' => $instance_id, 'precedence' => ++$precedence));
             }
         } else {
             if ($field->type == 'image') {
                 # Unset any old file associations (will get cleaned up after this loop)
                 DB::table(DB_FILES)->where('field_id', $field->id)->where('instance_id', $instance_id)->update(array('instance_id' => null));
                 # Capture the uploaded file by setting the reverse-lookup
                 DB::table(DB_FILES)->where('id', Input::get($field->name))->update(array('instance_id' => $instance_id));
             }
             $updates[$field->name] = self::sanitize($field);
         }
     }
     //slug
     if (!empty($object->url)) {
         $uniques = DB::table($object->name)->where('id', '<>', $instance_id)->lists('slug');
         $updates['slug'] = Slug::make(Input::get('slug'), $uniques);
     }
     /* //todo manage a redirect table if client demand warrants it
     		$old_slug = DB::table($object->name)->find($instance_id)->pluck('slug');
     		if ($updates['slug'] != $old_slug) {
     		}*/
     //run update
     DB::table($object->name)->where('id', $instance_id)->update($updates);
     //clean up abandoned files
     FileController::cleanup();
     //update object meta
     DB::table(DB_OBJECTS)->where('id', $object->id)->update(['count' => DB::table($object->name)->whereNull('deleted_at')->count(), 'updated_at' => new DateTime(), 'updated_by' => Auth::user()->id]);
     return Redirect::to(Input::get('return_to'));
 }