├── cache └── index.html ├── plugins ├── index.php ├── hook_list.txt ├── ads_plugin.php └── hello_plugin.php ├── lib ├── .htaccess ├── Snoopy.class.php ├── pagination.class.php ├── template.class.php ├── array_pagination.class.php ├── plugin.class.php ├── functions.php └── mysql.class.php ├── inc ├── .htaccess ├── settings.php └── init.php ├── tpl ├── plugin_manager.tpl ├── usr_set.tpl ├── admin_actions.tpl ├── .htaccess ├── style │ ├── favicon.ico │ ├── png │ │ ├── 3gp.png │ │ ├── 7z.png │ │ ├── asp.png │ │ ├── avi.png │ │ ├── bmp.png │ │ ├── css.png │ │ ├── dat.png │ │ ├── dmg.png │ │ ├── doc.png │ │ ├── eps.png │ │ ├── exe.png │ │ ├── fla.png │ │ ├── flv.png │ │ ├── gif.png │ │ ├── gz.png │ │ ├── ico.png │ │ ├── inf.png │ │ ├── jad.png │ │ ├── jar.png │ │ ├── jpg.png │ │ ├── js.png │ │ ├── jsp.png │ │ ├── mdb.png │ │ ├── mp3.png │ │ ├── mp4.png │ │ ├── mpg.png │ │ ├── ogg.png │ │ ├── pdf.png │ │ ├── php.png │ │ ├── png.png │ │ ├── pps.png │ │ ├── ppt.png │ │ ├── psd.png │ │ ├── rar.png │ │ ├── rtf.png │ │ ├── sis.png │ │ ├── swf.png │ │ ├── tar.png │ │ ├── tif.png │ │ ├── tmp.png │ │ ├── txt.png │ │ ├── vob.png │ │ ├── xls.png │ │ ├── xml.png │ │ ├── xpi.png │ │ ├── zip.png │ │ └── file.png │ ├── images │ │ ├── arr.gif │ │ ├── bdir.gif │ │ ├── body.gif │ │ ├── gdir.gif │ │ ├── grey1.png │ │ ├── logo.gif │ │ ├── title.gif │ │ ├── content.gif │ │ ├── folder.png │ │ ├── footer.gif │ │ ├── header.gif │ │ └── title2.gif │ └── style.css ├── footer.tpl ├── readme.txt ├── request.tpl ├── admin_pass.tpl ├── file.tpl ├── admin_upload_form.tpl ├── admin_options.tpl ├── index.tpl ├── header.tpl └── admin_import_form.tpl ├── lang ├── readme.txt └── index.php ├── .htaccess ├── logout.php ├── footer.php ├── header.php ├── icon.php ├── files └── .htaccess ├── usr_set.php ├── README.txt ├── Change_Log.txt ├── admincp ├── tpl_editor.php ├── index.php ├── plugin_market.php ├── import.php ├── upload.php ├── actions.php └── plugin_manager.php ├── tos.php ├── request.php ├── install.php ├── file.php ├── index.php ├── LICENSE.txt └── thumb.php /cache/index.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /plugins/index.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/.htaccess: -------------------------------------------------------------------------------- 1 | deny from all -------------------------------------------------------------------------------- /inc/.htaccess: -------------------------------------------------------------------------------- 1 | Options -Indexes -------------------------------------------------------------------------------- /tpl/plugin_manager.tpl: -------------------------------------------------------------------------------- 1 | {$content} 2 | -------------------------------------------------------------------------------- /tpl/usr_set.tpl: -------------------------------------------------------------------------------- 1 |
2 | {$form} 3 |
-------------------------------------------------------------------------------- /tpl/admin_actions.tpl: -------------------------------------------------------------------------------- 1 |
2 | {$form} 3 |
-------------------------------------------------------------------------------- /lang/readme.txt: -------------------------------------------------------------------------------- 1 | If you translate it please send it to ionutvmi@gmail.com -------------------------------------------------------------------------------- /tpl/.htaccess: -------------------------------------------------------------------------------- 1 | 2 | Order Allow,Deny 3 | Deny from all 4 | -------------------------------------------------------------------------------- /lib/Snoopy.class.php: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/lib/Snoopy.class.php -------------------------------------------------------------------------------- /tpl/style/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/favicon.ico -------------------------------------------------------------------------------- /tpl/style/png/3gp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/3gp.png -------------------------------------------------------------------------------- /tpl/style/png/7z.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/7z.png -------------------------------------------------------------------------------- /tpl/style/png/asp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/asp.png -------------------------------------------------------------------------------- /tpl/style/png/avi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/avi.png -------------------------------------------------------------------------------- /tpl/style/png/bmp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/bmp.png -------------------------------------------------------------------------------- /tpl/style/png/css.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/css.png -------------------------------------------------------------------------------- /tpl/style/png/dat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/dat.png -------------------------------------------------------------------------------- /tpl/style/png/dmg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/dmg.png -------------------------------------------------------------------------------- /tpl/style/png/doc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/doc.png -------------------------------------------------------------------------------- /tpl/style/png/eps.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/eps.png -------------------------------------------------------------------------------- /tpl/style/png/exe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/exe.png -------------------------------------------------------------------------------- /tpl/style/png/fla.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/fla.png -------------------------------------------------------------------------------- /tpl/style/png/flv.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/flv.png -------------------------------------------------------------------------------- /tpl/style/png/gif.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/gif.png -------------------------------------------------------------------------------- /tpl/style/png/gz.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/gz.png -------------------------------------------------------------------------------- /tpl/style/png/ico.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/ico.png -------------------------------------------------------------------------------- /tpl/style/png/inf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/inf.png -------------------------------------------------------------------------------- /tpl/style/png/jad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/jad.png -------------------------------------------------------------------------------- /tpl/style/png/jar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/jar.png -------------------------------------------------------------------------------- /tpl/style/png/jpg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/jpg.png -------------------------------------------------------------------------------- /tpl/style/png/js.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/js.png -------------------------------------------------------------------------------- /tpl/style/png/jsp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/jsp.png -------------------------------------------------------------------------------- /tpl/style/png/mdb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/mdb.png -------------------------------------------------------------------------------- /tpl/style/png/mp3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/mp3.png -------------------------------------------------------------------------------- /tpl/style/png/mp4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/mp4.png -------------------------------------------------------------------------------- /tpl/style/png/mpg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/mpg.png -------------------------------------------------------------------------------- /tpl/style/png/ogg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/ogg.png -------------------------------------------------------------------------------- /tpl/style/png/pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/pdf.png -------------------------------------------------------------------------------- /tpl/style/png/php.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/php.png -------------------------------------------------------------------------------- /tpl/style/png/png.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/png.png -------------------------------------------------------------------------------- /tpl/style/png/pps.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/pps.png -------------------------------------------------------------------------------- /tpl/style/png/ppt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/ppt.png -------------------------------------------------------------------------------- /tpl/style/png/psd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/psd.png -------------------------------------------------------------------------------- /tpl/style/png/rar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/rar.png -------------------------------------------------------------------------------- /tpl/style/png/rtf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/rtf.png -------------------------------------------------------------------------------- /tpl/style/png/sis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/sis.png -------------------------------------------------------------------------------- /tpl/style/png/swf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/swf.png -------------------------------------------------------------------------------- /tpl/style/png/tar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/tar.png -------------------------------------------------------------------------------- /tpl/style/png/tif.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/tif.png -------------------------------------------------------------------------------- /tpl/style/png/tmp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/tmp.png -------------------------------------------------------------------------------- /tpl/style/png/txt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/txt.png -------------------------------------------------------------------------------- /tpl/style/png/vob.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/vob.png -------------------------------------------------------------------------------- /tpl/style/png/xls.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/xls.png -------------------------------------------------------------------------------- /tpl/style/png/xml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/xml.png -------------------------------------------------------------------------------- /tpl/style/png/xpi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/xpi.png -------------------------------------------------------------------------------- /tpl/style/png/zip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/zip.png -------------------------------------------------------------------------------- /tpl/style/images/arr.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/images/arr.gif -------------------------------------------------------------------------------- /tpl/style/png/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/png/file.png -------------------------------------------------------------------------------- /tpl/style/images/bdir.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/images/bdir.gif -------------------------------------------------------------------------------- /tpl/style/images/body.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/images/body.gif -------------------------------------------------------------------------------- /tpl/style/images/gdir.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/images/gdir.gif -------------------------------------------------------------------------------- /tpl/style/images/grey1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/images/grey1.png -------------------------------------------------------------------------------- /tpl/style/images/logo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/images/logo.gif -------------------------------------------------------------------------------- /tpl/style/images/title.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/images/title.gif -------------------------------------------------------------------------------- /tpl/style/images/content.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/images/content.gif -------------------------------------------------------------------------------- /tpl/style/images/folder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/images/folder.png -------------------------------------------------------------------------------- /tpl/style/images/footer.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/images/footer.gif -------------------------------------------------------------------------------- /tpl/style/images/header.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/images/header.gif -------------------------------------------------------------------------------- /tpl/style/images/title2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BaseMax/master_autoindex/HEAD/tpl/style/images/title2.gif -------------------------------------------------------------------------------- /tpl/footer.tpl: -------------------------------------------------------------------------------- 1 | 2 | 3 |
© 2012 master-land.net
4 | 5 | -------------------------------------------------------------------------------- /tpl/readme.txt: -------------------------------------------------------------------------------- 1 | Instead of editing this files i suggest you make a plugin :) it's as easy as 1,2,3 2 | Also if you want to you can share it www.master-land.net or ionutvmi@gmail.com 3 | Open Source makes the world a better place -------------------------------------------------------------------------------- /tpl/request.tpl: -------------------------------------------------------------------------------- 1 | {$add} 2 |
3 |
4 |
5 | 6 |
7 |
8 | {$requests} 9 |
10 | {$show_pages} 11 |
-------------------------------------------------------------------------------- /.htaccess: -------------------------------------------------------------------------------- 1 | # Master Autoindex 2 | # 2012 master-land.net 3 | # ionutvmi@gmail.com 4 | 5 | RewriteEngine On 6 | RewriteRule ^data/([0-9]+)/(.*).html$ index.php?dir=$1 [QSA,L] 7 | RewriteRule ^data/file/([0-9]+)/(.*).html$ file.php?id=$1 [QSA,L] 8 | 9 | -------------------------------------------------------------------------------- /tpl/admin_pass.tpl: -------------------------------------------------------------------------------- 1 |
2 | {$password}
3 |
4 |
5 | 6 | 7 |
8 |
-------------------------------------------------------------------------------- /tpl/file.tpl: -------------------------------------------------------------------------------- 1 | {$_admin} 2 |
{$show_icon}
3 |
{$name}
4 |
{$description}
5 |
{$size}
6 |
{$views}
7 |
{$time}
8 |
{$dloads}
9 | {$extra_img} 10 | {$download} 11 | -------------------------------------------------------------------------------- /logout.php: -------------------------------------------------------------------------------- 1 | url); 10 | setcookie("pass", 0, time() - 3600 * 24 * 30, $path_info['path']); // delete 11 | 12 | header("Location: ".$_SERVER["HTTP_REFERER"]); -------------------------------------------------------------------------------- /inc/settings.php: -------------------------------------------------------------------------------- 1 | db_name = "test"; 8 | $set->db_user = "root"; 9 | $set->db_host = "localhost"; 10 | $set->db_pass = ""; 11 | 12 | 13 | $set->name = "Master Autoindex"; // site name 14 | $set->url = "http://localhost/autoindex"; // site url 15 | $set->logo = "http://master-land.net/images/logo.png"; // logo url (full url http://site.com/logo.png) 16 | $set->perpage = "10"; // how many records per page 17 | define("MAI_PREFIX","mai_"); -------------------------------------------------------------------------------- /footer.php: -------------------------------------------------------------------------------- 1 | run_hook("footer_top"); 7 | 8 | $footer = " $lang->Home | $lang->TOS | $lang->admin_panel"; 9 | if($_SESSION['adminpass']) 10 | $footer .= " | $lang->logout "; 11 | 12 | $tpl->grab('footer.tpl','footer'); 13 | $tpl->assign('footer',$footer); 14 | 15 | $tpl->display(); 16 | 17 | 18 | $plugins->run_hook("footer_end"); 19 | 20 | hmmm 21 | -------------------------------------------------------------------------------- /tpl/admin_upload_form.tpl: -------------------------------------------------------------------------------- 1 |
2 | {$message} 3 | {$upload_files} 4 |
6 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | {$max_file_size} 21 |
-------------------------------------------------------------------------------- /header.php: -------------------------------------------------------------------------------- 1 | run_hook("header_top"); 8 | 9 | if(!$title) 10 | $title = strip_tags(end($links)); 11 | 12 | 13 | $title = $title." - ". $set->name; 14 | $logo = empty($set->logo) ? $set->name : "logo"; 15 | 16 | // $links should be defined in inc/init.php as an array 17 | if(is_array($links)) 18 | foreach($links as $link) 19 | $_links .= $link." "; 20 | 21 | $tpl->grab('header.tpl','header'); 22 | $tpl->assign('title',$title); 23 | $tpl->assign('logo',$logo); 24 | $tpl->assign('url',$set->url); 25 | $tpl->assign('links',$_links); 26 | $tpl->display(); 27 | 28 | $plugins->run_hook("header_end"); -------------------------------------------------------------------------------- /tpl/admin_options.tpl: -------------------------------------------------------------------------------- 1 | {$update_av} 2 |
3 | {$mark} {$file_manager}
4 | {$mark} {$upload_files}
5 | {$mark} {$import_files}
6 | {$mark} {$request} {$request_new}
7 | {$mark} {$settings}
8 | {$mark} {$plugin_manager}
9 | {$mark} {$tpl_editor}
10 | {$mark} {$plugins_market}
11 |
12 |
©MAI V{$version}
-------------------------------------------------------------------------------- /icon.php: -------------------------------------------------------------------------------- 1 | run_hook("icon_top"); 6 | 7 | $file = substr(base64_decode($_GET["s"]),1); 8 | $q = array("icon.png","ico.png","i.png","icono.png","Icon.png","Ico.png","I.png","Icono.png","ICON.png","ICO.png","I.png","ICONO.png","ICON.PNG","ICO.PNG","I.PNG","ICONO.PNG","icons/icon.png","icons/ico.png","icons/i.png","icons/icono.png","i","I","i1.png","AppIcon01.png"); 9 | $zip = new PclZip($file); 10 | $ar = $zip->extract(PCLZIP_OPT_BY_NAME,$q,PCLZIP_OPT_EXTRACT_IN_OUTPUT); 11 | 12 | $plugins->run_hook("icon"); 13 | 14 | if(!empty($ar)) { 15 | header("Content-type: image/png"); 16 | }else { 17 | $cz=file_get_contents(MAI_TPL."style/png/jar.png"); 18 | header("Content-type: image/png"); 19 | echo $cz; 20 | } 21 | 22 | $plugins->run_hook("icon_end"); -------------------------------------------------------------------------------- /tpl/index.tpl: -------------------------------------------------------------------------------- 1 |
2 | {$admin} {$main_msg} 3 | {$updates} 4 |
5 | 11 |
{$downloads_menu}
{$description}
12 |
13 | {$show_order} 14 |
15 | {$_admin2} 16 | {$folders} 17 | {$files} 18 |
19 | {$show_pages} 20 |
21 |
{$extra}
22 |
. {$settings}
23 |
. {$request}
24 | -------------------------------------------------------------------------------- /tpl/header.tpl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | {$title} 10 | 11 | 12 | 13 | 14 | 15 | 16 |
{$logo}
17 | 18 | 19 | 20 | 23 | -------------------------------------------------------------------------------- /files/.htaccess: -------------------------------------------------------------------------------- 1 | # blocheaza accesul la fisierul htaccess 2 | 3 | 4 | 5 | order allow,deny 6 | 7 | deny from all 8 | 9 | 10 | 11 | AddType application/octet-stream .csv 12 | AddType application/octet-stream .xls 13 | AddType application/octet-stream .doc 14 | AddType application/octet-stream .avi 15 | AddType application/octet-stream .mpg 16 | AddType application/octet-stream .mov 17 | AddType application/octet-stream .pdf 18 | AddType application/octet-stream .jpg 19 | AddType application/octet-stream .jpeg 20 | AddType application/octet-stream .gif 21 | AddType application/octet-stream .3gp 22 | AddType application/octet-stream .mp4 23 | AddType application/octet-stream .txt 24 | 25 | # blocheaza executarea anumitor fisiere 26 | 27 | RemoveType .pl .cgi .php .php3 .php4 .php5 .xml .phtml .phtm .html .htm .wml .shtm .shtml .asp 28 | 29 | RemoveHandler .pl .cgi .php .php3 .php4 .php5 .xml .phtml .phtm .html .htm .wml .shtm .shtml .asp 30 | 31 | #php_flag engine off 32 | 33 | Options -Indexes 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /usr_set.php: -------------------------------------------------------------------------------- 1 | run_hook("usr_set_top"); 8 | 9 | $links[] = mai_img("arr.gif")." $lang->settings "; 10 | 11 | if($_POST['items']){ 12 | $_SESSION['perp'] = (int)$_POST['items']; 13 | $form .= "
$lang->saved
"; 14 | } 15 | 16 | $form .= "
17 | 18 | $lang->elements_per_page: 19 | 28 | 29 | 30 |
31 | 32 |
"; 33 | 34 | 35 | include "header.php"; 36 | $tpl->grab("usr_set.tpl","usr_set"); 37 | $tpl->assign("form",$form); 38 | $tpl->display(); 39 | 40 | $plugins->run_hook("usr_set_end"); 41 | include "footer.php"; -------------------------------------------------------------------------------- /lib/pagination.class.php: -------------------------------------------------------------------------------- 1 | $v) 16 | if($k != 'page') 17 | $query .= "&$k=$v"; 18 | 19 | if($page > 4) 20 | $this->pages .= "$lang->first "; 21 | 22 | if($page > 1) 23 | $this->pages .= "$lang->prev "; 24 | 25 | for($i = max(1, $page - 3); $i <= min($page + 3, $total_pages); $i++) 26 | $this->pages .= ($i == $page ? $i : " $i "); 27 | 28 | if($page < $total_pages) 29 | $this->pages .= "$lang->next"; 30 | 31 | if($page < $total_pages-3) 32 | $this->pages .= " $lang->last "; 33 | 34 | return true; 35 | } 36 | } -------------------------------------------------------------------------------- /tpl/admin_import_form.tpl: -------------------------------------------------------------------------------- 1 |
2 | {$message} 3 | {$import_files} 4 |
5 |
9 | {$url} | {$name}
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 |
20 |
21 |
-------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | /******************** 2 | * * 3 | * ionutvmi * 4 | * MASTER AUTOINDEX * 5 | * v 1.0.6 BETA * 6 | * * 7 | ********************/ 8 | 9 | This source may contain some beta features 10 | if you are looking for the stable release go to 11 | 12 | http://master-land.net/autoindex 13 | 14 | 15 | /*** REQUIREMENTS **/ 16 | PHP5 17 | MYSQL5 18 | A WEB BROWSER 19 | 20 | /****** INSTALL ****/ 21 | 1. unzip the archive 22 | 2. upload to your server 23 | 3. run yoursite/install.php 24 | 4. complete the fields required and you should be done 25 | 5. enjoy 26 | 27 | /******* support ******/ 28 | if you like this script share it with everybody 29 | also if you are good with php you can make some plugins 30 | you can share them on www.master-land.net 31 | 32 | /******* bugs ******/ 33 | I'M STILL TESTING THIS SCRIPT SO IF YOU FIND ANY BUGS PLEASE REPORT IT AT ionutvmi@gmail.com also you can get help on master-land.net 34 | 35 | /**** DONATIONS ****/ 36 | If you want to support the development of this app you can donate via PayPal: ionutvmi@gmail.com 37 | 38 | Thank you, 39 | ionutvmi@gmail.com -------------------------------------------------------------------------------- /Change_Log.txt: -------------------------------------------------------------------------------- 1 | V 1.0.6 - To be released 2 | - remember me on admincp added 3 | - error in add new folder fix needed 4 | - mysql compatibility added 5 | - fix folder & files display based on sorting (added new column isdir in files table) 6 | - diable force download use header() instead 7 | - plugins _on_save() function added 8 | - easy install for plugins directly from admincp added 9 | 10 | ---------------------- 11 | V 1.0.5 - 11 Feb 2013 12 | - fixed php 5.4 object bug 13 | - if the admin message is blank nothing is shown in the index page 14 | - pagination in plugin manager added 15 | - new hooks on index page 16 | 17 | ---------------------- 18 | V 1.0.4 - 16 Oct 2012 19 | - magic quote bug fixed 20 | - added description option in edit menu 21 | 22 | ---------------------- 23 | V 1.0.2 - 28 Sep 2012 24 | - preview bug fixed 25 | - added protection against shell files 26 | 27 | ---------------------- 28 | V 1.0.1 - 26 Sep 2012 29 | - important bugs fixed 30 | - option to move files/dir added 31 | 32 | * new plugins - http://master-land.net/f/37/plugins.html 33 | ---------------------- 34 | V 1.0 BETA - 22 Sep 2012 - Initial Relese 35 | * plugins - http://master-land.net/f/37/plugins.html 36 | * bugs - http://master-land.net/f/38/bugs.html -------------------------------------------------------------------------------- /lib/template.class.php: -------------------------------------------------------------------------------- 1 | strBuffer = $plugins->run_hook($strHook,file_get_contents(MAI_ROOT . MAI_TPL .$strFile)); 25 | return true; 26 | } 27 | 28 | /** 29 | * Replace the vars from teplate with the specific value 30 | * 31 | * @param string The var name. 32 | * @param string The var value. 33 | * @return boolean Always true. 34 | */ 35 | public function assign( $strVar, $strValue ) { 36 | $this->strBuffer = str_replace($this->strBeginTag . '$' . $strVar . $this->strEndTag , $strValue, $this->strBuffer); 37 | return true; 38 | } 39 | 40 | 41 | // display the final result 42 | public function display() { 43 | echo $this->strBuffer; 44 | } 45 | } 46 | ?> -------------------------------------------------------------------------------- /lib/array_pagination.class.php: -------------------------------------------------------------------------------- 1 | perPage = $perPage; 24 | 25 | // Assign the page variable 26 | if (!empty($_GET['page'])) { 27 | $this->page = $_GET['page']; // using the get method 28 | } else { 29 | $this->page = 1; // if we don't have a page number then assume we are on the first page 30 | } 31 | 32 | // Take the length of the array 33 | $this->length = count($array); 34 | 35 | // Get the number of pages 36 | $this->pages = ceil($this->length / $this->perPage); 37 | 38 | if($this->page > $this->pages) $this->page=$this->pages; 39 | 40 | // Calculate the starting point 41 | $this->start = ceil(($this->page - 1) * $this->perPage); 42 | 43 | // Return the part of the array we have requested 44 | return array_slice($array, $this->start, $this->perPage); 45 | } 46 | 47 | 48 | } -------------------------------------------------------------------------------- /plugins/hook_list.txt: -------------------------------------------------------------------------------- 1 | /inc/init.php 2 | init 3 | /header.php 4 | header_top 5 | header 6 | header_end 7 | /footer.php 8 | footer_top 9 | footer 10 | footer_end 11 | /icon.php 12 | icon_top 13 | icon 14 | icon_end 15 | /index.php 16 | index_top 17 | index_updates 18 | index_admin 19 | index_search 20 | index_order 21 | index_folders 22 | index_folders_end 23 | index_files_top 24 | index_files 25 | index_files_end 26 | index 27 | index_end 28 | /request.php 29 | request_top 30 | request_ins 31 | request_rpl 32 | request_del 33 | request 34 | request_end 35 | /functions.php 36 | mai_img 37 | /admincp/index.php 38 | admin_end 39 | admin_top 40 | admin_pass 41 | admin_options 42 | /admincp/upload.php 43 | admin_upload_form_top 44 | admin_upload_form_post 45 | admin_upload_form_jad_top 46 | admin_upload_form_jad 47 | admin_upload_form_mid_top 48 | admin_upload_form_mid 49 | admin_upload_form 50 | admin_upload_form_end 51 | /admincp/import.php 52 | admin_import_form_top 53 | admin_import_form_jad 54 | admin_import_form_mid 55 | admin_import_form_jad_top 56 | admin_import_form_mid_top 57 | admin_upload_form_mid 58 | admin_import_form 59 | admin_import_form_post 60 | admin_import_form_end 61 | /admincp/actions.php 62 | admin_actions_top 63 | admin_actions_add 64 | admin_actions_add_top 65 | admin_actions_add_end 66 | admin_actions_edit_top 67 | admin_actions_edit 68 | admin_actions_editset_top 69 | admin_actions_editset 70 | admin_actions_editset_end 71 | admin_actions_delete_top 72 | admin_actions_delete_a 73 | admin_actions_delete_b 74 | admin_actions_delete_end 75 | admin_actions 76 | admin_actions_end 77 | /file.php 78 | file_top 79 | file_mid 80 | file 81 | download 82 | file_end 83 | /usr_set.php 84 | usr_set_top 85 | usr_set 86 | usr_set_end 87 | /admincp/tpl_editor.php 88 | tpl_editor_top 89 | tpl_editor 90 | tpl_editor_end 91 | -------------------------------------------------------------------------------- /inc/init.php: -------------------------------------------------------------------------------- 1 | url 17 | $set->url = rtrim($set->url, "/"); 18 | 19 | include MAI_ROOT."lib/mysql.class.php"; 20 | include MAI_ROOT."lib/plugin.class.php"; 21 | include MAI_ROOT."lib/template.class.php"; 22 | include MAI_ROOT."lang/index.php"; 23 | include MAI_ROOT."lib/functions.php"; 24 | 25 | // make $lang an object 26 | $lang = (object)$lang; 27 | // template object 28 | $tpl = new Tpl(); 29 | 30 | // version 31 | $set->version = '1.0.6 BETA'; 32 | 33 | // db connection 34 | $db = new dbConn($set->db_host,$set->db_user,$set->db_pass,$set->db_name); 35 | 36 | 37 | $set->sinfo = $db->get_row("SELECT * FROM `". MAI_PREFIX ."settings`"); 38 | 39 | if(!$set->sinfo){ 40 | header("Location: install.php"); 41 | exit; 42 | } 43 | 44 | 45 | // check if we have any cookie saved 46 | if($_COOKIE['pass'] == $set->sinfo->admin_pass) 47 | $_SESSION['adminpass'] = $set->sinfo->admin_pass; 48 | 49 | 50 | // get the settings for plugins 51 | if(!is_array(unserialize($set->sinfo->active_plugins))) 52 | $set->sinfo->active_plugins = serialize(array()); 53 | 54 | $_PS = $db->select("SELECT `name`,`value` FROM `".MAI_PREFIX."plugins_settings`"); 55 | if($_PS){ 56 | foreach($_PS as $__PS){ 57 | $set->plugins[$__PS->name] = $__PS->value; 58 | } 59 | } 60 | 61 | // plugins object 62 | $plugins = new Plugins(); 63 | $plugins->load(); 64 | 65 | 66 | 67 | 68 | $links[] = mai_img("arr.gif")." $lang->Home"; 69 | 70 | $plugins->run_hook("init"); 71 | 72 | remove_magic_quotes(); -------------------------------------------------------------------------------- /admincp/tpl_editor.php: -------------------------------------------------------------------------------- 1 | run_hook("tpl_editor_top"); 14 | 15 | if(!is_admin()) { 16 | ob_end_clean(); 17 | header("Location: $set->url");exit; 18 | } 19 | 20 | $links[] = mai_img("arr.gif")." $lang->admincp "; 21 | $links[] = mai_img("arr.gif")." $lang->tpl_editor"; 22 | 23 | 24 | $act = $_GET['act']; 25 | 26 | if($act == 'edit') { 27 | 28 | $file = MAI_ROOT."/".MAI_TPL."/".$_GET['f']; 29 | if(!file_exists($file)) 30 | die("File does not exists !"); 31 | 32 | $links[] = mai_img("arr.gif")." ".basename($file).""; 33 | 34 | if($_POST) 35 | if(file_put_contents($file, $_POST['data'])) 36 | $content .= "
$lang->saved
"; 37 | else 38 | $content .= "
$lang->error
"; 39 | 40 | 41 | 42 | $content .= "
43 |
44 |
45 | 46 |
47 |
"; 48 | 49 | } else { 50 | 51 | $files = glob(MAI_ROOT."/".MAI_TPL."*.tpl"); 52 | if($files) 53 | foreach($files as $file) 54 | $content .= "
» ".basename($file)." ".convert(filesize($file))."
"; 55 | $content .= "
$lang->tpl_notice
"; 56 | } 57 | 58 | 59 | include "../header.php"; 60 | $plugins->run_hook("tpl_editor"); 61 | echo $content; 62 | $plugins->run_hook("tpl_editor_end"); 63 | include "../footer.php"; -------------------------------------------------------------------------------- /lib/plugin.class.php: -------------------------------------------------------------------------------- 1 | hooks[$hook])) // Fire a callback 26 | { 27 | foreach($this->hooks[$hook] as $function) 28 | { 29 | $value = call_user_func($function, $value); 30 | } 31 | return $value; 32 | }else{ 33 | return $value; 34 | } 35 | } 36 | 37 | /** 38 | * Add a hook onto which a plugin can be attached. 39 | * 40 | * @param string The hook name. 41 | * @param string The function of this hook. 42 | * @return boolean Always true. 43 | */ 44 | 45 | function add_hook($hook,$function){ 46 | 47 | $this->hooks[$hook][] = $function; 48 | return true; 49 | } 50 | 51 | 52 | /** 53 | * Load plugin files 54 | * 55 | * @return boolean Always true. 56 | */ 57 | function load($all = false){ 58 | global $plugins,$set; 59 | 60 | $files = glob(MAI_ROOT."plugins/*_plugin.php"); 61 | // grab active plugins list 62 | if(!is_array(unserialize($set->sinfo->active_plugins))) 63 | $set->sinfo->active_plugins = serialize(array()); 64 | 65 | foreach($files as $file){ 66 | // grab plugin name 67 | $pname = substr(basename($file),0,-11); 68 | // require active plugins 69 | if($all == false){ 70 | if(in_array($pname,unserialize($set->sinfo->active_plugins))) 71 | require_once($file); 72 | }else { 73 | if(!in_array(basename($file),array_map("basename",get_included_files()))) 74 | require_once($file); 75 | } 76 | } 77 | if($all) 78 | $this->hooks = array(); // we don't execute on plugin manager 79 | return true; 80 | } 81 | 82 | } -------------------------------------------------------------------------------- /admincp/index.php: -------------------------------------------------------------------------------- 1 | run_hook("admin_top"); 8 | 9 | $links[] = mai_img("arr.gif")." $lang->admincp"; 10 | 11 | 12 | 13 | if(((sha1($_POST['pass']) == $set->sinfo->admin_pass) && ($_POST['token'] == $_SESSION['token'])) OR is_admin()) { 14 | $_SESSION['token'] = ''; 15 | 16 | if($_POST['r'] == 1) { 17 | $path_info = parse_url($set->url); 18 | setcookie("pass", sha1($_POST['pass']), time() + 3600 * 24 * 30, $path_info['path']); // 30 days 19 | } 20 | 21 | if(!$_SESSION['adminpass']){ 22 | $_SESSION['adminpass'] = sha1($_POST['pass']); 23 | if($set->version != @file_get_contents("http://master-land.net/autoindex/updates.txt")) 24 | $update_av = "
A NEW VERSION IS AVAILABLE
"; 25 | } 26 | $request_new = "(".$db->count("SELECT `id` FROM `".MAI_PREFIX."request` WHERE `reply`=''").")"; 27 | 28 | include "../header.php"; 29 | $tpl->grab('admin_options.tpl','admin_options'); 30 | $tpl->assign('password',$lang->password); 31 | $tpl->assign('url',$set->url); 32 | $tpl->assign('import_files',$lang->import_files); 33 | $tpl->assign('settings',$lang->settings); 34 | $tpl->assign('update_av',$update_av); 35 | $tpl->assign('login',$lang->login); 36 | $tpl->assign('request',$lang->request); 37 | $tpl->assign('request_new',$request_new); 38 | $tpl->assign('file_manager',$lang->file_manager); 39 | $tpl->assign('plugin_manager',$lang->plugin_manager); 40 | $tpl->assign('tpl_editor',$lang->tpl_editor); 41 | $tpl->assign('plugins_market',$lang->plugins_market); 42 | $tpl->assign('upload_files',$lang->upload_files); 43 | $tpl->assign('mark',mai_img('arr.gif')); 44 | $tpl->assign('version',$set->version); 45 | }else{ 46 | $token = $_SESSION['token'] = md5(rand()); 47 | 48 | include "../header.php"; 49 | $tpl->grab('admin_pass.tpl','admin_pass'); 50 | $tpl->assign('password',$lang->password); 51 | $tpl->assign('token',$token); 52 | $tpl->assign('login',$lang->login); 53 | $tpl->assign('remember', $lang->remember); 54 | 55 | } 56 | $tpl->display(); 57 | $plugins->run_hook("admin_end"); 58 | include "../footer.php"; 59 | 60 | ?> -------------------------------------------------------------------------------- /tos.php: -------------------------------------------------------------------------------- 1 | TOS"; 10 | include "header.php"; 11 | 12 | echo "
$lang->terms_of_service
".nl2br("YOU EXPRESSLY AGREE THAT USE OF THE SERVICE IS AT YOUR SOLE RISK AND THAT THE SERVICE IS PROVIDED ON AN \"AS IS\" AND \"AS AVAILABLE\" BASIS. $set->name, ITS AFFILIATES, AND THEIR OFFICERS, DIRECTORS, EMPLOYEES, AND AGENTS (HEREINAFTER \"$set->name GROUP\") DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. 13 | 14 | $set->name GROUP MAKES NO WARRANTIES OR REPRESENTATIONS ABOUT THE ACCURACY OR COMPLETENESS OF THE CONTENT PROVIDED ON OR VIA THE SERVICE AND $set->name GROUP ASSUMES NO LIABILITY OR RESPONSIBILITY FOR ANY (I) ERRORS, OMISSIONS OR INACCURACIES OF CONTENT OR SUBMISSIONS, (II) PERSONAL INJURY OR PROPERTY DAMAGE OF ANY NATURE RESULTING FROM YOUR ACCESS TO AND USE OF THE SERVICE, (III) ANY UNAUTHORIZED ACCESS TO OR USE OF OUR SECURE SERVERS AND/OR ANY AND ALL PERSONAL INFORMATION AND/OR FINANCIAL INFORMATION THAT MAY BE CONTAINED THEREIN, (IV) ANY DELETION OF DATA OR INTERRUPTION OR DISCONTINUENCE OF TRANSMISSION TO OR FROM OR THROUGH THE SERVICE, (IV) ANY BUGS, VIRUSES, TROJAN HORSES, MALICIOUS CODE OR THE LIKE WHICH MAY BE TRANSMITTED TO OR THROUGH THE SERVICE BY ANY USER OR THIRD PARTY, AND/OR (V) ANY ERRORS OR OMISSIONS IN ANY CONTENT OR FOR ANY LOSS OR DAMAGE OF ANY KIND INCURRED AS A RESULT OF THE USE OF ANY CONTENT OR SUBMISSIONS THAT MAY BE UPLOADED TO OR OTHERWISE MADE AVAILABLE THROUGH THE SERVICE. 15 | 16 | $set->name GROUP IS NOT RESPONSIBLE FOR ANY CONTENT OR TRANSACTIONS THAT IS CONTAINED OR MAY BE AVAILABLE OUTSIDE THE SERVICE. $set->name GROUP MAKES NO REPRESENTATIONS, WARRANTEES, GUARANTEES OR ANY ENDORSEMENTS AS TO THE QUALITY, SUITABILITY, FUNCTIONALITY OR LEGALITY OF ANY PRODUCTS, SERVICES OR OTHER OFFERINGS THAT MAY BE ADVERTISED OR MADE AVAILABLE BY A THIRD PARTY THROUGH THE SERVICE OR WHICH MAY BE LINKED TO THE SERVICE SUCH AS IN ADVERTISING OR A SUBMISSION. ACCORDINGLY, $set->name GROUP WILL NOT BE A PARTY TO OR IN ANY WAY BE RESPONSIBLE FOR ANY TRANSACTION THAT MAY OCCUR BETWEEN YOU AND SUCH THIRD PARTIES AND YOU SHOULD ALWAYS USE PRUDENT JUDGMENT AND READ THE PRIVACY POLICIES ON WEBSITES OF SUCH THIRD PARTIES. 17 | 18 | $set->name reserves the right to change any and all content, software and other items used or contained at $set->name and any services and applications offered through the $set->name site at any time without notice.")."
"; 19 | 20 | include "footer.php"; -------------------------------------------------------------------------------- /plugins/ads_plugin.php: -------------------------------------------------------------------------------- 1 | add_hook("header","ads_show_top"); 20 | $plugins->add_hook("footer","ads_show_foot"); 21 | 22 | function ads_info(){ 23 | 24 | return array( 25 | "name" => "Adverts Plugin", 26 | "author" => "ionutvmi", 27 | "author_site" => "http://master-land.net", 28 | "description" => "it will display html ads in header and/or footer", 29 | ); 30 | 31 | } 32 | 33 | function ads_install(){ 34 | global $db; 35 | // settings 36 | $settings_data = array( 37 | "name" => "ads_show", // name of the setting must be unique so adding the plugin name is a good practice 38 | "value" => "2", // default value 39 | "title" => "Place ads on:", // title will be displayed on settings page 40 | "description" => "the place where the ads will be displayed", // description 41 | "type" => "select \n 0=Top \n 1=Bottom \n 2=Both", // type check master-land.net for more info 42 | "plugin" => "ads", // your plugin 43 | ); 44 | $settings_data2 = array( 45 | "name" => "ads_show_text_top", 46 | "value" => "Top ad text", 47 | "title" => "Top Ad", 48 | "description" => "the ad content that will be placed in header", 49 | "type" => "textarea", 50 | "plugin" => "ads", 51 | ); 52 | $settings_data3 = array( 53 | "name" => "ads_show_text_foot", 54 | "value" => "Footer ad text", 55 | "title" => "Footer Ad", 56 | "description" => "the ad content that will be placed in footer", 57 | "type" => "textarea", 58 | "plugin" => "ads", 59 | ); 60 | $db->insert_array(MAI_PREFIX."plugins_settings",$settings_data); 61 | $db->insert_array(MAI_PREFIX."plugins_settings",$settings_data2); 62 | $db->insert_array(MAI_PREFIX."plugins_settings",$settings_data3); 63 | 64 | } 65 | 66 | function ads_is_installed(){ 67 | global $db; 68 | if($db->count("SELECT `name` FROM `".MAI_PREFIX."plugins_settings` WHERE `plugin`='ads'") > 0) 69 | return true; 70 | 71 | return false; 72 | } 73 | 74 | function ads_uninstall(){ 75 | global $db; 76 | $db->query("DELETE FROM `".MAI_PREFIX."plugins_settings` WHERE `plugin`='ads'"); 77 | } 78 | 79 | // no special activate/deactivate required here 80 | 81 | function ads_show_top($value){ 82 | global $db,$set; 83 | 84 | if($set->plugins["ads_show"] == '0' OR $set->plugins["ads_show"] == '2') 85 | $value = str_replace("","".$set->plugins["ads_show_text_top"],$value); 86 | 87 | return $value; 88 | } 89 | 90 | function ads_show_foot($value){ 91 | global $db,$set; 92 | 93 | if($set->plugins["ads_show"] == '1' OR $set->plugins["ads_show"] == '2') 94 | $value = str_replace("","".$set->plugins["ads_show_text_foot"],$value); 95 | 96 | return $value; 97 | } -------------------------------------------------------------------------------- /request.php: -------------------------------------------------------------------------------- 1 | run_hook("request_top"); 10 | 11 | $links[] = mai_img("arr.gif")." $lang->request "; 12 | 13 | 14 | if($_POST['rq']){ 15 | $request_text = $_POST['rq']; 16 | if($request_text[10] && !$_COOKIE['ss']){ 17 | $db->query("INSERT INTO `".MAI_PREFIX."request` SET `text`='".$db->escape($request_text)."'"); 18 | $add = "
$lang->req_added
"; 19 | setcookie('ss',md5(1),time()+3600*12); 20 | $plugins->run_hook("request_ins"); 21 | }else{ 22 | $add = "
$lang->req_limit
"; 23 | } 24 | } 25 | if($_POST['reply'] && is_admin()){ 26 | $plugins->run_hook("request_rpl"); 27 | $db->query("UPDATE `".MAI_PREFIX."request` SET `reply` = '".$db->escape($_POST['reply'])."' WHERE `id`='".(int)$_POST['req']."'"); 28 | header("Location: ?page=$page"); 29 | } 30 | if($_GET['delete'] && is_admin()){ 31 | $plugins->run_hook("request_del"); 32 | $db->query("DELETE FROM `".MAI_PREFIX."request` WHERE `id`='".(int)$_GET['req']."'"); 33 | header("Location: ?page=$page"); 34 | } 35 | 36 | if(!is_admin()) 37 | $where_text = "WHERE `reply` != ''"; 38 | // pagination 39 | $total_results = $db->count("SELECT * FROM `".MAI_PREFIX."request` $where_text"); 40 | if($total_results > 0){ 41 | $perpage = $_SESSION['perp'] ? (int)$_SESSION['perp'] : $set->perpage; 42 | $page = (int)$_GET['page'] == 0 ? 1 : (int)$_GET['page']; 43 | if($page > ceil($total_results/$perpage)) $page = ceil($total_results/$perpage); 44 | $start = ($page-1)*$perpage; 45 | $s_pages = new pag($total_results,$page,$perpage); 46 | $show_pages = $lang->pages.": ".$s_pages->pages; 47 | 48 | $data = $db->select("SELECT * FROM `".MAI_PREFIX."request` $where_text ORDER BY `id` DESC LIMIT $start,$perpage"); 49 | 50 | if($data){ 51 | $requests = "
$lang->req_last
"; 52 | foreach($data as $d){ 53 | $requests .= "
54 | ".nl2br(htmlentities($d->text))."
"; 55 | if((int)$_GET['req'] == $d->id && is_admin()) 56 | $requests .= "
$lang->cancel
"; 57 | else 58 | $requests .=($d->reply == '' ? "*" : "")." $lang->admin : ".nl2br(htmlentities($d->reply))."".(is_admin() ? " - id'>$lang->reply | id'>$lang->delete" : ""); 59 | 60 | $requests .="
"; 61 | } 62 | } 63 | } 64 | include "header.php"; 65 | $tpl->grab("request.tpl","request"); 66 | $tpl->assign("requests",$requests); 67 | $tpl->assign("add",$add); 68 | $tpl->assign("show_pages",$show_pages); 69 | $tpl->assign("lgrequest",$lang->request); 70 | $tpl->display(); 71 | 72 | $plugins->run_hook("request_end"); 73 | include "footer.php"; -------------------------------------------------------------------------------- /lang/index.php: -------------------------------------------------------------------------------- 1 | "; 36 | $lang['time_v'] = array("s","m","h","day","days","month","months"); 37 | $lang["files"] = "Files"; 38 | $lang["prev"] = "Prev"; 39 | $lang["first"] = "First"; 40 | $lang["last"] = "Last"; 41 | $lang["next"] = "Next"; 42 | $lang["pages"] = "Pages"; 43 | $lang["datedesc"] = "Date Desc"; 44 | $lang["dateasc"] = "Date Asc"; 45 | $lang["nameasc"] = "Name Asc"; 46 | $lang["namedesc"] = "Name Desc"; 47 | $lang["sizedesc"] = "Size Desc"; 48 | $lang["sizeasc"] = "Size Asc"; 49 | $lang["sort"] = "Sort"; 50 | $lang["elements_per_page"] = "Items per page"; 51 | $lang["save"] = "Save"; 52 | $lang["saved"] = "Saved"; 53 | $lang["ok"] = "ok"; 54 | $lang["width"] = "Width"; 55 | $lang["request"] = "Make a request"; 56 | $lang["req_added"] = "Request added and it will be visible after admin review"; 57 | $lang["req_limit"] = "Error: Request must contain more then 2 words and you can add only one in 24 hours"; 58 | $lang["req_last"] = "Latest requests:"; 59 | $lang["search"] = "Search"; 60 | $lang["edit"] = "Edit"; 61 | $lang["delete"] = "Delete"; 62 | $lang["icon"] = "Icon"; 63 | $lang["yes"] = "Yes"; 64 | $lang["no"] = "No"; 65 | $lang["are_you_sure"] = "Are you sure ?"; 66 | $lang["data_gone"] = "Data was deleted !!!"; 67 | $lang["added"] = "Added"; 68 | $lang["add"] = "Add"; 69 | $lang["add_folder"] = "Add folder"; 70 | $lang["new"] = "new"; 71 | $lang["cancel"] = "Cancel"; 72 | $lang["reply"] = "Reply"; 73 | $lang["import_files"] = "Import Files"; 74 | $lang["url"] = "URL"; 75 | $lang["main_msg"] = "Main message"; 76 | $lang["author"] = "Author"; 77 | $lang["deactivate"] = "Deactivate"; 78 | $lang["activate"] = "Activate"; 79 | $lang["install"] = "Install"; 80 | $lang["uninstall"] = "UnInstall"; 81 | $lang["keep_blank"] = "keep it blank if you don't want to change"; 82 | $lang["on"] = "On"; // as in turned on... ( the oven not what you're thinking :) ) 83 | $lang["off"] = "Off"; 84 | $lang["back"] = "Back"; 85 | $lang["path"] = "Path"; 86 | $lang["description"] = "Description"; 87 | $lang["remember"] = "Remember Me"; 88 | $lang["tpl_editor"] = "Tpl Editor"; 89 | $lang["tpl_notice"] = "(!) Be careful when you edit the tpl files it can disable the functionality of the site or of your plugins ! So make sure you know what you are doing !"; 90 | $lang["plugins_market"] = "Plugins Market"; 91 | $lang["plugin_installed"] = "Plugin was installed successfully !
Now go to Plugin Manager and activate it !"; 92 | 93 | -------------------------------------------------------------------------------- /admincp/plugin_market.php: -------------------------------------------------------------------------------- 1 | run_hook("plugin_market_top"); 15 | 16 | if(!is_admin()) { 17 | ob_end_clean(); 18 | header("Location: $set->url");exit; 19 | } 20 | 21 | $links[] = mai_img("arr.gif")." $lang->admincp "; 22 | $links[] = mai_img("arr.gif")." $lang->plugins_market"; 23 | 24 | 25 | $act = $_GET['act']; 26 | 27 | if(($act == 'install') && ($p_name = trim($_GET['p']))) { 28 | 29 | $tmp_name = "plugin".rand().".zip"; 30 | 31 | if(copy("http://master-land.net/autoindex/lib/".$p_name, $tmp_name)) { 32 | 33 | $zip = new ZipArchive; 34 | 35 | // this algorithm should work fine but some extra testing is required 36 | // you can contribute on github.com/ionutvmi 37 | 38 | 39 | if ($zip->open($tmp_name) === true) { 40 | 41 | for($i = 0; $i < $zip->numFiles; $i++) { // we try (and hopefully succeed) to put the files in the correct folders 42 | 43 | $filename = $zip->getNameIndex($i); 44 | 45 | $new_name = $filename; 46 | 47 | if(strpos($filename, "autoindex/") === 0) 48 | $new_name = str_ireplace("autoindex/","", $filename); 49 | 50 | 51 | if(trim($new_name) == '') 52 | continue; 53 | 54 | $info = $zip->statIndex($i); 55 | if($info['crc'] == 0) { // is dir 56 | 57 | if(!is_dir(MAI_ROOT.$new_name)) 58 | @mkdir(MAI_ROOT.$new_name,0777,true); 59 | 60 | continue; 61 | } 62 | 63 | if(substr($filename, -11) == "_plugin.php") { 64 | 65 | copy("zip://".dirname(__FILE__)."/".$tmp_name."#".$filename, MAI_ROOT."plugins/".basename($filename)); 66 | continue; 67 | } 68 | 69 | copy("zip://".dirname(__FILE__)."/".$tmp_name."#".$filename, MAI_ROOT.$new_name); 70 | 71 | } 72 | 73 | $zip->close(); 74 | } 75 | 76 | $content .="
$lang->plugin_installed
"; 77 | } else 78 | $content .="
$lang->error
"; 79 | 80 | @unlink($tmp_name); 81 | } else { 82 | 83 | 84 | $data = file_get_contents("http://master-land.net/autoindex/market.php?".$_SERVER['QUERY_STRING']); 85 | 86 | $data = preg_replace("##iUs", "", $data); 87 | $data = preg_replace("#(.+)#iUs", "", $data); 88 | $data = preg_replace("~
(.+)
~iUs", "", $data, 1); 89 | $data = preg_replace("~~i", "
$lang->install
", $data, 1); 90 | 91 | 92 | 93 | 94 | $content = $data. ""; 95 | } 96 | 97 | 98 | include "../header.php"; 99 | $plugins->run_hook("plugin_market"); 100 | echo $content; 101 | $plugins->run_hook("plugin_market_end"); 102 | include "../footer.php"; -------------------------------------------------------------------------------- /tpl/style/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | color : #545454; 3 | font-size : 15px; 4 | font-family : Times; 5 | background-image : url(images/body.gif); 6 | background-attachment : fixed; 7 | max-width : 600px; 8 | margin : auto; 9 | } 10 | a:link, a:active, a:visited { 11 | color : #1f8ba0; 12 | text-decoration : none; 13 | } 14 | a:hover, a:focus { 15 | text-decoration : underline; 16 | } 17 | div { 18 | background-color : #fff; 19 | margin : 1px; 20 | padding : 2px; 21 | } 22 | hr { 23 | margin : 0; 24 | border-color : #f0f0f0 #fff #fff; 25 | border-style : solid; 26 | border-width : 1px; 27 | } 28 | .header { 29 | color : #fff; 30 | padding:5px; 31 | font-weight:bold; 32 | font-size: 20px; 33 | background-color : #93db2e; 34 | background-image : url(images/header.gif); 35 | background-repeat : no-repeat; 36 | background-position : right 50%; 37 | } 38 | .lastnews { 39 | background-image : url(images/content.gif); 40 | background-repeat : repeat-x; 41 | background-position : 50% top; 42 | border : 1px solid #ececec; 43 | } 44 | .links { 45 | background-image : url(images/content.gif); 46 | background-repeat : repeat-x; 47 | background-position : 50% top; 48 | border : 1px solid #ececec; 49 | } 50 | .title { 51 | background-color : #e5eff0; 52 | background-image : url(images/title.gif); 53 | background-repeat : repeat-x; 54 | background-position : 50% bottom; 55 | border : 1px solid #dbe5e6; 56 | padding:3px; 57 | text-align:center; 58 | } 59 | 60 | .title2 { 61 | background-color : #eef8e0; 62 | background-image : url(images/title2.gif); 63 | background-repeat : repeat-x; 64 | background-position : 50% bottom; 65 | border : 1px solid #e1ecd1; 66 | padding:3px; 67 | text-align:center; 68 | } 69 | .content { 70 | background-image : url(images/content.gif); 71 | background-repeat : repeat-x; 72 | background-position : 50% top; 73 | border : 1px solid #ececec; 74 | padding:3px; 75 | } 76 | .content2 { 77 | background-image : url(images/content.gif); 78 | background-repeat : repeat-x; 79 | background-position : 50% top; 80 | border : 1px solid #dcdcdc; 81 | padding:3px; 82 | } 83 | .content2 a:link, .content2 a:visited { 84 | color : #62931d; 85 | } 86 | .footer { 87 | color : #fff; 88 | background-color : #32b6ce; 89 | background-image : url(images/footer.gif); 90 | background-repeat : no-repeat; 91 | background-position : right 50%; 92 | text-align:center; 93 | padding:3px; 94 | } 95 | .footer a{ 96 | color:white; 97 | } 98 | .vs { 99 | text-align : center; 100 | } 101 | span { 102 | color : #96dc2c; 103 | } 104 | .zag { 105 | font-size : large; 106 | } 107 | .green { 108 | color:green; 109 | } 110 | .red { 111 | color:red; 112 | } 113 | 114 | .download { 115 | text-align:center; 116 | background-color:#d4d4d4; 117 | -webkit-border-radius: 0.3em; 118 | border-radius: 0.3em; 119 | padding: 3px; 120 | background-image: url("images/grey1.png"); 121 | background-repeat:repeat-x; 122 | border:1px solid #4483E2; 123 | } 124 | .pages { 125 | text-align:center; 126 | -webkit-border-radius: 0.3em; 127 | border-radius: 0.3em; 128 | padding: 3px; 129 | background-image: url("images/grey1.png"); 130 | } 131 | .submit { 132 | text-align:center; 133 | -webkit-border-radius: 0.3em; 134 | border-radius: 0.3em; 135 | padding: 3px; 136 | background-image: url("images/grey1.png"); 137 | } 138 | .sort { 139 | text-align:center; 140 | -webkit-border-radius: 0.3em; 141 | border-radius: 0.3em; 142 | padding: 3px; 143 | background-image: url("images/grey1.png"); 144 | } 145 | .icon { 146 | text-align:center; 147 | -webkit-border-radius: 0.3em; 148 | border: 1px solid #ccc; 149 | padding: 3px; 150 | background-image:url(images/content.gif); 151 | background-repeat : repeat-x; 152 | } 153 | .search { 154 | text-align:center; 155 | -webkit-border-radius: 0.3em; 156 | border: 1px solid #ccc; 157 | padding: 3px; 158 | background-image:url(images/content.gif); 159 | background-repeat : repeat-x; 160 | } 161 | .new { 162 | color:red; 163 | } 164 | img { 165 | vertical-align:center; 166 | 167 | } 168 | /* Style by Mad 169 | http://wapdiz.ru */ -------------------------------------------------------------------------------- /lib/functions.php: -------------------------------------------------------------------------------- 1 | $val) { 10 | $value[$index] = stripslashes_recursive($val); 11 | } 12 | return $value; 13 | } else { 14 | return stripslashes($value); 15 | } 16 | } 17 | 18 | function remove_magic_quotes() 19 | { 20 | if( get_magic_quotes_gpc() ) { 21 | $_GET = stripslashes_recursive($_GET); 22 | $_POST = stripslashes_recursive($_POST); 23 | } 24 | } 25 | 26 | 27 | function mai_img($src,$alt = '') { 28 | global $plugins,$set; 29 | 30 | return $plugins->run_hook("mai_img","$alt"); 31 | } 32 | function mai_converturl($string){ 33 | $string=str_replace(" ","-",$string); 34 | $string=str_replace(".","-",$string); 35 | $string=str_replace("@","-",$string); 36 | $string=str_replace("/","-",$string); 37 | $string=str_replace("\\","-",$string); 38 | $string=preg_replace("/[^a-zA-Z0-9\-]/", "", $string); 39 | return $string; 40 | } 41 | function is_admin(){ 42 | global $set; 43 | if($_SESSION['adminpass'] == $set->sinfo->admin_pass) 44 | return true; 45 | return false; 46 | } 47 | function get_max_upl() { 48 | $max_upload = (int)(ini_get('upload_max_filesize')); 49 | $max_post = (int)(ini_get('post_max_size')); 50 | $memory_limit = (int)(ini_get('memory_limit')); 51 | return min($max_upload, $max_post, $memory_limit); 52 | } 53 | function convert($size) 54 | { 55 | $unit=array('B','KB','MB','GB','TB','PB'); 56 | return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i]; 57 | } 58 | function tsince($t,$arr){ 59 | $tt=time() - $t; 60 | $tp=$arr[0]; 61 | if ($tt>=60 && $tt<3600) { 62 | $tt=floor($tt / 60); $tp=$arr[1]; } 63 | if ($tt>=3600 && $tt<86400) { 64 | $tt=floor($tt / 3600); 65 | $tp=$arr[2]; } 66 | if ($tt>= 86400 && $tt < 2592000) { 67 | $tt=floor($tt / 86400); 68 | if($tt=='1') {$tp=$arr[3];}else{$tp=$arr[4];} } 69 | if ($tt >= 2592000) { 70 | $tt=floor($tt / 2592000); 71 | if($tt=='1') {$tp=$arr[5];}else{$tp=$arr[6];} } 72 | 73 | return "$tt $tp "; 74 | } 75 | function deleteAll($directory, $empty = false) { 76 | if(substr($directory,-1) == "/") { 77 | $directory = substr($directory,0,-1); 78 | } 79 | 80 | if(!file_exists($directory) || !is_dir($directory)) { 81 | return false; 82 | } elseif(!is_readable($directory)) { 83 | return false; 84 | } else { 85 | $directoryHandle = opendir($directory); 86 | 87 | while ($contents = readdir($directoryHandle)) { 88 | if($contents != '.' && $contents != '..') { 89 | $path = $directory . "/" . $contents; 90 | 91 | if(is_dir($path)) { 92 | deleteAll($path); 93 | } else { 94 | unlink($path); 95 | } 96 | } 97 | } 98 | 99 | closedir($directoryHandle); 100 | 101 | if($empty == false) { 102 | if(!rmdir($directory)) { 103 | return false; 104 | } 105 | } 106 | 107 | return true; 108 | } 109 | } 110 | 111 | // remove by value: 112 | function array_remove_value () 113 | { 114 | $args = func_get_args(); 115 | return array_diff($args[0],array_slice($args,1)); 116 | } 117 | 118 | function dirmv( $source, $destination ) { 119 | if ( is_dir( $source ) ) { 120 | @mkdir( $destination ); 121 | $directory = dir( $source ); 122 | while ( FALSE !== ( $readdirectory = $directory->read() ) ) { 123 | if ( $readdirectory == '.' || $readdirectory == '..' ) { 124 | continue; 125 | } 126 | $PathDir = $source . '/' . $readdirectory; 127 | if ( is_dir( $PathDir ) ) { 128 | dirmv( $PathDir, $destination . '/' . $readdirectory ); 129 | continue; 130 | } 131 | rename( $PathDir, $destination . '/' . $readdirectory ); 132 | } 133 | 134 | $directory->close(); 135 | }else { 136 | rename( $source, $destination ); 137 | } 138 | } -------------------------------------------------------------------------------- /admincp/import.php: -------------------------------------------------------------------------------- 1 | run_hook("admin_import_form_top"); 9 | 10 | if(!is_admin()) { 11 | header("Location: $set->url");exit; 12 | } 13 | 14 | $links[] = mai_img("arr.gif")." $lang->admincp "; 15 | $links[] = mai_img("arr.gif")." $lang->import_files "; 16 | $message = ''; 17 | 18 | $all_folders = $db->select("SELECT `path` FROM `". MAI_PREFIX ."files` WHERE `size` = '0'"); 19 | 20 | foreach($all_folders as $folder){ 21 | $folder = substr($folder->path,6); // remove /files 22 | $path_opt .= ""; 23 | } 24 | if($_POST){ 25 | 26 | $path = "../files".$_POST['path']; 27 | 28 | $i=0; 29 | foreach($_POST['f'] as $f){ 30 | if(trim($_POST['n'][$i]) == '') 31 | $_name = preg_match("~(.*)\.(\w)~i",basename($f)) ? basename($f) : "file_$i.dat"; 32 | else 33 | $_name = preg_match("~(.*)\.(\w)~i",basename($_POST['n'][$i])) ? basename($_POST['n'][$i]) : "file_$i.dat"; 34 | $plugins->run_hook("admin_import_form_post"); 35 | if($f !='' AND $f !='http://' AND !file_exists($path."/".$_name)){ 36 | $ext = (object)pathinfo($_name); 37 | if($ext->extension == 'jad'){ 38 | 39 | $lines = file($f); 40 | foreach($lines as $line) 41 | if(strpos($line,"MIDlet-Jar-URL:") !== FALSE) 42 | $url = trim(str_replace("MIDlet-Jar-URL:","",$line)); 43 | 44 | $plugins->run_hook("admin_import_form_jad_top"); 45 | 46 | if($url){ 47 | 48 | $snoopy = new Snoopy; 49 | if($snoopy->fetch($url)){ 50 | $_name = preg_match("~(.*)\.(\w)~i",basename($url)) ? basename($url) : "game_$i.jar"; 51 | fopen($path."/".$_name,"w"); 52 | if(file_put_contents($path."/".$_name,$snoopy->results)){ 53 | $message .= "
".$_name.$lang->file_uploaded."
"; 54 | $dirid = $db->get_row("SELECT id FROM `". MAI_PREFIX ."files` WHERE `path`='".substr($path,2)."'")->id; 55 | if($dirid != 0) { 56 | foreach(explode('/',substr($path,9)) as $dr){ 57 | $_dr .="/".$dr; 58 | if($_dr != '/') 59 | $db->query("UPDATE `". MAI_PREFIX ."files` SET `time`='".time()."' WHERE `path` = '/files$_dr'"); 60 | } 61 | } 62 | 63 | $db->insert("INSERT INTO `". MAI_PREFIX ."files` SET `name`='".$db->escape($_name)."', `path`='".substr($path,2)."/".$db->escape($_name)."',`indir`='$dirid', `time`='".time()."',`size`='".filesize($path."/".$_name)."'"); 64 | $plugins->run_hook("admin_import_form_jad"); 65 | } 66 | } 67 | } 68 | }else{ 69 | $plugins->run_hook("admin_import_form_mid_top"); 70 | $snoopy = new Snoopy; 71 | if($snoopy->fetch($f)){ 72 | fopen($path."/".$_name,"w"); 73 | file_put_contents($path."/".$_name,$snoopy->results); 74 | $message .= "
".$_name.$lang->file_uploaded."
"; 75 | $dirid = $db->get_row("SELECT id FROM `". MAI_PREFIX ."files` WHERE `path`='".substr($path,2)."'")->id; 76 | 77 | if($dirid != 0) { 78 | foreach(explode('/',substr($path,9)) as $dr){ 79 | $_dr .="/".$dr; 80 | if($_dr != '/') 81 | $db->query("UPDATE `". MAI_PREFIX ."files` SET `time`='".time()."' WHERE `path` = '/files$_dr'"); 82 | } 83 | 84 | } 85 | $db->insert("INSERT INTO `". MAI_PREFIX ."files` SET `name`='".$db->escape($_name)."', `path`='".substr($path,2)."/".$db->escape($_name)."',`indir`='$dirid', `time`='".time()."',`size`='".filesize($path."/".$_name)."'"); 86 | $plugins->run_hook("admin_import_form_mid"); 87 | }else 88 | $message .= "
".$_FILES['f']['name'][$i].$lang->file_not_uploaded."
"; 89 | } 90 | 91 | } 92 | ++$i; 93 | } 94 | } 95 | 96 | 97 | include "../header.php"; 98 | $tpl->grab("admin_import_form.tpl","admin_import_form"); 99 | $tpl->assign("import_files",$lang->import_files); 100 | $tpl->assign("url",$lang->url); 101 | $tpl->assign("name",$lang->name); 102 | $tpl->assign("message",$message); 103 | $tpl->assign("path_opt",$path_opt); 104 | $tpl->display(); 105 | $plugins->run_hook("admin_import_form_end"); 106 | include "../footer.php"; 107 | 108 | ?> -------------------------------------------------------------------------------- /admincp/upload.php: -------------------------------------------------------------------------------- 1 | run_hook("admin_upload_form_top"); 9 | 10 | if(!is_admin()) { 11 | header("Location: $set->url");exit; 12 | } 13 | 14 | $links[] = mai_img("arr.gif")." $lang->admincp "; 15 | $links[] = mai_img("arr.gif")." $lang->upload_files "; 16 | $maximum = get_max_upl(); 17 | $message = ''; 18 | 19 | $all_folders = $db->select("SELECT `path` FROM `". MAI_PREFIX ."files` WHERE `size` = '0'"); 20 | 21 | foreach($all_folders as $folder){ 22 | $folder = substr($folder->path,6); // remove /files 23 | $path_opt .= ""; 24 | } 25 | if($_FILES){ 26 | 27 | $path = "../files".$_POST['path']; 28 | 29 | $i=0; 30 | foreach($_FILES['f']['name'] as $f){ 31 | 32 | $plugins->run_hook("admin_upload_form_post"); 33 | 34 | if(file_exists($_FILES['f']['tmp_name'][$i]) AND !file_exists($path."/".$_FILES['f']['name'][$i])){ 35 | $ext = (object)pathinfo($_FILES['f']['name'][$i]); 36 | if((($_FILES['f']['size'][$i]/1024)/1024) < $maximum){ 37 | if($ext->extension == 'jad'){ 38 | $lines = file($_FILES['f']['tmp_name'][$i]); 39 | @unlink($_FILES['f']['tmp_name'][$i]); 40 | foreach($lines as $line) 41 | if(strpos($line,"MIDlet-Jar-URL:") !== FALSE) 42 | $url = trim(str_replace("MIDlet-Jar-URL:","",$line)); 43 | 44 | $plugins->run_hook("admin_upload_form_jad_top"); 45 | 46 | if($url){ 47 | $snoopy = new Snoopy; 48 | if($snoopy->fetch($url)){ 49 | $_name = preg_match("~(.*)\.(\w)~i",basename($url)) ? basename($url) : "game_$i.jar"; 50 | fopen($path."/".$_name,"w"); 51 | if(file_put_contents($path."/".$_name,$snoopy->results)){ 52 | $message .= "
".$_name.$lang->file_uploaded."
"; 53 | $dirid = $db->get_row("SELECT id FROM `". MAI_PREFIX ."files` WHERE `path`='".substr($path,2)."'")->id; 54 | if($dirid != 0) { 55 | foreach(explode('/',substr($path,9)) as $dr){ 56 | $_dr .="/".$dr; 57 | if($_dr != '/') 58 | $db->query("UPDATE `". MAI_PREFIX ."files` SET `time`='".time()."' WHERE `path` = '/files$_dr'"); 59 | } 60 | } 61 | 62 | $db->insert("INSERT INTO `". MAI_PREFIX ."files` SET `name`='".$db->escape($_name)."', `path`='".substr($path,2)."/".$db->escape($_name)."',`indir`='$dirid', `time`='".time()."',`size`='".filesize($path."/".$_name)."'"); 63 | $plugins->run_hook("admin_upload_form_jad"); 64 | } 65 | } 66 | } 67 | }else{ 68 | $plugins->run_hook("admin_upload_form_mid_top"); 69 | if(move_uploaded_file($_FILES['f']['tmp_name'][$i],$path."/".$_FILES['f']['name'][$i])){ 70 | $message .= "
".$_FILES['f']['name'][$i].$lang->file_uploaded."
"; 71 | $dirid = $db->get_row("SELECT id FROM `". MAI_PREFIX ."files` WHERE `path`='".substr($path,2)."'")->id; 72 | 73 | if($dirid != 0) { 74 | foreach(explode('/',substr($path,9)) as $dr){ 75 | $_dr .="/".$dr; 76 | if($_dr != '/') 77 | $db->query("UPDATE `". MAI_PREFIX ."files` SET `time`='".time()."' WHERE `path` = '/files$_dr'"); 78 | } 79 | 80 | } 81 | $db->insert("INSERT INTO `". MAI_PREFIX ."files` SET `name`='".$db->escape($_FILES['f']['name'][$i])."', `path`='".substr($path,2)."/".$db->escape($_FILES['f']['name'][$i])."',`indir`='$dirid', `time`='".time()."',`size`='".$_FILES['f']['size'][$i]."'"); 82 | $plugins->run_hook("admin_upload_form_mid"); 83 | }else 84 | $message .= "
".$_FILES['f']['name'][$i].$lang->file_not_uploaded."
"; 85 | } 86 | }else { 87 | @unlink($_FILES['f']['name'][$i]); 88 | $message .= "
".$_FILES['f']['name'][$i].$lang->file_too_big."
"; 89 | } 90 | 91 | } 92 | ++$i; 93 | } 94 | } 95 | $maximum .= "M"; 96 | 97 | include "../header.php"; 98 | $tpl->grab("admin_upload_form.tpl","admin_upload_form"); 99 | $tpl->assign("upload_files",$lang->upload_files); 100 | $tpl->assign("message",$message); 101 | $tpl->assign("path_opt",$path_opt); 102 | $tpl->assign("max_file_size",$lang->max_file_size.$maximum); 103 | $tpl->display(); 104 | 105 | $plugins->run_hook("admin_upload_form_end"); 106 | include "../footer.php"; 107 | 108 | ?> -------------------------------------------------------------------------------- /install.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | master-land.net installer 4 | 12 | 13 | 14 |

