Merge remote branch 'gitorious/0.9.x' into 0.9.x

This commit is contained in:
Evan Prodromou 2010-11-26 22:11:12 -05:00
commit 8212df3e1a
3 changed files with 189 additions and 1 deletions

View File

@ -457,9 +457,103 @@ var SN = { // StatusNet
return false;
});
if (typeof this.files == "object") {
// Some newer browsers will let us fetch the files for preview.
for (var i = 0; i < this.files.length; i++) {
SN.U.PreviewAttach(this.files[i]);
}
}
});
},
/**
* For browsers with FileAPI support: make a thumbnail if possible,
* and append it into the attachment display widget.
*
* Known good:
* - Firefox 3.6.6, 4.0b7
* - Chrome 8.0.552.210
*
* Known ok metadata, can't get contents:
* - Safari 5.0.2
*
* Known fail:
* - Opera 10.63, 11 beta (no input.files interface)
*
* @param {File} file
*
* @todo use configured thumbnail size
* @todo detect pixel size?
* @todo should we render a thumbnail to a canvas and then use the smaller image?
*/
PreviewAttach: function(file) {
var tooltip = file.type + ' ' + Math.round(file.size / 1024) + 'KB';
var preview = true;
var blobAsDataURL;
if (typeof window.createObjectURL != "undefined") {
/**
* createObjectURL lets us reference the file directly from an <img>
* This produces a compact URL with an opaque reference to the file,
* which we can reference immediately.
*
* - Firefox 3.6.6: no
* - Firefox 4.0b7: no
* - Safari 5.0.2: no
* - Chrome 8.0.552.210: works!
*/
blobAsDataURL = function(blob, callback) {
callback(window.createObjectURL(blob));
}
} else if (typeof window.FileReader != "undefined") {
/**
* FileAPI's FileReader can build a data URL from a blob's contents,
* but it must read the file and build it asynchronously. This means
* we'll be passing a giant data URL around, which may be inefficient.
*
* - Firefox 3.6.6: works!
* - Firefox 4.0b7: works!
* - Safari 5.0.2: no
* - Chrome 8.0.552.210: works!
*/
blobAsDataURL = function(blob, callback) {
var reader = new FileReader();
reader.onload = function(event) {
callback(reader.result);
}
reader.readAsDataURL(blob);
}
} else {
preview = false;
}
var imageTypes = ['image/png', 'image/jpeg', 'image/gif', 'image/svg+xml'];
if ($.inArray(file.type, imageTypes) == -1) {
// We probably don't know how to show the file.
preview = false;
}
var maxSize = 8 * 1024 * 1024;
if (file.size > maxSize) {
// Don't kill the browser trying to load some giant image.
preview = false;
}
if (preview) {
blobAsDataURL(file, function(url) {
var img = $('<img>')
.attr('title', tooltip)
.attr('alt', tooltip)
.attr('src', url)
.attr('style', 'height: 120px');
$('#'+SN.C.S.NoticeDataAttachSelected).append(img);
});
} else {
var img = $('<div></div>').text(tooltip);
$('#'+SN.C.S.NoticeDataAttachSelected).append(img);
}
},
NoticeLocationAttach: function() {
var NLat = $('#'+SN.C.S.NoticeLat).val();
var NLon = $('#'+SN.C.S.NoticeLon).val();

2
js/util.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,94 @@
<?php
/*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2010, StatusNet, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*/
if (!defined('STATUSNET')) {
exit(1);
}
/**
* Example to disable all debug messages and those containing 'About to push':
* addPlugin('LogFilter', array(
* 'priority' => array(LOG_DEBUG => false),
* 'regex' => array('/About to push/' => false)
* ));
*
* @todo add an admin panel
*
* @package LogFilterPlugin
* @maintainer Brion Vibber <brion@status.net>
*/
class LogFilterPlugin extends Plugin
{
public $default = true; // Set to false to require opting things in
public $priority = array(); // override by priority: array(LOG_ERR => true, LOG_DEBUG => false)
public $regex = array(); // override by regex match of message: array('/twitter/i' => false)
function onPluginVersion(&$versions)
{
$versions[] = array('name' => 'LogFilter',
'version' => STATUSNET_VERSION,
'author' => 'Brion Vibber',
'homepage' => 'http://status.net/wiki/Plugin:LogFilter',
'rawdescription' =>
_m('Provides server-side setting to filter log output by type or keyword.'));
return true;
}
/**
* Hook for the StartLog event in common_log().
* If a message doesn't pass our filters, we'll abort it.
*
* @param string $priority
* @param string $msg
* @param string $filename
* @return boolean hook result code
*/
function onStartLog(&$priority, &$msg, &$filename)
{
if ($this->filter($priority, $msg)) {
// Let it through
return true;
} else {
// Abort -- this line will go to /dev/null :)
return false;
}
}
/**
* Do the filtering...
*
* @param string $priority
* @param string $msg
* @return boolean true to let the log message be processed
*/
function filter($priority, $msg)
{
$state = $this->default;
if (array_key_exists($priority, $this->priority)) {
$state = $this->priority[$priority];
}
foreach ($this->regex as $regex => $override) {
if (preg_match($regex, $msg)) {
$state = $override;
}
}
return $state;
}
}