aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/Photo.php137
-rw-r--r--include/language.php8
-rw-r--r--mod/zregister.php47
-rw-r--r--version.inc2
4 files changed, 121 insertions, 73 deletions
diff --git a/include/Photo.php b/include/Photo.php
index 2733f5ed5..1044155b5 100644
--- a/include/Photo.php
+++ b/include/Photo.php
@@ -4,7 +4,6 @@ if(! class_exists("Photo")) {
class Photo {
private $image;
- private $ext;
/**
* Put back gd stuff, not everybody have Imagick
@@ -41,22 +40,53 @@ class Photo {
public function __construct($data, $type=null) {
$this->imagick = class_exists('Imagick');
+ $this->types = $this->supportedTypes();
+ if (!array_key_exists($type,$this->types)){
+ $type='image/jpeg';
+ }
+ $this->type = $type;
if($this->is_imagick()) {
$this->image = new Imagick();
$this->image->readImageBlob($data);
- // If it is a gif, it may be animated, get it ready for any future operations
- if($this->image->getFormat() !== "GIF") $this->image = $this->image->coalesceImages();
+ /**
+ * Setup the image to the format it will be saved to
+ */
+ $map = $this->get_FormatsMap();
+ $format = $map[$type];
+ $this->image->setFormat($format);
- $this->ext = strtolower($this->image->getImageFormat());
- } else {
- $this->types = $this->supportedTypes();
- if (!array_key_exists($type,$this->types)){
- $type='image/jpeg';
+ // Always coalesce, if it is not a multi-frame image it won't hurt anyway
+ $this->image = $this->image->coalesceImages();
+
+ /**
+ * setup the compression here, so we'll do it only once
+ */
+ switch($this->getType()){
+ case "image/png":
+ $quality = get_config('system','png_quality');
+ if((! $quality) || ($quality > 9))
+ $quality = PNG_QUALITY;
+ /**
+ * From http://www.imagemagick.org/script/command-line-options.php#quality:
+ *
+ * 'For the MNG and PNG image formats, the quality value sets
+ * the zlib compression level (quality / 10) and filter-type (quality % 10).
+ * The default PNG "quality" is 75, which means compression level 7 with adaptive PNG filtering,
+ * unless the image has a color map, in which case it means compression level 7 with no PNG filtering'
+ */
+ $quality = $quality * 10;
+ $this->image->setCompressionQuality($quality);
+ break;
+ case "image/jpeg":
+ $quality = get_config('system','jpeg_quality');
+ if((! $quality) || ($quality > 100))
+ $quality = JPEG_QUALITY;
+ $this->image->setCompressionQuality($quality);
}
+ } else {
$this->valid = false;
- $this->type = $type;
$this->image = @imagecreatefromstring($data);
if($this->image !== FALSE) {
$this->width = imagesx($this->image);
@@ -83,6 +113,18 @@ class Photo {
return $this->imagick;
}
+ /**
+ * Maps Mime types to Imagick formats
+ */
+ public function get_FormatsMap() {
+ $m = array(
+ 'image/jpeg' => 'JPG',
+ 'image/png' => 'PNG',
+ 'image/gif' => 'GIF'
+ );
+ return $m;
+ }
+
public function is_valid() {
if($this->is_imagick())
return ($this->image !== FALSE);
@@ -111,8 +153,8 @@ class Photo {
if(!$this->is_valid())
return FALSE;
- /* Clean it */
if($this->is_imagick()) {
+ /* Clean it */
$this->image = $this->image->deconstructImages();
return $this->image;
}
@@ -123,10 +165,6 @@ class Photo {
if(!$this->is_valid())
return FALSE;
- if($this->is_imagick()) {
- // This should do the trick (see supportedTypes above)
- return 'image/'. $this->getExt();
- }
return $this->type;
}
@@ -134,9 +172,7 @@ class Photo {
if(!$this->is_valid())
return FALSE;
- if($this->is_imagick())
- return $this->ext;
- return $this->types[$this->type];
+ return $this->types[$this->getType()];
}
public function scaleImage($max) {
@@ -148,7 +184,7 @@ class Photo {
* If it is not animated, there will be only one iteration here,
* so don't bother checking
*/
- // Don't forget to go back to the first frame for any further operation
+ // Don't forget to go back to the first frame
$this->image->setFirstIterator();
do {
$this->image->resizeImage($max, $max, imagick::FILTER_LANCZOS, 1, true);
@@ -365,7 +401,7 @@ class Photo {
if($this->is_imagick()) {
$this->image->setFirstIterator();
do {
- $this->image->resizeImage($max, $max, imagick::FILTER_LANCZOS, 1, false);
+ $this->image->resizeImage($dim, $dim, imagick::FILTER_LANCZOS, 1, false);
} while ($this->image->nextImage());
return;
}
@@ -425,59 +461,32 @@ class Photo {
if(!$this->is_valid())
return FALSE;
- $quality = FALSE;
+ if($this->is_imagick()) {
+ /* Clean it */
+ $this->image = $this->image->deconstructImages();
+ $string = $this->image->getImagesBlob();
+ return $string;
+ }
- /**
- * Hmmm, for Imagick
- * we should do the conversion/compression at the initialisation i think
- * This method may be called several times,
- * and there is no need to do that more than once
- */
+ $quality = FALSE;
- if(!$this->is_imagick()) ob_start();
+ ob_start();
switch($this->getType()){
case "image/png":
$quality = get_config('system','png_quality');
if((! $quality) || ($quality > 9))
$quality = PNG_QUALITY;
- if($this->is_imagick()) {
- /**
- * From http://www.imagemagick.org/script/command-line-options.php#quality:
- *
- * 'For the MNG and PNG image formats, the quality value sets
- * the zlib compression level (quality / 10) and filter-type (quality % 10).
- * The default PNG "quality" is 75, which means compression level 7 with adaptive PNG filtering,
- * unless the image has a color map, in which case it means compression level 7 with no PNG filtering'
- */
- $quality = $quality * 10;
- } else imagepng($this->image,NULL, $quality);
- break;
- case "image/gif":
- // We change nothing here, do we?
+ imagepng($this->image,NULL, $quality);
break;
- default:
- // Convert to jpeg by default
+ case "image/jpeg":
$quality = get_config('system','jpeg_quality');
if((! $quality) || ($quality > 100))
$quality = JPEG_QUALITY;
- if($this->is_imagick())
- $this->image->setImageFormat('jpeg');
- else imagejpeg($this->image,NULL,$quality);
- }
-
- if($this->is_imagick()) {
- if($quality !== FALSE) {
- // Do we need to iterate for animations?
- $this->image->setImageCompressionQuality($quality);
- $this->image->stripImage();
- }
-
- $string = $this->image->getImagesBlob();
- } else {
- $string = ob_get_contents();
- ob_end_clean();
+ imagejpeg($this->image,NULL,$quality);
}
+ $string = ob_get_contents();
+ ob_end_clean();
return $string;
}
@@ -583,14 +592,14 @@ function guess_image_type($filename, $fromcurl=false) {
}
if (is_null($type)){
// Guessing from extension? Isn't that... dangerous?
- if($this->is_imagick()) {
+ if(class_exists('Imagick')) {
/**
* Well, this not much better,
* but at least it comes from the data inside the image,
* we won't be tricked by a manipulated extension
*/
$image = new Imagick($filename);
- $type = 'image/'. strtolower($image->getImageFormat());
+ $type = $image->getImageMimeType();
} else {
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$types = Photo::supportedTypes();
@@ -625,11 +634,7 @@ function import_profile_photo($photo,$uid,$cid) {
$filename = basename($photo);
$img_str = fetch_url($photo,true);
- if($this->is_imagick()) $type = null;
- else {
- // guess mimetype from headers or filename
- $type = guess_image_type($photo,true);
- }
+ $type = guess_image_type($photo,true);
$img = new Photo($img_str, $type);
if($img->is_valid()) {
diff --git a/include/language.php b/include/language.php
index 823fd3c96..dc54fbd2e 100644
--- a/include/language.php
+++ b/include/language.php
@@ -110,6 +110,14 @@ function load_translation_table($lang) {
}
else
$a->strings = array();
+
+ // Allow individual strings to be over-ridden on this site
+ // Either for the default language or for all languages
+
+ if(file_exists("view/local-$lang/strings.php")) {
+ include("view/local-$lang/strings.php");
+ }
+
}}
// translate string if translation exists
diff --git a/mod/zregister.php b/mod/zregister.php
index 4eea51ddc..b683a9d85 100644
--- a/mod/zregister.php
+++ b/mod/zregister.php
@@ -3,6 +3,29 @@
function zregister_init(&$a) {
$a->page['template'] = 'full';
+
+ $cmd = ((argc() > 1) ? argv(1) : '');
+
+
+ if($cmd === 'email_check.json') {
+ $result = array('error' => false, 'message' => '');
+ $email = $_REQUEST['email'];
+
+ if(! allowed_email($email))
+ $result['message'] = t('Your email domain is not among those allowed on this site.');
+ if((! valid_email($email)) || (! validate_email($email)))
+ $result['message'] .= t('Not a valid email address.') . EOL;
+ if($result['message'])
+ $result['error'] = true;
+
+ header('content-type: application/json');
+ echo json_encode($result);
+ killme();
+ }
+
+
+
+
}
@@ -16,7 +39,7 @@ function zregister_post(&$a) {
$max_dailies = intval(get_config('system','max_daily_registrations'));
if($max_dailies) {
- $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
+ $r = q("select count(*) as total from account where account_created > UTC_TIMESTAMP - INTERVAL 1 day");
if($r && $r[0]['total'] >= $max_dailies) {
return;
}
@@ -177,17 +200,29 @@ function zregister_content(&$a) {
}
}
+ // Configurable terms of service link
+
+ $tosurl = get_config('system','tos_url');
+ if(! $tosurl)
+ $tosurl = $a->get_baseurl() . '/help/TermsOfService';
+
+ $toslink = '<a href="' . $tosurl . '" >' . t('Terms of Service') . '</a>';
+
+ // Configurable whether to restrict age or not - default is based on international legal requirements
+ // This can be relaxed if you are on a restricted server that does not share with public servers
+
+ if(get_config('system','no_age_restriction'))
+ $label_tos = sprintf( t('I accept the %s for this website'), $toslink);
+ else
+ $label_tos = sprintf( t('I am over 13 years of age and accept the %s for this website'), $toslink);
+
$email = ((x($_REQUEST,'email')) ? $_REQUEST['email'] : "" );
$password = ((x($_REQUEST,'password')) ? $_REQUEST['password'] : "" );
$password2 = ((x($_REQUEST,'password2')) ? $_REQUEST['password2'] : "" );
$invite_code = ((x($_REQUEST,'invite_code')) ? $_REQUEST['invite_code'] : "" );
- $tosurl = get_config('system','tos_url');
- if(! $tosurl)
- $tosurl = $a->get_baseurl() . '/help/TOS';
- $toslink = '<a href="' . $tosurl . '" >' . t('Terms of Service') . '</a>';
$o = replace_macros(get_markup_template('zregister.tpl'), array(
@@ -201,7 +236,7 @@ function zregister_content(&$a) {
'$label_email' => t('Your email address'),
'$label_pass1' => t('Choose a password'),
'$label_pass2' => t('Please re-enter your password'),
- '$label_tos' => sprintf( t('I have read and accept the %s for this website'), $toslink),
+ '$label_tos' => $label_tos,
'$email' => $email,
'$pass1' => $password,
diff --git a/version.inc b/version.inc
index 4441bb0e1..2ca963b77 100644
--- a/version.inc
+++ b/version.inc
@@ -1 +1 @@
-2012-07-21.22
+2012-07-22.23