예제 #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 getStatic($ident, $locale, $namespace)
 {
     if ($this->hasTranslate($ident, $locale, $namespace)) {
         return $this->translates[$locale][$namespace][$ident];
     }
     $translateFrom = \Config::get('builder::translate.auto_translate_from');
     $adminUriTemplate = ltrim(\Config::get('builder::admin.uri') . '/*', '/');
     $adminDashboardUriTemplate = ltrim(\Config::get('builder::admin.uri'), '/');
     if (\Request::is($adminUriTemplate) || \Request::is($adminDashboardUriTemplate)) {
         $translateFrom = 'ru';
     }
     if ($this->isAutoTranslate($locale)) {
         // HACK: ua to uk for yandex translate api
         $yandexTranslateFrom = $translateFrom == 'ua' ? 'uk' : $translateFrom;
         $yandexTranslateTo = $locale;
         if (\Request::is($adminUriTemplate) || \Request::is($adminDashboardUriTemplate)) {
             $yandexTranslateTo = $yandexTranslateTo == 'ua' ? 'uk' : $yandexTranslateTo;
         }
         // HACK: for admin-panel translates
         $language = $yandexTranslateFrom . '-' . $yandexTranslateTo;
         $res = \Jarboe::translate($ident, $language);
         $id = \DB::table('translations')->where('key', $ident)->where('namespace', $namespace)->pluck('id');
         if ($id) {
             \DB::table('translations')->where('id', $id)->update(array('value_' . $translateFrom => $ident, 'value_' . $locale => $res));
         } else {
             \DB::table('translations')->insert(array('namespace' => $namespace, 'key' => $ident, 'value_' . $translateFrom => $ident, 'value_' . $locale => $res));
         }
         \Cache::forget('translations');
         return $res;
     }
     // FIXME: possible bad logic
     $id = \DB::table('translations')->where('key', $ident)->where('namespace', $namespace)->pluck('id');
     if (!$id) {
         \DB::table('translations')->insert(array('namespace' => $namespace, 'key' => $ident, 'value_' . $translateFrom => $ident));
         \Cache::forget('translations');
     }
     return false;
 }
예제 #3
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);
 }
예제 #4
0
<?php

//
Route::filter('check_permissions', function () {
    if (Request::isMethod('get')) {
        Jarboe::checkNavigationPermissions();
    }
});
Route::filter('auth_admin', function () {
    if (!Sentry::check()) {
        if (Request::ajax()) {
            return Response::make('Unauthorized', 401);
        } else {
            return Redirect::guest('login');
        }
    } else {
        if (!Sentry::getUser()->isSuperUser()) {
            // FIXME:
            $admin = Sentry::findGroupByName('admin');
            if (!Sentry::getUser()->inGroup($admin)) {
                if (Request::ajax()) {
                    return Response::make('Unauthorized', 401);
                } else {
                    return Redirect::guest('/');
                }
            }
        }
    }
});
예제 #5
0
 function urlify($string)
 {
     return Jarboe::urlify($string);
 }
예제 #6
0
 public function getSlug()
 {
     return Jarboe::urlify(strip_tags($this->title));
 }
 public function handleTree()
 {
     $controller = Jarboe::tree();
     return $controller->process();
 }