Skip to content

Commit

Permalink
Refactored some code to work more logically
Browse files Browse the repository at this point in the history
  • Loading branch information
PHLAK committed May 8, 2013
1 parent ee6d938 commit d6b9303
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 33 deletions.
7 changes: 7 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
die($lister->getFileHash($_GET['hash']));
}

// Initialize the directory array
if (isset($_GET['dir'])) {
$dirArray = $lister->listDirectory($_GET['dir']);
} else {
$dirArray = $lister->listDirectory('.');
}

// Define theme path
if (!defined('THEMEPATH')) {
define('THEMEPATH', $lister->getThemePath());
Expand Down
74 changes: 42 additions & 32 deletions resources/DirectoryLister.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,6 @@ public function __construct() {
// Set the theme name
$this->_themeName = $this->_config['theme_name'];

// Set the directory global variable
if (isset($_GET['dir'])) {
$this->_directory = $this->_setDirecoryPath($_GET['dir']);
} else {
$this->_directory = $this->_setDirecoryPath(null);
}

}


Expand All @@ -71,7 +64,10 @@ public function __construct() {
*
* @param string $path Relative path of directory to list
*/
public function listDirectory($directory = null) {
public function listDirectory($directory) {

// Set directory
$this->setDirectoryPath($directory);

// Set directory varriable if left blank
if ($directory === null) {
Expand Down Expand Up @@ -194,30 +190,6 @@ public function getThemePath($absolute = false) {
}


/**
* Add a message to the system message array
*
* @param string $type The type of message (ie - error, success, notice, etc.)
* @param string $message The message to be displayed to the user
* @access public
*/
public function setSystemMessage($type, $text) {

// Create empty message array if it doesn't already exist
if (isset($this->_systemMessage) && !is_array($this->_systemMessage)) {
$this->_systemMessage = array();
}

// Set the error message
$this->_systemMessage[] = array(
'type' => $type,
'text' => $text
);

return true;
}


/**
* Get an array of error messages or false when empty.
*
Expand Down Expand Up @@ -275,6 +247,44 @@ public function getFileHash($filePath) {
}


/**
* Set directory path variable
*
* @param string $path Path to directory
* @access public
*/
public function setDirectoryPath($path = null) {

// Set the directory global variable
$this->_directory = $this->_setDirecoryPath($path);

}


/**
* Add a message to the system message array
*
* @param string $type The type of message (ie - error, success, notice, etc.)
* @param string $message The message to be displayed to the user
* @access public
*/
public function setSystemMessage($type, $text) {

// Create empty message array if it doesn't already exist
if (isset($this->_systemMessage) && !is_array($this->_systemMessage)) {
$this->_systemMessage = array();
}

// Set the error message
$this->_systemMessage[] = array(
'type' => $type,
'text' => $text
);

return true;
}


/**
* Validates and returns the directory path
*
Expand Down
2 changes: 1 addition & 1 deletion resources/themes/bootstrap/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
</div>

<ul id="directoryListing">
<?php $x = 1; foreach($lister->listDirectory() as $name => $fileInfo): ?>
<?php $x = 1; foreach($dirArray as $name => $fileInfo): ?>
<li class="<?php echo $x %2 == 0 ? 'even' : 'odd'; ?>">
<a href="<?php echo $fileInfo['file_path']; ?>" class="clearfix">
<span class="fileName">
Expand Down

0 comments on commit d6b9303

Please sign in to comment.