An image for each contributor
Posted: Thu Nov 04, 2004 3:59 pm
Is it possible to associate an image (ie, a pic of the contributor) to each contributor?
Cheers,
Davide
Cheers,
Davide
Code: Select all
<?php # $Id: serendipity_event_karma.php,v 1.14.2.9 2004/10/29 11:37:36 garvinhicking Exp $
switch ($serendipity['lang']) {
case 'de':
@define('PLUGIN_AUTHORPIC_NAME', 'Bild des Autoren');
@define('PLUGIN_AUTHORPIC_BLAHBLAH', 'Zeigt ein Bild des Autoren zu jedem Eintrag. Das Bild muss im Ordner "img" vom jeweiligen Templateordner liegen und so heißen, wie der Autorname. Alle Sonderzeichen (Umlaute, Leerzeichen, ...) müssen dabei durch ein "_" im Dateinamen ersetzt werden.');
@define('PLUGIN_AUTHORPIC_EXTENSION', 'Dateiendung');
@define('PLUGIN_AUTHORPIC_EXTENSION_BLAHBLAH', 'Welche Dateiendung haben die Bilder der Autoren?');
break;
case 'en':
default:
@define('PLUGIN_AUTHORPIC_NAME', 'Picture of the author');
@define('PLUGIN_AUTHORPIC_BLAHBLAH', 'Shows a picture of the author to each entry. The image file must be placed in the "img" Subfolder of your selected template and be called like the authorname. All special characters (quotes, spaces, ...) must be replaced by an "_" inside the filename.');
@define('PLUGIN_AUTHORPIC_EXTENSION', 'File extension');
@define('PLUGIN_AUTHORPIC_EXTENSION_BLAHBLAH', 'Which file extension do the images of the authors have?');
break;
}
class serendipity_event_authorpic extends serendipity_event
{
var $found_images = array();
function introspect(&$propbag)
{
global $serendipity;
$propbag->add('name', PLUGIN_AUTHORPIC_NAME);
$propbag->add('description', PLUGIN_AUTHORPIC_BLAHBLAH);
$propbag->add('stackable', false);
$propbag->add('author', 'Garvin Hicking');
$propbag->add('version', '1.0');
$propbag->add('event_hooks', array('frontend_display' => true, 'css' => true));
$propbag->add('scrambles_true_content', true);
$propbag->add('configuration', array('extension'));
}
function introspect_config_item($name, &$propbag)
{
switch($name) {
case 'extension':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_AUTHORPIC_EXTENSION);
$propbag->add('description', PLUGIN_AUTHORPIC_EXTENSION_BLAHBLAH);
$propbag->add('default', 'jpg');
break;
default:
return false;
}
return true;
}
function generate_content(&$title)
{
$title = PLUGIN_AUTHORPIC_NAME;
}
function event_hook($event, &$bag, &$eventData, $addData = null) {
global $serendipity;
$hooks = &$bag->get('event_hooks');
if (isset($hooks[$event])) {
switch($event) {
case 'css':
if (stristr('.serendipity_authorpic', $addData)) {
// class exists in CSS, so a user has customized it and we don't need default
return true;
}
?>
.serendipity_authorpic {
float: right;
margin: 5px;
border: 0px;
display: block;
}
<?php
return true;
break;
case 'frontend_display':
if ($bag->get('scrambles_true_content') && is_array($addData) && isset($addData['no_scramble'])) {
return true;
}
if (isset($this->found_images[$eventData['username']])) {
// Author image was already found previously. Display it.
$eventData['body'] = $this->found_images[$eventData['username']] . $eventData['body'];
} elseif ($img = serendipity_getTemplateFile('img/' . preg_replace('@[^a-z0-9]@i', '_', $eventData['username']) . '.' . $this->get_config('extension'))) {
// Author image exists, save it in cache and display it.
$this->found_images[$eventData['username']] = '<img class="serendipity_authorpic" src="' . $img . '" alt="' . AUTHOR . '" title="' . htmlspecialchars($eventData['username']) . '" />';
$eventData['body'] = $this->found_images[$eventData['username']] . $eventData['body'];
} else {
// No image found, do not try again in next article.
$this->found_images[$eventData['username']] = '';
}
return true;
break;
default:
return false;
}
} else {
return false;
}
}
}
/* vim: set sts=4 ts=4 expandtab : */
?>
Code: Select all
<div class="serendipity_Entry_Date">
<h3 class="serendipity_date">Domenica, novembre 28. 2004</h3>
<h4 class="serendipity_title"><a href="/serendipity/index.php?/archives/7-Cinque-cereali,-il-film.html">Cinque cereali, il film?</a></h4>
<div class="serendipity_entry">
<div class="serendipity_entry_body_folded">La notte porta consiglio, recita l'adagio popolare.<br />
E la notte... AND SO ON...produzione.<br />
JT</div>
<div class='serendipity_entryFooter'>
Scritto da Joaquim Tejo in <a href="/serendipity/index.php?/categories/3-Novita">Novità</a> at <a href="/serendipity/index.php?/archives/7-Cinque-cereali,-il-film.html">20:30</a>
| <a href="/serendipity/index.php?/archives/7-Cinque-cereali,-il-film.html#comments">Commenti (4)</a> | <a href="/serendipity/index.php?/archives/7-Cinque-cereali,-il-film.html#trackbacks">Trackbacks (0)</a> </div>
</div>
<!--
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<rdf:Description
rdf:about="http://lnx.cnomania.it/serendipity/index.php?/feeds/ei_7.rdf"
trackback:ping="http://lnx.cnomania.it/serendipity/comment.php?type=trackback&entry_id=7"
dc:title="Cinque cereali, il film?"
dc:identifier="http://lnx.cnomania.it/serendipity/index.php?/archives/7-Cinque-cereali,-il-film.html" />
</rdf:RDF>
-->
</div>
Code: Select all
if (isset($this->found_images[$eventData['username']])) {
// Author image was already found previously. Display it.
$eventData['body'] = $this->found_images[$eventData['username']] . $eventData['body'];
} elseif ($img = serendipity_getTemplateFile('img/' . preg_replace('@[^a-z0-9]@i', '_', $eventData['username']) . '.' . $this->get_config('extension'))) {
// Author image exists, save it in cache and display it.
$this->found_images[$eventData['username']] = '<img class="serendipity_authorpic" src="' . $img . '" alt="' . AUTHOR . '" title="' . htmlspecialchars($eventData['username']) . '" />';
$eventData['body'] = $this->found_images[$eventData['username']] . $eventData['body'];
} else {
// No image found, do not try again in next article.
$this->found_images[$eventData['username']] = '';
}
Code: Select all
if (isset($this->found_images[$eventData['username']])) {
// Author image was already found previously. Display it.
$eventData['body'] = '<!-- reusing -->' . $this->found_images[$eventData['username']] . $eventData['body'];
} elseif ($img = serendipity_getTemplateFile('img/' . preg_replace('@[^a-z0-9]@i', '_', $eventData['username']) . '.' . $this->get_config('extension'))) {
// Author image exists, save it in cache and display it.
$this->found_images[$eventData['username']] = '<img class="serendipity_authorpic" src="' . $img . '" alt="' . AUTHOR . '" title="' . htmlspecialchars($eventData['username']) . '" />';
$eventData['body'] = '<!-- img found -->' . $this->found_images[$eventData['username']] . $eventData['body'];
} else {
// No image found, do not try again in next article.
$this->found_images[$eventData['username']] = '<!-- no image img/' . preg_replace('@[^a-z0-9]@i', '_', $eventData['username']) . '.' . $this->get_config('extension') . ' was found (' . $img . ') -->';
}
Code: Select all
<div class="serendipity_Entry_Date">
<h3 class="serendipity_date">Domenica, novembre 28. 2004</h3>
<h4 class="serendipity_title"><a href="/serendipity/index.php?/archives/7-Cinque-cereali,-il-film.html">Cinque cereali, il film?</a></h4>
<div class="serendipity_entry">
<div class="serendipity_entry_body_folded">La notte porta consiglio, recita l'adagio popolare.<br />
E la notte scorsa di certo ha portato consiglio agli Accademici, o meglio, alla piccola delegazione riunita per il drink della buonanotte al Leon d'Oro.<br />
I cattedratici, meditando fra un bicchiere di birra e una tazza di latte, hanno deliberato la necessità di riprendere in mano un progetto di vecchia data, rimasto, ahinoi, sempre sulla carta. <br />
Il tempo è giunto, si sono detti, di mettere mano alla macchina da presa, e far vedere all'orbe terraqueo chi siamo.<br />
Eh sì, avete capito bene, se la fortuna ci sarà propizia avremo per le mani una produzione cinematografica firmata "Cinque Cereali".<br />
Le maggiori difficoltà sono sul versante del finanziamento, anche se pare che una nota ditta di grappe di Vigolovattaro sia interessata alla produzione.<br />
JT</div>
<div class='serendipity_entryFooter'>
Scritto da Joaquim Tejo in <a href="/serendipity/index.php?/categories/3-Novita">Novità</a> at <a href="/serendipity/index.php?/archives/7-Cinque-cereali,-il-film.html">20:30</a>
| <a href="/serendipity/index.php?/archives/7-Cinque-cereali,-il-film.html#comments">Commenti (4)</a> | <a href="/serendipity/index.php?/archives/7-Cinque-cereali,-il-film.html#trackbacks">Trackbacks (0)</a> | <a href="http://lnx.cnomania.it/serendipity/serendipity_entries.php?serendipity[action]=admin&serendipity[adminModule]=entries&serendipity[adminAction]=edit&serendipity[id]=7">Modifica notizia</a> </div>
</div>
<!--
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<rdf:Description
rdf:about="http://lnx.cnomania.it/serendipity/index.php?/feeds/ei_7.rdf"
trackback:ping="http://lnx.cnomania.it/serendipity/comment.php?type=trackback&entry_id=7"
dc:title="Cinque cereali, il film?"
dc:identifier="http://lnx.cnomania.it/serendipity/index.php?/archives/7-Cinque-cereali,-il-film.html" />
</rdf:RDF>
-->
</div>
