Example #1
0
function substr_text_only($string, $limit, $end = '...')
{
    $with_html_count = strlen($string);
    $without_html_count = strlen(strip_tags($string));
    $html_tags_length = $with_html_count - $without_html_count;
    return str_limit($string, $limit + $html_tags_length, $end);
}
 /**
  * Processes displaying the data to the grid
  *
  * @return DataGrid
  * @throws \Stevebauman\LogReader\Exceptions\UnableToRetrieveLogFilesException
  */
 public function grid()
 {
     $columns = ['id', 'level', 'date', 'header'];
     $settings = ['sort' => 'date', 'direction' => 'desc', 'pdf_view' => 'pdf'];
     $transformer = function ($element) {
         $element['level'] = $this->levelToLabel($element['level']);
         $element['show_url'] = route('admin.logs.show', array($element['id']));
         $element['header'] = str_limit($element['header']);
         return $element;
     };
     $reader = $this->reader;
     $filters = request()->input('filters');
     if (is_array($filters)) {
         /*
          * If an include_read filter is toggled, make sure
          * we toggle it on the log reader
          */
         foreach ($filters as $filter) {
             if (array_key_exists('include_read', $filter)) {
                 $reader->includeRead();
             }
         }
     }
     return datagrid($reader->get(), $columns, $settings, $transformer);
 }
Example #3
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     //handel the request
     $validator = Validator::make($request->all(), ['title' => 'required|unique:posts|max:67', 'image' => 'required|image|mimes:jpeg,png|max:5000']);
     if ($validator->fails()) {
         return redirect('seodashboard/posts/create')->withErrors($validator)->withInput();
     }
     $post = new Post();
     $post->title = $request->input('title');
     $post->content = $request->input('content');
     $post->published = $request->input('status');
     $post->excrypt = str_limit($request->input('excrypt'), 155);
     $tags = $request->input('tags');
     $categories = $request->input('categories');
     $tags = $this->ConvertTagsToList($tags);
     //save image path in database
     if ($request->hasFile('image')) {
         $destinationPath = 'images';
         $file = $request->file('image');
         $fileName = $file->getClientOriginalName();
         $file->move($destinationPath, $fileName);
         $post->image = $fileName;
     }
     $post->save();
     $post->tags()->attach($tags);
     $post->categories()->attach($categories);
     return redirect('seodashboard/posts');
 }
Example #4
0
 public function updateDescription()
 {
     if ($this->content == null) {
         return;
     }
     $this->description = str_limit(strip_tags($this->content), 200);
 }
Example #5
0
    public function getIncidents()
    {
        $incidents = ITP::select(['ID', 'Title', 'ReportingOrg', 'ImpactDescription', 'BriefDescription', 'IncidentLevel', 'Date', 'Section', 'IncidentOwner', 'Engineer', 'IncidentStatus']);
        $datatables = Datatables::of($incidents)->editColumn('BriefDescription', function ($incident) {
            return '
					<div class="text-semibold"><a href="./incident/' . $incident->ID . '/edit">' . str_limit($incident->Title, 40) . '</a></div>
                    <div class="text-muted">' . str_limit($incident->BriefDescription, 80) . '</div>
				';
        })->removeColumn('Title');
        if ($months = $datatables->request->get('months')) {
            $datatables->where(function ($query) use($months) {
                foreach ($months as $month) {
                    $query->orWhereRaw('MONTH(Date) = ' . $month);
                }
            });
        }
        if ($quarters = $datatables->request->get('quarters')) {
            $datatables->where(function ($query) use($quarters) {
                foreach ($quarters as $quarter) {
                    $query->orWhereRaw('MONTH(Date) = ' . $quarter);
                }
            });
        }
        if ($years = $datatables->request->get('years')) {
            $datatables->where(function ($query) use($years) {
                foreach ($years as $year) {
                    $query->orWhereRaw('YEAR(Date) = ' . $year);
                }
            });
        }
        return $datatables->make(true);
    }
