Browse files

added ignore_pattern and sort_with options

  • Loading branch information...
1 parent f1f3023 commit aa37d7a5d0eef43f976130271b8afd856a3ed378 unknown committed May 31, 2012
Showing with 47 additions and 5 deletions.
  1. +47 −5 pi.directory_contents.php
View
52 pi.directory_contents.php
@@ -12,7 +12,7 @@
$plugin_info = array(
'pi_name' => 'Directory Contents',
- 'pi_version' => '1.0',
+ 'pi_version' => '1.1',
'pi_author' => 'Justin Koivisto',
'pi_author_url' => 'http://koivi.com/ee-directory-contents',
'pi_description' => 'Reads directories from your filesystem to generate links or return lists',
@@ -34,6 +34,8 @@ class Directory_contents{
private $link_name;
private $inline_images;
private $tagdata;
+ private $ignore_pattern;
+ private $sort_with;
public function __construct(){
$this->EE =& get_instance();
@@ -50,6 +52,8 @@ public function __construct(){
$this->link_name = FALSE;
$this->inline_images = FALSE;
$this->tagdata = '';
+ $this->ignore_pattern = '';
+ $this->sort_with = 'sort';
// get parameter options
$this->set_options();
@@ -116,6 +120,29 @@ private function set_options(){
$this->span = TRUE;
}
+ // ignore pattern
+ $ignore_pattern = $this->EE->TMPL->fetch_param('ignore_pattern');
+ if(!empty($ignore_pattern)){
+ $this->ignore_pattern = $ignore_pattern;
+ }
+
+ // sorting function
+ $sort_with = $this->EE->TMPL->fetch_param('sort_with');
+ if(!empty($sort_with)){
+ switch($sort_with){
+ case 'sort':
+ case 'rsort':
+ case 'natcasesort':
+ case 'natsort':
+ case 'shuffle':
+ $this->sort_with = $sort_with;
+ break;
+ default:
+ $this->sort_with = 'sort';
+ break;
+ }
+ }
+
// tag pairs have data
$this->tagdata = $this->EE->TMPL->tagdata;
@@ -176,8 +203,9 @@ private function gen_tags($dir){
}
closedir($dh);
- // sort the items alphabetically
- sort($items);
+ // sort the items
+ $sort_with = $this->sort_with;
+ $sort_with($items);
foreach($items as $res){
if(is_dir($dir.'/'.$res)){
@@ -210,12 +238,19 @@ private function gen_links($dir, $level=0){
$items = array();
while($res = readdir($dh)){
if($res == '.' || $res == '..') continue;
+
+ // ignore pattern implementation
+ if(!empty($this->ignore_pattern) && preg_match($this->ignore_pattern, $res)){
+ continue;
+ }
+
$items[] = $res;
}
closedir($dh);
- // sort the items alphabetically
- sort($items);
+ // sort the items
+ $sort_with = $this->sort_with;
+ $sort_with($items);
foreach($items as $res){
// start this item's linking
@@ -295,6 +330,8 @@ function usage(){
add_level_class="no"
add_span="no"
images_inline="no"
+ ignore_pattern=""
+ sort_with="sort"
}
---------------------------------------------------------------------
(default values above)
@@ -315,6 +352,11 @@ function usage(){
* images_inline: [opt] if "yes" will generate <img> tags for image types rather than simply link them.
+ * ignore_pattern: [opt] a perl regular expression to use to match against a file/directory name to exclude from the output.
+
+ * sort_with: [opt] the name of the supported funtion to use to sort the directory contents with. one of: sort, rsort, natcasesort, natsort, shuffle
+
+
NOTE: You may use custom HTML for the image tag generation. For example:
{exp:directory_contents:links src="path" images_inline="yes"}
<div><a href="{DC_img_url}" rel="prettyPhoto"><img src="{DC_img_url}" /></a></div>

0 comments on commit aa37d7a

Please sign in to comment.