From 9c402767ee4f89d78d1a33d64541fcf793315416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaussoin=20Timoth=C3=A9e?= Date: Fri, 10 Apr 2015 23:48:17 +0200 Subject: [PATCH] - Use GMT as a time reference in the database - Apply the timezone offset when displaying the date - Get the subscribers counter from the database - Display the attached pictures in the posts - Add some new locales - Get the group subscriptions (if owner) --- app/helpers/DateHelper.php | 3 +++ app/helpers/TimezoneHelper.php | 9 ++++++++ app/models/item/Item.php | 1 + app/models/item/ItemDAO.php | 5 +++++ app/models/postn/Postn.php | 4 ++-- app/widgets/Chat/Chat.php | 4 ++-- app/widgets/Group/Group.php | 26 ++++++++++++++++++++++ app/widgets/Group/_group_header.tpl | 17 ++++++++++---- app/widgets/Group/_group_posts.tpl | 14 ++++++++++++ app/widgets/Group/_group_subscriptions.tpl | 20 +++++++++++++++++ app/widgets/Group/locales.ini | 6 ++++- app/widgets/Groups/_groups_server.tpl | 18 ++++++++++----- app/widgets/Groups/locales.ini | 3 +++ bootstrap.php | 3 +++ 14 files changed, 119 insertions(+), 14 deletions(-) create mode 100644 app/widgets/Group/_group_subscriptions.tpl diff --git a/app/helpers/DateHelper.php b/app/helpers/DateHelper.php index db71e93c1..c355ede04 100755 --- a/app/helpers/DateHelper.php +++ b/app/helpers/DateHelper.php @@ -45,6 +45,9 @@ function getTimezoneCorrection() { * @return string */ function prepareDate($time, $hours = true) { + // We had the server timezone + $time = $time + TIMEZONE_OFFSET; + $t = $time ? $time : time(); $date = ''; diff --git a/app/helpers/TimezoneHelper.php b/app/helpers/TimezoneHelper.php index 45dbb2bab..0ffc520f2 100755 --- a/app/helpers/TimezoneHelper.php +++ b/app/helpers/TimezoneHelper.php @@ -10,6 +10,15 @@ function getTimezoneList() return $timezones; } +/* + * Get the offset of a timezone + */ +function getTimezoneOffset($timezone) +{ + $tz = new DateTimeZone($timezone); + return $tz->getOffset(new DateTime); +} + /* * Generate the timezone list */ diff --git a/app/models/item/Item.php b/app/models/item/Item.php index ededc5242..3af98ecd8 100755 --- a/app/models/item/Item.php +++ b/app/models/item/Item.php @@ -13,6 +13,7 @@ class Item extends Model { public $description; public $subscription; public $num; + public $sub; public function __construct() { $this->_struct = ' diff --git a/app/models/item/ItemDAO.php b/app/models/item/ItemDAO.php index b01487f37..80bd049d9 100755 --- a/app/models/item/ItemDAO.php +++ b/app/models/item/ItemDAO.php @@ -143,6 +143,11 @@ class ItemDAO extends SQL { where origin = :server group by node) as p on p.node = item.node + left outer join ( + select node, count(node) as sub from subscription + where server = :server + group by node) as sub + on sub.node = item.node left outer join (select server, node, subscription from subscription where jid = :node) as s on s.server = item.server and s.node = item.node diff --git a/app/models/postn/Postn.php b/app/models/postn/Postn.php index 26c8606ca..2db02ad0c 100755 --- a/app/models/postn/Postn.php +++ b/app/models/postn/Postn.php @@ -145,14 +145,14 @@ class Postn extends Model { if($entry->entry->updated) $this->updated = (string)$entry->entry->updated; else - $this->updated = date(DATE_ISO8601); + $this->updated = gmdate(DATE_ISO8601); if($entry->entry->published) $this->published = (string)$entry->entry->published; elseif($entry->entry->updated) $this->published = (string)$entry->entry->updated; else - $this->published = date(DATE_ISO8601); + $this->published = gmdate(DATE_ISO8601); if($delay) $this->delay = $delay; diff --git a/app/widgets/Chat/Chat.php b/app/widgets/Chat/Chat.php index b52200643..4e1a570a3 100644 --- a/app/widgets/Chat/Chat.php +++ b/app/widgets/Chat/Chat.php @@ -200,8 +200,8 @@ class Chat extends WidgetCommon } $m->body = rawurldecode($message); - $m->published = date('Y-m-d H:i:s'); - $m->delivered = date('Y-m-d H:i:s'); + $m->published = gmdate('Y-m-d H:i:s'); + $m->delivered = gmdate('Y-m-d H:i:s'); if(!preg_match('#^\?OTR#', $m->body)) { $md = new \Modl\MessageDAO(); diff --git a/app/widgets/Group/Group.php b/app/widgets/Group/Group.php index c9d04332a..f3839d4dc 100755 --- a/app/widgets/Group/Group.php +++ b/app/widgets/Group/Group.php @@ -3,6 +3,7 @@ use Moxl\Xec\Action\Pubsub\GetItemsId; use Moxl\Xec\Action\Pubsub\GetMetadata; use Moxl\Xec\Action\Pubsub\GetAffiliations; +use Moxl\Xec\Action\Pubsub\GetSubscriptions; use Moxl\Xec\Action\Pubsub\Subscribe; use Moxl\Xec\Action\Pubsub\Unsubscribe; @@ -26,6 +27,8 @@ class Group extends WidgetCommon $this->registerEvent('pubsub_subscribe_handle', 'onSubscribed'); $this->registerEvent('pubsub_unsubscribe_handle', 'onUnsubscribed'); $this->registerEvent('pubsub_getaffiliations_handle', 'onAffiliations'); + $this->registerEvent('pubsub_getsubscriptions_handle', 'onSubscriptions'); + $this->registerEvent('pubsub_getconfig_handle', 'onConfig'); $this->registerEvent('pubsub_setconfig_handle', 'onConfigSaved'); $this->registerEvent('bookmark_set_handle', 'onBookmark'); @@ -73,7 +76,19 @@ class Group extends WidgetCommon $view = $this->tpl(); RPC::call('movim_append', 'group_widget', $view->draw('_group_publish', true)); } + } + + function onSubscriptions($packet) + { + list($subscriptions, $server, $node) = array_values($packet->content); + + $view = $this->tpl(); + + $view->assign('subscriptions', $subscriptions); + $view->assign('server', $server); + $view->assign('node', $node); + Dialog::fill($view->draw('_group_subscriptions', true), true); } function onConfig($packet) @@ -202,6 +217,17 @@ class Group extends WidgetCommon ->request(); } + function ajaxGetSubscriptions($server, $node) + { + if(!$this->validateServerNode($server, $node)) return; + + $r = new GetSubscriptions; + $r->setTo($server) + ->setNode($node) + ->setSync() + ->request(); + } + function ajaxAskSubscribe($server, $node) { if(!$this->validateServerNode($server, $node)) return; diff --git a/app/widgets/Group/_group_header.tpl b/app/widgets/Group/_group_header.tpl index 88b5083c9..600480825 100644 --- a/app/widgets/Group/_group_header.tpl +++ b/app/widgets/Group/_group_header.tpl @@ -7,27 +7,36 @@
-

{if="$item != null"} diff --git a/app/widgets/Group/_group_posts.tpl b/app/widgets/Group/_group_posts.tpl index c0ee9c306..1e0f3f5c6 100755 --- a/app/widgets/Group/_group_posts.tpl +++ b/app/widgets/Group/_group_posts.tpl @@ -59,6 +59,20 @@ {/loop} {/if} + {if="isset($value->getAttachements().pictures)"} +
    + {loop="$value->getAttachements().pictures"} +
  • + + + + + + +
  • + {/loop} +
+ {/if} {/loop} diff --git a/app/widgets/Group/_group_subscriptions.tpl b/app/widgets/Group/_group_subscriptions.tpl new file mode 100644 index 000000000..99d5853c5 --- /dev/null +++ b/app/widgets/Group/_group_subscriptions.tpl @@ -0,0 +1,20 @@ +
+
    +
  • + {$c->__('group.subscriptions')} + {$subscriptions|count} +
  • + {loop="$subscriptions"} +
  • + + {$value.jid} + +
  • + {/loop} +
+
+
+ + {$c->__('button.close')} + +
diff --git a/app/widgets/Group/locales.ini b/app/widgets/Group/locales.ini index e29b7ff53..b625805c9 100755 --- a/app/widgets/Group/locales.ini +++ b/app/widgets/Group/locales.ini @@ -9,4 +9,8 @@ group.sure = 'Are you sure ?' group.empty_title = 'Groups' group.empty_text = 'Discover, follow and share' group.empty = 'Something bad happened to this group' -group.config_saved = 'Group configuration saved' +group.config_saved = 'Group configuration saved' + +group.get_config = 'Configure your group' +group.get_subscriptions = 'Get the subscriptions' +group.subscriptions = 'Subscriptions' diff --git a/app/widgets/Groups/_groups_server.tpl b/app/widgets/Groups/_groups_server.tpl index 754a07b4a..97a8fca1a 100644 --- a/app/widgets/Groups/_groups_server.tpl +++ b/app/widgets/Groups/_groups_server.tpl @@ -3,7 +3,7 @@
  • subscription == 'subscribed'"}action{/if} - {if="$value->description"}condensed{/if} + condensed " data-server="{$value->server}" data-node="{$value->node}" @@ -21,11 +21,19 @@ {else} {$value->node} {/if} - {$value->num} + + {if="$value->description"} + + {$value->description|strip_tags} + + {/if} - {if="$value->description"} -

    {$value->description|strip_tags}

    - {/if} +

    + {if="$value->sub > 0"} + {$c->__('groups.sub', $value->sub)} - + {/if} + {$c->__('groups.num', $value->num)} +

  • {/loop} diff --git a/app/widgets/Groups/locales.ini b/app/widgets/Groups/locales.ini index 652fa28db..1e26c644e 100644 --- a/app/widgets/Groups/locales.ini +++ b/app/widgets/Groups/locales.ini @@ -3,3 +3,6 @@ groups.contact_post = 'Contact post' groups.empty_text1 = "You don't have any subscriptions yet, select a group server above to start exploring." groups.empty_text2 = "Subscribe to your favorite feeds by bookmarking them." groups.subscriptions = 'My Subscriptions' + +groups.sub = '%s subscribers' +groups.num = '%s posts' diff --git a/bootstrap.php b/bootstrap.php index 228c66b9e..509129076 100755 --- a/bootstrap.php +++ b/bootstrap.php @@ -272,6 +272,9 @@ class Bootstrap { // We set the default timezone to the server timezone $cd = new \Modl\ConfigDAO(); $config = $cd->get(); + + // And we set a global offset + define('TIMEZONE_OFFSET', getTimezoneOffset($config->timezone)); date_default_timezone_set($config->timezone); }