Пример #1
0
/**
 * translates a document path to an ID
 *
 * @author  Andreas Gohr <*****@*****.**>
 * @todo    move to pageutils
 */
function pathID($path, $keeptxt = false)
{
    $id = utf8_decodeFN($path);
    $id = str_replace('/', ':', $id);
    if (!$keeptxt) {
        $id = preg_replace('#\\.txt$#', '', $id);
    }
    $id = preg_replace('#^:+#', '', $id);
    $id = preg_replace('#:+$#', '', $id);
    return $id;
}
 /**
  * Formats and prints one file in the list in the thumbnails view
  *
  * @see media_printfile_thumbs()
  */
 function _mod_media_printfile_thumbs($item, $auth, $jump = false, $display_namespace = false)
 {
     global $lang;
     global $conf;
     // Prepare filename
     $file = $this->_getOriginalFileName($item['id']);
     if ($file === false) {
         $file = utf8_decodeFN($item['file']);
     }
     // build fake media id
     $ns = getNS($item['id']);
     $fakeId = $ns === false ? $file : "{$ns}:{$file}";
     $fakeId_escaped = hsc($fakeId);
     // output
     echo '<li><dl title="' . $fakeId_escaped . '">' . NL;
     echo '<dt>';
     if ($item['isimg']) {
         media_printimgdetail($item, true);
     } else {
         echo '<a name="d_:' . $item['id'] . '" class="image" title="' . $fakeId_escaped . '" href="' . media_managerURL(array('image' => $fakeId, 'ns' => $ns, 'tab_details' => 'view')) . '">';
         echo media_printicon($fakeId_escaped);
         echo '</a>';
     }
     echo '</dt>' . NL;
     if (!$display_namespace) {
         $name = hsc($file);
     } else {
         $name = $fakeId_escaped;
     }
     echo '<dd class="name"><a href="' . media_managerURL(array('image' => $fakeId, 'ns' => $ns, 'tab_details' => 'view')) . '" name="h_:' . $item['id'] . '">' . $name . '</a></dd>' . NL;
     if ($item['isimg']) {
         $size = '';
         $size .= (int) $item['meta']->getField('File.Width');
         $size .= '&#215;';
         $size .= (int) $item['meta']->getField('File.Height');
         echo '<dd class="size">' . $size . '</dd>' . NL;
     } else {
         echo '<dd class="size">&#160;</dd>' . NL;
     }
     $date = dformat($item['mtime']);
     echo '<dd class="date">' . $date . '</dd>' . NL;
     $filesize = filesize_h($item['size']);
     echo '<dd class="filesize">' . $filesize . '</dd>' . NL;
     echo '</dl></li>' . NL;
 }
 /**
  * Gets basic info from the file - should work with non-JPEGs
  *
  * @author  Sebastian Delmont <*****@*****.**>
  * @author  Andreas Gohr <*****@*****.**>
  */
 function _parseFileInfo()
 {
     if (file_exists($this->_fileName) && is_file($this->_fileName)) {
         $this->_info['file'] = array();
         $this->_info['file']['Name'] = utf8_decodeFN(utf8_basename($this->_fileName));
         $this->_info['file']['Path'] = fullpath($this->_fileName);
         $this->_info['file']['Size'] = filesize($this->_fileName);
         if ($this->_info['file']['Size'] < 1024) {
             $this->_info['file']['NiceSize'] = $this->_info['file']['Size'] . 'B';
         } elseif ($this->_info['file']['Size'] < 1024 * 1024) {
             $this->_info['file']['NiceSize'] = round($this->_info['file']['Size'] / 1024) . 'KB';
         } elseif ($this->_info['file']['Size'] < 1024 * 1024 * 1024) {
             $this->_info['file']['NiceSize'] = round($this->_info['file']['Size'] / (1024 * 1024)) . 'MB';
         } else {
             $this->_info['file']['NiceSize'] = $this->_info['file']['Size'] . 'B';
         }
         $this->_info['file']['UnixTime'] = filemtime($this->_fileName);
         // get image size directly from file
         $size = getimagesize($this->_fileName);
         $this->_info['file']['Width'] = $size[0];
         $this->_info['file']['Height'] = $size[1];
         // set mime types and formats
         // http://www.php.net/manual/en/function.getimagesize.php
         // http://www.php.net/manual/en/function.image-type-to-mime-type.php
         switch ($size[2]) {
             case 1:
                 $this->_info['file']['Mime'] = 'image/gif';
                 $this->_info['file']['Format'] = 'GIF';
                 break;
             case 2:
                 $this->_info['file']['Mime'] = 'image/jpeg';
                 $this->_info['file']['Format'] = 'JPEG';
                 break;
             case 3:
                 $this->_info['file']['Mime'] = 'image/png';
                 $this->_info['file']['Format'] = 'PNG';
                 break;
             case 4:
                 $this->_info['file']['Mime'] = 'application/x-shockwave-flash';
                 $this->_info['file']['Format'] = 'SWF';
                 break;
             case 5:
                 $this->_info['file']['Mime'] = 'image/psd';
                 $this->_info['file']['Format'] = 'PSD';
                 break;
             case 6:
                 $this->_info['file']['Mime'] = 'image/bmp';
                 $this->_info['file']['Format'] = 'BMP';
                 break;
             case 7:
                 $this->_info['file']['Mime'] = 'image/tiff';
                 $this->_info['file']['Format'] = 'TIFF (Intel)';
                 break;
             case 8:
                 $this->_info['file']['Mime'] = 'image/tiff';
                 $this->_info['file']['Format'] = 'TIFF (Motorola)';
                 break;
             case 9:
                 $this->_info['file']['Mime'] = 'application/octet-stream';
                 $this->_info['file']['Format'] = 'JPC';
                 break;
             case 10:
                 $this->_info['file']['Mime'] = 'image/jp2';
                 $this->_info['file']['Format'] = 'JP2';
                 break;
             case 11:
                 $this->_info['file']['Mime'] = 'application/octet-stream';
                 $this->_info['file']['Format'] = 'JPX';
                 break;
             case 12:
                 $this->_info['file']['Mime'] = 'application/octet-stream';
                 $this->_info['file']['Format'] = 'JB2';
                 break;
             case 13:
                 $this->_info['file']['Mime'] = 'application/x-shockwave-flash';
                 $this->_info['file']['Format'] = 'SWC';
                 break;
             case 14:
                 $this->_info['file']['Mime'] = 'image/iff';
                 $this->_info['file']['Format'] = 'IFF';
                 break;
             case 15:
                 $this->_info['file']['Mime'] = 'image/vnd.wap.wbmp';
                 $this->_info['file']['Format'] = 'WBMP';
                 break;
             case 16:
                 $this->_info['file']['Mime'] = 'image/xbm';
                 $this->_info['file']['Format'] = 'XBM';
                 break;
             default:
                 $this->_info['file']['Mime'] = 'image/unknown';
         }
     } else {
         $this->_info['file'] = array();
         $this->_info['file']['Name'] = utf8_basename($this->_fileName);
         $this->_info['file']['Url'] = $this->_fileName;
     }
     return true;
 }
