本文整理汇总了PHP中Str::limit方法的典型用法代码示例。如果您正苦于以下问题:PHP Str::limit方法的具体用法?PHP Str::limit怎么用?PHP Str::limit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Str
的用法示例。
在下文中一共展示了Str::limit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: format
public function format($value)
{
if ($this->module->flag == "L") {
return Str::limit($value, $this->listLimit);
}
return $value;
}
示例2: getDatatable
public function getDatatable()
{
$products = $this->ProductRepo->find(Input::get('sSearch'));
return Datatable::query($products)->addColumn('checkbox', function ($model) {
return '<input type="checkbox" name="ids[]" value="' . $model->public_id . '">';
})->addColumn('product_key', function ($model) {
return link_to('products/' . $model->public_id, $model->product_key);
})->addColumn('notes', function ($model) {
return nl2br(Str::limit($model->notes, 50));
})->addColumn('cost', function ($model) {
return Utils::formatMoney($model->cost, 1);
})->addColumn('name', function ($model) {
return nl2br($model->category_name);
})->addColumn('dropdown', function ($model) {
return '<div class="btn-group tr-action" style="visibility:hidden;">
<button type="button" class="btn btn-xs btn-default dropdown-toggle" data-toggle="dropdown">
' . trans('texts.select') . ' <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="' . URL::to('products/' . $model->public_id) . '/edit">' . uctrans('texts.edit_product') . '</a></li>
<li class="divider"></li>
<li><a href="' . URL::to('products/' . $model->public_id) . '/archive">' . uctrans('texts.delete_product') . '</a></li>
</ul>
</div>';
})->make();
}
示例3: edit
public function edit($id)
{
if (Request::isMethod('post')) {
$rules = array('title' => 'required|min:4', 'link' => 'required', 'content' => 'required|min:100', 'published_at' => 'required', 'meta_description' => 'max:500', 'meta_keywords' => 'required');
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect::to("admin/post/{$id}/edit")->withErrors($validator)->withInput(Input::except(''));
} else {
$table = Post::find($id);
$table->title = e(Input::get('title'));
$table->link = Input::get('link');
$table->user_id = Auth::user()->id;
$table->content = e(Input::get('content'));
$table->meta_title = Input::get('meta_title') ? Input::get('meta_title') : $table->title;
$table->meta_description = Input::get('meta_description') ? Input::get('meta_description') : Str::limit(strip_tags(HTML::decode($table->content)), 155);
$table->meta_keywords = Input::get('meta_keywords');
$table->published_at = Post::toDate(Input::get('published_at'));
$table->active = Input::get('active', 0);
if ($table->save()) {
$name = trans("name.{$this->name}");
return Redirect::to("admin/{$this->name}")->with('success', trans("message.{$this->action}", ['name' => $name]));
}
return Redirect::to("admin/{$this->name}")->with('error', trans('message.error'));
}
}
return View::make("admin.{$this->name}.{$this->action}", ['item' => Post::find($id), 'name' => $this->name, 'action' => $this->action]);
}
示例4: index
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]);
}
示例5: excerpt
/**
* Get the page's excerpt
* @return string
*/
public function excerpt($length = 80)
{
if (strpos($this->content, '<!--more-->')) {
list($excerpt, $more) = explode('<!--more-->', $this->content);
return Services\String::tidy($excerpt);
} else {
return Services\String::tidy(Str::limit($this->content, $length));
}
}
示例6: format
public function format($value)
{
$flag = $this->module->flag;
if ($flag == "L") {
return Markdown::defaultTransform(Str::limit($value, $this->listLimit));
}
if ($flag == "R") {
return Markdown::defaultTransform($value);
}
return $value;
}
示例7: editAlbum
public function editAlbum()
{
$id = \Input::get('id');
$title = \Input::get('text');
$album = $this->albumRepository->get($id);
if (!$album) {
return '0';
}
if (empty($title)) {
return \Str::limit(ucwords($album->title), 30);
}
$album = $this->albumRepository->save($title, $album);
return \Str::limit(ucwords($album->title), 30);
}
示例8: upload
/**
* Attempts to upload a file, adds it to the database and removes other database entries for that file type if they are asked to be removed
* @param string $field The name of the $_FILES field you want to upload
* @param boolean $upload_type The type of upload ('news', 'gallery', 'section') etc
* @param boolean $type_id The ID of the item (above) that the upload is linked to
* @param boolean $remove_existing Setting this to true will remove all existing uploads of the passed in type (useful for replacing news article images when a new on
* @param boolean $title Sets the title of the upload
* @param boolean $path_to_store Sets the path to the upload (where it should go)
* @return object Returns the upload object so we can work with the uploaded file and details
*/
public static function upload($details = array())
{
$upload_details = array('remove_existing_for_link' => true, 'path_to_store' => path('public') . 'uploads/', 'resizing' => array('small' => array('w' => 200, 'h' => 200), 'thumb' => array('w' => 200, 'h' => 200)));
if (!empty($details)) {
$required_keys = array('upload_field_name', 'upload_type', 'upload_link_id', 'title');
$continue = true;
foreach ($required_keys as $key) {
if (!isset($details[$key]) || empty($details[$key])) {
Messages::add('error', 'Your upload array details are not complete... please fill this in properly.');
$continue = false;
}
}
if ($continue) {
$configuration = $details + $upload_details;
$input = Input::file($configuration['upload_field_name']);
if ($input && $input['error'] == UPLOAD_ERR_OK) {
if ($configuration['remove_existing_for_link']) {
static::remove($configuration['upload_type'], $configuration['upload_link_id']);
}
$ext = File::extension($input['name']);
$filename = Str::slug($configuration['upload_type'] . '-' . $configuration['upload_link_id'] . '-' . Str::limit(md5($input['name']), 10, false) . '-' . $configuration['title'], '-');
Input::upload($configuration['upload_field_name'], $configuration['path_to_store'], $filename . '.' . $ext);
$upload = new Upload();
$upload->link_type = $configuration['upload_type'];
$upload->link_id = $configuration['upload_link_id'];
$upload->filename = $filename . '.' . $ext;
if (Koki::is_image($configuration['path_to_store'] . $filename . '.' . $ext)) {
$upload->small_filename = $filename . '_small' . '.' . $ext;
$upload->thumb_filename = $filename . '_thumb' . '.' . $ext;
$upload->image = 1;
}
$upload->extension = $ext;
$upload->user_id = Auth::user()->id;
$upload->save();
if (Koki::is_image($configuration['path_to_store'] . $filename . '.' . $ext)) {
WideImage::load($configuration['path_to_store'] . $upload->filename)->resize($configuration['resizing']['small']['w'], $configuration['resizing']['small']['h'])->saveToFile($configuration['path_to_store'] . $upload->small_filename);
WideImage::load($configuration['path_to_store'] . $upload->small_filename)->crop('center', 'center', $configuration['resizing']['thumb']['w'], $configuration['resizing']['thumb']['h'])->saveToFile($configuration['path_to_store'] . $upload->thumb_filename);
}
return true;
}
}
} else {
Messages::add('error', 'Your upload array details are empty... please fill this in properly.');
}
return false;
}
示例9: agregar
public static function agregar($info)
{
$respuesta = array();
$rules = array('archivo' => array('mimes:pdf'));
$validator = Validator::make($info, $rules);
if ($validator->fails()) {
//return Response::make($validator->errors->first(), 400);
//Si está todo mal, carga lo que corresponde en el mensaje.
$respuesta['mensaje'] = $validator;
$respuesta['error'] = 'no pasa';
} else {
$file = $info['archivo'];
$count = count($file->getClientOriginalName()) - 4;
$nombreArchivo = Str::limit(Str::slug($file->getClientOriginalName()), $count, "");
$extension = $file->getClientOriginalExtension();
//if you need extension of the file
//$extension = File::extension($file['name']);
$carpeta = '/uploads/archivos/';
$directory = public_path() . $carpeta;
//$filename = sha1(time() . Hash::make($filename) . time()) . ".{$extension}";
//Pregunto para que no se repita el nombre de la imagen
if (!is_null(Archivo::archivoPorNombre($nombreArchivo . ".{$extension}"))) {
$filename = $nombreArchivo . "(" . Str::limit(sha1(time()), 3, "") . ")" . ".{$extension}";
} else {
$filename = $nombreArchivo . ".{$extension}";
}
//$upload_success = $file->move($directory, $filename);
if ($file->move($directory, $filename)) {
$datos = array('nombre' => $filename, 'titulo' => $nombreArchivo . ".{$extension}", 'carpeta' => $carpeta, 'tipo' => "{$extension}", 'estado' => 'A', 'fecha_carga' => date("Y-m-d H:i:s"), 'usuario_id_carga' => Auth::user()->id);
$archivo = static::create($datos);
//Mensaje correspondiente a la agregacion exitosa
$respuesta['mensaje'] = 'Archivo creado.';
$respuesta['error'] = false;
$respuesta['data'] = $archivo;
//return Response::json('success', 200);
} else {
//Mensaje correspondiente a la agregacion exitosa
$respuesta['mensaje'] = 'Archivo erróneo.';
$respuesta['error'] = true;
$respuesta['data'] = null;
//return Response::json('error', 400);
}
}
return $respuesta;
}
示例10: participantsListsExport
public function participantsListsExport()
{
$users_list = $this->getParticipants(10000);
$glue = Input::get('glue');
$headers = array('local_id', 'remote_id', iconv("UTF-8", Input::get('coding'), 'Имя'), iconv("UTF-8", Input::get('coding'), 'Фамилия'), iconv("UTF-8", Input::get('coding'), 'Элект.почта'), iconv("UTF-8", Input::get('coding'), 'Фотография'), iconv("UTF-8", Input::get('coding'), 'Пол. 1 - жен, 2 - муж.'), iconv("UTF-8", Input::get('coding'), 'Телефон'), iconv("UTF-8", Input::get('coding'), 'Город'), iconv("UTF-8", Input::get('coding'), 'Победитель'), iconv("UTF-8", Input::get('coding'), 'Номер недели'), iconv("UTF-8", Input::get('coding'), 'Дата рождения'), iconv("UTF-8", Input::get('coding'), 'Дата регистрации'), iconv("UTF-8", Input::get('coding'), 'Всего лайков'), iconv("UTF-8", Input::get('coding'), 'Лайки по соц.сетям'), iconv("UTF-8", Input::get('coding'), 'Фотография из соц.сети'), iconv("UTF-8", Input::get('coding'), 'Кол.введ.кодов'), iconv("UTF-8", Input::get('coding'), 'Рассказ'), iconv("UTF-8", Input::get('coding'), 'ID рассказа'), iconv("UTF-8", Input::get('coding'), 'Статус рассказа. 0-отсутсвует. 1-одобрен. 2-на модерации. 3-отклонен'));
if ($glue === 'tab') {
$output = implode("\t", $headers) . "\n";
} else {
$output = implode("{$glue}", $headers) . "\n";
}
foreach ($users_list as $user) {
try {
$user->name = iconv("UTF-8", Input::get('coding'), $user->name);
} catch (Exception $e) {
}
try {
$user->surname = iconv("UTF-8", Input::get('coding'), $user->surname);
} catch (Exception $e) {
}
try {
$user->total_extend = iconv("UTF-8", Input::get('coding'), $user->total_extend);
} catch (Exception $e) {
}
try {
$user->writing = iconv("UTF-8", Input::get('coding'), str_replace(array("\r\n", "\n\r", "\r", "\n", "\t", ";"), "", strip_tags(Str::limit($user->writing, 1000))));
} catch (Exception $e) {
$user->writing = iconv("UTF-8", Input::get('coding'), 'ВНИМАНИЕ! ВОЗНИКЛА ОШИБКА ПРИ ПЕРЕКОДИРОВАНИИ.');
}
try {
$user->city = iconv("UTF-8", Input::get('coding'), $user->city);
} catch (Exception $e) {
}
$fields = (array) $user;
if ($glue === 'tab') {
$output .= implode("\t", $fields) . "\n";
} else {
$output .= implode("{$glue}", $fields) . "\n";
}
}
$headers = array('Content-Type' => 'text/csv', 'Content-Disposition' => 'attachment; filename="ExportList.csv"');
return Response::make(rtrim($output, "\n"), 200, $headers);
}
示例11: boot
/**
* Register bindings in the container.
*
* @param Dispatcher $events
*
* @return void
*/
public function boot(Dispatcher $events)
{
$this->app->booted(function () {
if (Request::getUser() && Request::getPassword()) {
return Auth::onceBasic('name');
}
});
$events->listen('auth.login', function ($user) {
$user->last_login = new Carbon();
$user->last_ip = Request::getClientIp();
$user->save();
});
/* IRC Notification */
$events->listen('eloquent.created: Strimoid\\Models\\User', function (User $user) {
$url = Config::get('app.hubot_url');
if (!$url) {
return;
}
try {
Guzzle::post($url, ['json' => ['room' => '#strimoid', 'text' => 'Mamy nowego użytkownika ' . $user->name . '!']]);
} catch (Exception $e) {
}
});
$events->listen('eloquent.created: Strimoid\\Models\\Entry', function (Entry $entry) {
$url = Config::get('app.hubot_url');
if (!$url) {
return;
}
try {
$text = strip_tags($entry->text);
$text = trim(preg_replace('/\\s+/', ' ', $text));
$text = Str::limit($text, 100);
Guzzle::post($url, ['json' => ['room' => '#strimoid-entries', 'text' => '[' . $entry->group->name . '] ' . $entry->user->name . ': ' . $text]]);
} catch (Exception $e) {
}
});
$events->subscribe(NewActionHandler::class);
$events->subscribe(NotificationsHandler::class);
$events->subscribe(PubSubHandler::class);
}
示例12: getDatatable
public function getDatatable()
{
$query = DB::table('products')->where('products.account_id', '=', Auth::user()->account_id)->where('products.deleted_at', '=', null)->select('products.public_id', 'products.product_key', 'products.notes', 'products.cost');
return Datatable::query($query)->addColumn('product_key', function ($model) {
return link_to('products/' . $model->public_id . '/edit', $model->product_key);
})->addColumn('notes', function ($model) {
return nl2br(Str::limit($model->notes, 100));
})->addColumn('cost', function ($model) {
return Utils::formatMoney($model->cost);
})->addColumn('dropdown', function ($model) {
return '<div class="btn-group tr-action" style="visibility:hidden;">
<button type="button" class="btn btn-xs btn-default dropdown-toggle" data-toggle="dropdown">
' . trans('texts.select') . ' <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="' . URL::to('products/' . $model->public_id) . '/edit">' . uctrans('texts.edit_product') . '</a></li>
<li class="divider"></li>
<li><a href="' . URL::to('products/' . $model->public_id) . '/archive">' . uctrans('texts.archive_product') . '</a></li>
</ul>
</div>';
})->orderColumns(['cost', 'product_key', 'cost'])->make();
}
示例13: getDatatable
public function getDatatable()
{
$query = DB::table('branches')->where('branches.account_id', '=', Auth::user()->account_id)->where('branches.deleted_at', '=', null)->where('branches.public_id', '>', 0)->select('branches.public_id', 'branches.name', 'branches.address1', 'branches.address2');
return Datatable::query($query)->addColumn('name', function ($model) {
return link_to('branches/' . $model->public_id . '/edit', $model->name);
})->addColumn('address1', function ($model) {
return nl2br(Str::limit($model->address1, 100));
})->addColumn('address2', function ($model) {
return nl2br(Str::limit($model->address2, 100));
})->addColumn('dropdown', function ($model) {
return '<div class="btn-group tr-action" style="visibility:hidden;">
<button type="button" class="btn btn-xs btn-default dropdown-toggle" data-toggle="dropdown">
' . trans('texts.select') . ' <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="' . URL::to('branches/' . $model->public_id) . '/edit">' . uctrans('texts.edit_branch') . '</a></li>
<li class="divider"></li>
<li><a href="' . URL::to('branches/' . $model->public_id) . '/archive">' . uctrans('texts.archive_branch') . '</a></li>
</ul>
</div>';
})->orderColumns(['name', 'address1'])->make();
}
示例14:
<li onclick="window.location='<?php
echo $issue->to();
?>
#comment<?php
echo $comment->id;
?>
';">
<div class="tag">
<label class="label notice">Comment</label>
</div>
<div class="data">
<span class="comment">
"<?php
echo Str::limit($comment->comment, 60);
?>
"
</span>
by
<strong><?php
echo $user->firstname . ' ' . $user->lastname;
?>
</strong> on issue <a href="<?php
echo $issue->to();
?>
"><?php
echo $issue->title;
?>
</a>
<span class="time">
示例15: getCommentForAdministratorAttribute
/**
* Accessor. Returns a truncated and escaped comment string for use in the administrator package index
*
* @param $value
* @return string
*/
public function getCommentForAdministratorAttribute($value)
{
return \Str::limit(htmlspecialchars($value, null, 'UTF-8'), 50);
}