Example #6
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $weixin = $request->session()->get('wechat.oauth_user');
     // 不接受无信用的凭证
     if (empty($weixin['id']) || strlen($weixin['id']) !== 28) {
         return abort(405);
     }
     // 生成一个随机的userKEY用于会话验证
     // 将该session的过期时间设置为比access_token
     // 的refresh时长多10s,一旦access_token刷新,
     // userKEY的值会重新计算并存储
     $token = $weixin['token'];
     $refresh = $token['refresh_token'];
     $expires = $token['expires_in'];
     // 假设用户数据已经存在于数据库中
     $user = Weixin_User::getFullyUserInfoWithOpenID($token['openid']);
     if (empty($user)) {
         $user = Weixin_User::storeNewUserInfo(new Weixin_User(), $weixin->toArray());
     }
     $user_id = $user->user_id;
     $key = 'jk_session:' . $user_id . ':userKEY';
     // 存储当前会话消息
     $request->session()->put('jukebox_user', $user_id);
     // 计算并存储userKEY
     if (!\PRedis::command('get', [$key])) {
         \PRedis::command('setex', [$key, intval($expires) + 10, str_limit($refresh, 5) . str_random(1)]);
     }
     return $next($request);
 }
Example #7
0
 public function store($data, $type = null)
 {
     $this->user_id = Auth::id();
     $this->question_id = $data['question'];
     $this->slug = Tools::slug($data['title']);
     $this->title = $data['title'];
     $this->type = $data['post_type'];
     $this->selected_option = $data['option'];
     switch ($type) {
         case 'text':
             $this->content = Purifier::clean($data['content']);
             $description = $data['content'];
             break;
         case 'link':
         case 'video':
         case 'vine':
             $this->content = Purifier::clean($data['link'], 'noHtml');
             $description = $data['description'];
             break;
         case 'audio':
         case 'photo':
             $file = Input::file('post_file');
             $this->post_file_ext = $file->getClientOriginalExtension();
             $this->post_file = $this->savePostFile($file, $type, Auth::id());
             $description = $data['content'];
             break;
     }
     $this->description = str_limit(Purifier::clean($description, 'noHtml'), 255, '');
     $this->save();
     return ['id' => $this->id, 'slug' => $this->slug];
 }
 function __construct()
 {
     View::share('latestActivePosts', (new LatestActivePosts())->get());
     $this->meta = new Meta();
     $this->meta->set(['title' => 'Wordpress Killed Me - Your place to rant about Wordpress', 'description' => 'Trouble with Wordpress? Here you are at the right place to scream it out to the world.', 'keywords' => ['wordpress', 'cms', 'only for blogs', 'hate', 'rant', 'fail'], 'image' => 'http://wordpresskilled.me/img/hp-image.png', 'og' => ['site_name' => 'Wordpress Killed Me', 'title' => 'Wordpress Killed Me - Your place to rant about Wordpress', 'description' => 'Trouble with Wordpress? Here you are at the right place to scream it out to the world.', 'keywords' => ['wordpress', 'cms', 'only for blogs', 'hate', 'rant', 'fail'], 'image' => 'http://wordpresskilled.me/img/hp-image.png'], 'twitter' => ['card' => 'summary', 'site' => '@wpkilledme', 'title' => 'Wordpress Killed Me - Your place to rant about Wordpress', 'description' => str_limit('Trouble with Wordpress? Here you are at the right place to scream it out to the world.', 180), 'image' => 'http://wordpresskilled.me/img/twitter-image.png']]);
     View::share('meta', $this->meta);
 }
Example #9
0
function description_trim($description, $limit = 500, $end = '...')
{
    $description = strip_tags(str_limit($description, $limit, $end));
    $description = str_replace("  ", "", $description);
    $description = str_replace("\n", "", $description);
    return $description;
}
Example #10
0
 public function onSaving(Topic $topic)
 {
     $topic->title = Purifier::clean($topic->title, 'title');
     $topic->body_original = Purifier::clean(trim($topic->body), 'body');
     $topic->body = app('markdown')->text($topic->body_original);
     $topic->excerpt = str_limit(trim(preg_replace('/\\s+/', ' ', strip_tags($topic->body))), 200);
 }
Example #11
0
 public function buildFileName($invoice = false)
 {
     $key = $invoice ? 'invoice' : 'paper';
     if ($this->files[$key . '_name']) {
         #if already build
         return $this->files[$key . '_name'];
     }
     if (!request()->file($this->files[$key])) {
         return '';
     }
     $ext = request()->file($this->files[$key])->getClientOriginalExtension();
     $name = request()->file($this->files[$key])->getClientOriginalName();
     $name = str_replace('.' . $ext, '', $name);
     #check if name is bigger then 90 chars and cut + remove ... from string
     $name = str_limit($name, 90);
     if (substr($name, -1) == '.') {
         $name = substr($name, 0, -3);
     }
     $userName = explode(' ', auth()->user()->name);
     $name .= '_' . $userName[0][0] . $userName[1][0];
     #get user letters
     if ($invoice) {
         $name .= 'I';
         #add i before number
     }
     $name .= rand(1, 999);
     $name .= '.' . $ext;
     #add extension
     if (File::exists(self::$path . $name)) {
         $name = $this->buildFileName($invoice);
     }
     $this->files[$key . '_name'] = $name;
     return $name;
 }
