Wrong Checkin redone

This commit is contained in:
Grischa Brockhaus 2011-12-14 03:22:37 +01:00
parent 97ce51559c
commit e83110a795
19 changed files with 0 additions and 447 deletions

View file

@ -1,9 +0,0 @@
<?php # $Id: lang_en.inc.php,v 1.1 2006/08/16 04:49:12 elf2000 Exp $
/**
* @version $Revision: 1.1 $
* @author Translator Name <yourmail@example.com>
* EN-Revision: Revision of lang_en.inc.php
*/
@define('PLUGIN_EVENT_OEMBED_NAME', 'oEmbed Plugin');

View file

@ -1,10 +0,0 @@
<?php # $Id: lang_en.inc.php,v 1.1 2006/08/16 04:49:12 elf2000 Exp $
/**
* @version $Revision: 1.1 $
* @author Translator Name <yourmail@example.com>
* EN-Revision: Revision of lang_en.inc.php
*/
@define('PLUGIN_EVENT_OEMBED_NAME', 'oEmbed Plugin');
@define('PLUGIN_EVENT_OEMBED_DESC', 'oEmbed is a format for allowing an embedded representation of a URL on your blog. It allows blog articles to display embedded content (such as tweets, photos or videos) when a user posts a link to that resource, without having to parse the resource directly.');

View file

@ -1,12 +0,0 @@
<?php
abstract class EmbedProvider {
public $url;
public $endpoint;
public abstract function match($url);
public abstract function provide($url,$format="json");
// public abstract function register();
public function __construct($url,$endpoint){
$this->url = $url;
$this->endpoint = $endpoint;
}
}

View file

@ -1,3 +0,0 @@
<?php
class Exception404 extends Exception{
}

View file

@ -1,4 +0,0 @@
<?
class LinkEmbed extends OEmbed{
}

View file

@ -1,23 +0,0 @@
<?php
abstract class OEmbed{// extends LazyTemplateEngine{
public $type;
public $version;
public $title;
public $author_name;
public $author_url;
public $provider_name;
public $provider_url;
public $cache_age;
public $description; // added by me, not part of OEmbed
public $resource_url; // added by me, not part of OEmbed
public $thumbnail_url;
public $thumbnail_width;
public $thumbnail_height;
public function cloneObj($object){
foreach($object as $key=>$value){
$this->$key=(string)$value;
}
}
}

View file

@ -1,74 +0,0 @@
<?php
class OEmbedProvider extends EmbedProvider{
private $urlRegExp;
private $jsonEndpoint;
private $xmlEndpoint;
public function __construct($url,$endpoint){
parent::__construct($url,$endpoint);
$this->urlRegExp=preg_replace(array("/\*/","/\//","/\.\*\./"),array(".*","\/",".*"),$url);
$this->urlRegExp="/".$this->urlRegExp."/";
if (preg_match("/\{format\}/",$endpoint)){
$this->jsonEndpoint=preg_replace("/\{format\}/","json",$endpoint);
$this->jsonEndpoint.="?url={url}";
$this->xmlEndpoint=preg_replace("/\{format\}/","xml",$endpoint);
$this->xmlEndpoint.="?url={url}";
} else {
$this->jsonEndpoint=$endpoint."?url={url}&format=json";
$this->xmlEndpoint=$endpoint."?url={url}&format=xml";
}
}
public function getUrlRegExp(){ return $this->urlRegExp; }
public function getJsonEndpoint(){ return $this->jsonEndpoint; }
public function getXmlEndpoint(){ return $this->xmlEndpoint; }
public function match($url){
return preg_match($this->urlRegExp,$url);
}
private function provideXML($url){
return file_get_contents(preg_replace("/\{url\}/",urlencode($url),$this->xmlEndpoint));
}
private function getTypeObj($type){
switch($type){
case "photo":
return new PhotoEmbed();
break;
case "video":
return new VideoEmbed();
break;
case "link":
return new LinkEmbed();
break;
case "rich":
return new RichEmbed();
break;
default:
return new OEmbed();
}
}
private function provideObject($url){
$xml=simplexml_load_string($this->provideXML($url));
//TODO $xml->type alapjan assigner
$obj = $this->getTypeObj((string)$xml->type);
$obj->cloneObj($xml);
$obj->resource_url=$url;
return $obj;
}
private function provideSerialized($url){
$serialized=serialize($this->provideObject($url));
return $serialized;
}
public function provide($url,$format="json"){
if($format=="xml"){
return $this->provideXML($url);
} else if ($format=="object"){
return $this->provideObject($url);
} else if ($format=="serialized"){
return $this->provideSerialized($url);
} else {
return file_get_contents(preg_replace("/\{url\}/",urlencode($url),$this->jsonEndpoint));
}
}
public function register(){}
}

