diff options
author | Alessandro Cosentino <cosenal@gmail.com> | 2012-10-28 10:57:35 -0400 |
---|---|---|
committer | Alessandro Cosentino <cosenal@gmail.com> | 2012-10-28 10:57:35 -0400 |
commit | a7f7f04052ded38c94e15a4e94645f6ab2b39941 (patch) | |
tree | 0a2c06adb471d5c18535c308f7991b4c9675f876 | |
parent | ff6bee25f0468d291616be9235ae556457d7fc0d (diff) |
sharing items in the News app
-rw-r--r-- | appinfo/app.php | 4 | ||||
-rw-r--r-- | css/news.css | 10 | ||||
-rw-r--r-- | js/items.js | 1 | ||||
-rw-r--r-- | lib/feedtypes.php | 1 | ||||
-rw-r--r-- | lib/itemmapper.php | 9 | ||||
-rw-r--r-- | lib/share/item.php | 44 | ||||
-rw-r--r-- | templates/main.php | 1 | ||||
-rw-r--r-- | templates/part.feeds.php | 7 | ||||
-rw-r--r-- | templates/part.items.php | 6 | ||||
-rw-r--r-- | templates/part.shared.php | 68 |
10 files changed, 144 insertions, 7 deletions
diff --git a/appinfo/app.php b/appinfo/app.php index 97ad68ee3..7825f4fc5 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -28,6 +28,8 @@ OC::$CLASSPATH['OC_Search_Provider_News'] = 'apps/news/lib/search.php'; OC::$CLASSPATH['OCA\News\Backgroundjob'] = 'apps/news/lib/backgroundjob.php'; OCP\Backgroundjob::addRegularTask( 'OCA\News\Backgroundjob', 'run' ); +OC::$CLASSPATH['OCA\News\Share_Backend_News_Item'] = 'apps/news/lib/share/item.php'; + OCP\App::addNavigationEntry( array( 'id' => 'news', 'order' => 74, @@ -37,3 +39,5 @@ OCP\App::addNavigationEntry( array( )); OC_Search::registerProvider('OC_Search_Provider_News'); + +OCP\Share::registerBackend('news_item', 'OCA\News\Share_Backend_News_Item'); diff --git a/css/news.css b/css/news.css index 4d4f6bbfd..748904a66 100644 --- a/css/news.css +++ b/css/news.css @@ -663,16 +663,20 @@ div.add_parentfolder { } .feed_item:hover .secondary_item_utils { - display: block; - } + display: inline-block; + } + .feed_item a.share { + background:url('%webroot%/core/img/actions/share.svg') no-repeat center; + } + .feed_item:hover .secondary_item_utils li.keep_unread { cursor: pointer; - } .feed_item .secondary_item_utils li input[type=checkbox]{ } + /* dialog/menues */ #addfolder_dialog, #addfeed_dialog, #changefolder_dialog { diff --git a/js/items.js b/js/items.js index cee18759e..65b5483ec 100644 --- a/js/items.js +++ b/js/items.js @@ -346,6 +346,7 @@ var News = News || {}; } }); break; + } return pairs; }; diff --git a/lib/feedtypes.php b/lib/feedtypes.php index b4f7d6f3a..d330a5b2a 100644 --- a/lib/feedtypes.php +++ b/lib/feedtypes.php @@ -18,4 +18,5 @@ class FeedType { const FOLDER = 1; const STARRED = 2; const SUBSCRIPTIONS = 3; + const SHARED = 4; };
\ No newline at end of file diff --git a/lib/itemmapper.php b/lib/itemmapper.php index 92a3928d7..ba9be41a7 100644 --- a/lib/itemmapper.php +++ b/lib/itemmapper.php @@ -236,11 +236,14 @@ class ItemMapper { /** * @brief Retrieve an item from the database - * @param id The id of the feed in the database table. + * @param id The id of the item in the database table. */ public function findById($id) { - $stmt = \OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' WHERE id = ?'); - $result = $stmt->execute(array($id)); + $stmt = \OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' JOIN ' . FeedMapper::tableName . + ' ON ' . self::tableName . '.feed_id = ' . FeedMapper::tableName . '.id WHERE ' + . self::tableName .'.id = ? AND ' . FeedMapper::tableName . '.user_id = ? '); + $result = $stmt->execute(array($id, $this->userid)); + $row = $result->fetchRow(); $item = $this->fromRow($row); diff --git a/lib/share/item.php b/lib/share/item.php new file mode 100644 index 000000000..db9ab0f48 --- /dev/null +++ b/lib/share/item.php @@ -0,0 +1,44 @@ +<?php +/** +* ownCloud - News app +* +* @author Alessandro Cosentino +* Copyright (c) 2012 - Alessandro Cosentino <cosenal@gmail.com> +* +* This file is licensed under the Affero General Public License version 3 or later. +* See the COPYING-README file +* +*/ + +namespace OCA\News; + +class Share_Backend_News_Item implements \OCP\Share_Backend { + + const FORMAT_ITEM = 0; + + private static $item; + + public function isValidSource($itemSource, $uidOwner) { + $itemMapper = new ItemMapper($uidOwner); + $this->item = $itemMapper->findById($itemSource); + if ($this->item !== null) { + return true; + } + return false; + } + + public function generateTarget($itemSource, $shareWith, $exclude = null) { + return $this->item->getTitle(); + } + + public function formatItems($items, $format, $parameters = null) { + $formattedItems = array(); + foreach ($items as $item) { + $itemMapper = new ItemMapper($item['uid_owner']); + $formattedItem = $itemMapper->findById($item['item_source']); + $formattedItems[] = $formattedItem; + } + return $formattedItems; + } + +}
\ No newline at end of file diff --git a/templates/main.php b/templates/main.php index 3c4eff3f4..364ad9846 100644 --- a/templates/main.php +++ b/templates/main.php @@ -52,6 +52,7 @@ echo $this->inc("part.dialogues"); <div id="rightcontent" class="rightcontent"> <?php echo '<div id="feed_items">'; + //echo $this->inc("part.shared"); echo $this->inc("part.items"); echo '</div>'; ?> diff --git a/templates/part.feeds.php b/templates/part.feeds.php index 14a7b0dd4..5e9895870 100644 --- a/templates/part.feeds.php +++ b/templates/part.feeds.php @@ -40,6 +40,7 @@ $allfeeds = isset($_['allfeeds']) ? $_['allfeeds'] : ''; $lastViewedFeedId = $_['lastViewedFeedId']; $lastViewedFeedType = $_['lastViewedFeedType']; $starredCount = $_['starredCount']; +$sharedCount = $_['sharedCount']; ?> @@ -54,5 +55,11 @@ $starredCount = $_['starredCount']; <span class="unread_items_counter"><?php echo $starredCount ?></span> </li> +<li class="shared <?php if($lastViewedFeedType == OCA\News\FeedType::SHARED) { echo "active"; }; ?>"> + <a class="title" href="#" ><?php echo $l->t('Shared'); ?></a> + <span class="unread_items_counter"><?php echo $sharedCount ?></span> +</li> + + <?php print_collection_list($allfeeds, $lastViewedFeedId, $lastViewedFeedType); diff --git a/templates/part.items.php b/templates/part.items.php index 70bdb4022..58c7459da 100644 --- a/templates/part.items.php +++ b/templates/part.items.php @@ -51,11 +51,15 @@ foreach($items as $item) { echo '<div class="body">' . $item->getBody() . '</div>'; + echo '<div><a class="share" data-item-type="news_item" data-item="' . $item->getId() . '" title="' . $l->t('Share') . + '" data-possible-permissions="' . (OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_SHARE) . '"/></div>'; + echo '<div class="bottom_utils">'; - echo '<ul class="secondary_item_utils">'; + echo '<ul class="secondary_item_utils">'; echo '<li class="keep_unread">' . $l->t('Keep unread') . '<input type="checkbox" /></li>'; echo '</ul>'; echo '</div>'; + echo '</li>'; diff --git a/templates/part.shared.php b/templates/part.shared.php new file mode 100644 index 000000000..5e29d8c92 --- /dev/null +++ b/templates/part.shared.php @@ -0,0 +1,68 @@ +<?php + +$items = OCP\Share::getItemsSharedWith('news_item', 1); + +//print_r($items); + +echo '<ul>'; +foreach($items as $item) { + + if($item->isRead()) { + $newsItemClass = "read"; + } else { + $newsItemClass = ""; + } + + if($item->isImportant()) { + $starClass = 'important'; + $startTitle = $l->t('Mark as unimportant'); + } else { + $starClass = ''; + $startTitle = $l->t('Mark as important'); + } + + echo '<li class="feed_item ' . $newsItemClass .'" data-id="' . $item->getId() . '" data-feedid="' . $item->getFeedId() . '">'; + echo '<span class="timestamp">' . $item->getDate() . '</span>'; + echo '<h2 class="item_date"><time class="timeago" datetime="' . + date('c', $item->getDate()) . '">' . date('F j, Y, g:i a', $item->getDate()) . '</time>' . '</h2>'; + + echo '<div class="utils">'; + echo '<ul class="primary_item_utils">'; + echo '<li class="star ' . $starClass . '" title="' . $startTitle . '"></li>'; + echo '</ul>'; + echo '</div>'; + + echo '<h1 class="item_title"><a target="_blank" href="' . $item->getUrl() . '">' . htmlspecialchars($item->getTitle(), ENT_QUOTES, 'UTF-8') . '</a></h1>'; + + if ((int)$lastViewedFeedType !== OCA\News\FeedType::FEED) { + $feedTitle = $l->t('from') . ' ' . '<a href="#" class="from_feed"> ' . $item->getFeedTitle() . '</a> '; + } else { + $feedTitle = ''; + } + + if(($item->getAuthor() !== null) && (trim($item->getAuthor()) !== '')) { + $author = $l->t('by') . ' ' . htmlspecialchars($item->getAuthor(), ENT_QUOTES, 'UTF-8'); + } else { + $author = ''; + } + + if(!($feedTitle === '' && $author === '')){ + echo '<h2 class="item_author">'. $feedTitle . $author . '</h2>'; + } + + echo '<div class="body">' . $item->getBody() . '</div>'; + + echo '<div><a class="share" data-item-type="news_item" data-item="' . $item->getId() . '" title="' . $l->t('Share') . + '" data-possible-permissions="' . (OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_SHARE) . '"/></div>'; + + echo '<div class="bottom_utils">'; + echo '<ul class="secondary_item_utils">'; + echo '<li class="keep_unread">' . $l->t('Keep unread') . '<input type="checkbox" /></li>'; + echo '</ul>'; + echo '</div>'; + + + echo '</li>'; + + } +echo '</ul>'; |