Beispiel #1
0
 /**
  * Send a zipped theme
  *
  * @author Samuele Tognini <*****@*****.**>
  */
 function send_theme($file)
 {
     require_once DOKU_PLUGIN . 'indexmenu/syntax/indexmenu.php';
     $idxm = new syntax_plugin_indexmenu_indexmenu();
     //clean the file name
     $file = cleanID($file);
     //check config
     if (!$idxm->getConf('be_repo') || empty($file)) {
         return false;
     }
     $repodir = INDEXMENU_IMG_ABSDIR . "/repository";
     $zipfile = $repodir . "/{$file}.zip";
     $localtheme = INDEXMENU_IMG_ABSDIR . "/{$file}/";
     //theme does not exists
     if (!file_exists($localtheme)) {
         return false;
     }
     if (!io_mkdir_p($repodir)) {
         return false;
     }
     $lm = @filemtime($zipfile);
     //no cached zip or older than 1 day
     if ($lm < time() - 60 * 60 * 24) {
         //create the zip
         require_once DOKU_PLUGIN . "indexmenu/inc/pclzip.lib.php";
         @unlink($zipfile);
         $zip = new PclZip($zipfile);
         $status = $zip->add($localtheme, PCLZIP_OPT_REMOVE_ALL_PATH);
         //error
         if ($status == 0) {
             return false;
         }
     }
     $len = (int) filesize($zipfile);
     //don't send large zips
     if ($len > 2 * 1024 * 1024) {
         return false;
     }
     //headers
     header('Cache-Control: must-revalidate, no-transform, post-check=0, pre-check=0');
     header('Pragma: public');
     header('Content-Type: application/zip');
     header('Content-Disposition: attachment; filename="' . basename($zipfile) . '";');
     header("Content-Transfer-Encoding: binary");
     //send zip
     $fp = @fopen($zipfile, 'rb');
     if ($fp) {
         $ct = @fread($fp, $len);
         print $ct;
     }
     @fclose($fp);
     return true;
 }
 /**
  * Rendering for nonexisting namespace
  * expect: no paragraph due to no message set
  * expect: one paragraph, since message set
  * expect: contains namespace which replaced {{ns}}
  * expect: message contained rendered italic syntax
  */
 function testRenderEmptymsg()
 {
     global $conf;
     $noexistns = 'nonexisting:namespace';
     $emptyindexsyntax = "{{indexmenu>{$noexistns}}}";
     $xhtml = new Doku_Renderer_xhtml();
     $plugin = new syntax_plugin_indexmenu_indexmenu();
     $null = new Doku_Handler();
     $result = $plugin->handle($emptyindexsyntax, 0, 10, $null);
     //no empty message
     $plugin->render('xhtml', $xhtml, $result);
     $doc = phpQuery::newDocument($xhtml->doc);
     $this->assertEquals(0, pq('p', $doc)->length);
     // Fill in empty message
     $conf['plugin']['indexmenu']['empty_msg'] = 'This namespace is //empty//: {{ns}}';
     $plugin->render('xhtml', $xhtml, $result);
     $doc = phpQuery::newDocument($xhtml->doc);
     $this->assertEquals(1, pq('p', $doc)->length);
     $this->assertEquals(1, pq("p:contains({$noexistns})")->length);
     $this->assertEquals(1, pq("p em")->length);
 }
Beispiel #3
0
 /**
  * Print index nodes
  *
  * @author Samuele Tognini <*****@*****.**>
  * @author Andreas Gohr <*****@*****.**>
  */
 function print_index($ns)
 {
     require_once DOKU_PLUGIN . 'indexmenu/syntax/indexmenu.php';
     global $conf;
     $idxm = new syntax_plugin_indexmenu_indexmenu();
     $ns = $idxm->_parse_ns($ns);
     $level = -1;
     $max = 0;
     $data = array();
     if ($_REQUEST['max'] > 0) {
         $max = $_REQUEST['max'];
         $level = $max;
     }
     $nss = $_REQUEST['nss'] ? cleanID($_REQUEST['nss']) : '';
     $idxm->sort = $_REQUEST['sort'];
     $idxm->msort = $_REQUEST['msort'];
     $idxm->rsort = $_REQUEST['rsort'];
     $idxm->nsort = $_REQUEST['nsort'];
     $fsdir = "/" . utf8_encodeFN(str_replace(':', '/', $ns));
     $opts = array('level' => $level, 'nons' => $_REQUEST['nons'], 'nss' => array(array($nss, 1)), 'max' => $max, 'js' => false, 'nopg' => $_REQUEST['nopg'], 'skip_index' => $idxm->getConf('skip_index'), 'skip_file' => $idxm->getConf('skip_file'), 'headpage' => $idxm->getConf('headpage'), 'hide_headpage' => $idxm->getConf('hide_headpage'));
     if ($idxm->sort || $idxm->msort || $idxm->rsort) {
         $idxm->_search($data, $conf['datadir'], array($idxm, '_search_index'), $opts, $fsdir);
     } else {
         search($data, $conf['datadir'], array($idxm, '_search_index'), $opts, $fsdir);
     }
     if ($_REQUEST['nojs']) {
         require_once DOKU_INC . 'inc/html.php';
         $out_tmp = html_buildlist($data, 'idx', array($idxm, "_html_list_index"), "html_li_index");
         $out .= preg_replace('/<ul class="idx">(.*)<\\/ul>/s', "\$1", $out_tmp);
     } else {
         $nodes = $idxm->_jsnodes($data, '', 0);
         $out = "ajxnodes = [";
         $out .= rtrim($nodes[0], ",");
         $out .= "];";
     }
     return $out;
 }