function internalmedia($src, $title = NULL, $align = NULL, $width = NULL, $height = NULL, $cache = NULL)
 {
     global $conf;
     global $ID;
     resolve_mediaid(getNS($ID), $src, $exists);
     $link = array();
     $link['class'] = 'media';
     $link['target'] = '_blank';
     $link['title'] = $this->_xmlEntities($src);
     $link['url'] = 'media/' . str_replace(':', '/', $src);
     $link['name'] = $this->_media($src, $title, $align, $width, $height, $cache);
     //output formatted
     $this->doc .= $this->_formatLink($link);
 }
 public function internalmedia($src, $title = NULL, $align = NULL, $width = NULL, $height = NULL, $cache = NULL, $linking = NULL, $return = false)
 {
     global $ID;
     list($src, $hash) = explode('#', $src, 2);
     resolve_mediaid(getNS($ID), $src, $exists);
     $noLink = false;
     $render = $linking == 'linkonly' ? false : true;
     $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render);
     list($ext, $mime, $dl) = mimetype($src, false);
     if (substr($mime, 0, 5) == 'image' && $render) {
         if ($linking == NULL || $linking == '' || $linking == 'details') {
             $linking = 'direct';
         }
         $link['url'] = ml($src, array('id' => $ID, 'cache' => $cache), $linking == 'direct');
     } elseif ($mime == 'application/x-shockwave-flash' && $render) {
         // don't link flash movies
         $noLink = true;
     } else {
         // add file icons
         $class = preg_replace('/[^_\\-a-z0-9]+/i', '_', $ext);
         $link['class'] .= ' mediafile mf_' . $class;
         $link['url'] = ml($src, array('id' => $ID, 'cache' => $cache), true);
         if ($exists) {
             $link['title'] .= ' (' . filesize_h(filesize(mediaFN($src))) . ')';
         }
     }
     if ($hash) {
         $link['url'] .= '#' . $hash;
     }
     //markup non existing files
     if (!$exists) {
         $link['class'] .= ' wikilink2';
     }
     //output formatted
     if ($linking == 'nolink' || $noLink) {
         $this->doc .= $link['name'];
     } else {
         $this->doc .= $this->_formatLink($link);
     }
 }
Example #3
0
 function normalize($value, $hint)
 {
     global $ID;
     // strip leading {{ and closing }}
     $value = preg_replace(array('/^\\{\\{/', '/\\}\\}$/u'), '', $value);
     // drop any title and alignment spacing whitespace
     $value = explode('|', $value, 2);
     $value = trim($value[0]);
     if ($this->isExternalMedia($value)) {
         // external image
         // we don't do anything else here
     } else {
         // internal image
         // discard size string and other options
         $pos = strrpos($value, '?');
         if ($pos !== false) {
             $value = substr($value, 0, $pos);
         }
         // resolve page id with respect to selected base
         resolve_mediaid(getNS($ID), $value, $exists);
     }
     return $value;
 }
Example #4
0
 function _firstimage($src)
 {
     if ($this->firstimage) {
         return;
     }
     global $ID;
     list($src, $hash) = explode('#', $src, 2);
     if (!preg_match('/^https?:\\/\\//i', $src)) {
         resolve_mediaid(getNS($ID), $src, $exists);
     }
     if (preg_match('/.(jpe?g|gif|png)$/i', $src)) {
         $this->firstimage = $src;
     }
 }
Example #5
0
 /**
  * Gathers all page and media data for given namespaces.
  * 
  * @namespaces array() of namespaces
  * @depth Search depth
  * @include_media Determines if media should be regarded, Values: 'ns','all','none'.
  * @use_cached_pages Determines if only cached pages should be used. If this option is turned off, the operation will cache all non-cached pages within the namespace.
  * @use_first_header Determines if the first header is used for title of the pages.
  * 
  * @return array with pages and media: array('pages'=>pages, 'media'=>media).   
  */
 function gather_data($namespaces, $depth = 0, $include_media = 'none', $use_cached_pages = true, $use_first_header = false)
 {
     global $conf;
     $transplugin = plugin_load('helper', 'translation');
     $pages = array();
     $media = array();
     // Loop through the namespaces
     foreach ($namespaces as $ns) {
         // Get the media of the namespace
         if ($include_media == 'ns') {
             $this->get_media($media, $ns, $depth);
         }
         // Get the pages of the namespace
         $this->get_pages($pages, $ns, $depth, $use_first_header);
     }
     // Loop through the pages to get links and media
     foreach ($pages as $pid => $item) {
         // get instructions
         $ins = p_cached_instructions(wikiFN($pid), $use_cached_pages, $pid);
         // find links and media usage
         foreach ($ins as $i) {
             $mid = null;
             // Internal link?
             if ($i[0] == 'internallink') {
                 $id = $i[1][0];
                 $exists = true;
                 resolve_pageid($item['ns'], $id, $exists);
                 list($id) = explode('#', $id, 2);
                 if ($id == $pid) {
                     continue;
                 }
                 // skip self references
                 if ($exists && isset($pages[$id])) {
                     $pages[$pid]['links'][] = $id;
                 }
                 if (is_array($i[1][1]) && $i[1][1]['type'] == 'internalmedia') {
                     $mid = $i[1][1]['src'];
                     // image link
                 } else {
                     continue;
                     // we're done here
                 }
             }
             if ($i[0] == 'internalmedia') {
                 $mid = $i[1][0];
             }
             if (is_null($mid)) {
                 continue;
             }
             if ($include_media == 'none') {
                 continue;
             }
             // no media wanted
             $exists = true;
             resolve_mediaid($item['ns'], $mid, $exists);
             list($mid) = explode('#', $mid, 2);
             $mid = cleanID($mid);
             if ($exists) {
                 if ($include_media == 'all') {
                     if (!isset($media[$mid])) {
                         //add node
                         $media[$mid] = array('size' => filesize(mediaFN($mid)), 'time' => filemtime(mediaFN($mid)), 'ns' => getNS($mid), 'title' => noNS($mid));
                     }
                     $pages[$pid]['media'][] = $mid;
                 } elseif (isset($media[$mid])) {
                     $pages[$pid]['media'][] = $mid;
                 }
             }
         }
         // clean up duplicates
         $pages[$pid]['links'] = array_unique($pages[$pid]['links']);
         $pages[$pid]['media'] = array_unique($pages[$pid]['media']);
     }
     return array('pages' => $pages, 'media' => $media);
 }
