diff options
author | Robin Appelman <icewind@owncloud.com> | 2012-12-25 17:29:56 +0400 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2012-12-25 17:29:56 +0400 |
commit | 9da9778aff6c3ce32f5e3ab8ca6fb31894f2daa0 (patch) | |
tree | c32f4a40040ed7b29add3bca472aa9961b140a6d /reader | |
parent | 067a4044d552c2e9df5931f017b35bf8042dd2f0 (diff) | |
parent | 78ba55468e50fe915f68af10deb1fe9a5048d837 (diff) |
Merge branch 'master' into filesystem
Diffstat (limited to 'reader')
-rw-r--r-- | reader/ajax/remove_tags.php | 16 | ||||
-rwxr-xr-x | reader/ajax/tags.php | 7 | ||||
-rwxr-xr-x | reader/appinfo/database.xml | 2 | ||||
-rwxr-xr-x | reader/css/reader.css | 11 | ||||
-rwxr-xr-x | reader/js/.goutputstream-GYESPW | 161 | ||||
-rwxr-xr-x | reader/js/integrate.js | 44 | ||||
-rwxr-xr-x | reader/lib/library_display.php | 36 | ||||
-rwxr-xr-x | reader/lib/tag_utils.php | 11 | ||||
-rwxr-xr-x | reader/templates/tagged.php | 3 |
9 files changed, 250 insertions, 41 deletions
diff --git a/reader/ajax/remove_tags.php b/reader/ajax/remove_tags.php new file mode 100644 index 000000000..82ad3671e --- /dev/null +++ b/reader/ajax/remove_tags.php @@ -0,0 +1,16 @@ +<?php + include ('apps/reader/lib/tag_utils.php'); + $filepath = $_POST['filepath']; + $tag_toBeRemv = $_POST['tag']; + $tags = find_tags_for_ebook($filepath); + + $arr = explode(',',$tags); + $arr2 = array(); + foreach($arr as $a) { + if (strcmp($a,$tag_toBeRemv) != 0) + $arr2[] = $a; + } + $new_tags = implode(",",$arr2); + update_tag_for_ebook($new_tags,$filepath); + +?> diff --git a/reader/ajax/tags.php b/reader/ajax/tags.php index 489e89b11..8892ba0b3 100755 --- a/reader/ajax/tags.php +++ b/reader/ajax/tags.php @@ -1,14 +1,15 @@ <?php include('apps/reader/lib/tag_utils.php'); - $path_of_ebook = $_POST['path']; $new_tag = $_POST['tag']; - $path_of_ebook = urldecode($path_of_ebook); + $path_of_ebook = $_POST['path']; $tags = find_tags_for_ebook($path_of_ebook); if ($tags != NULL) { - $new_tag = $tags.",".$new_tag; + echo $new_tag; + $new_tag = $tags.','.$new_tag; update_tag_for_ebook($new_tag,$path_of_ebook); } else { insert_new_tag($new_tag,$path_of_ebook); + echo $new_tag; } ?> diff --git a/reader/appinfo/database.xml b/reader/appinfo/database.xml index 01ca55675..43bd79f22 100755 --- a/reader/appinfo/database.xml +++ b/reader/appinfo/database.xml @@ -26,7 +26,7 @@ <type>text</type> <default></default> <notnull>false</notnull> - <length>20</length> + <length>100</length> </field> </declaration> diff --git a/reader/css/reader.css b/reader/css/reader.css index 9cdc6a98f..ec0bfecac 100755 --- a/reader/css/reader.css +++ b/reader/css/reader.css @@ -15,8 +15,8 @@ td.filename.svg { background:no-repeat; height:150px; white-space:normal; color: td.filename a.name { position:relative;} a.name span.nametext { position:relative; top: 4px; left:-25px; } -span.nametext { padding-left:1px; font-family:Arial; font-size:16px; font-weight:normal; white-space:nowrap; text-transform:capitalize; } -a.dirs span.nametext { margin-left:10px;} +span.nametext { padding-left:1px; font-family:Arial; font-size:16px; font-weight:normal; white-space:nowrap;} +a.dirs span.nametext {margin-left:10px;} div#thumbs { position:relative;} div#thumbs img { border:1px solid #EEE; -webkit-box-shadow: 4px 4px 4px 0px grey; box-shadow: 4px 4px 4px 0px grey; /*position:absolute; left:25px; top: 20px;*/} @@ -24,3 +24,10 @@ div#thumbs img { border:1px solid #EEE; -webkit-box-shadow: 4px 4px 4px 0px grey #displaybox { margin-top:8px; margin-left:12px; font-size:14px; color:grey; width:200px; height:30px; } #displaybox a { color:grey; } input.start { margin-left:12px;} + +div#result { position:absolute; left:2px; top:35px;} +.each_result { background-color: #EEE; display:inline-block; margin:5px; height:25px; border-radius:5px; } +.each_result:hover { background-color: #DDD;} +#each_tag,#close { padding: 5px; font-size:14px;} +#each_tag { color:grey;} +form#TagForm { position:absolute; top:100px; left:10px;} diff --git a/reader/js/.goutputstream-GYESPW b/reader/js/.goutputstream-GYESPW new file mode 100755 index 000000000..11b2e0248 --- /dev/null +++ b/reader/js/.goutputstream-GYESPW @@ -0,0 +1,161 @@ +$(document).ready(function() { + $('#fileList tr').each(function(){ + // data-file attribute to contain unescaped filenames. + $(this).attr('data-file',decodeURIComponent($(this).attr('data-file'))); + }); + + $('#file_action_panel').attr('activeAction', false); + + $("#TagForm").submit(function(event) { + event.preventDefault(); + var $form = $( this ), + tag = $form.find( 'input[name="tag"]' ).val(), + url = 'apps/reader/ajax/tags.php'; + var path = $(this).parent().children('a.name').attr('dir'); + $.post( url, {tag:tag,path:path}, + function( data ) { + $("#result").append('<a href = "apps/reader/fetch_tags.php?tag='+data+'">'+data+'</a>'); + } + ); + }); + + $('#close').click(function(){ + event.preventDefault(); + var parent = $(this).parent(); + var filepath = $(this).parent().parent().parent().children('a.name').attr('dir'); + var url = 'apps/reader/ajax/remove_tags.php'; + var tag = $(this).attr('value'); + $.post(url, {tag:tag, filepath:filepath}, function(data) {alert(data)}); + }); +}); + +$(function() { + // See if url conatins the index 'reader' + if(location.href.indexOf("reader")!=-1) { + 'use strict'; + // create thumbnails for pdfs inside current directory. + create_thumbnails(); + create_thumbnails_for_directories(); + // Render pdf view on every click of a thumbnail, now and in future. + $('td.filename a.name').live('click',function(event) { + event.preventDefault(); + var filename=$(this).parent().parent().attr('data-file'); + var tr=$('tr').filterAttr('data-file',filename); + var mime=$(this).parent().parent().data('mime'); + var type=$(this).parent().parent().data('type'); + // Check if clicked link is a pdf file or a directory, perform suitable function. + var action=getAction(mime,type); + if(action){ + action(filename); + } + }); + } +}); + +/* Function that returns suitable function definition to be executed on + * click of the file whose mime and type are passed. */ +function getAction(mime,type) { + var name; + if(mime == 'application/pdf') { + name = function (filename){ + showPDFviewer($('#dir').val(),filename); + } + } + else { + name = function (filename){ + window.location=OC.linkTo('reader', 'index.php') + '&dir='+ + encodeURIComponent($('#dir').val()).replace(/%2F/g, '/')+'/'+ + encodeURIComponent(filename) + '/'; + } + } + return name; +} + +function create_thumbnails() { + PDFJS.disableWorker = true; + $('td#thumbnail_container > img').each(function() { + // Get url and title of each pdf file from image tags. + var title = $(this).parent().parent().attr('data-file'); + var location = $(this).attr('id'); + var url = OC.linkTo('files', 'download.php')+'?file=' + location; + var thumbnail_exists = $(this).attr('value'); + if (thumbnail_exists == "false") { + if (url.indexOf('pdf') != -1) { + render_thumbnail(url,location,title); + } + } + }); +} + +function create_thumbnails_for_directories() { + $('div#thumbs img').each(function(){ + var thumb_exists = $(this).attr('value'); + if (thumb_exists == "false") { + var location = $(this).attr('id'); + var url = OC.linkTo('files', 'download.php')+'?file=' + location; + var title = location.replace(/\\/g,'/').replace( /.*\//, '' ); + if (url.indexOf('pdf') != -1) { + render_thumbnail(url,location,title); + } + } + }); +} + +function canvasSaver(canvas,title,location) { + var canvas_data = canvas.toDataURL('image/png'); + $.post("apps/reader/ajax/canvas_saver.php", {canv_data:canvas_data,title:title,location:location}); +} + + +function render_thumbnail(url,location,title) { + + PDFJS.getDocument(url).then(function(pdf) { + // Using promise to fetch the page + pdf.getPage(1).then(function(page) { + var scale = 0.2; + var viewport = page.getViewport(scale); + + // Create canvas elements for each pdf's first page. + var canvas = document.createElement("canvas"); + + // Canvas elements should be of proper size, not too big, not too small. + if (viewport.height > 170 || viewport.width > 130) { + scale = 0.1; + } + else if (viewport.height < 129 || viewport.width < 86) { + scale = 0.3; + } + + viewport = page.getViewport(scale); + canvas.height = viewport.height; + canvas.width = viewport.width; + + var ctx = canvas.getContext('2d'); + ctx.save(); + ctx.fillStyle = 'rgb(255, 255, 255)'; + ctx.fillRect(0, 0, canvas.width, canvas.height); + ctx.restore(); + + var view = page.view; + var scaleX = (canvas.width / page.width); + var scaleY = (canvas.height / page.height); + ctx.translate(-view.x * scaleX, -view.y * scaleY); + + // Render PDF page into canvas context + var renderContext = { + canvasContext: ctx, + viewport: viewport + }; + + pageRendering = page.render(renderContext); + pageRendering.onData(function(){ + canvasSaver(canvas,title,location); + var imageElement = document.getElementById(location); + imageElement.src = canvas.toDataURL(); + imageElement.style.height = '100px'; + imageElement.style.width = '100px'; + + }); + }); + }); +} diff --git a/reader/js/integrate.js b/reader/js/integrate.js index 75d127d6c..141fe7b43 100755 --- a/reader/js/integrate.js +++ b/reader/js/integrate.js @@ -5,25 +5,10 @@ $(document).ready(function() { }); $('#file_action_panel').attr('activeAction', false); - - $('.start').click(function(){ - var contentbox = $(this).parent().children('div#contentbox'); - var path = $(this).parent().children('a.name').attr('dir'); - contentbox.show(100); - contentbox.keypress(function(e) { - if(e.which == 13) { - var tag = contentbox.text(); - contentbox.text(''); - contentbox.hide(); - var displaybox = $(this).parent().children('div#displaybox'); - displaybox.append('<a href = "apps/reader/fetch_tags.php?tag='+tag+'">'+tag+'</a>'); - displaybox.append(' '); - $.post('apps/reader/ajax/tags.php', {tag:tag, path:path}); - } - }); - }); + }); + $(function() { // See if url conatins the index 'reader' if(location.href.indexOf("reader")!=-1) { @@ -45,6 +30,31 @@ $(function() { } }); } + + $('form#TagForm').submit(function(event) { + event.preventDefault(); + var path = $(this).parent().children('a.name').attr('dir'); + var result = $(this).parent().children('div#result'); + var $form = $(this), + tag = $form.find( 'input[name="tag"]' ).val(), + url = $form.attr('action'); + $.post( url, {tag:tag,path:path}, + function(data) { + result.append('<div class = "each_result"><a id = "each_tag" "href = "apps/reader/fetch_tags.php?tag='+data+'">'+data+'</a><a id = "close" value = "'+data+'">x</a></div></div>'); + } + ); + }); + + $('a#close').click(function(){ + event.preventDefault(); + var elem = $(this).parent(); + var filepath = $(this).parent().parent().parent().children('a.name').attr('dir'); + var url = 'apps/reader/ajax/remove_tags.php'; + var tag = $(this).attr('value'); + elem.hide(); + $.post(url, {tag:tag, filepath:filepath}); + }); + }); /* Function that returns suitable function definition to be executed on diff --git a/reader/lib/library_display.php b/reader/lib/library_display.php index 853740633..6383211fd 100755 --- a/reader/lib/library_display.php +++ b/reader/lib/library_display.php @@ -9,24 +9,30 @@ function display_each_ebook($directory,$name) { <span class = "nametext">'. htmlspecialchars(urldecode($name)). '</span> - </a> - <div id = "displaybox">'; - $each_row = find_tags_for_ebook(urldecode($directory).urldecode($name)); - $tags = explode(",",$each_row); - $tag_count = 1; + </a>'; + $each_row = find_tags_for_ebook(urldecode($directory).urldecode($name)); + $tags = explode(",",$each_row); + if (count($tags) < 5) { + echo '<form action = "apps/reader/ajax/tags.php" id="TagForm"> + <input type="text" name="tag" placeholder="Add Tag..." /> + <input type="submit" value="Add Tag" /> + </form>'; + } + + if (count($tags) >= 1) { + echo '<div id="result">'; foreach ($tags as $tag) { - if ($tag_count == 2) { - echo ", "; - } - echo '<a href = "'.\OCP\Util::linkTo('reader', 'fetch_tags.php').'?tag='.$tag.'">' - .ucwords($tag). + if ($tag != '' ) { + echo '<div class = "each_result">'; + echo '<a id = "each_tag" href = "'.\OCP\Util::linkTo('reader', 'fetch_tags.php').'?tag='.$tag.'">' + .ucwords($tag). '</a>'; - $tag_count+= 1; + echo '<a id = "close" value = "'.$tag.'">x</a></div>'; + } } - echo '</div> - <input type="button" class="start" value="Add Tag"> - <div id="contentbox" contenteditable="true"></div> - </td>'; + echo '</div>'; + } + echo '</td>'; } function display_sub_dirs($current_dir,$sub_dirs) { diff --git a/reader/lib/tag_utils.php b/reader/lib/tag_utils.php index d18cdd416..7d77a3feb 100755 --- a/reader/lib/tag_utils.php +++ b/reader/lib/tag_utils.php @@ -11,8 +11,14 @@ function find_tags_for_ebook($path_of_ebook) { } function update_tag_for_ebook($new_tag,$path_of_ebook) { - $stmt = OCP\DB::prepare("UPDATE *PREFIX*eBook_library SET tags = ? WHERE filepath = ?"); - $stmt->execute(array($new_tag,$path_of_ebook)); + $tags = find_tags_for_ebook($path_of_ebook); + $each_tag = explode(",",$tags); + if (count($each_tag) < 5) { + $stmt = OCP\DB::prepare("UPDATE *PREFIX*eBook_library SET tags = ? WHERE filepath = ?"); + $stmt->execute(array($new_tag,$path_of_ebook)); + } + else + return; } function insert_new_tag($new_tag,$path_of_ebook) { @@ -46,4 +52,5 @@ function delete_entry($filepath) { $stmt = OCP\DB::prepare($sql); $res = $stmt->execute(array($filepath)); } + ?> diff --git a/reader/templates/tagged.php b/reader/templates/tagged.php index a3105306d..5ac3665a7 100755 --- a/reader/templates/tagged.php +++ b/reader/templates/tagged.php @@ -17,7 +17,8 @@ while($r = $res->fetchRow()) { $dirname = dirname($r['filepath']); if ($dirname != '/') { - $dirname = $dirname.'/'; } + $dirname = $dirname.'/'; + } display_ebooks(basename($r['filepath']),$dirname); } ?> |