View file

@ -1,6 +0,0 @@
<?
class PhotoEmbed extends OEmbed{
public $url;
public $width;
public $height;
}

View file

@ -1,45 +0,0 @@
<?php
/*
* PHP OEmbed provider/proxy - for details, visit
*
* http://code.google.com/p/php-oembed/
*
* Copyright(C) by Adam Nemeth. Licensed under New BSD license.
*
* I would love to hear every feedback on aadaam at googlesmailservice
*
*/
class ProviderManager{
private $providers;
private static $_instance;
private function __construct(){
$this->providers=array();
$xml = simplexml_load_file(PROVIDER_XML);// PROVIDER_XML comes from config.php
foreach($xml->provider as $provider){
if(!isset($provider->class) && isset($provider->endpoint)){
$this->register(new OEmbedProvider($provider->url,$provider->endpoint));
} else {
$classname="".$provider->class; // force to be string :)
$reflection = new ReflectionClass($classname);
$this->register($reflection->newInstance($provider));//so we could pass config vars
}
}
}
static function getInstance(){
if(!isset($_instance) || $_instance==null){
$_instance = new ProviderManager();
}
return $_instance;
}
public function register($provider){
$this->providers[]=$provider;
}
public function provide($url,$format){
foreach ($this->providers as $provider){
if ($provider->match($url)){
return $provider->provide($url,$format);
}
}
return null;
}
}

View file

@ -1,6 +0,0 @@
<?
class RichEmbed extends OEmbed {
public $html;
public $width;
public $height;
}

View file

@ -1,7 +0,0 @@
<?
class VideoEmbed extends OEmbed {
public $html;
public $width;
public $height;
public $duration; // added by me, not part of OEmbed
}

View file

