Browse Source

- Fix the Cache system

- Remove the ContactVcard widget and move the datas to Contact Summary
- Add Days in Chat
- Fix a bug in the Logout widget
- Fix a bug in Vcard submission (XML characters)
pull/5/head
Jaussoin Timothée 14 years ago
parent
commit
16ad39c6f1
  1. 3
      index.php
  2. 8
      jajax.php
  3. 4
      loader.php
  4. 6
      system/Event.php
  5. 2
      system/Jabber.php
  6. 5
      system/RPC.php
  7. 37
      system/Utils.php
  8. 53
      system/Widget/WidgetBase.php
  9. 60
      system/Widget/WidgetWrapper.php
  10. 15
      system/Widget/widgets/Chat/Chat.php
  11. 58
      system/Widget/widgets/ContactSummary/ContactSummary.php
  12. 16
      system/Widget/widgets/ContactSummary/contactsummary.css
  13. BIN
      system/Widget/widgets/ContactSummary/img/address.png
  14. BIN
      system/Widget/widgets/ContactSummary/img/birth.png
  15. BIN
      system/Widget/widgets/ContactSummary/img/hearth.png
  16. BIN
      system/Widget/widgets/ContactSummary/img/mobile.png
  17. BIN
      system/Widget/widgets/ContactSummary/img/place.png
  18. 3
      system/Widget/widgets/Feed/Feed.php
  19. 4
      system/Widget/widgets/Log/Log.php
  20. 5
      system/Widget/widgets/Logout/Logout.php
  21. 5
      system/Widget/widgets/Profile/Profile.php
  22. 11
      system/Widget/widgets/Profile/profile.css
  23. 9
      system/Widget/widgets/Vcard/Vcard.php
  24. 26
      system/Widget/widgets/Wall/Wall.php
  25. 2
      system/js/movim.js
  26. 2
      themes/movim/css/style2.css
  27. 4
      themes/movim/friend.tpl
  28. 6
      themes/movim/img/default.svg
  29. 2
      themes/movim/profile.tpl

3
index.php

@ -56,6 +56,9 @@ if(!file_exists("config/conf.xml")) {
$rqst = new ControllerMain();
$rqst->handle();
$widgets = WidgetWrapper::getInstance(false);
$widgets->iterateCached('saveCache');
// Closing stuff
WidgetWrapper::destroyInstance();
global $sdb;

8
jajax.php

@ -27,4 +27,12 @@ $polling = true;
$rpc = new RPC();
$rpc->handle();
$widgets = WidgetWrapper::getInstance(false);
$widgets->iterateCached('saveCache');
// Closing stuff
WidgetWrapper::destroyInstance();
global $sdb;
$sdb->close();
?>

4
loader.php

@ -8,8 +8,8 @@ define('PROPERTIES_PATH', BASE_PATH.'page/properties/');
define('THEMES_PATH', BASE_PATH . 'themes/');
define('USERS_PATH', BASE_PATH . 'user/');
//define('DB_DEBUG', true);
//define('DB_LOGFILE', BASE_PATH . 'log/queries.log');
define('DB_DEBUG', true);
define('DB_LOGFILE', BASE_PATH . 'log/queries.log');
// Loads up all system libraries.
require_once(LIB_PATH . "Lang/i18n.php");

6
system/Event.php

@ -28,6 +28,12 @@ class Event
'type' => $type,
'data' => $event,
)));
$widgets->iterateAll('isEvents', array(
array(
'type' => $type,
'data' => $event,
)));
// Outputting any RPC calls.
RPC::commit();

2
system/Jabber.php

