26 changed files with 3968 additions and 7 deletions
-
24app/models/cache/Cache.php
-
121app/models/cache/CacheDAO.php
-
51app/models/caps/Caps.php
-
115app/models/caps/CapsDAO.php
-
348app/models/contact/Contact.php
-
658app/models/contact/ContactDAO.php
-
46app/models/message/Message.php
-
168app/models/message/MessageDAO.php
-
47app/models/node/Node.php
-
254app/models/node/NodeDAO.php
-
235app/models/postn/Postn.php
-
573app/models/postn/PostnDAO.php
-
139app/models/presence/Presence.php
-
146app/models/presence/PresenceDAO.php
-
31app/models/privacy/Privacy.php
-
58app/models/privacy/PrivacyDAO.php
-
53app/models/rosterlink/RosterLink.php
-
395app/models/rosterlink/RosterLinkDAO.php
-
27app/models/session/Session.php
-
190app/models/session/SessionDAO.php
-
49app/models/subscription/Subscription.php
-
222app/models/subscription/SubscriptionDAO.php
-
6app/widgets/ConfigData/ConfigData.php
-
6app/widgets/PubsubSubscriptionConfig/PubsubSubscriptionConfig.php
-
9app/widgets/WidgetCommon/WidgetCommon.php
-
4bootstrap.php
@ -0,0 +1,24 @@ |
|||
<?php |
|||
|
|||
namespace modl; |
|||
|
|||
class Cache extends ModlModel{ |
|||
public $session; |
|||
public $data; |
|||
public $checksum; |
|||
public $timestamp; |
|||
|
|||
public function __construct() { |
|||
$this->_struct = "
|
|||
{ |
|||
'session' : |
|||
{'type':'string', 'size':128, 'mandatory':true, 'key':true }, |
|||
'data' : |
|||
{'type':'text', 'mandatory':true }, |
|||
'checksum' : |
|||
{'type':'string', 'size':128, 'mandatory':true, 'key':true }, |
|||
'timestamp' : |
|||
{'type':'date' } |
|||
}";
|
|||
} |
|||
} |
|||
@ -0,0 +1,121 @@ |
|||
<?php |
|||
|
|||
namespace modl; |
|||
|
|||
class CacheDAO extends ModlSQL { |
|||
/*function create() { |
|||
$sql = ' |
|||
drop table if exists CacheVar'; |
|||
$this->_db->query($sql); |
|||
|
|||
$sql = ' |
|||
create table if not exists `CacheVar` ( |
|||
`id` binary(40) NOT NULL, |
|||
`key` varchar(128) DEFAULT NULL, |
|||
`data` LONGTEXT, |
|||
`checksum` varchar(64) DEFAULT NULL, |
|||
`timestamp` int(11) DEFAULT NULL, |
|||
PRIMARY KEY (`id`) |
|||
) CHARACTER SET utf8 COLLATE utf8_bin |
|||
'; |
|||
$this->_db->query($sql); |
|||
}*/ |
|||
|
|||
function get($key) { |
|||
//$sql = 'select * from CacheVar where CacheVar.key=\''.$key.'\'';
|
|||
//return $this->mapper('Cache', $this->_db->query($sql), 'item');
|
|||
|
|||
$this->_sql = ' |
|||
select * from cache |
|||
where |
|||
session = :session'; |
|||
|
|||
$this->prepare( |
|||
'Cache', |
|||
array( |
|||
'session' => $key |
|||
) |
|||
); |
|||
|
|||
return $this->run('Cache', 'item'); |
|||
} |
|||
|
|||
function set(Cache $cache) { |
|||
|
|||
$this->_sql = ' |
|||
update cache |
|||
set data = :data, |
|||
checksum = :checksum, |
|||
timestamp = :timestamp |
|||
where session = :session'; |
|||
|
|||
$this->prepare( |
|||
'Cache', |
|||
array( |
|||
'session' => $cache->session, |
|||
'data' => $cache->data, |
|||
'timestamp' => $cache->timestamp, |
|||
'checksum' => $cache->checksum |
|||
) |
|||
); |
|||
|
|||
$this->run('Cache'); |
|||
|
|||
if(!$this->_effective) { |
|||
$this->_sql = ' |
|||
insert into cache |
|||
(session, data, checksum, timestamp) |
|||
values (:session, :data, :checksum, :timestamp)'; |
|||
|
|||
$this->prepare( |
|||
'Cache', |
|||
array( |
|||
'session' => $cache->session, |
|||
'data' => $cache->data, |
|||
'timestamp' => $cache->timestamp, |
|||
'checksum' => $cache->checksum |
|||
) |
|||
); |
|||
|
|||
return $this->run('Cache'); |
|||
} |
|||
/*$request = $this->_db->prepare(' |
|||
update CacheVar |
|||
set data = ?, |
|||
checksum = ?, |
|||
timestamp = ? |
|||
where id = ?'); |
|||
|
|||
$hash = sha1($cache->key); |
|||
|
|||
$request->bind_param( |
|||
'ssis', |
|||
$cache->data, |
|||
$cache->checksum, |
|||
$cache->timestamp, |
|||
$hash |
|||
); |
|||
|
|||
$request->execute(); |
|||
|
|||
if($this->_db->affected_rows == 0) { |
|||
$request = $this->_db->prepare(' |
|||
insert into CacheVar |
|||
(`id`,`key`, `data`, `checksum`, `timestamp`) |
|||
values (?,?,?,?,?)'); |
|||
|
|||
$request->bind_param( |
|||
'ssssi', |
|||
$hash, |
|||
$cache->key, |
|||
$cache->data, |
|||
$cache->checksum, |
|||
$cache->timestamp |
|||
); |
|||
|
|||
$request->execute(); |
|||
} |
|||
|
|||
$request->close();*/ |
|||
} |
|||
} |
|||
@ -0,0 +1,51 @@ |
|||
<?php |
|||
|
|||
namespace modl; |
|||
|
|||
class Caps extends ModlModel { |
|||
public $node; |
|||
public $category; |
|||
public $type; |
|||
public $name; |
|||
public $features; |
|||
|
|||
public function __construct() { |
|||
$this->_struct = "
|
|||
{ |
|||
'node' : |
|||
{'type':'string', 'size':256, 'mandatory':true, 'key':true }, |
|||
'category' : |
|||
{'type':'string', 'size':128, 'mandatory':true }, |
|||
'type' : |
|||
{'type':'string', 'size':128, 'mandatory':true }, |
|||
'name' : |
|||
{'type':'string', 'size':128, 'mandatory':true }, |
|||
'features' : |
|||
{'type':'text', 'mandatory':true } |
|||
}";
|
|||
} |
|||
|
|||
public function set($query, $node = false) { |
|||
\movim_log($query); |
|||
if(!$node) |
|||
$this->node = (string)$query->query->attributes()->node; |
|||
else |
|||
$this->node = $node; |
|||
|
|||
if( |
|||
isset($query->query) && |
|||
isset($query->query->identity) && |
|||
$query->query->identity->attributes()) { |
|||
$this->category = (string)$query->query->identity->attributes()->category; |
|||
$this->type = (string)$query->query->identity->attributes()->type; |
|||
$this->name = (string)$query->query->identity->attributes()->name; |
|||
} |
|||
|
|||
$fet = array(); |
|||
foreach($query->query->feature as $f) { |
|||
array_push($fet, (string)$f->attributes()->var); |
|||
} |
|||
$this->features = serialize($fet); |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,115 @@ |
|||
<?php |
|||
|
|||
namespace modl; |
|||
|
|||
class CapsDAO extends ModlSQL { |
|||
/*function create() { |
|||
$sql = ' |
|||
drop table if exists Caps'; |
|||
|
|||
$this->_db->query($sql); |
|||
|
|||
$sql = ' |
|||
create table if not exists `Caps` ( |
|||
`id` int(11) NOT NULL AUTO_INCREMENT, |
|||
`node` varchar(256) DEFAULT NULL, |
|||
`category` varchar(128) DEFAULT NULL, |
|||
`type` varchar(128) DEFAULT NULL, |
|||
`name` varchar(128) DEFAULT NULL, |
|||
`features` text, |
|||
PRIMARY KEY (`id`) |
|||
) CHARACTER SET utf8 COLLATE utf8_bin |
|||
'; |
|||
$this->_db->query($sql); |
|||
}*/ |
|||
|
|||
function get($node) { |
|||
//$sql = 'select * from Caps where node=\''.$node.'\'';
|
|||
//return $this->mapper('Caps', $this->_db->query($sql), 'item');
|
|||
|
|||
$this->_sql = ' |
|||
select * from caps |
|||
where |
|||
node = :node'; |
|||
|
|||
$this->prepare( |
|||
'Caps', |
|||
array( |
|||
'node' => $node |
|||
) |
|||
); |
|||
|
|||
return $this->run('Caps', 'item'); |
|||
} |
|||
|
|||
function getAll() { |
|||
//$sql = 'select * from Caps';
|
|||
//return $this->mapper('Caps', $this->_db->query($sql));
|
|||
|
|||
$this->_sql = ' |
|||
select * from caps'; |
|||
|
|||
$this->prepare( |
|||
'Caps' |
|||
); |
|||
|
|||
return $this->run('Caps'); |
|||
} |
|||
|
|||
function set(Caps $caps) { |
|||
/*$request = $this->prepare(' |
|||
insert into Caps |
|||
(node, |
|||
category, |
|||
type, |
|||
name, |
|||
features |
|||
) |
|||
values( |
|||
?,?,?,?,? |
|||
)', $caps); |
|||
|
|||
$request->bind_param( |
|||
'sssss', |
|||
$caps->node, |
|||
$caps->category, |
|||
$caps->type, |
|||
$caps->name, |
|||
$caps->features |
|||
); |
|||
$request->execute(); |
|||
|
|||
$request->close();*/ |
|||
|
|||
|
|||
$this->_sql = ' |
|||
insert into caps |
|||
( |
|||
node, |
|||
category, |
|||
type, |
|||
name, |
|||
features |
|||
) |
|||
values( |
|||
:node, |
|||
:category, |
|||
:type, |
|||
:name, |
|||
:features |
|||
)'; |
|||
|
|||
$this->prepare( |
|||
'Caps', |
|||
array( |
|||
'node' => $caps->node, |
|||
'category' => $caps->category, |
|||
'type' => $caps->type, |
|||
'name' => $caps->name, |
|||
'features' => $caps->features, |
|||
) |
|||
); |
|||
|
|||
return $this->run('Caps'); |
|||
} |
|||
} |
|||
@ -0,0 +1,348 @@ |
|||
<?php |
|||
|
|||
namespace modl; |
|||
|
|||
class Contact extends ModlModel { |
|||
protected $jid; |
|||
|
|||
protected $fn; |
|||
protected $name; |
|||
protected $date; |
|||
protected $url; |
|||
|
|||
protected $email; |
|||
|
|||
protected $adrlocality; |
|||
protected $adrpostalcode; |
|||
protected $adrcountry; |
|||
|
|||
protected $gender; |
|||
protected $marital; |
|||
|
|||
protected $phototype; |
|||
protected $photobin; |
|||
|
|||
protected $description; |
|||
|
|||
protected $protected; |
|||
protected $privacy; |
|||
|
|||
// User Mood (contain serialized array) - XEP 0107
|
|||
protected $mood; |
|||
|
|||
// User Activity (contain serialized array) - XEP 0108
|
|||
protected $activity; |
|||
|
|||
// User Nickname - XEP 0172
|
|||
protected $nickname; |
|||
|
|||
// User Tune - XEP 0118
|
|||
protected $tuneartist; |
|||
protected $tunelenght; |
|||
protected $tunerating; |
|||
protected $tunesource; |
|||
protected $tunetitle; |
|||
protected $tunetrack; |
|||
|
|||
// User Location
|
|||
protected $loclatitude; |
|||
protected $loclongitude; |
|||
protected $localtitude; |
|||
protected $loccountry; |
|||
protected $loccountrycode; |
|||
protected $locregion; |
|||
protected $locpostalcode; |
|||
protected $loclocality; |
|||
protected $locstreet; |
|||
protected $locbuilding; |
|||
protected $loctext; |
|||
protected $locuri; |
|||
protected $loctimestamp; |
|||
|
|||
public function __construct() { |
|||
$this->_struct = "
|
|||
{ |
|||
'jid' : |
|||
{'type':'string', 'size':128, 'mandatory':true, 'key':true }, |
|||
'fn' : |
|||
{'type':'string', 'size':128 }, |
|||
'name' : |
|||
{'type':'string', 'size':128 }, |
|||
'date' : |
|||
{'type':'date', 'size':11 }, |
|||
'url' : |
|||
{'type':'string', 'size':128 }, |
|||
'email' : |
|||
{'type':'string', 'size':128 }, |
|||
'adrlocality' : |
|||
{'type':'string', 'size':128 }, |
|||
'adrpostalcode' : |
|||
{'type':'string', 'size':128 }, |
|||
'adrcountry' : |
|||
{'type':'string', 'size':128 }, |
|||
'gender' : |
|||
{'type':'string', 'size':1 }, |
|||
'marital' : |
|||
{'type':'string', 'size':20 }, |
|||
'phototype' : |
|||
{'type':'string', 'size':128 }, |
|||
'photobin' : |
|||
{'type':'text'}, |
|||
'description' : |
|||
{'type':'text'}, |
|||
'privacy' : |
|||
{'type':'int', 'size':11 }, |
|||
'mood' : |
|||
{'type':'string', 'size':128 }, |
|||
'activity' : |
|||
{'type':'string', 'size':128 }, |
|||
'nickname' : |
|||
{'type':'string', 'size':128 }, |
|||
'tuneartist' : |
|||
{'type':'string', 'size':128 }, |
|||
'tunelenght' : |
|||
{'type':'int', 'size':11 }, |
|||
'tunerating' : |
|||
{'type':'int', 'size':11 }, |
|||
'tunesource' : |
|||
{'type':'string', 'size':128 }, |
|||
'tunetitle' : |
|||
{'type':'string', 'size':128 }, |
|||
'tunetrack' : |
|||
{'type':'string', 'size':128 }, |
|||
'loclatitude' : |
|||
{'type':'string', 'size':128 }, |
|||
'loclongitude' : |
|||
{'type':'string', 'size':128 }, |
|||
'localtitude' : |
|||
{'type':'int', 'size':11 }, |
|||
'loccountry' : |
|||
{'type':'string', 'size':128 }, |
|||
'loccountrycode' : |
|||
{'type':'string', 'size':128 }, |
|||
'locregion' : |
|||
{'type':'string', 'size':128 }, |
|||
'locpostalcode' : |
|||
{'type':'string', 'size':128 }, |
|||
'loclocality' : |
|||
{'type':'string', 'size':128 }, |
|||
'locstreet' : |
|||
{'type':'string', 'size':128 }, |
|||
'locbuilding' : |
|||
{'type':'string', 'size':128 }, |
|||
'loctext' : |
|||
{'type':'string', 'size':128 }, |
|||
'locuri' : |
|||
{'type':'string', 'size':128 }, |
|||
'loctimestamp' : |
|||
{'type':'date', 'size':11 } |
|||
}";
|
|||
} |
|||
|
|||
public function set($vcard, $jid) { |
|||
$this->jid = \echapJid($jid); |
|||
|
|||
$date = strtotime((string)$vcard->vCard->BDAY); |
|||
|
|||
if($date != false && $date != '' && $date != '-3600') |
|||
$this->date = date('Y-m-d', $date); |
|||
else |
|||
$this->date = '0000-00-00'; |
|||
|
|||
$this->name = (string)$vcard->vCard->NICKNAME; |
|||
$this->fn = (string)$vcard->vCard->FN; |
|||
$this->url = (string)$vcard->vCard->URL; |
|||
|
|||
$this->gender = (string)$vcard->vCard->{'X-GENDER'}; |
|||
$this->marital = (string)$vcard->vCard->MARITAL->STATUS; |
|||
|
|||
$this->email = (string)$vcard->vCard->EMAIL->USERID; |
|||
|
|||
$this->adrlocality = (string)$vcard->vCard->ADR->LOCALITY; |
|||
$this->adrpostalcode = (string)$vcard->vCard->ADR->PCODE; |
|||
$this->adrcountry = (string)$vcard->vCard->ADR->CTRY; |
|||
|
|||
$this->phototype = (string)$vcard->vCard->PHOTO->TYPE; |
|||
$this->photobin = (string)$vcard->vCard->PHOTO->BINVAL; |
|||
|
|||
$this->description = (string)$vcard->vCard->DESC; |
|||
|
|||
$this->privacy = 0; |
|||
} |
|||
|
|||
public function createThumbnails() { |
|||
\createThumbnails(strtolower($this->jid), $this->photobin); |
|||
} |
|||
|
|||
public function getPhoto($size = 'l', $jid = false) { |
|||
$jid = strtolower($jid); |
|||
if($jid != false) { |
|||
$str = BASE_URI.'cache/'.strtolower($jid).'_'.$size.'.jpg'; |
|||
} elseif( |
|||
isset($this->phototype) |
|||
&& isset($this->photobin) |
|||
&& $this->phototype != '' |
|||
&& $this->photobin != '' |
|||
) { |
|||
$str = BASE_URI.'cache/'.strtolower($this->jid).'_'.$size.'.jpg'; |
|||
} else { |
|||
if(isset($this->jid)) |
|||
$out = base_convert($this->jid, 32, 8); |
|||
else |
|||
$out = base_convert(md5(openssl_random_pseudo_bytes(5)), 16, 8); |
|||
|
|||
if($out == false) |
|||
$out[4] = 1; |
|||
$str = BASE_URI.'themes/movim/img/default'.$out[4].'.svg'; |
|||
} |
|||
|
|||
return $str; |
|||
} |
|||
|
|||
public function setLocation($stanza) { |
|||
$this->loclatitude = (string)$stanza->items->item->geoloc->lat; |
|||
$this->loclongitude = (string)$stanza->items->item->geoloc->lon; |
|||
$this->localtitude = (string)$stanza->items->item->geoloc->alt; |
|||
$this->loccountry = (string)$stanza->items->item->geoloc->country; |
|||
$this->loccountrycode = (string)$stanza->items->item->geoloc->countrycode; |
|||
$this->locregion = (string)$stanza->items->item->geoloc->region; |
|||
$this->locpostalcode = (string)$stanza->items->item->geoloc->postalcode; |
|||
$this->loclocality = (string)$stanza->items->item->geoloc->locality; |
|||
$this->locstreet = (string)$stanza->items->item->geoloc->street; |
|||
$this->locbuilding = (string)$stanza->items->item->geoloc->building; |
|||
$this->loctext = (string)$stanza->items->item->geoloc->text; |
|||
$this->locuri = (string)$stanza->items->item->geoloc->uri; |
|||
$this->loctimestamp = date( |
|||
'Y-m-d H:i:s', |
|||
strtotime((string)$stanza->items->item->geoloc->timestamp)); |
|||
} |
|||
|
|||
public function setTune($stanza) { |
|||
$this->tuneartist = (string)$stanza->items->item->tune->artist; |
|||
$this->tunelenght = (int)$stanza->items->item->tune->lenght; |
|||
$this->tunerating = (int)$stanza->items->item->tune->rating; |
|||
$this->tunesource = (string)$stanza->items->item->tune->source; |
|||
$this->tunetitle = (string)$stanza->items->item->tune->title; |
|||
$this->tunetrack = (string)$stanza->items->item->tune->track; |
|||
} |
|||
|
|||
public function getPlace() { |
|||
$place = ''; |
|||
|
|||
if($this->loctext != '') |
|||
$place .= $this->loctext.' '; |
|||
else { |
|||
if($this->locbuilding != '') |
|||
$place .= $this->locbuilding.' '; |
|||
if($this->locstreet != '') |
|||
$place .= $this->locstreet.'<br />'; |
|||
if($this->locpostalcode != '') |
|||
$place .= $this->locpostalcode.' '; |
|||
if($this->loclocality != '') |
|||
$place .= $this->loclocality.'<br />'; |
|||
if($this->locregion != '') |
|||
$place .= $this->locregion.' - '; |
|||
if($this->loccountry != '') |
|||
$place .= $this->loccountry; |
|||
} |
|||
|
|||
return $place; |
|||
} |
|||
|
|||
public function getTrueName() { |
|||
$truename = ''; |
|||
|
|||
if(isset($this->rostername)) |
|||
$rostername = str_replace('\40', '', $this->rostername); |
|||
else |
|||
$rostername = ''; |
|||
|
|||
if( |
|||
isset($this->rostername) |
|||
&& $rostername != '' |
|||
&& !filter_var($rostername, FILTER_VALIDATE_EMAIL) |
|||
) |
|||
$truename = $rostername; |
|||
elseif( |
|||
isset($this->fn) |
|||
&& $this->fn != '' |
|||
&& !filter_var($this->fn, FILTER_VALIDATE_EMAIL) |
|||
) |
|||
$truename = $this->fn; |
|||
elseif( |
|||
isset($this->nickname) |
|||
&& $this->nickname != '' |
|||
&& !filter_var($this->nickname, FILTER_VALIDATE_EMAIL) |
|||
) |
|||
$truename = $this->nickname; |
|||
elseif( |
|||
isset($this->name) |
|||
&& $this->name != '' |
|||
&& !filter_var($this->name, FILTER_VALIDATE_EMAIL) |
|||
) |
|||
$truename = $this->name; |
|||
else |
|||
$truename = $this->jid; |
|||
|
|||
return $truename; |
|||
} |
|||
|
|||
function getAge() { |
|||
if($this->date != '1970-01-01') |
|||
return intval(substr(date('Ymd') - date('Ymd', strtotime($this->date)), 0, -4)); |
|||
} |
|||
} |
|||
|
|||
class RosterContact extends Contact { |
|||
protected $rostername; |
|||
protected $groupname; |
|||
protected $status; |
|||
protected $ressource; |
|||
protected $value; |
|||
protected $delay; |
|||
protected $chaton; |
|||
protected $last; |
|||
protected $rosterask; |
|||
protected $node; |
|||
protected $ver; |
|||
protected $category; |
|||
protected $type; |
|||
|
|||
public function __construct() { |
|||
parent::__construct(); |
|||
$this->_struct = "
|
|||
{ |
|||
'rostername' : |
|||
{'type':'string', 'size':128 }, |
|||
'rosterask' : |
|||
{'type':'string', 'size':128 }, |
|||
'groupname' : |
|||
{'type':'string', 'size':128 }, |
|||
'ressource' : |
|||
{'type':'string', 'size':128, 'key':true }, |
|||
'value' : |
|||
{'type':'int', 'size':11, 'mandatory':true }, |
|||
'chaton' : |
|||
{'type':'int', 'size':11 }, |
|||
'status' : |
|||
{'type':'text'}, |
|||
'node' : |
|||
{'type':'string', 'size':128 }, |
|||
'ver' : |
|||
{'type':'string', 'size':128 }, |
|||
'delay' : |
|||
{'type':'date'}, |
|||
'last' : |
|||
{'type':'int', 'size':11 } |
|||
}";
|
|||
} |
|||
|
|||
// This method is only use on the connection
|
|||
public function setPresence($p) { |
|||
$this->ressource = $p->ressource; |
|||
$this->value = $p->value; |
|||
$this->status = $p->status; |
|||
$this->delay = $p->delay; |
|||
$this->last = $p->last; |
|||
} |
|||
} |
|||
@ -0,0 +1,658 @@ |
|||
<?php |
|||
|
|||
namespace modl; |
|||
|
|||
class ContactDAO extends ModlSQL { |
|||
function __construct() { |
|||
parent::__construct(); |
|||
} |
|||
|
|||
function get($jid) { |
|||
$this->_sql = ' |
|||
select *, privacy.value as privacy from contact |
|||
left outer join privacy |
|||
on contact.jid = privacy.pkey |
|||
where jid = :jid'; |
|||
|
|||
$this->prepare( |
|||
'Contact', |
|||
array( |
|||
'jid' => $jid |
|||
) |
|||
); |
|||
|
|||
return $this->run('Contact', 'item'); |
|||
} |
|||
|
|||
function set(Contact $contact) { |
|||
$this->_sql = ' |
|||
update contact |
|||
set fn = :fn, |
|||
name = :name, |
|||
date = :date, |
|||
url = :url, |
|||
|
|||
email = :email, |
|||
|
|||
adrlocality = :adrlocality, |
|||
adrpostalcode = :adrpostalcode, |
|||
adrcountry = :adrcountry, |
|||
|
|||
gender = :gender, |
|||
marital = :marital, |
|||
|
|||
phototype = :phototype, |
|||
photobin = :photobin, |
|||
|
|||
description = :description, |
|||
|
|||
privacy = :privacy, |
|||
|
|||
mood = :mood, |
|||
|
|||
activity = :activity, |
|||
|
|||
nickname = :nickname, |
|||
|
|||
tuneartist = :tuneartist, |
|||
tunelenght = :tunelenght, |
|||
tunerating = :tunerating, |
|||
tunesource = :tunesource, |
|||
tunetitle = :tunetitle, |
|||
tunetrack = :tunetrack, |
|||
|
|||
loclatitude = :loclatitude, |
|||
loclongitude = :loclongitude, |
|||
localtitude = :localtitude, |
|||
loccountry = :loccountry, |
|||
loccountrycode = :loccountrycode, |
|||
locregion = :locregion, |
|||
locpostalcode = :locpostalcode, |
|||
loclocality = :loclocality, |
|||
locstreet = :locstreet, |
|||
locbuilding = :locbuilding, |
|||
loctext = :loctext, |
|||
locuri = :locuri, |
|||
loctimestamp = :loctimestamp |
|||
where contact.jid = :jid'; |
|||
|
|||
$this->prepare( |
|||
'Contact', |
|||
array( |
|||
'fn' => $contact->fn, |
|||
'name' => $contact->name, |
|||
'date' => $contact->date, |
|||
'url' => $contact->url, |
|||
|
|||
'email' => $contact->email, |
|||
|
|||
'adrlocality' => $contact->adrlocality, |
|||
'adrpostalcode' => $contact->adrpostalcode, |
|||
'adrcountry' => $contact->adrcountry, |
|||
|
|||
'gender' => $contact->gender, |
|||
'marital' => $contact->marital, |
|||
|
|||
'phototype' => $contact->phototype, |
|||
'photobin' => $contact->photobin, |
|||
|
|||
'description' => $contact->description, |
|||
|
|||
'privacy' => $contact->privacy, |
|||
|
|||
// User Mood (contain serialized array) - XEP 0107
|
|||
'mood' => $contact->mood, |
|||
|
|||
// User Activity (contain serialized array) - XEP 0108
|
|||
'activity' => $contact->activity, |
|||
|
|||
// User Nickname - XEP 0172
|
|||
'nickname' => $contact->nickname, |
|||
|
|||
// User Tune - XEP 0118
|
|||
'tuneartist' => $contact->tuneartist, |
|||
'tunelenght' => $contact->tunelenght, |
|||
'tunerating' => $contact->tunerating, |
|||
'tunesource' => $contact->tunesource, |
|||
'tunetitle' => $contact->tunetitle, |
|||
'tunetrack' => $contact->tunetrack, |
|||
|
|||
// User Location
|
|||
'loclatitude' => $contact->loclatitude, |
|||
'loclongitude' => $contact->loclongitude, |
|||
'localtitude' => $contact->localtitude, |
|||
'loccountry' => $contact->loccountry, |
|||
'loccountrycode' => $contact->loccountrycode, |
|||
'locregion' => $contact->locregion, |
|||
'locpostalcode' => $contact->locpostalcode, |
|||
'loclocality' => $contact->loclocality, |
|||
'locstreet' => $contact->locstreet, |
|||
'locbuilding' => $contact->locbuilding, |
|||
'loctext' => $contact->loctext, |
|||
'locuri' => $contact->locuri, |
|||
'loctimestamp' => $contact->loctimestamp, |
|||
|
|||
'jid' => $contact->jid |
|||
) |
|||
); |
|||
|
|||
$this->run('Contact'); |
|||
|
|||
if(!$this->_effective) { |
|||
$this->_sql = ' |
|||
insert into contact |
|||
( |
|||
fn, |
|||
name, |
|||
date, |
|||
url, |
|||
|
|||
email, |
|||
|
|||
adrlocality, |
|||
adrpostalcode, |
|||
adrcountry, |
|||
|
|||
gender, |
|||
marital, |
|||
|
|||
phototype, |
|||
photobin, |
|||
|
|||
description, |
|||
|
|||
privacy, |
|||
|
|||
mood, |
|||
|
|||
activity, |
|||
|
|||
nickname, |
|||
|
|||
tuneartist, |
|||
tunelenght, |
|||
tunerating, |
|||
tunesource, |
|||
tunetitle, |
|||
tunetrack, |
|||
|
|||
loclatitude, |
|||
loclongitude, |
|||
localtitude, |
|||
loccountry, |
|||
loccountrycode, |
|||
locregion, |
|||
locpostalcode, |
|||
loclocality, |
|||
locstreet, |
|||
locbuilding, |
|||
loctext, |
|||
locuri, |
|||
loctimestamp, |
|||
jid) |
|||
values ( |
|||
:fn, |
|||
:name, |
|||
:date, |
|||
:url, |
|||
|
|||
:email, |
|||
|
|||
:adrlocality, |
|||
:adrpostalcode, |
|||
:adrcountry, |
|||
|
|||
:gender, |
|||
:marital, |
|||
|
|||
:phototype, |
|||
:photobin, |
|||
|
|||
:description, |
|||
|
|||
:privacy, |
|||
|
|||
:mood, |
|||
|
|||
:activity, |
|||
|
|||
:nickname, |
|||
|
|||
:tuneartist, |
|||
:tunelenght, |
|||
:tunerating, |
|||
:tunesource, |
|||
:tunetitle, |
|||
:tunetrack, |
|||
|
|||
:loclatitude, |
|||
:loclongitude, |
|||
:localtitude, |
|||
:loccountry, |
|||
:loccountrycode, |
|||
:locregion, |
|||
:locpostalcode, |
|||
:loclocality, |
|||
:locstreet, |
|||
:locbuilding, |
|||
:loctext, |
|||
:locuri, |
|||
:loctimestamp, |
|||
:jid)'; |
|||
|
|||
|
|||
$this->prepare( |
|||
'Contact', |
|||
array( |
|||
'fn' => $contact->fn, |
|||
'name' => $contact->name, |
|||
'date' => $contact->date, |
|||
'url' => $contact->url, |
|||
|
|||
'email' => $contact->email, |
|||
|
|||
'adrlocality' => $contact->adrlocality, |
|||
'adrpostalcode' => $contact->adrpostalcode, |
|||
'adrcountry' => $contact->adrcountry, |
|||
|
|||
'gender' => $contact->gender, |
|||
'marital' => $contact->marital, |
|||
|
|||
'phototype' => $contact->phototype, |
|||
'photobin' => $contact->photobin, |
|||
|
|||
'description' => $contact->description, |
|||
|
|||
'privacy' => $contact->privacy, |
|||
|
|||
// User Mood (contain serialized array) - XEP 0107
|
|||
'mood' => $contact->mood, |
|||
|
|||
// User Activity (contain serialized array) - XEP 0108
|
|||
'activity' => $contact->activity, |
|||
|
|||
// User Nickname - XEP 0172
|
|||
'nickname' => $contact->nickname, |
|||
|
|||
// User Tune - XEP 0118
|
|||
'tuneartist' => $contact->tuneartist, |
|||
'tunelenght' => $contact->tunelenght, |
|||
'tunerating' => $contact->tunerating, |
|||
'tunesource' => $contact->tunesource, |
|||
'tunetitle' => $contact->tunetitle, |
|||
'tunetrack' => $contact->tunetrack, |
|||
|
|||
// User Location
|
|||
'loclatitude' => $contact->loclatitude, |
|||
'loclongitude' => $contact->loclongitude, |
|||
'localtitude' => $contact->localtitude, |
|||
'loccountry' => $contact->loccountry, |
|||
'loccountrycode' => $contact->loccountrycode, |
|||
'locregion' => $contact->locregion, |
|||
'locpostalcode' => $contact->locpostalcode, |
|||
'loclocality' => $contact->loclocality, |
|||
'locstreet' => $contact->locstreet, |
|||
'locbuilding' => $contact->locbuilding, |
|||
'loctext' => $contact->loctext, |
|||
'locuri' => $contact->locuri, |
|||
'loctimestamp' => $contact->loctimestamp, |
|||
|
|||
'jid' => $contact->jid |
|||
) |
|||
); |
|||
|
|||
$this->run('Contact'); |
|||
} |
|||
} |
|||
|
|||
function getAll() { |
|||
$this->_sql = |
|||
'select *, privacy.value as privacy from contact |
|||
left outer join privacy |
|||
on contact.jid = privacy.pkey'; |
|||
|
|||
$this->prepare('Contact'); |
|||
return $this->run('Contact'); |
|||
} |
|||
|
|||
function getAllPublic() { |
|||
$this->_sql = |
|||
'select *, privacy.value as privacy from contact |
|||
left outer join privacy |
|||
on contact.jid = privacy.pkey |
|||
where privacy.value = 1'; |
|||
|
|||
$this->prepare('Contact'); |
|||
return $this->run('Contact'); |
|||
} |
|||
|
|||
function cleanRoster() { |
|||
$this->_sql = ' |
|||
delete from RosterLink |
|||
where RosterLink.key = :key'; |
|||
|
|||
$this->prepare( |
|||
'RosterLink', |
|||
array( |
|||
'key' => $this->_user |
|||
) |
|||
); |
|||
|
|||
return $this->run('RosterLink'); |
|||
} |
|||
function getRoster() { |
|||
$this->_sql = ' |
|||
select * from rosterlink |
|||
left outer join presence |
|||
on rosterlink.jid = presence.jid and rosterlink.session = presence.session |
|||
left outer join contact |
|||
on rosterlink.jid = contact.jid |
|||
where rosterlink.session = :session |
|||
order by groupname'; |
|||
|
|||
$this->prepare( |
|||
'RosterLink', |
|||
array( |
|||
'session' => $this->_user |
|||
) |
|||
); |
|||
|
|||
return $this->run('RosterContact'); |
|||
/*$this->_sql = ' |
|||
select |
|||
RosterLink.jid, |
|||
contact.fn, |
|||
contact.nickname, |
|||
contact.name, |
|||
contact.phototype, |
|||
contact.photobin, |
|||
contact.loclatitude, |
|||
contact.loclongitude, |
|||
contact.localtitude, |
|||
contact.loccountry, |
|||
contact.loccountrycode, |
|||
contact.locregion, |
|||
contact.locpostalcode, |
|||
contact.loclocality, |
|||
contact.locstreet, |
|||
contact.locbuilding, |
|||
contact.loctext, |
|||
contact.locuri, |
|||
contact.loctimestamp, |
|||
contact.mood, |
|||
contact.tuneartist, |
|||
contact.tunelenght, |
|||
contact.tunerating, |
|||
contact.tunesource, |
|||
contact.tunetitle, |
|||
contact.tunetrack, |
|||
RosterLink.rostername, |
|||
RosterLink.group, |
|||
Presence.status, |
|||
Presence.ressource, |
|||
Presence.presence, |
|||
Presence.delay, |
|||
Presence.last, |
|||
Presence.node, |
|||
Presence.ver |
|||
from RosterLink left outer join |
|||
( |
|||
select * from Presence |
|||
where Presence.key=\''.$this->_user.'\' |
|||
group by jid, node, ver |
|||
order by presence) as Presence |
|||
on Presence.jid = RosterLink.jid |
|||
left join contact on RosterLink.jid = contact.jid |
|||
where RosterLink.key=\''.$this->_user.'\' |
|||
group by RosterLink.jid |
|||
order by RosterLink.group'; |
|||
|
|||
return $this->mapper('RosterContact', $this->_db->query($sql));*/ |
|||
} |
|||
|
|||
function getRosterChat() { |
|||
/* |
|||
* $sql = ' |
|||
select |
|||
RosterLink.jid, |
|||
contact.fn, |
|||
contact.nickname, |
|||
contact.name, |
|||
contact.phototype, |
|||
contact.photobin, |
|||
contact.loclatitude, |
|||
contact.loclongitude, |
|||
contact.localtitude, |
|||
contact.loccountry, |
|||
contact.loccountrycode, |
|||
contact.locregion, |
|||
contact.locpostalcode, |
|||
contact.loclocality, |
|||
contact.locstreet, |
|||
contact.locbuilding, |
|||
contact.loctext, |
|||
contact.locuri, |
|||
contact.loctimestamp, |
|||
contact.mood, |
|||
contact.tuneartist, |
|||
contact.tunelenght, |
|||
contact.tunerating, |
|||
contact.tunesource, |
|||
contact.tunetitle, |
|||
contact.tunetrack, |
|||
RosterLink.rostername, |
|||
RosterLink.groupname, |
|||
RosterLink.chaton, |
|||
Presence.status, |
|||
Presence.ressource, |
|||
Presence.presence, |
|||
Presence.delay, |
|||
Presence.last, |
|||
Presence.node, |
|||
Presence.ver |
|||
from RosterLink left outer join |
|||
( |
|||
select * from Presence |
|||
where Presence.key=\''.$this->_user.'\' |
|||
group by jid, node, ver |
|||
order by presence) as Presence |
|||
on Presence.jid = RosterLink.jid |
|||
left join contact on RosterLink.jid = contact.jid |
|||
where RosterLink.key=\''.$this->_user.'\' |
|||
and RosterLink.chaton > 0 |
|||
group by RosterLink.jid |
|||
order by RosterLink.groupname'; |
|||
|
|||
return $this->mapper('RosterContact', $this->_db->query($sql)); |
|||
*/ |
|||
$this->_sql = ' |
|||
select * from rosterlink |
|||
left outer join ( |
|||
select * from presence |
|||
order by presence.priority desc |
|||
limit 1 |
|||
) as presence |
|||
on rosterlink.jid = presence.jid |
|||
left outer join contact |
|||
on rosterlink.jid = contact.jid |
|||
where rosterlink.session = :session |
|||
and rosterLink.chaton > 0 |
|||
order by rosterlink.groupname, presence.value, rosterlink.jid'; |
|||
|
|||
$this->prepare( |
|||
'RosterLink', |
|||
array( |
|||
'session' => $this->_user |
|||
) |
|||
); |
|||
|
|||
return $this->run('RosterContact'); |
|||
} |
|||
|
|||
function getRosterItem($jid) { |
|||
/*$sql = ' |
|||
select |
|||
RosterLink.jid, |
|||
contact.fn, |
|||
contact.nickname, |
|||
contact.name, |
|||
contact.url, |
|||
contact.phototype, |
|||
contact.photobin, |
|||
contact.loclatitude, |
|||
contact.loclongitude, |
|||
contact.localtitude, |
|||
contact.loccountry, |
|||
contact.loccountrycode, |
|||
contact.locregion, |
|||
contact.locpostalcode, |
|||
contact.loclocality, |
|||
contact.locstreet, |
|||
contact.locbuilding, |
|||
contact.loctext, |
|||
contact.locuri, |
|||
contact.loctimestamp, |
|||
contact.mood, |
|||
contact.tuneartist, |
|||
contact.tunelenght, |
|||
contact.tunerating, |
|||
contact.tunesource, |
|||
contact.tunetitle, |
|||
contact.tunetrack, |
|||
RosterLink.rostername, |
|||
RosterLink.groupname, |
|||
RosterLink.chaton, |
|||
Presence.status, |
|||
Presence.ressource, |
|||
Presence.presence, |
|||
Presence.delay, |
|||
Presence.last, |
|||
Presence.node, |
|||
Presence.ver, |
|||
RosterLink.rosterask |
|||
from RosterLink |
|||
left outer join |
|||
( |
|||
select * from Presence |
|||
where Presence.key=\''.$this->_user.'\' |
|||
and Presence.jid=\''.$jid.'\' |
|||
group by jid, node, ver |
|||
order by presence) as Presence |
|||
on Presence.jid = RosterLink.jid |
|||
left outer join contact on RosterLink.jid = contact.jid |
|||
where RosterLink.key=\''.$this->_user.'\' |
|||
and RosterLink.jid=\''.$this->_db->real_escape_string($jid).'\';'; |
|||
|
|||
return $this->mapper('RosterContact', $this->_db->query($sql), 'item'); */ |
|||
$this->_sql = ' |
|||
select * from rosterlink |
|||
left outer join ( |
|||
select * from presence |
|||
where session = :session |
|||
and jid = :jid |
|||
order by presence.value |
|||
limit 1 |
|||
) as presence |
|||
on rosterlink.jid = presence.jid |
|||
left outer join contact |
|||
on rosterlink.jid = contact.jid |
|||
where rosterlink.session = :session |
|||
and rosterlink.jid = :jid |
|||
order by rosterlink.groupname, presence.value, rosterlink.jid'; |
|||
|
|||
$this->prepare( |
|||
'RosterLink', |
|||
array( |
|||
'session' => $this->_user, |
|||
'jid' => $jid |
|||
) |
|||
); |
|||
|
|||
return $this->run('RosterContact', 'item'); |
|||
} |
|||
|
|||
function getRosterSubscribe() { |
|||
/*$sql = ' |
|||
select |
|||
RosterLink.jid, |
|||
contact.fn, |
|||
contact.nickname, |
|||
contact.name, |
|||
contact.phototype, |
|||
contact.photobin, |
|||
contact.loclatitude, |
|||
contact.loclongitude, |
|||
contact.localtitude, |
|||
contact.loccountry, |
|||
contact.loccountrycode, |
|||
contact.locregion, |
|||
contact.locpostalcode, |
|||
contact.loclocality, |
|||
contact.locstreet, |
|||
contact.locbuilding, |
|||
contact.loctext, |
|||
contact.locuri, |
|||
contact.loctimestamp, |
|||
contact.mood, |
|||
contact.tuneartist, |
|||
contact.tunelenght, |
|||
contact.tunerating, |
|||
contact.tunesource, |
|||
contact.tunetitle, |
|||
contact.tunetrack, |
|||
RosterLink.rostername, |
|||
RosterLink.group, |
|||
RosterLink.chaton, |
|||
Presence.status, |
|||
Presence.ressource, |
|||
Presence.presence, |
|||
Presence.delay, |
|||
Presence.last, |
|||
Presence.node, |
|||
Presence.ver |
|||
from RosterLink left outer join |
|||
( |
|||
select * from Presence |
|||
where Presence.key=\''.$this->_user.'\' |
|||
group by jid, node, ver |
|||
order by presence) as Presence |
|||
on Presence.jid = RosterLink.jid |
|||
left join contact on RosterLink.jid = contact.jid |
|||
where RosterLink.key=\''.$this->_user.'\' |
|||
and RosterLink.rosterask = \'subscribe\' |
|||
group by RosterLink.jid |
|||
order by RosterLink.groupname'; |
|||
|
|||
return $this->mapper('RosterContact', $this->_db->query($sql));*/ |
|||
|
|||
return null; |
|||
} |
|||
|
|||
function getStatistics() { |
|||
$this->_sql = ' |
|||
select |
|||
(select count(*) from postn where postn.session = :session ) as post, |
|||
(select count(*) from rosterLink where rosterLink.session= :session ) as rosterLink, |
|||
(select count(*) from presence where presence.session= :session ) as presence, |
|||
(select count(*) from message where message.session = :session) as message;'; |
|||
|
|||
$this->prepare( |
|||
'Postn', |
|||
array( |
|||
'session' => $this->_user |
|||
) |
|||
); |
|||
|
|||
return $this->run(null, 'array'); |
|||
/* |
|||
$sql = ' |
|||
select |
|||
(select count(*) from Postn where Postn.key = \''.$this->_user.'\' ) as Post, |
|||
(select count(*) from RosterLink where RosterLink.key = \''.$this->_user.'\' ) as RosterLink, |
|||
(select count(*) from Presence where Presence.key = \''.$this->_user.'\' ) as Presence, |
|||
(select count(*) from Message where Message.key = \''.$this->_user.'\') as Message'; |
|||
|
|||
$resultset = $this->_db->query($sql); |
|||
return $resultset->fetch_array(MYSQLI_ASSOC); */ |
|||
} |
|||
} |
|||
@ -0,0 +1,46 @@ |
|||
<?php |
|||
|
|||
namespace modl; |
|||
|
|||
class Message extends ModlModel { |
|||
public $session; |
|||
public $jidto; |
|||
public $jidfrom; |
|||
|
|||
public $ressource; |
|||
|
|||
public $type; |
|||
|
|||
public $subject; |
|||
public $thread; |
|||
public $body; |
|||
|
|||
public $published; |
|||
public $delivered; |
|||
|
|||
public function __construct() { |
|||
$this->_struct = "
|
|||
{ |
|||
'session' : |
|||
{'type':'string', 'size':128, 'mandatory':true }, |
|||
'jidto' : |
|||
{'type':'string', 'size':128, 'mandatory':true }, |
|||
'jidfrom' : |
|||
{'type':'string', 'size':128, 'mandatory':true }, |
|||
'ressource' : |
|||
{'type':'string', 'size':128 }, |
|||
'type' : |
|||
{'type':'string', 'size':20 }, |
|||
'subject' : |
|||
{'type':'text'}, |
|||
'thread' : |
|||
{'type':'string', 'size':128 }, |
|||
'body' : |
|||
{'type':'text'}, |
|||
'published' : |
|||
{'type':'date'}, |
|||
'delivered' : |
|||
{'type':'date'} |
|||
}";
|
|||
} |
|||
} |
|||
@ -0,0 +1,168 @@ |
|||
<?php |
|||
|
|||
namespace modl; |
|||
|
|||
class MessageDAO extends ModlSQL { |
|||
/*function create() { |
|||
$sql = ' |
|||
drop table if exists Message'; |
|||
|
|||
$this->_db->query($sql); |
|||
|
|||
$sql = ' |
|||
create table if not exists Message ( |
|||
`id` int(11) NOT NULL AUTO_INCREMENT, |
|||
`key` varchar(128) DEFAULT NULL, |
|||
`to` varchar(128) DEFAULT NULL, |
|||
`from` varchar(128) DEFAULT NULL, |
|||
`ressource` varchar(128) DEFAULT NULL, |
|||
`type` varchar(20) DEFAULT NULL, |
|||
`subject` text, |
|||
`thread` varchar(128) DEFAULT NULL, |
|||
`body` text, |
|||
`published` datetime DEFAULT NULL, |
|||
`delivered` datetime DEFAULT NULL, |
|||
PRIMARY KEY (`id`) |
|||
) AUTO_INCREMENT=10 CHARACTER SET utf8 COLLATE utf8_bin'; |
|||
|
|||
$this->_db->query($sql); |
|||
}*/ |
|||
|
|||
function set(Message $message) { |
|||
$this->_sql = ' |
|||
insert into Message |
|||
( |
|||
session, |
|||
jidto, |
|||
jidfrom, |
|||
ressource, |
|||
type, |
|||
subject, |
|||
thread, |
|||
body, |
|||
published, |
|||
delivered) |
|||
values( |
|||
:session, |
|||
:jidto, |
|||
:jidfrom, |
|||
:ressource, |
|||
:type, |
|||
:subject, |
|||
:thread, |
|||
:body, |
|||
:published, |
|||
:delivered |
|||
)'; |
|||
|
|||
$this->prepare( |
|||
'Message', |
|||
array( |
|||
'session' => $this->_user, |
|||
'jidto' => $message->jidto, |
|||
'jidfrom' => $message->jidfrom, |
|||
'ressource' => $message->ressource, |
|||
'type' => $message->type, |
|||
'subject' => $message->subject, |
|||
'thread' => $message->thread, |
|||
'body' => $message->body, |
|||
'published' => $message->published, |
|||
'delivered' =>$message->delivered |
|||
) |
|||
); |
|||
|
|||
return $this->run('Message'); |
|||
|
|||
/*$request = $this->_db->prepare(' |
|||
insert into Message |
|||
(`key`, |
|||
`to`, |
|||
`from`, |
|||
`ressource`, |
|||
`type`, |
|||
`subject`, |
|||
`thread`, |
|||
`body`, |
|||
`published`, |
|||
`delivered`) |
|||
values( |
|||
?,?,?,?,?, |
|||
?,?,?,?,? |
|||
)'); |
|||
|
|||
$request->bind_param( |
|||
'ssssssssss', |
|||
$message->key, |
|||
$message->to, |
|||
$message->from, |
|||
$message->ressource, |
|||
$message->type, |
|||
$message->subject, |
|||
$message->thread, |
|||
$message->body, |
|||
$message->published, |
|||
$message->delivered |
|||
); |
|||
$request->execute(); |
|||
|
|||
$request->close();*/ |
|||
} |
|||
|
|||
function getContact($jid, $limitf = false, $limitr = false) { |
|||
/* |
|||
$sql = ' |
|||
select * from Message |
|||
where Message.key = \''.$this->_user->getLogin().'\' |
|||
and (Message.from = \''.$this->_db->real_escape_string($jid).'\' |
|||
or Message.to = \''.$this->_db->real_escape_string($jid).'\') |
|||
order by Message.published desc'; |
|||
|
|||
if($limitr) |
|||
$sql = $sql.' limit '.$limitf.','.$limitr; |
|||
|
|||
return array_reverse($this->mapper('Message', $this->_db->query($sql))); |
|||
*/ |
|||
|
|||
$this->_sql = ' |
|||
select * from message |
|||
where session = :session |
|||
and (jidfrom = :jidfrom |
|||
or jidto = :jidto) |
|||
order by published desc'; |
|||
|
|||
if($limitr) |
|||
$this->_sql = $this->_sql.' limit '.$limitr.' offset '.$limitf; |
|||
|
|||
$this->prepare( |
|||
'Message', |
|||
array( |
|||
'session' => $this->_user, |
|||
'jidfrom' => $jid, |
|||
'jidto' => $jid |
|||
) |
|||
); |
|||
|
|||
return $this->run('Message'); |
|||
} |
|||
|
|||
function clearMessage() { |
|||
$this->_sql = ' |
|||
delete from message |
|||
where session = :session'; |
|||
|
|||
$this->prepare( |
|||
'Message', |
|||
array( |
|||
'session' => $this->_user |
|||
) |
|||
); |
|||
|
|||
return $this->run('Message'); |
|||
/* |
|||
$sql = ' |
|||
delete from Message |
|||
where Message.key=\''.$this->_user->getLogin().'\''; |
|||
|
|||
return $this->_db->query($sql);*/ |
|||
} |
|||
} |
|||
@ -0,0 +1,47 @@ |
|||
<?php |
|||
|
|||
namespace modl; |
|||
|
|||
class Node extends ModlModel { |
|||
public $serverid; |
|||
public $nodeid; |
|||
public $title; |
|||
public $config; |
|||
public $updated; |
|||
public $number; |
|||
|
|||
public function __construct() { |
|||
$this->_struct = "
|
|||
{ |
|||
'serverid' : |
|||
{'type':'string', 'size':128, 'mandatory':true }, |
|||
'nodeid' : |
|||
{'type':'string', 'size':128, 'mandatory':true }, |
|||
'title' : |
|||
{'type':'string', 'size':128 }, |
|||
'config' : |
|||
{'type':'text' }, |
|||
'updated' : |
|||
{'type':'date'} |
|||
}";
|
|||
} |
|||
|
|||
public function set($item, $serverid) { |
|||
$this->serverid = $serverid; |
|||
$this->nodeid = (string)$item->attributes()->node; |
|||
$this->title = (string)$item->attributes()->name; |
|||
$this->updated = date('Y-m-d H:i:s'); |
|||
} |
|||
|
|||
public function getName() { |
|||
if($this->title == '') |
|||
return $this->nodeid; |
|||
else |
|||
return $this->title; |
|||
} |
|||
} |
|||
|
|||
class Server extends ModlModel { |
|||
public $serverid; |
|||
public $number; |
|||
} |
|||
@ -0,0 +1,254 @@ |
|||
<?php |
|||
|
|||
namespace modl; |
|||
|
|||
class NodeDAO extends ModlSQL { |
|||
/*function create() { |
|||
$sql = ' |
|||
drop table if exists Node'; |
|||
|
|||
$this->_db->query($sql); |
|||
|
|||
$sql = ' |
|||
create table if not exists Node ( |
|||
serverid varchar(45) NOT NULL, |
|||
nodeid varchar(45) NOT NULL, |
|||
title varchar(128) DEFAULT NULL, |
|||
config text, |
|||
updated datetime NOT NULL |
|||
) CHARACTER SET utf8 COLLATE utf8_bin'; |
|||
$this->_db->query($sql); |
|||
}*/ |
|||
|
|||
function set(Node $node) { |
|||
$this->_sql = ' |
|||
update node |
|||
set config = :config, |
|||
title = :title, |
|||
updated = :updated |
|||
where serverid = :serverid |
|||
and nodeid = :nodeid'; |
|||
|
|||
$this->prepare( |
|||
'Node', |
|||
array( |
|||
'config' => $node->config, |
|||
'title' => $node->title, |
|||
'updated'=> $node->updated, |
|||
'serverid' => $node->serverid, |
|||
'nodeid' => $node->nodeid |
|||
) |
|||
); |
|||
|
|||
$this->run('Node'); |
|||
|
|||
if(!$this->_effective) { |
|||
$this->_sql = ' |
|||
insert into node |
|||
(serverid, |
|||
nodeid, |
|||
config, |
|||
title, |
|||
updated |
|||
) |
|||
values( |
|||
:serverid, |
|||
:nodeid, |
|||
:config, |
|||
:title, |
|||
:updated |
|||
)'; |
|||
|
|||
$this->prepare( |
|||
'Node', |
|||
array( |
|||
'config' => $node->config, |
|||
'title' => $node->title, |
|||
'updated'=> $node->updated, |
|||
'serverid' => $node->serverid, |
|||
'nodeid' => $node->nodeid |
|||
) |
|||
); |
|||
|
|||
$this->run('Node'); |
|||
} |
|||
|
|||
/*$request = $this->_db->prepare(' |
|||
update Node |
|||
set config = ?, |
|||
title = ?, |
|||
updated = ? |
|||
where serverid = ? |
|||
and nodeid = ?'); |
|||
|
|||
$request->bind_param( |
|||
'sssss', |
|||
$node->config, |
|||
$node->title, |
|||
$node->updated, |
|||
$node->serverid, |
|||
$node->nodeid |
|||
); |
|||
|
|||
$result = $request->execute(); |
|||
|
|||
if($this->_db->affected_rows == 0) { |
|||
$request = $this->_db->prepare(' |
|||
insert into Node |
|||
(serverid, |
|||
nodeid, |
|||
config, |
|||
title, |
|||
updated |
|||
) |
|||
values( |
|||
?,?,?,?,? |
|||
)'); |
|||
|
|||
$request->bind_param( |
|||
'sssss', |
|||
$node->serverid, |
|||
$node->nodeid, |
|||
$node->config, |
|||
$node->title, |
|||
$node->updated |
|||
); |
|||
$request->execute(); |
|||
} |
|||
|
|||
$request->close();*/ |
|||
} |
|||
|
|||
function getServers() { |
|||
/*$sql = ' |
|||
select serverid, count(nodeid) as number |
|||
from Node |
|||
where nodeid not like \'urn:xmpp:microblog:0:comments/%\' |
|||
group by serverid |
|||
order by number desc'; |
|||
|
|||
$resultset = $this->_db->query($sql); |
|||
return $this->mapper('Server', $this->_db->query($sql));*/ |
|||
|
|||
$this->_sql = ' |
|||
select serverid, count(nodeid) as number |
|||
from node |
|||
where nodeid not like \'urn:xmpp:microblog:0:comments/%\' |
|||
group by serverid |
|||
order by number desc'; |
|||
|
|||
$this->prepare( |
|||
'Server' |
|||
); |
|||
|
|||
return $this->run('Server'); |
|||
} |
|||
|
|||
function getNodes($serverid) { |
|||
/*$serverid = $this->_db->real_escape_string($serverid); |
|||
$sql = ' |
|||
select Node.*, count(P.nodeid) as number from Node |
|||
left outer join (select * from Postn where Postn.from = \''.$serverid.'\' group by nodeid) as P |
|||
on Node.nodeid = P.node |
|||
where serverid=\''.$serverid.'\' |
|||
group by nodeid |
|||
order by number desc'; |
|||
|
|||
return $this->mapper('Node', $this->_db->query($sql)); |
|||
*/ |
|||
|
|||
/*$this->_sql = ' |
|||
select node.*, count(P.nodeid) as number from node |
|||
left outer join (select * from postn where postn.jid = :serverid) as P |
|||
on node.nodeid = P.node |
|||
where serverid= :serverid |
|||
order by number desc'; |
|||
*/ |
|||
|
|||
$this->_sql = ' |
|||
select * from node |
|||
where serverid= :serverid'; |
|||
|
|||
$this->prepare( |
|||
'Node', |
|||
array( |
|||
'serverid' => $serverid |
|||
) |
|||
); |
|||
|
|||
return $this->run('Node'); |
|||
} |
|||
|
|||
function deleteNodes($serverid) { |
|||
/*$serverid = $this->_db->real_escape_string($serverid); |
|||
$sql = ' |
|||
delete from Node |
|||
where serverid=\''.$serverid.'\' '; |
|||
|
|||
return $this->_db->query($sql); */ |
|||
|
|||
$this->_sql = ' |
|||
delete from node |
|||
where serverid= :serverid'; |
|||
|
|||
$this->prepare( |
|||
'Node', |
|||
array( |
|||
'serverid' => $serverid |
|||
) |
|||
); |
|||
|
|||
return $this->run('Node'); |
|||
} |
|||
|
|||
function deleteNode($serverid, $nodeid) { |
|||
/*$serverid = $this->_db->real_escape_string($serverid); |
|||
$nodeid = $this->_db->real_escape_string($nodeid); |
|||
$sql = ' |
|||
delete from Node |
|||
where serverid=\''.$serverid.'\' and |
|||
nodeid=\''.$nodeid.'\''; |
|||
|
|||
return $this->_db->query($sql); */ |
|||
|
|||
$this->_sql = ' |
|||
delete from node |
|||
where serverid = :serverid |
|||
and nodeid = :nodeid'; |
|||
|
|||
$this->prepare( |
|||
'Node', |
|||
array( |
|||
'serverid' => $serverid, |
|||
'nodeid' => $nodeid |
|||
) |
|||
); |
|||
|
|||
return $this->run('Node'); |
|||
} |
|||
|
|||
function getNode($serverid, $nodeid) { |
|||
/*$sql = ' |
|||
select * from Node |
|||
where nodeid = \''.$nodeid.'\' |
|||
and serverid = \''.$serverid.'\''; |
|||
|
|||
return $this->mapper('Node', $this->_db->query($sql), 'item');*/ |
|||
|
|||
$this->_sql = ' |
|||
select * from node |
|||
where |
|||
nodeid = :nodeid |
|||
and serverid = :serverid'; |
|||
|
|||
$this->prepare( |
|||
'Node', |
|||
array( |
|||
'nodeid' => $nodeid, |
|||
'serverid' => $serverid |
|||
) |
|||
); |
|||
|
|||
return $this->run('Node', 'item'); |
|||
} |
|||
} |
|||
@ -0,0 +1,235 @@ |
|||
<?php |
|||
|
|||
namespace modl; |
|||
|
|||
class Postn extends ModlModel { |
|||
public $session; |
|||
|
|||
public $jid; // Where the post is comming from (jid or server)
|
|||
public $node; // microblog or pubsub
|
|||
public $nodeid; // the ID if the item
|
|||
|
|||
public $aname; // author name
|
|||
public $aid; // author id
|
|||
|
|||
public $title; //
|
|||
public $content; // the content
|
|||
|
|||
public $commentplace; |
|||
|
|||
public $published; //
|
|||
public $updated; //
|
|||
public $delay; //
|
|||
|
|||
public $tags; |
|||
|
|||
public $lat; |
|||
public $lon; |
|||
|
|||
public $links; |
|||
|
|||
public $privacy; |
|||
|
|||
public $hash; |
|||
|
|||
public function __construct() { |
|||
$this->hash = md5(openssl_random_pseudo_bytes(5)); |
|||
|
|||
$this->_struct = "
|
|||
{ |
|||
'session' : |
|||
{'type':'string', 'size':128, 'mandatory':true, 'key':true }, |
|||
'jid' : |
|||
{'type':'string', 'size':128, 'mandatory':true, 'key':true }, |
|||
'node' : |
|||
{'type':'string', 'size':128, 'mandatory':true, 'key':true }, |
|||
'nodeid' : |
|||
{'type':'string', 'size':256, 'mandatory':true, 'key':true }, |
|||
'aname' : |
|||
{'type':'string', 'size':128 }, |
|||
'aid' : |
|||
{'type':'string', 'size':128 }, |
|||
'title' : |
|||
{'type':'text' }, |
|||
'content' : |
|||
{'type':'text' }, |
|||
'commentplace' : |
|||
{'type':'string', 'size':128 }, |
|||
|
|||
'published' : |
|||
{'type':'date' }, |
|||
'updated' : |
|||
{'type':'date' }, |
|||
'delay' : |
|||
{'type':'date' }, |
|||
|
|||
'lat' : |
|||
{'type':'string', 'size':128 }, |
|||
'lon' : |
|||
{'type':'string', 'size':128 }, |
|||
|
|||
'links' : |
|||
{'type':'text' }, |
|||
'tags' : |
|||
{'type':'text' }, |
|||
'hash' : |
|||
{'type':'string', 'size':128 } |
|||
}";
|
|||
} |
|||
|
|||
public function set($item, $from, $delay = false, $node = false) { |
|||
$user = new \User(); |
|||
$this->session = $user->getLogin(); |
|||
|
|||
if($item->item) |
|||
$entry = $item->item; |
|||
else |
|||
$entry = $item; |
|||
|
|||
$this->jid = $from; |
|||
|
|||
if($node) |
|||
$this->node = $node; |
|||
else |
|||
$this->node = (string)$item->attributes()->node; |
|||
|
|||
$this->nodeid = (string)$entry->attributes()->id; |
|||
|
|||
if($entry->entry->id) |
|||
$this->nodeid = (string)$entry->entry->id; |
|||
|
|||
if($entry->entry->author->name) |
|||
$this->aname = (string)$entry->entry->author->name; |
|||
if($entry->entry->author->uri) |
|||
$this->aid = substr((string)$entry->entry->author->uri, 5); |
|||
|
|||
// Non standard support
|
|||
if($entry->entry->source && $entry->entry->source->author->name) |
|||
$this->aname = (string)$entry->entry->source->author->name; |
|||
if($entry->entry->source && $entry->entry->source->author->uri) |
|||
$this->aid = substr((string)$entry->entry->source->author->uri, 5); |
|||
|
|||
$this->title = (string)$entry->entry->title; |
|||
|
|||
// Content
|
|||
if($entry->entry->summary && (string)$entry->entry->summary != '') |
|||
$summary = '<p class="summary">'.(string)$entry->entry->summary.'</p>'; |
|||
else |
|||
$summary = ''; |
|||
|
|||
if($entry->entry && $entry->entry->content) { |
|||
if((string)$entry->entry->content->attributes()->type == 'text') |
|||
$content = (string)$entry->entry->content; |
|||
elseif( |
|||
(string)$entry->entry->content->attributes()->type == ('html' || 'xhtml') |
|||
//&& $entry->entry->content->html
|
|||
//&& $entry->entry->content->html->body
|
|||
) { |
|||
$content = (string)$entry->entry->content/*->html->body*/->asXML(); |
|||
} else |
|||
$content = (string)$entry->entry->content; |
|||
} elseif($summary == '') |
|||
$content = t('Content not found'); |
|||
else |
|||
$content = ''; |
|||
|
|||
$content = $summary.$content; |
|||
|
|||
if($entry->entry->published) |
|||
$this->published = date(DATE_ISO8601, strtotime((string)$entry->entry->published)); |
|||
else |
|||
$this->published = date(DATE_ISO8601); |
|||
|
|||
if($entry->entry->updated) |
|||
$this->updated = date(DATE_ISO8601, strtotime((string)$entry->entry->updated)); |
|||
else |
|||
$this->updated = date(DATE_ISO8601); |
|||
|
|||
if($delay) |
|||
$this->delay = $delay; |
|||
|
|||
$contentimg = $this->setAttachements($entry->entry->link); |
|||
|
|||
if($entry->entry->category) { |
|||
$this->tags = array(); |
|||
foreach($entry->entry->category as $cat) |
|||
array_push($this->tags, (string)$cat->attributes()->term); |
|||
} |
|||
|
|||
if(!empty($this->tags)) |
|||
$this->tags = serialize($this->tags); |
|||
|
|||
if($contentimg != '') |
|||
$content .= '<br />'.$contentimg; |
|||
|
|||
if(!isset($this->commentplace)) |
|||
$this->commentplace = $this->jid; |
|||
|
|||
$this->content = trim($content); |
|||
|
|||
if($entry->entry->geoloc) { |
|||
if($entry->entry->geoloc->lat != 0) |
|||
$this->lat = (string)$entry->entry->geoloc->lat; |
|||
if($entry->entry->geoloc->lon != 0) |
|||
$this->lon = (string)$entry->entry->geoloc->lon; |
|||
} |
|||
} |
|||
|
|||
private function setAttachements($links) { |
|||
$contentimg = ''; |
|||
|
|||
$l = array(); |
|||
|
|||
foreach($links as $attachment) { |
|||
$enc = array(); |
|||
$enc = (array)$attachment->attributes(); |
|||
$enc = $enc['@attributes']; |
|||
array_push($l, $enc); |
|||
|
|||
|
|||
if((string)$attachment->attributes()->title == 'comments') { |
|||
$substr = explode('?',substr((string)$attachment->attributes()->href, 5)); |
|||
$this->commentplace = reset($substr); |
|||
} |
|||
} |
|||
|
|||
if(!empty($l)) |
|||
$this->links = serialize($l); |
|||
|
|||
return $contentimg; |
|||
} |
|||
|
|||
public function getPlace() { |
|||
if(isset($this->lat, $this->lon) && $this->lat != '' && $this->lon != '') { |
|||
return true; |
|||
} |
|||
else |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
class ContactPostn extends Postn { |
|||
public $jid; |
|||
|
|||
public $fn; |
|||
public $name; |
|||
|
|||
public $privacy; |
|||
|
|||
public $phototype; |
|||
public $photobin; |
|||
|
|||
public $nickname; |
|||
|
|||
function getContact() { |
|||
$c = new Contact(); |
|||
$c->jid = $this->jid; |
|||
$c->fn = $this->fn; |
|||
$c->name = $this->name; |
|||
$c->nickname = $this->nickname; |
|||
$c->phototype = $this->phototype; |
|||
$c->photobin = $this->photobin; |
|||
|
|||
return $c; |
|||
} |
|||
} |
|||
@ -0,0 +1,573 @@ |
|||
<?php |
|||
|
|||
namespace modl; |
|||
|
|||
class PostnDAO extends ModlSQL { |
|||
/*function create() { |
|||
$sql = ' |
|||
drop table if exists Postn'; |
|||
|
|||
$this->_db->query($sql); |
|||
|
|||
$sql = ' |
|||
create table if not exists Postn ( |
|||
`id` binary(40) NOT NULL, |
|||
`key` varchar(128) DEFAULT NULL, |
|||
|
|||
`from` varchar(128) DEFAULT NULL, |
|||
`node` varchar(128) DEFAULT NULL, |
|||
`nodeid` varchar(128) DEFAULT NULL, |
|||
|
|||
`aname` varchar(128) DEFAULT NULL, |
|||
`aid` varchar(128) DEFAULT NULL, |
|||
|
|||
`title` varchar(128) DEFAULT NULL, |
|||
`content` text, |
|||
|
|||
`commentplace`varchar(128) DEFAULT NULL, |
|||
|
|||
`published`datetime DEFAULT NULL, |
|||
`updated` datetime DEFAULT NULL, |
|||
`delay` datetime DEFAULT NULL, |
|||
|
|||
`lat` varchar(128) DEFAULT NULL, |
|||
`lon` varchar(128) DEFAULT NULL, |
|||
|
|||
`links` text, |
|||
`tags` text, |
|||
|
|||
`hash` varchar(128) DEFAULT NULL, |
|||
PRIMARY KEY (id) |
|||
) CHARACTER SET utf8 COLLATE utf8_bin;'; |
|||
|
|||
$this->_db->query($sql); |
|||
}*/ |
|||
|
|||
function set(Postn $post) { |
|||
$this->_sql = ' |
|||
update postn |
|||
set aname = :aname, |
|||
aid = :aid, |
|||
|
|||
title = :title, |
|||
content = :content, |
|||
|
|||
commentplace = :commentplace, |
|||
|
|||
published = :published, |
|||
updated = :updated, |
|||
delay = :delay, |
|||
|
|||
lat = :lat, |
|||
lon = :lon, |
|||
|
|||
links = :links, |
|||
tags = :tags, |
|||
|
|||
hash = :hash |
|||
|
|||
where session = :session |
|||
and jid = :jid |
|||
and node = :node |
|||
and nodeid = :nodeid'; |
|||
|
|||
$this->prepare( |
|||
'Postn', |
|||
array( |
|||
'aname' => $post->aname, |
|||
'aid' => $post->aid, |
|||
|
|||
'title' => $post->title, |
|||
'content' => $post->content, |
|||
|
|||
'commentplace' => $post->commentplace, |
|||
|
|||
'published' => $post->published, |
|||
'updated' => $post->updated, |
|||
'delay' => $post->delay, |
|||
|
|||
'lat' => $post->lat, |
|||
'lon' => $post->lon, |
|||
|
|||
'links' => $post->links, |
|||
'tags' => $post->tags, |
|||
|
|||
'hash' => $post->hash, |
|||
|
|||
'session' => $post->session, |
|||
'jid' => $post->jid, |
|||
'node' => $post->node, |
|||
'nodeid' => $post->nodeid |
|||
) |
|||
); |
|||
|
|||
$this->run('Postn'); |
|||
|
|||
if(!$this->_effective) { |
|||
$this->_sql =' |
|||
insert into postn |
|||
( |
|||
session, |
|||
|
|||
jid, |
|||
node, |
|||
nodeid, |
|||
|
|||
aname, |
|||
aid, |
|||
|
|||
title, |
|||
content, |
|||
|
|||
commentplace, |
|||
|
|||
published, |
|||
updated, |
|||
delay, |
|||
|
|||
lat, |
|||
lon, |
|||
|
|||
links, |
|||
tags, |
|||
|
|||
hash) |
|||
values( |
|||
:session, |
|||
|
|||
:jid, |
|||
:node, |
|||
:nodeid, |
|||
|
|||
:aname, |
|||
:aid, |
|||
|
|||
:title, |
|||
:content, |
|||
|
|||
:commentplace, |
|||
|
|||
:published, |
|||
:updated, |
|||
:delay, |
|||
|
|||
:lat, |
|||
:lon, |
|||
|
|||
:links, |
|||
:tags, |
|||
|
|||
:hash |
|||
)'; |
|||
|
|||
$this->prepare( |
|||
'Postn', |
|||
array( |
|||
'aname' => $post->aname, |
|||
'aid' => $post->aid, |
|||
|
|||
'title' => $post->title, |
|||
'content' => $post->content, |
|||
|
|||
'commentplace' => $post->commentplace, |
|||
|
|||
'published' => $post->published, |
|||
'updated' => $post->updated, |
|||
'delay' => $post->delay, |
|||
|
|||
'lat' => $post->lat, |
|||
'lon' => $post->lon, |
|||
|
|||
'links' => $post->links, |
|||
'tags' => $post->tags, |
|||
|
|||
'hash' => $post->hash, |
|||
|
|||
'session' => $post->session, |
|||
'jid' => $post->jid, |
|||
'node' => $post->node, |
|||
'nodeid' => $post->nodeid |
|||
) |
|||
); |
|||
|
|||
$this->run('Postn'); |
|||
} |
|||
/* |
|||
$request = $this->prepare(' |
|||
update Postn |
|||
set `aname` = ?, |
|||
`aid` = ?, |
|||
|
|||
`title` = ?, |
|||
`content` = ?, |
|||
|
|||
`commentplace` = ?, |
|||
|
|||
`published` = ?, |
|||
`updated` = ?, |
|||
`delay` = ?, |
|||
|
|||
`lat` = ?, |
|||
`lon` = ?, |
|||
|
|||
`links` = ?, |
|||
`tags` = ?, |
|||
|
|||
`hash` = ? |
|||
|
|||
where `id` = ?', $post); |
|||
|
|||
|
|||
where `key` = ? |
|||
and `from` = ? |
|||
and `node` = ? |
|||
and `nodeid` = ?', $post); |
|||
$hash = sha1( |
|||
$post->key. |
|||
$post->from. |
|||
$post->node. |
|||
$post->nodeid |
|||
); |
|||
|
|||
$request->bind_param( |
|||
'ssssssssssssss', |
|||
$post->aname, |
|||
$post->aid, |
|||
$post->title, |
|||
$post->content, |
|||
$post->commentplace, |
|||
$post->published, |
|||
$post->updated, |
|||
$post->delay, |
|||
$post->lat, |
|||
$post->lon, |
|||
$post->links, |
|||
$post->tags, |
|||
$post->hash, |
|||
$hash |
|||
); |
|||
|
|||
$result = $request->execute(); |
|||
|
|||
if($this->_db->affected_rows == 0) { |
|||
$request = $this->prepare(' |
|||
insert into Postn |
|||
( |
|||
`id`, |
|||
`key`, |
|||
|
|||
`from`, |
|||
`node`, |
|||
`nodeid`, |
|||
|
|||
`aname`, |
|||
`aid`, |
|||
|
|||
`title`, |
|||
`content`, |
|||
|
|||
`commentplace`, |
|||
|
|||
`published`, |
|||
`updated`, |
|||
`delay`, |
|||
|
|||
`lat`, |
|||
`lon`, |
|||
|
|||
`links`, |
|||
`tags`, |
|||
|
|||
`hash`) |
|||
values( |
|||
?,?,?,?,?, |
|||
?,?,?,?,?, |
|||
?,?,?,?,?, |
|||
?,?,? |
|||
)', $post); |
|||
|
|||
$request->bind_param( |
|||
'ssssssssssssssssss', |
|||
$hash, |
|||
$post->key, |
|||
$post->from, |
|||
$post->node, |
|||
$post->nodeid, |
|||
$post->aname, |
|||
$post->aid, |
|||
$post->title, |
|||
$post->content, |
|||
$post->commentplace, |
|||
$post->published, |
|||
$post->updated, |
|||
$post->delay, |
|||
$post->lat, |
|||
$post->lon, |
|||
$post->links, |
|||
$post->tags, |
|||
$post->hash |
|||
); |
|||
$request->execute(); |
|||
} |
|||
|
|||
$request->close();*/ |
|||
} |
|||
|
|||
function delete($nodeid) { |
|||
$this->_sql = ' |
|||
delete from postn |
|||
where nodeid = :nodeid'; |
|||
|
|||
$this->prepare( |
|||
'Postn', |
|||
array( |
|||
'nodeid' => $nodeid |
|||
) |
|||
); |
|||
|
|||
return $this->run('Message'); |
|||
|
|||
/*$from = $this->_db->real_escape_string($from); |
|||
$nodeid = $this->_db->real_escape_string($nodeid); |
|||
$sql = ' |
|||
delete from Postn |
|||
where nodeid=\''.$nodeid.'\''; |
|||
return $this->_db->query($sql); */ |
|||
} |
|||
|
|||
function getNode($from, $node, $limitf = false, $limitr = false) { |
|||
/*$sql = ' |
|||
select *, Postn.aid, Privacy.value as privacy from Postn |
|||
left outer join Contact on Postn.aid = Contact.jid |
|||
left outer join Privacy on Postn.nodeid = Privacy.key |
|||
where Postn.key = \''.$this->_user->getLogin().'\' |
|||
and Postn.from = \''.$from.'\' |
|||
and Postn.node = \''.$node.'\' |
|||
order by Postn.published desc'; |
|||
|
|||
if($limitr) |
|||
$sql = $sql.' limit '.$limitf.','.$limitr; |
|||
|
|||
return $this->mapper('ContactPostn', $this->_db->query($sql));*/ |
|||
|
|||
$this->_sql = ' |
|||
select *, postn.aid, privacy.value as privacy from postn |
|||
left outer join contact on postn.aid = contact.jid |
|||
left outer join privacy on postn.nodeid = privacy.pkey |
|||
where postn.session = :session |
|||
and postn.jid = :jid |
|||
and postn.node = :node |
|||
order by postn.published desc'; |
|||
|
|||
if($limitr) |
|||
$this->_sql = $this->_sql.' limit '.$limitr.' offset '.$limitf; |
|||
|
|||
$this->prepare( |
|||
'Postn', |
|||
array( |
|||
'session' => $this->_user, |
|||
'jid' => $from, |
|||
'node' => $node |
|||
) |
|||
); |
|||
|
|||
return $this->run('ContactPostn'); |
|||
} |
|||
|
|||
function getFeed($limitf = false, $limitr = false) { |
|||
/* |
|||
* $sql = ' |
|||
select *, Postn.aid as jid, Privacy.value as privacy from Postn |
|||
left outer join Contact on Postn.aid = Contact.jid |
|||
left outer join Privacy on Postn.nodeid = Privacy.key |
|||
where Postn.key = \''.$this->_user->getLogin().'\' |
|||
and Postn.node like \'urn:xmpp:microblog:0\' |
|||
and (Postn.from in (select RosterLink.jid from RosterLink where RosterLink.key = \''.$this->_user->getLogin().'\') |
|||
or Postn.from = \''.$this->_user->getLogin().'\') |
|||
order by Postn.published desc'; |
|||
|
|||
if($limitr) |
|||
$sql = $sql.' limit '.$limitf.','.$limitr; |
|||
|
|||
return $this->mapper('ContactPostn', $this->_db->query($sql)); |
|||
*/ |
|||
|
|||
$this->_sql = ' |
|||
select *, postn.aid as jid, privacy.value as privacy from postn |
|||
left outer join contact on postn.aid = contact.jid |
|||
left outer join privacy on postn.nodeid = privacy.pkey |
|||
where postn.session = :session |
|||
and postn.node like \'urn:xmpp:microblog:0\' |
|||
and (postn.jid in (select rosterlink.jid from rosterlink where rosterlink.session = :session) |
|||
or postn.jid = :session) |
|||
order by postn.published desc'; |
|||
|
|||
if($limitr) |
|||
$this->_sql = $this->_sql.' limit '.$limitr.' offset '.$limitf; |
|||
|
|||
$this->prepare( |
|||
'Postn', |
|||
array( |
|||
'session' => $this->_user |
|||
) |
|||
); |
|||
|
|||
return $this->run('ContactPostn'); |
|||
} |
|||
|
|||
function getNews($limitf = false, $limitr = false) { |
|||
/*$sql = ' |
|||
select *, Postn.aid as jid from Postn |
|||
left outer join Contact on Postn.aid = Contact.jid |
|||
left outer join Subscription on |
|||
Postn.key = Subscription.jid and |
|||
Postn.from = Subscription.server and |
|||
Postn.node = Subscription.node |
|||
where Postn.key = \''.$this->_user->getLogin().'\' |
|||
and Postn.node not like \'urn:xmpp:microblog:0:comments/%\' |
|||
and Postn.node not like \'urn:xmpp:inbox\' |
|||
and subscription is not null |
|||
order by Postn.published desc'; |
|||
|
|||
if($limitr) |
|||
$sql = $sql.' limit '.$limitf.','.$limitr; |
|||
|
|||
return $this->mapper('ContactPostn', $this->_db->query($sql));*/ |
|||
|
|||
$this->_sql = ' |
|||
select *, postn.aid as jid from postn |
|||
left outer join contact on postn.aid = contact.jid |
|||
left outer join subscription on |
|||
postn.session = subscription.jid and |
|||
postn.jid = subscription.server and |
|||
postn.node = subscription.node |
|||
where postn.session = :session |
|||
and postn.node not like \'urn:xmpp:microblog:0:comments/%\' |
|||
and postn.node not like \'urn:xmpp:inbox\' |
|||
and subscription is not null |
|||
order by postn.published desc'; |
|||
|
|||
if($limitr) |
|||
$this->_sql = $this->_sql.' limit '.$limitr.' offset '.$limitf; |
|||
|
|||
$this->prepare( |
|||
'Postn', |
|||
array( |
|||
'session' => $this->_user |
|||
) |
|||
); |
|||
|
|||
return $this->run('ContactPostn'); |
|||
} |
|||
|
|||
|
|||
function getPublic($jid, $node) { |
|||
/*if($node != false) |
|||
$n = 'and Postn.node = \''.$node.'\' '; |
|||
|
|||
$sql = ' |
|||
select *, Postn.aid as jid, Privacy.value as privacy from Postn |
|||
left outer join Contact on Postn.aid = Contact.jid |
|||
join Privacy on Postn.nodeid = Privacy.key |
|||
where Postn.from = \''.$jid.'\' |
|||
'.$n.' |
|||
and Postn.node not like \'urn:xmpp:microblog:0:comments/%\' |
|||
and Privacy.value = 1 |
|||
group by nodeid |
|||
order by Postn.published desc |
|||
limit 0, 20'; |
|||
|
|||
return $this->mapper('ContactPostn', $this->_db->query($sql)); */ |
|||
|
|||
/*if($node != false) |
|||
$n = 'and Postn.node = :node '; |
|||
else |
|||
$n = '';*/ |
|||
|
|||
/*$this->_sql = ' |
|||
select *, postn.aid as jid, privacy.value as privacy from postn |
|||
left outer join contact on postn.aid = contact.jid |
|||
join privacy on postn.nodeid = privacy.pkey |
|||
where postn.jid = :jid |
|||
and Postn.node = :node |
|||
and postn.node not like \'urn:xmpp:microblog:0:comments/%\' |
|||
and privacy.value = 1 |
|||
group by nodeid |
|||
order by postn.published desc';*/ |
|||
//limit 0, 20';
|
|||
|
|||
$this->_sql = ' |
|||
select *, postn.aid, privacy.value as privacy from postn |
|||
left outer join contact on postn.aid = contact.jid |
|||
left outer join privacy on postn.nodeid = privacy.pkey |
|||
where postn.jid = :jid |
|||
and postn.session = :jid |
|||
and postn.node = :node |
|||
and privacy.value = 1 |
|||
order by postn.published desc'; |
|||
|
|||
$this->prepare( |
|||
'Postn', |
|||
array( |
|||
'jid' => $jid, |
|||
'node' => $node |
|||
) |
|||
); |
|||
|
|||
return $this->run('ContactPostn'); |
|||
} |
|||
|
|||
function getComments($posts) { |
|||
$commentsid = ''; |
|||
if(is_array($posts)) { |
|||
$i = 0; |
|||
foreach($posts as $post) { |
|||
if($i == 0) |
|||
$commentsid = "'urn:xmpp:microblog:0:comments/".$post->nodeid."'"; |
|||
else |
|||
$commentsid .= ",'urn:xmpp:microblog:0:comments/".$post->nodeid."'"; |
|||
$i++; |
|||
} |
|||
} else { |
|||
$commentsid = "'urn:xmpp:microblog:0:comments/".$posts->nodeid."'"; |
|||
} |
|||
|
|||
// We request all the comments relative to our messages
|
|||
$this->_sql = ' |
|||
select *, postn.aid as jid from postn |
|||
left outer join contact on postn.aid = contact.jid |
|||
where postn.session = :session |
|||
and postn.node in ('.$commentsid.') |
|||
order by postn.published'; |
|||
|
|||
$this->prepare( |
|||
'Postn', |
|||
array( |
|||
'session' => $this->_user |
|||
) |
|||
); |
|||
|
|||
return $this->run('ContactPostn'); |
|||
} |
|||
|
|||
function clearPost() { |
|||
/*$sql = ' |
|||
delete from Postn |
|||
where Postn.key=\''.$this->_user->getLogin().'\''; |
|||
|
|||
return $this->_db->query($sql);*/ |
|||
|
|||
$this->_sql = ' |
|||
delete from postn |
|||
where session = :session'; |
|||
|
|||
$this->prepare( |
|||
'Postn', |
|||
array( |
|||
'session' => $this->_user |
|||
) |
|||
); |
|||
|
|||
return $this->run('Postn'); |
|||
} |
|||
} |
|||
@ -0,0 +1,139 @@ |
|||
<?php |
|||
|
|||
namespace modl; |
|||
|
|||
class Presence extends ModlModel { |
|||
protected $id; |
|||
|
|||
protected $session; |
|||
protected $jid; |
|||
|
|||
// General presence informations
|
|||
protected $ressource; |
|||
protected $value; |
|||
protected $priority; |
|||
protected $status; |
|||
|
|||
// Client Informations
|
|||
protected $node; |
|||
protected $ver; |
|||
|
|||
// Delay - XEP 0203
|
|||
protected $delay; |
|||
|
|||
// Last Activity - XEP 0256
|
|||
protected $last; |
|||
|
|||
public function __construct() { |
|||
$this->_struct = "
|
|||
{ |
|||
'id' : |
|||
{'type':'string', 'size':128, 'mandatory':true }, |
|||
'session' : |
|||
{'type':'string', 'size':128, 'mandatory':true, 'key':true }, |
|||
'jid' : |
|||
{'type':'string', 'size':128, 'mandatory':true, 'key':true }, |
|||
'ressource' : |
|||
{'type':'string', 'size':128, 'key':true }, |
|||
'value' : |
|||
{'type':'int', 'size':11, 'mandatory':true }, |
|||
'priority' : |
|||
{'type':'int', 'size':11 }, |
|||
'status' : |
|||
{'type':'text'}, |
|||
'node' : |
|||
{'type':'string', 'size':128 }, |
|||
'ver' : |
|||
{'type':'string', 'size':128 }, |
|||
'delay' : |
|||
{'type':'date'}, |
|||
'last' : |
|||
{'type':'int', 'size':11 } |
|||
}";
|
|||
} |
|||
|
|||
// Validation
|
|||
/* |
|||
public $_validates = array( |
|||
'presence_of' => array('key', 'jid', 'presence') |
|||
); |
|||
*/ |
|||
public function setPresence($stanza) { |
|||
$jid = explode('/',(string)$stanza->attributes()->from); |
|||
|
|||
if($stanza->attributes()->to) |
|||
$to = current(explode('/',(string)$stanza->attributes()->to)); |
|||
else |
|||
$to = $jid[0]; |
|||
|
|||
$this->session = $to; |
|||
$this->jid = $jid[0]; |
|||
if(isset($jid[1])) |
|||
$this->ressource = $jid[1]; |
|||
else |
|||
$this->ressource = 'default'; |
|||
|
|||
$this->status = (string)$stanza->status; |
|||
|
|||
if($stanza->c) { |
|||
$this->node = (string)$stanza->c->attributes()->node; |
|||
$this->ver = (string)$stanza->c->attributes()->ver; |
|||
} |
|||
|
|||
if($stanza->priority) |
|||
$this->priority = (string)$stanza->priority; |
|||
|
|||
if((string)$stanza->attributes()->type == 'error') { |
|||
$this->value = 6; |
|||
} elseif((string)$stanza->attributes()->type == 'unavailable') { |
|||
$this->value = 5; |
|||
} elseif((string)$stanza->show == 'away') { |
|||
$this->value = 2; |
|||
} elseif((string)$stanza->show == 'dnd') { |
|||
$this->value = 3; |
|||
} elseif((string)$stanza->show == 'xa') { |
|||
$this->value = 4; |
|||
} else { |
|||
$this->value = 1; |
|||
} |
|||
|
|||
if($stanza->delay) { |
|||
$this->delay = |
|||
date( |
|||
'Y-m-d H:i:s', |
|||
strtotime( |
|||
(string)$stanza->delay->attributes()->stamp |
|||
) |
|||
) |
|||
; |
|||
} |
|||
|
|||
if($stanza->query) { |
|||
$this->last = (int)$stanza->query->attributes()->seconds; |
|||
} |
|||
} |
|||
|
|||
public function getPresence() { |
|||
$txt = array( |
|||
1 => 'online', |
|||
2 => 'away', |
|||
3 => 'dnd', |
|||
4 => 'xa', |
|||
5 => 'offline', |
|||
6 => 'server_error' |
|||
); |
|||
|
|||
$arr = array(); |
|||
$arr['jid'] = $this->jid; |
|||
$arr['ressource'] = $this->ressource; |
|||
$arr['presence'] = $this->value; |
|||
$arr['presence_txt'] = $txt[$this->value]; |
|||
$arr['priority'] = $this->priority; |
|||
$arr['status'] = $this->status; |
|||
$arr['node'] = $this->node; |
|||
$arr['ver'] = $this->ver; |
|||
|
|||
return $arr; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,146 @@ |
|||
<?php |
|||
|
|||
namespace modl; |
|||
|
|||
class PresenceDAO extends ModlSQL { |
|||
function __construct() { |
|||
parent::__construct(); |
|||
} |
|||
|
|||
function set(Presence $presence) { |
|||
$id = sha1( |
|||
$presence->session. |
|||
$presence->jid. |
|||
$presence->ressource |
|||
); |
|||
|
|||
$this->_sql = ' |
|||
update presence |
|||
set value = :value, |
|||
priority = :priority, |
|||
status = :status, |
|||
node = :node, |
|||
ver = :ver, |
|||
delay = :delay, |
|||
last = :last |
|||
where id = :id'; |
|||
|
|||
$this->prepare( |
|||
'Presence', |
|||
array( |
|||
'value' => $presence->value, |
|||
'priority' => $presence->priority, |
|||
'status' => $presence->status, |
|||
'node' => $presence->node, |
|||
'ver' => $presence->ver, |
|||
'delay' => $presence->delay, |
|||
'last' => $presence->last, |
|||
'id' => $id |
|||
) |
|||
); |
|||
|
|||
$this->run('Presence'); |
|||
|
|||
if(!$this->_effective) { |
|||
$this->_sql = ' |
|||
insert into presence |
|||
(id,session, jid, ressource, value, priority, status, node, ver, delay,last) |
|||
values( |
|||
:id, |
|||
:session, |
|||
:jid, |
|||
:ressource, |
|||
:value, |
|||
:priority, |
|||
:status, |
|||
:node, |
|||
:ver, |
|||
:delay, |
|||
:last)'; |
|||
|
|||
$this->prepare( |
|||
'Presence', |
|||
array( |
|||
'id' => $id, |
|||
'session' => $presence->session, |
|||
'jid' => $presence->jid, |
|||
'ressource' => $presence->ressource, |
|||
'value' => $presence->value, |
|||
'priority' => $presence->priority, |
|||
'status' => $presence->status, |
|||
'node' => $presence->node, |
|||
'ver' => $presence->ver, |
|||
'delay' => $presence->delay, |
|||
'last' => $presence->last |
|||
) |
|||
); |
|||
|
|||
$this->run('Presence'); |
|||
} |
|||
} |
|||
|
|||
function getAll() { |
|||
$this->_sql = ' |
|||
select * from presence; |
|||
'; |
|||
|
|||
$this->prepare('Presence'); |
|||
return $this->run('Presence'); |
|||
} |
|||
|
|||
|
|||
function getPresence($jid, $ressource) { |
|||
$this->_sql = ' |
|||
select * from presence |
|||
where |
|||
session = :session |
|||
and jid = :jid |
|||
and ressource = :ressource'; |
|||
|
|||
$this->prepare( |
|||
'Presence', |
|||
array( |
|||
'session' => $this->_user, |
|||
'jid' => $jid, |
|||
'ressource' => $ressource |
|||
) |
|||
); |
|||
|
|||
return $this->run('Presence', 'item'); |
|||
} |
|||
|
|||
|
|||
function getJid($jid) { |
|||
$this->_sql = ' |
|||
select * from presence |
|||
where |
|||
session = :session |
|||
and jid = :jid'; |
|||
|
|||
$this->prepare( |
|||
'Presence', |
|||
array( |
|||
'session' => $this->_user, |
|||
'jid' => $jid |
|||
) |
|||
); |
|||
|
|||
return $this->run('Presence'); |
|||
} |
|||
|
|||
function clearPresence($session) { |
|||
$this->_sql = ' |
|||
delete from presence |
|||
where |
|||
session = :session'; |
|||
|
|||
$this->prepare( |
|||
'Presence', |
|||
array( |
|||
'session' => $session |
|||
) |
|||
); |
|||
|
|||
return $this->run('Presence'); |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
<?php |
|||
|
|||
namespace modl; |
|||
|
|||
class Privacy extends ModlModel { |
|||
public $pkey; |
|||
public $value; |
|||
protected $hash; |
|||
|
|||
public function __construct() { |
|||
$this->_struct = "
|
|||
{ |
|||
'pkey' : |
|||
{'type':'string', 'size':256, 'mandatory':true, 'key':true }, |
|||
'value' : |
|||
{'type':'int', 'size':4, 'mandatory':true }, |
|||
'hash' : |
|||
{'type':'string', 'size':128, 'mandatory':true } |
|||
}";
|
|||
} |
|||
|
|||
static function set($key, $value) { |
|||
$p = new Privacy(); |
|||
$p->pkey = $key; |
|||
$p->value = $value; |
|||
$p->hash = md5(openssl_random_pseudo_bytes(5)); |
|||
|
|||
$pd = new PrivacyDAO(); |
|||
$pd->set($p); |
|||
} |
|||
} |
|||
@ -0,0 +1,58 @@ |
|||
<?php |
|||
|
|||
namespace modl; |
|||
|
|||
class PrivacyDAO extends ModlSQL { |
|||
function set(Privacy $p) { |
|||
$this->_sql = ' |
|||
update privacy |
|||
set value = :value, |
|||
hash = :hash |
|||
where pkey = :pkey'; |
|||
|
|||
$this->prepare( |
|||
'Privacy', |
|||
array( |
|||
'pkey' => $p->pkey, |
|||
'value' => $p->value, |
|||
'hash' => $p->hash |
|||
) |
|||
); |
|||
|
|||
$this->run('Privacy'); |
|||
|
|||
if(!$this->_effective) { |
|||
$this->_sql = ' |
|||
insert into privacy |
|||
(pkey, value, hash) |
|||
values (:pkey,:value,:hash)'; |
|||
|
|||
$this->prepare( |
|||
'Privacy', |
|||
array( |
|||
'pkey' => $p->pkey, |
|||
'value' => $p->value, |
|||
'hash' => $p->hash |
|||
) |
|||
); |
|||
|
|||
$this->run('Privacy'); |
|||
} |
|||
} |
|||
|
|||
function get($key) { |
|||
$this->_sql = ' |
|||
select * from privacy |
|||
where |
|||
pkey = :pkey'; |
|||
|
|||
$this->prepare( |
|||
'Privacy', |
|||
array( |
|||
'pkey' => $key |
|||
) |
|||
); |
|||
|
|||
return $this->run('Privacy', 'item'); |
|||
} |
|||
} |
|||
@ -0,0 +1,53 @@ |
|||
<?php |
|||
|
|||
namespace modl; |
|||
|
|||
class RosterLink extends ModlModel { |
|||
public $session; |
|||
public $jid; |
|||
|
|||
public $rostername; |
|||
public $rosterask; |
|||
public $rostersubscription; |
|||
|
|||
public $realname; |
|||
|
|||
public $groupname; |
|||
|
|||
public $chaton; |
|||
|
|||
public function __construct() { |
|||
$this->_struct = "
|
|||
{ |
|||
'session' : |
|||
{'type':'string', 'size':128, 'mandatory':true, 'key':true }, |
|||
'jid' : |
|||
{'type':'string', 'size':128, 'mandatory':true, 'key':true }, |
|||
'rostername' : |
|||
{'type':'string', 'size':128 }, |
|||
'rosterask' : |
|||
{'type':'string', 'size':128 }, |
|||
'rostersubscription' : |
|||
{'type':'string', 'size':128 }, |
|||
'realname' : |
|||
{'type':'string', 'size':128 }, |
|||
'groupname' : |
|||
{'type':'string', 'size':128 }, |
|||
'chaton' : |
|||
{'type':'int', 'size':11 } |
|||
}";
|
|||
} |
|||
|
|||
|
|||
function set($stanza) { |
|||
$this->jid = (string)$stanza->attributes()->jid; |
|||
|
|||
if(isset($stanza->attributes()->name) && (string)$stanza->attributes()->name != '') |
|||
$this->rostername = (string)$stanza->attributes()->name; |
|||
else |
|||
$this->rostername = (string)$stanza->attributes()->jid; |
|||
$this->rosterask = (string)$stanza->attributes()->ask; |
|||
$this->rostersubscription = (string)$stanza->attributes()->subscription; |
|||
$this->groupname = (string)$stanza->group; |
|||
} |
|||
} |
|||
@ -0,0 +1,395 @@ |
|||
<?php |
|||
|
|||
namespace modl; |
|||
|
|||
class RosterLinkDAO extends ModlSQL { |
|||
/*function create() { |
|||
$sql = ' |
|||
drop table if exists `RosterLink`'; |
|||
|
|||
$this->_db->query($sql); |
|||
|
|||
$sql = ' |
|||
create table if not exists `RosterLink` ( |
|||
`id` int(11) NOT NULL AUTO_INCREMENT, |
|||
`key` varchar(128) DEFAULT NULL, |
|||
`jid` varchar(128) DEFAULT NULL, |
|||
`rostername` varchar(128) DEFAULT NULL, |
|||
`rosterask` varchar(128) DEFAULT NULL, |
|||
`rostersubscription` varchar(128) DEFAULT NULL, |
|||
`realname` varchar(128) DEFAULT NULL, |
|||
`group` varchar(128) DEFAULT NULL, |
|||
`chaton` int(11) DEFAULT NULL, |
|||
PRIMARY KEY (`id`) |
|||
) CHARACTER SET utf8 COLLATE utf8_bin'; |
|||
$this->_db->query($sql); |
|||
}*/ |
|||
|
|||
function set(RosterLink $r) { |
|||
/*$r->key = $this->_user->getLogin(); |
|||
$this->keepTransaction(' |
|||
insert into RosterLink |
|||
(RosterLink.key, |
|||
jid, |
|||
rostername, |
|||
rosterask, |
|||
rostersubscription, |
|||
realname, |
|||
RosterLink.group, |
|||
chaton) |
|||
values (?,?,?,?,?,?,?,?)', |
|||
array( |
|||
'sssssssi', |
|||
$r->key, |
|||
$r->jid, |
|||
$r->rostername, |
|||
$r->rosterask, |
|||
$r->rostersubscription, |
|||
$r->realname, |
|||
$r->group, |
|||
$r->chaton), |
|||
$r |
|||
);*/ |
|||
|
|||
$this->_sql = ' |
|||
insert into rosterlink |
|||
( |
|||
session, |
|||
jid, |
|||
rostername, |
|||
rosterask, |
|||
rostersubscription, |
|||
realname, |
|||
groupname, |
|||
chaton) |
|||
values ( |
|||
:session, |
|||
:jid, |
|||
:rostername, |
|||
:rosterask, |
|||
:rostersubscription, |
|||
:realname, |
|||
:groupname, |
|||
:chaton |
|||
)'; |
|||
|
|||
$this->prepare( |
|||
'RosterLink', |
|||
array( |
|||
'session' => $this->_user, |
|||
'jid' => $r->jid, |
|||
'rostername' => $r->rostername, |
|||
'rosterask' => $r->rosterask, |
|||
'rostersubscription' => $r->rostersubscription, |
|||
'realname' => $r->realname, |
|||
'groupname' => $r->groupname, |
|||
'chaton' => $r->chaton |
|||
) |
|||
); |
|||
|
|||
return $this->run('RosterLink'); |
|||
} |
|||
|
|||
function update(RosterLink $r) { |
|||
$this->_sql = ' |
|||
update rosterlink |
|||
set rostername = :rostername, |
|||
rosterask = :rosterask, |
|||
rostersubscription = :rostersubscription, |
|||
realname = :realname, |
|||
groupname = :groupname, |
|||
chaton = :chaton |
|||
where session = :session |
|||
and jid = :jid'; |
|||
|
|||
$this->prepare( |
|||
'RosterLink', |
|||
array( |
|||
'session' => $this->_user, |
|||
'jid' => $r->jid, |
|||
'rostername' => $r->rostername, |
|||
'rosterask' => $r->rosterask, |
|||
'rostersubscription' => $r->rostersubscription, |
|||
'realname' => $r->realname, |
|||
'groupname' => $r->groupname, |
|||
'chaton' => $r->chaton |
|||
) |
|||
); |
|||
|
|||
return $this->run('RosterLink'); |
|||
/*$r->key = $this->_user->getLogin(); |
|||
$this->keepTransaction(' |
|||
update RosterLink |
|||
set rostername = ?, |
|||
rosterask = ?, |
|||
rostersubscription = ?, |
|||
realname = ?, |
|||
RosterLink.group = ?, |
|||
chaton = ? |
|||
where RosterLink.key = ? |
|||
and jid = ?', |
|||
array( |
|||
'sssssiss', |
|||
$r->rostername, |
|||
$r->rosterask, |
|||
$r->rostersubscription, |
|||
$r->realname, |
|||
$r->group, |
|||
$r->chaton, |
|||
$r->key, |
|||
$r->jid), |
|||
$r |
|||
); */ |
|||
} |
|||
|
|||
function setNow(RosterLink $r) { |
|||
/*$request = $this->prepare(' |
|||
update RosterLink |
|||
set rostername = ?, |
|||
rosterask = ?, |
|||
rostersubscription = ?, |
|||
realname = ?, |
|||
RosterLink.group = ?, |
|||
chaton = ? |
|||
where RosterLink.key = ? |
|||
and jid = ?', $r); |
|||
|
|||
$request->bind_param( |
|||
'sssssiss', |
|||
$r->rostername, |
|||
$r->rosterask, |
|||
$r->rostersubscription, |
|||
$r->realname, |
|||
$r->group, |
|||
$r->chaton, |
|||
$r->key, |
|||
$r->jid); |
|||
|
|||
$request->execute(); |
|||
|
|||
if($this->_db->affected_rows == 0) { |
|||
$request = $this->prepare(' |
|||
insert into RosterLink |
|||
(RosterLink.key, |
|||
jid, |
|||
rostername, |
|||
rosterask, |
|||
rostersubscription, |
|||
realname, |
|||
RosterLink.group, |
|||
chaton) |
|||
values (?,?,?,?,?,?,?,?)', $r); |
|||
$request->bind_param( |
|||
'sssssssi', |
|||
$r->key, |
|||
$r->jid, |
|||
$r->rostername, |
|||
$r->rosterask, |
|||
$r->rostersubscription, |
|||
$r->realname, |
|||
$r->group, |
|||
$r->chaton); |
|||
|
|||
$request->execute(); |
|||
} |
|||
|
|||
$request->close();*/ |
|||
$this->update($r); |
|||
|
|||
if(!$this->_effective) |
|||
$this->set($r); |
|||
} |
|||
|
|||
function setChat($jid, $chaton) { |
|||
/*$sql = 'update RosterLink set chaton ='.$chaton.' |
|||
where RosterLink.key=\''.$this->_user->getLogin().'\' |
|||
and jid=\''.$this->_db->real_escape_string($jid).'\''; |
|||
$this->_db->query($sql); */ |
|||
|
|||
$this->_sql = ' |
|||
update rosterlink |
|||
set chaton = :chaton |
|||
where session = :session |
|||
and jid = :jid'; |
|||
|
|||
$this->prepare( |
|||
'RosterLink', |
|||
array( |
|||
'session' => $this->_user, |
|||
'jid' => $jid, |
|||
'chaton' => $chaton |
|||
) |
|||
); |
|||
|
|||
return $this->run('RosterLink'); |
|||
} |
|||
|
|||
function get($jid) { |
|||
/*$key = $this->_user->getLogin(); |
|||
|
|||
$sql = ' |
|||
select * |
|||
from RosterLink |
|||
where RosterLink.key=\''.$key.'\' |
|||
and jid =\''.$jid.'\''; |
|||
|
|||
return $this->mapper('RosterLink', $this->_db->query($sql), 'item');*/ |
|||
|
|||
$this->_sql = ' |
|||
select * |
|||
from rosterlink |
|||
where session=:session |
|||
and jid = :jid'; |
|||
|
|||
$this->prepare( |
|||
'RosterLink', |
|||
array( |
|||
'session' => $this->_user, |
|||
'jid' => $jid, |
|||
) |
|||
); |
|||
|
|||
return $this->run('RosterLink', 'item'); |
|||
} |
|||
|
|||
function getGroups() { |
|||
/*$key = $this->_user->getLogin(); |
|||
|
|||
$sql = ' |
|||
select RosterLink.group |
|||
from RosterLink |
|||
where RosterLink.key=\''.$this->_db->real_escape_string($key).'\' |
|||
group by RosterLink.group'; |
|||
|
|||
$arr = array(); |
|||
|
|||
$resultset = $this->_db->query($sql); |
|||
while($r = $resultset->fetch_array( MYSQL_NUM)) |
|||
array_push($arr, $r[0]); |
|||
|
|||
return $arr;*/ |
|||
|
|||
$this->_sql = ' |
|||
select groupname |
|||
from rosterlink |
|||
where session = :session |
|||
group by groupname'; |
|||
|
|||
$this->prepare( |
|||
'RosterLink', |
|||
array( |
|||
'session' => $this->_user |
|||
) |
|||
); |
|||
|
|||
$results = $this->run('RosterLink'); |
|||
$arr = array(); |
|||
|
|||
foreach($results as $r) |
|||
array_push($arr, $r->groupname); |
|||
|
|||
return $arr; |
|||
} |
|||
|
|||
function getRoster($to = null) { |
|||
if($to != null) |
|||
$session = $to; |
|||
else |
|||
$session = $this->_user; |
|||
/* |
|||
$sql = ' |
|||
select * |
|||
from RosterLink |
|||
where RosterLink.key=\''.$this->_db->real_escape_string($key).'\''; |
|||
|
|||
return $this->mapper('RosterLink', $this->_db->query($sql));*/ |
|||
|
|||
$this->_sql = ' |
|||
select * |
|||
from rosterlink |
|||
where session=:session'; |
|||
|
|||
$this->prepare( |
|||
'RosterLink', |
|||
array( |
|||
'session' => $session |
|||
) |
|||
); |
|||
|
|||
return $this->run('RosterLink'); |
|||
} |
|||
|
|||
function getChats() { |
|||
//$key = $this->_user->getLogin();
|
|||
|
|||
/*$sql = ' |
|||
select * |
|||
from RosterLink |
|||
where RosterLink.key=\''.$this->_db->real_escape_string($key).'\' |
|||
and chaton > 0'; |
|||
|
|||
return $this->mapper('RosterLink', $this->_db->query($sql));*/ |
|||
|
|||
$this->_sql = ' |
|||
select * |
|||
from rosterlink |
|||
where session=:session |
|||
and chaton > 0'; |
|||
|
|||
$this->prepare( |
|||
'RosterLink', |
|||
array( |
|||
'session' => $this->_user |
|||
) |
|||
); |
|||
|
|||
return $this->run('RosterLink'); |
|||
} |
|||
|
|||
function clearRosterLink() { |
|||
/* |
|||
$sql = ' |
|||
delete from RosterLink |
|||
where RosterLink.key=\''.$this->_user->getLogin().'\''; |
|||
|
|||
return $this->_db->query($sql); |
|||
*/ |
|||
$this->_sql = ' |
|||
delete from rosterlink |
|||
where session = :session'; |
|||
|
|||
$this->prepare( |
|||
'RosterLink', |
|||
array( |
|||
'session' => $this->_user |
|||
) |
|||
); |
|||
|
|||
return $this->run('RosterLink'); |
|||
} |
|||
|
|||
function delete($jid) { |
|||
/* |
|||
$sql = ' |
|||
delete from RosterLink |
|||
where RosterLink.key=\''.$this->_user->getLogin().'\' |
|||
and jid=\''.$this->_db->real_escape_string($jid).'\''; |
|||
|
|||
return $this->_db->query($sql); |
|||
*/ |
|||
$this->_sql = ' |
|||
delete from rosterlink |
|||
where session = :session |
|||
and jid = :jid'; |
|||
|
|||
$this->prepare( |
|||
'RosterLink', |
|||
array( |
|||
'session' => $this->_user, |
|||
'jid' => $jid |
|||
) |
|||
); |
|||
|
|||
return $this->run('RosterLink'); |
|||
} |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
<?php |
|||
|
|||
namespace modl; |
|||
|
|||
class Session extends ModlModel { |
|||
public $name; |
|||
public $value; |
|||
public $session; |
|||
public $container; |
|||
public $timestamp; |
|||
|
|||
public function __construct() { |
|||
$this->_struct = "
|
|||
{ |
|||
'name' : |
|||
{'type':'string', 'size':128, 'mandatory':true, 'key':true }, |
|||
'value' : |
|||
{'type':'text', 'mandatory':true }, |
|||
'session' : |
|||
{'type':'string', 'size':128, 'mandatory':true, 'key':true }, |
|||
'container' : |
|||
{'type':'string', 'size':128, 'mandatory':true, 'key':true }, |
|||
'timestamp' : |
|||
{'type':'date' } |
|||
}";
|
|||
} |
|||
} |
|||
@ -0,0 +1,190 @@ |
|||
<?php |
|||
|
|||
namespace modl; |
|||
|
|||
class SessionDAO extends ModlSQL { |
|||
/*function create() { |
|||
$sql = ' |
|||
drop table if exists `SessionVar`'; |
|||
|
|||
$this->_db->query($sql); |
|||
|
|||
$sql = ' |
|||
create table if not exists `SessionVar` ( |
|||
`id` binary(40) NOT NULL, |
|||
`name` varchar(128) DEFAULT NULL, |
|||
`value` text, |
|||
`session` varchar(128) DEFAULT NULL, |
|||
`container` varchar(128) DEFAULT NULL, |
|||
`timestamp` int(11) DEFAULT NULL, |
|||
PRIMARY KEY (`id`) |
|||
) CHARACTER SET utf8 COLLATE utf8_bin'; |
|||
$this->_db->query($sql); |
|||
}*/ |
|||
|
|||
function set($session, $container, $name, $value, $timestamp) { |
|||
$timestamp = date(DATE_ISO8601, $timestamp); |
|||
/* |
|||
$request = $this->prepare(' |
|||
update SessionVar |
|||
set value = ?, |
|||
timestamp = ? |
|||
where id = ?', $session); |
|||
|
|||
$hash = sha1( |
|||
$session. |
|||
$container. |
|||
$name |
|||
) ; |
|||
|
|||
where session = ? |
|||
and container = ? |
|||
and name = ?', $session); |
|||
|
|||
if(!$request) |
|||
return $request; |
|||
|
|||
$request->bind_param( |
|||
'sis', |
|||
$value, |
|||
$timestamp, |
|||
$hash |
|||
); |
|||
|
|||
$request->execute(); |
|||
|
|||
if($this->_db->affected_rows == 0) { |
|||
$request = $this->_db->prepare(' |
|||
insert into SessionVar |
|||
(id, name, value, session, container, timestamp) |
|||
values (?,?,?,?,?,?)'); |
|||
|
|||
$request->bind_param( |
|||
'sssssi', |
|||
$hash, |
|||
$name, |
|||
$value, |
|||
$session, |
|||
$container, |
|||
$timestamp); |
|||
|
|||
$request->execute(); |
|||
} |
|||
|
|||
$request->close();*/ |
|||
|
|||
$this->_sql = ' |
|||
update session |
|||
set value = :value, |
|||
timestamp = :timestamp |
|||
where session = :session |
|||
and container = :container |
|||
and name = :name'; |
|||
|
|||
$this->prepare( |
|||
'Session', |
|||
array( |
|||
'session' => $session, |
|||
'container' => $container, |
|||
'name' => $name, |
|||
'value' => $value, |
|||
'timestamp' => $timestamp |
|||
) |
|||
); |
|||
|
|||
$this->run('Session'); |
|||
|
|||
if(!$this->_effective) { |
|||
$this->_sql = ' |
|||
insert into session |
|||
(name, value, session, container, timestamp) |
|||
values (:name, :value, :session, :container, :timestamp)'; |
|||
|
|||
$this->prepare( |
|||
'Session', |
|||
array( |
|||
'session' => $session, |
|||
'container' => $container, |
|||
'name' => $name, |
|||
'value' => $value, |
|||
'timestamp' => $timestamp |
|||
) |
|||
); |
|||
|
|||
return $this->run('Session'); |
|||
} |
|||
} |
|||
|
|||
function get($session, $container, $name) { |
|||
$this->_sql = ' |
|||
select * from session |
|||
where |
|||
session = :session |
|||
and container = :container |
|||
and name = :name'; |
|||
|
|||
$this->prepare( |
|||
'Session', |
|||
array( |
|||
'session' => $session, |
|||
'container' => $container, |
|||
'name' => $name |
|||
) |
|||
); |
|||
|
|||
return $this->run('Session', 'item'); |
|||
} |
|||
|
|||
function delete($session, $container, $name) { |
|||
/*$sql = ' |
|||
delete from SessionVar |
|||
where session = \''.$session.'\' |
|||
and container = \''.$container.'\' |
|||
and name = \''.$name.'\''; |
|||
|
|||
return $this->_db->query($sql); */ |
|||
|
|||
$this->_sql = ' |
|||
delete from session |
|||
where |
|||
session = :session |
|||
and container = :container |
|||
and name = :name'; |
|||
|
|||
$this->prepare( |
|||
'Session', |
|||
array( |
|||
'session' => $session, |
|||
'container' => $container, |
|||
'name' => $name |
|||
) |
|||
); |
|||
|
|||
return $this->run('Session'); |
|||
} |
|||
|
|||
function deleteContainer($session, $container) { |
|||
/*$sql = ' |
|||
delete from SessionVar |
|||
where session = \''.$session.'\' |
|||
and container = \''.$container.'\''; |
|||
|
|||
return $this->_db->query($sql);*/ |
|||
|
|||
$this->_sql = ' |
|||
delete from session |
|||
where |
|||
session = :session |
|||
and container = :container'; |
|||
|
|||
$this->prepare( |
|||
'Session', |
|||
array( |
|||
'session' => $session, |
|||
'container' => $container, |
|||
) |
|||
); |
|||
|
|||
return $this->run('Session'); |
|||
} |
|||
} |
|||
@ -0,0 +1,49 @@ |
|||
<?php |
|||
|
|||
namespace modl; |
|||
|
|||
class Subscription extends ModlModel { |
|||
public $jid; |
|||
public $server; |
|||
public $node; |
|||
public $subscription; |
|||
public $subid; |
|||
public $title; |
|||
public $timestamp; |
|||
|
|||
|
|||
public function __construct() { |
|||
$this->_struct = "
|
|||
{ |
|||
'jid' : |
|||
{'type':'string', 'size':128, 'mandatory':true, 'key':true }, |
|||
'server' : |
|||
{'type':'string', 'size':128, 'mandatory':true, 'key':true }, |
|||
'node' : |
|||
{'type':'string', 'size':128, 'mandatory':true, 'key':true }, |
|||
'subscription' : |
|||
{'type':'string', 'size':128, 'mandatory':true }, |
|||
'subid' : |
|||
{'type':'string', 'size':128 }, |
|||
'title' : |
|||
{'type':'string', 'size':128 }, |
|||
'timestamp' : |
|||
{'type':'date' } |
|||
}";
|
|||
} |
|||
|
|||
|
|||
|
|||
function set($jid, $server, $node, $s) { |
|||
$this->jid = $jid; |
|||
$this->server = $server; |
|||
$this->node = $node; |
|||
$this->jid = (string)$s->attributes()->jid; |
|||
$this->subscription = (string)$s->attributes()->subscription; |
|||
$this->subid = (string)$s->attributes()->subid; |
|||
$this->timestamp = date('Y-m-d H:i:s', rand(1111111111, 8888888888)); |
|||
|
|||
if($this->subid = '') |
|||
$this->subid = 'default'; |
|||
} |
|||
} |
|||
@ -0,0 +1,222 @@ |
|||
<?php |
|||
|
|||
namespace modl; |
|||
|
|||
class SubscriptionDAO extends ModlSQL { |
|||
/*function create() { |
|||
$sql = ' |
|||
drop table if exists `Subscription`'; |
|||
|
|||
$this->_db->query($sql); |
|||
|
|||
$sql = ' |
|||
create table if not exists `Subscription` ( |
|||
`jid` varchar(128) DEFAULT NULL, |
|||
`server` varchar(128) DEFAULT NULL, |
|||
`node` varchar(128) DEFAULT NULL, |
|||
`subscription` varchar(128) DEFAULT NULL, |
|||
`subid` varchar(128) DEFAULT NULL, |
|||
`timestamp` datetime DEFAULT NULL |
|||
) CHARACTER SET utf8 COLLATE utf8_bin'; |
|||
$this->_db->query($sql); |
|||
}*/ |
|||
|
|||
function set(Subscription $s) { |
|||
$this->_sql = ' |
|||
update subscription |
|||
set subscription = :subscription, |
|||
timestamp = :timestamp, |
|||
subid = :subid |
|||
where jid = :jid |
|||
and server = :server |
|||
and node = :node'; |
|||
|
|||
$this->prepare( |
|||
'Subscription', |
|||
array( |
|||
'subscription' => $s->subscription, |
|||
'timestamp' => $s->timestamp, |
|||
'jid' => $s->jid, |
|||
'server'=> $s->server, |
|||
'node' => $s->node, |
|||
'subid' => $s->subid |
|||
) |
|||
); |
|||
|
|||
$this->run('Subscription'); |
|||
|
|||
if(!$this->_effective) { |
|||
$this->_sql = ' |
|||
insert into Subscription |
|||
(jid, server, node, subscription, subid, timestamp) |
|||
values (:jid, :server, :node, :subscription, :subid, :timestamp)'; |
|||
|
|||
$this->prepare( |
|||
'Subscription', |
|||
array( |
|||
'subscription' => $s->subscription, |
|||
'timestamp' => $s->timestamp, |
|||
'jid' => $s->jid, |
|||
'server'=> $s->server, |
|||
'node' =>$s->node, |
|||
'subid' => $s->subid |
|||
) |
|||
); |
|||
|
|||
$this->run('Subscription'); |
|||
} |
|||
/* |
|||
$request = $this->_db->prepare(' |
|||
update Subscription |
|||
set subscription = ?, |
|||
timestamp = ? |
|||
where jid = ? |
|||
and server = ? |
|||
and node = ? |
|||
and subid = ?'); |
|||
|
|||
$request->bind_param( |
|||
'ssssss', |
|||
$s->subscription, |
|||
$s->timestamp, |
|||
$s->jid, |
|||
$s->server, |
|||
$s->node, |
|||
$s->subid); |
|||
|
|||
$request->execute(); |
|||
|
|||
if($this->_db->affected_rows == 0) { |
|||
$request = $this->_db->prepare(' |
|||
insert into Subscription |
|||
(jid, server, node, subscription, subid, timestamp) |
|||
values (?,?,?,?,?,?)'); |
|||
|
|||
$request->bind_param( |
|||
'ssssss', |
|||
$s->jid, |
|||
$s->server, |
|||
$s->node, |
|||
$s->subscription, |
|||
$s->subid, |
|||
$s->timestamp); |
|||
|
|||
$request->execute(); |
|||
} |
|||
|
|||
$request->close(); |
|||
*/ |
|||
} |
|||
|
|||
function get($server, $node) { |
|||
/*$sql = ' |
|||
select * from Subscription |
|||
where jid = \''.$this->_user.'\' |
|||
and server = \''.$server.'\' |
|||
and node = \''.$node.'\''; |
|||
|
|||
return $this->mapper('Subscription', $this->_db->query($sql)); */ |
|||
|
|||
$this->_sql = ' |
|||
select * from subscription |
|||
where jid = :jid |
|||
and server = :server |
|||
and node = :node'; |
|||
|
|||
$this->prepare( |
|||
'Subscription', |
|||
array( |
|||
'jid' => $this->_user, |
|||
'server' => $server, |
|||
'node' => $node |
|||
) |
|||
); |
|||
|
|||
return $this->run('Subscription'); |
|||
} |
|||
|
|||
function getSubscribed() { |
|||
/* |
|||
$sql = ' |
|||
select * from Subscription |
|||
where jid = \''.$this->_user.'\' |
|||
group by server, node'; |
|||
|
|||
return $this->mapper('Subscription', $this->_db->query($sql)); |
|||
*/ |
|||
|
|||
$this->_sql = ' |
|||
select jid, server, node, subscription from subscription |
|||
where jid = :jid |
|||
group by server, node, jid, subscription'; |
|||
|
|||
$this->prepare( |
|||
'Subscription', |
|||
array( |
|||
'jid' => $this->_user |
|||
) |
|||
); |
|||
|
|||
return $this->run('Subscription'); |
|||
} |
|||
|
|||
function deleteNode($server, $node) { |
|||
/*$sql = ' |
|||
delete from Subscription |
|||
where jid = \''.$this->_user.'\' |
|||
and server = \''.$server.'\' |
|||
and node = \''.$node.'\''; |
|||
|
|||
return $this->_db->query($sql); |
|||
* */ |
|||
|
|||
$this->_sql = ' |
|||
delete from subscription |
|||
where jid = :jid |
|||
and server = :server |
|||
and node = :node'; |
|||
|
|||
$this->prepare( |
|||
'Subscription', |
|||
array( |
|||
'jid' => $this->_user, |
|||
'server' => $server, |
|||
'node' => $node |
|||
) |
|||
); |
|||
|
|||
return $this->run('Subscription'); |
|||
} |
|||
|
|||
function deleteNodeSubid($server, $node, $subid) { |
|||
/* |
|||
$sql = ' |
|||
delete from Subscription |
|||
where jid = \''.$this->_user.'\' |
|||
and server = \''.$server.'\' |
|||
and node = \''.$node.'\' |
|||
and subid= \''.$subid.'\''; |
|||
|
|||
return $this->_db->query($sql); |
|||
*/ |
|||
|
|||
$this->_sql = ' |
|||
delete from subscription |
|||
where jid = :jid |
|||
and server = :server |
|||
and node = :node |
|||
and subid = :subid'; |
|||
|
|||
$this->prepare( |
|||
'Subscription', |
|||
array( |
|||
'jid' => $this->_user, |
|||
'server' => $server, |
|||
'node' => $node, |
|||
'subid' => $subid, |
|||
) |
|||
); |
|||
|
|||
return $this->run('Subscription'); |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue