1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: HotBloker |
---|
4 | Version: 2.0 |
---|
5 | Description: this plugin creates .htaccess files in your './galleries/' directory to disallow "hotlink" to your pics, BUT not for your thumbnails (so rss feed still works !!) : |
---|
6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=291 |
---|
7 | Author: repie38 |
---|
8 | Author URI: http://www.pierre-b.com |
---|
9 | */ |
---|
10 | |
---|
11 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
12 | DEFINE('HB_VERSION','v2.0'); |
---|
13 | define('HB_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/'); |
---|
14 | |
---|
15 | class HB |
---|
16 | { |
---|
17 | var $etat; |
---|
18 | var $real_cat; |
---|
19 | function init($dir) { |
---|
20 | if (file_exists($dir.'/.htaccess')) { |
---|
21 | $this->etat="on"; |
---|
22 | foreach ($this->real_cat as $cat) { |
---|
23 | $this->etat = ((file_exists($cat.'/thumbnail/.htaccess')) and ( $this->etat=="on" )) ? "on" : "off" ; |
---|
24 | } |
---|
25 | } |
---|
26 | else { |
---|
27 | $this->etat="off"; |
---|
28 | } |
---|
29 | } |
---|
30 | |
---|
31 | function hotblock_dir($dir,$tn) |
---|
32 | { |
---|
33 | $htaccess_content ="RewriteEngine on \n"; |
---|
34 | $htaccess_content.="RewriteCond %{HTTP_REFERER} !^$ \n"; |
---|
35 | $htaccess_content.="RewriteCond %{HTTP_REFERER} !^"."http://".$_SERVER["HTTP_HOST"]."/".".*$ [NC] \n"; |
---|
36 | $htaccess_content.="RewriteRule .*\.*$ " . get_absolute_root_url(1) . "plugins/hotbloker/img/bloked.gif [NC] \n"; |
---|
37 | |
---|
38 | if ($tn) { |
---|
39 | $htaccess_content = "RewriteEngine on \n"; |
---|
40 | $htaccess_content.= "RewriteRule ^.*$ -"; |
---|
41 | } |
---|
42 | $file = fopen( $dir.'/.htaccess', 'w' ); |
---|
43 | |
---|
44 | fwrite($file, $htaccess_content ); |
---|
45 | fclose( $file ); |
---|
46 | if (!$tn) { |
---|
47 | foreach ($this->real_cat as $cat) { |
---|
48 | //hotfree_dir($cat); |
---|
49 | if (file_exists($cat.'/thumbnail')) $this->hotblock_dir($cat.'/thumbnail',1); |
---|
50 | } |
---|
51 | } |
---|
52 | } |
---|
53 | |
---|
54 | function hotfree_dir($dir,$tn) |
---|
55 | { |
---|
56 | if (file_exists($dir.'/.htaccess')) |
---|
57 | { |
---|
58 | unlink($dir.'/.htaccess'); |
---|
59 | } |
---|
60 | if (!$tn) { |
---|
61 | foreach ($this->real_cat as $cat) { |
---|
62 | $this->hotfree_dir($cat.'/thumbnail',1); |
---|
63 | } |
---|
64 | } |
---|
65 | } |
---|
66 | |
---|
67 | |
---|
68 | function plugin_admin_menu($menu) |
---|
69 | { |
---|
70 | array_push($menu, |
---|
71 | array( |
---|
72 | 'NAME' => 'HotBlocker', |
---|
73 | 'URL' => get_admin_plugin_menu_link(dirname(__FILE__).'/admin/hb_admin.php') |
---|
74 | ) |
---|
75 | ); |
---|
76 | return $menu; |
---|
77 | } |
---|
78 | |
---|
79 | function list_path_of_real_cat() |
---|
80 | { |
---|
81 | $list="";$real_cat=array(); |
---|
82 | $query = 'SELECT `id` FROM '.CATEGORIES_TABLE.' WHERE `dir` != \'NULL\';'; |
---|
83 | $cat = pwg_query($query); |
---|
84 | if (empty($cat)) |
---|
85 | return null; |
---|
86 | |
---|
87 | while ($row=mysql_fetch_row($cat)) { |
---|
88 | array_push($real_cat,$row[0]); |
---|
89 | } |
---|
90 | $this->real_cat = get_fulldirs($real_cat); |
---|
91 | } |
---|
92 | } |
---|
93 | |
---|
94 | |
---|
95 | $obj = new HB(); |
---|
96 | add_event_handler('get_admin_plugin_menu_links', array(&$obj, 'plugin_admin_menu') ); |
---|
97 | set_plugin_data($plugin['id'], $obj) |
---|
98 | |
---|
99 | ?> |
---|