From 306036c62613fd849a80c83c50cd220f75e64c90 Mon Sep 17 00:00:00 2001 From: Fabio Comuni Date: Mon, 24 Oct 2011 13:02:38 +0200 Subject: cache api --- boot.php | 1 + include/cache.php | 29 +++++++++++++++++++++++++++++ include/oembed.php | 16 ++++++---------- include/poller.php | 3 +-- 4 files changed, 37 insertions(+), 12 deletions(-) create mode 100644 include/cache.php diff --git a/boot.php b/boot.php index 017e21814..9623b4b14 100644 --- a/boot.php +++ b/boot.php @@ -6,6 +6,7 @@ require_once('include/plugin.php'); require_once('include/text.php'); require_once("include/pgettext.php"); require_once('include/nav.php'); +require_once('include/cache.php'); define ( 'FRIENDIKA_PLATFORM', 'Free Friendika'); define ( 'FRIENDIKA_VERSION', '2.3.1140' ); diff --git a/include/cache.php b/include/cache.php new file mode 100644 index 000000000..082974c61 --- /dev/null +++ b/include/cache.php @@ -0,0 +1,29 @@ + + + diff --git a/include/poller.php b/include/poller.php index cef0647b5..a19f0716f 100644 --- a/include/poller.php +++ b/include/poller.php @@ -64,8 +64,7 @@ function poller_run($argv, $argc){ } // clear old cache - q("DELETE FROM `cache` WHERE `updated` < '%s'", - dbesc(datetime_convert('UTC','UTC',"now - 30 days"))); + Cache::clear(); $manual_id = 0; $generation = 0; -- cgit v1.2.3 From a9fb8e4d6052dbb5db95939128d491897b4f6a0c Mon Sep 17 00:00:00 2001 From: Fabio Comuni Date: Mon, 24 Oct 2011 14:30:11 +0200 Subject: Use oembed for bookmark, audio, video, youtube --- include/bbcode.php | 41 ++++++++++++++++++++++++++++++++++++----- mod/item.php | 1 - 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/include/bbcode.php b/include/bbcode.php index b33be686e..81f37ca04 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -9,6 +9,22 @@ function stripcode_br_cb($s) { return '[code]' . str_replace('
', '', $s[1]) . '[/code]'; } +function tryoembed($match){ + $url = ((count($match)==2)?$match[1]:$match[2]); + + $o = oembed_fetch_url($url); + + //echo "
"; var_dump($match, $url, $o); killme();
+
+	if ($o->type=="error") return $match[0];
+	
+	$html = oembed_format_object($o);
+	
+	return $html;
+	
+}
+
+
 
 	// BBcode 2 HTML was written by WAY2WEB.net
 	// extended to work with Mistpark/Friendika - Mike Macgirvin
