summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorZach Copley <zach@controlyourself.ca>2009-06-23 14:29:46 -0700
committerZach Copley <zach@controlyourself.ca>2009-06-23 14:29:46 -0700
commitf04a54ed2f70686d67ed50da21bde61c55b07696 (patch)
treed4dbfac2a98e35b6f47696f787a3c2aa551f51ab /classes
parent31325f0995bb61413b07f166d253b13fb27d085d (diff)
parent2d3e990ed47ee1c7130e1febabe7133884a85c80 (diff)
Merge branch '0.8.x' of git@gitorious.org:laconica/dev into 0.8.x
* '0.8.x' of git@gitorious.org:laconica/dev: (61 commits) Using default theme design values (it was previously set to identica Updated default colour theme and IE6 colours for transparent values chmod +x delete_status_network.sh rm -Rf, not rmdir script to delete a status network chmod allsites.php script to show all sites on a network use different name for connection and database use /etc/laconica/setup.cfg instead of local file other base directories On XHR notice post, calls NoticeAttachment to trigger thumbnail and oembed and thumbnail don't need sequences add innodb by default to status networks pwgen not pwdgen make pwgen command configurable a little sql script to drop full-text index and use innodb for profile and notice remove common_debug from newnotice append uploads to content rather than showing them double use a subclass for single notice items to show attachments make file command configurable ...
Diffstat (limited to 'classes')
-rw-r--r--classes/File.php67
-rw-r--r--classes/File_oembed.php29
-rw-r--r--classes/File_redirection.php70
-rw-r--r--classes/File_thumbnail.php11
4 files changed, 65 insertions, 112 deletions
diff --git a/classes/File.php b/classes/File.php
index 1de136240..b98c9e665 100644
--- a/classes/File.php
+++ b/classes/File.php
@@ -124,8 +124,8 @@ class File extends Memcached_DataObject
function isRespectsQuota($user) {
if ($_FILES['attach']['size'] > common_config('attachments', 'file_quota')) {
return sprintf(_('No file may be larger than %d bytes ' .
- 'and the file you sent was %d bytes. Try to upload a smaller version.'),
- common_config('attachments', 'file_quota'), $_FILES['attach']['size']);
+ 'and the file you sent was %d bytes. Try to upload a smaller version.'),
+ common_config('attachments', 'file_quota'), $_FILES['attach']['size']);
}
$query = "select sum(size) as total from file join file_to_post on file_to_post.file_id = file.id join notice on file_to_post.post_id = notice.id where profile_id = {$user->id} and file.url like '%/notice/%/file'";
@@ -148,44 +148,49 @@ class File extends Memcached_DataObject
// where should the file go?
- static function filename($notice_id, $basename)
- {
- return $notice_id . '-' . $basename;
- }
-
- static function path($filename)
- {
- $dir = common_config('attachments', 'dir');
+ static function filename($profile, $basename, $mimetype)
+ {
+ require_once 'MIME/Type/Extension.php';
+ $mte = new MIME_Type_Extension();
+ $ext = $mte->getExtension($mimetype);
+ $nickname = $profile->nickname;
+ $datestamp = strftime('%Y%m%dT%H%M%S', time());
+ $random = strtolower(common_confirmation_code(32));
+ return "$nickname-$datestamp-$random.$ext";
+ }
- if ($dir[strlen($dir)-1] != '/') {
- $dir .= '/';
- }
+ static function path($filename)
+ {
+ $dir = common_config('attachments', 'dir');
- return $dir . $filename;
- }
+ if ($dir[strlen($dir)-1] != '/') {
+ $dir .= '/';
+ }
- static function url($filename)
- {
- $path = common_config('attachments', 'path');
+ return $dir . $filename;
+ }
- if ($path[strlen($path)-1] != '/') {
- $path .= '/';
- }
+ static function url($filename)
+ {
+ $path = common_config('attachments', 'path');
- if ($path[0] != '/') {
- $path = '/'.$path;
- }
+ if ($path[strlen($path)-1] != '/') {
+ $path .= '/';
+ }
- $server = common_config('attachments', 'server');
+ if ($path[0] != '/') {
+ $path = '/'.$path;
+ }
- if (empty($server)) {
- $server = common_config('site', 'server');
- }
+ $server = common_config('attachments', 'server');
- // XXX: protocol
+ if (empty($server)) {
+ $server = common_config('site', 'server');
+ }
- return 'http://'.$server.$path.$filename;
- }
+ // XXX: protocol
+ return 'http://'.$server.$path.$filename;
+ }
}
diff --git a/classes/File_oembed.php b/classes/File_oembed.php
index 51ee57b29..69230e4a4 100644
--- a/classes/File_oembed.php
+++ b/classes/File_oembed.php
@@ -25,24 +25,24 @@ require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
* Table Definition for file_oembed
*/
-class File_oembed extends Memcached_DataObject
+class File_oembed extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $__table = 'file_oembed'; // table name
public $file_id; // int(4) primary_key not_null
- public $version; // varchar(20)
- public $type; // varchar(20)
- public $provider; // varchar(50)
- public $provider_url; // varchar(255)
- public $width; // int(4)
- public $height; // int(4)
- public $html; // text()
- public $title; // varchar(255)
- public $author_name; // varchar(50)
- public $author_url; // varchar(255)
- public $url; // varchar(255)
+ public $version; // varchar(20)
+ public $type; // varchar(20)
+ public $provider; // varchar(50)
+ public $provider_url; // varchar(255)
+ public $width; // int(4)
+ public $height; // int(4)
+ public $html; // text()
+ public $title; // varchar(255)
+ public $author_name; // varchar(50)
+ public $author_url; // varchar(255)
+ public $url; // varchar(255)
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* Static get */
@@ -51,6 +51,10 @@ class File_oembed extends Memcached_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
+ function sequenceKey()
+ {
+ return array(false, false, false);
+ }
function _getOembed($url, $maxwidth = 500, $maxheight = 400, $format = 'json') {
$cmd = common_config('oohembed', 'endpoint') . '?url=' . urlencode($url);
@@ -84,4 +88,3 @@ class File_oembed extends Memcached_DataObject
}
}
-
diff --git a/classes/File_redirection.php b/classes/File_redirection.php
index edd915c1e..c173017e2 100644
--- a/classes/File_redirection.php
+++ b/classes/File_redirection.php
@@ -25,21 +25,20 @@ require_once INSTALLDIR.'/classes/File_oembed.php';
define('USER_AGENT', 'Laconica user agent / file probe');
-
/**
* Table Definition for file_redirection
*/
-class File_redirection extends Memcached_DataObject
+class File_redirection extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $__table = 'file_redirection'; // table name
public $url; // varchar(255) primary_key not_null
- public $file_id; // int(4)
- public $redirections; // int(4)
- public $httpcode; // int(4)
+ public $file_id; // int(4)
+ public $redirections; // int(4)
+ public $httpcode; // int(4)
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* Static get */
@@ -48,8 +47,6 @@ class File_redirection extends Memcached_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
-
-
function _commonCurl($url, $redirs) {
$curlh = curl_init();
curl_setopt($curlh, CURLOPT_URL, $url);
@@ -86,8 +83,6 @@ class File_redirection extends Memcached_DataObject
return $url;
}
-
-
$curlh = File_redirection::_commonCurl($short_url, $redirs);
// Don't include body in output
curl_setopt($curlh, CURLOPT_NOBODY, true);
@@ -143,62 +138,7 @@ class File_redirection extends Memcached_DataObject
}
function _userMakeShort($long_url, $user) {
- if (empty($user)) {
- // common current user does not find a user when called from the XMPP daemon
- // therefore we'll set one here fix, so that XMPP given URLs may be shortened
- $user->urlshorteningservice = 'ur1.ca';
- }
- $curlh = curl_init();
- curl_setopt($curlh, CURLOPT_CONNECTTIMEOUT, 20); // # seconds to wait
- curl_setopt($curlh, CURLOPT_USERAGENT, 'Laconica');
- curl_setopt($curlh, CURLOPT_RETURNTRANSFER, true);
-
- switch($user->urlshorteningservice) {
- case 'ur1.ca':
- require_once INSTALLDIR.'/lib/Shorturl_api.php';
- $short_url_service = new LilUrl;
- $short_url = $short_url_service->shorten($long_url);
- break;
-
- case '2tu.us':
- $short_url_service = new TightUrl;
- require_once INSTALLDIR.'/lib/Shorturl_api.php';
- $short_url = $short_url_service->shorten($long_url);
- break;
-
- case 'ptiturl.com':
- require_once INSTALLDIR.'/lib/Shorturl_api.php';
- $short_url_service = new PtitUrl;
- $short_url = $short_url_service->shorten($long_url);
- break;
-
- case 'bit.ly':
- curl_setopt($curlh, CURLOPT_URL, 'http://bit.ly/api?method=shorten&long_url='.urlencode($long_url));
- $short_url = current(json_decode(curl_exec($curlh))->results)->hashUrl;
- break;
-
- case 'is.gd':
- curl_setopt($curlh, CURLOPT_URL, 'http://is.gd/api.php?longurl='.urlencode($long_url));
- $short_url = curl_exec($curlh);
- break;
- case 'snipr.com':
- curl_setopt($curlh, CURLOPT_URL, 'http://snipr.com/site/snip?r=simple&link='.urlencode($long_url));
- $short_url = curl_exec($curlh);
- break;
- case 'metamark.net':
- curl_setopt($curlh, CURLOPT_URL, 'http://metamark.net/api/rest/simple?long_url='.urlencode($long_url));
- $short_url = curl_exec($curlh);
- break;
- case 'tinyurl.com':
- curl_setopt($curlh, CURLOPT_URL, 'http://tinyurl.com/api-create.php?url='.urlencode($long_url));
- $short_url = curl_exec($curlh);
- break;
- default:
- $short_url = false;
- }
-
- curl_close($curlh);
-
+ $short_url = common_shorten_url($long_url);
if ($short_url) {
$short_url = (string)$short_url;
// store it
diff --git a/classes/File_thumbnail.php b/classes/File_thumbnail.php
index 21dcad571..44b92a2fa 100644
--- a/classes/File_thumbnail.php
+++ b/classes/File_thumbnail.php
@@ -25,7 +25,7 @@ require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
* Table Definition for file_thumbnail
*/
-class File_thumbnail extends Memcached_DataObject
+class File_thumbnail extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
@@ -33,8 +33,8 @@ class File_thumbnail extends Memcached_DataObject
public $__table = 'file_thumbnail'; // table name
public $file_id; // int(4) primary_key not_null
public $url; // varchar(255) unique_key
- public $width; // int(4)
- public $height; // int(4)
+ public $width; // int(4)
+ public $height; // int(4)
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* Static get */
@@ -43,6 +43,11 @@ class File_thumbnail extends Memcached_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
+ function sequenceKey()
+ {
+ return array(false, false, false);
+ }
+
function saveNew($data, $file_id) {
$tn = new File_thumbnail;
$tn->file_id = $file_id;