public function setUp() { parent::setUp(); $this->action = new action_plugin_data(); $this->helper = plugin_load('helper', 'data'); $this->db = $this->helper->_getDB(); $this->db->query('INSERT INTO pages ( pid, page, title , class , lastmod) VALUES (?, ?, ?, ?, ?)', 1, 'test', 'title', 'class', time()); }
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()); }
/** * Carry out required processing */ public function handle() { if (!isset($_REQUEST['data_go']) || !checkSecurityToken()) { return; } $sqlite = $this->dthlp->_getDB(); if (!$sqlite) { return; } $res = $sqlite->query("SELECT pid, page FROM pages"); $rows = $sqlite->res2arr($res); $count = 0; foreach ($rows as $row) { if (!page_exists($row['page'])) { $sqlite->query('DELETE FROM data WHERE pid = ?', $row['pid']); $sqlite->query('DELETE FROM pages WHERE pid = ?', $row['pid']); $count++; } } msg(sprintf($this->getLang('pages_del'), $count), 1); }
/** * Output html of the admin page */ public function html() { $sqlite = $this->dthlp->_getDB(); if (!$sqlite) { return; } echo $this->locale_xhtml('admin_intro'); $sql = "SELECT * FROM aliases ORDER BY name"; $res = $sqlite->query($sql); $rows = $sqlite->res2arr($res); $form = new Doku_Form(array('method' => 'post')); $form->addHidden('page', 'data_aliases'); $form->addElement('<table class="inline">' . '<tr>' . '<th>' . $this->getLang('name') . '</th>' . '<th>' . $this->getLang('type') . '</th>' . '<th>' . $this->getLang('prefix') . '</th>' . '<th>' . $this->getLang('postfix') . '</th>' . '<th>' . $this->getLang('enum') . '</th>' . '</tr>'); // add empty row for adding a new entry $rows[] = array('name' => '', 'type' => '', 'prefix' => '', 'postfix' => '', 'enum' => ''); $cur = 0; foreach ($rows as $row) { $form->addElement('<tr>'); $form->addElement('<td>'); $form->addElement(form_makeTextField('d[' . $cur . '][name]', $row['name'], '')); $form->addElement('</td>'); $form->addElement('<td>'); $form->addElement(form_makeMenuField('d[' . $cur . '][type]', array('', 'page', 'title', 'mail', 'url', 'dt', 'wiki', 'tag', 'hidden', 'img'), $row['type'], '')); $form->addElement('</td>'); $form->addElement('<td>'); $form->addElement(form_makeTextField('d[' . $cur . '][prefix]', $row['prefix'], '')); $form->addElement('</td>'); $form->addElement('<td>'); $form->addElement(form_makeTextField('d[' . $cur . '][postfix]', $row['postfix'], '')); $form->addElement('</td>'); $form->addElement('<td>'); $form->addElement(form_makeTextField('d[' . $cur . '][enum]', $row['enum'], '')); $form->addElement('</td>'); $form->addElement('</tr>'); $cur++; } $form->addElement('</table>'); $form->addElement(form_makeButton('submit', 'admin', $this->getLang('submit'))); $form->printForm(); }
/** * @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); }
public function testMakeTranslationReplacement() { $helper = new helper_plugin_data(); $this->assertEquals('en', $helper->makeTranslationReplacement('%lang%')); $this->assertEquals('', $helper->makeTranslationReplacement('%trans%')); if (plugin_enable('translation')) { global $conf; global $ID; $conf['plugin']['translation']['translations'] = 'de'; $ID = 'de:somepage'; $this->assertEquals('en', $helper->makeTranslationReplacement('%lang%')); $this->assertEquals('de', $helper->makeTranslationReplacement('%trans%')); } }
public function testMakeTranslationReplacement() { $helper = new helper_plugin_data(); $this->assertEquals('en', $helper->makeTranslationReplacement('%lang%')); $this->assertEquals('', $helper->makeTranslationReplacement('%trans%')); $plugininstalled = in_array('translation', plugin_list('helper', $all = true)); if (!$plugininstalled) { $this->markTestSkipped('Pre-condition not satisfied: translation plugin must be installed'); } if ($plugininstalled && plugin_enable('translation')) { global $conf; global $ID; $conf['plugin']['translation']['translations'] = 'de'; $ID = 'de:somepage'; $this->assertEquals('en', $helper->makeTranslationReplacement('%lang%')); $this->assertEquals('de', $helper->makeTranslationReplacement('%trans%')); } }