本文整理汇总了PHP中Page::exists方法的典型用法代码示例。如果您正苦于以下问题:PHP Page::exists方法的具体用法?PHP Page::exists怎么用?PHP Page::exists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Page
的用法示例。
在下文中一共展示了Page::exists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCopy
/**
* ページデータをコピーする
*
* @param int $id ページID
* @param array $data コピーしたいデータ
* @param array $expected 期待値
* @param string $message テストが失敗した時に表示されるメッセージ
* @dataProvider copyDataProvider
*/
public function testCopy($id, $data, $expected, $message = null)
{
$data = array('Page' => $data);
$result = $this->Page->copy($id, $data);
// コピーしたファイル存在チェック
$path = getViewPath() . 'Pages' . $result['Page']['url'] . '.php';
$this->assertFileExists($path, $message);
@unlink($path);
// DBに書き込まれているかチェック
$exists = $this->Page->exists($result['Page']['id']);
$this->assertTrue($exists);
}
示例2: testCopy
/**
* ページデータをコピーする
*
* @param int $id ページID
* @param int $newParentId 新しい親コンテンツID
* @param string $newTitle 新しいタイトル
* @param int $newAuthorId 新しい作成者ID
* @param int $newSiteId 新しいサイトID
* @param string $message テストが失敗した時に表示されるメッセージ
* @dataProvider copyDataProvider
*/
public function testCopy($id, $newParentId, $newTitle, $newAuthorId, $newSiteId, $message = null)
{
$this->_loginAdmin();
$result = $this->Page->copy($id, $newParentId, $newTitle, $newAuthorId, $newSiteId);
// コピーしたファイル存在チェック
$path = APP . 'View' . DS . 'Pages' . $result['Content']['url'] . '.php';
$this->assertFileExists($path, $message);
@unlink($path);
// DBに書き込まれているかチェック
$exists = $this->Page->exists($result['Page']['id']);
$this->assertTrue($exists);
}
示例3: pieCleanString
if ($_POST['source']) {
// User provided input via HTTP request.
$_REQUEST['source'] = pieCleanString($_REQUEST['source']);
$_REQUEST['title'] = pieGetOption($_REQUEST['title']);
$_REQUEST['comment'] = pieGetOption($_REQUEST['comment']);
} elseif (file_exists($preview)) {
// Read source and meta data from temporary preview file.
if (!($dump = file_get_contents($preview))) {
pieError("SourceReadError");
}
$meta = pieExplodePage($dump);
foreach (array('source', 'title', 'comment') as $i) {
$_REQUEST[$i] = $meta[$i];
}
unset($meta);
} elseif ($page->exists($_REQUEST['page'])) {
// The page already exists. Use and edit the existing source.
$diff = new Increment();
if (!($meta = $diff->readPage($_REQUEST['page'], $_REQUEST['stamp']))) {
pieError("SourceVersionMissing");
}
$_REQUEST['source'] = $meta['source'];
if ($_REQUEST['section'] > 0) {
$section = new Section();
// Extract the specified section.
if (($_REQUEST['source'] = $section->extract($meta['source'], $_REQUEST['section'])) === false) {
pieError('SectionNotFound');
}
}
if ($meta['type'] == "alias") {
// The existing page is an alias.
示例4: pieError
pieError('SourceWriteError');
}
fclose($f);
} elseif (file_exists($preview)) {
// Read the data from the temporary preview file.
if (!($dump = file_get_contents($preview))) {
pieError("SourceReadError");
}
$meta = pieExplodePage($dump);
$_REQUEST['source'] = trim($meta['source']);
} else {
// No source available.
pieError("SourceReadError");
}
// Handle partial updates.
if (@$_REQUEST['section'] > 0 && $page->exists(@$_REQUEST['page'])) {
if (!$page->read($_REQUEST['page'], 0)) {
pieError('SourceReadError');
}
if ($page->meta['type'] != 'full' && $page->meta['type'] != 'shadow') {
pieError('SectionNotFound');
}
// Determine the text that come before and after the edited section.
$section = new Section();
if (($p = $section->offset($page->source, $_REQUEST['section'])) === false) {
pieError('SectionNotFound');
}
if (($old = $section->extract($page->source, $_REQUEST['section'])) === false) {
pieError('SectionNotFound');
}
$_REQUEST['source'] = substr($page->source, 0, $p) . rtrim($_REQUEST['source']) . "\n\n" . substr($page->source, $p + strlen($old));
示例5: elseif
} elseif (@$_REQUEST['mode'] == "links") {
// Walk all pages and examine their links.
// Collect a list of _links_, i. e. destinations of broken links.
$page = new Page();
$file = new File();
$deadpages = array();
$deadfiles = array();
for ($name = $page->first(); $name; $name = $page->next()) {
if (!$page->read($name, 0)) {
pieError("SourceReadError");
}
if ($page->meta['pages']) {
// There are page links that are to be checked.
$list = explode(" ", $page->meta['pages']);
foreach ($list as $i) {
if (!$page->exists($i)) {
$deadpages[$i]++;
}
}
}
if ($page->meta['files']) {
// There are file links that are to be checked.
$list = explode(" ", $page->meta['files']);
foreach ($list as $i) {
if (!$file->exists($i)) {
$deadfiles[$i]++;
}
}
}
}
if (!count($deadpages) && !count($deadfiles)) {
示例6: pieGetOption
/*
* Display information about the current version of a page.
*/
include_once "{$lib}/class/page.php";
include_once "{$lib}/share/stdio.php";
include_once "{$lib}/share/string.php";
pieHead();
$_REQUEST['page'] = pieGetOption(@$_REQUEST['page']);
$page = new Page();
$page->name = $_REQUEST['page'];
// Sanity check:
if (!$page->isValidName($_REQUEST['page'])) {
pieError("PageNameInvalid");
}
if (!$page->exists($_REQUEST['page'])) {
pieError("PageNotFound");
}
if (intval($_REQUEST['stamp']) > 0) {
$stamp = $_REQUEST['stamp'];
} else {
$stamp = 0;
}
$page->read($_REQUEST['page'], $stamp);
$stamp = $page->meta['stamp'];
// Check for alias:
if ($page->meta['type'] == "alias") {
pieError("AliasRedirect", array('page' => htmlspecialchars($page->meta['original']), 'alias' => htmlspecialchars($_REQUEST['page'])));
}
// Prepare output:
$data = array('page_count' => 0, 'file_count' => 0);
示例7: pieError
pieError("ImportError");
}
// Browse directory for the first time to check for pages
// that already exist in the current name space.
$total = 0;
$count = 0;
$page = new Page();
while (($file = readdir($dh)) !== false) {
if ($file == "." || $file == "..") {
continue;
}
$name = decodeName($file);
if (!$page->isValidName($name)) {
pieError("InvalidName", array('page' => htmlspecialchars($name)));
}
if ($page->exists($name)) {
pieError("PageExists", array('page' => htmlspecialchars($name)));
}
$total++;
}
// Walk directory for the second time. This time, encountered
// files (and pages contained therein) are imported for real.
rewinddir($dh);
while (($file = readdir($dh)) !== false) {
if ($file == "." || $file == "..") {
continue;
}
if (!importFile($_REQUEST['path'] . "/{$file}")) {
pieError("ImportError", array('page' => htmlspecialchars($file)));
}
$count++;
示例8: site_create_from_sitemap
private function site_create_from_sitemap()
{
$db = DB::connect();
$domain = parse_url($_POST['url'], PHP_URL_HOST);
if (!Site::exists($domain)) {
$pagerank = Google::get_pagerank($domain);
$db->exec("INSERT INTO site VALUES('', '{$domain}', '{$pagerank}')");
}
if (!($xml = simplexml_load_file($_POST['url']))) {
trigger_error('Unable to load sitemap at ' . $_POST['url'], E_USER_ERROR);
header('HTTP/1.1 302 Found');
header("Location: " . Options::get('base_url'));
exit;
}
foreach ($xml->url as $url) {
if (!Page::exists($url->loc)) {
$db->exec("INSERT INTO page VALUES('', '{$url->loc}', '')");
// @todo update page metrics
}
}
}
示例9: pieError
// Read the source from a temporary preview file.
if (!($meta = file_get_contents($preview))) {
pieError("SourceReadError");
}
$meta = pieExplodePage($meta);
foreach ($meta as $k => $v) {
$_REQUEST[$k] = $v;
}
} else {
// No source available.
pieError("SourceEmpty");
}
$_REQUEST['source'] = preg_replace('/\\x0a{3,}/s', "\n\n", @$_REQUEST['source']);
// Prepare the previous version for examination.
$current = new Page();
if ($page->exists($page->name)) {
if (!$current->read($page->name, 0)) {
pieError('SourceReadError');
}
if (trim($current->source) == $_REQUEST['source']) {
// No changes have been made.
pieError('NoChanges');
}
}
// Handle section updates.
$_REQUEST['section'] = intval(@$_REQUEST['section']);
if ($_REQUEST['section'] > 0 && $page->exists($page->name)) {
if ($current->meta['type'] == 'alias') {
pieError('SectionNotFound');
}
// Determine the text chunks that come before and after the edited
示例10: pieGetOption
include_once "{$lib}/class/page.php";
include_once "{$lib}/class/file.php";
include_once "{$lib}/share/link.php";
include_once "{$lib}/share/stdio.php";
include_once "{$lib}/share/string.php";
pieLoadLocale();
pieHead();
if (@$_REQUEST['page']) {
// Preparations for pages.
$_REQUEST['page'] = pieGetOption($_REQUEST['page']);
$resource = new Page();
$resource->name = $_REQUEST['page'];
if (!$resource->isValidName($_REQUEST['page'])) {
pieError("PageNameInvalid");
}
if (!$resource->exists($_REQUEST['page'])) {
pieError("PageNotFound");
}
if (!$resource->read($_REQUEST['page'], 0)) {
pieError("SourceReadError");
}
if ($resource->meta['type'] == "alias") {
pieError("AliasRedirect", array('page' => htmlspecialchars($resource->meta['original']), 'alias' => htmlspecialchars($_REQUEST['page'])));
}
$context = 'page';
$history = $resource->history($_REQUEST['page']);
} elseif (@$_REQUEST['file']) {
// Preparations for files.
$_REQUEST['file'] = pieGetOption($_REQUEST['file']);
$resource = new File();
$resource->name = $_REQUEST['file'];
示例11: writePage
function writePage($name, $meta)
{
if (!$meta['stamp']) {
$meta['stamp'] = time();
}
$page = new Page();
if (!$page->isValidName($name)) {
return false;
}
if (!$page->exists($name)) {
return $this->_writeFullSource($name, $meta);
}
// Determine the current diff level.
$work = $meta;
$work['parent'] = 0;
for ($level = 0; $work['type'] != 'full'; $level++) {
if (!$page->read($name, $work['parent'])) {
return false;
}
$work = $page->meta;
}
$max = intval($GLOBALS['pie']['max_diff_level']);
if ($max > 0 && $level > $max) {
return $this->_writeFullSource($name, $meta);
}
// Determine the version to be referred to as parent.
if (!($current = $this->readPage($name, 0))) {
return false;
}
$meta['parent'] = $current['stamp'];
// Create a diff between the latest version and the new one.
if (!($diff = $this->diff($current['source'], $meta['source']))) {
return false;
}
if (strlen($meta['source']) - strlen($diff) < 100) {
// The diff is not much smaller (or even larger)
// than the original source.
// Write a full version instead of just a diff.
unset($meta['parent']);
return $this->_writeFullSource($name, $meta);
}
// Note:
// At this stage, it is decided to write a diff instead
// of a full version.
// If the current page is an alias, delete it altogether,
// to be replaced by a real page with the current data.
if ($current['type'] == 'alias') {
if (!$page->delete($name)) {
return false;
}
}
// Replace the latest shadow, if any.
$replace = false;
if ($current['type'] == 'shadow') {
$replace = true;
}
// Write a diff.
$page->name = $name;
$page->source = $diff;
$full = $meta['source'];
unset($meta['source']);
$meta['type'] = 'diff';
$page->meta = $meta;
if (!$page->write($replace)) {
return false;
}
// Create an additional shadow record including the full source.
$page->source = $full;
$page->meta['type'] = 'shadow';
return $page->write(false);
}
示例12: elseif
$target = $_REQUEST['page'];
$context = "page";
} elseif (@$_REQUEST['file'] && !@$_REQUEST['page']) {
$_REQUEST['file'] = pieGetOption($_REQUEST['file']);
$target = $_REQUEST['file'];
$context = "file";
} else {
pieError("ActionInvalid");
}
// Page or file?
if ($context == "page") {
$object = new Page();
if (!$object->isValidName($target)) {
pieError("PageNameInvalid");
}
if (!$object->exists($target)) {
pieError("PageNotFound");
}
if (!$object->read($target, 0)) {
pieError("SourceReadError");
}
// Lock the page.
if (!$object->lock($GLOBALS['pie']['user'])) {
pieError("PageLockError");
}
} elseif ($context == "file") {
$object = new File();
if (!$object->isValidName($target)) {
pieError("FileNameInvalid");
}
if (!$object->exists($target)) {
示例13: onProtectionSave
public static function onProtectionSave(Page $article, &$errorMsg)
{
global $wgUser, $wgRequest;
if (!$article->exists()) {
return true;
// simple custom levels set for action=protect
} elseif (!FlaggedRevs::inReviewNamespace($article->getTitle())) {
return true;
// not a reviewable page
} elseif (wfReadOnly() || !$wgUser->isAllowed('stablesettings')) {
return true;
// user cannot change anything
}
$form = new PageStabilityProtectForm($wgUser);
$form->setPage($article->getTitle());
// target page
$permission = $wgRequest->getVal('mwStabilityLevel');
if ($permission == "none") {
$permission = '';
// 'none' => ''
}
$form->setAutoreview($permission);
// protection level (autoreview restriction)
$form->setWatchThis(null);
// protection form already has a watch check
$form->setReasonExtra($wgRequest->getText('mwProtect-reason'));
// manual
$form->setReasonSelection($wgRequest->getVal('wpProtectReasonSelection'));
// dropdown
$form->setExpiryCustom($wgRequest->getVal('mwStabilizeExpiryOther'));
// manual
$form->setExpirySelection($wgRequest->getVal('mwStabilizeExpirySelection'));
// dropdown
$form->ready();
// params all set
if ($wgRequest->wasPosted() && $form->isAllowed()) {
$status = $form->submit();
if ($status !== true) {
$errorMsg = wfMsg($status);
// some error message
}
}
return true;
}
示例14: elseif
$source = $_REQUEST['page'];
$context = "page";
} elseif (@$_REQUEST['file'] && !@$_REQUEST['page']) {
$_REQUEST['file'] = pieGetOption($_REQUEST['file']);
$source = $_REQUEST['file'];
$context = "file";
} else {
pieError("ActionInvalid");
}
// Validate the source: page or file?
if ($context == "page") {
$object = new Page();
if (!$object->isValidName($source)) {
pieError("PageNameInvalid");
}
if (!$object->exists($source)) {
pieError("PageNotFound");
}
if (!$object->read($source, 0)) {
pieError("SourceReadError");
}
// Lock the page.
if (!$object->lock($GLOBALS['pie']['user'])) {
pieError("PageLockError");
}
} elseif ($context == "file") {
$object = new File();
if (!$object->isValidName($source)) {
pieError("FileNameInvalid");
}
if (!$object->exists($source)) {
示例15: pieGetOption
include_once "{$lib}/class/page.php";
include_once "{$lib}/class/locale.php";
include_once "{$lib}/share/link.php";
include_once "{$lib}/share/stdio.php";
include_once "{$lib}/share/string.php";
include_once "{$lib}/share/referers.php";
pieLoadLocale();
pieHead();
// Verify the input.
if (@$_REQUEST['page'] && !@$_REQUEST['file']) {
$resource = pieGetOption($_REQUEST['page']);
$page = new Page();
if (!$page->isValidName($resource)) {
pieError("PageNameInvalid");
}
if (!$page->exists($resource)) {
pieError("PageNotFound");
}
$context = "page";
} elseif (@$_REQUEST['file'] && !@$_REQUEST['page']) {
$resource = pieGetOption($_REQUEST['file']);
$file = new File();
if (!$file->isValidName($resource)) {
pieError("FileNameInvalid");
}
if (!$file->exists($resource)) {
pieError("FileNotFound");
}
$context = "file";
} else {
pieError("ActionInvalid");