Browse Source

- Clean some old code

- Remove Media and MediaUpload widgets
- Add the comments on the blog
- Fix an issue on the nginx daemon configuration generation
pull/16/head
Jaussoin Timothée 11 years ago
parent
commit
3247ef07dc
  1. 9
      app/assets/js/movim_utils.js
  2. 9
      app/widgets/Blog/Blog.php
  3. 31
      app/widgets/Blog/blog.tpl
  4. 186
      app/widgets/Media/Media.php
  5. 7
      app/widgets/Media/_media_empty.tpl
  6. BIN
      app/widgets/Media/img/paper.png
  7. 10
      app/widgets/Media/locales.ini
  8. 112
      app/widgets/Media/media.css
  9. 181
      app/widgets/Media/media.js
  10. 15
      app/widgets/Media/media.tpl
  11. 32
      app/widgets/MediaUpload/MediaUpload.php
  12. 5
      app/widgets/MediaUpload/locales.ini
  13. 28
      app/widgets/MediaUpload/mediaupload.css
  14. 56
      app/widgets/MediaUpload/mediaupload.tpl
  15. 1
      app/widgets/Post/locales.ini
  16. 2
      app/widgets/System/System.php
  17. 1
      locales/locales.ini
  18. 2
      src/Movim/Daemon/Core.php

9
app/assets/js/movim_utils.js