Example #12
0
 public function postUpdate(Requests\Admin\ArticleRequest $request, $type, $act, $id = 0)
 {
     $article = new Article();
     if ($act == 'edit') {
         $article = Article::find($id);
     }
     $article->user_id = \Auth::id();
     $article->node_id = $request->input('node');
     $article->title = $request->input('title');
     $article->seo_title = $request->input('seo_title');
     $article->description = $request->input('description');
     $article->keywords = $request->input('keywords');
     $article->type = $request->input('type');
     $article->image = $request->input('get_image');
     $article->outline = $request->input('outline') ?: str_limit(strip_tags($request->input('content')));
     $article->content = $request->input('content');
     $article->order = $request->input('order');
     $article->views = $request->input('views');
     $article->hot = $request->input('hot') ? 1 : 0;
     $article->status = $request->input('status') ? 1 : 0;
     $article->recommend = $request->input('recommend') ? 1 : 0;
     $article->show_index = $request->input('show_index') ? 1 : 0;
     if ($article->save()) {
         $info = ['from' => 'update', 'status' => 'success'];
         j4flash($info);
         return redirect('admin/article/index/' . $type);
     } else {
         return redirect()->back()->withErrors(['err' => lang('submit failed')])->withInput();
     }
 }
Example #13
0
 public function createPost(Requests\Bins\CreateBin $request)
 {
     $description = $request->has('description') && trim($request->input('description')) != '' ? $request->input('description') : null;
     $bin = Bin::create(['user_id' => auth()->user()->getAuthIdentifier(), 'title' => $request->input('title'), 'description' => $description, 'visibility' => $request->input('visibility')]);
     if ($bin->isPublic()) {
         $status = 'Bin: #laravel ' . $bin->url() . ' ' . $bin->title;
         Twitter::postTweet(['status' => str_limit($status, 135), 'format' => 'json']);
         $bin->tweeted = true;
         $bin->save();
     }
     $bin->versions()->sync($request->input('versions'));
     $files = [];
     foreach ($request->input('name') as $key => $value) {
         $files[$key]['name'] = $value;
     }
     foreach ($request->input('language') as $key => $value) {
         $files[$key]['language'] = $value;
     }
     foreach ($request->input('code') as $key => $value) {
         $files[$key]['code'] = $value;
     }
     foreach ($files as $item) {
         $type = Type::where('css_class', $item['language'])->first();
         $bin->snippets()->create(['type_id' => $type->id, 'name' => $item['name'], 'code' => $item['code']]);
     }
     session()->flash('success', 'Bin created successfully!');
     return redirect()->route('bin.code', $bin->getRouteKey());
 }
Example #14
0
 /**
  * @param string $title
  * @param string $tinyIcon
  * @param string $largeIcon
  * @param string $locationName
  */
 public function __construct($title, $tinyIcon, $largeIcon, $locationName)
 {
     $this->title = $title;
     $this->tinyIcon = $tinyIcon;
     $this->largeIcon = $largeIcon;
     $this->locationName = str_limit($locationName, 256);
 }
Example #15
0
 public function getSummaryAttribute()
 {
     if (empty($this->summary)) {
         return str_limit(strip_tags($this->content), 1200);
     }
     return;
 }
Example #16
0
 public function index($id)
 {
     $post = $this->postRepository->findById($id);
     if (!$post or !$post->present()->canView()) {
         if (\Request::ajax()) {
             return '';
         }
         return $this->theme->section('error-page');
     }
     $this->theme->share('site_description', $post->text ? \Str::limit($post->text, 100) : \Config::get('site_description'));
     $this->theme->share('ogUrl', \URL::route('post-page', ['id' => $post->id]));
     if ($post->text) {
         $this->theme->share('ogTitle', \Str::limit($post->text, 100));
     }
     if ($post->present()->hasValidImage()) {
         foreach ($post->present()->images() as $image) {
             $this->theme->share('ogImage', \Image::url($image, 600));
         }
     }
     $ad = empty($post->text) ? trans('post.post') : str_limit($post->text, 60);
     $design = [];
     if ($post->page_id) {
         $design = $post->page->present()->readDesign();
     } elseif ($post->community_id) {
         $design = $post->community->present()->readDesign();
     } else {
         $design = $post->user->present()->readDesign();
     }
     return $this->render('post.page', ['post' => $post], ['title' => $this->setTitle($ad), 'design' => $design]);
 }
