예제 #1
0
 /**
  * Formats cell's content.
  * @param  mixed
  * @param  DibiRow|array
  * @return string
  */
 public function formatContent($value, $data = NULL)
 {
     $value = htmlSpecialChars($value);
     if (is_array($this->replacement) && !empty($this->replacement)) {
         if (in_array($value, array_keys($this->replacement))) {
             $value = $this->replacement[$value];
         }
     }
     foreach ($this->formatCallback as $callback) {
         if (is_callable($callback)) {
             $value = call_user_func($callback, $value, $data);
         }
     }
     // translate & truncate
     if ($value instanceof Html) {
         $text = $this->dataGrid->translate($value->getText());
         if ($this->maxLength != 0) {
             $text = String::truncate($text, $this->maxLength);
         }
         $value->setText($text);
         $value->title = $this->dataGrid->translate($value->title);
     } else {
         if ($this->maxLength != 0) {
             $value = String::truncate($value, $this->maxLength);
         }
     }
     return $value;
 }
예제 #2
0
 /**
  * Displays a table of the current modules content.
  *
  * Route: admin/multilanguage/modules/manage/:slug
  *
  * @param string $module The name of the module to get content for.
  */
 public static function manageModule($module)
 {
     $output = array();
     $content = Multilanguage::getModuleContent($module);
     if ($content) {
         foreach ($content as $type => $typeContent) {
             $table = Html::table();
             $header = $table->addHeader();
             $header->addCol('Content');
             if ($typeContent) {
                 foreach ($typeContent as $id => $data) {
                     $data = String::truncate($data, 200, '...');
                     $row = $table->addRow();
                     $row->addCol(Html::a()->get($data, 'admin/multilanguage/modules/manage/' . $module . '/' . $type . '/' . $id));
                 }
             } else {
                 $table->addRow()->addCol('<em>No content.</em>');
             }
             $output[] = array('title' => ucfirst($type) . ' Content', 'content' => $table->render());
         }
     } else {
         $output = array('title' => 'No Content', 'content' => '<p>This module has not specified any content to manage.</p>');
     }
     return $output;
 }
예제 #3
0
 public function for_display($table, $field_names, $objects)
 {
     foreach ($field_names as $field) {
         $field_info[$field] = new Field_Information(array('name' => $field, 'table' => $table));
     }
     foreach ($objects as &$object) {
         foreach ($field_info as $name => $info) {
             if ($info->options !== NULL) {
                 $exploded_options = explode("\n", $info->options);
                 foreach ($exploded_options as $option) {
                     if (!empty($option)) {
                         $option_temp = explode(',', $option);
                         $options[$option_temp[0]] = $option_temp[1];
                     }
                 }
             }
             if ($info->type !== NULL) {
                 $field_type = $info->type;
                 $object->{$name} = $this->{$field_type}($object->{$name}, $options);
             } else {
                 $object->{$name} = String::truncate(htmlspecialchars($object->{$name}), '400', '[...]');
             }
         }
     }
     return $objects;
 }
예제 #4
0
 /**
  * Returns a string of $length characters or less of the blog entry’s text
  * that can be used as excerpt. HTML-Tags and UBB-Code is stripped
  *	
  * @param $length
  * @return string
  */
 public function excerpt($length = 50)
 {
     if ($this->hasField('excerpt') && !$this->isEmpty('excerpt')) {
         return $this->excerpt;
     }
     $firstWords = preg_replace('@\\[\\[([^\\]]+)\\]\\]@', '', $this->text);
     $firstWords = String::truncate(strip_tags($firstWords), $length);
     return $firstWords;
 }
 /**
  * Main RSS example.
  *
  * @return void
  */
 public function feed()
 {
     if (empty($this->request->params['ext']) || $this->request->params['ext'] !== 'rss') {
         throw new NotFoundException();
     }
     // This is only needed without the viewClassMap setting for RequestHandler
     //$this->viewClass = 'Tools.Rss';
     $this->News = ClassRegistry::init('Sandbox.NewsRecord');
     $news = $this->News->feed();
     $items = array();
     foreach ($news as $key => $val) {
         $content = nl2br(h($val['News']['content']));
         $link = array('action' => 'feedview', $val['News']['id']);
         $guidLink = array('action' => 'view', $val['News']['id']);
         $items[] = array('title' => $val['News']['title'], 'link' => $link, 'guid' => array('url' => $guidLink, '@isPermaLink' => 'true'), 'description' => String::truncate($val['News']['content']), 'dc:creator' => $val['User']['username'], 'pubDate' => $val['News']['published'], 'content:encoded' => $content);
     }
     $atomLink = array('action' => 'feed', 'ext' => 'rss');
     $channel = array('title' => __('News/Updates') . '', 'link' => '/', 'atom:link' => array('@href' => $atomLink), 'description' => __('Most recent news articles'), 'language' => 'en-en', 'image' => array('url' => '/img/statics/logo_rss.png', 'link' => '/'));
     $data = array('document' => array(), 'channel' => $channel, 'items' => $items);
     $this->set(array('channel' => $data, '_serialize' => 'channel'));
 }
예제 #6
0
 /**
  * Displays a form for creating a new translation of the current string. Also displays a table
  * of current translations for the current string.
  *
  * Route: admin/multilanguage/strings/manage/:id
  *
  * @param int $id The id of the string to create translations for
  */
 public static function manageContent($id)
 {
     if (!($string = Multilanguage::stringcontent()->find($id))) {
         return ERROR_404;
     }
     if (isset($_POST['create_translation']) && Html::form()->validate()) {
         $tmpId = Multilanguage::string()->insert(array('stringcontent_id' => $string->id, 'language_id' => $_POST['language_id'], 'content' => $_POST['content']));
         if ($tmpId) {
             Message::ok('Translation created successfully.');
             unset($_POST['language_id']);
             // Clear selected language
         } else {
             Message::error('Error creating translation, please try again.');
         }
     }
     $langs = Multilanguage::language()->orderBy('name')->all();
     $sortedLangs = array('' => 'Choose One');
     foreach ($langs as $l) {
         $sortedLangs[$l->id] = $l->name;
     }
     $form[] = array('fields' => array('language_id' => array('title' => 'Language', 'type' => 'select', 'options' => $sortedLangs, 'validate' => array('required')), 'content' => array('title' => 'Translated String', 'type' => strlen($string->content) > 25 ? 'textarea' : 'text', 'validate' => array('required'), 'default_value' => $string->content), 'create_translation' => array('type' => 'submit', 'value' => 'Create Translation')));
     $table = Html::table();
     $header = $table->addHeader();
     $header->addCol('String');
     $header->addCol('Language', array('colspan' => 2));
     $translations = Multilanguage::string()->select('multilanguage_strings.*, multilanguage_languages.name AS language')->leftJoin('multilanguage_languages', 'multilanguage_languages.id', '=', 'multilanguage_strings.language_id')->where('multilanguage_strings.stringcontent_id', '=', $id)->orderBy('multilanguage_languages.name')->all();
     if ($translations) {
         foreach ($translations as $t) {
             $row = $table->addRow();
             $row->addCol(Html::a()->get(String::truncate($t->content, 100, '...'), 'admin/multilanguage/strings/edit/' . $id . '/' . $t->id));
             $row->addCol($t->language);
             $row->addCol(Html::a()->get('Delete', 'admin/multilanguage/strings/delete/' . $id . '/' . $t->id, array('onclick' => "return confirm('Delete this translation?')")), array('class' => 'right'));
         }
     } else {
         $table->addRow()->addCol('<em>No translations.</em>', array('colspan' => 3));
     }
     return array(array('title' => 'Create String Translation', 'content' => Html::form()->build($form)), array('title' => 'Translations', 'content' => $table->render()));
 }
예제 #7
0
 /**
  * Display attachment preview for given $field
  * 
  * @param string $field Attachment field name
  * @param array $data Form data
  * @param array $options
  * 
  * @todo Use HtmlHelper compatible display tags for html outputs
  */
 public function preview($field = null, $data = null, $options = array())
 {
     $this->setEntity($field);
     $modelKey = $this->model();
     $fieldKey = $this->field();
     $options = am(array('label' => Inflector::humanize($fieldKey), 'size' => 'default', 'actionEdit' => false, 'actionDelete' => false), $options);
     //TODO make actionUrl configurable
     $actionUrl = am(array('plugin' => $this->request->params['plugin'], 'controller' => $this->request->params['controller'], 'action' => 'attachment'), $this->request->params['named'], $this->request->params['pass'], array('model' => $modelKey, 'field' => $fieldKey));
     $attachments = $this->getAttachments($fieldKey, $data);
     $label = $out = "";
     if ($options['label']) {
         $label = $this->Html->tag('label', $options['label']);
     }
     foreach ($attachments as $attachment) {
         $_out = $_actions = "";
         //thumb
         $_out .= $this->Html->div('attachment-form-preview-thumb', $this->previewImage($attachment, array(), $options['size']));
         //name
         $_out .= $this->Html->div('attachment-form-preview-basename', $this->Html->link(String::truncate($attachment['basename'], 45), array(), array('title' => $attachment['basename'])));
         //actionEdit
         if ($options['actionEdit']) {
             $editUrl = am($actionUrl, array('cmd' => 'edit'));
             $_actions .= $this->Html->link(__('Edit'), $editUrl, array('class' => 'attachment-edit'));
         }
         //actionDelete
         if ($options['actionDelete']) {
             $deleteUrl = am($actionUrl, array('cmd' => 'delete'));
             $_actions .= $this->Html->link(__('Delete'), $deleteUrl, array('class' => 'attachment-delete'), __("Do you really want to delete the attachment '%s'", $attachment['basename']));
         }
         $_out .= $this->Html->div('attachment-form-preview-actions', $_actions);
         //wrap inner
         $_out = $this->Html->div('attachment-form-preview', $_out);
         //wrap outer
         $out .= $this->Html->div('attachment-form-preview-wrap', $_out);
     }
     return $this->Html->div('attachment-form-container', $label . $out . '<div style="clear:both;"></div>');
 }
예제 #8
0
	<div style="position: relative;" class="slideshow">
    <a href="projects.php" title="View our Projects"><img src="images/banners/banner1.jpg" alt="" /></a>
    <a href="projects.php" title="View our Projects"><img src="images/banners/banner2.jpg" alt="" /></a>
    <a href="projects.php" title="View our Projects"><img src="images/banners/banner4.jpg" alt="" /></a>
	</div>


</div>
<div class="sidebar">
<div class="overlap">

<div class="readmoreimg"><a href="about.php"><img src="images/readmore.png" alt="Read More..." title="Read More &rarr;" /></a></div>

<?php 
echo String::truncate(BasicCms::block('about'), 500, '');
?>

<!--<div class="readmore"><a href="">Read More</a> &rarr;</div>-->

</div>
</div>
<div class="banners" style="border-right: 1px solid #b5b5b5;">

<a href="about.php"><img src="images/banners/aboutus.jpg" title="About Champion Builders, Inc." alt="" /></a>
<a href="services.php"><img src="images/banners/services.jpg" title="View our List of Services" alt="" /></a>
<a href="projects.php"><img src="images/banners/projects.jpg" title="View our Projects" alt="" /></a>
<a href="quote.php"><img src="images/banners/quote.jpg" title="Get a Quote" alt="" /></a>
<a href="kirby.php"><img src="images/banners/kirby.jpg" title="Kirby Building Systems Authorized Supplier" alt="" /></a>
<a href="employment.php"><img src="images/banners/employment.jpg" title="Want to work with Champion?" alt="" /></a>
예제 #9
0
      <th>Date Submitted</th>
    </tr>
    <?php 
foreach ($paginator->this_page() as $contact) {
    ?>
    <tr>
      <td><?php 
    echo $contact->name;
    ?>
</td>
      <td><?php 
    echo $contact->email;
    ?>
</td>
      <td><?php 
    echo String::truncate($contact->subject, 30);
    ?>
</td>
      <td><?php 
    echo $contact->created_at;
    ?>
</td>
			<td><a href="show.php?id=<?php 
    echo $contact->id;
    ?>
">Show</a></td>
    </tr>
    <?php 
}
?>
  </table>
예제 #10
0
<div id="header">
	<span class="fl">
		<?php 
echo $HTML->link(Router::getRoute('root'), __('← zurück'), array('class' => 'button', 'title' => __('Den Admin verlassen und zur Website wechseln')));
?>
		<?php 
echo $HTML->link(Router::getRoute('admin'), Sanitizer::HTML(__('Administration :1', String::truncate(AppController::NAME, 40, '…'))));
?>
	</span>
	<span class="fr">
		<?php 
echo __('Eingeloggt als: :1 :2', $HTML->link($Me->adminDetailPageUri(), $Me->get('name')), $HTML->link(Router::getRoute('adminLogout'), __('logout'), array('class' => array('button', 'red'))));
?>
	</span>
