1111 *
1212 * @brief Plum Analytics plugin class
1313 */
14+ namespace APP \plugins \generic \plumAnalytics ;
15+
16+ use PKP \plugins \GenericPlugin ;
17+ use PKP \config \Config ;
18+ use PKP \plugins \PluginRegistry ;
19+ use PKP \linkAction \LinkAction ;
20+ use PKP \linkAction \request \AjaxModal ;
21+ use PKP \core \JSONMessage ;
22+ use PKP \plugins \Hook ;
23+ use APP \plugins \generic \plumAnalytics \PlumAnalyticsBlockPlugin ;
24+ use APP \plugins \generic \plumAnalytics \PlumAnalyticsSettingsForm ;
25+ use APP \template \TemplateManager ;
1426
15- import ('lib.pkp.classes.plugins.GenericPlugin ' );
1627
1728class PlumAnalyticsPlugin extends GenericPlugin {
1829
@@ -71,20 +82,15 @@ function register($category, $path, $mainContextId = null) {
7182 if ($ success && $ this ->getEnabled ()) {
7283 // Attach to any possible hook; actual widget hook and script hook will be determined by insertWidget()
7384 foreach ($ this ->availableHooks as $ k => $ v ) {
74- HookRegistry:: register ($ v , array ($ this , 'insertWidget ' ));
85+ Hook:: add ($ v , array ($ this , 'insertWidget ' ));
7586 }
7687
7788 // Load this plugin as a block plugin as well
78- $ this ->import ('PlumAnalyticsBlockPlugin ' );
7989 PluginRegistry::register (
8090 'blocks ' ,
8191 new PlumAnalyticsBlockPlugin ($ this ->getName (), $ this ->getPluginPath ()),
8292 $ this ->getPluginPath ()
8393 );
84-
85- // Enable TinyMCEditor in textarea fields
86- HookRegistry::register ('TinyMCEPlugin::getEnableFields ' , array ($ this , 'getTinyMCEEnabledFields ' ));
87-
8894 }
8995 return $ success ;
9096 }
@@ -110,7 +116,6 @@ function getDescription() {
110116 */
111117 function getActions ($ request , $ verb ) {
112118 $ router = $ request ->getRouter ();
113- import ('lib.pkp.classes.linkAction.request.AjaxModal ' );
114119 return array_merge (
115120 $ this ->getEnabled ()?array (
116121 new LinkAction (
@@ -135,31 +140,18 @@ function getActions($request, $verb) {
135140 */
136141 function insertWidget ($ hookName , $ params ) {
137142 $ output =& $ params [2 ];
138- $ templateMgr = TemplateManager::getManager ();
139-
140143 $ request = $ this ->getRequest ();
144+ $ templateMgr = TemplateManager::getManager ($ request );
141145 $ context = $ request ->getContext ();
142146 $ doi = $ this ->getSubmissionDOI ($ templateMgr , $ context ->getId (), $ hookName );
143147 if ($ doi ) {
144148 if ($ hookName == 'Templates::Article::Footer::PageFooter ' ) {
145- if (method_exists ($ this , 'getTemplateResource ' )) {
146- // OJS 3.1.2+
147- $ target = $ this ->getTemplateResource ('pageTagPlumScript.tpl ' );
148- } else {
149- // before OJS 3.1.2
150- $ target = $ this ->getTemplatePath () . 'pageTagPlumScript.tpl ' ;
151- }
149+ $ target = $ this ->getTemplateResource ('pageTagPlumScript.tpl ' );
152150 $ output .= $ templateMgr ->fetch ($ target );
153151 }
154152 if ($ this ->availableHooks [$ this ->getSetting ($ context ->getId (), 'hook ' )] == $ hookName ) {
155153 $ this ->setupTemplateManager ($ context ->getId (), $ doi , $ templateMgr );
156- if (method_exists ($ this , 'getTemplateResource ' )) {
157- // OJS 3.1.2+
158- $ target = $ this ->getTemplateResource ('pageTagPlumWidget.tpl ' );
159- } else {
160- // before OJS 3.1.2
161- $ target = $ this ->getTemplatePath () . 'pageTagPlumWidget.tpl ' ;
162- }
154+ $ target = $ this ->getTemplateResource ('pageTagPlumWidget.tpl ' );
163155 $ output .= $ templateMgr ->fetch ($ target );
164156 }
165157 }
@@ -186,13 +178,7 @@ function setupTemplateManager($contextId, $doi, $templateMgr) {
186178 // database setting is stored without "plum" prefix, e.g. plumSettingName is settingName
187179 $ templateMgr ->assign ($ k , $ this ->getSetting ($ contextId , lcfirst (substr ($ k , 4 ))));
188180 }
189- if (method_exists ($ this , 'getTemplateResource ' )) {
190- // OJS 3.1.2+
191- $ templateMgr ->assign ('plumWidgetTemplatePath ' , $ this ->getTemplateResource ('pageTagPlumWidget.tpl ' ));
192- } else {
193- // before OJS 3.1.2
194- $ templateMgr ->assign ('plumWidgetTemplatePath ' , $ this ->getTemplatePath (). 'pageTagPlumWidget.tpl ' );
195- }
181+ $ templateMgr ->assign ('plumWidgetTemplatePath ' , $ this ->getTemplateResource ('pageTagPlumWidget.tpl ' ));
196182 }
197183
198184 /**
@@ -248,11 +234,9 @@ function manage($args, $request) {
248234 $ verb = $ request ->getUserVar ('verb ' );
249235 switch ($ verb ) {
250236 case 'settings ' :
251- $ templateMgr = TemplateManager::getManager ();
252- $ templateMgr ->register_function ( 'plugin_url ' , array ($ this , 'smartyPluginUrl ' ));
237+ $ templateMgr = TemplateManager::getManager ($ request );
238+ $ templateMgr ->registerPlugin ( ' function ' , 'plugin_url ' , array ($ this , 'smartyPluginUrl ' ));
253239 $ context = $ request ->getContext ();
254-
255- $ this ->import ('PlumAnalyticsSettingsForm ' );
256240 $ form = new PlumAnalyticsSettingsForm ($ this , $ context ->getId ());
257241 if ($ request ->getUserVar ('save ' )) {
258242 $ form ->readInputData ();
0 commit comments