Hello,
I want to create a template with tab (like "talk", but more than it), and use the css class "wikilink1" if the page exist and "wikilink2" if it doesn't exist.
For example, I have a tab for "general", "tab1", "tab2". Pages "general" and "tab1" exist but not "tab2".
But for the moment I can't find how know if "page on tab2" exist or not. I think I don't find the good variable for
file_exists($complet_link) ? 'wikilink1' : 'wikilink2';
Here, my complete code about tabs :
<?php
if (!defined("DOKU_INC")){
die();
}
// Declare tab type (for links) :
$tab_category = array('general', 'animation', 'gameplay', 'dev', 'talk');
$number_cat = count($tab_category);
// Creation of the dynamic variable $name (TODO : rename it, stupid var).
for ($i = 0; $i < $number_cat; $i++) {
$name = $tab_category[$i] ;
// Retrieve the current link from the page and explode it so you can process each piece separately
$tab_actualid = explode(":", getID() ) ;
// Recover wiki url
$kh_wikibase = DOKU_BASE ;
// Links
$name_link = $name ;
// translations
$khtab_loc = 'tab_' . $name . '_loc' ;
$tab_general_loc = tpl_getLang("$khtab_loc");
// Detect if translation plugin is active or not. If yes, add the lang namespace ("fr", "en", etc.) at the beginning.
if ($translation) {
$tab_listlang = explode(" ", $conf["plugin"]["translation"]["translations"]) ;
// Make sure the first ns is a language thing.
if (in_array($tab_actualid[0], $tab_listlang)) {
// get the language namespace
$tab_nsactuallang = "$tab_actualid[0]";
// retrieves the last element of the array
$lastid = array_pop($tab_actualid);
// removes the first 2 elements of the table
$firstid = array_slice($tab_actualid, 2);
// glue up what's left
$tab_actualns = implode(":", $firstid);
// Génération des liens
// if $tab_actualns is empty, we don't put an NS link
if (empty($tab_actualns)) {
// The fist tab (general article) is NOT in :general: NS, otherwise startpage don't work good.
if ( $i == 0) {
$tab_link = $tab_nsactuallang.":".$lastid;
}
else
$tab_link = $tab_nsactuallang.":".$name_link.":".$lastid;
}
else {
if ( $i == 0) {
$tab_link = $tab_nsactuallang.":".$tab_actualns.":".$lastid;
}
else
$tab_link = $tab_nsactuallang.":".$name_link.":".$tab_actualns.":".$lastid;
}
}
else { // If it doesn't start with one of the languages, but there is something at the beginning and the translation plugin treated as without translation plugin, copied from below...
$lastid = array_pop($tab_actualid);
// removes the first element from the table (category)
$firstid = array_slice($tab_actualid, 1);
// glue up what's left
$tab_actualns = implode(":", $firstid);
if (empty($tab_actualns)) {
// if NS is empty, don't create NS
if ( $i == 0) {
$tab_link = $lastid;
}
else
$tab_link = $name_link.":".$lastid;
}
else {
$tab_link = $tab_actualns.":".$lastid;
$tab_link = $name_link.":".$tab_actualns.":".$lastid;
}
}
}
// If there are not plugin Translation, we don't use "en" (or "fr", "de", etc.) and start with tab category
else
{
$lastid = array_pop($tab_actualid);
// removes the first element from the table (category)
$firstid = array_slice($tab_actualid, 1);
// glue up what's left
$tab_actualns = implode(":", $firstid);
if (empty($tab_actualns)) {
// if NS is empty, don't create NS
if ( $i == 0) {
$tab_link = $lastid;
}
else
$tab_link = $name_link.":".$lastid;
}
else {
if ( $i == 0) {
$tab_link = $tab_actualns.":".$lastid;
}
else
$tab_link = $name_link.":".$tab_actualns.":".$lastid;
}
}
$complet_link = "$kh_wikibase$tab_link" ;
// creation of as many tabs as links
$class_khtab = file_exists($complet_link) ? 'wikilink1' : 'wikilink2';
echo '<div class="khtab"><span><a href="' . "$complet_link" . '" class="' . "$class_khtab" . '" title="' . "$tab_link" . '" >' . "$tab_general_loc" . '</a></span></div>' ;
}
?>