_aliases() public method

Load defined type aliases
public _aliases ( ) : array
return array
コード例 #1
0
 public function testAliases()
 {
     $helper = new helper_plugin_data();
     $db = $helper->_getDB();
     $this->assertTrue($db !== false);
     $db->query("INSERT INTO aliases (name, type, prefix, postfix, enum) VALUES (?,?,?,?,?)", 'alias', 'wiki', '[[', ']]', '');
     $expect = array('alias' => array('type' => 'wiki', 'prefix' => '[[', 'postfix' => ']]'));
     $this->assertEquals($expect, $helper->_aliases());
 }
コード例 #2
0
 /**
  * @param Doku_Event $event
  */
 function _handle_ajax(Doku_Event $event)
 {
     if ($event->data !== 'data_page') {
         return;
     }
     $event->stopPropagation();
     $event->preventDefault();
     $type = substr($_REQUEST['aliastype'], 10);
     $aliases = $this->dthlp->_aliases();
     if (!isset($aliases[$type])) {
         echo 'Unknown type';
         return;
     }
     if ($aliases[$type]['type'] !== 'page') {
         echo 'AutoCompletion is only supported for page types';
         return;
     }
     if (substr($aliases[$type]['postfix'], -1, 1) === ':') {
         // Resolve namespace start page ID
         global $conf;
         $aliases[$type]['postfix'] .= $conf['start'];
     }
     $search = $_REQUEST['search'];
     $c_search = $search;
     $in_ns = false;
     if (!$search) {
         // No search given, so we just want all pages in the prefix
         $c_search = $aliases[$type]['prefix'];
         $in_ns = true;
     }
     $pages = ft_pageLookup($c_search, $in_ns, false);
     $regexp = '/^';
     if ($aliases[$type]['prefix'] !== '') {
         $regexp .= preg_quote($aliases[$type]['prefix'], '/');
     }
     $regexp .= '([^:]+)';
     if ($aliases[$type]['postfix'] !== '') {
         $regexp .= preg_quote($aliases[$type]['postfix'], '/');
     }
     $regexp .= '$/';
     $result = array();
     foreach ($pages as $page => $title) {
         $id = array();
         if (!preg_match($regexp, $page, $id)) {
             // Does not satisfy the postfix and prefix criteria
             continue;
         }
         $id = $id[1];
         if ($search !== '' && stripos($id, cleanID($search)) === false && stripos($title, $search) === false) {
             // Search string is not in id part or title
             continue;
         }
         if ($title === '') {
             $title = utf8_ucwords(str_replace('_', ' ', $id));
         }
         $result[hsc($id)] = hsc($title);
     }
     $json = new JSON();
     header('Content-Type: application/json');
     echo $json->encode($result);
 }