/** * Initializes Facebook Connect */ public static function init() { widget::add('foot', html::script(array('js/fbconnect.js', 'http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US'))); widget::add('foot', html::script_source("FB.init('" . FB::$config['api_key'] . "');")); // Add logged in Facebook user id to session for easier access if ($logged_in = FB::instance()->get_loggedin_user()) { $_SESSION['fb_uid'] = $logged_in; } }
Widget::add('footer', html::script_source(' function filters(all) { if (all) { // Open all $("form.filters input").each(function() { $("." + this.id + ":hidden").slideDown("normal"); }); } else { // Filter individually $("form.filters input").each(function() { if ($(this).is(":checked")) { $("." + this.id + ":hidden").slideDown("normal"); } else { $("." + this.id + ":visible").slideUp("normal"); } }); } } head.ready("jquery-ui", function() { // Hook clicks $("form.filters :checkbox").click(function() { var checked = $(this).is(":checked"); if ($(this).val() != "all") { // Individual filters if (checked) { // Uncheck "all" $("form.filters input[value=all]").attr("checked", false); } // Check "all" if no other filters if ($("form.filters input[value!=all]").is(":checked") == false) { $("form.filters input[value=all]").attr("checked", "checked"); filters(true); } else { filters(); } } else { // All filters if (!checked) { return false; } $("form.filters input[value!=all]").attr("checked", false); filters(checked); } }); }); '));
</dd> </dl> <?php } ?> </li> <?php if ($venue->latitude && $venue->longitude) { ?> <li class="grid-7 alpha omega map"> <div id="map" style="display: none"><?php echo __('Map loading'); ?> </div> <?php $map = new Gmap('map', array('ScrollWheelZoom' => true)); $map->center($venue->latitude, $venue->longitude, 15)->controls('small')->types(); $map->add_marker($venue->latitude, $venue->longitude, '<strong>' . html::specialchars($venue->name) . '</strong><p>' . html::specialchars($venue->address) . '<br />' . html::specialchars($venue->zip) . ' ' . html::specialchars($venue->city_name) . '</p>'); widget::add('foot', html::script_source($map->render('gmaps/jquery_event'))); widget::add('foot', html::script_source("\$('.contact a:first').click(function() { \$('#map').toggle('normal', gmap_open); return false; });")); ?> </li> <?php } ?> </ul> </div> </section>
<?php echo Form::checkbox('filter[]', 'all', true, array('id' => 'all-' . $type)); ?> <?php echo Form::label('all-' . $type, __('All')); ?> </li> <?php foreach ($filter['filters'] as $key => $name) { ?> <li> <?php echo Form::checkbox('filter[]', $type . '-' . $key, false, array('id' => $type . '-' . $key)); ?> <?php echo Form::label($type . '-' . $key, $name); ?> </li> <?php } ?> </ul> </fieldset> <?php } ?> <?php echo form::close(); Widget::add('footer', html::script_source("\nfunction filters(all) {\n\tif (all) {\n\n\t\t// Open all\n\t\t\$('form.filters input').each(function() {\n\t\t\t\$('.' + this.id + ':hidden').slideDown('normal');\n\t\t});\n\n\t} else {\n\n\t\t// Filter individually\n\t\t\$('form.filters input').each(function() {\n\t\t\tif (\$(this).is(':checked')) {\n\t\t\t\t\$('.' + this.id + ':hidden').slideDown('normal');\n\t\t\t} else {\n\t\t\t\t\$('.' + this.id + ':visible').slideUp('normal');\n\t\t\t}\n\t\t});\n\n\t}\n}\n\n\$(function() {\n\n\t// Hook clicks\n\t\$('form.filters :checkbox').click(function() {\n\n\t\tvar checked = \$(this).is(':checked');\n\n\t\tif (\$(this).val() != 'all') {\n\n\t\t\t// Individual filters\n\t\t\tif (checked) {\n\n\t\t\t\t// Uncheck 'all'\n\t\t\t\t\$('form.filters input[value=\"all\"]').attr('checked', false);\n\n\t\t\t}\n\n\t\t\t// Check 'all' if no other filters\n\t\t\tif (\$('form.filters input[value!=\"all\"]').is(':checked') == false) {\n\t\t\t\t\$('form.filters input[value=\"all\"]').attr('checked', 'checked');\n\t\t\t\tfilters(true);\n\t\t\t} else {\n\t\t\t\tfilters();\n\t\t\t}\n\n\t\t} else {\n\n\t\t\t// All filters\n\t\t\tif (!checked) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\t\$('form.filters input[value!=\"all\"]').attr('checked', false);\n\t\t\tfilters(checked);\n\n\t\t}\n\n\t});\n});\n"));
/** * Edit event * * @param int|string $event_id */ public function _event_edit($event_id = false) { $this->history = false; $event = new Event_Model((int) $event_id); // For authenticated users only if (!$this->user || !$event->is_author() && !$this->visitor->logged_in(array('admin', 'event moderator'))) { url::back('/events'); } $errors = $form_errors = array(); $form_values = $event->as_array(); $form_values['start_date'] = ''; $form_values['start_hour'] = ''; $form_values['end_hour'] = ''; /***** CHECK POST *****/ if (request::method() == 'post') { $post = array_merge($this->input->post(), $_FILES); $extra = array('start_time' => date::unix2sql(strtotime($post['start_date'] . ' ' . date::time_24h($post['start_hour'])))); if (!empty($post['end_hour'])) { $end_time = strtotime($post['start_date']); // end hour is earlier than start hour = event ends the next day if ($post['end_hour'] < $post['start_hour']) { $end_time = strtotime('+1 day', $end_time); } $extra['end_time'] = date('Y-m-d', $end_time) . ' ' . date::time_24h($post['end_hour']) . ':00'; } // update $editing = (bool) $event->id; if ($editing) { $extra['modified'] = date::unix2sql(time()); $extra['modifies'] = (int) $event->modifies + 1; } else { $extra['author_id'] = $this->user->id; } $city = ORM::factory('city', $post['city_id']); if ($city) { $extra['country_id'] = $city->country_id; } if (csrf::valid() && $event->validate($post, true, $extra)) { // Update tags $event->remove(ORM::factory('tag')); if (!empty($post['tags'])) { foreach ($post['tags'] as $tag_id => $tag) { $event->add(ORM::factory('tag', $tag_id)); } $event->save(); } // Handle flyer uploads foreach (array('flyer_front_image_id' => $post->flyer_front, 'flyer_back_image_id' => $post->flyer_back) as $image_id => $flyer) { if (isset($flyer) && empty($flyer['error'])) { $image = Image_Model::factory('events.flyer', $flyer, $this->user->id); if ($image->id) { $event->add($image); $event->{$image_id} = $image->id; $event->save(); } } } if (!$editing) { newsfeeditem_events::event($this->user, $event); } url::redirect(url::model($event)); } else { $form_errors = $post->errors(); } $form_values = arr::overwrite($form_values, $post->as_array()); } /***** /CHECK POST *****/ /***** SHOW FORM *****/ if ($event->id) { $this->page_actions[] = array('link' => url::model($event) . '/delete/?token=' . csrf::token(), 'text' => __('Delete event'), 'class' => 'event-delete'); $this->page_title = text::title($event->name); $this->page_subtitle = __('Edit event'); list($form_values['start_date'], $form_values['start_hour']) = explode(' ', date('Y-m-d H', strtotime($event->start_time))); if (!empty($event->end_time)) { list($temp, $form_values['end_hour']) = explode(' ', date('Y-m-d H', strtotime($event->end_time))); } } else { $this->page_title = __('New event'); } $form = $event->get_form(); // Tags if ($tag_group = Kohana::config('events.tag_group')) { $form['tags'] = $form_values['tags'] = array(); $tags = ORM::factory('tag_group', $tag_group); foreach ($tags->tags as $tag) { $form['tags'][$tag->id] = $tag->name; if ($event->has($tag)) { $form_values['tags'][$tag->id] = $tag->name; } } } // City autocomplete $this->_autocomplete_city('city_name'); // Venue autocomplete $venues = ORM::factory('venue')->where('event_host', '=', 1)->find_all(); $hosts = array(); foreach ($venues as $venue) { $hosts[] = "{ id: '" . $venue->id . "', text: '" . html::chars($venue->name) . "' }"; } widget::add('foot', html::script_source('var venues = [' . implode(', ', $hosts) . "];\n\$('input[name=venue_name]').autocomplete(venues, {\n\tformatItem: function(item) {\n\t\treturn item.text;\n\t}\n}).result(function(event, item) {\n\t\$('input[name=venue_id]').val(item.id);\n});")); // Date pickers widget::add('foot', html::script_source("\$('input#start_date').datepicker({ dateFormat: 'd.m.yy', firstDay: 1, changeFirstDay: false, showOtherMonths: true, showWeeks: true, showStatus: true, showOn: 'both' });")); if (empty($errors)) { widget::add('main', View::factory('events/event_edit', array('form' => $form, 'values' => $form_values, 'errors' => $form_errors))); } else { // $this->_error(Kohana::lang('generic.error'), $errors); } /***** /SHOW FORM *****/ $this->_side_views(); }
<section id="<?php echo $id; ?> " class="mod tabs"> <ul> <?php $t = 0; $selected = 0; foreach ($tabs as $tab) { $selected = !empty($tab['selected']) ? $t : $selected; $t++; ?> <li><?php echo html::anchor($tab['href'], $tab['title']); ?> </li> <?php } ?> </ul> <?php foreach ($tabs as $tab) { echo $tab['tab']; } ?> </section> <?php // Initialize tabs immediately to aviod ugly jumping echo html::script_source('$("#' . $id . '").tabs({ selected: ' . $selected . ', collapsible: true, fx: { height: "toggle", opacity: "toggle", duration: "fast" } });'); //echo html::script_source('$("#' . $id . ' > ul").tabs("#' . $id . ' .tab", { initialIndex: ' . $selected . ', effect: "fade" });');
<?php $names = array(); foreach (explode(',', $image->description) as $name) { $names[] = html::user(trim($name)); } ?> <footer> <?php echo __('In picture: :users', array(':users' => implode(', ', $names))); ?> </footer> <?php } ?> </div> </section> <?php echo html::script_source(' $(document).keyup(function(e) { var key = e.keyCode || e.which; if (e.target.type === undefined) { switch (key) { case 37: var link = $(".gallery-image a.prev").first().attr("href"); break; case 39: var link = $(".gallery-image a.next").first().attr("href"); break; } if (link) { window.location = link; } } }); ');
?> <li><?php echo form::submit(false, __('Shout')); ?> </li> </ul> <?php echo form::csrf(); ?> </fieldset> <?php echo form::close(); ?> <?php // AJAX hooks echo html::script_source(' $(function() { $("section.shout form").live("submit", function(e) { e.preventDefault(); var shouts = $(this).closest("section.shout"); $.post($(this).attr("action"), $(this).serialize(), function(data) { shouts.replaceWith(data); }); return false; }); }); '); }
echo html::script_source(' $(function() { $("a.comment-delete").each(function(i) { var action = $(this); action.data("action", function() { var comment = action.attr("href").match(/([0-9]*)\\/delete/); if (comment) { $.get(action.attr("href"), function() { $("#comment-" + comment[1]).slideUp(); }); } }); }); $("a.comment-private").live("click", function(e) { e.preventDefault(); var href = $(this).attr("href"); var comment = href.match(/([0-9]*)\\/private/); $(this).fadeOut() if (comment) { $.get(href, function() { $("#comment-" + comment[1]).addClass("private"); }); } return false; }); $("section.comments form").live("submit", function(e) { e.preventDefault(); var comment = $(this).closest("section.comments"); $.post($(this).attr("action"), $(this).serialize(), function(data) { comment.replaceWith(data); }); return false; }); }); ');
<section id="invitation" class="grid-2 prefix-5"> <?php echo form::open('sign/up'); ?> <fieldset> <ul> <?php echo form::input_wrap('code', null, 'title="' . __('Invitation code') . '" maxlength="32"', __('Got invited?')); ?> <li><?php echo form::submit('invitation_check', __('Sign up')); ?> </li> </ul> </fieldset> <?php echo form::close(); ?> </section> </div> </section> <?php echo html::script_source("\$('input:text, input:password').hint('hint');"); echo widget::get('foot'); ?> </body> </html>
/** * JavaScript source code block * * @param string $source * @return string */ public static function script_source($source) { $complied = ''; if (is_array($source)) { foreach ($source as $script) { $compiled .= html::script_source($script); } } else { $compiled = implode("\n", array('<script>', trim($source), '</script>')); } return $compiled; }
echo html::script_source(' $(function() { $("a.post-edit").live("click", function(e) { e.preventDefault(); var href = $(this).attr("href"); var post = href.match(/([0-9]*)\\/edit/); $("#post-" + post[1] + " .actions").fadeOut(); $.get(href, function(data) { $("#post-" + post[1] + " .post-content").html(data); }); }); $("a.post-delete").each(function(i) { var action = $(this); action.data("action", function() { var post = action.attr("href").match(/([0-9]*)\\/delete/); if (post) { $.get(action.attr("href"), function(data) { $("#post-" + post[1]).slideUp(); }); } }); }); $("a.post-quote").live("click", function(e) { e.preventDefault(); var href = $(this).attr("href"); var post = href.match(/([0-9]*)\\/quote/); var article = $(this).closest("article"); $("#post-" + post[1] + " .actions").fadeOut(); $.get(href, function(data) { article.append(data); window.scrollTo(0, article.find("#quote").offset().top - 20); }); }); $("section.post-content form").live("submit", function(e) { e.preventDefault(); var post = $(this).closest("article"); $.post($(this).attr("action"), $(this).serialize(), function(data) { post.replaceWith(data); }); }); $("section.post-content form a").live("click", function(e) { e.preventDefault(); var post = $(this).closest("article"); $.get($(this).attr("href"), function(data) { post.replaceWith(data); }); }); $("section#quote form a").live("click", function(e) { e.preventDefault(); var section = $(this).closest("section"); var article = section.closest("article"); section.slideUp(null, function() { section.remove(); }); article.find(".actions").fadeIn(); }); }); ');
/** * Add autocomplete for city * * @param string $field * @param string $hidden */ public function _autocomplete_city($field = 'city_name', $hidden = 'city_id') { $countries = array(); foreach (Kohana::config('locale.countries') as $country) { $countries[] = $country[1]; } $countries = ORM::factory('country')->where('country', 'IN', $countries)->find_all(); $cities = array(); foreach ($countries as $country) { foreach ($country->cities->find_all() as $city) { $cities[] = array('id' => $city->id, 'text' => html::chars($city->city)); } } widget::add('foot', html::script_source(' var cities = ' . json_encode($cities) . '; $("input#' . $field . '").autocomplete(cities, { formatItem: function(item) { return item.text; } }).result(function(event, item) { $("input[name=' . $hidden . ']").val(item.id); }); ')); }
<div class="lightbox" id="slideshow"> <a class="prev" title="<?php echo __('Previous'); ?> ">«</a> <a class="next" title="<?php echo __('Next'); ?> ">»</a> <a class="action close" title="<?php echo __('Close'); ?> ">✖</a> <div class="info"></div> </div> <?php echo html::script_source(' $(function() { $(".lightboxed a").overlay({ effect: "apple", target: "#slideshow", expose: { color: "#222", loadSpeed: 200, opacity: 0.75 } }).gallery({ template: "<strong>${title}</strong> <span class=\\"details\\">' . __('Image ${index} of ${total}') . '</span>" }); }); ');
echo form::textarea_wrap(array('name' => 'post', 'id' => $post_id, 'rows' => 20, 'cols' => 25), $post, '', true, '', $errors); ?> </ul> </fieldset> <fieldset> <?php echo form::csrf(); ?> <?php echo empty($post['id']) ? '' : form::hidden('id', $post['id']); ?> <?php echo empty($parent_id) ? '' : form::hidden('parent_id', $parent_id); ?> <?php echo form::submit(false, __('Save')); ?> <?php echo html::anchor(request::is_ajax() ? 'forum/post/' . ($post['id'] ? $post['id'] : $parent_id) : url::back('/forum', true), __('Cancel')); ?> </fieldset> <?php echo form::close(); ?> <?php echo html::script_source('$(function() { $("#' . $post_id . '").markItUp(bbCodeSettings); });');
/** * User profile */ public function _view() { $this->tab_id = 'profile'; $owner = $this->user && $this->member->id == $this->user->id; if ($owner && $this->user->newcomments) { $this->user->newcomments = 0; $this->user->save(); } // Actions if ($this->member->has_access(User_Model::ACCESS_EDIT)) { $this->page_actions[] = array('link' => url::user($this->member) . '/edit', 'text' => __('Settings'), 'class' => 'settings'); } // Picture widget::add('side', View_Mod::factory('member/member', array('mod_class' => 'member member-' . $this->member->id, 'user' => $this->member))); // Comments if ($this->member->has_access(User_Model::ACCESS_COMMENT)) { $comment = new User_Comment_Model(); $form_values = $comment->as_array(); $form_errors = array(); // check post if (csrf::valid() && ($post = $this->input->post())) { $comment->user_id = $this->member->id; $comment->author_id = $this->user->id; $comment->comment = $post['comment']; if (isset($post['private'])) { $comment->private = 1; } try { $comment->save(); if (!$owner) { $this->member->newcomments += 1; $this->member->save(); } $this->user->commentsleft += 1; $this->user->save(); if (!request::is_ajax()) { url::redirect(url::current()); } } catch (ORM_Validation_Exception $e) { $form_errors = $e->validation->errors(); $form_values = arr::overwrite($form_values, $post); } } // Handle pagination $per_page = 25; $page_num = $this->uri->segment('page') ? $this->uri->segment('page') : 1; $page_offset = ($page_num - 1) * $per_page; $total_comments = $this->member->get_comment_count(); $comments = $this->member->find_comments($page_num, $per_page, $this->user); $pagination = new Pagination(array('items_per_page' => $per_page, 'total_items' => $total_comments)); $view = View::factory('generic/comments', array('delete' => '/member/comment/%d/delete/?token=' . csrf::token(), 'private' => '/member/comment/%d/private/?token=' . csrf::token(), 'comments' => $comments, 'errors' => $form_errors, 'values' => $form_values, 'pagination' => $pagination, 'user' => $this->user)); if (request::is_ajax()) { echo $view; return; } widget::add('main', $view); } // Basic info $basic_info = array(); if (!empty($this->member->name)) { $basic_info[__('Name')] = html::specialchars($this->member->name); } if (!empty($this->member->city_name)) { $basic_info[__('City')] = html::specialchars($this->member->city_name); } if (!empty($this->member->dob) && $this->member->dob != '0000-00-00') { $basic_info[__('Date of Birth')] = __(':dob (:years years)', array(':dob' => date::format('DMYYYY', $this->member->dob), ':years' => date::timespan(strtotime($this->member->dob), null, 'years'))); } if (!empty($this->member->gender)) { $basic_info[__('Gender')] = $this->member->gender == 'm' ? __('Male') : __('Female'); } if (!empty($this->member->latitude) && !empty($this->member->longitude)) { $basic_info[__('Location')] = $this->member->latitude . ', ' . $this->member->longitude; $basic_info[__('Location')] = html::anchor('#map', __('Toggle map'), array('class' => 'expander', 'title' => __('Show/hide'))) . '<div id="map" style="display: none">' . __('Map loading') . '</div>'; $map = new Gmap('map', array('ScrollWheelZoom' => true)); $map->center($this->member->latitude, $this->member->longitude, 15)->controls('small')->types(); $map->add_marker($this->member->latitude, $this->member->longitude, html::avatar($this->member->avatar, $this->member->username) . html::user($this->member)); widget::add('foot', html::script_source($map->render('gmaps/jquery_event'))); widget::add('foot', html::script_source("\$('a[href*=\"#map\"]:first').click(function() { \$('#map').toggle('normal', gmap_open); return false; });")); } // Site info $site_info = array(__('Registered') => date::format('DMYYYY_HM', $this->member->created) . ' [#' . $this->member->id . ']', __('Logins') => __(':logins (:ago ago)', array(':logins' => number_format($this->member->logins, 0), ':ago' => '<abbr title="' . date::format('DMYYYY_HM', $this->member->last_login) . '">' . date::timespan_short($this->member->last_login) . '</abbr>')), __('Posts') => number_format($this->member->posts, 0), __('Comments') => number_format($this->member->commentsleft, 0)); // Initialize tabs $tabs = array('basic-info' => array('href' => '#basic-info', 'title' => __('Basic info'), 'tab' => new View('generic/list_info', array('id' => 'basic-info', 'title' => __('Basic info'), 'list' => $basic_info))), 'site-info' => array('href' => '#site-info', 'title' => __('Site info'), 'tab' => new View('generic/list_info', array('id' => 'site-info', 'title' => __('Site info'), 'list' => $site_info)))); widget::add('side', View::factory('generic/tabs', array('id' => 'info-tab', 'tabs' => $tabs))); $this->_side_views(); }
<?php echo form::textarea_wrap(array('name' => 'entry', 'id' => 'entry', 'tabindex' => 2, 'rows' => 20, 'cols' => 25), $values, '', true, '', $errors); ?> </ul> </fieldset> <fieldset> <?php echo form::csrf(); ?> <?php echo empty($values['id']) ? '' : form::hidden('id', $values['id']); ?> <?php echo form::submit(array('tabindex' => 3), __('Save')); ?> <?php echo html::anchor($_SESSION['history'], __('Cancel')); ?> </fieldset> <?php echo form::close(); ?> </div> </section> <?php echo html::script_source('$(function() { $("#entry").markItUp(bbCodeSettings); });');