function inline() { if (func_num_args() == 0) { return 'tag(): no argument(s). '; } global $vars, $defaultpage; $page = isset($vars['page']) ? $vars['page'] : $defaultpage; $args = func_get_args(); array_pop($args); // drop {} $tags = $args; if (isset($vars['preview']) || isset($vars['realview']) || is_page_newer($page, $this->get_tags_filename($page))) { $this->save_tags($page, $tags); } return $this->display_tags($page); }
/** * Read cache * * @param $apage pagename * @return mixed contents or FALSE if cache should be renewed */ function read_cache($apage) { if ($this->options['cache'][1] == 'off' || $this->options['cache'][1] == 'reset') { return false; } if (!is_page($apage)) { return false; } $cache = $this->get_cache_filename($apage); if (!$this->file_exists($cache)) { return false; } if (!$this->is_readable($cache)) { $this->error = "Cache file, {$cache} is not readable. "; return; } $lines = file($cache); $pages = csv_explode(',', rtrim(array_shift($lines))); foreach ($pages as $page) { list($page, $title) = csv_explode('=', $page); $visited[$page] = $title; } // renew cache if preview mode if (isset($vars['preview']) || isset($vars['realview'])) { return false; } // renew cache if page is newer than cache foreach ($visited as $page => $title) { if (is_page_newer($page, $cache)) { return false; } } $this->visited = $visited; $metalines = array(); foreach ($lines as $line) { $metas = csv_explode(',', rtrim($line)); $metaline = array(); foreach ($metas as $meta) { list($key, $val) = explode('=', $meta, 2); $metaline[$key] = $val; } $metalines[] = $metaline; } $this->metalines = $metalines; }
/** * 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; }
/** * Read cache * * @param string $page page name * @param string $cache cache file name * @param string $reset reset option 'on', 'off', 'new', seconds * @return mixed contents or FALSE if cache should be renewed */ function read_cache($page, $cache, $reset = 'off') { global $vars; if (isset($vars['preview']) || isset($vars['realview'])) { return FALSE; } if ($reset === 'on') { return FALSE; } elseif ($reset === 'new') { if (is_page_newer($page, $cache)) { return FALSE; } } elseif (is_numeric($reset)) { if (is_page_newer($page, $cache)) { return FALSE; } $cachestamp = file_exists($cache) ? filemtime($cache) : 0; if (time() > $cachestamp + $sleep) { return FALSE; } } return file_get_contents($cache); }