1<?php 2 3use ComboStrap\LinkUtility; 4use ComboStrap\PluginUtility; 5 6if (!defined('DOKU_INC')) die(); 7require_once(__DIR__ . '/../class/PluginUtility.php'); 8require_once(__DIR__ . '/../class/LinkUtility.php'); 9 10/** 11 * Class action_plugin_combo_move 12 * Handle the move of a page in order to update the link 13 */ 14class action_plugin_combo_linkmove extends DokuWiki_Action_Plugin 15{ 16 17 /** 18 * As explained https://www.dokuwiki.org/plugin:move#support_for_other_plugins 19 * @param Doku_Event_Handler $controller 20 */ 21 function register(Doku_Event_Handler $controller) 22 { 23 $controller->register_hook('PLUGIN_MOVE_HANDLERS_REGISTER', 'BEFORE', $this, 'handle_move', array()); 24 } 25 26 /** 27 * Handle the move of a page 28 * @param Doku_Event $event 29 * @param $params 30 */ 31 function handle_move(Doku_Event $event, $params) 32 { 33 /** 34 * The handlers is the name of the component (ie refers to the {@link syntax_plugin_combo_link} handler) 35 * and 'rewrite_combo' to the below method 36 */ 37 $event->data['handlers'][syntax_plugin_combo_link::COMPONENT] = array($this, 'rewrite_combo'); 38 } 39 40 /** 41 * 42 * @param $match 43 * @param $state 44 * @param $pos 45 * @param $plugin 46 * @param helper_plugin_move_handler $handler 47 */ 48 public function rewrite_combo($match, $state, $pos, $plugin, helper_plugin_move_handler $handler) 49 { 50 /** 51 * The original move method 52 * is {@link helper_plugin_move_handler::internallink()} 53 * 54 */ 55 if ($state == DOKU_LEXER_ENTER) { 56 $ref = LinkUtility::parse($match)[LinkUtility::ATTRIBUTE_REF]; 57 $link = new LinkUtility($ref); 58 if ($link->getType() == LinkUtility::TYPE_INTERNAL) { 59 60 $handler->internallink($match, $state, $pos); 61 $suffix = "]]"; 62 if (substr($handler->calls, -strlen($suffix)) == $suffix) { 63 $handler->calls = substr($handler->calls, 0, strlen($handler->calls) - strlen($suffix)); 64 } 65 66 } else { 67 68 // Other type of links 69 $handler->calls .= $match; 70 71 } 72 } else { 73 74 // Description and ending 75 $handler->calls .= $match; 76 77 } 78 } 79 80 81} 82