Example #6
0
 /**
  * Normalizes a media array.
  */
 function _normalize_media($instruction)
 {
     global $ID;
     // construct media structure based on input
     if (isset($instruction['type'])) {
         $media = $instruction;
     } else {
         list($src, $title, $align, $width, $height, $cache, $linking) = $instruction;
         $media = compact('src', 'title', 'align', 'width', 'height');
         $media['type'] = 'internalmedia';
     }
     // normalize internal media links
     if ($media['type'] == 'internalmedia') {
         list($src, $hash) = explode('#', $media['src'], 2);
         resolve_mediaid(getNS($ID), $src, $exists);
         if ($hash) {
             $src .= '#' . $hash;
         }
         $media['src'] = ':' . $src;
     }
     // render the media structure
     return $this->_mediaSyntax($media);
 }
Example #7
0
 /**
  * Construct a new ID relative to the current page's location
  *
  * Uses a relative link only if the original was relative, too. This function is for
  * pages and media files.
  *
  * @param string $relold the old, possibly relative ID
  * @param string $new    the new, full qualified ID
  * @param string $type 'media' or 'page'
  * @throws Exception on bad argument
  * @return string
  */
 public function relativeLink($relold, $new, $type)
 {
     global $conf;
     if ($type != 'media' && $type != 'page') {
         throw new Exception('Not a valid type');
     }
     // first check if the old link still resolves
     $exists = false;
     $old = $relold;
     if ($type == 'page') {
         resolve_pageid($this->ns, $old, $exists);
     } else {
         resolve_mediaid($this->ns, $old, $exists);
     }
     if ($old == $new) {
         return $relold;
         // old link still resolves, keep as is
     }
     if ($conf['useslash']) {
         $relold = str_replace('/', ':', $relold);
     }
     // check if the link was relative
     if (strpos($relold, ':') === false || $relold[0] == '.') {
         $wasrel = true;
     } else {
         $wasrel = false;
     }
     // if it wasn't relative then, leave it absolute now, too
     if (!$wasrel) {
         if ($this->ns && !getNS($new)) {
             $new = ':' . $new;
         }
         $new = $this->_nsStartCheck($relold, $new, $type);
         return $new;
     }
     // split the paths and see how much common parts there are
     $selfpath = explode(':', $this->ns);
     $goalpath = explode(':', getNS($new));
     $min = min(count($selfpath), count($goalpath));
     for ($common = 0; $common < $min; $common++) {
         if ($selfpath[$common] != $goalpath[$common]) {
             break;
         }
     }
     // we now have the non-common part and a number of uppers
     $ups = max(count($selfpath) - $common, 0);
     $remainder = array_slice($goalpath, $common);
     $upper = $ups ? array_fill(0, $ups, '..:') : array();
     // build the new relative path
     $newrel = join(':', $upper);
     if ($remainder) {
         $newrel .= join(':', $remainder) . ':';
     }
     $newrel .= noNS($new);
     $newrel = str_replace('::', ':', trim($newrel, ':'));
     if ($newrel[0] != '.' && $this->ns && getNS($newrel)) {
         $newrel = '.' . $newrel;
     }
     // if the old link ended with a colon and the new one is a start page, adjust
     $newrel = $this->_nsStartCheck($relold, $newrel, $type);
     // don't use relative paths if it is ridicoulus:
     if (strlen($newrel) > strlen($new)) {
         $newrel = $new;
         if ($this->ns && !getNS($new)) {
             $newrel = ':' . $newrel;
         }
         $newrel = $this->_nsStartCheck($relold, $newrel, $type);
     }
     return $newrel;
 }
 /**
  * Render an internal media file
  *
  * @param string $src       media ID
  * @param string $title     descriptive text
  * @param string $align     left|center|right
  * @param int    $width     width of media in pixel
  * @param int    $height    height of media in pixel
  * @param string $cache     cache|recache|nocache
  * @param string $linking   linkonly|detail|nolink
  * @param bool   $returnonly whether to return odt or write to doc attribute
  */
 function internalmedia($src, $title = NULL, $align = NULL, $width = NULL, $height = NULL, $cache = NULL, $linking = NULL, $returnonly = false)
 {
     global $ID;
     resolve_mediaid(getNS($ID), $src, $exists);
     list(, $mime) = mimetype($src);
     if (substr($mime, 0, 5) == 'image') {
         $file = mediaFN($src);
         if ($returnonly) {
             return $this->_odtAddImage($file, $width, $height, $align, $title, true);
         } else {
             $this->_odtAddImage($file, $width, $height, $align, $title);
         }
     } else {
         /*
                     // FIXME build absolute medialink and call externallink()
                     $this->code('FIXME internalmedia: '.$src);
         */
         //FIX by EPO/Intersel - create a link to the dokuwiki internal resource
         if (empty($title)) {
             $title = explode(':', $src);
             $title = end($title);
         }
         if ($returnonly) {
             return $this->externalmedia(str_replace('doku.php?id=', 'lib/exe/fetch.php?media=', wl($src, '', true)), $title, null, null, null, null, null, true);
         } else {
             $this->externalmedia(str_replace('doku.php?id=', 'lib/exe/fetch.php?media=', wl($src, '', true)), $title, null, null, null, null, null);
         }
         //End of FIX
     }
 }