@ -381,7 +381,6 @@ class Jabber
} 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') {
movim_log($payload);
$this->getWallItem($this->getCleanJid(), $payload['pubsub']['publish']['item']['@attributes']['id']);
}
$this->getComments($payload['@attributes']['from'], $id);
@ -390,7 +389,6 @@ class Jabber
}
}
elseif(isset($payload['pubsub']) && isset($payload['error'])) {
movim_log($payload);
list($xmlns, $parent) = explode("/", $payload['pubsub']['items']['@attributes']['node']);
if(isset($payload['error']['item-not-found'])) {
$c = new PostHandler();

5
system/RPC.php

@ -93,11 +93,6 @@ class RPC
$user = new User();
$xmppSession = Jabber::getInstance($user->getLogin());
$xmppSession->pingServer();
// We cache the widgets
$widgets = WidgetWrapper::getInstance(false);
foreach($widgets->get_registered_widgets() as $widget_name)
$widgets->run_widget($widget_name, 'saveCache');
} else {
$xml = file_get_contents('php://input');
$request = simplexml_load_string($xml);

37
system/Utils.php

@ -117,33 +117,38 @@ function prepareString($string) {
* @param timestamp $string
* @return string
*/
function prepareDate($time) {
function prepareDate($time, $hours = true) {
$today = strtotime(date('M j, Y'));
$reldays = ($time - $today)/86400;
if ($reldays >= 0 && $reldays < 1) {
return t('Today') .' - '. date('H:i', $time);
$date = t('Today');
} else if ($reldays >= 1 && $reldays < 2) {
return t('Tomorrow') .' - '. date('H:i', $time);
$date = t('Tomorrow');
} else if ($reldays >= -1 && $reldays < 0) {
return t('Yesterday') .' - '. date('H:i', $time);
}
$date = t('Yesterday');
} else {
if (abs($reldays) < 7) {
if ($reldays > 0) {
$reldays = floor($reldays);
return 'In ' . $reldays . ' '.t('day') . ($reldays != 1 ? 's' : '');
if (abs($reldays) < 7) {
if ($reldays > 0) {
$reldays = floor($reldays);
$date = 'In ' . $reldays . ' '.t('day') . ($reldays != 1 ? 's' : '');
} else {
$reldays = abs(floor($reldays));
$date = t(' %d days ago', $reldays);
}
}
if (abs($reldays) < 182) {
$date = date('l, j F',$time ? $time : time());
} else {
$reldays = abs(floor($reldays));
return t(' %d days ago', $reldays) .' - '. date('H:i', $time);
$date = date('l, j F, Y',$time ? $time : time());
}
}
if (abs($reldays) < 182) {
return date('l, j F - H:i',$time ? $time : time());
} else {
return date('l, j F, Y - H:i',$time ? $time : time());
}
if($hours)
$date .= ' - '. date('H:i', $time);
return $date;
}
/**

53
system/Widget/WidgetBase.php

@ -98,28 +98,22 @@ class WidgetBase
return $path;
}
/**
* Set the cache element to true to cache the widget at the end of the PHP exec
*/
public function setCacheCall()
private function saveCacheFile()
{
if($this->cached) {
$widgets = WidgetWrapper::getInstance(false);
$widgets->set_cached_widget($this->name);
}
Logger::log(2, 'Cache: Update of '.$this->name.' widget - '.$this->user->getLogin());
$fp = fopen(BASE_PATH."/cache/".md5($this->name.$this->user->getLogin()).".thtml", "w");
ob_start();
$this->build();
$out = ob_get_clean();
fwrite($fp, trim(preg_replace( '/\s+/', ' ',$out)));
fclose($fp);
return $out;
}
public function saveCache()
{
$widgets = WidgetWrapper::getInstance(false);
if($widgets->get_cached_widget($this->name) == true) {
$fp = fopen(BASE_PATH."/cache/".md5($this->name.$this->user->getLogin()).".thtml", "w");
ob_start();
$this->build();
$out = ob_get_clean();
fwrite($fp, trim(preg_replace( '/\s+/', ' ',$out)));
fclose($fp);
}
{
$this->saveCacheFile();
}
public function getCache()
@ -133,18 +127,18 @@ class WidgetBase
else {
$widgets = WidgetWrapper::getInstance(false);
if($this->cached == true) {
$fp = fopen($file, "w");
ob_start();
$this->build();
$out = ob_get_clean();
fwrite($fp, trim(preg_replace( '/\s+/', ' ',$out)));
fclose($fp);
$out = $this->saveCacheFile();
echo $out;
}
else
$this->build();
}
}
public function getName()
{
return $this->name;
}
/**
* Generates and print an ajax call.
@ -237,7 +231,7 @@ class WidgetBase
if(is_array($this->events) && array_key_exists($proto['type'], $this->events)) {
// If a new event came to the widget, we update the cache
$this->setCacheCall();
//$this->setCacheCall();
$returns = array();
foreach($this->events[$proto['type']] as $handler) {
@ -247,6 +241,15 @@ class WidgetBase
return $returns;
}
}
public function isEvents($proto)
{
if(is_array($this->events) &&
array_key_exists($proto['type'], $this->events) &&
$this->cached == true) {
return true;
}
}
/**
* returns the list of javascript files to be loaded for the widget.

60
system/Widget/WidgetWrapper.php

@ -23,9 +23,11 @@
class WidgetWrapper
{
private $register_widgets;
private $all_widgets = array();
private $loaded_widgets = array();
private $loaded_widgets_old;
private $loaded_widgets_cached = array();
//private $loaded_widgets_cached = array();
private $cached_widgets;
private static $instance;
@ -46,13 +48,14 @@ class WidgetWrapper
$this->loaded_widgets_old = $widgets;
}
$this->register_widgets = array();
$this->all_widgets = array();
$widgets_dir = scandir(LIB_PATH ."Widget/widgets/");
foreach($widgets_dir as $widget_dir) {
if(is_dir(LIB_PATH ."Widget/widgets/".$widget_dir) &&
$widget_dir != '..' &&
$widget_dir != '.')
array_push($this->register_widgets, $widget_dir);
array_push($this->all_widgets, $widget_dir);
}
}
@ -61,7 +64,6 @@ class WidgetWrapper
if(!is_object(self::$instance)) {
self::$instance = new WidgetWrapper($register);
}
//movim_log(self::$instance);
return self::$instance;
}
@ -100,29 +102,20 @@ class WidgetWrapper
}
}
function get_registered_widgets()
function get_all_widgets()
{
return $this->register_widgets;
return $this->all_widgets;
}
function set_cached_widget($widget_name)
function get_cached_widgets()
{
//if(in_array($widget_name, $this->loaded_widgets))
$this->loaded_widgets_cached[$widget_name] = true;
}
function get_cached_widget($widget_name)
{
if($this->loaded_widgets_cached[$widget_name] == true)
return true;
else
return false;
return $this->cached_widgets;
}
/**
* Loads a widget and returns it.
*/
private function load_widget($widget_name)
public function load_widget($widget_name)
{
// Attempting to load the user's widgets in priority
$widget_path = "";
@ -158,7 +151,7 @@ class WidgetWrapper
*/
function run_widget($widget_name, $method, array $params = NULL)
{
if(//$this->register_widgets &&
if($this->register_widgets &&
!in_array($widget_name, $this->loaded_widgets)) {
$this->loaded_widgets[] = $widget_name;
}
@ -194,6 +187,35 @@ class WidgetWrapper
return $buff;
}
function iterateAll($method, array $params = NULL) {
$widgets = $this->get_all_widgets();
$isevent = array();
foreach($widgets as $widget) {
if($this->run_widget($widget, $method, $params))
$isevent[$widget] = true;
}
if(!empty($isevent))
$this->cached_widgets = $isevent;
return $isevent;
}
function iterateCached($method, array $params = NULL)
{
$buff = array();
$widgets = $this->cached_widgets;
if(!empty($widgets)) {
foreach($widgets as $widget => $val) {
$buff[] = $this->run_widget($widget, $method, $params);
}
}
return $buff;
}
/**
* Returns the list of loaded CSS.

15
system/Widget/widgets/Chat/Chat.php

@ -77,9 +77,7 @@ class Chat extends WidgetBase
RPC::call('scrollAllTalks');
$contact->chaton = 1;
$sdb->save($contact);
}
if($message->getData('body') != '') {
}else if($message->getData('body') != '') {
$html = $this->prepareMessage($message);
@ -236,15 +234,20 @@ class Chat extends WidgetBase
array('to' => $contact->getData('jid') , '|from' => $contact->getData('jid'))
)
)
->orderby('published', true)
->orderby('published', false)
->limit(0, 20);
$messages = Message::run_query($query);
if($messages != false) {
$messages = array_reverse($messages);
foreach($messages as $m)
$day = '';
foreach($messages as $m) {
$messageshtml .= $this->prepareMessage($m);
if($day != date('d',strtotime($m->getData('published')))) {
$messageshtml .= '<div class="message presence">'.prepareDate(strtotime($m->getData('published')), false).'</div>';
$day = date('d',strtotime($m->getData('published')));
}
}
}
$style = '';

58
system/Widget/widgets/ContactSummary/ContactSummary.php

@ -37,9 +37,20 @@ class ContactSummary extends WidgetBase
{
$this->xmpp->getVCard($jid);
}
private function testIsSet($element)
{
if(isset($element) && $element != '')
return true;
else
return false;
}
function prepareContactSummary($contact)
{
$gender = getGender();
$marital = getMarital();
$presence = PresenceHandler::getPresence($contact->getData('jid'), true);
$html ='<h1>'.$contact->getTrueName().'</h1><img src="'.$contact->getPhoto().'"/>';
@ -48,6 +59,53 @@ class ContactSummary extends WidgetBase
if($presence != NULL)
$html .= '<div id="status">'.$presence['status'].'</div>';
$html .='<h2>'.t('General Informations').'</h2>';
if($this->testIsSet($contact->getData('name')))
$html .= $contact->getData('name').'<br />';
if($contact->getData('gender') != 'N' && $this->testIsSet($contact->getData('gender')))
$html .= $gender[$contact->getData('gender')].'<br />';
if($contact->getData('marital') != 'none' && $this->testIsSet($contact->getData('marital')))
$html .= '<span class="hearth"></span>'.$marital[$contact->getData('marital')].'<br />';
if($contact->getData('date') != '0000-00-00' && $this->testIsSet($contact->getData('date')))
$html .= '<span class="birth"></span>'.date('j M Y',strtotime($contact->getData('date'))).'<br />';
if($this->testIsSet($contact->getData('jid')))
$html .= '<span class="address"></span>'.$contact->getData('jid').'<br />';
if($this->testIsSet($contact->getData('url')))
$html .= '<span class="website"></span>'.'<a target="_blank" href="'.$contact->getData('url').'">'.$contact->getData('url').'</a>';
//if($this->testIsSet($contact->getData('desc')))
// $html .= t('About Me').prepareString($contact->getData('desc'));
if($presence['node'] != '' && $presence['ver'] != '') {
$clienttype =
array(
'bot' => t('Bot'),
'pc' => t('Desktop'),
'phone' => t('Phone')
);
$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>';
}
if($this->testIsSet($caps->getData('name')))
$cinfos .= $caps->getData('name').'<br />';
if($cinfos != "")
$html .='<h2>'.t('Client Informations').'</h2>' . $cinfos;
}
return $html;
}

16
system/Widget/widgets/ContactSummary/contactsummary.css

@ -1,6 +1,6 @@
#contactsummary {
text-align: center;
padding-bottom: 10px;
text-align: center;
}
#contactsummary h1 {
@ -14,6 +14,7 @@
#contactsummary img {
max-width: 150px;
max-height: 150px;
margin: 0 auto;
}
@ -21,5 +22,16 @@
color: #444;
padding: 3px;
font-size: 11px;
margin-right: 3px;
}
#contactsummary span {
background-repeat: no-repeat;
background-position: 0px 12px;
padding: 8px;
}
#contactsummary span.birth { background-image: url(img/birth.png); }
#contactsummary span.address { background-image: url(img/address.png); }
#contactsummary span.website { background-image: url(img/place.png); }
#contactsummary span.hearth { background-image: url(img/hearth.png); }
#contactsummary span.mobile { background-image: url(img/mobile.png); }

BIN
system/Widget/widgets/ContactSummary/img/address.png

After

Width: 10  |  Height: 10  |  Size: 271 B

BIN
system/Widget/widgets/ContactSummary/img/birth.png

After

Width: 10  |  Height: 10  |  Size: 228 B

BIN
system/Widget/widgets/ContactSummary/img/hearth.png

After

Width: 10  |  Height: 10  |  Size: 307 B

BIN
system/Widget/widgets/ContactSummary/img/mobile.png

After

Width: 10  |  Height: 10  |  Size: 227 B

BIN
system/Widget/widgets/ContactSummary/img/place.png

After

Width: 10  |  Height: 10  |  Size: 432 B

3
system/Widget/widgets/Feed/Feed.php

@ -10,6 +10,7 @@ class Feed extends WidgetCommon {
$this->registerEvent('nocomment', 'onNoComment');
$this->registerEvent('nocommentstream', 'onNoCommentStream');
$this->registerEvent('stream', 'onStream');
$this->registerEvent('vcard', 'onVcard');
$this->cached = true;
}
@ -25,6 +26,8 @@ class Feed extends WidgetCommon {
}
}
function onVcard($contact) { }
function prepareFeed($start) {
$query = Post::query()
->where(array('key' => $this->user->getLogin(), 'parentid' => ''))

4
system/Widget/widgets/Log/Log.php

@ -40,11 +40,11 @@ class Log extends WidgetBase
function onEvent($data)
{
RPC::call('movim_prepend',
/* RPC::call('movim_prepend',
'log_content',
RPC::cdata("<span>%s&gt; data : </span>%s<br />",
date('H:i:s'),
var_export($data, true)));
var_export($data, true)));*/
}
}

5
system/Widget/widgets/Logout/Logout.php

@ -29,7 +29,7 @@ class Logout extends WidgetBase
$this->registerEvent('serverdisconnect', 'onPostDisconnect'); // When you're kicked out
$this->registerEvent('mypresence', 'onMyPresence');
$this->cached = true;
//$this->cached = true;
}
function onMyPresence()
@ -63,6 +63,7 @@ class Logout extends WidgetBase
{
// We update the cache with our status and presence
$presence = Cache::c('presence');
movim_log($presence);
if($show == "boot") $show = $presence['show'];
Cache::c(
'presence',
@ -102,7 +103,7 @@ class Logout extends WidgetBase
</div>
';
$presence = Cache::c('presence');
if($presence['boot'])
if($presence['boot'] == true)
$html .= '<script type="text/javascript">setTimeout(\''.$this->genCallAjax('ajaxSetStatus', '"boot"').'\', 5000);</script>';
return $html;

5
system/Widget/widgets/Profile/Profile.php

@ -62,7 +62,8 @@ class Profile extends WidgetBase
if(isset($me[0])) {
$me = $me[0];
$html = '
$html ='<h1>'.$me->getTrueName().'</h1><img src="'.$me->getPhoto().'"/>';
/*$html = '
<table>
<tr>
<td>
@ -73,7 +74,7 @@ class Profile extends WidgetBase
</td>
</tr>
</table>
';
';*/
$html .= '
<input
type="text"

11
system/Widget/widgets/Profile/profile.css

@ -9,14 +9,17 @@
}
#profile h1 {
margin: 0px;
line-height: 1.3em;
padding: 0px;
padding-left: 10px;
border: none;
margin-bottom: 5px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
#profile img {
width: 70px;
max-width: 150px;
margin: 0 auto;
}
#profile #status {

9
system/Widget/widgets/Vcard/Vcard.php

@ -26,7 +26,7 @@ class Vcard extends WidgetBase
$this->addcss('vcard.css');
$this->addjs('vcard.js');
$this->cached = true;
//$this->cached = true;
}
function onMyVcardReceived()
@ -35,7 +35,10 @@ class Vcard extends WidgetBase
RPC::call('movim_fill', 'vcard', RPC::cdata($html));
}
function ajaxVcardSubmit($vcard) {
function ajaxVcardSubmit($vcard)
{
foreach($vcard as $key => $value)
$vcard[$key] = rawurldecode($value);
# Format it ISO 8601:
$vcard['vCardBDay'] = $vcard['vCardBYear'].'-'.$vcard['vCardBMonth'].'-'.$vcard['vCardBDay'];
$this->xmpp->updateVcard($vcard);
@ -196,7 +199,7 @@ class Vcard extends WidgetBase
function build()
{
?>
<div class="tabelem" title="<?php echo t('Profile'); ?>" id="vcard">
<div class="tabelem" title="<?php echo t('Edit my Profile'); ?>" id="vcard">
<?php
echo $this->prepareInfos();
?>

26
system/Widget/widgets/Wall/Wall.php

@ -45,9 +45,10 @@ class Wall extends WidgetCommon
}
function onNoStream() {
RPC::call('hideWall');
$html = '<div style="padding: 1.5em; text-align: center;">Ain\'t Nobody Here But Us Chickens...</div>';
RPC::call('movim_fill', 'wall', RPC::cdata($html));
RPC::commit();
}
}
function onStream($payload) {
$html = '';
@ -71,15 +72,16 @@ class Wall extends WidgetCommon
'key' => $this->user->getLogin(),
'parentid' => '',
'jid' => $payload["@attributes"]["from"]))
->orderby('updated', true);
->orderby('updated', true)
->limit('0', '20');
$messages = Post::run_query($query);
if($messages == false) {
RPC::call('hideWall');
$this->onNoStream();
} else {
$html = '';
foreach(array_slice($messages, 0, 20) as $message) {
foreach($messages as $message) {
$html .= $this->preparePost($message);
}
echo $html;
@ -115,22 +117,28 @@ class Wall extends WidgetCommon
</a>
<br /><br />-->
<?php
global $sdb;
$messages = $sdb->select('Post', array('key' => $this->user->getLogin(), 'jid' => $_GET['f'], 'parentid' => ''), 'updated', true);
$query = Post::query()
->where(array(
'key' => $this->user->getLogin(),
'parentid' => '',
'jid' => $_GET['f']))
->orderby('updated', true)
->limit('0', '20');
$messages = Post::run_query($query);
if($messages == false) {
?>
<script type="text/javascript">
<?php echo 'setTimeout(\''.$this->genCallAjax('ajaxWall', '"'.$_GET['f'].'"').'\', 500);'; ?>
</script>
<div style="padding: 1em; text-align: center;">
<div style="padding: 1.5em; text-align: center;">
<?php echo t('Loading the contact feed ...'); ?>
</div>
<?php
} else {
$html = '';
foreach(array_slice($messages, 0, 20) as $message) {
foreach($messages as $message) {
$html .= $this->preparePost($message);
}
echo $html;

2
system/js/movim.js

@ -50,7 +50,7 @@ function movim_parse_form(formname) {
var data = H();
for(var i = 0; i < form.elements.length; i++) {
data.set(form.elements[i].name,
form.elements[i].value);
encodeURIComponent(form.elements[i].value));
}
return data;
}

2
themes/movim/css/style2.css

@ -155,7 +155,7 @@ ul.clean li {
width: 599px;
background-color: white;
border-left: 1px solid #DDD;
padding-top: 40px;
padding-top: 35px;
min-height: 1000px;
overflow: hidden;
}

4
themes/movim/friend.tpl

@ -14,7 +14,7 @@
<?php $this->widget('Roster');?>
</div>
<div id="center">
<?php $this->widget('Tabs');?>
<?php /*$this->widget('Tabs');*/?>
<?php $this->widget('Wall');?>
<?php $this->widget('ContactCard');?>
<?php /*$this->widget('ContactCard');*/?>
</div>

6
themes/movim/img/default.svg

@ -32,7 +32,7 @@
showgrid="true"
showborder="false"
inkscape:window-width="1920"
inkscape:window-height="1012"
inkscape:window-height="1016"
inkscape:window-x="0"
inkscape:window-y="24"
inkscape:window-maximized="1"
@ -46,7 +46,9 @@
empspacing="5"
visible="true"
enabled="true"
snapvisiblegridlinesonly="true" />
snapvisiblegridlinesonly="true"
originx="0px"
originy="-3.8281246e-07px" />
</sodipodi:namedview>
<metadata
id="metadata7">

2
themes/movim/profile.tpl

@ -15,6 +15,6 @@
<?php $this->widget('Roster');?>
</div>
<div id="center">
<h1><?php echo t('Profile'); ?></h1>
<h1><?php echo t('Edit my profile'); ?></h1>
<?php $this->widget('Vcard');?>
</div>
Loading…
Cancel
Save