Facebook to email

Facebook to email Git Source Tree

Root/modules/module.php

1<?php
2/**
3 * Copyright 2014 Grégory Soutadé
4 *
5 * This file is part of f2email.
6 *
7 * f2email is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * f2email is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with f2email. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21require_once 'database.php';
22
23interface Plugin {
24}
25
26abstract class Module implements Plugin
27{
28 protected $db;
29 protected $user;
30 protected $local_pref = array();
31 protected $global_pref = "";
32
33 function __construct($db, $user)
34 {
35 $this->db = $db;
36 $this->user = $user;
37
38 $this->db->insert_or_load_module($this, $user);
39 $this->db->get_module_local_pref($this, $user);
40
41 return true;
42 }
43
44 function getID() {return crc32(__FILE__);}
45
46 abstract function getName();
47
48 function getDescription() { return ""; }
49
50 function getHelp() { return ""; }
51
52 function hasLocalPref() { return 0 ; }
53
54 function hasGlobalPref() { return 0 ; }
55
56 function validatePref($pref) { return false ; }
57
58 function setLocalPref($pref, $fb_object_id, $persistent=true)
59 {
60 $this->local_pref["$fb_object_id"] = $pref;
61 if ($persistent)
62 $this->db->set_module_local_pref($this, $this->user, $fb_object_id, $pref);
63 }
64
65 function setGlobalPref($pref, $persistent=true)
66 {
67 $this->global_pref = $pref;
68 if ($persistent)
69 $this->db->set_module_global_pref($this->user, $this->getID(), $pref);
70 }
71
72 function getGlobalPref() { return $this->global_pref; }
73
74 function getLocalPref($fb_object_id)
75 {
76 if (array_key_exists("$fb_object_id", $this->local_pref))
77 return $this->local_pref["$fb_object_id"];
78 return "";
79 }
80
81 abstract function manageNotification($fb_object, $notification);
82}
83?>

Archive Download this file

Branches