public function value() { if ($this->entity->value === '0' || $this->entity->value === '1') { return $this->entity->value === '0' ? 'false' : 'true'; } return Str::limit($this->entity->value, 20); }
/** * @param $value * @return string */ public function getDescriptionAttribute($value) { if ($value == '') { return Str::limit(strip_tags($this->attributes['content']), 130, '...'); } return $value; }
public function index() { Str::limit('hello', 10); $data['posts'] = Post::getAll(); $data['slides'] = [(object) ['src' => 'assets/img/gallery/slider-img-1.jpg', 'alt' => 'Slider', 'href' => 'gallery-single.htm', 'name' => 'test1'], (object) ['src' => 'assets/img/gallery/slider-img-2.jpg', 'alt' => 'Slider', 'href' => 'gallery-single.htm', 'name' => 'test1'], (object) ['src' => 'assets/img/gallery/slider-img-2.jpg', 'alt' => 'Slider', 'href' => 'gallery-single.htm', 'name' => 'test1'], (object) ['src' => 'assets/img/gallery/slider-img-1.jpg', 'alt' => 'Slider', 'href' => 'gallery-single.htm', 'name' => 'test1']]; $data['post'] = Post::getLatest()->first(); return view('home.index', $data); }
/** * @param Currency $currency * * @return string */ public function getTransactionLink(Currency $currency) { if ($this->category == 'move') { return ''; } if ($currency->explorer) { return HTML::link(str_replace('%id', $this->txid, $currency->explorer), Str::limit($this->txid, 20), ['target' => '_blank']) . " <span class='fa fa-new-window'></span>"; } return HTML::link('#', Str::limit($this->txid, 20), ['data-toggle' => 'tooltip', 'title' => $this->txid]); }
/** * Execute the console command. * * @return void */ public function fire() { $dayBefore = Carbon::now()->subDay(); $content = Content::where('created_at', '>', $dayBefore)->orderBy('uv', 'desc')->firstOrFail(); $client = new Client(['base_url' => 'https://api.twitter.com/1.1/', 'defaults' => ['auth' => 'oauth']]); $oauth = new Oauth1(['consumer_key' => config('social.twitter.consumer_key'), 'consumer_secret' => config('social.twitter.consumer_secret'), 'token' => config('social.twitter.token'), 'token_secret' => config('social.twitter.token_secret')]); $client->getEmitter()->attach($oauth); $params = ['status' => Str::limit($content->title, 100) . ' https://strm.pl/c/' . $content->hashId()]; $client->post('statuses/update.json', ['body' => $params]); }
/** * Generate Item uuid. * * @param $menuName * @param $itemURL * * @return string */ public function getItemUuiD($menuItem) { $itemID = ''; if (is_a($menuItem, MenuItem::class)) { $itemID = 'MenuItem' . $menuItem->getURL(); } if (is_a($menuItem, MenuBuilder::class)) { $itemID = 'MenuBuilder' . $menuItem->getName(); } return Str::limit(md5(Str::slug($itemID)), 12, null); }
function render($instance, $key, $options) { if ($instance->{$key}) { $limit = 100; if ($options && intval($options)) { $limit = intval($options); } return Str::limit($instance->{$key}, $limit); } return null; }
function createGroup(Author $author) { $faker = $this->faker(); $group = new Group(); $group->title = join(' ', $faker->words(5)); $group->link = $faker->boolean() ? '/' . $faker->slug(3) . '.html' : ''; $group->inline = $faker->boolean(); $group->annotation = Str::limit($faker->realText(), 250); $group->author()->associate($author); $group->save(); return $group; }
public function testStringLimit() { $str1 = 'Laravel is really awesome'; $str2 = Str::limit($str1); $this->assertEquals($str2, 'Laravel is really awesome'); $str1 = 'Laravel is really awesome'; $str2 = Str::limit($str1, 7); $this->assertEquals($str2, 'Laravel...'); $str1 = 'Laravel is really awesome'; $str2 = Str::limit($str1, 7, '!!!'); $this->assertEquals($str2, 'Laravel!!!'); }
/** * Run the migrations. * * @return void */ public function up() { Schema::table('games', function(Blueprint $table) { $table->string('slug', 32); }); $games = Game::all(); foreach( $games as $item ) { $item->slug = Str::limit( Str::slug( $item->title), 32, ''); $item->save(); } }
/** * Run the migrations. * * @return void */ public function up() { Schema::table('categories', function(Blueprint $table) { $table->string('icon')->nullable(); $table->string('slug', 32); $table->string('type')->nullable(); }); $categories = Category::all(); foreach( $categories as $item ) { $item->slug = Str::limit( Str::slug( $item->name), 32, ''); $item->save(); } }
/** * Run the database seeds. * * @return void */ public function run() { $authors = Author::all(); $this->iterate(self::PAGES_TO_SEED / 2, self::PAGES_TO_SEED, function ($i) use($authors) { $author = $authors->random(); do { $author = $authors->random(); } while ($author->groups->isEmpty()); $faker = $this->faker(); $page = new Page(); $page->title = $faker->sentence(5); $page->annotation = Str::limit(join(' ', $faker->sentences(5)), 250); $page->link = $faker->slug(3); $page->size = $faker->numberBetween(0, 9999); $page->author()->associate($author); $page->group()->associate($author->groups->random()); $page->save(); }); }
/** * Limit the number of characters in the string. * * @param int $limit * @param string $end * @return static */ public function limit($limit = 100, $end = '...') { return new static(Str::limit($this->string, $limit, $end)); }
public function getReleaseDate() { if ($this->released_at !== null) { return $this->released_at; } if ($this->published_at !== null) { return Str::limit($this->published_at, 10, ''); } return Str::limit($this->attributes['created_at'], 10, ''); }
/** * Limit the number of characters in a string. * * @param string $value * @param int $limit * @param string $end * @return string */ public function limit($value, $limit = 12, $end = '') { return Str::limit($value, $limit, $end); }
public static function limitMarkdownText($str, $limit, $ignored_tags = false) { // Remove content in $ignored_tags if ($ignored_tags) { $str = Thinker::removeTagsFromString($str, $ignored_tags); } // Shorten Markdown $str = preg_replace("/\r|\n/", " ", strip_tags($str)); $str_limited = Str::limit($str, $limit); // Text < Limit if (strlen($str) == strlen($str_limited)) { return $str; } // Text > Limit $str_limited_words = explode(" ", $str_limited); array_pop($str_limited_words); $str_limited = join($str_limited_words, " ") . '…'; return $str_limited; }
/** * @param int $limit * @return string */ public function getDescription($limit = 130) { return Str::limit(strip_tags($this->model->getAttribute('content')), $limit, '...'); }
/** * Prepare the title output. * * @param string $output * * @return string */ private function prepareTitleOutput($output) { return htmlspecialchars(Str::limit(strip_tags($output), $this->getMax()), ENT_QUOTES, 'UTF-8', false); }
/** * When title change then slug will change. * @param $name * @internal param $title */ public function setNameAttribute($name) { $this->attributes['name'] = $name; $this->attributes['slug'] = Str::limit( Str::slug($name), 32, ''); }
/** * Returns a summary of the guide by limiting the description attribute. * * @return string */ public function getSummaryAttribute() { return Str::limit($this->description, 25); }
private function getHash() { $hash = md5($this->image_source); return '-' . Str::limit($hash, 5, ''); }
/** * Sanitize the username. * * @param array $inputs * * @return string */ protected function sanitizeUsername(array $inputs) { $username = $this->has('username') ? $inputs['username'] : Str::limit($inputs['first_name'], 1, '.') . ' ' . $inputs['last_name']; return Str::slug($username, config('arcanesoft.auth.slug-separator', '.')); }
/** * When title change then slug will change. * @param $title */ public function setTitleAttribute($title) { $this->attributes['title'] = $title; $this->attributes['slug'] = Str::limit( Str::slug($title), 32, ''); }
public function getCutAttribute() { return Str::limit($this->attributes['article'], 120); //ограничивает по количеству символов }
public function draw($id = 'untitled') { //start up if ($this->draggable) { array_unshift($this->columns, ['label' => '', 'type' => 'draggy', 'name' => 'draggy']); } if ($this->deletable) { self::column('delete', 'delete', ''); } if ($this->grouped) { $last_group = ''; } $colspan = count($this->columns); $rowspan = count($this->rows); //build <thead> $columns = []; foreach ($this->columns as $column) { $columns[] = '<th class="type-' . $column['type'] . ' ' . $column['name'] . '">' . $column['label'] . '</th>'; } $head = '<thead><tr>' . implode($columns) . '</tr></thead>'; //build rows $bodies = $rows = []; foreach ($this->rows as $row) { $columns = []; $link = true; foreach ($this->columns as $column) { //handle groupings if ($this->grouped && $last_group != $row->{$this->grouped}) { $last_group = $row->{$this->grouped}; if (count($rows)) { $bodies[] = '<tbody>' . implode($rows) . '</tbody>'; } $bodies[] = '<tr class="group"><td colspan=' . $colspan . '">' . $last_group . '</td></tr>'; $rows = []; } //process value if necessary if ($column['type'] == 'draggy') { $value = config('center.icons.drag'); } elseif ($column['type'] == 'delete') { $value = '<a href="' . $row->delete . '">' . ($row->deleted_at ? config('center.icons.deleted') : config('center.icons.undeleted')) . '</a>'; } elseif ($column['type'] == 'image') { $value = '<img src="' . $row->{$column['name'] . '_url'} . '" width="' . $column['width'] . '" height="' . $column['height'] . '">'; if (isset($row->link)) { $value = '<a href="' . $row->link . '">' . $value . '</a>'; } } elseif ($column['type'] == 'stripe_charge') { $value = $row->{$column['name']} ? '<a href="https://dashboard.stripe.com/payments/' . $row->{$column['name']} . '" target="_blank">' . config('center.icons.new_window') . ' ' . trans('center::site.stripe_open') . '</a>' : ''; } else { $value = Str::limit(strip_tags($row->{$column['name']})); if ($column['type'] == 'updated_at') { $value = Dates::relative($value); } elseif ($column['type'] == 'time') { $value = Dates::time($value); } elseif ($column['type'] == 'date') { $value = Dates::absolute($value); } elseif ($column['type'] == 'date-relative') { $value = Dates::relative($value); } elseif (in_array($column['type'], ['datetime', 'timestamp'])) { $value = Dates::absolute($value); } elseif ($column['type'] == 'checkbox') { $value = $value ? trans('center::site.yes') : trans('center::site.no'); } elseif ($column['type'] == 'money') { $value = '$' . number_format($value, 2); } if (isset($row->link) && $link) { if ($column['type'] == 'color') { $value = '<a href="' . $row->link . '" style="background-color: ' . $value . '"></a>'; } else { if ($value == '') { $value = '…'; } $value = '<a href="' . $row->link . '">' . $value . '</a>'; $link = false; } } } //create cell $columns[] = '<td class="type-' . $column['type'] . ' ' . $column['name'] . '">' . $value . '</td>'; } //create row $rows[] = '<tr' . (empty($row->id) ? '' : ' id="' . $row->id . '"') . ($this->deletable && $row->deleted_at ? ' class="inactive"' : '') . '>' . implode($columns) . '</tr>'; } $bodies[] = '<tbody>' . implode($rows) . '</tbody>'; //output return '<table id="' . $id . '" class="table table-condensed' . ($this->draggable ? ' draggable" data-draggable-url="' . $this->draggable : '') . '" data-csrf-token="' . Session::token() . '">' . $head . implode($bodies) . '</table>'; }
public function subject() { $prefix = $this->versionSubjectPrefix(); $subject = Str::limit($this->getWrappedObject()->subject, 80); return $prefix ? $prefix . ' ' . $subject : $subject; }
/** * Retrieve the ticker excerpt. * * @param integer $limit 58 * @param string $end ... * @return string */ public function excerpt($limit = 58, $end = ' ...') { return Str::limit($this->content(), $limit, $end); }
/** * limit **/ public function limit($limit = 100, $end = '...') { $this->value = Str::limit($this->value, $limit, $end); return $this; }
/** * Limit the number of characters in a string. * * @param string $value * @param int $limit * @param string $end * @return string */ function str_limit($value, $limit = 100, $end = '...') { return Str::limit($value, $limit, $end); }
public function textarea() { $this->column_html .= Str::limit($this->value, 50) . PHP_EOL; $this->column_html .= '</td>' . PHP_EOL; return $this->column_html; }