An image for each contributor
-
nutsmuggler
- Regular
- Posts: 16
- Joined: Thu Nov 04, 2004 1:05 pm
An image for each contributor
Is it possible to associate an image (ie, a pic of the contributor) to each contributor?
Cheers,
Davide
Cheers,
Davide
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Re: An image for each contributor
This can be easily done with a plugin.
I just created one and added it to the additional_plugins CVS module of serendipity. Here's the code of it, just save it as "serendipity_event_authorpic.php" inside a new folder "plugins/serendipity_event_authorpic" - then you can activate it in your plugin configuration.
The plugin looks for images called just like the authorname in the img subfolder of your template directory; so if the authorname is "garvin hicking", it will fetch a file from "templates/default/img/garvin_hicking.jpg".
Have fun with it!
I just created one and added it to the additional_plugins CVS module of serendipity. Here's the code of it, just save it as "serendipity_event_authorpic.php" inside a new folder "plugins/serendipity_event_authorpic" - then you can activate it in your plugin configuration.
The plugin looks for images called just like the authorname in the img subfolder of your template directory; so if the authorname is "garvin hicking", it will fetch a file from "templates/default/img/garvin_hicking.jpg".
Have fun with it!
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 : */
?>
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
-
nutsmuggler
- Regular
- Posts: 16
- Joined: Thu Nov 04, 2004 1:05 pm
Thanks Gravin, a BTO plugin iss more than I expected.
I am really sorry to report that there probably is a bug:
That's what I find in the plugin panel, in the Event plugin section:
Parse error: parse error, unexpected T_STRING, expecting T_CASE or T_DEFAULT or '}' in /web/htdocs/www.cnomania.it/home/serendipity/plugin ... horpic.php on line 4
I'd like to fix this bug myself, but I have no knowledge of php.
Thanks a million anyway,
Davide
I am really sorry to report that there probably is a bug:
That's what I find in the plugin panel, in the Event plugin section:
Parse error: parse error, unexpected T_STRING, expecting T_CASE or T_DEFAULT or '}' in /web/htdocs/www.cnomania.it/home/serendipity/plugin ... horpic.php on line 4
I'd like to fix this bug myself, but I have no knowledge of php.
Thanks a million anyway,
Davide
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
I suppose you made a mistake by copy/pasting the script from here? What is line 4 of your file? I can mail you the right file, if you supply me with your mail adress 
Regards,
Garvin.
Regards,
Garvin.
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
-
nutsmuggler
- Regular
- Posts: 16
- Joined: Thu Nov 04, 2004 1:05 pm
Well, thanks again!
If all pricey application were supported as this free one...
Maybe something went wrong in the copy/paste process...
You can mail the file at
cno@cnomania.it
Cheers again,
Davide
If all pricey application were supported as this free one...
Maybe something went wrong in the copy/paste process...
You can mail the file at
cno@cnomania.it
Cheers again,
Davide
-
nutsmuggler
- Regular
- Posts: 16
- Joined: Thu Nov 04, 2004 1:05 pm
Hi Garvin, and hello to all the folks in the forum.
I have been experimenting with your "BTO"
Picture-of-the author plugin. I have put it in the correct directory, and I can see it in the administration panel; the plugin seems to be working. Yet no picture appears... I have inserted a picture for my user, Nutsmuggler, in the Idea template directory (Idea is indeed the template I am using); I have kept the capital N, since Unix is case sensitive, right? No image...
Can you suggest me what the problem might be?
Cheers,
Davide
I have been experimenting with your "BTO"
Can you suggest me what the problem might be?
Cheers,
Davide
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
nutsmuggler,
you are right with the capitals; but you need to put the image in templates/idea/img/Nutsmuggler.jpg (or .gif or whatever extension you configurued)...
Regards,
Garvin
you are right with the capitals; but you need to put the image in templates/idea/img/Nutsmuggler.jpg (or .gif or whatever extension you configurued)...
Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
-
nutsmuggler
- Regular
- Posts: 16
- Joined: Thu Nov 04, 2004 1:05 pm
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Are you using version 0.8 of serendipity? If so, the caching plugin may interfer; can click on 'rebuild cached entries' in that case?
If you're using 0.7 we would have to add a little debugging. Have you looked at the HTML source and see there if there's any image HTML printed?
Regards,
Garvin.
If you're using 0.7 we would have to add a little debugging. Have you looked at the HTML source and see there if there's any image HTML printed?
Regards,
Garvin.
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
-
nutsmuggler
- Regular
- Posts: 16
- Joined: Thu Nov 04, 2004 1:05 pm
I'm using version 0.7.
I've looked at the page HTML source; I don't think there is any image in the source. Here's the extract of a news entry:
Here is a link to the page:
http://lnx.cnomania.it/serendipity/
Joaquim Tejo is my nick, and I have uploaded a Jouaquim_Tejo.jpg test image in /templates/idea/img:
http://lnx.cnomania.it/serendipity/temp ... m_Tejo.jpg
Cheers,
Davide
I've looked at the page HTML source; I don't think there is any image in the source. Here's the extract of a news entry:
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>
http://lnx.cnomania.it/serendipity/
Joaquim Tejo is my nick, and I have uploaded a Jouaquim_Tejo.jpg test image in /templates/idea/img:
http://lnx.cnomania.it/serendipity/temp ... m_Tejo.jpg
Cheers,
Davide
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Thanks for letting me know.
Now, please edit your plugin file and alter this piece:
to this:
I added some more verbose HTML-comment output which should in any case be added to your blog.
I am online in #s9y.org on freenode if you want some "realtime" help with this
Regards,
Garvin.
Now, please edit your plugin file and alter this piece:
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 . ') -->';
}
I am online in #s9y.org on freenode if you want some "realtime" help with this
Regards,
Garvin.
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
-
nutsmuggler
- Regular
- Posts: 16
- Joined: Thu Nov 04, 2004 1:05 pm
-
nutsmuggler
- Regular
- Posts: 16
- Joined: Thu Nov 04, 2004 1:05 pm
I've modified the file; still I can see no changes in the page layout.
Here's the HTML code:
Cheers,
Davide
Here's the HTML code:
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>
Davide
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
This definitely seems like you haven't installed the plugin.
You need to go to "Plugins" and then choose the plugin to insert from the dropdown list of the lower part of the screen ("Event plugins") and click on 'insert plugin'...can you make a screenshot of how your list of installed event plugins looks like? The plugins isn't executed at all, because then the HTML comments would be seen...
Regards,
Garvin
You need to go to "Plugins" and then choose the plugin to insert from the dropdown list of the lower part of the screen ("Event plugins") and click on 'insert plugin'...can you make a screenshot of how your list of installed event plugins looks like? The plugins isn't executed at all, because then the HTML comments would be seen...
Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
-
nutsmuggler
- Regular
- Posts: 16
- Joined: Thu Nov 04, 2004 1:05 pm
