Browse Source

- Add an "Explore" page to discover new contacts

- New table "RosterLink" which split the Roster informations from the Contact table
- Update all the widgets for the new DB structure
- Clean lot of old stuffs in the code
- New time detection for the server time
- Improve page loading speed by reducing number of DB request and request answer size
pull/16/head
Jaussoin Timothée 13 years ago
parent
commit
4d63c14339
  1. 36
      image.php
  2. 8
      loader.php
  3. 10
      system/Cache.php
  4. 43
      system/Controller/ControllerMain.php
  5. 103
      system/Datas/Attachment.php
  6. 88
      system/Datas/Contact.php
  7. 9
      system/Datas/Post.php
  8. 31
      system/Datas/RosterLink.php
  9. 797
      system/Jabber.php
  10. 55
      system/Utils.php
  11. 22
      system/Widget/WidgetCommon.php
  12. 63
      system/Widget/widgets/Chat/Chat.php
  13. 8
      system/Widget/widgets/Chat/chat.css
  14. 1
      system/Widget/widgets/ContactCard/ContactCard.php
  15. 33
      system/Widget/widgets/ContactInfo/ContactInfo.php
  16. 4
      system/Widget/widgets/ContactSummary/ContactSummary.php
  17. 55
      system/Widget/widgets/Explore/Explore.php
  18. 44
      system/Widget/widgets/Explore/explore.css
  19. 10
      system/Widget/widgets/Feed/Feed.php
  20. 4
      system/Widget/widgets/Login/Login.php
  21. 4
      system/Widget/widgets/Logout/Logout.php
  22. 78
      system/Widget/widgets/Notifs/Notifs.php
  23. 1
      system/Widget/widgets/Profile/Profile.php
  24. 3
      system/Widget/widgets/ProfileData/ProfileData.php
  25. 29
      system/Widget/widgets/Roster/Roster.php
  26. 2
      system/Widget/widgets/Syndication/Syndication.php
  27. 16
      system/Widget/widgets/Vcard/Vcard.php
  28. 1
      system/Widget/widgets/Wall/Wall.php
  29. 1
      themes/movim/config.tpl
  30. 25
      themes/movim/explore.tpl
  31. 1
      themes/movim/friend.tpl

36
image.php