@@ -40,11 +56,14 @@ function bbcode($Text,$preserve_nl = false) {
 	// Set up the parameters for a MAIL search string
 	$MAILSearchString = $URLSearchString;
 
-	// Perform URL Search
-
 
+	// Perform URL Search
 	$Text = preg_replace("/([^\]\=]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1$2', $Text);
+	
+	$Text = preg_replace_callback("/\[bookmark\=([^\]]*)\].*?\[\/bookmark\]/ism",'tryoembed',$Text);
+	$Text = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",'[url=$1]$2[/url]',$Text);
 
+	$Text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism",'tryoembed',$Text);
 	$Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/ism", '$1', $Text);
 	$Text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$2', $Text);
 	//$Text = preg_replace("/\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[\/url\]/ism", '$2', $Text);
@@ -120,6 +139,13 @@ function bbcode($Text,$preserve_nl = false) {
 	// [img]pathtoimage[/img]
 	$Text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '' . t('Image/photo') . '', $Text);
 
+
+
+	// Try to Oembed
+	$Text = preg_replace_callback("/\[video\](.*?)\[\/video\]/ism", 'tryoembed', $Text);
+	$Text = preg_replace_callback("/\[audio\](.*?)\[\/audio\]/ism", 'tryoembed', $Text);
+
+
 	// html5 video and audio
 
 	$Text = preg_replace("/\[video\](.*?)\[\/video\]/ism", '', $Text);
@@ -129,17 +155,22 @@ function bbcode($Text,$preserve_nl = false) {
 	$Text = preg_replace("/\[iframe\](.*?)\[\/iframe\]/ism", '', $Text);
          
 
-	if (get_pconfig(local_user(), 'oembed', 'use_for_youtube' )==1){
+	/*if (get_pconfig(local_user(), 'oembed', 'use_for_youtube' )==1){
 		// use oembed for youtube links
 		$Text = preg_replace("/\[youtube\]/",'[embed]',$Text); 
 		$Text = preg_replace("/\[\/youtube\]/",'[/embed]',$Text); 
-	} else {
+	} else {*/
 		// Youtube extensions
+        $Text = preg_replace_callback("/\[youtube\](https?:\/\/www.youtube.com\/watch\?v\=.*?)\[\/youtube\]/ism", 'tryoembed', $Text);        
+        $Text = preg_replace_callback("/\[youtube\](https?:\/\/youtu.be\/.*?)\[\/youtube\]/ism",'tryoembed',$Text); 
+        
         $Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/watch\?v\=(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text); 
         $Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/embed\/(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text); 
         $Text = preg_replace("/\[youtube\]https?:\/\/youtu.be\/(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text); 
+		
+        
 		$Text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", '', $Text);
-	}
+	//}
 
 	$Text = preg_replace("/\[vimeo\]https?:\/\/player.vimeo.com\/video\/([0-9]+)(.*?)\[\/vimeo\]/ism",'[vimeo]$1[/vimeo]',$Text); 
 	$Text = preg_replace("/\[vimeo\]https?:\/\/vimeo.com\/([0-9]+)(.*?)\[\/vimeo\]/ism",'[vimeo]$1[/vimeo]',$Text); 
diff --git a/mod/item.php b/mod/item.php
index ab104735b..0e855d54d 100644
--- a/mod/item.php
+++ b/mod/item.php
@@ -338,7 +338,6 @@ function item_post(&$a) {
 	$bookmark = 0;
 	if(preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",$body,$match)) {
 		$bookmark = 1;
-		$body = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",'[url=$1]$2[/url]',$body);
 	}
 
 
-- 
cgit v1.2.3


From ac474cf53c28d8fc05eacb1d9076f8c88f1f69ae Mon Sep 17 00:00:00 2001
From: Fabio Comuni 
Date: Mon, 24 Oct 2011 14:39:39 +0200
Subject: try to use oembed on vimeo tag

---
 include/bbcode.php | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/bbcode.php b/include/bbcode.php
index 81f37ca04..7045f196f 100644
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -172,6 +172,9 @@ function bbcode($Text,$preserve_nl = false) {
 		$Text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", '', $Text);
 	//}
 
+	$Text = preg_replace_callback("/\[vimeo\]https?:\/\/player.vimeo.com\/video\/([0-9]+)(.*?)\[\/vimeo\]/ism",'tryoembed',$Text); 
+	$Text = preg_replace_callback("/\[vimeo\]https?:\/\/vimeo.com\/([0-9]+)(.*?)\[\/vimeo\]/ism",'tryoembed',$Text); 
+
 	$Text = preg_replace("/\[vimeo\]https?:\/\/player.vimeo.com\/video\/([0-9]+)(.*?)\[\/vimeo\]/ism",'[vimeo]$1[/vimeo]',$Text); 
 	$Text = preg_replace("/\[vimeo\]https?:\/\/vimeo.com\/([0-9]+)(.*?)\[\/vimeo\]/ism",'[vimeo]$1[/vimeo]',$Text); 
 	$Text = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism", '', $Text);
-- 
cgit v1.2.3


From 718a9009be697ab8873a9ca41571f1d9701c97e7 Mon Sep 17 00:00:00 2001
From: Fabio Comuni 
Date: Mon, 24 Oct 2011 17:27:38 +0200
Subject: new icon "play"

---
 images/icons/10/play.png | Bin 0 -> 420 bytes
 images/icons/16/play.png | Bin 0 -> 508 bytes
 images/icons/22/play.png | Bin 0 -> 601 bytes
 images/icons/48/play.png | Bin 0 -> 1017 bytes
 images/icons/Makefile    |   3 ++-
 images/icons/play.png    | Bin 0 -> 6285 bytes
 6 files changed, 2 insertions(+), 1 deletion(-)
 create mode 100644 images/icons/10/play.png
 create mode 100644 images/icons/16/play.png
 create mode 100644 images/icons/22/play.png
 create mode 100644 images/icons/48/play.png
 create mode 100644 images/icons/play.png

diff --git a/images/icons/10/play.png b/images/icons/10/play.png
new file mode 100644
index 000000000..a9f99e4d1
Binary files /dev/null and b/images/icons/10/play.png differ
diff --git a/images/icons/16/play.png b/images/icons/16/play.png
new file mode 100644
index 000000000..19ad05bf2
Binary files /dev/null and b/images/icons/16/play.png differ
diff --git a/images/icons/22/play.png b/images/icons/22/play.png
new file mode 100644
index 000000000..a7a8b6124
Binary files /dev/null and b/images/icons/22/play.png differ
diff --git a/images/icons/48/play.png b/images/icons/48/play.png
new file mode 100644
index 000000000..fce589370
Binary files /dev/null and b/images/icons/48/play.png differ
diff --git a/images/icons/Makefile b/images/icons/Makefile
index 39428d154..6a96fb676 100644
--- a/images/icons/Makefile
+++ b/images/icons/Makefile
@@ -1,7 +1,8 @@
 
 IMAGES=add.png edit.png	gear.png info.png menu.png \
 		notify_off.png star.png  delete.png feed.png group.png \
-		lock.png notice.png notify_on.png user.png link.png
+		lock.png notice.png notify_on.png user.png link.png \
+		play.png
 
 DESTS=10/ 16/ 22/ 48/ \
 		$(addprefix 10/, $(IMAGES)) \
diff --git a/images/icons/play.png b/images/icons/play.png
new file mode 100644
index 000000000..7c942072e
Binary files /dev/null and b/images/icons/play.png differ
-- 
cgit v1.2.3


From 75d4f332335e66375815b339526252e8ab34be32 Mon Sep 17 00:00:00 2001
From: Fabio Comuni 
Date: Mon, 24 Oct 2011 17:28:28 +0200
Subject: move html for oembeded videos in template. fix oembed discovery

---
 include/oembed.php    | 38 ++++++++++++++++++++++----------------
 view/oembed_video.tpl |  4 ++++
 2 files changed, 26 insertions(+), 16 deletions(-)
 create mode 100644 view/oembed_video.tpl

diff --git a/include/oembed.php b/include/oembed.php
index d40ceb3fd..2933252b3 100644
--- a/include/oembed.php
+++ b/include/oembed.php
@@ -7,7 +7,7 @@ function oembed_replacecb($matches){
 
 
 function oembed_fetch_url($embedurl){
-
+	
 	$txt = Cache::get($embedurl);
 				
 	if(is_null($txt)){
@@ -16,18 +16,18 @@ function oembed_fetch_url($embedurl){
 		// try oembed autodiscovery
 		$redirects = 0;
 		$html_text = fetch_url($embedurl, false, $redirects, 15);
-		if(! $html_text)
-			return;
-		$dom = @DOMDocument::loadHTML($html_text);
-		if ($dom){
-			$xpath = new DOMXPath($dom);
-			$attr = "oembed";
-		
-			$xattr = oe_build_xpath("class","oembed");
-			$entries = $xpath->query("//link[@type='application/json+oembed']");
-			foreach($entries as $e){
-				$href = $e->getAttributeNode("href")->nodeValue;
-				$txt = fetch_url($href);
+		if($html_text){
+			$dom = @DOMDocument::loadHTML($html_text);
+			if ($dom){
+				$xpath = new DOMXPath($dom);
+				$attr = "oembed";
+			
+				$xattr = oe_build_xpath("class","oembed");
+				$entries = $xpath->query("//link[@type='application/json+oembed']");
+				foreach($entries as $e){
+					$href = $e->getAttributeNode("href")->nodeValue;
+					$txt = fetch_url($href);
+				}
 			}
 		}
 		
@@ -59,9 +59,15 @@ function oembed_format_object($j){
 				/*$tw = (isset($j->thumbnail_width)) ? $j->thumbnail_width:200;
 				$th = (isset($j->thumbnail_height)) ? $j->thumbnail_height:180;*/
 				$tw=150; $th=120; 
-				$ret.= "";
-				$ret.= "";
-				$ret.= "";
+				$tpl=get_markup_template('oembed_video.tpl');
+				$ret.=replace_macros($tpl, array(
+					'$embedurl'=>$embedurl,
+					'$escapedhtml'=>urlencode($j->html),
+					'$tw'=>$tw,
+					'$th'=>$th,
+					'$turl'=>$j->thumbnail_url,
+				));
+				
 			} else {
 				$ret=$j->html;
 			}
diff --git a/view/oembed_video.tpl b/view/oembed_video.tpl
new file mode 100644
index 000000000..29b5149ba
--- /dev/null
+++ b/view/oembed_video.tpl
@@ -0,0 +1,4 @@
+
+	
+	
+
-- cgit v1.2.3 From 40ea48bdabb5b7b8c87cd3c37e12c0c24eb91014 Mon Sep 17 00:00:00 2001 From: Fabio Comuni Date: Mon, 24 Oct 2011 17:28:48 +0200 Subject: fix vimeo oembed bbcode regexp --- include/bbcode.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/bbcode.php b/include/bbcode.php index 7045f196f..a8c66d30f 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -172,8 +172,8 @@ function bbcode($Text,$preserve_nl = false) { $Text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", '', $Text); //} - $Text = preg_replace_callback("/\[vimeo\]https?:\/\/player.vimeo.com\/video\/([0-9]+)(.*?)\[\/vimeo\]/ism",'tryoembed',$Text); - $Text = preg_replace_callback("/\[vimeo\]https?:\/\/vimeo.com\/([0-9]+)(.*?)\[\/vimeo\]/ism",'tryoembed',$Text); + $Text = preg_replace_callback("/\[vimeo\](https?:\/\/player.vimeo.com\/video\/[0-9]+).*?\[\/vimeo\]/ism",'tryoembed',$Text); + $Text = preg_replace_callback("/\[vimeo\](https?:\/\/vimeo.com\/[0-9]+).*?\[\/vimeo\]/ism",'tryoembed',$Text); $Text = preg_replace("/\[vimeo\]https?:\/\/player.vimeo.com\/video\/([0-9]+)(.*?)\[\/vimeo\]/ism",'[vimeo]$1[/vimeo]',$Text); $Text = preg_replace("/\[vimeo\]https?:\/\/vimeo.com\/([0-9]+)(.*?)\[\/vimeo\]/ism",'[vimeo]$1[/vimeo]',$Text); -- cgit v1.2.3 From 2905df527f2fbc9b426ebc89a53adc5c6cf1ee47 Mon Sep 17 00:00:00 2001 From: Fabio Comuni Date: Mon, 24 Oct 2011 17:31:14 +0200 Subject: fix oembed video thumb display ratio --- include/oembed.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/include/oembed.php b/include/oembed.php index 2933252b3..924e61289 100644 --- a/include/oembed.php +++ b/include/oembed.php @@ -56,9 +56,11 @@ function oembed_format_object($j){ switch ($j->type) { case "video": { if (isset($j->thumbnail_url)) { - /*$tw = (isset($j->thumbnail_width)) ? $j->thumbnail_width:200; - $th = (isset($j->thumbnail_height)) ? $j->thumbnail_height:180;*/ - $tw=150; $th=120; + $tw = (isset($j->thumbnail_width)) ? $j->thumbnail_width:200; + $th = (isset($j->thumbnail_height)) ? $j->thumbnail_height:180; + $tr = $tw/$th; + + $th=120; $tw = $th*$tr; $tpl=get_markup_template('oembed_video.tpl'); $ret.=replace_macros($tpl, array( '$embedurl'=>$embedurl, -- cgit v1.2.3