function index() { $this->template->content = new View('admin/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 = new Settings_Model(1); $settings->site_style = $post->site_style; $settings->save(); //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 $settings = ORM::factory('settings', 1); $form = array('site_style' => $settings->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(); }
/** * Handles SMS Settings */ function index() { $this->template->content = new View('admin/facebook'); $this->template->content->title = Kohana::lang('ui_admin.settings'); // setup and initialize form field names $form = array('facebook_appid' => '', 'facebook_appsecret' => ''); // 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('facebook_appid', 'length[1,150]'); $post->add_rules('facebook_appsecret', 'length[1,150]'); // Test to see if things passed the rule checks if ($post->validate()) { // Yes! everything is valid $settings = new Settings_Model(1); $settings->facebook_appid = $post->facebook_appid; $settings->facebook_appsecret = $post->facebook_appsecret; $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('facebook_appid' => $settings->facebook_appid, 'facebook_appsecret' => $settings->facebook_appsecret); } $this->template->content->form = $form; $this->template->content->errors = $errors; $this->template->content->form_error = $form_error; $this->template->content->form_saved = $form_saved; }
/** * Geocoding function that uses nominatin engine. * * @param string Address * @return string[]|boolean Location information [country, country_id, location_name, latitude, longitude], FALSE if unsucessful * */ public static function nominatim($address) { $payload = FALSE; $result = FALSE; $params = array("format" => "json", "addressdetails" => 1, "accept-language" => Settings_Model::get('site_language'), "q" => $address, "zoom" => 200); $url = "http://nominatim.openstreetmap.org/search/?" . http_build_query($params); $url_request = new HttpClient($url); if ($result = $url_request->execute()) { $payload = json_decode($result); } else { Kohana::log('error', "Geocode - Nominatin\n" . $url_request->get_error_msg()); } // TODO: Nomaninatins documentation on error returning is poor - this could be improved to have meaningful error messages if (!$payload || count($payload) == 0) { return FALSE; } $result = array_shift($payload); $country_name = isset($result->address->country) ? $result->address->country : $result->display_name; $country = self::getCountryId($country_name); // if we can't find the country by name, try finding it by code if ($country == 0 && isset($result->address->country_code)) { $country = self::getCountryIdByCode($result->address->country_code); } $geocodes = array('country' => $country_name, 'country_id' => $country, 'location_name' => $result->display_name, 'latitude' => $result->lat, 'longitude' => $result->lon); return $geocodes; }
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')); }
/** * 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'); }
/** * Render all the active blocks * * @return string block html */ public static function render() { // Get Active Blocks $active_blocks = Settings_Model::get_setting('blocks'); $active_blocks = array_filter(explode("|", $active_blocks)); foreach ($active_blocks as $block) { $block = new $block(); $block->block(); } }
/** * 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); } } }
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; }
/** * 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 : ""; }
public static function populate_db($db_name, $user, $settings) { $mhi_db = Kohana::config('database.default'); $table_prefix = $mhi_db['table_prefix']; $mhi_db_name = $mhi_db['connection']['database']; // Switch to new DB for a moment mysql_query('USE ' . $db_name); $db_schema = file_get_contents('sql/ushahidi.sql'); // If a table prefix is specified, add it to sql if ($table_prefix) { $find = array('CREATE TABLE IF NOT EXISTS `', 'INSERT INTO `', 'ALTER TABLE `', 'UPDATE `'); $replace = array('CREATE TABLE IF NOT EXISTS `' . $table_prefix . '_', 'INSERT INTO `' . $table_prefix . '_', 'ALTER TABLE `' . $table_prefix . '_', 'UPDATE `' . $table_prefix . '_'); $db_schema = str_replace($find, $replace, $db_schema); } /** * split by ; to get the sql statement for creating individual * tables. */ $tables = explode(';', $db_schema); foreach ($tables as $query) { $result = mysql_query($query); } // Set up admin user on new site $usr = ORM::factory('user', '1'); $usr->username = $user['username']; $usr->name = $user['name']; $usr->password = $user['password']; $usr->email = $user['email']; $usr->save(); // Save site settings (name, tagline, etc) $setgs = new Settings_Model(1); $setgs->site_name = $settings['site_name']; $setgs->site_tagline = $settings['site_tagline']; $setgs->api_google = Kohana::config('settings.api_google'); $setgs->date_modify = date("Y-m-d H:i:s", time()); $setgs->save(); // Switch back to the appropriate DB mysql_query('USE ' . $mhi_db_name); return true; }
public function index() { $this->template->content = new View('admin/stats/hits'); $this->template->content->title = Kohana::lang('ui_admin.statistics'); // Retrieve Current Settings $stat_id = Settings_Model::get_setting('stat_id'); if ($stat_id === NULL or $stat_id == 0) { $sitename = Settings_Model::get_setting('site_name'); $url = url::base(); $this->template->content->stat_id = Stats_Model::create_site($sitename, $url); } // Show the hits page since stats are already set up $this->hits(); }
public function index() { $this->template = ""; $this->auto_render = FALSE; // grab the necessary keys consumer key, secret, token, token secret $consumer_key = Settings_Model::get_setting('twitter_api_key'); $consumer_secret = Settings_Model::get_setting('twitter_api_key_secret'); $oauth_token = Settings_Model::get_setting('twitter_token'); $oauth_token_secret = Settings_Model::get_setting('twitter_token_secret'); $_SESSION['access_token'] = array('oauth_token' => $oauth_token, 'oauth_token_secret' => $oauth_token_secret); $access_token = $_SESSION['access_token']; $connection = new Twitter_Oauth($consumer_key, $consumer_secret, $access_token['oauth_token'], $access_token['oauth_token_secret']); $connection->decode_json = FALSE; $connection->get('account/verify_credentials'); if ($connection->http_code == 200) { echo json_encode(array("status" => "success", "message" => Kohana::lang('ui_main.success'))); } else { echo json_encode(array("status" => "error", "message" => Kohana::lang('ui_main.error') . " - " . Kohana::lang('ui_admin.error_twitter'))); } }
public function index() { // Grabbing tweets requires cURL so we will check for that here. if (!function_exists('curl_exec')) { throw new Kohana_Exception('twitter.cURL_not_installed'); return false; } // Retrieve Last Stored Twitter ID $last_tweet_id = ""; $tweets = ORM::factory('message')->with('reporter')->where('service_id', '3')->orderby('service_messageid', 'desc')->find(); if ($tweets->loaded == true) { $last_tweet_id = "&since_id=" . $tweets->service_messageid; } // Perform Hashtag Search $twitter_hashtags = Settings_Model::get_setting('twitter_hashtags'); $hashtags = explode(',', $twitter_hashtags); foreach ($hashtags as $hashtag) { if (!empty($hashtag)) { $page = 1; $have_results = TRUE; //just starting us off as true, although there may be no results while ($have_results == TRUE and $page <= 2) { //This loop is for pagination of rss results $hashtag = rawurlencode(trim(str_replace('#', '', $hashtag))); $twitter_url = 'http://search.twitter.com/search.json?q=%23' . $hashtag . '&rpp=100&page=' . $page; //.$last_tweet_id; $curl_handle = curl_init(); curl_setopt($curl_handle, CURLOPT_URL, $twitter_url); curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 4); //Since Twitter is down a lot, set timeout to 4 secs curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); //Set curl to store data in variable instead of print $buffer = curl_exec($curl_handle); curl_close($curl_handle); $have_results = $this->add_hash_tweets($buffer); //if FALSE, we will drop out of the loop $page++; } } } }
public function index() { // Grab all the twitter credentials - tokens and keys $consumer_key = Settings_Model::get_setting('twitter_api_key'); $consumer_secret = Settings_Model::get_setting('twitter_api_key_secret'); $oauth_token = Settings_Model::get_setting('twitter_token'); $oauth_token_secret = Settings_Model::get_setting('twitter_token_secret'); $_SESSION['access_token'] = array('oauth_token' => $oauth_token, 'oauth_token_secret' => $oauth_token_secret); /* Get user access tokens out of the session. */ $access_token = $_SESSION['access_token']; /* Create a TwitterOauth object with consumer/user tokens. */ $connection = new Twitter_Oauth($consumer_key, $consumer_secret, $access_token['oauth_token'], $access_token['oauth_token_secret']); $connection->decode_json = FALSE; // Retrieve Last Stored Twitter ID $last_tweet_id = ""; $tweets = ORM::factory('message')->with('reporter')->where('service_id', '3')->orderby('service_messageid', 'desc')->find(); if ($tweets->loaded == true) { $last_tweet_id = "&since_id=" . $tweets->service_messageid; } // Perform Hashtag Search $twitter_hashtags = Settings_Model::get_setting('twitter_hashtags'); $hashtags = explode(',', $twitter_hashtags); foreach ($hashtags as $hashtag) { if (!empty($hashtag)) { $page = 1; $have_results = TRUE; //just starting us off as true, although there may be no results while ($have_results == TRUE and $page <= 2) { //This loop is for pagination of twitter results $hashtag = rawurlencode(trim($hashtag)); $twitter_url = $connection->get('search/tweets', array('count' => 100, 'q' => $hashtag)); $have_results = $this->add_hash_tweets($twitter_url); $page++; } } } }
/** * Geonames Feeds GeoCoding (RSS to GEORSS) * Due to limitations, this returns only 20 items * * @param string location / address * @return string raw georss data */ function geocode_feed($feed_url = NULL) { $base_url = "http://" . GEOCODER_GEONAMES . "/rssToGeoRSS?"; // Only requests service if we have an user $geocode_username = Settings_Model::get_setting('feed_geolocation_user'); if ($feed_url && !empty($geocode_username)) { // First check to make sure geonames webservice is running $geonames_status = @remote::status($base_url); if ($geonames_status == "200") { // Successful $request_url = $base_url . "&feedUrl=" . urlencode($feed_url) . "&username=" . $geocode_username; } else { // Down perhaps?? Use direct feed $request_url = $feed_url; } $request = new HttpClient($request_url); if (!($georss = $request->execute($request_url))) { // If the request failed, something may be wrong with the GEOCODER_GEONAMES service return false; } //$georss = utf8_encode($georss); // Lez verify this we got a good reply from the geocoder before proceeding $data = new SimplePie(); $data->set_raw_data($georss); $data->init(); $data->handle_content_type(); // Feed no good - get outta here! if ($data->error()) { Kohana::log('error', $data->error() . $request_url); return false; } return trim($georss); } else { return false; } }
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)%'); }
/** * 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; }
/** * 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; }
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)); } } }
<?php defined('SYSPATH') or die('No direct script access.'); /** * 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(); // Main Site Settings Kohana::config_set('settings.site_name', $settings['site_name']); Kohana::config_set('settings.site_email', $settings['site_email']); Kohana::config_set('settings.site_banner_id', $settings['site_banner_id']); Kohana::config_set('settings.site_tagline', $settings['site_tagline']); Kohana::config_set('settings.site_style', $settings['site_style']); Kohana::config_set('settings.site_contact_page', $settings['site_contact_page']); Kohana::config_set('settings.site_help_page', $settings['site_help_page']); Kohana::config_set('settings.site_message', $settings['site_message']); Kohana::config_set('settings.site_copyright_statement', $settings['site_copyright_statement']); Kohana::config_set('settings.site_submit_report_message', $settings['site_submit_report_message']); Kohana::config_set('settings.allow_alerts', $settings['allow_alerts']);
/** * Use remote Ushahidi deployments API to get Incident Data * Limit to 20 not to kill remote server */ private function _process_site_reports($site) { $limit = 20; $since_id = 0; $count = 0; $modified_ids = array(); // this is an array of our primary keys $more_reports_to_pull = TRUE; // @todo grab new reports first while ($more_reports_to_pull == TRUE) { $UshApiLib_Site_Info = new UshApiLib_Site_Info(sharing_helper::clean_url($site->site_url) . "/api", $site->site_username, $site->site_password); $params = new UshApiLib_Incidents_Task_Parameter(); $params->setBy(UshApiLib_Incidents_Bys::INCIDENTS_SINCE_ID); $params->setLimit($limit); $params->setId($since_id); $params->setOrderField(UshApiLib_Task_Base::INCIDENT_ID_INDEX); $params->setSort(0); if (isset($_GET['debug']) and $_GET['debug'] == 1) { echo "<strong>Query String:</strong> " . Kohana::debug($params->get_query_string()) . "<br/><br/>"; } $task = new UshApiLib_Incidents_Task($params, $UshApiLib_Site_Info); $response = $task->execute(); if ($response->getError_code()) { if (isset($_GET['debug']) and $_GET['debug'] == 1) { $json = json_decode($task->getJson(), TRUE); // Check for error code 007 - no results if ($json['error']['code'] == '007') { echo "No results.<BR /><BR />"; } else { echo "Error Code: " . $response->getError_code() . " Message: " . $response->getError_message() . "<BR /><BR />"; var_dump($task->getJson()); } } return; } // Grab existing items $existing_items = ORM::factory('sharing_incident')->where('sharing_site_id', $site->id)->find_all(); // Build array of existing items, key'd by remote id $array = array(); foreach ($existing_items as $item) { $array[$item->remote_incident_id] = $item; } $existing_items = $array; $self_url_parsed = parse_url(URL::site()); // Parse Incidents Into Database $count = 0; foreach ($response->getIncidents() as $remote_incident_id => $incident_json) { if (isset($_GET['debug']) and $_GET['debug'] == 1) { echo "Importing report {$remote_incident_id} : " . $incident_json["incident"]->incident_title . "<br/>"; } $orm_incident = $incident_json['incident']; $json_incident = $incident_json['original']['incident']; // Was this report originally from this site? // Using parse_url so we don't get fooled by tralining slashes or other url crazy bits if (!empty($incident_json['original']['incident']['sharingsourceurl'])) { $source_url_parsed = parse_url($incident_json['original']['incident']['sharingsourceurl']); } else { $source_url_parsed = array("host" => NULL); } // Kohana::log('sharing2import', "[" . $site->id . "] " . $source_url_parsed["host"] . " - " . $self_url_parsed["host"]); if ($source_url_parsed["host"] == $self_url_parsed["host"]) { // Update counts and skip $since_id = $remote_incident_id; $count++; continue; } // Check if we've saved this before. if (isset($existing_items[$remote_incident_id])) { $sharing_incident = $existing_items[$remote_incident_id]; } else { $sharing_incident = ORM::factory('sharing_incident'); } // Find and save categories $category_titles = array(null); foreach ($incident_json['categories'] as $category) { $category_titles[] = $category->category_title; } // If matching categories, load them up $categories = ORM::factory('category')->in('category_title', $category_titles)->find_all(); // Otherwise default to "Other" category if ($categories->count() == 0) { $categories = array(ORM::factory('Category', Settings_Model::get_setting('sharing_other_category_id'))); } // Handle location $existing_location = $sharing_incident->location; if ($existing_location->loaded) { $existing_location->delete(); } $incident_json['location']->save(); $sharing_incident->location_id = $incident_json['location']->id; $date = $orm_incident->incident_date; // if the API sent us a unix timestamp, use it instead if (!empty($json_incident["incidentudate"])) { $date = date("Y-m-d H:i:s", $json_incident["incidentudate"]); } $sharing_incident->incident_title = $orm_incident->incident_title; $sharing_incident->incident_description = $orm_incident->incident_description; $sharing_incident->incident_date = $date; $sharing_incident->incident_mode = $orm_incident->incident_mode; $sharing_incident->incident_active = $orm_incident->incident_active; $sharing_incident->incident_verified = $orm_incident->incident_verified; $sharing_incident->sharing_site_id = $site->id; $sharing_incident->remote_incident_id = $remote_incident_id; $sharing_incident->updated = date("Y-m-d H:i:s", time()); $sharing_incident->save(); // Save media ORM::factory('sharing_incident_media')->where('sharing_incident_id', $sharing_incident->id)->delete_all(); foreach ($incident_json['media'] as $media) { $media->save(); $new_sharing_incident_media = ORM::factory('sharing_incident_media'); $new_sharing_incident_media->media_id = $media->id; $new_sharing_incident_media->sharing_incident_id = $sharing_incident->id; $new_sharing_incident_media->save(); } // Save categories ORM::factory('sharing_incident_category')->where('sharing_incident_id', $sharing_incident->id)->delete_all(); foreach ($categories as $category) { $new_sharing_incident_category = ORM::factory('sharing_incident_category'); $new_sharing_incident_category->category_id = $category->id; $new_sharing_incident_category->sharing_incident_id = $sharing_incident->id; $new_sharing_incident_category->save(); } // Save the primary key of the row we touched. We will be deleting ones that weren't touched. $modified_ids[] = $sharing_incident->id; // Save the highest pulled incident id so we can grab the next set from that id on $since_id = $remote_incident_id; // Save count so we know if we need to pull any more reports or not $count++; } if ($count < $limit) { $more_reports_to_pull = FALSE; } } // Delete the reports that are no longer being displayed on the shared site if (count($modified_ids) > 0) { $sharing_incidents = ORM::factory('sharing_incident')->notin('id', $modified_ids)->where('sharing_site_id', $site->id)->find_all(); if ($sharing_incidents->count() > 0) { ORM::factory('sharing_incident_category')->in('sharing_incident_id', $sharing_incidents->primary_key_array())->delete_all(); ORM::factory('sharing_incident_media')->in('sharing_incident_id', $sharing_incidents->primary_key_array())->delete_all(); ORM::factory('sharing_incident_comment')->in('sharing_incident_id', $sharing_incidents->primary_key_array())->delete_all(); // @todo delete associated categories/location/media $sharing_incidents = ORM::factory('sharing_incident')->notin('id', $modified_ids)->where('sharing_site_id', $site->id)->delete_all(); } } }
/** * Handles settings for Global SMS Providers - Clickatell In This Case */ function smsglobal() { $this->template->content = new View('admin/smsglobal'); $this->template->content->title = 'Settings'; // setup and initialize form field names $form = array('clickatell_api' => '', 'clickatell_username' => '', 'clickatell_password' => ''); // 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('clickatell_api', 'required', 'length[4,20]'); $post->add_rules('clickatell_username', 'required', 'length[3,50]'); $post->add_rules('clickatell_password', 'required', 'length[5,50]'); // Test to see if things passed the rule checks if ($post->validate()) { // Yes! everything is valid $settings = new Settings_Model(1); $settings->clickatell_api = $post->clickatell_api; $settings->clickatell_username = $post->clickatell_username; $settings->clickatell_password = $post->clickatell_password; $settings->date_modify = date("Y-m-d H:i:s", time()); $settings->save(); // 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('clickatell_api' => $settings->clickatell_api, 'clickatell_username' => $settings->clickatell_username, 'clickatell_password' => $settings->clickatell_password); } $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->template->js = new View('admin/smsglobal_js'); }
/** * Email Settings */ function email() { $this->template->content = new View('admin/email'); $this->template->content->title = Kohana::lang('ui_admin.settings'); // setup and initialize form field names $form = array('email_username' => '', 'email_password' => '', 'email_port' => '', 'email_host' => '', 'email_servertype' => '', 'email_ssl' => ''); // 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('email_username', 'required', 'length[3,50]'); $post->add_rules('email_password', 'length[3,100]'); $post->add_rules('email_port', 'numeric[1,100]', 'length[1,20]'); $post->add_rules('email_host', 'required', 'length[3,100]'); $post->add_rules('email_servertype', 'required', 'length[3,100]'); // Test to see if things passed the rule checks if ($post->validate()) { // Yes! everything is valid $settings = new Settings_Model(1); $settings->email_username = $post->email_username; $settings->email_password = $post->email_password; $settings->email_port = $post->email_port; $settings->email_host = $post->email_host; $settings->email_servertype = $post->email_servertype; $settings->email_ssl = $post->email_ssl; $settings->save(); //add details to application/config/email.php //$this->_add_email_settings($settings); // 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('email_username' => $settings->email_username, 'email_password' => $settings->email_password, 'email_port' => $settings->email_port, 'email_host' => $settings->email_host, 'email_servertype' => $settings->email_servertype, 'email_ssl' => $settings->email_ssl); } $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->email_ssl_array = array('1' => Kohana::lang('ui_admin.yes'), '0' => Kohana::lang('ui_admin.no')); // Javascript Header $this->template->js = new View('admin/email_js'); }
public function index($feedtype = 'rss2') { $this->template->this_page = 'feed_add'; $this->template->content = new View('admin/feeds'); // setup and initialize form field names /* $cat1fields1 = array('1feed_url1' => '', '1weight1' => 1, '1feed_category1' => 1); */ $form = array(); $num_of_fields_persection = 6; /** ######### Apala required changes ########## settings should come for api the line below */ $settings = ORM::factory('settings', 1); $form["EMAIL"] = $settings->site_email; $form["SMS"] = $settings->sms_no1; $hashtags = explode(',', $settings->twitter_hashtags); $cat_counter = 0; $cat_max = count($hashtags); for ($i = 1; $i <= $num_of_fields_persection; $i++) { if ($cat_counter < $cat_max) { $form["hashtag" . $i] = $hashtags[$cat_counter]; $cat_counter++; } else { $form["hashtag" . $i] = ""; } } /** ######### Apala required changes ########## These categories and feeds tables should get info from API line 74 and 78. */ $categories = ORM::factory('category')->where('category_visible = 1')->orderby('id')->find_all(); $coreFolder = DOCROOT . "/../Core/"; $coreSetupFile = $coreFolder . "Setup.php"; include_once $coreSetupFile; $workflow = new \Swiftriver\Core\Workflows\ChannelProcessingJobs\ListAllChannelProcessingJobs(); $json = $workflow->RunWorkflow("swiftriver_apala"); $return = json_decode($json); $channels = $return->channels; /* APALA - Dropped in favor of the file call $service = new ServiceWrapper($this->API_URL."ListAllChannelProcessingJobs.php"); $json = $service->MakePOSTRequest(array("key" => "test"), 5); $return = json_decode($json); $channels = $return->channels; */ foreach ($categories as $cat) { /** ######### Apala required changes ########## DB Call below. ::factory('feed')*/ $prev_feeds = $channels; //ORM::factory('feed')->where('category_id',$cat->id)->find_all(); $cat_counter = 0; $cat_max = count($prev_feeds); for ($i = 1; $i <= $num_of_fields_persection; $i++) { //this section gets the information from the database and sign it to the right fields. if ($cat_counter < $cat_max && $cat->id == 5) { //|| $cat->id == 4 || $cat->id == 3 ) //only the feed catagories can be saved at a moment. $pre_feed = $prev_feeds[$cat_counter]; $form[$cat->category_title . "ID" . $i] = $pre_feed->id; //$pre_feed->id; $form[$cat->category_title . "feed_url" . $i] = $pre_feed->parameters->feedUrl; $form[$cat->category_title . "updatePeriod" . $i] = $pre_feed->updatePeriod; $form[$cat->category_title . "weight" . $i] = 0; //$pre_feed->weight ; $form[$cat->category_title . "feed_category" . $i] = 5; //$pre_feed->category_id; $cat_counter++; } else { $form[$cat->category_title . "ID" . $i] = 0; $form[$cat->category_title . "feed_url" . $i] = ''; $form[$cat->category_title . "weight" . $i] = 0; $form[$cat->category_title . "updatePeriod" . $i] = 1; $form[$cat->category_title . "feed_category" . $i] = $cat->id; } } } /* echo "<p>"; print_r($form); echo "</p>"; exit(0); */ //copy the form as errors, so the errors will be stored with keys corresponding to the form field names $errors = $form; $form_error = 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 = Validation::factory(array_merge($_POST, $_FILES)); // Add some filters $post->pre_filter('trim', TRUE); if ($post->validate()) { foreach ($categories as $cat) { for ($i = 1; $i <= $num_of_fields_persection; $i++) { if ($cat->id == 5) { if (isset($_POST[$cat->category_title . "feed_url" . $i]) && !empty($_POST[$cat->category_title . "feed_url" . $i])) { $feed_url = $_POST[$cat->category_title . "feed_url" . $i]; $feed_weight = $_POST[$cat->category_title . "weight_hf" . $i]; $this->_save_feed($feed_url, $cat->id, $_POST[$cat->category_title . "updatePeriod" . $i], isset($_POST[$cat->category_title . "weight" . $i]) ? 100 : ($feed_weight == 100 ? 0 : $feed_weight)); } else { if (isset($_POST[$cat->category_title . "ID" . $i]) && $_POST[$cat->category_title . "ID" . $i] != 0) { // delete what the user has deleted. $db = new Database(); $db->query("Delete from feed where id=" . $_POST[$cat->category_title . "ID" . $i]); } } } } } // exit(0); $hashtags = isset($_POST["hashtag1"]) && !empty($_POST["hashtag1"]) ? $_POST["hashtag1"] : ''; for ($i = 2; $i < $num_of_fields_persection; $i++) { if (isset($_POST["hashtag" . $i]) && !empty($_POST["hashtag" . $i])) { $hashtags .= "," . $_POST["hashtag" . $i]; } } /** ######### Apala required changes ########## settings should come for api the lines below */ //save the hashtags in the settings table. /** ######### Apala required changes ########## DB Call below new Settings_Model */ $settings = new Settings_Model(1); $settings->twitter_hashtags = $hashtags; $settings->site_email = $_POST["EMAIL"]; $settings->sms_no1 = $_POST["SMS"]; $settings->save(); $this->template->content->form_saved = true; $this->template->content->form_action = "Added / Updated"; // exit(0); url::redirect("/admin/feeds"); } else { // populate the error fields, if any $errors = arr::overwrite($errors, $post->errors('report')); $form_error = TRUE; } } $this->template->content->errors = $errors; $this->template->content->form_error = $form_error; $this->template->content->form_saved = false; $this->template->content->form = $form; // Count categories to determine column length }
/** * MHI Settings. * @param int $page */ function settings() { $this->template->content = new View('admin/mhi_settings'); // setup and initialize form field names $this->template->content->form = array('google_analytics' => ''); // Copy the form as errors, so the errors will be stored with keys // corresponding to the form field names $this->template->content->errors = $this->template->content->form; $this->template->content->form_error = FALSE; $this->template->content->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); // Validation Rules $post->add_rules('google_analytics', 'length[0,20]'); // Test to see if things passed the rule checks if ($post->validate()) { // Yes! everything is valid $settings = new Settings_Model(1); $settings->google_analytics = $post->google_analytics; $settings->date_modify = date("Y-m-d H:i:s", time()); $settings->save(); $this->template->content->form_saved = TRUE; $this->template->content->form = arr::overwrite($this->template->content->form, $post->as_array()); } else { // repopulate the form fields $this->template->content->form = arr::overwrite($this->template->content->form, $post->as_array()); // populate the error fields, if any $this->template->content->errors = arr::overwrite($this->template->content->errors, $post->errors('settings')); $this->template->content->form_error = TRUE; } } else { // Retrieve Current Settings $settings = ORM::factory('settings', 1); $this->template->content->form = array('google_analytics' => $settings->google_analytics); } }
/** * Manage Public Listing for External Applications */ public function publiclisting() { $this->template->content = new View('admin/manage/publiclisting'); $this->template->content->encoded_stat_id = base64_encode(Settings_Model::get_setting('stat_id')); $this->template->content->encoded_stat_key = base64_encode(Settings_Model::get_setting('stat_key')); }
public function index($feedtype = 'rss2') { $this->template->this_page = 'feed_add'; $this->template->content = new View('admin/feeds'); // setup and initialize form field names /* $cat1fields1 = array('1feed_url1' => '', '1weight1' => 1, '1feed_category1' => 1); */ $form = array(); $num_of_fields_persection = 6; $settings = ORM::factory('settings', 1); $form["EMAIL"] = $settings->site_email; $form["SMS"] = $settings->sms_no1; $hashtags = explode(',', $settings->twitter_hashtags); $cat_counter = 0; $cat_max = count($hashtags); for ($i = 1; $i <= $num_of_fields_persection; $i++) { if ($cat_counter < $cat_max) { $form["hashtag" . $i] = $hashtags[$cat_counter]; $cat_counter++; } else { $form["hashtag" . $i] = ""; } } $categories = ORM::factory('category')->where('category_visible = 1')->orderby('id')->find_all(); foreach ($categories as $cat) { $prev_feeds = ORM::factory('feed')->where('category_id', $cat->id)->find_all(); $cat_counter = 0; $cat_max = count($prev_feeds); for ($i = 1; $i <= $num_of_fields_persection; $i++) { //this section gets the information from the database and sign it to the right fields. if ($cat_counter < $cat_max && $prev_feeds[$cat_counter]->category_id == $cat->id) { $pre_feed = $prev_feeds[$cat_counter]; $form[$cat->category_title . "ID" . $i] = $pre_feed->id; $form[$cat->category_title . "feed_url" . $i] = $pre_feed->feed_url; $form[$cat->category_title . "weight" . $i] = $pre_feed->weight; $form[$cat->category_title . "feed_category" . $i] = $pre_feed->category_id; $cat_counter++; } else { $form[$cat->category_title . "ID" . $i] = 0; $form[$cat->category_title . "feed_url" . $i] = ''; $form[$cat->category_title . "weight" . $i] = 0; $form[$cat->category_title . "feed_category" . $i] = $cat->id; } } } //copy the form as errors, so the errors will be stored with keys corresponding to the form field names $errors = $form; $form_error = 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 = Validation::factory(array_merge($_POST, $_FILES)); // Add some filters $post->pre_filter('trim', TRUE); if ($post->validate()) { foreach ($categories as $cat) { for ($i = 1; $i <= $num_of_fields_persection; $i++) { if (isset($_POST[$cat->category_title . "feed_url" . $i]) && !empty($_POST[$cat->category_title . "feed_url" . $i])) { $feed_url = $_POST[$cat->category_title . "feed_url" . $i]; $feed_weight = $_POST[$cat->category_title . "weight_hf" . $i]; $this->_save_feed($_POST[$cat->category_title . "ID" . $i], $feed_url, $cat->id, $feed_url, isset($_POST[$cat->category_title . "weight" . $i]) ? 100 : ($feed_weight == 100 ? 0 : $feed_weight)); } else { if (isset($_POST[$cat->category_title . "ID" . $i]) && $_POST[$cat->category_title . "ID" . $i] != 0) { // delete what the user has deleted. $db = new Database(); $db->query("Delete from feed where id=" . $_POST[$cat->category_title . "ID" . $i]); } } } } // exit(0); $hashtags = isset($_POST["hashtag1"]) && !empty($_POST["hashtag1"]) ? $_POST["hashtag1"] : ''; for ($i = 2; $i < $num_of_fields_persection; $i++) { if (isset($_POST["hashtag" . $i]) && !empty($_POST["hashtag" . $i])) { $hashtags .= "," . $_POST["hashtag" . $i]; } } //save the hashtags in the settings table. $settings = new Settings_Model(1); $settings->twitter_hashtags = $hashtags; $settings->site_email = $_POST["EMAIL"]; $settings->sms_no1 = $_POST["SMS"]; $settings->save(); $this->template->content->form_saved = true; $this->template->content->form_action = "Added / Updated"; // exit(0); url::redirect("/admin/feeds"); } else { // populate the error fields, if any $errors = arr::overwrite($errors, $post->errors('report')); $form_error = TRUE; } } $this->template->content->errors = $errors; $this->template->content->form_error = $form_error; $this->template->content->form_saved = false; $this->template->content->form = $form; // Count categories to determine column length }
/** * Send A New Message Using Default SMS Provider */ public function send() { $this->template = ""; $this->auto_render = FALSE; // Setup and initialize form field names $form = array('to_id' => '', 'message' => ''); // Copy the form as errors, so the errors will be stored with keys // corresponding to the form field names $errors = $form; $form_error = 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('to_id', 'required', 'numeric'); $post->add_rules('message', 'required', 'length[1,160]'); // Test to see if things passed the rule checks if ($post->validate()) { // Yes! everything is valid $reply_to = ORM::factory('message', $post->to_id); if ($reply_to->loaded == true) { // Yes! Replyto Exists // This is the message we're replying to $sms_to = $reply_to->message_from; //checks if the number is encrypted if (preg_match("/([a-zA-Z])(\\D)/", $sms_to)) { $this->decrypter = new Encrypt(); $sms_to = $this->decrypter->decode($sms_to); } else { $sms_to = $sms_to; } // Load Users Settings $settings = Settings_Model::get_array(); if (!empty($settings)) { // Get SMS Numbers if (!empty($settings['sms_no1'])) { $sms_from = $settings['sms_no1']; } elseif (!empty($settings['sms_no2'])) { $sms_from = $settings['sms_no2']; } elseif (!empty($settings['sms_no3'])) { $sms_from = $settings['sms_no3']; } else { // User needs to set up an SMS number $sms_from = "000"; } // Send Message $response = sms::send($sms_to, $sms_from, $post->message); // Message Went Through?? if ($response === TRUE) { $message = ORM::factory('message'); $message->parent_id = $post->to_id; // The parent message $message->message_from = $sms_from; $message->message_to = $sms_to; $message->message = $post->message; $message->message_type = 2; // This is an outgoing message $message->reporter_id = $reply_to->reporter_id; $message->message_date = date("Y-m-d H:i:s", time()); $message->save(); echo json_encode(array("status" => "sent", "message" => Kohana::lang('ui_admin.message_sent'))); } else { // Message Failed echo json_encode(array("status" => "error", "message" => Kohana::lang('ui_admin.error_msg') . " - " . $response)); } } else { echo json_encode(array("status" => "error", "message" => Kohana::lang('ui_admin.error_msg') . Kohana::lang('ui_admin.check_sms_settings'))); } } else { // Send_To Mobile Number Doesn't Exist echo json_encode(array("status" => "error", "message" => Kohana::lang('ui_admin.error_msg') . Kohana::lang('ui_admin.check_number'))); } } else { // Populate the error fields, if any $errors = arr::overwrite($errors, $post->errors('messages')); echo json_encode(array("status" => "error", "message" => Kohana::lang('ui_admin.error_msg') . Kohana::lang('ui_admin.check_message_valid'))); } } }
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; }