MASTER AUTOINDEX INSTALLER

15 | db_name = "'.$_POST['name'].'"; 28 | $set->db_user = "'.$_POST['user'].'"; 29 | $set->db_host = "'.$_POST['host'].'"; 30 | $set->db_pass = "'.$_POST['pass'].'"; 31 | 32 | 33 | $set->name = "'.$_POST['site_name'].'"; // site name 34 | $set->url = "'.$_POST['site_url'].'"; // site url 35 | $set->logo = "'.$_POST['site_logo'].'"; // logo url (full url http://site.com/logo.png) 36 | $set->perpage = "10"; // how many records per page 37 | define("MAI_PREFIX","'.$_POST['prefix'].'"); 38 | '; 39 | 40 | if(!fwrite($fp,trim($content))) 41 | $error = 1; 42 | 43 | fclose($fp); 44 | 45 | include "inc/settings.php"; 46 | 47 | include "lib/mysql.class.php"; 48 | 49 | $db = new dbConn($set->db_host,$set->db_user,$set->db_pass,$set->db_name); 50 | 51 | 52 | if(!$db->query("CREATE TABLE IF NOT EXISTS `".$_POST['prefix']."files` ( 53 | `id` int(11) NOT NULL AUTO_INCREMENT, 54 | `name` varchar(200) NOT NULL, 55 | `path` text NOT NULL, 56 | `indir` int(11) NOT NULL DEFAULT '0', 57 | `views` int(11) NOT NULL, 58 | `dcount` int(11) NOT NULL, 59 | `time` int(11) NOT NULL, 60 | `size` int(11) NOT NULL, 61 | `icon` text NOT NULL, 62 | `description` text NOT NULL, 63 | `isdir` int(11) NOT NULL, 64 | PRIMARY KEY (`id`) 65 | ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;")) $error = 1; 66 | if(!$db->query("INSERT INTO `".$_POST['prefix']."files` (`id`, `name`, `path`, `indir`, `views`, `dcount`, `time`, `size`, `icon`,`isdir`) VALUES 67 | (1, 'Games', '/files/Games', 0, 0, 0, 1348259936, 0, '', 1);")) $error = 1; 68 | if(!$db->query("CREATE TABLE IF NOT EXISTS `".$_POST['prefix']."plugins_settings` ( 69 | `name` varchar(200) NOT NULL, 70 | `value` text NOT NULL, 71 | `title` text NOT NULL, 72 | `description` text NOT NULL, 73 | `type` text NOT NULL, 74 | `plugin` text NOT NULL, 75 | UNIQUE KEY `name` (`name`) 76 | ) ENGINE=MyISAM DEFAULT CHARSET=latin1;")) $error = 1; 77 | if(!$db->query("CREATE TABLE IF NOT EXISTS `".$_POST['prefix']."request` ( 78 | `id` int(11) NOT NULL AUTO_INCREMENT, 79 | `text` text NOT NULL, 80 | `reply` text NOT NULL, 81 | PRIMARY KEY (`id`) 82 | ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;")) $error = 1; 83 | if(!$db->query("CREATE TABLE IF NOT EXISTS `".$_POST['prefix']."settings` ( 84 | `admin_pass` varchar(100) NOT NULL, 85 | `main_msg` text NOT NULL, 86 | `active_plugins` text NOT NULL 87 | ) ENGINE=MyISAM DEFAULT CHARSET=latin1;")) $error = 1; 88 | if(!$db->query("INSERT INTO `".$_POST['prefix']."settings` (`admin_pass`, `main_msg`, `active_plugins`) VALUES 89 | ('".sha1(trim($_POST['admin_pass']))."', 'Welcome to our site !\r\nHope you enjoy it :D', 'a:0:{}');")) $error = 1; 90 | 91 | if($error){ 92 | echo "Some error camed up. Check if /inc/settings.php is writable and if your prefix is correct."; 93 | }else { 94 | echo "

