/** * Insert object into DB based on previously recorded changes * * Triggers the plugin event AfterUserInsert. * * @param boolean TRUE to automatically create new blog if group has permission * @return boolean true on success */ function dbinsert($create_auto_blog = true) { global $Plugins, $DB; $DB->begin(); if ($result = parent::dbinsert()) { // We could insert the user object.. // Add new fields: if (!empty($this->new_fields)) { $sql = 'INSERT INTO T_users__fields( uf_user_ID, uf_ufdf_ID, uf_varchar ) VALUES (' . $this->ID . ', ' . implode('), (' . $this->ID . ', ', $this->new_fields) . ' )'; $DB->query($sql, 'Insert new fields'); // Reset new fields in object: $this->new_fields = array(); } // Notify plugins: // A user could be created also in another DB (to synchronize it with b2evo) $Plugins->trigger_event('AfterUserInsert', $params = array('User' => &$this)); $Group =& $this->get_Group(); if ($create_auto_blog && $Group->check_perm('perm_getblog', 'allowed')) { // automatically create new blog for this user // TODO: sam2kb> Create a blog only when this user is validated! $new_Blog = new Blog(NULL); $shortname = $this->get('login'); $new_Blog->set('owner_user_ID', $this->ID); $new_Blog->set('shortname', $shortname); $new_Blog->set('name', $shortname . '\'s blog'); $new_Blog->set('locale', $this->get('locale')); $new_Blog->set('urlname', urltitle_validate($shortname, $shortname, $new_Blog->ID, false, 'blog_urlname', 'blog_ID', 'T_blogs', $this->get('locale'))); // Defines blog settings by its kind. $Plugins->trigger_event('InitCollectionKinds', array('Blog' => &$new_Blog, 'kind' => 'std')); $new_Blog->create(); } // Save IP Range and user counter antispam_increase_counter('user'); } $DB->commit(); return $result; }
/** * Insert object into DB based on previously recorded changes * * Triggers the plugin event AfterUserInsert. * * @param boolean TRUE to automatically create new blog if group has permission * @return boolean true on success */ function dbinsert($create_auto_blog = true) { global $Plugins, $DB; $DB->begin(); if ($result = parent::dbinsert()) { // We could insert the user object.. // Add new fields: if (!empty($this->new_fields)) { $sql = 'INSERT INTO T_users__fields( uf_user_ID, uf_ufdf_ID, uf_varchar ) VALUES (' . $this->ID . ', ' . implode('), (' . $this->ID . ', ', $this->new_fields) . ' )'; $DB->query($sql, 'Insert new fields'); // Reset new fields in object: $this->new_fields = array(); } // Notify plugins: // A user could be created also in another DB (to synchronize it with b2evo) $Plugins->trigger_event('AfterUserInsert', $params = array('User' => &$this)); $Group =& $this->get_Group(); if ($create_auto_blog && $Group->check_perm('perm_getblog', 'allowed')) { // automatically create new blog for this user // TODO: sam2kb> Create a blog only when this user is validated! $new_Blog = new Blog(NULL); $shortname = $this->get('login'); $new_Blog->set('owner_user_ID', $this->ID); $new_Blog->set('shortname', $shortname); $new_Blog->set('name', $shortname . '\'s blog'); $new_Blog->set('locale', $this->get('locale')); $new_Blog->set('urlname', urltitle_validate($shortname, $shortname, $new_Blog->ID, false, 'blog_urlname', 'blog_ID', 'T_blogs', $this->get('locale'))); // Defines blog settings by its kind. $Plugins->trigger_event('InitCollectionKinds', array('Blog' => &$new_Blog, 'kind' => 'std')); $new_Blog->create(); } /* Save IP Range -- start */ $ip = int2ip(ip2int($_SERVER['REMOTE_ADDR'])); // Convert IPv6 to IPv4 if (preg_match('#^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$#i', $ip)) { // Check IP for correct format $ip_24bit_start = ip2int(preg_replace('#\\.\\d{1,3}$#i', '.0', $ip)); $ip_24bit_end = ip2int(preg_replace('#\\.\\d{1,3}$#i', '.255', $ip)); if ($iprange = get_ip_range($ip_24bit_start, $ip_24bit_end)) { // Update ip range $DB->query('UPDATE T_antispam__iprange SET aipr_user_count = ' . $DB->quote($iprange->aipr_user_count + 1) . ' WHERE aipr_ID = ' . $DB->quote($iprange->aipr_ID)); } else { // Insert new ip range $DB->query('INSERT INTO T_antispam__iprange ( aipr_IPv4start, aipr_IPv4end, aipr_user_count ) VALUES ( ' . $DB->quote($ip_24bit_start) . ', ' . $DB->quote($ip_24bit_end) . ', ' . $DB->quote('1') . ' ) '); } } /* Save IP Range -- end */ } $DB->commit(); return $result; }
$current_User->check_perm('blogs', 'create', true); $edited_Blog = new Blog(NULL); $edited_Blog->set('owner_user_ID', $current_User->ID); param('kind', 'string', true); $edited_Blog->init_by_kind($kind); param('skin_ID', 'integer', true); $AdminUI->append_path_level('new', array('text' => sprintf(T_('New %s'), get_collection_kinds($kind)))); break; case 'create': // Insert into DB: // Check that this action request is not a CSRF hacked request: $Session->assert_received_crumb('collection'); // Check permissions: $current_User->check_perm('blogs', 'create', true); $edited_Blog = new Blog(NULL); $edited_Blog->set('owner_user_ID', $current_User->ID); param('kind', 'string', true); $edited_Blog->init_by_kind($kind); if (!$current_User->check_perm('blog_admin', 'edit', false, $edited_Blog->ID)) { // validate the urlname, which was already set by init_by_kind() function // It needs to validated, because the user can not set the blog urlname, and every new blog would have the same urlname without validation. // When user has edit permission to blog admin part, the urlname will be validated in load_from_request() function. $edited_Blog->set('urlname', urltitle_validate($edited_Blog->get('urlname'), '', 0, false, 'blog_urlname', 'blog_ID', 'T_blogs')); } param('skin_ID', 'integer', true); $edited_Blog->set_setting('normal_skin_ID', $skin_ID); if ($edited_Blog->load_from_Request(array())) { // create the new blog $edited_Blog->create($kind); // We want to highlight the edited object on next list display: // $Session->set( 'fadeout_array', array( 'blog_ID' => array($edited_Blog->ID) ) );
public function testSet() { $blog = new Blog(); $blog->set(array('name' => 'foo', 'url' => '*****@*****.**')); $this->assertEquals('foo', $blog->name); }