@ -36,6 +36,16 @@ function display_image($hash, $type) {
header('Expires: ' . gmdate('D, d M Y H:i:s', time()+24*60*60) . ' GMT');
}
function display_default() {
ob_clean();
ob_start();
$content = file_get_contents('themes/movim/img/default.svg');
display_image($hash, "image/svg+xml");
echo $content;
exit;
}
if (!function_exists('getallheaders')) {
function getallheaders() {
foreach($_SERVER as $key=>$value) {
@ -51,7 +61,7 @@ if (!function_exists('getallheaders')) {
}
// We load the avatar from the database and we display it
if(isset($_GET['c'])) {
//if(isset($_GET['c'])) {
$hash = md5($_GET['c'].$_GET['size']);
$headers = getallheaders();
@ -61,31 +71,25 @@ if(isset($_GET['c'])) {
{
header('HTTP/1.1 304 Not Modified');
exit;
} elseif($_GET['c'] == 'default') {
ob_clean();
ob_start();
$content = file_get_contents('themes/movim/img/default.svg');
display_image($hash, "image/svg+xml");
echo $content;
exit;
}
} elseif($_GET['c'] == '' || $_GET['c'] == 'default') {
display_default();
}
else {
$user = new User();
if($user->isLogged())
$where = array('key' => $user->getLogin(), 'jid' => $_GET['c']);
$where = array('jid' => $_GET['c']);
else
$where = array('jid' => $_GET['c']);
$c = new Contact();
$query = Contact::query()->select()
->where($where);
->where($where);
$contact = Contact::run_query($query);
if($contact[0]->getData('phototype') != '' &&
if(isset($contact[0]) &&
$contact[0]->getData('phototype') != '' &&
$contact[0]->getData('photobin') != '' &&
$contact[0]->getData('phototype') != 'f' &&
$contact[0]->getData('photobin') != 'f') {
@ -137,9 +141,11 @@ if(isset($_GET['c'])) {
display_image($hash, $contact[0]->getData('phototype'));
echo base64_decode($contact[0]->getData('photobin'));
}
} else {
display_default();
}
}
}
//}
// Closing db (dirty...)
global $sdb;

8
loader.php

@ -24,14 +24,13 @@ require_once(LIB_PATH . "Datas/Contact.php");
require_once(LIB_PATH . "Datas/Presence.php");
require_once(LIB_PATH . "Datas/Message.php");
require_once(LIB_PATH . "Datas/Post.php");
require_once(LIB_PATH . "Datas/Attachment.php");
require_once(LIB_PATH . "Datas/RosterLink.php");
require_once(LIB_PATH . "Session.php");
require_once(LIB_PATH . "Utils.php");
require_once(LIB_PATH . "Cache.php");
require_once(LIB_PATH . "Conf.php");
require_once(LIB_PATH . "Event.php");
//require_once(LIB_PATH . "Jabber.php");
require_once(LIB_PATH . "Logger.php");
require_once(LIB_PATH . "MovimException.php");
require_once(LIB_PATH . "RPC.php");
@ -56,10 +55,9 @@ define('JAXL_LOG_EVENT', true);
define('JAXL_LOG_LEVEL', 4);
define('JAXL_LOG_ROTATE', false);
//define('JAXL_BASE_PATH', LIB_PATH . 'Jaxl/');
// We set the default timezone to the server timezone
date_default_timezone_set('UTC');
date_default_timezone_set(getLocalTimezone());
$useragent = $_SERVER['HTTP_USER_AGENT'];

10
system/Cache.php

@ -35,11 +35,6 @@ class Cache
// Saving the user's login.
$user = new User();
$this->login = $user->getLogin();
//$this->db = new DatajarEngineWrapper(Conf::getServerConfElement('storageConnection'));
//$var = new CacheVar();
//$this->db->create($var);
}
function __destruct()
@ -113,9 +108,6 @@ class Cache
$md5 = md5($data);
$time = time();
//$var = new CacheVar();
//$this->db->load($var, array('key' => $cache_key));
$var = new CacheVar();
/*$success = $var->load(array(
@ -140,8 +132,6 @@ class Cache
$var->timestamp = $time;
$var->run_query($var->query()->save($var));
//$this->db->save($var);
}
/**

43
system/Controller/ControllerMain.php

@ -24,6 +24,8 @@ class ControllerMain extends ControllerBase
{
parent::__construct();
global $sdb;
$c = new RosterLink();
$sdb->create($c);
$c = new Contact();
$sdb->create($c);
$p = new Presence();
@ -46,6 +48,7 @@ class ControllerMain extends ControllerBase
} else {
$this->page->setTitle(t('%s - Welcome to Movim', APP_TITLE));
$this->page->menuAddLink(t('Home'), '?q=mainPage', true);
$this->page->menuAddLink(t('Explore'), '?q=explore');
$this->page->menuAddLink(t('Profile'), '?q=profile');
$this->page->menuAddLink(t('Configuration'), '?q=config');
$this->page->menuAddLink(t('Help'), '?q=help');
@ -63,7 +66,11 @@ class ControllerMain extends ControllerBase
$user = new User();
$query = Contact::query()
->where(array('key' => $user->getLogin(), 'jid' => $_GET['f']));
->where(
array(
'jid' => $_GET['f']
)
);
$contact = Contact::run_query($query);
if(isset($contact[0]))
@ -102,6 +109,7 @@ class ControllerMain extends ControllerBase
} else {
$this->page->setTitle(t('%s - Configuration', APP_TITLE));
$this->page->menuAddLink(t('Home'), '?q=mainPage');
$this->page->menuAddLink(t('Explore'), '?q=explore');
$this->page->menuAddLink(t('Profile'), '?q=profile');
$this->page->menuAddLink(t('Configuration'), '?q=config', true);
$this->page->menuAddLink(t('Help'), '?q=help');
@ -123,6 +131,7 @@ class ControllerMain extends ControllerBase
} else {
$this->page->setTitle(t('%s - Profile', APP_TITLE));
$this->page->menuAddLink(t('Home'), '?q=mainPage');
$this->page->menuAddLink(t('Explore'), '?q=explore');
$this->page->menuAddLink(t('Profile'), '?q=profile', true);
$this->page->menuAddLink(t('Configuration'), '?q=config');
$this->page->menuAddLink(t('Help'), '?q=help');
@ -201,16 +210,35 @@ class ControllerMain extends ControllerBase
*/
function feed()
{
/*$this->page->setTitle(t('%s - Login to Movim', APP_TITLE));
$this->page->menuAddLink(t('Home'), '?q=mainPage', true);
$content = new TplPageBuilder($user);
$this->page->setContent($content->build('login.tpl'));
echo $this->page->build('page.tpl');*/
$content = new TplPageBuilder();
echo $content->build('feed.tpl');
}
/**
* Explore the XMPP network
*/
function explore()
{
$user = new User();
$this->page->setTitle(t('%s - Explore', APP_TITLE));
if(!$user->isLogged()) {
$this->login();
} else {
$this->page->menuAddLink(t('Home'), '?q=mainPage');
$this->page->menuAddLink(t('Explore'), '?q=explore', true);
$this->page->menuAddLink(t('Profile'), '?q=profile');
$this->page->menuAddLink(t('Configuration'), '?q=config');
$this->page->menuAddLink(t('Help'), '?q=help');
$this->page->menuAddLink(t('Logout'), '?q=disconnect');
}
$content = new TplPageBuilder($user);
$this->page->setContent($content->build('explore.tpl'));
echo $this->page->build('page.tpl');
}
/*
* Show help page
@ -226,6 +254,7 @@ class ControllerMain extends ControllerBase
$this->login();
} else {
$this->page->menuAddLink(t('Home'), '?q=mainPage');
$this->page->menuAddLink(t('Explore'), '?q=explore');
$this->page->menuAddLink(t('Profile'), '?q=profile');
$this->page->menuAddLink(t('Configuration'), '?q=config');
$this->page->menuAddLink(t('Help'), '?q=help', true);

103
system/Datas/Attachment.php

@ -1,103 +0,0 @@
<?php
class Attachment extends DatajarBase {
protected $key;
protected $jid;
protected $node;
protected $attachmentid;
protected $title;
protected $type;
protected $length;
protected $link;
protected $thumb;
protected function type_init() {
$this->key = DatajarType::varchar(128);
$this->jid = DatajarType::varchar(128);
$this->node = DatajarType::varchar(128);
$this->attachmentid = DatajarType::varchar(128);
$this->title = DatajarType::varchar(128);
$this->type = DatajarType::varchar(128);
$this->length = DatajarType::int();
$this->link = DatajarType::varchar(128);
$this->thumb = DatajarType::varchar(128);
}
public function getData($data) {
return $this->$data->getval();
}
}
class AttachmentHandler {
static function getAttachment($key, $node) {
global $sdb;
$attachment = $sdb->select('Attachment', array('key' => $key, 'node'=> $node));
if($attachment != false)
return $attachment;
else
return false;
}
function saveAttachment($array, $jid, $from, $node) {
global $sdb;
$attachment = $sdb->select('Attachment', array(
'key' => $jid,
'jid' => $from,
'node'=> $node,
'attachmentid' => sha1($array['@attributes']['href'].
$array['@attributes']['title'].
$array['@attributes']['length'])
));
if($attachment == false) {
$attachment = new Attachment();
$attachment->key = $jid;
$attachment->jid = $from;
$attachment->node = $node;
$attachment->attachmentid = sha1($array['@attributes']['href'].
$array['@attributes']['title'].
$array['@attributes']['length']);
$attachment->title = $array['@attributes']['title'];
$attachment->type = $array['@attributes']['type'];
$attachment->length = $array['@attributes']['length'];
$attachment->link = $array['@attributes']['href'];
$attachment->thumb = $array['link'][0]['@attributes']['href'];
$sdb->save($attachment);
} else {
global $sdb;
$attachment = new Attachment();
$sdb->load($attachment, array(
'key' => $jid,
'jid' => $from,
'node'=> $node,
'attachmentid' => sha1($array['@attributes']['href'].
$array['@attributes']['title'].
$array['@attributes']['length'])
));
$attachment->title = $array['@attributes']['title'];
$attachment->type = $array['@attributes']['type'];
$attachment->length = $array['@attributes']['length'];
$attachment->link = $array['@attributes']['href'];
$attachment->thumb = $array['link'][0]['@attributes']['href'];
$sdb->save($attachment);
}
}
}

88
system/Datas/Contact.php

@ -1,7 +1,7 @@
<?php
class Contact extends DatajarBase {
public $key;
//public $key;
public $jid;
public $fn;
@ -12,19 +12,11 @@ class Contact extends DatajarBase {
public $gender;
public $marital;
public $group;
public $rostername;
public $rosterask;
public $rostersubscription;
public $phototype;
public $photobin;
public $desc;
public $vcardreceived;
public $chaton;
public $public;
// User Mood (contain serialized array) - XEP 0107
@ -62,7 +54,6 @@ class Contact extends DatajarBase {
protected function type_init() {
$this->key = DatajarType::varchar(128);
$this->jid = DatajarType::varchar(128);
$this->fn = DatajarType::varchar(128);
@ -73,19 +64,11 @@ class Contact extends DatajarBase {
$this->gender = DatajarType::varchar(1);
$this->marital = DatajarType::varchar(20);
$this->group = DatajarType::varchar(128);
$this->rostername = DatajarType::varchar(128);
$this->rosterask = DatajarType::varchar(128);
$this->rostersubscription = DatajarType::varchar(128);
$this->phototype = DatajarType::varchar(128);
$this->photobin = DatajarType::text();
$this->desc = DatajarType::text();
$this->vcardreceived = DatajarType::int();
$this->chaton = DatajarType::int();
$this->public = DatajarType::int();
$this->mood = DatajarType::varchar(128);
@ -114,46 +97,6 @@ class Contact extends DatajarBase {
$this->locuri = DatajarType::varchar(128);
$this->loctimestamp = DatajarType::datetime();
}
public function setContact($array) {
$user = new User();
$date = strtotime($array['vCard']['BDAY']);
if($date != false)
$this->date->setval(date('Y-m-d', $date));
$this->key->setval($user->getLogin());
$this->jid->setval(($array['@attributes']['from'] != NULL) ? $array['@attributes']['from'] : $user->getLogin());
$this->name->setval($array['vCard']['NICKNAME']);
$this->fn->setval($array['vCard']['FN']);
$this->url->setval($array['vCard']['URL']);
$this->gender->setval($array['vCard']['X-GENDER']);
$this->marital->setval($array['vCard']['MARITAL']['STATUS']);
if($this->rostersubscription->getval() == false)
$this->rostersubscription->setval('none');
$this->phototype->setval($array['vCard']['PHOTO']['TYPE']);
$this->photobin->setval($array['vCard']['PHOTO']['BINVAL']);
$this->desc->setval($array['vCard']['DESC']);
$this->vcardreceived->setval(1);
$this->public->setval(0);
}
public function setContactRosterItem($item) {
$user = new User();
$this->key->setval($user->getLogin());
$this->jid->setval($item['@attributes']['jid']);
$this->rostername->setval($item['@attributes']['name']);
$this->rosterask->setval($item['@attributes']['ask']);
$this->rostersubscription->setval($item['@attributes']['subscription']);
$this->group->setval($item['group']);
}
public function getTrueName() {
$truename = '';
@ -163,8 +106,8 @@ class Contact extends DatajarBase {
$truename = $this->nickname->getval();
elseif(isset($this->name) && $this->name->getval() != '' && !filter_var($this->name->getval(), FILTER_VALIDATE_EMAIL))
$truename = $this->name->getval();
elseif(isset($this->rostername) && $this->rostername->getval() != '' && !filter_var($this->rostername->getval(), FILTER_VALIDATE_EMAIL))
$truename = $this->rostername->getval();
//elseif(isset($this->rostername) && $this->rostername->getval() != '' && !filter_var($this->rostername->getval(), FILTER_VALIDATE_EMAIL))
// $truename = $this->rostername->getval();
else
$truename = $this->jid->getval();
@ -172,7 +115,15 @@ class Contact extends DatajarBase {
}
public function getData($data) {
return $this->$data->getval();
return trim($this->$data->getval());
}
public function getAge() {
if(isset($this->date) && $this->date->getval() != '0000-00-00') {
return floor( (strtotime(date('Y-m-d')) - strtotime($this->date->getval())) / 31556926).' '.t('yo');
} else {
return '';
}
}
public function getPlace() {
@ -216,8 +167,10 @@ class Contact extends DatajarBase {
strtotime((string)$stanza->item->geoloc->timestamp)));
}
public function getPhoto($size = 'normal') {
if(
public function getPhoto($size = 'normal', $jid = false) {
if($jid != false)
$str = 'image.php?c='.$jid.'&size='.$size;
elseif(
isset($this->phototype)
&& isset($this->photobin)
&& $this->phototype->getval() != ''
@ -232,6 +185,11 @@ class Contact extends DatajarBase {
return $str;
}
static public function getPhotoFromJid($size, $jid) {
$c = new Contact();
return $c->getPhoto($size, $jid);
}
}
class ContactHandler {
@ -244,7 +202,7 @@ class ContactHandler {
public function get($jid) {
global $sdb;
$user = new User();
$sdb->load($this->instance, array('key' => $user->getLogin(), 'jid' => $jid));
$sdb->load($this->instance, array('jid' => $jid));
return $this->instance;
}
}

9
system/Datas/Post.php

@ -103,18 +103,9 @@ class Post extends DatajarBase {
$this->street->setval((string)$item->entry->geoloc->street);
$this->building->setval((string)$item->entry->geoloc->building);
// If we have only one link in the entry
/*if(string)$item->entry->link->attributes()) {
(string)$item->entry->link[0]['attributes() = (string)$item->entry->link->attributes();
unset((string)$item->entry->link->attributes());
}*/
$contentimg = '';
foreach($item->entry->link as $attachment) {
/*if($attachment['link[0]['attributes()->title == 'thumb') {
AttachmentHandler::saveAttachment($attachment, $key, $from, (string)$item->attributes()->id);
}*/
if(isset($attachment->link[0]) && (string)$attachment->link[0]->attributes()->title == 'thumb') {
$contentimg .= '
<a href="'.(string)$attachment->attributes()->href.'" target="_blank" class="imglink"><img title="'.(string)$attachment->attributes()->title.'" src="'.(string)$attachment->link[0]->attributes()->href.'"/></a>';

31
system/Datas/RosterLink.php

@ -0,0 +1,31 @@
<?php
class RosterLink extends DatajarBase {
public $key;
public $jid;
public $rostername;
public $rosterask;
public $rostersubscription;
public $group;
public $chaton;
protected function type_init() {
$this->key = DatajarType::varchar(128);
$this->jid = DatajarType::varchar(128);
$this->rostername = DatajarType::varchar(128);
$this->rosterask = DatajarType::varchar(128);
$this->rostersubscription = DatajarType::varchar(128);
$this->group = DatajarType::varchar(128);
$this->chaton = DatajarType::int();
}
public function getData($data) {
return trim($this->$data->getval());
}
}

797
system/Jabber.php

@ -1,797 +0,0 @@
<?php
/**
* @file Jabber.php
* This file is part of MOVIM.
*
* @brief Wrapper around Jaxl to handle mid-level functionalities
*
* @author Etenil <etenil@etenilsrealm.nl>
*
* @version 1.0
* @date 13 October 2010
*
* Copyright (C)2010 Movim Project
*
* See COPYING for licensing information.
*/
//include(LIB_PATH . 'Jaxl/core/jaxl.class.php');
class Jabber
{
private static $instance;
private $jaxl;
private $payload;
/**
* Firing up basic parts of jaxl and setting variables.
*/
private function __construct($jid)
{
$userConf = UserConf::getConf($jid);
$serverConf = Conf::getServerConf();
$sess = Session::start(APP_NAME);
$sess->remove('jid'); // ???
$this->jaxl = new JAXL(array(
// User Configuration
'resource' => "Movim",
// Here we need to exchange the host and domain to allow the connexion, Jaxl bug ?
'host' => $userConf['domain'],
'domain' => $userConf['host'],
'boshHost' => $userConf['boshHost'],
'boshSuffix' => $userConf['boshSuffix'],
'boshPort' => $userConf['boshPort'],
// Server configuration
'boshCookieTTL' => $serverConf['boshCookieTTL'],
'boshCookiePath' => $serverConf['boshCookiePath'],
'boshCookieDomain' => $serverConf['boshCookieDomain'],
'boshCookieHTTPS' => $serverConf['boshCookieHTTPS'],
'boshCookieHTTPOnly' => $serverConf['boshCookieHTTPOnly'],
'logLevel' => $serverConf['logLevel'],
'boshOut'=>false,
));
// Loading required XEPS
$this->jaxl->requires(array(
'JAXL0030', // Service Discovery
'JAXL0054', // VCard
'JAXL0060', // Pubsub
'JAXL0107', // User Mood
'JAXL0118', // User Tune
'JAXL0115', // Entity Capabilities
'JAXL0133', // Service Administration
'JAXL0085', // Chat State Notification
'JAXL0092', // Software Version
'JAXL0203', // Delayed Delivery
'JAXL0202', // Entity Time
'JAXL0206', // Jabber over Bosh
'JAXL0277' // Microblogging
));
// Defining call-backs
// Connect-Disconnect
$this->jaxl->addPlugin('jaxl_post_auth', array(&$this, 'postAuth'));
$this->jaxl->addPlugin('jaxl_post_auth_failure', array(&$this, 'postAuthFailure'));
$this->jaxl->addPlugin('jaxl_post_disconnect', array(&$this, 'postDisconnect'));
$this->jaxl->addPlugin('jaxl_get_auth_mech', array(&$this, 'postAuthMech'));
// The handlers
$this->jaxl->addPlugin('jaxl_get_iq', array(&$this, 'getIq'));
$this->jaxl->addPlugin('jaxl_get_message', array(&$this, 'getMessage'));
$this->jaxl->addPlugin('jaxl_get_presence', array(&$this, 'getPresence'));
// Others hooks
$this->jaxl->addPlugin('jaxl_get_bosh_curl_error', array(&$this, 'boshCurlError'));
$this->jaxl->addplugin('jaxl_get_empty_body', array(&$this, 'getEmptyBody'));
}
/**
* Get the current instance
*
* @param string $jid = false
* @return instance
*/
static public function getInstance($jid = false)
{
if(!is_object(self::$instance)) {
if(!$jid) {
$user = new User();
if(!$user->isLogged()) {
return false;
throw new MovimException(t("User not logged in."));
} else {
$jid = $user->getLogin();
if($jid = "")
throw new MovimException(t("JID not provided."));
}
} else {
self::$instance = new Jabber($jid);
}
}
return self::$instance;
}
function destroy()
{
self::$instance = null;
}
/**
* Start the BOSH connection
*
* @param string $jid
* @param string $pass
* @return void
*/
public function login($jid, $pass)
{
if(!checkJid($jid)) {
throw new MovimException(t("jid '%s' is incorrect", $jid));
} else {
$id = explode('@',$jid);
$user = $id[0];
$this->jaxl->user = $user;
$this->jaxl->pass = $pass;
$this->jaxl->startCore('bosh');
}
self::setStatus($presence['status'], $presence['show'], false, true);
}
/**
* postAuth
*
* @return void
*/
public function postAuth() {
}
/**
* postAuthFailure
*
* @return void
*/
public function postAuthFailure() {
$this->jaxl->shutdown();
throw new MovimException("Login error.", 300);
$user = new User();
$user->desauth();
}
/**
* Return the current ressource
*
* @return string
*/
public function getResource()
{
$res = JAXLUtil::splitJid($this->jaxl->jid);
return $res[2];
}
/**
* Return the current Cleaned Jid
*
* @return string
*/
public function getCleanJid() {
$jid = $this->jaxl->jid;
$res = JAXLUtil::splitJid($jid);
return $res[0].'@'.$res[1];
}
public function boshCurlError() {
// $this->jaxl->shutdown();
// throw new MovimException("Bosh connection error.");
// $user = new User();
// $user->desauth();
}
/**
* Auth mechanism
*
* @param array $mechanism
* @return void
*/
public function postAuthMech($mechanism) {
if(in_array("DIGEST-MD5", $mechanism))
$this->jaxl->auth('DIGEST-MD5');
elseif(in_array("PLAIN", $mechanism))
$this->jaxl->auth('PLAIN');
}
/**
* Close the BOSH connection
*
* @return void
*/
public function logout()
{
$this->jaxl->JAXL0206('endStream');
}
/**
* postDisconnect
*
* @param array $data
* @return void
*/
public function postDisconnect($data)
{
$evt = new Event();
$evt->runEvent('postdisconnected', $data);
}
/**
* Pings the server. This must be done regularly in order to keep the
* session running
*
* @return void
*/
public function pingServer()
{
$this->jaxl->JAXL0206('ping');
}
/**
* Get an empty body
*
* @param array $payload
* @return void
*/
public function getEmptyBody($payload) {
$evt = new Event();
// Oooooh, am I disconnected??
if(preg_match('/condition=[\'"]item-not-found[\'"]/', $payload) || preg_match('/condition=[\'"]improper-addressing[\'"]/', $payload)) {
$this->postAuthFailure();
} else {
$evt->runEvent('incomingemptybody', 'ping');
}
}
/**
* Iq handler
*
* @param array $payload
* @return void
*/
public function getIq($payload) {
$payload = $payload['movim'];
global $sdb;
$evt = new Event();
// Holy mackerel, that's a vcard!
if(is_array($payload['vCard']) &&
$payload['@attributes']['type'] != 'error')
{
$c = new ContactHandler();
// If the vcard is mine
if($payload['@attributes']['from'] == $this->getCleanJid() ||
$payload['@attributes']['from'] == NULL )
{
$contact = $c->get($this->getCleanJid());
$contact->setContact($payload);
$sdb->save($contact);
$evt->runEvent('myvcard', $payload);
}
// Yo it's your vcard dude !
elseif(isset($payload['@attributes']['from'])) {
$contact = $c->get($payload['@attributes']['from']);
$contact->setContact($payload);
$sdb->save($contact);
$evt->runEvent('vcard', $contact);
}
}
elseif($payload['@attributes']['xmlns'] == 'http://jabber.org/protocol/disco#info') {
global $sdb;
$c = new CapsHandler();
$caps = $c->get($payload['query']['@attributes']['node']);
$caps->setCaps($payload['query']);
$sdb->save($caps);
}
// Roster case
elseif($payload['@attributes']['xmlns'] == 'jabber:iq:roster') {
global $sdb;
// If we got the full roster list
if($payload['@attributes']['type'] == 'result') {
foreach($payload['query']['item'] as $item) {
// If we've got only one item in the roster we use it as the only one
if(isset($item['subscription']))
$item = $payload['query']['item'];
$c = new ContactHandler();
$contact = $c->get($item['@attributes']['jid']);
$contact->setContactRosterItem($item);
$sdb->save($contact);
}
$evt->runEvent('roster', $payload);
}
// If we got only one item
elseif($payload['@attributes']['type'] == "set") {
$c = new ContactHandler();
$item = $payload['query']['item'];
$contact = $c->get($item['@attributes']['jid']);
// It's a new contact !
if($item['@attributes']['subscription'] == 'remove') {
$evt->runEvent('contactremove', $item['@attributes']['jid']);
}
// Contact removed
elseif(in_array($item['@attributes']['subscription'], array('from', 'to', 'both'))) {
$contact->setContactRosterItem($item);
$sdb->save($contact);
$evt->runEvent('contactadd', $item['@attributes']['jid']);
}
}
}
// Pubsub case
elseif(isset($payload['pubsub']) && !(isset($payload['error']))) {
list($xmlns, $parent) = explode("/", $payload['pubsub']['items']['@attributes']['node']);
if(isset($payload['pubsub']['items']['item'])) {
foreach($payload['pubsub']['items']['item'] as $item) {
if(isset($item['id']))
$item = $payload['pubsub']['items']['item'];
// We've got a new Post !
if(isset($item['@attributes']) && isset($item['entry'])) {
$c = new PostHandler();
$post = $c->get($this->getCleanJid(), $item['@attributes']['id']);
// We save it in the database
if($xmlns == 'urn:xmpp:microblog:0')
$post->setPost($item, $payload['@attributes']['from']);
elseif($xmlns == 'urn:xmpp:microblog:0:comments')
$post->setPost($item, $payload['@attributes']['from'], $parent);
$sdb->save($post);
// And we run the correct event
if($xmlns == 'urn:xmpp:microblog:0') {
$evt->runEvent('post', $item['@attributes']['id']);
$evt->runEvent('stream', $payload);
} elseif($xmlns == 'urn:xmpp:microblog:0:comments')
$evt->runEvent('comment', $parent);
}
}
} elseif(isset($payload['pubsub']['publish']['@attributes']['node'])) {
list($xmlns, $id) = explode("/", $payload['pubsub']['publish']['@attributes']['node']);
if($payload['pubsub']['publish']['@attributes']['node'] == 'urn:xmpp:microblog:0') {
$this->getWallItem($this->getCleanJid(), $payload['pubsub']['publish']['item']['@attributes']['id']);
}
$this->getComments($payload['@attributes']['from'], $id);
} else {
$evt->runEvent('nocomment', $parent);
if($xmlns == 'urn:xmpp:microblog:0')
$evt->runEvent('nostream', $parent);
}
}
elseif(isset($payload['pubsub']) && isset($payload['error'])) {
list($xmlns, $parent) = explode("/", $payload['pubsub']['items']['@attributes']['node']);
if(isset($payload['error']['item-not-found'])) {
if($xmlns == 'urn:xmpp:microblog:0:comments')
$evt->runEvent('nocommentstream', $parent);
else
$evt->runEvent('nostream', $parent);
}
elseif(in_array( $payload['error']['@attributes']['code'], array(501, 503)) &&
$payload['pubsub']['create']['@attributes']['node'] == 'urn:xmpp:microblog:0') {
$conf = new ConfVar();
$sdb->load($conf, array(
'login' => $this->getCleanJid()
));
$conf->set('first', 3);
$sdb->save($conf);
}
elseif(isset($payload['error']['feature-not-implemented']) ||
isset($payload['error']['not-authorized']) ||
isset($payload['error']['service-unavailable']) ||
isset($payload['error']['item-not-found'])) {
$evt->runEvent('nostream');
}
}
elseif(isset($payload['error'])) {
$evt->runEvent('nostream');
}
else {
$evt->runEvent('none', var_export($payload, true));
}
$evt->runEvent('incomingemptybody', 'ping');
}
/**
* Message handler
*
* @param array $payloads
* @return void
*/
public function getMessage($payloads) {
$evt = new Event();
foreach($payloads as $payload) {
if($payload['offline'] != JAXL0203::$ns && $payload['type'] == 'chat') { // reject offline message
if($payload['chatState'] == 'active' && $payload['body'] == NULL)
$evt->runEvent('incomeactive', $payload);
elseif($payload['chatState'] == 'composing')
$evt->runEvent('composing', $payload);
elseif($payload['chatState'] == 'paused')
$evt->runEvent('paused', $payload);
else {
global $sdb;
$m = new Message();
$m->setMessageChat($payload['movim']);
$sdb->save($m);
$evt->runEvent('message', $m);
}
} elseif($payload['movim']['event']['items']['@attributes']['node'] == 'urn:xmpp:microblog:0') {
$payload = $payload['movim'];
if(isset($payload['event']['items']['item'])) {
global $sdb;
$c = new PostHandler();
$post = $c->get($this->getCleanJid(), $payload['event']['items']['item']['@attributes']['id']);
if($post->getData('nodeid') == $payload['event']['items']['item']['@attributes']['id'])
$new = true;
$post->setPost($payload['event']['items']['item'], $payload['@attributes']['from'], false, $this->getCleanJid());
$sdb->save($post);
}
if($new == false) {
$sess = Session::start(APP_NAME);
if($sess->get('currentcontact') == $payload['@attributes']['from']) {
$evt->runEvent('currentpost', $payload);
}
if($payload['@attributes']['from'] != $this->getCleanJid())
$evt->runEvent('post', $payload['event']['items']['item']['@attributes']['id']);
}
}
}
$evt->runEvent('incomingemptybody', 'ping');
}
/**
* Presence handler
*
* @param array $payloads
* @return void
*/
public function getPresence($payloads) {
global $sdb;
$evt = new Event();
foreach($payloads as $payload) {
$payload = $payload['movim'];
if($payload['@attributes']['type'] == 'subscribe') {
$evt->runEvent('subscribe', $payload);
}
else {
// We update the presences
list($jid, $ressource) = explode('/',$payload['@attributes']['from']);
// We ask for the entity-capabilities and we prevent to ask our own capabilities
if(isset($payload['c']) && $jid != $this->getCleanJid()) {
$c = new CapsHandler();
$caps = $c->get($payload['c']['@attributes']['node'].'#'.$payload['c']['@attributes']['ver']);
// We ask for the caps only if we haven't found it in the database
if($caps->getData('category') == null) {
$this->jaxl->JAXL0030(
'discoInfo',
$payload['@attributes']['from'],
$this->getCleanJid(),
false,
$payload['c']['@attributes']['node'].'#'.$payload['c']['@attributes']['ver']
);
}
}
$presence = $sdb->select('Presence', array(
'key' => $this->getCleanJid(),
'jid' => $jid,
'ressource' => $ressource
));
if($presence == false) {
$presence = new Presence();
$presence->setPresence($payload);
$sdb->save($presence);
} else {
$presence = new Presence();
$sdb->load($presence, array(
'key' => $this->getCleanJid(),
'jid' => $jid,
'ressource' => $ressource
));
$presence->setPresence($payload);
$sdb->save($presence);
}
if($payload['@attributes']['from'] == $payload['@attributes']['to'])
$evt->runEvent('mypresence', $presence);
$evt->runEvent('presence', $presence);
}
}
$evt->runEvent('incomingemptybody', 'ping');
}
/**
* Ask for a vCard
*
* @param string $jid = false
* @return void
*/
public function getVCard($jid = false)
{
$this->jaxl->JAXL0054('getVCard', $jid, $this->jaxl->jid, false);
}
/**
* sendVcard
*
* @param array $vcard
* @return void
*/
public function updateVcard($vcard)
{
$this->jaxl->JAXL0054('updateVCard', $vcard);
$this->jaxl->JAXL0054('getVCard', false, $this->jaxl->jid, false);
}
/**
* Create personnal microblog node
*
* @return void
*/
public function createNode()
{
$this->jaxl->JAXL0277('createNode', $this->getCleanJid());
}
/**
* Subscribe to a node
*
* @param unknown $jid = false
* @return void
*/
public function subscribeNode($jid)
{
$this->jaxl->JAXL0277('subscribeNode', $this->getCleanJid(), $jid);
}
/**
* Ask for some items
*
* @param unknown $jid = false
* @return void
*/
public function getWall($jid = false) {
$this->jaxl->JAXL0277('getItems', $jid);
}
/**
* Ask for an item
*
* @param unknown $jid = false
* @return void
*/
public function getWallItem($jid = false, $id) {
$this->jaxl->JAXL0277('getItem', $jid, $id);
}
/**
* Ask for some comments of an article
*
* @param string $jid
* @param string $id
* @return void
*/
public function getComments($place, $id) {
$this->jaxl->JAXL0277('getComments', $place, $id);
}
/**
* Service Discovery
*
* @param string $jid = false
* @return void
*/
public function discover($jid = false)
{
$this->jaxl->JAXL0277('getItems', 'edhelas@jappix.com');
}
public function discoNodes($pod)
{
$this->jaxl->JAXL0060('discoNodes', $pod, $this->jaxl->jid);
}
/**
* Get some items about a node
*
* @param string $pod
* @param string $node
* @return void
*/
public function discoItems($pod, $node)
{
$this->jaxl->JAXL0060('getNodeItems', $pod, $this->jaxl->jid, $node);
}
/**
* Publish an item on microblog feed
*
* @param string $content
* @return void
*/
public function publishItem($content)
{
$id = md5(openssl_random_pseudo_bytes(5));
$this->jaxl->JAXL0277('createCommentNode', $this->getCleanJid() ,$id);
$this->jaxl->JAXL0277('publishItem', $this->getCleanJid() ,$content, false, false, $id);
}
/**
* Publish a comment on a microblog item
*
* @param string $content
* @return void
*/
public function publishComment($place, $id, $content)
{
$this->jaxl->JAXL0277('publishComment', $place, $id ,$content, $this->getCleanJid());
}
/**
* Ask for the roster
*
* @return void
*/
public function getRosterList()
{
$this->jaxl->getRosterList();
}
/**
* Set a new status
*
* @param string $status
* @param string $show
* @return void
*/
public function setStatus($status, $show)
{
$this->jaxl->setStatus($status, $show, 41, false);
}
/**
* Send a message
*
* @param string $addressee
* @param steirng $body
* @return void
*/
public function sendMessage($addressee, $body)
{
// Checking on the jid.
if(checkJid($addressee)) {
$this->jaxl->sendMessage($addressee, $body, false, 'chat');
} else {
throw new MovimException("Incorrect JID `$addressee'");
}
}
/**
* Subscribe to a contact request
*
* @param unknown $jid
* @return void
*/
public function subscribedContact($jid) {
if(checkJid($jid)) {
$this->jaxl->subscribed($jid);
$this->jaxl->addRoster($jid);
} else {
throw new MovimException("Incorrect JID `$jid'");
}
}
/**
* Accecpt a new contact
*
* @param string $jid
* @param string $group
* @param string $alias
* @return void
*/
public function acceptContact($jid, $group, $alias)
{
if(checkJid($jid)) {
$this->jaxl->addRoster($jid, $group, $alias);
$this->jaxl->subscribe($jid);
} else {
throw new MovimException("Incorrect JID `$jid'");
}
}
/**
* Add a new contact
*
* @param string $jid
* @param string $grJaxloup
* @param string $alias
* @return void
*/
public function addContact($jid, $group, $alias) {
if(checkJid($jid)) {
$this->jaxl->subscribe($jid);
} else {
throw new MovimException("Incorrect JID `$jid'");
}
}
/**
* Remove a contact
*
* @param string $jid
* @return void
*/
public function removeContact($jid) {
if(checkJid($jid)) {
$this->jaxl->deleteRoster($jid);
$this->jaxl->unsubscribe($jid);
} else {
throw new MovimException("Incorrect JID `$jid'");
}
}
/**
* Unsubscribe to a contact
*
* @param unknown $jid
* @return void
*/
public function unsubscribed($jid) {
$this->jaxl->unsubscribed($jid);
}
}
?>

55
system/Utils.php

@ -256,6 +256,61 @@ function getPresences() {
);
}
/*
* Get the user local timezone
*/
function getLocalTimezone()
{
$iTime = time();
$arr = localtime($iTime);
$arr[5] += 1900;
$arr[4]++;
$iTztime = gmmktime($arr[2], $arr[1], $arr[0], $arr[4], $arr[3], $arr[5], $arr[8]);
$offset = doubleval(($iTztime-$iTime)/(60*60));
$zonelist =
array
(
'Kwajalein' => -12.00,
'Pacific/Midway' => -11.00,
'Pacific/Honolulu' => -10.00,
'America/Anchorage' => -9.00,
'America/Los_Angeles' => -8.00,
'America/Denver' => -7.00,
'America/Tegucigalpa' => -6.00,
'America/New_York' => -5.00,
'America/Caracas' => -4.30,
'America/Halifax' => -4.00,
'America/St_Johns' => -3.30,
'America/Argentina/Buenos_Aires' => -3.00,
'America/Sao_Paulo' => -3.00,
'Atlantic/South_Georgia' => -2.00,
'Atlantic/Azores' => -1.00,
'Europe/Dublin' => 0,
'Europe/Belgrade' => 1.00,
'Europe/Minsk' => 2.00,
'Asia/Kuwait' => 3.00,
'Asia/Tehran' => 3.30,
'Asia/Muscat' => 4.00,
'Asia/Yekaterinburg' => 5.00,
'Asia/Kolkata' => 5.30,
'Asia/Katmandu' => 5.45,
'Asia/Dhaka' => 6.00,
'Asia/Rangoon' => 6.30,
'Asia/Krasnoyarsk' => 7.00,
'Asia/Brunei' => 8.00,
'Asia/Seoul' => 9.00,
'Australia/Darwin' => 9.30,
'Australia/Canberra' => 10.00,
'Asia/Magadan' => 11.00,
'Pacific/Fiji' => 12.00,
'Pacific/Tongatapu' => 13.00
);
$index = array_keys($zonelist, $offset);
if(sizeof($index)!=1)
return false;
return $index[0];
}
/**
* Check the current Jid
*

22
system/Widget/WidgetCommon.php

@ -46,7 +46,6 @@ class WidgetCommon extends WidgetBase {
->where(
array(
'Post`.`key' => $this->user->getLogin(),
'Contact`.`key' => $this->user->getLogin(),
array('Post`.`parentid' => $commentid)))
->orderby('Post.published', false);
$comments = Post::run_query($query);
@ -97,8 +96,13 @@ class WidgetCommon extends WidgetBase {
$tmp .= 'protect black';
else
$tmp .= 'protect orange';
//$tmp .= 'me';
}
if($message[1]->getTrueName() == null)
$name = $message[0]->getData('jid');
else
$name = $message[1]->getTrueName();
$tmp .= '" id="'.$message[0]->getData('nodeid').'" >
<a href="?q=friend&f='.$message[0]->getData('jid').'">
@ -106,7 +110,7 @@ class WidgetCommon extends WidgetBase {
</a>
<span>
<a href="?q=friend&f='.$message[0]->getData('jid').'">'.$message[1]->getTrueName().'</a>
<a href="?q=friend&f='.$message[0]->getData('jid').'">'.$name.'</a>
</span>
<span class="date">
'.prepareDate(strtotime($message[0]->getData('updated'))).'
@ -114,16 +118,7 @@ class WidgetCommon extends WidgetBase {
$tmp .= '<div class="content">
'.prepareString(html_entity_decode($message[0]->getData('content'))). '</div>';
//$attachments = AttachmentHandler::getAttachment($this->user->getLogin(), $message[0]->getData('nodeid'));
/*if($attachments) {
$tmp .= '<div class="attachment">';
foreach($attachments as $attachment)
$tmp .= '<a target="_blank" href="'.$attachment->getData('link').'"><img alt="'.$attachment->getData('title').'" title="'.$attachment->getData('title').'" src="'.$attachment->getData('thumb').'"></a>';
$tmp .= '</div>';
}*/
if($message[0]->getPlace() != false)
$tmp .= '<span class="place">
<a
@ -278,7 +273,6 @@ class WidgetCommon extends WidgetBase {
if($comments) {
foreach($comments as $comment) {
//var_dump($comment[1]);
if(isset($comment[1])) {
$photo = $comment[1]->getPhoto('s');
$name = $comment[1]->getTrueName();

63
system/Widget/widgets/Chat/Chat.php

@ -69,11 +69,11 @@ class Chat extends WidgetBase
$jid = $message->getData('from');
}
$query = Contact::query()->select()
$query = RosterLink::query()->select()
->where(array(
'key' => $key,
'jid' => $jid));
$contact = Contact::run_query($query);
$contact = RosterLink::run_query($query);
if($contact)
$contact = $contact[0];
@ -120,11 +120,11 @@ class Chat extends WidgetBase
function onComposing($jid)
{
$query = Contact::query()->select()
$query = RosterLink::query()->select()
->where(array(
'key' => $this->user->getLogin(),
'jid' => $jid));
$contact = Contact::run_query($query);
$contact = RosterLink::run_query($query);
$contact = $contact[0];
if($contact->getData('chaton') == 1) {
@ -138,11 +138,11 @@ class Chat extends WidgetBase
function onPaused($jid)
{
$query = Contact::query()->select()
$query = RosterLink::query()->select()
->where(array(
'key' => $this->user->getLogin(),
'jid' => $jid));
$contact = Contact::run_query($query);
$contact = RosterLink::run_query($query);
$contact = $contact[0];
if($contact->getData('chaton') == 1) {
@ -163,21 +163,22 @@ class Chat extends WidgetBase
*/
function ajaxOpenTalk($jid)
{
$query = Contact::query()->select()
$query = RosterLink::query()->select()
->where(array(
'key' => $this->user->getLogin(),
'jid' => $jid));
$contact = Contact::run_query($query);
'RosterLink`.`key' => $this->user->getLogin(),
'RosterLink`.`jid' => $jid));
$contact = RosterLink::run_query($query);
$contact = $contact[0];
$query = Presence::query()->select()
->where(array(
'key' => $this->user->getLogin(),
'jid' => $jid));
'jid' => $jid))
->orderby('presence', false);
$presence = Presence::run_query($query);
$presence = $presence[0];
if($contact->getData('chaton') == 0 && isset($presence) && $presence->presence->getval() != 6) {
if($contact->getData('chaton') == 0 && isset($presence) && !in_array($presence->presence->getval(), array(5, 6))) {
$contact->chaton->setval(2);
$contact->run_query($contact->query()->save($contact));
@ -229,12 +230,12 @@ class Chat extends WidgetBase
*/
function ajaxCloseTalk($jid)
{
$query = Contact::query()->select()
$query = RosterLink::query()->select()
->where(array(
'key' => $this->user->getLogin(),
'jid' => $jid));
$contacts = Contact::run_query($query);
//$contact = $contact[0];
$contacts = RosterLink::run_query($query);
foreach($contacts as $contact) {
if((int)$contact->getData('chaton') == 1 || (int)$contact->getData('chaton') == 2) {
$contact->chaton->setval(0);
@ -246,11 +247,11 @@ class Chat extends WidgetBase
function ajaxHideTalk($jid)
{
$query = Contact::query()->select()
$query = RosterLink::query()->select()
->where(array(
'key' => $this->user->getLogin(),
'jid' => $jid));
$contact = Contact::run_query($query);
$contact = RosterLink::run_query($query);
$contact = $contact[0];
if($contact->getData('chaton') == 1) {
@ -324,9 +325,9 @@ class Chat extends WidgetBase
<div class="head" >
<span class="chatbutton cross" onclick="'.$this->genCallAjax("ajaxCloseTalk", "'".$contact->getData('jid')."'").' closeTalk(this)"></span>
<span class="chatbutton arrow" onclick="'.$this->genCallAjax("ajaxHideTalk", "'".$contact->getData('jid')."'").' hideTalk(this)"></span>
<img class="avatar" src="'.$contact->getPhoto('xs').'" />
<img class="avatar" src="'.Contact::getPhotoFromJid('xs', $contact->getData('jid')).'" />
<a class="name" href="?q=friend&f='.$contact->getData('jid').'">
'.$contact->getTrueName().'
'.$contact->getData('rostername').'
</a>
</div>
<div class="messages" id="messages'.$contact->getData('jid').'">
@ -347,7 +348,7 @@ class Chat extends WidgetBase
<div class="tab '.$tabclass.'" '.$tabstyle.' onclick="'.$this->genCallAjax("ajaxHideTalk", "'".$contact->getData('jid')."'").' showTalk(this);">
<div class="name">
<img class="avatar" src="'.$contact->getPhoto('xs').'" />'.$contact->getTrueName().'
<img class="avatar" src="'.Contact::getPhotoFromJid('xs', $contact->getData('jid')).'" />'.$contact->getData('rostername').'
</div>
</div>
</div>
@ -357,16 +358,16 @@ class Chat extends WidgetBase
function build()
{
$query = Contact::query()
->where(
array(
'key' => $this->user->getLogin(),
$query = RosterLink::query()
->where(
array(
'chaton' =>
array(1, '|2'))
)
);
$contacts = Contact::run_query($query);
'RosterLink`.`key' => $this->user->getLogin(),
array(
'chaton' =>
array(1, '|2'))
)
);
$contacts = RosterLink::run_query($query);
echo '<div id="chats">';
if($contacts != false) {

8
system/Widget/widgets/Chat/chat.css

@ -85,6 +85,12 @@
#chats .chat .panel .head a.name {
padding-right: 1em;
display: inline-block;
margin: 0px;
width: 145px;
overflow: hidden;
text-overflow: ellipsis;
margin-top: 3px;
}
#chats .chat .tab:hover {
@ -100,7 +106,7 @@
#chats .chat .panel .head {
background-color: #242424;
color: white;
line-height: 24px;
line-height: 17px;
border: 1px solid #222;
border-radius: 2px 2px 0px 0px;
border-bottom: 1px solid #242424;

1
system/Widget/widgets/ContactCard/ContactCard.php

@ -97,7 +97,6 @@ class ContactCard extends WidgetCommon
{
$query = Contact::query()->select()
->where(array(
'key' => $this->user->getLogin(),
'jid' => $_GET['f']));
$contact = Contact::run_query($query);
?>

33
system/Widget/widgets/ContactInfo/ContactInfo.php

@ -24,28 +24,24 @@ class ContactInfo extends WidgetCommon
}
function ajaxRemoveContact($jid) {
//if(checkJid($jid)) {
$r = new moxl\RosterRemoveItem();
$r->setTo($jid)
->request();
$p = new moxl\PresenceUnsubscribe();
$p->setTo($jid)
->request();
/*} else {
throw new MovimException("Incorrect JID `$jid'");
}*/
function ajaxRemoveContact($jid) {
$r = new moxl\RosterRemoveItem();
$r->setTo($jid)
->request();
$p = new moxl\PresenceUnsubscribe();
$p->setTo($jid)
->request();
}
function prepareContactInfo()
{
$query = Contact::query()->join('Presence',
$query = Contact::query()
->join('Presence',
array('Contact.jid' =>
'Presence.jid'))
->where(array(
'Contact`.`key' => $this->user->getLogin(),
'Contact`.`jid' => $_GET['f']));
$user = Contact::run_query($query);
@ -117,9 +113,6 @@ class ContactInfo extends WidgetCommon
$c = new CapsHandler();
$caps = $c->get($presence['node'].'#'.$presence['ver']);
if($this->testIsSet($caps->getData('type'))) {
if($caps->getData('type') == 'phone')
$cinfos = '<span class="mobile"></span>';
@ -136,7 +129,7 @@ class ContactInfo extends WidgetCommon
$html .='<h2>'.t('Actions').'</h2>';
if(isset($presence['presence']) && $presence['presence'] != 5) {
if(isset($presence['presence']) && !in_array($presence['presence'], array(5, 6))) {
$html .= '
<a
class="button tiny icon chat"
@ -151,7 +144,7 @@ class ContactInfo extends WidgetCommon
$html .= '<div style="clear: both;"></div>';
if($contact->rostersubscription->getval() != 'vcard') {
/*if($contact->rostersubscription->getval() != 'vcard') {
$html .='
<a
class=""
@ -203,7 +196,7 @@ class ContactInfo extends WidgetCommon
>
'.t('Invite this user').'
</a>';
}
}*/
}
}

4
system/Widget/widgets/ContactSummary/ContactSummary.php

@ -86,9 +86,6 @@ class ContactSummary extends WidgetCommon
$html .= '
</div>';
}
if($contact->getData('vcardreceived') != 1)
$html .= '<script type="text/javascript">setTimeout(\''.$this->genCallAjax('ajaxRefreshVcard', '"'.$contact->getData('jid').'"').'\', 2000);</script>';
return $html;
}
@ -97,7 +94,6 @@ class ContactSummary extends WidgetCommon
{
$query = \Contact::query()->select()
->where(array(
'key' => $this->user->getLogin(),
'jid' => $_GET['f']));
$contact = \Contact::run_query($query);
?>

55
system/Widget/widgets/Explore/Explore.php

@ -0,0 +1,55 @@
<?php
class Explore extends WidgetCommon {
function WidgetLoad()
{
$this->addcss('explore.css');
}
function build()
{
$users_limit = 20;
$gender = getGender();
$marital = getMarital();
$query = Contact::query()->select()
->where(array(
'public' => 1))
->limit(0, $users_limit);
$users = Contact::run_query($query);
/*$users_number = sizeof($users);
if($users_number < $users_limit) {
$users_fill = array();
for($i = 0; $i<$users_limit-$users_number; $i++)
array_push($users_fill, new Contact());
$users = array_merge($users, $users_fill);
}*/
shuffle($users);
?>
<div id="explore">
<?php
foreach($users as $user) {
echo '
<a href="?q=friend&f='.$user->getData('jid').'">
<div class="contactbox">
<img class="avatar" src="'.$user->getPhoto('m').'"/>
<div class="desc">'.prepareString($user->getData('desc')).'</div>
<span class="name">'.$user->getTrueName().'</span>
<span class="asv">'.
$user->getAge().' '.
$gender[$user->getData('gender')].'<br />'.
$marital[$user->getData('marital')].'
</span>
</div>
</a>';
}
?>
</div>
<?php
}
}

44
system/Widget/widgets/Explore/explore.css

@ -0,0 +1,44 @@
#explore {
padding: 1.5em;
padding-top: 0px;
margin-bottom: 2em;
}
.contactbox {
height: 50px;
padding: 1.5em 0px;
border-bottom: 1px solid #DDD;
}
.contactbox:hover {
background-color: #F9F9F9;
}
.contactbox img.avatar {
height: 50px;
width: 50px;
float: left;
margin-right: 10px;
border-radius: 4px;
}
.contactbox .name {
font-weight: bold;
display: block;
text-overflow: ellipsis;
max-width: 30%;
white-space: nowrap;
}
.contactbox .asv {
color: #888;
}
.contactbox .desc {
width: 50%;
height: 100%;
float: right;
overflow: hidden;
text-overflow: ellipsis;
white-space: pre-wrap;
}

10
system/Widget/widgets/Feed/Feed.php

@ -176,11 +176,6 @@ class Feed extends WidgetCommon {
->join('Contact', array('Post.jid' => 'Contact.jid'))
->where(
array(
'Contact`.`key' => $this->user->getLogin(),
array(
'Contact`.`rostersubscription!' => 'none',
'|Contact`.`rosterask' => 'subscribe',
'|Contact`.`jid' => $this->user->getLogin()),
'Post`.`parentid' => ''))
->orderby('Post.updated', true)
->limit($start, '20');
@ -232,11 +227,6 @@ class Feed extends WidgetCommon {
$p->setTo($this->user->getLogin())
->request();
}
function ajaxFeed()
{
//$this->xmpp->getWall($this->xmpp->getCleanJid());
}
function build()
{

4
system/Widget/widgets/Login/Login.php

@ -250,7 +250,7 @@ class Login extends WidgetBase {
</form>
<div id="publicusers">
<?php
<?php /*
$users_limit = 55;
$query = Contact::query()->select()
@ -278,7 +278,7 @@ class Login extends WidgetBase {
else
echo '<img src="'.$user->getPhoto('s').'"/>';
}
?>
*/ ?>
</div>
<?php
}

4
system/Widget/widgets/Logout/Logout.php

@ -25,11 +25,7 @@ class Logout extends WidgetBase
{
$this->addcss('logout.css');
$this->addjs('logout.js');
//$this->registerEvent('postdisconnected', 'onPostDisconnect');
//$this->registerEvent('serverdisconnect', 'onPostDisconnect'); // When you're kicked out
$this->registerEvent('mypresence', 'onMyPresence');
//$this->cached = true;
}
function onMyPresence()

78
system/Widget/widgets/Notifs/Notifs.php

@ -32,7 +32,6 @@ class Notifs extends WidgetBase
function onMessage($message) {
$query = Contact::query()->select()
->where(array(
'key' => $message->getData('to'),
'jid' => $message->getData('from')));
$contact = Contact::run_query($query);
@ -97,46 +96,30 @@ class Notifs extends WidgetBase
}
function ajaxSubscribed($jid) {
//if(checkJid($jid)) {
$p = new moxl\PresenceSubscribed();
$p->setTo($jid)
->request();
/*$p = new moxl\PresenceSubscribe();
$p->setTo($jid)
->request();*/
/*} else {
throw new MovimException("Incorrect JID `$jid'");
}*/
$p = new moxl\PresenceSubscribed();
$p->setTo($jid)
->request();
}
function ajaxRefuse($jid) {
//if(checkJid($jid)) {
$p = new moxl\PresenceUnsubscribed();
$p->setTo($jid)
->request();
$notifs = Cache::c('activenotifs');
unset($notifs[$jid]);
Cache::c('activenotifs', $notifs);
/*} else {
throw new MovimException("Incorrect JID `$jid'");
}*/
$p = new moxl\PresenceUnsubscribed();
$p->setTo($jid)
->request();
$notifs = Cache::c('activenotifs');
unset($notifs[$jid]);
Cache::c('activenotifs', $notifs);
}
function ajaxAccept($jid, $alias) {
//if(checkJid($jid)) {
$r = new moxl\RosterAddItem();
$r->setTo($jid)
->request();
$p = new moxl\PresenceSubscribe();
$p->setTo($jid)
->request();
/*} else {
throw new MovimException("Incorrect JID `$jid'");
}*/
$r = new moxl\RosterAddItem();
$r->setTo($jid)
->request();
$p = new moxl\PresenceSubscribe();
$p->setTo($jid)
->request();
$notifs = Cache::c('activenotifs');
unset($notifs[$jid]);
@ -145,17 +128,13 @@ class Notifs extends WidgetBase
}
function ajaxAddContact($jid, $alias) {
//if(checkJid($jid)) {
$r = new moxl\RosterAddItem();
$r->setTo($jid)
->request();
$p = new moxl\PresenceSubscribe();
$p->setTo($jid)
->request();
/*} else {
throw new MovimException("Incorrect JID `$jid'");
}*/
$r = new moxl\RosterAddItem();
$r->setTo($jid)
->request();
$p = new moxl\PresenceSubscribe();
$p->setTo($jid)
->request();
}
function build() {
@ -163,16 +142,15 @@ class Notifs extends WidgetBase
if($notifs == false)
$notifs = array();
$query = Contact::query()
$query = RosterLink::query()
->where(
array(
'key' => $this->user->getLogin(),
'jid!' => $this->user->getLogin(),
array(
'rostersubscription!' => 'none',
'Contact`.`rostersubscription!' => 'vcard',
'rostersubscription!' => 'vcard',
'|rosterask' => 'subscribe')));
$contacts = Contact::run_query($query);
$contacts = RosterLink::run_query($query);
?>
<div id="notifs">
<span id="widgettitle">

1
system/Widget/widgets/Profile/Profile.php

@ -77,7 +77,6 @@ class Profile extends WidgetBase
{
$query = Contact::query()->select()
->where(array(
'key' => $this->user->getLogin(),
'jid' => $this->user->getLogin()));
$contact = Contact::run_query($query);

3
system/Widget/widgets/ProfileData/ProfileData.php

@ -87,8 +87,7 @@ class ProfileData extends WidgetBase
$query = Contact::query()
->select()
->where(
array('key' => $this->user->getLogin(),
'jid' => $this->user->getLogin())
array('jid' => $this->user->getLogin())
);
$c = Contact::run_query($query);

29
system/Widget/widgets/Roster/Roster.php

@ -30,7 +30,7 @@ class Roster extends WidgetBase
$this->registerEvent('contactadd', 'onRoster');
$this->registerEvent('contactremove', 'onRoster');
$this->registerEvent('presence', 'onPresence');
$this->registerEvent('vcard', 'onVcard');
//this->registerEvent('vcard', 'onVcard');
$this->cached = false;
}
@ -42,7 +42,7 @@ class Roster extends WidgetBase
RPC::cdata($arr['jid']), RPC::cdata($arr['presence_txt']));
}
function onVcard($contact)
/*function onVcard($contact)
{
$query = \Presence::query()->select()
->where(array(
@ -57,7 +57,7 @@ class Roster extends WidgetBase
$html = $this->prepareRosterElement($c, true);
RPC::call('movim_fill', 'roster'.$contact->getData('jid'), RPC::cdata($html));
}
}*/
function onRoster()
{
@ -98,8 +98,8 @@ class Roster extends WidgetBase
$middle .= '"';
$middle .= ' href="?q=friend&f='.$contact[0]->getData('jid').'"
>
<img class="avatar" src="'.$contact[0]->getPhoto('xs').'" />'.
'<span>'.$contact[0]->getTrueName();
<img class="avatar" src="'.Contact::getPhotoFromJid('xs', $contact[0]->getData('jid')).'" />'.
'<span>'.$contact[0]->getData('rostername');
if($contact[0]->getData('rosterask') == 'subscribe')
$middle .= " #";
if($presence['ressource'] != '')
@ -120,18 +120,17 @@ class Roster extends WidgetBase
function prepareRoster()
{
$query = Contact::query()->join('Presence',
array('Contact.jid' =>
$query = RosterLink::query()->join('Presence',
array('RosterLink.jid' =>
'Presence.jid'))
->where(
array(
'Contact`.`key' => $this->user->getLogin(),
'Contact`.`jid!' => $this->user->getLogin(),
->where(
array(
'Contact`.`rostersubscription!' => 'none',
'Contact`.`rostersubscription!' => 'vcard',
'|Contact`.`rosterask' => 'subscribe')))
->orderby('Contact.group', true);
'RosterLink`.`key' => $this->user->getLogin(),
array(
'RosterLink`.`rostersubscription!' => 'none',
'RosterLink`.`rostersubscription!' => 'vcard',
'|RosterLink`.`rosterask' => 'subscribe')))
->orderby('RosterLink.group', true);
$contactsq = Contact::run_query($query);

2
system/Widget/widgets/Syndication/Syndication.php

@ -25,9 +25,7 @@ class Syndication extends WidgetBase
if(isset($from)) {
// We query the last messages
$query = Post::query()
//->join('Contact', array('Post.jid' => 'Contact.jid'))
->where(array(
'key' => $from,
'jid' => $from,
'public' => 1,
'parentid' => ''))

16
system/Widget/widgets/Vcard/Vcard.php

@ -55,15 +55,14 @@ class Vcard extends WidgetBase
$query = \Contact::query()->select()
->where(array(
'key' => $this->user->getLogin(),
'jid' => $this->user->getLogin()));
'jid' => $this->user->getLogin())
);
$data = \Contact::run_query($query);
if($data) {
$c = $data[0];
}
$c->key->setval($this->user->getLogin());
$c->jid->setval($this->user->getLogin());
$date = strtotime($vcard['date']);
@ -75,16 +74,13 @@ class Vcard extends WidgetBase
$c->gender->setval($vcard['gender']);
$c->marital->setval($vcard['marital']);
if($c->rostersubscription->getval() == false)
$c->rostersubscription->setval('none');
$c->phototype->setval($vcard['phototype']);
$c->photobin->setval($vcard['photobin']);
$c->desc->setval(trim($vcard['desc']));
$c->vcardreceived->setval(0);
if($vcard['public'] == 'true')
$c->public->setval(1);
else
@ -98,7 +94,11 @@ class Vcard extends WidgetBase
function prepareInfos($error = false) {
$query = Contact::query()
->where(array('key' => $this->user->getLogin(), 'jid' => $this->user->getLogin()));
->where(
array(
'jid' => $this->user->getLogin()
)
);
$me = Contact::run_query($query);
$submit = $this->genCallAjax('ajaxVcardSubmit', "movim_parse_form('vcard')");

1
system/Widget/widgets/Wall/Wall.php

@ -87,7 +87,6 @@ class Wall extends WidgetCommon
$query = Post::query()
->join('Contact', array('Post.jid' => 'Contact.jid'))
->where(array(
'Contact`.`key' => $this->user->getLogin(),
'Post`.`jid' => $from,
'Post`.`parentid' => ''))
->orderby('Post.updated', true)

1
themes/movim/config.tpl

@ -3,7 +3,6 @@
<?php $this->widget('Poller');?>
<?php $this->widget('Logout');?>
<?php $this->widget('Chat');?>
<?php /*$this->widget('Log');*/?>
<div id="head">
<?php $this->widget('Profile');?>

25
themes/movim/explore.tpl

@ -0,0 +1,25 @@
<?php /* -*- mode: html -*- */
?>
<?php $this->widget('Poller');?>
<?php $this->widget('Logout');?>
<?php $this->widget('Chat');?>
<div id="head">
<?php $this->widget('Profile');?>
</div>
<div id="main">
<div id="left">
<?php $this->widget('ProfileData');?>
</div>
<div id="center" class="protect black">
<h1><?php echo t('Explore'); ?></h1>
<?php $this->widget('Explore');?>
</div>
</div>
<div id="right">
<?php $this->widget('Notifs');?>
<?php $this->widget('Roster');?>
</div>

1
themes/movim/friend.tpl

@ -11,7 +11,6 @@
<div id="main">
<div id="left">
<?php /*$this->widget('Profile');*/?>
<?php $this->widget('ContactInfo');?>
</div>

Loading…
Cancel
Save