Example #9
0
 function internalmedia($src, $title = NULL, $align = NULL, $width = NULL, $height = NULL, $cache = NULL, $linking = NULL)
 {
     global $conf;
     global $ID;
     resolve_mediaid(getNS($ID), $src, $exists);
     $link = array();
     $link['class'] = 'media';
     $link['style'] = '';
     $link['pre'] = '';
     $link['suf'] = '';
     $link['more'] = '';
     $link['target'] = $conf['target']['media'];
     $link['title'] = $this->_xmlEntities($src);
     list($ext, $mime) = mimetype($src);
     if (substr($mime, 0, 5) == 'image') {
         $link['url'] = ml($src, array('id' => $ID, 'cache' => $cache), $linking == 'direct');
     } elseif ($mime == 'application/x-shockwave-flash') {
         // don't link flash movies
         $noLink = TRUE;
     } else {
         // add file icons
         $class = preg_replace('/[^_\\-a-z0-9]+/i', '_', $ext);
         $link['class'] .= ' mediafile mf_' . $class;
         $link['url'] = ml($src, array('id' => $ID, 'cache' => $cache), true);
     }
     $link['name'] = $this->_media($src, $title, $align, $width, $height, $cache);
     //output formatted
     if ($linking == 'nolink' || $noLink) {
         $this->doc .= $link['name'];
     } else {
         $this->doc .= $this->_formatLink($link);
     }
 }
