forum.coppermine-gallery.net
No Support => Feature requests => Topic started by: chtito on November 20, 2004, 05:52:20 pm
-
In relation to this thread (http://forum.coppermine-gallery.net/index.php?topic=11904.new#new),
here is a new breadcrumb function which can call a customised theme_breadcrumb function if it exists. (The function is based on the 1.4 breadcrumb function, but should also work on 1.3 version with the cpg_db_query --> db_query modification)
/**
* breadcrumb()
*
* Build the breadcrumb navigation
*
* @param integer $cat
* @param string $breadcrumb
* @param string $BREADCRUMB_TEXT
* @return
**/
function breadcrumb($cat, &$breadcrumb, &$BREADCRUMB_TEXT)
{
global $album, $lang_errors, $lang_list_categories;
global $CONFIG,$CURRENT_ALBUM_DATA, $CURRENT_CAT_NAME;
// first we build the category path: names and id
if ($cat != 0)
{ //Categories other than 0 need to be selected
$category_array = array();
if ($cat >= FIRST_USER_CAT)
{
$user_name = get_username($cat - FIRST_USER_CAT);
if (!$user_name) $user_name = 'Mr. X';
$category_array[] = array($cat, $user_name);
$CURRENT_CAT_NAME = sprintf($lang_list_categories['xx_s_gallery'], $user_name);
$row['parent'] = 1;
}
else
{
$result = cpg_db_query("SELECT name, parent FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = '$cat'");
if (mysql_num_rows($result) == 0)
cpg_die(CRITICAL_ERROR, $lang_errors['non_exist_cat'], __FILE__, __LINE__);
$row = mysql_fetch_array($result);
$category_array[] = array($cat, $row['name']);
$CURRENT_CAT_NAME = $row['name'];
mysql_free_result($result);
}
while($row['parent'] != 0)
{
$result = cpg_db_query("SELECT cid, name, parent FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = '{$row['parent']}'");
if (mysql_num_rows($result) == 0)
cpg_die(CRITICAL_ERROR, $lang_errors['orphan_cat'], __FILE__, __LINE__);
$row = mysql_fetch_array($result);
$category_array[] = array($row['cid'], $row['name']);
mysql_free_result($result);
} // while
$category_array = array_reverse($category_array);
}
$breadcrumb_links = array();
$BREADCRUMB_TEXTS = array();
// Add the Home link to breadcrumb
$breadcrumb_links[0] = '<a href="index.php">'.$lang_list_categories['home'].'</a>';
$BREADCRUMB_TEXTS[0] = $lang_list_categories['home'];
$cat_order = 1;
foreach ($category_array as $category)
{
$breadcrumb_links[$cat_order] = "<a href=\"index.php?cat={$category[0]}\">{$category[1]}</a>";
$BREADCRUMB_TEXTS[$cat_order] = $category[1];
$cat_order += 1;
}
//Add Link for album if aid is set
if (isset($CURRENT_ALBUM_DATA['aid']))
{
$breadcrumb_links[$cat_order] = "<a href=\"thumbnails.php?album=".$CURRENT_ALBUM_DATA['aid']."\">".$CURRENT_ALBUM_DATA['title']."</a>";
$BREADCRUMB_TEXTS[$cat_order] = $CURRENT_ALBUM_DATA['title'];
}
// we check if the theme_breadcrumb exists...
if (function_exists('theme_breadcrumb'))
{
theme_breadcrumb($breadcrumb_list, $BREADCRUMB_TEXTS, $breadcrumb, $BREADCRUMB_TEXT);
return;
}
// otherwise we have a default breadcrumb builder:
$breadcrumb = '';
$BREADCRUMB_TEXT = '';
foreach ($breadcrumb_links as $breadcrumb_link)
{
$breadcrumb .= ' > ' . $breadcrumb_link;
}
foreach ($BREADCRUMB_TEXTS as $BREADCRUMB_TEXT_elt)
{
$BREADCRUMB_TEXT .= ' > ' . $BREADCRUMB_TEXT_elt;
}
// We remove the first ' > '
$breadcrumb = substr_replace($breadcrumb,'', 0, 3);
$BREADCRUMB_TEXT = substr_replace($BREADCRUMB_TEXT,'', 0, 3);
//echo $breadcrumb;
}
-
Please use the code tags when posting php code, not php /php tags.
-
To get a really customised appearance, here are the few changes to make (besides the breadcrumb function already described above):
1) In the function msg_box in functions.inc.php:
function msg_box($title, $msg_text, $button_text="", $button_link="", $width="-1")
{
if (function_exists('theme_msg_box'))
{
theme_msg_box($title, $msg_text, $button_text, $button_link, $width);
return;
}
...and the rest of the function left unchanged.
2)In the function cpg_die of the same file:
function cpg_die($msg_code, $msg_text, $error_file, $error_line, $output_buffer = false)
{
global $CONFIG, $lang_cpg_die, $template_cpg_die;
// Simple output if theme file is not loaded
if(!function_exists('pageheader')){
echo 'Fatal error :<br />'.$msg_text;
exit;
}
$ob = ob_get_contents();
if ($ob) ob_end_clean();
if (function_exists('theme_cpg_die'))
{
theme_cpg_die($msg_code, $msg_text, $error_file, $error_line, $output_buffer);
return;
}
...the rest being left unchanged.
3)And the beginning of the function generate_smilies in smilies.inc.php may be replaced by:
function generate_smilies($form = 'post', $field = 'message')
{
global $THEME_DIR;
$smilies = get_smilies_table2();
$paths = array($THEME_DIR.'/smiles/','images/smiles/');
if (function_exists('theme_generate_smilies'))
{
$html = theme_generate_smilies($smilies, $form);
}
else
{
$html = '<table width="100%" border="0" cellspacing="0" cellpadding="0">' . "\n" . ' <tr align="center" valign="middle">' . "\n";
foreach($smilies as $smiley) {
$smile_path = (file_exists($paths[0].$smiley[1]))?($paths[0]):($paths[1]);
$caption = $smiley[2] . " " . $smiley[0];
$html .= ' <td width="5%"><img src="images/smiles/' . $smiley[1] . '" alt="' . $caption . '" width="15" height="15" border="0" style="cursor:pointer;cursor:hand;" title="' . $caption . '" onclick="javascript:emoticon_' . $form . '(\'' . $smiley[0] . '\')"></td>' . "\n";
}
$html .= ' </tr>' . "\n" . '</table>' . "\n";
}
...the rest being left unchanged.
With these changes it is possible to create a completely tablefree theme, while leaving the possibility of a table design. I will release such a theme as soon as it is ready.
Cheers,
== Olivier
-
There are considerations along those lines for the version after cpg1.4, with many functions from functions.inc.php that will be used only if there is not a custom function that will override it, a sort of function fallback.
Joachim