示例#1
0
文件: lang.php 项目: trk/ionize
 function save_options()
 {
     // Force lang URLs ?
     $data = array('name' => 'force_lang_urls', 'content' => $this->input->post('force_lang_urls'));
     $this->settings_model->save_setting($data);
     // UI update panels
     $this->_reload_panel();
     $this->success(lang('ionize_message_lang_updated'));
 }
示例#2
0
 /**
  * Handles twitter Settings
  */
 function index()
 {
     $this->template->content = new View('admin/settings/twitter/main');
     $this->template->content->title = Kohana::lang('ui_admin.settings');
     // setup and initialize form field names
     $form = array('twitter_api_key' => '', 'twitter_api_key_secret' => '', 'twitter_token' => '', 'twitter_token_secret' => '', 'twitter_hashtags' => '');
     //	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('twitter_api_key', 'required', 'length[1,150]');
         $post->add_rules('twitter_api_key_secret', 'required', 'length[1,150]');
         $post->add_rules('twitter_token', 'required', 'length[1,150]');
         $post->add_rules('twitter_token_secret', 'required', 'length[1,150]');
         $post->add_rules('twitter_hashtags', 'length[1,150]');
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             // Yes! everything is valid
             Settings_Model::save_setting('twitter_api_key', $post->twitter_api_key);
             Settings_Model::save_setting('twitter_api_key_secret', $post->twitter_api_key_secret);
             Settings_Model::save_setting('twitter_token', $post->twitter_token);
             Settings_Model::save_setting('twitter_token_secret', $post->twitter_token_secret);
             Settings_Model::save_setting('twitter_hashtags', $post->twitter_hashtags);
             // 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 {
         $form = array('twitter_api_key' => Settings_Model::get_setting('twitter_api_key'), 'twitter_api_key_secret' => Settings_Model::get_setting('twitter_api_key_secret'), 'twitter_token' => Settings_Model::get_setting('twitter_token'), 'twitter_token_secret' => Settings_Model::get_setting('twitter_token_secret'), 'twitter_hashtags' => Settings_Model::get_setting('twitter_hashtags'));
     }
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
     // Javascript Header
     $this->themes->js = new View('admin/settings/twitter/twitter_js');
 }
