PSR-2. I'm not a huge fan, but ugly consistency beats no consistency...

This commit is contained in:
Shish
2019-05-28 17:59:38 +01:00
parent 5ec3e89884
commit 34b05cca7c
295 changed files with 27094 additions and 24632 deletions

View File

@@ -19,71 +19,75 @@
* every couple of hours.
*/
class Featured extends Extension {
public function onInitExt(InitExtEvent $event) {
global $config;
$config->set_default_int('featured_id', 0);
}
class Featured extends Extension
{
public function onInitExt(InitExtEvent $event)
{
global $config;
$config->set_default_int('featured_id', 0);
}
public function onPageRequest(PageRequestEvent $event) {
global $config, $page, $user;
if($event->page_matches("featured_image")) {
if($event->get_arg(0) == "set" && $user->check_auth_token()) {
if($user->can("edit_feature") && isset($_POST['image_id'])) {
$id = int_escape($_POST['image_id']);
if($id > 0) {
$config->set_int("featured_id", $id);
log_info("featured", "Featured image set to $id", "Featured image set");
$page->set_mode("redirect");
$page->set_redirect(make_link("post/view/$id"));
}
}
}
if($event->get_arg(0) == "download") {
$image = Image::by_id($config->get_int("featured_id"));
if(!is_null($image)) {
$page->set_mode("data");
$page->set_type($image->get_mime_type());
$page->set_data(file_get_contents($image->get_image_filename()));
}
}
if($event->get_arg(0) == "view") {
$image = Image::by_id($config->get_int("featured_id"));
if(!is_null($image)) {
send_event(new DisplayingImageEvent($image));
}
}
}
}
public function onPageRequest(PageRequestEvent $event)
{
global $config, $page, $user;
if ($event->page_matches("featured_image")) {
if ($event->get_arg(0) == "set" && $user->check_auth_token()) {
if ($user->can("edit_feature") && isset($_POST['image_id'])) {
$id = int_escape($_POST['image_id']);
if ($id > 0) {
$config->set_int("featured_id", $id);
log_info("featured", "Featured image set to $id", "Featured image set");
$page->set_mode("redirect");
$page->set_redirect(make_link("post/view/$id"));
}
}
}
if ($event->get_arg(0) == "download") {
$image = Image::by_id($config->get_int("featured_id"));
if (!is_null($image)) {
$page->set_mode("data");
$page->set_type($image->get_mime_type());
$page->set_data(file_get_contents($image->get_image_filename()));
}
}
if ($event->get_arg(0) == "view") {
$image = Image::by_id($config->get_int("featured_id"));
if (!is_null($image)) {
send_event(new DisplayingImageEvent($image));
}
}
}
}
public function onPostListBuilding(PostListBuildingEvent $event) {
global $config, $database, $page, $user;
$fid = $config->get_int("featured_id");
if($fid > 0) {
$image = $database->cache->get("featured_image_object:$fid");
if($image === false) {
$image = Image::by_id($fid);
if($image) { // make sure the object is fully populated before saving
$image->get_tag_array();
}
$database->cache->set("featured_image_object:$fid", $image, 600);
}
if(!is_null($image)) {
if(ext_is_live("Ratings")) {
if(strpos(Ratings::get_user_privs($user), $image->rating) === FALSE) {
return;
}
}
$this->theme->display_featured($page, $image);
}
}
}
public function onPostListBuilding(PostListBuildingEvent $event)
{
global $config, $database, $page, $user;
$fid = $config->get_int("featured_id");
if ($fid > 0) {
$image = $database->cache->get("featured_image_object:$fid");
if ($image === false) {
$image = Image::by_id($fid);
if ($image) { // make sure the object is fully populated before saving
$image->get_tag_array();
}
$database->cache->set("featured_image_object:$fid", $image, 600);
}
if (!is_null($image)) {
if (ext_is_live("Ratings")) {
if (strpos(Ratings::get_user_privs($user), $image->rating) === false) {
return;
}
}
$this->theme->display_featured($page, $image);
}
}
}
public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event) {
global $user;
if($user->can("edit_feature")) {
$event->add_part($this->theme->get_buttons_html($event->image->id));
}
}
public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event)
{
global $user;
if ($user->can("edit_feature")) {
$event->add_part($this->theme->get_buttons_html($event->image->id));
}
}
}