serendipity_event_autotitle/ 0001777 0000041 0000041 00000000000 11165355073 016753 5 ustar www-data www-data serendipity_event_autotitle/lang_de.inc.php 0000755 0001750 0001750 00000000633 11165355205 020256 0 ustar onli onli
* EN-Revision: Revision of lang_en.inc.php
*/
@define('PLUGIN_EVENT_AUTOTITLE_NAME', 'Markup: Auto-Titel');
@define('PLUGIN_EVENT_AUTOTITLE_DESC', 'Fügt automatischen den Titel der verlinkten Seite als als "title"-Tag zum Link hinzu.');
?>
serendipity_event_autotitle/lang_en.inc.php 0001777 0000041 0000041 00000000562 11163426016 021637 0 ustar www-data www-data
* EN-Revision: Revision of lang_en.inc.php
*/
@define('PLUGIN_EVENT_AUTOTITLE_NAME', 'Markup: Autotitle');
@define('PLUGIN_EVENT_AUTOTITLE_DESC', 'Set the title-tag into the links of the entry.');
?>
serendipity_event_autotitle/UTF-8/ 0001777 0000041 0000041 00000000000 11165355036 017555 5 ustar www-data www-data serendipity_event_autotitle/UTF-8/lang_de.inc.php 0000755 0001750 0001750 00000000633 11165355223 021061 0 ustar onli onli
* EN-Revision: Revision of lang_en.inc.php
*/
@define('PLUGIN_EVENT_AUTOTITLE_NAME', 'Markup: Auto-Titel');
@define('PLUGIN_EVENT_AUTOTITLE_DESC', 'Fügt automatischen den Titel der verlinkten Seite als als "title"-Tag zum Link hinzu.');
?>
serendipity_event_autotitle/UTF-8/lang_en.inc.php 0001777 0000041 0000041 00000000562 11163426032 022440 0 ustar www-data www-data
* EN-Revision: Revision of lang_en.inc.php
*/
@define('PLUGIN_EVENT_AUTOTITLE_NAME', 'Markup: Autotitle');
@define('PLUGIN_EVENT_AUTOTITLE_DESC', 'Set the title-tag into the links of the entry.');
?>
serendipity_event_autotitle/serendipity_event_autotitle.php 0001777 0000041 0000041 00000014267 11166402540 025324 0 ustar www-data www-data add('name', PLUGIN_EVENT_AUTOTITLE_NAME);
$propbag->add('description', PLUGIN_EVENT_AUTOTITLE_DESC);
$propbag->add('stackable', false);
$propbag->add('author', 'Malte Paskuda');
$propbag->add('version', '0.1');
$propbag->add('requirements', array(
'php' => '4.1.0'
));
$propbag->add('cachable_events', array('frontend_display' => true));
$propbag->add('event_hooks', array('frontend_display' => true));
$propbag->add('groups', array('MARKUP'));
$this->markup_elements = array(
array(
'name' => 'ENTRY_BODY',
'element' => 'body',
),
array(
'name' => 'EXTENDED_BODY',
'element' => 'extended',
),
array(
'name' => 'COMMENT',
'element' => 'comment',
),
array(
'name' => 'HTML_NUGGET',
'element' => 'html_nugget',
)
);
$conf_array = array();
foreach($this->markup_elements as $element) {
$conf_array[] = $element['name'];
}
$propbag->add('configuration', $conf_array);
}
function install() {
serendipity_plugin_api::hook_event('backend_cache_entries', $this->title);
}
function uninstall() {
serendipity_plugin_api::hook_event('backend_cache_purge', $this->title);
serendipity_plugin_api::hook_event('backend_cache_entries', $this->title);
}
function generate_content(&$title) {
$title = $this->title;
}
function introspect_config_item($name, &$propbag)
{
switch($name) {
default:
$propbag->add('type', 'boolean');
$propbag->add('name', constant($name));
$propbag->add('description', sprintf(APPLY_MARKUP_TO, constant($name)));
$propbag->add('default', 'true');
}
return true;
}
function event_hook($event, &$bag, &$eventData) {
global $serendipity;
$hooks = &$bag->get('event_hooks');
if (isset($hooks[$event])) {
@include_once 'Cache/Lite.php';
if (!class_exists('Cache_Lite')) {
$this->debugMsg('Cache_Lite not available.');
return false;
}
$options = array(
'cacheDir' => $serendipity['serendipityPath'] . 'templates_c/',
'lifeTime' => 604800, //one week
'hashedDirectoryLevel' => 2,
'automaticCleaningFactor' => 200
);
$this->cache = new Cache_Lite($options);
switch($event) {
case 'frontend_display':
foreach ($this->markup_elements as $temp) {
if (serendipity_db_bool($this->get_config($temp['name'], true)) && isset($eventData[$temp['element']]) &&
!$eventData['properties']['ep_disable_markup_' . $this->instance] &&
!in_array($this->instance, (array)$serendipity['POST']['properties']['disable_markups']) &&
!$eventData['properties']['ep_no_nl2br'] &&
!isset($serendipity['POST']['properties']['ep_no_nl2br'])) {
$element = $temp['element'];
$eventData[$element] = $this->autotitle($eventData[$element]);
}
}
return true;
break;
default:
return false;
}
} else {
return false;
}
}
/**
* Get the title-tag of every linked site
* */
function autotitle($text) {
//get all links
preg_match_all('||is', $text, $links);
$link_amount = count($links[1]);
for ($i = 0; $i<$link_amount; $i++) {
//'link' is the whole inner of the a-tag
$link = $links[1][$i];
//ignore this link if title already set
if (strpos($link, 'title=') !== false) {
continue;
}
//if href is alone, last " is missing
if (substr($link, strlen($link), 1) != '"') {
$link = $link .'"';
}
//grab the real url
preg_match('|href="([^\"]*?)"|is', $link, $url);
$url = $url[1];
//prepare cache:
$this->cache->_setFileName($url, $this->cache_group);
//check cache:
$title = $this->get_cached_title($url);
if ($title === false) {
//$page = a maximum of the first 4kb of the linked site
$page = file_get_contents($url, 0, null, -1, 4096);
preg_match('|([^<]*?)|is', $page, $title);
$title = $title[1];
$this->cache_title($url, $title);
}
//insert title in links
$titled_link = "$link\" title=\"$title\"";
$text = str_replace("cache->get($url, $this->cache_group);
}
function cache_title($url, $title) {
return $this->cache->save($title, $url, $this->cache_group);
}
}
/* vim: set sts=4 ts=4 expandtab : */