function savePage($data, $options = array()) { global $DBInfo; $time = time(); $date = gmdate('Y-m-d H:i:s', $time); $ip = $_SERVER['REMOTE_ADDR']; $info = "{$ip},{$time},{$data['name']},{$data['pass']},{$data['email']},{$data['home']},{$data['subject']},"; $info .= "\"{$data['categories']}\",\"{$data['files']}\",\"{$data['summary']}\""; if ($data['no']) { # check password $id =& $data['no']; $body = $this->getPage($id); $comments = ''; if ($body != null) { include_once 'lib/metadata.php'; #list($meta,$body)=explode("\n\n",$body,2); #$metas=getMetadata($meta,1); list($metas, $nbody) = _get_metadata($body); if ($nbody) { $body = $nbody; } $data['name'] = $metas['Name']; $updated = "\nUpdated: " . gmdate('Y-m-d H:i:s', time()); $boundary = strtoupper(md5("COMMENT")); # XXX list($body, $comments) = explode('----' . $boundary . "\n", $body, 2); # XXX } else { return false; } } else { $id = $this->incCurrent(); $this->incCount(); $this->counter->incCounter($id, $options); $this->updateIndex($id, $info); } $message = <<<EOF Name: {$data['name']} Subject: {$data['subject']} Date: {$date}{$updated} Email: {$data['email']} HomePage: {$data['home']} IP: {$ip} {$data['text']} EOF; if ($comments) { $message .= '----' . $boundary . "\n" . $comments; } $log = $_SERVER['REMOTE_ADDR'] . ';;' . $data['name'] . ';;' . $comment; $options['log'] = $log; $options['pagename'] = $this->bbsname . ':' . $data['no']; $ret = $DBInfo->_savePage($this->getPageKey($id), $message, $options); if (!empty($data['attach'])) { $cache = new Cache_Text('attachments'); $cache->update($options['pagename'], $data['attach']); } return true; }
function get_instructions($body = '', $params = array()) { global $Config; $pikeys = array('#redirect', '#action', '#title', '#notitle', '#keywords', '#noindex', '#format', '#filter', '#postfilter', '#twinpages', '#notwins', '#nocomment', '#comment', '#language', '#camelcase', '#nocamelcase', '#cache', '#nocache', '#alias', '#linenum', '#nolinenum', '#description', '#image', '#noads', '#singlebracket', '#nosinglebracket', '#rating', '#norating', '#nodtd'); $pi = array(); $format = ''; // get page format from $pagetype if (empty($this->pi['#format']) and !empty($Config['pagetype'])) { preg_match('%(:|/)%', $this->name, $sep); $key = strtok($this->name, ':/'); if (isset($Config['pagetype'][$key]) and $f = $Config['pagetype'][$key]) { $p = preg_split('%(:|/)%', $f); $p2 = strlen($p[0] . $p[1]) + 1; $p[1] = $p[1] ? $f[strlen($p[0])] . $p[1] : ''; $p[2] = $p[2] ? $f[$p2] . $p[2] : ''; $format = $p[0]; if ($sep[1]) { # have : or / $format = $sep[1] == $p[1][0] ? substr($p[1], 1) : ($sep[1] == $p[2][0] ? substr($p[2], 1) : 'plain'); } } else { if (isset($Config['pagetype']['*'])) { $format = $Config['pagetype']['*']; } } // default page type } else { if (empty($body) and !empty($this->pi['#format'])) { $format = $this->pi['#format']; } } $update_pi = false; if (empty($body)) { if (!$this->exists()) { return array(); } if (isset($this->pi)) { return $this->pi; } $pi_cache = new Cache_text('PI'); if (empty($params['refresh']) and $this->mtime() < $pi_cache->mtime($this->name)) { $pi = $pi_cache->fetch($this->name); if (!isset($pi['#format'])) { $pi['#format'] = $Config['default_markup']; } return $pi; } $body = $this->get_raw_body(); $update_pi = true; } if (!empty($Config['use_metadata'])) { // FIXME experimental include_once 'lib/metadata.php'; list($this->metas, $nbody) = _get_metadata($body); if ($nbody != null) { $body = $nbody; } } if (!$format and $body[0] == '<') { list($line, $dummy) = explode("\n", $body, 2); if (substr($line, 0, 6) == '<?xml ') { #$format='xslt'; $format = 'xsltproc'; } elseif (preg_match('/^<\\?php(\\s|\\b)/', $line)) { $format = 'php'; } # builtin php detect } else { if ($body[0] == '#' and $body[1] == '!') { list($format, $body) = explode("\n", $body, 2); $format = rtrim(substr($format, 2)); } // not parsed lines are comments $notparsed = array(); $pilines = array(); $body_start = 0; while ($body and $body[0] == '#') { $body_start++; # extract first line list($line, $body) = explode("\n", $body, 2); if ($line == '#') { break; } else { if ($line[1] == '#') { $notparsed[] = $line; continue; } } $pilines[] = $line; $val = ''; if (($pos = strpos($line, ' ')) !== false) { list($key, $val) = explode(' ', $line, 2); } else { $key = trim($line); } $key = strtolower($key); $val = trim($val); if (in_array($key, $pikeys)) { $pi[$key] = $val ? $val : 1; } else { $notparsed[] = $line; array_pop($pilines); } } $piline = implode("\n", $pilines); $piline = $piline ? $piline . "\n" : ''; # if (isset($pi['#notwins'])) { $pi['#twinpages'] = 0; } if (isset($pi['#nocamelcase'])) { $pi['#camelcase'] = 0; } if (isset($pi['#nocache'])) { $pi['#cache'] = 0; } if (isset($pi['#nofilter'])) { unset($pi['#filter']); } if (isset($pi['#nosinglebracket'])) { $pi['#singlebracket'] = 0; } if (isset($pi['#nolinenum'])) { $pi['#linenum'] = 0; } } if (empty($pi['#format']) and !empty($format)) { $pi['#format'] = $format; } // override default if (!empty($pi['#format']) and ($p = strpos($pi['#format'], ' ')) !== false) { $pi['args'] = substr($pi['#format'], $p + 1); $pi['#format'] = substr($pi['#format'], 0, $p); } if (!empty($piline)) { $pi['raw'] = $piline; } if (!empty($body_start)) { $pi['start_line'] = $body_start; } if ($update_pi) { $pi_cache->update($this->name, $pi); $this->cache_instructions($pi, $params); } if (!isset($pi['#format'])) { $pi['#format'] = $Config['default_markup']; } return $pi; }