| 1 | <?php |
| 2 | /******************************************************************************** |
| 3 | * include/plugin.inc.php : The base class for each Plugin (action|match) |
| 4 | * ---------------------- |
| 5 | * |
| 6 | * This file is part of the philter distribution |
| 7 | * Copyright: See COPYING files that comes with this distribution |
| 8 | ********************************************************************************/ |
| 9 | |
| 10 | class Plugin { |
| 11 | /** constructor |
| 12 | */ |
| 13 | function Plugin() { } |
| 14 | |
| 15 | /** runtime id. |
| 16 | * this function must return 0 if the class should not have any instance |
| 17 | * @returns the rtti of the object |
| 18 | */ |
| 19 | function rtti() { return 0; } |
| 20 | |
| 21 | /** name of the plugin (to pick a choice in a select). |
| 22 | * @return a string describing the plugin |
| 23 | */ |
| 24 | function name() { return "abstract class !!"; } |
| 25 | |
| 26 | /** gives the LEFT JOIN to add to the sql request to have all this plugin datas |
| 27 | * @return the LEFT JOIN string, "" if irrelevant |
| 28 | */ |
| 29 | // function sql_get() { return ""; } |
| 30 | // function sql_clean($_uid, $_rid) { } |
| 31 | |
| 32 | /** stores the data to the mysql database |
| 33 | * @param $_uid the id of the filter |
| 34 | * @param $_rid the id of the rule |
| 35 | * @param $_data an array or a string containing all the sql data row for this plugin |
| 36 | * @return void |
| 37 | */ |
| 38 | function sql_store($_uid, $_rid, $_data) { } |
| 39 | |
| 40 | /** converts the row of the mysql SELECT into a shorter and usable $data |
| 41 | * @param &$sql a reference on the sql row |
| 42 | * @return an array with the shorter datas |
| 43 | */ |
| 44 | function sql_to_data(&$sql) { |
| 45 | if(preg_match('/^a:\d+:\{.*\}$/', $sql['data'])) |
| 46 | return unserialize($sql['data']); |
| 47 | else |
| 48 | return array($sql['pid'], $sql['data']); |
| 49 | } |
| 50 | |
| 51 | /** gives the procmailrc instruction of the data associated with this Plugin |
| 52 | * @param $_data an array or a string containing all the sql data row for this plugin |
| 53 | * @return the procmailrc string |
| 54 | */ |
| 55 | function to_string($_data) { return ""; } |
| 56 | |
| 57 | /** returns the function that creates the form in javascript (@see FwdPlugin for one example). |
| 58 | * @return the string containing the javascript code |
| 59 | */ |
| 60 | function to_js() { return ""; } |
| 61 | } |
| 62 | |
| 63 | class ActionPlugin extends Plugin { |
| 64 | /** constructor */ |
| 65 | function ActionPlugin() { $this->Plugin(); } |
| 66 | |
| 67 | function sql_store($_uid, $_rid, $_data) { |
| 68 | if(count($_data) == 2) |
| 69 | $data = $_data[1]; |
| 70 | else |
| 71 | $data = serialize($_data); |
| 72 | mysql_query("INSERT INTO ".bd()."actions SET uid='$_uid',rid='$_rid',pid='{$_data[0]}',data='$data'"); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | class MatchPlugin extends Plugin { |
| 77 | /** true if the plugin is used as global */ |
| 78 | var $global; |
| 79 | |
| 80 | /** constructor */ |
| 81 | function MatchPlugin($_glob) { |
| 82 | $this->Plugin(); |
| 83 | $this->global=$_glob; |
| 84 | } |
| 85 | |
| 86 | function sql_store($_uid, $_rid, $_data) { |
| 87 | if(count($_data) == 2) |
| 88 | $data = $_data[1]; |
| 89 | else |
| 90 | $data = serialize($_data); |
| 91 | if($this->global) |
| 92 | mysql_query("INSERT INTO ".bd()."matches SET uid='$_uid',rid='0',pid='{$_data[0]}',data='$data'"); |
| 93 | else |
| 94 | mysql_query("INSERT INTO ".bd()."matches SET uid='$_uid',rid='$_rid',pid='{$_data[0]}',data='$data'"); |
| 95 | } |
| 96 | |
| 97 | /** true if the plugin is used as global rule |
| 98 | * overload with (return false) if the plugin can not be used as a global rule |
| 99 | * overload with (return true) if the plugin can not be used as a normal rule |
| 100 | * @return true if usable as a global rule, false else |
| 101 | */ |
| 102 | function is_global() { return $this->global; } |
| 103 | } |
| 104 | |
| 105 | /******************************************************************************** |
| 106 | * $Id$ |
| 107 | * vim: set expandtab shiftwidth=4 tabstop=4 softtabstop=4 textwidth=100: |
| 108 | ********************************************************************************/ |
| 109 | ?> |