dkny70007 wrote:hi there, i have no knowladge about php, so could you help me out..thank you.
Sure, here's your plugin. Copy + Paste that block of code into a file 'serendipity_plugin_imagecategory.php' and save it in the directory 'plugins/serendipity_plugin_imagecategory' of your Serendipity installation.
Then you can go to "configure plugins" and select the new Plugin 'Image Category' and add that to your plugins.
It will then display a second icon for every category for which a file exists. Let's say your Category is called "photoshop", then you must have a file called "templates/default/img/photoshop.gif" which will be displayed. Pay attention to upper/lowercase of the filename, and all characters whice are not A-Z or 0-9 need to be replaced with "_".
Code: Select all
<?php
class serendipity_plugin_imagecategory extends serendipity_plugin {
var $title = 'Image Category';
function introspect(&$propbag) {
global $serendipity;
$propbag->add('name', 'Image Category');
$propbag->add('description', CATEGORY_PLUGIN_DESC . '(+ category images)');
$propbag->add('stackable', true);
$propbag->add('author', 'Serendipity Team');
$propbag->add('version', '1.0');
$propbag->add('configuration', array('authorid', 'image'));
}
function introspect_config_item($name, &$propbag)
{
global $serendipity;
switch($name) {
case 'authorid':
$row_authors = serendipity_db_query("SELECT username, authorid FROM {$serendipity['dbPrefix']}authors");
$authors = array('all' => ALL_AUTHORS);
if (is_array($row_authors)) {
foreach($row_authors as $row) {
$authors[$row['authorid']] = $row['username'];
}
}
$propbag->add('type', 'select');
$propbag->add('name', CATEGORIES_TO_FETCH);
$propbag->add('description', CATEGORIES_TO_FETCH_DESC);
$propbag->add('select_values', $authors);
$propbag->add('default', 'all');
break;
case 'image':
$propbag->add('type', 'string');
$propbag->add('name', XML_IMAGE_TO_DISPLAY);
$propbag->add('description', XML_IMAGE_TO_DISPLAY_DESC);
$propbag->add('default', serendipity_getTemplateFile('img/xml.gif'));
break;
default:
return false;
}
return true;
}
function generate_content(&$title) {
global $serendipity;
$which_category = $this->get_config('authorid');
$categories = serendipity_fetchCategories(empty($which_category) ? 'all' : $which_category);
$title = $this->title;
$html = '';
$image = $this->get_config('image', serendipity_getTemplateFile('img/xml.gif'));
$image = (($image == "'none'" || $image == 'none') ? '' : $image);
if (is_array($categories) && count($categories)) {
$html .= $this->serendipity_generateCategoryList($categories, array(0), 3, 0, 0, $image);
}
$html .= sprintf(
'<br /><a href="%s" title="%s">%s</a>',
$serendipity['serendipityHTTPPath'] . $serendipity['indexFile'],
ALL_CATEGORIES,
ALL_CATEGORIES
);
print $html;
}
function serendipity_generateCategoryList($cats, $select = array(0), $type = 0, $id = 0, $level = 0, $xmlImg = '') {
global $serendipity;
if ( !is_array($cats) || !count($cats) )
return;
$ret = '';
foreach ($cats as $cat) {
if ($cat['parentid'] == $id) {
switch ($type) {
case 3:
$category_id = serendipity_makeFilename($cat['category_name']);
if (!empty($xmlImg)) {
$catimg = serendipity_getTemplateFile('img/' . preg_replace('@[^a-z0-9]@i', '_', $cat['category_name']) . '.gif');
if (!empty($catimg)) {
$catimg = '<img alt="xml" src="' . $catimg . '" style="vertical-align: bottom; display: inline; border: 0px" /> ';
}
$ret .= sprintf(
'<div style="padding-bottom: 2px;">' .
'<a href="%s" title="%s"><img alt="xml" src="%s" style="vertical-align: bottom; display: inline; border: 0px" /></a> %s%s' .
'<a href="%s" title="%s">%s</a>' .
'</div>',
$serendipity['serendipityHTTPPath'] . 'rss.php?category=' . $cat['categoryid'] . '_' . $category_id,
htmlspecialchars($cat['category_description']),
$xmlImg,
$catimg,
str_repeat(' ', $level * 3),
serendipity_rewriteURL(PATH_CATEGORIES . '/' . $cat['categoryid'] . '-' . $category_id, 'serendipityHTTPPath'),
htmlspecialchars($cat['category_description']),
htmlspecialchars($cat['category_name']));
} else {
$ret .= sprintf(
'%s<a href="%s" title="%s">%s</a><br />',
str_repeat(' ', $level * 3),
serendipity_rewriteURL(PATH_CATEGORIES . '/' . $cat['categoryid'] . '-' . $category_id, 'serendipityHTTPPath'),
htmlspecialchars($cat['category_description']),
htmlspecialchars($cat['category_name']));
}
break;
}
$ret .= $this->serendipity_generateCategoryList($cats, $select, $type, $cat['categoryid'], $level + 1, $xmlImg);
}
}
return $ret;
}
}
?>