</div>
예제 #11
0
 public function beforeRender()
 {
     // Site wide layout variables
     $page_title_segments = $this->page_data['page_title'];
     $this->page_data['page_id'] = $this->request->params['controller'] . '-' . md5($this->page_data['page_id']);
     $this->page_data['page_title'] = implode(' &ndash; ', array_reverse($page_title_segments));
     $this->page_data['page_image'] = Router::url($this->page_data['page_image'], true) . '?' . filemtime('.' . $this->page_data['page_image']);
     $this->page_data['page_description'] = String::truncate(strip_tags($this->page_data['page_description']), 200, array('ellipsis' => '…'));
     $this->page_data['page_url'] = Router::url(null, true);
     // Facebook
     $this->page_data['opengraph']['og:url'] = Router::url($this->here, true);
     $this->page_data['opengraph']['og:title'] = $this->page_data['page_title'];
     $this->page_data['opengraph']['og:description'] = $this->page_data['page_description'];
     $this->page_data['opengraph']['og:image'] = Router::url('/img/share.jpg', true) . '?' . filemtime('./img/share.jpg');
     $this->page_data['opengraph']['fb:app_id'] = Configure::read('Facebook.appId');
     // Set body id
     if ($this->name == 'CakeError') {
         $this->page_data['body_id'] = 'error';
     } else {
         $this->page_data['body_id'] = strtolower("{$this->name}-{$this->action}");
     }
     if (isset($this->params['admin'])) {
         $this->layout = 'admin';
         // Role
         $role = Configure::read('App.env') == 'development' ? 'superadmin' : $this->currentUser['Group']['name'];
         $this->page_data['role'] = $role;
         $this->page_data['admin_menu'] = $this->getAdminMenu($role);
     } else {
     }
     $this->set($this->page_data);
     return parent::beforeRender();
 }
예제 #12
0
파일: text.php 프로젝트: ToddBudde/phrails
/**
 * @see String::$truncate()
 **/
function truncate($string, $limit, $pad = '...', $break = '.')
{
    return String::truncate($string, $limit, $pad, $break);
}
예제 #13
0
 /**
  * truncate test.
  * @return void
  */
 public function testTruncate()
 {
     iconv_set_encoding('internal_encoding', 'UTF-8');
     $s = "Řekněte, jak se (dnes) máte?";
     // Řekněte, jak se (dnes) máte?
     $this->assertEquals("…", String::truncate($s, -1), "length=-1");
     $this->assertEquals("…", String::truncate($s, 0), "length=0");
     $this->assertEquals("…", String::truncate($s, 1), "length=1");
     $this->assertEquals("Ř…", String::truncate($s, 2), "length=2");
     $this->assertEquals("Ře…", String::truncate($s, 3), "length=3");
     $this->assertEquals("Řek…", String::truncate($s, 4), "length=4");
     $this->assertEquals("Řekn…", String::truncate($s, 5), "length=5");
     $this->assertEquals("Řekně…", String::truncate($s, 6), "length=6");
     $this->assertEquals("Řeknět…", String::truncate($s, 7), "length=7");
     $this->assertEquals("Řekněte…", String::truncate($s, 8), "length=8");
     $this->assertEquals("Řekněte,…", String::truncate($s, 9), "length=9");
     $this->assertEquals("Řekněte,…", String::truncate($s, 10), "length=10");
     $this->assertEquals("Řekněte,…", String::truncate($s, 11), "length=11");
     $this->assertEquals("Řekněte,…", String::truncate($s, 12), "length=12");
     $this->assertEquals("Řekněte, jak…", String::truncate($s, 13), "length=13");
     $this->assertEquals("Řekněte, jak…", String::truncate($s, 14), "length=14");
     $this->assertEquals("Řekněte, jak…", String::truncate($s, 15), "length=15");
     $this->assertEquals("Řekněte, jak se…", String::truncate($s, 16), "length=16");
     $this->assertEquals("Řekněte, jak se …", String::truncate($s, 17), "length=17");
     $this->assertEquals("Řekněte, jak se …", String::truncate($s, 18), "length=18");
     $this->assertEquals("Řekněte, jak se …", String::truncate($s, 19), "length=19");
     $this->assertEquals("Řekněte, jak se …", String::truncate($s, 20), "length=20");
     $this->assertEquals("Řekněte, jak se …", String::truncate($s, 21), "length=21");
     $this->assertEquals("Řekněte, jak se (dnes…", String::truncate($s, 22), "length=22");
     $this->assertEquals("Řekněte, jak se (dnes)…", String::truncate($s, 23), "length=23");
     $this->assertEquals("Řekněte, jak se (dnes)…", String::truncate($s, 24), "length=24");
     $this->assertEquals("Řekněte, jak se (dnes)…", String::truncate($s, 25), "length=25");
     $this->assertEquals("Řekněte, jak se (dnes)…", String::truncate($s, 26), "length=26");
     $this->assertEquals("Řekněte, jak se (dnes)…", String::truncate($s, 27), "length=27");
     $this->assertEquals("Řekněte, jak se (dnes) máte?", String::truncate($s, 28), "length=28");
     $this->assertEquals("Řekněte, jak se (dnes) máte?", String::truncate($s, 29), "length=29");
     $this->assertEquals("Řekněte, jak se (dnes) máte?", String::truncate($s, 30), "length=30");
     $this->assertEquals("Řekněte, jak se (dnes) máte?", String::truncate($s, 31), "length=31");
     $this->assertEquals("Řekněte, jak se (dnes) máte?", String::truncate($s, 32), "length=32");
 }
