/** * Retrieve the article excerpt. * * @param integer $words 100 * @param string $end ... * @return string */ public function excerpt($words = 100, $end = '...') { if (!$this->attributes['excerpt']) { return Str::words(strip_tags($this->content()), $words, $end); } return strip_tags($this->attributes['excerpt']); }
public static function slugify($string, $separator = '-', $limit = 8) { $string = strtolower($string); $string = str_replace('', ' ', $string); $string = \Illuminate\Support\Str::words($string, $limit, ''); $string = mb_ereg_replace('([^ا-ی۰-۹a-z0-9]|-)+', $separator, $string); $string = strtolower($string); return trim($string, $separator); }
/** * Returns an excerpt of the page body * * @param int $words * @return string * @todo Remove HTML except b,i,code tags. */ public function excerpt($words = 50) { $body = $this->body; // If a more tag was found we'll take the first part. if (strpos($body, '<!--more-->')) { $parts = explode('<!--more-->', $body); return $parts[0]; } return Str::words($this->body, $words); }
function extend_title($what, $before = true, $divider = '-') { $divider = HTML::nbsp() . $divider . HTML::nbsp(); if (!is_array($what)) { $what = [$what]; } // Ensure each title element is no greater than a certain number of words. $what = array_map(function ($element) { return Str::words($element, 5); }, $what); $what = implode($divider, $what); return $before ? $what . $divider : $divider . $what; }
function render($instance, $key, $options) { if ($instance->{$key}) { $limit = 100; if ($options && intval($options)) { $limit = intval($options); } $str = sharp_markdown($instance->{$key}); $strW = Str::words($str, $limit, ''); $append = strlen($str) != strlen($strW) ? '...' : ''; return $this->replaceParagraphsByBr($this->closeTags($strW)) . $append; } return null; }
/** * Limit the number of words in a string **/ public function words($words = 100, $end = '...') { $this->value = Str::words($this->value, $words, $end); return $this; }
/** * Crée un RSS a partir du flux (fb ou non) et le store * @param $feed : feed got from the database * @return string * @throws \Facebook\FacebookRequestException */ public function getRSS($feed) { //get directly the rss in the storage if exists if (Storage::exists($this->rssDirectory . 'feed_' . $feed->id . '.xml')) { return Storage::get($this->rssDirectory . 'feed_' . $feed->id . '.xml'); } //if it's a facebook page : convert to rss if ($feed->is_facebook) { $url = parse_url($feed->url); $page = $url['path']; $application = array('app_id' => getenv('FACEBOOK_APP_ID'), 'app_secret' => getenv('FACEBOOK_APP_SECRET')); FacebookSession::setDefaultApplication($application['app_id'], $application['app_secret']); $session = new FacebookSession($application['app_id'] . '|' . $application['app_secret']); $request = new FacebookRequest($session, 'GET', '/' . $page . '/feed'); $response = $request->execute(); $graphObject = $response->getGraphObject(); $facebook_feed = $graphObject->asArray(); $xml = ' <?xml version="1.0"?> <rss version="2.0"> <channel> <title>RSS ' . $feed->name . '</title> <description></description> '; foreach ($facebook_feed['data'] as $entry) { //récupere l'id de la page et l'id du post $ids = explode('_', $entry->id); if ($entry->from->id == $ids[0] && isset($entry->message)) { //si il y a un message et que la page est auteur $title = Str::words($entry->message, 20, '...'); //limit mots $pubDate = date("D, d M Y H:i:s T", strtotime($entry->created_time)); $item = ' <item> <title><![CDATA[' . $title . ']]></title> <link>http://www.facebook.com/' . $ids[0] . '/posts/' . $ids[1] . '</link> <pubDate>' . date("r", strtotime($pubDate)) . '</pubDate> </item>'; $xml .= $item; } } $xml .= '</channel></rss>'; } else { $context = stream_context_create(array('http' => array('user_agent' => 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11'))); $xml = @file_get_contents($feed->url, FALSE, $context); } $xml = trim($xml); // if the file is not xml return false $xml_is_valid = @simplexml_load_string($xml); if (!$xml_is_valid) { throw new \Exception('invalid xml'); } Storage::put($this->rssDirectory . 'feed_' . $feed->id . '.xml', $xml); return $xml; }
$user = $factory->raw(App\Models\User::class); return array_merge($user, ['userType' => App\Models\User::USER_TYPE_ADMIN]); }); $factory->define(App\Models\UserCredential::class, function ($faker) { return ['password' => 'password']; }); $factory->define(App\Models\SocialLogin::class, function ($faker) { return ['provider' => $faker->randomElement(['facebook', 'google', 'twitter']), 'token' => $faker->sha256]; }); $factory->define(App\Models\SecondTestEntity::class, function ($faker) { return ['entity_id' => $faker->uuid, 'check_entity_id' => $faker->uuid, 'value' => $faker->word]; }); $factory->defineAs(App\Models\TestEntity::class, 'custom', function ($faker) use($factory) { $testEntity = $factory->raw(App\Models\TestEntity::class); return array_merge($testEntity, ['varchar' => 'custom']); }); $factory->define(App\Models\AuthToken::class, function () use($factory) { $jwtAuth = Illuminate\Support\Facades\App::make('Tymon\\JWTAuth\\JWTAuth'); $user = $factory->make(\App\Models\User::class); $token = $jwtAuth->fromUser($user); return ['token' => $token]; }); $factory->define(App\Models\ArticlePermalink::class, function (\Faker\Generator $faker) { return ['permalink' => $faker->unique()->slug]; }); $factory->define(App\Models\ArticleMeta::class, function (\Faker\Generator $faker) { return ['meta_name' => $faker->unique()->slug, 'meta_content' => $faker->slug, 'meta_property' => $faker->slug]; }); $factory->define(App\Models\Article::class, function (\Faker\Generator $faker) { return ['article_id' => $faker->uuid, 'title' => $faker->sentence, 'status' => $faker->randomElement(App\Models\Article::$statuses), 'content' => $content = implode("\n\n", $faker->paragraphs(3)), 'excerpt' => Str::words($content, 30, ''), 'primary_image' => $faker->imageUrl(500, 500, 'food'), 'permalink' => $faker->boolean(90) ? $faker->unique()->slug : null, 'first_published' => $faker->boolean(90) ? $faker->dateTimeThisDecade()->format('Y-m-d H:i:s') : null]; });
public function getExcerpt($words = 60) { return Str::words(strip_tags($this->content), $words); }
public static function makeExcerpt($str, $words = 100, $end = '...') { return Str::words(strip_tags($str), $words, $end); }
public function bodySummary() { $summary = Str::words($this->getWrappedObject()->body, 50); return App::make('Lio\\Markdown\\HtmlMarkdownConvertor')->convertMarkdownToHtml($summary); }
public function getShortAttribute() { return Str::words($this->attributes['value'], 10); }
function recordDesc($first, $second, $words = 20) { return $first ? Str::words(strip_tags($first), $words) : Str::words(strip_tags($second), $words); }
use Faker\Generator; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Str; /** * User Factory */ $factory->define(User::class, function (Generator $faker) { return ['name' => $faker->name, 'email' => $faker->email, 'password' => Hash::make(str_random(10)), 'remember_token' => str_random(10), 'active' => 0]; }); /** * Post Factory */ $factory->define(Post::class, function (Generator $faker) { $post_title = $faker->sentence(4); $post_content = $faker->paragraphs(5, 1); return ['post_title' => $post_title, 'post_slug' => str_slug($post_title), 'post_excerpt' => Str::words($faker->realText(200), 20), 'post_content' => $post_content, 'post_type' => 'post', 'post_image' => $faker->imageUrl('1200', '600'), 'is_front_page' => 0]; }); $factory->defineAs(Post::class, 'page', function (Generator $faker) use($factory) { $post = $factory->raw(Post::class); return array_merge($post, ['post_type' => 'page']); }); $factory->defineAs(Post::class, 'front-page', function (Generator $faker) use($factory) { $post = $factory->raw(Post::class); return array_merge($post, ['post_type' => 'page', 'is_front_page' => 1]); }); /** * Comment Factory */ $factory->define(Comment::class, function (Generator $faker) { return ['post_id' => $faker->numberBetween(1, 15), 'comment_body' => $faker->sentences(5, true)]; });
/** * sanitize cell output if needed * * @param $string * @return mixed */ protected function sanitize($string) { return Str::words(nl2br(htmlspecialchars($string)), 30); }
/** * Limit the number of words in the string. * * @param int $words * @param string $end * @return static */ public function limitWords($words = 100, $end = '...') { return new static(Str::words($this->string, $words, $end)); }
/** * If there is no defined exerpt for the text, create it from the content * @param $excerpt * @return string */ public function getExcerptAttribute($excerpt) { if ($excerpt) { return $excerpt; //if it is already set, do nothing } return Str::words($this->content, self::defaultExcerptWordCount, ''); }
public function summary() { $html = new \Html2Text\Html2Text($this->body); return Str::words($html->getText(), 50); }
<i class="fa fa-map-marker"></i> <a class="alt" href="<?php echo act('event@search', ['location' => $event->location]); ?> "><?php echo $event->location; ?> </a> </p> {{--<p class="caption-price">Tickets from $49,99</p>--}} <?php if (!$compact) { ?> <p class="caption-text"><?php echo Str::words($event->description, 15, ' [...]'); ?> </p> <div class="caption-more"> <ul class="piped"> <?php foreach ($event->themes as $ev_theme) { ?> <li> <a href="<?php echo act('theme@events', $ev_theme->slug); ?> ">{{$ev_theme->name}}</a> </li> <?php
public function createRoom() { $input = Input::all(); $thread = Thread::create(['subject' => $input['subject']]); // Message $message = Message::create(['thread_id' => $thread->id, 'user_id' => Auth::user()->id, 'body' => $input['message']]); // Sender Participant::create(['thread_id' => $thread->id, 'user_id' => Auth::user()->id, 'last_read' => new Carbon()]); // Recipients if (Input::has('recipients')) { $thread->addParticipants($input['recipients']); } $data = array('room' => $thread->id, 'message' => array('body' => Str::words($message->body, 60), 'user_id' => Auth::user()->id)); event(new ChatRoomCreated($data)); return redirect(App::getLocale() . '/chat'); }
public function testStringStartsWords() { $str1 = 'Laravel is really awesome'; $str2 = Str::words($str1); $this->assertEquals($str2, 'Laravel is really awesome'); $str1 = 'Laravel is really awesome'; $str2 = Str::words($str1, 3); $this->assertEquals($str2, 'Laravel is really...'); $str1 = 'Laravel is really awesome'; $str2 = Str::words($str1, 2, '###'); $this->assertEquals($str2, 'Laravel is###'); }
/** * @param $value * @param int $words * @param string $end * @return string */ function str_words($value, $words = 100, $end = '...') { return Str::words($value, $words, $end); }
/** * Return model in Datatable ajax | Also search by ajax. * * @return mixed */ public function getData() { $model = $this->crud['model']; $columns = $this->crud['columns']; //Check if has a pivot column $pivots = array_pluck($this->crud['columns'], ['pivot']); $isPivot = array_search('true', $pivots); if ($isPivot != false) { $pivotField = $this->crud['columns'][$isPivot]; // dd($pivotField); $data = $model::select('*')->get(); //dd($columns); } else { $data = $model::select('*')->get(); } $datatable = Datatables::of($data); foreach ($columns as $column) { if (isset($column['type']) && $column['type'] == 'select_multiple') { $datatable->addColumn($column['name'], '')->editColumn($column['name'], function ($columnInfo) use($column) { $results = $columnInfo->{$column['entity']}()->getResults(); $html = '-'; if ($results && $results->count()) { $results_array = $results->lists($column['attribute'], 'id'); $html = implode(', ', $results_array->toArray()); } return $html; }); } elseif (isset($column['type']) && $column['type'] == 'select') { $datatable->addColumn($column['name'], '')->editColumn($column['name'], function ($columnInfo) use($column) { $html = '-'; if ($columnInfo->{$column['entity']}()->getResults()) { $html = $columnInfo->{$column['entity']}()->getResults()->{$column['attribute']}; } return $html; }); } elseif (isset($column['type']) && $column['type'] == 'model_function') { $datatable->addColumn($column['name'], '')->editColumn($column['name'], function ($columnInfo) use($column) { return $columnInfo->{$column['function_name']}(); }); } elseif (isset($column['type']) && $column['type'] == 'image') { $datatable->addColumn($column['name'], '')->editColumn($column['name'], function ($columnInfo) use($column) { return "<img src='" . asset($columnInfo->{$column['name']}) . "' width='50%' />"; }); } elseif (isset($column['type']) && $column['type'] == 'browse') { $datatable->addColumn($column['name'], '')->editColumn($column['name'], function ($columnInfo) use($column) { if (isset($column['browse']) && $column['browse'] != 'image') { return $columnInfo->content; } return "<img src='" . asset($columnInfo->{$column['name']}) . "' width='50%' />"; }); } elseif (isset($column['type']) && isset($column['pivot']) && $column['pivot'] == true) { $datatable->editColumn($column['name'], function ($columnInfo) use($column) { // dd($columnInfo); // dd($column); //["model"] $pivotModel = $this->crud['model']; $dataPivot = $column['model']::find($columnInfo[$column['entity']]); if ($dataPivot) { return $dataPivot->{$column}['attribute']; } }); } elseif (isset($column['type']) && $column['type'] == 'date') { $datatable->addColumn($column['name'], '')->editColumn($column['name'], function ($columnInfo) use($column) { if ($columnInfo->{$column['name']} != null) { $locale = isset($column['language']) ? $column['language'] : 'en'; $format = isset($column['format']) ? $column['format'] : 'Y-m-d'; Date::setLocale($locale); $date = Date::parse($columnInfo->{$column['name']}); return $date->format($format); } return ''; }); } else { if (array_search('content', $columns)) { $datatable->editColumn($column['name'], function ($columnInfo) use($column) { return strip_tags(Str::words($columnInfo->content, 50, '...')); }); } else { $datatable->editColumn($column['name'], function ($columnInfo) use($column) { if (trim($columnInfo->{$column['name']}) == '') { if (isset($this->crud['is_translate']) && $this->crud['is_translate'] == true) { if ($columnInfo->translate()) { $columnInfo->{$column['name']} = $columnInfo->{$column['name']}; } } } return str_limit(strip_tags($columnInfo->{$column['name']}), 80, '[...]'); }); } } } if (!(isset($crud['edit_permission']) && $crud['edit_permission'] === false && isset($crud['delete_permission']) && $crud['delete_permission'] === false)) { $datatable->addColumn('actions', '')->editColumn('actions', function ($column) { $html = ''; if (!(isset($crud['edit_permission']) && !$crud['edit_permission'])) { $html .= '<a href="' . url($this->crud['route']) . '/' . $column->id . '/edit" class="btn btn-xs btn-complete "><i class="fa fa-edit p-r-10"></i>' . _(trans('crud.edit')) . '</a>'; } if (!(isset($crud['delete_permission']) && !$crud['delete_permission'])) { $html .= '<a href="' . url($this->crud['route']) . '/' . $column->id . '" class="btn btn-xs btn-danger m-l-5" data-button-type="delete"><i class="fa fa-trash p-r-10 "></i>' . _(trans('crud.delete')) . '</a>'; } return $html; }); } return $datatable->make(true); }
public function postCustomerEdit(NewCustomerRequest $request, Customer $customer, CustomerProfile $profile, Payment $payment) { $id = $request->input('customer_id'); $this->customer = $customer->whereId((int) $id)->update(['firstname' => Str::title($request->input('firstname')), 'lastname' => Str::title($request->input('lastname')), 'email' => Str::lower($request->input('email')), 'phone' => $request->input('phone')]); $dob = explode('/', $request->input('dob')); $dob_piece = [$dob[2], $dob[1], $dob[0]]; $this->profile = $profile->where('customer_id', (int) $id)->update(['dob' => implode('-', $dob_piece), 'gender_id' => $request->input('gender'), 'state_id' => $request->input('state_of_origin'), 'hostel_address' => $request->input('hostel_address'), 'guardian_name' => Str::words($request->input('guardian_name')), 'guardian_phone' => $request->input('guardian_phone'), 'guardian_address' => $request->input('guardian_address')]); $this->payment = $payment->where('customer_id', (int) $id)->update(['account_balance' => $request->input('account_balance')]); if (!$this->customer && !$this->profile) { flash()->error('An error occurred, try updating the Customer again!'); } else { flash()->success('Customer Updated Successfully!'); } return redirect()->route('customer.list'); }
function recordDesc($first = '', $second = '', $words = 20, $title = '', $chars = 60) { $first = strip_tags($first); $second = strip_tags($second); if (!empty($title)) { if (strlen($title) > $chars) { $chars = strlen($title) - $chars; $words = $words - $chars; } return $first ? Str::limit($first, $words) : Str::limit($second, $words); } else { return $first ? Str::words($first, $words) : Str::words($second, $words); } }