本文整理汇总了PHP中Cake\Utility\Text类的典型用法代码示例。如果您正苦于以下问题:PHP Text类的具体用法?PHP Text怎么用?PHP Text使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Text类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: leadPlus
/**
* Show truncated long text and hide full version for flyout
*
* When there is a lot of text for a small area, this shows just the
* truncated lead. The full text is in an element that is hidden.
* Javascript or css can implement a flyout to show the full thing.
*
* Attributes:
* $filed.leadPlus =>
* div // div containing the hidden full text
* p // div > p containg the full text
* span // div + span containg truncated text
* truncate // [truncate][limit] charcter count in truncated text
*
* @param type $helper
*/
public function leadPlus($field)
{
if (!$this->hasUuid()) {
$uuid = new Uuid();
} else {
$uuid = $this->helper->entity->_uuid;
}
// established passed and default attributes
$passed_attributes = $this->helper->attributes("{$field}.leadPlus");
$default = new \Cake\Collection\Collection(['full_text' => ['span' => ['id' => $uuid->uuid('full'), 'class' => 'full_text', 'style' => 'cursor: pointer; display: none;', 'onclick' => 'var id = this.id.replace("full", "truncated"); this.style.display = "none"; document.getElementById(id).style.display = "inline-block";']], 'truncated_text' => ['span' => ['id' => $uuid->uuid('truncated'), 'class' => 'truncated_text', 'style' => 'cursor: pointer; display: inline-block;', 'onclick' => 'var id = this.id.replace("truncated", "full"); this.style.display = "none"; document.getElementById(id).style.display = "inline-block";']], 'truncate' => ['limit' => [100]], 'p' => []]);
// intermediary values for calculations
$key_template = $default->map(function ($value, $key) {
return null;
});
// this yeilds array with all keys. values will be int if passed in, null if default
$attribute_keys = array_flip(array_keys($passed_attributes)) + $key_template->toArray();
// get attributes to use during rendering
$attribute = $default->map(function ($value, $key) use($attribute_keys, $passed_attributes) {
if (is_null($attribute_keys[$key])) {
return $value;
} else {
return array_merge($value, $passed_attributes[$key]);
}
})->toArray();
// output
// SOMEONE SORT THIS OUT TO MAKE IT HAVE DEFAULT out-of-the-box BEHAVIOR
$hidden = $this->helper->Html->tag('span', $this->helper->entity->{$field}, $attribute['full_text']['span']);
$text = $this->helper->Html->tag('span', Text::truncate($this->helper->entity->{$field}, $attribute['truncate']['limit']), $attribute['truncated_text']['span']);
return $this->helper->Html->tag('p', $text . $hidden, $attribute['p']);
}
示例2: upload
public function upload()
{
try {
$audioTable = TableRegistry::get('Audios');
$dateTimeUtc = new \DateTimeZone('UTC');
$now = new \DateTime('now', $dateTimeUtc);
// Generate file name
$serverDir = TMP . 'files' . DS;
$serverFileName = Text::uuid() . '.wav';
$uploadFullPath = $serverDir . $serverFileName;
// Move file to temp location
if (!move_uploaded_file($_FILES['file']['tmp_name'], $uploadFullPath)) {
throw new \Exception('Cannot copy file to tmp location: ' . $uploadFullPath);
}
$uploadFullPath = $this->__convertToPhoneAudio($uploadFullPath);
$data = ['file_name' => $_FILES['file']['name'], 'server_dir' => $serverDir, 'server_name' => $serverFileName, 'create_datetime' => $now];
$audio = $audioTable->newEntity($data);
$audioTable->save($audio);
$response['status'] = 1;
$response['audioId'] = $audio->audio_id;
} catch (\Excaption $ex) {
$response['status'] = 0;
$response['message'] = $ex->getMessage();
}
$this->set(compact('response'));
$this->set('_serialize', ['response']);
}
示例3: tabs
/**
* Create bootstrap tabs.
*
* @param array $data
* @param string $id
* @return string
* @SuppressWarnings(PHPMD.ShortVariable)
*/
public function tabs($id, array $data = [])
{
$i = 0;
$output = [];
foreach ($data as $key => $options) {
$i++;
$title = !is_array($options) ? $options : $key;
$alias = Text::slug((string) Inflector::underscore($key), '-');
if (is_string($options)) {
$options = [];
}
$_options = ['linkOptions' => ['data-toggle' => 'tab']];
if (isset($options['title'])) {
$title = $options['title'];
unset($options['title']);
}
$_options['linkOptions']['title'] = $title;
if ($i == 1) {
$_options = $this->addClass($_options, 'active');
}
$options = Hash::merge($_options, $options);
$linkOptions = $options['linkOptions'];
unset($options['linkOptions']);
$link = $this->Html->link($title, '#' . $alias, $linkOptions);
$output[] = $this->Html->tag('li', $link, $options);
}
return $this->Html->tag('ul', implode('', $output), ['class' => 'nav nav-tabs', 'id' => $id]);
}
示例4: getDescription
/**
*
*/
public function getDescription($data, $entity, $options)
{
$content = '';
extract($options);
if (isset($fields)) {
if (is_array($fields)) {
foreach ($fields as $field) {
if ($entity->has($field)) {
$temp = preg_replace_callback("/(&#[0-9]+;)/", function ($m) {
return mb_convert_encoding($m[1], "UTF-8", "HTML-ENTITIES");
}, $entity->{$field});
$temp = preg_replace('/&[a-z]+;/', '', $temp);
$temp = preg_replace('/<\\/[a-z]+><[a-z]+>/', ' ', $temp);
$temp = preg_replace('/[\\s]{1,}/', ' ', $temp);
$content .= strip_tags($temp);
}
}
} else {
if ($entity->has($fields)) {
$temp = preg_replace_callback("/(&#[0-9]+;)/", function ($m) {
return mb_convert_encoding($m[1], "UTF-8", "HTML-ENTITIES");
}, $entity->{$fields});
$temp = preg_replace('/&[a-z]+;/', '', $temp);
$temp = preg_replace('/<\\/[a-z]+><[a-z]+>/', ' ', $temp);
$temp = preg_replace('/[\\s]{1,}/', ' ', $temp);
$content .= strip_tags($temp);
}
}
}
return Text::truncate($content, 160, ['ellipsis' => '', 'exact' => false, 'html' => false]);
}
示例5: add
/**
* Add method
*
* @return void Redirects on successful add, renders view otherwise.
*/
public function add()
{
$boletos = $this->Boletoxretornos->Boletos->find('all')->toArray();
$arrayBoletos;
$opBoletos;
$i = 0;
foreach ($boletos as $x) {
$arrayBoletos[$i] = $x->id;
$opBoletos[$i] = $x->inr_boleto;
$i++;
}
$boletoxretorno = $this->Boletoxretornos->newEntity();
if ($this->request->is('post')) {
$boletoxretorno = $this->Boletoxretornos->patchEntity($boletoxretorno, $this->request->data);
$boletoxretorno->id = Text::uuid();
$boletoxretorno->boleto_id = $arrayBoletos[$boletoxretorno->boleto_id];
if ($this->Boletoxretornos->save($boletoxretorno)) {
$this->Flash->success(__('O retorno foi salvo.'));
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('O retorno não pôde ser salvo. Tente novamente.'));
}
}
$this->set(compact('boletoxretorno', 'opBoletos'));
$this->set('_serialize', ['boletoxretorno']);
}
示例6: add
/**
* Add method
*
* @return void Redirects on successful add, renders view otherwise.
*/
public function add()
{
$participantes = $this->Boletos->Participantes->find('all')->toArray();
$arrayParticipantes;
$opParticipantes;
$i = 0;
foreach ($participantes as $x) {
$opParticipantes[$i] = $x['cnm_participante'];
$arrayParticipantes[$i] = $x['id'];
$i++;
}
$boleto = $this->Boletos->newEntity();
if ($this->request->is('post')) {
$boleto = $this->Boletos->patchEntity($boleto, $this->request->data);
$boleto->id = Text::uuid();
$boleto->participante_id = $arrayParticipantes[$boleto->participante_id];
if ($this->Boletos->save($boleto)) {
$this->Flash->success(__('O boleto foi salvo.'));
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('O boleto não pôde ser salvo. Tente novamente.'));
}
}
$this->set(compact('boleto', 'opParticipantes'));
$this->set('_serialize', ['boleto']);
}
示例7: add
/**
* Add method
*
* @return void Redirects on successful add, renders view otherwise.
*/
public function add($idSub)
{
$submissoes = $this->Submissaoxcoautores->Submissoes->find('all')->toArray();
$i = 0;
$arraySubmissoes;
$opSubmissoes;
foreach ($submissoes as $x) {
$arraySubmissoes[$i] = $x->id;
$opSubmissoes[$i] = $x->ctl_submissao;
$i++;
}
$submissaoxcoautore = $this->Submissaoxcoautores->newEntity();
if ($this->request->is('post')) {
$submissaoxcoautore = $this->Submissaoxcoautores->patchEntity($submissaoxcoautore, $this->request->data);
$submissaoxcoautore->id = Text::uuid();
$submissaoxcoautore->submissao_id = $idSub;
//$arraySubmissoes[$submissaoxcoautore->submissao_id];
if ($this->Submissaoxcoautores->save($submissaoxcoautore)) {
$this->Flash->success(__('O coautor foi salvo.'));
return $this->redirect(['controller' => 'Submissoes', 'action' => 'index']);
} else {
$this->Flash->error(__('O coautor não pôde ser salvo. Tente novamente.'));
}
}
$this->set(compact('submissaoxcoautore', 'opSubmissoes'));
$this->set('_serialize', ['submissaoxcoautore']);
}
示例8: _getSlug
/**
* Gets the tag slug (virtual field)
* @return string|null
*/
protected function _getSlug()
{
if (empty($this->_properties['tag'])) {
return null;
}
return Text::slug($this->_properties['tag']);
}
示例9: add
public function add()
{
$clientInfo = $this->ClientInfos->newEntity();
if ($this->request->is('post')) {
$userid = Text::uuid();
$contactid = Text::uuid();
$clientid = Text::uuid();
$this->loadModel('Users');
$users = $this->Users->newEntity();
$users = $this->Users->patchEntity($users, $this->request->data['Users']);
$this->Users->save($users);
$this->loadModel('ClientInfos');
$clientInfos = $this->ClientInfos->newEntity();
$clientInfos = $this->ClientInfos->patchEntity($clientInfos, $this->request->data['ClientInfos']);
$this->ClientInfos->save($clientInfos);
$this->loadModel('ClientContacts');
$clientContacts = $this->ClientContacts->newEntity();
$clientContacts = $this->ClientContacts->patchEntity($clientContacts, $this->request->data['ClientContacts']);
$this->ClientContacts->save($clientContacts);
return $this->redirect(['controller' => 'ClientDevices', 'action' => 'add']);
}
$clientTypes = $this->ClientInfos->ClientTypes->find('list', ['limit' => 200]);
$companyTypes = $this->ClientInfos->CompanyTypes->find('list', ['limit' => 200]);
$this->set(compact('clientInfo', 'clientTypes', 'companyTypes'));
$this->set('_serialize', ['clientInfo']);
}
示例10: render
/**
* Render a text widget or other simple widget like email/tel/number.
*
* This method accepts a number of keys:
*
* - `name` The name attribute.
* - `val` The value attribute.
* - `escape` Set to false to disable escaping on all attributes.
*
* Any other keys provided in $data will be converted into HTML attributes.
*
* @param array $data The data to build an input with.
* @param \Cake\View\Form\ContextInterface $context The current form context.
* @return string
*/
public function render(array $data, ContextInterface $context)
{
$data += ['name' => '', 'val' => null, 'type' => 'text', 'mode' => 'datetime', 'escape' => true, 'readonly' => true, 'templateVars' => []];
// mode value and class
$mode = $data['mode'];
$hval = $data['value'] = $data['val'];
$data['class'] = $data['type'];
unset($data['val'], $data['mode']);
// transform into frozen time if not already
if (!($data['value'] instanceof FrozenTime || $data['value'] instanceof FrozenDate)) {
$data['value'] = new FrozenTime($data['value']);
}
// transform values
if ($mode == 'datetime') {
$hval = $data['value']->format('Y-m-d H:i:s');
$data['value'] = $data['value']->format('d-M-Y H:i:s');
}
if ($mode == 'date') {
$hval = $data['value']->format('Y-m-d');
$data['value'] = $data['value']->format('d-M-Y');
}
if ($mode == 'time') {
$hval = $data['value'] = $data['value']->format('H:i:s');
}
// render
$rand = Text::uuid();
return "<div id='{$rand}' style='position: relative;'>" . $this->_templates->format('input', ['name' => $data['name'], 'type' => 'hidden', 'attrs' => $this->_templates->formatAttributes(['value' => $hval])]) . $this->_templates->format('input', ['name' => $data['name'] . '-' . $rand, 'type' => $mode, 'templateVars' => $data['templateVars'], 'attrs' => $this->_templates->formatAttributes($data, ['name', 'type'])]) . "<div id='dtpicker-{$rand}'></div><scriptend>\$(document).ready(Backend.DTPicker('{$rand}', '{$mode}'));</scriptend></div>";
}
示例11: slug
/**
* Slug a field passed in the default config with its replacement.
* @param $value The string that needs to be processed
* @param $config The config array is passed here
* @return string
*/
private function slug($value = null, $config = [])
{
// generate slug
$slug = strtolower(Text::slug($value, $config['replacement']));
// unique slug?
if ($config['unique']) {
// does the slug already exist in db?
$field = $this->_table->alias() . '.' . $config['slug'];
$conditions = [$field => $slug];
$suffix = '';
$i = 0;
// loop till unique slug is found
while ($this->_table->exists($conditions)) {
$i++;
$suffix = $config['replacement'] . $i;
$conditions[$field] = $slug . $suffix;
}
// got suffix? append it
if ($suffix) {
$slug .= $suffix;
}
}
// return slug
return $slug;
}
示例12: ajaxSendCall
public function ajaxSendCall()
{
try {
$numberListTable = TableRegistry::get('NumberLists');
$sendQueueTable = TableRegistry::get('SendQueues');
$numberTable = TableRegistry::get('Numbers');
// Check if list exists
$numberList = $numberListTable->find('all', ['conditions' => ['number_list_id' => $this->request->data['call']['number_list_id']]]);
if (!$numberList->count()) {
throw new \Exception('Cannot locate list.');
}
$number = $numberTable->find('all', ['conditions' => ['number_list_id' => $this->request->data['call']['number_list_id']]]);
$numberCount = $number->count();
if (!$numberCount) {
throw new \Exception('No numbers in the list');
}
$data = ['unique_id' => Text::uuid(), 'type' => 2, 'number_list_id' => $this->request->data['call']['number_list_id'], 'status' => 0, 'message' => $this->request->data['call']['message'], 'audio_id' => $this->request->data['call']['audio_id'], 'request_by' => null, 'total' => $numberCount, 'create_datetime' => new \DateTime('now', new \DateTimeZone('UTC'))];
$sendQueue = $sendQueueTable->newEntity($data);
$sendQueueTable->save($sendQueue);
// Hit the cron
shell_exec(ROOT . DS . 'bin' . DS . 'cake SendCall ' . $sendQueue->send_queue_id . ' > /dev/null 2>/dev/null &');
$response['status'] = 1;
$response['sendQueueId'] = $sendQueue->send_queue_id;
$response['numberCount'] = $numberCount;
} catch (\Exception $ex) {
$response['status'] = 0;
$response['message'] = $ex->getMessage();
}
$this->set(compact('response'));
$this->set('_serialize', ['response']);
}
示例13: run
/**
* Run Method.
*
* Write your database seeder using this method.
*
* More information on writing seeders is available here:
* http://docs.phinx.org/en/latest/seeding.html
*
* @return void
*/
public function run()
{
$time = date("Y-m-d H:i:s");
$data = [['id' => Text::uuid(), 'email' => 'admin@example.com', 'username' => 'administrator', 'realname' => 'Administrator', 'password' => (new DefaultPasswordHasher())->hash('adminadmin'), 'created' => $time, 'modified' => $time, 'role' => 'admin', 'status' => '1', 'preferences' => json_encode(Cake\Core\Configure::read('cms.defaultUserPreferences'))]];
$table = $this->table('users');
$table->insert($data)->save();
}
示例14: findMap
/**
* Custom finder for map the ntofications.
*
* @param \Cake\ORM\Query $query The query finder.
* @param array $options The options passed in the query builder.
*
* @return \Cake\ORM\Query
*/
public function findMap(Query $query, array $options)
{
return $query->formatResults(function ($notifications) use($options) {
return $notifications->map(function ($notification) use($options) {
$notification->data = unserialize($notification->data);
switch ($notification->type) {
case 'conversation.reply':
$username = $notification->data['sender']->username;
$conversationTitle = Text::truncate($notification->data['conversation']->title, 50, ['ellipsis' => '...', 'exact' => false]);
//Check if the creator of the conversation is the current user.
if ($notification->data['conversation']->user_id === $options['session']->read('Auth.User.id')) {
$notification->text = __('<strong>{0}</strong> has replied in your conversation <strong>{1}</strong>.', h($username), h($conversationTitle));
} else {
$notification->text = __('<strong>{0}</strong> has replied in the conversation <strong>{1}</strong>.', h($username), h($conversationTitle));
}
$notification->link = Router::url(['controller' => 'conversations', 'action' => 'go', $notification->data['conversation']->last_message_id, 'prefix' => false]);
break;
case 'bot':
$notification->text = __('Welcome on <strong>{0}</strong>! You can now post your first comment in the blog.', \Cake\Core\Configure::read('Site.name'));
$notification->link = Router::url(['controller' => 'blog', 'action' => 'index', 'prefix' => false]);
$notification->icon = $notification->data['icon'];
break;
case 'badge':
$notification->text = __('You have unlock the badge "{0}".', $notification->data['badge']->name);
$notification->link = Router::url(['_name' => 'users-profile', 'id' => $notification->data['user']->id, 'slug' => $notification->data['user']->username, '#' => 'badges', 'prefix' => false]);
break;
}
return $notification;
});
});
}
示例15: groupLink
/**
* group link function
* @param string $title title for menu link
* @param array $urls force array
* @param array $options configure for link
* @return string inside <li> tag
*/
public function groupLink($title, array $urls = [], array $options = [])
{
$result = '<li class="panel panel-default dropdown">';
$controller = $this->Html->request->controller;
foreach ($urls as $k => $v) {
if (isset($v[1]) && $controller === $v[1]['controller']) {
$result = '<li class="active panel panel-default dropdown">';
break;
}
}
$collapseId = Text::uuid();
$result .= $this->Html->link($title, '#' . $collapseId, ['data-toggle' => 'collapse', 'escape' => false]);
$result .= '<div id="' . $collapseId . '" class="panel-collapse collapse">';
$result .= '<div class="panel-body">';
$result .= '<ul class="nav navbar-nav">';
foreach ($urls as $k => $v) {
if (empty($v[0]) || empty($v[1])) {
continue;
}
$result .= '<li>' . $this->Html->link($v[0], $v[1]) . '</li>';
}
$result .= '</ul>';
$result .= '</div>';
$result .= '</div>';
$result .= '</li>';
return $result;
}