Browse Source

- Add a 'Hot' widget in the Explore page

- Put nice placeholder in the feeds
- Fix some CSS
- Add new element in the Item model
pull/16/head
Jaussoin Timothée 11 years ago
parent
commit
90fcbc81b9
  1. 36
      app/models/item/Item.php
  2. 64
      app/models/item/ItemDAO.php
  3. 2
      app/views/explore.tpl
  4. 31
      app/widgets/Explore/Explore.php
  5. 16
      app/widgets/Explore/_explore_user.tpl
  6. 10
      app/widgets/Explore/explore.tpl
  7. 10
      app/widgets/Feed/Feed.php
  8. 4
      app/widgets/Feed/_feed_empty.tpl
  9. 2
      app/widgets/Feed/locales.ini
  10. 21
      app/widgets/Hot/Hot.php
  11. 22
      app/widgets/Hot/hot.tpl
  12. 1
      app/widgets/Hot/locales.ini
  13. 13
      app/widgets/News/News.php
  14. 4
      app/widgets/News/_news_empty.tpl
  15. 2
      app/widgets/News/locales.ini
  16. 47
      app/widgets/Node/Node.php
  17. 4
      app/widgets/Node/_node_empty.tpl
  18. 2
      app/widgets/Node/locales.ini
  19. 2
      app/widgets/Node/node.tpl
  20. 1
      locales/locales.ini
  21. 4
      themes/movim/css/mobile.css
  22. 34
      themes/movim/css/style.css

36
app/models/item/Item.php

