]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/YammerImport/YammerImportPlugin.php
Yammer import API keys can now be overridden by the admin.
[quix0rs-gnu-social.git] / plugins / YammerImport / YammerImportPlugin.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2010, StatusNet, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 /**
21  * @package YammerImportPlugin
22  * @maintainer Brion Vibber <brion@status.net>
23  */
24
25 if (!defined('STATUSNET')) { exit(1); }
26
27 class YammerImportPlugin extends Plugin
28 {
29     /**
30      * Hook for RouterInitialized event.
31      *
32      * @param Net_URL_Mapper $m path-to-action mapper
33      * @return boolean hook return
34      */
35     function onRouterInitialized($m)
36     {
37         $m->connect('admin/yammer',
38                     array('action' => 'yammeradminpanel'));
39         $m->connect('admin/yammer/auth',
40                     array('action' => 'yammerauth'));
41         return true;
42     }
43
44     /**
45      * Set up queue handlers for import processing
46      * @param QueueManager $qm
47      * @return boolean hook return
48      */
49     function onEndInitializeQueueManager(QueueManager $qm)
50     {
51         $qm->connect('yammer', 'YammerQueueHandler');
52
53         return true;
54     }
55
56     /**
57      * Set up all our tables...
58      */
59     function onCheckSchema()
60     {
61         $schema = Schema::get();
62
63         $tables = array('Yammer_state',
64                         'Yammer_user',
65                         'Yammer_group',
66                         'Yammer_notice',
67                         'Yammer_notice_stub');
68         foreach ($tables as $table) {
69             $schema->ensureTable(strtolower($table), $table::schemaDef());
70         }
71
72         return true;
73     }
74
75     /**
76      * If the plugin's installed, this should be accessible to admins.
77      */
78     function onAdminPanelCheck($name, &$isOK)
79     {
80         if ($name == 'yammer') {
81             $isOK = true;
82             return false;
83         }
84
85         return true;
86     }
87
88     /**
89      * Add the Yammer admin panel to the list...
90      */
91     function onEndAdminPanelNav($nav)
92     {
93         if (AdminPanelAction::canAdmin('yammer')) {
94             $action_name = $nav->action->trimmed('action');
95
96             $nav->out->menuItem(common_local_url('yammeradminpanel'),
97                                 _m('Yammer'),
98                                 _m('Yammer import'),
99                                 $action_name == 'yammeradminpanel',
100                                 'nav_yammer_admin_panel');
101         }
102
103         return true;
104     }
105
106     /**
107      * Automatically load the actions and libraries used by the plugin
108      *
109      * @param Class $cls the class
110      *
111      * @return boolean hook return
112      *
113      */
114     function onAutoload($cls)
115     {
116         $base = dirname(__FILE__);
117         $lower = strtolower($cls);
118         switch ($lower) {
119         case 'sn_yammerclient':
120         case 'yammerimporter':
121         case 'yammerrunner':
122         case 'yammerapikeyform':
123         case 'yammerauthinitform':
124         case 'yammerauthverifyform':
125         case 'yammerprogressform':
126         case 'yammerqueuehandler':
127             require_once "$base/lib/$lower.php";
128             return false;
129         case 'yammeradminpanelaction':
130             $crop = substr($lower, 0, strlen($lower) - strlen('action'));
131             require_once "$base/actions/$crop.php";
132             return false;
133         case 'yammer_state':
134         case 'yammer_notice_stub':
135         case 'yammer_common':
136         case 'yammer_user':
137         case 'yammer_group':
138         case 'yammer_notice':
139             require_once "$base/classes/$cls.php";
140             return false;
141         default:
142             return true;
143         }
144     }
145 }