protected function SaveToDB()
 {
     $db = $this->db;
     $db->delete("id = {$this->id}");
     foreach ($this->data as $name => $value) {
         if ($name == 'id') {
             continue;
         }
         $name = dbquote($name);
         $value = dbquote($value);
         $this->db->insertrow("(id, name, value) values ({$this->id}, {$name}, {$value})");
     }
 }
 public function indexof($name, $value)
 {
     if ($this->dbversion) {
         return $this->db->findprop($this->idprop, "{$name} = " . dbquote($value));
     }
     foreach ($this->items as $id => $item) {
         if ($item[$name] == $value) {
             return $id;
         }
     }
     return false;
 }
Exemple #3
0
 public function hasfriend($url)
 {
     if ($this->dbversion) {
         return $this->select('url = ' . dbquote($url), 'limit 1');
     } else {
         foreach ($this->items as $id => $item) {
             if ($url == $item['url']) {
                 return $id;
             }
         }
         return false;
     }
 }
Exemple #4
0
 public function findcookie($cookie)
 {
     $cookie = dbquote($cookie);
     if (($a = $this->select('cookie = ' . $cookie, 'limit 1')) && count($a) > 0) {
         return (int) $a[0];
     }
     return false;
 }
 public function wpgetComments($blog_id, $login, $password, $struct)
 {
     $this->auth($login, $password, 'moderator');
     $where = '';
     $where .= isset($struct['status']) ? ' status = ' . dbquote($struct['status']) : '';
     $where .= isset($struct['post_id']) ? ' post = ' . (int) $struct['post_id'] : '';
     $offset = isset($struct['offset']) ? (int) $struct['offset'] : 0;
     $count = isset($struct['number']) ? (int) $struct['number'] : 10;
     $limit = " order by posted limit {$offset}, {$count}";
     $comments = tcomments::i();
     $items = $comments->select($where, $limit);
     $result = array();
     $comment = new tcomment();
     foreach ($items as $id) {
         $comment->id = $id;
         $result[] = $this->_getcomment($comment);
     }
     return $result;
 }
 public function setblacklist(array $a)
 {
     $a = array_unique($a);
     array_delete_value($a, '');
     $this->data['blacklist'] = $a;
     $this->save();
     $dblist = array();
     foreach ($a as $s) {
         if ($s == '') {
             continue;
         }
         $dblist[] = dbquote($s);
     }
     if (count($dblist) > 0) {
         $db = $this->db;
         $db->delete("item in (select id from {$db->users} where email in (" . implode(',', $dblist) . '))');
     }
 }
 public function exists($url)
 {
     return $this->db->finditem('url =' . dbquote($url));
 }
 public function delete($url)
 {
     $url = dbquote($url);
     if ($id = $this->db->findid('url = ' . $url)) {
         $this->db->iddelete($id);
     } else {
         return false;
     }
     $this->clearcache();
     $this->deleted($id);
     return true;
 }
 public function uploadthumb($filename, &$content)
 {
     $hash = trim(base64_encode(md5($content, true)), '=');
     $files = tfiles::i();
     if (($id = $files->indexof('hash', $hash)) || ($id = $files->getdb('imghashes')->findid('hash = ' . dbquote($hash)))) {
         return $id;
     }
     if ($image = imagecreatefromstring($content)) {
         if (!strbegin($filename, litepublisher::$paths->files)) {
             $filename = litepublisher::$paths->files . ltrim($filename, '\\/');
         }
         $destfilename = self::replace_ext($filename, '.jpg');
         $destfilename = self::makeunique($destfilename);
         if (self::createthumb($image, $destfilename, $this->previewwidth, $this->previewheight, $this->ratio, $this->clipbounds, $this->quality_snapshot)) {
             $info = getimagesize($destfilename);
             $item = $this->getdefaultvalues(str_replace(DIRECTORY_SEPARATOR, '/', substr($destfilename, strlen(litepublisher::$paths->files))));
             $item['media'] = 'image';
             $item['mime'] = $info['mime'];
             $item['width'] = $info[0];
             $item['height'] = $info[1];
             $id = $files->additem($item);
             if ($hash != $files->getvalue($id, 'hash')) {
                 $files->getdb('imghashes')->insert(array('id' => $id, 'hash' => $hash));
             }
             $this->added($id);
             return $id;
         }
     }
     return false;
 }
 function store()
 {
     global $xoopsDB, $xoopsUser, $xoopsModule;
     $vars =& $this->vars;
     $dirty =& $this->dirty;
     $notify = false;
     function dbquote($x)
     {
         global $xoopsDB;
         return $xoopsDB->quoteString($x);
     }
     if (empty($vars['mid'])) {
         // new entry
         unset($vars['mid']);
         $vars['ctime'] = $vars['mtime'] = time();
         $fields = join(',', array_keys($vars));
         $values = join(',', array_map('dbquote', $vars));
         $res = $xoopsDB->query("INSERT INTO " . MAIN . "({$fields}) VALUES({$values})");
         if ($res) {
             $notify = true;
             $vars['mid'] = $mid = $xoopsDB->getInsertId();
             $work = get_upload_path(0);
             if (is_dir($work)) {
                 rename($work, get_upload_path($mid));
             }
             $this->dirty = array();
             if ($this->kdirty) {
                 $sql = "INSERT INTO " . RELAY . "(keyref, midref) VALUES(%u, {$mid})";
                 foreach ($this->keys as $k) {
                     $xoopsDB->query(sprintf($sql, $k));
                 }
             }
         }
     } else {
         // update entry
         $mid = $vars['mid'];
         // something to change?
         if (empty($dirty) && !$this->kdirty && !$this->adirty) {
             return false;
         }
         $vars['mtime'] = time();
         $dirty[] = 'mtime';
         $sets = array();
         foreach ($dirty as $k) {
             $sets[] = $k . '=' . dbquote($vars[$k]);
         }
         $set = join(',', $sets);
         $res = $xoopsDB->query("UPDATE " . MAIN . " SET {$set} WHERE mid=" . $mid);
         if ($res) {
             $this->dirty = array();
             if ($this->kdirty) {
                 $xoopsDB->query("DELETE FROM " . RELAY . " WHERE midref={$mid}");
                 $sql = "INSERT INTO " . RELAY . "(keyref, midref) VALUES(%u, {$mid})";
                 foreach ($this->keys as $k) {
                     $xoopsDB->query(sprintf($sql, $k));
                 }
             }
         }
     }
     // save attachment
     if ($res) {
         $adirty =& $this->adirty;
         $attach =& $this->attach;
         if (count($adirty)) {
             foreach ($adirty as $id) {
                 if ($id) {
                     if (!$this->storeAttach($attach[$id])) {
                         return false;
                     }
                 } else {
                     foreach ($attach as $k => $data) {
                         if (empty($data['keyid'])) {
                             $res = $this->storeAttach($data);
                             if ($res) {
                                 unset($attach[$k]);
                                 $data['keyid'] = $res;
                                 $attach[$res] = $data;
                             } else {
                                 return false;
                             }
                         }
                     }
                 }
                 if (!$res) {
                     return false;
                 }
                 unset($adirty[$id]);
             }
         }
         $tags = array('TITLE' => $this->getVar('title'), 'POSTER' => $xoopsUser->getVar('uname'), 'URL' => XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/detail.php?mid=' . $this->getVar('mid'));
         $this->admin_notify(_MD_NOTIFY_SUBJECT, $tags);
     }
     return $mid;
 }
 public function find($service, $uid)
 {
     return $this->db->findid('service = ' . dbquote($service) . ' and uid = ' . dbquote($uid));
 }
 public function find($name, $email, $url)
 {
     $id = $this->db->findid('name = ' . dbquote($name) . ' and email = ' . dbquote($email) . ' and url = ' . dbquote($url));
     return $id == '0' ? false : (int) $id;
 }
 public function adddir($dir)
 {
     $dir = trim(str_replace(DIRECTORY_SEPARATOR, '/', $dir), '/');
     $dirs = array();
     $files = array();
     if ($list = $this->getfilelist($dir)) {
         foreach ($list['dirs'] as $filename) {
             $newdir = $dir . '/' . $filename;
             $dirs[] = litepublisher::$db->escape($filename);
             $this->adddir($newdir);
         }
         foreach ($list['files'] as $filename) {
             if (preg_match('/\\.(php|tml|css|ini|sql|js|txt)$/', $filename)) {
                 $files[] = dbquote($filename);
                 $this->add($dir, $filename);
             }
         }
     }
     $sql = sprintf("(dir = %s and filename <> '' ", dbquote($dir));
     $sql .= count($files) == 0 ? ')' : sprintf(' and filename not in (%s))', implode(',', $files));
     if ($dir == '') {
         $sql .= count($dirs) == 0 ? ')' : sprintf(' or (filename = \'\' and dir <> \'\' and (dir not regexp \'^(%s)($|\\\\/)\') )', implode('|', $dirs));
     } else {
         $sqldir = litepublisher::$db->escape($dir);
         $sql .= sprintf(' or (filename = \'\' and dir != \'%1$s\' and left(dir, %2$d) = \'%1$s\'', $sqldir, strlen($sqldir));
         $sql .= count($dirs) == 0 ? ')' : sprintf(' and (SUBSTRING(dir, %d) not regexp \'^(%s)($|\\\\/)\') )', strlen($sqldir) + 2, implode('|', $dirs));
     }
     if ($deleted = $this->db->getitems($sql)) {
         $items = array();
         $idurls = array();
         foreach ($deleted as $item) {
             $items[] = $item['id'];
             $idurls[] = $item['idurl'];
         }
         litepublisher::$urlmap->db->deleteitems($idurls);
         $this->db->deleteitems($items);
     }
     if ($id = $this->db->findid("filename = '' and dir = " . dbquote($dir))) {
         return $id;
     }
     $item = array('idurl' => 0, 'filename' => '', 'dir' => $dir);
     $id = $this->db->add($item);
     if ($dir == '') {
         if ($urlitem = litepublisher::$urlmap->db->finditem("url = '/source/'")) {
             $idurl = $urlitem['id'];
         } else {
             $idurl = litepublisher::$urlmap->add("/source/", get_class($this), $id);
         }
     } else {
         $idurl = litepublisher::$urlmap->add("/source/{$dir}/", get_class($this), $id);
         //echo "/source/$dir/ added<br>";
     }
     $this->db->setvalue($id, 'idurl', $idurl);
     return $id;
 }