Пример #4
0
/**
 * Print some info about the current page
 *
 * @author Andreas Gohr <*****@*****.**>
 * @param bool $ret return content instead of printing it
 * @return bool|string
 */
function tpl_pageinfo($ret = false)
{
    global $conf;
    global $lang;
    global $INFO;
    global $ID;
    // return if we are not allowed to view the page
    if (!auth_quickaclcheck($ID)) {
        return false;
    }
    // prepare date and path
    $fn = $INFO['filepath'];
    if (!$conf['fullpath']) {
        if ($INFO['rev']) {
            $fn = str_replace(fullpath($conf['olddir']) . '/', '', $fn);
        } else {
            $fn = str_replace(fullpath($conf['datadir']) . '/', '', $fn);
        }
    }
    $fn = utf8_decodeFN($fn);
    $date = dformat($INFO['lastmod']);
    // print it
    if ($INFO['exists']) {
        $out = '';
        $out .= $fn;
        $out .= ' · ';
        $out .= $lang['lastmod'];
        $out .= ': ';
        $out .= $date;
        if ($INFO['editor']) {
            $out .= ' ' . $lang['by'] . ' ';
            $out .= editorinfo($INFO['editor']);
        } else {
            $out .= ' (' . $lang['external_edit'] . ')';
        }
        if ($INFO['locked']) {
            $out .= ' · ';
            $out .= $lang['lockedby'];
            $out .= ': ';
            $out .= editorinfo($INFO['locked']);
        }
        if ($ret) {
            return $out;
        } else {
            echo $out;
            return true;
        }
    }
    return false;
}
Пример #5
0
/**
 * Formats and prints one file in the list in the thumbnails view
 *
 * @author Kate Arzamastseva <*****@*****.**>
 */