Example #17
0
 /**
  * The pages short content
  *
  * @return mixed null|string
  */
 public function getExcerptAttribute()
 {
     if (array_has($this->attributes, 'body')) {
         return str_limit(strip_tags($this->attributes['body']), 200);
     }
     return null;
 }
 /**
  * Update podcast items
  *
  * @return mixed
  */
 public function handle()
 {
     $uniquePodcasts = DB::table('podcasts')->select('id', 'feed_url', 'machine_name')->groupBy('machine_name')->get();
     foreach ($uniquePodcasts as $podcast) {
         $usersSubscribedToThisPodcast = DB::table('podcasts')->select('user_id', 'id as podcast_id')->where('machine_name', '=', $podcast->machine_name)->get();
         $items = Feeds::make($podcast->feed_url)->get_items();
         // Calculate 48 hours ago
         $yesterday = time() - 24 * 2 * 60 * 60;
         foreach ($items as $item) {
             $itemPubDate = $item->get_date();
             if ($item->get_date('U') > $yesterday) {
                 // new items
                 foreach ($usersSubscribedToThisPodcast as $subscriber) {
                     $podcastItemsCount = DB::table('items')->select('user_id', 'title', 'podcast_id')->where('title', '=', strip_tags($item->get_title()))->where('user_id', '=', $subscriber->user_id)->where('podcast_id', '=', $subscriber->podcast_id)->count();
                     // if this item is not already in the DB
                     if ($podcastItemsCount == 0) {
                         Item::create(['user_id' => $subscriber->user_id, 'title' => strip_tags($item->get_title()), 'description' => strip_tags(str_limit($item->get_description(), 100)), 'published_at' => $item->get_date('Y-m-d'), 'url' => $item->get_permalink(), 'audio_url' => $item->get_enclosure()->get_link(), 'podcast_id' => $subscriber->podcast_id]);
                     }
                 }
             } else {
                 break;
             }
         }
     }
 }
Example #19
0
 public function publishDraftCreate($article_id)
 {
     $input = Input::all();
     $validator = Validator::make($input, DraftArticle::$rules, DraftArticle::$validatorMessages);
     if ($validator->passes()) {
         $model = DraftArticle::where('id', '=', $article_id)->first();
         $model->title = Input::get('title');
         $model->digest = str_limit(strip_tags(Input::get('content')), 30, '...');
         $pictures = $model->pictures;
         if (!$pictures->isEmpty()) {
             $model->cover = $pictures->first()->path;
         } else {
             $model->cover = "/static/img/nopic.png";
         }
         $model->status = '002';
         $model->content = Input::get('content');
         if ($model->save()) {
             $response['success'] = true;
         } else {
             $response['success'] = false;
             $response['message'] = '发布失败。';
         }
     } else {
         $response['success'] = false;
         $response['message'] = $validator->messages()->first();
     }
     return Response::json($response);
 }
Example #20
0
 /**
  * Return an array with character information.
  * This includes the key info as well as the
  * extended information such as type/expiry etc.
  *
  * @return array
  */
 public function all_with_info()
 {
     $response = [];
     foreach (EveApiKeyModel::all() as $key) {
         $response[$key->key_id] = ['enabled' => $key->enabled, 'user_id' => $key->user_id, 'key_id' => $key->key_id, 'v_code' => str_limit($key->v_code, 15), 'access_mask' => $key->info ? $key->info->accessMask : null, 'type' => $key->info ? $key->info->type : null, 'expires' => $key->info ? $key->info->expires : null, 'last_error' => $key->last_error, 'characters' => count($key->characters) > 0 ? implode(', ', $key->characters->lists('characterName')->all()) : null];
     }
     return $response;
 }
Example #21
0
 /**
  * @param string $path
  *
  * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
  *
  * @return View|Response
  */
 public function pageAction(string $path)
 {
     $slug = str_limit($path, 63, '');
     if ($this->staticViewExists($slug)) {
         return $this->makeStaticView($slug);
     }
     throw new NotFoundHttpException();
 }
