Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Blocks
Author Message
horror-code
New Member
New Member



Joined: Apr 29, 2013
Posts: 23

PostPosted: Fri May 03, 2013 2:44 am Reply with quote

I am trying to get the original theme preview block to work, and I previously made a post in another topic about this but it deserves it's own.

I did some testing but I came up with a funky list that contains all of the themes on one line without the ability to change them, obviously. Here are my changes:

Code:


<?php

/************************************************************************/
/* PHP-NUKE: Web Portal System                                          */
/* ===========================                                          */
/*                                                                      */
/* Copyright (c) 2002 by Francisco Burzi                                */
/* http://phpnuke.org                                                   */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/

if ( !defined('BLOCK_FILE') ) {
    Header('Location: ../index.php');
    die();
}

global $user, $userinfo, $Default_Theme, $cookie;

getusrinfo($user);
$content .= '<center>';
$content .= '<form action="modules.php?name=Your_Account" method="post">';
$content .= '<p></p>';
$content .= '<BR>';
$content .= '<select name="theme" onchange=submit();>';
$handle=opendir('themes');
while ($file = readdir($handle)) {
if ( (!ereg("[.]",$file)) ) {
$themelist .= '' . $file . '';
}
}
closedir($handle);
$themelist = explode(' ', $themelist);
sort($themelist);
for ($i=0; $i < sizeof($themelist); $i++) {
if($themelist[$i]!='') {
$content .= '<option value="' . $themelist[$i] . '"';
if((($userinfo[theme]=="") && ($themelist[$i]=="$Default_Theme")) || ($userinfo[theme]==$themelist[$i])) $content .= "selected";
$content .= '> ' . $themelist[$i] . 'n';
}
}
$content .= '</select>';

$content .= '<input type="hidden" name="storynum" value="$userinfo[storynum]">';
$content .= '<input type="hidden" name="ublockon" value="$userinfo[ublockon]">';
$content .= '<input type="hidden" name="ublock" value="$userinfo[ublock]">';
$content .= '<input type="hidden" name="uname" value="$userinfo[uname]">';
$content .= '<input type="hidden" name="user_id" value="$userinfo[user_id]">"';
$content .= '<input type="hidden" name="op" value="savetheme">';

$content .= '</form>';
$content .= '</center>';

?>


Cant even remember the original, but I'm betting I did something wrong...
 
View user's profile Send private message
neralex
Site Admin



Joined: Aug 22, 2007
Posts: 1772

PostPosted: Fri May 03, 2013 3:48 am Reply with quote

Your block-file use some old code. With PHP5 we can do it easier.

1. we need every time in a block the varible $content = ''; before we extend it like this $content .= '';
2. to scan a dir we can use in PHP5 scandir without to start a handle with opendir
3. ereg is since PHP5x deprecated and scandir loads all for us in an array
4. to make sure to catch really a folder, we can use is_dir for checking the directory
5. the field-names from the users-table are currently a little bit different but its only needed to catch the user_id
6. to catch the current theme we need the global $ThemeSel
7. at the end we spend a little bit much more love in the validation of the xHTML markup and we have a theme-switcher for users

Code:
<?php

if ( !defined('BLOCK_FILE') ) {Header('Location: ../index.php'); die();}
if (!defined('PHP_EOL')) define('PHP_EOL', strtoupper(substr(PHP_OS,0,3) == 'WIN') ? "\r\n" : "\n");
global $user, $ThemeSel;
$content = '';
if (is_user($user)) {
   $userinfo = getusrinfo($user);
   $folder = 'themes';
   if (is_dir($folder)) {
      $content .= '<form action="modules.php" method="post">' . PHP_EOL
              . '<div class="text-center">' . PHP_EOL
              . '<select name="theme" onchange="submit();">' . PHP_EOL;
      $themelist = scandir($folder);
      sort($themelist);
      $count_themelist = count($themelist);
      $exclude = array('.','..');
      for ($i=0; $i < $count_themelist; $i++) {
         if (is_dir($folder . '/' . $themelist[$i]) && !in_array($themelist[$i], $exclude)) {
            $content .= '   <option value="' . $themelist[$i] . '"' . ($themelist[$i] == $ThemeSel ? ' selected="selected"' : '') . '>' . $themelist[$i] . '</option>' . PHP_EOL;
         }
      }
      unset($themelist);
      $content .= '</select>' . PHP_EOL
              . '<input type="hidden" name="user_id" value="' . $userinfo['user_id'] . '" />' . PHP_EOL
              . '<input type="hidden" name="name" value="Your_Account" />' . PHP_EOL
              . '<input type="hidden" name="op" value="savetheme" />' . PHP_EOL
              . '</div>' . PHP_EOL
              . '</form>' . PHP_EOL;       
   }
} else {
   $userinfo = array();
   $content .= '<div class="text-center">Only for users!</div>' . PHP_EOL;
}


Wink

_________________
Github: RavenNuke 
View user's profile Send private message
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Blocks

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©