/** * 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 = $conf['cachedir'] . '/messages.txt'; $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("checkUpdatesMessages(): downloading messages.txt"); $http = new DokuHTTPClient(); $http->timeout = 12; $data = $http->get(DOKU_MESSAGEURL . $updateVersion); io_saveFile($cf, $data); } else { dbglog("checkUpdatesMessages(): messages.txt 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); } } }
/** * Handle the match */ function handle($data, $state, $pos, Doku_Handler $handler) { $data = explode("\n", $data); $conf = array_shift($data); array_pop($data); $conf = trim(substr($conf, 10, -1)); $conf = $this->parseOpts($conf); // parse $count = count($data); for ($i = 0; $i < $count; $i++) { // copy line, free memory $line = $data[$i]; unset($data[$i]); $line = trim($line); $line = rtrim($line, " ;"); if (strpos($line, '->') === false) { $opt = $this->parseNode($line); } else { $opt = $this->parseEdge($line); } } $xml = $this->getXML($conf, $w, $h); $xmlid = md5($xml); $cache = getcachename($xmlid, 'graphgear'); io_saveFile($cache, $xml); return array('xmlid' => $xmlid, 'width' => $w, 'height' => $h); }
/** * Check for new messages from upstream * * @author Andreas Gohr <*****@*****.**> */ function checkUpdateMessages() { global $conf; global $INFO; if (!$conf['updatecheck']) { return; } if ($conf['useacl'] && !$INFO['ismanager']) { return; } $cf = $conf['cachedir'] . '/messages.txt'; $lm = @filemtime($cf); // check if new messages needs to be fetched if ($lm < time() - 60 * 60 * 24 || $lm < @filemtime(DOKU_CONF . 'msg')) { $num = @file(DOKU_CONF . 'msg'); $num = is_array($num) ? (int) $num[0] : 0; $http = new DokuHTTPClient(); $http->timeout = 8; $data = $http->get(DOKU_MESSAGEURL . $num); io_saveFile($cf, $data); } else { $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); } } }
public function handle_ajax_call() { global $INPUT; header('Content-Type: text/plain'); $langCode = $INPUT->str('lang'); $text = $INPUT->str('text'); $dir = DOKU_CONF . 'lang/' . $langCode; $file = $dir . '/register.txt'; // make sure the directory exists if (!file_exists($dir)) { if (mkdir($dir, 0755) === false) { echo $this->getLang('makeDirError'); return; } } // save the file if (file_put_contents($file, $text) === false) { echo $this->getLang('saveFileError'); return; } // set file permissions chmod($file, 0644); // log the change $timestamp = time(); $id = $langCode . ':register'; addLogEntry($timestamp, $id); // save this revision in the attic $atticFile = wikiFN($id, $timestamp, true); io_saveFile($atticFile, $text, false); // send OK to the browser echo 'OK'; }
/** * Handle the match */ function handle($match, $state, $pos, &$handler) { global $ID; global $ACT; // don't show linkback section on blog mainpages if (defined('IS_BLOG_MAINPAGE')) { return false; } // don't allow usage of syntax in comments if (isset($_REQUEST['comment'])) { return false; } // get linkback meta file name $file = metaFN($ID, '.linkbacks'); $data = array('send' => false, 'receive' => false, 'display' => false, 'sentpings' => array(), 'receivedpings' => array(), 'number' => 0); if (@file_exists($file)) { $data = unserialize(io_readFile($file, false)); } if ($match == '~~LINKBACK~~') { $data['receive'] = true; $data['display'] = true; } else { if ($match == '~~LINKBACK:off~~') { $data['receive'] = false; $data['display'] = false; } else { $data['receive'] = false; $data['display'] = true; } } io_saveFile($file, serialize($data)); }
/** * Handle the match */ function handle($match, $state, $pos, &$handler) { global $ID, $ACT; // strip markup $match = substr($match, 12, -2); // split title (if there is one) list($match, $title) = explode('|', $match, 2); // assign discussion state if ($match == ':off') { $status = 0; } else { if ($match == ':closed') { $status = 2; } else { $status = 1; } } if ($ACT == 'preview') { return; } // get discussion meta file name $file = metaFN($ID, '.comments'); $data = array(); if (@file_exists($file)) { $data = unserialize(io_readFile($file, false)); } $data['title'] = $title; $data['status'] = $status; io_saveFile($file, serialize($data)); return $status; }
/** * Handle the match */ function handle($match, $state, $pos, Doku_Handler $handler) { $info = $this->getInfo(); // prepare default data $return = array('width' => 0, 'height' => 0, 'layout' => 'dot', 'align' => '', 'version' => $info['date']); // prepare input $lines = explode("\n", $match); $conf = array_shift($lines); array_pop($lines); // match config options if (preg_match('/\\b(left|center|right)\\b/i', $conf, $match)) { $return['align'] = $match[1]; } if (preg_match('/\\b(\\d+)x(\\d+)\\b/', $conf, $match)) { $return['width'] = $match[1]; $return['height'] = $match[2]; } if (preg_match('/\\b(dot|neato|twopi|circo|fdp)\\b/i', $conf, $match)) { $return['layout'] = strtolower($match[1]); } if (preg_match('/\\bwidth=([0-9]+)\\b/i', $conf, $match)) { $return['width'] = $match[1]; } if (preg_match('/\\bheight=([0-9]+)\\b/i', $conf, $match)) { $return['height'] = $match[1]; } $input = join("\n", $lines); $return['md5'] = md5($input); // we only pass a hash around // store input for later use io_saveFile($this->_cachename($return, 'txt'), $input); return $return; }
function handle_approve(&$event, $param) { global $ID, $REV, $INFO; if ($event->data == 'show' && isset($_GET['approve'])) { if (!$this->can_approve()) { return; } //change last commit comment to Approved $meta = p_read_metadata($ID); $meta[current][last_change][sum] = $meta[persistent][last_change][sum] = APPROVED; $meta[current][last_change][user] = $meta[persistent][last_change][user] = $INFO[client]; if (!array_key_exists($INFO[client], $meta[current][contributor])) { $meta[current][contributor][$INFO[client]] = $INFO[userinfo][name]; $meta[persistent][contributor][$INFO[client]] = $INFO[userinfo][name]; } p_save_metadata($ID, $meta); //update changelog //remove last line from file $changelog_file = metaFN($ID, '.changes'); $changes = file($changelog_file, FILE_SKIP_EMPTY_LINES); $lastLogLine = array_pop($changes); $info = parseChangelogLine($lastLogLine); $info[user] = $INFO[client]; $info[sum] = APPROVED; $logline = implode("\t", $info) . "\n"; array_push($changes, $logline); io_saveFile($changelog_file, implode('', $changes)); header('Location: ?id=' . $ID); } }
/** * Saves the name of the uploaded media file to a meta file */ function _saveMeta(&$event) { global $conf; $id = $event->data[2]; $filename_tidy = noNS($id); // retrieve original filename if (!empty($_POST['id'])) { // via normal uploader $filename_pat = $conf['useslash'] ? '/([^:;\\/]*)$/' : '/([^:;]*)$/'; preg_match($filename_pat, $_POST['id'], $matches); $filename_orig = $matches[1]; } elseif (isset($_FILES['Filedata'])) { // via multiuploader $filename_orig = $_FILES['upload']['name']; } else { return; } $filename_safe = $this->common->_sanitizeFileName($filename_orig); // no need to save original filename if ($filename_tidy === $filename_safe) { return; } // fallback if suspicious characters found if ($filename_orig !== $filename_safe) { return; } // save original filename to metadata $metafile = metaFN($id, '.filename'); io_saveFile($metafile, serialize(array('filename' => $filename_safe))); }
/** * handle user request */ function handle() { if ($_POST['redirdata']) { if (io_saveFile(dirname(__FILE__) . '/redirect.conf', cleanText($_POST['redirdata']))) { msg($this->getLang('saved'), 1); } } }
function _write($file) { $contents = "The\nWrite\nTest\n"; $this->assertTrue(io_saveFile($file, $contents)); $this->assertEquals($contents, io_readFile($file)); $this->assertTrue(io_saveFile($file, $contents, true)); $this->assertEquals($contents . $contents, io_readFile($file)); }
function save_dbnames_ser($fname, $content) { if (function_exists(io_saveFile)) { return io_saveFile($fname, $content); } else { return file_put_contents($names_fname, $content); } }
function numberingDB() { $db = metaFN("numbering:seqnum", '.ser'); if (!file_exists($db)) { io_saveFile($db, "", array()); } return $db; }
/** * handle user request */ function handle() { if ($_POST['redirdata']) { if (io_saveFile($this->getsavedir() . '/shorturl.conf', $_POST['redirdata'])) { msg($this->getLang('saved'), 1); } } }
/** * Enable or disable autosubmit * @param bool $enable If TRUE, it will enable autosubmit. Else, it will disable it. */ function _enableAutosubmit($enable) { if ($enable) { io_saveFile($this->helper->autosubmitFile, ' '); } else { @unlink($this->helper->autosubmitFile); } }
function writeCache($id) { if (!$this->is_inCache($id)) { $this->cache[md5($id)] = $id; io_saveFile($this->script_file, serialize($this->cache)); return true; } return false; }
/** */ function process_feed(&$event, $param) { global $ID; if ($this->helper->pageUpdated()) { $metafile = metaFN('newsfeed:wasupdated', '.meta'); io_saveFile($metafile, time() . "\n" . $ID . "\n"); $this->helper->saveFeedData($ID); } }
function test_delete() { $file = TMP_DIR . '/test.txt'; $contents = "The\nDelete\nDelete01\nDelete02\nDelete\nDeleteX\nTest\n"; io_saveFile($file, $contents); $this->assertTrue(io_deleteFromFile($file, "Delete\n")); $this->assertEquals("The\nDelete01\nDelete02\nDeleteX\nTest\n", io_readFile($file)); $this->assertTrue(io_deleteFromFile($file, "#Delete\\d+\n#", true)); $this->assertEquals("The\nDeleteX\nTest\n", io_readFile($file)); }
public function setUp() { parent::setUp(); $opts_file = dirname(DOKU_CONF) . '/data/meta/__move_opts'; if (file_exists($opts_file)) { unlink($opts_file); } $file = "oldns:page01\tnewns:page01\n" . "oldns:page02\tnewns:page02\n" . "oldns:page03\tnewns:page03\n" . "oldns:page04\tnewns:page04\n" . "oldns:page05\tnewns:page05\n" . "oldns:page06\tnewns:page06\n" . "oldns:page07\tnewns:page07\n" . "oldns:page08\tnewns:page08\n" . "oldns:page09\tnewns:page09\n" . "oldns:page10\tnewns:page10\n" . "oldns:page11\tnewns:page11\n" . "oldns:page12\tnewns:page12\n" . "oldns:page13\tnewns:page13\n" . "oldns:page14\tnewns:page14\n" . "oldns:page15\tnewns:page15\n" . "oldns:page16\tnewns:page16\n" . "oldns:page17\tnewns:page17\n" . "oldns:page18\tnewns:page18"; $file_path = dirname(DOKU_CONF) . '/data/meta/__move_pagelist'; io_saveFile($file_path, $file); }
function _log($msg) { global $conf; $user = $_SERVER['REMOTE_USER']; if (!$user) { $user = $_REQUEST['u']; } $t = time(); $log = $t . "\t" . strftime($conf['dformat'], $t) . "\t" . $_SERVER['REMOTE_ADDR'] . "\t" . $user . "\t" . $msg; io_saveFile($conf['cachedir'] . '/loglog.log', "{$log}\n", true); }
function addBook($id, $epub, $title) { $md5 = md5($id); if (!$this->is_inCache($id)) { $this->cache[$md5] = $id; } if (!isset($this->cache['current_books'])) { $this->cache['current_books'] = array(); } $this->cache['current_books'][$md5] = array('title' => $title, 'epub' => $epub); io_saveFile($this->script_file, serialize($this->cache)); }
public function test_subdirectory() { $this->setUpFiles('/foo/bar'); $import = preg_replace('#(^.*[/])#', '', $this->import); $in_css = '@import "' . $import . '";'; $in_less = '@foo: "bar"; content: @foo;'; $expected_css = '@import "/foo/bar/' . $import . '";'; $expected_less = 'content: "bar";'; io_saveFile($this->import, $in_less); $this->csstest($in_css, $expected_css, $expected_less); }
public function save($id) { $datetime = date('Y-m-d H:i:s'); $page = cleanID($id); $ipAddress = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; $agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; $logline = $datetime . ',' . $page . ',' . $ipAddress . ',"' . $referer . '","' . $agent . '"' . PHP_EOL; if (!io_saveFile($this->filename(), $logline, true)) { msg("Unable to write log404 file."); } }
/** * Builds a Google Sitemap of all public pages known to the indexer * * The map is placed in the cache directory named sitemap.xml.gz - This * file needs to be writable! * * @author Michael Hamann * @author Andreas Gohr * @link https://www.google.com/webmasters/sitemaps/docs/en/about.html * @link http://www.sitemaps.org/ */ public function generate() { global $conf; if ($conf['sitemap'] < 1 || !is_numeric($conf['sitemap'])) { return false; } $sitemap = Sitemapper::getFilePath(); if (@file_exists($sitemap)) { if (!is_writable($sitemap)) { return false; } } else { if (!is_writable(dirname($sitemap))) { return false; } } if (@filesize($sitemap) && @filemtime($sitemap) > time() - $conf['sitemap'] * 86400) { // 60*60*24=86400 dbglog('Sitemapper::generate(): Sitemap up to date'); // FIXME: only in debug mode return false; } dbglog("Sitemapper::generate(): using {$sitemap}"); // FIXME: Only in debug mode $pages = idx_getIndex('page', ''); dbglog('Sitemapper::generate(): creating sitemap using ' . count($pages) . ' pages'); $items = array(); // build the sitemap items foreach ($pages as $id) { //skip hidden, non existing and restricted files if (isHiddenPage($id)) { continue; } if (auth_aclcheck($id, '', '') < AUTH_READ) { continue; } $item = SitemapItem::createFromID($id); if ($item !== NULL) { $items[] = $item; } } $eventData = array('items' => &$items, 'sitemap' => &$sitemap); $event = new Doku_Event('SITEMAP_GENERATE', $eventData); if ($event->advise_before(true)) { //save the new sitemap $result = io_saveFile($sitemap, Sitemapper::getXML($items)); } $event->advise_after(); return $result; }
/** check permissions and send page to be processed */ function process_feed(&$event, $param) { global $ID, $INFO; $perm = $this->helper->has_permission(); if ($perm == 2 && $INFO['perm'] != 1) { //INFO['perm'] = 1 when logging out msg($this->getLang('no_permission')); return; } if ($this->helper->pageUpdated()) { $metafile = $this->helper->getMetaFN('wasupdated', '.meta'); io_saveFile($metafile, time() . "\n" . $ID . "\n"); $this->helper->saveFeedData($ID); } }
/** * Log an action * * @param $msg * @param null|string $user */ protected function _log($msg, $user = null) { global $conf; global $INPUT; if (is_null($user)) { $user = $INPUT->server->str('REMOTE_USER'); } if (!$user) { $user = $_REQUEST['u']; } if (!$user) { return; } $t = time(); $log = $t . "\t" . strftime($conf['dformat'], $t) . "\t" . $_SERVER['REMOTE_ADDR'] . "\t" . $user . "\t" . $msg; io_saveFile($conf['cachedir'] . '/loglog.log', "{$log}\n", true); }
/** * * * @param Doku_Event $event Not used * @param mixed $param Not used * @return void */ public function handle(Doku_Event &$event, $param) { global $conf; if ($event->data != 'feedaggregator') { return; } $event->preventDefault(); // See if we need a token and whether it matches. $requiredToken = $this->getConf('token'); $suppliedToken = isset($_GET['token']) ? $_GET['token'] : false; if (!empty($requiredToken) && $suppliedToken !== $requiredToken) { msg("Token doesn't match for feedaggregator"); return true; } // Get the feed list. $feeds = file(fullpath($conf['tmpdir'] . '/feedaggregator.csv')); // Set up SimplePie and merge all the feeds together. $simplepie = new FeedParser(); $ua = 'Mozilla/4.0 (compatible; DokuWiki feedaggregator plugin ' . wl('', '', true) . ')'; $simplepie->set_useragent($ua); $simplepie->force_feed($this->getConf('force_feed')); $simplepie->force_fsockopen($this->getConf('force_fsockopen')); $simplepie->set_feed_url($feeds); // Set up caching. $cacheDir = fullpath($conf['cachedir'] . '/feedaggregator'); io_mkdir_p($cacheDir); $simplepie->enable_cache(); $simplepie->set_cache_location($cacheDir); // Run the actual feed aggregation. $simplepie->init(); // Check for errors. if ($simplepie->error()) { header("Content-type:text/plain"); echo join("\n", $simplepie->error()); } // Create the output HTML and cache it for use by the syntax component. $html = ''; foreach ($simplepie->get_items() as $item) { $html .= "<div class='feedaggregator_item'>\n" . "<h2>" . $item->get_title() . "</h2>\n" . $item->get_content() . "\n" . "<p>" . " <a href='" . $item->get_permalink() . "'>Published " . $item->get_date('j M Y') . "</a> " . " in <a href='" . $item->get_feed()->get_permalink() . "'>" . $item->get_feed()->get_title() . "</a>" . "</p>\n" . "</div>\n\n"; } io_saveFile($cacheDir . '/output.html', $html); // Output nothing, as this should be run from cron and we don't want to // flood the logs with success. exit(0); }
/** * @group slow */ public function test_moveSingleMedia_colonstart() { global $AUTH_ACL; $AUTH_ACL[] = "wiki:*\t@ALL\t16"; $AUTH_ACL[] = "foobar:*\t@ALL\t8"; $filepath = DOKU_TMP_DATA . 'media/wiki/testimage.png'; io_makeFileDir($filepath); io_saveFile($filepath, ''); saveWikiText('wiki:movetest', '{{:wiki:testimage.png?200}}', 'Test initialized'); idx_addPage('wiki:movetest'); $src = 'wiki:testimage.png'; $dst = 'foobar:logo_2.png'; /** @var helper_plugin_move_op $move */ $move = plugin_load('helper', 'move_op'); $this->assertTrue($move->moveMedia($src, $dst)); $this->assertTrue(@file_exists(mediaFn('foobar:logo_2.png'))); $this->assertEquals('{{:foobar:logo_2.png?200}}', rawWiki('wiki:movetest')); }
function _autosubmit(Doku_Event &$event, $param) { //Do we have to send the data now if (!$this->helper->isAutosubmitEnabled() || $this->_isTooEarlyToSubmit()) { return; } //Actually send it $status = $this->helper->sendData($this->helper->gatherAsString()); if ($status !== '') { //If an error occured, log it io_saveFile($this->helper->autosubmitErrorFile, $status); } else { //If the data has been sent successfully, previous log of errors are useless @unlink($this->helper->autosubmitErrorFile); //Update the last time we sent data touch($this->helper->autosubmitFile); } $event->stopPropagation(); $event->preventDefault(); }
/** * Create output */ function render($mode, &$renderer, $data) { if (empty($data)) { return false; } global $ID; if ($mode == 'xhtml') { list($state, $match) = $data; switch ($state) { case DOKU_LEXER_SPECIAL: $this->helper->setUpdate($match); $metafile = metaFN('newsfeed:timestamp', '.meta'); io_saveFile($metafile, time()); $renderer->doc .= ""; break; } return true; } return false; }