function media_printfile_thumbs($item, $auth, $jump = false, $display_namespace = false)
{
    // Prepare filename
    $file = utf8_decodeFN($item['file']);
    // output
    echo '<li><dl title="' . hsc($item['id']) . '">' . NL;
    echo '<dt>';
    if ($item['isimg']) {
        media_printimgdetail($item, true);
    } else {
        echo '<a id="d_:' . $item['id'] . '" class="image" title="' . $item['id'] . '" href="' . media_managerURL(array('image' => hsc($item['id']), 'ns' => getNS($item['id']), 'tab_details' => 'view')) . '">';
        echo media_printicon($item['id'], '32x32');
        echo '</a>';
    }
    echo '</dt>' . NL;
    if (!$display_namespace) {
        $name = hsc($file);
    } else {
        $name = hsc($item['id']);
    }
    echo '<dd class="name"><a href="' . media_managerURL(array('image' => hsc($item['id']), 'ns' => getNS($item['id']), 'tab_details' => 'view')) . '" id="h_:' . $item['id'] . '">' . $name . '</a></dd>' . NL;
    if ($item['isimg']) {
        $size = '';
        $size .= (int) $item['meta']->getField('File.Width');
        $size .= '&#215;';
        $size .= (int) $item['meta']->getField('File.Height');
        echo '<dd class="size">' . $size . '</dd>' . NL;
    } else {
        echo '<dd class="size">&#160;</dd>' . NL;
    }
    $date = dformat($item['mtime']);
    echo '<dd class="date">' . $date . '</dd>' . NL;
    $filesize = filesize_h($item['size']);
    echo '<dd class="filesize">' . $filesize . '</dd>' . NL;
    echo '</dl></li>' . NL;
}
Пример #6
0
 /**
  * Print index nodes
  *
  * @author Samuele Tognini <*****@*****.**>
  * @author Andreas Gohr <*****@*****.**>
  * @author Rene Hadler <*****@*****.**>
  */
 function print_index($ns)
 {
     require_once DOKU_PLUGIN . 'indexmenu/syntax/indexmenu.php';
     global $conf;
     $idxm = new syntax_plugin_indexmenu_indexmenu();
     $ns = $idxm->_parse_ns(rawurldecode($ns));
     $level = -1;
     $max = 0;
     $data = array();
     $skipfile = array();
     $skipns = 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'];
     $idxm->hsort = $_REQUEST['hsort'];
     $fsdir = "/" . utf8_encodeFN(str_replace(':', '/', $ns));
     $skipf = utf8_decodeFN($_REQUEST['skipfile']);
     $skipfile[] = $this->getConf('skip_file');
     if (isset($skipf)) {
         $index = 0;
         if ($skipf[1] == '+') {
             $index = 1;
         }
         $skipfile[$index] = substr($skipf, 1);
     }
     $skipn = utf8_decodeFN($_REQUEST['skipns']);
     $skipns[] = $this->getConf('skip_index');
     if (isset($skipn)) {
         $index = 0;
         if ($skipn[1] == '+') {
             $index = 1;
         }
         $skipns[$index] = substr($skipn, 1);
     }
     $opts = array('level' => $level, 'nons' => $_REQUEST['nons'], 'nss' => array(array($nss, 1)), 'max' => $max, 'js' => false, 'nopg' => $_REQUEST['nopg'], 'skip_index' => $skipns, 'skip_file' => $skipfile, 'headpage' => $idxm->getConf('headpage'), 'hide_headpage' => $idxm->getConf('hide_headpage'));
     if ($idxm->sort || $idxm->msort || $idxm->rsort || $idxm->hsort) {
         $idxm->_search($data, $conf['datadir'], array($idxm, '_search_index'), $opts, $fsdir);
     } else {
         search($data, $conf['datadir'], array($idxm, '_search_index'), $opts, $fsdir);
     }
     $out = '';
     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;
 }
/**
 * Print some info about the current page
 *
 * @author  Andreas Gohr <*****@*****.**>
 * @author  Giuseppe Di Terlizzi <*****@*****.**>
 *
 * @param   bool $ret return content instead of printing it
 * @return  bool|string
 */
