Beispiel #1
0
function b_sitemap_xpwiki($mydirname)
{
    global $sitemap_configs;
    (method_exists('MyTextSanitizer', 'sGetInstance') and $myts =& MyTextSanitizer::sGetInstance()) || ($myts =& MyTextSanitizer::getInstance());
    $ret = array();
    include_once dirname(dirname(__FILE__)) . '/include.php';
    $xpwiki =& XpWiki::getInitedSingleton($mydirname);
    $result = $xpwiki->func->get_existpages(FALSE, '', array('limit' => 5, 'order' => ' ORDER BY editedtime DESC', 'select' => array('title'), 'nolisting' => TRUE));
    $ret = array();
    // Recent Changes
    $show_cat = @$sitemap_configs['show_subcategoris'] ? 'child' : 'parent';
    if ($show_cat === 'child') {
        $ret['id'] = 0;
        $ret['title'] = $xpwiki->root->_LANG['skin']['recent'];
        $ret['url'] = '?' . rawurlencode($xpwiki->root->whatsnew);
    }
    foreach ($result as $_res) {
        $pgid = $_res['pgid'];
        $page = $_res['name'];
        $title = $_res['title'];
        $title = $xpwiki->root->pagename_num2str ? preg_replace('/\\/(?:[0-9\\-]+|[B0-9][A-Z0-9]{9})$/', '/' . $xpwiki->func->get_heading($page), $page) : $page;
        $ret[$show_cat][] = array("id" => intval($pgid), "title" => $myts->makeTboxData4Show($title), "url" => $xpwiki->func->get_page_uri($page), 'image' => 2);
    }
    if ($show_cat === 'child') {
        $ret = array('parent' => array($ret));
    }
    // Other menus
    $ret['parent'][] = array('id' => 0, 'title' => $xpwiki->root->_LANG['skin']['list'], 'url' => '?cmd=list');
    $ret['parent'][] = array('id' => 0, 'title' => $xpwiki->root->_attach_messages['msg_list'], 'url' => '?plugin=attach&pcmd=list');
    $ret['parent'][] = array('id' => 0, 'title' => $xpwiki->root->_LANG['skin']['help'], 'url' => '?Help');
    return $ret;
}
Beispiel #2
0
function b_xpwiki_notification_show($options)
{
    $mydirname = empty($options[0]) ? 'xpwiki' : $options[0];
    if (preg_match('/[^0-9a-zA-Z_-]/', $mydirname)) {
        die('Invalid mydirname');
    }
    $pgid = !empty($_GET['pgid']) ? intval($_GET['pgid']) : 0;
    if (!isset($GLOBALS['Xpwiki_' . $mydirname]) || !$pgid) {
        return false;
    }
    $this_template = empty($options[1]) ? 'db:' . $mydirname . '_block_notification.html' : trim($options[1]);
    include_once XOOPS_TRUST_PATH . "/modules/xpwiki/include.php";
    $xw =& XpWiki::getInitedSingleton($mydirname);
    $notification = $xw->func->get_notification_select($pgid);
    if ($notification) {
        $block = array('mydirname' => $mydirname, 'mod_url' => XOOPS_URL . '/modules/' . $mydirname, 'content' => $notification);
        require_once XOOPS_ROOT_PATH . '/class/template.php';
        $tpl = new XoopsTpl();
        $tpl->assign('block', $block);
        $ret['content'] = $tpl->fetch($this_template);
    } else {
        $ret = false;
    }
    return $ret;
}
 function validate_users2notify($link_id, $users2notify = array())
 {
     if (!$users2notify || $users2notify === array(0)) {
         return $users2notify;
     }
     include_once dirname(dirname(__FILE__)) . "/include.php";
     $xpwiki =& XpWiki::getInitedSingleton($this->mydirname);
     $xpwiki_users2notify = $xpwiki->func->get_users_can_read($link_id);
     return array_intersect($users2notify, $xpwiki_users2notify);
 }
Beispiel #4
0
 function xpwiki_notify_base($mydirname, $category, $item_id)
 {
     if ($category == 'global') {
         $item['name'] = '';
         $item['url'] = '';
         return $item;
     }
     include_once dirname(__FILE__) . '/include.php';
     $xpwiki =& XpWiki::getInitedSingleton($mydirname);
     if (substr($category, 0, 4) === 'page') {
         // Assume we have a valid $item_id
         $item['name'] = $xpwiki->func->get_name_by_pgid($item_id);
         $item['url'] = $xpwiki->func->get_page_uri($item['name'], true);
         return $item;
     }
 }
 function validate_id($link_id)
 {
     static $check;
     if (isset($check[$this->mydirname][$link_id])) {
         return $check[$this->mydirname][$link_id];
     }
     $ret = intval($link_id);
     if ($ret <= 0) {
         $ret = false;
     } else {
         include_once dirname(dirname(__FILE__)) . "/include.php";
         $xpwiki =& XpWiki::getInitedSingleton($this->mydirname);
         $page = $xpwiki->func->get_name_by_pgid($ret);
         if (!$xpwiki->func->is_page($page) || !$xpwiki->func->check_readable($page, false, false)) {
             $ret = false;
         }
     }
     $check[$this->mydirname][$link_id] = $ret;
     return $ret;
 }
Beispiel #6
0
 function make_body($cmd, $dir, $retry = false, $pages = array())
 {
     $select = '';
     if ($dir === $this->cont['DATA_DIR']) {
         $ext = '.txt';
         $_dir = dirname($this->cont['DATA_HOME']);
         $items = array();
         if ($dh = opendir($_dir)) {
             while (($item = readdir($dh)) !== false) {
                 if (is_dir($_dir . '/' . $item)) {
                     if ($this->root->mydirname !== $item && is_file($_dir . '/' . $item . '/private/ini/pukiwiki.ini.php')) {
                         $obj =& XpWiki::getInitedSingleton($item);
                         if ($obj->root->module['mid']) {
                             $items[] = $item;
                         }
                     }
                 }
             }
             closedir($dh);
         }
         if ($items) {
             $select = '<div><input type="checkbox" name="move" value="1" /> ';
             $select .= $this->msg['msg_move_flag'];
             $select .= '<select name="movedir">';
             foreach ($items as $_dir) {
                 $select .= '<option value="' . $_dir . '">' . $_dir . '</option>';
             }
             $select .= '</select></div>';
         }
     } elseif ($dir === $this->cont['BACKUP_DIR']) {
         $ext = function_exists('gzfile') ? ".gz" : ".txt";
     } elseif ($dir === $this->cont['DIFF_DIR']) {
         $ext = '.txt';
     } elseif ($dir === $this->cont['TRACKBACK_DIR']) {
         $ext = '.ref';
     } elseif ($dir === $this->cont['COUNTER_DIR']) {
         $ext = '.count';
     }
     $script = $this->func->get_script_uri();
     $body = '';
     $body .= "<form method='post' action=\"{$script}?cmd={$cmd}\"><div>\n";
     if ($dir === $this->cont['DATA_DIR']) {
         $body .= "<input type=\"hidden\" name=\"dir\" value=\"DATA\"/>\n";
         $body .= "<input type=\"hidden\" name=\"mode\" value=\"select\"/>\n";
         $body .= "{$this->msg['msg_regexp_label']}<input type='text' name='regexp' value='{$this->root->vars['s_regxp']}' />\n";
         $body .= "<input type=\"submit\" value=\"{$this->msg['btn_research']}\" /></div></form>\n";
     }
     if ($retry === false) {
         $body .= "<form method='post' action=\"{$script}?cmd={$cmd}\"><div>\n";
         if ($pages) {
             $body .= $this->page_list2($pages, 'read', FALSE, TRUE);
         } else {
             if ($dir === $this->cont['DATA_DIR']) {
                 $body .= '<p>' . $this->msg['msg_is_freezed'] . '</p>';
                 $body .= $this->page_list2($this->func->get_existpages(true));
             } else {
                 $body .= '<p>' . $this->msg['msg_is_freezed'] . '</p>';
                 $body .= '<p>' . $this->msg['msg_is_deleted'] . '</p>';
                 $body .= $this->page_list2($this->func->get_existpages($dir, $ext, true));
             }
         }
         if ($dir === $this->cont['DATA_DIR']) {
             $dir = 'DATA';
             $body .= $cmd === 'deldel' ? "<input type=\"checkbox\" name=\"cascade\" value=\"1\" checked=\"checked\"/> <span>{$this->msg['msg_together_flag']}</span><br />\n" : "";
             $body .= $select;
         } elseif ($dir === $this->cont['BACKUP_DIR']) {
             $dir = 'BACKUP';
         } elseif ($dir === $this->cont['DIFF_DIR']) {
             $dir = 'DIFF';
         } elseif ($dir === $this->cont['TRACKBACK_DIR']) {
             $dir = 'REFERER';
         } elseif ($dir === $this->cont['COUNTER_DIR']) {
             $dir = 'COUNTER';
         }
         $body .= "<input type=\"hidden\" name=\"mode\" value=\"confirm\"/>\n";
         $body .= "<input type=\"hidden\" name=\"dir\" value=\"{$dir}\"/>\n";
         $body .= "<input type=\"submit\" value=\"{$this->msg['btn_concern']}\" /></div></form>\n";
         $body .= $this->msg['msg_check'];
     }
     return $body;
 }