@ -1,80 +0,0 @@
<?php
class YouTubeProvider extends EmbedProvider {
public function match($url){
return preg_match('/youtube.com\/watch\?v=([\w-]+)/',$url) || preg_match('/youtu.be\/([\w-]+)/',$url); // http://youtu.be/8UVNT4wvIGY
}
public function getEmbed($url){
$urlArray=array();
if(preg_match("/(www.)?youtube.com\/watch\?v=([\w-]+)/",$url,$matches)){
$video_id=$matches[2];
}
else if(preg_match("/(www.)?youtu.be\/([\w-]+)/",$url,$matches)){
$video_id=$matches[2];
}
$myEmbed = new VideoEmbed();
$myEmbed->type='video';
$myEmbed->version='1.0';
$myEmbed->provider_name="Youtube";
$myEmbed->provider_url="http://youtube.com";
$myEmbed->resource_url=$url;
$xml = new DOMDocument;
if(@($xml->load('http://gdata.youtube.com/feeds/api/videos/'.$video_id))) {
@$guid = $xml->getElementsByTagName("guid")->item(0)->nodeValue;
$link = str_replace("http://www.youtube.com/watch?v=","http://bergengocia.net/indavideobombyoutubemashup/view.php?id=",$guid);
$myEmbed->title =$xml->getElementsByTagName("title")->item(0)->nodeValue;
$myEmbed->description =$xml->getElementsByTagNameNS("*","description")->item(0)->nodeValue;
$myEmbed->author_name =$xml->getElementsByTagName("author")->item(0)->getElementsByTagName("name")->item(0)->nodeValue;
$myEmbed->author_url =$xml->getElementsByTagName("author")->item(0)->getElementsByTagName("uri")->item(0)->nodeValue;
$myEmbed->thumbnail_url =$xml->getElementsByTagNameNS("*","thumbnail")->item(0)->getAttribute("url");
$myEmbed->thumbnail_width =$xml->getElementsByTagNameNS("*","thumbnail")->item(0)->getAttribute("width");
$myEmbed->thumbnail_height =$xml->getElementsByTagNameNS("*","thumbnail")->item(0)->getAttribute("height");
$med_content_url=$xml->getElementsByTagNameNS("http://search.yahoo.com/mrss/","content")->item(0)->getAttribute("url");
$myEmbed->html=
'<object width="425" height="350">'."\n".
' <param name="movie" value="'.$med_content_url.'"></param>'."\n".
' <embed src="'.$med_content_url.'"'.
' type="application/x-shockwave-flash" width="425" height="350">'."\n".
' </embed>'."\n".
'</object>'; // according to http://code.google.com/apis/youtube/developers_guide_protocol.html#Displaying_information_about_a_video
$myEmbed->width="425";
$myEmbed->height="350"; // same as in the html
//$myEmbed->duration=$xml->getElementsByTagNameNS($xml->lookupNamespaceURI("*"),"content")->item(0)->getAttribute("duration");
//$time = floor($duration / 60) . ":" . $duration % 60;
return $myEmbed;
} else throw new Exception404("xxx");
}
private function provideXML($url){
$string="";
foreach($this->getEmbed($url) as $key=>$value){
if(isset($value)&& $value!="") $string.=" <".$key.">".$value."</".$key.">\n";
}
$string="<oembed>\n".$string."</oembed>";
return $string;
}
private function provideObject($url){
return $this->getEmbed($url);
}
private function provideJSON($url){
return json_encode($this->getEmbed($url));
}
private function provideSerialized($url){
return serialize($this->getEmbed($url));
}
public function provide($url,$format="json"){
if($format=="xml"){
return $this->provideXML($url);
} else if ($format=="object"){
return $this->provideObject($url);
} else if ($format=="serialized"){
return $this->provideSerialized($url);
} else {
return $this->provideJSON($url);;
}
}
public function __construct($config){
parent::__construct("http://youtube.com","");
}
}

View file

@ -1,10 +0,0 @@
<?php
define("PROVIDER_XML", dirname(__FILE__) . '/' . "providers.xml");
define("TEMPLATE_PATH", dirname(__FILE__) . '/' . "templates/");
function __autoload($classname){
if(file_exists($x=dirname(__FILE__) . '/' .$classname.".class.php")) {
require_once($x);
}
}
?>

View file

@ -1,24 +0,0 @@
<?xml version="1.0"?>
<providers>
<provider>
<url>http://*.flickr.com/*</url>
<endpoint>http://www.flickr.com/services/oembed/</endpoint>
</provider>
<provider>
<url>http://*.pownce.com/*</url>
<endpoint>http://api.pownce.com/2.1/oembed.{format}</endpoint>
</provider>
<provider>
<url>https://*.twitter.com/*</url>
<endpoint>https://api.twitter.com/1/statuses/oembed.{format}</endpoint>
</provider>
<provider>
<url>http://*.vimeo.com/*</url>
<endpoint>http://vimeo.com/api/oembed.{format}</endpoint>
</provider>
<provider>
<url>http://*.youtube.*/*</url>
<class>YouTubeProvider</class>
</provider>
</providers>

View file

