Twitter embed with (tweet link) is working.
This commit is contained in:
parent
37caa6260a
commit
27d0fadcf1
|
@ -1,4 +1,4 @@
|
|||
<?
|
||||
<?php
|
||||
class LinkEmbed extends OEmbed{
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?
|
||||
<?php
|
||||
class PhotoEmbed extends OEmbed{
|
||||
public $url;
|
||||
public $width;
|
||||
|
|
|
@ -1,20 +1,10 @@
|
|||
<?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
|
||||
$xml = simplexml_load_file(PLUGIN_OEMBED_PROVIDER_XML_FILE);// 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));
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?
|
||||
<?php
|
||||
class RichEmbed extends OEmbed {
|
||||
public $html;
|
||||
public $width;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?
|
||||
<?php
|
||||
class VideoEmbed extends OEmbed {
|
||||
public $html;
|
||||
public $width;
|
||||
|
|
|
@ -1,10 +1,27 @@
|
|||
<?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);
|
||||
}
|
||||
if (!defined("PLUGIN_OEMBED_PROVIDER_XML_FILE")) {
|
||||
@define("PLUGIN_OEMBED_PROVIDER_XML_FILE", dirname(__FILE__) . '/' . "providers.xml");
|
||||
}
|
||||
?>
|
||||
|
||||
// Include all class files
|
||||
/*
|
||||
$oembed_config_class_wildcard = dirname(__FILE__) . "/*class.php";
|
||||
foreach (glob($oembed_config_class_wildcard) as $filename)
|
||||
{
|
||||
//echo "$filename<br/>\n";
|
||||
@include $filename;
|
||||
}
|
||||
*/
|
||||
require_once dirname(__FILE__) . '/' . 'Exception404.class.php';
|
||||
require_once dirname(__FILE__) . '/' . 'OEmbed.class.php';
|
||||
require_once dirname(__FILE__) . '/' . 'LinkEmbed.class.php';
|
||||
require_once dirname(__FILE__) . '/' . 'PhotoEmbed.class.php';
|
||||
require_once dirname(__FILE__) . '/' . 'RichEmbed.class.php';
|
||||
require_once dirname(__FILE__) . '/' . 'VideoEmbed.class.php';
|
||||
|
||||
require_once dirname(__FILE__) . '/' . 'EmbedProvider.class.php';
|
||||
require_once dirname(__FILE__) . '/' . 'OEmbedProvider.class.php';
|
||||
require_once dirname(__FILE__) . '/' . 'YouTubeProvider.class.php';
|
||||
|
||||
require_once dirname(__FILE__) . '/' . 'ProviderManager.class.php';
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?
|
||||
/** Testfile für die Provider Konfiguration
|
||||
/** Testfile für die Provider Konfiguration
|
||||
* @author: Grischa Brockhaus
|
||||
*/
|
||||
|
||||
|
|
|
@ -11,7 +11,9 @@ if (file_exists($probelang)) {
|
|||
}
|
||||
|
||||
include dirname(__FILE__) . '/lang_en.inc.php';
|
||||
|
||||
include_once dirname(__FILE__) . '/oembed/config.php'; // autoload oembed classes
|
||||
|
||||
|
||||
class serendipity_event_oembed extends serendipity_event
|
||||
{
|
||||
var $title = PLUGIN_EVENT_OEMBED_NAME;
|
||||
|
@ -32,7 +34,9 @@ class serendipity_event_oembed extends serendipity_event
|
|||
));
|
||||
$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).
|
||||
// 'backend_publish' => true, // An entry was puplished (was draft before or saved from the scratch).
|
||||
// 'backend_save' => true, // An entry was saved.
|
||||
'frontend_display' => true,
|
||||
));
|
||||
|
||||
//$propbag->add('configuration', array('max_items','ext_vis_stat','stat_all','banned_bots'));
|
||||
|
@ -44,13 +48,29 @@ class serendipity_event_oembed extends serendipity_event
|
|||
|
||||
function event_hook($event, &$bag, &$eventData) {
|
||||
global $serendipity;
|
||||
|
||||
|
||||
static $simplePatterns = null;
|
||||
|
||||
if ($simplePatterns==null) {
|
||||
$simplePatterns = array(
|
||||
//'simpleTweet' => '@\(tweet\s+(\S*)\)@Usi',
|
||||
'simpleTweet' => '@\(tweet\s+(.*)\)@Usi',
|
||||
);
|
||||
}
|
||||
|
||||
$hooks = &$bag->get('event_hooks');
|
||||
|
||||
if (isset($hooks[$event])) {
|
||||
switch($event) {
|
||||
case 'frontend_display':
|
||||
case 'backend_publish':
|
||||
$this->update_entry($eventData);
|
||||
case 'backend_save':
|
||||
if (!isset($eventData['body']) && !isset($eventData['extended'])) {
|
||||
// Do not use for user comments, html nuggets, static pages etc.
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
$this->update_entry($eventData, $simplePatterns);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -59,8 +79,34 @@ class serendipity_event_oembed extends serendipity_event
|
|||
|
||||
}
|
||||
|
||||
function update_entry($eventData) {
|
||||
|
||||
function update_entry(&$eventData, &$patterns) {
|
||||
if (!empty($eventData['body'])) {
|
||||
$eventData['body'] = preg_replace_callback(
|
||||
$patterns['simpleTweet'],
|
||||
array( $this, "oembedRewriteCallback"),
|
||||
$eventData['body']);
|
||||
}
|
||||
/*
|
||||
if (!empty($eventData['extended'])) {
|
||||
$eventData['extended'] = preg_replace_callback(
|
||||
$patterns['simpleTweet'],
|
||||
array( $this, "oembedRewriteCallback"),
|
||||
$eventData['extended']);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
function oembedRewriteCallback($match) {
|
||||
$url = $match[1];
|
||||
//$url = "http://www.flickr.com/photos/gbrockhaus/2052855443/in/set-72157603214268227/";
|
||||
//print "<br/><b>callback</b><br/>";
|
||||
print_r($match[1]);
|
||||
$manager = ProviderManager::getInstance();
|
||||
$obj=$manager->provide($url,"object");
|
||||
if (!empty($obj)) {
|
||||
if ($obj->type == 'rich') return $obj->html;
|
||||
}
|
||||
return $match[0];
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue