Example #1
0
 /**
  * 获取或创建IP信息
  * <p>返回数组array('id','addr','ban')</p>
  * @since 1
  * @return array
  */
 public function get_ip()
 {
     $ip_addr = $this->get_addr();
     $re = array('id' => 0, 'ban' => '1', 'addr' => '');
     if ($ip_addr != '') {
         $sql = 'SELECT `id`,`ip_addr`,`ip_ban` FROM `' . $this->table_name . '` WHERE `ip_addr` = ?';
         $sth = $this->db->prepare($sql);
         $sth->bindParam(1, $ip_addr, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT);
         if ($sth->execute() == true) {
             $res = $sth->fetch(PDO::FETCH_ASSOC);
             if ($res['id'] > 0) {
                 $re = array('id' => $res['id'], 'addr' => $res['ip_addr'], 'ban' => $res['ip_ban']);
             } else {
                 $sql_insert = 'INSERT INTO `' . $this->table_name . '`(`id`,`ip_addr`,`ip_ban`) VALUES(NULL,?,0)';
                 $sth_insert = $this->db->prepare($sql_insert);
                 $sth_insert->bindParam(1, $ip_addr, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT);
                 if ($sth_insert->execute() == true) {
                     $last_id = $this->db->lastInsertId();
                     $re = array('id' => $last_id, 'addr' => $ip_addr, 'ban' => '0');
                 }
             }
         }
     }
     return $re;
 }
Example #2
0
 /**
  * 添加新的记录
  * @since 7
  * @param string $title 标题
  * @param string $content 内容
  * @param string $type 类型
  * @param int $parent 上一级ID
  * @param int $user 用户ID
  * @param string $pw 密码SHA1或匹配值
  * @param string $name 媒体文件原名称
  * @param string $url 媒体路径或内容访问路径
  * @param string $status 状态 public|private|trash
  * @param string $meta 媒体文件访问头信息
  * @return int 0或记录ID
  */
 public function add($title, $content, $type, $parent, $user, $pw, $name, $url, $status, $meta)
 {
     $return = 0;
     $sql = 'INSERT INTO `' . $this->table_name . '`(`post_title`,`post_content`,`post_date`,`post_ip`,`post_type`,`post_order`,`post_parent`,`post_user`,`post_password`,`post_name`,`post_url`,`post_status`,`post_meta`) VALUES(:title,:content,NOW(),:ip,:type,0,:parent,:user,:pw,:name,:url,:status,:meta)';
     $sth = $this->db->prepare($sql);
     $sth->bindParam(':title', $title, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT);
     $sth->bindParam(':content', $content, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT);
     $sth->bindParam(':ip', $this->ip_id, PDO::PARAM_INT);
     $type = $this->get_type($type);
     $sth->bindParam(':type', $type, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT);
     $sth->bindParam(':parent', $parent, PDO::PARAM_INT | PDO::PARAM_INPUT_OUTPUT);
     $sth->bindParam(':user', $user, PDO::PARAM_INT | PDO::PARAM_INPUT_OUTPUT);
     $sth->bindParam(':pw', $pw, PDO::PARAM_STR);
     $sth->bindParam(':name', $name, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT);
     $sth->bindParam(':url', $url, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT);
     $sth->bindParam(':status', $status, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT);
     $sth->bindParam(':meta', $meta, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT);
     if ($sth->execute() == true) {
         $return = $this->db->lastInsertId();
     }
     return $return;
 }
Example #3
0
 /**
  * 添加新的用户组
  * @since 5
  * @param string $name 用户组名称
  * @param string $power 权限
  * @return boolean|int
  */
 public function add_group($name, $power)
 {
     $return = false;
     if ($this->check_name($name) == true && $this->check_is_power($power) == true) {
         $sql_select = 'SELECT `id` FROM `' . $this->table_name_group . '` WHERE `group_name` = :name';
         $sth_select = $this->db->prepare($sql_select);
         $sth_select->bindParam(':name', $name, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT);
         if ($sth_select->execute() == true) {
             $res_select = $sth_select->fetchColumn();
             if ($res_select) {
                 return $return;
             }
             $sql = 'INSERT INTO `' . $this->table_name_group . '`(`group_name`,`group_power`,`group_status`) VALUES(:name,:power,\'1\')';
             $sth = $this->db->prepare($sql);
             $sth->bindParam(':name', $name, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT);
             $sth->bindParam(':power', $power, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT);
             if ($sth->execute() == true) {
                 $return = $this->db->lastInsertId();
             }
         }
     }
     return $return;
 }