function bootstrap3_pageinfo($ret = false)
{
    global $conf;
    global $lang;
    global $INFO;
    global $ID;
    // return if we are not allowed to view the page
    if (!auth_quickaclcheck($ID)) {
        return false;
    }
    // prepare date and path
    $fn = $INFO['filepath'];
    if (!$conf['fullpath']) {
        if ($INFO['rev']) {
            $fn = str_replace(fullpath($conf['olddir']) . '/', '', $fn);
        } else {
            $fn = str_replace(fullpath($conf['datadir']) . '/', '', $fn);
        }
    }
    $date_format = bootstrap3_conf('pageInfoDateFormat');
    $page_info = bootstrap3_conf('pageInfo');
    $fn = utf8_decodeFN($fn);
    $date = $date_format == 'dformat' ? dformat($INFO['lastmod']) : datetime_h($INFO['lastmod']);
    // print it
    if ($INFO['exists']) {
        $fn_full = $fn;
        if (!in_array('extension', $page_info)) {
            $fn = str_replace(array('.txt.gz', '.txt'), '', $fn);
        }
        $out = '<ul class="list-inline">';
        if (in_array('filename', $page_info)) {
            $out .= sprintf('<li><i class="fa fa-fw fa-file-text-o text-muted"></i> <span title="%s">%s</span></li>', $fn_full, $fn);
        }
        if (in_array('date', $page_info)) {
            $out .= sprintf('<li><i class="fa fa-fw fa-calendar text-muted"></i> %s <span title="%s">%s</span></li>', $lang['lastmod'], dformat($INFO['lastmod']), $date);
        }
        if (in_array('editor', $page_info)) {
            if (isset($INFO['editor'])) {
                $user = editorinfo($INFO['editor']);
                if (bootstrap3_conf('useGravatar')) {
                    global $auth;
                    $user_data = $auth->getUserData($INFO['editor']);
                    $HTTP = new DokuHTTPClient();
                    $gravatar_img = get_gravatar($user_data['mail'], 16);
                    $gravatar_check = $HTTP->get($gravatar_img . '&d=404');
                    if ($gravatar_check) {
                        $user_img = sprintf('<img src="%s" alt="" width="16" class="img-rounded" /> ', $gravatar_img);
                        $user = str_replace(array('iw_user', 'interwiki'), '', $user);
                        $user = $user_img . $user;
                    }
                }
                $out .= sprintf('<li class="text-muted">%s %s</li>', $lang['by'], $user);
            } else {
                $out .= sprintf('<li>(%s)</li>', $lang['external_edit']);
            }
        }
        if ($INFO['locked'] && in_array('locked', $page_info)) {
            $out .= sprintf('<li><i class="fa fa-fw fa-lock text-muted"></i> %s %s</li>', $lang['lockedby'], editorinfo($INFO['locked']));
        }
        $out .= '</ul>';
        if ($ret) {
            return $out;
        } else {
            echo $out;
            return true;
        }
    }
    return false;
}
Пример #8
0
/**
 * Formats and prints one file in the list
 */
