/** * Load a controller callable * * @param \Symfony\Component\HttpFoundation\Request $request Symfony Request object * @return bool|Callable Callable or false * @throws \src\controller\exception */ public function getController(Request $request) { $controller = $request->attributes->get('_controller'); if (!$controller) { throw new \src\controller\exception($this->user->lang['CONTROLLER_NOT_SPECIFIED']); } // Require a method name along with the service name if (stripos($controller, ':') === false) { throw new \src\controller\exception($this->user->lang['CONTROLLER_METHOD_NOT_SPECIFIED']); } list($service, $method) = explode(':', $controller); if (!$this->container->has($service)) { throw new \src\controller\exception($this->user->lang('CONTROLLER_SERVICE_UNDEFINED', $service)); } $controller_object = $this->container->get($service); /* * If this is an extension controller, we'll try to automatically set * the style paths for the extension (the ext author can change them * if necessary). */ $controller_dir = explode('\\', get_class($controller_object)); // 0 vendor, 1 extension name, ... if (!is_null($this->template) && isset($controller_dir[1])) { $controller_style_dir = 'ext/' . $controller_dir[0] . '/' . $controller_dir[1] . '/styles'; if (is_dir($this->src_root_path . $controller_style_dir)) { $this->template->set_style(array($controller_style_dir, 'styles')); } } return array($controller_object, $method); }
/** * This listener is run when the KernelEvents::EXCEPTION event is triggered * * @param GetResponseForExceptionEvent $event * @return null */ public function on_kernel_exception(GetResponseForExceptionEvent $event) { $exception = $event->getException(); $message = $exception->getMessage(); if ($exception instanceof \src\exception\exception_interface) { $message = call_user_func_array(array($this->user, 'lang'), array_merge(array($message), $exception->get_parameters())); } if (!$event->getRequest()->isXmlHttpRequest()) { page_header($this->user->lang('INFORMATION')); $this->template->assign_vars(array('MESSAGE_TITLE' => $this->user->lang('INFORMATION'), 'MESSAGE_TEXT' => $message)); $this->template->set_filenames(array('body' => 'message_body.html')); page_footer(true, false, false); $response = new Response($this->template->assign_display('body'), 500); } else { $data = array(); if (!empty($message)) { $data['message'] = $message; } if (defined('DEBUG')) { $data['trace'] = $exception->getTrace(); } $response = new JsonResponse($data, 500); } if ($exception instanceof HttpExceptionInterface) { $response->setStatusCode($exception->getStatusCode()); $response->headers->add($exception->getHeaders()); } $event->setResponse($response); }
/** * {@inheritDoc} */ public function generate_field($profile_row, $preview_options = false) { $profile_row['field_ident'] = isset($profile_row['var_name']) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident']; $field_ident = $profile_row['field_ident']; $default_value = $profile_row['lang_default_value']; $profile_row['field_value'] = $this->request->is_set($field_ident) ? $this->request->variable($field_ident, $default_value, true) : (!isset($this->user->profile_fields[$field_ident]) || $preview_options !== false ? $default_value : $this->user->profile_fields[$field_ident]); $this->template->assign_block_vars($this->get_name_short(), array_change_key_case($profile_row, CASE_UPPER)); }
/** * Assign editable fields to template, mode can be profile (for profile change) or register (for registration) * Called by ucp_profile and ucp_register */ public function generate_profile_fields($mode, $lang_id) { $sql_where = ''; switch ($mode) { case 'register': // If the field is required we show it on the registration page $sql_where .= ' AND f.field_show_on_reg = 1'; break; case 'profile': // Show hidden fields to moderators/admins if (!$this->auth->acl_gets('a_', 'm_') && !$this->auth->acl_getf_global('m_')) { $sql_where .= ' AND f.field_show_profile = 1'; } break; default: trigger_error('Wrong profile mode specified', E_USER_ERROR); break; } $sql = 'SELECT l.*, f.* FROM ' . $this->fields_language_table . ' l, ' . $this->fields_table . " f\n\t\t\tWHERE f.field_active = 1\n\t\t\t\t{$sql_where}\n\t\t\t\tAND l.lang_id = " . (int) $lang_id . ' AND l.field_id = f.field_id ORDER BY f.field_order'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { // Return templated field $profile_field = $this->type_collection[$row['field_type']]; $tpl_snippet = $profile_field->process_field_row('change', $row); $this->template->assign_block_vars('profile_fields', array('LANG_NAME' => $this->user->lang($row['lang_name']), 'LANG_EXPLAIN' => $this->user->lang($row['lang_explain']), 'FIELD' => $tpl_snippet, 'FIELD_ID' => $profile_field->get_field_ident($row), 'S_REQUIRED' => $row['field_required'] ? true : false)); } $this->db->sql_freeresult($result); }
/** * Outputs the metadata into the template * * @return null */ public function output_template_data() { $this->template->assign_vars(array('META_NAME' => $this->metadata['name'], 'META_TYPE' => $this->metadata['type'], 'META_DESCRIPTION' => isset($this->metadata['description']) ? $this->metadata['description'] : '', 'META_HOMEPAGE' => isset($this->metadata['homepage']) ? $this->metadata['homepage'] : '', 'META_VERSION' => isset($this->metadata['version']) ? $this->metadata['version'] : '', 'META_TIME' => isset($this->metadata['time']) ? $this->metadata['time'] : '', 'META_LICENSE' => $this->metadata['license'], 'META_REQUIRE_PHP' => isset($this->metadata['require']['php']) ? $this->metadata['require']['php'] : '', 'META_REQUIRE_PHP_FAIL' => !$this->validate_require_php(), 'META_REQUIRE_src' => isset($this->metadata['extra']['soft-require']['src/src']) ? $this->metadata['extra']['soft-require']['src/src'] : '', 'META_REQUIRE_src_FAIL' => !$this->validate_require_src(), 'META_DISPLAY_NAME' => isset($this->metadata['extra']['display-name']) ? $this->metadata['extra']['display-name'] : '')); foreach ($this->metadata['authors'] as $author) { $this->template->assign_block_vars('meta_authors', array('AUTHOR_NAME' => $author['name'], 'AUTHOR_EMAIL' => isset($author['email']) ? $author['email'] : '', 'AUTHOR_HOMEPAGE' => isset($author['homepage']) ? $author['homepage'] : '', 'AUTHOR_ROLE' => isset($author['role']) ? $author['role'] : '')); } }
/** * {@inheritDoc} */ public function generate_field($profile_row, $preview_options = false) { $profile_row['field_ident'] = isset($profile_row['var_name']) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident']; $field_ident = $profile_row['field_ident']; $default_value = $profile_row['field_default_value']; // checkbox - set the value to "true" if it has been set to 1 if ($profile_row['field_length'] == 2) { $value = $this->request->is_set($field_ident) && $this->request->variable($field_ident, $default_value) == 1 ? true : (!isset($this->user->profile_fields[$field_ident]) || $preview_options !== false ? $default_value : $this->user->profile_fields[$field_ident]); } else { $value = $this->request->is_set($field_ident) ? $this->request->variable($field_ident, $default_value) : (!isset($this->user->profile_fields[$field_ident]) || $preview_options !== false ? $default_value : $this->user->profile_fields[$field_ident]); } $profile_row['field_value'] = (int) $value; $this->template->assign_block_vars('bool', array_change_key_case($profile_row, CASE_UPPER)); if ($profile_row['field_length'] == 1) { if (!$this->lang_helper->is_set($profile_row['field_id'], $profile_row['lang_id'], 1)) { if ($preview_options) { $this->lang_helper->load_preview_options($profile_row['field_id'], $profile_row['lang_id'], $preview_options); } else { $this->lang_helper->load_option_lang($profile_row['lang_id']); } } $options = $this->lang_helper->get($profile_row['field_id'], $profile_row['lang_id']); foreach ($options as $option_id => $option_value) { $this->template->assign_block_vars('bool.options', array('OPTION_ID' => $option_id, 'CHECKED' => $value == $option_id ? ' checked="checked"' : '', 'VALUE' => $option_value)); } } }
/** * {@inheritDoc} */ public function generate_field($profile_row, $preview_options = false) { $profile_row['field_ident'] = isset($profile_row['var_name']) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident']; $field_ident = $profile_row['field_ident']; $now = getdate(); if (!$this->request->is_set($profile_row['field_ident'] . '_day')) { if ($profile_row['field_default_value'] == 'now') { $profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']); } list($day, $month, $year) = explode('-', !isset($this->user->profile_fields[$field_ident]) || $preview_options !== false ? $profile_row['field_default_value'] : $this->user->profile_fields[$field_ident]); } else { if ($preview_options !== false && $profile_row['field_default_value'] == 'now') { $profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']); list($day, $month, $year) = explode('-', !isset($this->user->profile_fields[$field_ident]) || $preview_options !== false ? $profile_row['field_default_value'] : $this->user->profile_fields[$field_ident]); } else { $day = $this->request->variable($profile_row['field_ident'] . '_day', 0); $month = $this->request->variable($profile_row['field_ident'] . '_month', 0); $year = $this->request->variable($profile_row['field_ident'] . '_year', 0); } } $profile_row['s_day_options'] = '<option value="0"' . (!$day ? ' selected="selected"' : '') . '>--</option>'; for ($i = 1; $i < 32; $i++) { $profile_row['s_day_options'] .= '<option value="' . $i . '"' . ($i == $day ? ' selected="selected"' : '') . ">{$i}</option>"; } $profile_row['s_month_options'] = '<option value="0"' . (!$month ? ' selected="selected"' : '') . '>--</option>'; for ($i = 1; $i < 13; $i++) { $profile_row['s_month_options'] .= '<option value="' . $i . '"' . ($i == $month ? ' selected="selected"' : '') . ">{$i}</option>"; } $profile_row['s_year_options'] = '<option value="0"' . (!$year ? ' selected="selected"' : '') . '>--</option>'; for ($i = $now['year'] - 100; $i <= $now['year'] + 100; $i++) { $profile_row['s_year_options'] .= '<option value="' . $i . '"' . ($i == $year ? ' selected="selected"' : '') . ">{$i}</option>"; } $profile_row['field_value'] = 0; $this->template->assign_block_vars('date', array_change_key_case($profile_row, CASE_UPPER)); }
/** * Return templated value/field. Possible values for $mode are: * change == user is able to set/enter profile values; preview == just show the value */ public function process_field_row($mode, $profile_row) { $preview_options = $mode == 'preview' ? $profile_row['lang_options'] : false; // set template filename $this->template->set_filenames(array('cp_body' => $this->get_template_filename())); // empty previously filled blockvars $this->template->destroy_block_vars($this->get_name_short()); // Assign template variables $this->generate_field($profile_row, $preview_options); return $this->template->assign_display('cp_body'); }
/** * Output a message * * In case of an error, please throw an exception instead * * @param string $message The message to display (must be a language variable) * @param array $parameters The parameters to use with the language var * @param string $title Title for the message (must be a language variable) * @param int $code The HTTP status code (e.g. 404, 500, 503, etc.) * @return Response A Response instance */ public function message($message, array $parameters = array(), $title = 'INFORMATION', $code = 200) { array_unshift($parameters, $message); $message_text = call_user_func_array(array($this->user, 'lang'), $parameters); $message_title = $this->user->lang($title); if ($this->request->is_ajax()) { global $refresh_data; return new JsonResponse(array('MESSAGE_TITLE' => $message_title, 'MESSAGE_TEXT' => $message_text, 'S_USER_WARNING' => false, 'S_USER_NOTICE' => false, 'REFRESH_DATA' => !empty($refresh_data) ? $refresh_data : null), $code); } $this->template->assign_vars(array('MESSAGE_TEXT' => $message_text, 'MESSAGE_TITLE' => $message_title)); return $this->render('message_body.html', $message_title, $code); }
/** * {@inheritDoc} */ public function generate_field($profile_row, $preview_options = false) { $profile_row['field_ident'] = isset($profile_row['var_name']) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident']; $field_ident = $profile_row['field_ident']; $default_value = $profile_row['field_default_value']; $value = $this->request->is_set($field_ident) ? $this->request->variable($field_ident, $default_value) : (!isset($this->user->profile_fields[$field_ident]) || $preview_options !== false ? $default_value : $this->user->profile_fields[$field_ident]); if (!$this->lang_helper->is_set($profile_row['field_id'], $profile_row['lang_id'], 1)) { if ($preview_options) { $this->lang_helper->load_preview_options($profile_row['field_id'], $profile_row['lang_id'], $preview_options); } else { $this->lang_helper->load_option_lang($profile_row['lang_id']); } } $profile_row['field_value'] = (int) $value; $this->template->assign_block_vars('dropdown', array_change_key_case($profile_row, CASE_UPPER)); $options = $this->lang_helper->get($profile_row['field_id'], $profile_row['lang_id']); foreach ($options as $option_id => $option_value) { $this->template->assign_block_vars('dropdown.options', array('OPTION_ID' => $option_id, 'SELECTED' => $value == $option_id ? ' selected="selected"' : '', 'VALUE' => $option_value)); } }
/** * {@inheritDoc} */ public function generate_field($profile_row, $preview_options = false) { $profile_row['field_ident'] = isset($profile_row['var_name']) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident']; $field_ident = $profile_row['field_ident']; $default_value = $profile_row['field_default_value']; if ($this->request->is_set($field_ident)) { $value = $this->request->variable($field_ident, '') === '' ? null : $this->request->variable($field_ident, $default_value); } else { if ($preview_options === false && array_key_exists($field_ident, $this->user->profile_fields) && is_null($this->user->profile_fields[$field_ident])) { $value = null; } else { if (!isset($this->user->profile_fields[$field_ident]) || $preview_options !== false) { $value = $default_value; } else { $value = $this->user->profile_fields[$field_ident]; } } } $profile_row['field_value'] = is_null($value) || $value === '' ? '' : (int) $value; $this->template->assign_block_vars('int', array_change_key_case($profile_row, CASE_UPPER)); }
/** * Fill in the plupload configuration options in the template * * @param \src\cache\service $cache * @param \src\template\template $template * @param string $s_action The URL to submit the POST data to * @param int $forum_id The ID of the forum * @param int $max_files Maximum number of files allowed. 0 for unlimited. * * @return null */ public function configure(\src\cache\service $cache, \src\template\template $template, $s_action, $forum_id, $max_files) { $filters = $this->generate_filter_string($cache, $forum_id); $chunk_size = $this->get_chunk_size(); $resize = $this->generate_resize_string(); $template->assign_vars(array('S_RESIZE' => $resize, 'S_PLUPLOAD' => true, 'FILTERS' => $filters, 'CHUNK_SIZE' => $chunk_size, 'S_PLUPLOAD_URL' => htmlspecialchars_decode($s_action), 'MAX_ATTACHMENTS' => $max_files, 'ATTACH_ORDER' => $this->config['display_order'] ? 'asc' : 'desc', 'L_TOO_MANY_ATTACHMENTS' => $this->user->lang('TOO_MANY_ATTACHMENTS', $max_files))); $this->user->add_lang('plupload'); }
/** * Output all the notification methods to the template * * @param \src\notification\manager $src_notifications * @param \src\template\template $template * @param \src\user $user * @param string $block */ public function output_notification_methods(\src\notification\manager $src_notifications, \src\template\template $template, \src\user $user, $block = 'notification_methods') { $notification_methods = $src_notifications->get_subscription_methods(); foreach ($notification_methods as $method => $method_data) { $template->assign_block_vars($block, array('METHOD' => $method_data['id'], 'NAME' => $user->lang($method_data['lang']))); } }
/** * Show welcome message * * @param string $title main title * @param string $description page description */ protected function welcome_message($title, $description) { $this->template->assign_vars(array('L_TITLE' => $this->user->lang[$title], 'L_EXPLAIN' => isset($this->user->lang[$description]) ? $this->user->lang[$description] : '')); }
/** * Render the template of the form * * @param \src\template\template $template * @return null */ public function render(\src\template\template $template) { add_form_key('memberlist_email'); $template->assign_vars(array('ERROR_MESSAGE' => sizeof($this->errors) ? implode('<br />', $this->errors) : '')); }
/** * {inheritDoc} */ public function render(\src\template\template $template) { $l_admin_info = $this->config_text->get('contact_admin_info'); if ($l_admin_info) { $contact_admin_data = $this->config_text->get_array(array('contact_admin_info', 'contact_admin_info_uid', 'contact_admin_info_bitfield', 'contact_admin_info_flags')); $l_admin_info = generate_text_for_display($contact_admin_data['contact_admin_info'], $contact_admin_data['contact_admin_info_uid'], $contact_admin_data['contact_admin_info_bitfield'], $contact_admin_data['contact_admin_info_flags']); } $template->assign_vars(array('S_CONTACT_ADMIN' => true, 'S_CONTACT_FORM' => $this->config['contact_admin_form_enable'], 'S_IS_REGISTERED' => $this->user->data['is_registered'], 'S_POST_ACTION' => append_sid($this->src_root_path . 'memberlist.' . $this->phpEx, 'mode=contactadmin'), 'CONTACT_INFO' => $l_admin_info, 'MESSAGE' => $this->body, 'SUBJECT' => $this->subject, 'NAME' => $this->sender_name, 'EMAIL' => $this->sender_address)); parent::render($template); }
/** * Generate template rendered pagination * Allows full control of rendering of pagination with the template * * @param string $base_url is url prepended to all links generated within the function * If you use page numbers inside your controller route, base_url should contains a placeholder (%d) * for the page. Also be sure to specify the pagination path information into the start_name argument * @param string $block_var_name is the name assigned to the pagination data block within the template (example: <!-- BEGIN pagination -->) * @param string $start_name is the name of the parameter containing the first item of the given page (example: start=20) * If you use page numbers inside your controller route, start name should be the string * that should be removed for the first page (example: /page/%d) * @param int $num_items the total number of items, posts, etc., used to determine the number of pages to produce * @param int $per_page the number of items, posts, etc. to display per page, used to determine the number of pages to produce * @param int $start the item which should be considered currently active, used to determine the page we're on * @param bool $reverse_count determines whether we weight display of the list towards the start (false) or end (true) of the list * @param bool $ignore_on_page decides whether we enable an active (unlinked) item, used primarily for embedded lists * @return null */ public function generate_template_pagination($base_url, $block_var_name, $start_name, $num_items, $per_page, $start = 1, $reverse_count = false, $ignore_on_page = false) { $total_pages = ceil($num_items / $per_page); $on_page = $this->get_on_page($per_page, $start); $u_previous_page = $u_next_page = ''; if ($total_pages > 1) { if ($reverse_count) { $start_page = $total_pages > 5 ? $total_pages - 4 : 1; $end_page = $total_pages; } else { // What we're doing here is calculating what the "start" and "end" pages should be. We // do this by assuming pagination is "centered" around the currently active page with // the three previous and three next page links displayed. Anything more than that and // we display the ellipsis, likewise anything less. // // $start_page is the page at which we start creating the list. When we have five or less // pages we start at page 1 since there will be no ellipsis displayed. Anymore than that // and we calculate the start based on the active page. This is the min/max calculation. // First (max) would we end up starting on a page less than 1? Next (min) would we end // up starting so close to the end that we'd not display our minimum number of pages. // // $end_page is the last page in the list to display. Like $start_page we use a min/max to // determine this number. Again at most five pages? Then just display them all. More than // five and we first (min) determine whether we'd end up listing more pages than exist. // We then (max) ensure we're displaying the minimum number of pages. $start_page = $total_pages > 5 ? min(max(1, $on_page - 2), $total_pages - 4) : 1; $end_page = $total_pages > 5 ? max(min($total_pages, $on_page + 2), 5) : $total_pages; } if ($on_page != 1) { $u_previous_page = $this->generate_page_link($base_url, $on_page - 1, $start_name, $per_page); $this->template->assign_block_vars($block_var_name, array('PAGE_NUMBER' => '', 'PAGE_URL' => $u_previous_page, 'S_IS_CURRENT' => false, 'S_IS_PREV' => true, 'S_IS_NEXT' => false, 'S_IS_ELLIPSIS' => false)); } // This do...while exists purely to negate the need for start and end assign_block_vars, i.e. // to display the first and last page in the list plus any ellipsis. We use this loop to jump // around a little within the list depending on where we're starting (and ending). $at_page = 1; do { // We decide whether to display the ellipsis during the loop. The ellipsis is always // displayed as either the second or penultimate item in the list. So are we at either // of those points and of course do we even need to display it, i.e. is the list starting // on at least page 3 and ending three pages before the final item. $this->template->assign_block_vars($block_var_name, array('PAGE_NUMBER' => $at_page, 'PAGE_URL' => $this->generate_page_link($base_url, $at_page, $start_name, $per_page), 'S_IS_CURRENT' => !$ignore_on_page && $at_page == $on_page, 'S_IS_NEXT' => false, 'S_IS_PREV' => false, 'S_IS_ELLIPSIS' => $at_page == 2 && $start_page > 2 || $at_page == $total_pages - 1 && $end_page < $total_pages - 1)); // We may need to jump around in the list depending on whether we have or need to display // the ellipsis. Are we on page 2 and are we more than one page away from the start // of the list? Yes? Then we jump to the start of the list. Likewise are we at the end of // the list and are there more than two pages left in total? Yes? Then jump to the penultimate // page (so we can display the ellipsis next pass). Else, increment the counter and keep // going if ($at_page == 2 && $at_page < $start_page - 1) { $at_page = $start_page; } else { if ($at_page == $end_page && $end_page < $total_pages - 1) { $at_page = $total_pages - 1; } else { $at_page++; } } } while ($at_page <= $total_pages); if ($on_page != $total_pages) { $u_next_page = $this->generate_page_link($base_url, $on_page + 1, $start_name, $per_page); $this->template->assign_block_vars($block_var_name, array('PAGE_NUMBER' => '', 'PAGE_URL' => $u_next_page, 'S_IS_CURRENT' => false, 'S_IS_PREV' => false, 'S_IS_NEXT' => true, 'S_IS_ELLIPSIS' => false)); } } // If the block_var_name is a nested block, we will use the last (most // inner) block as a prefix for the template variables. If the last block // name is pagination, the prefix is empty. If the rest of the // block_var_name is not empty, we will modify the last row of that block // and add our pagination items. $tpl_block_name = $tpl_prefix = ''; if (strrpos($block_var_name, '.') !== false) { $tpl_block_name = substr($block_var_name, 0, strrpos($block_var_name, '.')); $tpl_prefix = strtoupper(substr($block_var_name, strrpos($block_var_name, '.') + 1)); } else { $tpl_prefix = strtoupper($block_var_name); } $tpl_prefix = $tpl_prefix == 'PAGINATION' ? '' : $tpl_prefix . '_'; $template_array = array($tpl_prefix . 'BASE_URL' => is_string($base_url) ? $base_url : '', $tpl_prefix . 'START_NAME' => $start_name, $tpl_prefix . 'PER_PAGE' => $per_page, 'U_' . $tpl_prefix . 'PREVIOUS_PAGE' => $on_page != 1 ? $u_previous_page : '', 'U_' . $tpl_prefix . 'NEXT_PAGE' => $on_page != $total_pages ? $u_next_page : '', $tpl_prefix . 'TOTAL_PAGES' => $total_pages, $tpl_prefix . 'CURRENT_PAGE' => $on_page, $tpl_prefix . 'PAGE_NUMBER' => $this->on_page($num_items, $per_page, $start)); if ($tpl_block_name) { $this->template->alter_block_array($tpl_block_name, $template_array, true, 'change'); } else { $this->template->assign_vars($template_array); } }
/** * Options to pick a timezone and date/time * * @param \src\template\template $template src template object * @param \src\user $user Object of the current user * @param string $default A timezone to select * @param boolean $truncate Shall we truncate the options text * * @return array Returns an array containing the options for the time selector. */ function src_timezone_select($template, $user, $default = '', $truncate = false) { static $timezones; $default_offset = ''; if (!isset($timezones)) { $unsorted_timezones = src_get_timezone_identifiers($default); $timezones = array(); foreach ($unsorted_timezones as $timezone) { $tz = new DateTimeZone($timezone); $dt = $user->create_datetime('now', $tz); $offset = $dt->getOffset(); $current_time = $dt->format($user->lang['DATETIME_FORMAT'], true); $offset_string = src_format_timezone_offset($offset, true); $timezones['UTC' . $offset_string . ' - ' . $timezone] = array('tz' => $timezone, 'offset' => $offset_string, 'current' => $current_time); if ($timezone === $default) { $default_offset = 'UTC' . $offset_string; } } unset($unsorted_timezones); uksort($timezones, 'src_tz_select_compare'); } $tz_select = $opt_group = ''; foreach ($timezones as $key => $timezone) { if ($opt_group != $timezone['offset']) { // Generate tz_select for backwards compatibility $tz_select .= $opt_group ? '</optgroup>' : ''; $tz_select .= '<optgroup label="' . $user->lang(array('timezones', 'UTC_OFFSET_CURRENT'), $timezone['offset'], $timezone['current']) . '">'; $opt_group = $timezone['offset']; $template->assign_block_vars('timezone_select', array('LABEL' => $user->lang(array('timezones', 'UTC_OFFSET_CURRENT'), $timezone['offset'], $timezone['current']), 'VALUE' => $key . ' - ' . $timezone['current'])); $selected = !empty($default_offset) && strpos($key, $default_offset) !== false ? ' selected="selected"' : ''; $template->assign_block_vars('timezone_date', array('VALUE' => $key . ' - ' . $timezone['current'], 'SELECTED' => !empty($selected), 'TITLE' => $user->lang(array('timezones', 'UTC_OFFSET_CURRENT'), $timezone['offset'], $timezone['current']))); } $label = $timezone['tz']; if (isset($user->lang['timezones'][$label])) { $label = $user->lang['timezones'][$label]; } $title = $user->lang(array('timezones', 'UTC_OFFSET_CURRENT'), $timezone['offset'], $label); if ($truncate) { $label = truncate_string($label, 50, 255, false, '...'); } // Also generate timezone_select for backwards compatibility $selected = $timezone['tz'] === $default ? ' selected="selected"' : ''; $tz_select .= '<option title="' . $title . '" value="' . $timezone['tz'] . '"' . $selected . '>' . $label . '</option>'; $template->assign_block_vars('timezone_select.timezone_options', array('TITLE' => $title, 'VALUE' => $timezone['tz'], 'SELECTED' => !empty($selected), 'LABEL' => $label)); } $tz_select .= '</optgroup>'; return $tz_select; }
/** * Set template paths to load */ protected function set_template_paths($path_name, $paths) { $this->setup_template(); $this->template->set_custom_style($path_name, $paths); }