Installation Complete

95 | "; 96 | 97 | // @unlink(__FILE__); 98 | } 99 | 100 | }else{ 101 | 102 | @chmod("files",0777); 103 | @chmod("inc/settings.php",0666); 104 | 105 | echo " 106 | 107 | Database Host

108 | Database User

109 | Database Password

110 | Database Name

111 | Table Prefix:

112 | Site Name

113 | 114 | Site Logo(keep blank if you don't have)

115 | Site Url

116 | Admin Pass:

117 |
118 | "; 119 | 120 | } 121 | ?> 122 |

www.master-land.net

123 | 124 | -------------------------------------------------------------------------------- /lib/mysql.class.php: -------------------------------------------------------------------------------- 1 | link = @mysqli_connect($db_host, $db_user, $db_pass, $db_name); 16 | 17 | if (!$this->link) die('Connect Error (' . mysqli_connect_errno() . ') '.mysqli_connect_error()); 18 | 19 | mysqli_select_db($this->link, $db_name) or die(mysqli_error($this->link)); 20 | 21 | return true; 22 | } 23 | 24 | function select($q){ 25 | 26 | $result = mysqli_query($this->link,$q); 27 | 28 | if(mysqli_num_rows($result) > 0) 29 | 30 | while($res = mysqli_fetch_object($result)) 31 | 32 | $arr[] = $res; 33 | 34 | if($arr) return $arr; 35 | 36 | return false; 37 | } 38 | function get_row($q){ 39 | $result = mysqli_query($this->link,$q); 40 | 41 | if(mysqli_num_rows($result) == 1) 42 | 43 | $arr = mysqli_fetch_object($result); 44 | 45 | if($arr) return $arr; 46 | 47 | return false; 48 | } 49 | function count($q){ 50 | $result = mysqli_query($this->link,$q); 51 | 52 | return mysqli_num_rows($result); 53 | 54 | } 55 | 56 | function query($q){ 57 | 58 | return mysqli_query($this->link,$q); 59 | 60 | } 61 | 62 | function escape($str){ 63 | 64 | return mysqli_real_escape_string($this->link,$str); 65 | 66 | } 67 | function insert($q){ 68 | 69 | if(mysqli_query($this->link,$q)) 70 | return mysqli_insert_id($this->link); 71 | return false; 72 | } 73 | function insert_array($table,$array){ 74 | $q = "INSERT INTO `$table`"; 75 | $q .=" (`".implode("`,`",array_keys($array))."`) "; 76 | $q .=" VALUES ('".implode("','",array_values($array))."') "; 77 | 78 | if(mysqli_query($this->link,$q)) 79 | return mysqli_insert_id($this->link); 80 | return false; 81 | } 82 | } 83 | } else { // we use the old mysql 84 | class dbConn { 85 | var $link = null; 86 | 87 | function __construct($db_host,$db_user,$db_pass,$db_name){ 88 | 89 | $this->link = @mysql_connect($db_host, $db_user, $db_pass); 90 | 91 | if (!$this->link) die('Connect Error (' . mysql_errno() . ') '.mysql_error()); 92 | 93 | mysql_select_db($db_name, $this->link) or die(mysql_error($this->link)); 94 | 95 | return true; 96 | } 97 | 98 | function select($q){ 99 | 100 | $result = mysql_query($q, $this->link); 101 | 102 | if(mysql_num_rows($result) > 0) 103 | 104 | while($res = mysql_fetch_object($result)) 105 | 106 | $arr[] = $res; 107 | 108 | if($arr) return $arr; 109 | 110 | return false; 111 | } 112 | function get_row($q){ 113 | $result = mysql_query($q, $this->link); 114 | 115 | if(mysql_num_rows($result) == 1) 116 | 117 | $arr = mysql_fetch_object($result); 118 | 119 | if($arr) return $arr; 120 | 121 | return false; 122 | } 123 | function count($q){ 124 | $result = mysql_query($q, $this->link); 125 | 126 | return mysql_num_rows($result); 127 | 128 | } 129 | 130 | function query($q){ 131 | 132 | return mysql_query($q, $this->link); 133 | 134 | } 135 | 136 | function escape($str){ 137 | 138 | return mysql_real_escape_string($str, $this->link); 139 | 140 | } 141 | function insert($q){ 142 | 143 | if(mysql_query($q, $this->link)) 144 | return mysql_insert_id($this->link); 145 | return false; 146 | } 147 | function insert_array($table,$array){ 148 | $q = "INSERT INTO `$table`"; 149 | $q .=" (`".implode("`,`",array_keys($array))."`) "; 150 | $q .=" VALUES ('".implode("','",array_values($array))."') "; 151 | 152 | if(mysql_query($q, $this->link)) 153 | return mysql_insert_id($this->link); 154 | return false; 155 | } 156 | } 157 | 158 | 159 | } -------------------------------------------------------------------------------- /file.php: -------------------------------------------------------------------------------- 1 | run_hook("file_top"); 10 | 11 | 12 | $fid = (int)$_GET['id']; 13 | 14 | $file = $db->get_row("SELECT * FROM `". MAI_PREFIX ."files` WHERE `id`='$fid'"); 15 | 16 | if(!$file) { 17 | header("Location: $set->url"); 18 | exit; 19 | } 20 | $title = $file->name; 21 | 22 | if(isset($_GET["download"])) { 23 | $plugins->run_hook("download",null); 24 | 25 | $db->query("UPDATE `". MAI_PREFIX ."files` SET `dcount` = dcount+1 WHERE `id` = '$fid'"); 26 | 27 | if(isset($_GET['jad'])) { 28 | include 'lib/pclzip.lib.php'; 29 | $l = ".".$file->path; 30 | $zip = new PclZip($l); 31 | $content = $zip->extract(PCLZIP_OPT_BY_NAME,'META-INF/MANIFEST.MF',PCLZIP_OPT_EXTRACT_AS_STRING); 32 | $filesize=filesize($l); 33 | header('Content-type: text/vnd.sun.j2me.app-descriptor'); 34 | header('Content-Disposition: attachment; filename="'.basename($l).'.jad";'); 35 | 36 | echo $content[0]['content']."\n".'MIDlet-Jar-Size: '.$filesize."\n".'MIDlet-Jar-URL: '.$set->url.$file->path; 37 | exit; 38 | 39 | }else { 40 | 41 | if (file_exists(".".$file->path)) { 42 | header("Location: $set->url".$file->path); 43 | exit; 44 | } 45 | } 46 | } 47 | $db->query("UPDATE `". MAI_PREFIX ."files` SET `views` = views+1 WHERE `id` = '$fid'"); 48 | $name = $lang->name." : ".$file->name; 49 | $description = $lang->description." : ".$file->description; 50 | $time = $lang->uploaded_on." : ".date("D, d M Y",$file->time); 51 | $size = $lang->size." : ".convert($file->size); 52 | $dloads = $lang->downloads." : ".$file->dcount; 53 | $views = $lang->views." : ".$file->views; 54 | 55 | $ext = (object)pathinfo($file->path); 56 | $ext->extension = strtolower($ext->extension); 57 | 58 | 59 | if(in_array($ext->extension,array('png','jpg','jpeg','gif','jar'))) { 60 | if($ext->extension == 'jar') 61 | $icon = "/icon.php?s=".base64_encode($file->path); 62 | else{ 63 | $icon = "/thumb.php?w=128&src=".base64_encode($file->path); 64 | $extra_img = "
65 | $lang->width : 66 | 16px 67 | 32px 68 | 64px 69 | 128px 70 | 256px 71 | 512px 72 |
73 |
74 | x 75 | 76 |
77 |
"; 78 | } 79 | }else{ 80 | $all_icons = str_replace(".png","",array_map("basename",glob(MAI_TPL."style/png/*.png"))); 81 | if(!in_array($ext->extension,$all_icons)) 82 | $icon = "/". MAI_TPL ."style/png/file.png"; 83 | else 84 | $icon = "/". MAI_TPL ."style/png/$ext->extension.png"; 85 | } 86 | 87 | if($file->icon != '') 88 | $icon = "/thumb.php?ext&w=128&src=".urlencode($file->icon); 89 | 90 | $plugins->run_hook("file_mid"); 91 | 92 | 93 | $show_icon = ""; 94 | 95 | 96 | $download = "
$lang->download $ext->extension
"; 97 | if($ext->extension == 'jar') 98 | $download .= "
$lang->download JAD
"; 99 | 100 | foreach(explode('/',substr($file->path,7)) as $dr){ 101 | if(trim($dr != "")) { 102 | $_dr .="/".$dr; 103 | $id = $db->get_row("SELECT `id`,`name` FROM `". MAI_PREFIX ."files` WHERE `path` = '/files".$db->escape($_dr)."'"); 104 | $links[] = mai_img("arr.gif")." $id->name"; 105 | } 106 | } 107 | if(is_admin()){ 108 | $_admin = ""; 110 | } 111 | 112 | include "header.php"; 113 | $tpl->grab("file.tpl",'file'); 114 | $tpl->assign('name',$name); 115 | $tpl->assign('description',$description); 116 | $tpl->assign('size',$size); 117 | $tpl->assign('dloads',$dloads); 118 | $tpl->assign('views',$views); 119 | $tpl->assign('show_icon',$show_icon); 120 | $tpl->assign('time',$time); 121 | $tpl->assign('download',$download); 122 | $tpl->assign('extra_img',$extra_img); 123 | $tpl->assign('_admin',$_admin); 124 | $tpl->display(); 125 | 126 | $plugins->run_hook("file_end"); 127 | 128 | include "footer.php"; -------------------------------------------------------------------------------- /plugins/hello_plugin.php: -------------------------------------------------------------------------------- 1 | _ 4 | * where the is same as in file name _plugin.php 5 | * in our case is hello 6 | * this is mandatory only for default functions 7 | * Default function list: _info(), _install(), _uninstall(), _is_installed(), _activate, _deactivate 8 | * all this functions are optional a plugin can work just fine without any of this functions 9 | * BUT I RECOMMEND YOU USE THEM (if needed of course) 10 | 11 | 12 | 13 | 14 | * Hooks 15 | * Tho find a hook name you open the file that you want to edit 16 | * example `header.php` and you search for something like 17 | * $tpl->grab('header.tpl','header'); or like $plugins->run_hook("header_top"); 18 | * ******************************** 19 | * On the first case the first argument is the template file name and the second is the hook 20 | * now if you want to run your function at that point or on that the difference that 21 | * you need to note is that the one called using grab() has to return 22 | * a value witch will be the teplate file content. Your function should look like this 23 | * function hello_dosomething($value){ 24 | * // do something 25 | * return $value; 26 | * } 27 | * ******************************** 28 | * On the seccond run_hook() only the name of the hook is defined you don't 29 | * have to return anything and your function will look like 30 | * function hello_dosomething(){ 31 | * // do something 32 | * } 33 | * 34 | * 35 | * hope you spot the difference if you still need help check other plugins or 36 | * ask for help on www.master-land.net 37 | */ 38 | 39 | 40 | // you can use as many hooks as you need 41 | // now we are interested in the first case were the hook name is `header` 42 | // so we need to add our function to be executed in that place 43 | // as you can notice the first is the hook name and the second is our function name 44 | 45 | 46 | $plugins->add_hook("header","hello_show_text"); 47 | 48 | 49 | 50 | //// Now let's build our plugin 51 | 52 | // we first provide some info about the plugin 53 | function hello_info(){ 54 | /** 55 | * Array containing info about your plugin 56 | * name - plugin name witch will be displayed in Manager 57 | * author - author name(s) 58 | * author_site - author site if you don't have keep it blank 59 | * description - a very small description about this plugin 60 | */ 61 | return array( 62 | "name" => "Hello World", 63 | "author" => "ionutvmi", 64 | "author_site" => "http://master-land.net", 65 | "description" => "this is a demo plugin, it will show a text on the top of the page", 66 | ); 67 | } 68 | 69 | // function hello_install() { 70 | // /** 71 | // * This should install the plugin. Add or alter tables, text files etc. 72 | // * It will be called in the manager on admin request. 73 | // */ 74 | // return true; 75 | // } 76 | // function hello_uninstall() { 77 | // /** 78 | // * This should uninstall the plugin. Remove or alter tables, text files etc. 79 | // * It will be called in the manager on admin request. 80 | // */ 81 | // return true; 82 | // } 83 | 84 | // function hello_is_installed(){ 85 | // /** 86 | // * This ONLY checks if the plugin is installed 87 | // */ 88 | // return true; 89 | // } 90 | 91 | // function hello_activate(){ 92 | // /** 93 | // * This should make the plugin 'visible' 94 | // * by making the required changes on template vars etc.. 95 | // */ 96 | // return true; 97 | // } 98 | // function hello_deactivate(){ 99 | // /** 100 | // * This should 'hide' the plugin but keep all the data such as tables 101 | // * or txt files . the should be removed only by _uninstall() 102 | // * it will be also called before _uninstall() if the plugin is active 103 | // */ 104 | // return true; 105 | // } 106 | 107 | 108 | 109 | // in this particular case we don't have anything to install so we don't need to define the functions that handle that 110 | 111 | 112 | // now let's build our function 113 | // it's not mandatory for the function to start with the plugin name 114 | // but it's a good practice so we don't have problems with other plugins 115 | 116 | // it called using grab() so we need to return the `value` 117 | function hello_show_text($value){ 118 | global $set; 119 | // $value is the template content before the vars are replaced 120 | 121 | // we check if our plugin is active 122 | if(in_array('hello',unserialize($set->sinfo->active_plugins))){ 123 | 124 | $value = str_replace(""," Hello World :D
This is my first plugin",$value); 125 | 126 | } 127 | 128 | // return the value !! 129 | return $value; 130 | } 131 | 132 | 133 | 134 | /// done now we save it in /plugins folder with the name _plugin.php 135 | // after we do that we go to Admin Panel -> Plugin manager and we should see our plugin 136 | // we Activate it and see if it works 137 | 138 | 139 | //// That's about it... Pretty easy huh ? 140 | // hope you have fun and be as creative as posible with it :) 141 | // don't forget about www.master-land.net for help 142 | 143 | /// Regards ionutvmi@gmail.com 144 | 145 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | run_hook("index_top"); 11 | 12 | $dir = (int)$_GET['dir']; 13 | 14 | if($dir){ 15 | $downloads_menu = $db->get_row("SELECT `name`,`path`,`description` FROM `". MAI_PREFIX ."files` WHERE `id` = '$dir'"); 16 | 17 | if($downloads_menu->name != '') 18 | $lang->downloads_menu = $downloads_menu->name; 19 | 20 | 21 | foreach(explode('/',substr($downloads_menu->path,7)) as $dr){ 22 | $_dr .="/".$dr; 23 | $id = $db->get_row("SELECT `id`,`name` FROM `". MAI_PREFIX ."files` WHERE `path` = '/files".$db->escape($_dr)."'"); 24 | $links[] = mai_img("arr.gif")." ".htmlentities($id->name).""; 25 | } 26 | $title = $id->name; 27 | 28 | }else{ 29 | $title = $lang->Welcome; 30 | // updates 31 | 32 | $updates = "$lang->updates
"; 33 | $up_data = $db->select("SELECT * FROM `". MAI_PREFIX ."files` WHERE size > 0 ORDER BY `id` DESC LIMIT 0,5"); 34 | 35 | $plugins->run_hook("index_updates"); 36 | if($up_data){ 37 | foreach($up_data as $udata){ 38 | $updates .= sprintf($lang->updates_text,"$udata->name",tsince($udata->time,$lang->time_v)); 39 | } 40 | }else 41 | $updates .= $lang->no_data; 42 | } 43 | 44 | if(is_admin()){ 45 | $_admin = "$lang->edit | 46 | $lang->delete "; 47 | $_admin2 = ""; 48 | 49 | $plugins->run_hook("index_admin"); 50 | } 51 | 52 | 53 | $where_text = "`indir` = '$dir'"; 54 | 55 | if(!empty($_GET["search"])){ 56 | $search_words = explode(" ", $_GET["search"]); 57 | foreach ($search_words as $search_word) { 58 | $where []= "`name` LIKE '%$search_word%'"; 59 | $where2[]= "`description` LIKE '%$search_word%'"; 60 | } 61 | $where_text = "(".implode(" AND ",$where).") OR (".implode(" AND ",$where2).") AND `size` > 0"; 62 | $search_text = htmlentities($_GET["search"],ENT_QUOTES); 63 | $links[]=mai_img("arr.gif").$lang->search; 64 | }elseif(!$dir) 65 | $links = ' '; 66 | 67 | $plugins->run_hook("index_search"); 68 | 69 | $total_results = $db->count("SELECT `id` FROM `". MAI_PREFIX ."files` WHERE $where_text"); 70 | if($total_results > 0) { 71 | 72 | // pagination 73 | $perpage = $_SESSION['perp'] ? (int)$_SESSION['perp'] : $set->perpage; 74 | $page = (int)$_GET['page'] == 0 ? 1 : (int)$_GET['page']; 75 | if($page > ceil($total_results/$perpage)) $page = ceil($total_results/$perpage); 76 | $start = ($page-1)*$perpage; 77 | 78 | $s_pages = new pag($total_results,$page,$perpage); 79 | $show_pages = $lang->pages.": ".$s_pages->pages; 80 | // order by 81 | if($_POST['sort']) 82 | $_SESSION['sort'] = (int)$_POST['sort']; 83 | if($_SESSION['sort'] === null) $_SESSION['sort'] = 6; 84 | 85 | switch($_SESSION['sort']){ 86 | case 1 : 87 | $order = "`time` ASC"; $dateasc=" selected='1'"; break; 88 | case 2 : 89 | $order = "`name` DESC"; $namedesc=" selected='1'"; break; 90 | case 3 : 91 | $order = "`name` ASC"; $nameasc=" selected='1'";break; 92 | case 4 : 93 | $order = "`size` DESC"; $sizedesc=" selected='1'";break; 94 | case 5 : 95 | $order = "`size` ASC"; $sizeasc=" selected='1'";break; 96 | default : 97 | $order = "`time` DESC"; $datedesc=" selected='1'"; 98 | } 99 | $show_order = "
$lang->sort 100 |
"; 108 | 109 | $plugins->run_hook("index_order"); 110 | 111 | $data = $db->select("SELECT * FROM `". MAI_PREFIX ."files` WHERE $where_text ORDER BY `isdir` DESC, $order LIMIT $start,$perpage"); 112 | 113 | 114 | foreach($data as $d){ 115 | if($d->time > (time()-60*60*24)) 116 | $new_text = "($lang->new)"; 117 | else 118 | $new_text = ''; 119 | if(is_dir(".".$d->path)){ 120 | 121 | if($d->isdir == 0) { // since 1.0.6 a folder is no longer defined as size = 0 122 | // this is just a fix for users who upgrade, a clean install should never get here 123 | $db->query("UPDATE `". MAI_PREFIX ."files` SET `isdir` = '1' WHERE `id` = '$d->id'"); 124 | } 125 | 126 | $count = $db->count("SELECT `id` FROM `". MAI_PREFIX ."files` WHERE `path` LIKE '".$d->path."%' AND `isdir` = '0'"); 127 | 128 | $plugins->run_hook("index_folders"); 129 | 130 | $folders .= ""; 137 | 138 | $plugins->run_hook("index_folders_end"); 139 | 140 | }else{ 141 | $plugins->run_hook("index_files_top"); 142 | 143 | $files .= ""; 171 | 172 | $plugins->run_hook("index_files_end"); 173 | } 174 | } 175 | } else { 176 | $files = $lang->no_data; 177 | } 178 | 179 | 180 | // if the admin message is blank don't display the admin name 181 | if(trim($set->sinfo->main_msg) == "") 182 | $lang->admin = null; 183 | else{ 184 | $lang->admin .= ":"; 185 | $set->sinfo->main_msg .= "

"; 186 | } 187 | include "header.php"; 188 | $tpl->grab('index.tpl','index'); 189 | $tpl->assign('MAI_TPL',$set->url."/".MAI_TPL); 190 | $tpl->assign('url',$set->url); 191 | $tpl->assign('admin',$lang->admin); 192 | $tpl->assign('downloads_menu',$lang->downloads_menu); 193 | $tpl->assign('description',$downloads_menu->description); 194 | $tpl->assign('main_msg',$set->sinfo->main_msg); 195 | $tpl->assign('updates',$updates); 196 | $tpl->assign('files',$files); 197 | $tpl->assign('folders',$folders); 198 | $tpl->assign('extra',$lang->extra); 199 | $tpl->assign('settings',$lang->settings); 200 | $tpl->assign('show_pages',$show_pages); 201 | $tpl->assign('search',$lang->search); 202 | $tpl->assign('search_text',$search_text); 203 | $tpl->assign('request',$lang->request); 204 | $tpl->assign('show_order',$show_order); 205 | $tpl->assign('_admin2',$_admin2); 206 | $tpl->display(); 207 | 208 | $plugins->run_hook("index_end"); 209 | 210 | include "footer.php"; 211 | 212 | ?> -------------------------------------------------------------------------------- /admincp/actions.php: -------------------------------------------------------------------------------- 1 | run_hook("admin_actions_top"); 9 | 10 | 11 | if(!is_admin()) { 12 | header("Location: $set->url");exit; 13 | } 14 | $fid = (int)$_GET['id']; 15 | 16 | 17 | $links[] = mai_img("arr.gif")." $lang->admincp "; 18 | $links[] = mai_img("arr.gif")." $lang->file_manager "; 19 | 20 | // add 21 | if($_GET['act'] == 'add') { 22 | $file = $db->get_row("SELECT * FROM `". MAI_PREFIX ."files` WHERE `id`='$fid'"); 23 | if(!$file){ 24 | $file = new stdClass(); // php 5.4 fix 25 | $file->path = "/files"; 26 | } 27 | if(!is_dir("..".$file->path)){ 28 | header("Location: $set->url");exit; 29 | } 30 | 31 | $plugins->run_hook("admin_actions_add_top"); 32 | 33 | if($_POST['name']){ 34 | if($db->count("SELECT `id` FROM `". MAI_PREFIX ."files` WHERE `path` = '".$file->path."/".$_POST['name']."'") == 0) { 35 | if($db->insert("INSERT INTO `". MAI_PREFIX ."files` SET `name`='".$db->escape($_POST['name'])."',`path`='".$db->escape($file->path."/".$_POST['name'])."', `icon`='".$db->escape($_POST['icon'])."',`indir`='".(int)$_GET['id']."', `time`='".time()."', `isdir`='1'")){ 36 | mkdir("..".$file->path."/".$_POST['name'],0777); 37 | 38 | $plugins->run_hook("admin_actions_add"); 39 | 40 | // $form .= "
$lang->added
"; 41 | header("Location: $set->url/data/".(int)$_GET['id']."/$file->name.html"); 42 | } 43 | } 44 | } 45 | $links[] = mai_img("arr.gif")." $lang->add "; 46 | 47 | $form .= "
48 | $lang->name :
49 | $lang->icon :
50 |
51 | 52 |
"; 53 | $plugins->run_hook("admin_actions_add_end"); 54 | } 55 | // edit 56 | if($_GET['act'] == 'edit') { 57 | $file = $db->get_row("SELECT * FROM `". MAI_PREFIX ."files` WHERE `id`='$fid'"); 58 | if(!$file) { 59 | header("Location: $set->url"); 60 | exit; 61 | } 62 | $plugins->run_hook("admin_actions_edit_top"); 63 | 64 | if($file->size > 0) 65 | $links[] = mai_img("arr.gif")." $file->name "; 66 | else 67 | $links[] = mai_img("arr.gif")." $file->name "; 68 | if($_POST['name']){ 69 | $path = "/files".$_POST['path']; 70 | $dirid = $db->get_row("SELECT id FROM `". MAI_PREFIX ."files` WHERE `path`='".$path."'")->id; 71 | $real_path = $path."/".basename($file->path); 72 | if($db->query("UPDATE `". MAI_PREFIX ."files` SET `name`='".$db->escape($_POST['name'])."', `icon`='".$db->escape($_POST['icon'])."', `indir`='".$dirid."', `path`= '".$db->escape($real_path)."', `description`='".$db->escape($_POST['description'])."' WHERE `id`='$file->id'")){ 73 | 74 | if($file->path != $real_path){ 75 | if(is_file("..".$file->path)){ 76 | rename("..".$file->path,"..".$real_path); 77 | }else{ 78 | dirmv("..".$file->path,"..".$real_path); 79 | $db->query("UPDATE `". MAI_PREFIX ."files` SET `path`=replace(`path`,'".$db->escape($file->path)."','".$db->escape($real_path)."') WHERE `path` LIKE '".$db->escape($file->path)."%'"); 80 | } 81 | } 82 | $form .= "
$lang->saved
"; 83 | $file->icon = $_POST['icon']; // to keep it updated 84 | $file->name = $_POST['name']; // to keep it updated 85 | $file->path = $real_path; // to keep it updated 86 | $file->description = $_POST['description']; // to keep it updated 87 | $plugins->run_hook("admin_actions_edit"); 88 | } 89 | } 90 | $links[] = mai_img("arr.gif")." $lang->edit "; 91 | 92 | $form .= "
93 | $lang->name :
94 | $lang->icon :
95 | $lang->description :

96 | $lang->path: /".basename($file->path)."
111 | 112 |
"; 113 | $plugins->run_hook("admin_actions_edit_end"); 114 | } 115 | // edit settings 116 | if($_GET['act'] == 'editset') { 117 | $plugins->run_hook("admin_actions_editset_top"); 118 | 119 | $links[count($links)-1] = mai_img("arr.gif")." $lang->settings"; 120 | 121 | if($_GET['sphp']) { // edit settings.php 122 | 123 | $file = MAI_ROOT."/inc/settings.php"; 124 | if(!file_exists($file)) 125 | die("File does not exists !"); 126 | 127 | $links[] = mai_img("arr.gif")." $lang->edit settings.php"; 128 | 129 | if($_POST) 130 | if(file_put_contents($file, $_POST['data'])) 131 | $form .= "
$lang->saved
"; 132 | else 133 | $form .= "
$lang->error
"; 134 | 135 | 136 | 137 | $form .= " 138 |
139 |
140 | 141 |
142 | "; 143 | 144 | 145 | } else { 146 | 147 | if($_POST['msg']){ 148 | if(trim($_POST['pass']) != ''){ 149 | $pass = ", `admin_pass` = '".sha1($_POST['pass'])."'"; 150 | $_SESSION['adminpass'] = sha1($_POST['pass']); 151 | } 152 | if($db->query("UPDATE `". MAI_PREFIX ."settings` SET `main_msg`='".$db->escape($_POST['msg'])."' $pass")){ 153 | $form .= "
$lang->saved
"; 154 | $set->sinfo->main_msg = $_POST['msg']; // to keep it updated 155 | $plugins->run_hook("admin_actions_editset"); 156 | } 157 | } 158 | 159 | 160 | $form .= "
161 | $lang->main_msg :

162 | $lang->password ($lang->keep_blank):

163 |
164 | 165 |

166 | » $lang->edit settings.php"; 167 | $plugins->run_hook("admin_actions_editset_end"); 168 | } 169 | } 170 | //delete 171 | if($_GET['act'] == 'delete') { 172 | $file = $db->get_row("SELECT * FROM `". MAI_PREFIX ."files` WHERE `id`='$fid'"); 173 | if(!$file) { 174 | header("Location: $set->url"); 175 | exit; 176 | } 177 | $plugins->run_hook("admin_actions_delete_top"); 178 | if($file->size > 0) 179 | $links[] = mai_img("arr.gif")." $file->name "; 180 | else 181 | $links[] = mai_img("arr.gif")." $file->name "; 182 | $links[] = mai_img("arr.gif")." $lang->delete "; 183 | if($_POST['yes']){ 184 | if(is_dir("..".$file->path)){ 185 | deleteAll("..".$file->path); 186 | $db->query("DELETE FROM `". MAI_PREFIX ."files` WHERE `path` LIKE '$file->path%'"); 187 | $plugins->run_hook("admin_actions_delete_a"); 188 | }else { 189 | @unlink("..".$file->path); 190 | $db->query("DELETE FROM `". MAI_PREFIX ."files` WHERE `id`='$file->id'"); 191 | $plugins->run_hook("admin_actions_delete_b"); 192 | } 193 | $form = "
$lang->data_gone
"; 194 | }else { 195 | $form .="
196 | $lang->are_you_sure
197 | $lang->no 198 |
"; 199 | } 200 | $plugins->run_hook("admin_actions_delete_end"); 201 | } 202 | 203 | include "../header.php"; 204 | $tpl->grab("admin_actions.tpl","admin_actions"); 205 | $tpl->assign("form",$form); 206 | $tpl->display(); 207 | 208 | $plugins->run_hook("admin_actions_end"); 209 | 210 | include "../footer.php"; -------------------------------------------------------------------------------- /admincp/plugin_manager.php: -------------------------------------------------------------------------------- 1 | run_hook("plugin_manager_top"); 13 | 14 | if(!is_admin()) { 15 | ob_end_clean(); 16 | header("Location: $set->url");exit; 17 | } 18 | $links[] = mai_img("arr.gif")." $lang->admincp "; 19 | $links[] = mai_img("arr.gif")." $lang->plugin_manager"; 20 | 21 | $plugins->load(true); // we don't run plugins here 22 | $act = $_GET['act']; 23 | $page = (int)$_GET['page'] == 0 ? 1 : (int)$_GET['page']; 24 | 25 | // activate 26 | if($act == 'activate'){ 27 | $plug = $_GET['plugin']; 28 | $active_plugins = unserialize($set->sinfo->active_plugins); 29 | if(!is_array($active_plugins)) 30 | $active_plugins = array(); 31 | 32 | $active_plugins[] = $plug; 33 | $db->query("UPDATE `".MAI_PREFIX."settings` SET `active_plugins` = '".serialize(array_unique($active_plugins))."'"); 34 | 35 | if(is_callable($plug."_activate")){ 36 | call_user_func($plug."_activate"); 37 | } 38 | ob_end_clean(); 39 | header("Location: ?page=$page"); 40 | exit; 41 | } 42 | // deactivate 43 | if($act == 'deactivate'){ 44 | $plug = $_GET['plugin']; 45 | $active_plugins = unserialize($set->sinfo->active_plugins); 46 | if(!is_array($active_plugins)) 47 | $active_plugins = array(); 48 | 49 | $active_plugins = array_remove_value($active_plugins,$plug); 50 | 51 | $db->query("UPDATE `".MAI_PREFIX."settings` SET `active_plugins` = '".serialize(array_unique($active_plugins))."'"); 52 | 53 | if(is_callable($plug."_deactivate")){ 54 | call_user_func($plug."_deactivate"); 55 | } 56 | ob_end_clean(); 57 | header("Location: ?page=$page"); 58 | exit; 59 | } 60 | 61 | // install 62 | if($act == "install"){ 63 | $plug = $_GET['plugin']; 64 | if(is_callable($plug."_install")){ 65 | call_user_func($plug."_install"); 66 | } 67 | ob_end_clean(); 68 | header("Location: ?page=$page"); 69 | exit; 70 | 71 | } 72 | 73 | // uninstall 74 | if($act == "uninstall"){ 75 | $plug = $_GET['plugin']; 76 | 77 | if($_POST['yes']){ 78 | // if it's active 79 | if(in_array($plug,unserialize($set->sinfo->active_plugins))){ 80 | // we deactivate 81 | $active_plugins = unserialize($set->sinfo->active_plugins); 82 | if(!is_array($active_plugins)) 83 | $active_plugins = array(); 84 | 85 | $active_plugins = array_remove_value($active_plugins,$plug); 86 | 87 | $db->query("UPDATE `".MAI_PREFIX."settings` SET `active_plugins` = '".serialize(array_unique($active_plugins))."'"); 88 | if(is_callable($plug."_deactivate")){ 89 | call_user_func($plug."_deactivate"); 90 | } 91 | } 92 | // we uninstall 93 | if(is_callable($plug."_uninstall")){ 94 | call_user_func($plug."_uninstall"); 95 | } 96 | ob_end_clean(); 97 | header("Location: ?page=$page"); 98 | exit; 99 | }else { 100 | 101 | $content = "
102 |
103 | $lang->are_you_sure
104 | $lang->cancel 105 |
106 |
"; 107 | } 108 | ////// settings 109 | }elseif($act == "settings"){ 110 | $content .= "
".htmlentities($_GET['plugin'])." - $lang->settings
"; 111 | $plug = $_GET['plugin']; 112 | 113 | if($_POST){ 114 | $on_save = true; 115 | $fail_message = 'fail'; // use this var to store any error message in _on_save() 116 | if(is_callable($plug."_on_save")){ 117 | $on_save = (bool)call_user_func($plug."_on_save"); 118 | } 119 | 120 | if($on_save){ 121 | foreach($_POST as $k => $v){ 122 | if(is_array($v)) 123 | $value = $db->escape(serialize($v)); 124 | else 125 | $value = $db->escape($v); 126 | 127 | $db->query("UPDATE `".MAI_PREFIX."plugins_settings` SET `value`='$value' WHERE `name` = '".$db->escape($k)."'"); 128 | } 129 | 130 | $content .= "
$lang->saved
"; 131 | } else 132 | $content .= "
$fail_message
"; 133 | } 134 | 135 | 136 | $data = $db->select("SELECT * FROM `".MAI_PREFIX."plugins_settings` WHERE `plugin` = '".$db->escape($plug)."'"); 137 | // is it active ?? 138 | if(!in_array($plug,unserialize($set->sinfo->active_plugins)) OR !$data){ 139 | ob_end_clean(); 140 | header("Location: ?page=$page");exit; 141 | } 142 | $content .= "
"; 143 | foreach($data as $p){ 144 | $content .="
$p->title
$p->description
"; 145 | if($p->type == 'yesno'){ 146 | $content .=""; 150 | } 151 | if($p->type == 'onoff'){ 152 | $content .=""; 156 | } 157 | if($p->type == 'textarea'){ 158 | $content .=""; 159 | } 160 | if($p->type == 'text'){ 161 | $content .=""; 162 | } 163 | if(preg_match("~select(.+)~i",$p->type)){ 164 | $type=explode("\n",$p->type); 165 | $content .= ""; 172 | } 173 | if(preg_match("~radio(.+)~i",$p->type)){ 174 | $type=explode("\n",$p->type); 175 | for($i=1;$i <= count($type); $i++){ 176 | $val = explode("=",$type[$i]); 177 | if(trim($val[0]) != '') 178 | $content .= "value == $val[0] ? " checked='vmi'" : "").">".htmlentities($val[1])."
"; 179 | } 180 | } 181 | if(preg_match("~checkbox(.+)~i",$p->type)){ 182 | $type=explode("\n",$p->type); 183 | for($i=1;$i <= count($type); $i++){ 184 | $val = explode("=",$type[$i]); 185 | if(trim($val[0]) != '') 186 | $content .= "value)) ? " checked='vmi'" : "").">".htmlentities($val[1])."
"; 187 | } 188 | } 189 | $content .="
"; 190 | } 191 | $content .= "
192 | "; 193 | }else { 194 | // plugin list 195 | include "../lib/array_pagination.class.php"; 196 | include "../lib/pagination.class.php"; 197 | 198 | $plugs_list = glob("../plugins/*_plugin.php"); 199 | 200 | $total_results = count($plugs_list); 201 | // pagination 202 | $perpage = $_SESSION['perp'] ? (int)$_SESSION['perp'] : $set->perpage; 203 | // $page is defined in the first lines 204 | if($page > ceil($total_results/$perpage)) $page = ceil($total_results/$perpage); 205 | $start = ($page-1)*$perpage; 206 | 207 | $s_pages = new pag($total_results,$page,$perpage); 208 | $show_pages = $lang->pages.": ".$s_pages->pages; 209 | 210 | $a_pag = new array_pagination; 211 | $plugs = $a_pag->generate($plugs_list,$perpage); 212 | 213 | foreach($plugs as $plug){ 214 | // grab the plugin name this is why the name of the plugin must be 215 | // _plugin.php 216 | $plug =substr(basename($plug),0,-11); 217 | 218 | $content .= "
"; 219 | if(is_callable($plug."_info")){ 220 | $info = (object)call_user_func($plug."_info"); 221 | } 222 | $content .= $info->name !='' ? $info->name : $plug; 223 | 224 | if(is_callable($plug."_uninstall")) 225 | $uninstall = " - $lang->uninstall"; 226 | else 227 | $uninstall = ''; 228 | if(is_callable($plug."_is_installed")){ 229 | $is_installed = (bool)call_user_func($plug."_is_installed"); 230 | }else 231 | $is_installed = true; 232 | 233 | if($is_installed){ 234 | $is_active = in_array($plug,unserialize($set->sinfo->active_plugins)); 235 | if($is_active){ 236 | // check for settings 237 | if($db->count("SELECT `name` FROM `".MAI_PREFIX."plugins_settings` WHERE `plugin` = '".$db->escape($plug)."'") > 0) 238 | $content .= " - $lang->settings "; 239 | $content .= " - $lang->deactivate"; 240 | }else 241 | $content .= " - $lang->activate"; 242 | 243 | // show uninstall 244 | $content .= $uninstall; 245 | } else { 246 | $content .= " - $lang->install"; 247 | } 248 | 249 | if($db->count("SELECT `name` FROM `".MAI_PREFIX."plugins_settings` WHERE `plugin` = '".$db->escape($plug)."'") > 0) 250 | $have_set = true; 251 | 252 | $content .= "
".($info->author !='' ? "$lang->author ".($info->author_site !='' ? "$info->author" : $info->author)."
" : "")."$info->description
"; 253 | $content .= "
"; 254 | } 255 | $content .= "
$show_pages
"; 256 | 257 | } 258 | 259 | include "../header.php"; 260 | $tpl->grab("plugin_manager.tpl","plugin_manager"); 261 | $tpl->assign("content",$content); 262 | $tpl->display(); 263 | $plugins->run_hook("plugin_manager_end"); 264 | include "../footer.php"; -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. 5 | 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Library General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License 307 | along with this program; if not, write to the Free Software 308 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 309 | 310 | 311 | Also add information on how to contact you by electronic and paper mail. 312 | 313 | If the program is interactive, make it output a short notice like this 314 | when it starts in an interactive mode: 315 | 316 | Gnomovision version 69, Copyright (C) year name of author 317 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 318 | This is free software, and you are welcome to redistribute it 319 | under certain conditions; type `show c' for details. 320 | 321 | The hypothetical commands `show w' and `show c' should show the appropriate 322 | parts of the General Public License. Of course, the commands you use may 323 | be called something other than `show w' and `show c'; they could even be 324 | mouse-clicks or menu items--whatever suits your program. 325 | 326 | You should also get your employer (if you work as a programmer) or your 327 | school, if any, to sign a "copyright disclaimer" for the program, if 328 | necessary. Here is a sample; alter the names: 329 | 330 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 331 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 332 | 333 | , 1 April 1989 334 | Ty Coon, President of Vice 335 | 336 | This General Public License does not permit incorporating your program into 337 | proprietary programs. If your program is a subroutine library, you may 338 | consider it more useful to permit linking proprietary applications with the 339 | library. If this is what you want to do, use the GNU Library General 340 | Public License instead of this License. 341 | -------------------------------------------------------------------------------- /thumb.php: -------------------------------------------------------------------------------- 1 | url.base64_decode($_REQUEST['src']); 9 | 10 | 11 | 12 | 13 | /** 14 | * TimThumb by Ben Gillbanks and Mark Maunder 15 | * Based on work done by Tim McDaniels and Darren Hoyt 16 | * http://code.google.com/p/timthumb/ 17 | * 18 | * GNU General Public License, version 2 19 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 20 | * 21 | * Examples and documentation available on the project homepage 22 | * http://www.binarymoon.co.uk/projects/timthumb/ 23 | * 24 | * $Rev$ 25 | */ 26 | 27 | /* 28 | * --- TimThumb CONFIGURATION --- 29 | * To edit the configs it is best to create a file called timthumb-config.php 30 | * and define variables you want to customize in there. It will automatically be 31 | * loaded by timthumb. This will save you having to re-edit these variables 32 | * everytime you download a new version 33 | */ 34 | define ('VERSION', '2.8.10'); // Version of this script 35 | //Load a config file if it exists. Otherwise, use the values below 36 | if( file_exists(dirname(__FILE__) . '/timthumb-config.php')) require_once('timthumb-config.php'); 37 | if(! defined('DEBUG_ON') ) define ('DEBUG_ON', false); // Enable debug logging to web server error log (STDERR) 38 | if(! defined('DEBUG_LEVEL') ) define ('DEBUG_LEVEL', 1); // Debug level 1 is less noisy and 3 is the most noisy 39 | if(! defined('MEMORY_LIMIT') ) define ('MEMORY_LIMIT', '30M'); // Set PHP memory limit 40 | if(! defined('BLOCK_EXTERNAL_LEECHERS') ) define ('BLOCK_EXTERNAL_LEECHERS', false); // If the image or webshot is being loaded on an external site, display a red "No Hotlinking" gif. 41 | 42 | //Image fetching and caching 43 | if(! defined('ALLOW_EXTERNAL') ) define ('ALLOW_EXTERNAL', TRUE); // Allow image fetching from external websites. Will check against ALLOWED_SITES if ALLOW_ALL_EXTERNAL_SITES is false 44 | if(! defined('ALLOW_ALL_EXTERNAL_SITES') ) define ('ALLOW_ALL_EXTERNAL_SITES', true); // Less secure. 45 | if(! defined('FILE_CACHE_ENABLED') ) define ('FILE_CACHE_ENABLED', TRUE); // Should we store resized/modified images on disk to speed things up? 46 | if(! defined('FILE_CACHE_TIME_BETWEEN_CLEANS')) define ('FILE_CACHE_TIME_BETWEEN_CLEANS', 86400); // How often the cache is cleaned 47 | 48 | if(! defined('FILE_CACHE_MAX_FILE_AGE') ) define ('FILE_CACHE_MAX_FILE_AGE', 86400); // How old does a file have to be to be deleted from the cache 49 | if(! defined('FILE_CACHE_SUFFIX') ) define ('FILE_CACHE_SUFFIX', '.timthumb.txt'); // What to put at the end of all files in the cache directory so we can identify them 50 | if(! defined('FILE_CACHE_PREFIX') ) define ('FILE_CACHE_PREFIX', 'timthumb'); // What to put at the beg of all files in the cache directory so we can identify them 51 | if(! defined('FILE_CACHE_DIRECTORY') ) define ('FILE_CACHE_DIRECTORY', './cache'); // Directory where images are cached. Left blank it will use the system temporary directory (which is better for security) 52 | if(! defined('MAX_FILE_SIZE') ) define ('MAX_FILE_SIZE', 10485760); // 10 Megs is 10485760. This is the max internal or external file size that we'll process. 53 | if(! defined('CURL_TIMEOUT') ) define ('CURL_TIMEOUT', 20); // Timeout duration for Curl. This only applies if you have Curl installed and aren't using PHP's default URL fetching mechanism. 54 | if(! defined('WAIT_BETWEEN_FETCH_ERRORS') ) define ('WAIT_BETWEEN_FETCH_ERRORS', 3600); //Time to wait between errors fetching remote file 55 | 56 | //Browser caching 57 | if(! defined('BROWSER_CACHE_MAX_AGE') ) define ('BROWSER_CACHE_MAX_AGE', 864000); // Time to cache in the browser 58 | if(! defined('BROWSER_CACHE_DISABLE') ) define ('BROWSER_CACHE_DISABLE', false); // Use for testing if you want to disable all browser caching 59 | 60 | //Image size and defaults 61 | if(! defined('MAX_WIDTH') ) define ('MAX_WIDTH', 1500); // Maximum image width 62 | if(! defined('MAX_HEIGHT') ) define ('MAX_HEIGHT', 1500); // Maximum image height 63 | if(! defined('NOT_FOUND_IMAGE') ) define ('NOT_FOUND_IMAGE', ''); // Image to serve if any 404 occurs 64 | if(! defined('ERROR_IMAGE') ) define ('ERROR_IMAGE', ''); // Image to serve if an error occurs instead of showing error message 65 | if(! defined('PNG_IS_TRANSPARENT') ) define ('PNG_IS_TRANSPARENT', FALSE); //42 Define if a png image should have a transparent background color. Use False value if you want to display a custom coloured canvas_colour 66 | if(! defined('DEFAULT_Q') ) define ('DEFAULT_Q', 90); // Default image quality. Allows overrid in timthumb-config.php 67 | if(! defined('DEFAULT_ZC') ) define ('DEFAULT_ZC', 1); // Default zoom/crop setting. Allows overrid in timthumb-config.php 68 | if(! defined('DEFAULT_F') ) define ('DEFAULT_F', ''); // Default image filters. Allows overrid in timthumb-config.php 69 | if(! defined('DEFAULT_S') ) define ('DEFAULT_S', 0); // Default sharpen value. Allows overrid in timthumb-config.php 70 | if(! defined('DEFAULT_CC') ) define ('DEFAULT_CC', 'ffffff'); // Default canvas colour. Allows overrid in timthumb-config.php 71 | 72 | 73 | //Image compression is enabled if either of these point to valid paths 74 | 75 | //These are now disabled by default because the file sizes of PNGs (and GIFs) are much smaller than we used to generate. 76 | //They only work for PNGs. GIFs and JPEGs are not affected. 77 | if(! defined('OPTIPNG_ENABLED') ) define ('OPTIPNG_ENABLED', false); 78 | if(! defined('OPTIPNG_PATH') ) define ('OPTIPNG_PATH', '/usr/bin/optipng'); //This will run first because it gives better compression than pngcrush. 79 | if(! defined('PNGCRUSH_ENABLED') ) define ('PNGCRUSH_ENABLED', false); 80 | if(! defined('PNGCRUSH_PATH') ) define ('PNGCRUSH_PATH', '/usr/bin/pngcrush'); //This will only run if OPTIPNG_PATH is not set or is not valid 81 | 82 | /* 83 | -------====Website Screenshots configuration - BETA====------- 84 | 85 | If you just want image thumbnails and don't want website screenshots, you can safely leave this as is. 86 | 87 | If you would like to get website screenshots set up, you will need root access to your own server. 88 | 89 | Enable ALLOW_ALL_EXTERNAL_SITES so you can fetch any external web page. This is more secure now that we're using a non-web folder for cache. 90 | Enable BLOCK_EXTERNAL_LEECHERS so that your site doesn't generate thumbnails for the whole Internet. 91 | 92 | Instructions to get website screenshots enabled on Ubuntu Linux: 93 | 94 | 1. Install Xvfb with the following command: sudo apt-get install subversion libqt4-webkit libqt4-dev g++ xvfb 95 | 2. Go to a directory where you can download some code 96 | 3. Check-out the latest version of CutyCapt with the following command: svn co https://cutycapt.svn.sourceforge.net/svnroot/cutycapt 97 | 4. Compile CutyCapt by doing: cd cutycapt/CutyCapt 98 | 5. qmake 99 | 6. make 100 | 7. cp CutyCapt /usr/local/bin/ 101 | 8. Test it by running: xvfb-run --server-args="-screen 0, 1024x768x24" CutyCapt --url="http://markmaunder.com/" --out=test.png 102 | 9. If you get a file called test.png with something in it, it probably worked. Now test the script by accessing it as follows: 103 | 10. http://yoursite.com/path/to/timthumb.php?src=http://markmaunder.com/&webshot=1 104 | 105 | Notes on performance: 106 | The first time a webshot loads, it will take a few seconds. 107 | From then on it uses the regular timthumb caching mechanism with the configurable options above 108 | and loading will be very fast. 109 | 110 | --ADVANCED USERS ONLY-- 111 | If you'd like a slight speedup (about 25%) and you know Linux, you can run the following command which will keep Xvfb running in the background. 112 | nohup Xvfb :100 -ac -nolisten tcp -screen 0, 1024x768x24 > /dev/null 2>&1 & 113 | Then set WEBSHOT_XVFB_RUNNING = true below. This will save your server having to fire off a new Xvfb server and shut it down every time a new shot is generated. 114 | You will need to take responsibility for keeping Xvfb running in case it crashes. (It seems pretty stable) 115 | You will also need to take responsibility for server security if you're running Xvfb as root. 116 | 117 | 118 | */ 119 | if(! defined('WEBSHOT_ENABLED') ) define ('WEBSHOT_ENABLED', false); //Beta feature. Adding webshot=1 to your query string will cause the script to return a browser screenshot rather than try to fetch an image. 120 | if(! defined('WEBSHOT_CUTYCAPT') ) define ('WEBSHOT_CUTYCAPT', '/usr/local/bin/CutyCapt'); //The path to CutyCapt. 121 | if(! defined('WEBSHOT_XVFB') ) define ('WEBSHOT_XVFB', '/usr/bin/xvfb-run'); //The path to the Xvfb server 122 | if(! defined('WEBSHOT_SCREEN_X') ) define ('WEBSHOT_SCREEN_X', '1024'); //1024 works ok 123 | if(! defined('WEBSHOT_SCREEN_Y') ) define ('WEBSHOT_SCREEN_Y', '768'); //768 works ok 124 | if(! defined('WEBSHOT_COLOR_DEPTH') ) define ('WEBSHOT_COLOR_DEPTH', '24'); //I haven't tested anything besides 24 125 | if(! defined('WEBSHOT_IMAGE_FORMAT') ) define ('WEBSHOT_IMAGE_FORMAT', 'png'); //png is about 2.5 times the size of jpg but is a LOT better quality 126 | if(! defined('WEBSHOT_TIMEOUT') ) define ('WEBSHOT_TIMEOUT', '20'); //Seconds to wait for a webshot 127 | if(! defined('WEBSHOT_USER_AGENT') ) define ('WEBSHOT_USER_AGENT', "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.18) Gecko/20110614 Firefox/3.6.18"); //I hate to do this, but a non-browser robot user agent might not show what humans see. So we pretend to be Firefox 128 | if(! defined('WEBSHOT_JAVASCRIPT_ON') ) define ('WEBSHOT_JAVASCRIPT_ON', true); //Setting to false might give you a slight speedup and block ads. But it could cause other issues. 129 | if(! defined('WEBSHOT_JAVA_ON') ) define ('WEBSHOT_JAVA_ON', false); //Have only tested this as fase 130 | if(! defined('WEBSHOT_PLUGINS_ON') ) define ('WEBSHOT_PLUGINS_ON', true); //Enable flash and other plugins 131 | if(! defined('WEBSHOT_PROXY') ) define ('WEBSHOT_PROXY', ''); //In case you're behind a proxy server. 132 | if(! defined('WEBSHOT_XVFB_RUNNING') ) define ('WEBSHOT_XVFB_RUNNING', false); //ADVANCED: Enable this if you've got Xvfb running in the background. 133 | 134 | 135 | // If ALLOW_EXTERNAL is true and ALLOW_ALL_EXTERNAL_SITES is false, then external images will only be fetched from these domains and their subdomains. 136 | if(! isset($ALLOWED_SITES)){ 137 | $ALLOWED_SITES = array ( 138 | 'flickr.com', 139 | 'staticflickr.com', 140 | 'picasa.com', 141 | 'img.youtube.com', 142 | 'upload.wikimedia.org', 143 | 'photobucket.com', 144 | 'imgur.com', 145 | 'imageshack.us', 146 | 'tinypic.com', 147 | ); 148 | } 149 | // ------------------------------------------------------------- 150 | // -------------- STOP EDITING CONFIGURATION HERE -------------- 151 | // ------------------------------------------------------------- 152 | 153 | timthumb::start(); 154 | 155 | class timthumb { 156 | protected $src = ""; 157 | protected $is404 = false; 158 | protected $docRoot = ""; 159 | protected $lastURLError = false; 160 | protected $localImage = ""; 161 | protected $localImageMTime = 0; 162 | protected $url = false; 163 | protected $myHost = ""; 164 | protected $isURL = false; 165 | protected $cachefile = ''; 166 | protected $errors = array(); 167 | protected $toDeletes = array(); 168 | protected $cacheDirectory = ''; 169 | protected $startTime = 0; 170 | protected $lastBenchTime = 0; 171 | protected $cropTop = false; 172 | protected $salt = ""; 173 | protected $fileCacheVersion = 1; //Generally if timthumb.php is modifed (upgraded) then the salt changes and all cache files are recreated. This is a backup mechanism to force regen. 174 | protected $filePrependSecurityBlock = "handleErrors(); 180 | $tim->securityChecks(); 181 | if($tim->tryBrowserCache()){ 182 | exit(0); 183 | } 184 | $tim->handleErrors(); 185 | if(FILE_CACHE_ENABLED && $tim->tryServerCache()){ 186 | exit(0); 187 | } 188 | $tim->handleErrors(); 189 | $tim->run(); 190 | $tim->handleErrors(); 191 | exit(0); 192 | } 193 | public function __construct(){ 194 | global $ALLOWED_SITES; 195 | $this->startTime = microtime(true); 196 | date_default_timezone_set('UTC'); 197 | $this->debug(1, "Starting new request from " . $this->getIP() . " to " . $_SERVER['REQUEST_URI']); 198 | $this->calcDocRoot(); 199 | //On windows systems I'm assuming fileinode returns an empty string or a number that doesn't change. Check this. 200 | $this->salt = @filemtime(__FILE__) . '-' . @fileinode(__FILE__); 201 | $this->debug(3, "Salt is: " . $this->salt); 202 | if(FILE_CACHE_DIRECTORY){ 203 | if(! is_dir(FILE_CACHE_DIRECTORY)){ 204 | @mkdir(FILE_CACHE_DIRECTORY); 205 | if(! is_dir(FILE_CACHE_DIRECTORY)){ 206 | $this->error("Could not create the file cache directory."); 207 | return false; 208 | } 209 | } 210 | $this->cacheDirectory = FILE_CACHE_DIRECTORY; 211 | if (!touch($this->cacheDirectory . '/index.html')) { 212 | $this->error("Could not create the index.html file - to fix this create an empty file named index.html file in the cache directory."); 213 | } 214 | } else { 215 | $this->cacheDirectory = sys_get_temp_dir(); 216 | } 217 | //Clean the cache before we do anything because we don't want the first visitor after FILE_CACHE_TIME_BETWEEN_CLEANS expires to get a stale image. 218 | $this->cleanCache(); 219 | 220 | $this->myHost = preg_replace('/^www\./i', '', $_SERVER['HTTP_HOST']); 221 | $this->src = $this->param('src'); 222 | $this->url = parse_url($this->src); 223 | $this->src = preg_replace('/https?:\/\/(?:www\.)?' . $this->myHost . '/i', '', $this->src); 224 | 225 | if(strlen($this->src) <= 3){ 226 | $this->error("No image specified"); 227 | return false; 228 | } 229 | if(BLOCK_EXTERNAL_LEECHERS && array_key_exists('HTTP_REFERER', $_SERVER) && (! preg_match('/^https?:\/\/(?:www\.)?' . $this->myHost . '(?:$|\/)/i', $_SERVER['HTTP_REFERER']))){ 230 | // base64 encoded red image that says 'no hotlinkers' 231 | // nothing to worry about! :) 232 | $imgData = base64_decode("R0lGODlhUAAMAIAAAP8AAP///yH5BAAHAP8ALAAAAABQAAwAAAJpjI+py+0Po5y0OgAMjjv01YUZ\nOGplhWXfNa6JCLnWkXplrcBmW+spbwvaVr/cDyg7IoFC2KbYVC2NQ5MQ4ZNao9Ynzjl9ScNYpneb\nDULB3RP6JuPuaGfuuV4fumf8PuvqFyhYtjdoeFgAADs="); 233 | header('Content-Type: image/gif'); 234 | header('Content-Length: ' . sizeof($imgData)); 235 | header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0'); 236 | header("Pragma: no-cache"); 237 | header('Expires: ' . gmdate ('D, d M Y H:i:s', time())); 238 | echo $imgData; 239 | return false; 240 | exit(0); 241 | } 242 | if(preg_match('/^https?:\/\/[^\/]+/i', $this->src)){ 243 | $this->debug(2, "Is a request for an external URL: " . $this->src); 244 | $this->isURL = true; 245 | } else { 246 | $this->debug(2, "Is a request for an internal file: " . $this->src); 247 | } 248 | if($this->isURL && (! ALLOW_EXTERNAL)){ 249 | $this->error("You are not allowed to fetch images from an external website."); 250 | return false; 251 | } 252 | if($this->isURL){ 253 | if(ALLOW_ALL_EXTERNAL_SITES){ 254 | $this->debug(2, "Fetching from all external sites is enabled."); 255 | } else { 256 | $this->debug(2, "Fetching only from selected external sites is enabled."); 257 | $allowed = false; 258 | foreach($ALLOWED_SITES as $site){ 259 | if ((strtolower(substr($this->url['host'],-strlen($site)-1)) === strtolower(".$site")) || (strtolower($this->url['host'])===strtolower($site))) { 260 | $this->debug(3, "URL hostname {$this->url['host']} matches $site so allowing."); 261 | $allowed = true; 262 | } 263 | } 264 | if(! $allowed){ 265 | return $this->error("You may not fetch images from that site. To enable this site in timthumb, you can either add it to \$ALLOWED_SITES and set ALLOW_EXTERNAL=true. Or you can set ALLOW_ALL_EXTERNAL_SITES=true, depending on your security needs."); 266 | } 267 | } 268 | } 269 | 270 | $cachePrefix = ($this->isURL ? '_ext_' : '_int_'); 271 | if($this->isURL){ 272 | $arr = explode('&', $_SERVER ['QUERY_STRING']); 273 | asort($arr); 274 | $this->cachefile = $this->cacheDirectory . '/' . FILE_CACHE_PREFIX . $cachePrefix . md5($this->salt . implode('', $arr) . $this->fileCacheVersion) . FILE_CACHE_SUFFIX; 275 | } else { 276 | $this->localImage = $this->getLocalImagePath($this->src); 277 | if(! $this->localImage){ 278 | $this->debug(1, "Could not find the local image: {$this->localImage}"); 279 | $this->error("Could not find the internal image you specified."); 280 | $this->set404(); 281 | return false; 282 | } 283 | $this->debug(1, "Local image path is {$this->localImage}"); 284 | $this->localImageMTime = @filemtime($this->localImage); 285 | //We include the mtime of the local file in case in changes on disk. 286 | $this->cachefile = $this->cacheDirectory . '/' . FILE_CACHE_PREFIX . $cachePrefix . md5($this->salt . $this->localImageMTime . $_SERVER ['QUERY_STRING'] . $this->fileCacheVersion) . FILE_CACHE_SUFFIX; 287 | } 288 | $this->debug(2, "Cache file is: " . $this->cachefile); 289 | 290 | return true; 291 | } 292 | public function __destruct(){ 293 | foreach($this->toDeletes as $del){ 294 | $this->debug(2, "Deleting temp file $del"); 295 | @unlink($del); 296 | } 297 | } 298 | public function run(){ 299 | if($this->isURL){ 300 | if(! ALLOW_EXTERNAL){ 301 | $this->debug(1, "Got a request for an external image but ALLOW_EXTERNAL is disabled so returning error msg."); 302 | $this->error("You are not allowed to fetch images from an external website."); 303 | return false; 304 | } 305 | $this->debug(3, "Got request for external image. Starting serveExternalImage."); 306 | if($this->param('webshot')){ 307 | if(WEBSHOT_ENABLED){ 308 | $this->debug(3, "webshot param is set, so we're going to take a webshot."); 309 | $this->serveWebshot(); 310 | } else { 311 | $this->error("You added the webshot parameter but webshots are disabled on this server. You need to set WEBSHOT_ENABLED == true to enable webshots."); 312 | } 313 | } else { 314 | $this->debug(3, "webshot is NOT set so we're going to try to fetch a regular image."); 315 | $this->serveExternalImage(); 316 | 317 | } 318 | } else { 319 | $this->debug(3, "Got request for internal image. Starting serveInternalImage()"); 320 | $this->serveInternalImage(); 321 | } 322 | return true; 323 | } 324 | protected function handleErrors(){ 325 | if($this->haveErrors()){ 326 | if(NOT_FOUND_IMAGE && $this->is404()){ 327 | if($this->serveImg(NOT_FOUND_IMAGE)){ 328 | exit(0); 329 | } else { 330 | $this->error("Additionally, the 404 image that is configured could not be found or there was an error serving it."); 331 | } 332 | } 333 | if(ERROR_IMAGE){ 334 | if($this->serveImg(ERROR_IMAGE)){ 335 | exit(0); 336 | } else { 337 | $this->error("Additionally, the error image that is configured could not be found or there was an error serving it."); 338 | } 339 | } 340 | $this->serveErrors(); 341 | exit(0); 342 | } 343 | return false; 344 | } 345 | protected function tryBrowserCache(){ 346 | if(BROWSER_CACHE_DISABLE){ $this->debug(3, "Browser caching is disabled"); return false; } 347 | if(!empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) ){ 348 | $this->debug(3, "Got a conditional get"); 349 | $mtime = false; 350 | //We've already checked if the real file exists in the constructor 351 | if(! is_file($this->cachefile)){ 352 | //If we don't have something cached, regenerate the cached image. 353 | return false; 354 | } 355 | if($this->localImageMTime){ 356 | $mtime = $this->localImageMTime; 357 | $this->debug(3, "Local real file's modification time is $mtime"); 358 | } else if(is_file($this->cachefile)){ //If it's not a local request then use the mtime of the cached file to determine the 304 359 | $mtime = @filemtime($this->cachefile); 360 | $this->debug(3, "Cached file's modification time is $mtime"); 361 | } 362 | if(! $mtime){ return false; } 363 | 364 | $iftime = strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']); 365 | $this->debug(3, "The conditional get's if-modified-since unixtime is $iftime"); 366 | if($iftime < 1){ 367 | $this->debug(3, "Got an invalid conditional get modified since time. Returning false."); 368 | return false; 369 | } 370 | if($iftime < $mtime){ //Real file or cache file has been modified since last request, so force refetch. 371 | $this->debug(3, "File has been modified since last fetch."); 372 | return false; 373 | } else { //Otherwise serve a 304 374 | $this->debug(3, "File has not been modified since last get, so serving a 304."); 375 | header ($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified'); 376 | $this->debug(1, "Returning 304 not modified"); 377 | return true; 378 | } 379 | } 380 | return false; 381 | } 382 | protected function tryServerCache(){ 383 | $this->debug(3, "Trying server cache"); 384 | if(file_exists($this->cachefile)){ 385 | $this->debug(3, "Cachefile {$this->cachefile} exists"); 386 | if($this->isURL){ 387 | $this->debug(3, "This is an external request, so checking if the cachefile is empty which means the request failed previously."); 388 | if(filesize($this->cachefile) < 1){ 389 | $this->debug(3, "Found an empty cachefile indicating a failed earlier request. Checking how old it is."); 390 | //Fetching error occured previously 391 | if(time() - @filemtime($this->cachefile) > WAIT_BETWEEN_FETCH_ERRORS){ 392 | $this->debug(3, "File is older than " . WAIT_BETWEEN_FETCH_ERRORS . " seconds. Deleting and returning false so app can try and load file."); 393 | @unlink($this->cachefile); 394 | return false; //to indicate we didn't serve from cache and app should try and load 395 | } else { 396 | $this->debug(3, "Empty cachefile is still fresh so returning message saying we had an error fetching this image from remote host."); 397 | $this->set404(); 398 | $this->error("An error occured fetching image."); 399 | return false; 400 | } 401 | } 402 | } else { 403 | $this->debug(3, "Trying to serve cachefile {$this->cachefile}"); 404 | } 405 | if($this->serveCacheFile()){ 406 | $this->debug(3, "Succesfully served cachefile {$this->cachefile}"); 407 | return true; 408 | } else { 409 | $this->debug(3, "Failed to serve cachefile {$this->cachefile} - Deleting it from cache."); 410 | //Image serving failed. We can't retry at this point, but lets remove it from cache so the next request recreates it 411 | @unlink($this->cachefile); 412 | return true; 413 | } 414 | } 415 | } 416 | protected function error($err){ 417 | $this->debug(3, "Adding error message: $err"); 418 | $this->errors[] = $err; 419 | return false; 420 | 421 | } 422 | protected function haveErrors(){ 423 | if(sizeof($this->errors) > 0){ 424 | return true; 425 | } 426 | return false; 427 | } 428 | protected function serveErrors(){ 429 | header ($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request'); 430 | $html = '
    '; 431 | foreach($this->errors as $err){ 432 | $html .= '
  • ' . htmlentities($err) . '
  • '; 433 | } 434 | $html .= '