@ -1,24 +0,0 @@
<?
/*
* PHP OEmbed provider/proxy - for details, visit
*
* http://code.google.com/p/php-oembed/
*
* Copyright(C) by Adam Nemeth. Licensed under New BSD license.
*
* I would love to hear every feedback on aadaam at googlesmailservice
*
*/
require_once(dirname(__FILE__) . '/../' . "config.php");
$xml = simplexml_load_file(dirname(__FILE__) . '/../' . "providers.xml");
foreach($xml->provider as $provider){
// $x = new OEmbedProvider("http://*.flickr.com/*","http://www.flickr.com/services/oembed/");
$x = new OEmbedProvider($provider->url,$provider->endpoint);
echo $x->url.":\n";
if ($x->match("http://www.flickr.com/photos/bees/2341623661/")){
print_r($x->provide("http://www.flickr.com/photos/bees/2341623661/","object"));
}
echo " ".$x->getUrlRegExp()."\n";
echo " ".$x->getJsonEndpoint()."\n";
echo " ".$x->getXmlEndpoint()."\n";
}

View file

@ -1,24 +0,0 @@
<?
/** Testfile für die Provider Konfiguration
* @author: Grischa Brockhaus
*/
require_once(dirname(__FILE__) . '/../' . "config.php");
function test($manager, $url) {
$obj=$manager->provide($url,"object");
if (!empty($obj)) print_r($obj);
}
$manager = ProviderManager::getInstance();
// Youtube long link
test($manager,"http://www.youtube.com/watch?v=8UVNT4wvIGY");
// Youtube Kurze URL
test($manager,"http://youtu.be/8UVNT4wvIGY");
// Twitter
test($manager,"https://twitter.com/#!/tagesschau/status/146562892454572032");
// flickr
test($manager,"http://www.flickr.com/photos/gbrockhaus/2052855443/in/set-72157603214268227/");
// vimeo
test($manager,"http://vimeo.com/33510073");

View file

@ -1,8 +0,0 @@
<?php
$xml = simplexml_load_file(dirname(__FILE__) . '/../' . "providers.xml");
foreach($xml->provider as $provider){
echo $provider->url;
echo $provider->endpoint;
}

View file

@ -1,12 +0,0 @@
<?
require_once(dirname(__FILE__) . '/../' . "config.php");
function testYoutubeProvider() {
$x = new YouTubeProvider('');
$obj = $x->provide("","object");
//print_r($obj);
print_r($obj->html);
}
testYoutubeProvider();

View file

@ -1,66 +0,0 @@
<?php
if (IN_serendipity !== true) {
die ("Don't hack!");
}
// Probe for a language include with constants. Still include defines later on, if some constants were missing
$probelang = dirname(__FILE__) . '/' . $serendipity['charset'] . 'lang_' . $serendipity['lang'] . '.inc.php';
if (file_exists($probelang)) {
include $probelang;
}
include dirname(__FILE__) . '/lang_en.inc.php';
class serendipity_event_oembed extends serendipity_event
{
var $title = PLUGIN_EVENT_OEMBED_NAME;
function introspect(&$propbag)
{
global $serendipity;
$propbag->add('name', PLUGIN_EVENT_OEMBED_NAME);
$propbag->add('description', PLUGIN_EVENT_OEMBED_DESC);
$propbag->add('stackable', false);
$propbag->add('author', 'Grischa Brockhaus');
$propbag->add('version', '0.01');
$propbag->add('requirements', array(
'serendipity' => '0.8',
'smarty' => '2.6.7',
'php' => '5.1.0'
));
$propbag->add('groups', array('FRONTEND_EXTERNAL_SERVICES'));
$propbag->add('event_hooks', array(
'backend_publish' => true, // An entry was puplished (was draft before or saved from the scratch).
));
//$propbag->add('configuration', array('max_items','ext_vis_stat','stat_all','banned_bots'));
}
function introspect_config_item($name, &$propbag)
{
}
function event_hook($event, &$bag, &$eventData) {
global $serendipity;
$hooks = &$bag->get('event_hooks');
if (isset($hooks[$event])) {
switch($event) {
case 'backend_publish':
$this->update_entry($eventData);
return true;
}
}
return true;
}
function update_entry($eventData) {
}
}