forked from sirkris/phpMeow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimagedir.phpmeow.class.php
More file actions
90 lines (77 loc) · 1.86 KB
/
imagedir.phpmeow.class.php
File metadata and controls
90 lines (77 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
/*
* phpMeow - A Cute and Fuzzy Alternative to CAPTCHA
* Created by Kris Craig. April - July, 2011.
*
* phpMeow is the first fully-functional, secure
* implementation of KittenAuth in PHP.
*
* This software is open-source and you're free to
* use and/or distribute it as you see fit. See
* LICENSE file for more information.
*
* Get the latest version at: http://www.github.com/sirkris/phpmeow
*/
class phpmeow_imagedir
{
function load_images_from_subdir( $dirpath )
{
if ( !is_dir( $dirpath ) || !is_readable( $dirpath ) )
{
return FALSE;
}
if ( $dh = opendir( $dirpath ) )
{
$images = array();
while ( ( $file = readdir( $dh ) ) !== FALSE )
{
/* Let's just keep it simple and stick to jpegs. If you change this, also change the GD2 load function to match. --Kris */
if ( strcasecmp( filetype( $dirpath . "/" . $file ), "file" ) == 0
&& strcasecmp( substr( $file, strlen( $file ) - 4, 4 ), ".jpg" ) == 0 )
{
$images[] = $dirpath . "/" . $file;
}
}
closedir( $dh );
return $images;
}
else
{
return FALSE;
}
}
function load_directories( $dirpath )
{
if ( !is_dir( $dirpath ) || !is_readable( $dirpath ) )
{
return FALSE;
}
if ( $dh = opendir( $dirpath ) )
{
$dirs = array();
while ( ( $file = readdir( $dh ) ) !== FALSE )
{
if ( strcasecmp( filetype( $dirpath . "/" . $file ), "dir" ) == 0
&& strcmp( $file, "." ) && strcmp( $file, ".." ) )
{
$dirs[] = $file;
}
}
closedir( $dh );
return $dirs;
}
}
function load_cute_fuzzy_animals( $basepath )
{
$animals = array();
if ( !( $dirs = self::load_directories( $basepath ) ) )
{
return FALSE;
}
foreach ( $dirs as $dkey => $dirname )
{
$animals[$dirname] = self::load_images_from_subdir( $basepath . "/" . $dirname );
}
return $animals;
}
}