diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-03-21 16:32:36 +0100 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-03-21 16:32:36 +0100 |
commit | ac84b27965f5a1aec859e389f099fb844e33de46 (patch) | |
tree | c98d7aace90fcb442208349918a3e71cd9a7691a /lib | |
parent | f475d882d0a76908400e9857f7e8a4ae8ad8a752 (diff) |
reorganize folder
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api.php | 166 | ||||
-rw-r--r-- | lib/backgroundjob.php | 91 | ||||
-rw-r--r-- | lib/controller.php | 108 | ||||
-rw-r--r-- | lib/request.php | 83 | ||||
-rw-r--r-- | lib/response.php | 218 | ||||
-rw-r--r-- | lib/search.php | 38 | ||||
-rw-r--r-- | lib/security.php | 104 | ||||
-rw-r--r-- | lib/share/item.php | 44 | ||||
-rw-r--r-- | lib/utils.php | 208 |
9 files changed, 0 insertions, 1060 deletions
diff --git a/lib/api.php b/lib/api.php deleted file mode 100644 index 28f471207..000000000 --- a/lib/api.php +++ /dev/null @@ -1,166 +0,0 @@ -<?php - -/** -* ownCloud - App Template Example -* -* @author Bernhard Posselt -* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Affero General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -* -*/ - - -namespace OCA\News; - -/** - * This is used to wrap the owncloud static api calls into an object to make the - * code better abstractable for use in the dependency injection container - * - * Extend this to your needs - */ -class API { - - private $appName; - - /** - * @param string $appName: the name of your application - */ - public function __construct($appName){ - $this->appName = $appName; - } - - - /** - * @return the name of your application - */ - public function getAppName(){ - return $this->appName; - } - - - /** - * @return: the user id of the current user - */ - public function getUserId(){ - return \OCP\USER::getUser(); - } - - - /** - * Sets the current navigation entry to the currently running app - */ - public function activateNavigationEntry(){ - \OCP\App::setActiveNavigationEntry($this->appName); - } - - - /** - * Adds a new javascript file - * @param string $scriptName: the name of the javascript in js/ - * without the suffix - */ - public function addScript($scriptName, $appName=null){ - if($appName === null ){ - $appName = $this->appName; - } - \OCP\Util::addScript($appName, $scriptName); - } - - - /** - * Adds a new css file - * @param string $styleName: the name of the css file in css/ - * without the suffix - */ - public function addStyle($styleName){ - \OCP\Util::addStyle($this->appName, $styleName); - } - - - /** - * @brief shorthand for addScript for files in the 3rdparty directory - * @param string $name: the name of the file without the suffix - */ - public function add3rdPartyScript($name){ - \OCP\Util::addScript($this->appName . '/3rdparty', $name); - } - - - /** - * @brief shorthand for addStyle for files in the 3rdparty directory - * @param string $name: the name of the file without the suffix - */ - public function add3rdPartyStyle($name){ - \OCP\Util::addStyle($this->appName . '/3rdparty', $name); - } - - /** - * Looks up a systemwide defined value - * @param string $key: the key of the value, under which it was saved - * @return the saved value - */ - public function getSystemValue($key){ - return \OCP\Config::getSystemValue($key, ''); - } - - - /** - * Sets a new systemwide value - * @param string $key: the key of the value, under which will be saved - * @param $value: the value that should be stored - */ - public function setSystemValue($key, $value){ - return \OCP\Config::setSystemValue($key, $value); - } - - - /** - * Shortcut for setting a user defined value - * @param $key the key under which the value is being stored - * @param $value the value that you want to store - */ - public function setUserValue($key, $value){ - \OCP\Config::setUserValue($this->getUserId(), $this->appName, $key, $value); - } - - - /** - * Shortcut for getting a user defined value - * @param $key the key under which the value is being stored - */ - public function getUserValue($key){ - return \OCP\Config::getUserValue($this->getUserId(), $this->appName, $key); - } - - - /** - * Returns the translation object - * @return the translation object - */ - public function getTrans(){ - return \OC_L10N::get($this->appName); - } - - - public function getLocalFilePath($path){ - return \OC_Filesystem::getLocalFile($path); - } - - - public function openEventSource(){ - return new \OC_EventSource(); - } - -}
\ No newline at end of file diff --git a/lib/backgroundjob.php b/lib/backgroundjob.php deleted file mode 100644 index 098ff8393..000000000 --- a/lib/backgroundjob.php +++ /dev/null @@ -1,91 +0,0 @@ -<?php -/** -* ownCloud - News app -* -* @author Jakob Sack -* @copyright 2012 Jakob Sack owncloud@jakobsack.de -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Affero General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -* -*/ - -namespace OCA\News; - -/** - * This class maps a feed to an entry in the feeds table of the database. - */ -class Backgroundjob { - static public function sortFeeds( $a, $b ) { - if( $a->getId() == $b->getId() ) { - return 0; - } - elseif( $a->getId() < $b->getId() ) { - return -1; - } - else{ - return 1; - } - } - - static public function run() { - if( \OC::$CLI ) { - self::cliStep(); - } - else{ - self::webStep(); - } - } - - static private function cliStep() { - $feedmapper = new FeedMapper(); - - // Iterate over all feeds - $feeds = $feedmapper->findAll(); - foreach( $feeds as $feed ) { - self::updateFeed( $feedmapper, $feed ); - } - } - - static private function webStep() { - // Iterate over all users - $lastid = \OCP\Config::getAppValue('news', 'backgroundjob_lastid',0); - - $feedmapper = new FeedMapper(); - $feeds = $feedmapper->findAll(); - usort( $feeds, array( 'OCA\News\Backgroundjob', 'sortFeeds' )); - - $done = false; - foreach( $feeds as $feed ) { - if( $feed->getId() > $lastid ) { - // set lastid BEFORE updating feed! - \OCP\Config::setAppValue('news', 'backgroundjob_lastid',$feed->getId()); - $done = true; - self::updateFeed( $feedmapper, $feed ); - } - } - - if( !$done ) { - \OCP\Config::setAppValue('news', 'backgroundjob_lastid',0); - } - } - - static private function updateFeed( $feedmapper, $feed ) { - $newfeed = null; - $newfeed = Utils::fetch( $feed->getUrl() ); - if( $newfeed !== null ) { - $feedmapper = new FeedMapper(); - $newfeedid = $feedmapper->save($newfeed, $feed->getFolderId() ); - } - } -} diff --git a/lib/controller.php b/lib/controller.php deleted file mode 100644 index 292e25a18..000000000 --- a/lib/controller.php +++ /dev/null @@ -1,108 +0,0 @@ -<?php -/** -* ownCloud - News app -* -* @author Bernhard Posselt -* Copyright (c) 2012 - Bernhard Posselt <nukeawhale@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 Controller { - - protected $userId; - protected $appName; - protected $request; - protected $api; - protected $trans; - - public function __construct($request, $api){ - $this->api = $api; - $this->userId = $api->getUserId(); - $this->appName = $api->getAppName(); - $this->request = $request; - $this->trans = $api->getTrans(); - } - - - /** - * @brief lets you access post and get parameters by the index - * @param string $key: the key which you want to access in the $_POST or - * $_GET array. If both arrays store things under the same - * key, return the value in $_POST - * @param $default: the value that is returned if the key does not exist - * @return: the content of the array - */ - protected function params($key, $default=null){ - $postValue = $this->request->getPOST($key); - $getValue = $this->request->getGET($key); - - if($postValue !== null){ - return $postValue; - } - - if($getValue !== null){ - return $getValue; - } - - return $default; - } - - /** - * Shortcut for accessing an uploaded file through the $_FILES array - * @param string $key: the key that will be taken from the $_FILES array - * @return the file in the $_FILES element - */ - protected function getUploadedFile($key){ - return $this->request->getFILES($key); - } - - - /** - * Binds variables to the template and prints it - * The following values are always assigned: userId, trans - * @param $templateName the name of the template - * @param $arguments an array with arguments in $templateVar => $content - * @param string $renderAs: admin, user or blank: admin renders the page on - * the admin settings page, user renders a normal - * owncloud page, blank renders the template alone - */ - protected function render($templateName, $arguments=array(), - $renderAs='user'){ - $response = new TemplateResponse($this->appName, $templateName); - $response->setParams($arguments); - $response->renderAs($renderAs); - return $response; - } - - - /** - * @brief renders a json success - * @param array $params an array which will be converted to JSON - */ - protected function renderJSON($params=array()){ - $response = new JSONResponse($this->appName); - $response->setParams($params); - return $response; - } - - - /** - * @brief renders a json error - * @param string $msg: the error message - * @param string $file: the file that it occured in - * @param array $params an array which will be converted to JSON - */ - protected function renderJSONError($msg, $file="", $params=array()){ - $response = new JSONResponse($this->appName); - $response->setParams($params); - $response->setErrorMessage($msg, $file); - return $response; - } - - -} diff --git a/lib/request.php b/lib/request.php deleted file mode 100644 index 013c9b80e..000000000 --- a/lib/request.php +++ /dev/null @@ -1,83 +0,0 @@ -<?php -/** -* ownCloud - News app -* -* @author Bernhard Posselt -* Copyright (c) 2012 - Bernhard Posselt <nukeawhale@gmail.com> -* -* This file is licensed under the Affero General Public License version 3 or later. -* See the COPYING-README file -* -*/ - -namespace OCA\News; - - -/** - * Encapsulates user id, $_GET and $_POST arrays for better testability - */ -class Request { - - private $get; - private $post; - private $userId; - private $files; - - /** - * @param string $userId: the id of the current user - * @param array $get: the $_GET array - * @param array $post: the $_POST array - * @param array $files the $_FILES array - */ - public function __construct($userId, $get=array(), $post=array(), $files=array()) { - $this->get = $get; - $this->post = $post; - $this->userId = $userId; - $this->files = $files; - } - - - /** - * Returns the get value or the default if not found - * @param string $key: the array key that should be looked up - * @param string $default: if the key is not found, return this value - * @return the value of the stored array - */ - public function getGET($key, $default=null){ - if(isset($this->get[$key])){ - return $this->get[$key]; - } else { - return $default; - } - } - - - /** - * Returns the get value of the files array - * @param string $key: the array key that should be looked up - * @return the value of the stored array - */ - public function getFILES($key){ - if(isset($this->files[$key])){ - return $this->files[$key]; - } else { - return null; - } - } - - - /** - * Returns the get value or the default if not found - * @param string $key: the array key that should be looked up - * @param string $default: if the key is not found, return this value - * @return the value of the stored array - */ - public function getPOST($key, $default=null){ - if(isset($this->post[$key])){ - return $this->post[$key]; - } else { - return $default; - } - } - -} diff --git a/lib/response.php b/lib/response.php deleted file mode 100644 index 993d061d3..000000000 --- a/lib/response.php +++ /dev/null @@ -1,218 +0,0 @@ -<?php -/** -* ownCloud - News app -* -* @author Bernhard Posselt -* Copyright (c) 2012 - Bernhard Posselt <nukeawhale@gmail.com> -* -* This file is licensed under the Affero General Public License version 3 or later. -* See the COPYING-README file -* -*/ - -namespace OCA\News; - - -abstract class Response { - - private $headers; - - protected function __construct(){ - $this->headers = array(); - } - - /** - * Adds a new header to the response that will be called before the render - * function - * @param string header: the string that will be used in the header() function - */ - public function addHeader($header){ - array_push($this->headers, $header); - } - - - /** - * Renders all headers - */ - public function render(){ - foreach($this->headers as $value) { - header($value); - } - } - - -} - - -/** - * Prompts the user to download the a textfile - */ -class TextDownloadResponse extends Response { - - private $content; - private $filename; - private $contentType; - - /** - * Creates a response that prompts the user to download the file - * @param string $content: the content that should be written into the file - * @param string $filename: the name that the downloaded file should have - * @param string $contentType: the mimetype that the downloaded file should have - */ - public function __construct($content, $filename, $contentType){ - parent::__construct(); - $this->content = $content; - $this->filename = $filename; - $this->contentType = $contentType; - - $this->addHeader('Content-Disposition: attachment; filename="' . $filename . '"'); - $this->addHeader('Content-Type: ' . $contentType); - } - - - /** - * Simply sets the headers and returns the file contents - * @return the file contents - */ - public function render(){ - parent::render(); - return $this->content; - } - - -} - - -/** - * Response for a normal template - */ -class TemplateResponse extends Response { - - private $templateName; - private $params; - private $appName; - private $renderAs; - - /** - * @param string $appName: the name of your app - * @param string $templateName: the name of the template - */ - public function __construct($appName, $templateName) { - parent::__construct(); - $this->templateName = $templateName; - $this->appName = $appName; - $this->params = array(); - $this->renderAs = 'user'; - } - - - /** - * @brief sets template parameters - * @param array $params: an array with key => value structure which sets template - * variables - */ - public function setParams($params){ - $this->params = $params; - } - - - /** - * @brief sets the template page - * @param string $renderAs: admin, user or blank: admin renders the page on - * the admin settings page, user renders a normal - * owncloud page, blank renders the template alone - */ - public function renderAs($renderAs='user'){ - $this->renderAs = $renderAs; - } - - - /** - * Returns the rendered html - * @return the rendered html - */ - public function render(){ - parent::render(); - - if($this->renderAs === 'blank'){ - $template = new \OCP\Template($this->appName, $this->templateName); - } else { - $template = new \OCP\Template($this->appName, $this->templateName, - $this->renderAs); - } - - foreach($this->params as $key => $value){ - $template->assign($key, $value, false); - } - - return $template->fetchPage(); - } - -} - - -/** - * A renderer for JSON calls - */ -class JSONResponse extends Response { - - private $name; - private $data; - private $appName; - - /** - * @param string $appName: the name of your app - */ - public function __construct($appName) { - parent::__construct(); - $this->appName = $appName; - $this->data = array(); - $this->error = false; - } - - /** - * @brief sets values in the data json array - * @param array $params: an array with key => value structure which will be - * transformed to JSON - */ - public function setParams($params){ - $this->data['data'] = $params; - } - - - /** - * @brief in case we want to render an error message, also logs into the - * owncloud log - * @param string $message: the error message - * @param string $file: the file where the error occured, use __FILE__ in - * the file where you call it - */ - public function setErrorMessage($msg, $file){ - $this->error = true; - $this->data['msg'] = $msg; - \OCP\Util::writeLog($this->appName, $file . ': ' . $msg, \OCP\Util::ERROR); - } - - - /** - * Returns the rendered json - * @return the rendered json - */ - public function render(){ - parent::render(); - - ob_start(); - - if($this->error){ - \OCP\JSON::error($this->data); - } else { - \OCP\JSON::success($this->data); - } - - $result = ob_get_contents(); - ob_end_clean(); - - return $result; - } - -}
\ No newline at end of file diff --git a/lib/search.php b/lib/search.php deleted file mode 100644 index d9cf1d294..000000000 --- a/lib/search.php +++ /dev/null @@ -1,38 +0,0 @@ -<?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 -* -*/ - -class OC_Search_Provider_News extends OC_Search_Provider{ - - function search($query) { - if (!OCP\App::isEnabled('news')) { - return array(); - } - - $feedMapper = new OCA\News\FeedMapper(OCP\USER::getUser()); - $results=array(); - - if($feedMapper->feedCount() > 0) { - $allFeeds = $feedMapper->findAll(); - - $l = new OC_l10n('news'); - - foreach($allFeeds as $feed) { - if(substr_count(strtolower($feed->getTitle()), strtolower($query)) > 0) { - $link = \OC_Helper::linkToRoute('news_index_feed', array('feedid' => $feed->getId())); - $results[]=new OC_Search_Result($feed->getTitle(), '', $link, (string)$l->t('News')); - } - } - } - return $results; - - } -} diff --git a/lib/security.php b/lib/security.php deleted file mode 100644 index 99258285c..000000000 --- a/lib/security.php +++ /dev/null @@ -1,104 +0,0 @@ -<?php -/** -* ownCloud - News app -* -* @author Bernhard Posselt -* Copyright (c) 2012 - Bernhard Posselt <nukeawhale@gmail.com> -* -* This file is licensed under the Affero General Public License version 3 or later. -* See the COPYING-README file -* -*/ - - -namespace OCA\News; - - -/** - * This class is a simple object with getters and setters and allows - * finegrained controll over security checks - * All security checks are enabled by default - */ -class Security { - - private $csrfCheck; - private $loggedInCheck; - private $appEnabledCheck; - private $isAdminCheck; - private $appName; - - /** - * @param string $appName: the name of the app - */ - public function __construct($appName){ - $this->appName = $appName; - - // enable all checks by default - $this->csrfCheck = true; - $this->loggedInCheck = true; - $this->appEnabledCheck = true; - $this->isAdminCheck = true; - } - - - public function setCSRFCheck($csrfCheck){ - $this->csrfCheck = $csrfCheck; - } - - public function setLoggedInCheck($loggedInCheck){ - $this->loggedInCheck = $loggedInCheck; - } - - public function setAppEnabledCheck($appEnabledCheck){ - $this->appEnabledCheck = $appEnabledCheck; - } - - public function setIsAdminCheck($isAdminCheck){ - $this->isAdminCheck = $isAdminCheck; - } - - - /** - * Runs all security checks - */ - public function runChecks() { - - if($this->loggedInCheck){ - \OCP\JSON::checkLoggedIn(); - } - - if($this->appEnabledCheck){ - \OCP\JSON::checkAppEnabled($this->appName); - } - - if($this->isAdminCheck){ - \OCP\JSON::checkAdminUser(); - } - - } - - - /** - * Runs all the security checks for AJAX requests - */ - public function runAjaxChecks(){ - if($this->csrfCheck){ - \OCP\JSON::callCheck(); - } - - if($this->loggedInCheck){ - \OCP\JSON::checkLoggedIn(); - } - - if($this->appEnabledCheck){ - \OCP\JSON::checkAppEnabled($this->appName); - } - - if($this->isAdminCheck){ - \OCP\JSON::checkAdminUser(); - } - - } - - -}
\ No newline at end of file diff --git a/lib/share/item.php b/lib/share/item.php deleted file mode 100644 index db9ab0f48..000000000 --- a/lib/share/item.php +++ /dev/null @@ -1,44 +0,0 @@ -<?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/lib/utils.php b/lib/utils.php deleted file mode 100644 index 560114ca7..000000000 --- a/lib/utils.php +++ /dev/null @@ -1,208 +0,0 @@ -<?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; - -// load SimplePie library -//TODO: is this a suitable place for the following require? -require_once 'news/3rdparty/SimplePie/autoloader.php'; - -class Utils { - - /** - * @brief Transform a date from UNIX timestamp format to MDB2 timestamp format - * @param dbtimestamp a date in the UNIX timestamp format - * @returns a date in the MDB2 timestamp format, or NULL if an error occurred - */ - public static function unixtimeToDbtimestamp($unixtime) { - if ($unixtime === null) { - return null; - } - $dt = \DateTime::createFromFormat('U', $unixtime); - if ($dt === false) { - return null; - } - return $dt->format('Y-m-d H:i:s'); - } - - /** - * @brief Transform a date from MDB2 timestamp format to UNIX timestamp format - * @param dbtimestamp a date in the MDB2 timestamp format - * @returns a date in the UNIX timestamp format, or NULL if an error occurred - */ - public static function dbtimestampToUnixtime($dbtimestamp) { - if ($dbtimestamp === null) { - return null; - } - $dt = \DateTime::createFromFormat('Y-m-d H:i:s', $dbtimestamp); - if ($dt === false) { - return null; - } - return $dt->format('U'); - } - - /** - * @brief Fetch a feed from remote - * @param url remote url of the feed - * @returns an instance of OC_News_Feed - */ - public static function fetch($url) { - $spfeed = new \SimplePie_Core(); - $spfeed->set_feed_url( $url ); - $spfeed->enable_cache( false ); - - if (!$spfeed->init()) { - return null; - } - - //temporary try-catch to bypass SimplePie bugs - try { - $spfeed->handle_content_type(); - $title = $spfeed->get_title(); - - $items = array(); - if ($spitems = $spfeed->get_items()) { - foreach($spitems as $spitem) { - $itemUrl = $spitem->get_permalink(); - $itemTitle = $spitem->get_title(); - $itemGUID = $spitem->get_id(); - $itemBody = $spitem->get_content(); - $item = new Item($itemUrl, $itemTitle, $itemGUID, $itemBody); - - $spAuthor = $spitem->get_author(); - if ($spAuthor !== null) { - $item->setAuthor($s |