/** * Executed after performing the action hooks * * Increases counter and purge cache */ public function after_action() { if ($this->autoinc) { global $ID; p_set_metadata($ID, array('bureaucracy' => array($this->get_key() => $this->opt['value'] + 1))); // Force rerendering by removing the instructions cache file $cache_fn = getCacheName(wikiFN($ID) . $_SERVER['HTTP_HOST'] . $_SERVER['SERVER_PORT'], '.' . 'i'); if (file_exists($cache_fn)) { unlink($cache_fn); } } }
/** * Constructor * * Loads the cache */ public function __construct() { global $conf; $this->logfile = fullpath($conf['metadir'] . '/' . $this->getConf('accesslog')); // file not found? assume absolute path if (!file_exists($this->logfile)) { $this->logfile = $this->getConf('accesslog'); } // load the cache file $this->logcache = getCacheName($this->getConf('accesslog'), '.statdisplay'); if (file_exists($this->logcache)) { $this->logdata = unserialize(io_readFile($this->logcache, false)); } }
/** * Check for pages changes and eventually purge cache. * * @author Samuele Tognini <*****@*****.**> * * @param Doku_Event $event * @param mixed $param not defined */ function _purgecache(&$event, $param) { global $ID; global $conf; /** @var cache_parser $cache */ $cache =& $event->data; if (!isset($cache->page)) { return; } //purge only xhtml cache if ($cache->mode != "xhtml") { return; } //Check if it is an pagequery page if (!p_get_metadata($ID, 'pagequery')) { return; } $aclcache = $this->getConf('aclcache'); if ($conf['useacl']) { $newkey = false; if ($aclcache == 'user') { //Cache per user if ($_SERVER['REMOTE_USER']) { $newkey = $_SERVER['REMOTE_USER']; } } else { if ($aclcache == 'groups') { //Cache per groups global $INFO; if ($INFO['userinfo']['grps']) { $newkey = implode('#', $INFO['userinfo']['grps']); } } } if ($newkey) { $cache->key .= "#" . $newkey; $cache->cache = getCacheName($cache->key, $cache->ext); } } //Check if a page is more recent than purgefile. if (@filemtime($cache->cache) < @filemtime($conf['cachedir'] . '/purgefile')) { $event->preventDefault(); $event->stopPropagation(); $event->result = false; } }
/** * For pages containing an aggregation, add the last modified date of the database itself * to the cache dependencies * * @param Doku_Event $event event object by reference * @param mixed $param [the parameters passed as fifth argument to register_hook() when this * handler was registered] * @return bool */ public function handle_cache_aggregation(Doku_Event $event, $param) { global $INPUT; /** @var \cache_parser $cache */ $cache = $event->data; if ($cache->mode != 'xhtml') { return true; } if (!$cache->page) { return true; } // not a page cache $meta = p_get_metadata($cache->page, 'plugin struct'); if (isset($meta['hasaggregation'])) { /** @var helper_plugin_struct_db $db */ $db = plugin_load('helper', 'struct_db'); // cache depends on last database save $cache->depends['files'][] = $db->getDB()->getAdapter()->getDbFile(); // dynamic renders should never overwrite the default page cache // we need this in additon to handle_cache_dynamic() below because we can only // influence if a cache is used, not that it will be written if ($INPUT->has(SearchConfigParameters::$PARAM_FILTER) || $INPUT->has(SearchConfigParameters::$PARAM_OFFSET) || $INPUT->has(SearchConfigParameters::$PARAM_SORT)) { $cache->key .= 'dynamic'; } // cache depends on today's date if ($meta['hasaggregation'] & SearchConfig::$CACHE_DATE) { $oldage = $cache->depends['age']; $newage = time() - mktime(0, 0, 1); // time since first second today $cache->depends['age'] = min($oldage, $newage); } // cache depends on current user if ($meta['hasaggregation'] & SearchConfig::$CACHE_USER) { $cache->key .= ';' . $INPUT->server->str('REMOTE_USER'); } // rebuild cachename $cache->cache = getCacheName($cache->key, $cache->ext); } return true; }
/** * Check for new messages from upstream * * @author Andreas Gohr <*****@*****.**> */ function checkUpdateMessages() { global $conf; global $INFO; global $updateVersion; if (!$conf['updatecheck']) { return; } if ($conf['useacl'] && !$INFO['ismanager']) { return; } $cf = getCacheName($updateVersion, '.updmsg'); $lm = @filemtime($cf); // check if new messages needs to be fetched if ($lm < time() - 60 * 60 * 24 || $lm < @filemtime(DOKU_INC . DOKU_SCRIPT)) { @touch($cf); dbglog("checkUpdateMessages(): downloading messages to " . $cf); $http = new DokuHTTPClient(); $http->timeout = 12; $resp = $http->get(DOKU_MESSAGEURL . $updateVersion); if (is_string($resp) && ($resp == "" || substr(trim($resp), -1) == '%')) { // basic sanity check that this is either an empty string response (ie "no messages") // or it looks like one of our messages, not WiFi login or other interposed response io_saveFile($cf, $resp); } else { dbglog("checkUpdateMessages(): unexpected HTTP response received"); } } else { dbglog("checkUpdateMessages(): messages up to date"); } $data = io_readFile($cf); // show messages through the usual message mechanism $msgs = explode("\n%\n", $data); foreach ($msgs as $msg) { if ($msg) { msg($msg, 2); } } }
/** * Gets a local scalable copy of the SVG with its dimensions * * @param $id * @param int $cachetime * @return bool|array either array($file, $width, $height) or false if no cache available */ public function getAdjustedSVG($id, $cachetime = -1) { $info = $this->getInfo(); $cachefile = getCacheName($id . $info['date'], '.svg'); $cachedate = @filemtime($cachefile); if ($cachedate && $cachetime < time() - $cachedate) { list($width, $height) = $this->readSVGsize($cachefile); return array($cachefile, $width, $height); } // still here, create a new cache file if (preg_match('/^https?:\\/\\//i', $id)) { io_download($id, $cachefile); #FIXME make max size configurable } else { @copy(mediaFN($id), $cachefile); } clearstatcache(false, $cachefile); // adjust the size in the cache file if (file_exists($cachefile)) { list($width, $height) = $this->readSVGsize($cachefile, true); return array($cachefile, $width, $height); } return false; }
/** * Output all needed JavaScript * * @author Andreas Gohr <*****@*****.**> */ function js_out() { global $conf; global $lang; global $config_cascade; // The generated script depends on some dynamic options $cache = getCacheName('scripts' . $_SERVER['HTTP_HOST'] . $_SERVER['SERVER_PORT'], '.js'); // array of core files $files = array(DOKU_INC . 'lib/scripts/helpers.js', DOKU_INC . 'lib/scripts/events.js', DOKU_INC . 'lib/scripts/delay.js', DOKU_INC . 'lib/scripts/cookie.js', DOKU_INC . 'lib/scripts/script.js', DOKU_INC . 'lib/scripts/tw-sack.js', DOKU_INC . 'lib/scripts/ajax.js', DOKU_INC . 'lib/scripts/index.js', DOKU_INC . 'lib/scripts/drag.js', DOKU_INC . 'lib/scripts/textselection.js', DOKU_INC . 'lib/scripts/toolbar.js', DOKU_INC . 'lib/scripts/edit.js', DOKU_INC . 'lib/scripts/linkwiz.js', DOKU_INC . 'lib/scripts/media.js', DOKU_INC . 'lib/scripts/subscriptions.js', DOKU_TPLINC . 'script.js'); // add possible plugin scripts and userscript $files = array_merge($files, js_pluginscripts()); if (isset($config_cascade['userscript']['default'])) { $files[] = $config_cascade['userscript']['default']; } // check cache age & handle conditional request header('Cache-Control: public, max-age=3600'); header('Pragma: public'); if (js_cacheok($cache, $files)) { http_conditionalRequest(filemtime($cache)); if ($conf['allowdebug']) { header("X-CacheUsed: {$cache}"); } // finally send output if ($conf['gzip_output'] && http_gzip_valid($cache)) { header('Vary: Accept-Encoding'); header('Content-Encoding: gzip'); readfile($cache . ".gz"); } else { if (!http_sendfile($cache)) { readfile($cache); } } return; } else { http_conditionalRequest(time()); } // start output buffering and build the script ob_start(); // add some global variables print "var DOKU_BASE = '" . DOKU_BASE . "';"; print "var DOKU_TPL = '" . DOKU_TPL . "';"; print "var DOKU_UHN = " . (int) useHeading('navigation') . ";"; print "var DOKU_UHC = " . (int) useHeading('content') . ";"; // load JS specific translations $json = new JSON(); $lang['js']['plugins'] = js_pluginstrings(); echo 'LANG = ' . $json->encode($lang['js']) . ";\n"; // load toolbar toolbar_JSdefines('toolbar'); // load files foreach ($files as $file) { echo "\n\n/* XXXXXXXXXX begin of " . str_replace(DOKU_INC, '', $file) . " XXXXXXXXXX */\n\n"; js_load($file); echo "\n\n/* XXXXXXXXXX end of " . str_replace(DOKU_INC, '', $file) . " XXXXXXXXXX */\n\n"; } // init stuff js_runonstart("addEvent(document,'click',closePopups)"); js_runonstart('addTocToggle()'); js_runonstart("initSizeCtl('size__ctl','wiki__text')"); js_runonstart("initToolbar('tool__bar','wiki__text',toolbar)"); if ($conf['locktime'] != 0) { js_runonstart("locktimer.init(" . ($conf['locktime'] - 60) . ",'" . js_escape($lang['willexpire']) . "'," . $conf['usedraft'] . ")"); } js_runonstart('scrollToMarker()'); js_runonstart('focusMarker()'); // init hotkeys - must have been done after init of toolbar # disabled for FS#1958 js_runonstart('initializeHotkeys()'); // end output buffering and get contents $js = ob_get_contents(); ob_end_clean(); // compress whitespace and comments if ($conf['compress']) { $js = js_compress($js); } $js .= "\n"; // https://bugzilla.mozilla.org/show_bug.cgi?id=316033 // save cache file io_saveFile($cache, $js); if (function_exists('gzopen')) { io_saveFile("{$cache}.gz", $js); } // finally send output if ($conf['gzip_output']) { header('Vary: Accept-Encoding'); header('Content-Encoding: gzip'); print gzencode($js, 9, FORCE_GZIP); } else { print $js; } }
/** * Delete a draft * * @author Andreas Gohr <*****@*****.**> */ function ajax_draftdel() { $id = cleanID($_REQUEST['id']); if (empty($id)) { return; } $client = $_SERVER['REMOTE_USER']; if (!$client) { $client = clientIP(true); } $cname = getCacheName($client . $id, '.draft'); @unlink($cname); }
/** * Wrapper for GeSHi Code Highlighter, provides caching of its output * * @author Christopher Smith <*****@*****.**> */ function p_xhtml_cached_geshi($code, $language) { $cache = getCacheName($language . $code, ".code"); if (@file_exists($cache) && !$_REQUEST['purge'] && filemtime($cache) > filemtime(DOKU_INC . 'inc/geshi.php')) { $highlighted_code = io_readFile($cache, false); @touch($cache); } else { require_once DOKU_INC . 'inc/geshi.php'; $geshi = new GeSHi($code, strtolower($language), DOKU_INC . 'inc/geshi'); $geshi->set_encoding('utf-8'); $geshi->enable_classes(); $geshi->set_header_type(GESHI_HEADER_PRE); $geshi->set_overall_class("code {$language}"); $geshi->set_link_target($conf['target']['extern']); $highlighted_code = $geshi->parse_code(); io_saveFile($cache, $highlighted_code); } return $highlighted_code; }
/** * Return info about the current document as associative * array. * * @author Andreas Gohr <*****@*****.**> */ function pageinfo() { global $ID; global $REV; global $USERINFO; global $conf; // include ID & REV not redundant, as some parts of DokuWiki may temporarily change $ID, e.g. p_wiki_xhtml // FIXME ... perhaps it would be better to ensure the temporary changes weren't necessary $info['id'] = $ID; $info['rev'] = $REV; if ($_SERVER['REMOTE_USER']) { $info['userinfo'] = $USERINFO; $info['perm'] = auth_quickaclcheck($ID); $info['subscribed'] = is_subscribed($ID, $_SERVER['REMOTE_USER']); $info['client'] = $_SERVER['REMOTE_USER']; // if some outside auth were used only REMOTE_USER is set if (!$info['userinfo']['name']) { $info['userinfo']['name'] = $_SERVER['REMOTE_USER']; } } else { $info['perm'] = auth_aclcheck($ID, '', null); $info['subscribed'] = false; $info['client'] = clientIP(true); } $info['namespace'] = getNS($ID); $info['locked'] = checklock($ID); $info['filepath'] = realpath(wikiFN($ID)); $info['exists'] = @file_exists($info['filepath']); if ($REV) { //check if current revision was meant if ($info['exists'] && @filemtime($info['filepath']) == $REV) { $REV = ''; } else { //really use old revision $info['filepath'] = realpath(wikiFN($ID, $REV)); $info['exists'] = @file_exists($info['filepath']); } } $info['rev'] = $REV; if ($info['exists']) { $info['writable'] = is_writable($info['filepath']) && $info['perm'] >= AUTH_EDIT; } else { $info['writable'] = $info['perm'] >= AUTH_CREATE; } $info['editable'] = $info['writable'] && empty($info['lock']); $info['lastmod'] = @filemtime($info['filepath']); //load page meta data $info['meta'] = p_get_metadata($ID); //who's the editor if ($REV) { $revinfo = getRevisionInfo($ID, $REV, 1024); } else { $revinfo = isset($info['meta']['last_change']) ? $info['meta']['last_change'] : getRevisionInfo($ID, $info['lastmod'], 1024); } $info['ip'] = $revinfo['ip']; $info['user'] = $revinfo['user']; $info['sum'] = $revinfo['sum']; // See also $INFO['meta']['last_change'] which is the most recent log line for page $ID. // Use $INFO['meta']['last_change']['type']==='e' in place of $info['minor']. if ($revinfo['user']) { $info['editor'] = $revinfo['user']; } else { $info['editor'] = $revinfo['ip']; } // draft $draft = getCacheName($info['client'] . $ID, '.draft'); if (@file_exists($draft)) { if (@filemtime($draft) < @filemtime(wikiFN($ID))) { // remove stale draft @unlink($draft); } else { $info['draft'] = $draft; } } return $info; }
/** * Return info about the current document as associative * array. * * @author Andreas Gohr <*****@*****.**> * * @return array with info about current document */ function pageinfo() { global $ID; global $REV; global $RANGE; global $lang; /* @var Input $INPUT */ global $INPUT; $info = basicinfo($ID); // include ID & REV not redundant, as some parts of DokuWiki may temporarily change $ID, e.g. p_wiki_xhtml // FIXME ... perhaps it would be better to ensure the temporary changes weren't necessary $info['id'] = $ID; $info['rev'] = $REV; if ($INPUT->server->has('REMOTE_USER')) { $sub = new Subscription(); $info['subscribed'] = $sub->user_subscription(); } else { $info['subscribed'] = false; } $info['locked'] = checklock($ID); $info['filepath'] = fullpath(wikiFN($ID)); $info['exists'] = file_exists($info['filepath']); $info['currentrev'] = @filemtime($info['filepath']); if ($REV) { //check if current revision was meant if ($info['exists'] && $info['currentrev'] == $REV) { $REV = ''; } elseif ($RANGE) { //section editing does not work with old revisions! $REV = ''; $RANGE = ''; msg($lang['nosecedit'], 0); } else { //really use old revision $info['filepath'] = fullpath(wikiFN($ID, $REV)); $info['exists'] = file_exists($info['filepath']); } } $info['rev'] = $REV; if ($info['exists']) { $info['writable'] = is_writable($info['filepath']) && $info['perm'] >= AUTH_EDIT; } else { $info['writable'] = $info['perm'] >= AUTH_CREATE; } $info['editable'] = $info['writable'] && empty($info['locked']); $info['lastmod'] = @filemtime($info['filepath']); //load page meta data $info['meta'] = p_get_metadata($ID); //who's the editor $pagelog = new PageChangeLog($ID, 1024); if ($REV) { $revinfo = $pagelog->getRevisionInfo($REV); } else { if (!empty($info['meta']['last_change']) && is_array($info['meta']['last_change'])) { $revinfo = $info['meta']['last_change']; } else { $revinfo = $pagelog->getRevisionInfo($info['lastmod']); // cache most recent changelog line in metadata if missing and still valid if ($revinfo !== false) { $info['meta']['last_change'] = $revinfo; p_set_metadata($ID, array('last_change' => $revinfo)); } } } //and check for an external edit if ($revinfo !== false && $revinfo['date'] != $info['lastmod']) { // cached changelog line no longer valid $revinfo = false; $info['meta']['last_change'] = $revinfo; p_set_metadata($ID, array('last_change' => $revinfo)); } $info['ip'] = $revinfo['ip']; $info['user'] = $revinfo['user']; $info['sum'] = $revinfo['sum']; // See also $INFO['meta']['last_change'] which is the most recent log line for page $ID. // Use $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT in place of $info['minor']. if ($revinfo['user']) { $info['editor'] = $revinfo['user']; } else { $info['editor'] = $revinfo['ip']; } // draft $draft = getCacheName($info['client'] . $ID, '.draft'); if (file_exists($draft)) { if (@filemtime($draft) < @filemtime(wikiFN($ID))) { // remove stale draft @unlink($draft); } else { $info['draft'] = $draft; } } return $info; }
/** * @param string $key primary identifier * @param string $ext file extension */ public function __construct($key, $ext) { $this->key = $key; $this->ext = $ext; $this->cache = getCacheName($key, $ext); }
function registerOnLoad($js) { global $ID; global $lang; $preview_button = $lang['btn_preview']; $fckg_conf_direction = $this->getConf('direction'); if ($fckg_conf_direction == "dokuwiki") { $fckg_lang_direction = $lang['direction']; } else { $fckg_lang_direction = $fckg_conf_direction; } $media_tmp_ns = preg_match('/:/', $ID) ? preg_replace('/:\\w+$/', "", $ID, 1) : ""; $locktimer_msg = "Your lock for editing this page is about to expire in a minute.\\n" . "You can reset the timer by clicking the Back-up button."; $meta_fn = metaFN($ID, '.fckg'); $meta_id = 'meta/' . str_replace(':', '/', $ID) . '.fckg'; global $INFO; global $conf; global $USERINFO; $_OS = strtolower(PHP_OS); $cname = getCacheName($INFO['client'] . $ID, '.draft'); $open_upload = $this->getConf('open_upload'); $editor_backup = $this->getConf('editor_bak'); $create_folder = $this->getConf('create_folder'); if (!isset($INFO['userinfo']) && !$open_upload) { $user_type = 'visitor'; } else { $user_type = 'user'; } // if no ACL is used always return upload rights if ($conf['useacl']) { $client = $_SERVER['REMOTE_USER']; } else { $client = ""; } $fnencode = isset($conf['fnencode']) ? $conf['fnencode'] : 'url'; $user_groups = $USERINFO['grps']; if (!$user_groups) { $user_groups = array(); } if (@in_array("guest", $user_groups)) { $create_folder = 'n'; $user_type = 'visitor'; } $user_groups = implode(";;", $user_groups); if ($INFO['isadmin'] || $INFO['ismanager']) { $client = ""; } $user_name = $USERINFO['name']; $user_email = $USERINFO['mail']; $ver_anteater = mktime(0, 0, 0, 11, 7, 2010); $dwiki_version = mktime(0, 0, 0, 01, 01, 2008); if (isset($conf['fnencode'])) { $ver_anteater = mktime(0, 0, 0, 11, 7, 2010); $dwiki_version = mktime(0, 0, 0, 11, 7, 2010); } else { if (function_exists('getVersionData')) { $verdata = getVersionData(); if (isset($verdata) && preg_match('/(\\d+)-(\\d+)-(\\d+)/', $verdata['date'], $ver_date)) { if ($ver_date[1] >= 2005 && ($ver_date[3] > 0 && $ver_date[3] < 31) && ($ver_date[2] > 0 && $ver_date[2] <= 12)) { // month day year $dwiki_version = @mktime(0, 0, 0, $ver_date[2], $ver_date[3], $ver_date[1]); if (!$dwiki_version) { $dwiki_version = mktime(0, 0, 0, 01, 01, 2008); } $ver_anteater = mktime(0, 0, 0, 11, 7, 2010); } } } } $default_fb = $this->getConf('default_fb'); if ($default_fb == 'none') { $client = ""; } $doku_base = DOKU_BASE; return <<<end_of_string <script type='text/javascript'> //<![CDATA[ if(window.dw_locktimer) { var locktimer = dw_locktimer; } var FCKRecovery = ""; var oldonload = window.onload; var ourLockTimerINI = false; var oldBeforeunload; var fckg_onload = function() { {$js} }; jQuery(window).bind('load',{},fckg_onload); function fckgEditorTextChanged() { window.textChanged = false; oldBeforeunload(); if(window.dwfckTextChanged) { return LANG.notsavedyet; } } function getCurrentWikiNS() { var DWikiMediaManagerCommand_ns = '{$media_tmp_ns}'; return DWikiMediaManagerCommand_ns; } var ourLockTimerRefreshID; var ourLockTimerIsSet = true; var ourLockTimerWarningtimerID; var ourFCKEditorNode = null; var ourLockTimerIntervalID; var dwfckTextChanged = false; /** * event handler * handles both mousepresses and keystrokes from FCKeditor window * assigned in fckeditor.html */ function handlekeypress (e) { //alert(e); if(ourLockTimerIsSet) { lockTimerRefresh(); } window.dwfckTextChanged = true; } function unsetDokuWikiLockTimer() { if(window.locktimer && !ourLockTimerINI) { locktimer.old_reset = locktimer.reset; locktimer.old_warning = locktimer.warning; ourLockTimerINI=true; } else { window.setTimeout("unsetDokuWikiLockTimer()", 600); } locktimer.reset = function(){ locktimer.clear(); // alert(locktimer.timeout); window.clearTimeout(ourLockTimerWarningtimerID); ourLockTimerWarningtimerID = window.setTimeout(function () { locktimer.warning(); }, locktimer.timeout); }; locktimer.warning = function(){ window.clearTimeout(ourLockTimerWarningtimerID); if(ourLockTimerIsSet) { if(locktimer.msg.match(/{$preview_button}/i)) { locktimer.msg = locktimer.msg.replace(/{$preview_button}/i, "Back-up"); } alert(locktimer.msg); } else { alert("{$locktimer_msg}"); } }; locktimer.ourLockTimerReset = locktimer.reset; locktimer.our_lasttime = new Date(); lockTimerRefresh(); } function lockTimerRefresh(bak) { var now = new Date(); if(!ourLockTimerINI) unsetDokuWikiLockTimer(); if((now.getTime() - locktimer.our_lasttime.getTime() > 45*1000) || bak){ var dwform = GetE('dw__editform'); window.clearTimeout(ourLockTimerWarningtimerID); var params = 'call=lock&id='+locktimer.pageid; if(ourFCKEditorNode) { dwform.elements.wikitext.value = ourFCKEditorNode.innerHTML; params += '&prefix='+encodeURIComponent(dwform.elements.prefix.value); params += '&wikitext='+encodeURIComponent(dwform.elements.wikitext.value); params += '&suffix='+encodeURIComponent(dwform.elements.suffix.value); params += '&date='+encodeURIComponent(dwform.elements.date.value); } locktimer.our_lasttime = now; jQuery.post( DOKU_BASE + 'lib/exe/ajax.php', params, function (data) { data = data.replace(/auto/,"") + ' by fckgLite'; locktimer.response = data; locktimer.refreshed(data); }, 'html' ); } } /** Legacy function has no current use */ function getRecoveredText() { return FCKRecovery; } function resetDokuWikiLockTimer(delete_checkbox) { var dom_checkbox = document.getElementById('fckg_timer'); var dom_label = document.getElementById('fckg_timer_label'); locktimer.clear(); if(ourLockTimerIsSet) { ourLockTimerIsSet = false; locktimer.reset = locktimer.old_reset; locktimer.refresh(); return; } if(delete_checkbox) { dom_checkbox.style.display = 'none'; dom_label.style.display = 'none'; } ourLockTimerIsSet = true; locktimer.reset = locktimer.ourLockTimerReset; lockTimerRefresh(); } function renewLock(bak) { if(ourLockTimerIsSet) { lockTimerRefresh(true); } else { locktimer.refresh(); } locktimer.reset(); if(bak) { var id = "{$ID}"; parse_wikitext('bakup'); var dwform = GetE('dw__editform'); if(dwform.elements.fck_wikitext.value == '__false__' ) return; GetE('saved_wiki_html').innerHTML = ourFCKEditorNode.innerHTML; if(({$editor_backup}) == 0 ) { return; } var params = "rsave_id={$meta_fn}"; params += '&wikitext='+encodeURIComponent(dwform.elements.fck_wikitext.value); jQuery.post( DOKU_BASE + 'lib/plugins/fckg/scripts/refresh_save.php', params, function (data) { if(data == 'done') { show_backup_msg("{$meta_id}"); } else { alert("error saving: " + id); } }, 'html' ); } } function revert_to_prev() { if(!(GetE('saved_wiki_html').innerHTML.length)) { if(!confirm(backup_empty)) { return; } } ourFCKEditorNode.innerHTML = GetE('saved_wiki_html').innerHTML; } function draft_delete() { var debug = false; var params = "draft_id={$cname}"; jQuery.ajax({ url: DOKU_BASE + 'lib/plugins/fckg/scripts/draft_delete.php', async: false, data: params, type: 'POST', dataType: 'html', success: function(data){ if(debug) { alert(data); } } }); } function disableDokuWikiLockTimer() { resetDokuWikiLockTimer(false); if(ourLockTimerIntervalID) { window.clearInterval(ourLockTimerIntervalID); } if(ourLockTimerIsSet) { ourLockTimerIntervalID = window.setInterval(function () { locktimer.refresh(); }, 30000); } } function dwfckKeypressInstallHandler() { if(window.addEventListener){ oDokuWiki_FCKEditorInstance.EditorDocument.addEventListener('keyup', handlekeypress , false) ; } else { oDokuWiki_FCKEditorInstance.EditorDocument.attachEvent('onkeyup', handlekeypress ) ; } } var DWFCK_EditorWinObj; function FCKEditorWindowObj(w) { DWFCK_EditorWinObj = w; } function fckg_isRTL() { var direction = "{$fckg_lang_direction}"; return direction == 'rtl'; } var oDokuWiki_FCKEditorInstance; function FCKeditor_OnComplete( editorInstance ) { oDokuWiki_FCKEditorInstance = editorInstance; var f = document.getElementById('wiki__text'); oDokuWiki_FCKEditorInstance.VKI_attach = function() { VKI_attach(f, oDokuWiki_FCKEditorInstance.get_FCK(), 'French'); } oDokuWiki_FCKEditorInstance.get_FCK().fckLImmutables = fckLImmutables; oDokuWiki_FCKEditorInstance.dwiki_user = "******"; oDokuWiki_FCKEditorInstance.dwiki_client = "{$client}"; oDokuWiki_FCKEditorInstance.dwiki_usergroups = "{$user_groups}"; oDokuWiki_FCKEditorInstance.dwiki_doku_base = "{$doku_base}"; oDokuWiki_FCKEditorInstance.dwiki_create_folder = "{$create_folder}"; oDokuWiki_FCKEditorInstance.dwiki_fnencode = "{$fnencode}"; oDokuWiki_FCKEditorInstance.dwiki_version = {$dwiki_version}; oDokuWiki_FCKEditorInstance.dwiki_anteater = {$ver_anteater}; document.getElementById('wiki__text___Frame').style.height = "450px"; document.getElementById('size__ctl').innerHTML = document.getElementById('fck_size__ctl').innerHTML; if(window.addEventListener){ editorInstance.EditorDocument.addEventListener('keydown', CTRL_Key_Formats, false) ; if(document.documentMode && document.documentMode == 9) { editorInstance.EditorDocument.addEventListener('click', fckgMousePos, false) ; } } else { editorInstance.EditorDocument.attachEvent('onkeydown', CTRL_Key_Formats) ; } dwfckKeypressInstallHandler(); var index = navigator.userAgent.indexOf('Safari'); if(index == -1 || (navigator.userAgent.indexOf('Chrome'))) { oldBeforeunload = window.onbeforeunload; window.onbeforeunload = fckgEditorTextChanged; } var FCK = oDokuWiki_FCKEditorInstance.get_FCK(); if(FCK.EditorDocument && FCK.EditorDocument.body && !ourFCKEditorNode) { ourFCKEditorNode = FCK.EditorDocument.body; } var FCKConfig = editorInstance.get_FCKConfig(); FCKConfig.fckgUserName = "******"; FCKConfig.fckgUserMail="{$user_email}"; // alert(FCKConfig.name); } function fckgMousePos(e) { if(!e) e=event; if(document.documentMode && document.documentMode == 9) { oDokuWiki_FCKEditorInstance.get_FCK().mouse_x = e.clientX; oDokuWiki_FCKEditorInstance.get_FCK().mouse_y = e.clientY; oDokuWiki_FCKEditorInstance.get_FCK().screen_x = e.screenX; oDokuWiki_FCKEditorInstance.get_FCK().screen_y = e.screenY; oDokuWiki_FCKEditorInstance.get_FCK().target = e.target; } } function CTRL_Key_Formats(parm) { if(!parm.ctrlKey) return; if(parm.altKey) return; // for alt GR key, where ctrl might be set to true \t\t /* h1 - h5 */ if(parm.keyCode >=49 && parm.keyCode <=53) { var n = parm.keyCode - 48; oDokuWiki_FCKEditorInstance.get_FCK().Styles.ApplyStyle('_FCK_h' + n); return; } /* code/monospace -> 77 = 'm' */ if(parm.keyCode == 77) { oDokuWiki_FCKEditorInstance.get_FCK().Styles.ApplyStyle('_FCK_code'); \t\treturn; } /* CTRL-0 = Normal, i.e. <p> */ if(parm.keyCode == 48) { oDokuWiki_FCKEditorInstance.get_FCK().Styles.ApplyStyle('_FCK_p'); } } var DWikifnEncode = "{$fnencode}"; /* Make sure that show buttons in top and/or bottom clear the fckl file */ function get_showButtons() {\t \tvar inputs = document.getElementsByTagName('input'); for(var i=0; i<inputs.length; i++) {\t if(inputs[i].type && inputs[i].type.match(/submit/i)) {\t\t \t\t \t\t\tif(inputs[i].value.match(/Show/i) || (inputs[i].form && inputs[i].form.className.match(/btn_show/) ) ) \t\t\tinputs[i].onmouseup = draft_delete; } } } /* make sure the entire page has been loaded */ setTimeout("get_showButtons()", 3000); //]]> </script> end_of_string; }
function get_resized_image($width, $height, $override_sizetype = '', $filetype = '') { global $ihConf; $sizetype = $override_sizetype == '' ? $this->sizetype : $override_sizetype; switch ($sizetype) { case 'large': $file_extension = $ihConf['large']['filetype'] == 'no_change' ? $this->extension : '.' . $ihConf['large']['filetype']; $background = $ihConf['large']['bg']; $quality = $ihConf['large']['quality']; $width = $ihConf['large']['width']; $height = $ihConf['large']['height']; break; case 'medium': $file_extension = $ihConf['medium']['filetype'] == 'no_change' ? $this->extension : '.' . $ihConf['medium']['filetype']; $background = $ihConf['medium']['bg']; $quality = $ihConf['medium']['quality']; break; case 'small': $file_extension = $ihConf['small']['filetype'] == 'no_change' ? $this->extension : '.' . $ihConf['small']['filetype']; $background = $ihConf['small']['bg']; $quality = $ihConf['small']['quality']; break; default: $file_extension = $this->extension; $background = $ihConf['default']['bg']; $quality = $ihConf['default']['quality']; break; } list($newwidth, $newheight, $resize) = $this->calculate_size($width, $height); // set canvas dimensions if ($newwidth > 0 && $newheight > 0) { $this->canvas['width'] = $newwidth; $this->canvas['height'] = $newheight; } $this->initialize_overlays($sizetype); // override filetype? $file_extension = $filetype == '' ? $file_extension : $filetype; // Do we need to resize, watermark, zoom or convert to another filetype? if ($resize || $this->watermark['file'] != '' || $this->zoom['file'] != '' || $file_extension != $this->extension) { $local = getCacheName($this->src . $this->watermark['file'] . $this->zoom['file'] . $quality . $background . $ihConf['watermark']['gravity'] . $ihConf['zoom']['gravity'], '.image.' . $newwidth . 'x' . $newheight . $file_extension); //echo $local . '<br />'; $mtime = @filemtime($local); // 0 if not exists if ($mtime > @filemtime($this->filename) && $mtime > @filemtime($this->watermark['file']) && $mtime > @filemtime($this->zoom['file']) || $this->resize_imageIM($file_extension, $local, $background, $quality) || $this->resize_imageGD($file_extension, $local, $background, $quality)) { return str_replace($ihConf['dir']['docroot'], '', $local); } //still here? resizing failed } return $this->src; }
/** * Returns the local binary to use * * Downloads it if necessary * * @return bool|string */ protected function getLocalBinary() { global $conf; $bin = $this->getBinaryName(); if (!$bin) { return false; } // check distributed files first if (file_exists(__DIR__ . '/ditaa/' . $bin)) { return __DIR__ . '/ditaa/' . $bin; } $info = $this->getInfo(); $cache = getCacheName($info['date'], ".{$bin}"); if (file_exists($cache)) { return $cache; } $url = 'https://github.com/akavel/ditaa/releases/download/g1.0.0/' . $bin; if (io_download($url, $cache, false, '', 0)) { @chmod($cache, $conf['dmode']); return $cache; } return false; }
/** * Delete a draft * * @author Andreas Gohr <*****@*****.**> */ function ajax_draftdel() { global $INPUT; $id = cleanID($INPUT->str('id')); if (empty($id)) { return; } $client = $_SERVER['REMOTE_USER']; if (!$client) { $client = clientIP(true); } $cname = getCacheName($client . $id, '.draft'); @unlink($cname); }
function cache($key, $ext) { $this->key = $key; $this->ext = $ext; $this->cache = getCacheName($key, $ext); }
/** * function _preprocess * @author Myron Turner <*****@*****.**> */ function _preprocess() { global $ID; global $REV; global $DATE; global $RANGE; global $PRE; global $SUF; global $INFO; global $SUM; global $lang; global $conf; global $ckgedit_lang; //set summary default if (!$SUM) { if ($REV) { $SUM = $lang['restored']; } elseif (!$INFO['exists']) { $SUM = $lang['created']; } } if ($INFO['exists']) { if ($RANGE) { list($PRE, $text, $SUF) = rawWikiSlices($RANGE, $ID, $REV); } else { $text = rawWiki($ID, $REV); } } else { //try to load a pagetemplate $text = pageTemplate($ID); //Check for text from template event handler if (!$text && $this->page_from_template) { $text = $this->page_from_template; } } $text = preg_replace_callback('/(~~NOCACHE~~|~~NOTOC~~|\\{\\{rss>http:\\/\\/.*?\\}\\})/ms', create_function('$matches', '$matches[0] = str_replace("{{rss>http://", "{ { rss>Feed:", $matches[0]); $matches[0] = str_replace("~", "~ ", $matches[0]); return $matches[0];'), $text); if ($this->getConf('smiley_hack')) { $new_addr = $_SERVER['SERVER_NAME'] . DOKU_BASE; $text = preg_replace("#(?<=http://)(.*?)(?=lib/plugins/ckgedit/ckeditor/plugins/smiley/images)#s", $new_addr, $text); } $text = preg_replace_callback('/\\[\\[\\w+>.*?\\]\\]/ms', create_function('$matches', 'return str_replace("/", "__IWIKI_FSLASH__" ,$matches[0]);'), $text); global $useComplexTables; if ($this->getConf('complex_tables') || strrpos($text, '~~COMPLEX_TABLES~~') !== false) { $useComplexTables = true; } else { $useComplexTables = false; } if (strpos($text, '%%') !== false) { $text = preg_replace_callback("/<(nowiki|code|file)>(.*?)<\\/(nowiki|code|file)/ms", function ($matches) { $matches[0] = str_replace('%%', 'DBLPERCENT', $matches[0]); return $matches[0]; }, $text); $text = preg_replace_callback("/(?<!nowiki>)%%(.*?)%%/ms", function ($matches) { return '<nowiki>' . $matches[1] . '</nowiki>'; }, $text); $text = str_replace('DBLPERCENT', '%%', $text); } $pos = strpos($text, '<'); if ($pos !== false) { $text = preg_replace_callback('/(<nowiki>)(.*?)(<\\/nowiki>)/ms', create_function('$matches', '$needles = array("[","]", "/", ".", "*", "_","\'","<",">","%", "{", "}", "\\\\","("); $replacements = array("[","]","/", ".", "*", "_", "'", "<",">","%", "{","}", "\","("); $matches[2] = str_replace($needles, $replacements, $matches[2]); return $matches[1] . $matches[2] . $matches[3];'), $text); $text = preg_replace_callback('/<(code|file)(.*?)(>)(.*?)(<\\/\\1>)/ms', create_function('$matches', ' //file_put_contents("geshi.txt", print_r($matches,true)); if(preg_match("/(^\\s*geshi:\\s*(\\w+)(\\s+\\w+\\.\\w+)*\\s*)$/m",$matches[0],$gmatch)){ $gmatch[0] = preg_replace("/\\s*geshi:\\s+/","",$gmatch[0]); $matches[1] .= " " . trim($gmatch[0]); //file_put_contents("gmatch.txt", print_r($gmatch,true)); $c=1; $matches[4] = str_replace($gmatch[1],"",$matches[4],$c); } if(preg_match("/\\w+/",$matches[2])) { $matches[4] = str_replace("CHEVRONescC", ">>",$matches[4]); $matches[4] = str_replace("CHEVRONescO", "<<",$matches[4]); $matches[4] = preg_replace("/<(?!\\s)/ms", "__GESHI_OPEN__", $matches[4]); } else { if( preg_match("/MULTI/",$matches[0])) { $open = "< "; $close = " >"; } else { $open = "<"; $close = ">"; } $matches[4] = preg_replace("/<(?!\\s)/ms", $open, $matches[4]); $matches[4] = preg_replace("/(?<!\\s)>/ms", $close, $matches[4]); } $matches[4] = str_replace("\\"", "__GESHI_QUOT__", $matches[4]); return "<" . $matches[1] . $matches[2] . $matches[3] . $matches[4] . $matches[5];'), $text); /* \n_ckgedit_NPBBR_\n: the final \n prevents this from iterfering with next in line markups -- in particular tables which require a new line and margin left this may leave an empty paragraph in the xhtml, which is removed below */ $text = preg_replace('/<\\/(code|file)>(\\s*)(?=[^\\w])(\\s*)/m', "</\$1>\n_ckgedit_NPBBR_\n\$2", $text); $text = preg_replace_callback('/~~START_HTML_BLOCK~~.*?CLOSE_HTML_BLOCK/ms', create_function('$matches', '$matches[0] = str_replace("_ckgedit_NPBBR_","",$matches[0]); return $matches[0];'), $text); $text = preg_replace_callback('/(\\|\\s*)(<code>|<file>)(.*?)(<\\/code>|<\\/file>)\\n_ckgedit_NPBBR_(?=.*?\\|)/ms', create_function('$matches', '$matches[2] = preg_replace("/<code>/ms", "TPRE_CODE", $matches[2]); $matches[2] = preg_replace("/<file>/ms", "TPRE_FILE", $matches[2]); $matches[4] = "TPRE_CLOSE"; $matches[3] = preg_replace("/^\\n+/", "TC_NL",$matches[3]); $matches[3] = preg_replace("/\\n/ms", "TC_NL",$matches[3]); return $matches[1] . $matches[2] . trim($matches[3]) . $matches[4];'), $text); $text = preg_replace('/TPRE_CLOSE\\s+/ms', "TPRE_CLOSE", $text); $text = preg_replace('/<(?!code|file|del|sup|sub|\\/\\/|\\s|\\/del|\\/code|\\/file|\\/sup|\\/sub)/ms', "<", $text); $text = str_replace('%%<', '%%<', $text); } if ($this->getConf('duplicate_notes')) { $text = preg_replace_callback('/\\(\\((.*?)\\)\\)/ms', create_function('$matches', 'static $count = 0; $count++; $ins = "FNoteINSert" . $count; $needles = array("[","]", "/", ".", "*", "_","\'","<",">","%", "{", "}", "\\\\","("); $replacements = array("[","]","/", ".", "*", "_", "'", "<",">","%", "{","}", "\","("); $matches[1] = str_replace($needles, $replacements, $matches[1]); return "(($ins" . $matches[1] . "))" ;'), $text); } $text = preg_replace('/^\\>/ms', "_QUOT_", $text); // dw quotes $text = str_replace('>>', 'CHEVRONescC', $text); $text = str_replace('<<', 'CHEVRONescO', $text); $text = preg_replace('/(={3,}.*?)(\\{\\{.*?\\}\\})(.*?={3,})/', "\$1\$3\n\$2", $text); $email_regex = '/\\/\\/\\<\\/\\/(.*?@.*?)>/'; $text = preg_replace($email_regex, "<\$1>", $text); $text = preg_replace('/{{(.*)\\.swf(\\s*)}}/ms', "__SWF__\$1.swf\$2__FWS__", $text); $this->xhtml = $this->_render_xhtml($text); $this->xhtml = str_replace("__IWIKI_FSLASH__", "⁄", $this->xhtml); if ($this->getConf('duplicate_notes')) { $this->xhtml = preg_replace("/FNoteINSert\\d+/ms", "", $this->xhtml); } $this->xhtml = str_replace("__GESHI_QUOT__", '"', $this->xhtml); $this->xhtml = str_replace("__GESHI_OPEN__", "< ", $this->xhtml); $this->xhtml = str_replace('CHEVRONescC', '>>', $this->xhtml); $this->xhtml = str_replace('CHEVRONescO', '<<', $this->xhtml); $this->xhtml = preg_replace('/_QUOT_/ms', '>', $this->xhtml); // dw quotes if ($pos !== false) { $this->xhtml = preg_replace_callback('/(TPRE_CODE|TPRE_FILE)(.*?)(TPRE_CLOSE)/ms', create_function('$matches', '$matches[1] = preg_replace("/TPRE_CODE/","<pre class=\'code\'>\\n", $matches[1]); $matches[1] = preg_replace("/TPRE_FILE/","<pre class=\'file\'>\\n", $matches[1]); $matches[2] = preg_replace("/TC_NL/ms", "\\n", $matches[2]); $matches[3] = "</pre>"; return $matches[1] . $matches[2] . $matches[3];'), $this->xhtml); } $this->xhtml = preg_replace_callback('/~~START_HTML_BLOCK~~[\\n\\s]*(.*?)CLOSE_HTML_BLOCK/ms', create_function('$matches', '$matches[1] = str_replace("&","&",$matches[1]); $matches[1] = html_entity_decode($matches[1],ENT_QUOTES, "UTF-8"); $matches[1] = preg_replace("/<\\/?code.*?>/", "",$matches[1]); $matches[1] = preg_replace("/^\\s*<\\/p>/","",$matches[1]); $tmp = explode("\\n", $matches[1]); for($n=0; $n<7; $n++) { if( (preg_match("/(<p>\\s*)*( |\\s+)<\\/p>/",$tmp[$n])) || (preg_match("/^\\s+$/",$tmp[$n]))) { unset($tmp[$n]); } } return "~~START_HTML_BLOCK~~" . implode("\\n",$tmp) . "CLOSE_HTML_BLOCK"; '), $this->xhtml); $this->xhtml = preg_replace_callback('/(<pre)(.*?)(>)(.*?)(<\\/pre>)/ms', create_function('$matches', '$matches[4] = preg_replace("/(\\||\\^)[ ]+(\\||\\^)/ms","$1 $2" , $matches[4]); return $matches[1] . $matches[2] . $matches[3] . $matches[4] . $matches[5];'), $this->xhtml); $this->xhtml = preg_replace_callback('/~~MULTI_PLUGIN_OPEN~~(.*?)~~MULTI_PLUGIN_CLOSE~~/ms', create_function('$matches', 'return str_replace("<", "< ",$matches[0]);'), $this->xhtml); $cname = getCacheName($INFO['client'] . $ID, '.draft.fckl'); if (file_exists($cname)) { $cdata = unserialize(io_readFile($cname, false)); $cdata['text'] = urldecode($cdata['text']); preg_match_all("/<\\/(.*?)\\>/", $cdata['text'], $matches); /* exclude drafts saved from preview mode */ if (!in_array('code', $matches[1]) && !in_array('file', $matches[1]) && !in_array('nowiki', $matches[1])) { $this->draft_text = $cdata['text']; $this->draft_found = true; msg($this->getLang('draft_msg')); } unlink($cname); } return true; }
$pl->gfx_error('maxzoom'); } if ($data['inv'] < 1.0) { $data['inv'] = 1.0; } // original size, no upscaling // calculate tile boundaries $data['tlx'] = (int) ($data['col'] * $data['ts'] * $data['inv']); $data['tly'] = (int) ($data['row'] * $data['ts'] * $data['inv']); $data['brx'] = (int) ($data['tlx'] + $data['ts'] * $data['inv']); $data['bry'] = (int) ($data['tly'] + $data['ts'] * $data['inv']); if ($data['tlx'] > $data['width'] || $data['tly'] > $data['height']) { $pl->gfx_error('blank'); } // cache times $data['cache'] = getCacheName($data['file'], '.pv.' . $data['zoom'] . '-' . $data['col'] . '-' . $data['row'] . '.jpg'); $data['cachet'] = @filemtime($data['cache']); // (re)generate if ($data['cachet'] < $data['mtime']) { $pl->tile_lock($data); if ($conf['im_convert']) { $pl->tile_im($data); } else { $pl->tile_gd($data); } $pl->tile_unlock($data); } // send header('Content-type: image/jpeg'); http_conditionalRequest(max($data['mtime'], $data['selft'])); //use x-sendfile header to pass the delivery to compatible webservers
/** * Download a remote file and return local filename * * returns false if download fails. Uses cached file if available and * wanted * * @author Andreas Gohr <*****@*****.**> * @author Pavel Vitis <*****@*****.**> */ function media_get_from_URL($url, $ext, $cache) { global $conf; // if no cache or fetchsize just redirect if ($cache == 0) { return false; } if (!$conf['fetchsize']) { return false; } $local = getCacheName(strtolower($url), ".media.{$ext}"); $mtime = @filemtime($local); // 0 if not exists //decide if download needed: if ($mtime == 0 || $cache != -1 && $mtime < time() - $cache) { if (media_image_download($url, $local)) { return $local; } else { return false; } } //if cache exists use it else if ($mtime) { return $local; } //else return false return false; }
* XML feed export * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Andreas Gohr <*****@*****.**> */ if (!defined('DOKU_INC')) { define('DOKU_INC', dirname(__FILE__) . '/'); } require_once DOKU_INC . 'inc/init.php'; //close session session_write_close(); // get params $opt = rss_parseOptions(); // the feed is dynamic - we need a cache for each combo // (but most people just use the default feed so it's still effective) $cache = getCacheName(join('', array_values($opt)) . $_SERVER['REMOTE_USER'], '.feed'); $key = join('', array_values($opt)) . $_SERVER['REMOTE_USER']; $cache = new cache($key, '.feed'); // prepare cache depends $depends['files'] = getConfigFiles('main'); $depends['age'] = $conf['rss_update']; $depends['purge'] = $_REQUEST['purge'] ? true : false; // check cacheage and deliver if nothing has changed since last // time or the update interval has not passed, also handles conditional requests header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Type: application/xml; charset=utf-8'); header('X-Robots-Tag: noindex'); if ($cache->useCache($depends)) { http_conditionalRequest($cache->_time); if ($conf['allowdebug']) {
/** * Output all needed Styles * * @author Andreas Gohr <*****@*****.**> */ function css_out() { global $conf; global $lang; global $config_cascade; $mediatype = 'screen'; if (isset($_REQUEST['s']) && in_array($_REQUEST['s'], array('all', 'print', 'feed'))) { $mediatype = $_REQUEST['s']; } $tpl = trim(preg_replace('/[^\\w-]+/', '', $_REQUEST['t'])); if ($tpl) { $tplinc = DOKU_INC . 'lib/tpl/' . $tpl . '/'; $tpldir = DOKU_BASE . 'lib/tpl/' . $tpl . '/'; } else { $tplinc = DOKU_TPLINC; $tpldir = DOKU_TPL; } // The generated script depends on some dynamic options $cache = getCacheName('styles' . $_SERVER['HTTP_HOST'] . $_SERVER['SERVER_PORT'] . DOKU_BASE . $tplinc . $mediatype, '.css'); // load template styles $tplstyles = array(); if (@file_exists($tplinc . 'style.ini')) { $ini = parse_ini_file($tplinc . 'style.ini', true); foreach ($ini['stylesheets'] as $file => $mode) { $tplstyles[$mode][$tplinc . $file] = $tpldir; } } // Array of needed files and their web locations, the latter ones // are needed to fix relative paths in the stylesheets $files = array(); // load core styles $files[DOKU_INC . 'lib/styles/' . $mediatype . '.css'] = DOKU_BASE . 'lib/styles/'; // load plugin styles $files = array_merge($files, css_pluginstyles($mediatype)); // load template styles if (isset($tplstyles[$mediatype])) { $files = array_merge($files, $tplstyles[$mediatype]); } // if old 'default' userstyle setting exists, make it 'screen' userstyle for backwards compatibility if (isset($config_cascade['userstyle']['default'])) { $config_cascade['userstyle']['screen'] = $config_cascade['userstyle']['default']; } // load user styles if (isset($config_cascade['userstyle'][$mediatype])) { $files[$config_cascade['userstyle'][$mediatype]] = DOKU_BASE; } // load rtl styles // @todo: this currently adds the rtl styles only to the 'screen' media type // but 'print' and 'all' should also be supported if ($mediatype == 'screen') { if ($lang['direction'] == 'rtl') { if (isset($tplstyles['rtl'])) { $files = array_merge($files, $tplstyles['rtl']); } } } // check cache age & handle conditional request header('Cache-Control: public, max-age=3600'); header('Pragma: public'); if (css_cacheok($cache, array_keys($files), $tplinc)) { http_conditionalRequest(filemtime($cache)); if ($conf['allowdebug']) { header("X-CacheUsed: {$cache}"); } // finally send output if ($conf['gzip_output'] && http_gzip_valid($cache)) { header('Vary: Accept-Encoding'); header('Content-Encoding: gzip'); readfile($cache . ".gz"); } else { if (!http_sendfile($cache)) { readfile($cache); } } return; } else { http_conditionalRequest(time()); } // start output buffering and build the stylesheet ob_start(); // print the default classes for interwiki links and file downloads css_interwiki(); css_filetypes(); // load files foreach ($files as $file => $location) { print css_loadfile($file, $location); } // end output buffering and get contents $css = ob_get_contents(); ob_end_clean(); // apply style replacements $css = css_applystyle($css, $tplinc); // place all @import statements at the top of the file $css = css_moveimports($css); // compress whitespace and comments if ($conf['compress']) { $css = css_compress($css); } // save cache file io_saveFile($cache, $css); if (function_exists('gzopen')) { io_saveFile("{$cache}.gz", $css); } // finally send output if ($conf['gzip_output']) { header('Vary: Accept-Encoding'); header('Content-Encoding: gzip'); print gzencode($css, 9, FORCE_GZIP); } else { print $css; } }
/** * Return info about the current document as associative * array. * * @author Andreas Gohr <*****@*****.**> */ function pageinfo() { global $ID; global $REV; global $RANGE; global $USERINFO; global $lang; // include ID & REV not redundant, as some parts of DokuWiki may temporarily change $ID, e.g. p_wiki_xhtml // FIXME ... perhaps it would be better to ensure the temporary changes weren't necessary $info['id'] = $ID; $info['rev'] = $REV; // set info about manager/admin status. $info['isadmin'] = false; $info['ismanager'] = false; if (isset($_SERVER['REMOTE_USER'])) { $info['userinfo'] = $USERINFO; $info['perm'] = auth_quickaclcheck($ID); $info['subscribed'] = get_info_subscribed(); $info['client'] = $_SERVER['REMOTE_USER']; if ($info['perm'] == AUTH_ADMIN) { $info['isadmin'] = true; $info['ismanager'] = true; } elseif (auth_ismanager()) { $info['ismanager'] = true; } // if some outside auth were used only REMOTE_USER is set if (!$info['userinfo']['name']) { $info['userinfo']['name'] = $_SERVER['REMOTE_USER']; } } else { $info['perm'] = auth_aclcheck($ID, '', null); $info['subscribed'] = false; $info['client'] = clientIP(true); } $info['namespace'] = getNS($ID); $info['locked'] = checklock($ID); $info['filepath'] = fullpath(wikiFN($ID)); $info['exists'] = @file_exists($info['filepath']); if ($REV) { //check if current revision was meant if ($info['exists'] && @filemtime($info['filepath']) == $REV) { $REV = ''; } elseif ($RANGE) { //section editing does not work with old revisions! $REV = ''; $RANGE = ''; msg($lang['nosecedit'], 0); } else { //really use old revision $info['filepath'] = fullpath(wikiFN($ID, $REV)); $info['exists'] = @file_exists($info['filepath']); } } $info['rev'] = $REV; if ($info['exists']) { $info['writable'] = is_writable($info['filepath']) && $info['perm'] >= AUTH_EDIT; } else { $info['writable'] = $info['perm'] >= AUTH_CREATE; } $info['editable'] = $info['writable'] && empty($info['locked']); $info['lastmod'] = @filemtime($info['filepath']); //load page meta data $info['meta'] = p_get_metadata($ID); //who's the editor if ($REV) { $revinfo = getRevisionInfo($ID, $REV, 1024); } else { if (is_array($info['meta']['last_change'])) { $revinfo = $info['meta']['last_change']; } else { $revinfo = getRevisionInfo($ID, $info['lastmod'], 1024); // cache most recent changelog line in metadata if missing and still valid if ($revinfo !== false) { $info['meta']['last_change'] = $revinfo; p_set_metadata($ID, array('last_change' => $revinfo)); } } } //and check for an external edit if ($revinfo !== false && $revinfo['date'] != $info['lastmod']) { // cached changelog line no longer valid $revinfo = false; $info['meta']['last_change'] = $revinfo; p_set_metadata($ID, array('last_change' => $revinfo)); } $info['ip'] = $revinfo['ip']; $info['user'] = $revinfo['user']; $info['sum'] = $revinfo['sum']; // See also $INFO['meta']['last_change'] which is the most recent log line for page $ID. // Use $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT in place of $info['minor']. if ($revinfo['user']) { $info['editor'] = $revinfo['user']; } else { $info['editor'] = $revinfo['ip']; } // draft $draft = getCacheName($info['client'] . $ID, '.draft'); if (@file_exists($draft)) { if (@filemtime($draft) < @filemtime(wikiFN($ID))) { // remove stale draft @unlink($draft); } else { $info['draft'] = $draft; } } // mobile detection $info['ismobile'] = clientismobile(); return $info; }
/** * Download a remote file and return local filename * * returns false if download fails. Uses cached file if available and * wanted * * @author Andreas Gohr <*****@*****.**> * @author Pavel Vitis <*****@*****.**> */ function get_from_URL($url, $ext, $cache) { global $conf; $local = getCacheName(strtolower($url), ".media.{$ext}"); $mtime = @filemtime($local); // 0 if not exists //decide if download needed: if ($cache == 0 || $mtime != 0 && $cache != -1 || $mtime == 0 || $cache != -1 && $mtime < time() - $cache) { if (io_download($url, $local)) { return $local; } else { return false; } } //if cache exists use it else if ($mtime) { return $local; } //else return false return false; }
function registerOnLoad($js) { global $ID; global $lang; global $skip_styling; $preview_button = $lang['btn_preview']; $ckgedit_conf_direction = $this->getConf('direction'); if ($ckgedit_conf_direction == "dokuwiki") { $ckgedit_lang_direction = $lang['direction']; } else { $ckgedit_lang_direction = $ckgedit_conf_direction; } $ImageUploadAllowedExtensions = $this->get_ckgedit_ImageAllowedExtensions(); $media_tmp_ns = preg_match('/:/', $ID) ? preg_replace('/:\\w+$/', "", $ID, 1) : ""; $locktimer_msg = "Your lock for editing this page is about to expire in a minute.\\n" . "You can reset the timer by clicking the Back-up button."; $meta_fn = metaFN($ID, '.ckgedit'); $meta_id = 'meta/' . str_replace(':', '/', $ID) . '.ckgedit'; global $INFO; global $conf; global $USERINFO; $_OS = strtolower(PHP_OS); $cname = getCacheName($INFO['client'] . $ID, '.draft'); $useheading = $conf['useheading']; if ($useheading && $useheading != 'content' && $useheading != '0') { $useheading = 'y'; } else { $useheading = 'n'; } //msg('uh='.$useheading); $open_upload = $this->getConf('open_upload'); $editor_backup = $this->getConf('editor_bak'); $create_folder = $this->getConf('create_folder'); $interface_lang = $this->getConf('other_lang'); $scayt_lang = $this->getConf('scayt_lang'); list($name, $scayt_lang) = explode('/', $scayt_lang); $scayt_auto = $this->getConf('scayt_auto'); $color_opts = $this->getConf('color_options'); $font_opts = $this->getConf('font_options'); $toolbar_opts = $this->getConf('alt_toolbar'); $mfiles = $this->getConf('mfiles'); if (!isset($INFO['userinfo']) && !$open_upload) { $user_type = 'visitor'; } else { $user_type = 'user'; } $save_dir = DOKU_URL . ltrim($conf['savedir'], '/.\\/'); // if no ACL is used always return upload rights if ($conf['useacl']) { $client = $_SERVER['REMOTE_USER']; } else { $client = ""; } $user_name = $USERINFO['name']; $user_email = $USERINFO['mail']; $fnencode = isset($conf['fnencode']) ? $conf['fnencode'] : 'url'; $user_groups = $USERINFO['grps']; if (!$user_groups) { $user_groups = array(); } if (@in_array("guest", $user_groups)) { $create_folder = 'n'; $user_type = 'visitor'; } $user_groups = implode(";;", $user_groups); if ($INFO['isadmin'] || $INFO['ismanager']) { $client = ""; } $ver_anteater = mktime(0, 0, 0, 11, 7, 2010); $dwiki_version = mktime(0, 0, 0, 01, 01, 2008); if (isset($conf['fnencode'])) { $ver_anteater = mktime(0, 0, 0, 11, 7, 2010); $dwiki_version = mktime(0, 0, 0, 11, 7, 2010); } else { if (function_exists('getVersionData')) { $verdata = getVersionData(); if (isset($verdata) && preg_match('/(\\d+)-(\\d+)-(\\d+)/', $verdata['date'], $ver_date)) { if ($ver_date[1] >= 2005 && ($ver_date[3] > 0 && $ver_date[3] < 31) && ($ver_date[2] > 0 && $ver_date[2] <= 12)) { // month day year $dwiki_version = @mktime(0, 0, 0, $ver_date[2], $ver_date[3], $ver_date[1]); if (!$dwiki_version) { $dwiki_version = mktime(0, 0, 0, 01, 01, 2008); } $ver_anteater = mktime(0, 0, 0, 11, 7, 2010); } } } } $default_fb = $this->getConf('default_fb'); if ($default_fb == 'none') { $client = ""; } $doku_base = DOKU_BASE; return <<<end_of_string <script type='text/javascript'> //<![CDATA[ if(window.dw_locktimer) { var locktimer = dw_locktimer; } var FCKRecovery = ""; var oldonload = window.onload; var ourLockTimerINI = false; var oldBeforeunload; var ckgedit_onload = function() { {$js} }; jQuery(window).bind('load',{},ckgedit_onload); function ckgeditEditorTextChanged() { window.textChanged = false; oldBeforeunload(); if(window.dwfckTextChanged) { return LANG.notsavedyet; } } function getCurrentWikiNS() { var DWikiMediaManagerCommand_ns = '{$media_tmp_ns}'; return DWikiMediaManagerCommand_ns; } var ourLockTimerRefreshID; var ourLockTimerIsSet = true; var ourLockTimerWarningtimerID; var ourFCKEditorNode = null; var ourLockTimerIntervalID; var dwfckTextChanged = false; /** * event handler * handles both mousepresses and keystrokes from FCKeditor window * assigned in fckeditor.html */ function handlekeypress (e) { if(ourLockTimerIsSet) { lockTimerRefresh(); } window.dwfckTextChanged = true; } function unsetDokuWikiLockTimer() { if(window.locktimer && !ourLockTimerINI) { locktimer.old_reset = locktimer.reset; locktimer.old_warning = locktimer.warning; ourLockTimerINI=true; } else { window.setTimeout("unsetDokuWikiLockTimer()", 600); } locktimer.reset = function(){ locktimer.clear(); // alert(locktimer.timeout); window.clearTimeout(ourLockTimerWarningtimerID); ourLockTimerWarningtimerID = window.setTimeout(function () { locktimer.warning(); }, locktimer.timeout); }; locktimer.warning = function(){ window.clearTimeout(ourLockTimerWarningtimerID); if(ourLockTimerIsSet) { if(locktimer.msg.match(/{$preview_button}/i)) { locktimer.msg = locktimer.msg.replace(/{$preview_button}/i, "Back-up"); } alert(locktimer.msg); } else { alert("{$locktimer_msg}"); } }; locktimer.ourLockTimerReset = locktimer.reset; locktimer.our_lasttime = new Date(); lockTimerRefresh(); } function lockTimerRefresh(bak) { var now = new Date(); if(!ourLockTimerINI) unsetDokuWikiLockTimer(); if((now.getTime() - locktimer.our_lasttime.getTime() > 45*1000) || bak){ var dwform = GetE('dw__editform'); window.clearTimeout(ourLockTimerWarningtimerID); var params = 'call=lock&id='+locktimer.pageid; if(CKEDITOR.instances) { dwform.elements.wikitext.value = CKEDITOR.instances.wiki__text.getData(); params += '&prefix='+encodeURIComponent(dwform.elements.prefix.value); params += '&wikitext='+encodeURIComponent(dwform.elements.wikitext.value); params += '&suffix='+encodeURIComponent(dwform.elements.suffix.value); params += '&date='+encodeURIComponent(dwform.elements.date.value); } locktimer.our_lasttime = now; jQuery.post( DOKU_BASE + 'lib/exe/ajax.php', params, function (data) { data = data.replace(/auto/,"") + ' by ckgeditLite'; locktimer.response = data; locktimer.refreshed(data); }, 'html' ); } } /** Legacy function has no current use */ function getRecoveredText() { return FCKRecovery; } function resetDokuWikiLockTimer(delete_checkbox) { var dom_checkbox = document.getElementById('ckgedit_timer'); var dom_label = document.getElementById('ckgedit_timer_label'); locktimer.clear(); if(ourLockTimerIsSet) { ourLockTimerIsSet = false; locktimer.reset = locktimer.old_reset; locktimer.refresh(); return; } if(delete_checkbox) { dom_checkbox.style.display = 'none'; dom_label.style.display = 'none'; } ourLockTimerIsSet = true; locktimer.reset = locktimer.ourLockTimerReset; lockTimerRefresh(); } function renewLock(bak) { if(ourLockTimerIsSet) { lockTimerRefresh(true); } else { locktimer.refresh(); } locktimer.reset(); if(bak) { var id = "{$ID}"; parse_wikitext('bakup'); var dwform = GetE('dw__editform'); if(dwform.elements.fck_wikitext.value == '__false__' ) return; GetE('saved_wiki_html').innerHTML = CKEDITOR.instances.wiki__text.getData(); // ourFCKEditorNode.innerHTML; if(({$editor_backup}) == 0 ) { return; } var params = "rsave_id=" + encodeURIComponent("{$meta_fn}"); params += '&wikitext='+encodeURIComponent(dwform.elements.fck_wikitext.value); jQuery.post( DOKU_BASE + 'lib/plugins/ckgedit/scripts/refresh_save.php', params, function (data) { if(data == 'done') { show_backup_msg("{$meta_id}"); } else { alert("error saving: " + id); } }, 'html' ); } } function revert_to_prev() { if(!(GetE('saved_wiki_html').innerHTML.length)) { if(!confirm(backup_empty)) { return; } } CKEDITOR.instances.wiki__text.setData( GetE('saved_wiki_html').innerHTML); } function draft_delete() { var debug = false; var params = "draft_id={$cname}"; jQuery.ajax({ url: DOKU_BASE + 'lib/plugins/ckgedit/scripts/draft_delete.php', async: false, data: params, type: 'POST', dataType: 'html', success: function(data){ if(debug) { alert(data); } } }); } function disableDokuWikiLockTimer() { resetDokuWikiLockTimer(false); if(ourLockTimerIntervalID) { window.clearInterval(ourLockTimerIntervalID); } if(ourLockTimerIsSet) { ourLockTimerIntervalID = window.setInterval(function () { locktimer.refresh(); }, 30000); } } function dwfckKeypressInstallHandler() { if(window.addEventListener){ oDokuWiki_FCKEditorInstance.EditorDocument.addEventListener('keyup', handlekeypress , false) ; } else { oDokuWiki_FCKEditorInstance.EditorDocument.attachEvent('onkeyup', handlekeypress ) ; } } var DWFCK_EditorWinObj; function FCKEditorWindowObj(w) { DWFCK_EditorWinObj = w; } function ckgedit_isRTL() { var direction = "{$ckgedit_lang_direction}"; return direction == 'rtl'; } function remove_styling() { //'TextColor,BGColor, FontAssist,Font,FontSize'; var opts = ""; var color_opts = parseInt( "{$color_opts}"); var font_opts = parseInt("{$font_opts}"); var skip_styling=parseInt("{$skip_styling}"); if(color_opts) { opts ='TextColor,BGColor,FontAssist'; } else if(!skip_styling) { opts = 'FontAssist'; } if(font_opts) { if(color_opts || !skip_styling) opts+=','; opts +='Font,FontSize'; } if("{$toolbar_opts}") { if(opts) opts+=','; opts+="{$toolbar_opts}"; } return opts; } function ckgedit_language_chk(config) { if("{$scayt_auto}" == 'on') { config.scayt_autoStartup = true; } else config.scayt_autoStartup = false; config.scayt_sLang="{$scayt_lang}"; var lang = "{$interface_lang}"; if(lang == 'default') return; ; config.language = lang; } var oDokuWiki_FCKEditorInstance; function FCKeditor_OnComplete( editorInstance ) { oDokuWiki_FCKEditorInstance = editorInstance; editorInstance.on( 'key', handlekeypress, editorInstance ); oDokuWiki_FCKEditorInstance.dwiki_user = "******"; oDokuWiki_FCKEditorInstance.dwiki_client = "{$client}"; oDokuWiki_FCKEditorInstance.dwiki_usergroups = "{$user_groups}"; oDokuWiki_FCKEditorInstance.dwiki_doku_base = "{$doku_base}"; oDokuWiki_FCKEditorInstance.dwiki_create_folder = "{$create_folder}"; oDokuWiki_FCKEditorInstance.dwiki_fnencode = "{$fnencode}"; oDokuWiki_FCKEditorInstance.dwiki_version = {$dwiki_version}; oDokuWiki_FCKEditorInstance.dwiki_anteater = {$ver_anteater}; oDokuWiki_FCKEditorInstance.isLocalDwikiBrowser = false; oDokuWiki_FCKEditorInstance.isUrlExtern = false; oDokuWiki_FCKEditorInstance.isDwikiMediaFile = false; oDokuWiki_FCKEditorInstance.imageUploadAllowedExtensions="{$ImageUploadAllowedExtensions}"; oDokuWiki_FCKEditorInstance.fckgUserName = "******"; oDokuWiki_FCKEditorInstance.fckgUserMail="{$user_email}"; oDokuWiki_FCKEditorInstance.useheading = "{$useheading}"; oDokuWiki_FCKEditorInstance.mfiles = parseInt("{$mfiles}"); var index = navigator.userAgent.indexOf('Safari'); if(index == -1 || (navigator.userAgent.indexOf('Chrome'))) { oldBeforeunload = window.onbeforeunload; window.onbeforeunload = ckgeditEditorTextChanged; } } var DWikifnEncode = "{$fnencode}"; /* Make sure that show buttons in top and/or bottom clear the fckl file */ function get_showButtons() {\t \tvar inputs = document.getElementsByTagName('input'); for(var i=0; i<inputs.length; i++) {\t if(inputs[i].type && inputs[i].type.match(/submit/i)) {\t\t \t\t \t\t\tif(inputs[i].value.match(/Show/i) || (inputs[i].form && inputs[i].form.className.match(/btn_show/) ) ) \t\t\tinputs[i].onmouseup = draft_delete; } } } /* make sure the entire page has been loaded */ setTimeout("get_showButtons()", 3000); //]]> </script> end_of_string; }
/** * Saves a draft on preview * * @todo this currently duplicates code from ajax.php :-/ */ function act_draftsave($act) { global $INFO; global $ID; global $conf; if ($conf['usedraft'] && $_POST['wikitext']) { $draft = array('id' => $ID, 'prefix' => $_POST['prefix'], 'text' => $_POST['wikitext'], 'suffix' => $_POST['suffix'], 'date' => $_POST['date'], 'client' => $INFO['client']); $cname = getCacheName($draft['client'] . $ID, '.draft'); if (io_saveFile($cname, serialize($draft))) { $INFO['draft'] = $cname; } } return $act; }
/** * Wrapper for GeSHi Code Highlighter, provides caching of its output * * @param string $code source code to be highlighted * @param string $language language to provide highlighting * @param string $wrapper html element to wrap the returned highlighted text * * @author Christopher Smith <*****@*****.**> * @author Andreas Gohr <*****@*****.**> */ function p_xhtml_cached_geshi($code, $language, $wrapper = 'pre') { global $conf, $config_cascade, $INPUT; $language = strtolower($language); // remove any leading or trailing blank lines $code = preg_replace('/^\\s*?\\n|\\s*?\\n$/', '', $code); $cache = getCacheName($language . $code, ".code"); $ctime = @filemtime($cache); if ($ctime && !$INPUT->bool('purge') && $ctime > filemtime(DOKU_INC . 'inc/geshi.php') && $ctime > @filemtime(DOKU_INC . 'inc/geshi/' . $language . '.php') && $ctime > filemtime(reset($config_cascade['main']['default']))) { // dokuwiki changed $highlighted_code = io_readFile($cache, false); } else { $geshi = new GeSHi($code, $language, DOKU_INC . 'inc/geshi'); $geshi->set_encoding('utf-8'); $geshi->enable_classes(); $geshi->set_header_type(GESHI_HEADER_PRE); $geshi->set_link_target($conf['target']['extern']); // remove GeSHi's wrapper element (we'll replace it with our own later) // we need to use a GeSHi wrapper to avoid <BR> throughout the highlighted text $highlighted_code = trim(preg_replace('!^<pre[^>]*>|</pre>$!', '', $geshi->parse_code()), "\n\r"); io_saveFile($cache, $highlighted_code); } // add a wrapper element if required if ($wrapper) { return "<{$wrapper} class=\"code {$language}\">{$highlighted_code}</{$wrapper}>"; } else { return $highlighted_code; } }
$newdata = str_replace('<?xml version="1.0" encoding="iso-8859-1"?>', '<?xml version="1.0" encoding="' . $charset . '"?>', $newdata); } // EN-Revision for new translated files if (!stristr($newdata, 'EN-Revision:')) { $newdata = str_replace('<!-- $' . 'Revision' . ': ', '<!-- \\$' . 'Revision' . ": 1 \$ -->\n<!-- EN-Revision: ", $newdata); } // Send file as is (download) if (isset($_REQUEST['download'])) { header('Content-Type: application/download'); header('Content-Disposition: attachment; filename=' . basename($requestedFilename)); print $newdata; exit; } if ($requireLogin) { // Save file in user cache folder $f = fopen($user['cache'] . getCacheName($requestedFilename), 'w'); fputs($f, $newdata); fclose($f); // Simple log $f = fopen($user['cache'] . "files.txt", 'a'); $time = getDateTimeToLog(); $ip = getUserIP(); fputs($f, "{$time}|{$ip}|{$requestedFilename}\r\n"); fclose($f); } exit("File has been saved in your cache folder. You can now <a href='editxml.php?file={$requestedFilename}&source={$source}&download=yes&noframes=1'>download it</a> or edit another file"); } if (empty($_SESSION['textedit'])) { // Mark XML Tags to be hidden (when hidexml is true) $hideXMLTag = empty($_SESSION['hidexml']) ? '' : $_SESSION['hidexml']; $startXMLTag = '';
function get_resized_image($width, $height, $override_sizetype = '', $filetype = '') { global $ihConf; $sizetype = $override_sizetype == '' ? $this->sizetype : $override_sizetype; switch ($sizetype) { case 'large': $file_extension = $ihConf['large']['filetype'] == 'no_change' ? $this->extension : '.' . $ihConf['large']['filetype']; $background = $ihConf['large']['bg']; $quality = $ihConf['large']['quality']; $width = $ihConf['large']['width']; $height = $ihConf['large']['height']; break; case 'medium': $file_extension = $ihConf['medium']['filetype'] == 'no_change' ? $this->extension : '.' . $ihConf['medium']['filetype']; $background = $ihConf['medium']['bg']; $quality = $ihConf['medium']['quality']; break; case 'small': $file_extension = $ihConf['small']['filetype'] == 'no_change' ? $this->extension : '.' . $ihConf['small']['filetype']; $background = $ihConf['small']['bg']; $quality = $ihConf['small']['quality']; break; default: $file_extension = $this->extension; $background = $ihConf['default']['bg']; $quality = $ihConf['default']['quality']; break; } list($newwidth, $newheight, $resize) = $this->calculate_size($width, $height); // set canvas dimensions if ($newwidth > 0 && $newheight > 0) { $this->canvas['width'] = $newwidth; $this->canvas['height'] = $newheight; } $this->initialize_overlays($sizetype); // override filetype? $file_extension = $filetype == '' ? $file_extension : $filetype; // Do we need to resize, watermark, zoom or convert to another filetype? if ($resize || $this->watermark['file'] != '' || $this->zoom['file'] != '' || $file_extension != $this->extension) { // $local = getCacheName($this->src . $this->watermark['file'] . $this->zoom['file'] . $quality . $background . $ihConf['watermark']['gravity'] . $ihConf['zoom']['gravity'], '.image.' . $newwidth . 'x' . $newheight . $file_extension); // use pathinfo to get full path of an image $image_path = pathinfo($this->src); // get image name from path $image_basename = $image_path['basename']; // now let's clean it up for those who don't know image files SHOULD be named $image_basename = str_replace(' ', '-', $image_basename); // Replaces all spaces with hyphens $image_basename = preg_replace('/[^A-Za-z0-9\\-_]/', '', $image_basename); // Removes special chars, keeps hyphen and underscore $image_basename = preg_replace('/-+/', '-', $image_basename); // Replaces multiple hyphens with single one // get last directory from path $image_dirname = basename($image_path['dirname']); // now let's clean up the directory name just like we did with image name (this should be a function, I know, I know...) $image_dirname = str_replace(' ', '-', $image_dirname); // Replaces all spaces with hyphens $image_dirname = preg_replace('/[^A-Za-z0-9\\-_]/', '', $image_dirname); // Removes special chars, keeps hyphen and underscore $image_dirname = preg_replace('/-+/', '-', $image_dirname); // Replaces multiple hyphens with single one // if last directory is images (meaning image is stored in main images folder), do nothing, else append directory name $image_dirname == rtrim(DIR_WS_IMAGES, '/') ? $image_dir = '' : ($image_dir = $image_dirname . '-'); // and now do the magic and create cached image name with the above parameters $local = getCacheName(strtolower($image_dir . $image_basename), '.image.' . $newwidth . 'x' . $newheight . $file_extension); //echo $local . '<br />'; $mtime = @filemtime($local); // 0 if not exists if ($mtime > @filemtime($this->filename) && $mtime > @filemtime($this->watermark['file']) && $mtime > @filemtime($this->zoom['file']) || $this->resize_imageIM($file_extension, $local, $background, $quality) || $this->resize_imageGD($file_extension, $local, $background, $quality)) { return str_replace($ihConf['dir']['docroot'], '', $local); } //still here? resizing failed } return $this->src; }
/** * check draft */ function test_draft() { global $ID, $conf; $ID = 'wiki:syntax'; $filename = $conf['datadir'] . '/wiki/syntax.txt'; $rev = filemtime($filename); $info = $this->_get_expected_pageinfo(); $info['id'] = 'wiki:syntax'; $info['namespace'] = 'wiki'; $info['filepath'] = $filename; $info['exists'] = true; $info['lastmod'] = $rev; $info['currentrev'] = $rev; $info['meta'] = p_get_metadata($ID); // setup a draft, make it more recent than the current page // - pageinfo should recognise it and keep it $draft = getCacheName($info['client'] . $ID, '.draft'); touch($draft, $rev + 10); $info['draft'] = $draft; $this->assertEquals($info, pageinfo()); $this->assertFileExists($draft); // make the draft older than the current page // - pageinfo should remove it and not return the 'draft' key touch($draft, $rev - 10); unset($info['draft']); $this->assertEquals($info, pageinfo()); $this->assertFalse(file_exists($draft)); }