diff options
author | Jan-Christoph Borchardt <JanCBorchardt@fsfe.org> | 2011-08-28 23:38:24 +0200 |
---|---|---|
committer | Jan-Christoph Borchardt <JanCBorchardt@fsfe.org> | 2011-08-28 23:38:24 +0200 |
commit | 60a5581071e536defc06d9bb2290c7f4be39b8ac (patch) | |
tree | 08aab6cdcd2ba2989dce2147259ff7512f6f69dd /apps | |
parent | 947216942ad26fc7580a344cb24456fa17e78b4c (diff) | |
parent | 281b2187abac07826c3231816d9d4746ae2c0e91 (diff) | |
download | nextcloud-server-60a5581071e536defc06d9bb2290c7f4be39b8ac.tar.gz nextcloud-server-60a5581071e536defc06d9bb2290c7f4be39b8ac.zip |
Merge branch 'master' into calendar
Diffstat (limited to 'apps')
52 files changed, 820 insertions, 472 deletions
diff --git a/apps/bookmarks/addBm.php b/apps/bookmarks/addBm.php new file mode 100644 index 00000000000..2dab33afb22 --- /dev/null +++ b/apps/bookmarks/addBm.php @@ -0,0 +1,48 @@ +<?php + +/** +* ownCloud - bookmarks plugin +* +* @author Arthur Schiwon +* @copyright 2011 Arthur Schiwon blizzz@arthur-schiwon.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 Lesser General Public +* License along with this library. If not, see <http://www.gnu.org/licenses/>. +* +*/ + +require_once('../../lib/base.php'); + +// Check if we are a user +if( !OC_User::isLoggedIn()){ + header( 'Location: '.OC_Helper::linkTo( '', 'index.php' )); + exit(); +} + +require_once('bookmarksHelper.php'); + +OC_App::setActiveNavigationEntry( 'bookmarks_index' ); + +OC_Util::addScript('bookmarks','addBm'); +OC_Util::addStyle('bookmarks', 'bookmarks'); + +$tmpl = new OC_Template( 'bookmarks', 'addBm', 'user' ); + +$url = isset($_GET['url']) ? urldecode($_GET['url']) : ''; +$metadata = getURLMetadata($url); + +$tmpl->assign('URL', htmlentities($metadata['url'])); +$tmpl->assign('TITLE', htmlentities($metadata['title'])); +$tmpl->assign('DESCRIPTION', htmlentities($metadata['description'])); + +$tmpl->printPage();
\ No newline at end of file diff --git a/apps/bookmarks/ajax/addBookmark.php b/apps/bookmarks/ajax/addBookmark.php index d3d23aad267..78913f7a132 100644 --- a/apps/bookmarks/ajax/addBookmark.php +++ b/apps/bookmarks/ajax/addBookmark.php @@ -51,15 +51,14 @@ $query = OC_DB::prepare(" $params=array( - urldecode($_GET["url"]), - urldecode($_GET["title"]), - urldecode($_GET["description"]), + htmlspecialchars_decode($_GET["url"]), + htmlspecialchars_decode($_GET["title"]), + htmlspecialchars_decode($_GET["description"]), OC_User::getUser() ); $query->execute($params); $b_id = OC_DB::insertid(); - if($b_id !== false) { $query = OC_DB::prepare(" INSERT INTO *PREFIX*bookmarks_tags diff --git a/apps/bookmarks/ajax/delBookmark.php b/apps/bookmarks/ajax/delBookmark.php index a47bd2b9ea4..bf1611fe5c1 100644 --- a/apps/bookmarks/ajax/delBookmark.php +++ b/apps/bookmarks/ajax/delBookmark.php @@ -35,18 +35,33 @@ if( !OC_User::isLoggedIn()){ exit(); } +$params=array( + htmlspecialchars_decode($_GET["url"]), + OC_User::getUser() + ); + $query = OC_DB::prepare(" - DELETE FROM *PREFIX*bookmarks + SELECT id FROM *PREFIX*bookmarks WHERE url LIKE ? AND user_id = ? "); + +$id = $query->execute($params)->fetchOne(); + +$query = OC_DB::prepare(" + DELETE FROM *PREFIX*bookmarks + WHERE id = $id + "); -$params=array( - urldecode($_GET["url"]), - OC_User::getUser() - ); -$result = $query->execute($params); +$result = $query->execute(); + +$query = OC_DB::prepare(" + DELETE FROM *PREFIX*bookmarks_tags + WHERE bookmark_id = $id + "); + +$result = $query->execute(); // var_dump($params); echo json_encode( array( "status" => "success", "data" => array())); diff --git a/apps/bookmarks/ajax/getMeta.php b/apps/bookmarks/ajax/getMeta.php new file mode 100644 index 00000000000..e9fe0d684dc --- /dev/null +++ b/apps/bookmarks/ajax/getMeta.php @@ -0,0 +1,44 @@ +<?php + +/** +* ownCloud - bookmarks plugin +* +* @author Arthur Schiwon +* @copyright 2011 Arthur Schiwon blizzz@arthur-schiwon.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 Lesser General Public +* License along with this library. If not, see <http://www.gnu.org/licenses/>. +* +*/ + +//no apps or filesystem +$RUNTIME_NOSETUPFS=true; + +require_once('../../../lib/base.php'); + +// We send json data +header( 'Content-Type: application/jsonrequest' ); + +// Check if we are a user +if( !OC_User::isLoggedIn()){ + echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => 'Authentication error' ))); + exit(); +} + +// $metadata = array(); + +require '../bookmarksHelper.php'; +$metadata = getURLMetadata(htmlspecialchars_decode($_GET["url"])); + + +echo json_encode( array( 'status' => 'success', 'data' => $metadata)); diff --git a/apps/bookmarks/ajax/recordClick.php b/apps/bookmarks/ajax/recordClick.php index 4dcb0b4a0df..116daea8bbb 100644 --- a/apps/bookmarks/ajax/recordClick.php +++ b/apps/bookmarks/ajax/recordClick.php @@ -40,7 +40,7 @@ $query = OC_DB::prepare(" AND url LIKE ? "); -$params=array(OC_User::getUser(), urldecode($_GET["url"])); +$params=array(OC_User::getUser(), htmlspecialchars_decode($_GET["url"])); $bookmarks = $query->execute($params); header( "HTTP/1.1 204 No Content" ); diff --git a/apps/bookmarks/ajax/updateList.php b/apps/bookmarks/ajax/updateList.php index 1217a64c6e1..ceecc5b7efa 100644 --- a/apps/bookmarks/ajax/updateList.php +++ b/apps/bookmarks/ajax/updateList.php @@ -27,47 +27,61 @@ $RUNTIME_NOSETUPFS=true; require_once('../../../lib/base.php'); // We send json data -header( "Content-Type: application/jsonrequest" ); +header( 'Content-Type: application/jsonrequest' ); // Check if we are a user if( !OC_User::isLoggedIn()){ - echo json_encode( array( "status" => "error", "data" => array( "message" => "Authentication error" ))); + echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => 'Authentication error' ))); exit(); } $params=array(OC_User::getUser()); +$CONFIG_DBTYPE = OC_Config::getValue( 'dbtype', 'sqlite' ); //Filter for tag? -$filterTag = isset($_GET["tag"]) ? urldecode($_GET["tag"]) : false; +$filterTag = isset($_GET['tag']) ? '%' . htmlspecialchars_decode($_GET['tag']) . '%' : false; if($filterTag){ - $sqlFilterTag = "HAVING INSTR (tags, ?) > 0"; + $sqlFilterTag = 'HAVING tags LIKE ?'; $params[] = $filterTag; } else { $sqlFilterTag = ''; } -$offset = isset($_GET["page"]) ? intval($_GET["page"]) * 10 : 0; +$offset = isset($_GET['page']) ? intval($_GET['page']) * 10 : 0; $params[] = $offset; -$CONFIG_DBTYPE = OC_Config::getValue( "dbtype", "sqlite" ); +$sort = isset($_GET['sort']) ? ($_GET['sort']) : 'bookmarks_sorting_recent'; +if($sort == 'bookmarks_sorting_clicks') { + $sqlSort = 'clickcount DESC'; +} else { + $sqlSort = 'id DESC'; +} + if( $CONFIG_DBTYPE == 'sqlite' or $CONFIG_DBTYPE == 'sqlite3' ){ - $_gc_separator = ", ' '"; + $_gc_separator = ', \' \''; } else { - $_gc_separator = "SEPARATOR ' '"; + $_gc_separator = 'SEPARATOR \' \''; } -//FIXME: bookmarks without tags are not being retrieved -$query = OC_DB::prepare(" - SELECT url, title, description, GROUP_CONCAT( tag $_gc_separator ) AS tags +$query = OC_DB::prepare(' + SELECT url, title, description, + CASE WHEN *PREFIX*bookmarks.id = *PREFIX*bookmarks_tags.bookmark_id + THEN GROUP_CONCAT( tag ' .$_gc_separator. ' ) + ELSE \' \' + END + AS tags FROM *PREFIX*bookmarks, *PREFIX*bookmarks_tags - WHERE *PREFIX*bookmarks.id = *PREFIX*bookmarks_tags.bookmark_id + WHERE (*PREFIX*bookmarks.id = *PREFIX*bookmarks_tags.bookmark_id + OR *PREFIX*bookmarks.id NOT IN ( + SELECT *PREFIX*bookmarks_tags.bookmark_id FROM *PREFIX*bookmarks_tags + ) + ) AND *PREFIX*bookmarks.user_id = ? GROUP BY url - $sqlFilterTag - ORDER BY *PREFIX*bookmarks.id DESC - LIMIT ?, 10"); + '.$sqlFilterTag.' + ORDER BY *PREFIX*bookmarks.'.$sqlSort.' + LIMIT ?, 10'); - $bookmarks = $query->execute($params)->fetchAll(); -echo json_encode( array( "status" => "success", "data" => $bookmarks)); +echo json_encode( array( 'status' => 'success', 'data' => $bookmarks)); diff --git a/apps/bookmarks/appinfo/database.xml b/apps/bookmarks/appinfo/database.xml index 8848974d260..c30db8bd0c8 100644 --- a/apps/bookmarks/appinfo/database.xml +++ b/apps/bookmarks/appinfo/database.xml @@ -33,7 +33,7 @@ <name>description</name> <type>text</type> <default></default> - <notnull>true</notnull> + <notnull>false</notnull> <length>255</length> </field> <field> diff --git a/apps/bookmarks/bookmarksHelper.php b/apps/bookmarks/bookmarksHelper.php new file mode 100644 index 00000000000..aee941a27b9 --- /dev/null +++ b/apps/bookmarks/bookmarksHelper.php @@ -0,0 +1,23 @@ +<?php + +function getURLMetadata($url) { + //allow only http(s) and (s)ftp + $protocols = '/^[hs]{0,1}[tf]{0,1}tp[s]{0,1}\:\/\//i'; + //if not (allowed) protocol is given, assume http + if(preg_match($protocols, $url) == 0) { + $url = 'http://' . $url; + } + $metadata['url'] = $url; + + $page = file_get_contents($url); + @preg_match( "/<title>(.*)<\/title>/si", $page, $match ); + $metadata['title'] = htmlspecialchars_decode(@$match[1]); + + $meta = get_meta_tags($url); + + if(array_key_exists('description', $meta)) { + $metadata['description'] = $meta['description']; + } + + return $metadata; +}
\ No newline at end of file diff --git a/apps/bookmarks/css/bookmarks.css b/apps/bookmarks/css/bookmarks.css index aa28424c0b2..96559172448 100644 --- a/apps/bookmarks/css/bookmarks.css +++ b/apps/bookmarks/css/bookmarks.css @@ -23,10 +23,29 @@ text-decoration: underline; } +.bookmarks_sorting { + float: left; + margin-left: 2em; +} + +.bookmarks_sorting li { + padding: 1ex 1em; + border: 1px solid gray; + -moz-border-radius:1em; -webkit-border-radius:1em; border-radius:1em; +} + +.bookmarks_sorting_active { + font-weight: bold; +} + .bookmarks_add { display: none; } +.bookmarks_addBml { + text-decoration: underline; +} + .bookmarks_label { width: 7em; display: inline-block; @@ -60,4 +79,8 @@ .bookmark_tags { color: #ff3333; -}
\ No newline at end of file +} + +.clear { + clear:both; +} diff --git a/apps/bookmarks/js/addBm.js b/apps/bookmarks/js/addBm.js new file mode 100644 index 00000000000..7c914f2338a --- /dev/null +++ b/apps/bookmarks/js/addBm.js @@ -0,0 +1,17 @@ +$(document).ready(function() { + $('#bookmark_add_submit').click(addBookmark); +}); + +function addBookmark(event) { + var url = $('#bookmark_add_url').val(); + var title = $('#bookmark_add_title').val(); + var description = $('#bookmark_add_description').val(); + var tags = $('#bookmark_add_tags').val(); + $.ajax({ + url: 'ajax/addBookmark.php', + data: 'url=' + encodeURI(url) + '&title=' + encodeURI(title) + '&description=' + encodeURI(description) + '&tags=' + encodeURI(tags), + success: function(data){ + location.href='index.php'; + } + }); +}
\ No newline at end of file diff --git a/apps/bookmarks/js/bookmarks.js b/apps/bookmarks/js/bookmarks.js index 04db8b42a79..ac87d967be8 100644 --- a/apps/bookmarks/js/bookmarks.js +++ b/apps/bookmarks/js/bookmarks.js @@ -1,6 +1,8 @@ var bookmarks_page = 0; var bookmarks_loading = false; +var bookmarks_sorting = 'bookmarks_sorting_recent'; + $(document).ready(function() { $('.bookmarks_addBtn').click(function(event){ $('.bookmarks_add').slideToggle(); @@ -9,6 +11,11 @@ $(document).ready(function() { $('#bookmark_add_submit').click(addBookmark); $(window).scroll(updateOnBottom); + $('#bookmark_add_url').focusout(getMetadata); + $('.' + bookmarks_sorting).addClass('bookmarks_sorting_active'); + + $('.bookmarks_sorting li').click(function(event){changeSorting(this)}); + $('.bookmarks_list').empty(); getBookmarks(); }); @@ -18,9 +25,10 @@ function getBookmarks() { //have patience :) return; } + $.ajax({ url: 'ajax/updateList.php', - data: 'tag=' + encodeURI($('#bookmarkFilterTag').val()) + '&page=' + bookmarks_page, + data: 'tag=' + encodeURI($('#bookmarkFilterTag').val()) + '&page=' + bookmarks_page + '&sort=' + bookmarks_sorting, success: function(bookmarks){ bookmarks_page += 1; $('.bookmark_link').unbind('click', recordClick); @@ -36,6 +44,30 @@ function getBookmarks() { }); } +function getMetadata() { + var url = encodeEntities($('#bookmark_add_url').val()) + $.ajax({ + url: 'ajax/getMeta.php', + data: 'url=' + encodeURIComponent(url), + success: function(pageinfo){ + $('#bookmark_add_url').val(pageinfo.data.url); + $('#bookmark_add_description').val(pageinfo.data.description); + $('#bookmark_add_title').val(pageinfo.data.title); + } + }); +} + +function changeSorting(sortEl) { + $('.' + bookmarks_sorting).removeClass('bookmarks_sorting_active'); + bookmarks_sorting = sortEl.className; + $('.' + bookmarks_sorting).addClass('bookmarks_sorting_active'); + + $('.bookmarks_list').empty(); + bookmarks_page = 0; + bookmarks_loading = false; + getBookmarks(); +} + function addBookmark(event) { var url = encodeEntities($('#bookmark_add_url').val()) var title = encodeEntities($('#bookmark_add_title').val()) @@ -80,6 +112,9 @@ function updateBookmarksList(bookmark) { for ( var i=0, len=tags.length; i<len; ++i ){ taglist = taglist + '<a class="bookmark_tags" href="?tag=' + encodeURI(tags[i]) + '">' + tags[i] + '</a> '; } + if(!hasProtocol(bookmark.url)) { + bookmark.url = 'http://' + bookmark.url; + } $('.bookmarks_list').append( '<div class="bookmark_single">' + '<p class="bookmark_title"><a href="' + encodeEntities(bookmark.url) + '" target="_new" class="bookmark_link">' + encodeEntities(bookmark.title) + '</a></p>' + @@ -113,3 +148,8 @@ function encodeEntities(s){ return ""; } } + +function hasProtocol(url) { + var regexp = /(ftp|http|https|sftp)/; + return regexp.test(url); +} diff --git a/apps/bookmarks/templates/addBm.php b/apps/bookmarks/templates/addBm.php new file mode 100644 index 00000000000..cbc4910e1ae --- /dev/null +++ b/apps/bookmarks/templates/addBm.php @@ -0,0 +1,8 @@ +<div class="bookmarks_addBm"> + <p><label class="bookmarks_label">Address</label><input type="text" id="bookmark_add_url" class="bookmarks_input" value="<? echo $_['URL']; ?>"/></p> + <p><label class="bookmarks_label">Title</label><input type="text" id="bookmark_add_title" class="bookmarks_input" value="<? echo $_['TITLE']; ?>" /></p> + <p><label class="bookmarks_label">Description</label><input type="text" id="bookmark_add_description" class="bookmarks_input" value="<? echo $_['DESCRIPTION']; ?>" /></p> + <p><label class="bookmarks_label">Tags</label><input type="text" id="bookmark_add_tags" class="bookmarks_input" /></p> + <p><label class="bookmarks_label"> </label><label class="bookmarks_hint">Hint: Use space to separate tags.</label></p> + <p><label class="bookmarks_label"></label><input type="submit" id="bookmark_add_submit" /></p> +</div>
\ No newline at end of file diff --git a/apps/bookmarks/templates/list.php b/apps/bookmarks/templates/list.php index 769ad815244..4f101d44f90 100644 --- a/apps/bookmarks/templates/list.php +++ b/apps/bookmarks/templates/list.php @@ -1,7 +1,8 @@ -<input type="hidden" id="bookmarkFilterTag" value="<?php echo htmlentities($_GET['tag']); ?>" /> +<input type="hidden" id="bookmarkFilterTag" value="<?php if(isset($_GET['tag'])) echo htmlentities($_GET['tag']); ?>" /> <h2 class="bookmarks_headline"><?php echo isset($_GET["tag"]) ? 'Bookmarks with tag: ' . urldecode($_GET["tag"]) : 'All bookmarks'; ?></h2> <div class="bookmarks_menu"> - <input type="button" class="bookmarks_addBtn" value="Add Bookmark" /> + <input type="button" class="bookmarks_addBtn" value="Add Bookmark"/> + <a class="bookmarks_addBml" href="javascript:var url = encodeURIComponent(location.href);window.open('<?php echo (isset($_SERVER['HTTPS']) ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . OC_Helper::linkTo('bookmarks', 'addBm.php'); ?>?url='+url, 'owncloud-bookmarks');" title="Drag this to your browser bookmarks and click it, when you want to bookmark a webpage.">Add page to ownCloud</a> </div> <div class="bookmarks_add"> <p><label class="bookmarks_label">Address</label><input type="text" id="bookmark_add_url" class="bookmarks_input" /></p> @@ -11,6 +12,13 @@ <p><label class="bookmarks_label"> </label><label class="bookmarks_hint">Hint: Use space to separate tags.</label></p> <p><label class="bookmarks_label"></label><input type="submit" id="bookmark_add_submit" /></p> </div> +<div class="bookmarks_sorting pager"> + <ul> + <li class="bookmarks_sorting_recent">Recent Bookmarks</li> + <li class="bookmarks_sorting_clicks">Most clicks</li> + </ul> +</div> +<div class="clear"></div> <div class="bookmarks_list"> <noscript> JavaScript is needed to display your Bookmarks diff --git a/apps/contacts/templates/index.php b/apps/contacts/templates/index.php index ffcca50b34d..46e85a09d11 100644 --- a/apps/contacts/templates/index.php +++ b/apps/contacts/templates/index.php @@ -13,5 +13,5 @@ OC_Util::addStyle('contacts','styles'); <?php echo $this->inc("part.details"); ?> </div> <?php if(count($_['addressbooks']) == 1 ): ?> - <?php echo $l->t('The path to this addressbook is %s', array(OC::$WEBROOT.'/apps/contacts/carddav.php/addressbooks/'.OC_User::getUser().'/'.$_['addressbooks'][0]['uri'])); ?> + <?php echo $l->t('The path to this addressbook is %s', array(((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https' : 'http').'://'.$_SERVER['HTTP_HOST'].OC::$WEBROOT.'/apps/contacts/carddav.php/addressbooks/'.OC_User::getUser().'/'.$_['addressbooks'][0]['uri'])); ?> <?php endif; ?> diff --git a/apps/contacts/templates/part.details.php b/apps/contacts/templates/part.details.php index 5048349abc5..81b32f2ff56 100644 --- a/apps/contacts/templates/part.details.php +++ b/apps/contacts/templates/part.details.php @@ -30,6 +30,6 @@ <?php endif; ?> <div id="contacts_cardoptions"> - <a id="contacts_deletecard"><img class="svg action" src="<?php echo image_path('', 'actions/delete.svg'); ?>" /></a> - <a id="contacts_addproperty"><img class="svg action" src="<?php echo image_path('', 'actions/download.svg'); ?>" /></a> + <a id="contacts_deletecard"><img class="svg action" alt="<?php echo $l->t('Delete');?>" src="<?php echo image_path('', 'actions/delete.svg'); ?>" /></a> + <a id="contacts_addproperty"><img class="svg action" alt="<?php echo $l->t('Download');?>" src="<?php echo image_path('', 'actions/download.svg'); ?>" /></a> </div> diff --git a/apps/contacts/temporaryupdate.php b/apps/contacts/temporaryupdate.php deleted file mode 100644 index 4b6453364e3..00000000000 --- a/apps/contacts/temporaryupdate.php +++ /dev/null @@ -1,33 +0,0 @@ -<?php -/** - * ownCloud - Addressbook - * - * @author Jakob Sack - * @copyright 2011 Jakob Sack mail@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/>. - * - */ -// Init owncloud -require_once('../../lib/base.php'); -$connector = new OC_Connector_Sabre_Principal; -$users = OC_User::getUsers(); - -foreach($users as $user){ - $foo = $connector->getPrincipalByPath('principals/'.$user); - if(!isset($foo)){ - OC_Connector_Sabre_Principal::addPrincipal(array('uid'=>$user)); - } -} -echo "done";
\ No newline at end of file diff --git a/apps/files_sharing/ajax/getitem.php b/apps/files_sharing/ajax/getitem.php index cdb59b9cd1b..249af6cfa31 100644 --- a/apps/files_sharing/ajax/getitem.php +++ b/apps/files_sharing/ajax/getitem.php @@ -6,17 +6,18 @@ require_once('../lib_share.php'); $userDirectory = "/".OC_User::getUser()."/files"; $source = $userDirectory.$_GET['source']; -$users = OC_Share::getMySharedItem($source); $path = $source; -for ($i = 0; $i < count($users); $i++) { - if ($users[$i]['uid_shared_with'] == OC_Share::PUBLICLINK) { - $users[$i]['token'] = OC_Share::getTokenFromSource($source); +if ($users = OC_Share::getMySharedItem($source)) { + for ($i = 0; $i < count($users); $i++) { + if ($users[$i]['uid_shared_with'] == OC_Share::PUBLICLINK) { + $users[$i]['token'] = OC_Share::getTokenFromSource($source); + } } } $source = dirname($source); while ($source != "" && $source != "/" && $source != "." && $source != $userDirectory) { - $values = array_values(OC_Share::getMySharedItem($source)); - if (count($values) > 0) { + if ($values = OC_Share::getMySharedItem($source)) { + $values = array_values($values); $parentUsers = array(); for ($i = 0; $i < count($values); $i++) { if ($values[$i]['uid_shared_with'] == OC_Share::PUBLICLINK) { diff --git a/apps/files_sharing/ajax/share.php b/apps/files_sharing/ajax/share.php index d9bf4ff7abe..e672cf02403 100644 --- a/apps/files_sharing/ajax/share.php +++ b/apps/files_sharing/ajax/share.php @@ -4,20 +4,25 @@ $RUNTIME_NOAPPS = true; require_once('../../../lib/base.php'); require_once('../lib_share.php'); +$userDirectory = "/".OC_User::getUser()."/files"; $sources = explode(";", $_POST['sources']); $uid_shared_with = $_POST['uid_shared_with']; $permissions = $_POST['permissions']; foreach ($sources as $source) { + // Make sure file exists and can be shared if ($source && OC_FILESYSTEM::file_exists($source) && OC_FILESYSTEM::is_readable($source)) { - $source = "/".OC_User::getUser()."/files".$source; - try { - $shared = new OC_Share($source, $uid_shared_with, $permissions); - if ($uid_shared_with == OC_Share::PUBLICLINK) { - echo $shared->getToken(); - } - } catch (Exception $exception) { - echo "false"; + $source = $userDirectory.$source; + // If the file doesn't exist, it may be shared with the current user + } else if (!$source = OC_Share::getSource($userDirectory.$source)) { + echo "false"; + } + try { + $shared = new OC_Share($source, $uid_shared_with, $permissions); + if ($uid_shared_with == OC_Share::PUBLICLINK) { + echo $shared->getToken(); } + } catch (Exception $exception) { + echo "false"; } } diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php index 771d91b93ba..c175142319f 100644 --- a/apps/files_sharing/appinfo/app.php +++ b/apps/files_sharing/appinfo/app.php @@ -1,9 +1,11 @@ <?php -require_once('apps/files_sharing/lib_share.php'); require_once('apps/files_sharing/sharedstorage.php'); -OC_Filesystem::registerStorageType("shared", "OC_Filestorage_Shared", array("datadir"=>"string")); +OC::$CLASSPATH['OC_Share'] = "apps/files_sharing/lib_share.php"; +OC_Hook::connect("OC_Filesystem", "post_delete", "OC_Share", "deleteItem"); +OC_Hook::connect("OC_Filesystem", "post_rename", "OC_Share", "renameItem"); +OC_Filesystem::registerStorageType("shared", "OC_Filestorage_Shared", array("datadir" => "string")); OC_Util::addScript("files_sharing", "share"); OC_Util::addScript("3rdparty", "chosen/chosen.jquery.min"); OC_Util::addStyle( 'files_sharing', 'sharing' ); diff --git a/apps/files_sharing/get.php b/apps/files_sharing/get.php index e50a319ace4..a1b6c316cd5 100644 --- a/apps/files_sharing/get.php +++ b/apps/files_sharing/get.php @@ -67,7 +67,7 @@ if ($source !== false) { header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Pragma: public"); - header("Content-Disposition: filename='".basename($source)."'"); + header("Content-Disposition: filename=".basename($source)); header("Content-Type: " . $mimetype); header("Content-Length: " . OC_Filesystem::filesize($source)); //download the file @@ -80,4 +80,4 @@ if ($source !== false) { $tmpl->printPage(); die(); } -?>
\ No newline at end of file +?> diff --git a/apps/files_sharing/js/share.js b/apps/files_sharing/js/share.js index 1fae8cbdc95..1bd1ac1075b 100644 --- a/apps/files_sharing/js/share.js +++ b/apps/files_sharing/js/share.js @@ -117,7 +117,7 @@ $(document).ready(function() { cache: false, data: data, success: function() { - var option = "<option value='"+uid_shared_with+"'>"+uid_shared_with+"</option>"; + var option = '<option value="'+uid_shared_with+'">'+uid_shared_with+'</option>'; $(user).remove(); $(option).appendTo('#share_with'); $('#share_with').trigger('liszt:updated'); @@ -128,7 +128,7 @@ $(document).ready(function() { $('#makelink').live('change', function() { if (this.checked) { var source = $('#dropdown').data('file'); - var uid_shared_with = "public"; + var uid_shared_with = 'public'; var permissions = 0; var data = 'sources='+encodeURIComponent(source)+'&uid_shared_with='+encodeURIComponent(uid_shared_with)+'&permissions='+encodeURIComponent(permissions); $.ajax({ @@ -144,7 +144,7 @@ $(document).ready(function() { }); } else { var source = $('#dropdown').data('file'); - var uid_shared_with = "public"; + var uid_shared_with = 'public'; var data = 'source='+encodeURIComponent(source)+'&uid_shared_with='+encodeURIComponent(uid_shared_with); $.ajax({ type: 'GET', @@ -165,19 +165,19 @@ $(document).ready(function() { }); function createDropdown(filename, files) { - var html = "<div id='dropdown' class='drop' data-file='"+files+"'>"; - html += "<div id='private'>"; - html += "<select data-placeholder='User or Group' style='width:220px;' id='share_with' class='chzen-select'>"; - html += "<option value=''></option>"; - html += "</select>"; - html += "<ul id='shared_list'></ul>"; - html += "</div>"; - html += "<div id='public'>"; - html += "<input type='checkbox' name='makelink' id='makelink' value='1' /><label for='makelink'>make public</label>"; - //html += "<input type='checkbox' name='public_link_write' id='public_link_write' value='1' /><label for='public_link_write'>allow upload</label>"; - html += "<br />"; - html += "<input id='link' style='display:none; width:90%;' />"; - html += "</div>"; + var html = '<div id="dropdown" class="drop" data-file="'+files+'">'; + html += '<div id="private">'; + html += '<select data-placeholder="User or Group" style="width:220px;" id="share_with" class="chzen-select">'; + html += '<option value=""></option>'; + html += '</select>'; + html += '<ul id="shared_list"></ul>'; + html += '</div>'; + html += '<div id="public">'; + html += '<input type="checkbox" name="makelink" id="makelink" value="1" /><label for="makelink">make public</label>'; + //html += '<input type="checkbox" name="public_link_write" id="public_link_write" value="1" /><label for="public_link_write">allow upload</label>'; + html += '<br />'; + html += '<input id="link" style="display:none; width:90%;" />'; + html += '</div>'; if (filename) { $('tr[data-file="'+filename+'"]').addClass('mouseOver'); $(html).appendTo($('tr[data-file="'+filename+'"] td.filename')); @@ -211,13 +211,13 @@ function createDropdown(filename, files) { function addUser(uid_shared_with, permissions, parentFolder) { if (parentFolder) { - var user = "<li>Parent folder "+parentFolder+" shared with "+uid_shared_with+"</li>"; + var user = '<li>Parent folder '+parentFolder+' shared with '+uid_shared_with+'</li>'; } else { - var checked = ((permissions > 0) ? "checked='checked'" : "style='display:none;'"); - var style = ((permissions == 0) ? "style='display:none;'" : ""); - var user = "<li data-uid_shared_with='"+uid_shared_with+"'>"+uid_shared_with; - user += "<input type='checkbox' name='permissions' id='"+uid_shared_with+"' class='permissions' "+checked+"/><label for='"+uid_shared_with+"' "+style+">can edit</label>"; - user += "<a href='' title='Unshare' class='unshare' style='display:none;'><img class='svg' src='"+OC.imagePath('core','actions/delete')+"'/></a></li>"; + var checked = ((permissions > 0) ? 'checked="checked"' : 'style="display:none;"'); + var style = ((permissions == 0) ? 'style="display:none;"' : ''); + var user = '<li data-uid_shared_with="'+uid_shared_with+'">'+uid_shared_with; + user += '<input type="checkbox" name="permissions" id="'+uid_shared_with+'" class="permissions" "+checked+" /><label for="'+uid_shared_with+'" '+style+'>can edit</label>'; + user += '<a href="" class="unshare" style="display:none;"><img class="svg" alt="Unshare" src="'+OC.imagePath('core','actions/delete')+'"/></a></li>'; } $('#share_with option[value="'+uid_shared_with+'"]').remove(); $('#share_with').trigger('liszt:updated'); @@ -227,6 +227,6 @@ function addUser(uid_shared_with, permissions, parentFolder) { function showPublicLink(token) { $('#makelink').attr('checked', true); $('#link').data('token', token); - $('#link').val(parent.location.protocol+"//"+location.host+OC.linkTo('files_sharing','get.php')+'?token='+token); + $('#link').val(parent.location.protocol+'//'+location.host+OC.linkTo('files_sharing','get.php')+'?token='+token); $('#link').show('blind'); } diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index df704c131e7..978847f4a8f 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -20,9 +20,6 @@ * */ -OC_Hook::connect("OC_FILESYSTEM","post_delete", "OC_Share", "deleteItem"); -OC_Hook::connect("OC_FILESYSTEM","post_rename", "OC_Share", "renameItem"); - /** * This class manages shared items within the database. */ @@ -69,7 +66,8 @@ class OC_Share { throw new Exception("This item is already shared with ".$uid); } // Check if the target already exists for the user, if it does append a number to the name - $target = "/".$uid."/files/Shared/".basename($source); + $sharedFolder = "/".$uid."/files/Shared"; + $target = $sharedFolder."/".basename($source); if (self::getSource($target)) { if ($pos = strrpos($target, ".")) { $name = substr($target, 0, $pos); @@ -90,6 +88,9 @@ class OC_Share { $uid = $uid."@".$gid; } $query->execute(array($uid_owner, $uid, $source, $target, $permissions)); + // Clear the folder size cache for the 'Shared' folder + $clearFolderSize = OC_DB::prepare("DELETE FROM *PREFIX*foldersize WHERE path = ?"); + $clearFolderSize->execute(array($sharedFolder)); } } } @@ -175,8 +176,16 @@ class OC_Share { public static function getMySharedItem($source) { $source = self::cleanPath($source); $query = OC_DB::prepare("SELECT uid_shared_with, permissions FROM *PREFIX*sharing WHERE source = ? AND uid_owner = ?"); - return $query->execute(array($source, OC_User::getUser()))->fetchAll(); + $result = $query->execute(array($source, OC_User::getUser()))->fetchAll(); + if (count($result) > 0) { + return $result; + } else if ($originalSource = self::getSource($source)) { + return $query->execute(array($originalSource, OC_User::getUser()))->fetchAll(); + } else { + return false; + } } + /** * Get all items the current user is sharing * @return An array with all items the user is sharing @@ -185,7 +194,7 @@ class OC_Share { $query = OC_DB::prepare("SELECT uid_shared_with, source, permissions FROM *PREFIX*sharing WHERE uid_owner = ?"); return $query->execute(array(OC_User::getUser()))->fetchAll(); } - + /** * Get the items within a shared folder that have their own entry for the purpose of name, location, or permissions that differ from the folder itself * @@ -204,7 +213,7 @@ class OC_Share { $query = OC_DB::prepare("SELECT uid_owner, source, target, permissions FROM *PREFIX*sharing WHERE SUBSTR(source, 1, ?) = ? OR SUBSTR(target, 1, ?) = ? AND uid_shared_with ".self::getUsersAndGroups()); return $query->execute(array($length, $folder, $length, $folder))->fetchAll(); } - + /** * Get the source and target parent folders of the specified target location * @param $target The target location of the item @@ -302,18 +311,6 @@ class OC_Share { } /** - * Set the source location to a new value - * @param $oldSource The current source location - * @param $newTarget The new source location - */ - public static function setSource($oldSource, $newSource) { - $oldSource = self::cleanPath($oldSource); - $newSource = self::cleanPath($newSource); - $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET source = REPLACE(source, ?, ?) WHERE uid_owner = ?"); - $query->execute(array($oldSource, $newSource, OC_User::getUser())); - } - - /** * Set the target location to a new value * * You must use the pullOutOfFolder() function to change the target location of a file inside a shared folder if the target location differs from the folder @@ -327,7 +324,7 @@ class OC_Share { $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET target = REPLACE(target, ?, ?) WHERE uid_shared_with ".self::getUsersAndGroups()); $query->execute(array($oldTarget, $newTarget)); } - + /** * Change the permissions for the specified item and user * @@ -342,7 +339,7 @@ class OC_Share { $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET permissions = ? WHERE SUBSTR(source, 1, ?) = ? AND uid_owner = ? AND uid_shared_with ".self::getUsersAndGroups($uid_shared_with)); $query->execute(array($permissions, strlen($source), $source, OC_User::getUser())); } - + /** * Unshare the item, removes it from all specified users * @@ -356,13 +353,14 @@ class OC_Share { $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE SUBSTR(source, 1, ?) = ? AND uid_owner = ? AND uid_shared_with ".self::getUsersAndGroups($uid_shared_with)); $query->execute(array(strlen($source), $source, OC_User::getUser())); } - + /** * Unshare the item from the current user, removes it only from the database and doesn't touch the source file * - * You must use the pullOutOfFolder() function to unshare a file inside a shared folder and set $newTarget to nothing + * You must use the pullOutOfFolder() function before you call unshareFromMySelf() and set the delete parameter to false to unshare from self a file inside a shared folder * * @param $target The target location of the item + * @param $delete (Optional) If true delete the entry from the database, if false the permission is set to UNSHARED */ public static function unshareFromMySelf($target, $delete = true) { $target = self::cleanPath($target); @@ -377,25 +375,23 @@ class OC_Share { /** * Remove the item from the database, the owner deleted the file - * @param $arguments Array of arguments passed from OC_HOOK + * @param $arguments Array of arguments passed from OC_Hook */ public static function deleteItem($arguments) { - $source = "/".OC_User::getUser()."/files".$arguments['path']; - $source = self::cleanPath($source); + $source = "/".OC_User::getUser()."/files".self::cleanPath($arguments['path']); $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE SUBSTR(source, 1, ?) = ? AND uid_owner = ?"); $query->execute(array(strlen($source), $source, OC_User::getUser())); } /** * Rename the item in the database, the owner renamed the file - * @param $arguments Array of arguments passed from OC_HOOK + * @param $arguments Array of arguments passed from OC_Hook */ public static function renameItem($arguments) { - $oldSource = "/".OC_User::getUser()."/files".$arguments['oldpath']; - $oldSource = self::cleanPath($oldSource); - $newSource = "/".OC_User::getUser()."/files".$arguments['newpath']; - $newSource = self::cleanPath($newSource); - self::setSource($oldSource, $newSource); + $oldSource = "/".OC_User::getUser()."/files".self::cleanPath($arguments['oldpath']); + $newSource = "/".OC_User::getUser()."/files".self::cleanPath($arguments['newpath']); + $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET source = REPLACE(source, ?, ?) WHERE uid_owner = ?"); + $query->execute(array($oldSource, $newSource, OC_User::getUser())); } } diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index 695fe3160ab..53f25b60e91 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -79,37 +79,37 @@ class OC_Filestorage_Shared extends OC_Filestorage { public function opendir($path) { if ($path == "" || $path == "/") { - global $FAKEDIRS; $path = $this->datadir.$path; $sharedItems = OC_Share::getItemsInFolder($path); if (empty($sharedItems)) { return false; - } - $files = array(); - foreach ($sharedItems as $item) { - // If item is in the root of the shared storage provider add it to the fakedirs - if (dirname($item['target'])."/" == $path) { - $files[] = basename($item['target']); + } else { + global $FAKEDIRS; + $files = array(); + foreach ($sharedItems as $item) { + // If item is in the root of the shared storage provider and the item exists add it to the fakedirs + if (dirname($item['target'])."/" == $path && $this->file_exists(basename($item['target']))) { + $files[] = basename($item['target']); + } } + $FAKEDIRS['shared'] = $files; + return opendir('fakedir://shared'); } - $FAKEDIRS['shared'] = $files; - return opendir('fakedir://shared'); } else { $source = $this->getSource($path); if ($source) { $storage = OC_Filesystem::getStorage($source); $dh = $storage->opendir($this->getInternalPath($source)); - // Remove any duplicate or trailing '/' - $path = rtrim($this->datadir.$path, "/"); - $path = preg_replace('{(/)\1+}', "/", $path); $modifiedItems = OC_Share::getItemsInFolder($source); if ($modifiedItems && $dh) { - global $FAKEDIRS; $sources = array(); $targets = array(); + // Remove any duplicate or trailing '/' + $path = preg_replace('{(/)\1+}', "/", $path); + $targetFolder = rtrim($this->datadir.$path, "/"); foreach ($modifiedItems as $item) { - // If the item is in the current directory and has a different name than the source, add it to the arrays - if (dirname($item['target']) == $path) { + // If the item is in the current directory and the item exists add it to the arrays + if (dirname($item['target']) == $targetFolder && $this->file_exists($path."/".basename($item['target']))) { // If the item was unshared from self, add it it to the arrays if ($item['permissions'] == OC_Share::UNSHARED) { $sources[] = basename($item['source']); @@ -124,6 +124,7 @@ class OC_Filestorage_Shared extends OC_Filestorage { if (empty($sources)) { return $dh; } else { + global $FAKEDIRS; $files = array(); while (($filename = readdir($dh)) !== false) { if ($filename != "." && $filename != "..") { @@ -210,7 +211,6 @@ class OC_Filestorage_Shared extends OC_Filestorage { } public function filesize($path) { - if ($path == "" || $path == "/" || $this->is_dir($path)) { return $this->getFolderSize($path); } else { @@ -221,10 +221,14 @@ class OC_Filestorage_Shared extends OC_Filestorage { } } } - + public function getFolderSize($path) { - $dbpath = OC_User::getUser()."/files/Share/".$path."/"; - $query = OC_DB::prepare("SELECT size FROM *PREFIX*foldersize WHERE path=?"); + // Shared folder sizes are cached separately from the source folder sizes because folders can have different names + $path = rtrim($path, "/"); + $path = ltrim($path, "/"); + $path = preg_replace('{(/)\1+}', "/", $path); + $dbpath = rtrim($this->datadir.$path, "/"); + $query = OC_DB::prepare("SELECT size FROM *PREFIX*foldersize WHERE path = ?"); $size = $query->execute(array($dbpath))->fetchAll(); if (count($size) > 0) { return $size[0]['size']; @@ -233,19 +237,15 @@ class OC_Filestorage_Shared extends OC_Filestorage { } } - public function calculateFolderSize($path) { + private function calculateFolderSize($path) { if ($this->is_file($path)) { $path = dirname($path); } - $path = str_replace("//", "/", $path); - if ($this->is_dir($path) && substr($path, -1) != "/") { - $path .= "/"; - } $size = 0; if ($dh = $this->opendir($path)) { while (($filename = readdir($dh)) !== false) { if ($filename != "." && $filename != "..") { - $subFile = $path.$filename; + $subFile = $path."/".$filename; if ($this->is_file($subFile)) { $size += $this->filesize($subFile); } else { @@ -254,7 +254,7 @@ class OC_Filestorage_Shared extends OC_Filestorage { } } if ($size > 0) { - $dbpath = OC_User::getUser()."/files/Share/".$path; + $dbpath = rtrim($this->datadir.$path, "/"); $query = OC_DB::prepare("INSERT INTO *PREFIX*foldersize VALUES(?,?)"); $result = $query->execute(array($dbpath, $size)); } @@ -262,16 +262,15 @@ class OC_Filestorage_Shared extends OC_Filestorage { return $size; } - public function clearFolderSizeCache($path){ + private function clearFolderSizeCache($path) { + $path = rtrim($path, "/"); + $path = preg_replace('{(/)\1+}', "/", $path); if ($this->is_file($path)) { $path = dirname($path); } - $path = str_replace("//", "/", $path); - if ($this->is_dir($path) && substr($path, -1) != "/") { - $path .= "/"; - } + $dbpath = rtrim($this->datadir.$path, "/"); $query = OC_DB::prepare("DELETE FROM *PREFIX*foldersize WHERE path = ?"); - $result = $query->execute(array($path)); + $result = $query->execute(array($dbpath)); if ($path != "/" && $path != "") { $parts = explode("/", $path); $part = array_pop($parts); @@ -391,7 +390,11 @@ class OC_Filestorage_Shared extends OC_Filestorage { $source = $this->getSource($path); if ($source) { $storage = OC_Filesystem::getStorage($source); - return $storage->file_put_contents($this->getInternalPath($source), $data); + $result = $storage->file_put_contents($this->getInternalPath($source), $data); + if ($result) { + $this->clearFolderSizeCache($path); + } + return $result; } } } @@ -459,7 +462,11 @@ class OC_Filestorage_Shared extends OC_Filestorage { } else { if ($this->is_writeable($path2)) { $tmpFile = $this->toTmpFile($path1); - return $this->fromTmpFile($tmpFile, $path2); + $result = $this->fromTmpFile($tmpFile, $path2); + if ($result) { + $this->clearFolderSizeCache($path2); + } + return $result; } else { return false; } @@ -487,70 +494,38 @@ class OC_Filestorage_Shared extends OC_Filestorage { $source = $this->getSource($path); if ($source) { $storage = OC_Filesystem::getStorage($source); - return $storage->fromTmpFile($tmpFile, $this->getInternalPath($source)); + $result = $storage->fromTmpFile($tmpFile, $this->getInternalPath($source)); + if ($result) { + $this->clearFolderSizeCache($path); + } + return $result; } } else { return false; } } - public function fromUploadedFile($tmpPath, $path) { - $source = $this->getSource($tmpPath); - if ($source) { - $storage = OC_Filesystem::getStorage($source); - return $storage->fromUploadedFile($this->getInternalPath($source), $path); - } - } - - public function getMimeType($path) { - $source = $this->getSource($path); - if ($source) { - $storage = OC_Filesystem::getStorage($source); - return $storage->getMimeType($this->getInternalPath($source)); - } - } - - public function delTree($path) { - $target = $this->datadir.$path; - if (OC_Share::getPermissions($target) & OC_Share::DELETE) { + public function fromUploadedFile($tmpFile, $path) { + if ($this->is_writeable($path)) { $source = $this->getSource($path); if ($source) { $storage = OC_Filesystem::getStorage($source); - return $storage->delTree($this->getInternalPath($source)); - } - } else { - // Check if the folder is inside a shared folder - if (OC_Share::getParentFolders($target)) { - // If entry for folder already exists - if (OC_Share::getItem($target)) { - OC_Share::setTarget($target, "/"); - } else { - OC_Share::pullOutOfFolder($target, "/"); - // Call setTarget in case there are any database entries for items inside this folder - OC_Share::setTarget($target, "/"); + $result = $storage->fromUploadedFile($tmpFile, $this->getInternalPath($source)); + if ($result) { + $this->clearFolderSizeCache($path); } - // Delete the database entry - } else { - OC_Share::unshareFromMySelf($target); + return $result; } - $this->clearFolderSizeCache($this->getInternalPath($target)); - return true; - } - } - - public function find($path) { - $source = $this->getSource($path); - if ($source) { - $storage = OC_Filesystem::getStorage($source); - return $storage->find($this->getInternalPath($source)); + } else { + return false; } } - public function getTree($path) { + public function getMimeType($path) { $source = $this->getSource($path); if ($source) { $storage = OC_Filesystem::getStorage($source); - return $storage->getTree($this->getInternalPath($source)); + return $storage->getMimeType($this->getInternalPath($source)); } } @@ -570,9 +545,33 @@ class OC_Filestorage_Shared extends OC_Filestorage { } } - // TODO query all shared files? - public function search($query) { - + public function search($query) { + return $this->searchInDir($query); + } + + private function searchInDir($query, $path = "") { + $files = array(); + if ($dh = $this->opendir($path)) { + while (($filename = readdir($dh)) !== false) { + if ($filename != "." && $filename != "..") { + if (strstr(strtolower($filename), strtolower($query))) { + $files[] = $path."/".$filename; + } + if ($this->is_dir($path."/".$filename)) { + $files = array_merge($files, $this->searchInDir($query, $path."/".$filename)); + } + } + } + } + return $files; + } + + public function getLocalFile($path) { + $source = $this->getSource($path); + if ($source) { + $storage = OC_Filesystem::getStorage($source); + return $storage->getLocalFile($this->getInternalPath($source)); + } } } diff --git a/apps/files_textviewer/js/textviewer.js b/apps/files_textviewer/js/textviewer.js index b1a564df9bb..143c97c9d47 100644 --- a/apps/files_textviewer/js/textviewer.js +++ b/apps/files_textviewer/js/textviewer.js @@ -122,10 +122,9 @@ $(document).ready(function() { a.data('file',text); a.attr('href','#'); a.click(function(){ - var file=$(this).data('file'); - var text=file.split('/').pop(); - var dir=file.substr(0,file.length-file.length-1); - TextViewer.showText(dir,text); + var file=text.split('/').pop(); + var dir=text.substr(0,text.length-file.length-1); + TextViewer.showText(dir,file); }); } }); diff --git a/apps/media/ajax/api.php b/apps/media/ajax/api.php index a9bd4f745af..3b4932728da 100644 --- a/apps/media/ajax/api.php +++ b/apps/media/ajax/api.php @@ -56,7 +56,6 @@ OC_MEDIA_COLLECTION::$uid=OC_User::getUser(); if($arguments['action']){ switch($arguments['action']){ case 'delete': - unset($_SESSION['collection']); $path=$arguments['path']; OC_MEDIA_COLLECTION::deleteSongByPath($path); $paths=explode(PATH_SEPARATOR,OC_Preferences::getValue(OC_User::getUser(),'media','paths','')); @@ -65,21 +64,13 @@ if($arguments['action']){ OC_Preferences::setValue(OC_User::getUser(),'media','paths',implode(PATH_SEPARATOR,$paths)); } case 'get_collection': - if(!isset($_SESSION['collection'])){ - $artists=OC_MEDIA_COLLECTION::getArtists(); - foreach($artists as &$artist){ - $artist['albums']=OC_MEDIA_COLLECTION::getAlbums($artist['artist_id']); - foreach($artist['albums'] as &$album){ - $album['songs']=OC_MEDIA_COLLECTION::getSongs($artist['artist_id'],$album['album_id']); - } - } - - $_SESSION['collection']=json_encode($artists); - } - echo $_SESSION['collection']; + $data=array(); + $data['artists']=OC_MEDIA_COLLECTION::getArtists(); + $data['albums']=OC_MEDIA_COLLECTION::getAlbums(); + $data['songs']=OC_MEDIA_COLLECTION::getSongs(); + echo json_encode($data); break; case 'scan': - unset($_SESSION['collection']); OC_DB::beginTransaction(); set_time_limit(0); //recursive scan can take a while $path=$arguments['path']; @@ -88,7 +79,6 @@ if($arguments['action']){ flush(); break; case 'scanFile': - unset($_SESSION['collection']); echo (OC_MEDIA_SCANNER::scanFile($arguments['path']))?'true':'false'; break; case 'get_artists': diff --git a/apps/media/css/music.css b/apps/media/css/music.css index f8e41064fd8..59d10f74db5 100644 --- a/apps/media/css/music.css +++ b/apps/media/css/music.css @@ -1,6 +1,21 @@ -#folderlist li { margin-bottom:1em; } -#folderlist button.prettybutton { font-size:1em; width:10em; } -li button.right.prettybutton { font-size:1em; } +#controls ul.jp-controls { padding:0; } +#controls ul.jp-controls li { display:inline; } +#controls ul.jp-controls li a { position:absolute; padding:.8em 1em; } +a.jp-play, a.jp-pause { left:2.5em; } +a.jp-pause { display:none; } +a.jp-next { left:5em; } + +div.jp-progress { position:absolute; overflow:hidden; top:.5em; left:8em; width:15em; height:1.2em; padding:0; } +div.jp-seek-bar { background:#eee; width:0; height:100%; cursor:pointer; } +div.jp-play-bar { background:#ccc; width:0; height:100%; } +div.jp-seeking-bg { background:url("../img/pbar-ani.gif"); } +div.jp-current-time,div.jp-duration { position:absolute; font-size:.64em; font-style:oblique; top:1em; left:13.5em; width:22em; } +div.jp-duration { text-align:right; } + +a.jp-mute,a.jp-unmute { left:24em; } +div.jp-volume-bar { position:absolute; overflow:hidden; background:#eee; width:4em; height:0.4em; cursor:pointer; top:1.3em; left:27em; } +div.jp-volume-bar-value { background:#ccc; width:0; height:0.4em; } + #collection { padding-top:1em; position:relative; width:70em; float:left; } #collection li.album,#collection li.song { margin-left:3em; } #leftcontent img.remove { display:none; float:right; cursor:pointer; } @@ -12,5 +27,14 @@ li button.right.prettybutton { font-size:1em; } #collection li { padding-right:10px; } #searchresults input.play, #searchresults input.add { float:left; height:1em; width:1em; } #collection tr.collapsed td.album, #collection tr.collapsed td.title { color:#ddd; } -a.expander { float:right; display:block; } +a.expander { } tr.active { background-color:#eee; } +tr.artist, tr.artist td { + border-top: 1px solid lightgrey; +} +tr.album td.artist { + padding-left: 20px; +} +tr.song td.artist { + padding-left: 40px; +} diff --git a/apps/media/css/player.css b/apps/media/css/player.css index 98a76e82f0d..8b137891791 100644 --- a/apps/media/css/player.css +++ b/apps/media/css/player.css @@ -1,16 +1 @@ -#controls ul.jp-controls { padding:0; } -#controls ul.jp-controls li { display:inline; } -#controls ul.jp-controls li a { position:absolute; padding:.8em 1em; } -a.jp-play, a.jp-pause { left:2.5em; } -a.jp-next { left:5em; } -div.jp-progress { position:absolute; overflow:hidden; top:.5em; left:8em; width:15em; height:1.2em; padding:0; } -div.jp-seek-bar { background:#eee; width:0; height:100%; cursor:pointer; } -div.jp-play-bar { background:#ccc; width:0; height:100%; } -div.jp-seeking-bg { background:url("../img/pbar-ani.gif"); } -div.jp-current-time,div.jp-duration { position:absolute; font-size:.64em; font-style:oblique; top:1em; left:13.5em; width:22em; } -div.jp-duration { text-align:right; } - -a.jp-mute,a.jp-unmute { left:24em; } -div.jp-volume-bar { position:absolute; overflow:hidden; background:#eee; width:4em; height:0.4em; cursor:pointer; top:1.3em; left:27em; } -div.jp-volume-bar-value { background:#ccc; width:0; height:0.4em; } diff --git a/apps/media/js/collection.js b/apps/media/js/collection.js index 98d21b236e0..405fbbcf4a5 100644 --- a/apps/media/js/collection.js +++ b/apps/media/js/collection.js @@ -1,5 +1,9 @@ Collection={ artists:[], + albums:[], + songs:[], + artistsById:{}, + albumsById:{}, loaded:false, loading:false, loadedListeners:[], @@ -12,18 +16,37 @@ Collection={ $.ajax({ url: OC.linkTo('media','ajax/api.php')+'?action=get_collection', dataType: 'json', - success: function(collection){ - Collection.artists=collection; - - //set the album and artist fieds for the songs - for(var i=0;i<collection.length;i++){ - var artist=collection[i]; - for(var j=0;j<artist.albums.length;j++){ - var album=artist.albums[j] - for(var w=0;w<album.songs.length;w++){ - album.songs[w].album_name=album.album_name; - album.songs[w].artist_name=artist.artist_name; - } + success: function(data){ + //normalize the data + for(var i=0;i<data.artists.length;i++){ + var artist=data.artists[i]; + var artistData={name:artist.artist_name,songs:[],albums:[]}; + Collection.artistsById[artist.artist_id]=artistData; + Collection.artists.push(artistData); + } + for(var i=0;i<data.albums.length;i++){ + var album=data.albums[i]; + var artistName=Collection.artistsById[album.album_artist].name; + var albumData={name:album.album_name,artist:artistName,songs:[]}; + Collection.albumsById[album.album_id]=albumData; + Collection.albums.push(albumData); + Collection.artistsById[album.album_artist].albums.push(albumData); + } + for(var i=0;i<data.songs.length;i++){ + var song=data.songs[i]; + if(Collection.artistsById[song.song_artist] && Collection.albumsById[song.song_album]){ + var songData={ + name:song.song_name, + artist:Collection.artistsById[song.song_artist].name, + album:Collection.albumsById[song.song_album].name, + lastPlayed:song.song_lastplayed, + length:song.song_length, + path:song.song_path, + playCount:song.song_playcount, + }; + Collection.songs.push(songData); + Collection.artistsById[song.song_artist].songs.push(songData); + Collection.albumsById[song.song_album].songs.push(songData); } } @@ -32,7 +55,7 @@ Collection={ for(var i=0;i<Collection.loadedListeners.length;i++){ Collection.loadedListeners[i](); } - if(collection.length==0){ + if(data.songs.length==0){ $('#scan input.start').val(t('media','Scan Collection')); $('#scan input.start').click(); } @@ -53,93 +76,104 @@ Collection={ var template=Collection.parent.find('tr.template'); var lastArtist=''; var lastAlbum=''; - $.each(Collection.artists,function(index,artist){ - $.each(artist.albums,function(index,album){ - $.each(album.songs,function(index,song){ - var tr=template.clone().removeClass('template'); - tr.find('td.title a').text(song.song_name); - tr.find('td.title a').click(function(event){ - event.preventDefault(); - PlayList.add(song,true); - PlayList.play(0); - Collection.parent.find('tr').removeClass('active'); - tr.addClass('active'); - }); - if(artist.artist_name!=lastArtist){ - tr.find('td.artist a').click(function(event){ - event.preventDefault(); - PlayList.add(artist,true); - PlayList.play(0); - Collection.parent.find('tr').removeClass('active'); - $('tr[data-artist="'+artist.artist_name+'"]').addClass('active'); - }); - tr.find('td.artist a').text(artist.artist_name); - if(artist.albums.length>1){ - var expander=$('<a class="expander">></a>'); - expander.data('expanded',true); - expander.click(function(event){ - var tr=$(this).parent().parent(); - if(expander.data('expanded')){ - Collection.hideArtist(tr.data('artist')); - }else{ - Collection.showArtist(tr.data('artist')); - } - }); - tr.children('td.artist').append(expander); - } - } - if(album.album_name!=lastAlbum){ - tr.find('td.album a').click(function(event){ - event.preventDefault(); - PlayList.add(album,true); - PlayList.play(0); - Collection.parent.find('tr').removeClass('active'); - $('tr[data-album="'+album.album_name+'"]').addClass('active'); - }); - tr.find('td.album a').text(album.album_name); - if(album.songs.length>1){ - var expander=$('<a class="expander">></a>'); - expander.data('expanded',true); - expander.click(function(event){ - var tr=$(this).parent().parent(); - if(expander.data('expanded')){ - Collection.hideAlbum(tr.data('album')); - }else{ - Collection.showAlbum(tr.data('album')); - } - }); - tr.children('td.album').append(expander); - } + $.each(Collection.artists,function(i,artist){ + if(artist.name && artist.songs.length>0){ + var tr=template.clone().removeClass('template'); + tr.find('td.title a').text(artist.songs.length+' '+t('media','songs')); + tr.find('td.album a').text(artist.albums.length+' '+t('media','albums')); + tr.find('td.artist a').text(artist.name); + tr.data('artistData',artist); + tr.find('td.artist a').click(function(event){ + event.preventDefault(); + PlayList.add(artist); + PlayList.play(0); + Collection.parent.find('tr').removeClass('active'); + $('tr[data-artist="'+artist.name+'"]').addClass('active'); + }); + var expander=$('<a class="expander">></a>'); + expander.data('expanded',false); + expander.click(function(event){ + var tr=$(this).parent().parent(); + if(expander.data('expanded')){ + Collection.hideArtist(tr.data('artist')); + }else{ + Collection.showArtist(tr.data('artist')); } - tr.attr('data-artist',artist.artist_name); - tr.attr('data-album',album.album_name); - lastArtist=artist.artist_name; - lastAlbum=album.album_name; - - Collection.parent.find('tbody').append(tr); }); - Collection.hideAlbum(artist.artist_name,album.album_name); - }); - Collection.hideArtist(artist.artist_name); + tr.find('td.artist').addClass('buttons'); + Collection.addButtons(tr,artist); + tr.children('td.artist').append(expander); + tr.attr('data-artist',artist.name); + Collection.parent.find('tbody').append(tr); + } }); } } }, showArtist:function(artist){ - Collection.parent.find('tr[data-artist="'+artist+'"]').show(); - Collection.parent.find('tr[data-artist="'+artist+'"]').first().removeClass('collapsed'); - Collection.parent.find('tr[data-artist="'+artist+'"] a.expander').data('expanded',true); - Collection.parent.find('tr[data-artist="'+artist+'"] a.expander').addClass('expanded'); - Collection.parent.find('tr[data-artist="'+artist+'"] a.expander').text('v'); + var tr=Collection.parent.find('tr[data-artist="'+artist+'"]'); + var nextRow=tr.next(); + var artist=tr.data('artistData'); + var first=true; + $.each(artist.albums,function(foo,album){ + $.each(album.songs,function(i,song){ + if(first){ + newRow=tr; + }else{ + var newRow=tr.clone(); + } + if(i==0){ + newRow.find('td.album a').text(album.name); + newRow.find('td.album a').click(function(event){ + event.preventDefault(); + PlayList.add(album); + PlayList.play(0); + Collection.parent.find('tr').removeClass('active'); + $('tr[data-album="'+album.name+'"]').addClass('active'); + }); + }else{ + newRow.find('.expander').remove(); + newRow.find('td.album a').text(''); + } + newRow.find('td.title a').text(song.name); + Collection.addButtons(newRow,song); + newRow.find('td.title a').click(function(event){ + event.preventDefault(); + PlayList.add(song); + PlayList.play(0); + Collection.parent.find('tr').removeClass('active'); + $('tr[data-title="'+song.name+'"]').addClass('active'); + }); + newRow.attr('data-album',album.name); + newRow.attr('data-title',song.name); + newRow.attr('data-artist',artist.name); + if(!first){ + nextRow.before(newRow); + } + first=false; + }); + }); + tr.removeClass('collapsed'); + tr.find('a.expander').data('expanded',true); + tr.find('a.expander').addClass('expanded'); + tr.find('a.expander').text('v'); }, hideArtist:function(artist){ - if(Collection.parent.find('tr[data-artist="'+artist+'"]').length>1){ - Collection.parent.find('tr[data-artist="'+artist+'"]').hide(); - Collection.parent.find('tr[data-artist="'+artist+'"]').first().show(); - Collection.parent.find('tr[data-artist="'+artist+'"]').first().addClass('collapsed'); - Collection.parent.find('tr[data-artist="'+artist+'"] a.expander').data('expanded',false); - Collection.parent.find('tr[data-artist="'+artist+'"] a.expander').removeClass('expanded'); - Collection.parent.find('tr[data-artist="'+artist+'"] a.expander').text('>'); + var tr=Collection.parent.find('tr[data-artist="'+artist+'"]'); + if(tr.length>1){ + var artist=tr.first().data('artistData'); + tr.first().find('td.album a').text(artist.albums.length+' '+t('media','albums')); + tr.first().find('td.title a').text(artist.songs.length+' '+t('media','songs')); + tr.first().find('td.album a').unbind('click'); + tr.first().find('td.title a').unbind('click'); + tr.each(function(i,row){ + if(i>0){ + $(row).remove(); + } + }); + tr.find('a.expander').data('expanded',false); + tr.find('a.expander').removeClass('expanded'); + tr.find('a.expander').text('>'); } }, showAlbum:function(artist,album){ @@ -161,16 +195,26 @@ Collection={ song.song_playcount++; } }, - addButtons:function(parent){ - parent.children('button.add').click(function(){ - var type=$(this).parent().data('type'); - PlayList.add($(this).parent().data(type)); + addButtons:function(parent,data){ + buttons = parent.find('.buttons'); + if(buttons.find('.add').length<=0) { + buttons.append('<img class="add" src="'+OC.imagePath('core','actions/play-add')+'"/>'); + } + if(buttons.find('.play').length<=0) { + buttons.append('<img class="play" src="'+OC.imagePath('core','actions/play')+'"/>'); + } + buttons.find('.add').unbind('click'); + buttons.find('.add').click(function(event){ + event.preventDefault(); + PlayList.add(data,true); + PlayList.render(); }); - parent.children('button.play').click(function(){ - var type=$(this).parent().data('type'); - var oldSize=PlayList.items.length; - PlayList.add($(this).parent().data(type)); - PlayList.play(oldSize); + buttons.find('.play').unbind('click'); + buttons.find('.play').click(function(event){ + event.preventDefault(); + PlayList.add(data); + PlayList.play(0,0); + PlayList.render(); }); }, find:function(artistName,albumName,songName){ diff --git a/apps/media/js/player.js b/apps/media/js/player.js index 0b0502c7780..f696b87bbde 100644 --- a/apps/media/js/player.js +++ b/apps/media/js/player.js @@ -5,10 +5,8 @@ var PlayList={ player:null, volume:0.8, active:false, - tempPlaylist:[], - isTemp:true, next:function(){ - var items=(PlayList.isTemp)?PlayList.tempPlaylist:PlayList.items; + var items=PlayList.items; var next=PlayList.current+1; if(next>=items.length){ next=0; @@ -17,7 +15,7 @@ var PlayList={ PlayList.render(); }, previous:function(){ - var items=(PlayList.isTemp)?PlayList.tempPlaylist:PlayList.items; + var items=PlayList.items; var next=PlayList.current-1; if(next<0){ next=items.length-1; @@ -26,7 +24,7 @@ var PlayList={ PlayList.render(); }, play:function(index,time,ready){ - var items=(PlayList.isTemp)?PlayList.tempPlaylist:PlayList.items; + var items=PlayList.items; if(index==null){ index=PlayList.current; } @@ -34,8 +32,11 @@ var PlayList={ PlayList.current=index; if(PlayList.player){ if(PlayList.player.data('jPlayer').options.supplied!=items[index].type){//the the audio type changes we need to reinitialize jplayer + PlayList.player.jPlayer("play",time); + localStorage.setItem(oc_current_user+'oc_playlist_time',time); PlayList.player.jPlayer("destroy"); - PlayList.init(items[index].type,function(){PlayList.play(null,time,ready)}); + PlayList.save(); // so that the init don't lose the playlist + PlayList.init(items[index].type,null); // init calls load that calls play }else{ PlayList.player.jPlayer("setMedia", items[PlayList.current]); items[index].playcount++; @@ -60,7 +61,10 @@ var PlayList={ } } }else{ - PlayList.init(items[index].type,PlayList.play); + localStorage.setItem(oc_current_user+'oc_playlist_time',time); + localStorage.setItem(oc_current_user+'oc_playlist_playing','true'); + PlayList.save(); // so that the init don't lose the playlist + PlayList.init(items[index].type,null); // init calls load that calls play } } }, @@ -100,37 +104,30 @@ var PlayList={ swfPath:OC.linkTo('media','js'), }); }, - add:function(song,temp,dontReset){ + add:function(song,dontReset){ if(!dontReset){ - PlayList.tempPlaylist=[];//clear the temp playlist + PlayList.items=[];//clear the playlist } - PlayList.isTemp=temp; - PlayList.isTemp=true; if(!song){ return; } if(song.substr){//we are passed a string, asume it's a url to a song - PlayList.addFile(song,temp,true); + PlayList.addFile(song,true); } if(song.albums){//a artist object was passed, add all albums inside it $.each(song.albums,function(index,album){ - PlayList.add(album,temp,true); + PlayList.add(album,true); }); - } - if(song.songs){//a album object was passed, add all songs inside it + } else if(song.songs){//a album object was passed, add all songs inside it $.each(song.songs,function(index,song){ - PlayList.add(song,temp,true); + PlayList.add(song,true); }); } - if(song.song_name){ - var type=musicTypeFromFile(song.song_path); - var item={name:song.song_name,type:type,artist:song.artist_name,album:song.album_name,length:song.song_length,playcount:song.song_playcount}; - item[type]=PlayList.urlBase+encodeURIComponent(song.song_path); - if(PlayList.isTemp){ - PlayList.tempPlaylist.push(item); - }else{ - PlayList.items.push(item); - } + if(song.path){ + var type=musicTypeFromFile(song.path); + var item={name:song.name,type:type,artist:song.artist,album:song.album,length:song.length,playcount:song.playCount}; + item[type]=PlayList.urlBase+encodeURIComponent(song.path); + PlayList.items.push(item); } }, addFile:function(path){ @@ -160,10 +157,14 @@ var PlayList={ if(typeof localStorage !== 'undefined' && localStorage){ localStorage.setItem(oc_current_user+'oc_playlist_items',JSON.stringify(PlayList.items)); localStorage.setItem(oc_current_user+'oc_playlist_current',PlayList.current); - var time=Math.round(PlayList.player.data('jPlayer').status.currentTime); - localStorage.setItem(oc_current_user+'oc_playlist_time',time); - var volume=PlayList.player.data('jPlayer').options.volume*100; - localStorage.setItem(oc_current_user+'oc_playlist_volume',volume); + if(PlayList.player) { + if(PlayList.player.data('jPlayer')) { + var time=Math.round(PlayList.player.data('jPlayer').status.currentTime); + localStorage.setItem(oc_current_user+'oc_playlist_time',time); + var volume=PlayList.player.data('jPlayer').options.volume*100; + localStorage.setItem(oc_current_user+'oc_playlist_volume',volume); + } + } if(PlayList.active){ localStorage.setItem(oc_current_user+'oc_playlist_active','false'); } diff --git a/apps/media/l10n/ca.php b/apps/media/l10n/ca.php index 810eecd8a49..f0e24d8514d 100644 --- a/apps/media/l10n/ca.php +++ b/apps/media/l10n/ca.php @@ -1,8 +1,13 @@ <?php $TRANSLATIONS = array( "Music" => "Música", +"Play" => "Reprodueix", +"Pause" => "Pausa", +"Previous" => "Anterior", +"Next" => "Següent", +"Mute" => "Mut", +"Unmute" => "Activa el so", "Songs scanned" => "Cançons escanejades", "Rescan Collection" => "Escaneja de nou la col·lecció", -"Pause" => "Pausa", "Artist" => "Artista", "Album" => "Àlbum", "Title" => "Títol" diff --git a/apps/media/l10n/da.php b/apps/media/l10n/da.php index 671f0cf44ca..64cdc59ded5 100644 --- a/apps/media/l10n/da.php +++ b/apps/media/l10n/da.php @@ -1,8 +1,8 @@ <?php $TRANSLATIONS = array( "Music" => "Musik", +"Pause" => "Pause", "Songs scanned" => "Sange skannet", "Rescan Collection" => "Genskan Samling", -"Pause" => "Pause", "Artist" => "Kunstner", "Album" => "Album", "Title" => "Titel" diff --git a/apps/media/l10n/de.php b/apps/media/l10n/de.php index 9f664b78d80..7a87f6dcb35 100644 --- a/apps/media/l10n/de.php +++ b/apps/media/l10n/de.php @@ -1,8 +1,8 @@ <?php $TRANSLATIONS = array( "Music" => "Musik", +"Pause" => "Pause", "Songs scanned" => "Lieder gescannt", "Rescan Collection" => "Sammlung scannen", -"Pause" => "Pause", "Artist" => "Künstler", "Album" => "Album", "Title" => "Titel" diff --git a/apps/media/l10n/el.php b/apps/media/l10n/el.php index 0543dae8b3c..6d4b781b78f 100644 --- a/apps/media/l10n/el.php +++ b/apps/media/l10n/el.php @@ -1,8 +1,13 @@ <?php $TRANSLATIONS = array( "Music" => "Μουσική", +"Play" => "Αναπαραγωγή", +"Pause" => "Παύση", +"Previous" => "Προηγούμενο", +"Next" => "Επόμενο", +"Mute" => "Σίγαση", +"Unmute" => "Επαναφορά ήχου", "Songs scanned" => "Σαρωμένα τραγούγια", "Rescan Collection" => "Επανασάρωση συλλογής", -"Pause" => "Παύση", "Artist" => "Καλλιτέχνης", "Album" => "Άλμπουμ", "Title" => "Τίτλος" diff --git a/apps/media/l10n/es.php b/apps/media/l10n/es.php index 2b4044706f0..b97fb0bf157 100644 --- a/apps/media/l10n/es.php +++ b/apps/media/l10n/es.php @@ -1,8 +1,13 @@ <?php $TRANSLATIONS = array( "Music" => "Música", +"Play" => "Reproducir", +"Pause" => "Pausa", +"Previous" => "Anterior", +"Next" => "Siguiente", +"Mute" => "Silenciar", +"Unmute" => "Sonar", "Songs scanned" => "Canciones encontradas", "Rescan Collection" => "Buscar música nueva", -"Pause" => "Pausa", "Artist" => "Artista", "Album" => "Álbum", "Title" => "Título" diff --git a/apps/media/l10n/fr.php b/apps/media/l10n/fr.php index 619ee9bc835..3e4e0f19283 100644 --- a/apps/media/l10n/fr.php +++ b/apps/media/l10n/fr.php @@ -1,8 +1,8 @@ <?php $TRANSLATIONS = array( "Music" => "Musique", +"Pause" => "Pause", "Songs scanned" => "Pistes scannées", "Rescan Collection" => "Réanalyser la Collection", -"Pause" => "Pause", "Artist" => "Artiste", "Album" => "Album", "Title" => "Titre" diff --git a/apps/media/l10n/id.php b/apps/media/l10n/id.php new file mode 100644 index 00000000000..7127f85fbf0 --- /dev/null +++ b/apps/media/l10n/id.php @@ -0,0 +1,9 @@ +<?php $TRANSLATIONS = array( +"Music" => "Musik", +"Pause" => "Jeda", +"Songs scanned" => "Lagu-lagu yang telah dipindai", +"Rescan Collection" => "Pindai ulang Koleksi", +"Artist" => "Artis", +"Album" => "Album", +"Title" => "Judul" +); diff --git a/apps/media/l10n/it.php b/apps/media/l10n/it.php index 9e9b3d151ef..f0d9c606e74 100644 --- a/apps/media/l10n/it.php +++ b/apps/media/l10n/it.php @@ -1,6 +1,13 @@ <?php $TRANSLATIONS = array( "Music" => "Musica", +"Play" => "Play", "Pause" => "Pausa", +"Previous" => "Precedente", +"Next" => "Successiva", +"Mute" => "Disattiva audio", +"Unmute" => "Riattiva audio", +"Songs scanned" => "Canzoni analizzate", +"Rescan Collection" => "Rianalizza colezione", "Artist" => "Artista", "Album" => "Album", "Title" => "Titolo" diff --git a/apps/media/l10n/nl.php b/apps/media/l10n/nl.php index 5d4e41ba0da..7ae0a761af0 100644 --- a/apps/media/l10n/nl.php +++ b/apps/media/l10n/nl.php @@ -1,8 +1,8 @@ <?php $TRANSLATIONS = array( "Music" => "Muziek", +"Pause" => "Pauze", "Songs scanned" => "nummers gescanned", "Rescan Collection" => "Collectie opnieuw scannen", -"Pause" => "Pauze", "Artist" => "Artiest", "Album" => "Album", "Title" => "Titel" diff --git a/apps/media/l10n/pl.php b/apps/media/l10n/pl.php new file mode 100644 index 00000000000..bb74d6d578a --- /dev/null +++ b/apps/media/l10n/pl.php @@ -0,0 +1,9 @@ +<?php $TRANSLATIONS = array( +"Music" => "Muzyka", +"Pause" => "Zatrzymaj", +"Songs scanned" => "Przeskanowane utwory", +"Rescan Collection" => "Przeskanuj kolekcję", +"Artist" => "Artysta", +"Album" => "Album", +"Title" => "Tytuł" +); diff --git a/apps/media/l10n/pt_BR.php b/apps/media/l10n/pt_BR.php index 750b86359a9..ac5b1c22d7d 100644 --- a/apps/media/l10n/pt_BR.php +++ b/apps/media/l10n/pt_BR.php @@ -1,8 +1,13 @@ <?php $TRANSLATIONS = array( "Music" => "Música", +"Play" => "Tocar", +"Pause" => "Pausa", +"Previous" => "Anterior", +"Next" => "Próximo", +"Mute" => "Mudo", +"Unmute" => "Não Mudo", "Songs scanned" => "Músicas encontradas", "Rescan Collection" => "Atualizar a Coleção", -"Pause" => "Pausa", "Artist" => "Artista", "Album" => "Álbum", "Title" => "Título" diff --git a/apps/media/l10n/sv.php b/apps/media/l10n/sv.php index 8e2e7039c50..b3a7f18f7b2 100644 --- a/apps/media/l10n/sv.php +++ b/apps/media/l10n/sv.php @@ -1,8 +1,8 @@ <?php $TRANSLATIONS = array( "Music" => "Musik", +"Pause" => "Paus", "Songs scanned" => "Skannade låtar", "Rescan Collection" => "Sök igenom samlingen", -"Pause" => "Paus", "Artist" => "Artist", "Album" => "Album", "Title" => "Titel" diff --git a/apps/media/lib_media.php b/apps/media/lib_media.php index 062672b91e8..3086f84a93a 100644 --- a/apps/media/lib_media.php +++ b/apps/media/lib_media.php @@ -24,10 +24,8 @@ //we need to have the sha256 hash of passwords for ampache OC_Hook::connect('OC_User','post_login','OC_MEDIA','loginListener'); -//connect to the filesystem for auto updating if configured -if(OC_Preferences::getValue(OC_User::getUser(),'media','autoupdate',false)){ - OC_Hook::connect('OC_Filesystem','post_write','OC_MEDIA','updateFile'); -} +//connect to the filesystem for auto updating +OC_Hook::connect('OC_Filesystem','post_write','OC_MEDIA','updateFile'); //listen for file deletions to clean the database if a song is deleted OC_Hook::connect('OC_Filesystem','delete','OC_MEDIA','deleteFile'); @@ -56,20 +54,14 @@ class OC_MEDIA{ */ public static function updateFile($params){ $path=$params['path']; - $folderNames=explode(PATH_SEPARATOR,OC_Preferences::getValue(OC_User::getUser(),'media','paths','')); - foreach($folderNames as $folder){ - if(substr($path,0,strlen($folder))==$folder){ - require_once 'lib_scanner.php'; - require_once 'lib_collection.php'; - //fix a bug where there were multiply '/' in front of the path, it should only be one - while($path[0]=='/'){ - $path=substr($path,1); - } - $path='/'.$path; - error_log($path); - OC_MEDIA_SCANNER::scanFile($path); - } + require_once 'lib_scanner.php'; + require_once 'lib_collection.php'; + //fix a bug where there were multiply '/' in front of the path, it should only be one + while($path[0]=='/'){ + $path=substr($path,1); } + $path='/'.$path; + OC_MEDIA_SCANNER::scanFile($path); } /** diff --git a/apps/media/templates/music.php b/apps/media/templates/music.php index 3cbb1c50a95..9b40faa9619 100644 --- a/apps/media/templates/music.php +++ b/apps/media/templates/music.php @@ -1,11 +1,11 @@ <div id="controls"> <ul class="jp-controls"> - <li><a href="#" class="jp-play action"><img class="svg" src="<?php echo image_path('core', 'actions/play-big.svg'); ?>" /></a></li> - <li><a href="#" class="jp-pause action"><img class="svg" src="<?php echo image_path('core', 'actions/pause-big.svg'); ?>" /></a></li> - <li><a href="#" class="jp-previous action"><img class="svg" src="<?php echo image_path('core', 'actions/play-previous.svg'); ?>" /></a></li> - <li><a href="#" class="jp-next action"><img class="svg" src="<?php echo image_path('core', 'actions/play-next.svg'); ?>" /></a></li> - <li><a href="#" class="jp-mute action"><img class="svg" src="<?php echo image_path('core', 'actions/sound.svg'); ?>" /></a></li> - <li><a href="#" class="jp-unmute action"><img class="svg" src="<?php echo image_path('core', 'actions/sound-off.svg'); ?>" /></a></li> + <li><a href="#" class="jp-play action"><img class="svg" alt="<?php echo $l->t('Play');?>" src="<?php echo image_path('core', 'actions/play-big.svg'); ?>" /></a></li> + <li><a href="#" class="jp-pause action"><img class="svg" alt="<?php echo $l->t('Pause');?>" src="<?php echo image_path('core', 'actions/pause-big.svg'); ?>" /></a></li> + <li><a href="#" class="jp-previous action"><img class="svg" alt="<?php echo $l->t('Previous');?>" src="<?php echo image_path('core', 'actions/play-previous.svg'); ?>" /></a></li> + <li><a href="#" class="jp-next action"><img class="svg" alt="<?php echo $l->t('Next');?>" src="<?php echo image_path('core', 'actions/play-next.svg'); ?>" /></a></li> + <li><a href="#" class="jp-mute action"><img class="svg" alt="<?php echo $l->t('Mute');?>" src="<?php echo image_path('core', 'actions/sound.svg'); ?>" /></a></li> + <li><a href="#" class="jp-unmute action"><img class="svg" alt="<?php echo $l->t('Unmute');?>" src="<?php echo image_path('core', 'actions/sound-off.svg'); ?>" /></a></li> </ul> <div class="jp-progress"> <div class="jp-seek-bar"> @@ -25,23 +25,25 @@ <div id="rightcontent"> <div id="scan"> - <p id="scancount" style="display:none"><span class="songCount">0</span> <?php echo $l->t('Songs scanned')?> - <input type="button" class="start" value="<?php echo $l->t('Rescan Collection')?>"></input> - <input type="button" class="stop" style="display:none" value="<?php echo $l->t('Pause')?>"></input></p> + <p id="scancount" style="display:none"><span class="songCount">0</span> <?php echo $l->t('Songs scanned')?></p> + <input type="button" class="start" value="<?php echo $l->t('Rescan Collection')?>" /> + <input type="button" class="stop" style="display:none" value="<?php echo $l->t('Pause')?>" /> <div id="scanprogressbar"></div> </div> <table id="collection"> <thead> - <th><?php echo $l->t('Artist')?></th> - <th><?php echo $l->t('Album')?></th> - <th><?php echo $l->t('Title')?></th> + <tr> + <th><?php echo $l->t('Artist')?></th> + <th><?php echo $l->t('Album')?></th> + <th><?php echo $l->t('Title')?></th> + </tr> </thead> <tbody> <tr class="template"> - <td class="artist"><a/></td> - <td class="album"><a/></td> - <td class="title"><a/></td> + <td class="artist"><a></a></td> + <td class="album"><a></a></td> + <td class="title"><a></a></td> </tr> </tbody> </table> diff --git a/apps/test_db/appinfo/app.php b/apps/test_db/appinfo/app.php new file mode 100644 index 00000000000..b1ec4c4639c --- /dev/null +++ b/apps/test_db/appinfo/app.php @@ -0,0 +1,17 @@ +<?php + +OC_App::register( array( + 'order' => 11, + 'id' => 'test_db', + 'name' => 'Test' )); + +OC_App::addNavigationEntry( array( + 'id' => 'test_db_index', + 'order' => 11, + 'href' => OC_Helper::linkTo( 'test_db', 'index.php' ), +/* + 'icon' => OC_Helper::imagePath( 'openstreetgame', 'icon.svg' ), +*/ + 'name' => 'Test DB' )); + +?> diff --git a/apps/test_db/appinfo/info.xml b/apps/test_db/appinfo/info.xml new file mode 100644 index 00000000000..06c716453cc --- /dev/null +++ b/apps/test_db/appinfo/info.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="ISO-8859-1" ?> +<info> + <id>test_db</id> + <name>Test DB</name> + <description>A test of the db</description> + <version>0.1</version> + <licence>AGPL</licence> + <author>Côme BERNIGAUD</author> + <require>2</require> +</info> diff --git a/apps/test_db/appinfo/install.php b/apps/test_db/appinfo/install.php new file mode 100644 index 00000000000..034bf359140 --- /dev/null +++ b/apps/test_db/appinfo/install.php @@ -0,0 +1,7 @@ +<?php +//do some dummy stuff to test the newly created tables +/* +$query=OC_DB::prepare("INSERT INTO *PREFIX*test_dummy(foo_name,foo_value) VALUES(?,?)"); +$query->execute(array('bar',42)); +*/ +?> diff --git a/apps/test_db/index.php b/apps/test_db/index.php new file mode 100644 index 00000000000..2569aedb9b3 --- /dev/null +++ b/apps/test_db/index.php @@ -0,0 +1,26 @@ +<?php + +require_once('../../lib/base.php'); + +// Check if we are a user +if( !OC_User::isLoggedIn()){ + header( "Location: ".OC_Helper::linkTo( '', 'index.php' )); + exit(); +} + +class Test { + private $test1; + private $test2; + public function init() { + $this->test1 = "test1"; + $this->test2 = 2; + } + public function show() { + echo "test1:".$this->test1."<br/>test2:".$this->test2."<br/>"; + } +}; + +$tmpl = new OC_Template( 'test_db', 'index', 'user' ); + +$tmpl->printPage(); +?> diff --git a/apps/test_db/templates/index.php b/apps/test_db/templates/index.php new file mode 100644 index 00000000000..3209e4d4b7b --- /dev/null +++ b/apps/test_db/templates/index.php @@ -0,0 +1,17 @@ +<?php + +$t1 = new Test(); +$t1->init(); +$t1->show(); +$testid = OC_DB4App::store('test_db','main',OC_User::getUser(),$t1); +echo "id in db is $testid<br/>\n"; + +$t2 = OC_DB4App::get_object('test_db','main',$testid); +$t2->show(); + +print_r(OC_DB4App::get_objects('test_db','main',OC_User::getUser())); + +OC_DB4App::delete_object('test_db','main',$testid); + +OC_DB4App::drop('test_db','main'); +?> diff --git a/apps/user_ldap/appinfo/app.php b/apps/user_ldap/appinfo/app.php index a6fca415012..7906241f79b 100644 --- a/apps/user_ldap/appinfo/app.php +++ b/apps/user_ldap/appinfo/app.php @@ -23,6 +23,8 @@ require_once('apps/user_ldap/user_ldap.php'); +OC_APP::registerAdmin('user_ldap','settings'); + // define LDAP_DEFAULT_PORT define("OC_USER_BACKEND_LDAP_DEFAULT_PORT", 389); diff --git a/apps/user_ldap/settings.php b/apps/user_ldap/settings.php index 696b95c37e0..8dbd3c0462b 100644 --- a/apps/user_ldap/settings.php +++ b/apps/user_ldap/settings.php @@ -20,14 +20,6 @@ * License along with this library. If not, see <http://www.gnu.org/licenses/>. * */ - -require_once('../../lib/base.php'); - -if( !OC_User::isLoggedIn() || !OC_Group::inGroup( OC_User::getUser(), 'admin' )){ - header( "Location: ".OC_Helper::linkTo( '', "index.php" )); - exit(); -} - $params = array('ldap_host', 'ldap_port', 'ldap_dn', 'ldap_password', 'ldap_base', 'ldap_filter'); foreach($params as $param){ @@ -35,11 +27,9 @@ foreach($params as $param){ OC_Appconfig::setValue('user_ldap', $param, $_POST[$param]); } } -OC_App::setActiveNavigationEntry( "user_ldap_settings" ); - // fill template -$tmpl = new OC_Template( 'user_ldap', 'settings', 'admin' ); +$tmpl = new OC_Template( 'user_ldap', 'settings'); foreach($params as $param){ $value = OC_Appconfig::getValue('user_ldap', $param,''); $tmpl->assign($param, $value); @@ -48,4 +38,4 @@ foreach($params as $param){ // ldap_port has a default value $tmpl->assign( 'ldap_port', OC_Appconfig::getValue('user_ldap', 'ldap_port', OC_USER_BACKEND_LDAP_DEFAULT_PORT)); -$tmpl->printPage(); +return $tmpl->fetchPage(); diff --git a/apps/user_ldap/templates/settings.php b/apps/user_ldap/templates/settings.php index 5dddb71a022..32e1b29dafb 100644 --- a/apps/user_ldap/templates/settings.php +++ b/apps/user_ldap/templates/settings.php @@ -1,27 +1,12 @@ -<form id="ldap" action='#' method='post'> - <fieldset> - <legend>LDAP</legend> - <div> - <div> - <span>Host: *</span><span><input type="text" name="ldap_host" width="200" value="<?php echo $_['ldap_host']; ?>"></span> - </div> - <div> - <span>Port: *</span><span><input type="text" name="ldap_port" width="200" value="<?php echo $_['ldap_port']; ?>"></span> - </div> - <div> - <span>DN:<input type="text" name="ldap_dn" width="200" value="<?php echo $_['ldap_dn']; ?>"></span> - </div> - <div> - <span>Password:<input type="password" name="ldap_password" width="200" value="<?php echo $_['ldap_password']; ?>"></span> - </div> - <div> - <span>Base: *<input type="text" name="ldap_base" width="200" value="<?php echo $_['ldap_base']; ?>"></span> - </div> - <div> - <span>Filter * (use %uid placeholder):<input type="text" name="ldap_filter" width="200" value="<?php echo $_['ldap_filter']; ?>"></span> - </div> - </div> - <input type='submit' value='Save'/> - <br/> * required +<form id="ldap" action="#" method="post"> + <fieldset class="personalblock"> + <legend><strong>LDAP</strong></legend> + <p><label for="ldap_host">Host<input type="text" id="ldap_host" name="ldap_host" value="<?php echo $_['ldap_host']; ?>"></label> + <label for="ldap_port">Port</label><input type="text" id="ldap_port" name="ldap_port" value="<?php echo $_['ldap_port']; ?>" /></p> + <p><label for="ldap_dn">Name</label><input type="text" id="ldap_dn" name="ldap_dn" value="<?php echo $_['ldap_dn']; ?>" /> + <label for="ldap_password">Password</label><input type="password" id="ldap_password" name="ldap_password" value="<?php echo $_['ldap_password']; ?>" /></p> + <p><label for="ldap_base">Base</label><input type="text" id="ldap_base" name="ldap_base" value="<?php echo $_['ldap_base']; ?>" /> + <label for="ldap_filter">Filter (use %uid placeholder)</label><input type="text" id="ldap_filter" name="ldap_filter" value="<?php echo $_['ldap_filter']; ?>" /></p> + <input type="submit" value="Save" /> </fieldset> -</form>
\ No newline at end of file +</form> diff --git a/apps/user_ldap/user_ldap.php b/apps/user_ldap/user_ldap.php index 54fc51fe0cd..2d94ef828ab 100644 --- a/apps/user_ldap/user_ldap.php +++ b/apps/user_ldap/user_ldap.php @@ -63,6 +63,9 @@ class OC_USER_LDAP extends OC_User_Backend { private function getDs() { if(!$this->ds) { $this->ds = ldap_connect( $this->ldap_host, $this->ldap_port ); + if(ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3)) + if(ldap_set_option($this->ds, LDAP_OPT_REFERRALS, 0)) + ldap_start_tls($this->ds); } // login |