Example #22
0
 /**
  * @param $rawFileName
  * @return string
  */
 private static function renameFile($rawFileName, $extensionPart)
 {
     $randomStr = str_random(6);
     $namePart = strstr($rawFileName, $extensionPart, true);
     // Concat file name
     $fileName = str_slug($namePart) . '-' . $randomStr . '.' . $extensionPart;
     return str_limit($fileName, 254, '');
 }
Example #23
0
 public function body()
 {
     $body = Purifier::clean($this->body);
     $body1 = str_replace('<p>', '', $body);
     $body2 = str_replace('</p>', '', $body1);
     return str_limit($body2, 300, '...');
     return $body2;
 }
 /**
  * Display the specified resource.
  *
  * @param $post
  * @return Response
  */
 public function show($post = null)
 {
     if (!$post) {
         abort(404);
     }
     $this->meta->set(['title' => $post->title . ' | Wordpress Killed Me', 'description' => $post->text, 'og' => ['title' => $post->title . ' | Wordpress Killed Me', 'description' => $post->text], 'twitter' => ['title' => $post->title . ' | Wordpress Killed Me', 'description' => str_limit($post->text, 180)]]);
     return view('post.show', ['post' => $post]);
 }
Example #25
0
 /**
  * Returns a new work request grid.
  *
  * @return \Cartalyst\DataGrid\DataGrid
  */
 public function grid()
 {
     $columns = ['id', 'subject', 'best_time', 'created_at'];
     $settings = ['sort' => 'created_at', 'direction' => 'desc', 'threshold' => 10, 'throttle' => 11];
     $transformer = function (WorkRequest $workRequest) {
         return ['id' => $workRequest->id, 'subject' => str_limit($workRequest->subject), 'best_time' => $workRequest->best_time, 'created_at' => $workRequest->created_at, 'view_url' => route('maintenance.work-requests.show', [$workRequest->id])];
     };
     return $this->workRequest->grid($columns, $settings, $transformer);
 }
 public function getStrRolesAttribute()
 {
     $roles = $this->roles()->lists('acronym');
     $trim_roles = [];
     foreach ($roles as $role) {
         $trim_roles[] = str_limit($role, 3, '');
     }
     return implode(',', $trim_roles);
 }
Example #27
0
 public function tweetBin(Bin $bin)
 {
     $status = 'Bin: #laravel ' . $bin->url() . ' ' . $bin->title;
     Twitter::postTweet(['status' => str_limit($status, 135), 'format' => 'json']);
     $bin->tweeted = true;
     $bin->save();
     session()->flash('success', 'Bin has successfully been tweeted!');
     return redirect()->back();
 }
Example #28
0
 /**
  * Returns a new work order grid.
  *
  * @return \Cartalyst\DataGrid\DataGrid
  */
 public function grid()
 {
     $columns = ['id', 'priority_id', 'status_id', 'created_at', 'user_id', 'subject'];
     $settings = ['sort' => 'created_at', 'direction' => 'desc', 'threshold' => 10, 'throttle' => 11];
     $transformer = function (WorkOrder $workOrder) {
         return ['id' => $workOrder->id, 'created_at' => $workOrder->created_at, 'subject' => str_limit($workOrder->subject), 'view_url' => route('maintenance.work-orders.show', [$workOrder->id]), 'created_by' => $workOrder->user->full_name, 'status' => $workOrder->viewer()->lblStatus(), 'priority' => $workOrder->viewer()->lblPriority()];
     };
     return $this->workOrder->grid($columns, $settings, $transformer);
 }
Example #29
0
 public function index(Request $request)
 {
     $users = $this->userRepository->listaUser($request);
     return Datatables::of($users)->addColumn('img', function (User $user) {
         return $user->imagenes->map(function ($imagenes) {
             return str_limit($imagenes->img, 30, '...');
         })->implode('<br>');
     })->make(true);
 }
 /**
  * Handle the command.
  *
  * @param  StoreNewSnippetCommand  $command
  * @return void
  */
 public function handle(StoreNewSnippetCommand $command)
 {
     if (empty($command->title)) {
         $command->title = str_limit($command->body, 10);
     }
     $snippet = Snippet::create(['user_id' => $command->user_id, 'title' => $command->title, 'body' => $command->body, 'mode' => $command->mode, 'password' => $command->password]);
     SnippetSlug::create(['snippet_id' => $snippet->id, 'slug' => $snippet]);
     return $snippet;
 }