Example #1
0
 /**
  * Insert object into DB based on previously recorded changes.
  *
  * @return boolean true
  */
 function dbinsert()
 {
     global $DB, $localtimenow;
     $DB->begin();
     $this->set_param('timestamp', 'date', date2mysql($localtimenow));
     $result = parent::dbinsert();
     if ($result) {
         // Commit current transaction
         $DB->commit();
     } else {
         // Rollback current transaction
         $DB->rollback();
     }
     return $result;
 }
Example #2
0
    /**
     * Insert object into DB based on previously recorded changes.
     */
    function dbinsert()
    {
        global $DB;
        $DB->begin();
        if (parent::dbinsert()) {
            global $Blog;
            // Update/Insert/Delete custom fields:
            $this->dbsave_custom_fields();
            if (!empty($Blog)) {
                // Enable this item type only for selected Blog:
                $DB->query('INSERT INTO T_items__type_coll
					       ( itc_ityp_ID, itc_coll_ID )
					VALUES ( ' . $this->ID . ', ' . $Blog->ID . ' )');
            }
        }
        $DB->commit();
    }
Example #3
0
 /**
  * Insert object into DB based on previously recorded changes.
  */
 function dbinsert()
 {
     global $DB;
     $DB->begin();
     parent::dbinsert();
     // Create group permissions/settings for the current group
     $GroupSettings =& $this->get_GroupSettings();
     $GroupSettings->dbupdate($this->ID);
     $DB->commit();
 }
Example #4
0
 /**
  * Insert into the DB
  */
 function dbinsert()
 {
     global $DB;
     $DB->begin();
     if (parent::dbinsert()) {
         if (isset($this->CollectionSettings)) {
             // So far all settings have been saved to collection #0 !
             // Update the settings: hackish but the base class should not even store this value actually...
             // dh> what do you mean? What "base class"? Is there a problem with CollectionSettings?
             $this->CollectionSettings->cache[$this->ID] = $this->CollectionSettings->cache[0];
             unset($this->CollectionSettings->cache[0]);
             $this->CollectionSettings->dbupdate();
         }
     }
     $DB->commit();
 }
Example #5
0
    /**
     * 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;
    }
Example #6
0
    /**
     * Insert message in existing thread
     *
     * @return true if success, instead false
     */
    function dbinsert_message()
    {
        global $DB, $localtimenow;
        if ($this->ID != 0) {
            die('Existing object cannot be inserted!');
        }
        $DB->begin();
        $this->get_Thread();
        $this->Thread->set_param('datemodified', 'string', date('Y-m-d H:i:s', $localtimenow));
        if ($this->Thread->dbupdate()) {
            $this->set_param('thread_ID', 'integer', $this->Thread->ID);
            if (parent::dbinsert()) {
                $sql = 'UPDATE T_messaging__threadstatus
						SET tsta_first_unread_msg_ID = ' . $this->ID . '
						WHERE tsta_thread_ID = ' . $this->Thread->ID . '
							AND tsta_user_ID <> ' . $this->author_user_ID . '
							AND tsta_first_unread_msg_ID IS NULL';
                $DB->query($sql, 'Insert thread statuses');
                // check if contact pairs between sender and recipients exists
                $recipient_list = $this->Thread->load_recipients();
                // remove author user from recipient list
                $recipient_list = array_diff($recipient_list, array($this->author_user_ID));
                // insert missing contact pairs if required
                if ($this->dbinsert_contacts($recipient_list)) {
                    if ($this->dbupdate_last_contact_datetime()) {
                        $DB->commit();
                        $this->send_email_notifications(false);
                        return true;
                    }
                }
            }
        }
        $DB->rollback();
        return false;
    }
Example #7
0
    /**
     * Insert object into DB based on previously recorded changes.
     *
     * @return boolean true on success
     */
    function dbinsert()
    {
        global $DB;
        if ($this->ID != 0) {
            debug_die('Existing object cannot be inserted!');
        }
        $DB->begin();
        $order_max = $DB->get_var('SELECT MAX(wi_order)
				 FROM T_widget
				WHERE wi_coll_ID = ' . $this->coll_ID . '
					AND wi_sco_name = ' . $DB->quote($this->sco_name), 0, 0, 'Get current max order');
        $this->set('order', $order_max + 1);
        $res = parent::dbinsert();
        $DB->commit();
        return $res;
    }
Example #8
0
 /**
  * Get karma and set it before adding the Comment to DB.
  *
  * @return boolean true on success, false if it did not get inserted
  */
 function dbinsert()
 {
     /**
      * @var Plugins
      */
     global $Plugins;
     global $Settings;
     // Get karma percentage (interval -100 - 100)
     $spam_karma = $Plugins->trigger_karma_collect('GetSpamKarmaForComment', array('Comment' => &$this));
     $this->set_spam_karma($spam_karma);
     // Change status accordingly:
     if (!is_null($spam_karma)) {
         if ($spam_karma < $Settings->get('antispam_threshold_publish')) {
             // Publish:
             $this->set('status', 'published');
         } elseif ($spam_karma > $Settings->get('antispam_threshold_delete')) {
             // Delete/No insert:
             return false;
         }
     }
     $dbchanges = $this->dbchanges;
     if ($r = parent::dbinsert()) {
         $Plugins->trigger_event('AfterCommentInsert', $params = array('Comment' => &$this, 'dbchanges' => $dbchanges));
     }
     return $r;
 }
Example #9
0
    /**
     * 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;
    }
Example #10
0
 /**
  * Insert object into DB based on previously recorded changes.
  *
  * @return boolean true on success
  */
 function dbinsert()
 {
     global $DB, $localtimenow;
     load_funcs('items/model/_item.funcs.php');
     if ($this->ID != 0) {
         die('Existing object cannot be inserted!');
     }
     // Start transaction because of urltitle validation
     $DB->begin('SERIALIZABLE');
     // validate url title / slug
     $this->set('urlname', urltitle_validate($this->urlname, $this->name, $this->ID, false, $this->dbprefix . 'urlname', $this->dbIDname, $this->dbtablename));
     $this->set_param('last_touched_ts', 'date', date('Y-m-d H:i:s', $localtimenow));
     if (parent::dbinsert()) {
         // The chapter was inserted successful
         $DB->commit();
         return true;
     }
     // Could not insert the chapter object
     $DB->rollback();
     return false;
 }
Example #11
0
 /**
  * Insert object into DB based on previously recorded changes
  *
  * @return boolean true on success, false on failure
  */
 function dbinsert()
 {
     global $Debuglog;
     if ($this->meta == 'unknown') {
         debug_die('cannot insert File if meta data has not been checked before');
     }
     if ($this->ID != 0 || $this->meta != 'notfound') {
         debug_die('Existing file object cannot be inserted!');
     }
     $Debuglog->add('Inserting meta data for new file into db', 'files');
     // Let's make sure the bare minimum gets saved to DB:
     $this->set_param('root_type', 'string', $this->_FileRoot->type);
     $this->set_param('root_ID', 'integer', $this->_FileRoot->in_type_ID);
     $this->set_param('path', 'string', $this->_rdfp_rel_path);
     // Let parent do the insert:
     $r = parent::dbinsert();
     // We can now consider the meta data has been loaded:
     $this->meta = 'loaded';
     return $r;
 }
Example #12
0
    /**
     * Insert into the DB
     */
    function dbinsert()
    {
        global $DB, $Plugins, $Settings;
        $DB->begin();
        if ($this->get('order') == 0) {
            // Set an order as max value of previous order + 1 if it is not defined yet
            $SQL = new SQL();
            $SQL->SELECT('MAX( blog_order )');
            $SQL->FROM('T_blogs');
            $max_order = intval($DB->get_var($SQL->get()));
            $this->set('order', $max_order + 1);
        }
        $set_default_blog_ID = isset($Settings);
        if (get_setting_Blog('default_blog_ID')) {
            // Don't set a default blog if it is already defined and the blog exists in DB
            $set_default_blog_ID = false;
        }
        if ($set_default_blog_ID) {
            // No default blog yet, Use for first base url as "Default collection on baseurl"
            $this->set('access_type', 'baseurl');
        } else {
            // For all other blogs use "Extra path on index.php"
            $this->set('access_type', 'extrapath');
        }
        if (parent::dbinsert()) {
            if ($set_default_blog_ID) {
                // Use this blog as default because it is probably first created
                $Settings->set('default_blog_ID', $this->ID);
                $Settings->dbupdate();
            }
            if (isset($this->CollectionSettings)) {
                // So far all settings have been saved to collection #0 !
                // Update the settings: hackish but the base class should not even store this value actually...
                // dh> what do you mean? What "base class"? Is there a problem with CollectionSettings?
                $this->CollectionSettings->cache[$this->ID] = $this->CollectionSettings->cache[0];
                unset($this->CollectionSettings->cache[0]);
                $this->CollectionSettings->dbupdate();
            }
            $default_post_type_ID = $this->get_setting('default_post_type');
            if (!empty($default_post_type_ID)) {
                // Enable post type that is used by default for this collection:
                global $DB;
                $DB->query('INSERT INTO T_items__type_coll
									 ( itc_ityp_ID, itc_coll_ID )
						VALUES ( ' . $DB->quote($default_post_type_ID) . ', ' . $DB->quote($this->ID) . ' )');
            }
            // Enable default item types for the inserted collection:
            $this->enable_default_item_types();
            $Plugins->trigger_event('AfterCollectionInsert', $params = array('Blog' => &$this));
        }
        $DB->commit();
    }
Example #13
0
 /**
  * Insert object into DB based on previously recorded changes.
  *
  * @return boolean true on success, false on failure to insert
  */
 function dbinsert()
 {
     global $DB;
     $dbchanges = $this->dbchanges;
     $DB->begin();
     if (($r = parent::dbinsert()) !== false) {
         // Update types of the Files
         $this->update_file_types();
         $DB->commit();
     } else {
         $DB->rollback();
     }
     return $r;
 }
Example #14
0
 /**
  * Insert object into DB based on previously recorded changes
  *
  * @return boolean true on success, false on failure
  */
 function dbinsert()
 {
     global $Debuglog;
     if ($this->meta == 'unknown') {
         debug_die('cannot insert File if meta data has not been checked before');
     }
     if ($this->ID != 0 || $this->meta != 'notfound') {
         debug_die('Existing file object cannot be inserted!');
     }
     $Debuglog->add('Inserting meta data for new file into db', 'files');
     // Let's make sure the bare minimum gets saved to DB:
     $this->set_param('root_type', 'string', $this->_FileRoot->type);
     $this->set_param('root_ID', 'number', $this->_FileRoot->in_type_ID);
     $this->set_param('path', 'string', $this->_rdfp_rel_path);
     $this->set_param('path_hash', 'string', md5($this->_FileRoot->type . $this->_FileRoot->in_type_ID . $this->_rdfp_rel_path, true));
     if (!$this->is_dir()) {
         // create hash value only for files but not for folders
         $this->set_param('hash', 'string', md5_file($this->get_full_path(), true));
     }
     // Let parent do the insert:
     $r = parent::dbinsert();
     // We can now consider the meta data has been loaded:
     $this->meta = 'loaded';
     return $r;
 }
Example #15
0
 /**
  * Get karma and set it before adding the Comment to DB.
  *
  * @return boolean true on success, false if it did not get inserted
  */
 function dbinsert()
 {
     /**
      * @var Plugins
      */
     global $Plugins;
     global $Settings;
     // Get karma percentage (interval -100 - 100)
     $spam_karma = $Plugins->trigger_karma_collect('GetSpamKarmaForComment', array('Comment' => &$this));
     $this->set_spam_karma($spam_karma);
     // Change status accordingly:
     if (!is_null($spam_karma)) {
         if ($spam_karma < $Settings->get('antispam_threshold_publish')) {
             // Publish:
             $this->set('status', 'published');
         } elseif ($spam_karma > $Settings->get('antispam_threshold_delete')) {
             // Delete/No insert:
             return false;
         }
     }
     // set comment secret for quick moderation
     // fp> users have requested this for all comments
     $comment_Item =& $this->get_Item();
     $comment_Blog =& $comment_Item->get_Blog();
     if ($comment_Blog->get_setting('comment_quick_moderation') != 'never') {
         // quick moderation is permitted, set comment secret
         $this->set('secret', generate_random_key());
     }
     $dbchanges = $this->dbchanges;
     if ($r = parent::dbinsert()) {
         if ($this->is_published()) {
             // Update last touched date of item if comment is created in published status
             $comment_Item->update_last_touched_date();
         }
         $Plugins->trigger_event('AfterCommentInsert', $params = array('Comment' => &$this, 'dbchanges' => $dbchanges));
     }
     return $r;
 }
Example #16
0
 /**
  * Insert object into DB based on previously recorded changes.
  *
  * @return boolean true
  */
 function dbinsert()
 {
     global $DB;
     $DB->begin();
     if (parent::dbinsert()) {
         // Skin saved, also save containers:
         $this->db_save_containers();
     }
     $DB->commit();
     return true;
 }
Example #17
0
 /**
  * Insert object into DB based on previously recorded changes
  *
  * Triggers the plugin event AfterUserInsert.
  *
  * @return boolean true on success
  */
 function dbinsert()
 {
     global $Plugins;
     if ($result = parent::dbinsert()) {
         // We could insert the user object..
         // Notify plugins:
         // A user could be created also in another DB (to synchronize it with b2evo)
         $Plugins->trigger_event('AfterUserInsert', $params = array('User' => &$this));
     }
     return $result;
 }