Creating a very simple plugin - Part 2

CrazyCoder

Member
arffffff morning guys :))))))
nooooooooooooooooooo not HIM !!!!!!! not again !!!!!!! you must think, ouuuuchhhhhh :))))

well, heuuuuuu may i continue to post ? oops, i hope i do not reach your patiente and kindness limits :)

so, i redone another time my skinchanger, why ? lol, because dealing with the admin skin,
is not so easy, along to the others 'standards' skins.

so heres the way i did it :

1) i added a new hook to index.php , just here after this require :

PHP:
require_once("{$CONF['path']}/sources/misc/skin.php");
 
//Hook Location 4 SetSkin
eval (PluginManager::getPluginManager ()->pluginHooks ('set_skin'));
2) i better wroten my plugin, at least i think so :: so here the set_skin.php :

PHP:
//######## NEW CODE Plugin SET_SKIN  ########//
 
/* to find the right vars to use : print_r($_SERVER); */
 
$guest_skin = $_POST['stylesheet'];
 
$test_qstring = substr($_SERVER['QUERY_STRING'],0,7);
$test_ruri = substr($_SERVER['REQUEST_URI'],0,18);
 
/* for debug
echo '<h3>';
echo $test_qstring;
echo "<br /><br />";
echo $test_ruri;
echo "<br /><br />";
echo '</h3>';
*/
 
if($test_ruri!='/pureones/admin/' && $test_qstring!='a=admin') {
 
 
// form var is there - set up cookie and refresh
if(isset($guest_skin)) {
setcookie("guest_skin", $guest_skin, time()+360000);
$TMPL['skin_name'] = $_COOKIE["guest_skin"];
unset($guest_skin);
header("Location: {$CONF['path']}");
}
 
// form var is not there
else {
 
// cookie is there
if($_COOKIE['guest_skin'])
$TMPL['skin_name'] = $_COOKIE['guest_skin'];
 
// cookie is not there
else
$TMPL['skin_name'] = $CONF['default_skin'];
 
}
 
}//
 
 
else {
 
if($test_ruri == '/pureones/admin/') {
setcookie("admin_skin", 'admin', time()+360000);
$TMPL['skin_name'] = "admin";
//setcookie("guest_skin", 'admin', time()+360000);
}
elseif($test_qstring == 'a=admin') {
setcookie("admin_skin", 'admin', time()+360000);
$TMPL['skin_name'] = "admin";
}
else { }
 
}
 
// THE FORM
 
$TMPL['visitor_skin_list'] = "
<div style=\"display: block;list-style: none;text-align: center;width: 250px;height: auto;\">
<ul>
<li><b>{$LNG['setskin_header_text']}</b><br />
<form method=\"post\" action=\"index.php\">
<select class=\"blackonwhite\" name=\"stylesheet\"  size=\"1\"
onchange=\"this.form.submit();\">";
 
//define the path
$path = "skins";
$dir_handle = @opendir($path) or die("Unable to open $path");
while ($file = readdir($dir_handle)) {
  if($file!="." && $file!=".." && $file!="admin") {
 
if($file == $TMPL['skin_name']) {
$TMPL['visitor_skin_list'] .= "<option value=\"$file\" selected=\"selected\">$file</option>";
}
else {
$TMPL['visitor_skin_list'] .= "<option value=\"$file\">$file</option>";
}
 
}
 
}
//closing the directory
closedir($dir_handle);
 
$TMPL['visitor_skin_list'] .= "</select>
<input type=\"hidden\">
</form>
</li>
</ul>
</div>";
 
 
$TMPL['mycustom_field'] .= $TMPL['visitor_skin_list'];
$TMPL['show_mycustom_field'] .= base::do_plugin_skin('./plugins/SetSkin','setskin_selector_html');

conclusion : still a big bug, grrr grrrrrr

To Browse the site, throught skins its OK.
IF i go to admin, its ok $TMPL['skin_name'] is well seted to "admin",
BUT once logged into admin, pafffffffffff the admin skin is lost, booooooo, and the skin select option frozens.

