function map_name_to_new_user($name, $newuser_name)
 {
     global $wpdb;
     if (strlen($newuser_name) > 0) {
         $newuser_id = fwp_insert_new_user($newuser_name);
         if (is_numeric($newuser_id)) {
             if (is_null($name)) {
                 // Unfamiliar author
                 $this->update_setting('unfamiliar author', $newuser_id);
             } else {
                 $map = $this->setting('map authors');
                 $map['name'][$name] = $newuser_id;
                 $this->update_setting('map authors', $map);
             }
         } else {
             // TODO: Add some error detection and reporting
         }
     } else {
         // TODO: Add some error reporting
     }
 }
	function map_name_to_new_user ($name, $newuser_name) {
		global $wpdb;

		if (strlen($newuser_name) > 0) :
			$newuser_id = fwp_insert_new_user($newuser_name);
			if (is_numeric($newuser_id)) :
				if (is_null($name)) : // Unfamiliar author
					$this->update_setting('unfamiliar author', $newuser_id);
				else :
					$map = $this->setting('map authors');
					$map['name'][$name] = $newuser_id;
					$this->update_setting('map authors', $map);
				endif;
			else :
				// TODO: Add some error detection and reporting
			endif;
		else :
			// TODO: Add some error reporting
		endif;
	} /* SyndicatedLink::map_name_to_new_user () */
Esempio n. 3
0
 function save_settings($post)
 {
     if ($this->for_feed_settings()) {
         $alter = array();
         // Unfamiliar author rule
         if (isset($post["unfamiliar_author"])) {
             if ('newuser' == $post['unfamiliar_author']) {
                 $new_name = trim($post["unfamiliar_author_newuser"]);
                 $this->link->map_name_to_new_user(NULL, $new_name);
             } else {
                 $this->link->update_setting("unfamiliar author", $post['unfamiliar_author'], 'site-default');
             }
         }
         // Handle author mapping rules
         if (isset($post['author_rules_name']) and isset($post['author_rules_action'])) {
             if (isset($post['author_rules_name']['all'])) {
                 if (strlen($post['author_rules_name']['all']) > 0) {
                     $post['author_rules_name'] = array('all' => $post['author_rules_name']['all']);
                     // Erase all the rest.
                 }
             }
             unset($this->link->settings['map authors']);
             foreach ($post['author_rules_name'] as $key => $name) {
                 // Normalize for case and whitespace
                 $name = strtolower(trim($name));
                 $author_action = strtolower(trim($post['author_rules_action'][$key]));
                 if (strlen($name) > 0) {
                     if ('newuser' == $author_action) {
                         $new_name = trim($post['author_rules_newuser'][$key]);
                         $this->link->map_name_to_new_user($name, $new_name);
                     } else {
                         $this->link->settings['map authors']['name'][$name] = $author_action;
                     }
                 }
             }
         }
         if (isset($post['add_author_rule_name']) and isset($post['add_author_rule_action'])) {
             $name = strtolower(trim($post['add_author_rule_name']));
             $author_action = strtolower(trim($post['add_author_rule_action']));
             if (strlen($name) > 0) {
                 if ('newuser' == $author_action) {
                     $new_name = trim($post['add_author_rule_newuser']);
                     $this->link->map_name_to_new_user($name, $new_name);
                 } else {
                     $this->link->settings['map authors']['name'][$name] = $author_action;
                 }
             }
         }
     } else {
         if ('newuser' == $post['unfamiliar_author']) {
             $new_name = trim($post['unfamiliar_author_newuser']);
             $new_id = fwp_insert_new_user($new_name);
             if (is_numeric($new_id)) {
                 update_option('feedwordpress_unfamiliar_author', $new_id);
             } else {
                 // TODO: Add some error detection and reporting
                 // Put WP_Error stuff into $this->mesg ?
             }
         } else {
             update_option('feedwordpress_unfamiliar_author', $post['unfamiliar_author']);
         }
         update_option('feedwordpress_do_not_match_author_by_email', (isset($post['match_author_by_email']) and 'yes' == $post['match_author_by_email']) ? 'no' : 'yes');
         if (isset($post['null_emails'])) {
             update_option('feedwordpress_null_email_set', $post['null_emails']);
         }
     }
     parent::save_settings($post);
     $this->refresh_author_list();
 }