@ -21,15 +21,10 @@ function movim_get_node(str) {
/**
* @brief Force Movim to go back to the login page
* @param string error
*/
function movim_disconnect(error)
function movim_disconnect()
{
if(error == null) {
window.location.replace(ERROR_URI);
} else {
window.location.replace(ERROR_URI + error);
}
window.location.replace(ERROR_URI);
}
/**

9
app/widgets/Blog/Blog.php

@ -32,4 +32,13 @@ class Blog extends WidgetBase {
$this->view->assign('posts', $messages);
}
function getComments($post)
{
$pd = new \Modl\PostnDAO();
return $pd->getComments($post);
//$view = $this->tpl();
//$view->assign('comments', $comments);
}
}

31
app/widgets/Blog/blog.tpl

@ -97,7 +97,38 @@
{/if}
</ul>
</footer>
{$comments = $c->getComments($value)}
{if="$comments"}
<ul class="spaced middle">
<li class="subheader">
{$c->__('post.comments')}
<span class="info">{$comments|count}</span>
</li>
{loop="$comments"}
<li class="condensed">
{$url = $value->getContact()->getPhoto('s')}
{if="$url"}
<span class="icon bubble">
<img src="{$url}">
</span>
{else}
<span class="icon bubble color {$value->getContact()->jid|stringToColor}">
<i class="md md-person"></i>
</span>
{/if}
<span class="info">{$value->published|strtotime|prepareDate}</span>
<span>
{$value->getContact()->getTrueName()}
</span>
<p>
{$value->content}
</p>
</li>
{/loop}
</ul>
{/if}
</article>
{/loop}
{if="$posts == null"}
<ul class="simple thick">

186
app/widgets/Media/Media.php

@ -1,186 +0,0 @@
<?php
/**
* @package Widgets
*
* @file Media.php
* This file is part of MOVIM.
*
* @brief The media manager.
*
* @author Timothée Jaussoin <edhelas@gmail.com>
*
* @version 1.0
* @date 07 December 2011
*
* Copyright (C)2010 MOVIM project
*
* See COPYING for licensing information.
*/
class Media extends WidgetBase {
function load()
{
$this->addcss('media.css');
$this->addjs('media.js');
if(isset($this->user)
&& !is_dir($this->user->userdir)
&& $this->user->userdir != '') {
mkdir($this->user->userdir);
touch($this->user->userdir.'index.html');
}
$this->registerEvent('media', 'onMediaUploaded');
}
function display() {
$this->view->assign('refresh', $this->call('ajaxRefreshMedia'));
}
function ajaxRefreshMedia()
{
$html = $this->mainFolder();
RPC::call('movim_fill', 'media', $html);
RPC::commit();
}
function ajaxDeleteItem($name)
{
unlink($this->user->userdir.$name);
$this->ajaxRefreshMedia();
}
function listFiles()
{
if(empty($this->user->getDir())) {
$mediaempty = $this->tpl();
return $mediaempty->draw('_media_empty', true);
}
$html = '<ul class="thumb">';
foreach($this->user->getDir() as $file) {
$p = new \Picture;
// Just to prevent issue when you update from an old Movim version
if($p->get($this->user->userdir.$file, 300) == false) {
$p->fromPath($this->user->userdir.$file);
$p->set($this->user->userdir.$file);
}
$html .=
'<li style="background-image: url('.$p->get($this->user->userdir.$file, 300).');">
<a href="'.Route::urlize('media', $file).'">
</a>
<div
class="remove"
onclick="'.
$this->call(
'ajaxDeleteItem',
"'".$file."'"
).'">
<i class="fa fa-times"></i>
</div>
</li>
';
}
$html .= '</ul>';
return $html;
}
function mainFolder()
{
$percent = number_format(($this->user->dirSize()/$this->user->sizelimit)*100, 2);
$html =
$this->listFiles().'
<span class="size"
title="'.sizeToCleanSize($this->user->dirSize()).' '.$this->__('media.on').' '.sizeToCleanSize($this->user->sizelimit).'"
>'.
$percent.'%
</span>';
return $html;
}
function pictureViewer($f)
{
if(file_exists($this->user->userdir.$f) && getimagesize($this->user->userdir.$f) != 0) {
$er = @exif_read_data($this->user->userdir.$f);
$exif = '';
if($er) {
if(isset($er['FileName']))
$exif .= '
<li>
<span>'.$this->__('media.name').'</span>'.
$er['FileName'].'
</li>';
if(isset($er['COMPUTED']['Width']) && isset($er['COMPUTED']['Height']))
$exif .= '
<li>
<span>'.$this->__('media.resolution').'</span>'.
$er['COMPUTED']['Width'].'x'.$er['COMPUTED']['Height'].'
</li>';
if(isset($er['FileSize']))
$exif .= '
<li>
<span>'.$this->__('media.size').'</span>'.
sizeToCleanSize($er['FileSize']).'
</li>';
if(isset($er['DateTime']))
$exif .= '
<li>
<span>'.$this->__('media.date').'</span>'.
prepareDate(strtotime($er['DateTime'])).'
</li>';
if(isset($er['ISOSpeedRatings']))
$exif .= '
<li>
<span>'.$this->__('media.iso').'</span>'.
$er['ISOSpeedRatings'].'
</li>';
if(isset($er['Model']))
$exif .= '
<li>
<span>'.$this->__('media.camera').'</span>'.
$er['Model'].'
</li>';
if(isset($er['Artist']))
$exif .= '
<li>
<span>'.$this->__('media.artist').'</span>'.
$er['Artist'].'
</li>';
}
$exif .= '
<li>
<span>'.$this->__('media.original').'</span>
<a target="_blank" href="'.$this->user->useruri.$f.'">'.
$this->__('media.link').'
</a>
</li>';
$html = '
<div class="viewer">
<img src="'.$this->user->useruri.$f.'" style="max-width: '.$er['COMPUTED']['Width'].'px"/>
<div class="exif">
<ul>
'.$exif.'
</ul>
</div>
</div>';
return $html;
}
}
}

7
app/widgets/Media/_media_empty.tpl

@ -1,7 +0,0 @@
<div class="placeholder paddedtop icon media">
<h1>{$c->__('error.whoops')}</h1>
<p class="paddedtop">
{$c->__('error.media_not_found')}
</p>
<a class="button color green" href="{$c->route('media', null, 'mediaupload')}"><i class="fa fa-upload"></i> {$c->__('button.upload')}</a>
</div>

BIN
app/widgets/Media/img/paper.png

Before

Width: 100  |  Height: 100  |  Size: 7.9 KiB

10
app/widgets/Media/locales.ini

@ -1,10 +0,0 @@
media.name = 'Name'
media.resolution = 'Resolution'
media.size = 'Size'
media.date = 'Date'
media.iso = 'ISO'
media.camera = 'Camera'
media.artist = 'Artist'
media.original = 'Original'
media.link = 'Link'
media.on = 'on'

112
app/widgets/Media/media.css

@ -1,112 +0,0 @@
#center {
position: relative;
}
#navtabs, #navtabs li.on {
background-color: transparent;
color: white;
}
#navtabs,
#navtabs li.on a {
border-color: #333;
}
#navtabs li.on {
}
#navtabs li.on a,
#media h1 {
color: white;
}
#navtabs li:hover a {
border-color: #353535;
}
#media .breadcrumb {
background-color: transparent;
}
#media .breadcrumb a:after {
border-color: #222;
}
#media ul.thumb a {
position: relative;
}
#media ul.thumb li div.remove {
position: absolute;
bottom: 0px;
right: 0px;
background-color: rgba(0, 0, 0, 0.6);
font-weight: bold;
width: 2em;
height: 2em;
text-align: center;
line-height: 2em;
font-size: 1em;
display: none;
}
#media ul.thumb li:hover div.remove {
display: block;
}
#media ul.thumb li:hover div.remove:hover {
background-color: black;
cursor: pointer;
}
#center {
background-color: #222;
color: white;
}
#viewer .viewer {
position: relative;
}
#viewer .viewer img {
width: 100%;
margin: 0 auto;
height: auto;
display: block;
}
#viewer .viewer .exif {
position: absolute;
bottom: 0px;
background-color: rgba(0, 0, 0, 0.8);
width: 100%;
padding: 1em;
}
#viewer .viewer .exif ul {
list-style-type: none;
}
#viewer .viewer .exif ul li {
width: 50%;
display: block;
float: left;
overflow: hidden;
white-space: nowrap;
line-height: 1.3em;
text-overflow: ellipsis;
}
#viewer .viewer .exif span {
font-weight: bold;
margin-right: 1em;
}
#media .size {
position: absolute;
top: -3em;
right: 0px;
line-height: 3em;
display: block;
padding-right: 4em;
}

