function ParseSerializedPage($text, $default_pagename, $user) { if (!preg_match('/^a:\\d+:{[si]:\\d+/', $text)) { return false; } $pagehash = unserialize($text); // Split up pagehash into four parts: // pagename // content // page-level meta-data // revision-level meta-data if (!defined('FLAG_PAGE_LOCKED')) { define('FLAG_PAGE_LOCKED', 1); } $pageinfo = array('pagedata' => array(), 'versiondata' => array()); $pagedata =& $pageinfo['pagedata']; $versiondata =& $pageinfo['versiondata']; // Fill in defaults. if (empty($pagehash['pagename'])) { $pagehash['pagename'] = $default_pagename; } if (empty($pagehash['author'])) { $pagehash['author'] = $user->getId(); } foreach ($pagehash as $key => $value) { switch ($key) { case 'pagename': case 'version': case 'hits': $pageinfo[$key] = $value; break; case 'content': $pageinfo[$key] = join("\n", $value); break; case 'flags': if (($value & FLAG_PAGE_LOCKED) != 0) { $pagedata['locked'] = 'yes'; } break; case 'owner': case 'created': $pagedata[$key] = $value; break; case 'acl': case 'perm': $pagedata['perm'] = ParseMimeifiedPerm($value); break; case 'lastmodified': $versiondata['mtime'] = $value; break; case 'author': case 'author_id': case 'summary': $versiondata[$key] = $value; break; } } return $pageinfo; }
function ParseMimeifiedPages($data) { if (!($headers = ParseRFC822Headers($data)) || empty($headers['content-type'])) { //trigger_error( sprintf(_("Can't find %s"),'content-type header'), // E_USER_WARNING ); return false; } $typeheader = $headers['content-type']; if (!(list($type, $subtype, $params) = ParseMimeContentType($typeheader))) { trigger_error(sprintf("Can't parse %s: (%s)", 'content-type', $typeheader), E_USER_WARNING); return false; } if ("{$type}/{$subtype}" == 'multipart/mixed') { return ParseMimeMultipart($data, $params['boundary']); } else { if ("{$type}/{$subtype}" != 'application/x-phpwiki') { trigger_error(sprintf("Bad %s", "content-type: {$type}/{$subtype}"), E_USER_WARNING); return false; } } // FIXME: more sanity checking? $page = array(); $pagedata = array(); $versiondata = array(); $pagedata['date'] = strtotime($headers['date']); //DONE: support owner and acl foreach ($params as $key => $value) { if (empty($value)) { continue; } $value = rawurldecode($value); switch ($key) { case 'pagename': case 'version': $page[$key] = $value; break; case 'flags': if (preg_match('/PAGE_LOCKED/', $value)) { $pagedata['locked'] = 'yes'; } break; case 'owner': case 'created': case 'hits': $pagedata[$key] = $value; break; case 'acl': case 'perm': if (class_exists('PagePermission')) { $pagedata['perm'] = ParseMimeifiedPerm($value); } break; case 'lastmodified': $versiondata['mtime'] = $value; break; case 'author': case 'author_id': case 'summary': case 'markup': case 'pagetype': $versiondata[$key] = $value; break; } } // FIXME: do we need to try harder to find a pagename if we // haven't got one yet? if (!isset($versiondata['author'])) { global $request; if (is_object($request)) { $user = $request->getUser(); $versiondata['author'] = $user->getId(); //FIXME:? } } $encoding = strtolower($headers['content-transfer-encoding']); if ($encoding == 'quoted-printable') { $data = QuotedPrintableDecode($data); } else { if ($encoding && $encoding != 'binary') { ExitWiki(sprintf("Unknown %s", 'encoding type: $encoding')); } } $data .= GenerateFootnotesFromRefs($params); $page['content'] = preg_replace('/[ \\t\\r]*\\n/', "\n", chop($data)); $page['pagedata'] = $pagedata; $page['versiondata'] = $versiondata; return array($page); }