示例#3
0
 /**
  * Upgrade page.
  *
  */
 public function index()
 {
     $this->template->content = new View('admin/upgrade/upgrade');
     $form_action = "";
     $this->template->content->title = Kohana::lang('ui_admin.upgrade_ushahidi');
     //$this->template->content->db_version =  Kohana::config('
     //	  settings.db_version');
     $this->template->content->db_version = Kohana::config('settings.db_version');
     //Setup and initialize form fields names
     $form = array('chk_db_backup_box' => '');
     //check if form has been submitted
     if ($_POST) {
         // For sanity sake, validate the data received from users.
         $post = Validation::factory(array_merge($_POST, $_FILES));
         // Add some filters
         $post->pre_filter('trim', TRUE);
         $post->add_rules('chk_db_backup_box', 'between[0,1]');
         if ($post->validate()) {
             $this->upgrade->logger("STARTED UPGRADE\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
             $this->template->content = new View('admin/upgrade/upgrade_status');
             $this->themes->js = new View('admin/upgrade/upgrade_status_js');
             $this->themes->js->backup = $post->chk_db_backup_box;
             $this->template->content->title = Kohana::lang('ui_admin.upgrade_ushahidi_status');
             $this->session->set('ftp_server', $post->ftp_server);
             $this->session->set('ftp_user_name', $post->ftp_user_name);
             $this->session->set('ftp_user_pass', $post->ftp_user_pass);
             Settings_Model::save_setting('ftp_server', $post->ftp_server);
             Settings_Model::save_setting('ftp_user_name', $post->ftp_user_name);
             // Log file location
             $this->themes->js->log_file = url::site() . "admin/upgrade/logfile?f=" . $this->session->get('upgrade_session') . ".txt";
         } else {
             $this->themes->js = new View('admin/upgrade/upgrade_js');
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = $post->errors('upgrade');
             $form_error = TRUE;
         }
     } else {
         $this->themes->js = new View('admin/upgrade/upgrade_js');
     }
     $this->template->content->ftp_server = Settings_Model::get_setting('ftp_server');
     $this->template->content->ftp_user_name = Settings_Model::get_setting('ftp_user_name');
     $this->template->content->form_action = $form_action;
     $this->template->content->current_version = Kohana::config('settings.ushahidi_version');
     $this->template->content->current_db_version = Kohana::config('settings.db_version');
     $this->template->content->environment = $this->_environment();
     $this->template->content->release_version = is_object($this->release) == true ? $this->release->version : "";
     $this->template->content->release_db_version = is_object($this->release) == true ? $this->release->version_db : "";
     $this->template->content->changelogs = is_object($this->release) == true ? $this->release->changelog : array();
     $this->template->content->download = is_object($this->release) == true ? $this->release->download : "";
     $this->template->content->critical = is_object($this->release) == true ? $this->release->critical : "";
 }
示例#4
0
 function index()
 {
     $this->template->content = new View('admin/addons/themes');
     $this->template->content->title = 'Addons';
     // setup and initialize form field names
     $form = array('site_style' => '');
     //  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_style', 'length[1,50]');
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             // Yes! everything is valid
             Settings_Model::save_setting('site_style', $post->site_style);
             // 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 {
         $site_style = Settings_Model::get_setting('site_style');
         // Retrieve Current Settings
         $form = array('site_style' => !empty($site_style) ? $site_style : 'default');
     }
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
     $themes = addon::get_addons('theme');
     foreach ($themes as $key => $theme) {
         // We want to hide checkin themes if checkins is not enabled
         if (!Kohana::config('settings.checkins') and $theme['Checkins'] == 1) {
             unset($themes[$key]);
         }
     }
     $this->template->content->themes = $themes;
 }
    /**
     * Creates the required database tables for the sharing module
     */
    public function run_install()
    {
        // Create the database tables
        // Include the table_prefix
        $this->db->query("\n\t\t\tCREATE TABLE IF NOT EXISTS `" . Kohana::config('database.default.table_prefix') . "sharing_site`\n\t\t\t(\n\t\t\t\t`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t`site_name` varchar(150) NOT NULL COMMENT 'name that appears on the front end',\n\t\t\t\t`site_url` varchar(255) NOT NULL COMMENT 'url of the deployment to share with',\n\t\t\t\t`site_color` varchar(20) DEFAULT 'CC0000' COMMENT 'color that shows the shared reports',\n\t\t\t\t`site_active` tinyint(4) NOT NULL DEFAULT '1' COMMENT 'sharing active or inactive ',\n\t\t\t\t`share_categories` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'sharing active or inactive ',\n\t\t\t\t`share_reports` tinyint(4) NOT NULL DEFAULT '1' COMMENT 'sharing active or inactive ',\n\t\t\t\t`site_username` varchar(150) NOT NULL COMMENT 'username for the remote site',\n\t\t\t\t`site_password` varchar(150) NOT NULL COMMENT 'password for the remote site',\n\t\t\t\tPRIMARY KEY (id)\n\t\t\t) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COMMENT='Stores sites we are getting shared reports from'\n\t\t\t");
        $result = $this->db->query("SHOW COLUMNS FROM `sharing_site` LIKE 'site_username';");
        if ($result->count() == 0) {
            $this->db->query('
					ALTER TABLE `sharing_site`
						ADD COLUMN `site_username` varchar(150) NOT NULL COMMENT \'username for the remote site\',
						ADD COLUMN `site_password` varchar(150) NOT NULL COMMENT \'password for the remote site\'
				');
        }
        $this->db->query("\n\t\t\tCREATE TABLE IF NOT EXISTS `" . Kohana::config('database.default.table_prefix') . "sharing_incident`\n\t\t\t(\n\t\t\t\t`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t`location_id` bigint(20) unsigned NOT NULL,\n\t\t\t\t`sharing_site_id` INT UNSIGNED NOT NULL,\n\t\t\t\t`remote_incident_id` BIGINT(20) UNSIGNED NOT NULL,\n\t\t\t\t`updated` datetime DEFAULT NULL,\n\t\t\t\t`incident_title` varchar(255) NOT NULL COMMENT 'title of the report',\n\t\t\t\t`incident_description` longtext,\n\t\t\t\t`incident_date` datetime DEFAULT NULL,\n\t\t\t\t`incident_mode` tinyint(4) NOT NULL DEFAULT '1' COMMENT '1 - WEB, 2 - SMS, 3 - EMAIL, 4 - TWITTER',\n\t\t\t\t`incident_active` tinyint(4) NOT NULL DEFAULT '0',\n\t\t\t\t`incident_verified` tinyint(4) NOT NULL DEFAULT '0',\n\t\t\t\tPRIMARY KEY (id),\n\t\t\t\tKEY `location_id` (`location_id`)\n\t\t\t) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COMMENT='Stores shared reports'\n\t\t\t");
        $this->db->query("\n\t\t\tCREATE TABLE IF NOT EXISTS `" . Kohana::config('database.default.table_prefix') . "sharing_incident_category` (\n\t\t\t  `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t  `sharing_incident_id` bigint(20) unsigned NOT NULL DEFAULT '0',\n\t\t\t  `category_id` int(11) unsigned NOT NULL DEFAULT '5',\n\t\t\t  PRIMARY KEY (`id`),\n\t\t\t  UNIQUE KEY `sharing_incident_category_ids` (`sharing_incident_id`,`category_id`)\n\t\t\t) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COMMENT='Stores shared reports categories'\n\t\t\t");
        $this->db->query("\n\t\t\tCREATE TABLE IF NOT EXISTS `" . Kohana::config('database.default.table_prefix') . "sharing_incident_media` (\n\t\t\t  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t  `sharing_incident_id` bigint(20) unsigned NOT NULL DEFAULT '0',\n\t\t\t  `media_id` bigint(20) unsigned NOT NULL DEFAULT '0',\n\t\t\t  PRIMARY KEY (`id`),\n\t\t\t  UNIQUE KEY `sharing_incident_media_ids` (`sharing_incident_id`,`media_id`)\n\t\t\t) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COMMENT='Stores shared reports media'\n\t\t\t");
        $this->db->query("\n\t\t\tCREATE TABLE IF NOT EXISTS `" . Kohana::config('database.default.table_prefix') . "sharing_incident_comment` (\n\t\t\t  `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t  `sharing_incident_id` bigint(20) unsigned NOT NULL DEFAULT '0',\n\t\t\t  `comment_id` int(11) unsigned NOT NULL DEFAULT '5',\n\t\t\t  PRIMARY KEY (`id`),\n\t\t\t  UNIQUE KEY `sharing_incident_comment_ids` (`sharing_incident_id`,`comment_id`)\n\t\t\t) ENGINE=MyISAM AUTO_INCREMENT=14064 DEFAULT CHARSET=utf8 COMMENT='Stores shared reports comments'\n\t\t\t");
        $this->db->query("\n\t\t\tCREATE TABLE IF NOT EXISTS `" . Kohana::config('database.default.table_prefix') . "sharing_category`\n\t\t\t(\n\t\t\t\t`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t`sharing_site_id` INT UNSIGNED NOT NULL,\n\t\t\t\t`category_id` BIGINT(20) UNSIGNED NOT NULL,\n\t\t\t\t`remote_category_id` BIGINT(20) UNSIGNED NOT NULL,\n\t\t\t\t`updated` datetime DEFAULT NULL,\n\t\t\t\tPRIMARY KEY (id),\n\t\t\t  UNIQUE KEY `category_id` (`category_id`),\n\t\t\t  UNIQUE KEY `remote_category_id` (`sharing_site_id`,`remote_category_id`)\n\t\t\t) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COMMENT='Stores shared categories'\n\t\t\t");
        // Create view for querying
        $this->db->query("\n\t\t\tCREATE OR REPLACE ALGORITHM=UNDEFINED DEFINER=CURRENT_USER SQL SECURITY INVOKER VIEW `sharing_combined_incident` AS\n\t\t\t\tSELECT `incident`.`id` AS `id`,\n\t\t\t\t\t`incident`.`incident_title` AS `incident_title`,\n\t\t\t\t\t`incident`.`incident_description` AS `incident_description`,\n\t\t\t\t\t`incident`.`incident_date` AS `incident_date`,\n\t\t\t\t\t`incident`.`incident_mode` AS `incident_mode`,\n\t\t\t\t\t`incident`.`location_id` AS `location_id`,\n\t\t\t\t\t`incident`.`incident_active` AS `incident_active`,\n\t\t\t\t\t`incident`.`incident_verified` AS `incident_verified`,\n\t\t\t\t\t'main' AS `source`,\n\t\t\t\t\tNULL AS `source_url`\n\t\t\t\tFROM `incident`\n\t\t\t\tUNION\n\t\t\t\tSELECT\n\t\t\t\t\t`sharing_incident`.`id` AS `id`,\n\t\t\t\t\t`sharing_incident`.`incident_title` AS `incident_title`,\n\t\t\t\t\t`sharing_incident`.`incident_description` AS `incident_description`,\n\t\t\t\t\t`sharing_incident`.`incident_date` AS `incident_date`,\n\t\t\t\t\t`sharing_incident`.`incident_mode` AS `incident_mode`,\n\t\t\t\t\t`sharing_incident`.`location_id` AS `location_id`,\n\t\t\t\t\t`sharing_incident`.`incident_active` AS `incident_active`,\n\t\t\t\t\t`sharing_incident`.`incident_verified` AS `incident_verified`,\n\t\t\t\t\t`sharing_incident`.`sharing_site_id` AS `source`,\n\t\t\t\t\t`sharing_site`.`site_url` AS `source_url`\n\t\t\t\tFROM `sharing_incident`\n\t\t\t\tLEFT JOIN `sharing_site`\n\t\t\t\t\tON (`sharing_incident`.`sharing_site_id` = `sharing_site`.`id`)\n\t\t\t");
        $this->db->query("\n\t\t\tCREATE OR REPLACE ALGORITHM=UNDEFINED DEFINER=CURRENT_USER SQL SECURITY INVOKER VIEW `sharing_combined_incident_category` AS\n\t\t\t\tSELECT `incident_category`.`incident_id` AS `incident_id`,\n\t\t\t\t\tNULL AS `sharing_incident_id`,\n\t\t\t\t\t`incident_category`.`category_id` AS `category_id`\n\t\t\t\tFROM `incident_category`\n\t\t\t\tUNION\n\t\t\t\tSELECT\n\t\t\t\t\tNULL AS `incident_id`,\n\t\t\t\t\t`sharing_incident_category`.`sharing_incident_id` AS `sharing_incident_id`,\n                  `sharing_incident_category`.`category_id` AS `category_id`\n\t\t\t\tFROM `sharing_incident_category`\n\t\t\t");
        //Dump the sharing scheduler item from bundled SQL dump file
        $this->db->query("DELETE FROM `" . Kohana::config('database.default.table_prefix') . "scheduler` where scheduler_name = 'Sharing' ");
        // Add sharing in to scheduler table
        $this->db->query("INSERT IGNORE INTO `" . Kohana::config('database.default.table_prefix') . "scheduler`\n\t\t\t\t(`scheduler_name`,`scheduler_last`,`scheduler_weekday`,`scheduler_day`,`scheduler_hour`,`scheduler_minute`,`scheduler_controller`,`scheduler_active`) VALUES\n\t\t\t\t('Sharing','0','-1','-1','-1','-1','s_sharing','1')");
        // Add Other category to the categories list (if it doesn't exist already)
        $categoryname = "Other";
        $other_category = ORM::factory('category')->where('category_title', $categoryname)->where('parent_id', 0)->find();
        $current_other_category_id = Settings_Model::get_setting('sharing_other_category_id');
        if ($other_category->loaded && empty($current_other_category_id)) {
            // We already have a category "Other", save setting
            Settings_Model::save_setting('sharing_other_category_id', $other_category->id);
        } else {
            // No category named "Other". Do we have an id save though (maybe it's been renamed)
            $category = ORM::factory('Category', Settings_Model::get_setting('sharing_other_category_id'));
            if (!$category->loaded) {
                $this->notices[] = Kohana::lang('import.new_category') . $categoryname;
                $category = new Category_Model();
                $category->category_title = $categoryname;
                // We'll use grey for now. Maybe something random?
                $category->category_color = '000000';
                $category->category_visible = 1;
                // FIXIT: We need to make this zero for non-central deployments?
                $category->category_trusted = 1;
                // Trusted - can't delete
                $category->category_description = "Category with reports that couldn't be categorised from other deployments";
                //FIXIT: need to l10n this;
                $category->category_position = ORM::factory('category')->count_all();
                $category->save();
                Settings_Model::save_setting('sharing_other_category_id', $category->id);
            }
        }
    }
示例#6
0
 function index()
 {
     $this->template->content = new View('admin/addons/themes');
     $this->template->content->title = 'Addons';
     // setup and initialize form field names
     $form = array('site_style' => '');
     //  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_style', 'length[1,50]');
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             // Yes! everything is valid
             Settings_Model::save_setting('site_style', $post->site_style);
             //add details to application/config/email.php
             //$this->_add_email_settings($settings);
             // Delete Settings Cache
             $cache = Cache::instance();
             $cache->delete('settings');
             $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
         $form = array('site_style' => Settings_Model::get_setting('site_style'));
     }
     $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->themes = $this->_get_themes();
 }