예제 #14
0
 /**
  * Format the filename a specific way before uploading and attaching.
  * 
  * @access public
  * @param string $name	- The current filename without extension
  * @param string $field	- The form field name
  * @param array $file	- The $_FILES data
  * @return string
  */
 function formatFileName($name, $field, $file)
 {
     $file = pathinfo($name);
     $name = String::truncate($file['filename'], 20);
     return Inflector::slug($name) . '_' . uniqid();
 }
예제 #15
0
<?php

if (!empty($BlogPosts)) {
    foreach ($BlogPosts as $entry) {
        $text = $BlogPostFormater->format($entry->text);
        if ($entry->isEmpty('headline')) {
            $headline = String::truncate(strip_tags($text), 60, '…');
        } else {
            $headline = strip_tags($entry->get('headline'));
        }
        ?>
	<item>
		<title><?php 
        echo strtr($headline, array('&' => '&#x26;'));
        ?>
</title>
		<pubDate><?php 
        echo date('r', $entry->published);
        ?>
</pubDate>
		<description><![CDATA[<?php 
        echo $text;
        ?>
]]></description>
		<content:encoded><![CDATA[<?php 
        echo $text;
        ?>
<!-- p52h7fmk9e -->]]></content:encoded>
		<guid isPermaLink="true"><?php 
        echo $entry->detailPageURL();
        ?>
예제 #16
0
파일: node.php 프로젝트: Ephigenia/harrison
		<?php 
$nodeName = $Node->getText('headline', null, $Node->get('name'));
if (empty($nodeName)) {
    $nodeName = __('(kein Name)');
}
$nodeName = String::truncate($nodeName, 50, '…', false, true);
if ($Node->hasFlags(NodeFlag::ALLOW_EDIT) || $Me->user_group_id == 1) {
    echo $HTML->link($Node->adminDetailPageUri('edit'), $nodeName);
} else {
    echo Sanitizer::html($nodeName);
}
?>
<br />
		<p>
			<?php 
echo String::truncate(strip_tags($Node->getText('text')), 300, '…');
?>
		</p>
	</td>
	<?php 
if (!empty($showPadding)) {
    ?>
		<td class="created">
			<span class="time" datetime="<?php 
    echo date('c', $nodeTimestamp);
    ?>
">
				<?php 
    echo strftime('%x %H:%M', $nodeTimestamp);
    ?>
			</span>
예제 #17
0
 /**
  * @depends testToString
  *
  */
 public function testTruncate()
 {
     $o = new String(self::MULTI_LINE);
     $this->assertEquals('What is? This...', (string) $o->truncate(15));
     $o = new String(self::MY_STRING);
     $this->assertEquals('...', (string) $o->truncate(15));
 }
예제 #18
0
?>
</h1>
<ul class="breadcrumb">
	<li><?php 
echo $HTML->link(Router::getRoute('admin'), __('Home'));
?>
</li>
	<?php 
if (!empty($BlogPost)) {
    ?>
	<li><?php 
    echo $HTML->link(Router::getRoute('adminBlogPost'), __('Blog'));
    ?>
</li>
	<li><?php 
    echo $HTML->link($BlogPost->adminDetailPageUri(), String::truncate($BlogPost->get('headline'), 20, '…'));
    ?>
</li>
	<?php 
}
?>
	<li><?php 
echo __('Kommentare');
?>
</li>
</ul>

<?php 
if (empty($Comments)) {
    echo $HTML->p(__('Es sind noch keine Kommentare vorhanden.'), array('class' => 'hint'));
} else {
예제 #19
0
 /**
  * Replace truncate tags by result of `String::truncate()`.
  *
  * Examples:
  *  - [truncate]A very long string[/truncate]
  *  - [truncate length=8][User.email][/truncate]
  *  - [truncate length=[php]return strlen([User.email]) - 4;[/php]][User.email][/truncate]
  *  - [truncate ellipsis="...."]Another string[/truncate]
  *
  * @param string $str String to check and modify.
  * @return string Modified string.
  */
 protected function _replaceTruncate($str)
 {
     if (!preg_match_all('/\\[truncate(.*?)\\](.*)\\[\\/truncate\\]/i', $str, $matches)) {
         // Fallback regex for when no options are passed.
         if (!preg_match_all('/\\[truncate(.*?)\\](.[^\\[]*)\\[\\/truncate\\]/i', $str, $matches)) {
             return $str;
         }
     }
     foreach ($matches[0] as $i => $find) {
         $opts = $this->_extractAttributes(trim($matches[1][$i]));
         $length = 100;
         if (isset($opts['length'])) {
             $length = $opts['length'];
             unset($opts['length']);
         }
         $replace = empty($matches[2][$i]) ? '' : String::truncate($matches[2][$i], $length, $opts);
         $str = str_replace($find, $replace, $str);
     }
     return $str;
 }
예제 #20
0
?>
</h1>
<ul class="breadcrumb">
	<li><?php 
echo $HTML->link(Router::getRoute('admin'), __('Home'));
?>
</li>
	<?php 
// upload into a folder aka category
if (isset($Folder)) {
    echo $HTML->tag('li', $HTML->link(Router::getRoute('adminMediaFiles'), __('Dateien & Bilder')));
    echo $HTML->tag('li', $HTML->link($Folder->adminDetailPageUri(), $Folder->get('name')));
    // upload into a node
} elseif (isset($Node)) {
    echo $HTML->tag('li', $HTML->link(Router::getRoute('adminNode'), __('Seiten')));
    echo $HTML->tag('li', $HTML->link($Node->adminDetailPageUri(array('action' => 'edit')), String::truncate($Node->getText('headline', $Node->get('name')), 40, '…')));
} else {
    echo $HTML->tag('li', $HTML->link(Router::getRoute('adminMediaFiles'), __('Dateien & Bilder')));
}
?>
	<li><?php 
echo __('Datei hochladen');
?>
</li>
</ul>

<p class="hint">
	<?php 
echo __('Bitte beachten Sie beim Hochladen von Bildern, dasss diese nicht größer als <em>1024x1024 Pixel</em> sein sollten.');
?>
	<?php 
예제 #21
0
} else {
    $username = $gravatar . ' ' . Sanitizer::html($Comment->get('name'));
}
?>
		<cite><?php 
echo $username;
?>
</cite>
		<?php 
if ($Comment->hasField('ip') && !$Comment->isEmpty('ip')) {
    ?>
			<abbr class="ip" title="<?php 
    echo __('IP Adresse des Benutzers.');
    ?>
">(<?php 
    echo long2ip($Comment->ip);
    ?>
)</abbr>
		<?php 
}
?>
		<?php 
echo $HTML->link($Comment->BlogPost->detailPageUri(), $Comment->BlogPost->get('headline', 'BlogPost ' . $Comment->BlogPost->id));
?>
		<p>
			<?php 
echo wordwrap(String::truncate($Comment->text, 400, '…'), 30, LF, true);
?>
		</p>
	</td>
</tr>
예제 #22
0
 /**
  * Echoes array of associative arrays formatted as table
  * @param array $data
  * @param int $width
  * @return boolean
  */
 public static function table($data, $width = false)
 {
     $columns = array();
     foreach ($data as $row) {
         foreach ($row as $key => $value) {
             if (!in_array($key, $columns)) {
                 $columns[] = $key;
             }
         }
     }
     $columnsCount = count($columns);
     $dataCount = count($data);
     if ($colsSizePercentage) {
         if (count($colsSizePercentage) != $columnsCount) {
             self::error(String::build('Columns count did not match'));
             return false;
         }
         if (($precentage = array_sum($colsSizePercentage)) != 100) {
             self::error(String::build('Table size percentage is incorrect. ' . $precentage . '% received'));
             return false;
         }
     }
     $consoleSize = array('x' => $width ? $width : exec("tput cols"), 'y' => exec("tput lines"));
     $colWidth = ($consoleSize['x'] - $columnsCount) / $columnsCount;
     $tableParams = array('connector' => '#', 'borderX' => '-', 'borderY' => '|');
     /**
      * Header
      */
     self::write($tableParams['connector']);
     for ($i = 0; $i < $columnsCount; $i++) {
         self::write(str_repeat($tableParams['borderX'], $colWidth) . $tableParams['connector']);
     }
     self::write(PHP_EOL);
     foreach ($columns as $key => $value) {
         $whitespaceCount = $colWidth - strlen($value);
         $whitespaceCountHalf = floor($whitespaceCount / 2);
         self::write($tableParams['borderY'] . str_repeat(' ', $whitespaceCountHalf) . strtoupper($value) . str_repeat(' ', $whitespaceCount - $whitespaceCountHalf));
     }
     self::write($tableParams['borderY'] . PHP_EOL);
     self::write($tableParams['connector']);
     for ($i = 0; $i < $columnsCount; $i++) {
         self::write(str_repeat($tableParams['borderX'], $colWidth) . $tableParams['connector']);
     }
     self::write(PHP_EOL);
     /**
      * Body
      */
     for ($i = 0; $i < $dataCount; $i++) {
         for ($j = 0; $j < $columnsCount; $j++) {
             $value = String::truncate($data[$i][$columns[$j]], $colWidth);
             $whitespaceCount = $colWidth - strlen($value);
             self::write($tableParams['borderY'] . $value . str_repeat(' ', $whitespaceCount));
         }
         self::write($tableParams['borderY'] . PHP_EOL);
     }
     /**
      * Footer
      */
     self::write($tableParams['connector']);
     for ($i = 0; $i < $columnsCount; $i++) {
         self::write(str_repeat($tableParams['borderX'], $colWidth) . $tableParams['connector']);
     }
     self::write(PHP_EOL);
     return true;
 }
 public function ellipsis($string, $length = '30')
 {
     return String::truncate($string, $length, array('ellipsis' => '...', 'exact' => false));
 }
예제 #24
0
	<h4>
		<?php 
    echo $HTML->link($Comment->BlogPost->detailPageUri() . '#Comments', $Comment->BlogPost->get('headline'));
    ?>
	</h4>
	<?php 
}
?>
	<h3>
		<?php 
echo $this->element('gravatar', array('email' => $Comment->get('email'), 'size' => $avatarSize));
echo date(__('d.m.Y H:i'), $Comment->created) . '<br />';
if ($Comment->url) {
    echo $HTML->link('http://' . $Comment->url, $Comment->get('name'), array('rel' => 'external'));
} else {
    echo $Comment->get('name');
}
?>
	</h3><br />
	<?php 
$text = $Comment->text;
$text = Sanitizer::html($text);
$text = nl2br($text);
$text = Text::autoURLs($text);
$text = String::wrap($text, 55, true);
if (isset($truncated)) {
    $text = String::truncate($text, $truncated !== true ? $truncated : 120, '…');
}
echo Sanitizer::html($text);
?>
</li>
예제 #25
0
    public function testReplaceTruncate()
    {
        $text = <<<TXT
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
TXT;
        $result = $this->Table->replaceTruncate("[truncate]{$text}[/truncate]");
        $expected = String::truncate($text);
        $this->assertEqual($result, $expected);
        $result = $this->Table->replaceTruncate("[truncate length=10]{$text}[/truncate]");
        $expected = String::truncate($text, 10);
        $this->assertEqual($result, $expected);
        $result = $this->Table->replaceTruncate("[truncate length=20 ellipsis=.....]{$text}[/truncate]");
        $expected = String::truncate($text, 20, array('ellipsis' => '.....'));
        $this->assertEqual($result, $expected);
        $result = $this->Table->replaceTruncate("[truncate length=30 foo=bar]{$text}[/truncate]");
        $expected = String::truncate($text, 30);
        $this->assertEqual($result, $expected);
    }