-
Notifications
You must be signed in to change notification settings - Fork 3
/
create-link.php
83 lines (71 loc) · 2.74 KB
/
create-link.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
include_once(__DIR__ . '/inc/init.php');
if (fRequest::isPost()) {
fAuthorization::requireLoggedIn();
try {
$page_path = '/' . wiki_slugify(trim(fRequest::get('path')));
if (strstr($page_path, '..') || strstr($page_path, '//')) {
throw new fValidationException('There cannot be .. or // in the path');
}
$parent_path = Page::parentPage($page_path);
try {
$parent = new Page(array('path' => $parent_path));
} catch (fNotFoundException $e) {
throw new fValidationException('Please create the parent page first');
}
$user_name = wiki_get_current_user();
if (!$parent->isPermitted($user_name, 'create')) {
throw new fValidationException('You are not permitted to create links here!');
}
$dest = trim(fRequest::get('dest'));
$group_bits = array_sum(fRequest::get('group_bits', 'integer[]'));
$other_bits = array_sum(fRequest::get('other_bits', 'integer[]'));
$overwrite = fRequest::get('overwrite', 'boolean');
if (empty($dest)) {
throw new fValidationException('Destination cannot be blank.');
}
if ($group_bits < 0 or $group_bits > 7) {
throw new fValidationException('Invalid group permission bits.');
}
if ($other_bits < 0 or $other_bits > 7) {
throw new fValidationException('Invalid other permission bits.');
}
$submit = fRequest::get('submit');
if ($submit == 'Save link') {
try {
$db->query('BEGIN');
if ($overwrite) {
wiki_remove_page_by_path($db, $page_path);
}
$page = new Page();
$page->setPath($page_path);
$page->setOwnerName(wiki_get_current_user());
$page->setGroupId($groupid);
$page->setPermission($group_bits . $other_bits);
$page->setType(Page::HYPERLINK);
$page->setCreatedAt(now());
$page->store();
$hyperlink = new Hyperlink();
$hyperlink->setPageId($page->getId());
$hyperlink->setUrl($dest);
$hyperlink->setCreatedAt(now());
$hyperlink->store();
$db->query('COMMIT');
fMessaging::create('success', 'new link', $lang['link created successfully'] . ' <a target="_blank" href="' . SITE_BASE . $page->getPath() . '">Click here</a>');
fURL::redirect(wiki_new_link_path());
} catch (fException $e) {
$db->query('ROLLBACK');
throw $e;
}
} else {
throw new fValidationException('Invalid submit action.');
}
} catch (fException $e) {
fMessaging::create('failure', 'new link', $e->getMessage());
$title = $lang['New Link'];
$theme_path = wiki_theme_path(DEFAULT_THEME);
include wiki_theme(DEFAULT_THEME, 'new-link');
}
} else {
fURL::redirect(wiki_new_link_path());
}