本文整理汇总了PHP中Text::limit_chars方法的典型用法代码示例。如果您正苦于以下问题:PHP Text::limit_chars方法的具体用法?PHP Text::limit_chars怎么用?PHP Text::limit_chars使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Text
的用法示例。
在下文中一共展示了Text::limit_chars方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_new
public function action_new()
{
Breadcrumbs::add(Breadcrumb::factory()->set_title(__('New field')));
$this->template->title = __('New Custom Field for Advertisement');
//find all, for populating form select fields
$categories = Model_Category::get_as_array();
$order_categories = Model_Category::get_multidimensional();
if ($_POST) {
if (count(Model_Field::get_all()) > 65) {
Alert::set(Alert::ERROR, __('You have reached the maximum number of custom fields allowed.'));
HTTP::redirect(Route::url('oc-panel', array('controller' => 'fields', 'action' => 'index')));
}
$name = URL::title(Core::post('name'), '_');
if (strlen($name) >= 60) {
$name = Text::limit_chars($name, 60, '');
}
$field = new Model_Field();
try {
$options = array('label' => Core::post('label'), 'tooltip' => Core::post('tooltip'), 'required' => Core::post('required') == 'on' ? TRUE : FALSE, 'searchable' => Core::post('searchable') == 'on' ? TRUE : FALSE, 'admin_privilege' => Core::post('admin_privilege') == 'on' ? TRUE : FALSE, 'show_listing' => Core::post('show_listing') == 'on' ? TRUE : FALSE);
if ($field->create($name, Core::post('type'), Core::post('values'), Core::post('categories'), $options)) {
Core::delete_cache();
Alert::set(Alert::SUCCESS, sprintf(__('Field %s created'), $name));
} else {
Alert::set(Alert::WARNING, sprintf(__('Field %s already exists'), $name));
}
} catch (Exception $e) {
throw HTTP_Exception::factory(500, $e->getMessage());
}
HTTP::redirect(Route::url('oc-panel', array('controller' => 'fields', 'action' => 'index')));
}
$this->template->content = View::factory('oc-panel/pages/fields/new', array('categories' => $categories, 'order_categories' => $order_categories));
}
示例2: action_index
public function action_index()
{
if ($this->owner) {
$this->template->header->title = __('Dashboard');
$this->template->header->js = View::factory('pages/user/js/main');
$this->active = 'dashboard-navigation-link';
$this->sub_content = View::factory('pages/user/main')->bind('owner', $this->owner)->bind('account', $this->visited_account);
$gravatar_view = TRUE;
} else {
$this->template->header->title = __(':name\'s Profile', array(':name' => Text::limit_chars($this->visited_account->user->name)));
$this->template->header->js = View::factory('pages/user/js/profile');
$this->template->header->js->visited_account = $this->visited_account;
$this->template->header->js->bucket_list = json_encode($this->visited_account->user->get_buckets_array($this->user));
$this->template->header->js->river_list = json_encode($this->visited_account->user->get_rivers_array($this->user));
$this->sub_content = View::factory('pages/user/profile');
$this->sub_content->account = $this->visited_account;
$this->sub_content->anonymous = $this->anonymous;
$gravatar_view = FALSE;
$this->template->content->view_type = "user";
}
// Activity stream
$this->sub_content->activity_stream = View::factory('template/activities')->bind('activities', $activities)->bind('fetch_url', $fetch_url)->bind('owner', $this->owner)->bind('gravatar_view', $gravatar_view);
$fetch_url = URL::site() . $this->visited_account->account_path . '/user/action/actions';
$activity_list = Model_User_Action::get_activity_stream($this->visited_account->user->id, $this->user->id, !$this->owner);
$this->sub_content->has_activity = count($activity_list) > 0;
$activities = json_encode($activity_list);
}
示例3: query
public function query($sql, $params = NULL)
{
$args = func_get_args();
$display = str_replace("\n", '↵', $sql);
$display = preg_replace("/[\\s\t]+/", " ", $display);
$display = Text::limit_chars($display, 60);
return $this->run_driver("query( {$display} )", __FUNCTION__, $args, TRUE);
}
示例4: action_create
/**
* CRUD controller: CREATE
*/
public function action_create()
{
$this->auto_render = FALSE;
$this->template = View::factory('js');
if (!isset($_FILES['image'])) {
$this->template->content = json_encode('KO');
return;
}
$image = $_FILES['image'];
if (core::config('image.aws_s3_active')) {
require_once Kohana::find_file('vendor', 'amazon-s3-php-class/S3', 'php');
$s3 = new S3(core::config('image.aws_access_key'), core::config('image.aws_secret_key'));
}
if (!Upload::valid($image) or !Upload::not_empty($image) or !Upload::type($image, explode(',', core::config('image.allowed_formats'))) or !Upload::size($image, core::config('image.max_image_size') . 'M')) {
if (Upload::not_empty($image) and !Upload::type($image, explode(',', core::config('image.allowed_formats')))) {
$this->template->content = json_encode(array('msg' => $image['name'] . ' ' . sprintf(__('Is not valid format, please use one of this formats "%s"'), core::config('image.allowed_formats'))));
return;
}
if (!Upload::size($image, core::config('image.max_image_size') . 'M')) {
$this->template->content = json_encode(array('msg' => $image['name'] . ' ' . sprintf(__('Is not of valid size. Size is limited to %s MB per image'), core::config('image.max_image_size'))));
return;
}
$this->template->content = json_encode(array('msg' => $image['name'] . ' ' . __('Image is not valid. Please try again.')));
return;
} elseif ($image != NULL) {
// saving/uploading img file to dir.
$path = 'images/cms/';
$root = DOCROOT . $path;
//root folder
$image_name = URL::title(pathinfo($image['name'], PATHINFO_FILENAME));
$image_name = Text::limit_chars(URL::title(pathinfo($image['name'], PATHINFO_FILENAME)), 200);
$image_name = time() . '.' . $image_name;
// if folder does not exist, try to make it
if (!file_exists($root) and !@mkdir($root, 0775, true)) {
// mkdir not successful ?
$this->template->content = json_encode(array('msg' => __('Image folder is missing and cannot be created with mkdir. Please correct to be able to upload images.')));
return;
// exit function
}
// save file to root folder, file, name, dir
if ($file = Upload::save($image, $image_name, $root)) {
// put image to Amazon S3
if (core::config('image.aws_s3_active')) {
$s3->putObject($s3->inputFile($file), core::config('image.aws_s3_bucket'), $path . $image_name, S3::ACL_PUBLIC_READ);
}
$this->template->content = json_encode(array('link' => Core::config('general.base_url') . $path . $image_name));
return;
} else {
$this->template->content = json_encode(array('msg' => $image['name'] . ' ' . __('Image file could not been saved.')));
return;
}
$this->template->content = json_encode(array('msg' => $image['name'] . ' ' . __('Image is not valid. Please try again.')));
}
}
示例5: action_edit
public function action_edit()
{
$view = View::factory('exercise/form')->bind('form', $form)->bind('questions', $questions)->bind('selected_questions', $selected_questions)->bind('exercise_questions', $exercise_questions)->bind('error_notif', $error_notif);
$submitted = false;
$course = ORM::factory('course', Session::instance()->get('course_id'));
$error_notif = array();
$exercise_id = (int) $this->request->param('id');
$exercise = ORM::factory('exercise', $exercise_id);
if ($this->request->method() === 'POST' && $this->request->post()) {
$submitted = true;
$safepost = Arr::map('Security::xss_clean', $this->request->post());
$validator = $exercise->validator($safepost);
if ($validator->check() && $this->validate_form($safepost)) {
$exercise->values(array_merge($safepost, array('course_id' => $course->id, 'slug' => Text::limit_chars(Inflector::underscore($safepost['title'])), 'modified_at' => date('Y-m-d H:i:s', time()))));
$exercise->save();
$zip_ques = Arr::zip($safepost['selected'], $safepost['marks']);
$exercise->delete_questions()->add_questions($zip_ques);
if ($safepost['pub_status'] == '1') {
$exist = ORM::factory('feed');
$exist->where('type', ' = ', 'exercise');
$exist->where('action', ' = ', 'add');
$exist->where('respective_id', ' = ', $exercise->id);
$exist->where('course_id', ' = ', Session::instance()->get('course_id'));
$exists = $exist->find_all();
if (count($exists) == 0) {
$feed = new Feed_Exercise();
$feed->set_action('add');
$feed->set_course_id(Session::instance()->get('course_id'));
$feed->set_respective_id($exercise->id);
$feed->set_actor_id(Auth::instance()->get_user()->id);
$feed->streams(array('course_id' => (int) Session::instance()->get('course_id')));
$feed->save();
}
}
Session::instance()->set('success', 'Exercise edited successfully.');
Request::current()->redirect('exercise');
exit;
} else {
$this->_errors = array_merge($this->_errors, $validator->errors('exercise'));
$error_notif = Arr::get($this->_errors, 'questions', '');
}
}
$exercise_questions = $exercise->questions()->as_array('question_id', 'marks');
$selected_questions = array_keys($exercise_questions);
$saved_data = $exercise->as_array();
$form = $this->form('exercise/edit/id/' . $exercise->id, $submitted, $saved_data);
Breadcrumbs::add(array('Edit', ''));
// set content
$questions = Model_Question::get_questions(array('course_id' => $course->id));
$this->content = $view;
}
示例6: write
public function write(array $messages)
{
foreach ($messages as $message) {
$additional = Arr::get($message, 'additional');
$ip = Request::$client_ip;
$uri = Arr::get($_SERVER, 'SERVER_NAME') . Arr::get($_SERVER, 'REQUEST_URI');
$referer = Arr::get($_SERVER, 'HTTP_REFERER');
$agent = Arr::get($_SERVER, 'HTTP_USER_AGENT');
$post = var_export($_POST, TRUE);
$file = str_replace(DOCROOT, '', Arr::get($message, 'file'));
// Write each message into the log database table
DB::insert('logs', array('time', 'level', 'body', 'file', 'line', 'class', 'function', 'additional', 'ip', 'uri', 'referer', 'agent', 'post'))->values(array(Arr::get($message, 'time'), Arr::get($message, 'level'), Text::limit_chars(Arr::get($message, 'body'), 2048), $file, Arr::get($message, 'line'), Arr::get($message, 'class'), Arr::get($message, 'function'), empty($additional) ? NULL : Text::limit_chars(print_r($additional, TRUE), 2048), $ip, $uri, $referer, $agent, $post))->execute();
}
}
示例7: content
/**
* Render content.
*
* @return string
*/
public function content()
{
// Show limited amount of data
$info = Text::limit_chars($this->event->info, 300);
$show_more = $info != $this->event->info;
// Max 3 lines
$lines = explode("\n", str_replace(array("\r\n", "\r"), "\n", $info), 3);
$show_more = $show_more || count($lines) == 3;
if (count($lines) > 2) {
$lines[2] .= '…';
}
$info = implode("\n", $lines);
return '<div class="djs">' . BB::factory($info)->render(null, true) . '</div>';
}
示例8: button
/**
* generates HTML for apy buton
* @param Model_Order $order
* @return string
*/
public static function button(Model_Order $order)
{
if (Core::config('payment.mercadopago_client_id') != '' and Core::config('payment.mercadopago_client_secret') != '' and Theme::get('premium') == 1) {
// Include Mercadopago library
require Kohana::find_file('vendor/mercadopago', 'mercadopago');
// Create an instance with your MercadoPago credentials (CLIENT_ID and CLIENT_SECRET):
$mp = new MP(core::config('payment.mercadopago_client_id'), core::config('payment.mercadopago_client_secret'));
$preference_data = array("items" => array(array("id" => $order->id_order, "title" => $order->product->title, "currency_id" => $order->currency, "picture_url" => $order->product->get_first_image(), "description" => Text::limit_chars(Text::removebbcode($order->product->description), 30, NULL, TRUE), "category_id" => $order->product->category->name, "quantity" => 1, "unit_price" => self::money_format($order->amount))), "payer" => array("name" => Auth::instance()->get_user()->name, "email" => Auth::instance()->get_user()->email), "back_urls" => array("success" => Route::url('oc-panel', array('controller' => 'profile', 'action' => 'orders')), "failure" => Route::url('default', array('controller' => 'ad', 'action' => 'checkout', 'id' => $order->id_order))), "auto_return" => "approved", "notification_url" => Route::url('default', array('controller' => 'mercadopago', 'action' => 'ipn', 'id' => $order->id_order)), "expires" => false);
$preference = $mp->create_preference($preference_data);
$link = $preference["response"]["init_point"];
return View::factory('pages/mercadopago/button', array('link' => $link));
}
return '';
}
示例9: get_clients
public function get_clients()
{
$c_db = array();
$clients = array();
$clients[NULL] = __('Select client');
if (Auth::instance()->logged_in("admin")) {
$c_db = Model::factory('Client')->order_by('id', 'desc')->find_all();
} else {
$c_db = Model::factory('Client')->order_by('id', 'desc')->where('user_id', '=', Auth::instance()->get_user()->id)->find_all();
}
foreach ($c_db as $client) {
$clients[$client->id] = ucfirst($client->name) . " " . ucfirst($client->surname) . ". " . Text::limit_chars($client->description, 50);
}
return $clients;
}
示例10: action_view
/**
* Просмотр вакансии
* @throws HTTP_Exception_404
* @return void
*/
public function action_view()
{
$service = ORM::factory('service', $this->request->param('service_id'));
if (!$service->loaded()) {
throw new HTTP_Exception_404('Такая компания не найдена');
}
$vacancy = $service->vacancies->where('id', '=', $this->request->param('vacancy_id'))->find();
if (!$vacancy->loaded()) {
throw new HTTP_Exception_404('Такая вакансия от компании ' . $service->name . ' не найдена');
}
$this->template->title = 'Вакансия ' . $vacancy->title . ' — ' . $service->name;
$this->template->bc = array_merge($this->template->bc, array('services/' . $service->id => $service->get_name(2), 'services/' . $service->id . '/vacancies' => 'Вакансии', '#' => Text::limit_chars($vacancy->title, 80)));
$this->view = View::factory('frontend/vacancy/view')->set('vacancy', $vacancy);
$this->template->content = $this->view;
}
示例11: action_inbox
/**
* Display a list of incoming messages
*
* @uses Assets::popup
* @uses Route::url
* @uses Route::get
* @uses Route::uri
* @uses Request::is_datatables
* @uses Form::checkbox
* @uses HTML::anchor
* @uses Date::formatted_time
* @uses HTML::icon
* @uses Text::limit_chars
*/
public function action_inbox()
{
Assets::popup();
$url = Route::url('user/message', array('action' => 'inbox'), TRUE);
$redirect = Route::get('user/message')->uri(array('action' => 'inbox'));
$form_action = Route::get('user/message')->uri(array('action' => 'bulk', 'id' => PM::INBOX));
$destination = '?destination=' . $redirect;
$is_datatables = Request::is_datatables();
/** @var $messages Model_Message */
$messages = ORM::factory('Message')->loadInbox();
if ($is_datatables) {
$this->_datatables = $messages->dataTables(array('id', 'subject', 'sender', 'sent'));
foreach ($this->_datatables->result() as $message) {
$this->_datatables->add_row(array(Form::checkbox('messages[' . $message->id . ']', $message->id, isset($_POST['messages'][$message->id])), HTML::anchor($message->user->url, $message->user->nick, array('class' => 'message-' . $message->status)), HTML::anchor($message->url, Text::limit_chars($message->subject, 20), array('class' => 'message-' . $message->status)) . ' ' . HTML::anchor($message->url, Text::limit_chars(strip_tags($message->body), 80)), Date::formatted_time($message->sent, 'M d, Y'), HTML::icon($message->delete_url . $destination, 'fa-trash-o', array('title' => __('Delete Message'), 'data-toggle' => 'popup', 'data-table' => '#user-message-inbox'))));
}
}
$this->title = __('Inbox');
$view = View::factory('message/inbox')->bind('datatables', $this->_datatables)->set('is_datatables', $is_datatables)->set('action', $form_action)->set('url', $url);
$this->response->body($view);
}
示例12: action_ajax_light_register
public function action_ajax_light_register()
{
if ($this->request->is_ajax()) {
$email = trim($this->request->post('email'));
$role = 2;
$invalidEmail = !filter_var($email, FILTER_VALIDATE_EMAIL);
$emailExists = ORM::factory('User')->where('email', '=', $email)->find();
$errors = array('invalid_email' => $invalidEmail, 'email_exists' => $emailExists->loaded());
$textErrors = array();
$errors_exists = false;
foreach ($errors as $key => $error) {
if ($error) {
$errors_exists = true;
}
}
if ($errors['invalid_email']) {
$textErrors[] = 'Неверный формат email адреса!';
}
if ($errors['email_exists']) {
$textErrors[] = 'Данный email адрес занят!';
}
if (!$errors_exists) {
$token = md5(time() . $email);
$emailParts = explode('@', $email);
$password = Text::limit_chars(md5(time() . 'hello world' . $email), 8, '');
$user = ORM::factory('User');
$user->name = Arr::get($emailParts, 0);
$user->username = Arr::get($emailParts, 0);
$user->email = $email;
$user->roles = $role;
$user->password = $password;
$user->register_token = $token;
$user->save();
$message = sprintf("Спасибо за регистрацию <br/>" . "Ваш логин: %s <br/>" . "Ваш пароль: %s <br/>" . "Ваш email: %s <br/>" . "Ссылка для активации: %s", Arr::get($emailParts, 0), $password, $email, HTML::anchor(URL::base('http') . 'module_auth/token?email=' . $email . '&token=' . $token));
Helpers_Email::send($email, 'Регистрация', $message, true);
}
echo json_encode(array('errors' => $textErrors, 'errors_exists' => $errors_exists));
}
exit;
}
示例13: pack_string
/**
* Pack string to array
*
* Gets a string divide the string based by using the symbol `$sep` creates an array,
* where each substring - a single element of the array and serialize this array to a string
*
* @param string $string String
* @param boolean $serialize Serialize array? [Optional]
* @param string $sep Separator [Optional]
* @param int|NULL $maxlen Max length of substring for trimming [Optional]
*
* @return string
*
* @uses Text::limit_chars
*/
public static function pack_string($string, $serialize = FALSE, $sep = PHP_EOL, $maxlen = 0)
{
$options = explode($sep, $string);
$result = array();
foreach ($options as $option) {
if ($option = trim($option)) {
$result[] = $maxlen ? Text::limit_chars($option, $maxlen) : $option;
}
}
return $serialize ? serialize($result) : $result;
}
示例14: test_limit_chars
/**
* Tests Text::limit_chars()
*
* @test
* @dataProvider provider_limit_chars
*/
function test_limit_chars($expected, $str, $limit, $end_char, $preserve_words)
{
$this->assertSame($expected, Text::limit_chars($str, $limit, $end_char, $preserve_words));
}
示例15:
?>
</a></li>
<?php
}
?>
<?php
}
?>
</ul>
</li>
<?php
}
?>
<li><p class="navbar-text"><?php
echo Text::limit_chars(Text::removebbcode($product->description), 45, NULL, TRUE);
?>
</p></li>
</ul>
<div class="btn-group navbar-right btn-header-group">
<?php
if (core::config('product.demo_resize') == TRUE) {
?>
<a class="btn btn-default btn-sm mobile-btn" title="Mobile" href="#">
<span class="fa fa-mobile fa-2x"></span>
</a>
<a class="btn btn-default btn-sm tablet-btn" title="Tablet" href="#">
<span class="fa fa-tablet fa-2x"></span>
</a>
<a class="btn btn-default btn-sm desktop-btn" title="Desktop full width" href="#">