Example #1
0
/**
 * Upgrades a Version 25 version of the Yioop! database to a Version 26 version
 * This version upgrade includes updation fo the Help pages in the database to
 * work with the changes to the way Hyperlinks are specified in wiki markup.
 * The changes were implemented to point all articles with page names
 * containing %20 to be able to work with '_' and vice versa.
 * @param object $db data source to use to upgrade
 */
function upgradeDatabaseVersion26(&$db)
{
    /** For reading HELP_GROUP_ID**/
    require_once BASE_DIR . "/configs/config.php";
    /** For GroupModel::setPageName method */
    require_once BASE_DIR . "/models/group_model.php";
    $db->execute("DELETE FROM VERSION WHERE ID < 25");
    $db->execute("UPDATE VERSION SET ID=26 WHERE ID=25");
    //Delete all existing pages in Help group
    $params = array(HELP_GROUP_ID);
    $sql = "DELETE FROM GROUP_PAGE WHERE GROUP_ID=?";
    $db->execute($sql, $params);
    $sql = "DELETE FROM GROUP_PAGE_HISTORY WHERE GROUP_ID=?";
    $db->execute($sql, $params);
    //Insert the Help Group pages with corrected titles
    $creation_time = microTimestamp();
    $sql = "INSERT INTO GROUPS VALUES(" . HELP_GROUP_ID . ",'Help','" . $creation_time . "','" . ROOT_ID . "',\n        '" . PUBLIC_BROWSE_REQUEST_JOIN . "', '" . GROUP_READ_WIKI . "',\n        " . UP_DOWN_VOTING_GROUP . ", " . FOREVER . ")";
    $db->execute($sql);
    $now = time();
    $db->execute("INSERT INTO USER_GROUP VALUES (" . ROOT_ID . ", " . HELP_GROUP_ID . ", " . ACTIVE_STATUS . ", {$now})");
    $db->execute("INSERT INTO USER_GROUP VALUES (" . PUBLIC_USER_ID . ", " . HELP_GROUP_ID . ", " . ACTIVE_STATUS . ", {$now})");
    //Insert into Groups
    $help_pages = getWikiHelpPages();
    foreach ($help_pages as $page_name => $page_content) {
        $page_content = str_replace("&amp;", "&", $page_content);
        $page_content = @htmlentities($page_content, ENT_QUOTES, "UTF-8");
        $group_model = new GroupModel(DB_NAME, false);
        $group_model->db = $db;
        $group_model->setPageName(ROOT_ID, HELP_GROUP_ID, $page_name, $page_content, "en-US", "Creating Default Pages", "{$page_name} " . "Help Page Created!", "Discuss the page in this thread!");
    }
}
Example #2
0
 /**
  * Add a groupname to the database using provided string
  *
  * @param string $group_name  the groupname to be added
  * @param int $user_id user identifier of who owns the group
  * @param int $register flag that says what kinds of registration are
  *      allowed for this group NO_JOIN, REQUEST_JOIN, PUBLIC_JOIN
  * @param int $member flag that says how members other than the owner can
  *      access this group GROUP_READ, GROUP_READ_COMMENT (can comment
  *      on threads but not start. i.e., a blog), GROUP_READ_WRITE,
  *      (can read, comment, start threads), GROUP_READ_WIKI, (can read,
  *      comment, start threads, and edit the wiki)
  * @param int $voting flag that says how members can vote on each others
  *      posts: NON_VOTING_GROUP, UP_VOTING_GROUP, UP_DOWN_VOTING_GROUP
  * @param int $post_lifetime specifies the time in seconds that posts should
  *      live before they expire and are deleted
  */
 function addGroup($group_name, $user_id, $register = REQUEST_JOIN, $member = GROUP_READ, $voting = NON_VOTING_GROUP, $post_lifetime = FOREVER)
 {
     $db = $this->db;
     $timestamp = microTimestamp();
     $sql = "INSERT INTO GROUPS (GROUP_NAME, CREATED_TIME, OWNER_ID,\n            REGISTER_TYPE, MEMBER_ACCESS, VOTE_ACCESS, POST_LIFETIME)\n            VALUES (?, ?, ?, ?, ?, ?, ?);";
     $db->execute($sql, array($group_name, $timestamp, $user_id, $register, $member, $voting, $post_lifetime));
     $sql = "SELECT G.GROUP_ID AS GROUP_ID FROM " . " GROUPS G WHERE G.GROUP_NAME = ?";
     $result = $db->execute($sql, array($group_name));
     if (!($row = $db->fetchArray($result))) {
         $last_id = -1;
     }
     $last_id = $row['GROUP_ID'];
     $now = time();
     $sql = "INSERT INTO USER_GROUP (USER_ID, GROUP_ID, STATUS,\n            JOIN_DATE) VALUES\n            ({$user_id}, {$last_id}, " . ACTIVE_STATUS . ", {$now})";
     $db->execute($sql);
     return $last_id;
 }
Example #3
0
 /**
  * Add a user with a given username and password to the list of users
  * that can login to the admin panel
  *
  * @param string $username  the username of the user to be added
  * @param string $password  the password in plaintext
  *      of the user to be added, and ZKP auth not being used (else
  *      this can be the empty string)
  * @param string $firstname the firstname of the user to be added
  * @param string $lastname the lastname of the user to be added
  * @param string $email the email of the user to be added
  * @param int $status one of ACTIVE_STATUS, INACTIVE_STATUS, or
  *      BANNED_STATUS
  * @param string $zkp_password  the password parameters needed to
  *      verify a Fiat-Shamir password
  * @return mixed false if operation not successful, user_id otherwise
  */
 function addUser($username, $password, $firstname = '', $lastname = '', $email = '', $status = ACTIVE_STATUS, $zkp_password = '')
 {
     $creation_time = microTimestamp();
     $db = $this->db;
     $sql = "INSERT INTO USERS(FIRST_NAME, LAST_NAME,\n            USER_NAME, EMAIL, PASSWORD, STATUS, HASH,\n            CREATION_TIME, ZKP_PASSWORD) VALUES (\n            ?, ?, ?, ?, ?, ?, ?, ?,?)";
     $result = $db->execute($sql, array($firstname, $lastname, $username, $email, crawlCrypt($password), $status, crawlCrypt($username . AUTH_KEY . $creation_time), $creation_time, $zkp_password));
     if (!($user_id = $this->getUserId($username))) {
         return false;
     }
     $now = time();
     $user_id = $db->escapeString($user_id);
     $sql = "INSERT INTO USER_GROUP (USER_ID, GROUP_ID, STATUS,\n            JOIN_DATE) VALUES(?, ?, ?, ?)";
     $result = $db->execute($sql, array($user_id, PUBLIC_GROUP_ID, ACTIVE_STATUS, $now));
     $sql = "INSERT INTO USER_ROLE  VALUES (?, ?) ";
     $result_id = $db->execute($sql, array($user_id, USER_ROLE));
     return $user_id;
 }