181
app/widgets/Media/media.js

@ -1,181 +0,0 @@
// common variables
var iBytesUploaded = 0;
var iBytesTotal = 0;
var iPreviousBytesLoaded = 0;
var iMaxFilesize = 1048576; // 1MB
var oTimer = 0;
var sResultFileSize = '';
function secondsToTime(secs) { // we will use this function to convert seconds in normal time format
var hr = Math.floor(secs / 3600);
var min = Math.floor((secs - (hr * 3600))/60);
var sec = Math.floor(secs - (hr * 3600) - (min * 60));
if (hr < 10) {hr = "0" + hr; }
if (min < 10) {min = "0" + min;}
if (sec < 10) {sec = "0" + sec;}
if (hr) {hr = "00";}
return hr + ':' + min + ':' + sec;
};
function bytesToSize(bytes) {
var sizes = ['Bytes', 'KB', 'MB'];
if (bytes == 0) return 'n/a';
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
return (bytes / Math.pow(1024, i)).toFixed(1) + ' ' + sizes[i];
};
function fileSelected() {
// hide different warnings
document.getElementById('upload_response').style.display = 'none';
document.getElementById('error').style.display = 'none';
document.getElementById('error2').style.display = 'none';
document.getElementById('abort').style.display = 'none';
document.getElementById('warnsize').style.display = 'none';
// get selected file element
var oFile = document.getElementById('image_file').files[0];
document.getElementById('uploadbutton').style.display = 'inline-block';
var img = new Image;
img.onerror = function() {
document.getElementById('error').style.display = 'block';
document.getElementById('uploadbutton').style.display = 'none';
return;
};
// little test for filesize
if (oFile.size > iMaxFilesize) {
document.getElementById('warnsize').style.display = 'block';
document.getElementById('uploadbutton').style.display = 'none';
return;
}
// get preview element
var oImage = document.getElementById('preview');
// prepare HTML5 FileReader
var oReader = new FileReader();
oReader.onload = function(e){
img.src = e.target.result;
// e.target.result contains the DataURL which we will use as a source of the image
oImage.src = e.target.result;
oImage.onload = function () { // binding onload event
// we are going to display some custom image information here
sResultFileSize = bytesToSize(oFile.size);
document.getElementById('fileinfo').style.display = 'block';
document.getElementById('filename').innerHTML = 'Name: ' + oFile.name;
document.getElementById('filesize').innerHTML = 'Size: ' + sResultFileSize;
document.getElementById('filetype').innerHTML = 'Type: ' + oFile.type;
document.getElementById('filedim').innerHTML = 'Dimension: ' + oImage.naturalWidth + ' x ' + oImage.naturalHeight;
};
};
// read selected file as DataURL
oReader.readAsDataURL(oFile);
}
function startUploading() {
// cleanup all temp states
iPreviousBytesLoaded = 0;
document.getElementById('upload_response').style.display = 'none';
document.getElementById('error').style.display = 'none';
document.getElementById('error2').style.display = 'none';
document.getElementById('abort').style.display = 'none';
document.getElementById('warnsize').style.display = 'none';
document.getElementById('progress_percent').innerHTML = '';
var oProgress = document.getElementById('progress');
oProgress.style.display = 'block';
oProgress.style.width = '0px';
// get form data for POSTing
var vFD = new FormData(document.getElementById('upload_form'));
// create XMLHttpRequest object, adding few event listeners, and POSTing our data
var oXHR = new XMLHttpRequest();
oXHR.upload.addEventListener('progress', uploadProgress, false);
oXHR.addEventListener('load', uploadFinish, false);
oXHR.addEventListener('error', uploadError, false);
oXHR.addEventListener('abort', uploadAbort, false);
oXHR.open('POST', 'upload.php');
oXHR.send(vFD);
// set inner timer
oTimer = setInterval(doInnerUpdates, 300);
}
function doInnerUpdates() { // we will use this function to display upload speed
var iCB = iBytesUploaded;
var iDiff = iCB - iPreviousBytesLoaded;
// if nothing new loaded - exit
if (iDiff == 0)
return;
iPreviousBytesLoaded = iCB;
iDiff = iDiff * 2;
var iBytesRem = iBytesTotal - iPreviousBytesLoaded;
var secondsRemaining = iBytesRem / iDiff;
// update speed info
var iSpeed = iDiff.toString() + 'B/s';
if (iDiff > 1024 * 1024) {
iSpeed = (Math.round(iDiff * 100/(1024*1024))/100).toString() + 'MB/s';
} else if (iDiff > 1024) {
iSpeed = (Math.round(iDiff * 100/1024)/100).toString() + 'KB/s';
}
document.getElementById('speed').innerHTML = iSpeed;
document.getElementById('remaining').innerHTML = ' ' + secondsToTime(secondsRemaining);
}
function uploadProgress(e) { // upload process in progress
if (e.lengthComputable) {
iBytesUploaded = e.loaded;
iBytesTotal = e.total;
var iPercentComplete = Math.round(e.loaded * 100 / e.total);
var iBytesTransfered = bytesToSize(iBytesUploaded);
document.getElementById('progress_percent').innerHTML = iPercentComplete.toString() + '%';
document.getElementById('progress').style.width = (iPercentComplete * 4).toString() + 'px';
document.getElementById('b_transfered').innerHTML = iBytesTransfered;
if (iPercentComplete == 100) {
var oUploadResponse = document.getElementById('upload_response');
oUploadResponse.innerHTML = '<h1>Please wait...processing</h1>';
oUploadResponse.style.display = 'block';
}
} else {
document.getElementById('progress').innerHTML = 'unable to compute';
}
}
function uploadFinish(e) { // upload successfully finished
var oUploadResponse = document.getElementById('upload_response');
oUploadResponse.innerHTML = e.target.responseText;
oUploadResponse.style.display = 'block';
document.getElementById('progress_percent').innerHTML = '100%';
document.getElementById('progress').style.width = '400px';
document.getElementById('filesize').innerHTML = sResultFileSize;
document.getElementById('remaining').innerHTML = ' 00:00:00';
clearInterval(oTimer);
refreshMedia();
}
function uploadError(e) { // upload error
document.getElementById('error2').style.display = 'block';
clearInterval(oTimer);
}
function uploadAbort(e) { // upload abort
document.getElementById('abort').style.display = 'block';
clearInterval(oTimer);
}