示例#7
0
 /**
  * Creates a new site in centralized stat tracker
  * @param sitename - name of the instance
  * @param url - base url
  */
 public function create_site($sitename, $url)
 {
     $stat_url = Kohana::config('config.external_site_protocol') . '://tracker.ushahidi.com/px.php?task=cs&sitename=' . urlencode($sitename) . '&url=' . urlencode($url);
     // Ignore errors since we are error checking later
     $xml = simplexml_load_string(self::_curl_req($stat_url));
     if ($xml === false) {
         return false;
     }
     $stat_id = (string) $xml->id[0];
     $stat_key = (string) $xml->key[0];
     if ($stat_id > 0) {
         Settings_Model::save_setting('stat_id', $stat_id);
         Settings_Model::save_setting('stat_key', $stat_key);
         return $stat_id;
     }
     return false;
 }
示例#8
0
 /**
  * Map Settings
  */
 public function index($saved = false)
 {
     // Display all maps
     $this->themes->api_url = Kohana::config('settings.api_url_all');
     // Current Default Country
     $current_country = Kohana::config('settings.default_country');
     $this->template->content = new View('admin/settings/main');
     $this->template->content->title = Kohana::lang('ui_admin.settings');
     // setup and initialize form field names
     $form = array('default_map' => '', 'api_google' => '', 'api_live' => '', 'default_country' => '', 'multi_country' => '', 'default_lat' => '', 'default_lon' => '', 'default_zoom' => '', 'default_map_all' => '', 'allow_clustering' => '', 'default_map_all_icon' => '', 'default_map_all_icon_id' => '', 'delete_default_map_all_icon' => '', 'enable_timeline' => '');
     //	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 = $saved == 'saved';
     // 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($_POST)->pre_filter('trim', TRUE)->add_rules('default_country', 'required', 'numeric', 'length[1,4]')->add_rules('multi_country', 'numeric', 'length[1,1]')->add_rules('default_map', 'required', 'length[0,100]')->add_rules('default_zoom', 'required', 'between[0,21]')->add_rules('default_lat', 'required', 'between[-85,85]')->add_rules('default_lon', 'required', 'between[-180,180]')->add_rules('allow_clustering', 'required', 'between[0,1]')->add_rules('default_map_all', 'required', 'alpha_numeric', 'length[6,6]')->add_rules('api_google', 'length[0,200]')->add_rules('api_live', 'length[0,200]')->add_rules('enable_timeline', 'numeric', 'length[1,1]');
         // Add rules for file upload
         $files = Validation::factory($_FILES);
         $files->add_rules('default_map_all_icon', '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)) {
             // Save all the settings
             Settings_Model::save_all($post);
             // E.Kala 20th April 2012
             // Ghetto workaround prevent resetting og Bing Maps API Key
             // Soon to be addressed conclusively
             if (isset($post['api_live']) and !empty($post['api_live'])) {
                 Settings_Model::save_setting('api_live', $post->api_live);
             }
             // Deal with default category icon now
             // Check if deleting or updating a new image (or doing nothing)
             if (isset($post->delete_default_map_all_icon) and $post->delete_default_map_all_icon == 1) {
                 // Delete old badge image
                 ORM::factory('media')->delete(Settings_Model::get_setting('default_map_all_icon_id'));
                 // Remove from DB table
                 Settings_Model::save_setting('default_map_all_icon_id', NULL);
             } else {
                 // We aren't deleting, so try to upload if we are uploading an image
                 $filename = upload::save('default_map_all_icon');
                 if ($filename) {
                     $new_filename = "default_map_all_" . 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(32, 32, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $m_name);
                     // Thumbnail
                     $t_name = $new_filename . "_t" . $file_type;
                     Image::factory($filename)->resize(16, 16, 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 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 image in settings
                     Settings_Model::save_setting('default_map_all_icon_id', $media->id);
                 }
             }
             // Delete Settings Cache
             $this->cache->delete('settings');
             $this->cache->delete_tag('settings');
             // Everything is A-Okay!
             $form_saved = TRUE;
             // Action::map_settings_modified - Map settings have changed
             Event::run('ushahidi_action.map_settings_modified');
             // Redirect to reload everything over again
             url::redirect('admin/settings/index/saved');
         } 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 = Settings_Model::get_settings(array_keys($form));
         $form = array('default_map' => $settings['default_map'], 'api_google' => $settings['api_google'], 'api_live' => $settings['api_live'], 'default_country' => $settings['default_country'], 'multi_country' => $settings['multi_country'], 'default_lat' => $settings['default_lat'], 'default_lon' => $settings['default_lon'], 'default_zoom' => $settings['default_zoom'], 'allow_clustering' => $settings['allow_clustering'], 'default_map_all' => $settings['default_map_all'], 'default_map_all_icon_id' => $settings['default_map_all_icon_id'], 'enable_timeline' => $settings['enable_timeline']);
     }
     // Get default category image
     if (($default_map_all_icon_id = Settings_Model::get_setting('default_map_all_icon_id')) !== NULL) {
         $icon = ORM::factory('media')->find($default_map_all_icon_id);
         $this->template->content->default_map_all_icon = url::convert_uploaded_to_abs($icon->media_link);
         $this->template->content->default_map_all_icon_m = url::convert_uploaded_to_abs($icon->media_medium);
         $this->template->content->default_map_all_icon_t = url::convert_uploaded_to_abs($icon->media_thumb);
     } else {
         $this->template->content->default_map_all_icon = NULL;
         $this->template->content->default_map_all_icon_m = NULL;
         $this->template->content->default_map_all_icon_t = NULL;
     }
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
     // Get Countries
     $countries = array();
     foreach (ORM::factory('country')->orderby('country')->find_all() as $country) {
         // Create a list of all categories
         $this_country = $country->country;
         if (strlen($this_country) > 35) {
             $this_country = substr($this_country, 0, 30) . "...";
         }
         $countries[$country->id] = $this_country;
     }
     $this->template->content->countries = $countries;
     // Zoom Array for Slider
     $default_zoom_array = array();
     for ($i = Kohana::config('map.minZoomLevel'); $i < Kohana::config('map.minZoomLevel') + Kohana::config('map.numZoomLevels'); $i++) {
         $default_zoom_array[$i] = $i;
     }
     $this->template->content->default_zoom_array = $default_zoom_array;
     // Get Map API Providers
     $layers = map::base();
     $map_array = array();
     foreach ($layers as $layer) {
         $map_array[$layer->name] = $layer->title;
     }
     $this->template->content->map_array = $map_array;
     $this->template->content->yesno_array = array('1' => utf8::strtoupper(Kohana::lang('ui_main.yes')), '0' => utf8::strtoupper(Kohana::lang('ui_main.no')));
     // Javascript Header
     $this->themes->map_enabled = TRUE;
     $this->themes->colorpicker_enabled = TRUE;
     $this->themes->js = new View('admin/settings/settings_js');
     $this->themes->js->default_map = $form['default_map'];
     $this->themes->js->default_zoom = $form['default_zoom'];
     $this->themes->js->default_lat = $form['default_lat'];
     $this->themes->js->default_lon = $form['default_lon'];
     $this->themes->js->all_maps_json = $this->_generate_settings_map_js();
 }