should i give up ?
 

CrazyCoder

Member
nope, as a plugin i fail about this one skin changer.
the only way its really 100% running without any conflicts,
Means you can have :
1 browser tab opened to visit the site, change a skin to another
+
1 browser tab showing the admin both at the same time and bothn with their own skin,

its to reput my very first code into index, directly :

so of course at the very beginning of the index we retrieve the var :

PHP:
$guest_skin = $_POST['stylesheet'];
and in index my code looks like this :

PHP:
// Determine the category skin and meta data
if ($TMPL['cat_exist']) {
  $TMPL['skin_name'] = $CONF['categories'][$TMPL['cat_exist']]['skin'];
  $TMPL['meta_description'] = $CONF['categories'][$TMPL['cat_exist']]['cat_desc']; 
  $TMPL['meta_keywords'] = $CONF['categories'][$TMPL['cat_exist']]['cat_key'];
}
else {
  $TMPL['skin_name'] = $CONF['default_skin'];
}
 
if (!is_dir("{$CONF['path']}/skins/{$TMPL['skin_name']}/") || !$TMPL['skin_name']) {
  $TMPL['skin_name'] = $CONF['default_skin'];
}
if (!is_dir("{$CONF['path']}/skins/{$CONF['default_skin']}/")) {
  $TMPL['skin_name'] = 'parabola';
}
require_once("{$CONF['path']}/sources/misc/skin.php");
 
 
 
 
 
//######## NEW CODE about SKIN_CHANGER  ########//
 
// form var is there - set up cookie and refresh
if(isset($guest_skin)) {
setcookie("guest_skin", $guest_skin, time()+360000);
$TMPL['skin_name'] = $_COOKIE["guest_skin"];
unset($guest_skin);
header("Location: {$CONF['path']}");
}
 
// form var is not there
elseif(!isset($guest_skin)) {
// cookie is there
if($_COOKIE['guest_skin']) {
$TMPL['skin_name'] = $_COOKIE['guest_skin'];
}
// cookie is not there
else
$TMPL['skin_name'] = $CONF['default_skin'];
}
 
// THE FORM
$TMPL['skins_list_header'] = $LNG['skins_list_header'];
$TMPL['skins_list_text'] = $LNG['skins_list_text'];
 
$TMPL['visitor_skin_list'] = "
<div style=\"display: block;list-style: none;text-align: center;width: 250px;height: auto;\">
<ul>
<li><b>{$TMPL['skins_list_header']}</b>&nbsp;&nbsp;&nbsp;
<form method=\"post\" action=\"index.php\">
<select class=\"blackonwhite\" name=\"stylesheet\"  size=\"1\"
onchange=\"this.form.submit();\">
<option value=\"choose2\">{$TMPL['skins_list_text']}</option>";
 
//define the path
$path = "skins";
$dir_handle = @opendir($path) or die("Unable to open $path");
while ($file = readdir($dir_handle)) {
  if($file!="." && $file!="..") {
if($file != "admin")
$TMPL['visitor_skin_list'] .= "<option value=\"$file\">$file</option>";
}
}
//closing the directory
closedir($dir_handle);
 
$TMPL['visitor_skin_list'] .= "</select>
<input type=\"hidden\">
</form>
</li>
</ul>
</div>";
 
//######## NEW CODE about SKIN_CHANGER  ########//
 
 
 
 
if(isset($FORM['a'])){
if($FORM['a'] == 'admin') {  $TMPL['skin_name'] = 'admin';}
}
i give up on converting this skin changer into a plugin, at least alone, i do not succeed
to complete all conditions together joined .........
 

Basti

Administrator
Staff member
hmm i think you made the skin changer a bit to complicated, but i may be a bit confused by all the coding you have posted until now :) Maybe i find the time within next week to make a simple skin changer plugin version 1. Will see.
 
Top