15
app/widgets/Media/media.tpl

@ -1,15 +0,0 @@
<script type="text/javascript">
function refreshMedia() {
{$refresh}
}
</script>
{if="isset($_GET['f'])"}
<div class="tabelem" title="{$c->__('page.viewer')}" id="viewer">
{$c->pictureViewer($_GET['f'])}
</div>
{/if}
<div class="tabelem" title="{$c->__('page.media')}" id="media">
{$c->mainFolder();}
<div class="clear"></div>
</div>

32
app/widgets/MediaUpload/MediaUpload.php

@ -1,32 +0,0 @@
<?php
/**
* @package Widgets
*
* @file MediaUpload.php
* This file is part of MOVIM.
*
* @brief The media upload.
*
* @author Timothée Jaussoin <edhelas@gmail.com>
*
* @version 1.0
* @date 07 December 2011
*
* Copyright (C)2010 MOVIM project
*
* See COPYING for licensing information.
*/
class MediaUpload extends WidgetBase {
function load() {
$this->addcss('mediaupload.css');
}
function display() {
if($this->user->dirSize() < $this->user->sizelimit)
$this->view->assign('limit', true);
else
$this->view->assign('limit', false);
}
}

5
app/widgets/MediaUpload/locales.ini

@ -1,5 +0,0 @@
upload.info = 'Please select image file'
upload.image_only = 'You should select valid image files only!'
upload.error = 'An error occurred while uploading the file'
upload.abort = 'The upload has been canceled by the user or the browser dropped the connection'
upload.size_limit = "Your file is very big. We can't accept it. Please select a smaller file"