Example #10
0
 /**
  * Deep Fetch and replace of links inside the texts matched by __getInternalLinks
  **/
 function __fetchAndReplaceLink($DATA)
 {
     global $conf, $currentID;
     $noDeepReplace = true;
     $newAdditionalParameters = $this->functions->settings->additionalParameters;
     $newDepth = $this->functions->settings->depth;
     $hadBase = false;
     // Clean data[2], remote ' and "
     $DATA[2] = preg_replace("/^\\s*?['\"]?(.*?)['\"]?\\s*?\$/", '\\1', trim($DATA[2]));
     $this->functions->debug->message("Starting Link Replacement", $DATA, 2);
     // $DATA[2] = urldecode($DATA[2]); // Leads to problems because it does not re-encode the url
     // External and mailto links
     if (preg_match("%^(https?://|mailto:|javascript:|data:)%", $DATA[2])) {
         $this->functions->debug->message("Don't like http, mailto, data or javascript links here", null, 1);
         return $this->__rebuildLink($DATA, "");
     }
     //if ( preg_match("%^(https?://|mailto:|" . DOKU_BASE . "/_export/)%", $DATA[2]) ) { return $this->__rebuildLink($DATA, ""); }
     // External media - this is deep down in the link, so we have to grep it out
     if (preg_match("%media=(https?://.*?\$)%", $DATA[2], $matches)) {
         $DATA[2] = $matches[1];
         $this->functions->debug->message("This is an HTTP like somewhere else", $DATA, 1);
         return $this->__rebuildLink($DATA, "");
     }
     // reference only links won't have to be rewritten
     if (preg_match("%^#.*?\$%", $DATA[2])) {
         $this->functions->debug->message("This is a refercence only", null, 1);
         return $this->__rebuildLink($DATA, "");
     }
     // strip all things out
     // changed Data
     $PARAMS = @parse_url($DATA[2], PHP_URL_QUERY);
     $ANCHOR = @parse_url($DATA[2], PHP_URL_FRAGMENT);
     $DATA[2] = @parse_url($DATA[2], PHP_URL_PATH);
     // 2010-08-25 - fix problem with relative movement in links ( "test/../test2" )
     $tmpData2 = '';
     while ($tmpData2 != $DATA[2]) {
         $tmpData2 = $DATA[2];
         $DATA[2] = preg_replace("#/(?!\\.\\.)[^\\/]*?/\\.\\./#", '/', $DATA[2]);
     }
     $temp = preg_replace("%^" . DOKU_BASE . "%", "", $DATA[2]);
     if ($temp != $DATA[2]) {
         $DATA[2] = $temp;
         $hadBase = true;
         // 2010-08-23 Check if there has been a rewrite here that will have to be considered later on
     }
     $this->functions->debug->message("URL before rewriting option for others than 1", array($DATA, $PARAMS, $hadBase), 1);
     // Handle rewrites other than 1 - just for non-lib-files
     // if ( !preg_match('$^/?lib/$', $DATA[2]) ) {
     if (!preg_match('$^(' . DOKU_BASE . ')?lib/$', $DATA[2])) {
         $this->functions->debug->message("Did not match '\$^(" . DOKU_BASE . ")?lib/\$' userewrite == ", $conf['userewrite'], 2);
         if ($conf['userewrite'] == 2) {
             $DATA[2] = $this->__getInternalRewriteURL($DATA[2]);
         } elseif ($conf['userewrite'] == 0) {
             $this->__getParamsAndDataRewritten($DATA, $PARAMS);
         }
     } else {
         $this->functions->debug->message("This file must be inside lib ...", null, 2);
     }
     $this->functions->debug->message("URL before rewriting option", array($DATA, $PARAMS), 2);
     $ORIGDATA2 = $DATA;
     //        $ORIGDATA2 = $DATA[2]; // 08/10/2010 - this line required a $this->functions->wl which may mess up with the base URL
     $this->functions->debug->message("OrigDATA is:", $ORIGDATA2, 1);
     // Generate ID
     $DATA[2] = str_replace('/', ':', $DATA[2]);
     // If Data was empty this must be the same file!;
     if (empty($DATA[2])) {
         $DATA[2] = $currentID;
     }
     $ID = $DATA[2];
     $MEDIAMATCHER = "#(_media(/|:)|media=|_detail(/|:)|_export(/|:)|do=export_)#i";
     // 2010-10-23 added "(/|:)" for the ID may not contain slashes anymore
     $ID = $this->functions->cleanID($DATA[2], null, preg_match($MEDIAMATCHER, $DATA[2]));
     //        $ID = $this->functions->cleanID($DATA[2], null, strstr($DATA[2], 'media') ); // Export anpassung nun weiter unten
     //        $IDexists = page_exists($ID); // 08/10/2010 - Not needed. This will be done in the next block.
     //        $this->functions->debug->message("Current ID: '$ID' exists: '" . ($IDexists ? 'true' : 'false') . "' (will be set to 'false' anyway)", null, 1);
     $IDifIDnotExists = $ID;
     // 08/10/2010 - Save ID - with possible upper cases to preserve them
     $IDexists = false;
     $this->functions->debug->message("Resolving ID: '{$ID}'", null, 2);
     if (preg_match($MEDIAMATCHER, $DATA[2])) {
         resolve_mediaid(null, $ID, $IDexists);
         $this->functions->debug->message("Current mediaID to filename: '" . mediaFN($ID) . "'", null, 2);
     } else {
         resolve_pageid(null, $ID, $IDexists);
         $this->functions->debug->message("Current ID to filename: '" . wikiFN($ID) . "'", null, 2);
     }
     $this->functions->debug->message("Current ID after resolvement: '{$ID}' the ID does exist: '" . ($IDexists ? 'true' : 'false') . "'", null, 2);
     //        $ORIGDATA2 = @parse_url($this->functions->wl($ORIGDATA2, null, true)); // What was the next 2 line for? It did mess up with links from {{jdoc>}}
     //        $this->functions->debug->message("OrigData ID after parse:", $ORIGDATA2, 1); // 08/10/2010 - The lines are obsolete when the $ORIGDATA2 = $DATA. $ORIGDATA is only for fallback
     // 08/10/2010 - If the ID does not exist, we may have a problem here with upper cases - they will all be lower by now!
     if (!$IDexists) {
         $ID = $IDifIDnotExists;
         // there may have been presevered Upper cases. We will need them!
     }
     // $this->functions->cleanID($DATA[2], null, strstr($DATA[2], 'media') || strstr($DATA[2], 'export') );
     if (substr($ID, -1) == ':' || empty($ID)) {
         $ID .= $conf['start'];
     }
     // Generate Download URL
     // $PARAMS = trim(str_replace('&amp;', '&', $PARAMS));
     $PARAMS = trim($PARAMS);
     $this->functions->removeWikiVariables($PARAMS, false, true);
     $url = $this->functions->wl($ID, null, true, null, null, true, $hadBase) . (!empty($ANCHOR) ? '#' . $ANCHOR : '') . (!empty($PARAMS) ? '?' . $PARAMS : '');
     $this->functions->debug->message("URL from ID: '{$url}'", null, 2);
     // Parse URI PATH and add "html"
     $uri = @parse_url($url);
     $DATA[2] = $uri['path'];
     $DATA['ANCHOR'] = $ANCHOR;
     $DATA['PARAMS'] = $PARAMS;
     $this->functions->debug->message("DATA after parsing.", $DATA, 2);
     // Second Rewrite for UseRewrite = 2
     if ($conf['userewrite'] == 2) {
         $DATA[2] = preg_replace('$/lib/.*?fetch\\.php$', '', $DATA[2]);
         $DATA[2] = preg_replace('%(/lib/.*?detail\\.php.*$)%', '\\1' . '.' . $this->functions->settings->fileType, $DATA[2]);
         if (preg_match('%/(lib/.*?detail|doku)\\.php%', $DATA[2])) {
             $noDeepReplace = false;
             $fileName = $this->functions->getSiteName($ID);
             $newDepth = str_repeat('../', count(explode('/', $fileName)) - 1);
         }
         $this->functions->debug->message("DATA after second rewrite with UseRewrite = 2", array($DATA, $noDeepReplace, $fileName, $newDepth), 1);
     }
     switch (array_pop(explode('/', $DATA[2]))) {
         // CSS Extra Handling with extra rewrites
         case 'css.php':
             // $DATA[2] .=  ( !$this->functions->settings->addParams || empty($PARAMS) ? '' : '.' . $this->functions->cleanID(preg_replace("/(=|\?|&amp;)/", ".", $PARAMS))) . '.css';
             $DATA[2] .= '.' . $this->functions->cleanID(preg_replace("/(=|\\?|&amp;)/", ".", $PARAMS)) . '.css';
             // allways put parameters behind
             // No paramters needed since they are rewritten.
             $DATA['PARAMS'] = "";
             $noDeepReplace = false;
             $fileName = $this->functions->getSiteName($ID);
             $newDepth = str_repeat('../', count(explode('/', $fileName)) - 1);
             $newAdditionalParameters['do'] = 'siteexport';
             $this->functions->debug->message("This is CSS file", array($DATA, $noDeepReplace, $fileName, $newDepth, $newAdditionalParameters), 2);
             break;
         case 'js.php':
             // $DATA[2] .= ( !$this->functions->settings->addParams || empty($PARAMS) ? '' : '.' . $this->functions->cleanID(preg_replace("/(=|\?|&amp;)/", ".", $PARAMS))) . '.js';
             $DATA[2] .= '.t.' . $this->functions->cleanID($_REQUEST['template']) . '.js';
             // allways put parameters behind
             // set Template
             if (!empty($_REQUEST['template'])) {
                 $url .= (strstr($url, '?') ? '&' : '?') . 'template=' . $_REQUEST['template'];
             }
             // No paramters needed since they are rewritten.
             $DATA['PARAMS'] = "";
             $newAdditionalParameters['do'] = 'siteexport';
             $this->functions->debug->message("This is JS file", array($DATA, $url, $fileName, $newAdditionalParameters), 2);
             break;
             // Detail Handling with extra Rewrites if Paramaters are available - otherwise this is just the fetch
         // Detail Handling with extra Rewrites if Paramaters are available - otherwise this is just the fetch
         case 'indexer.php':
             $this->functions->debug->message("Skipping indexer", null, 2);
             return "";
             break;
         case 'detail.php':
             $fileName = $this->functions->getSiteName($ID, true);
             // 2010-09-03 - rewrite with override enabled
         // 2010-09-03 - rewrite with override enabled
         case 'doku.php':
             if ($this->functions->settings->addParams) {
                 $noDeepReplace = false;
                 if (empty($fileName)) {
                     $fileName = $this->functions->getSiteName($ID);
                     // 2010-09-03 - rewrite with override enabled
                 }
                 $newDepth = str_repeat('../', count(explode('/', $fileName)) - 1);
                 $this->__rebuildDataForNormalFiles($DATA, $PARAMS);
                 $this->functions->debug->message("This is doku.php or detail.php file with addParams", array($DATA, $fileName, $newDepth, $newAdditionalParameters), 2);
                 break;
             }
             $url = str_replace('detail.php', 'fetch.php', $url);
             $this->functions->debug->message("This is doku.php or detail.php file '{$url}'", null, 2);
             // Fetch Handling for media - rewriting everything
         // Fetch Handling for media - rewriting everything
         case 'fetch.php':
             $this->__getParamsAndDataRewritten($DATA, $PARAMS, 'media');
             $DATA[2] = str_replace('/', ':', $DATA[2]);
             $ID = $this->functions->cleanID($DATA[2], null, strstr($DATA[2], 'media'));
             $urlM = ml($ID, null, true);
             $uriM = @parse_url($urlM);
             $DATA[2] = $uriM['path'] . (!empty($ANCHOR) ? '#' . $ANCHOR : '') . (!empty($PARAMS) ? '?' . $PARAMS : '');
             $DATA['PARAMS'] = "";
             $newAdditionalParameters = array();
             $this->functions->debug->message("This is fetch.php file", array($DATA, $ID, $PARAMS), 2);
             break;
             // default Handling for Pages
         // default Handling for Pages
         default:
             if (preg_match("%" . DOKU_BASE . "_detail/%", $DATA[2])) {
                 // GET ID Param from origdata2
                 preg_match("#id=(.*?)(&|\")#i", $DATA[0], $backlinkID);
                 $this->__rebuildDataForNormalFiles($DATA, $PARAMS);
                 $fileIDPart = isset($backlinkID[1]) && !empty($backlinkID[1]) ? $this->functions->cleanID(urldecode($backlinkID[1])) : 'detail';
                 $DATA[2] .= '/' . $fileIDPart . '.' . $this->functions->settings->fileType;
                 // add namespace and subpage for back button and add filetype
                 $noDeepReplace = false;
                 $fileName = $this->functions->shortenName($DATA[2]);
                 $newDepth = str_repeat('../', count(explode('/', $fileName)) - 1);
                 $url .= (strstr($url, '?') ? '&' : '?') . 'id=' . $fileIDPart;
                 // add id-part to URL for backlinks
                 $DATA['PARAMS'] = "";
                 $this->functions->debug->message("This is something with '_detail' file", array($DATA, $backlinkID, $newDepth, $url), 2);
             } else {
                 if (preg_match("%" . DOKU_BASE . "_export/(.*?)/%", $DATA[2], $fileType)) {
                     // Fixes multiple codeblocks in one file
                     $this->__rebuildDataForNormalFiles($DATA, $PARAMS);
                     // add the Params no matter what they are. This is export. We don't mess with other files
                     // adding the "/" fixes the usage of multiple codeblocks in the same namespace
                     $DATA[2] .= (empty($PARAMS) ? '' : '/' . $PARAMS) . '.' . $fileType[1];
                     $DATA['PARAMS'] = "";
                     $this->functions->debug->message("This is something with '_export' file", $DATA, 2);
                 } else {
                     if ($IDexists) {
                         // 08/10/2010 - was page_exists($ID) - but this should do as well.
                         // If this is a page ... skip it!
                         $DATA[2] .= (!$this->functions->settings->addParams || empty($PARAMS) ? '' : '.' . $this->functions->cleanID(preg_replace("/(=|\\?|&amp;)/", ".", $PARAMS))) . '.' . $this->functions->settings->fileType;
                         // 2012-06-15 originally has an absolute path ... we might need a relative one if not in our namespace
                         $this->functions->debug->message("OK, this is to be absolute: " . (empty($_REQUEST['absolutePath']) ? 'false' : 'true'), null, 1);
                         if (empty($_REQUEST['absolutePath'])) {
                             $DATA[2] = $this->functions->getRelativeURL($DATA[2], $currentID);
                         }
                         $DATA[2] = $this->functions->shortenName($DATA[2]);
                         // If Parameters are to be included in the filename - they must not be added twice
                         if ($this->functions->settings->addParams) {
                             $DATA['PARAMS'] = "";
                         }
                         $this->functions->debug->message("This page really exists", $DATA, 1);
                         return $this->__rebuildLink($DATA);
                     } else {
                         $this->__rebuildDataForNormalFiles($DATA, $PARAMS);
                     }
                 }
             }
             unset($newAdditionalParameters['diPlu']);
     }
     $this->functions->debug->message("DATA after SWITCH CASE decision", array($DATA, $noDeepReplace, $fileName, $newDepth), 1);
     if ($this->filewriter->canDoPDF()) {
         $this->functions->addAdditionalParametersToURL($url, $newAdditionalParameters);
         $DATA[2] = $url;
         unset($DATA['PARAMS']);
         $url = $this->__rebuildLink($DATA, '');
         $this->functions->debug->message("Creating PDF with URL '{$url}'", null, 2);
         return $url;
     }
     // Create Name to save the file at
     $DATA[2] = str_replace(':', '_', $DATA[2]);
     $DATA[2] = $this->functions->shortenName($DATA[2]);
     // File already loaded?
     // 2010-10-23 - changes in_array from DATA[2] to $url - to check real URLs, the DATA[2] file will be checked with fileExistsInZip
     if (in_array($url, array_keys($this->fileChecked))) {
         $DATA[2] = $this->fileChecked[$url];
         $this->functions->debug->message("File has been checked before.", array($DATA, $url), 2);
         return $this->__rebuildLink($DATA);
     }
     // 2010-09-03 - second check if the file is in the ZIP already.
     if ($this->filewriter->fileExistsInZip($DATA[2])) {
         $this->functions->debug->message("File with DATA exists in ZIP.", $DATA, 3);
         return $this->__rebuildLink($DATA);
     }
     // 2010-10-23 - What if this is a fetch.php? than we produced an error.
     //        $this->fileChecked[] = $DATA[2];
     $this->fileChecked[$url] = $DATA[2];
     // 2010-09-03 - One URL to one FileName
     // get tempFile and save it
     $origDepth = $this->functions->settings->depth;
     $this->functions->settings->depth = $newDepth;
     $tmpID = $currentID;
     $tmpFile === false;
     $this->functions->debug->message("Going to get the file", array($url, $noDeepReplace, $newAdditionalParameters), 2);
     $tmpFile = $this->__getHTTPFile($url, $noDeepReplace, $newAdditionalParameters);
     $this->functions->debug->message("This is the getHTTPFile result", $tmpFile, 2);
     $currentID = $tmpID;
     $this->functions->settings->depth = $origDepth;
     // 2010-09-03 - Reset depth at the very end
     if ($tmpFile === false) {
         // Keep an potentially extra link intact
         $this->functions->debug->message("The fetched file '{$url}' is 'false'", null, 3);
         if ($IDexists === false) {
             $this->functions->debug->message("The file does not exist, fallback to ORIGDATA", $ORIGDATA2, 2);
             $DATA[2] = $this->functions->shortenName($ORIGDATA2[2]);
             // get Origdata Path
         }
         $this->fileChecked[$url] = $DATA[2];
         // 2010-09-03 - One URL to one FileName
         $link = $this->__rebuildLink($DATA);
         $this->functions->debug->message("Final Link after empty file from '{$url}'", null, 2);
         return $link;
     }
     $this->functions->debug->message("The fetched file looks good.", $tmpFile, 1);
     // If a Filename was given that does not comply to the original name, us this one!
     if (!empty($tmpFile[1]) && !strstr($DATA[2], $tmpFile[1])) {
         $dParts = explode('/', $DATA[2]);
         array_pop($dParts);
         $dParts[] = $tmpFile[1];
         $DATA[2] = implode('/', $dParts);
     }
     // Add to zip
     $this->fileChecked[$url] = $DATA[2];
     // 2010-09-03 - One URL to one FileName
     $status = $this->filewriter->__addFileToZip($tmpFile[0], $DATA[2]);
     @unlink($tmpFile[0]);
     $newURL = $this->__rebuildLink($DATA);
     $this->functions->debug->message("Returning final Link to document: '{$newURL}'", null, 2);
     return $newURL;
 }
