/** * This function renders $content using the ODT-page-renderer. * It then unzips the ODT document and reads in the file contents * of the files 'content.xml', 'meta.xml' and 'styles.xml' and * saves the strings in $files ['content-xml'], $files ['meta-xml'] * and $files ['styles-xml']. * * @param array $files * @param string $content * @return boolean */ public static function getRenderedODTDocument(array &$files, $content) { // Create parser instructions for wiki page $content $instructions = p_get_instructions($content); // Render the page by looping through the instructions. $renderer = new renderer_plugin_odt_page(); foreach ($instructions as $instruction) { // Execute the callback against the Renderer if (method_exists($renderer, $instruction[0])) { call_user_func_array(array(&$renderer, $instruction[0]), $instruction[1] ? $instruction[1] : array()); } } io_savefile(TMP_DIR . '/odt/temp_test_doc.odt', $renderer->doc); $ZIP = new ZipLib(); $ok = $ZIP->Extract(TMP_DIR . '/odt/temp_test_doc.odt', TMP_DIR . '/odt/unpacked'); if ($ok == -1) { // Error unzipping document return false; } $files['content-xml'] = file_get_contents(TMP_DIR . '/odt/unpacked/content.xml'); $files['meta-xml'] = file_get_contents(TMP_DIR . '/odt/unpacked/meta.xml'); $files['styles-xml'] = file_get_contents(TMP_DIR . '/odt/unpacked/styles.xml'); // Success return true; }
function doImportTest($importCsv, $expectedResult, $expectedNewUsers, $expectedFailures) { global $auth; $before_users = $auth->retrieveUsers(); io_savefile($this->importfile, $importCsv); $result = $this->usermanager->tryImport(); $after_users = $auth->retrieveUsers(); $import_count = count($after_users) - count($before_users); $new_users = array_diff_key($after_users, $before_users); $diff_users = array_diff_assoc($after_users, $before_users); $expectedCount = count($expectedNewUsers); $this->assertEquals($expectedResult, $result); // import result as expected $this->assertEquals($expectedCount, $import_count); // number of new users matches expected number imported $this->assertEquals($expectedNewUsers, $this->stripPasswords($new_users)); // new user data matches imported user data $this->assertEquals($expectedCount, $this->countPasswords($new_users)); // new users have a password $this->assertEquals($expectedCount, $this->usermanager->mock_email_notifications_sent); // new users notified of their passwords $this->assertEquals($new_users, $diff_users); // no other users were harmed in the testing of this import $this->assertEquals($expectedFailures, $this->usermanager->getImportFailures()); // failures as expected }
/** * handle user request */ function handle() { global $conf; if (preg_match('/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/', trim($_REQUEST['ip']))) { $newban = trim($_REQUEST['ip']) . "\t" . time() . "\t" . $_SERVER['REMOTE_USER']; $cause = trim(preg_replace('/[\\n\\r\\t]+/', '', $_REQUEST['cause'])); $newban .= "\t" . $cause . "\n"; io_savefile($conf['cachedir'] . '/ipbanplugin.txt', $newban, true); } if (is_array($_REQUEST['delip'])) { $del = trim(array_shift(array_keys($_REQUEST['delip']))); $del = preg_quote($del, '/'); $new = array(); $bans = @file($conf['cachedir'] . '/ipbanplugin.txt'); if (is_array($bans)) { foreach ($bans as $ban) { if (!preg_match('/^' . $del . '\\t/', $ban)) { $new[] = $ban; } } } io_savefile($conf['cachedir'] . '/ipbanplugin.txt', join('', $new)); } }
/** * Build a ODT from the articles * * @param string $cachefile * @param string $title */ protected function generateODT($cachefile, $title) { global $ID; global $REV; /** @var renderer_plugin_odt_book $odt */ $odt = plugin_load('renderer', 'odt_book'); // store original pageid $keep = $ID; // loop over all pages $xmlcontent = ''; $cnt = count($this->list); for ($n = 0; $n < $cnt; $n++) { $page = $this->list[$n]; // set global pageid to the rendered page $ID = $page; $xmlcontent .= p_render('odt_book', p_cached_instructions(wikiFN($page, $REV), false, $page), $info); } //restore ID $ID = $keep; $odt->doc = $xmlcontent; $odt->setTitle($title); $odt->finalize_ODTfile(); // write to cache file io_savefile($cachefile, $odt->doc); }
/** * cache $instructions * * @param array $instructions the instruction to be cached * @return bool true on success, false otherwise */ public function storeCache($instructions) { if ($this->_nocache) { return false; } return io_savefile($this->cache, serialize($instructions)); }
/** * Upload a theme into my site * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Samuele Tognini <*****@*****.**> */ function upload($theme, $info) { $return = true; $host = 'samuele.netsons.org'; $path = '/dokuwiki/lib/plugins/indexmenu/upload/index.php'; //TODO: merge zip creation with that in ajax.php (create a class?) if (!($absdir = $this->checktmpsubdir())) { return false; } $tmp = $absdir . "/tmp"; $zipfile = "{$theme}.zip"; $filelist = "{$absdir}/{$theme}"; //create info if (!empty($info)) { io_savefile("{$tmp}/{$theme}/info.txt", $info); $filelist .= ",{$tmp}/{$theme}"; } //create zip $zip = new PclZip("{$tmp}/{$zipfile}"); $status = $zip->create($filelist, PCLZIP_OPT_REMOVE_ALL_PATH); if ($status == 0) { //error msg($this->getLang('zip_err') . ": " . $zip->errorName(true), -1); $return = false; } else { //prepare POST headers. $boundary = "---------------------------" . uniqid(""); $data = join("", file("{$tmp}/{$zipfile}")); $header = "POST {$path} HTTP/1.0\r\n"; $header .= "Host: {$host}\r\n"; $header .= "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1) Gecko/20061024 Iceweasel/2.0 (Debian-2.0+dfsg-1)\r\n"; $header .= "Content-type: multipart/form-data, boundary={$boundary}\r\n"; $body = "--" . $boundary . "\r\n"; $body .= "Content-Disposition: form-data; name=\"userfile\"; filename=\"{$zipfile}\"\r\n"; $body .= "Content-Type: application/x-zip-compressed\r\n\r\n"; $body .= $data . "\r\n"; $body .= "--" . $boundary . "\r\n"; $body .= "Content-Disposition: form-data; name=\"upload\"\r\n\r\n"; $body .= "Upload\r\n"; $body .= "--" . $boundary . "--\r\n"; $header .= "Content-Length: " . strlen($body) . "\r\n\r\n"; //connect and send zip if ($fp = fsockopen($host, 80)) { fwrite($fp, $header . $body); //reply $buf = ""; while (!feof($fp)) { $buf .= fgets($fp, 3200); } fclose($fp); //parse resply if (preg_match("/<!--indexmenu-->(.*)<!--\\/indexmenu-->/s", $buf, $match)) { $str = substr($match[1], 4, 7); switch ($str) { case "ERROR ": $mesg_type = -1; break; case "SUCCESS": $mesg_type = 1; break; default: $mesg_type = 2; } msg($match[1], $mesg_type); } else { $return = false; } } else { $return = false; } } $this->_rm_dir($tmp); return $return; }
function storeCache($instructions) { return io_savefile($this->cache, serialize($instructions)); }
/** * Allow rerites in this process again, unless some other lock exists */ public static function removeLock() { global $PLUGIN_MOVE_WORKING; global $conf; $PLUGIN_MOVE_WORKING = $PLUGIN_MOVE_WORKING ? $PLUGIN_MOVE_WORKING - 1 : 0; $lockfile = $conf['lockdir'] . self::LOCKFILENAME; if (!file_exists($lockfile)) { throw new Exception("removeLock failed: lockfile missing"); } else { $stack = intval(file_get_contents($lockfile)); if ($stack === 1) { unlink($lockfile); } else { --$stack; io_savefile($lockfile, strval($stack)); } } }