Exemplo n.º 1
0
 /**
  * Set links
  *
  * @param string $link name of the link table
  * @param string $table1 name of the first table
  * @param int $id1 a primary key
  * @param string $table2 name of the second table
  * @param int|array $id2 either a primary key, or an array of primary keys
  * @param bool if true, use the key of $id2 as the data
  */
 function saveLink($link, $table1, $id1, $table2, $id2, $onkey = false)
 {
     // One to many mapping
     // $id1 = One
     // $id2 = Many
     if (!is_array($id2)) {
         $tmp = $id2;
         unset($id2);
         $id2[] = $tmp;
     }
     $tid = suxDB::requestTransaction();
     $this->inTransaction = true;
     foreach ($id2 as $key => $val) {
         $form = array();
         $form["{$table1}_id"] = $id1;
         if ($onkey) {
             $form["{$table2}_id"] = $key;
         } else {
             $form["{$table2}_id"] = $val;
         }
         if ($form["{$table2}_id"]) {
             // Make sure this doesn't already exist
             $query = suxDB::prepareCountQuery($link, $form);
             $st = $this->db->prepare($query);
             $st->execute($form);
             if (!$st->fetchColumn()) {
                 // It's new, insert it
                 $query = suxDB::prepareInsertQuery($link, $form);
                 $st = $this->db->prepare($query);
                 $st->execute($form);
             }
         }
     }
     suxDB::commitTransaction($tid);
     $this->inTransaction = false;
 }
Exemplo n.º 2
0
 /**
  * trust a url
  * @param int $id user id
  * @param string $id url
  * @return bool
  */
 private function trustUrl($id, $url)
 {
     if (!filter_var($id, FILTER_VALIDATE_INT) || $id < 1) {
         return false;
     }
     $url = suxFunct::canonicalizeUrl($url);
     $trusted = array('users_id' => $id, 'auth_url' => $url);
     $query = suxDB::prepareCountQuery($this->db_table_trust, $trusted);
     $st = $this->db->prepare($query);
     $st->execute($trusted);
     if (!$st->fetchColumn()) {
         $query = suxDB::prepareInsertQuery($this->db_table_trust, $trusted);
         $st = $this->db->prepare($query);
         $st->execute($trusted);
     }
 }
Exemplo n.º 3
0
 /**
  * Attach an openid to a user
  *
  * @param string $openid_url url
  * @param int $users_id users_id
  */
 function attachOpenID($openid_url, $users_id = null)
 {
     // This user
     if (!$users_id) {
         if (!empty($_SESSION['users_id'])) {
             $users_id = $_SESSION['users_id'];
         } else {
             return false;
         }
     }
     // Any user
     if (!filter_var($users_id, FILTER_VALIDATE_INT) || $users_id < 1) {
         throw new Exception('Invalid user id');
     }
     // Canonicalize url
     $openid_url = suxFunct::canonicalizeUrl($openid_url);
     // Sql
     $oid = array('users_id' => $users_id, 'openid_url' => $openid_url);
     $query = suxDB::prepareCountQuery($this->db_table_openid, $oid);
     $st = $this->db->prepare($query);
     $st->execute($oid);
     if (!$st->fetchColumn()) {
         // Insert
         $query = suxDB::prepareInsertQuery($this->db_table_openid, $oid);
         $st = $this->db->prepare($query);
         $st->execute($oid);
     }
 }