/
project.php
124 lines (116 loc) · 4.33 KB
/
project.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
class Project extends Feathers implements Feather {
public function __init() {
$this->setField(
array("attr" => "title",
"type" => "text",
"label" => __("Title", "project"),
"optional" => true));
$this->setField(
array("attr" => "project_url",
"type" => "text",
"label" => __("URL", "project"),
"optional" => false));
$this->setField(
array("attr" => "client",
"type" => "text",
"label" => __("Client", "project"),
"optional" => true));
$this->setField(
array("attr" => "client_url",
"type" => "text",
"label" => __("Client URL", "project"),
"optional" => true));
$this->setField(
array("attr" => "description",
"type" => "text_block",
"label" => __("Description", "project"),
"optional" => false));
$this->setField(
array("attr" => "image",
"type" => "file",
"label" => __("Image", "project")));
$this->respondTo("admin_write_post", "swfupload");
$this->respondTo("admin_edit_post", "swfupload");
$this->setFilter("description", "markup_post_text");
$this->setFilter("title", "markup_post_title");
$this->respondTo("delete_post", "delete_file");
$this->respondTo("admin_write_post", "swfupload");
$this->respondTo("admin_edit_post", "swfupload");
}
public function submit() {
if(empty($_POST['description']))
error(__("Error"), __("Description can't be blank."));
if(empty($_POST['project_url']))
error(__("Error"), __("URL can't be blank."));
fallback($_POST['slug'], sanitize($_POST['title']));
if (!isset($_POST['filename'])) {
if (isset($_FILES['image']) and $_FILES['image']['error'] == 0)
$filename = upload($_FILES['image'], array("jpg", "jpeg", "png", "gif", "bmp"));
else
error(__("Error"), __("Couldn't upload photo."));
} else
$filename = $_POST['filename'];
return Post::add(
array("title" => $_POST['title'],
"description" => $_POST['description'],
"filename" => $filename,
"client" => $_POST['client'],
"project_url" => $_POST['project_url'],
"client_url" => $_POST['client_url']),
$_POST['slug'],
Post::check_url($_POST['slug']));
}
public function update() {
$post = new Post($_POST['id']);
if(empty($_POST['description']))
error(__("Error"), __("Description can't be blank."));
if(empty($_POST['project_url']))
error(__("Error"), __("URL can't be blank."));
if(!isset($_POST['filename'])) {
if (isset($_FILES['image']) and $_FILES['image']['error'] == 0) {
$this->delete_file($post);
$filename = upload($_FILES['image'], array("jpg", "jpeg", "png", "gif", "tiff", "bmp"));
} else {
$filename = $post->filename;
}
} else {
$this->delete_file($post);
$filename = $_POST['filename'];
}
$post->update(
array("title" => $_POST['title'],
"description" => $_POST['description'],
"filename" => $filename,
"client" => $_POST['client'],
"project_url" => $_POST['project_url'],
"client_url" => $_POST['client_url']));
}
public function title($post) {
if(!empty($post->client))
return fallback($post->title, $post->client, true);
else
return fallback($post->title, $post->title_from_excerpt());
}
public function excerpt($post) {
return $post->description;
}
public function feed_content($post) {
return $post->description;
}
public function swfupload($admin, $post = null) {
if (isset($post) and $post->feather != "project" or
isset($_GET['feather']) and $_GET['feather'] != "project") return;
Trigger::current()->call("prepare_swfupload", "image", "*.jpg;*.jpeg;*.png;*.gif;*.bmp");
}
public function image_tag_for($post, $max_width = 500, $max_height = null, $more_args = "quality=100") {
$filename = $post->filename;
$config = Config::current();
return '<a href="'.$config->chyrp_url.$config->uploads_path.$filename.'"><img src="'.$config->chyrp_url.'/includes/thumb.php?file=..'.$config->uploads_path.urlencode($filename).'&max_width='.$max_width.'&max_height='.$max_height.'&'.$more_args.'" alt="'.fallback($post->alt_text, $filename, true).'" /></a>';
}
public function delete_file($post) {
if ($post->feather != "project") return;
unlink(MAIN_DIR.Config::current()->uploads_path.$post->filename);
}
}
?>