Example #11
0
 function internalmedia($src, $title = NULL, $align = NULL, $width = NULL, $height = NULL, $cache = NULL, $linking = NULL)
 {
     global $conf;
     global $ID;
     $filename = mediaFN($src);
     resolve_mediaid(getNS($ID), $src, $exists);
     list($ext, $mime) = mimetype($src);
     if (substr($mime, 0, 5) == 'image') {
         $img = $this->mediatops($filename, $title, $align, $width, $height, $cache, $linking);
         $this->put($img);
         return;
     }
     if ($title == NULL) {
         $title = basename($filename);
     }
     array_push($this->dokulinks, array('id' => $filename, 'name' => $title, 'type' => 'file'));
     $this->putcmd('hyperref[');
     $this->put(md5($filename));
     $this->put(']{');
     $this->putent($title);
     $this->put('}');
     //    $this->unformatted('unkown '. $filename . '('. $mime . '=>' . $ext . ')');
 }
Example #12
0
 function internalmedia($src, $title = NULL, $align = NULL, $width = NULL, $height = NULL, $cache = NULL, $linking = NULL)
 {
     global $conf;
     global $ID;
     resolve_mediaid(getNS($ID), $src, $exists);
     list($ext, $mime) = mimetype($src);
     if (substr($mime, 0, 5) == 'image') {
         $file = mediaFN($src);
         $this->_odtAddImage($file, $width, $height, $align, $title);
     } else {
         // FIXME build absolute medialink and call externallink()
         $this->code('FIXME internalmedia: ' . $src);
     }
 }