示例#9
0
 /**
  * Handles SMS Settings
  */
 public function sms()
 {
     $this->template->content = new View('admin/settings/sms');
     $this->template->content->title = Kohana::lang('ui_admin.settings');
     // setup and initialize form field names
     $form = array('sms_provider' => '', 'sms_no1' => '', 'sms_no2' => '', 'sms_no3' => '', 'sms_alert_url' => '');
     //	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('sms_provider', 'length[1,100]');
         $post->add_rules('sms_no1', 'numeric', 'length[1,30]');
         $post->add_rules('sms_no2', 'numeric', 'length[1,30]');
         $post->add_rules('sms_no3', 'numeric', 'length[1,30]');
         $post->add_rules('sms_alert_url', 'required', 'between[0,1]');
         // HT: new setting for url on sms
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             if (!Settings_Model::get_setting('sms_alert_url')) {
                 Settings_Model::save_setting('sms_alert_url', $post->sms_alert_url);
             }
             // Yes! everything is valid
             Settings_Model::save_all($post);
             // 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 {
         $settings = Settings_Model::get_settings(array_keys($form));
         $settings['sms_alert_url'] = isset($settings['sms_alert_url']) ? $settings['sms_alert_url'] : 0;
         // HT: might not be in database so calling manually return NULL if not exist
         // Retrieve Current Settings
         $form = array('sms_provider' => $settings['sms_provider'], 'sms_no1' => $settings['sms_no1'], 'sms_no2' => $settings['sms_no2'], 'sms_no3' => $settings['sms_no3'], 'sms_alert_url' => $settings['sms_alert_url']);
     }
     $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->alert_url_array = array('1' => Kohana::lang('ui_admin.yes'), '0' => Kohana::lang('ui_admin.no'));
     $this->template->content->sms_provider_array = array_merge(array("" => "-- Select One --"), plugin::get_sms_providers());
 }
