1<?php 2 3 4/** 5 * Copyright (c) 2021. ComboStrap, Inc. and its affiliates. All Rights Reserved. 6 * 7 * This source code is licensed under the GPL license found in the 8 * COPYING file in the root directory of this source tree. 9 * 10 * @license GPL 3 (https://www.gnu.org/licenses/gpl-3.0.en.html) 11 * @author ComboStrap <support@combostrap.com> 12 * 13 */ 14 15 16require_once(__DIR__ . '/../vendor/autoload.php'); 17 18/** 19 * Mandatory, don't known why ? Otherwise it does not work 20 * The class is not found 21 */ 22require_once(__DIR__ . '/../ComboStrap/AnalyticsMenuItem.php'); 23 24use Combostrap\AnalyticsMenuItem; 25use ComboStrap\ExceptionNotFound; 26use ComboStrap\ExecutionContext; 27use ComboStrap\Identity; 28 29/** 30 * Class action_plugin_combo_analytics 31 * Update the analytics data 32 */ 33class action_plugin_combo_analytics extends DokuWiki_Action_Plugin 34{ 35 36 37 public function register(Doku_Event_Handler $controller) 38 { 39 40 41 /** 42 * Add a icon in the page tools menu 43 * https://www.dokuwiki.org/devel:event:menu_items_assembly 44 */ 45 $controller->register_hook('MENU_ITEMS_ASSEMBLY', 'AFTER', $this, 'handle_rail_bar'); 46 47 48 } 49 50 51 public function handle_rail_bar(Doku_Event $event, $param) 52 { 53 54 55 $executionContext = ExecutionContext::getActualOrCreateFromEnv(); 56 if (!$executionContext->isPublicationAction()) { 57 // a search for instance 58 return; 59 } 60 61 if (!Identity::isWriter()) { 62 return; 63 } 64 65 /** 66 * The `view` property defines the menu that is currently built 67 * https://www.dokuwiki.org/devel:menus 68 * If this is not the page menu, return 69 */ 70 if ($event->data['view'] != 'page') return; 71 72 global $INFO; 73 $exists = $INFO['exists'] ?? null; 74 if (!$exists) { 75 return; 76 } 77 array_splice($event->data['items'], -1, 0, array(new AnalyticsMenuItem())); 78 79 } 80 81 82} 83 84 85 86