Example #13
0
 /**
  * Returns HTML code for images used in link titles
  *
  * @author Andreas Gohr <*****@*****.**>
  * @param array $img
  * @return string HTML img tag or similar
  */
 function _imageTitle($img)
 {
     global $ID;
     // some fixes on $img['src']
     // see internalmedia() and externalmedia()
     list($img['src']) = explode('#', $img['src'], 2);
     if ($img['type'] == 'internalmedia') {
         resolve_mediaid(getNS($ID), $img['src'], $exists, $this->date_at, true);
     }
     return $this->_media($img['src'], $img['title'], $img['align'], $img['width'], $img['height'], $img['cache']);
 }
Example #14
0
 public function internalmedia($src, $title = NULL, $align = NULL, $width = NULL, $height = NULL, $cache = NULL, $linking = NULL)
 {
     global $ID;
     resolve_mediaid(getNS($ID), $src, $exists);
     $noLink = false;
     $render = $linking == 'linkonly' ? false : true;
     $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render);
     list($ext, $mime) = mimetype($src);
     if (substr($mime, 0, 5) == 'image' && $render) {
         $link['url'] = ml($src, array('id' => $ID, 'cache' => $cache), $linking == 'direct');
     } elseif ($mime == 'application/x-shockwave-flash') {
         // don't link flash movies
         $noLink = true;
     } else {
         // add file icons
         $class = preg_replace('/[^_\\-a-z0-9]+/i', '_', $ext);
         $link['class'] .= ' mediafile mf_' . $class;
         $link['url'] = ml($src, array('id' => $ID, 'cache' => $cache), true);
     }
     //var_dump($link);
     //output formatted
     if ($linking == 'nolink' || $noLink) {
         $this->doc .= $link['name'];
     } else {
         $this->doc .= $this->_formatLink($link);
     }
 }