示例#10
0
 public function sort()
 {
     $this->auto_render = FALSE;
     $this->template = "";
     if ($_POST) {
         if (isset($_POST['blocks']) and !empty($_POST['blocks'])) {
             $active_blocks = Settings_Model::get_setting('blocks');
             $active_blocks = array_filter(explode("|", $active_blocks));
             $blocks = array_map('trim', explode(',', $_POST['blocks']));
             $block_check = array();
             foreach ($blocks as $block) {
                 if (in_array($block, $active_blocks)) {
                     $block_check[] = $block;
                 }
             }
             Settings_Model::save_setting('blocks', implode("|", $active_blocks));
         }
     }
 }
示例#11
0
 public function sort()
 {
     $this->auto_render = FALSE;
     $this->template = "";
     if ($_POST) {
         $post = Validation::factory($_POST);
         $post->add_rules('blocks', 'required');
         if ($post->validate()) {
             $active_blocks = Settings_Model::get_setting('blocks');
             $active_blocks = array_filter(explode("|", $active_blocks));
             $blocks = array_map('trim', explode(',', $_POST['blocks']));
             $block_check = array();
             foreach ($blocks as $block) {
                 if (in_array($block, $active_blocks)) {
                     $block_check[] = $block;
                 }
             }
             Settings_Model::save_setting('blocks', implode("|", $block_check));
             echo 'success';
             return;
         }
     }
     echo 'failure';
     return;
 }
