/** * checks the i18n folder to see what folders we have available */ public static function get_i18n() { $locales = array(); // i18n path $i18n_path = APPPATH . 'i18n/'; // i18n folder $i18n_folder = @opendir($i18n_path); if (!$i18n_folder) { return false; } while (($i18n_dir = readdir($i18n_folder)) !== false) { if (is_dir($i18n_path . $i18n_dir) && is_readable($i18n_path . $i18n_dir)) { // Strip out . and .. and any other stuff if ($i18n_dir[0] == '.' || $i18n_dir == '..' || $i18n_dir == '.DS_Store' || $i18n_dir == '.git') { continue; } $locale = explode("_", $i18n_dir); if (count($locale) < 2) { continue; } $directories[$i18n_dir] = ush_locale::language($locale[0]) . " (" . $locale[1] . ")"; } } if (is_dir($i18n_dir)) { @closedir($i18n_dir); } return $directories; }
/** * checks the i18n folder to see what folders we have available * @param boolean Force reloading locale cache */ public static function get_i18n($refresh = FALSE) { // If we had cached locales return those if (!$refresh) { $locales = Cache::instance()->get('locales'); if ($locales) { return $locales; } } $locales = array(); // i18n path $i18n_path = APPPATH . 'i18n/'; // i18n folder $i18n_folder = @opendir($i18n_path); if (!$i18n_folder) { return false; } while (($i18n_dir = readdir($i18n_folder)) !== false) { if (is_dir($i18n_path . $i18n_dir) && is_readable($i18n_path . $i18n_dir)) { // Strip out . and .. and any other stuff if ($i18n_dir[0] == '.' || $i18n_dir == '..' || $i18n_dir == '.DS_Store' || $i18n_dir == '.git') { continue; } $locale = explode("_", $i18n_dir); if (count($locale) < 2 and !ush_locale::language($locale[0])) { continue; } $locales[$i18n_dir] = ush_locale::language($locale[0]) ? ush_locale::language($locale[0]) : $locale[0]; $locales[$i18n_dir] .= isset($locale[1]) ? " (" . $locale[1] . ")" : ""; } } if (is_dir($i18n_dir)) { @closedir($i18n_dir); } Cache::instance()->set('locales', $locales, array('locales'), 604800); return $locales; }
public function languages() { // *** Locales/Languages *** // First Get Available Locales $locales = ush_locale::get_i18n(); $languages = ""; $languages .= "<div class=\"language-box\">"; $languages .= form::open(NULL, array('method' => 'get')); /** * E.Kala - 05/01/2011 * * Fix to ensure to ensure that a change in language loads the page with the same data * * Only fetch the $_GET data to prevent double submission of data already submitted via $_POST * and create hidden form fields for each variable so that these are submitted along with the selected language * * The assumption is that previously submitted data had already been sanitized! */ foreach ($_GET as $name => $value) { if (is_array($value)) { continue; } $languages .= form::hidden($name, $value); } // Do a case insensitive sort of locales so it comes up in a rough alphabetical order natcasesort($locales); $languages .= form::dropdown('l', $locales, Kohana::config('locale.language'), ' onchange="this.form.submit()" '); $languages .= form::close(); $languages .= "</div>"; return $languages; }
public function languages() { // *** Locales/Languages *** // First Get Available Locales $locales = $this->cache->get('locales'); // If we didn't find any languages, we need to look them up and set the cache if (!$locales) { $locales = ush_locale::get_i18n(); $this->cache->set('locales', $locales, array('locales'), 604800); } // Locale form submitted? if (isset($_GET['l']) && !empty($_GET['l'])) { $this->session->set('locale', $_GET['l']); } // Has a locale session been set? if ($this->session->get('locale', FALSE)) { // Change current locale Kohana::config_set('locale.language', $_SESSION['locale']); } $languages = ""; $languages .= "<div class=\"language-box\">"; $languages .= "<form action=\"\">"; /** * E.Kala - 05/01/2011 * * Fix to ensure to ensure that a change in language loads the page with the same data * * Only fetch the $_GET data to prevent double submission of data already submitted via $_POST * and create hidden form fields for each variable so that these are submitted along with the selected language * * The assumption is that previously submitted data had already been sanitized! */ foreach ($_GET as $name => $value) { $languages .= form::hidden($name, $value); } // Do a case insensitive sort of locales so it comes up in a rough alphabetical order natcasesort($locales); $languages .= form::dropdown('l', $locales, Kohana::config('locale.language'), ' onchange="this.form.submit()" '); $languages .= "</form>"; $languages .= "</div>"; return $languages; }
/** * Add Edit Categories */ public function index() { $this->template->content = new View('admin/categories'); $this->template->content->title = Kohana::lang('ui_admin.categories'); // Locale (Language) Array $locales = ush_locale::get_i18n(); // Setup and initialize form field names $form = array('action' => '', 'category_id' => '', 'parent_id' => '', 'category_title' => '', 'category_description' => '', 'category_color' => '', 'category_image' => '', 'category_image_thumb' => '', 'form_auth_token' => ''); // Add the different language form keys for fields foreach ($locales as $lang_key => $lang_name) { $form['category_title_' . $lang_key] = ''; } // Copy the form as errors, so the errors will be stored with keys corresponding to the form field names $errors = $form; $form_error = FALSE; $form_saved = FALSE; $form_action = ""; $parents_array = array(); // Check, has the form been submitted, if so, setup validation if ($_POST) { // Fetch the post data $post_data = array_merge($_POST, $_FILES); // Extract category-specific information $category_data = arr::extract($post_data, 'parent_id', 'category_title', 'category_description', 'category_color'); // Extract category image and category languages for independent validation $secondary_data = arr::extract($post_data, 'category_image', 'category_title_lang', 'action'); // Setup validation for the secondary data $post = Validation::factory($secondary_data)->pre_filter('trim', TRUE); // Add validation for the add/edit action if ($post->action == 'a') { $post->add_rules('category_image', 'upload::valid', 'upload::type[gif,jpg,png]', 'upload::size[50K]'); // Add the different language form keys for fields foreach ($locales as $lang_key => $lang_name) { $post->add_rules('category_title_lang[' . $lang_key . ']', 'length[3,80]'); } } // Category instance for the operation $category = (!empty($_POST['category_id']) and Category_Model::is_valid_category($_POST['category_id'])) ? new Category_Model($_POST['category_id']) : new Category_Model(); // Check the specified action if ($post->action == 'a') { // Test to see if things passed the rule checks if ($category->validate($category_data) and $post->validate(FALSE)) { // Save the category $category->save(); // Get the category localization $languages = $category->loaded ? Category_Lang_Model::category_langs($category->id) : FALSE; $category_lang = isset($languages[$category->id]) ? $languages[$category->id] : FALSE; // Save localizations foreach ($post->category_title_lang as $lang_key => $localized_category_name) { $cl = isset($category_lang[$lang_key]['id']) ? ORM::factory('category_lang', $category_lang[$lang_key]['id']) : ORM::factory('category_lang'); $cl->category_title = $localized_category_name; $cl->locale = $lang_key; $cl->category_id = $category->id; $cl->save(); } // Upload Image/Icon $filename = upload::save('category_image'); if ($filename) { $new_filename = "category_" . $category->id . "_" . time(); // Name the files for the DB $cat_img_file = $new_filename . ".png"; $cat_img_thumb_file = $new_filename . "_16x16.png"; // Resize Image to 32px if greater Image::factory($filename)->resize(32, 32, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $cat_img_file); // Create a 16x16 version too Image::factory($filename)->resize(16, 16, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $cat_img_thumb_file); // Okay, now we have these three different files on the server, now check to see // if we should be dropping them on the CDN if (Kohana::config("cdn.cdn_store_dynamic_content")) { $cat_img_file = cdn::upload($cat_img_file); $cat_img_thumb_file = cdn::upload($cat_img_thumb_file); // We no longer need the files we created on the server. Remove them. $local_directory = rtrim(Kohana::config('upload.directory', TRUE), '/') . '/'; unlink($local_directory . $new_filename . ".png"); unlink($local_directory . $new_filename . "_16x16.png"); } // Remove the temporary file unlink($filename); // Delete Old Image $category_old_image = $category->category_image; if (!empty($category_old_image)) { if (file_exists(Kohana::config('upload.directory', TRUE) . $category_old_image)) { unlink(Kohana::config('upload.directory', TRUE) . $category_old_image); } elseif (Kohana::config("cdn.cdn_store_dynamic_content") and valid::url($category_old_image)) { cdn::delete($category_old_image); } } // Save $category->category_image = $cat_img_file; $category->category_image_thumb = $cat_img_thumb_file; $category->save(); Event::run('ushahidi_action.category_save', $post); } $form_saved = TRUE; $form_action = strtoupper(Kohana::lang('ui_admin.added_edited')); // Empty $form array array_fill_keys($form, ''); } else { // Validation failed // Repopulate the form fields $form = arr::overwrite($form, array_merge($category_data->as_array(), $post->as_array())); // populate the error fields, if any $errors = arr::overwrite($errors, array_merge($category_data->errors('category'), $post->errors('category'))); $form_error = TRUE; } } elseif ($post->action == 'd' and $post->validate()) { // Delete action if ($category->loaded) { ORM::factory('category_lang')->where(array('category_id' => $category->id))->delete_all(); // Check for all subcategories tied to this category and make them top level $children = ORM::factory('category')->where('parent_id', $category->id)->find_all(); if ($children) { foreach ($children as $child) { $sub_cat = new Category_Model($child->id); $sub_cat->parent_id = 0; $sub_cat->save(); } } // Check for all reports tied to this category to be deleted $result = ORM::factory('incident_category')->where('category_id', $category->id)->find_all(); // If there are reports returned by the query if ($result) { foreach ($result as $orphan) { $orphan_incident_id = $orphan->incident_id; // Check if the report is tied to any other category $count = ORM::factory('incident_category')->where('incident_id', $orphan_incident_id)->count_all(); // If this report is tied to only one category(is uncategorized) if ($count == 1) { // Assign it to the special category for uncategorized reports $orphaned = ORM::factory('incident_category', $orphan->id); $orphaned->category_id = 5; $orphaned->save(); // Deactivate the report so that it's not accessible on the frontend $orphaned_report = ORM::factory('incident', $orphan_incident_id); $orphaned_report->incident_active = 0; $orphaned_report->save(); } else { ORM::factory('incident_category')->delete($orphan->id); } } } // @todo Delete the category image // Delete category itself - except if it is trusted ORM::factory('category')->where('category_trusted != 1')->delete($category->id); $form_saved = TRUE; $form_action = strtoupper(Kohana::lang('ui_admin.deleted')); } } elseif ($post->action == 'v' and $post->validate()) { // Show/Hide Action if ($category->loaded) { // Check for all subcategories tied to this category $children = ORM::factory('category')->where('parent_id', $category->id)->find_all(); // Then show/hide subcategories based on status of parent category foreach ($children as $child) { $sub_cat = new Category_Model($child->id); $sub_cat->category_visible = $category->category_visible == 1 ? 0 : 1; $sub_cat->save(); } // Change status of the Parent Category $category->category_visible = $category->category_visible == 1 ? 0 : 1; $category->save(); $form_saved = TRUE; $form_action = strtoupper(Kohana::lang('ui_admin.modified')); } } elseif ($post->action == 'i' and $post->validate()) { // Delete Image/Icon Action if ($category->loaded) { $category_image = $category->category_image; $category_image_thumb = $category->category_image_thumb; // Delete the main image if (!empty($category_image) and file_exists(Kohana::config('upload.directory', TRUE) . $category_image)) { unlink(Kohana::config('upload.directory', TRUE) . $category_image); } // Delete the thumb if (!empty($category_image_thumb) and file_exists(Kohana::config('upload.directory', TRUE) . $category_image_thumb)) { unlink(Kohana::config('upload.directory', TRUE) . $category_image_thumb); } $category->category_image = NULL; $category->category_image_thumb = NULL; $category->save(); $form_saved = TRUE; $form_action = strtoupper(Kohana::lang('ui_admin.modified')); } } } // Pagination $pagination = new Pagination(array('query_string' => 'page', 'items_per_page' => $this->items_per_page, 'total_items' => ORM::factory('category')->where('parent_id', '0')->count_all())); $categories = ORM::factory('category')->with('category_lang')->where('parent_id', '0')->orderby('category_title', 'asc')->find_all($this->items_per_page, $pagination->sql_offset); $parents_array = ORM::factory('category')->where('parent_id', '0')->where('category_trusted != 1')->select_list('id', 'category_title'); // add none to the list $parents_array[0] = "--- Top Level Category ---"; // Put "--- Top Level Category ---" at the top of the list ksort($parents_array); $this->template->content->form = $form; $this->template->content->errors = $errors; $this->template->content->form_error = $form_error; $this->template->content->form_saved = $form_saved; $this->template->content->form_action = $form_action; $this->template->content->pagination = $pagination; $this->template->content->total_items = $pagination->total_items; $this->template->content->categories = $categories; $this->template->content->parents_array = $parents_array; // Javascript Header $this->template->colorpicker_enabled = TRUE; $this->template->tablerowsort_enabled = TRUE; $this->template->js = new View('admin/categories_js'); $this->template->form_error = $form_error; $this->template->content->locale_array = $locales; $this->template->js->locale_array = $locales; }
/** * Site Settings */ function site() { $this->template->content = new View('admin/site'); $this->template->content->title = Kohana::lang('ui_admin.settings'); $this->template->js = new View('admin/site_js'); // setup and initialize form field names $form = array('site_name' => '', 'site_tagline' => '', 'banner_image' => '', 'delete_banner_image' => '', 'site_email' => '', 'alerts_email' => '', 'site_language' => '', 'site_timezone' => '', 'site_message' => '', 'site_copyright_statement' => '', 'site_submit_report_message' => '', 'site_contact_page' => '', 'items_per_page' => '', 'items_per_page_admin' => '', 'blocks_per_row' => '', 'allow_alerts' => '', 'allow_reports' => '', 'allow_comments' => '', 'allow_feed' => '', 'allow_stat_sharing' => '', 'cache_pages' => '', 'cache_pages_lifetime' => '', 'private_deployment' => '', 'manually_approve_users' => '', 'require_email_confirmation' => '', 'checkins' => '', 'google_analytics' => '', 'twitter_hashtags' => '', 'api_akismet' => ''); // Copy the form as errors, so the errors will be stored with keys // corresponding to the form field names $errors = $form; $form_error = FALSE; $form_saved = FALSE; // Retrieve Current Settings $settings = ORM::factory('settings', 1); // check, has the form been submitted, if so, setup validation if ($_POST) { // Instantiate Validation, use $post, so we don't overwrite $_POST // fields with our own things $post = new Validation($_POST); // Add some filters $post->pre_filter('trim', TRUE); // Add some rules, the input field, followed by a list of checks, carried out in order $post->add_rules('site_name', 'required', 'length[3,250]'); $post->add_rules('site_tagline', 'length[3,250]'); $post->add_rules('site_email', 'email', 'length[4,100]'); //$post->add_rules('alerts_email','required', 'email', 'length[4,100]'); //$post->add_rules('site_message', 'standard_text'); $post->add_rules('site_copyright_statement', 'length[4,600]'); $post->add_rules('site_language', 'required', 'length[5, 5]'); //$post->add_rules('site_timezone','required', 'between[10,50]'); $post->add_rules('site_contact_page', 'required', 'between[0,1]'); $post->add_rules('items_per_page', 'required', 'between[5,50]'); $post->add_rules('items_per_page_admin', 'required', 'between[5,50]'); $post->add_rules('blocks_per_row', 'required', 'numeric'); $post->add_rules('allow_alerts', 'required', 'between[0,1]'); $post->add_rules('allow_reports', 'required', 'between[0,1]'); $post->add_rules('allow_comments', 'required', 'between[0,2]'); $post->add_rules('allow_feed', 'required', 'between[0,1]'); $post->add_rules('allow_stat_sharing', 'required', 'between[0,1]'); $post->add_rules('cache_pages', 'required', 'between[0,1]'); $post->add_rules('cache_pages_lifetime', 'required', 'in_array[60,300,600,900,1800]'); $post->add_rules('private_deployment', 'required', 'between[0,1]'); $post->add_rules('manually_approve_users', 'required', 'between[0,1]'); $post->add_rules('require_email_confirmation', 'required', 'between[0,1]'); $post->add_rules('checkins', 'required', 'between[0,1]'); $post->add_rules('google_analytics', 'length[0,20]'); $post->add_rules('twitter_hashtags', 'length[0,500]'); $post->add_rules('api_akismet', 'length[0,100]', 'alpha_numeric'); // Add rules for file upload $files = Validation::factory($_FILES); $files->add_rules('banner_image', 'upload::valid', 'upload::type[gif,jpg,png]', 'upload::size[250K]'); // Test to see if things passed the rule checks if ($post->validate() and $files->validate(FALSE)) { // Yes! everything is valid $settings = new Settings_Model(1); $settings->site_name = $post->site_name; $settings->site_tagline = $post->site_tagline; $settings->site_email = $post->site_email; $settings->alerts_email = $post->alerts_email; $settings->site_message = $post->site_message; $settings->site_copyright_statement = $post->site_copyright_statement; $settings->site_submit_report_message = $post->site_submit_report_message; $settings->site_language = $post->site_language; $settings->site_timezone = $post->site_timezone; if ($settings->site_timezone == "0") { // "0" is the "Server Timezone" setting and it needs to be null in the db $settings->site_timezone = NULL; } $settings->site_contact_page = $post->site_contact_page; $settings->items_per_page = $post->items_per_page; $settings->items_per_page_admin = $post->items_per_page_admin; $settings->blocks_per_row = $post->blocks_per_row; $settings->allow_alerts = $post->allow_alerts; $settings->allow_reports = $post->allow_reports; $settings->allow_comments = $post->allow_comments; $settings->allow_feed = $post->allow_feed; $settings->allow_stat_sharing = $post->allow_stat_sharing; $settings->cache_pages = $post->cache_pages; $settings->cache_pages_lifetime = $post->cache_pages_lifetime; $settings->private_deployment = $post->private_deployment; $settings->manually_approve_users = $post->manually_approve_users; $settings->require_email_confirmation = $post->require_email_confirmation; $settings->checkins = $post->checkins; $settings->google_analytics = $post->google_analytics; $settings->twitter_hashtags = $post->twitter_hashtags; $settings->api_akismet = $post->api_akismet; $settings->date_modify = date("Y-m-d H:i:s", time()); $settings->save(); // Deal with banner image now // Check if deleting or updating a new image (or doing nothing) if (isset($post->delete_banner_image) and $post->delete_banner_image == 1) { // Delete old badge image ORM::factory('media')->delete($settings->site_banner_id); // Remove from DB table $settings = new Settings_Model(1); $settings->site_banner_id = NULL; $settings->save(); } else { // We aren't deleting, so try to upload if we are uploading an image $filename = upload::save('banner_image'); if ($filename) { $new_filename = "banner_" . time(); $file_type = strrev(substr(strrev($filename), 0, 4)); // Large size $l_name = $new_filename . $file_type; Image::factory($filename)->save(Kohana::config('upload.directory', TRUE) . $l_name); // Medium size $m_name = $new_filename . "_m" . $file_type; Image::factory($filename)->resize(80, 80, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $m_name); // Thumbnail $t_name = $new_filename . "_t" . $file_type; Image::factory($filename)->resize(60, 60, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $t_name); // Name the files for the DB $media_link = $l_name; $media_medium = $m_name; $media_thumb = $t_name; // Okay, now we have these three different files on the server, now check to see // if we should be dropping them on the CDN if (Kohana::config("cdn.cdn_store_dynamic_content")) { $media_link = cdn::upload($media_link); $media_medium = cdn::upload($media_medium); $media_thumb = cdn::upload($media_thumb); // We no longer need the files we created on the server. Remove them. $local_directory = rtrim(Kohana::config('upload.directory', TRUE), '/') . '/'; unlink($local_directory . $l_name); unlink($local_directory . $m_name); unlink($local_directory . $t_name); } // Remove the temporary file unlink($filename); // Save banner image in the media table $media = new Media_Model(); $media->media_type = 1; // Image $media->media_link = $media_link; $media->media_medium = $media_medium; $media->media_thumb = $media_thumb; $media->media_date = date("Y-m-d H:i:s", time()); $media->save(); // Save new banner image in settings $settings = new Settings_Model(1); $settings->site_banner_id = $media->id; $settings->save(); } } // Delete Settings Cache $this->cache->delete('settings'); $this->cache->delete_tag('settings'); // Everything is A-Okay! $form_saved = TRUE; // Action::site_settings_modified - Site settings have changed Event::run('ushahidi_action.site_settings_modified'); // repopulate the form fields $form = arr::overwrite($form, $post->as_array()); } else { // repopulate the form fields $form = arr::overwrite($form, $post->as_array()); // populate the error fields, if any if (is_array($files->errors()) and count($files->errors()) > 0) { // Error with file upload $errors = arr::overwrite($errors, $files->errors('settings')); } else { // Error with other form filed $errors = arr::overwrite($errors, $post->errors('settings')); } $form_error = TRUE; } } else { $form = array('site_name' => $settings->site_name, 'site_tagline' => $settings->site_tagline, 'site_banner_id' => $settings->site_banner_id, 'site_email' => $settings->site_email, 'alerts_email' => $settings->alerts_email, 'site_message' => $settings->site_message, 'site_copyright_statement' => $settings->site_copyright_statement, 'site_submit_report_message' => $settings->site_submit_report_message, 'site_language' => $settings->site_language, 'site_timezone' => $settings->site_timezone, 'site_contact_page' => $settings->site_contact_page, 'items_per_page' => $settings->items_per_page, 'items_per_page_admin' => $settings->items_per_page_admin, 'blocks_per_row' => $settings->blocks_per_row, 'allow_alerts' => $settings->allow_alerts, 'allow_reports' => $settings->allow_reports, 'allow_comments' => $settings->allow_comments, 'allow_feed' => $settings->allow_feed, 'allow_stat_sharing' => $settings->allow_stat_sharing, 'cache_pages' => $settings->cache_pages, 'cache_pages_lifetime' => $settings->cache_pages_lifetime, 'private_deployment' => $settings->private_deployment, 'manually_approve_users' => $settings->manually_approve_users, 'require_email_confirmation' => $settings->require_email_confirmation, 'checkins' => $settings->checkins, 'google_analytics' => $settings->google_analytics, 'twitter_hashtags' => $settings->twitter_hashtags, 'api_akismet' => $settings->api_akismet); } // Get banner image if ($settings->site_banner_id != NULL) { $banner = ORM::factory('media')->find($settings->site_banner_id); $this->template->content->banner = url::convert_uploaded_to_abs($banner->media_link); $this->template->content->banner_m = url::convert_uploaded_to_abs($banner->media_medium); $this->template->content->banner_t = url::convert_uploaded_to_abs($banner->media_thumb); } else { $this->template->content->banner = NULL; $this->template->content->banner_m = NULL; $this->template->content->banner_t = NULL; } $this->template->colorpicker_enabled = TRUE; $this->template->content->form = $form; $this->template->content->errors = $errors; $this->template->content->form_error = $form_error; $this->template->content->form_saved = $form_saved; $this->template->content->items_per_page_array = array('5' => '5 Items', '10' => '10 Items', '20' => '20 Items', '30' => '30 Items', '50' => '50 Items'); $blocks_per_row_array = array(); for ($i = 1; $i <= 21; $i++) { $blocks_per_row_array[$i] = $i; } $this->template->content->blocks_per_row_array = $blocks_per_row_array; $this->template->content->yesno_array = array('1' => strtoupper(Kohana::lang('ui_main.yes')), '0' => strtoupper(Kohana::lang('ui_main.no'))); $this->template->content->comments_array = array('1' => strtoupper(Kohana::lang('ui_main.yes') . " - " . Kohana::lang('ui_admin.approve_auto')), '2' => strtoupper(Kohana::lang('ui_main.yes') . " - " . Kohana::lang('ui_admin.approve_manual')), '0' => strtoupper(Kohana::lang('ui_main.no'))); $this->template->content->cache_pages_lifetime_array = array('60' => '1 ' . Kohana::lang('ui_admin.minute'), '300' => '5 ' . Kohana::lang('ui_admin.minutes'), '600' => '10 ' . Kohana::lang('ui_admin.minutes'), '900' => '15 ' . Kohana::lang('ui_admin.minutes'), '1800' => '30 ' . Kohana::lang('ui_admin.minutes')); //Generate all timezones $site_timezone_array = array(); $site_timezone_array[0] = Kohana::lang('ui_admin.server_time'); foreach (timezone_identifiers_list() as $timezone) { $site_timezone_array[$timezone] = $timezone; } $this->template->content->site_timezone_array = $site_timezone_array; // Generate Available Locales $locales = ush_locale::get_i18n(); $this->template->content->locales_array = $locales; $this->cache->set('locales', $locales, array('locales'), 604800); }
/** * See {@link combine_files()} * */ private function _process_combined_files($type) { // Make a map of files that could be potentially combined $combinerCheck = array(); foreach ($this->combine_files[$type] as $combinedFile => $sourceItems) { foreach ($sourceItems as $id => $sourceItem) { if (isset($combinerCheck[$sourceItem]) && $combinerCheck[$sourceItem] != $combinedFile) { Kohana::log('alert', "Requirements_Backend::process_combined_files - file '{$sourceItem}' appears in two combined files:" . " '{$combinerCheck[$sourceItem]}' and '{$combinedFile}'"); } $combinerCheck[$sourceItem] = $combinedFile; $combinerCheck[$id] = $combinedFile; } } // Work out the relative URL for the combined files from the base folder $combinedFilesFolder = $this->getCombinedFilesFolder() ? $this->getCombinedFilesFolder() . '/' : ''; // Figure out which ones apply to this pageview $combinedFiles = array(); $newRequirements = array(); foreach ($this->{$type} as $id => $params) { $file = $type == 'js' ? $params : $params['file']; if (isset($combinerCheck[$file])) { $newRequirements[$combinerCheck[$file]] = $type == 'js' ? $combinedFilesFolder . $combinerCheck[$file] : array('file' => $combinedFilesFolder . $combinerCheck[$file]); $combinedFiles[$combinerCheck[$file]] = true; } elseif (isset($combinerCheck[$id])) { $newRequirements[$combinerCheck[$id]] = $type == 'js' ? $combinedFilesFolder . $combinerCheck[$id] : array('file' => $combinedFilesFolder . $combinerCheck[$id]); $combinedFiles[$combinerCheck[$id]] = true; } else { $newRequirements[$id] = $params; } } // Process the combined files $base = DOCROOT; foreach (array_diff_key($combinedFiles, $this->blocked) as $combinedFile => $dummy) { $fileList = $this->combine_files[$type][$combinedFile]; $combinedFilePath = $base . $combinedFilesFolder . $combinedFile; // Check for RTL alternatives if ($type == 'css' and ush_locale::is_rtl_language()) { $has_rtl_files = FALSE; foreach ($fileList as $index => $file) { $rtlFile = substr($file, 0, strpos($file, ".{$type}")) . "-rtl" . substr($file, strpos($file, ".{$type}")); if (file_exists(DOCROOT . $rtlFile)) { $fileList[$index] = $rtlFile; $has_rtl_files = TRUE; } } // Update combined files details, only if the include RTL alternatives // We store the RTL version separate from the LTR version, so we don't regenerate every time someone changes language if ($has_rtl_files) { $combinedFile = substr($combinedFile, 0, -4) . '-rtl.css'; $combinedFilePath = $base . $combinedFilesFolder . $combinedFile; $newRequirements[$combinedFile] = $type == 'js' ? $combinedFilesFolder . $combinedFile : array('file' => $combinedFilesFolder . $combinedFile); } } // Make the folder if necessary if (!file_exists(dirname($combinedFilePath))) { mkdir(dirname($combinedFilePath)); } // If the file isn't writebale, don't even bother trying to make the combined file // Complex test because is_writable fails if the file doesn't exist yet. if (file_exists($combinedFilePath) && !is_writable($combinedFilePath) || !file_exists($combinedFilePath) && !is_writable(dirname($combinedFilePath))) { Kohana::log('alert', "Requirements_Backend::process_combined_files(): Couldn't create '{$combinedFilePath}'"); continue; } // Determine if we need to build the combined include if (file_exists($combinedFilePath) && !isset($_GET['flush'])) { // file exists, check modification date of every contained file $srcLastMod = 0; foreach ($fileList as $file) { $srcLastMod = max(filemtime($base . $file), $srcLastMod); } $refresh = $srcLastMod > filemtime($combinedFilePath); } else { // file doesn't exist, or refresh was explicitly required $refresh = true; } if (!$refresh) { continue; } $combinedData = ""; foreach (array_diff($fileList, $this->blocked) as $id => $file) { $fileContent = file_get_contents($base . $file); // if we have a javascript file and jsmin is enabled, minify the content if ($type == 'js' && $this->combine_js_with_jsmin) { $fileContent = JSMin::minify($fileContent); } if ($type == 'css') { // Rewrite urls in css to be relative to the docroot // Docroot param needs to be actual server docroot, not root of ushahidi site. // Using $_SERVER['DOCUMENT_ROOT']. Should possibly use DOCROOT, but remove Kohana::config('core.site_domain', TRUE); $fileContent = Minify_CSS_UriRewriter::rewrite($fileContent, pathinfo($base . $file, PATHINFO_DIRNAME), $_SERVER['DOCUMENT_ROOT']); // compress css (if enabled) if ($this->combine_css_with_cssmin) { $fileContent = CSSmin::go($fileContent); } } // write a header comment for each file for easier identification and debugging // also the semicolon between each file is required for jQuery to be combinable properly $combinedData .= "/****** FILE: {$file} *****/\n" . $fileContent . "\n" . ($type == 'js' ? ';' : '') . "\n"; } $successfulWrite = false; $fh = fopen($combinedFilePath, 'wb'); if ($fh) { if (fwrite($fh, $combinedData) == strlen($combinedData)) { $successfulWrite = true; } fclose($fh); unset($fh); } // Should we push this to the CDN too? if (Kohana::config("cdn.cdn_store_dynamic_content") and Kohana::config("requirements.cdn_store_combined_files")) { $cdn_combined_path = cdn::upload($combinedFilesFolder . $combinedFile, FALSE); } // Unsuccessful write - just include the regular JS files, rather than the combined one if (!$successfulWrite) { Kohana::log('alert', "Requirements_Backend::process_combined_files(): Couldn't create '{$combinedFilePath}'"); continue; } } // @todo Alters the original information, which means you can't call this // method repeatedly - it will behave different on the second call! $this->{$type} = $newRequirements; }
/** * Default Settings From Database */ // Retrieve Cached Settings $cache = Cache::instance(); $subdomain = Kohana::config('settings.subdomain'); $settings = $cache->get($subdomain . '_settings'); if (!$settings or !is_array($settings)) { // Cache is Empty so Re-Cache $settings = Settings_Model::get_array(); $cache->set($subdomain . '_settings', $settings, array('settings'), 60); // 1 Day } // Set Site Language Kohana::config_set('locale.language', $settings['site_language']); ush_locale::detect_language(); // Copy everything into kohana config settings.XYZ foreach ($settings as $key => $setting) { Kohana::config_set('settings.' . $key, $setting); } // Set Site Timezone if (function_exists('date_default_timezone_set')) { $timezone = isset($settings['site_timezone']) ? $settings['site_timezone'] : null; // Set default timezone, due to increased validation of date settings // which cause massive amounts of E_NOTICEs to be generated in PHP 5.2+ date_default_timezone_set(empty($timezone) ? date_default_timezone_get() : $timezone); Kohana::config_set('settings.site_timezone', $timezone); } // Cache Settings $cache_pages = (isset($settings['cache_pages']) and $settings['cache_pages']) ? TRUE : FALSE; Kohana::config_set('cache.cache_pages', $cache_pages);