зеркало из https://github.com/nextcloud/news.git
shows articles in accordion view
This commit is contained in:
Родитель
6948000198
Коммит
fcd843bc0c
|
@ -9,3 +9,5 @@
|
|||
.news_input { float:left; font-size:12px; padding:4px 2px; border:solid 1px #aacfe4; width:200px; }
|
||||
|
||||
ul.controls li { float: left; }
|
||||
|
||||
.accordion .title { background: #DCDCDC; font-size: 12px; border-bottom:1px solid #ccc; font-weight:bold;}
|
||||
|
|
10
index.php
10
index.php
|
@ -24,7 +24,15 @@ $foldermapper = new OC_News_FolderMapper(OCP\USER::getUser());
|
|||
|
||||
$allfeeds = $foldermapper->root();
|
||||
|
||||
$feedid = isset( $_GET['feedid'] ) ? $_GET['feedid'] : null;
|
||||
if ($allfeeds) {
|
||||
$feedid = isset( $_GET['feedid'] ) ? $_GET['feedid'] : null;
|
||||
if ($feedid == null) {
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
$feedid = 0;
|
||||
}
|
||||
|
||||
$tmpl = new OCP\Template( 'news', 'main', 'user' );
|
||||
$tmpl->assign('allfeeds', $allfeeds);
|
||||
|
|
|
@ -77,5 +77,10 @@ $(document).ready(function(){
|
|||
$(this).parent().children().toggle();
|
||||
$(this).toggle();
|
||||
});
|
||||
|
||||
$('.accordion .title').click(function() {
|
||||
$(this).next().toggle();
|
||||
return false;
|
||||
}).next().hide();
|
||||
|
||||
});
|
11
lib/item.php
11
lib/item.php
|
@ -31,10 +31,11 @@ class OC_News_Item {
|
|||
private $status; //a bit-field set with status flags
|
||||
private $id; //id of the item in the database table
|
||||
|
||||
public function __construct($url, $title, $guid, $id = null){
|
||||
public function __construct($url, $title, $guid, $body, $id = null){
|
||||
$this->title = $title;
|
||||
$this->url = $url;
|
||||
$this->guid = $guid;
|
||||
$this->body = $body;
|
||||
$this->status |= StatusFlag::Unread;
|
||||
}
|
||||
|
||||
|
@ -105,4 +106,12 @@ class OC_News_Item {
|
|||
public function setUrl($url){
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
public function getBody(){
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
public function setBody($body){
|
||||
$this->body = $body;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,8 @@ class OC_News_ItemMapper {
|
|||
$title = $row['title'];
|
||||
$guid = $row['guid'];
|
||||
$status = $row['status'];
|
||||
$item = new OC_News_Item($url, $title, $guid);
|
||||
$body = $row['body'];
|
||||
$item = new OC_News_Item($url, $title, $guid, $body);
|
||||
$item->setStatus($status);
|
||||
$items[] = $item;
|
||||
}
|
||||
|
@ -62,16 +63,17 @@ class OC_News_ItemMapper {
|
|||
public function save(OC_News_Item $item, $feedid){
|
||||
$guid = $item->getGuid();
|
||||
$status = $item->getStatus();
|
||||
|
||||
|
||||
$itemid = $this->findIdFromGuid($guid, $feedid);
|
||||
|
||||
if ($itemid == null){
|
||||
$title = $item->getTitle();
|
||||
|
||||
$body = $item->getBody();
|
||||
|
||||
$stmt = OCP\DB::prepare('
|
||||
INSERT INTO ' . self::tableName .
|
||||
'(url, title, guid, feed_id, status)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
'(url, title, body, guid, feed_id, status)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
||||
');
|
||||
|
||||
if(empty($title)) {
|
||||
|
@ -79,9 +81,15 @@ class OC_News_ItemMapper {
|
|||
$title = $l->t('no title');
|
||||
}
|
||||
|
||||
if(empty($body)) {
|
||||
$l = OC_L10N::get('news');
|
||||
$body = $l->t('no body');
|
||||
}
|
||||
|
||||
$params=array(
|
||||
htmlspecialchars_decode($item->getUrl()),
|
||||
htmlspecialchars_decode($title),
|
||||
$body,
|
||||
$guid,
|
||||
$feedid,
|
||||
$status
|
||||
|
|
|
@ -36,7 +36,8 @@ class OC_News_Utils {
|
|||
$itemUrl = $spitem->get_permalink();
|
||||
$itemTitle = $spitem->get_title();
|
||||
$itemGUID = $spitem->get_id();
|
||||
$items[] = new OC_News_Item($itemUrl, $itemTitle, $itemGUID);
|
||||
$itemBody = $spitem->get_content();
|
||||
$items[] = new OC_News_Item($itemUrl, $itemTitle, $itemGUID, $itemBody);
|
||||
}
|
||||
|
||||
$feed = new OC_News_Feed($url, $title, $items);
|
||||
|
|
|
@ -6,8 +6,9 @@ $itemmapper = new OC_News_ItemMapper();
|
|||
|
||||
$items = $itemmapper->findAll($feedid);
|
||||
|
||||
echo '<ul>';
|
||||
echo '<ul class="accordion">';
|
||||
foreach($items as $item) {
|
||||
echo '<li>' . $item->getTitle() . '</li>';
|
||||
echo '<li><div class="title">' . $item->getTitle() . '</div>';
|
||||
echo '<div class="body">' . $item->getBody() . '</div></li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
|
|
Загрузка…
Ссылка в новой задаче