/** * Render view. * * @return string */ public function content() { ob_start(); $foursquare = $this->venue->foursquare(); if (!$foursquare) { echo new View_Alert(__('This venue has not been linked to Foursquare yet.'), null, View_Alert::INFO); } else { // Homepage echo HTML::anchor(Arr::path($foursquare, 'short_url'), HTML::image(Arr::path($foursquare, 'primarycategory.iconurl'), array('alt' => HTML::chars(Arr::path($foursquare, 'primarycategory.nodename')), 'title' => HTML::chars(Arr::path($foursquare, 'primarycategory.nodename')))) . ' ' . HTML::chars(Arr::path($foursquare, 'primarycategory.nodename'))), '<br />'; // Mayor if ($mayor = Arr::path($foursquare, 'stats.mayor.user')) { echo __('Mayor: :mayor, :city', array(':mayor' => HTML::anchor('http://foursquare.com/user/' . Arr::get($mayor, 'id'), HTML::chars(Arr::get($mayor, 'firstname')) . ' ' . HTML::chars(Arr::get($mayor, 'lastname'))), ':city' => HTML::chars($mayor['homecity']))), '<br />'; } // Checkins echo __('Check-ins: :checkins', array(':checkins' => '<var>' . Arr::path($foursquare, 'stats.checkins') . '</var>')), '<br />'; // Here now echo __('Here now: :herenow', array(':herenow' => '<var>' . Arr::path($foursquare, 'stats.herenow') . '</var>')), '<br />'; // Tips if ($tips = Arr::path($foursquare, 'tips')) { echo '<h5>', __('Tips (:tips)', array(':tips' => '<var>' . count($tips) . '</var>')), '</h5><dl>'; foreach (array_slice($tips, 0, 5) as $tip) { echo '<dt>', HTML::anchor('http://foursquare.com/user/' . Arr::path($tip, 'user.id'), HTML::chars(Arr::path($tip, 'user.firstname')) . ' ' . HTML::chars(Arr::path($tip, 'user.lastname'))), ', ', HTML::chars(Arr::path($tip, 'user.homecity')), ':</dt>'; echo '<dd>', Text::auto_p(HTML::chars(Arr::path($tip, 'text'))), '</dd>'; } echo '</dl>'; } } // Admin controls if (Permission::has($this->venue, Model_Venue::PERMISSION_UPDATE)) { echo HTML::anchor('#map', __('Link to Foursquare'), array('class' => 'action', 'id' => 'link-foursquare')); echo $this->form(); } return ob_get_clean(); }
/** * Render content. * * @return string */ public function content() { ob_start(); if ($this->track->description) { echo BB::factory($this->track->description)->render(); } if ($this->track->tracklist) { echo '<h3>Tracklist</h3>'; echo Text::auto_p(HTML::chars($this->track->tracklist)); } return ob_get_clean(); }
/** * Render view. * * @return string */ public function content() { ob_start(); // Line-up if ($this->event->dj) { ?> <p class="dj"> <h3><?php echo __('Line-up'); ?> </h3> <?php echo Text::auto_p(HTML::chars($this->event->dj)); ?> </p> <?php } echo HTML::anchor(Route::url('galleries', array('action' => 'upload')) . '?from=' . $this->event->id, __('Continue'), array('class' => 'action')); return ob_get_clean(); }
/** * Render content. * * @return string */ public function content() { ob_start(); if ($this->event->dj) { ?> <div class="dj"> <h3><?php echo __('Line-up'); ?> </h3> <?php echo Text::auto_p(HTML::chars($this->event->dj)); ?> </div> <?php } if ($this->event->info) { ?> <div class="extra-info"> <h3><?php echo __('Extra info'); ?> </h3> <?php echo BB::factory($this->event->info)->render(); ?> </div> <?php } return ob_get_clean(); }
public function render() { $this->template->errors = FALSE; $this->template->body = FALSE; $this->template->author = FALSE; $this->template->email = FALSE; $this->template->limited = FALSE; $this->template->user = Auth::instance()->get_user(); $page = $this->request->query('model'); $this->template->page = $page; $request = Request::initial(); if ($request->method() == 'POST') { if ($request->post('action') == 'delete') { if (Auth::instance()->logged_in('admin')) { $id = $request->post('id'); $comment = ORM::factory('comment', $id); $comment->delete(); $page->decrement_comments_count(); } else { throw new HTTP_Exception_403('You are not allowed to proceed this action'); } } elseif ($request->post('action') == 'edit') { if (Auth::instance()->logged_in('admin')) { $id = $request->post('id'); $body = strip_tags($request->post('value')); $comment = ORM::factory('comment', $id); $comment->body = $body; $comment->update(); $this->template = NULL; $body = Text::auto_p($body); // FIX: злобный хак, нужно как-нибудь исправить echo $body; die; } else { throw new HTTP_Exception_403('You are not allowed to proceed this action'); } } elseif ($request->post('hello_bots') != '') { $comment = ORM::factory('comment'); $hash = $request->post('hello_bots'); if (Security::check($hash)) { if ($user = Auth::instance()->get_user()) { $comment->user = $user; $comment->email = $user->email; } else { $comment->email = $request->post('email'); } $comment->body = $request->post('body'); $comment->author = $request->post('author'); $comment->topic = $request->post('comment_subscribe'); $comment->ip = ip2long(Request::$client_ip); $comment->page = $page; try { $comment->save(); $page->comments_count = $page->comments_count + 1; $page->update(); $subscribers = $page->comments->subscribers($page->id); foreach ($subscribers as $subscriber) { $data = array('sub_email' => $subscriber->email, 'sub_name' => $subscriber->author, 'page_url' => substr(URL::base('http'), 0, -1) . $this->template->uri($page), 'page_title' => $page->title, 'com_body' => $comment->body, 'com_name' => $comment->author); Queue::instance()->add('comment', $data); } } catch (ORM_Validation_Exception $exception) { $this->template->errors = $exception->errors('validation'); $this->template->body = $comment->body; $this->template->author = $comment->author; $this->template->email = $comment->email; } } } $this->template->hello_bots = Security::token(TRUE); } else { $this->template->hello_bots = Security::token(FALSE); } $per_page = $this->_per_page; $comment_page = $request->param('comment_page', 1); list($count, $comments) = $page->comments->fetch($comment_page, $comment_page, $per_page); $this->template->count = $count; $this->template->comments = $comments; $pagination_config = array('current_page' => array('source' => 'route', 'key' => 'comment_page'), 'items_per_page' => $per_page, 'total_items' => $count, 'view' => 'floating'); $_request = clone Request::$current; Request::$current = clone Request::$initial; $this->template->pager = Pagination::factory($pagination_config)->render(); Request::$current = clone $_request; unset($_request); }
</li> <?php } ?> </ul> <?php } ?> <?php if (!empty($codebench['description'])) { ?> <?php echo Text::auto_p(Text::auto_link($codebench['description']), FALSE); ?> <?php } ?> <?php // echo '<h2>Raw output:</h2>', Kohana::debug($codebench) ?> <?php } ?> <p id="footer"> Page executed in <strong><?php
<br> <?php echo Text::auto_link_urls('My email is someone@somewhere.ca and my web site is www.kohanaphp.com'); ?> <br> <?php echo Text::auto_link_emails('My email is someone@somewhere.ca and my web site is www.kohanaphp.com'); ?> <br/> <?php $string = "This is a block of\ntext that has\n\nSome line breaks in it."; echo Text::auto_p($string); ?> <br/> <pre> <?php echo "Simple:<br/>"; echo Text::bytes(5500), "\n"; echo Text::bytes(17139812000), "\n\n"; // Maximum unit echo "Max units in MB:\n"; echo Text::bytes(81620000000, 'MB'), "\n\n"; // 4 decimal accuracy echo "4 decimals:\n"; echo Text::bytes(91711816100, null, '%01.4f %s', TRUE), "\n\n";
public static function auto_p($string, $br = TRUE) { return Text::auto_p($string, $br = TRUE); }
/** * Action index */ public function action_index() { // Get id from param, if there is nothing then throw to 404 $division_segment = $this->request->param('division'); if (!$division_segment) { throw HTTP_Exception::factory(404); } $division = Tbl::factory('divisions')->where('segment', '=', $division_segment)->read(1); if (!$division) { throw HTTP_Exception::factory(404); } /* * Build columns */ // <editor-fold defaultstate="collapsed" desc="Build columns"> // Get order $query = $this->request->query(); $order_column = Arr::get($query, 'order_column', 'order'); $order_direction = Arr::get($query, 'order_direction', 'ASC'); $columns = array('id' => array('name' => 'id', 'order_column' => 'id', 'order_direction' => 'ASC'), 'title' => array('name' => 'title', 'order_column' => 'title', 'order_direction' => 'ASC'), 'segment' => array('name' => 'segment', 'order_column' => 'segment', 'order_direction' => 'ASC'), 'username' => array('name' => 'username', 'order_column' => 'username', 'order_direction' => 'ASC'), 'issued' => array('name' => 'issued', 'order_column' => 'issued', 'order_direction' => 'ASC'), 'created' => array('name' => 'created', 'order_column' => 'created', 'order_direction' => 'ASC'), 'order' => array('name' => 'order', 'order_column' => 'order', 'order_direction' => 'ASC'), 'activate' => array('name' => 'activate', 'order_column' => 'is_active', 'order_direction' => 'ASC'), 'send_comment_is_on' => array('name' => 'send_comment_is_on', 'order_column' => 'send_comment_is_on', 'order_direction' => 'ASC')); foreach ($columns as &$column) { if (isset($column['order_column'])) { if ($column['order_column'] == $order_column) { $column['current'] = TRUE; if ($order_direction == 'ASC') { $column['order_direction'] = 'DESC'; $column['current_asc'] = TRUE; } else { $column['order_direction'] = 'ASC'; $column['current_desc'] = TRUE; } } $column['url'] = URL::base(TRUE) . Request::current()->uri() . URL::query(array('order_column' => $column['order_column'], 'order_direction' => $column['order_direction']), FALSE); } } // </editor-fold> /* * If post create */ // <editor-fold defaultstate="collapsed" desc="If post create"> $create = array(); if ($this->request->post('create')) { // Build data $create['division_id'] = $division->id; $create['image_id'] = NULL; $create['user_id'] = $this->logged_in_user->id; $create['segment'] = $this->request->post('create_segment'); $create['title'] = $this->request->post('create_title'); $create['issued'] = $this->request->post('create_issued') ?: Date::formatted_time(); $create['created'] = Date::formatted_time(); $create['send_comment_is_on'] = $this->settings->send_comment_is_on_default; // Database transaction start Database::instance()->begin(); // Try try { // Create $item = Tbl::factory('items')->create($create); // Create items_fields $field_ids = Tbl::factory('fields')->where('division_id', '=', $item->division_id)->read()->as_array(NULL, 'id'); foreach ($field_ids as $field_id) { Tbl::factory('items_fields')->create(array('item_id' => $item->id, 'field_id' => $field_id, 'value' => NULL)); } // Create file Cms_Helper::set_file($item->segment, $this->settings->item_dir . '/' . $division->segment, 'item content'); // make image dir // images dirにitem segment名でディレクトリを作成 Cms_Helper::make_dir($item->segment, $this->settings->image_dir . '/item/' . $division->segment); // Database commit Database::instance()->commit(); // Clear create $create['segment'] = NULL; $create['title'] = NULL; $create['issued'] = NULL; // Add success notice Notice::add(Notice::SUCCESS, Kohana::message('general', 'create_success')); } catch (HTTP_Exception_302 $e) { $this->redirect($e->location()); } catch (Validation_Exception $e) { // Database rollback Database::instance()->rollback(); // Add validation notice Notice::add(Notice::VALIDATION, Kohana::message('general', 'create_failed'), NULL, $e->errors('validation')); } catch (Exception $e) { // Database rollback Database::instance()->rollback(); // Add error notice Notice::add(Notice::ERROR); } } // </editor-fold> /* * Get items */ // <editor-fold defaultstate="collapsed" desc="Get items"> // authority is edit if ($this->logged_in_user->role == 'edit') { // Get all items $all_items = Tbl::factory('items')->select('items.*')->select('users.username')->join('users', 'LEFT')->on('items.user_id', '=', 'users.id')->where('division_id', '=', $division->id)->where('users.id', '=', $this->logged_in_user->id)->order_by($order_column, $order_direction)->read()->as_array(); } elseif ($this->logged_in_user->role == 'direct' or $this->logged_in_user->role == 'admin') { // Get all items $all_items = Tbl::factory('items')->select('items.*')->select('users.username')->join('users', 'LEFT')->on('items.user_id', '=', 'users.id')->where('division_id', '=', $division->id)->order_by($order_column, $order_direction)->read()->as_array(); } else { $all_items = array(); } // Pagenate $pagenate = Pgn::factory(array('total_items' => count($all_items), 'items_per_page' => $this->settings->pagenate_items_per_page_for_items, 'follow' => $this->settings->pagenate_items_follow_for_items)); // Paginated items $items = array_slice($all_items, $pagenate->offset, $pagenate->items_per_page); foreach ($items as $item) { // Get division $division = Tbl::factory('divisions')->where('id', '=', $item->division_id)->read(1); // Get main image $item->main_image = Tbl::factory('images')->where('id', '=', $item->image_id)->read(1); if ($item->main_image) { $item->main_image->path = URL::site("imagefly", 'http') . '/item/' . $division->segment . '/' . $item->segment . '/'; $item->main_image->file = '/' . $item->main_image->segment . $item->main_image->ext; } // Get categories $item->categories = Tbl::factory('categories')->select('categories.*')->join('items_categories')->on('categories.id', '=', 'items_categories.category_id')->where('items_categories.item_id', '=', $item->id)->read()->as_array(); // Get received comments $item->received_commnets_count = count(Tbl::factory('received_comments')->where('item_id', '=', $item->id)->read()->as_array(NULL, 'id')); // Set to item $item->issued = $item->issued ? Date::formatted_time($item->issued, 'Y-n-j h:i') : $item->issued; $item->created = $item->created ? Date::formatted_time($item->created, 'Y-n-j h:i') : $item->created; $item->summary = Text::auto_p($item->summary); $item->edit_url = URL::site("{$this->settings->backend_name}/items/{$division->segment}/edit/{$item->id}", 'http'); $item->delete_url = URL::site("{$this->settings->backend_name}/items/{$division->segment}/delete/{$item->id}", 'http'); } // </editor-fold> /** * If post update */ // <editor-fold defaultstate="collapsed" desc="If post update"> if ($this->request->post('update')) { $post = $this->request->post(); // Set post to item foreach ($items as $item) { $item->order = isset($post['order'][$item->id]) ? $post['order'][$item->id] : 0; $item->is_active = isset($post['is_active'][$item->id]) ? $post['is_active'][$item->id] : 0; $item->send_comment_is_on = isset($post['send_comment_is_on'][$item->id]) ? $post['send_comment_is_on'][$item->id] : 0; } // Database transaction start Database::instance()->begin(); // Try try { // Update foreach ($items as $item) { Tbl::factory('items')->get($item->id)->update(array('order' => isset($post['order'][$item->id]) ? $post['order'][$item->id] : 0, 'is_active' => isset($post['is_active'][$item->id]) ? $post['is_active'][$item->id] : 0, 'send_comment_is_on' => isset($post['send_comment_is_on'][$item->id]) ? $post['send_comment_is_on'][$item->id] : 0)); } // Database commit Database::instance()->commit(); // Add success notice Notice::add(Notice::SUCCESS, Kohana::message('general', 'update_success')); // Todo::1 取得しなおし? $this->redirect(URL::site("{$this->settings->backend_name}/items/{$division->segment}", 'http')); } catch (HTTP_Exception_302 $e) { $this->redirect($e->location()); } catch (Validation_Exception $e) { // Database rollback Database::instance()->rollback(); // Add validation notice Notice::add(Notice::VALIDATION, Kohana::message('general', 'update_success'), NULL, $e->errors('validation')); } catch (Exception $e) { // Database rollback Database::instance()->rollback(); // Add error notice Notice::add(Notice::ERROR, $e->getMessage()); } } // </editor-fold> // local_menusの修正 $this->local_menus = array($this->local_menus['index']); /** * View */ // <editor-fold defaultstate="collapsed" desc="View"> $this->partials['pagenate'] = Tpl::get_file('pagenate', $this->settings->back_tpl_dir); $content_file = Tpl::get_file('index', $this->settings->back_tpl_dir . '/items', $this->partials); $this->content = Tpl::factory($content_file)->set('division', $division)->set('columns', $columns)->set('items', $items)->set('create', $create)->set('pagenate', $pagenate); // </editor-fold> }
<?php defined('SYSPATH') or die('No direct access allowed.'); /** * Event info * * @package Galleries * @author Antti Qvickström * @copyright (c) 2010 Antti Qvickström * @license http://www.opensource.org/licenses/mit-license.php MIT license */ if (!isset($event) || !$event->loaded()) { echo __('No event selected.'); return; } ?> <?php if ($event->dj) { ?> <article class="dj"> <?php echo Text::auto_p(HTML::chars($event->dj)); ?> </article> <?php } ?> <?php echo HTML::anchor(Route::get('galleries')->uri(array('action' => 'upload')) . '?from=' . $event->id, __('Continue'), array('class' => 'action'));
<p> <a href="#reply" class="reply-button right"><img src="/i/reply_button.png" alt="Ответить" /></a> <?php echo Helper::filter($comment->get_user_link(), Helper::COMMENT); ?> — <span class="comment_time small gray"><?php echo Date::formatted_time($comment->date, 'd/m/Y, H:i'); ?> </span> <div class="clear"></div> </p> <div class="comment-body"> <?php echo Text::auto_p(Helper::filter($comment->body, Helper::COMMENT)); ?> </div> </div> <div class="clear"></div> </li> <?php } ?> </ul> <div id="pager"> <?php echo $this->pager; ?> </div>
<div class="meedlegray">Интересы:</div> <?php echo Text::auto_p(Helper::escape($this->user->user_interests, Helper::BODY)); ?> </div> <?php } ?> <?php if ($this->user->user_brands) { ?> <div class="unit size1of2"> <div class="meedlegray">Бренды:</div> <?php echo Text::auto_p(Helper::escape($this->user->user_brands, Helper::BODY)); ?> </div> <?php } ?> </div> <div class="clear"></div> <span class="bottom_span"></span> </div></div> <div class="clear"></div> </div> <!--Конец с фоткой--> <!--1-я с табом-->
<div class="title_n"> <h5><?php echo HTML::date($news['date_pub']); ?> </h5> <h2><?php echo $news['title']; ?> </h2> </div> <div class="text"> <img src="<?php echo URL::base(); ?> public/content/news/<?php echo $news['image']; ?> .png" class="image_news" > <?php echo Text::auto_p($news['text']); ?> </div>
/** * Return BBCode parsed to HTML * * @param string $text * @param boolean $plain * @return string */ public function render($text = null, $plain = false) { if ($text) { $this->text = $text; } if (is_null($this->text)) { return ''; } // Convert old system tags to BBCode $text = str_replace(array('[link', '[/link]', '[q]', '[/q]'), array('[url', '[/url]', '[quote]', '[/quote]'), $this->text); // Parse BBCode if ($plain) { $this->SetPlainMode(); $parsed = Text::auto_p($this->Parse($text)); $this->SetPlainMode(false); } else { // Convert orphan media links to tags $text = $this->embed($text); $parsed = $this->Parse($text); } return $parsed; //$this->GetPlainMode() ? $parsed : Text::auto_p($parsed); }
<div class="project list"> <p><?php echo HTML::anchor(Route::get('project/crud')->uri(array('action' => 'create')), 'New Project'); ?> </p> <dl> <?php foreach ($projects as $project) { ?> <dt><?php echo HTML::anchor(Route::get('project')->uri(array('name' => $project->name)), $project->name); ?> </dt> <dd><?php echo Text::auto_p(Text::auto_link($project->description)); ?> </dd> <?php } ?> </dl> </div>
/** * This test makes sure that auto_p surrounds a single line of text * with paragraph tags * * @test */ public function test_auto_para_encloses_slot_in_paragraph() { $text = 'Pick a pinch of purple pepper'; $this->assertSame('<p>' . $text . '</p>', Text::auto_p($text)); }
/** * This test makes sure that auto_p surrounds a single line of text * with paragraph tags * * @test * @covers Text::auto_p */ function testAutoParaEnclosesSLOTInParagraph() { $text = 'Pick a pinch of purple pepper'; $this->assertSame('<p>' . $text . '</p>', Text::auto_p($text)); }
/** * Make sure that multiple new lines are replaced with paragraph tags * * @test * @covers Text::auto_p */ public function test_auto_para_replaces_multiple_newlines_with_paragraph() { $this->assertSame("<p>My name is john</p>\n\n<p>I'm a developer</p>", Text::auto_p("My name is john\n\n\n\nI'm a developer")); }
<h1>Post</h1> <h2><?php echo $post['title']; ?> </h2> <?php echo Text::auto_p($post['text']); ?> <div> <h3>Comments</h3> <ul> <?php foreach ($comments as $comment) { ?> <li> <img width="50" height="50" src="<?php echo $comment['logo']; ?> "> <span><?php echo $comment['name']; ?> </span> <p> <?php echo $comment['message']; ?> </p>