/** * mkdir recursively (mkdir of PHP5 has recursive flag) * * PHP Compat * * @access public * @static * @param string $dir * @param int $mode * @return boolean success or failure * @see php_compat_mkdir($dir, $mode, $recurstive, $context) * @version $Id: v 1.0 2008-06-05 11:14:46 sonots $ */ function r_mkdir($dir, $mode = 0755) { if (is_dir($dir) || @mkdir($dir, $mode)) { return true; } if (!r_mkdir(dirname($dir), $mode)) { return false; } return @mkdir($dir, $mode); }
/** * Dump the PukiWiki output of a page into a html file * * @param string $page Pagename * @param string $file Filename to be dumped. Default is computed from $page. * @param boolean $overwrite Force to overwrite. Default overwrites if $page is newer than $file * @param boolean $notimestamp Do not change timestamp for dumped file * @return mixed * TRUE : Success * FALSE: Failure * -1 : It is already up2date * -2 : Exit by read-restriction * -3 : Exit because statichtml USER_AGENT called statichtml again (infinite loop) */ function dump_page($page, $file = null, $overwrite = FALSE, $notimestamp = FALSE) { // statichtml USER_AGENT should not call statichtml again (avoid infinite loop) if (isset($GLOBALS['vars'][$this->plugin])) { return -3; } // Initialization if (!isset($file)) { $file = $this->get_dump_filename($page); } if (!is_page($page)) { if (file_exists($file)) { pkwk_chown($file); @unlink($file); } return TRUE; } // Up2date? if (!$overwrite && !is_page_newer($page, $file)) { return -1; } // Try to create dir $dir = dirname($file); if (isset($GLOBALS['PLUGIN_STATICHTML_MKDIR_CGI'])) { $error = file_get_contents($GLOBALS['PLUGIN_STATICHTML_MKDIR_CGI'] . '&mode=0777&dir=' . $dir); if ($error != '1') { $this->error = 'Failed to create ' . $dir . ' directory.'; return FALSE; } } else { if (r_mkdir($dir) === FALSE) { $this->error = 'Failed to create ' . $dir . ' directory.'; return FALSE; } } // Get contents if (is_read_auth($page) && !$this->CONF['readauth']) { return -2; // Do not read read-restriction pages } if (($contents = $this->http_pkwk_output($page)) === FALSE) { return -2; // HTTP GET failure (mostly because of read-restriction) } // Write $filemtime = file_exists($file) && $notimestamp ? filemtime($file) : FALSE; if (!file_put_contents($file, $contents)) { $this->error = 'Failed to create ' . $file; return FALSE; } if ($notimestamp) { pkwk_touch_file($file, $filemtime, $filemtime); } return TRUE; }