Example #15
0
/**
 * Find all the node and edge data for the given namespaces
 */
function gather_data($namespaces, $depth = 0, $incmedia = 'ns')
{
    global $conf;
    $transplugin = plugin_load('helper', 'translation');
    $pages = array();
    $media = array();
    foreach ($namespaces as $ns) {
        // find media
        if ($incmedia == 'ns') {
            $data = array();
            search($data, $conf['mediadir'], 'search_universal', array('depth' => $depth, 'listfiles' => true, 'listdirs' => false, 'pagesonly' => false, 'skipacl' => true, 'keeptxt' => true, 'meta' => true), str_replace(':', '/', $ns));
            // go through all those media files
            while ($item = array_shift($data)) {
                $media[$item['id']] = array('title' => noNS($item['id']), 'size' => $item['size'], 'ns' => getNS($item['id']), 'time' => $item['mtime']);
            }
        }
        // find pages
        $data = array();
        search($data, $conf['datadir'], 'search_universal', array('depth' => $depth, 'listfiles' => true, 'listdirs' => false, 'pagesonly' => true, 'skipacl' => true, 'firsthead' => true, 'meta' => true), str_replace(':', '/', $ns));
        // ns start page
        if ($ns && page_exists($ns)) {
            $data[] = array('id' => $ns, 'ns' => getNS($ns), 'title' => p_get_first_heading($ns, false), 'size' => filesize(wikiFN($ns)), 'mtime' => filemtime(wikiFN($ns)), 'perm' => 16, 'type' => 'f', 'level' => 0, 'open' => 1);
        }
        // go through all those pages
        while ($item = array_shift($data)) {
            $time = (int) p_get_metadata($item['id'], 'date created', false);
            if (!$time) {
                $time = $item['mtime'];
            }
            $lang = $transplugin ? $transplugin->getLangPart($item['id']) : '';
            if ($lang) {
                $item['ns'] = preg_replace('/^' . $lang . '(:|$)/', '', $item['ns']);
            }
            $pages[$item['id']] = array('title' => $item['title'], 'ns' => $item['ns'], 'size' => $item['size'], 'time' => $time, 'links' => array(), 'media' => array(), 'lang' => $lang);
        }
    }
    // now get links and media
    foreach ($pages as $pid => $item) {
        // get instructions
        $ins = p_cached_instructions(wikiFN($pid), false, $pid);
        // find links and media usage
        foreach ($ins as $i) {
            $mid = null;
            if ($i[0] == 'internallink') {
                $id = $i[1][0];
                $exists = true;
                resolve_pageid($item['ns'], $id, $exists);
                list($id) = explode('#', $id, 2);
                if ($id == $pid) {
                    continue;
                }
                // skip self references
                if ($exists && isset($pages[$id])) {
                    $pages[$pid]['links'][] = $id;
                }
                if (is_array($i[1][1]) && $i[1][1]['type'] == 'internalmedia') {
                    $mid = $i[1][1]['src'];
                    // image link
                } else {
                    continue;
                    // we're done here
                }
            }
            if ($i[0] == 'internalmedia') {
                $mid = $i[1][0];
            }
            if (is_null($mid)) {
                continue;
            }
            if ($incmedia == 'none') {
                continue;
            }
            // no media wanted
            $exists = true;
            resolve_mediaid($item['ns'], $mid, $exists);
            list($mid) = explode('#', $mid, 2);
            $mid = cleanID($mid);
            if ($exists) {
                if ($incmedia == 'all') {
                    if (!isset($media[$mid])) {
                        //add node
                        $media[$mid] = array('size' => filesize(mediaFN($mid)), 'time' => filemtime(mediaFN($mid)), 'ns' => getNS($mid), 'title' => noNS($mid));
                    }
                    $pages[$pid]['media'][] = $mid;
                } elseif (isset($media[$mid])) {
                    $pages[$pid]['media'][] = $mid;
                }
            }
        }
        // clean up duplicates
        $pages[$pid]['links'] = array_unique($pages[$pid]['links']);
        $pages[$pid]['media'] = array_unique($pages[$pid]['media']);
    }
    return array('pages' => $pages, 'media' => $media);
}
Example #16
0
 function _convert_media(&$renderer, &$instr, $id)
 {
     global $ID;
     // Resolvemedia returns the absolute path to media by reference
     $exists = false;
     resolve_mediaid(getNS($id), $instr[1][0], $exists);
 }
 /**
  * Replaces titles of non-labeled internal media links with their original filenames
  */
 function _replaceLinkTitle(&$event)
 {
     global $ID;
     global $conf;
     require_once DOKU_INC . 'inc/JpegMeta.php';
     $ns = getNS($ID);
     // get the instructions list from the handler
     $calls =& $event->data->calls;
     // array index numbers for readability
     list($handler_name, $instructions, $source, $title, $linking) = array(0, 1, 0, 1, 6);
     // scan media link and mark it with its original filename
     $last = count($calls) - 1;
     for ($i = 0; $i <= $last; $i++) {
         // NOTE: 'externalmedia' is processed here because there is a
         //       basename() bug in fetching its auto-filled linktext.
         //       For more details please see common->_correctBasename().
         if (!preg_match('/^(?:in|ex)ternalmedia$/', $calls[$i][$handler_name])) {
             continue;
         }
         $inst =& $calls[$i][$instructions];
         $filename = false;
         $linktext = $inst[$title];
         $linkonly = $inst[$linking] === 'linkonly';
         list($src, $hash) = explode('#', $inst[$source], 2);
         // get original filename
         if ($calls[$i][$handler_name] === 'internalmedia') {
             resolve_mediaid($ns, $src, $exists);
             list($ext, $mime, $dl) = mimetype($src);
             $filename = $this->_getOriginalFileName($src);
         } else {
             list($ext, $mime, $dl) = mimetype($src);
         }
         // prefetch auto-filled linktext
         if (!$linktext) {
             if (substr($mime, 0, 5) === 'image' && ($ext === 'jpg' || $ext === 'jpeg') && ($jpeg = new JpegMeta(mediaFN($src))) && ($caption = $jpeg->getTitle())) {
                 $linktext = $caption;
             } else {
                 $linktext = $this->common->_correctBasename(noNS($src));
             }
         }
         // add a marker (normally you cannot put '}}' in a media link title
         // and cannot put ':' in a filename)
         if ($filename === false) {
             $inst[$title] = $linktext;
         } elseif ($inst[$title] !== $linktext) {
             $inst[$title] = $linktext . '}}preservefilenames:autofilled:' . $filename;
         } else {
             $inst[$title] = $linktext . '}}preservefilenames::' . $filename;
         }
     }
 }