Beispiel #7
0
<?php

/*
 * Created on 2009/05/08 by nao-pon http://hypweb.net/
 * License: GPL v2 or (at your option) any later version
 * $Id: piCal.php,v 1.3 2011/06/01 06:27:52 nao-pon Exp $
 */
require_once XOOPS_TRUST_PATH . '/modules/xpwiki/include.php';
$xpwiki =& XpWiki::getInitedSingleton($plugin['dirname']);
if ($xpwiki->isXpWiki) {
    // options
    $options = array('base' => '', 'nochild' => FALSE, 'include' => '', 'exclude' => '');
    //$args = explode( '#' , trim($plugin['options']) ) ;
    $args = $xpwiki->func->csv_explode(',', trim($plugin['options']));
    $dummy =& $xpwiki->func->get_plugin_instance('dummy');
    $dummy->fetch_options($options, $args, array('base'));
    $base = '';
    if ($options['base']) {
        // Base name
        $base = rtrim($options['base'], '/') . '/';
    }
    $include = array();
    if ($options['include']) {
        foreach (explode('#', $options['include']) as $_page) {
            $include[] = '`name` LIKE \'' . addslashes($_page) . '\'';
        }
        $include = 'AND ' . join(' AND ', $include);
    } else {
        $include = '';
    }
    $exclude = array();
Beispiel #8
0
<?php

include_once XOOPS_TRUST_PATH . "/modules/xpwiki/include.php";
$xw =& XpWiki::getInitedSingleton($mydirname);
if (!$xw->func->get_pgid_by_name($xw->root->defaultpage)) {
    $xw->func->send_location('', '', $xw->cont['HOME_URL'] . '?cmd=dbsync');
}
$check_dir = array($xw->cont['UPLOAD_DIR'], $xw->cont['UPLOAD_DIR'] . 's', $xw->cont['BACKUP_DIR'], $xw->cont['CACHE_DIR'], $xw->cont['CACHE_DIR'] . 'page', $xw->cont['CACHE_DIR'] . 'plugin', $xw->cont['DIFF_DIR'], $xw->cont['TRACKBACK_DIR'], $xw->cont['RENDER_CACHE_DIR'], $xw->cont['DATA_DIR']);
$check_dir = array_unique($check_dir);
sort($check_dir);
$dir_res = array();
foreach ($check_dir as $dir) {
    $dir = rtrim($dir, '/');
    if (is_writable($dir)) {
        $dir .= ' (<span style="color:green;font-weight:bold;">OK</span>)';
    } else {
        $dir .= ' (<span style="color:red;font-weight:bold;">NG</span>)';
    }
    $dir_res[] = $dir;
}
$dir_res = '<ul><li>' . join('</li><li>', $dir_res) . '</li></ul>';
// output
xoops_cp_header();
include dirname(__FILE__) . '/mymenu.php';
echo <<<EOD

<h3>Writable check results</h3>
{$dir_res}

EOD;
xoops_cp_footer();
Beispiel #9
0
 function plugin_include_convert()
 {
     static $included = array();
     if (!isset($included[$this->xpwiki->pid])) {
         $included[$this->xpwiki->pid] = array();
     }
     static $count = array();
     if (!isset($count[$this->xpwiki->pid])) {
         $count[$this->xpwiki->pid] = 1;
     }
     if (func_num_args() == 0) {
         return $this->cont['PLUGIN_INCLUDE_USAGE'] . '<br />' . "\n";
     }
     // $menubar will already be shown via menu plugin
     if (!isset($included[$this->xpwiki->pid][$this->root->menubar])) {
         $included[$this->xpwiki->pid][$this->root->menubar] = TRUE;
     }
     // Loop yourself
     $root = isset($this->root->vars['page']) ? $this->root->vars['page'] : '';
     $included[$this->xpwiki->pid][$root] = TRUE;
     // Get arguments
     $args = func_get_args();
     // strip_bracket() is not necessary but compatible
     $pageKey = $page = isset($args[0]) ? $this->func->get_fullname($this->func->strip_bracket(array_shift($args)), $root) : '';
     $options = array('title' => FALSE, 'notitle' => FALSE, 'source' => FALSE, 'html' => FALSE);
     $this->fetch_options($options, $args);
     if ($options['source']) {
         $this->otherIncludeMode = 'source';
     } else {
         if ($options['html']) {
             $this->otherIncludeMode = 'html';
         }
     }
     $targetObj = NULL;
     $isThis = TRUE;
     if (intval(strpos($page, ':')) > 0) {
         list($other_dir, $_page) = explode(':', $page, 2);
         $targetObj =& XpWiki::getInitedSingleton($other_dir);
         if ($targetObj->isXpWiki) {
             $page = $_page;
             $isThis = FALSE;
         } else {
             $targetObj = NULL;
         }
     }
     if (is_null($targetObj)) {
         $targetObj =& $this;
         $other_dir = '';
     }
     $with_title = $options['title'] ? TRUE : ($options['notitle'] ? FALSE : $this->cont['PLUGIN_INCLUDE_WITH_TITLE']);
     $s_page = $this->func->htmlspecialchars($page);
     $r_page = rawurlencode($page);
     // Include A page, that probably includes another pages
     if ($targetObj->func->check_readable($page, false, false)) {
         //			$with_title = $this->cont['PLUGIN_INCLUDE_WITH_TITLE'];
         //			if (isset($args[0])) {
         //				switch(strtolower(array_shift($args))) {
         //				case 'title'  : $with_title = TRUE;  break;
         //				case 'notitle': $with_title = FALSE; break;
         //				}
         //			}
         $link = '<a href="' . $this->func->get_page_uri($page, TRUE) . '">' . $s_page . '</a>';
         // Read link
         // I'm stuffed
         $pageKey4disp = $this->func->htmlspecialchars($pageKey);
         if ($this->root->render_mode === 'main' && isset($included[$this->xpwiki->pid][$pageKey])) {
             return '#include(' . $pageKey4disp . '): Included already: ' . $link . '<br />' . "\n";
         }
         if (!$targetObj->func->is_page($page)) {
             return '#include(): No such page: ' . $s_page . '<br />' . "\n";
         }
         if ($count[$this->xpwiki->pid] > $this->cont['PLUGIN_INCLUDE_MAX']) {
             return '#include(): Limit exceeded: ' . $link . '<br />' . "\n";
         } else {
             ++$count[$this->xpwiki->pid];
         }
         // for renderer mode
         $this->root->rtf['disable_render_cache'] = TRUE;
         // One page, only one time, at a time
         $included[$this->xpwiki->pid][$pageKey] = TRUE;
         if ($this->root->render_mode === 'render') {
             $_PKWK_READONLY = $this->cont['PKWK_READONLY'];
             $this->cont['PKWK_READONLY'] = $this->root->rtf['PKWK_READONLY'];
         }
         if ($this->otherIncludeMode === 'html') {
             $body = '';
             if (!$isThis) {
                 $this->swap_global_vars($this->xpwiki, $targetObj);
                 $body .= '<div class="xpwiki_r_' . $other_dir . '">';
             } else {
                 $body .= '<div>';
             }
             $body .= $targetObj->func->convert_html($targetObj->func->get_source($page), $page);
             $body .= '</div>';
             if (!$isThis) {
                 $this->swap_global_vars($this->xpwiki, $targetObj);
             }
         } else {
             $body = $this->func->convert_html($targetObj->func->get_source($page), $page);
         }
         if ($this->root->render_mode === 'render') {
             $this->cont['PKWK_READONLY'] = $_PKWK_READONLY;
         }
     } else {
         $body = str_replace('$1', $page, $this->root->_msg_include_restrict);
     }
     // Put a title-with-edit-link, before including document
     if ($with_title) {
         $link = '<a href="' . $targetObj->root->script . '?cmd=edit&amp;page=' . $r_page . '">' . $s_page . '</a>';
         if ($page === $targetObj->root->menubar) {
             $body = '<span align="center"><h5 class="side_label">' . $link . '</h5></span><small>' . $body . '</small>';
         } else {
             $body = '<h1>' . $link . '</h1>' . "\n" . $body . "\n";
         }
     }
     return $body;
 }
Beispiel #10
0
function xpwikifunc_delete_counter($mydirname)
{
    $msg = array();
    include_once XOOPS_TRUST_PATH . '/modules/xpwiki/include.php';
    $xpwiki = XpWiki::getInitedSingleton($mydirname);
    if ($xpwiki->func->get_plugin_instance('counter')) {
        $dir = $xpwiki->cont['COUNTER_DIR'];
        if ($handle = opendir($dir)) {
            $suffix = $xpwiki->cont['PLUGIN_COUNTER_SUFFIX'];
            $del = false;
            while (false !== ($file = readdir($handle))) {
                if (substr($file, strlen($suffix) * -1) === $suffix) {
                    $target = $dir . $file;
                    $del = unlink($target) || $del;
                    //$msg[] = $target;
                }
            }
            closedir($handle);
            if ($del) {
                $msg[] = 'All counter files (' . $dir . '*' . $suffix . ') were deleted successful.';
            }
        }
    }
    return $msg;
}
Beispiel #11
0
 function get_ext_autolink($autolink)
 {
     // check valid pages.
     $valid = isset($autolink['target']) ? (string) $autolink['target'] : false;
     if ($valid && isset($this->root->vars['page'])) {
         $_check = false;
         foreach (explode('&', $valid) as $_valid) {
             if ($_valid && strpos($this->root->vars['page'], $_valid) === 0) {
                 $_check = true;
                 break;
             }
         }
         if (!$_check) {
             return '';
         }
     }
     // initialize
     $inits = array('target' => '', 'priority' => 40, 'url' => '', 'urldat' => 0, 'case_i' => 0, 'base' => '', 'len' => 3, 'enc' => $this->cont['CONTENT_CHARSET'], 'cache' => 10, 'title' => 'Ext:[KEY]', 'pat' => '', 'a_target' => '', 'a_class' => '', 'option' => '', 'popup' => '');
     $autolink = array_merge($inits, $autolink);
     if (preg_match('#^https?://#', $autolink['url'])) {
         $this->ext_autolink_own = false;
     } else {
         $this->ext_autolink_own = $autolink['url'];
     }
     // plain_db_write() から呼ばれている時自己Wiki以外はパス
     if (!empty($this->root->rtf['is_init']) && $this->ext_autolink_own !== '') {
         return '';
     }
     $autolink['base'] = trim($autolink['base'], '/');
     $this->ext_autolink_enc_conv = strtoupper($this->cont['CONTENT_CHARSET']) !== strtoupper($autolink['enc']);
     if ($autolink['urldat']) {
         $target = $autolink['url'];
     } else {
         $target = $this->ext_autolink_enc_conv ? mb_convert_encoding($autolink['base'], $autolink['enc'], $this->cont['CONTENT_CHARSET']) : $autolink['base'];
         $target = $autolink['url'] . '?plugin=api&pcmd=autolink&base=' . rawurlencode($target);
     }
     $cache = $this->cont['CACHE_DIR'] . sha1($target . $autolink['option']) . '.extautolink';
     // 重複登録チェック
     if (isset($this->root->rtf['get_ext_autolink_done'][$target])) {
         return '';
     }
     $this->root->rtf['get_ext_autolink_done'][$target] = true;
     $this->ci = $autolink['case_i'];
     $this->make_pagelink_options = array();
     $cache_min = intval(max($autolink['cache'], 10));
     // 自己xpWiki以外 & キャッシュあり & キャッシュが有効範囲
     if ($this->ext_autolink_own !== '' && is_file($cache) && filemtime($cache) + $cache_min * 60 > $this->cont['UTC']) {
         $pat = file_get_contents($cache);
         if ($this->ext_autolink_own !== false) {
             $obj =& XpWiki::getInitedSingleton($this->ext_autolink_own);
             if (!$obj->isXpWiki) {
                 return;
             }
             $this->ext_autolink_func =& $obj->func;
             $this->ci = $obj->root->page_case_insensitive;
         }
     } else {
         if ($this->ext_autolink_own !== false) {
             if ($this->ext_autolink_own) {
                 $obj =& XpWiki::getInitedSingleton($this->ext_autolink_own);
                 if (!$obj->isXpWiki) {
                     return;
                 }
                 $this->ext_autolink_func =& $obj->func;
                 $this->ci = $obj->root->page_case_insensitive;
                 $plugin =& $obj->func->get_plugin_instance('api');
             } else {
                 $this->ci = $this->root->page_case_insensitive;
                 $plugin =& $this->func->get_plugin_instance('api');
                 // Cache しない
                 $cache = false;
             }
             $options = array();
             if ($autolink['option']) {
                 $_options = $this->func->csv_explode(',', $autolink['option']);
                 foreach ($_options as $option) {
                     list($key, $val) = array_pad(explode(':', $option, 2), 2, TRUE);
                     $options[trim($key)] = trim($val);
                 }
             }
             $pat = $plugin->autolink(true, $autolink['base'], $options);
             if ($autolink['popup']) {
                 $this->make_pagelink_options['popup']['use'] = 1;
             }
         } else {
             $data = $this->func->http_request($target);
             if ($data['rc'] !== 200) {
                 $pat = '';
             } else {
                 $pat = $this->ext_autolink_enc_conv ? mb_convert_encoding($data['data'], $this->cont['CONTENT_CHARSET'], $autolink['enc']) : $data['data'];
                 $pat = trim($pat);
                 @(list($pat1, $pat2) = preg_split('/[\\r\\n]+/', $pat));
                 // check regex pattern
                 if ($pat1) {
                     foreach (explode("\t", $pat1) as $_pat) {
                         if (preg_match('/(' . $_pat . ')/S', '') === false) {
                             $pat1 = '';
                             break;
                         }
                     }
                 }
                 if ($pat2) {
                     foreach (explode("\t", $pat2) as $_pat) {
                         if (preg_match('/(' . $_pat . ')/S', '') === false) {
                             $pat2 = '';
                             break;
                         }
                     }
                 }
                 $pat = '';
                 if ($pat1) {
                     $pat = $pat1;
                 }
                 if ($pat2) {
                     $pat .= "\t" . $pat2;
                 }
             }
         }
         if ($cache) {
             $fp = fopen($cache, 'w');
             fwrite($fp, $pat);
             fclose($fp);
         }
     }
     $this->ext_autolink_url = $autolink['url'];
     $this->ext_autolink_base = $autolink['base'] ? $autolink['base'] . '/' : '';
     $this->ext_autolink_len = intval($autolink['len']);
     $this->ext_autolink_enc = $autolink['enc'];
     $this->ext_autolink_pat = $autolink['pat'];
     $this->ext_autolink_title = $autolink['title'];
     $this->ext_autolink_a_target = $autolink['a_target'] ? $autolink['a_target'] : $this->root->link_target;
     $this->ext_autolink_a_class = $autolink['a_class'] ? $autolink['a_class'] : 'ext_autolink';
     if ($this->ext_autolink_pat) {
         if (strpos($this->ext_autolink_pat, '[URL_ENCODE]') !== false) {
             $this->ext_autolink_replace['from'] = '[URL_ENCODE]';
             $this->ext_autolink_replace['func'] = create_function('$key', 'return urlencode($key);');
         } else {
             if (strpos($this->ext_autolink_pat, '[WIKI_ENCODE]') !== false) {
                 $this->ext_autolink_replace['from'] = '[WIKI_ENCODE]';
                 $this->ext_autolink_replace['func'] = create_function('$key', 'return XpWikiFunc::encode($key);');
             } else {
                 if (strpos($this->ext_autolink_pat, '[EWORDS_ENCODE]') !== false) {
                     $this->ext_autolink_replace['from'] = '[EWORDS_ENCODE]';
                     $this->ext_autolink_replace['func'] = create_function('$key', 'return str_replace(array(\'%\',\'.\'), array(\'\',\'2E\'), urlencode($key));');
                 }
             }
         }
     }
     return $pat;
 }
Beispiel #12
0
 function do_plugin_inline($name, $args = '', $body = '')
 {
     $plugin =& $this->get_plugin_instance($name);
     if ($args !== '') {
         $aryargs = $this->csv_explode(',', $args);
     } else {
         $aryargs = array();
     }
     if ($aryargs && ($_num = $plugin->can_call_otherdir_inline())) {
         // Other xpWiki dir
         $_num = intval($_num) - 1;
         if (intval(strpos($aryargs[$_num], ':')) > 0) {
             list($dir, $arg) = explode(':', $aryargs[$_num], 2);
             if ($this->root->mydirname === $dir) {
                 $aryargs[$_num] = $arg;
             } else {
                 if ($this->isXpWikiDirname($dir)) {
                     $other =& XpWiki::getInitedSingleton($dir);
                     if ($other->isXpWiki) {
                         $aryargs[$_num] = $arg;
                         $plugin->swap_global_vars($this, $other);
                         $ret = $other->func->do_plugin_inline($name, $this->csv_implode(',', $aryargs), $body);
                         $plugin->swap_global_vars($this, $other);
                         return $ret;
                     }
                 }
             }
         }
     }
     // NOTE: A reference of $body is always the last argument
     $aryargs[] = $body;
     // func_num_args() != 0
     // ¼Â¹Ô¥×¥é¥°¥¤¥ó̾¤òÅÐÏ¿
     $this->root->plugin_stack[] = $name;
     $_digest = $this->root->digest;
     $retvar = call_user_func_array(array(&$plugin, 'plugin_' . $name . '_inline'), $aryargs);
     $this->root->digest = $_digest;
     // Revert
     // ¼Â¹Ô¥×¥é¥°¥¤¥ó̾¤òËõ¾Ã
     array_pop($this->root->plugin_stack);
     if ($retvar === FALSE) {
         // Do nothing
         return htmlspecialchars('&' . $name . ($args ? '(' . $args . ')' : '') . ';');
     } else {
         if (in_array($name, $this->root->description_ignore_inlines)) {
             return $this->wrap_description_ignore($retvar);
         } else {
             return $retvar;
         }
     }
 }
Beispiel #13
0
 function &get_interwiki_url($name, &$param, &$alias)
 {
     static $interwikinames = array();
     static $encode_aliases = array('sjis' => 'SJIS', 'euc' => 'EUC-JP', 'utf8' => 'UTF-8');
     $false = FALSE;
     if (!isset($interwikinames[$this->root->mydirname])) {
         $interwiki_dat = $this->cont['CACHE_DIR'] . 'interwiki.dat';
         if (is_file($interwiki_dat)) {
             $interwikinames[$this->root->mydirname] = unserialize(file_get_contents($interwiki_dat));
         } else {
             $interwikinames[$this->root->mydirname] = $this->interwiki_dat_update($this->get_source($this->root->interwiki));
         }
     }
     if (!isset($interwikinames[$this->root->mydirname][$name])) {
         // Inner other xpwiki
         if ($this->isXpWikiDirname($name)) {
             $interwikinames[$this->root->mydirname][$name] = array($name, 'inner');
         } else {
             return $false;
         }
     }
     list($url, $opt) = $interwikinames[$this->root->mydirname][$name];
     $replaces = array();
     if (strpos($opt, '|') !== FALSE) {
         $options = explode('|', $opt);
         $opt = array_shift($options);
         foreach ($options as $option) {
             if (strpos($option, '>')) {
                 list($from, $to) = explode('>', $option);
                 $replaces[$from] = $to;
             } else {
                 if ($alias === '' && substr($option, 0, 7) === 'prefix:') {
                     $alias = substr($option, 7) . $param;
                 }
             }
         }
         if ($replaces) {
             $param = strtr($param, $replaces);
         }
     }
     // Encoding
     switch ($opt) {
         case '':
             /* FALLTHROUGH */
         /* FALLTHROUGH */
         case 'std':
             // Simply URL-encode the string, whose base encoding is the internal-encoding
             $param = rawurlencode($param);
             break;
         case 'asis':
             /* FALLTHROUGH */
         /* FALLTHROUGH */
         case 'raw':
             // Truly as-is
             $param = $param;
             break;
         case 'yw':
             // YukiWiki
             if (!preg_match('/' . $this->root->WikiName . '/', $param)) {
                 $param = '[[' . mb_convert_encoding($param, 'SJIS', $this->cont['SOURCE_ENCODING']) . ']]';
             }
             break;
         case 'moin':
             // MoinMoin
             $param = str_replace('%', '_', rawurlencode($param));
             break;
             // Æó½Å¤ËURL¥¨¥ó¥³¡¼¥É¤¹¤ë
         // Æó½Å¤ËURL¥¨¥ó¥³¡¼¥É¤¹¤ë
         case 'dbl':
             $param = rawurlencode(rawurlencode($param));
             break;
         case 'dbl_utf8':
             $param = rawurlencode(rawurlencode(mb_convert_encoding($param, 'UTF-8', $this->cont['SOURCE_ENCODING'])));
             break;
         case 'dbl_sjis':
             $param = rawurlencode(rawurlencode(mb_convert_encoding($param, 'SJIS', $this->cont['SOURCE_ENCODING'])));
             break;
         case 'dbl_euc-jp':
             $param = rawurlencode(rawurlencode(mb_convert_encoding($param, 'EUC-JP', $this->cont['SOURCE_ENCODING'])));
             break;
             // HexEncode·Ï
         // HexEncode·Ï
         case 'hex_utf8':
         case 'wiki_utf8':
             $param = $this->encode(mb_convert_encoding($param, 'UTF-8', $this->cont['SOURCE_ENCODING']));
             break;
         case 'hex_sjis':
         case 'wiki_sjis':
             $param = $this->encode(mb_convert_encoding($param, 'SJIS', $this->cont['SOURCE_ENCODING']));
             break;
         case 'hex_euc-jp':
         case 'wiki_euc-jp':
             $param = $this->encode(mb_convert_encoding($param, 'EUC-JP', $this->cont['SOURCE_ENCODING']));
             break;
             // Inner other xpwiki
         // Inner other xpwiki
         case 'inner':
         case 'xpwiki':
             if (strpos($url, '?') !== FALSE) {
                 list($url, $prefix) = explode('?', $url, 2);
                 $param = $prefix . $param;
             }
             $otherObj =& XpWiki::getInitedSingleton(basename($url));
             if ($otherObj->isXpWiki) {
                 if ($param !== '') {
                     if (!$otherObj->func->is_pagename($param)) {
                         return $false;
                     }
                 }
                 return $otherObj;
             }
             return $false;
             break;
             // Rakuten affiliate
         // Rakuten affiliate
         case 'rakuten':
             $param = '?pc=http%3A%2F%2Fesearch.rakuten.co.jp%2Frms%2Fsd%2Fesearch%2Fvc%3Fsv%3D2%26sitem%3D' . urlencode(urlencode(mb_convert_encoding($param, 'EUC-JP', $this->cont['SOURCE_ENCODING']))) . '&m=http%3A%2F%2Fs.j.rakuten.co.jp%2Fr%2Fs%2Fwb%3Fws%3D1%26w%3D' . urlencode(urlencode(mb_convert_encoding($param, 'SJIS', $this->cont['SOURCE_ENCODING'])));
             break;
             // ewords
         // ewords
         case 'ewords':
             $param = str_replace(array('%', '.'), array('', '2E'), urlencode(mb_convert_encoding($param, 'UTF-8', $this->cont['SOURCE_ENCODING'])));
             break;
         default:
             // Alias conversion of $opt
             if (isset($encode_aliases[$opt])) {
                 $opt =& $encode_aliases[$opt];
             }
             // Encoding conversion into specified encode, and URLencode
             $param = rawurlencode(mb_convert_encoding($param, $opt, $this->cont['SOURCE_ENCODING']));
     }
     // Replace or Add the parameter
     if (strpos($url, '$1') !== $false) {
         $url = str_replace('$1', $param, $url);
     } else {
         $url .= $param;
     }
     if (!preg_match('/' . $this->root->interwikinameRegex . '[!~*\'();\\/?:\\@&=+\\$,%#_0-9a-zA-Z.-]*/', $url) || strlen($url) > 512) {
         return $false;
     }
     return $url;
 }
Beispiel #14
0
    function toString($page = '', $flat = FALSE)
    {
        $pcmd = $this->mode == "imglist" ? "imglist" : "list";
        $pcmd2 = $this->mode == "imglist" ? "list" : "imglist";
        $otherkeys = array('cols', 'max', 'base', 'mode', 'winop', 'basedir', 'encode_hint', 'word');
        if ($this->is_popup) {
            $otherkeys[] = 'popup';
            if ($this->cont['UA_PROFILE'] === 'mobile') {
                $this->func->add_tag_head('<!--jqm_theme_d-->');
            }
        }
        if (!isset($this->root->vars['basedir'])) {
            $this->root->vars['basedir'] = $this->root->mydirname;
        }
        $otherparm = '';
        $otherprams = array();
        $hiddens = array();
        $hiddens['plugin'] = 'attach';
        $hiddens['pcmd'] = $pcmd;
        $hiddens['refer'] = isset($this->root->vars['refer']) ? $this->func->htmlspecialchars($this->root->vars['refer']) : '';
        foreach ($otherkeys as $key) {
            if (isset($this->root->vars[$key])) {
                $otherprams[] = rawurlencode($key) . '=' . rawurlencode($this->root->vars[$key]);
                $hiddens[$this->func->htmlspecialchars($key)] = $this->func->htmlspecialchars($this->root->vars[$key]);
            }
        }
        $select_js = $otherDir = $select = '';
        if ($this->is_popup) {
            $dirs = $otherDirs = array();
            if ($handle = opendir($this->cont['MODULE_PATH'])) {
                while (false !== ($dir = readdir($handle))) {
                    if (is_dir($this->cont['MODULE_PATH'] . $dir) && $dir[0] !== '.' && $this->func->isXpWikiDirname($dir)) {
                        $other = XpWiki::getInitedSingleton($dir);
                        if ($other->isXpWiki) {
                            if ($other->root->pages_for_attach) {
                                list($dirs[$dir]['defaultpage']) = explode('#', $other->root->pages_for_attach);
                            } else {
                                $dirs[$dir]['defaultpage'] = $other->root->defaultpage;
                            }
                            $dirs[$dir]['title'] = $other->root->module['title'];
                        }
                    }
                }
            }
            if (count($dirs) > 1) {
                ksort($dirs);
                foreach ($dirs as $dir => $val) {
                    $defaultpage = $val['defaultpage'];
                    $selected = $dir === $this->root->mydirname ? ' selected="selected"' : '';
                    if ($this->root->vars['basedir'] === $dir) {
                        $defaultpage = $this->root->vars['base'];
                    }
                    $otherDirs[] = '<option value="' . $dir . '#' . $this->func->htmlspecialchars($defaultpage) . '"' . $selected . '>' . $this->func->htmlspecialchars($val['title']) . '</option>';
                }
                $otherDir = '<form><img src="' . $this->cont['LOADER_URL'] . '?src=folder_go.png" alt="Dir" /> <select name="otherdir" style="max-width:85%;" onchange="xpwiki_dir_selector_change(this.options[this.selectedIndex].value)">' . join('', $otherDirs) . '</select></form>';
            }
            $where = array();
            if (!empty($this->root->vars['word'])) {
                foreach (explode(' ', mb_convert_kana($this->root->vars['word']), 's') as $search) {
                    $where[] = 'a.`name` LIKE \'%' . addslashes($search) . '%\'';
                }
            }
            $where = $where ? ' AND ' . join(' AND ', $where) : '';
            $otherPages = array();
            $shown = array($this->root->vars['base']);
            $attach =& $this->func->get_plugin_instance('attach');
            if ($this->root->pages_for_attach) {
                $otherPages[] = '<optgroup label="' . $this->root->_attach_messages['msg_select_useful'] . '">';
                foreach (explode('#', $this->root->pages_for_attach) as $_page) {
                    if ($this->func->check_readable($_page, false, false)) {
                        $selected = $_page === $page ? ' selected="selected"' : '';
                        $shown[] = $_page;
                        $_pgid = $this->func->get_pgid_by_name($_page);
                        if ($_pgid) {
                            $query = 'SELECT count( * ) FROM `' . $this->xpwiki->db->prefix($this->root->mydirname . '_attach') . '` a WHERE a.pgid="' . $_pgid . '" AND a.age = 0 AND a.name != "fusen.dat"' . $where . ' LIMIT 1';
                            $count = '';
                            if ($result = $this->xpwiki->db->query($query)) {
                                $row = $this->xpwiki->db->fetchRow($result);
                                $count = ' (' . $row[0] . ')';
                            }
                        } else {
                            $count = ' (0)';
                        }
                        $_attachable = '';
                        $_class = 'readable';
                        if ($attach->attachable($_page)) {
                            $_class = 'attachable';
                            if ($this->cont['UA_PROFILE'] !== 'default') {
                                $_attachable = '&uarr;';
                            }
                        }
                        $otherPages[] = '<option class="' . $_class . '" value="' . rawurlencode($_page) . '"' . $selected . '>' . $_attachable . $this->func->htmlspecialchars($_page) . $count . '</option>';
                    }
                }
                $otherPages[] = '</optgroup>';
            }
            $query = 'SELECT p.name, count( * ) AS count FROM `' . $this->xpwiki->db->prefix($this->root->mydirname . '_pginfo') . '` p INNER JOIN `' . $this->xpwiki->db->prefix($this->root->mydirname . '_attach') . '` a ON p.pgid = a.pgid WHERE a.age =0 AND a.name != "fusen.dat"' . $where . ' GROUP BY a.pgid ORDER BY count DESC, p.name ASC LIMIT 0 , 50';
            if ($result = $this->xpwiki->db->query($query)) {
                $otherPages[] = '<optgroup label="' . $this->root->_attach_messages['msg_select_manyitems'] . '">';
                while ($row = $this->xpwiki->db->fetchRow($result)) {
                    if ($this->func->check_readable($row[0], false, false)) {
                        if (in_array($row[0], $shown)) {
                            continue;
                        }
                        $selected = $row[0] === $page ? ' selected="selected"' : '';
                        $_page = $this->func->htmlspecialchars($row[0]);
                        $_attachable = '';
                        $_class = 'readable';
                        if ($attach->attachable($_page)) {
                            $_class = 'attachable';
                            if ($this->cont['UA_PROFILE'] !== 'default') {
                                $_attachable = '&uarr;';
                            }
                        }
                        $otherPages[] = '<option class="' . $_class . '" value="' . rawurlencode($_page) . '"' . $selected . '>' . $_attachable . $this->func->htmlspecialchars($_page) . ' (' . $row[1] . ')</option>';
                    }
                }
                $otherPages[] = '</optgroup>';
            }
            if ($otherPages) {
                $thisPage = '<option value="">--- ' . $this->root->_attach_messages['msg_page_select'] . ' ---</option>';
                if ($this->root->vars['basedir'] === $this->root->mydirname) {
                    $selected = $this->root->vars['base'] === $page ? ' selected="selected"' : '';
                    $thisPage .= '<option value="' . rawurlencode($this->root->vars['base']) . '"' . $selected . '>' . $this->func->htmlspecialchars($this->root->vars['base']) . $this->root->_attach_messages['msg_select_current'] . '</option>';
                }
                if (!empty($this->root->vars['refer'])) {
                    $thisPage .= '<option value="#">' . $this->root->_attach_messages['msg_show_all_pages'] . '</option>';
                }
                $base = rawurlencode($this->root->vars['base']);
                $select = '<form><img src="' . $this->cont['LOADER_URL'] . '?src=page_attach.png" alt="Pages" /> <select name="othorpage" style="max-width:85%;" onchange="xpwiki_file_selector_change(this.options[this.selectedIndex].value, \'' . $base . '\')">' . $thisPage . join('', $otherPages) . '</select></form>';
            }
            $select_js = <<<EOD
<script type="text/javascript"><!--
function xpwiki_file_selector_change(page, base) {
\tif (page || page == 0) {
\t\tif (page == '#') page = '';
\t\tvar href = location.href;
\t\tif (! href.match(/&refer=[^&]*/)) {
\t\t\thref += '&refer=';
\t\t}
\t\tlocation.href = href.replace(/&refer=[^&]*/, '&refer=' + page).replace(/&base=[^&]*/, '&base=' + base).replace(/&(start|encode_hint)=[^&]+/, '');
\t}
}
function xpwiki_dir_selector_change(dir) {
\tif (dir) {
\t\tvar arr = dir.split('#');
\t\tlocation.href = location.href.replace(/\\/modules\\/[^\\/]+/, '/modules/' + arr[0]).replace(/&refer=[^&]*/, '&refer=').replace(/&start=[^&]+/, '');
\t}
}
//-->
</script>
EOD;
        }
        $sword = isset($this->root->vars['word']) ? $this->func->htmlspecialchars($this->root->vars['word']) : '';
        $hidden = '';
        unset($hiddens['word']);
        foreach ($hiddens as $key => $val) {
            $hidden .= sprintf('<input type="hidden" name="%s" value="%s" />', $key, $val);
        }
        if ($flat) {
            $search = '';
        } else {
            if ($this->cont['UA_PROFILE'] === 'mobile') {
                $search = '<div><form method="get" action="' . $this->root->script . '"><input type="search" name="word" autocomplete="off" value="' . $sword . '" />' . $hidden . '</form></div>';
            } else {
                $search = '<div><form method="get" action="' . $this->root->script . '"><img src="' . $this->cont['LOADER_URL'] . '?src=find.png" alt="Search" /> <input size="15" type="search" name="word" value="' . $sword . '" /><input data-inline="true" type="submit" value="' . $this->root->_btn_search . '" />' . $hidden . '</form></div>';
            }
        }
        if ($page !== '') {
            if (!array_key_exists($page, $this->pages)) {
                return '';
            }
            return '<div class="attach_list">' . $select_js . $otherDir . $select . $search . $this->pages[$page]->toString($flat, FALSE, $this->mode) . '</div>';
        }
        if ($otherprams) {
            $otherparm = '&amp;' . join('&amp;', $otherprams);
        }
        $url = $this->root->script . "?plugin=attach&amp;pcmd={$pcmd}{$otherparm}&amp;order=" . $this->order . "&amp;start=";
        $url2 = $this->root->script . "?plugin=attach&amp;pcmd={$pcmd}{$otherparm}&amp;start=";
        $url3 = $this->root->script . "?plugin=attach&amp;pcmd={$pcmd2}{$otherparm}&amp;order=" . $this->order . "&amp;start=" . $this->start;
        $sort_time = $this->order == "name" ? " [ <a href=\"{$url2}0&amp;order=time\">{$this->root->_attach_messages['msg_sort_time']}</a> |" : " [ <b>{$this->root->_attach_messages['msg_sort_time']}</b> |";
        $sort_name = $this->order == "name" ? " <b>{$this->root->_attach_messages['msg_sort_name']}</b> ] " : " <a href=\"{$url2}0&amp;order=name\">{$this->root->_attach_messages['msg_sort_name']}</a> ] ";
        if ($this->is_popup) {
            $mode_tag = '';
        } else {
            $mode_tag = $this->mode == "imglist" ? "[ <a href=\"{$url3}\">{$this->root->_attach_messages['msg_list_view']}</a> ]" : "[ <a href=\"{$url3}\">{$this->root->_attach_messages['msg_image_view']}</a> ]";
        }
        $_start = $this->start + 1;
        $_end = $this->start + $this->max;
        $_end = min($_end, $this->count);
        $now = $this->start / $this->max + 1;
        $total = ceil($this->count / $this->max);
        $navi = array();
        for ($i = 1; $i <= $total; $i++) {
            if ($now == $i) {
                $navi[] = "<b>{$i}</b>";
            } else {
                $navi[] = "<a href=\"" . $url . ($i - 1) * $this->max . "\"><span class=\"button\">{$i}</span></a>";
            }
        }
        $navi = join(' ', $navi);
        $prev = max(0, $now - 1);
        $next = $now;
        $prev = $prev ? "<a href=\"" . $url . ($prev - 1) * $this->max . "\" title=\"Prev\"><span class=\"button\"> <img src=\"{$this->cont['LOADER_URL']}?src=prev.png\" width=\"6\" height=\"12\" alt=\"Prev\"> </span></a>" : "";
        $next = $next < $total ? "<a href=\"" . $url . $next * $this->max . "\" title=\"Next\"><span class=\"button\"> <img src=\"{$this->cont['LOADER_URL']}?src=next.png\" width=\"6\" height=\"12\" alt=\"Next\"> </span></a>" : "";
        $navi = "<div class=\"page_navi\">| {$navi} |<br />[{$prev} {$_start} - {$_end} / " . $this->count . " pages {$next}]<br />{$sort_time}{$sort_name}{$mode_tag}</div>";
        $ret = '';
        $pages = array_keys($this->pages);
        if ($pages) {
            foreach ($pages as $page) {
                $ret .= $this->pages[$page]->toString($flat, TRUE, $this->mode) . "\n";
            }
        } else {
            $navi = '';
        }
        return "\n<div class=\"attach_list\">{$select_js}{$otherDir}{$select}{$search}{$navi}" . ($navi ? "<hr />" : "") . "\n{$ret}\n" . ($navi ? "<hr />" : "") . "{$navi}</div>\n";
    }
Beispiel #15
0
    function xpwiki_onupdate_base($module, $mydirname)
    {
        // transations on module update
        global $msgs;
        // TODO :-D
        // for Cube 2.1
        if (defined('XOOPS_CUBE_LEGACY')) {
            $root =& XCube_Root::getSingleton();
            $root->mDelegateManager->add('Legacy.Admin.Event.ModuleUpdate.' . ucfirst($mydirname) . '.Success', 'xpwiki_message_append_onupdate');
            $root->mDelegateManager->add('Legacy.Admin.Event.ModuleUpdate.' . ucfirst($mydirname) . '.Fail', 'xpwiki_message_append_onupdate');
            $msgs = array();
        } else {
            if (!is_array($msgs)) {
                $msgs = array();
            }
        }
        $db =& Database::getInstance();
        $mid = $module->getVar('mid');
        // DB Check for db non support version
        $query = "SELECT * FROM " . $db->prefix($mydirname . "_pginfo");
        if (!$db->query($query)) {
            // TABLES (loading mysql.sql)
            $sql_file_path = dirname(__FILE__) . '/sql/mysql.sql';
            $prefix_mod = $db->prefix() . '_' . $mydirname;
            if (file_exists($sql_file_path)) {
                $ret[] = "SQL file found at <b>" . htmlspecialchars($sql_file_path, ENT_COMPAT, _CHARSET) . "</b>.<br /> Creating tables...";
                if (is_file(XOOPS_ROOT_PATH . '/class/database/oldsqlutility.php')) {
                    include_once XOOPS_ROOT_PATH . '/class/database/oldsqlutility.php';
                    $sqlutil = new OldSqlUtility();
                } else {
                    include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php';
                    $sqlutil = new SqlUtility();
                }
                $sql_query = trim(file_get_contents($sql_file_path));
                $sqlutil->splitMySqlFile($pieces, $sql_query);
                $created_tables = array();
                foreach ($pieces as $piece) {
                    $prefixed_query = $sqlutil->prefixQuery($piece, $prefix_mod);
                    if (!$prefixed_query) {
                        $ret[] = "Invalid SQL <b>" . htmlspecialchars($piece, ENT_COMPAT, _CHARSET) . "</b><br />";
                        return false;
                    }
                    if (!$db->query($prefixed_query[0])) {
                        $ret[] = '<b>' . htmlspecialchars($db->error(), ENT_COMPAT, _CHARSET) . '</b><br />';
                        //var_dump( $db->error() ) ;
                        return false;
                    } else {
                        if (!in_array($prefixed_query[4], $created_tables)) {
                            $ret[] = 'Table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4], ENT_COMPAT, _CHARSET) . '</b> created.<br />';
                            $created_tables[] = $prefixed_query[4];
                        } else {
                            $ret[] = 'Data inserted to table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4], ENT_COMPAT, _CHARSET) . '</b>.</br />';
                        }
                    }
                }
            }
        }
        // TABLES (write here ALTER TABLE etc. if necessary)
        $query = "SELECT `reading` FROM " . $db->prefix($mydirname . "_pginfo");
        if (!$db->query($query)) {
            $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_pginfo") . '` ADD `reading` VARCHAR( 255 ) BINARY NOT NULL');
        }
        $query = "SELECT `name_ci` FROM " . $db->prefix($mydirname . "_pginfo");
        if (!$db->query($query)) {
            $db->query('ALTER TABLE `' . $db->prefix($mydirname . '_pginfo') . '` ADD `name_ci` VARCHAR( 255 ) NOT NULL');
            $db->query('ALTER TABLE `' . $db->prefix($mydirname . '_pginfo') . '` ADD INDEX ( `name_ci` )');
            $db->query('UPDATE `' . $db->prefix($mydirname . '_pginfo') . '` SET `name_ci` = `name`');
        }
        $query = "SELECT `pgorder` FROM " . $db->prefix($mydirname . "_pginfo");
        if (!$db->query($query)) {
            $db->query('ALTER TABLE `' . $db->prefix($mydirname . '_pginfo') . '` ADD `pgorder` FLOAT DEFAULT \'1\' NOT NULL');
        }
        $query = "SELECT count(*) FROM " . $db->prefix($mydirname . "_cache");
        if (!$db->query($query)) {
            $db->query('CREATE TABLE `' . $db->prefix($mydirname . '_cache') . '` (
  `key` varchar(64) NOT NULL default \'\',
  `plugin` varchar(100) NOT NULL default \'\',
  `data` mediumblob NOT NULL,
  `mtime` int(11) NOT NULL default \'0\',
  `ttl` int(11) NOT NULL default \'0\',
  KEY `key` (`key`),
  KEY `plugin` (`plugin`)
) ENGINE=MyISAM');
        }
        $query = "SELECT count(*) FROM " . $db->prefix($mydirname . "_alias");
        if (!$db->query($query)) {
            $db->query('CREATE TABLE `' . $db->prefix($mydirname . '_alias') . '` (
  `name` varchar(255) binary NOT NULL DEFAULT \'\',
  `pgid` int(11) NOT NULL DEFAULT \'0\',
  PRIMARY KEY (`name`),
  KEY `pgid` (`pgid`)
) ENGINE=MyISAM');
            include_once XOOPS_TRUST_PATH . "/modules/xpwiki/include.php";
            $xpwiki = XpWiki::getInitedSingleton($mydirname);
            $xpwiki->init();
            if ($xpwiki->root->page_aliases) {
                $query = array();
                foreach ($xpwiki->root->page_aliases as $alias => $page) {
                    if ($pgid = $xpwiki->func->get_pgid_by_name($page)) {
                        $query[] = '(' . $db->quoteString($alias) . ',' . $pgid . ')';
                    }
                }
                if ($query) {
                    $query = 'INSERT INTO `' . $db->prefix($mydirname . "_alias") . '` (`name`,`pgid`) VALUES ' . join(',', $query);
                    if ($db->query($query)) {
                        $inifile = $xpwiki->cont['CACHE_DIR'] . 'pukiwiki.ini.php';
                        $ini = file_get_contents($inifile);
                        file_put_contents($inifile . '.alias.bak', $ini);
                        $ini = preg_replace('#//<page_aliases>.+//<page_aliases/>\\s+#s', '', $ini);
                        file_put_contents($inifile, $ini);
                    }
                }
            }
            unset($xpwiki);
        }
        // ADD Keys
        $table = $db->prefix($mydirname . '_attach');
        if ($result = $db->query('SHOW INDEX FROM `' . $table . '`')) {
            $keys = array('name' => '', 'type' => '', 'mode' => '', 'age' => '');
            while ($arr = $db->fetchArray($result)) {
                unset($keys[$arr['Key_name']]);
            }
            foreach ($keys as $_key => $_val) {
                $query = 'ALTER TABLE `' . $table . '` ADD INDEX(`' . $_key . '`' . $_val . ')';
                $db->query($query);
                //$msgs[] = $query;
            }
        }
        $table = $db->prefix($mydirname . '_pginfo');
        if ($result = $db->query('SHOW INDEX FROM `' . $table . '`')) {
            $keys = array('editedtime' => '', 'freeze' => '', 'egids' => '', 'vgids' => '', 'eaids' => '(255)', 'vaids' => '(255)', 'vids' => array('vaids' => '(200)', 'vgids' => '(133)'));
            while ($arr = $db->fetchArray($result)) {
                unset($keys[$arr['Key_name']]);
            }
            foreach ($keys as $_key => $_val) {
                if (is_array($_val)) {
                    $_index = array();
                    foreach ($_val as $__key => $__val) {
                        $_index[] = '`' . $__key . '`' . $__val;
                    }
                    $_index = join(', ', $_index);
                } else {
                    $_index = '`' . $_key . '`' . $_val;
                }
                $query = 'ALTER TABLE `' . $table . '` ADD INDEX `' . $_key . '`(' . $_index . ')';
                $db->query($query);
                //$msgs[] = $query;
            }
        }
        $table = $db->prefix($mydirname . '_rel');
        if ($result = $db->query('SHOW INDEX FROM `' . $table . '`')) {
            $keys = array('PRIMARY' => '');
            while ($arr = $db->fetchArray($result)) {
                unset($keys[$arr['Key_name']]);
            }
            if ($keys) {
                $dels = array();
                $query = 'SELECT CONCAT(pgid, \'_\', relid) as id, (count(*)-1) as count FROM `' . $table . '` GROUP BY id HAVING count >= 1';
                if ($result = $db->query($query)) {
                    while ($arr = $db->fetchRow($result)) {
                        $dels[$arr[0]] = $arr[1];
                    }
                }
                foreach ($dels as $key => $limit) {
                    $arr = explode('_', $key);
                    $query = 'DELETE FROM ' . $table . ' WHERE pgid=' . $arr[0] . ' AND relid=' . $arr[1] . ' LIMIT ' . $limit;
                    $db->query($query);
                    //$msgs[] = $query;
                }
                $query = 'ALTER TABLE `' . $table . '` ADD PRIMARY KEY(`pgid`,`relid`)';
                $db->query($query);
                //$msgs[] = $query;
            }
        }
        $table = $db->prefix($mydirname . '_count');
        if ($result = $db->query('SHOW INDEX FROM `' . $table . '`')) {
            $keys = array('today' => '');
            while ($arr = $db->fetchArray($result)) {
                unset($keys[$arr['Key_name']]);
            }
            foreach ($keys as $_key => $_val) {
                $query = 'ALTER TABLE `' . $table . '` ADD INDEX(`' . $_key . '`' . $_val . ')';
                $db->query($query);
                //$msgs[] = $query;
            }
        }
        // TEMPLATES (all templates have been already removed by modulesadmin)
        $tplfile_handler =& xoops_gethandler('tplfile');
        $tpl_path = dirname(__FILE__) . '/templates';
        if ($handler = @opendir($tpl_path . '/')) {
            while (($file = readdir($handler)) !== false) {
                if (substr($file, 0, 1) == '.') {
                    continue;
                }
                $file_path = $tpl_path . '/' . $file;
                if (is_file($file_path) && substr($file, -5) == '.html') {
                    $mtime = intval(@filemtime($file_path));
                    $tplfile =& $tplfile_handler->create();
                    $tplfile->setVar('tpl_source', file_get_contents($file_path), true);
                    $tplfile->setVar('tpl_refid', $mid);
                    $tplfile->setVar('tpl_tplset', 'default');
                    $tplfile->setVar('tpl_file', $mydirname . '_' . $file);
                    $tplfile->setVar('tpl_desc', '', true);
                    $tplfile->setVar('tpl_module', $mydirname);
                    $tplfile->setVar('tpl_lastmodified', $mtime);
                    $tplfile->setVar('tpl_lastimported', 0);
                    $tplfile->setVar('tpl_type', 'module');
                    if (!$tplfile_handler->insert($tplfile)) {
                        $msgs[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_COMPAT, _CHARSET) . '</b> to the database.</span>';
                    } else {
                        $tplid = $tplfile->getVar('tpl_id');
                        $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_COMPAT, _CHARSET) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)';
                        // generate compiled file
                        include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
                        include_once XOOPS_ROOT_PATH . '/class/template.php';
                        if (!xoops_template_touch($tplid)) {
                            $msgs[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_COMPAT, _CHARSET) . '</b>.</span>';
                        } else {
                            $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_COMPAT, _CHARSET) . '</b> compiled.</span>';
                        }
                    }
                }
            }
            closedir($handler);
        }
        include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
        include_once XOOPS_ROOT_PATH . '/class/template.php';
        xoops_template_clear_module_cache($mid);
        // xpWiki original functions
        include_once dirname(__FILE__) . '/include/check.func.php';
        $_ret = xpwikifunc_permission_check($mydirname);
        if (!$_ret) {
            $msgs = array_merge($msgs, xpwikifunc_defdata_check($mydirname, 'update'));
        } else {
            $msgs = array_merge($msgs, $_ret);
            return false;
        }
        // Delete COUNTER_DIR/*.counter
        $msgs = array_merge($msgs, xpwikifunc_delete_counter($mydirname));
        return true;
    }