'; 435 | echo '

A TimThumb error has occured

The following error(s) occured:
' . $html . '
'; 436 | echo '
Query String : ' . htmlentities ($_SERVER['QUERY_STRING']); 437 | echo '
TimThumb version : ' . VERSION . ''; 438 | } 439 | protected function serveInternalImage(){ 440 | $this->debug(3, "Local image path is $this->localImage"); 441 | if(! $this->localImage){ 442 | $this->sanityFail("localImage not set after verifying it earlier in the code."); 443 | return false; 444 | } 445 | $fileSize = filesize($this->localImage); 446 | if($fileSize > MAX_FILE_SIZE){ 447 | $this->error("The file you specified is greater than the maximum allowed file size."); 448 | return false; 449 | } 450 | if($fileSize <= 0){ 451 | $this->error("The file you specified is <= 0 bytes."); 452 | return false; 453 | } 454 | $this->debug(3, "Calling processImageAndWriteToCache() for local image."); 455 | if($this->processImageAndWriteToCache($this->localImage)){ 456 | $this->serveCacheFile(); 457 | return true; 458 | } else { 459 | return false; 460 | } 461 | } 462 | protected function cleanCache(){ 463 | if (FILE_CACHE_TIME_BETWEEN_CLEANS < 0) { 464 | return; 465 | } 466 | $this->debug(3, "cleanCache() called"); 467 | $lastCleanFile = $this->cacheDirectory . '/timthumb_cacheLastCleanTime.touch'; 468 | 469 | //If this is a new timthumb installation we need to create the file 470 | if(! is_file($lastCleanFile)){ 471 | $this->debug(1, "File tracking last clean doesn't exist. Creating $lastCleanFile"); 472 | if (!touch($lastCleanFile)) { 473 | $this->error("Could not create cache clean timestamp file."); 474 | } 475 | return; 476 | } 477 | if(@filemtime($lastCleanFile) < (time() - FILE_CACHE_TIME_BETWEEN_CLEANS) ){ //Cache was last cleaned more than 1 day ago 478 | $this->debug(1, "Cache was last cleaned more than " . FILE_CACHE_TIME_BETWEEN_CLEANS . " seconds ago. Cleaning now."); 479 | // Very slight race condition here, but worst case we'll have 2 or 3 servers cleaning the cache simultaneously once a day. 480 | if (!touch($lastCleanFile)) { 481 | $this->error("Could not create cache clean timestamp file."); 482 | } 483 | $files = glob($this->cacheDirectory . '/*' . FILE_CACHE_SUFFIX); 484 | if ($files) { 485 | $timeAgo = time() - FILE_CACHE_MAX_FILE_AGE; 486 | foreach($files as $file){ 487 | if(@filemtime($file) < $timeAgo){ 488 | $this->debug(3, "Deleting cache file $file older than max age: " . FILE_CACHE_MAX_FILE_AGE . " seconds"); 489 | @unlink($file); 490 | } 491 | } 492 | } 493 | return true; 494 | } else { 495 | $this->debug(3, "Cache was cleaned less than " . FILE_CACHE_TIME_BETWEEN_CLEANS . " seconds ago so no cleaning needed."); 496 | } 497 | return false; 498 | } 499 | protected function processImageAndWriteToCache($localImage){ 500 | $sData = getimagesize($localImage); 501 | $origType = $sData[2]; 502 | $mimeType = $sData['mime']; 503 | 504 | $this->debug(3, "Mime type of image is $mimeType"); 505 | if(! preg_match('/^image\/(?:gif|jpg|jpeg|png)$/i', $mimeType)){ 506 | return $this->error("The image being resized is not a valid gif, jpg or png."); 507 | } 508 | 509 | if (!function_exists ('imagecreatetruecolor')) { 510 | return $this->error('GD Library Error: imagecreatetruecolor does not exist - please contact your webhost and ask them to install the GD library'); 511 | } 512 | 513 | if (function_exists ('imagefilter') && defined ('IMG_FILTER_NEGATE')) { 514 | $imageFilters = array ( 515 | 1 => array (IMG_FILTER_NEGATE, 0), 516 | 2 => array (IMG_FILTER_GRAYSCALE, 0), 517 | 3 => array (IMG_FILTER_BRIGHTNESS, 1), 518 | 4 => array (IMG_FILTER_CONTRAST, 1), 519 | 5 => array (IMG_FILTER_COLORIZE, 4), 520 | 6 => array (IMG_FILTER_EDGEDETECT, 0), 521 | 7 => array (IMG_FILTER_EMBOSS, 0), 522 | 8 => array (IMG_FILTER_GAUSSIAN_BLUR, 0), 523 | 9 => array (IMG_FILTER_SELECTIVE_BLUR, 0), 524 | 10 => array (IMG_FILTER_MEAN_REMOVAL, 0), 525 | 11 => array (IMG_FILTER_SMOOTH, 0), 526 | ); 527 | } 528 | 529 | // get standard input properties 530 | $new_width = (int) abs ($this->param('w', 0)); 531 | $new_height = (int) abs ($this->param('h', 0)); 532 | $zoom_crop = (int) $this->param('zc', DEFAULT_ZC); 533 | $quality = (int) abs ($this->param('q', DEFAULT_Q)); 534 | $align = $this->cropTop ? 't' : $this->param('a', 'c'); 535 | $filters = $this->param('f', DEFAULT_F); 536 | $sharpen = (bool) $this->param('s', DEFAULT_S); 537 | $canvas_color = $this->param('cc', DEFAULT_CC); 538 | $canvas_trans = (bool) $this->param('ct', '1'); 539 | 540 | // set default width and height if neither are set already 541 | if ($new_width == 0 && $new_height == 0) { 542 | $new_width = 100; 543 | $new_height = 100; 544 | } 545 | 546 | // ensure size limits can not be abused 547 | $new_width = min ($new_width, MAX_WIDTH); 548 | $new_height = min ($new_height, MAX_HEIGHT); 549 | 550 | // set memory limit to be able to have enough space to resize larger images 551 | $this->setMemoryLimit(); 552 | 553 | // open the existing image 554 | $image = $this->openImage ($mimeType, $localImage); 555 | if ($image === false) { 556 | return $this->error('Unable to open image.'); 557 | } 558 | 559 | // Get original width and height 560 | $width = imagesx ($image); 561 | $height = imagesy ($image); 562 | $origin_x = 0; 563 | $origin_y = 0; 564 | 565 | // generate new w/h if not provided 566 | if ($new_width && !$new_height) { 567 | $new_height = floor ($height * ($new_width / $width)); 568 | } else if ($new_height && !$new_width) { 569 | $new_width = floor ($width * ($new_height / $height)); 570 | } 571 | 572 | // scale down and add borders 573 | if ($zoom_crop == 3) { 574 | 575 | $final_height = $height * ($new_width / $width); 576 | 577 | if ($final_height > $new_height) { 578 | $new_width = $width * ($new_height / $height); 579 | } else { 580 | $new_height = $final_height; 581 | } 582 | 583 | } 584 | 585 | // create a new true color image 586 | $canvas = imagecreatetruecolor ($new_width, $new_height); 587 | imagealphablending ($canvas, false); 588 | 589 | if (strlen($canvas_color) == 3) { //if is 3-char notation, edit string into 6-char notation 590 | $canvas_color = str_repeat(substr($canvas_color, 0, 1), 2) . str_repeat(substr($canvas_color, 1, 1), 2) . str_repeat(substr($canvas_color, 2, 1), 2); 591 | } else if (strlen($canvas_color) != 6) { 592 | $canvas_color = DEFAULT_CC; // on error return default canvas color 593 | } 594 | 595 | $canvas_color_R = hexdec (substr ($canvas_color, 0, 2)); 596 | $canvas_color_G = hexdec (substr ($canvas_color, 2, 2)); 597 | $canvas_color_B = hexdec (substr ($canvas_color, 4, 2)); 598 | 599 | // Create a new transparent color for image 600 | // If is a png and PNG_IS_TRANSPARENT is false then remove the alpha transparency 601 | // (and if is set a canvas color show it in the background) 602 | if(preg_match('/^image\/png$/i', $mimeType) && !PNG_IS_TRANSPARENT && $canvas_trans){ 603 | $color = imagecolorallocatealpha ($canvas, $canvas_color_R, $canvas_color_G, $canvas_color_B, 127); 604 | }else{ 605 | $color = imagecolorallocatealpha ($canvas, $canvas_color_R, $canvas_color_G, $canvas_color_B, 0); 606 | } 607 | 608 | 609 | // Completely fill the background of the new image with allocated color. 610 | imagefill ($canvas, 0, 0, $color); 611 | 612 | // scale down and add borders 613 | if ($zoom_crop == 2) { 614 | 615 | $final_height = $height * ($new_width / $width); 616 | 617 | if ($final_height > $new_height) { 618 | 619 | $origin_x = $new_width / 2; 620 | $new_width = $width * ($new_height / $height); 621 | $origin_x = round ($origin_x - ($new_width / 2)); 622 | 623 | } else { 624 | 625 | $origin_y = $new_height / 2; 626 | $new_height = $final_height; 627 | $origin_y = round ($origin_y - ($new_height / 2)); 628 | 629 | } 630 | 631 | } 632 | 633 | // Restore transparency blending 634 | imagesavealpha ($canvas, true); 635 | 636 | if ($zoom_crop > 0) { 637 | 638 | $src_x = $src_y = 0; 639 | $src_w = $width; 640 | $src_h = $height; 641 | 642 | $cmp_x = $width / $new_width; 643 | $cmp_y = $height / $new_height; 644 | 645 | // calculate x or y coordinate and width or height of source 646 | if ($cmp_x > $cmp_y) { 647 | 648 | $src_w = round ($width / $cmp_x * $cmp_y); 649 | $src_x = round (($width - ($width / $cmp_x * $cmp_y)) / 2); 650 | 651 | } else if ($cmp_y > $cmp_x) { 652 | 653 | $src_h = round ($height / $cmp_y * $cmp_x); 654 | $src_y = round (($height - ($height / $cmp_y * $cmp_x)) / 2); 655 | 656 | } 657 | 658 | // positional cropping! 659 | if ($align) { 660 | if (strpos ($align, 't') !== false) { 661 | $src_y = 0; 662 | } 663 | if (strpos ($align, 'b') !== false) { 664 | $src_y = $height - $src_h; 665 | } 666 | if (strpos ($align, 'l') !== false) { 667 | $src_x = 0; 668 | } 669 | if (strpos ($align, 'r') !== false) { 670 | $src_x = $width - $src_w; 671 | } 672 | } 673 | 674 | imagecopyresampled ($canvas, $image, $origin_x, $origin_y, $src_x, $src_y, $new_width, $new_height, $src_w, $src_h); 675 | 676 | } else { 677 | 678 | // copy and resize part of an image with resampling 679 | imagecopyresampled ($canvas, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); 680 | 681 | } 682 | 683 | if ($filters != '' && function_exists ('imagefilter') && defined ('IMG_FILTER_NEGATE')) { 684 | // apply filters to image 685 | $filterList = explode ('|', $filters); 686 | foreach ($filterList as $fl) { 687 | 688 | $filterSettings = explode (',', $fl); 689 | if (isset ($imageFilters[$filterSettings[0]])) { 690 | 691 | for ($i = 0; $i < 4; $i ++) { 692 | if (!isset ($filterSettings[$i])) { 693 | $filterSettings[$i] = null; 694 | } else { 695 | $filterSettings[$i] = (int) $filterSettings[$i]; 696 | } 697 | } 698 | 699 | switch ($imageFilters[$filterSettings[0]][1]) { 700 | 701 | case 1: 702 | 703 | imagefilter ($canvas, $imageFilters[$filterSettings[0]][0], $filterSettings[1]); 704 | break; 705 | 706 | case 2: 707 | 708 | imagefilter ($canvas, $imageFilters[$filterSettings[0]][0], $filterSettings[1], $filterSettings[2]); 709 | break; 710 | 711 | case 3: 712 | 713 | imagefilter ($canvas, $imageFilters[$filterSettings[0]][0], $filterSettings[1], $filterSettings[2], $filterSettings[3]); 714 | break; 715 | 716 | case 4: 717 | 718 | imagefilter ($canvas, $imageFilters[$filterSettings[0]][0], $filterSettings[1], $filterSettings[2], $filterSettings[3], $filterSettings[4]); 719 | break; 720 | 721 | default: 722 | 723 | imagefilter ($canvas, $imageFilters[$filterSettings[0]][0]); 724 | break; 725 | 726 | } 727 | } 728 | } 729 | } 730 | 731 | // sharpen image 732 | if ($sharpen && function_exists ('imageconvolution')) { 733 | 734 | $sharpenMatrix = array ( 735 | array (-1,-1,-1), 736 | array (-1,16,-1), 737 | array (-1,-1,-1), 738 | ); 739 | 740 | $divisor = 8; 741 | $offset = 0; 742 | 743 | imageconvolution ($canvas, $sharpenMatrix, $divisor, $offset); 744 | 745 | } 746 | //Straight from Wordpress core code. Reduces filesize by up to 70% for PNG's 747 | if ( (IMAGETYPE_PNG == $origType || IMAGETYPE_GIF == $origType) && function_exists('imageistruecolor') && !imageistruecolor( $image ) && imagecolortransparent( $image ) > 0 ){ 748 | imagetruecolortopalette( $canvas, false, imagecolorstotal( $image ) ); 749 | } 750 | 751 | $imgType = ""; 752 | $tempfile = tempnam($this->cacheDirectory, 'timthumb_tmpimg_'); 753 | if(preg_match('/^image\/(?:jpg|jpeg)$/i', $mimeType)){ 754 | $imgType = 'jpg'; 755 | imagejpeg($canvas, $tempfile, $quality); 756 | } else if(preg_match('/^image\/png$/i', $mimeType)){ 757 | $imgType = 'png'; 758 | imagepng($canvas, $tempfile, floor($quality * 0.09)); 759 | } else if(preg_match('/^image\/gif$/i', $mimeType)){ 760 | $imgType = 'gif'; 761 | imagegif($canvas, $tempfile); 762 | } else { 763 | return $this->sanityFail("Could not match mime type after verifying it previously."); 764 | } 765 | 766 | if($imgType == 'png' && OPTIPNG_ENABLED && OPTIPNG_PATH && @is_file(OPTIPNG_PATH)){ 767 | $exec = OPTIPNG_PATH; 768 | $this->debug(3, "optipng'ing $tempfile"); 769 | $presize = filesize($tempfile); 770 | $out = `$exec -o1 $tempfile`; //you can use up to -o7 but it really slows things down 771 | clearstatcache(); 772 | $aftersize = filesize($tempfile); 773 | $sizeDrop = $presize - $aftersize; 774 | if($sizeDrop > 0){ 775 | $this->debug(1, "optipng reduced size by $sizeDrop"); 776 | } else if($sizeDrop < 0){ 777 | $this->debug(1, "optipng increased size! Difference was: $sizeDrop"); 778 | } else { 779 | $this->debug(1, "optipng did not change image size."); 780 | } 781 | } else if($imgType == 'png' && PNGCRUSH_ENABLED && PNGCRUSH_PATH && @is_file(PNGCRUSH_PATH)){ 782 | $exec = PNGCRUSH_PATH; 783 | $tempfile2 = tempnam($this->cacheDirectory, 'timthumb_tmpimg_'); 784 | $this->debug(3, "pngcrush'ing $tempfile to $tempfile2"); 785 | $out = `$exec $tempfile $tempfile2`; 786 | $todel = ""; 787 | if(is_file($tempfile2)){ 788 | $sizeDrop = filesize($tempfile) - filesize($tempfile2); 789 | if($sizeDrop > 0){ 790 | $this->debug(1, "pngcrush was succesful and gave a $sizeDrop byte size reduction"); 791 | $todel = $tempfile; 792 | $tempfile = $tempfile2; 793 | } else { 794 | $this->debug(1, "pngcrush did not reduce file size. Difference was $sizeDrop bytes."); 795 | $todel = $tempfile2; 796 | } 797 | } else { 798 | $this->debug(3, "pngcrush failed with output: $out"); 799 | $todel = $tempfile2; 800 | } 801 | @unlink($todel); 802 | } 803 | 804 | $this->debug(3, "Rewriting image with security header."); 805 | $tempfile4 = tempnam($this->cacheDirectory, 'timthumb_tmpimg_'); 806 | $context = stream_context_create (); 807 | $fp = fopen($tempfile,'r',0,$context); 808 | file_put_contents($tempfile4, $this->filePrependSecurityBlock . $imgType . ' ?' . '>'); //6 extra bytes, first 3 being image type 809 | file_put_contents($tempfile4, $fp, FILE_APPEND); 810 | fclose($fp); 811 | @unlink($tempfile); 812 | $this->debug(3, "Locking and replacing cache file."); 813 | $lockFile = $this->cachefile . '.lock'; 814 | $fh = fopen($lockFile, 'w'); 815 | if(! $fh){ 816 | return $this->error("Could not open the lockfile for writing an image."); 817 | } 818 | if(flock($fh, LOCK_EX)){ 819 | @unlink($this->cachefile); //rename generally overwrites, but doing this in case of platform specific quirks. File might not exist yet. 820 | rename($tempfile4, $this->cachefile); 821 | flock($fh, LOCK_UN); 822 | fclose($fh); 823 | @unlink($lockFile); 824 | } else { 825 | fclose($fh); 826 | @unlink($lockFile); 827 | @unlink($tempfile4); 828 | return $this->error("Could not get a lock for writing."); 829 | } 830 | $this->debug(3, "Done image replace with security header. Cleaning up and running cleanCache()"); 831 | imagedestroy($canvas); 832 | imagedestroy($image); 833 | return true; 834 | } 835 | protected function calcDocRoot(){ 836 | // $docRoot = @$_SERVER['DOCUMENT_ROOT']; 837 | if (defined('LOCAL_FILE_BASE_DIRECTORY')) { 838 | $docRoot = LOCAL_FILE_BASE_DIRECTORY; 839 | } 840 | if(!isset($docRoot)){ 841 | $this->debug(3, "DOCUMENT_ROOT is not set. This is probably windows. Starting search 1."); 842 | if(isset($_SERVER['SCRIPT_FILENAME'])){ 843 | $docRoot = str_replace( '\\', '/', substr($_SERVER['SCRIPT_FILENAME'], 0, 0-strlen($_SERVER['PHP_SELF']))); 844 | $this->debug(3, "Generated docRoot using SCRIPT_FILENAME and PHP_SELF as: $docRoot"); 845 | } 846 | } 847 | if(!isset($docRoot)){ 848 | $this->debug(3, "DOCUMENT_ROOT still is not set. Starting search 2."); 849 | if(isset($_SERVER['PATH_TRANSLATED'])){ 850 | $docRoot = str_replace( '\\', '/', substr(str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']), 0, 0-strlen($_SERVER['PHP_SELF']))); 851 | $this->debug(3, "Generated docRoot using PATH_TRANSLATED and PHP_SELF as: $docRoot"); 852 | } 853 | } 854 | if($docRoot && $_SERVER['DOCUMENT_ROOT'] != '/'){ $docRoot = preg_replace('/\/$/', '', $docRoot); } 855 | $this->debug(3, "Doc root is: " . $docRoot); 856 | $this->docRoot = $docRoot; 857 | 858 | } 859 | protected function getLocalImagePath($src){ 860 | $src = ltrim($src, '/'); //strip off the leading '/' 861 | if(! $this->docRoot){ 862 | $this->debug(3, "We have no document root set, so as a last resort, lets check if the image is in the current dir and serve that."); 863 | //We don't support serving images outside the current dir if we don't have a doc root for security reasons. 864 | $file = preg_replace('/^.*?([^\/\\\\]+)$/', '$1', $src); //strip off any path info and just leave the filename. 865 | if(is_file($file)){ 866 | return $this->realpath($file); 867 | } 868 | return $this->error("Could not find your website document root and the file specified doesn't exist in timthumbs directory. We don't support serving files outside timthumb's directory without a document root for security reasons."); 869 | } //Do not go past this point without docRoot set 870 | 871 | //Try src under docRoot 872 | if(file_exists ($this->docRoot . '/' . $src)) { 873 | $this->debug(3, "Found file as " . $this->docRoot . '/' . $src); 874 | $real = $this->realpath($this->docRoot . '/' . $src); 875 | if(stripos($real, $this->docRoot) === 0){ 876 | return $real; 877 | } else { 878 | $this->debug(1, "Security block: The file specified occurs outside the document root."); 879 | //allow search to continue 880 | } 881 | } 882 | //Check absolute paths and then verify the real path is under doc root 883 | $absolute = $this->realpath('/' . $src); 884 | if($absolute && file_exists($absolute)){ //realpath does file_exists check, so can probably skip the exists check here 885 | $this->debug(3, "Found absolute path: $absolute"); 886 | if(! $this->docRoot){ $this->sanityFail("docRoot not set when checking absolute path."); } 887 | if(stripos($absolute, $this->docRoot) === 0){ 888 | return $absolute; 889 | } else { 890 | $this->debug(1, "Security block: The file specified occurs outside the document root."); 891 | //and continue search 892 | } 893 | } 894 | 895 | $base = $this->docRoot; 896 | 897 | // account for Windows directory structure 898 | if (strstr($_SERVER['SCRIPT_FILENAME'],':')) { 899 | $sub_directories = explode('\\', str_replace($this->docRoot, '', $_SERVER['SCRIPT_FILENAME'])); 900 | } else { 901 | $sub_directories = explode('/', str_replace($this->docRoot, '', $_SERVER['SCRIPT_FILENAME'])); 902 | } 903 | 904 | foreach ($sub_directories as $sub){ 905 | $base .= $sub . '/'; 906 | $this->debug(3, "Trying file as: " . $base . $src); 907 | if(file_exists($base . $src)){ 908 | $this->debug(3, "Found file as: " . $base . $src); 909 | $real = $this->realpath($base . $src); 910 | if(stripos($real, $this->realpath($this->docRoot)) === 0){ 911 | return $real; 912 | } else { 913 | $this->debug(1, "Security block: The file specified occurs outside the document root."); 914 | //And continue search 915 | } 916 | } 917 | } 918 | return false; 919 | } 920 | protected function realpath($path){ 921 | //try to remove any relative paths 922 | $remove_relatives = '/\w+\/\.\.\//'; 923 | while(preg_match($remove_relatives,$path)){ 924 | $path = preg_replace($remove_relatives, '', $path); 925 | } 926 | //if any remain use PHP realpath to strip them out, otherwise return $path 927 | //if using realpath, any symlinks will also be resolved 928 | return preg_match('#^\.\./|/\.\./#', $path) ? realpath($path) : $path; 929 | } 930 | protected function toDelete($name){ 931 | $this->debug(3, "Scheduling file $name to delete on destruct."); 932 | $this->toDeletes[] = $name; 933 | } 934 | protected function serveWebshot(){ 935 | $this->debug(3, "Starting serveWebshot"); 936 | $instr = "Please follow the instructions at http://code.google.com/p/timthumb/ to set your server up for taking website screenshots."; 937 | if(! is_file(WEBSHOT_CUTYCAPT)){ 938 | return $this->error("CutyCapt is not installed. $instr"); 939 | } 940 | if(! is_file(WEBSHOT_XVFB)){ 941 | return $this->Error("Xvfb is not installed. $instr"); 942 | } 943 | $cuty = WEBSHOT_CUTYCAPT; 944 | $xv = WEBSHOT_XVFB; 945 | $screenX = WEBSHOT_SCREEN_X; 946 | $screenY = WEBSHOT_SCREEN_Y; 947 | $colDepth = WEBSHOT_COLOR_DEPTH; 948 | $format = WEBSHOT_IMAGE_FORMAT; 949 | $timeout = WEBSHOT_TIMEOUT * 1000; 950 | $ua = WEBSHOT_USER_AGENT; 951 | $jsOn = WEBSHOT_JAVASCRIPT_ON ? 'on' : 'off'; 952 | $javaOn = WEBSHOT_JAVA_ON ? 'on' : 'off'; 953 | $pluginsOn = WEBSHOT_PLUGINS_ON ? 'on' : 'off'; 954 | $proxy = WEBSHOT_PROXY ? ' --http-proxy=' . WEBSHOT_PROXY : ''; 955 | $tempfile = tempnam($this->cacheDirectory, 'timthumb_webshot'); 956 | $url = $this->src; 957 | if(! preg_match('/^https?:\/\/[a-zA-Z0-9\.\-]+/i', $url)){ 958 | return $this->error("Invalid URL supplied."); 959 | } 960 | $url = preg_replace('/[^A-Za-z0-9\-\.\_\~:\/\?\#\[\]\@\!\$\&\'\(\)\*\+\,\;\=]+/', '', $url); //RFC 3986 961 | //Very important we don't allow injection of shell commands here. URL is between quotes and we are only allowing through chars allowed by a the RFC 962 | // which AFAIKT can't be used for shell injection. 963 | if(WEBSHOT_XVFB_RUNNING){ 964 | putenv('DISPLAY=:100.0'); 965 | $command = "$cuty $proxy --max-wait=$timeout --user-agent=\"$ua\" --javascript=$jsOn --java=$javaOn --plugins=$pluginsOn --js-can-open-windows=off --url=\"$url\" --out-format=$format --out=$tempfile"; 966 | } else { 967 | $command = "$xv --server-args=\"-screen 0, {$screenX}x{$screenY}x{$colDepth}\" $cuty $proxy --max-wait=$timeout --user-agent=\"$ua\" --javascript=$jsOn --java=$javaOn --plugins=$pluginsOn --js-can-open-windows=off --url=\"$url\" --out-format=$format --out=$tempfile"; 968 | } 969 | $this->debug(3, "Executing command: $command"); 970 | $out = `$command`; 971 | $this->debug(3, "Received output: $out"); 972 | if(! is_file($tempfile)){ 973 | $this->set404(); 974 | return $this->error("The command to create a thumbnail failed."); 975 | } 976 | $this->cropTop = true; 977 | if($this->processImageAndWriteToCache($tempfile)){ 978 | $this->debug(3, "Image processed succesfully. Serving from cache"); 979 | return $this->serveCacheFile(); 980 | } else { 981 | return false; 982 | } 983 | } 984 | protected function serveExternalImage(){ 985 | if(! preg_match('/^https?:\/\/[a-zA-Z0-9\-\.]+/i', $this->src)){ 986 | $this->error("Invalid URL supplied."); 987 | return false; 988 | } 989 | $tempfile = tempnam($this->cacheDirectory, 'timthumb'); 990 | $this->debug(3, "Fetching external image into temporary file $tempfile"); 991 | $this->toDelete($tempfile); 992 | #fetch file here 993 | if(! $this->getURL($this->src, $tempfile)){ 994 | @unlink($this->cachefile); 995 | touch($this->cachefile); 996 | $this->debug(3, "Error fetching URL: " . $this->lastURLError); 997 | $this->error("Error reading the URL you specified from remote host." . $this->lastURLError); 998 | return false; 999 | } 1000 | 1001 | $mimeType = $this->getMimeType($tempfile); 1002 | if(! preg_match("/^image\/(?:jpg|jpeg|gif|png)$/i", $mimeType)){ 1003 | $this->debug(3, "Remote file has invalid mime type: $mimeType"); 1004 | @unlink($this->cachefile); 1005 | touch($this->cachefile); 1006 | $this->error("The remote file is not a valid image."); 1007 | return false; 1008 | } 1009 | if($this->processImageAndWriteToCache($tempfile)){ 1010 | $this->debug(3, "Image processed succesfully. Serving from cache"); 1011 | return $this->serveCacheFile(); 1012 | } else { 1013 | return false; 1014 | } 1015 | } 1016 | public static function curlWrite($h, $d){ 1017 | fwrite(self::$curlFH, $d); 1018 | self::$curlDataWritten += strlen($d); 1019 | if(self::$curlDataWritten > MAX_FILE_SIZE){ 1020 | return 0; 1021 | } else { 1022 | return strlen($d); 1023 | } 1024 | } 1025 | protected function serveCacheFile(){ 1026 | $this->debug(3, "Serving {$this->cachefile}"); 1027 | if(! is_file($this->cachefile)){ 1028 | $this->error("serveCacheFile called in timthumb but we couldn't find the cached file."); 1029 | return false; 1030 | } 1031 | $fp = fopen($this->cachefile, 'rb'); 1032 | if(! $fp){ return $this->error("Could not open cachefile."); } 1033 | fseek($fp, strlen($this->filePrependSecurityBlock), SEEK_SET); 1034 | $imgType = fread($fp, 3); 1035 | fseek($fp, 3, SEEK_CUR); 1036 | if(ftell($fp) != strlen($this->filePrependSecurityBlock) + 6){ 1037 | @unlink($this->cachefile); 1038 | return $this->error("The cached image file seems to be corrupt."); 1039 | } 1040 | $imageDataSize = filesize($this->cachefile) - (strlen($this->filePrependSecurityBlock) + 6); 1041 | $this->sendImageHeaders($imgType, $imageDataSize); 1042 | $bytesSent = @fpassthru($fp); 1043 | fclose($fp); 1044 | if($bytesSent > 0){ 1045 | return true; 1046 | } 1047 | $content = file_get_contents ($this->cachefile); 1048 | if ($content != FALSE) { 1049 | $content = substr($content, strlen($this->filePrependSecurityBlock) + 6); 1050 | echo $content; 1051 | $this->debug(3, "Served using file_get_contents and echo"); 1052 | return true; 1053 | } else { 1054 | $this->error("Cache file could not be loaded."); 1055 | return false; 1056 | } 1057 | } 1058 | protected function sendImageHeaders($mimeType, $dataSize){ 1059 | if(! preg_match('/^image\//i', $mimeType)){ 1060 | $mimeType = 'image/' . $mimeType; 1061 | } 1062 | if(strtolower($mimeType) == 'image/jpg'){ 1063 | $mimeType = 'image/jpeg'; 1064 | } 1065 | $gmdate_expires = gmdate ('D, d M Y H:i:s', strtotime ('now +10 days')) . ' GMT'; 1066 | $gmdate_modified = gmdate ('D, d M Y H:i:s') . ' GMT'; 1067 | // send content headers then display image 1068 | header ('Content-Type: ' . $mimeType); 1069 | header ('Accept-Ranges: none'); //Changed this because we don't accept range requests 1070 | header ('Last-Modified: ' . $gmdate_modified); 1071 | header ('Content-Length: ' . $dataSize); 1072 | if(BROWSER_CACHE_DISABLE){ 1073 | $this->debug(3, "Browser cache is disabled so setting non-caching headers."); 1074 | header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0'); 1075 | header("Pragma: no-cache"); 1076 | header('Expires: ' . gmdate ('D, d M Y H:i:s', time())); 1077 | } else { 1078 | $this->debug(3, "Browser caching is enabled"); 1079 | header('Cache-Control: max-age=' . BROWSER_CACHE_MAX_AGE . ', must-revalidate'); 1080 | header('Expires: ' . $gmdate_expires); 1081 | } 1082 | return true; 1083 | } 1084 | protected function securityChecks(){ 1085 | } 1086 | protected function param($property, $default = ''){ 1087 | if (isset ($_GET[$property])) { 1088 | return $_GET[$property]; 1089 | } else { 1090 | return $default; 1091 | } 1092 | } 1093 | protected function openImage($mimeType, $src){ 1094 | switch ($mimeType) { 1095 | case 'image/jpeg': 1096 | $image = imagecreatefromjpeg ($src); 1097 | break; 1098 | 1099 | case 'image/png': 1100 | $image = imagecreatefrompng ($src); 1101 | break; 1102 | 1103 | case 'image/gif': 1104 | $image = imagecreatefromgif ($src); 1105 | break; 1106 | 1107 | default: 1108 | $this->error("Unrecognised mimeType"); 1109 | } 1110 | 1111 | return $image; 1112 | } 1113 | protected function getIP(){ 1114 | $rem = @$_SERVER["REMOTE_ADDR"]; 1115 | $ff = @$_SERVER["HTTP_X_FORWARDED_FOR"]; 1116 | $ci = @$_SERVER["HTTP_CLIENT_IP"]; 1117 | if(preg_match('/^(?:192\.168|172\.16|10\.|127\.)/', $rem)){ 1118 | if($ff){ return $ff; } 1119 | if($ci){ return $ci; } 1120 | return $rem; 1121 | } else { 1122 | if($rem){ return $rem; } 1123 | if($ff){ return $ff; } 1124 | if($ci){ return $ci; } 1125 | return "UNKNOWN"; 1126 | } 1127 | } 1128 | protected function debug($level, $msg){ 1129 | if(DEBUG_ON && $level <= DEBUG_LEVEL){ 1130 | $execTime = sprintf('%.6f', microtime(true) - $this->startTime); 1131 | $tick = sprintf('%.6f', 0); 1132 | if($this->lastBenchTime > 0){ 1133 | $tick = sprintf('%.6f', microtime(true) - $this->lastBenchTime); 1134 | } 1135 | $this->lastBenchTime = microtime(true); 1136 | error_log("TimThumb Debug line " . __LINE__ . " [$execTime : $tick]: $msg"); 1137 | } 1138 | } 1139 | protected function sanityFail($msg){ 1140 | return $this->error("There is a problem in the timthumb code. Message: Please report this error at timthumb's bug tracking page: $msg"); 1141 | } 1142 | protected function getMimeType($file){ 1143 | $info = getimagesize($file); 1144 | if(is_array($info) && $info['mime']){ 1145 | return $info['mime']; 1146 | } 1147 | return ''; 1148 | } 1149 | protected function setMemoryLimit(){ 1150 | $inimem = ini_get('memory_limit'); 1151 | $inibytes = timthumb::returnBytes($inimem); 1152 | $ourbytes = timthumb::returnBytes(MEMORY_LIMIT); 1153 | if($inibytes < $ourbytes){ 1154 | ini_set ('memory_limit', MEMORY_LIMIT); 1155 | $this->debug(3, "Increased memory from $inimem to " . MEMORY_LIMIT); 1156 | } else { 1157 | $this->debug(3, "Not adjusting memory size because the current setting is " . $inimem . " and our size of " . MEMORY_LIMIT . " is smaller."); 1158 | } 1159 | } 1160 | protected static function returnBytes($size_str){ 1161 | switch (substr ($size_str, -1)) 1162 | { 1163 | case 'M': case 'm': return (int)$size_str * 1048576; 1164 | case 'K': case 'k': return (int)$size_str * 1024; 1165 | case 'G': case 'g': return (int)$size_str * 1073741824; 1166 | default: return $size_str; 1167 | } 1168 | } 1169 | protected function getURL($url, $tempfile){ 1170 | $this->lastURLError = false; 1171 | $url = preg_replace('/ /', '%20', $url); 1172 | if(function_exists('curl_init')){ 1173 | $this->debug(3, "Curl is installed so using it to fetch URL."); 1174 | self::$curlFH = fopen($tempfile, 'w'); 1175 | if(! self::$curlFH){ 1176 | $this->error("Could not open $tempfile for writing."); 1177 | return false; 1178 | } 1179 | self::$curlDataWritten = 0; 1180 | $this->debug(3, "Fetching url with curl: $url"); 1181 | $curl = curl_init($url); 1182 | curl_setopt ($curl, CURLOPT_TIMEOUT, CURL_TIMEOUT); 1183 | curl_setopt ($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.122 Safari/534.30"); 1184 | curl_setopt ($curl, CURLOPT_RETURNTRANSFER, TRUE); 1185 | curl_setopt ($curl, CURLOPT_HEADER, 0); 1186 | curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, FALSE); 1187 | curl_setopt ($curl, CURLOPT_WRITEFUNCTION, 'timthumb::curlWrite'); 1188 | @curl_setopt ($curl, CURLOPT_FOLLOWLOCATION, true); 1189 | @curl_setopt ($curl, CURLOPT_MAXREDIRS, 10); 1190 | 1191 | $curlResult = curl_exec($curl); 1192 | fclose(self::$curlFH); 1193 | $httpStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE); 1194 | if($httpStatus == 404){ 1195 | $this->set404(); 1196 | } 1197 | if($curlResult){ 1198 | curl_close($curl); 1199 | return true; 1200 | } else { 1201 | $this->lastURLError = curl_error($curl); 1202 | curl_close($curl); 1203 | return false; 1204 | } 1205 | } else { 1206 | $img = @file_get_contents ($url); 1207 | if($img === false){ 1208 | $err = error_get_last(); 1209 | if(is_array($err) && $err['message']){ 1210 | $this->lastURLError = $err['message']; 1211 | } else { 1212 | $this->lastURLError = $err; 1213 | } 1214 | if(preg_match('/404/', $this->lastURLError)){ 1215 | $this->set404(); 1216 | } 1217 | 1218 | return false; 1219 | } 1220 | if(! file_put_contents($tempfile, $img)){ 1221 | $this->error("Could not write to $tempfile."); 1222 | return false; 1223 | } 1224 | return true; 1225 | } 1226 | 1227 | } 1228 | protected function serveImg($file){ 1229 | $s = getimagesize($file); 1230 | if(! ($s && $s['mime'])){ 1231 | return false; 1232 | } 1233 | header ('Content-Type: ' . $s['mime']); 1234 | header ('Content-Length: ' . filesize($file) ); 1235 | header ('Cache-Control: no-store, no-cache, must-revalidate, max-age=0'); 1236 | header ("Pragma: no-cache"); 1237 | $bytes = @readfile($file); 1238 | if($bytes > 0){ 1239 | return true; 1240 | } 1241 | $content = @file_get_contents ($file); 1242 | if ($content != FALSE){ 1243 | echo $content; 1244 | return true; 1245 | } 1246 | return false; 1247 | 1248 | } 1249 | protected function set404(){ 1250 | $this->is404 = true; 1251 | } 1252 | protected function is404(){ 1253 | return $this->is404; 1254 | } 1255 | } 1256 | --------------------------------------------------------------------------------