Example #18
0
 /**
  * Helper function for getting all media references from an instruction array
  *
  * @param array $instructions The instructions to scan
  * @param array $media_references The array of media references
  * @param string $id The reference id for resolving media ids
  */
 private function get_media_references_from_instructions($instructions, &$media_references, $id) {
     foreach ($instructions as $ins) {
         if ($ins[0] === 'internalmedia') {
             $src = $ins[1][0];
             list($src,$hash) = explode('#',$src,2);
             resolve_mediaid(getNS($id),$src, $exists);
             $media_references[] = $src;
         } elseif (in_array($ins[0], array('interwikilink', 'windowssharelink', 'externallink', 'emaillink', 'locallink', 'internallink'))) {
             $img = $ins[1][1];
             if (is_array($img) && $img['type'] === 'internalmedia') {
                 list($src,$hash) = explode('#',$img['src'],2);
                 resolve_mediaid(getNS($id), $src, $exists);
                 $media_references[] = $src;
             }
         } elseif ($ins[0] === 'nest') {
             // nested instructions
             $this->get_media_references_from_instructions($ins[1][0], $media_references, $id);
         } elseif ($ins[0] === 'plugin' && $ins[1][0] === 'variants_variants') {
             // the variants plugin has two branches with nested instructions, both need to be rewritten
             $this->get_media_references_from_instructions($ins[1][1][1], $media_references, $id);
             $this->get_media_references_from_instructions($ins[1][1][2], $media_references, $id);
         }
     }
 }
Example #19
0
/**
 * Returns the pages that use a given media file
 *
 * Does a quick lookup with the fulltext index, then
 * evaluates the instructions of the found pages
 *
 * Aborts after $max found results
 */
function ft_mediause($id, $max)
{
    if (!$max) {
        $max = 1;
    }
    // need to find at least one
    $result = array();
    // quick lookup of the mediafile
    // FIXME use metadata key lookup
    $media = noNS($id);
    $matches = idx_lookup(idx_tokenizer($media));
    $docs = array_keys(ft_resultCombine(array_values($matches)));
    if (!count($docs)) {
        return $result;
    }
    // go through all found pages
    $found = 0;
    $pcre = preg_quote($media, '/');
    foreach ($docs as $doc) {
        $ns = getNS($doc);
        preg_match_all('/\\{\\{([^|}]*' . $pcre . '[^|}]*)(|[^}]+)?\\}\\}/i', rawWiki($doc), $matches);
        foreach ($matches[1] as $img) {
            $img = trim($img);
            if (preg_match('/^https?:\\/\\//i', $img)) {
                continue;
            }
            // skip external images
            list($img) = explode('?', $img);
            // remove any parameters
            resolve_mediaid($ns, $img, $exists);
            // resolve the possibly relative img
            if ($img == $id) {
                // we have a match
                $result[] = $doc;
                $found++;
                break;
            }
        }
        if ($found >= $max) {
            break;
        }
    }
    sort($result);
    return $result;
}
 function _recordMediaUsage($src)
 {
     global $ID;
     list($src, $hash) = explode('#', $src, 2);
     if (media_isexternal($src)) {
         return;
     }
     resolve_mediaid(getNS($ID), $src, $exists);
     $this->meta['relation']['media'][$src] = $exists;
 }