예제 #1
0
 public function setSlugAttribute($value)
 {
     $slug = \Jarboe::urlify($value);
     $slugs = $this->where('parent_id', $this->parent_id)->where('id', '<>', $this->id)->whereRaw("slug REGEXP '^{$slug}(-[0-9]*)?\$'")->lists('slug');
     $slugCount = '';
     if ($slugs) {
         $slugCount = 0;
         foreach ($slugs as $existedSlug) {
             preg_match('~(\\d+)$~', $existedSlug, $matches);
             if (isset($matches[1])) {
                 $slugCount = $slugCount > $matches[1] ? $slugCount : $matches[1];
             }
         }
         $slugCount++;
     }
     $slug = $slugCount ? $slug . '-' . $slugCount : $slug;
     $this->attributes['slug'] = $slug;
 }
예제 #2
0
 protected function handleFileUpload()
 {
     // FIXME:
     $file = Input::file('file');
     if ($this->controller->hasCustomHandlerMethod('onFileUpload')) {
         $res = $this->controller->getCustomHandler()->onFileUpload($file);
         if ($res) {
             return $res;
         }
     }
     $extension = $file->getClientOriginalExtension();
     $fileName = time() . '_' . \Jarboe::urlify($file->getClientOriginalName()) . '.' . $extension;
     $definitionName = $this->controller->getOption('def_name');
     $prefixPath = 'storage/tb-' . $definitionName . '/';
     $postfixPath = date('Y') . '/' . date('m') . '/' . date('d') . '/';
     $destinationPath = $prefixPath . $postfixPath;
     $status = $file->move($destinationPath, $fileName);
     $data = array('status' => $status, 'link' => URL::to($destinationPath . $fileName), 'short_link' => $destinationPath . $fileName);
     return Response::json($data);
 }
예제 #3
0
 function urlify($string)
 {
     return Jarboe::urlify($string);
 }
예제 #4
0
 public function getSlug()
 {
     return Jarboe::urlify(strip_tags($this->title));
 }