source: extensions/hotblocker/main.inc.php @ 15555

Last change on this file since 15555 was 3699, checked in by repie38, 15 years ago

create hotblocker extension for repie38

File size: 2.7 KB
Line 
1<?php
2/*
3Plugin Name: HotBloker
4Version: 2.0
5Description: 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 !!) :
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=291
7Author: repie38
8Author URI: http://www.pierre-b.com
9*/
10
11if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
12DEFINE('HB_VERSION','v2.0');
13define('HB_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
14
15class 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();
96add_event_handler('get_admin_plugin_menu_links', array(&$obj, 'plugin_admin_menu') );
97set_plugin_data($plugin['id'], $obj)
98
99?>
Note: See TracBrowser for help on using the repository browser.