-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
skywalker512
committed
Jul 8, 2018
1 parent
c7547bf
commit f1dc0cd
Showing
5 changed files
with
231 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
## esoTalk – AutoLink plugin | ||
|
||
- When you post an URL, AutoLinks automatically embeds images, MP3 and videos. | ||
- Currently supported are: | ||
* images | ||
* mp3 | ||
* Youtube | ||
* Google Video | ||
* Facebook Video | ||
* Vimeo | ||
* Metacafe | ||
* Dailymotion | ||
* Myspace | ||
* SPIKE | ||
* Redlasso | ||
* OnSMASH | ||
* Tangle.com | ||
* LiveLeak | ||
|
||
|
||
### Installation | ||
|
||
Browse to your esoTalk plugin directory: | ||
``` | ||
cd WEB_ROOT_DIR/addons/plugins/ | ||
``` | ||
|
||
Clone the AutoLink plugin repo into the plugin directory: | ||
``` | ||
git clone [email protected]:esoTalk-plugins/AutoLink.git AutoLink | ||
``` | ||
|
||
Chown the AutoLink plugin folder to the right web user: | ||
``` | ||
chown -R apache:apache AutoLink/ | ||
``` | ||
|
||
Replace the `public function format()` code in **./core/libs/ETFormat.class.php**: | ||
```php | ||
public function format() | ||
{ | ||
// Trigger the "before format" event, which can be used to strip out code blocks. | ||
$this->trigger("beforeFormat"); | ||
|
||
// Format links, mentions, and quotes. | ||
if (C("esoTalk.format.mentions")) $this->mentions(); | ||
if (!$this->inline) $this->quotes(); | ||
$this->links(); | ||
|
||
// Format bullet and numbered lists. | ||
if (!$this->inline) $this->lists(); | ||
|
||
// Trigger the "format" event, where all regular formatting can be applied (bold, italic, etc.) | ||
$this->trigger("format"); | ||
|
||
// Format whitespace, adding in <br/> and <p> tags. | ||
if (!$this->inline) $this->whitespace(); | ||
|
||
// Trigger the "after format" event, where code blocks can be put back in. | ||
$this->trigger("afterFormat"); | ||
|
||
return $this; | ||
} | ||
``` | ||
|
||
with the following code: | ||
```php | ||
public function format($sticky = false) | ||
{ | ||
// Trigger the "before format" event, which can be used to strip out code blocks. | ||
$this->trigger("beforeFormat"); | ||
|
||
// Format links, mentions, and quotes. | ||
if (C("esoTalk.format.mentions")) $this->mentions(); | ||
if (!$this->inline) $this->quotes(); | ||
if(array_search('AutoLink', C("esoTalk.enabledPlugins"))) { | ||
if ($sticky) $this->links(); | ||
} | ||
else { | ||
$this->links(); | ||
} | ||
|
||
// Format bullet and numbered lists. | ||
if (!$this->inline) $this->lists(); | ||
|
||
// Trigger the "format" event, where all regular formatting can be applied (bold, italic, etc.) | ||
$this->trigger("format"); | ||
|
||
// Format whitespace, adding in <br/> and <p> tags. | ||
if (!$this->inline) $this->whitespace(); | ||
|
||
// Trigger the "after format" event, where code blocks can be put back in. | ||
$this->trigger("afterFormat"); | ||
|
||
return $this; | ||
} | ||
``` | ||
|
||
Replace the the following line (51) in **./core/views/conversations/conversation.php**: | ||
```php | ||
echo "<div class='excerpt'>".ET::formatter()->init($conversation["firstPost"])->inline(true)->firstLine()->clip(200)->format()->get()."</div>"; | ||
``` | ||
|
||
with the following code: | ||
```php | ||
echo "<div class='excerpt'>".ET::formatter()->init($conversation["firstPost"])->inline(true)->firstLine()->clip(200)->format(true)->get()."</div>"; | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
// Copyright 2014 Tristan van Bokkem | ||
|
||
if (!defined("IN_ESOTALK")) exit; | ||
|
||
ET::$pluginInfo["AutoLink"] = array( | ||
"name" => "自动填充", | ||
"description" => "当用户帖子中含有图片或者视频网站链接时自动填充为相应格式(支持图片和优酷/油管)", | ||
"version" => "1.2.1", | ||
"author" => "Ramouch0", | ||
"authorEmail" => "[email protected]", | ||
"authorURL" => "http://esotalk.org", | ||
"license" => "GPLv2" | ||
); | ||
|
||
class ETPlugin_AutoLink extends ETPlugin { | ||
|
||
// ACCEPTED PROTOTYPES | ||
// | ||
var $accepted_protocols = array( | ||
'http://', 'https://', 'ftp://', 'ftps://', 'mailto:', 'telnet://', | ||
'news://', 'nntp://', 'nntps://', 'feed://', 'gopher://', 'sftp://' ); | ||
|
||
// | ||
// AUTO-EMBED IMAGE FORMATS | ||
// | ||
var $accepted_image_formats = array( | ||
'gif', 'jpg', 'jpeg', 'tif', 'tiff', 'bmp', 'png', 'svg', 'ico' ); | ||
|
||
|
||
public function handler_format_format($sender) | ||
{ | ||
// quick check to rule out complete wastes of time | ||
if( strpos( $sender->content, '://' ) !== false || strpos($sender->content, 'mailto:' ) !== false ) | ||
{ | ||
$sender->content = preg_replace_callback( '/(?<=^|\r\n|\n| |\t|<br>|<br\/>|<br \/>)!?([a-z]+:(?:\/\/)?)([^ <>"\r\n\?]+)(\?[^ <>"\r\n]+)?/i', array( &$this, 'autoLink' ), $sender->content ); | ||
} | ||
} | ||
|
||
public function autoLink( $link = array()) | ||
{ | ||
// $link[0] = the complete URL | ||
// $link[1] = link prefix, lowercase (e.g., 'http://') | ||
// $link[2] = URL up to, but not including, the ? | ||
// $link[3] = URL params, including initial ? | ||
// sanitise input | ||
$link[1] = strtolower( $link[1] ); | ||
if( !isset( $link[3] ) ) $link[3] = ''; | ||
|
||
// check protocol is allowed | ||
if( !in_array( $link[1], $this->accepted_protocols ) ) return $link[0]; | ||
|
||
// check for forced-linking and strip prefix | ||
$forcelink = substr( $link[0], 0, 1 ) == '!'; | ||
if( $forcelink ) $link[0] = substr( $link[0], 1 ); | ||
|
||
$params = array(); | ||
$matches = array(); | ||
|
||
|
||
if( !$forcelink && ( $link[1] == 'http://' || $link[1] == 'https://' ) ) | ||
{ | ||
$width = 797; | ||
$height = 447; | ||
// images | ||
if( preg_match( '/\.([a-z]{1,5})$/i', $link[2], $matches ) && in_array( strtolower( $matches[1] ), $this->accepted_image_formats ) ) | ||
return '<img class="auto-embedded" src="'.$link[1].$link[2].$link[3].'" alt="-image-" title="'.$link[1].$link[2].$link[3].'" />'; | ||
// youtube | ||
else if( strcasecmp( 'www.youtube.com/watch', $link[2] ) == 0 && $this->params( $params, $link[3], 'v' ) ) | ||
return '<iframe width="'.$width.'" height="'.$height.'" src="'.$link[1].'www.youtube.com/embed/'.$params['v'].'" frameborder="0" allowfullscreen></iframe>'; | ||
else if( preg_match( '/^(?:www\.)?youtu\.be\/([^\/]+)/i', $link[2], $matches )) | ||
return '<iframe width="'.$width.'" height="'.$height.'" src="'.$link[1].'www.youtube.com/embed/'.$matches[1].'" frameborder="0" allowfullscreen></iframe>'; | ||
// google video | ||
else if( preg_match( '/^(video\.google\.co(?:m|\.uk))\/videoplay$/i', $link[2], $matches ) && $this->params( $params, $link[3], 'docid' ) ) | ||
return '<embed class="video" style="width:'.$width.'px;height:'.$height.'px" allowfullscreen="true" src="'.$link[1].$matches[1].'/googleplayer.swf?docid='.$params['docid'].'&fs=true" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" align="top" />'; | ||
// vimeo | ||
else if( preg_match( '/^(?:www\.)?vimeo\.com\/([^\/]+)/i', $link[2], $matches ) ) | ||
return '<iframe src="http://player.vimeo.com/video/'.$matches[1].'?byline=0&portrait=0" width="'.$width.'" height="'.$height.'" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>'; | ||
else if( strcasecmp( 'www.facebook.com/photo.php', $link[2] ) == 0 && $this->params( $params, $link[3], 'v' ) ) | ||
return '<iframe src="https://www.facebook.com/video/embed?video_id='.$params['v'].'" width="540" height="420" frameborder="0"></iframe>'; | ||
// youku | ||
else if( preg_match( '/^(?:v\.)?youku\.com\/v_show\/id_([^\/]+)\.html/i', $link[2], $matches )) | ||
return '<iframe width="'.$width.'" height="'.$height.'" src="https://player.youku.com/embed/'.$matches[1].'" frameborder="0" allowfullscreen></iframe>'; | ||
} | ||
|
||
|
||
// default to linkifying | ||
return '<a href="'.$link[0].'" rel="nofollow external">'.$link[0].'</a>'; | ||
|
||
} | ||
|
||
/*Reads query parameters | ||
params : result array as key => value | ||
string : query string | ||
required : array of required parameters key | ||
@return true if required parameters are present. | ||
*/ | ||
function params( &$params, $string, $required ) | ||
{ | ||
$string = html_entity_decode($string); | ||
if( !is_array( $required ) ) $required = array( $required ); | ||
if( substr( $string, 0, 1 ) == '?' ) $string = substr( $string, 1 ); | ||
$params = array(); | ||
$bits = preg_split( '/&/', $string ); | ||
foreach( $bits as $bit ) { | ||
$pair = preg_split( '/=/', $bit, 2 ); | ||
if( in_array( $pair[0], $required ) ) $params[ $pair[0] ] = $pair[1]; | ||
} | ||
return count( $required ) == count( $params ); | ||
} | ||
|
||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters