diff --git a/boot.php b/boot.php index 6695d4e52..5a563c991 100644 --- a/boot.php +++ b/boot.php @@ -8,11 +8,12 @@ require_once('include/datetime.php'); require_once('include/pgettext.php'); require_once('include/nav.php'); require_once('include/cache.php'); +require_once('library/Mobile_Detect/Mobile_Detect.php'); define ( 'FRIENDICA_PLATFORM', 'Friendica'); -define ( 'FRIENDICA_VERSION', '3.0.1407' ); +define ( 'FRIENDICA_VERSION', '3.0.1421' ); define ( 'DFRN_PROTOCOL_VERSION', '2.23' ); -define ( 'DB_UPDATE_VERSION', 1153 ); +define ( 'DB_UPDATE_VERSION', 1154 ); define ( 'EOL', "
\r\n" ); define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' ); @@ -191,6 +192,7 @@ define ( 'NOTIFY_SUGGEST', 0x0020 ); define ( 'NOTIFY_PROFILE', 0x0040 ); define ( 'NOTIFY_TAGSELF', 0x0080 ); define ( 'NOTIFY_TAGSHARE', 0x0100 ); +define ( 'NOTIFY_POKE', 0x0200 ); define ( 'NOTIFY_SYSTEM', 0x8000 ); @@ -215,7 +217,7 @@ define ( 'TERM_OBJ_PHOTO', 2 ); * various namespaces we may need to parse */ -define ( 'NAMESPACE_ZOT', 'http://purl.org/macgirvin/zot' ); +define ( 'NAMESPACE_ZOT', 'http://purl.org/zot' ); define ( 'NAMESPACE_DFRN' , 'http://purl.org/macgirvin/dfrn/1.0' ); define ( 'NAMESPACE_THREAD' , 'http://purl.org/syndication/thread/1.0' ); define ( 'NAMESPACE_TOMB' , 'http://purl.org/atompub/tombstones/1.0' ); @@ -250,6 +252,8 @@ define ( 'ACTIVITY_UPDATE', NAMESPACE_ACTIVITY_SCHEMA . 'update' ); define ( 'ACTIVITY_TAG', NAMESPACE_ACTIVITY_SCHEMA . 'tag' ); define ( 'ACTIVITY_FAVORITE', NAMESPACE_ACTIVITY_SCHEMA . 'favorite' ); +define ( 'ACTIVITY_POKE', NAMESPACE_ZOT . '/activity/poke' ); + define ( 'ACTIVITY_OBJ_COMMENT', NAMESPACE_ACTIVITY_SCHEMA . 'comment' ); define ( 'ACTIVITY_OBJ_NOTE', NAMESPACE_ACTIVITY_SCHEMA . 'note' ); define ( 'ACTIVITY_OBJ_PERSON', NAMESPACE_ACTIVITY_SCHEMA . 'person' ); @@ -556,7 +560,7 @@ if(! class_exists('App')) { $interval = 40000; $this->page['title'] = $this->config['sitename']; - $tpl = file_get_contents('view/head.tpl'); + $tpl = get_markup_template('head.tpl'); $this->page['htmlhead'] = replace_macros($tpl,array( '$baseurl' => $this->get_baseurl(), // FIXME for z_path!!!! '$local_user' => local_user(), @@ -569,6 +573,13 @@ if(! class_exists('App')) { )); } + function init_page_end() { + $tpl = get_markup_template('end.tpl'); + $this->page['end'] = replace_macros($tpl,array( + '$baseurl' => $this->get_baseurl() // FIXME for z_path!!!! + )); + } + function set_curl_code($code) { $this->curl_code = $code; } @@ -744,9 +755,10 @@ if(! function_exists('check_config')) { // If the update fails or times-out completely you may need to // delete the config entry to try again. - if(get_config('database','update_' . $x)) + $t = get_config('database','update_' . $x); + if($t !== false) break; - set_config('database','update_' . $x, '1'); + set_config('database','update_' . $x, time()); // call the specific update @@ -769,13 +781,14 @@ if(! function_exists('check_config')) { . 'Content-transfer-encoding: 8bit' ); //try the logger logger('CRITICAL: Update Failed: '. $x); + break; } - else + else { set_config('database','update_' . $x, 'success'); - + set_config('system','build', $x + 1); + } } } - set_config('system','build', DB_UPDATE_VERSION); } } } @@ -1238,6 +1251,12 @@ if(! function_exists('get_birthdays')) { if(! local_user()) return $o; + $mobile_detect = new Mobile_Detect(); + $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet(); + + if($is_mobile) + return $o; + $bd_format = t('g A l F d') ; // 8 AM Friday January 18 $bd_short = t('F d'); @@ -1317,6 +1336,13 @@ if(! function_exists('get_events')) { if(! local_user()) return $o; + + $mobile_detect = new Mobile_Detect(); + $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet(); + + if($is_mobile) + return $o; + $bd_format = t('g A l F d') ; // 8 AM Friday January 18 $bd_short = t('F d'); @@ -1438,9 +1464,18 @@ if(! function_exists('current_theme')) { $a = get_app(); - $system_theme = ((isset($a->config['system']['theme'])) ? $a->config['system']['theme'] : ''); - $theme_name = ((isset($_SESSION) && x($_SESSION,'theme')) ? $_SESSION['theme'] : $system_theme); + $mobile_detect = new Mobile_Detect(); + $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet(); + if($is_mobile) { + $system_theme = ((isset($a->config['system']['mobile-theme'])) ? $a->config['system']['mobile-theme'] : ''); + $theme_name = ((isset($_SESSION) && x($_SESSION,'mobile-theme')) ? $_SESSION['mobile-theme'] : $system_theme); + } + if(!$is_mobile || ($system_theme === '' && $theme_name === '')) { + $system_theme = ((isset($a->config['system']['theme'])) ? $a->config['system']['theme'] : ''); + $theme_name = ((isset($_SESSION) && x($_SESSION,'theme')) ? $_SESSION['theme'] : $system_theme); + } + if($theme_name && (file_exists('view/theme/' . $theme_name . '/style.css') || file_exists('view/theme/' . $theme_name . '/style.php'))) @@ -1576,18 +1611,21 @@ if(! function_exists('profile_tabs')){ 'url' => $url, 'sel' => ((!isset($tab)&&$a->argv[0]=='profile')?'active':''), 'title' => t('Status Messages and Posts'), + 'id' => 'status-tab', ), array( 'label' => t('Profile'), 'url' => $url.'/?tab=profile', 'sel' => ((isset($tab) && $tab=='profile')?'active':''), 'title' => t('Profile Details'), + 'id' => 'profile-tab', ), array( 'label' => t('Photos'), 'url' => $a->get_baseurl() . '/photos/' . $nickname, 'sel' => ((!isset($tab)&&$a->argv[0]=='photos')?'active':''), 'title' => t('Photo Albums'), + 'id' => 'photo-tab', ), ); @@ -1597,12 +1635,14 @@ if(! function_exists('profile_tabs')){ 'url' => $a->get_baseurl() . '/events', 'sel' =>((!isset($tab)&&$a->argv[0]=='events')?'active':''), 'title' => t('Events and Calendar'), + 'id' => 'events-tab', ); $tabs[] = array( 'label' => t('Personal Notes'), 'url' => $a->get_baseurl() . '/notes', 'sel' =>((!isset($tab)&&$a->argv[0]=='notes')?'active':''), 'title' => t('Only You Can See This'), + 'id' => 'notes-tab', ); } diff --git a/database.sql b/database.sql index 684491685..fa4f1bd58 100644 --- a/database.sql +++ b/database.sql @@ -456,6 +456,7 @@ CREATE TABLE IF NOT EXISTS `hook` ( `hook` char(255) NOT NULL, `file` char(255) NOT NULL, `function` char(255) NOT NULL, + `priority` int(11) UNSIGNED NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; diff --git a/include/Contact.php b/include/Contact.php index 14e1a52cd..ecc271a8e 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -192,6 +192,7 @@ function contact_photo_menu($contact) { $status_link=""; $photos_link=""; $posts_link=""; + $poke_link=""; $sparkle = false; if($contact['network'] === NETWORK_DFRN) { @@ -211,10 +212,12 @@ function contact_photo_menu($contact) { $pm_url = $a->get_baseurl() . '/message/new/' . $contact['id']; } + $poke_link = $a->get_baseurl() . '/poke/?f=&c=' . $contact['id']; $contact_url = $a->get_baseurl() . '/contacts/' . $contact['id']; $posts_link = $a->get_baseurl() . '/network/?cid=' . $contact['id']; $menu = Array( + t("Poke") => $poke_link, t("View Status") => $status_link, t("View Profile") => $profile_link, t("View Photos") => $photos_link, diff --git a/include/Photo.php b/include/Photo.php index ba4241a7b..1f751c77f 100644 --- a/include/Photo.php +++ b/include/Photo.php @@ -3,495 +3,686 @@ if(! class_exists("Photo")) { class Photo { - private $image; - private $width; - private $height; - private $valid; - private $type; - private $types; + private $image; - /** - * supported mimetypes and corresponding file extensions - */ - static function supportedTypes() { - $t = array(); - $t['image/jpeg'] ='jpg'; - if (imagetypes() & IMG_PNG) $t['image/png'] = 'png'; - return $t; - } + /** + * Put back gd stuff, not everybody have Imagick + */ + private $imagick; + private $width; + private $height; + private $valid; + private $type; + private $types; - public function __construct($data, $type="image/jpeg") { + /** + * supported mimetypes and corresponding file extensions + */ + static function supportedTypes() { + if(class_exists('Imagick')) { + /** + * Imagick::queryFormats won't help us a lot there... + * At least, not yet, other parts of friendica uses this array + */ + $t = array( + 'image/jpeg' => 'jpg', + 'image/png' => 'png', + 'image/gif' => 'gif' + ); + } else { + $t = array(); + $t['image/jpeg'] ='jpg'; + if (imagetypes() & IMG_PNG) $t['image/png'] = 'png'; + } - $this->types = $this->supportedTypes(); - if (!array_key_exists($type,$this->types)){ - $type='image/jpeg'; - } - $this->valid = false; - $this->type = $type; - $this->image = @imagecreatefromstring($data); - if($this->image !== FALSE) { - $this->width = imagesx($this->image); - $this->height = imagesy($this->image); - $this->valid = true; - imagealphablending($this->image, false); - imagesavealpha($this->image, true); - } - } + return $t; + } - public function __destruct() { - if($this->image) - imagedestroy($this->image); - } + 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; - public function is_valid() { - return $this->valid; - } + if($this->is_imagick()) { + $this->image = new Imagick(); + $this->image->readImageBlob($data); - public function getWidth() { - return $this->width; - } + /** + * Setup the image to the format it will be saved to + */ + $map = $this->get_FormatsMap(); + $format = $map[$type]; + $this->image->setFormat($format); - public function getHeight() { - return $this->height; - } + // Always coalesce, if it is not a multi-frame image it won't hurt anyway + $this->image = $this->image->coalesceImages(); - public function getImage() { - return $this->image; - } - - public function getType() { - return $this->type; - } - public function getExt() { - return $this->types[$this->type]; - } + /** + * 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->image = @imagecreatefromstring($data); + if($this->image !== FALSE) { + $this->width = imagesx($this->image); + $this->height = imagesy($this->image); + $this->valid = true; + imagealphablending($this->image, false); + imagesavealpha($this->image, true); + } + } + } - public function scaleImage($max) { + public function __destruct() { + if($this->image) { + if($this->is_imagick()) { + $this->image->clear(); + $this->image->destroy(); + return; + } + imagedestroy($this->image); + } + } - $width = $this->width; - $height = $this->height; + public function is_imagick() { + return $this->imagick; + } - $dest_width = $dest_height = 0; + /** + * Maps Mime types to Imagick formats + */ + public function get_FormatsMap() { + $m = array( + 'image/jpeg' => 'JPG', + 'image/png' => 'PNG', + 'image/gif' => 'GIF' + ); + return $m; + } - if((! $width)|| (! $height)) - return FALSE; + public function is_valid() { + if($this->is_imagick()) + return ($this->image !== FALSE); + return $this->valid; + } - if($width > $max && $height > $max) { - if($width > $height) { - $dest_width = $max; - $dest_height = intval(( $height * $max ) / $width); - } - else { - $dest_width = intval(( $width * $max ) / $height); - $dest_height = $max; - } - } - else { - if( $width > $max ) { - $dest_width = $max; - $dest_height = intval(( $height * $max ) / $width); - } - else { - if( $height > $max ) { - $dest_width = intval(( $width * $max ) / $height); - $dest_height = $max; - } - else { - $dest_width = $width; - $dest_height = $height; - } - } - } + public function getWidth() { + if(!$this->is_valid()) + return FALSE; + + if($this->is_imagick()) + return $this->image->getImageWidth(); + return $this->width; + } + + public function getHeight() { + if(!$this->is_valid()) + return FALSE; + + if($this->is_imagick()) + return $this->image->getImageHeight(); + return $this->height; + } + + public function getImage() { + if(!$this->is_valid()) + return FALSE; + + if($this->is_imagick()) { + /* Clean it */ + $this->image = $this->image->deconstructImages(); + return $this->image; + } + return $this->image; + } + + public function getType() { + if(!$this->is_valid()) + return FALSE; + + return $this->type; + } + + public function getExt() { + if(!$this->is_valid()) + return FALSE; + + return $this->types[$this->getType()]; + } + + public function scaleImage($max) { + if(!$this->is_valid()) + return FALSE; + + if($this->is_imagick()) { + /** + * 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 + $this->image->setFirstIterator(); + do { + $this->image->resizeImage($max, $max, imagick::FILTER_LANCZOS, 1, true); + } while ($this->image->nextImage()); + return; + } + + $width = $this->width; + $height = $this->height; + + $dest_width = $dest_height = 0; + + if((! $width)|| (! $height)) + return FALSE; + + if($width > $max && $height > $max) { + if($width > $height) { + $dest_width = $max; + $dest_height = intval(( $height * $max ) / $width); + } + else { + $dest_width = intval(( $width * $max ) / $height); + $dest_height = $max; + } + } + else { + if( $width > $max ) { + $dest_width = $max; + $dest_height = intval(( $height * $max ) / $width); + } + else { + if( $height > $max ) { + $dest_width = intval(( $width * $max ) / $height); + $dest_height = $max; + } + else { + $dest_width = $width; + $dest_height = $height; + } + } + } - $dest = imagecreatetruecolor( $dest_width, $dest_height ); - imagealphablending($dest, false); - imagesavealpha($dest, true); - if ($this->type=='image/png') imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha - imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height); - if($this->image) - imagedestroy($this->image); - $this->image = $dest; - $this->width = imagesx($this->image); - $this->height = imagesy($this->image); + $dest = imagecreatetruecolor( $dest_width, $dest_height ); + imagealphablending($dest, false); + imagesavealpha($dest, true); + if ($this->type=='image/png') imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha + imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height); + if($this->image) + imagedestroy($this->image); + $this->image = $dest; + $this->width = imagesx($this->image); + $this->height = imagesy($this->image); + } - } + public function rotate($degrees) { + if(!$this->is_valid()) + return FALSE; - public function rotate($degrees) { - $this->image = imagerotate($this->image,$degrees,0); - $this->width = imagesx($this->image); - $this->height = imagesy($this->image); - } + if($this->is_imagick()) { + $this->image->setFirstIterator(); + do { + $this->image->rotateImage(new ImagickPixel(), $degrees); + } while ($this->image->nextImage()); + return; + } - public function flip($horiz = true, $vert = false) { - $w = imagesx($this->image); - $h = imagesy($this->image); - $flipped = imagecreate($w, $h); - if($horiz) { - for ($x = 0; $x < $w; $x++) { - imagecopy($flipped, $this->image, $x, 0, $w - $x - 1, 0, 1, $h); - } - } - if($vert) { - for ($y = 0; $y < $h; $y++) { - imagecopy($flipped, $this->image, 0, $y, 0, $h - $y - 1, $w, 1); - } - } - $this->image = $flipped; - } + $this->image = imagerotate($this->image,$degrees,0); + $this->width = imagesx($this->image); + $this->height = imagesy($this->image); + } - public function orient($filename) { - // based off comment on http://php.net/manual/en/function.imagerotate.php + public function flip($horiz = true, $vert = false) { + if(!$this->is_valid()) + return FALSE; - if( (! function_exists('exif_read_data')) || ($this->getType() !== 'image/jpeg') ) - return; + if($this->is_imagick()) { + $this->image->setFirstIterator(); + do { + if($horiz) $this->image->flipImage(); + if($vert) $this->image->flopImage(); + } while ($this->image->nextImage()); + return; + } - $exif = exif_read_data($filename); - $ort = $exif['Orientation']; + $w = imagesx($this->image); + $h = imagesy($this->image); + $flipped = imagecreate($w, $h); + if($horiz) { + for ($x = 0; $x < $w; $x++) { + imagecopy($flipped, $this->image, $x, 0, $w - $x - 1, 0, 1, $h); + } + } + if($vert) { + for ($y = 0; $y < $h; $y++) { + imagecopy($flipped, $this->image, 0, $y, 0, $h - $y - 1, $w, 1); + } + } + $this->image = $flipped; + } - switch($ort) - { - case 1: // nothing - break; + public function orient($filename) { + // based off comment on http://php.net/manual/en/function.imagerotate.php - case 2: // horizontal flip - $this->flip(); - break; - - case 3: // 180 rotate left - $this->rotate(180); - break; - - case 4: // vertical flip - $this->flip(false, true); - break; - - case 5: // vertical flip + 90 rotate right - $this->flip(false, true); + if(!$this->is_valid()) + return FALSE; + + if( (! function_exists('exif_read_data')) || ($this->getType() !== 'image/jpeg') ) + return; + + $exif = exif_read_data($filename); + $ort = $exif['Orientation']; + + switch($ort) + { + case 1: // nothing + break; + + case 2: // horizontal flip + $this->flip(); + break; + + case 3: // 180 rotate left + $this->rotate(180); + break; + + case 4: // vertical flip + $this->flip(false, true); + break; + + case 5: // vertical flip + 90 rotate right + $this->flip(false, true); $this->rotate(-90); - break; - - case 6: // 90 rotate right - $this->rotate(-90); - break; - - case 7: // horizontal flip + 90 rotate right - $this->flip(); - $this->rotate(-90); - break; - - case 8: // 90 rotate left - $this->rotate(90); - break; - } - } + break; + + case 6: // 90 rotate right + $this->rotate(-90); + break; + + case 7: // horizontal flip + 90 rotate right + $this->flip(); + $this->rotate(-90); + break; + + case 8: // 90 rotate left + $this->rotate(90); + break; + } + } - public function scaleImageUp($min) { + public function scaleImageUp($min) { + if(!$this->is_valid()) + return FALSE; - $width = $this->width; - $height = $this->height; + if($this->is_imagick()) + return $this->scaleImage($min); - $dest_width = $dest_height = 0; + $width = $this->width; + $height = $this->height; - if((! $width)|| (! $height)) - return FALSE; + $dest_width = $dest_height = 0; - if($width < $min && $height < $min) { - if($width > $height) { - $dest_width = $min; - $dest_height = intval(( $height * $min ) / $width); - } - else { - $dest_width = intval(( $width * $min ) / $height); - $dest_height = $min; - } - } - else { - if( $width < $min ) { - $dest_width = $min; - $dest_height = intval(( $height * $min ) / $width); - } - else { - if( $height < $min ) { - $dest_width = intval(( $width * $min ) / $height); - $dest_height = $min; - } - else { - $dest_width = $width; - $dest_height = $height; - } - } - } + if((! $width)|| (! $height)) + return FALSE; + + if($width < $min && $height < $min) { + if($width > $height) { + $dest_width = $min; + $dest_height = intval(( $height * $min ) / $width); + } + else { + $dest_width = intval(( $width * $min ) / $height); + $dest_height = $min; + } + } + else { + if( $width < $min ) { + $dest_width = $min; + $dest_height = intval(( $height * $min ) / $width); + } + else { + if( $height < $min ) { + $dest_width = intval(( $width * $min ) / $height); + $dest_height = $min; + } + else { + $dest_width = $width; + $dest_height = $height; + } + } + } - $dest = imagecreatetruecolor( $dest_width, $dest_height ); - imagealphablending($dest, false); - imagesavealpha($dest, true); - if ($this->type=='image/png') imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha - imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height); - if($this->image) - imagedestroy($this->image); - $this->image = $dest; - $this->width = imagesx($this->image); - $this->height = imagesy($this->image); - - } + $dest = imagecreatetruecolor( $dest_width, $dest_height ); + imagealphablending($dest, false); + imagesavealpha($dest, true); + if ($this->type=='image/png') imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha + imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height); + if($this->image) + imagedestroy($this->image); + $this->image = $dest; + $this->width = imagesx($this->image); + $this->height = imagesy($this->image); + } - public function scaleImageSquare($dim) { + public function scaleImageSquare($dim) { + if(!$this->is_valid()) + return FALSE; - $dest = imagecreatetruecolor( $dim, $dim ); - imagealphablending($dest, false); - imagesavealpha($dest, true); - if ($this->type=='image/png') imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha - imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dim, $dim, $this->width, $this->height); - if($this->image) - imagedestroy($this->image); - $this->image = $dest; - $this->width = imagesx($this->image); - $this->height = imagesy($this->image); - } + if($this->is_imagick()) { + $this->image->setFirstIterator(); + do { + $this->image->resizeImage($dim, $dim, imagick::FILTER_LANCZOS, 1, false); + } while ($this->image->nextImage()); + return; + } + + $dest = imagecreatetruecolor( $dim, $dim ); + imagealphablending($dest, false); + imagesavealpha($dest, true); + if ($this->type=='image/png') imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha + imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dim, $dim, $this->width, $this->height); + if($this->image) + imagedestroy($this->image); + $this->image = $dest; + $this->width = imagesx($this->image); + $this->height = imagesy($this->image); + } - public function cropImage($max,$x,$y,$w,$h) { - $dest = imagecreatetruecolor( $max, $max ); - imagealphablending($dest, false); - imagesavealpha($dest, true); - if ($this->type=='image/png') imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha - imagecopyresampled($dest, $this->image, 0, 0, $x, $y, $max, $max, $w, $h); - if($this->image) - imagedestroy($this->image); - $this->image = $dest; - $this->width = imagesx($this->image); - $this->height = imagesy($this->image); - } + public function cropImage($max,$x,$y,$w,$h) { + if(!$this->is_valid()) + return FALSE; - public function saveImage($path) { - switch($this->type){ - case "image/png": - $quality = get_config('system','png_quality'); - if((! $quality) || ($quality > 9)) - $quality = PNG_QUALITY; - imagepng($this->image, $path, $quality); - break; - default: - $quality = get_config('system','jpeg_quality'); - if((! $quality) || ($quality > 100)) - $quality = JPEG_QUALITY; - imagejpeg($this->image,$path,$quality); - } - - } + if($this->is_imagick()) { + $this->image->setFirstIterator(); + do { + $this->image->cropImage($w, $h, $x, $y); + /** + * We need to remove the canva, + * or the image is not resized to the crop: + * http://php.net/manual/en/imagick.cropimage.php#97232 + */ + $this->image->setImagePage(0, 0, 0, 0); + } while ($this->image->nextImage()); + return $this->scaleImage($max); + } - public function imageString() { - ob_start(); - switch($this->type){ - case "image/png": - $quality = get_config('system','png_quality'); - if((! $quality) || ($quality > 9)) - $quality = PNG_QUALITY; - imagepng($this->image,NULL, $quality); - break; - default: - $quality = get_config('system','jpeg_quality'); - if((! $quality) || ($quality > 100)) - $quality = JPEG_QUALITY; + $dest = imagecreatetruecolor( $max, $max ); + imagealphablending($dest, false); + imagesavealpha($dest, true); + if ($this->type=='image/png') imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha + imagecopyresampled($dest, $this->image, 0, 0, $x, $y, $max, $max, $w, $h); + if($this->image) + imagedestroy($this->image); + $this->image = $dest; + $this->width = imagesx($this->image); + $this->height = imagesy($this->image); + } - imagejpeg($this->image,NULL,$quality); - } - $s = ob_get_contents(); - ob_end_clean(); - return $s; - } + public function saveImage($path) { + if(!$this->is_valid()) + return FALSE; + + $string = $this->imageString(); + file_put_contents($path, $string); + } + + public function imageString() { + if(!$this->is_valid()) + return FALSE; + + if($this->is_imagick()) { + /* Clean it */ + $this->image = $this->image->deconstructImages(); + $string = $this->image->getImagesBlob(); + return $string; + } + + $quality = FALSE; + + ob_start(); + + switch($this->getType()){ + case "image/png": + $quality = get_config('system','png_quality'); + if((! $quality) || ($quality > 9)) + $quality = PNG_QUALITY; + imagepng($this->image,NULL, $quality); + break; + case "image/jpeg": + $quality = get_config('system','jpeg_quality'); + if((! $quality) || ($quality > 100)) + $quality = JPEG_QUALITY; + imagejpeg($this->image,NULL,$quality); + } + $string = ob_get_contents(); + ob_end_clean(); + + return $string; + } - public function store($uid, $cid, $rid, $filename, $album, $scale, $profile = 0, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '') { + public function store($uid, $cid, $rid, $filename, $album, $scale, $profile = 0, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '') { - $r = q("select `guid` from photo where `resource-id` = '%s' and `guid` != '' limit 1", - dbesc($rid) - ); - if(count($r)) - $guid = $r[0]['guid']; - else - $guid = get_guid(); + $r = q("select `guid` from photo where `resource-id` = '%s' and `guid` != '' limit 1", + dbesc($rid) + ); + if(count($r)) + $guid = $r[0]['guid']; + else + $guid = get_guid(); - $x = q("select id from photo where `resource-id` = '%s' and uid = %d and `contact-id` = %d and `scale` = %d limit 1", - dbesc($rid), - intval($uid), - intval($cid), - intval($scale) - ); - if(count($x)) { - $r = q("UPDATE `photo` - set `uid` = %d, - `contact-id` = %d, - `guid` = '%s', - `resource-id` = '%s', - `created` = '%s', - `edited` = '%s', - `filename` = '%s', - `type` = '%s', - `album` = '%s', - `height` = %d, - `width` = %d, - `data` = '%s', - `scale` = %d, - `profile` = %d, - `allow_cid` = '%s', - `allow_gid` = '%s', - `deny_cid` = '%s', - `deny_gid` = '%s' - where id = %d limit 1", + $x = q("select id from photo where `resource-id` = '%s' and uid = %d and `contact-id` = %d and `scale` = %d limit 1", + dbesc($rid), + intval($uid), + intval($cid), + intval($scale) + ); + if(count($x)) { + $r = q("UPDATE `photo` + set `uid` = %d, + `contact-id` = %d, + `guid` = '%s', + `resource-id` = '%s', + `created` = '%s', + `edited` = '%s', + `filename` = '%s', + `type` = '%s', + `album` = '%s', + `height` = %d, + `width` = %d, + `data` = '%s', + `scale` = %d, + `profile` = %d, + `allow_cid` = '%s', + `allow_gid` = '%s', + `deny_cid` = '%s', + `deny_gid` = '%s' + where id = %d limit 1", - intval($uid), - intval($cid), - dbesc($guid), - dbesc($rid), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - dbesc(basename($filename)), - dbesc($this->type), - dbesc($album), - intval($this->height), - intval($this->width), - dbesc($this->imageString()), - intval($scale), - intval($profile), - dbesc($allow_cid), - dbesc($allow_gid), - dbesc($deny_cid), - dbesc($deny_gid), - intval($x[0]['id']) - ); - } - else { - $r = q("INSERT INTO `photo` - ( `uid`, `contact-id`, `guid`, `resource-id`, `created`, `edited`, `filename`, type, `album`, `height`, `width`, `data`, `scale`, `profile`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid` ) - VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', %d, %d, '%s', '%s', '%s', '%s' )", - intval($uid), - intval($cid), - dbesc($guid), - dbesc($rid), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - dbesc(basename($filename)), - dbesc($this->type), - dbesc($album), - intval($this->height), - intval($this->width), - dbesc($this->imageString()), - intval($scale), - intval($profile), - dbesc($allow_cid), - dbesc($allow_gid), - dbesc($deny_cid), - dbesc($deny_gid) - ); - } - return $r; - } + intval($uid), + intval($cid), + dbesc($guid), + dbesc($rid), + dbesc(datetime_convert()), + dbesc(datetime_convert()), + dbesc(basename($filename)), + dbesc($this->getType()), + dbesc($album), + intval($this->getHeight()), + intval($this->getWidth()), + dbesc($this->imageString()), + intval($scale), + intval($profile), + dbesc($allow_cid), + dbesc($allow_gid), + dbesc($deny_cid), + dbesc($deny_gid), + intval($x[0]['id']) + ); + } + else { + $r = q("INSERT INTO `photo` + ( `uid`, `contact-id`, `guid`, `resource-id`, `created`, `edited`, `filename`, type, `album`, `height`, `width`, `data`, `scale`, `profile`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid` ) + VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', %d, %d, '%s', '%s', '%s', '%s' )", + intval($uid), + intval($cid), + dbesc($guid), + dbesc($rid), + dbesc(datetime_convert()), + dbesc(datetime_convert()), + dbesc(basename($filename)), + dbesc($this->getType()), + dbesc($album), + intval($this->getHeight()), + intval($this->getWidth()), + dbesc($this->imageString()), + intval($scale), + intval($profile), + dbesc($allow_cid), + dbesc($allow_gid), + dbesc($deny_cid), + dbesc($deny_gid) + ); + } + return $r; + } }} /** * Guess image mimetype from filename or from Content-Type header - * + * * @arg $filename string Image filename * @arg $fromcurl boolean Check Content-Type header from curl request */ function guess_image_type($filename, $fromcurl=false) { logger('Photo: guess_image_type: '.$filename . ($fromcurl?' from curl headers':''), LOGGER_DEBUG); - $type = null; - if ($fromcurl) { - $a = get_app(); - $headers=array(); - $h = explode("\n",$a->get_curl_headers()); - foreach ($h as $l) { - list($k,$v) = array_map("trim", explode(":", trim($l), 2)); - $headers[$k] = $v; - } - if (array_key_exists('Content-Type', $headers)) - $type = $headers['Content-Type']; - } - if (is_null($type)){ - $ext = pathinfo($filename, PATHINFO_EXTENSION); - $types = Photo::supportedTypes(); - $type = "image/jpeg"; - foreach ($types as $m=>$e){ - if ($ext==$e) $type = $m; - } - - } + $type = null; + if ($fromcurl) { + $a = get_app(); + $headers=array(); + $h = explode("\n",$a->get_curl_headers()); + foreach ($h as $l) { + list($k,$v) = array_map("trim", explode(":", trim($l), 2)); + $headers[$k] = $v; + } + if (array_key_exists('Content-Type', $headers)) + $type = $headers['Content-Type']; + } + if (is_null($type)){ + // Guessing from extension? Isn't that... dangerous? + 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->getImageMimeType(); + } else { + $ext = pathinfo($filename, PATHINFO_EXTENSION); + $types = Photo::supportedTypes(); + $type = "image/jpeg"; + foreach ($types as $m=>$e){ + if ($ext==$e) $type = $m; + } + } + } logger('Photo: guess_image_type: type='.$type, LOGGER_DEBUG); - return $type; - + return $type; + } function import_profile_photo($photo,$uid,$cid) { - $a = get_app(); + $a = get_app(); - $r = q("select `resource-id` from photo where `uid` = %d and `contact-id` = %d and `scale` = 4 and `album` = 'Contact Photos' limit 1", - intval($uid), - intval($cid) - ); - if(count($r)) { - $hash = $r[0]['resource-id']; - } - else { - $hash = photo_new_resource(); - } - - $photo_failure = false; + $r = q("select `resource-id` from photo where `uid` = %d and `contact-id` = %d and `scale` = 4 and `album` = 'Contact Photos' limit 1", + intval($uid), + intval($cid) + ); + if(count($r)) { + $hash = $r[0]['resource-id']; + } + else { + $hash = photo_new_resource(); + } - $filename = basename($photo); - $img_str = fetch_url($photo,true); - - // guess mimetype from headers or filename - $type = guess_image_type($photo,true); + $photo_failure = false; - - $img = new Photo($img_str, $type); - if($img->is_valid()) { + $filename = basename($photo); + $img_str = fetch_url($photo,true); - $img->scaleImageSquare(175); - - $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 4 ); + $type = guess_image_type($photo,true); + $img = new Photo($img_str, $type); + if($img->is_valid()) { - if($r === false) - $photo_failure = true; + $img->scaleImageSquare(175); - $img->scaleImage(80); + $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 4 ); - $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 5 ); + if($r === false) + $photo_failure = true; - if($r === false) - $photo_failure = true; + $img->scaleImage(80); - $img->scaleImage(48); + $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 5 ); - $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 6 ); + if($r === false) + $photo_failure = true; - if($r === false) - $photo_failure = true; + $img->scaleImage(48); - $photo = $a->get_baseurl() . '/photo/' . $hash . '-4.' . $img->getExt(); - $thumb = $a->get_baseurl() . '/photo/' . $hash . '-5.' . $img->getExt(); - $micro = $a->get_baseurl() . '/photo/' . $hash . '-6.' . $img->getExt(); - } - else - $photo_failure = true; + $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 6 ); - if($photo_failure) { - $photo = $a->get_baseurl() . '/images/person-175.jpg'; - $thumb = $a->get_baseurl() . '/images/person-80.jpg'; - $micro = $a->get_baseurl() . '/images/person-48.jpg'; - } + if($r === false) + $photo_failure = true; - return(array($photo,$thumb,$micro)); + $photo = $a->get_baseurl() . '/photo/' . $hash . '-4.' . $img->getExt(); + $thumb = $a->get_baseurl() . '/photo/' . $hash . '-5.' . $img->getExt(); + $micro = $a->get_baseurl() . '/photo/' . $hash . '-6.' . $img->getExt(); + } + else + $photo_failure = true; + + if($photo_failure) { + $photo = $a->get_baseurl() . '/images/person-175.jpg'; + $thumb = $a->get_baseurl() . '/images/person-80.jpg'; + $micro = $a->get_baseurl() . '/images/person-48.jpg'; + } + + return(array($photo,$thumb,$micro)); } diff --git a/include/conversation.php b/include/conversation.php index 546e27db6..9047a9779 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -162,6 +162,49 @@ function localize_item(&$item){ $item['body'] = sprintf( t('%1$s is now friends with %2$s'), $A, $B)."\n\n\n".$Bphoto; } + if (stristr($item['verb'],ACTIVITY_POKE)) { + $verb = urldecode(substr($item['verb'],strpos($item['verb'],'#')+1)); + if(! $verb) + return; + if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) return; + + $Aname = $item['author-name']; + $Alink = $item['author-link']; + + $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">"; + + $obj = parse_xml_string($xmlhead.$item['object']); + $links = parse_xml_string($xmlhead."".unxmlify($obj->link).""); + + $Bname = $obj->title; + $Blink = ""; $Bphoto = ""; + foreach ($links->link as $l){ + $atts = $l->attributes(); + switch($atts['rel']){ + case "alternate": $Blink = $atts['href']; + case "photo": $Bphoto = $atts['href']; + } + + } + + $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]'; + $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]'; + if ($Bphoto!="") $Bphoto = '[url=' . zrl($Blink) . '][img=80x80]' . $Bphoto . '[/img][/url]'; + + // we can't have a translation string with three positions but no distinguishable text + // So here is the translate string. + + $txt = t('%1$s poked %2$s'); + + // now translate the verb + + $txt = str_replace( t('poked'), t($verb), $txt); + + // then do the sprintf on the translation string + + $item['body'] = sprintf($txt, $A, $B). "\n\n\n" . $Bphoto; + + } if ($item['verb']===ACTIVITY_TAG){ $r = q("SELECT * from `item`,`contact` WHERE `item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';", @@ -867,6 +910,7 @@ function item_photo_menu($item){ if(! count($a->contacts)) load_contact_links(local_user()); } + $poke_link=""; $contact_url=""; $pm_url=""; $status_link=""; @@ -896,6 +940,7 @@ function item_photo_menu($item){ } } if(($cid) && (! $item['self'])) { + $poke_link = $a->get_baseurl($ssl_state) . '/poke/?f=&c=' . $cid; $contact_url = $a->get_baseurl($ssl_state) . '/contacts/' . $cid; $posts_link = $a->get_baseurl($ssl_state) . '/network/?cid=' . $cid; @@ -918,6 +963,7 @@ function item_photo_menu($item){ t("Network Posts") => $posts_link, t("Edit Contact") => $contact_url, t("Send PM") => $pm_url, + t("Poke") => $poke_link ); @@ -929,7 +975,7 @@ function item_photo_menu($item){ $o = ""; foreach($menu as $k=>$v){ - if ($v!="") $o .= "
  • $k
  • \n"; + if ($v!="") $o .= "
  • $k
  • \n"; } return $o; }} @@ -1009,7 +1055,6 @@ function status_editor($a,$x, $notes_cid = 0, $popup=false) { $plaintext = true; $tpl = get_markup_template('jot-header.tpl'); - $a->page['htmlhead'] .= replace_macros($tpl, array( '$newpost' => 'true', '$baseurl' => $a->get_baseurl(true), @@ -1026,6 +1071,23 @@ function status_editor($a,$x, $notes_cid = 0, $popup=false) { )); + $tpl = get_markup_template('jot-end.tpl'); + $a->page['end'] .= replace_macros($tpl, array( + '$newpost' => 'true', + '$baseurl' => $a->get_baseurl(true), + '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'), + '$geotag' => $geotag, + '$nickname' => $x['nickname'], + '$ispublic' => t('Visible to everybody'), + '$linkurl' => t('Please enter a link URL:'), + '$vidurl' => t("Please enter a video link/URL:"), + '$audurl' => t("Please enter an audio link/URL:"), + '$term' => t('Tag term:'), + '$fileas' => t('Save to Folder:'), + '$whereareu' => t('Where are you right now?') + )); + + $tpl = get_markup_template("jot.tpl"); $jotplugins = ''; @@ -1101,6 +1163,7 @@ function status_editor($a,$x, $notes_cid = 0, $popup=false) { '$bang' => $x['bang'], '$profile_uid' => $x['profile_uid'], '$preview' => t('Preview'), + '$mobileapp' => t('Friendica mobile web'), )); diff --git a/include/diaspora.php b/include/diaspora.php index af9a91f02..a23c11bd2 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -2120,7 +2120,6 @@ function diaspora_unshare($me,$contact) { } - function diaspora_send_status($item,$owner,$contact,$public_batch = false) { $a = get_app(); @@ -2154,8 +2153,12 @@ function diaspora_send_status($item,$owner,$contact,$public_batch = false) { } } */ - // Removal of tags - $body = preg_replace('/#\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', '#$2', $body); + /** + * Transform #tags, strip off the [url] and replace spaces with underscore + */ + $body = preg_replace_callback('/#\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', create_function('$match', + 'return \'#\'. str_replace(\' \', \'_\', $match[2]);' + ), $body); //if(strlen($title)) // $body = "[b]".html_entity_decode($title)."[/b]\n\n".$body; diff --git a/include/enotify.php b/include/enotify.php index 814bd06a4..510991476 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -147,6 +147,24 @@ function notification($params) { $itemlink = $params['link']; } + if($params['type'] == NOTIFY_POKE) { + + $subject = sprintf( t('[Friendica:Notify] %1$s poked you') , $params['source_name']); + $preamble = sprintf( t('%1$s poked you at %2$s') , $params['source_name'], $sitename); + $epreamble = sprintf( t('%1$s [url=%2$s]poked you[/url].') , + '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]', + $params['link']); + + $subject = str_replace('poked', t($params['activity']), $subject); + $preamble = str_replace('poked', t($params['activity']), $preamble); + $epreamble = str_replace('poked', t($params['activity']), $epreamble); + + $sitelink = t('Please visit %s to view and/or reply to the conversation.'); + $tsitelink = sprintf( $sitelink, $siteurl ); + $hsitelink = sprintf( $sitelink, '' . $sitename . ''); + $itemlink = $params['link']; + } + if($params['type'] == NOTIFY_TAGSHARE) { $subject = sprintf( t('[Friendica:Notify] %s tagged your post') , $params['source_name']); $preamble = sprintf( t('%1$s tagged your post at %2$s') , $params['source_name'], $sitename); diff --git a/include/items.php b/include/items.php index b933804fd..701a7ada7 100755 --- a/include/items.php +++ b/include/items.php @@ -2107,6 +2107,118 @@ function local_delivery($importer,$data) { $feed->enable_order_by_date(false); $feed->init(); + + if($feed->error()) + logger('local_delivery: Error parsing XML: ' . $feed->error()); + + + // Check at the feed level for updated contact name and/or photo + + $name_updated = ''; + $new_name = ''; + $photo_timestamp = ''; + $photo_url = ''; + + + $rawtags = $feed->get_feed_tags( NAMESPACE_DFRN, 'owner'); + if(! $rawtags) + $rawtags = $feed->get_feed_tags( SIMPLEPIE_NAMESPACE_ATOM_10, 'author'); + if($rawtags) { + $elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]; + if($elems['name'][0]['attribs'][NAMESPACE_DFRN]['updated']) { + $name_updated = $elems['name'][0]['attribs'][NAMESPACE_DFRN]['updated']; + $new_name = $elems['name'][0]['data']; + } + if((x($elems,'link')) && ($elems['link'][0]['attribs']['']['rel'] === 'photo') && ($elems['link'][0]['attribs'][NAMESPACE_DFRN]['updated'])) { + $photo_timestamp = datetime_convert('UTC','UTC',$elems['link'][0]['attribs'][NAMESPACE_DFRN]['updated']); + $photo_url = $elems['link'][0]['attribs']['']['href']; + } + } + + if((is_array($contact)) && ($photo_timestamp) && (strlen($photo_url)) && ($photo_timestamp > $importer['avatar-date'])) { + logger('local_delivery: Updating photo for ' . $importer['name']); + require_once("Photo.php"); + $photo_failure = false; + $have_photo = false; + + $r = q("SELECT `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d LIMIT 1", + intval($importer['id']), + intval($importer['importer_uid']) + ); + if(count($r)) { + $resource_id = $r[0]['resource-id']; + $have_photo = true; + } + else { + $resource_id = photo_new_resource(); + } + + $img_str = fetch_url($photo_url,true); + // guess mimetype from headers or filename + $type = guess_image_type($photo_url,true); + + + $img = new Photo($img_str, $type); + if($img->is_valid()) { + if($have_photo) { + q("DELETE FROM `photo` WHERE `resource-id` = '%s' AND `contact-id` = %d AND `uid` = %d", + dbesc($resource_id), + intval($importer['id']), + intval($importer['importer_uid']) + ); + } + + $img->scaleImageSquare(175); + + $hash = $resource_id; + $r = $img->store($importer['importer_uid'], $importer['id'], $hash, basename($photo_url), 'Contact Photos', 4); + + $img->scaleImage(80); + $r = $img->store($importer['importer_uid'], $importer['id'], $hash, basename($photo_url), 'Contact Photos', 5); + + $img->scaleImage(48); + $r = $img->store($importer['importer_uid'], $importer['id'], $hash, basename($photo_url), 'Contact Photos', 6); + + $a = get_app(); + + q("UPDATE `contact` SET `avatar-date` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s' + WHERE `uid` = %d AND `id` = %d LIMIT 1", + dbesc(datetime_convert()), + dbesc($a->get_baseurl() . '/photo/' . $hash . '-4.'.$img->getExt()), + dbesc($a->get_baseurl() . '/photo/' . $hash . '-5.'.$img->getExt()), + dbesc($a->get_baseurl() . '/photo/' . $hash . '-6.'.$img->getExt()), + intval($importer['importer_uid']), + intval($importer['id']) + ); + } + } + + if((is_array($contact)) && ($name_updated) && (strlen($new_name)) && ($name_updated > $contact['name-date'])) { + $r = q("select * from contact where uid = %d and id = %d limit 1", + intval($importer['importer_uid']), + intval($importer['id']) + ); + + $x = q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1", + dbesc(notags(trim($new_name))), + dbesc(datetime_convert()), + intval($importer['importer_uid']), + intval($importer['id']) + ); + + // do our best to update the name on content items + + if(count($r)) { + q("update item set `author-name` = '%s' where `author-name` = '%s' and `author-link` = '%s' and uid = %d", + dbesc(notags(trim($new_name))), + dbesc($r[0]['name']), + dbesc($r[0]['url']), + intval($importer['importer_uid']) + ); + } + } + + /* // Currently unsupported - needs a lot of work $reloc = $feed->get_feed_tags( NAMESPACE_DFRN, 'relocate' ); @@ -2958,7 +3070,57 @@ function local_delivery($importer,$data) { $datarray['owner-avatar'] = $importer['thumb']; } - $r = item_store($datarray); + $posted_id = item_store($datarray); + + if(stristr($datarray['verb'],ACTIVITY_POKE)) { + $verb = urldecode(substr($datarray['verb'],strpos($datarray['verb'],'#')+1)); + if(! $verb) + continue; + $xo = parse_xml_string($datarray['object'],false); + + if(($xo->type == ACTIVITY_OBJ_PERSON) && ($xo->id)) { + + // somebody was poked/prodded. Was it me? + + $links = parse_xml_string("".unxmlify($xo->link)."",false); + + foreach($links->link as $l) { + $atts = $l->attributes(); + switch($atts['rel']) { + case "alternate": + $Blink = $atts['href']; + break; + default: + break; + } + } + if($Blink && link_compare($Blink,$a->get_baseurl() . '/profile/' . $importer['nickname'])) { + + // send a notification + require_once('include/enotify.php'); + + notification(array( + 'type' => NOTIFY_POKE, + 'notify_flags' => $importer['notify-flags'], + 'language' => $importer['language'], + 'to_name' => $importer['username'], + 'to_email' => $importer['email'], + 'uid' => $importer['importer_uid'], + 'item' => $datarray, + 'link' => $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $posted_id, + 'source_name' => stripslashes($datarray['author-name']), + 'source_link' => $datarray['author-link'], + 'source_photo' => ((link_compare($datarray['author-link'],$importer['url'])) + ? $importer['thumb'] : $datarray['author-avatar']), + 'verb' => $datarray['verb'], + 'otype' => 'person', + 'activity' => $verb, + + )); + } + } + } + continue; } } diff --git a/include/plugin.php b/include/plugin.php index ffa562273..8f6d6ea98 100644 --- a/include/plugin.php +++ b/include/plugin.php @@ -111,7 +111,7 @@ function reload_plugins() { if(! function_exists('register_hook')) { -function register_hook($hook,$file,$function) { +function register_hook($hook,$file,$function,$priority=0) { $r = q("SELECT * FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s' LIMIT 1", dbesc($hook), @@ -121,10 +121,11 @@ function register_hook($hook,$file,$function) { if(count($r)) return true; - $r = q("INSERT INTO `hook` (`hook`, `file`, `function`) VALUES ( '%s', '%s', '%s' ) ", + $r = q("INSERT INTO `hook` (`hook`, `file`, `function`, `priority`) VALUES ( '%s', '%s', '%s', '%s' ) ", dbesc($hook), dbesc($file), - dbesc($function) + dbesc($function), + dbesc($priority) ); return $r; }} @@ -145,7 +146,7 @@ if(! function_exists('load_hooks')) { function load_hooks() { $a = get_app(); $a->hooks = array(); - $r = q("SELECT * FROM `hook` WHERE 1"); + $r = q("SELECT * FROM `hook` WHERE 1 ORDER BY `priority` DESC"); if(count($r)) { foreach($r as $rr) { if(! array_key_exists($rr['hook'],$a->hooks)) @@ -255,6 +256,7 @@ function get_theme_info($theme){ 'author' => array(), 'maintainer' => array(), 'version' => "", + 'credits' => "", 'experimental' => false, 'unsupported' => false ); diff --git a/include/text.php b/include/text.php index 83819d095..1c50086aa 100644 --- a/include/text.php +++ b/include/text.php @@ -403,7 +403,7 @@ function load_view_file($s) { return file_get_contents("$d/$lang/$b"); $theme = current_theme(); - + if(file_exists("$d/theme/$theme/$b")) return file_get_contents("$d/theme/$theme/$b"); @@ -706,6 +706,22 @@ function linkify($s) { return($s); }} +function get_poke_verbs() { + + // index is present tense verb + // value is array containing past tense verb, translation of present, translation of past + + $arr = array( + 'poke' => array( 'poked', t('poke'), t('poked')), + 'ping' => array( 'pinged', t('ping'), t('pinged')), + 'prod' => array( 'prodded', t('prod'), t('prodded')), + 'slap' => array( 'slapped', t('slap'), t('slapped')), + 'finger' => array( 'fingered', t('finger'), t('fingered')), + 'rebuff' => array( 'rebuffed', t('rebuff'), t('rebuffed')), + ); + call_hooks('poke_verbs', $arr); + return $arr; +} /** * @@ -1562,7 +1578,7 @@ function undo_post_tagging($s) { function fix_mce_lf($s) { $s = str_replace("\r\n","\n",$s); - $s = str_replace("\n\n","\n",$s); +// $s = str_replace("\n\n","\n",$s); return $s; } diff --git a/index.php b/index.php index 61f3562b5..c9b7f34d7 100644 --- a/index.php +++ b/index.php @@ -118,6 +118,12 @@ if(! x($_SESSION,'authenticated')) $a->init_pagehead(); +/** + * Build the page ending -- this is stuff that goes right before + * the closing tag + */ + +$a->init_page_end(); if(! x($_SESSION,'sysmsg')) diff --git a/js/acl.min.js b/js/acl.min.js new file mode 100644 index 000000000..74904a02c --- /dev/null +++ b/js/acl.min.js @@ -0,0 +1 @@ +function ACL(e,t){that=this,that.url=e,that.kp_timer=null,t==undefined&&(t=[]),that.allow_cid=t[0]||[],that.allow_gid=t[1]||[],that.deny_cid=t[2]||[],that.deny_gid=t[3]||[],that.group_uids=[],that.nw=4,that.list_content=$("#acl-list-content"),that.item_tpl=unescape($(".acl-list-item[rel=acl-template]").html()),that.showall=$("#acl-showall"),t.length==0&&that.showall.addClass("selected"),that.showall.click(that.on_showall),$(".acl-button-show").live("click",that.on_button_show),$(".acl-button-hide").live("click",that.on_button_hide),$("#acl-search").keypress(that.on_search),$("#acl-wrapper").parents("form").submit(that.on_submit),that.get(0,100)}ACL.prototype.on_submit=function(){aclfileds=$("#acl-fields").html(""),$(that.allow_gid).each(function(e,t){aclfileds.append("")}),$(that.allow_cid).each(function(e,t){aclfileds.append("")}),$(that.deny_gid).each(function(e,t){aclfileds.append("")}),$(that.deny_cid).each(function(e,t){aclfileds.append("")})},ACL.prototype.search=function(){var e=$("#acl-search").val();that.list_content.html(""),that.get(0,100,e)},ACL.prototype.on_search=function(e){that.kp_timer&&clearTimeout(that.kp_timer),that.kp_timer=setTimeout(that.search,1e3)},ACL.prototype.on_showall=function(e){return e.preventDefault(),e.stopPropagation(),that.showall.hasClass("selected")?!1:(that.showall.addClass("selected"),that.allow_cid=[],that.allow_gid=[],that.deny_cid=[],that.deny_gid=[],that.update_view(),!1)},ACL.prototype.on_button_show=function(e){return e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation(),that.set_allow($(this).parent().attr("id")),!1},ACL.prototype.on_button_hide=function(e){return e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation(),that.set_deny($(this).parent().attr("id")),!1},ACL.prototype.set_allow=function(e){type=e[0],id=parseInt(e.substr(1));switch(type){case"g":that.allow_gid.indexOf(id)<0?that.allow_gid.push(id):that.allow_gid.remove(id),that.deny_gid.indexOf(id)>=0&&that.deny_gid.remove(id);break;case"c":that.allow_cid.indexOf(id)<0?that.allow_cid.push(id):that.allow_cid.remove(id),that.deny_cid.indexOf(id)>=0&&that.deny_cid.remove(id)}that.update_view()},ACL.prototype.set_deny=function(e){type=e[0],id=parseInt(e.substr(1));switch(type){case"g":that.deny_gid.indexOf(id)<0?that.deny_gid.push(id):that.deny_gid.remove(id),that.allow_gid.indexOf(id)>=0&&that.allow_gid.remove(id);break;case"c":that.deny_cid.indexOf(id)<0?that.deny_cid.push(id):that.deny_cid.remove(id),that.allow_cid.indexOf(id)>=0&&that.allow_cid.remove(id)}that.update_view()},ACL.prototype.update_view=function(){that.allow_gid.length==0&&that.allow_cid.length==0&&that.deny_gid.length==0&&that.deny_cid.length==0?(that.showall.addClass("selected"),$("#jot-perms-icon").removeClass("lock").addClass("unlock"),$("#jot-public").show(),$(".profile-jot-net input").attr("disabled",!1),typeof editor!="undefined"&&editor!=0&&$("#profile-jot-desc").html(ispublic)):(that.showall.removeClass("selected"),$("#jot-perms-icon").removeClass("unlock").addClass("lock"),$("#jot-public").hide(),$(".profile-jot-net input").attr("disabled","disabled"),$("#profile-jot-desc").html(" ")),$("#acl-list-content .acl-list-item").each(function(){$(this).removeClass("groupshow grouphide")}),$("#acl-list-content .acl-list-item").each(function(){itemid=$(this).attr("id"),type=itemid[0],id=parseInt(itemid.substr(1)),btshow=$(this).children(".acl-button-show").removeClass("selected"),bthide=$(this).children(".acl-button-hide").removeClass("selected");switch(type){case"g":var e="";that.allow_gid.indexOf(id)>=0&&(btshow.addClass("selected"),bthide.removeClass("selected"),e="groupshow"),that.deny_gid.indexOf(id)>=0&&(btshow.removeClass("selected"),bthide.addClass("selected"),e="grouphide"),$(that.group_uids[id]).each(function(t,n){e=="grouphide"&&$("#c"+n).removeClass("groupshow");if(e!=""){var r=$("#c"+n).attr("class");if(r==undefined)return!0;var i=r.indexOf("grouphide");i==-1&&$("#c"+n).addClass(e)}});break;case"c":that.allow_cid.indexOf(id)>=0&&(btshow.addClass("selected"),bthide.removeClass("selected")),that.deny_cid.indexOf(id)>=0&&(btshow.removeClass("selected"),bthide.addClass("selected"))}})},ACL.prototype.get=function(e,t,n){var r={start:e,count:t,search:n};$.ajax({type:"POST",url:that.url,data:r,dataType:"json",success:that.populate})},ACL.prototype.populate=function(e){var t=Math.ceil(e.tot/that.nw)*42;that.list_content.height(t),$(e.items).each(function(){html="
    "+that.item_tpl+"
    ",html=html.format(this.photo,this.name,this.type,this.id,"",this.network,this.link),this.uids!=undefined&&(that.group_uids[this.id]=this.uids),that.list_content.append(html)}),that.update_view()}; \ No newline at end of file diff --git a/js/ajaxupload.min.js b/js/ajaxupload.min.js new file mode 100644 index 000000000..246f2bdb2 --- /dev/null +++ b/js/ajaxupload.min.js @@ -0,0 +1,6 @@ +/** + * AJAX Upload ( http://valums.com/ajax-upload/ ) + * Copyright (c) Andris Valums + * Licensed under the MIT license ( http://valums.com/mit-license/ ) + * Thanks to Gary Haran, David Mark, Corey Burns and others for contributions. + */(function(){function log(){typeof console!="undefined"&&typeof console.log=="function"&&(Array.prototype.unshift.call(arguments,"[Ajax Upload]"),console.log(Array.prototype.join.call(arguments," ")))}function addEvent(e,t,n){if(e.addEventListener)e.addEventListener(t,n,!1);else{if(!e.attachEvent)throw new Error("not supported or DOM not loaded");e.attachEvent("on"+t,function(){n.call(e)})}}function addResizeEvent(e){var t;addEvent(window,"resize",function(){t&&clearTimeout(t),t=setTimeout(e,100)})}function getBox(e){var t,n,r,i,s=getOffset(e);return t=s.left,r=s.top,n=t+e.offsetWidth,i=r+e.offsetHeight,{left:t,right:n,top:r,bottom:i}}function addStyles(e,t){for(var n in t)t.hasOwnProperty(n)&&(e.style[n]=t[n])}function copyLayout(e,t){var n=getBox(e);addStyles(t,{position:"absolute",left:n.left+"px",top:n.top+"px",width:e.offsetWidth+"px",height:e.offsetHeight+"px"}),t.title=e.title}function fileFromPath(e){return e.replace(/.*(\/|\\)/,"")}function getExt(e){return-1!==e.indexOf(".")?e.replace(/.*[.]/,""):""}function hasClass(e,t){var n=new RegExp("\\b"+t+"\\b");return n.test(e.className)}function addClass(e,t){hasClass(e,t)||(e.className+=" "+t)}function removeClass(e,t){var n=new RegExp("\\b"+t+"\\b");e.className=e.className.replace(n,"")}function removeNode(e){e.parentNode.removeChild(e)}if(document.documentElement.getBoundingClientRect)var getOffset=function(e){var t=e.getBoundingClientRect(),n=e.ownerDocument,r=n.body,i=n.documentElement,s=i.clientTop||r.clientTop||0,o=i.clientLeft||r.clientLeft||0,u=1;if(r.getBoundingClientRect){var a=r.getBoundingClientRect();u=(a.right-a.left)/r.clientWidth}u>1&&(s=0,o=0);var f=t.top/u+(window.pageYOffset||i&&i.scrollTop/u||r.scrollTop/u)-s,l=t.left/u+(window.pageXOffset||i&&i.scrollLeft/u||r.scrollLeft/u)-o;return{top:f,left:l}};else var getOffset=function(e){var t=0,n=0;do t+=e.offsetTop||0,n+=e.offsetLeft||0,e=e.offsetParent;while(e);return{left:n,top:t}};var toElement=function(){var e=document.createElement("div");return function(t){e.innerHTML=t;var n=e.firstChild;return e.removeChild(n)}}(),getUID=function(){var e=0;return function(){return"ValumsAjaxUpload"+e++}}();window.AjaxUpload=function(e,t){this._settings={action:"upload.php",name:"userfile",data:{},autoSubmit:!0,responseType:!1,hoverClass:"hover",focusClass:"focus",disabledClass:"disabled",onChange:function(e,t){},onSubmit:function(e,t){},onComplete:function(e,t){}};for(var n in t)t.hasOwnProperty(n)&&(this._settings[n]=t[n]);e.jquery?e=e[0]:typeof e=="string"&&(/^#.*/.test(e)&&(e=e.slice(1)),e=document.getElementById(e));if(!e||e.nodeType!==1)throw new Error("Please make sure that you're passing a valid element");e.nodeName.toUpperCase()=="A"&&addEvent(e,"click",function(e){e&&e.preventDefault?e.preventDefault():window.event&&(window.event.returnValue=!1)}),this._button=e,this._input=null,this._disabled=!1,this.enable(),this._rerouteClicks()},AjaxUpload.prototype={setData:function(e){this._settings.data=e},disable:function(){addClass(this._button,this._settings.disabledClass),this._disabled=!0;var e=this._button.nodeName.toUpperCase();(e=="INPUT"||e=="BUTTON")&&this._button.setAttribute("disabled","disabled"),this._input&&(this._input.parentNode.style.visibility="hidden")},enable:function(){removeClass(this._button,this._settings.disabledClass),this._button.removeAttribute("disabled"),this._disabled=!1},_createInput:function(){var e=this,t=document.createElement("input");t.setAttribute("type","file"),t.setAttribute("name",this._settings.name),addStyles(t,{position:"absolute",right:0,margin:0,padding:0,fontSize:"480px",fontFamily:"sans-serif",cursor:"pointer"});var n=document.createElement("div");addStyles(n,{display:"block",position:"absolute",overflow:"hidden",margin:0,padding:0,opacity:0,direction:"ltr",zIndex:2147483583,cursor:"pointer"});if(n.style.opacity!=="0"){if(typeof n.filters=="undefined")throw new Error("Opacity not supported by the browser");n.style.filter="alpha(opacity=0)"}addEvent(t,"change",function(){if(!t||t.value==="")return;var n=fileFromPath(t.value);if(!1===e._settings.onChange.call(e,n,getExt(n))){e._clearInput();return}e._settings.autoSubmit&&e.submit()}),addEvent(t,"mouseover",function(){addClass(e._button,e._settings.hoverClass)}),addEvent(t,"mouseout",function(){removeClass(e._button,e._settings.hoverClass),removeClass(e._button,e._settings.focusClass),t.parentNode.style.visibility="hidden"}),addEvent(t,"focus",function(){addClass(e._button,e._settings.focusClass)}),addEvent(t,"blur",function(){removeClass(e._button,e._settings.focusClass)}),n.appendChild(t),document.body.appendChild(n),this._input=t},_clearInput:function(){if(!this._input)return;removeNode(this._input.parentNode),this._input=null,this._createInput(),removeClass(this._button,this._settings.hoverClass),removeClass(this._button,this._settings.focusClass)},_rerouteClicks:function(){var e=this;addEvent(e._button,"mouseover",function(){if(e._disabled)return;e._input||e._createInput();var t=e._input.parentNode;copyLayout(e._button,t),t.style.visibility="visible"})},_createIframe:function(){var e=getUID(),t=toElement('