function media_printfile($item, $auth, $jump, $display_namespace = false)
{
    global $lang;
    global $conf;
    // Prepare zebra coloring
    // I always wanted to use this variable name :-D
    static $twibble = 1;
    $twibble *= -1;
    $zebra = $twibble == -1 ? 'odd' : 'even';
    // Automatically jump to recent action
    if ($jump == $item['id']) {
        $jump = ' id="scroll__here" ';
    } else {
        $jump = '';
    }
    // Prepare fileicons
    list($ext, $mime, $dl) = mimetype($item['file'], false);
    $class = preg_replace('/[^_\\-a-z0-9]+/i', '_', $ext);
    $class = 'select mediafile mf_' . $class;
    // Prepare filename
    $file = utf8_decodeFN($item['file']);
    // Prepare info
    $info = '';
    if ($item['isimg']) {
        $info .= (int) $item['meta']->getField('File.Width');
        $info .= '&#215;';
        $info .= (int) $item['meta']->getField('File.Height');
        $info .= ' ';
    }
    $info .= '<i>' . dformat($item['mtime']) . '</i>';
    $info .= ' ';
    $info .= filesize_h($item['size']);
    // output
    echo '<div class="' . $zebra . '"' . $jump . '>' . NL;
    if (!$display_namespace) {
        echo '<a name="h_:' . $item['id'] . '" class="' . $class . '">' . hsc($file) . '</a> ';
    } else {
        echo '<a name="h_:' . $item['id'] . '" class="' . $class . '">' . hsc($item['id']) . '</a><br/>';
    }
    echo '<span class="info">(' . $info . ')</span>' . NL;
    media_fileactions($item, $auth);
    echo '<div class="example" id="ex_' . str_replace(':', '_', $item['id']) . '">';
    echo $lang['mediausage'] . ' <code>{{:' . $item['id'] . '}}</code>';
    echo '</div>';
    if ($item['isimg']) {
        media_printimgdetail($item);
    }
    echo '<div class="clearer"></div>' . NL;
    echo '</div>' . NL;
}
Пример #9
0
/**
 * Print some info about the current page
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function tpl_pageinfo()
{
    global $conf;
    global $lang;
    global $INFO;
    global $REV;
    global $ID;
    // return if we are not allowed to view the page
    if (!auth_quickaclcheck($ID)) {
        return;
    }
    // prepare date and path
    $fn = $INFO['filepath'];
    if (!$conf['fullpath']) {
        if ($REV) {
            $fn = str_replace(fullpath($conf['olddir']) . '/', '', $fn);
        } else {
            $fn = str_replace(fullpath($conf['datadir']) . '/', '', $fn);
        }
    }
    $fn = utf8_decodeFN($fn);
    $date = strftime($conf['dformat'], $INFO['lastmod']);
    // print it
    if ($INFO['exists']) {
        print $fn;
        print ' &middot; ';
        print $lang['lastmod'];
        print ': ';
        print $date;
        if ($INFO['editor']) {
            print ' ' . $lang['by'] . ' ';
            print $INFO['editor'];
        } else {
            print ' (' . $lang['external_edit'] . ')';
        }
        if ($INFO['locked']) {
            print ' &middot; ';
            print $lang['lockedby'];
            print ': ';
            print $INFO['locked'];
        }
        return true;
    }
    return false;
}
 /**
  * Sends a media file with its original filename
  * 
  * @see sendFile() in lib/exe/fetch.php
  */
 function _sendFile(&$event)
 {
     global $conf;
     global $MEDIA;
     $d = $event->data;
     $event->preventDefault();
     list($file, $mime, $dl, $cache) = array($d['file'], $d['mime'], $d['download'], $d['cache']);
     $fmtime = @filemtime($file);
     // send headers
     header("Content-Type: {$mime}");
     // smart http caching headers
     if ($cache == -1) {
         // cache
         // cachetime or one hour
         header('Expires: ' . gmdate('D, d M Y H:i:s', time() + max($conf['cachetime'], 3600)) . ' GMT');
         header('Cache-Control: public, proxy-revalidate, no-transform, max-age=' . max($conf['cachetime'], 3600));
         header('Pragma: public');
     } elseif ($cache > 0) {
         // recache
         // remaining cachetime + 10 seconds so the newly recached media is used
         header('Expires: ' . gmdate("D, d M Y H:i:s", $fmtime + $conf['cachetime'] + 10) . ' GMT');
         header('Cache-Control: public, proxy-revalidate, no-transform, max-age=' . max($fmtime - time() + $conf['cachetime'] + 10, 0));
         header('Pragma: public');
     } elseif ($cache == 0) {
         // nocache
         header('Cache-Control: must-revalidate, no-transform, post-check=0, pre-check=0');
         header('Pragma: public');
     }
     // send important headers first, script stops here if '304 Not Modified' response
     http_conditionalRequest($fmtime);
     // retrieve original filename and send Content-Disposition header
     $filename = $this->_getOriginalFileName($MEDIA);
     if ($filename === false) {
         $filename = utf8_decodeFN($this->common->_correctBasename($d['file']));
     }
     header($this->common->_buildContentDispositionHeader($dl, $filename));
     // use x-sendfile header to pass the delivery to compatible webservers
     if (http_sendfile($file)) {
         exit;
     }
     // send file contents
     $fp = @fopen($file, 'rb');
     if ($fp) {
         http_rangeRequest($fp, filesize($file), $mime);
     } else {
         header('HTTP/1.0 500 Internal Server Error');
         print "Could not read {$file} - bad permissions?";
     }
 }
 function utf8_decodeFN($file)
 {
     return utf8_decodeFN($file);
 }