示例#12
0
foreach (map::base() as $layer) {
    if (empty($layer->api_url)) {
        continue;
    }
    // Add to array, use url as key to avoid dupes
    $api_url_all[$layer->api_url] = $layer->api_url;
}
Kohana::config_set('settings.api_url_all', $api_url_all);
// Additional Mime Types (KMZ/KML)
Kohana::config_set('mimes.kml', array('text/xml'));
Kohana::config_set('mimes.kmz', array('text/xml'));
// Set 'settings.forgot_password_key' if not set already
if (!Kohana::config('settings.forgot_password_secret')) {
    $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+[]{};:,.?`~';
    $key = text::random($pool, 64);
    Settings_Model::save_setting('forgot_password_secret', $key);
    Kohana::config_set('settings.forgot_password_secret', $key);
    $cache->delete($subdomain . '_settings');
}
// Set dfault value for external site protocol
if (!Kohana::config('config.external_site_protocol')) {
    Kohana::config_set('config.external_site_protocol', 'https');
}
// Default for allowed_html in case upgraders don't add it to config.php
if (!Kohana::config('config.allowed_html')) {
    Kohana::config_set('config.allowed_html', 'a[href|title],p,img[src|alt],br,b,u,strong,em,i');
}
// Default for allowed iframe regexp, in case upgraders don't add it to config.php
if (!Kohana::config('config.allowed_iframe_regexp')) {
    Kohana::config_set('config.allowed_iframe_regexp', '%^http://(www.youtube.com/embed/|player.vimeo.com/video/|w.soundcloud.com/player)%');
}
示例#13
0
 /**
  * Creates a new site in centralized stat tracker
  * @param sitename - name of the instance
  * @param url - base url
  */
 public function create_site($sitename, $url)
 {
     $stat_url = 'https://tracker.ushahidi.com/px.php?task=cs&sitename=' . urlencode($sitename) . '&url=' . urlencode($url);
     // Ignore errors since we are error checking later
     $xml = simplexml_load_string(Stats_Model::_curl_req($stat_url));
     $stat_id = (string) $xml->id[0];
     $stat_key = (string) $xml->key[0];
     if ($stat_id > 0) {
         Settings_Model::save_setting('stat_id', $stat_id);
         Settings_Model::save_setting('stat_key', $stat_key);
         return $stat_id;
     }
     return false;
 }