Example #1
0
 public function main_element_attributes()
 {
     if (locale::is_rtl()) {
         return 'class="rtl"';
     }
     return '';
 }
Example #2
0
 /**
  * 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] = locale::language($locale[0]) . " (" . $locale[1] . ")";
         }
     }
     if (is_dir($i18n_dir)) {
         @closedir($i18n_dir);
     }
     return $directories;
 }
  function run(&$filter_chain, &$request, &$response) 
  {
    debug :: add_timing_point('locale filter started');
    
    if(!$node = map_request_to_node($request))
    {
    	define('CONTENT_LOCALE_ID', DEFAULT_CONTENT_LOCALE_ID);
    	define('MANAGEMENT_LOCALE_ID', CONTENT_LOCALE_ID);
    	
    	$locale =& locale :: instance();    	
    	$locale->setlocale();
    	
      $filter_chain->next();
      return;
    }
          
    if($object_locale_id = site_object :: get_locale_by_id($node['object_id']))
    	define('CONTENT_LOCALE_ID', $object_locale_id);
    else
      define('CONTENT_LOCALE_ID', DEFAULT_CONTENT_LOCALE_ID);
    
    $user = user :: instance();
    if($user_locale_id = $user->get_locale_id())
    	define('MANAGEMENT_LOCALE_ID', $user_locale_id);
    else
      define('MANAGEMENT_LOCALE_ID', CONTENT_LOCALE_ID);
              
    debug :: add_timing_point('locale filter finished');

  	$locale =& locale :: instance();    	
  	$locale->setlocale();
    
    $filter_chain->next();
  }   
Example #4
0
 public function body_attributes()
 {
     if (locale::is_rtl()) {
         return 'class="rtl"';
     }
     return '';
 }
	function get_cart_summ()
	{
		$cart =& cart :: instance();
		$locale = locale :: instance();
		
		return number_format($cart->get_total_summ(), $locale->fract_digits, $locale->decimal_symbol, $locale->thousand_separator);
	}
 function mime_mail()
 {
     $this->html_images = array();
     $this->headers = array();
     $this->is_built = false;
     $this->image_types = array('gif' => 'image/gif', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'jpe' => 'image/jpeg', 'bmp' => 'image/bmp', 'png' => 'image/png', 'tif' => 'image/tiff', 'tiff' => 'image/tiff', 'swf' => 'application/x-shockwave-flash');
     $locale =& locale::instance();
     $this->build_params['html_encoding'] = '8bit';
     $this->build_params['text_encoding'] = '8bit';
     $this->build_params['html_charset'] = $locale->get_charset();
     $this->build_params['text_charset'] = $locale->get_charset();
     $this->build_params['head_charset'] = $locale->get_charset();
     $this->build_params['text_wrap'] = 998;
     if (!empty($_SERVER['HTTP_HOST'])) {
         $helo = $_SERVER['HTTP_HOST'];
     } elseif (!empty($_SERVER['SERVER_NAME'])) {
         $helo = $_SERVER['SERVER_NAME'];
     } else {
         $helo = 'localhost';
     }
     $this->smtp_params['host'] = 'localhost';
     $this->smtp_params['port'] = 25;
     $this->smtp_params['helo'] = $helo;
     $this->smtp_params['auth'] = false;
     $this->smtp_params['user'] = '';
     $this->smtp_params['pass'] = '';
     $this->headers['MIME-Version'] = '1.0';
 }
	function _set_period_filter()
	{
		$locale =& locale :: instance();
		$start_date = new date();
		$start_date->set_hour(0);
		$start_date->set_minute(0);
		$start_date->set_second(0);

		if (isset($_REQUEST['stats_start_date']))
		{
			$start_date->set_by_string($_REQUEST['stats_start_date'], $locale->get_short_date_time_format());
		}
		
		$finish_date = new date();

		if (isset($_REQUEST['stats_finish_date']))
		{
			$finish_date->set_by_string($_REQUEST['stats_finish_date'], $locale->get_short_date_time_format());
		}

		$finish_date->set_hour(23);
		$finish_date->set_minute(59);
		$finish_date->set_second(59);
		
		$this->stats_report->set_period_filter($start_date, $finish_date);
	}
 function setUp()
 {
     $this->report = new Mockstats_referers_report($this);
     $this->ds = new stats_referers_except_groups_list_datasource_test_version($this);
     $this->ds->setReturnReference('_create_referers_report', $this->report);
     $this->ds->stats_referers_list_datasource();
     $this->locale =& locale::instance();
 }
 function locale_format($number, $locale_string = null)
 {
     $locale = locale::instance($locale_string);
     $neg = $number < 0;
     $num = $neg ? -$number : $number;
     $num_text =& number_format($num, $locale->get_currency_fract_digits(), $locale->get_currency_decimal_symbol(), $locale->get_currency_thousand_separator());
     $text =& utf8_str_replace(array('%c', '%p', '%q'), array($locale->get_currency_symbol(), $neg ? $locale->get_currency_negative_symbol() : $locale->get_currency_positive_symbol(), $num_text), $neg ? $locale->get_currency_negative_format() : $locale->get_currency_positive_format());
     return $text;
 }
 function check($value)
 {
     $locale =& locale::instance();
     $date =& new date();
     $date->set_by_string($value, $locale->get_short_date_format());
     if (!$date->is_valid()) {
         $this->error('INVALID_DATE');
     }
 }
Example #11
0
 private static function _add_locale_dropdown(&$form, $user = null)
 {
     $locales = locale::installed();
     if (count($locales) > 1) {
         // Put "none" at the first position in the array
         $locales = array_merge(array("" => t("&laquo; none &raquo;")), $locales);
         $selected_locale = $user && $user->locale ? $user->locale : "";
         $form->dropdown("locale")->label(t("Language Preference"))->options($locales)->selected($selected_locale);
     }
 }
 function format()
 {
     if ($this->format_string) {
         $format_string = $this->format_string;
     } else {
         $locale =& locale::instance($this->locale_type);
         $format_string = $locale->get_short_date_format();
     }
     echo $this->date->format($format_string);
 }
 function _valid_perform()
 {
     $locale_id = $this->dataspace->get('locale_id');
     if (!locale::is_valid_locale_id($locale_id)) {
         return new close_popup_response(RESPONSE_STATUS_FAILURE);
     }
     $user =& user::instance();
     $user->set_locale_id($locale_id);
     return new close_popup_response(RESPONSE_STATUS_SUCCESS);
 }
Example #14
0
 public static function load($locale = null)
 {
     self::$translations = array();
     if (!$locale && EE::is_set('_config', 'locale')) {
         $locale = EE::get('_config', 'locale');
     }
     if ($locale) {
         $file = EE::get('_dir') . '/' . EE::APP_TRANSLATIONS_DIR . '/' . $locale . '.php';
         if (file_exists($file)) {
             self::$translations = (require $file);
             return true;
         }
     }
     return false;
 }
 function _valid_perform(&$request, &$response)
 {
     $locale_id = $this->dataspace->get('locale_id');
     if ($request->has_attribute('popup')) {
         $response->write(close_popup_response($request));
     } elseif (isset($_SERVER['HTTP_REFERER'])) {
         $response->redirect($_SERVER['HTTP_REFERER']);
     } else {
         $response->redirect('/');
     }
     if (!locale::is_valid_locale_id($locale_id)) {
         $request->set_status(REQUEST_STATUS_FAILURE);
     }
     $user =& user::instance();
     $user->set_locale_id($locale_id);
     $request->set_status(REQUEST_STATUS_SUCCESS);
 }
 function _set_period_filter(&$request)
 {
     $locale =& locale::instance();
     $start_date = new date();
     $start_date->set_hour(0);
     $start_date->set_minute(0);
     $start_date->set_second(0);
     if ($stats_start_date = $request->get_attribute('stats_start_date')) {
         $start_date->set_by_string($stats_start_date, $locale->get_short_date_time_format());
     }
     $finish_date = new date();
     if ($stats_finish_date = $request->get_attribute('stats_finish_date')) {
         $finish_date->set_by_string($stats_finish_date, $locale->get_short_date_time_format());
     }
     $finish_date->set_hour(23);
     $finish_date->set_minute(59);
     $finish_date->set_second(59);
     $this->stats_report->set_period_filter($start_date, $finish_date);
 }
 function format($value)
 {
     $locale =& locale::instance();
     if (!isset($this->attributes['fract_digits']) || !$this->attributes['fract_digits']) {
         $fract_digits = $locale->fract_digits;
     } else {
         $fract_digits = (int) $this->attributes['fract_digits'];
     }
     if (!isset($this->attributes['decimal_symbol']) || !$this->attributes['decimal_symbol']) {
         $decimal_symbol = $locale->decimal_symbol;
     } else {
         $decimal_symbol = $this->attributes['dec_point'];
     }
     if (!isset($this->attributes['thousand_separator']) || !$this->attributes['thousand_separator']) {
         $thousand_separator = $locale->thousand_separator;
     } else {
         $thousand_separator = $this->attributes['thousand_separator'];
     }
     return number_format($value, $fract_digits, $decimal_symbol, $thousand_separator);
 }
 function _get_mail_body($template_path)
 {
     $template = new template($template_path);
     $locale =& locale::instance();
     $date = new date();
     $template->set('date', $date->format($locale->get_short_date_format()));
     $cart =& cart::instance();
     $list =& $template->find_child('cart_items');
     $list->register_dataset($cart->get_items_array_dataset());
     $template->set('name', $this->dataspace->get('name'));
     $template->set('notes', $this->dataspace->get('notes'));
     $template->set('phone', $this->dataspace->get('phone'));
     $template->set('address', $this->dataspace->get('address'));
     $template->set('email', $this->dataspace->get('email'));
     ob_start();
     $template->display();
     $content = ob_get_contents();
     ob_end_clean();
     return $content;
 }
 function &get_language_ini($with_variation = false)
 {
     $type = $with_variation ? 'variation' : 'default';
     if (get_class($this->language_ini[$type]) != 'ini') {
         $this->language_ini[$type] = locale::_get_ini($with_variation, LOCALE_DIR . 'language/');
     }
     return $this->language_ini[$type];
 }
	function get_value()
	{		
		$form =& $this->find_parent_by_class('form_component');
		
		$value = parent :: get_value();

		if(empty($value))
			$value = $this->get_attribute('default_value');		
		
		if($form->is_first_time())
		{				
			$locale =& locale :: instance();
			$date =& new date($value);
			
			$value = $date->format($locale->get_short_date_format());
		}
			
		return $value;
	}
 function get_options_array()
 {
     return locale::get_available_locales_data();
 }
Example #22
0
 /**
  * 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 = 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' => '');
     // 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()) {
                 // 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();
                     // Resize Image to 32px if greater
                     Image::factory($filename)->resize(32, 32, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $new_filename . ".png");
                     // Create a 16x16 version too
                     Image::factory($filename)->resize(16, 16, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $new_filename . "_16x16.png");
                     // Remove the temporary file
                     unlink($filename);
                     // Delete Old Image
                     $category_old_image = $category->category_image;
                     if (!empty($category_old_image) and file_exists(Kohana::config('upload.directory', TRUE) . $category_old_image)) {
                         unlink(Kohana::config('upload.directory', TRUE) . $category_old_image);
                     }
                     // Save
                     $category->category_image = $new_filename . ".png";
                     $category->category_image_thumb = $new_filename . "_16x16.png";
                     $category->save();
                 }
                 $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') {
             // Delete action
             if ($category->loaded) {
                 ORM::factory('category_lang')->where(array('category_id' => $category->id))->delete_all();
                 // @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') {
             // Show/Hide Action
             if ($category->loaded) {
                 $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') {
             // Delete Image/Icon Action
             if ($category->loaded) {
                 $category_image = $category->category_image;
                 $category_image_thumb = $category->category_image_thumb;
                 if (!empty($category_image) and file_exists(Kohana::config('upload.directory', TRUE) . $category_image)) {
                     unlink(Kohana::config('upload.directory', TRUE) . $category_image);
                 }
                 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_position', 'asc')->orderby('category_title', 'asc')->find_all($this->items_per_page, $pagination->sql_offset);
     $parents_array = ORM::factory('category')->where('parent_id', '0')->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;
 }
Example #23
0
 function _set_logged_user_data(&$user_data, $locale_id = '')
 {
     $this->_set_is_logged_in();
     $this->_set_id($user_data['id']);
     $this->_set_node_id($user_data['node_id']);
     $this->_set_login($user_data['identifier']);
     $this->_set_password($user_data['password']);
     $this->_set_email($user_data['email']);
     $this->_set_name($user_data['name']);
     $this->_set_lastname($user_data['lastname']);
     $this->_determine_groups();
     if ($locale_id && locale::is_valid_locale_id($locale_id)) {
         $this->set_locale_id($locale_id);
     }
 }
Example #24
0
	function index()
	{
		$this->template->content = new View('admin/categories');
		$this->template->content->title = Kohana::lang('ui_admin.categories');

		// Locale (Language) Array
		$locales = 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'  => ''
		);

		// 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)
		{
			// Instantiate Validation, use $post, so we don't overwrite $_POST fields with our own things

			$post = Validation::factory(array_merge($_POST,$_FILES));

			 //	 Add some filters

			$post->pre_filter('trim', TRUE);

			// Add Action

			if ($post->action == 'a')
			{
				// Add some rules, the input field, followed by a list of checks, carried out in order
				$post->add_rules('parent_id','required','numeric');
				$post->add_rules('category_title','required', 'length[3,80]');
				$post->add_rules('category_description','required');
				$post->add_rules('category_color','required', 'length[6,6]');
				$post->add_rules('category_image', 'upload::valid', 'upload::type[gif,jpg,png]', 'upload::size[50K]');

				$post->add_callbacks('parent_id', array($this,'parent_id_chk'));

				// 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]');
				}
			}

			// Test to see if things passed the rule checks
			if ($post->validate())
			{
				$category_id = $post->category_id;
				$category = new Category_Model($category_id);

				// Grab languages if they already exist

				$category_lang = Category_Lang_Model::category_langs($category->id);
				if(isset($category_lang[$category->id]))
				{
					$category_lang = $category_lang[$category->id];
				}else{
					$category_lang = FALSE;
				}

				if( $post->action == 'd' )
				{ // Delete Action

					// Delete localizations

					ORM::factory('category_lang')
						->where(array('category_id' => $category_id))
						->delete_all();

					// Delete category itself

					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' )
				{ // Show/Hide Action
					if ($category->loaded==true)
					{
						if ($category->category_visible == 1) {
							$category->category_visible = 0;
						}
						else
						{
							$category->category_visible = 1;
						}

						$category->save();
						$form_saved = TRUE;
						$form_action = strtoupper(Kohana::lang('ui_admin.modified'));
					}
				}
				elseif( $post->action == 'i' )
				{ // Delete Image/Icon Action

					if ($category->loaded==true)
					{
						$category_image = $category->category_image;
						$category_image_thumb = $category->category_image_thumb;

						if ( ! empty($category_image)
							 AND file_exists(Kohana::config('upload.directory', TRUE).$category_image))
						{
							unlink(Kohana::config('upload.directory', TRUE) . $category_image);
						}

						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'));
					}

				}
				elseif( $post->action == 'a' )
				{
					// Save Action
					$category->parent_id = $post->parent_id;
					$category->category_title = $post->category_title;
					$category->category_type = 5;
					$category->category_description = $post->category_description;
					$category->category_color = $post->category_color;
					$category->save();

					// Save Localizations
					foreach($post->category_title_lang as $lang_key => $localized_category_name){

						if(isset($category_lang[$lang_key]['id']))
						{
							// Update
							$cl = ORM::factory('category_lang',$category_lang[$lang_key]['id']);
						}else{
							// Add New
							$cl = 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();

						// Resize Image to 32px if greater
						Image::factory($filename)->resize(32,32,Image::HEIGHT)
							->save(Kohana::config('upload.directory', TRUE) . $new_filename.".png");
						// Create a 16x16 version too
						Image::factory($filename)->resize(16,16,Image::HEIGHT)
							->save(Kohana::config('upload.directory', TRUE) . $new_filename."_16x16.png");

						// Remove the temporary file
						unlink($filename);

						// Delete Old Image
						$category_old_image = $category->category_image;
						if ( ! empty($category_old_image)
							AND file_exists(Kohana::config('upload.directory', TRUE).$category_old_image))
							unlink(Kohana::config('upload.directory', TRUE).$category_old_image);

						// Save
						$category->category_image = $new_filename.".png";
						$category->category_image_thumb = $new_filename."_16x16.png";
						$category->save();
					}

					$form_saved = TRUE;
					$form_action = strtoupper(Kohana::lang('ui_admin.added_edited'));

					// Empty $form array
					array_fill_keys($form, '');
				}
			}
			// No! We have validation errors, we need to show the form again, with the errors
			else
			{
				// repopulate the form fields
				$form = arr::overwrite($form, $post->as_array());

			   // populate the error fields, if any
				$errors = arr::overwrite($errors, $post->errors('category'));
				$form_error = TRUE;
			}
		}

		// Pagination
		$pagination = new Pagination(array(
							'query_string' => 'page',
							'items_per_page' => (int) Kohana::config('settings.items_per_page_admin'),
							'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((int) Kohana::config('settings.items_per_page_admin'),
												$pagination->sql_offset);

		$parents_array = ORM::factory('category')
									 ->where('parent_id','0')
									 ->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->js = new View('admin/categories_js');
		$this->template->form_error = $form_error;

		$this->template->content->locale_array = $locales;
		$this->template->js->locale_array = $locales;
	}
Example #25
0
 static function fetch_updates()
 {
     $request->locales = array();
     $request->messages = new stdClass();
     $locales = locale::installed();
     foreach ($locales as $locale => $locale_data) {
         $request->locales[] = $locale;
     }
     // @todo Batch requests (max request size)
     foreach (Database::instance()->select("key", "locale", "revision", "translation")->from("incoming_translations")->get()->as_array() as $row) {
         if (!isset($request->messages->{$row->key})) {
             $request->messages->{$row->key} = 1;
         }
         if (!empty($row->revision) && !empty($row->translation)) {
             if (!is_object($request->messages->{$row->key})) {
                 $request->messages->{$row->key} = new stdClass();
             }
             $request->messages->{$row->key}->{$row->locale} = $row->revision;
         }
     }
     // @todo Include messages from outgoing_translations?
     $request_data = json_encode($request);
     $url = self::_server_url() . "?q=translations/fetch";
     list($response_data, $response_status) = remote::post($url, array("data" => $request_data));
     if (!remote::success($response_status)) {
         throw new Exception("@todo TRANSLATIONS_FETCH_REQUEST_FAILED " . $response_status);
     }
     if (empty($response_data)) {
         log::info("translations", "Translations fetch request resulted in an empty response");
         return;
     }
     $response = json_decode($response_data);
     // Response format (JSON payload):
     //   [{key:<key_1>, translation: <JSON encoded translation>, rev:<rev>, locale:<locale>},
     //    {key:<key_2>, ...}
     //   ]
     $count = count($response);
     log::info("translations", "Installed {$count} new / updated translation messages");
     foreach ($response as $message_data) {
         // @todo Better input validation
         if (empty($message_data->key) || empty($message_data->translation) || empty($message_data->locale) || empty($message_data->rev)) {
             throw new Exception("@todo TRANSLATIONS_FETCH_REQUEST_FAILED: Invalid response data");
         }
         $key = $message_data->key;
         $locale = $message_data->locale;
         $revision = $message_data->rev;
         $translation = serialize(json_decode($message_data->translation));
         // @todo Should we normalize the incoming_translations table into messages(id, key, message)
         // and incoming_translations(id, translation, locale, revision)? Or just allow
         // incoming_translations.message to be NULL?
         $locale = $message_data->locale;
         $entry = ORM::factory("incoming_translation")->where(array("key" => $key, "locale" => $locale))->find();
         if (!$entry->loaded) {
             // @todo Load a message key -> message (text) dict into memory outside of this loop
             $root_entry = ORM::factory("incoming_translation")->where(array("key" => $key, "locale" => "root"))->find();
             $entry->key = $key;
             $entry->message = $root_entry->message;
             $entry->locale = $locale;
         }
         $entry->revision = $revision;
         $entry->translation = $translation;
         $entry->save();
     }
 }
Example #26
0
 function login($login, $password, $locale_id = '')
 {
     $this->logout();
     if (!($record = $this->_get_identity_record($login, $password))) {
         return false;
     }
     $this->_set_is_logged_in();
     $this->_set_id($record['id']);
     $this->_set_node_id($record['node_id']);
     $this->_set_login($login);
     $this->_set_password($record['password']);
     $this->_set_email($record['email']);
     $this->_set_name($record['name']);
     $this->_set_lastname($record['lastname']);
     $this->_determine_groups();
     if ($locale_id && locale::is_valid_locale_id($locale_id)) {
         $this->set_locale_id($locale_id);
     }
     return true;
 }
Example #27
0
<div id="l10n-client" class="hidden">
  <div class="labels">
    <span class="toggle"><?php 
echo t("Translate Text");
?>
</span>
    <div class="label strings"><h2><?php 
echo t("Page Text");
?>
</h2></div>
    <div class="label source"><h2><?php 
echo t("Source");
?>
</div>
    <div class="label translation"><h2><?php 
echo t("Translation to %language", array("language" => locale::display_name()));
?>
</h2></div>
  </div>
  <div id="l10n-client-string-select">
    <ul class="string-list">
      <? foreach ($string_list as $string): ?>
      <li class="<?php 
echo $string["translation"] === "" ? "untranslated" : "translated";
?>
">
        <? if (is_array($string["source"])): ?>
       [one] - <?php 
echo $string["source"]["one"];
?>
<br/>
Example #28
0
 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 = 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=\"\">";
     $languages .= form::dropdown('l', $locales, Kohana::config('locale.language'), ' onchange="this.form.submit()" ');
     $languages .= "</form>";
     $languages .= "</div>";
     return $languages;
 }
Example #29
0
 /**
  * Site Settings
  */
 function site()
 {
     $this->template->content = new View('admin/site');
     $this->template->content->title = Kohana::lang('ui_admin.settings');
     // setup and initialize form field names
     $form = array('site_name' => '', 'site_tagline' => '', 'site_email' => '', 'alerts_email' => '', 'site_language' => '', 'site_contact_page' => '', 'items_per_page' => '', 'items_per_page_admin' => '', 'allow_reports' => '', 'allow_comments' => '', 'allow_feed' => '', 'allow_stat_sharing' => '', 'allow_clustering' => '', 'default_map_all' => '', '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;
     // 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,50]');
         $post->add_rules('site_tagline', 'length[3,100]');
         $post->add_rules('site_email', 'email', 'length[4,100]');
         $post->add_rules('alerts_email', 'email', 'length[4,100]');
         $post->add_rules('site_language', 'required', 'length[5, 5]');
         //$post->add_rules('site_help_page','required','between[0,1]');
         $post->add_rules('site_contact_page', 'required', 'between[0,1]');
         $post->add_rules('items_per_page', 'required', 'between[10,50]');
         $post->add_rules('items_per_page_admin', 'required', 'between[10,50]');
         $post->add_rules('allow_reports', 'required', 'between[0,1]');
         $post->add_rules('allow_comments', 'required', 'between[0,1]');
         $post->add_rules('allow_feed', 'required', 'between[0,1]');
         $post->add_rules('allow_stat_sharing', 'required', 'between[0,1]');
         $post->add_rules('allow_clustering', 'required', 'between[0,1]');
         $post->add_rules('default_map_all', 'required', 'alpha_numeric', 'length[6,6]');
         $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');
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             // 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_language = $post->site_language;
             //$settings->site_help_page = $post->site_help_page;
             $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->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->allow_clustering = $post->allow_clustering;
             $settings->default_map_all = $post->default_map_all;
             $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();
             // Delete Settings Cache
             $this->cache->delete('settings');
             $this->cache->delete_tag('settings');
             // Everything is A-Okay!
             $form_saved = TRUE;
             // 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
             $errors = arr::overwrite($errors, $post->errors('settings'));
             $form_error = TRUE;
         }
     } else {
         // Retrieve Current Settings
         $settings = ORM::factory('settings', 1);
         $form = array('site_name' => $settings->site_name, 'site_tagline' => $settings->site_tagline, 'site_email' => $settings->site_email, 'alerts_email' => $settings->alerts_email, 'site_language' => $settings->site_language, 'site_contact_page' => $settings->site_contact_page, 'items_per_page' => $settings->items_per_page, 'items_per_page_admin' => $settings->items_per_page_admin, 'allow_reports' => $settings->allow_reports, 'allow_comments' => $settings->allow_comments, 'allow_feed' => $settings->allow_feed, 'allow_stat_sharing' => $settings->allow_stat_sharing, 'allow_clustering' => $settings->allow_clustering, 'default_map_all' => $settings->default_map_all, 'google_analytics' => $settings->google_analytics, 'twitter_hashtags' => $settings->twitter_hashtags, 'api_akismet' => $settings->api_akismet);
     }
     $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('10' => '10 Items', '20' => '20 Items', '30' => '30 Items', '50' => '50 Items');
     $this->template->content->yesno_array = array('1' => strtoupper(Kohana::lang('ui_main.yes')), '0' => strtoupper(Kohana::lang('ui_main.no')));
     // Generate Available Locales
     $locales = locale::get_i18n();
     $this->template->content->locales_array = $locales;
     $this->cache->set('locales', $locales, array('locales'), 604800);
 }
Example #30
0
 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 = 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;
 }