Browse Source

- Merge with edhelas

pull/16/head
Jaussoin Timothée 11 years ago
parent
commit
5be3a15926
  1. 4
      app/models/config/Config.php
  2. 6
      app/models/config/ConfigDAO.php
  3. 1
      app/models/contact/Contact.php
  4. 17
      app/models/contact/ContactDAO.php
  5. 3
      app/models/sessionx/Sessionx.php
  6. 5
      app/models/sessionx/SessionxDAO.php
  7. 38
      app/widgets/AdminMain/adminmain.tpl
  8. 30
      app/widgets/Contact/Contact.php
  9. 37
      app/widgets/Contact/_contact_explore.tpl
  10. 44
      app/widgets/Contact/_contact_public.tpl
  11. 15
      daemon.php
  12. 13
      linker.php
  13. 8
      system/Sessionx.php
  14. 14
      system/Utils.php
  15. 1
      themes/material/css/form.css

4
app/models/config/Config.php

@ -10,7 +10,6 @@ class Config extends Model {
public $maxusers;
public $loglevel;
public $timezone;
public $websocketurl;
public $xmppwhitelist;
public $info;
public $unregister;
@ -36,8 +35,6 @@ class Config extends Model {
{"type":"string", "size":16, "mandatory":true },
"timezone" :
{"type":"string", "size":16, "mandatory":true },
"websocketurl" :
{"type":"string", "size":128, "mandatory":true },
"xmppwhitelist" :
{"type":"text" },
"info" :
@ -63,7 +60,6 @@ class Config extends Model {
$this->maxusers = -1;
$this->loglevel = 'empty';
$this->timezone = 'Etc/GMT';
$this->websocketurl = 'ws://localhost:5280';
$this->xmppwhitelist = '';
$this->info = '';
$this->unregister = false;

6
app/models/config/ConfigDAO.php

@ -4,7 +4,6 @@ namespace Modl;
class ConfigDAO extends SQL {
function set(Config $c) {
\movim_log('hop');
$this->_sql = '
update config
set environment = :environment,
@ -14,7 +13,6 @@ class ConfigDAO extends SQL {
maxusers = :maxusers,
loglevel = :loglevel,
timezone = :timezone,
websocketurl = :websocketurl,
xmppwhitelist = :xmppwhitelist,
info = :info,
unregister = :unregister,
@ -33,7 +31,6 @@ class ConfigDAO extends SQL {
'maxusers' => $c->maxusers,
'loglevel' => $c->loglevel,
'timezone' => $c->timezone,
'websocketurl' => $c->websocketurl,
'xmppwhitelist'=> $c->xmppwhitelist,
'info' => $c->info,
'unregister' => $c->unregister,
@ -68,7 +65,6 @@ class ConfigDAO extends SQL {
maxusers,
loglevel,
timezone,
websocketurl,
xmppwhitelist,
info,
unregister,
@ -86,7 +82,6 @@ class ConfigDAO extends SQL {
:maxusers,
:loglevel,
:timezone,
:websocketurl,
:xmppwhitelist,
:info,
:unregister,
@ -107,7 +102,6 @@ class ConfigDAO extends SQL {
'maxusers' => $c->maxusers,
'loglevel' => $c->loglevel,
'timezone' => $c->timezone,
'websocketurl' => $c->websocketurl,
'xmppwhitelist'=> $c->xmppwhitelist,
'info' => $c->info,
'unregister' => $c->unregister,

1
app/models/contact/Contact.php

@ -365,6 +365,7 @@ class Contact extends Model {
if(isset($this->date)
&& $this->date != '0000-00-00T00:00:00+0000'
&& $this->date != '1970-01-01 00:00:00'
&& $this->date != '1970-01-01 01:00:00'
&& $this->date != '1970-01-01T00:00:00+0000') {
$age = intval(substr(date('Ymd') - date('Ymd', strtotime($this->date)), 0, -4));
if($age != 0)

17
app/models/contact/ContactDAO.php

@ -373,7 +373,7 @@ class ContactDAO extends SQL {
left outer join privacy
on contact.jid = privacy.pkey
where privacy.value = 1
order by created desc';
order by updated desc';
if($limitr)
$this->_sql = $this->_sql.' limit '.$limitr.' offset '.$limitf;
@ -381,6 +381,21 @@ class ContactDAO extends SQL {
$this->prepare('Contact');
return $this->run('Contact');
}
function countAllPublic() {
$this->_sql =
'select count(*) from contact
left outer join privacy
on contact.jid = privacy.pkey
where privacy.value = 1';
$this->prepare('Contact');
$results = $this->run(null, 'array');
$results = array_values($results[0]);
return (int)$results[0];
}
function cleanRoster() {
$this->_sql = '

3
app/models/sessionx/Sessionx.php

@ -11,7 +11,6 @@ class Sessionx extends Model {
public $rid;
public $sid;
public $id;
public $url;
public $port;
public $host;
public $domain;
@ -40,8 +39,6 @@ class Sessionx extends Model {
{"type":"string", "size":64 },
"id" :
{"type":"int", "size":8, "mandatory":true },
"url" :
{"type":"string", "size":128, "mandatory":true },
"port" :
{"type":"int", "size":5, "mandatory":true },
"host" :

5
app/models/sessionx/SessionxDAO.php

@ -13,7 +13,6 @@ class SessionxDAO extends SQL {
rid = :rid,
sid = :sid,
id = :id,
url = :url,
port = :port,
host = :host,
domain = :domain,
@ -35,7 +34,6 @@ class SessionxDAO extends SQL {
'rid' => $s->rid,
'sid' => $s->sid,
'id' => $s->id,
'url' => $s->url,
'port' => $s->port,
'host' => $s->host,
'domain' => $s->domain,
@ -60,7 +58,6 @@ class SessionxDAO extends SQL {
rid,
sid,
id,
url,
port,
host,
domain,
@ -78,7 +75,6 @@ class SessionxDAO extends SQL {
:rid,
:sid,
:id,
:url,
:port,
:host,
:domain,
@ -99,7 +95,6 @@ class SessionxDAO extends SQL {
'rid' => $s->rid,
'sid' => $s->sid,
'id' => $s->id,
'url' => $s->url,
'port' => $s->port,
'host' => $s->host,
'domain' => $s->domain,

38
app/widgets/AdminMain/adminmain.tpl

@ -76,44 +76,6 @@
</div>
<br />
<h3>{$c->__('websocket.title')}</h3>
<!--{if="!$c->testBosh($conf->boshurl)"}
<div class="message error">
{$c->__('bosh.not_recheable')}
</div>
{/if}-->
<div>
<input type="text" id="websocketurl" name="websocketurl" placeholder="{$c->__('websocket.label')}" value="{$conf->websocketurl}"/>
<label for="websocketurl">{$c->__('websocket.label')}</label>
</div>
{if="isset($websockets)"}
<div class="element simple">
<label for="websocketurl">
{$c->__('websocket.publics')} -
<a target="_blank" href="https://api.movim.eu/">Movim API</a>
</label>
<dl>
{loop="$websockets->websockets"}
<dt>{$value->name}</dt>
<dd>{$value->url}</dd>
{/loop}
</dl>
</div>
{/if}
<ul class="thick">
<li class="condensed">
<span class="icon bubble color orange">
<i class="md md-warning"></i>
</span>
<span>{$c->__('websocket.info')}: <code>ws(s)://domain:port</code></span>
<p>{$c->__('websocket.save_info')}</p>
</li>
</ul>
<h3>{$c->__('whitelist.title')}</h3>

30
app/widgets/Contact/Contact.php

@ -7,6 +7,8 @@ use Moxl\Xec\Action\Pubsub\GetItems;
class Contact extends WidgetBase
{
private $_paging = 10;
function load()
{
$this->registerEvent('roster_updateitem_handle', 'onContactEdited');
@ -151,10 +153,10 @@ class Contact extends WidgetBase
{
if($jid == null) {
$cd = new \modl\ContactDAO();
$users = $cd->getAllPublic(0, 10);
if($users != null){
$count = $cd->countAllPublic();
if($count != 0){
$view = $this->tpl();
$view->assign('users', array_reverse($users));
$view->assign('users', $this->preparePublic());
return $view->draw('_contact_explore', true);
} else {
return '';
@ -166,6 +168,28 @@ class Contact extends WidgetBase
}
}
function ajaxPublic($page = 0)
{
$validate_page = Validator::int();
if(!$validate_page->validate($page)) return;
RPC::call('MovimTpl.fill', '#public_list', $this->preparePublic($page));
}
private function preparePublic($page = 0)
{
$cd = new \modl\ContactDAO();
$users = $cd->getAllPublic($page*$this->_paging, $this->_paging);
$count = $cd->countAllPublic();
if($users != null){
$view = $this->tpl();
$view->assign('pages', array_fill(0, (int)($count/$this->_paging), 'p'));
$view->assign('users', array_reverse($users));
$view->assign('page', $page);
return $view->draw('_contact_public', true);
}
}
function prepareContact($jid)
{
if(!$this->validateJid($jid)) return;

37
app/widgets/Contact/_contact_explore.tpl

@ -1,39 +1,6 @@
<br />
<h2>{$c->__('explore')}</h2>
<ul class="flex card active thick">
{loop="$users"}
<li class="{if="$value->description != ''"}condensed{/if} block" style="background-image: url();" onclick="Contact_ajaxGetContact('{$value->jid}');">
{$url = $value->getPhoto('s')}
{if="$url"}
<span class="icon bubble">
<img src="{$url}">
</span>
{else}
<span class="icon bubble color {$value->jid|stringToColor}">
<i class="md md-person"></i>
</span>
{/if}
<span>{$value->getTrueName()}</span>
{if="$value->getAge()"}
<span class="info">{$c->__('age.years', $value->getAge())}</span>
{/if}
{if="$value->getGender()"}
<span class="info">{$value->getGender()}</span>
{/if}
<!--
{if="$value->getMarital()"}
<span class="info">{$value->getMarital()}</span>
{/if}
-->
{if="$value->description != ''"}
<p>
{$value->description|strip_tags}
</p>
{/if}
</li>
{/loop}
<ul id="public_list" class="flex card active middle">
{$users}
</ul>

44
app/widgets/Contact/_contact_public.tpl

@ -0,0 +1,44 @@
{loop="$users"}
<li class="{if="$value->description != ''"}condensed{/if} block" style="background-image: url();" onclick="Contact_ajaxGetContact('{$value->jid}');">
{$url = $value->getPhoto('s')}
{if="$url"}
<span class="icon bubble">
<img src="{$url}">
</span>
{else}
<span class="icon bubble color {$value->jid|stringToColor}">
<i class="md md-person"></i>
</span>
{/if}
<span>{$value->getTrueName()}</span>
{if="$value->getAge()"}
<span class="info">{$c->__('age.years', $value->getAge())}</span>
{/if}
{if="$value->getGender()"}
<span class="info">{$value->getGender()}</span>
{/if}
<!--
{if="$value->getMarital()"}
<span class="info">{$value->getMarital()}</span>
{/if}
-->
{if="$value->description != ''"}
<p>
{$value->description|strip_tags}
</p>
{/if}
</li>
{/loop}
{if="$pages"}
<li class="block condensed">
<span class="icon gray">
<i class="md md-my-library-books"></i>
</span>
{loop="$pages"}
<a onclick="Contact_ajaxPublic('{$key}');" class="button flat {if="$key == $page"}on{/if}">{$key+1}</a>
{/loop}
</li>
{/if}

15
daemon.php

@ -24,6 +24,21 @@ if($argsize == 2) {
exit;
}
$md = Modl\Modl::getInstance();
$infos = $md->check();
if($infos != null) {
echo colorize("The database need to be updated before running the daemon\n", 'green');
foreach($infos as $i) {
echo colorize($i."\n", 'blue');
}
echo colorize("\nTo update the database run\n", 'green');
echo colorize("php mud.php db set\n", 'purple');
break;
}
$loop = \React\EventLoop\Factory::create();
$core = new Core($loop, $argv[1], $argv[2]);
$app = new HttpServer(new WsServer($core));

13
linker.php

@ -15,7 +15,6 @@ $dnsResolverFactory = new React\Dns\Resolver\Factory();
$dns = $dnsResolverFactory->createCached('8.8.8.8', $loop);
$connector = new React\SocketClient\Connector($loop, $dns);
//$connector = new Ratchet\Client\Factory($loop);
$stdin = new React\Stream\Stream(STDIN, $loop);
fwrite(STDERR, colorize(getenv('sid'), 'yellow')." widgets before : ".\sizeToCleanSize(memory_get_usage())."\n");
@ -32,8 +31,7 @@ $parser = new \Moxl\Parser;
$buffer = '';
$stdin_behaviour = function ($data) use (&$conn, $loop, &$buffer, &$connector, &$xmpp_behaviour, &$parser) {
//if(!isset($buffer)) $buffer = '';
$stdin_behaviour = function ($data) use (&$conn, $loop, &$buffer, &$connector, &$xmpp_behaviour, &$parser) {
if(substr($data, -1) == "") {
$messages = explode("", $buffer . substr($data, 0, -1));
$buffer = '';
@ -55,7 +53,6 @@ $stdin_behaviour = function ($data) use (&$conn, $loop, &$buffer, &$connector, &
$domain = \Moxl\Utils::getDomain($msg->host);
#fwrite(STDERR, colorize('open a socket to '.$domain, 'yellow')." : ".colorize('sent to XMPP', 'green')."\n");
$connector->create($domain, 5222)->then($xmpp_behaviour);
//$connector($config->websocketurl, array('xmpp'))->then($xmpp_behaviour);
}
} else {
return;
@ -79,7 +76,6 @@ $stdin_behaviour = function ($data) use (&$conn, $loop, &$buffer, &$connector, &
if(!empty($xml) && $conn) {
$conn->write(trim($xml));
//$conn->send(trim($xml));
#fwrite(STDERR, colorize(trim($xml), 'yellow')." : ".colorize('sent to XMPP', 'green')."\n");
}
}
@ -91,7 +87,6 @@ $stdin_behaviour = function ($data) use (&$conn, $loop, &$buffer, &$connector, &
};
$xmpp_behaviour = function (React\Stream\Stream $stream) use (&$conn, $loop, &$stdin, $stdin_behaviour, $parser) {
//$xmpp_behaviour = function (Ratchet\Client\WebSocket $stream) use (&$conn, $loop, &$stdin, $stdin_behaviour, $parser) {
$conn = $stream;
fwrite(STDERR, colorize(getenv('sid'), 'yellow')." : ".colorize('linker launched', 'blue')."\n");
fwrite(STDERR, colorize(getenv('sid'), 'yellow')." launched : ".\sizeToCleanSize(memory_get_usage())."\n");
@ -101,8 +96,7 @@ $xmpp_behaviour = function (React\Stream\Stream $stream) use (&$conn, $loop, &$s
// We define a huge buffer to prevent issues with SSL streams, see https://bugs.php.net/bug.php?id=65137
$conn->bufferSize = 1024*32;
//$conn->on('message', function($message) use (&$conn, $loop, $parser, $stream) {
$conn->on('data', function($message) use (&$conn, $loop, $parser/*, $stream*/) {
$conn->on('data', function($message) use (&$conn, $loop, $parser) {
if(!empty($message)) {
$restart = false;
@ -127,8 +121,6 @@ $xmpp_behaviour = function (React\Stream\Stream $stream) use (&$conn, $loop, &$s
fwrite(STDERR, colorize(getenv('sid'), 'yellow')." ".$parser->getError()."\n");
}
//\Moxl\Xec\Handler::handleStanza($message);
if($restart) {
$session = \Sessionx::start();
\Moxl\Stanza\Stream::init($session->host);
@ -148,7 +140,6 @@ $xmpp_behaviour = function (React\Stream\Stream $stream) use (&$conn, $loop, &$s
if(!empty($xml)) {
$conn->write(trim($xml));
//$conn->send(trim($xml));
#fwrite(STDERR, colorize(trim($xml), 'yellow')." : ".colorize('sent to XMPP', 'green')."\n");
}
}

8
system/Sessionx.php

@ -32,7 +32,6 @@ class Sessionx {
private $_resource;
private $_hash;
private $_sid;
private $_url;
private $_port;
private $_host;
private $_domain;
@ -86,7 +85,6 @@ class Sessionx {
$s->rid = $this->_rid;
$s->sid = $this->_sid;
$s->id = $this->_id;
$s->url = $this->_url;
$s->port = $this->_port;
$s->host = $this->_host;
$s->domain = $this->_domain;
@ -99,10 +97,6 @@ class Sessionx {
}
public function init($user, $pass, $host, $domain) {
$cd = new \Modl\ConfigDAO();
$config = $cd->get();
$this->_url = $config->websocketurl;
$this->_port = 5222;
$this->_host = $host;
$this->_domain = $domain;
@ -131,7 +125,6 @@ class Sessionx {
$this->_rid = $session->rid;
$this->_sid = $session->sid;
$this->_id = $session->id;
$this->_url = $session->url;
$this->_port = $session->port;
$this->_host = $session->host;
$this->_domain = $session->domain;
@ -155,7 +148,6 @@ class Sessionx {
in_array(
$key,
array(
'url',
'port',
'id',
'host',

14
system/Utils.php

@ -562,6 +562,20 @@ function generateKey($size) {
return $hash;
}
/*
* @desc Get the range aroung a position with a radius
*/
function geoRadius($latitude, $longitude, $radius) {
$lat_range = $range/69.172;
$lon_range = abs($range/(cos($latitude) * 69.172));
$min_lat = number_format($latitude - $lat_range, "4", ".", "");
$max_lat = number_format($latitude + $lat_range, "4", ".", "");
$min_lon = number_format($longitude - $lon_range, "4", ".", "");
$max_lon = number_format($longitude + $lon_range, "4", ".", "");
return array($min_lat, $max_lat, $min_lon, $max_lon);
}
/*
* @desc Request a simple url
*/

1
themes/material/css/form.css

@ -273,6 +273,7 @@ input[type=button]:hover {
}
.button.flat:hover,
.button.flat.on,
input[type=button].flat:hover {
background-color: rgba(153, 153, 153, 0.2);
}

Loading…
Cancel
Save