@ -7,7 +7,10 @@ class Item extends Model {
public $jid;
public $name;
public $node;
public $creator;
public $created;
public $updated;
public $description;
public $subscription;
public $num;
@ -20,8 +23,14 @@ class Item extends Model {
{"type":"string", "size":128, "mandatory":true, "key":true },
"node" :
{"type":"string", "size":128, "mandatory":true, "key":true },
"creator" :
{"type":"string", "size":128 },
"name" :
{"type":"string", "size":128 },
"created" :
{"type":"date"},
"description" :
{"type":"text" },
"updated" :
{"type":"date"}
}';
@ -38,6 +47,33 @@ class Item extends Model {
$this->name = (string)$item->attributes()->name;
$this->updated = date('Y-m-d H:i:s');
}
public function setMetadata($metadata, $from, $node) {
$this->server = $from;
$this->jid = $from;
$this->node = $node;
foreach($metadata->children() as $i) {
$key = (string)$i->attributes()->var;
switch ($key) {
case 'pubsub#title':
$this->name = (string)$i->value;
break;
case 'pubsub#creator':
$this->creator = (string)$i->value;
break;
case 'pubsub#creation_date':
$this->created = (string)$i->value;
break;
case 'pubsub#description':
$this->description = (string)$i->value;
break;
}
}
$this->updated = date('Y-m-d H:i:s');
}
public function getName() {
if($this->name != null)

64
app/models/item/ItemDAO.php

@ -7,7 +7,10 @@ class ItemDAO extends SQL {
$this->_sql = '
update item
set name = :name,
updated = :updated
creator = :creator,
created = :created,
updated = :updated,
description = :description
where server = :server
and jid = :jid
and node = :node';
@ -15,11 +18,14 @@ class ItemDAO extends SQL {
$this->prepare(
'Item',
array(
'name' => $item->name,
'updated'=> $item->updated,
'server' => $item->server,
'jid' => $item->jid,
'node' => $item->node
'name' => $item->name,
'created' => $item->created,
'updated' => $item->updated,
'server' => $item->server,
'jid' => $item->jid,
'node' => $item->node,
'creator' => $item->creator,
'description' => $item->description
)
);
@ -29,27 +35,36 @@ class ItemDAO extends SQL {
$this->_sql = '
insert into item
(server,
creator,
node,
jid,
name,
updated
created,
updated,
description
)
values(
:server,
:creator,
:node,
:jid,
:name,
:updated
:created,
:updated,
:description
)';
$this->prepare(
'Item',
array(
'name' => $item->name,
'updated'=> $item->updated,
'server' => $item->server,
'jid' => $item->jid,
'node' => $item->node
'name' => $item->name,
'creator' => $item->creator,
'created' => $item->created,
'updated' => $item->updated,
'server' => $item->server,
'jid' => $item->jid,
'node' => $item->node,
'description' => $item->description
)
);
@ -145,6 +160,29 @@ class ItemDAO extends SQL {
return $this->run('Item');
}
function getUpdatedItems($limitf = false, $limitr = false) {
$this->_sql = '
select * from item natural join (
select distinct node, max(updated) as num from postn
where node != :node
group by node
order by node) as post
order by num desc
';
if($limitr)
$this->_sql = $this->_sql.' limit '.$limitr.' offset '.$limitf;
$this->prepare(
'Item',
array(
'node' => 'urn:xmpp:microblog:0:comments%'
)
);
return $this->run('Item');
}
function deleteItems($server) {
$this->_sql = '
delete from item

2
app/views/explore.tpl

@ -14,6 +14,8 @@
<div id="center">
<div class="protect black" title="<?php echo getFlagTitle("black"); ?>"></div>
<h1><?php echo __('page.explore'); ?></h1>
<?php $this->widget('Hot');?>
<div class="clear"></div>
<?php $this->widget('Explore');?>
</div>
</div>

31
app/widgets/Explore/Explore.php

@ -60,30 +60,29 @@ class Explore extends WidgetCommon {
$html = '';
$cd = new \modl\ContactDAO();
$users = $cd->getAllPublic();
$gender = getGender();
$marital = getMarital();
if($users) {
$users = array_reverse($users);
foreach($users as $user) {
$html .= '
<article class="block">
<header>
<a href="' . Route::urlize('friend', $user->jid) . '">
<img class="avatar" src="' . $user->getPhoto('m') . '"/>
</a>
$g = $m = null;
<span class="name">
<a href="' . Route::urlize('friend', $user->jid) . '">' . $user->getTrueName() . '</a>
</span>
<span class="asv">' . $user->getAge() . ' ' . $gender[$user->gender] . ' ' . $marital[$user->marital] . '
</span>
</header>
if($user->gender != null && $user->gender != 'N') {
$g = $gender[$user->gender];
}
<section class="content">' . prepareString($user->description) . '</section>
if($user->marital != null && $user->marital != 'none') {
$m = $marital[$user->marital];
}
$userview = $this->tpl();
$userview->assign('user', $user);
$userview->assign('gender', $g);
$userview->assign('marital', $m);
$html .= $userview->draw('_explore_user', true);
<footer></footer>
</article>
';
}
}
return $html;

16
app/widgets/Explore/_explore_user.tpl

@ -0,0 +1,16 @@
<li class="block">
<img class="avatar" src="{$user->getPhoto('xs')}"/>
<a href="{$c->route('friend', $user->jid)}">
{if="$user->getAge()"}
<span class="tag blue">{$user->getAge()}</span>
{/if}
{if="$gender"}
<span class="tag green">{$gender}</span>
{/if}
{if="$marital"}
<span class="tag yellow">{$marital}</span>
{/if}
<span class="tag desc">{$user->description|preparestring}</span>
<span class="content">{$user->getTrueName()}</span>
</a>
</li>

10
app/widgets/Explore/explore.tpl

@ -1,4 +1,4 @@
<div id="serverresult" class="paddedtop">
<div id="serverresult" class="padded">
<a class="button color purple oppose icon search" href="{$myserver}">{$c->__('discover_my_server')}</a>
<h2>{$c->__('discussion_servers')}</h2>
<ul class="list">
@ -8,10 +8,12 @@
<div class="clear"></div>
<div class="paddedtopbottom">
<div class="padded">
<h2>{$c->__('last_registered')}</h2>
<div id="contactsresult">
<ul class="list">
{$contacts}
</div>
</ul>
<div class="clear"></div>
</div>

10
app/widgets/Feed/Feed.php

@ -155,10 +155,14 @@ class Feed extends WidgetCommon {
function prepareFeed($start) {
$pd = new \Modl\PostnDAO();
$pl = $pd->getFeed($start+1, $this->_feedsize);
$html = $this->preparePosts($pl);
$html .= $this->prepareNext($start, $html, $pl, 'ajaxGetFeed');
if(isset($pl)) {
$html = $this->preparePosts($pl);
$html .= $this->prepareNext($start, $html, $pl, 'ajaxGetFeed');
} else {
$view = $this->tpl();
$html = $view->draw('_feed_empty', true);
}
return $html;
}

4
app/widgets/Feed/_feed_empty.tpl

@ -0,0 +1,4 @@
<div class="placeholder padded">
<h1>{$c->__('feed.empty_title')}</h1>
<p>{$c->__('feed.empty')}</p>
</div>

2
app/widgets/Feed/locales.ini

@ -2,3 +2,5 @@ my_posts = 'My Posts'
feed.no_support = "Your server doesn't support post publication, you can only read contact's feeds"
feed.error = 'An error occured : '
feed.creating = 'Creating your feed...'
feed.empty_title = 'Hi!'
feed.empty = 'This is your newsfeed, here you will see the posts published by you and your contacts.'

21
app/widgets/Hot/Hot.php

@ -0,0 +1,21 @@
<?php
class Hot extends WidgetCommon
{
function load()
{
//$this->addcss('explore.css');
}
function display()
{
$nd = new \modl\ItemDAO();
$this->view->assign('nodes', $nd->getUpdatedItems(0, 10));
}
function getAvatar($server, $node) {
$user = new \modl\Contact;
$user->jid = $server.$node;
return $user->getPhoto('m');
}
}

22
app/widgets/Hot/hot.tpl

@ -0,0 +1,22 @@
<div class="paddedtop">
<h2>{$c->__('explore.hot')}</h2>
<ul class="list">
{loop="$nodes"}
<li class="block">
<a href="{$c->route('node', array($value->server, $value->node))}">
<span class="tag gray">{$c->__('post.updated')} {$value->num|strtotime|prepareDate}</span>
<span class="tag desc">{$value->description}</span>
<span class="content">
{if="isset($value->name)"}
{$value->name}
{else}
{$value->node}
{/if}
- {$value->server}
</span>
</a>
</li>
{/loop}
</ul>
</div>

1
app/widgets/Hot/locales.ini

@ -0,0 +1 @@
explore.hot = "What's Hot"

13
app/widgets/News/News.php

@ -43,11 +43,14 @@ class News extends WidgetCommon {
$pd = new \Modl\PostnDAO();
$pl = $pd->getNews($start+1, $this->_feedsize);
$html = $this->preparePosts($pl);
Cache::c('since', date(DATE_ISO8601, strtotime($pd->getLastDate())));
$html .= $this->prepareNext($start, $html, $pl, 'ajaxGetNews');
if(isset($pl)) {
$html = $this->preparePosts($pl);
Cache::c('since', date(DATE_ISO8601, strtotime($pd->getLastDate())));
$html .= $this->prepareNext($start, $html, $pl, 'ajaxGetNews');
} else {
$view = $this->tpl();
$html = $view->draw('_news_empty', true);
}
return $html;
}

4
app/widgets/News/_news_empty.tpl

@ -0,0 +1,4 @@
<div class="placeholder padded">
<h1>{$c->__('news.empty_title')}</h1>
<p>{$c->__('news.empty')}</p>
</div>

2
app/widgets/News/locales.ini

@ -0,0 +1,2 @@
news.empty_title = 'Hello'
news.empty = 'Welcome on your group feed, here you will see all the posts published in the groups you have subscribed.'

47
app/widgets/Node/Node.php

@ -47,10 +47,11 @@ class Node extends WidgetCommon
if(isset($_GET['s']) && isset($_GET['n'])) {
$this->view->assign('server', $_GET['s']);
$this->view->assign('node', $_GET['n']);
$this->view->assign('getaffiliations', $this->genCallAjax('ajaxGetAffiliations', "'".$_GET['s']."'", "'".$_GET['n']."'"));
$this->view->assign('getmetadata', $this->genCallAjax('ajaxGetMetadata', "'".$_GET['s']."'", "'".$_GET['n']."'"));
$this->view->assign('hash', md5($_GET['s'].$_GET['n']));
$this->view->assign('items', $this->prepareNode($_GET['s'], $_GET['n']));
$this->view->assign('getaffiliations', $this->genCallAjax('ajaxGetAffiliations', "'".$_GET['s']."'", "'".$_GET['n']."'"));
$this->view->assign('getmetadata', $this->genCallAjax('ajaxGetMetadata', "'".$_GET['s']."'", "'".$_GET['n']."'"));
$this->view->assign('hash', md5($_GET['s'].$_GET['n']));
$this->view->assign('items', $this->prepareNode($_GET['s'], $_GET['n']));
$this->view->assign('metadata', $this->prepareMetadata($_GET['s'], $_GET['n']));
$nd = new modl\ItemDAO();
$node = $nd->getItem($_GET['s'], $_GET['n']);
@ -98,18 +99,7 @@ class Node extends WidgetCommon
}
function onPubsubMetadata($params) {
// The URL add form
$metadataview = $this->tpl();
if(isset($params[0]['title']))
$metadataview->assign('title', $params[0]['title']);
if(isset($params[0]['description']))
$metadataview->assign('description', $params[0]['description']);
if(isset($params[0]['creation_date']))
$metadataview->assign('creation', prepareDate(strtotime($params[0]['creation_date'])));
if(isset($params[0]['creator']))
$metadataview->assign('creator', $params[0]['creator']);
$html = $metadataview->draw('_node_metadata', true);
$html = $this->prepareMetadata($params[0], $params[1]);
RPC::call('movim_fill', 'metadata', $html);
}
@ -192,7 +182,7 @@ class Node extends WidgetCommon
$nodeview->assign('submitform', '');
$nodeview->assign('posts', $this->preparePostsNode($serverid, $groupid, -1));
$nodeview->assign('posts', $this->preparePostsNode($serverid, $groupid, -1));
$html = $nodeview->draw('_node_content', true);
@ -217,12 +207,33 @@ class Node extends WidgetCommon
return $nexthtml;
}
function prepareMetadata($server, $node) {
$nd = new modl\ItemDAO();
$node = $nd->getItem($server, $node);
$metadataview = $this->tpl();
if(isset($node->name))
$metadataview->assign('title', $node->name);
else
$metadataview->assign('title', $node->node);
$metadataview->assign('description', $node->description);
$metadataview->assign('creation', prepareDate(strtotime($node->created)));
$metadataview->assign('creator', $node->creator);
return $metadataview->draw('_node_metadata', true);
}
function preparePostsNode($serverid, $groupid, $start) {
$pd = new \Modl\PostnDAO();
$pl = $pd->getNode($serverid, $groupid, $start+1, $this->_feedsize);
$html = $this->preparePosts($pl);
if(isset($pl)) {
$html = $this->preparePosts($pl);
} else {
$view = $this->tpl();
$html = $view->draw('_node_empty', true);
}
$html .= $this->prepareNext($start, $html, $pl, 'ajaxGetPostsNode', $serverid, $groupid);

4
app/widgets/Node/_node_empty.tpl

@ -0,0 +1,4 @@
<div class="placeholder padded">
<h1>{$c->__('node.empty_title')}</h1>
<p>{$c->__('node.empty')}</p>
</div>

2
app/widgets/Node/locales.ini

@ -3,3 +3,5 @@ node.unsubscribe = 'Unsubscribe'
node.share_label = 'Make your membership to this group public to your friends'
node.nickname_label = 'Give a nickname to this group if you want'
node.sure = 'Are you sure ?'
node.empty_title = 'Oops!'
node.empty = 'I cannot find any posts here. Try to push the refresh button.'

2
app/widgets/Node/node.tpl

@ -14,7 +14,7 @@
<div class="clear"></div>
<div class="metadata" id="metadata">
{$metadata}
</div>
<div id="formpublish" style="padding-bottom: 1em; display: none;">

1
locales/locales.ini

@ -256,6 +256,7 @@ post.share = 'Share with'
post.share_everyone = 'Everyone'
post.share_your_contacts= 'Your contacts'
post.delete = 'Delete this post'
post.updated = 'Updated'
[api]
api.error = 'The API is not reachable, try again later'

4
themes/movim/css/mobile.css

@ -243,6 +243,10 @@ dl dd {
width: 100%;
}
ul.list li span.tag.desc {
display: none;
}
}
@media screen and (max-width: 640px) {

34
themes/movim/css/style.css

@ -529,6 +529,28 @@ ul.list li span.tag {
margin-top: -0.5em;
}
ul.list li span.content {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
display: block;
}
ul.list li span.tag.desc {
color: gray;
max-width: 70%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
background-color: white;
}
ul.list li img {
float: left;
margin-right: 1em;
margin-top: 0.5em;
}
ul.list li span.tag.red { background-color: #D92727; }
ul.list li span.tag.blue { background-color: #0DB8B5; }
ul.list li span.tag.green { background-color: #6FCC43; }
@ -679,4 +701,16 @@ dl dd {
color: white;
}
/* Placeholder */
.placeholder {
text-align: center;
font-size: 1.2em;
max-width: 500px;
margin: 0 auto;
}
.placeholder p {
text-align: center;
}
Loading…
Cancel
Save