28
app/widgets/MediaUpload/mediaupload.css

@ -1,28 +0,0 @@
#mediaupload #fileinfo {
clear: left;
}
#progress_info {
margin-top: 1em;
}
#fileinfo,#error,#error2,#abort,#warnsize {
display:none;
}
#progress {
margin-right: 1em;
display:none;
float:left;
height:16px;
background-color: #111;
}
#progress_percent {
float:right;
}
#mediaupload #preview {
display:block;
float:right;
max-width: 200px;
max-height: 150px;
margin-top: 1em;
}

56
app/widgets/MediaUpload/mediaupload.tpl

@ -1,56 +0,0 @@
{if="$limit"}
<div class="tabelem padded" title="{$c->__('button.upload')}" id="mediaupload">
<form id="upload_form" enctype="multipart/form-data" method="post" action="upload.php">
<fieldset>
<div class="element">
<label for="image_file"><i class="fa fa-file-image-o"></i> {$c->__('upload.info')}</label>
<input type="file" name="image_file" id="image_file" onchange="fileSelected();" />
</div>
<img id="preview" />
<div id="fileinfo">
<div id="filename"></div>
<div id="filesize"></div>
<div id="filetype"></div>
<div id="filedim"></div>
</div>
<div class="clear"></div>
<div id="progress_info">
<div id="progress"></div>
<div id="progress_percent"></div>
<div class="clear_both"></div>
<div>
<div id="speed"></div>
<div id="remaining"></div>
<div id="b_transfered"></div>
<div class="clear_both"></div>
</div>
<div id="upload_response"></div>
</div>
</fieldset>
<div class="clear"></div>
<a id="uploadbutton" class="button color green" onclick="startUploading()" />
<i class="fa fa-upload"></i> {$c->__('button.upload')}
</a>
<div class="message info" id="error">
{$c->__('upload.image_only')}
</div>
<div class="message error" id="error2">
{$c->__('upload.error')}
</div>
<div class="message info" id="abort">
{$c->__('upload.abort')}
</div>
<div class="message info" id="warnsize">
{$c->__('upload.size_limit')}
</div>
</form>
</div>
{/if}

1
app/widgets/Post/locales.ini

@ -30,6 +30,5 @@ post.delete_title = 'Delete this post'
post.delete_text = 'You are going to delete this post, please confirm your action'
[comment]
post.comments = 'Comments'
post.comments_disabled = 'Comments disabled'
post.comment_published = 'Comment published'

2
app/widgets/System/System.php

@ -21,7 +21,7 @@ class System extends WidgetBase {
{
$this->view->assign('base_uri', BASE_URI);
$this->view->assign('base_host', BASE_HOST);
$this->view->assign('error_uri', substr_replace(Route::urlize('disconnect', 'err'), '', -3));
$this->view->assign('error_uri', Route::urlize('disconnect'));
$r = new Route;
$this->view->assign('current_page', $r->find());

1
locales/locales.ini

@ -281,6 +281,7 @@ post.delete = 'Delete this post'
post.updated = 'Updated'
post.content_not_found = 'Content not found'
post.default_title = 'Contact publication'
post.comments = 'Comments'
[api]
api.error = 'The API is not reachable, try again later'

2
src/Movim/Daemon/Core.php

@ -45,7 +45,7 @@ class Core implements MessageComponentInterface {
"\n";
echo colorize("Add this in your configuration file", 'yellow')."\n";
echo "location /ws/ {
proxy_pass http://{$explode['host']}:{$port}/;
proxy_pass http://localhost:{$port}/;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection \"Upgrade\";

Loading…
Cancel
Save