summaryrefslogtreecommitdiffstats
path: root/includes
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2023-01-19 20:17:55 +0100
committerHarald Eilertsen <haraldei@anduin.net>2023-01-19 20:17:55 +0100
commitf499d9e657fe79e4413eec9e20ae13d616fac6f5 (patch)
tree616588346d0dc9337b2cd096cf2af7320dcc060f /includes
parenta5a9bb640306a69ec8f9a3c3701c49f34d3e7ebc (diff)
downloadgigologadmin-f499d9e657fe79e4413eec9e20ae13d616fac6f5.tar.gz
gigologadmin-f499d9e657fe79e4413eec9e20ae13d616fac6f5.tar.bz2
gigologadmin-f499d9e657fe79e4413eec9e20ae13d616fac6f5.zip
Rename and restructure source files to conform to common namin schemes.
- Source files containing a class should only contain _one_ class. - Source files containing a class should be names class-[name of the class].php - Use dashes instead of underscores in file names. - Fix source file comments - Some nitpicking...
Diffstat (limited to 'includes')
-rw-r--r--includes/admin/views/giglog_admin_page.php2
-rw-r--r--includes/admin/views/giglog_import_gigs.php4
-rw-r--r--includes/class-giglogadmin-concert.php (renamed from includes/concert.php)26
-rw-r--r--includes/class-giglogadmin-duplicateconcertexception.php8
-rw-r--r--includes/class-giglogadmin-icalexport.php (renamed from includes/ical_export.php)21
-rw-r--r--includes/class-giglogadmin-plugin.php142
-rw-r--r--includes/class-giglogadmin-venue.php (renamed from includes/venue.php)17
-rw-r--r--includes/giglog_visitor_display.php13
-rw-r--r--includes/giglogadmin-shortcodes.php30
9 files changed, 221 insertions, 42 deletions
diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php
index f3eaa87..acd0172 100644
--- a/includes/admin/views/giglog_admin_page.php
+++ b/includes/admin/views/giglog_admin_page.php
@@ -6,7 +6,7 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
if ( ! class_exists( 'GiglogAdmin_AdminPage' ) ) {
- require_once __DIR__ . '/../../venue.php';
+ require_once __DIR__ . '/../../class-giglogadmin-venue.php';
require_once __DIR__ . '/_concerts_table.php';
require_once __DIR__ . '/_edit_concert_form.php';
require_once __DIR__ . '/_new_venue_form.php';
diff --git a/includes/admin/views/giglog_import_gigs.php b/includes/admin/views/giglog_import_gigs.php
index 505e4bd..758981e 100644
--- a/includes/admin/views/giglog_import_gigs.php
+++ b/includes/admin/views/giglog_import_gigs.php
@@ -6,8 +6,8 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
if ( ! class_exists( 'GiglogAdmin_ImportGigsPage' ) ) {
- require_once __DIR__ . '/../../concert.php';
- require_once __DIR__ . '/../../venue.php';
+ require_once __DIR__ . '/../../class-giglogadmin-concert.php';
+ require_once __DIR__ . '/../../class-giglogadmin-venue.php';
class GiglogAdmin_ImportGigsPage {
static function render_html(): void {
diff --git a/includes/concert.php b/includes/class-giglogadmin-concert.php
index 2849dba..6c7c4da 100644
--- a/includes/concert.php
+++ b/includes/class-giglogadmin-concert.php
@@ -1,21 +1,16 @@
<?php
-
-// SPDX-FileCopyrightText: 2021 Andrea Chirulescu <andrea.chirulescu@gmail.com>
-// SPDX-FileCopyrightText: 2021 Harald Eilertsen <haraldei@anduin.net>
-//
-// SPDX-License-Identifier: AGPL-3.0-or-later
-
-require_once __DIR__ . '/venue.php';
-
-if ( ! class_exists( 'GiglogAdmin_DuplicateConcertException' ) ) {
- // phpcs:ignore Squiz.Commenting.ClassComment.Missing
- class GiglogAdmin_DuplicateConcertException extends Exception {
-
- }
-}
+/**
+ * Class to handle concerts
+ *
+ * @package giglogadmin
+ *
+ * SPDX-FileCopyrightText: 2021 Andrea Chirulescu <andrea.chirulescu@gmail.com>
+ * SPDX-FileCopyrightText: 2021 Harald Eilertsen <haraldei@anduin.net>
+ *
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
if ( ! class_exists( 'GiglogAdmin_Concert' ) ) {
- require_once __DIR__ . '/venue.php';
/**
* Class to hold all information about a given concert.
@@ -431,4 +426,3 @@ if ( ! class_exists( 'GiglogAdmin_Concert' ) ) {
}
}
}
-
diff --git a/includes/class-giglogadmin-duplicateconcertexception.php b/includes/class-giglogadmin-duplicateconcertexception.php
new file mode 100644
index 0000000..3d39f47
--- /dev/null
+++ b/includes/class-giglogadmin-duplicateconcertexception.php
@@ -0,0 +1,8 @@
+<?php
+if ( ! class_exists( 'GiglogAdmin_DuplicateConcertException' ) ) {
+ // phpcs:ignore Squiz.Commenting.ClassComment.Missing
+ class GiglogAdmin_DuplicateConcertException extends Exception {
+
+ }
+}
+
diff --git a/includes/ical_export.php b/includes/class-giglogadmin-icalexport.php
index 627c83b..ba1d7f0 100644
--- a/includes/ical_export.php
+++ b/includes/class-giglogadmin-icalexport.php
@@ -1,13 +1,21 @@
<?php
-
-// SPDX-FileCopyrightText: 2022 Andrea Chirulescu <andrea.chirulescu@gmail.com>
-// SPDX-FileCopyrightText: 2022 Harald Eilertsen <haraldei@anduin.net>
-//
-// SPDX-License-Identifier: AGPL-3.0-or-later
+/**
+ * Class to handle ICAL export of concert data.
+ *
+ * @package giglogadmin
+ *
+ * SPDX-FileCopyrightText: 2022 Andrea Chirulescu <andrea.chirulescu@gmail.com>
+ * SPDX-FileCopyrightText: 2022 Harald Eilertsen <haraldei@anduin.net>
+ *
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
use Kigkonsult\Icalcreator\Vcalendar;
if ( ! class_exists( 'GiglogAdmin_IcalExport' ) ) {
+ /**
+ * Class to handle ICAL export of concert data.
+ */
class Giglogadmin_IcalExport {
static function textclean( string $txt ) : string {
@@ -15,8 +23,9 @@ if ( ! class_exists( 'GiglogAdmin_IcalExport' ) ) {
$cleantext = str_replace( ' ', '_', $cleantext );
return( $cleantext );
}
+
public static function export_ical() {
- $evid = $_GET['evid'];
+ $evid = $_GET['evid'];
$concert = GiglogAdmin_Concert::get( $evid );
$cfullname = $concert->cname() . ' live at ' . $concert->venue()->name() . ', ' . $concert->venue()->city();
diff --git a/includes/class-giglogadmin-plugin.php b/includes/class-giglogadmin-plugin.php
new file mode 100644
index 0000000..a195ffa
--- /dev/null
+++ b/includes/class-giglogadmin-plugin.php
@@ -0,0 +1,142 @@
+<?php
+/**
+ * The main giglogadmin plugin code.
+ *
+ * @package giglogadmin
+ *
+ * SPDX-FileCopyrightText: 2021 Andrea Chirulescu <andrea.chirulescu@gmail.com>
+ * SPDX-FileCopyrightText: 2021 Harald Eilertsen <haraldei@anduin.net>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+if ( ! class_exists( 'GiglogAdmin_Plugin' ) ) {
+
+ class GiglogAdmin_Plugin
+ {
+ static public function init(): void {
+ if ( !defined('GIGLOGADMIN_UNIT_TEST') ) {
+ require_once __DIR__ . '/admin/register_db_tables.php';
+ }
+
+ require_once __DIR__ . '/class-giglogadmin-venue.php';
+ require_once __DIR__ . '/class-giglogadmin-concert.php';
+ require_once __DIR__ . '/class-giglogadmin-icalexport.php';
+ require_once __DIR__ . '/view-helpers/select_field.php';
+
+ if (is_admin()) {
+ require_once __DIR__ . '/admin/views/giglog_admin_page.php';
+ require_once __DIR__ . '/admin/views/giglog_import_gigs.php';
+ require_once __DIR__ . '/admin/helpfiles/instrunctions.php';
+ require_once __DIR__ . '/admin/helpfiles/instr_reviewers.php';
+ require_once __DIR__ . '/admin/helpfiles/instr_photog.php';
+
+ add_action( 'admin_menu', array( 'GiglogAdmin_Plugin', 'add_admin_pages' ));
+ add_action( 'admin_menu', array( 'GiglogAdmin_Plugin', 'add_help_pages' ));
+
+ add_filter( 'wp_nav_menu_args', array( 'GiglogAdmin_Plugin', 'nav_menu_args' ));
+ }
+ else {
+ require_once __DIR__ . '/admin/views/_concerts_table.php';
+ require_once __DIR__ . '/giglogadmin-shortcodes.php';
+ }
+ }
+
+ static function activate(): void {
+ }
+
+ static function deactivate(): void {
+ }
+
+ /**
+ * Adds the 'Giglog' top level menu to the left side WordPress admin
+ * menu. Other subpages will come later.
+ *
+ * @return void
+ */
+ static function add_admin_pages(): void {
+ if ( ! current_user_can( 'manage_options' ) ) {
+ return;
+ }
+ $top = add_menu_page(
+ "Giglog admin", // Page title
+ "Giglog", // Menu title
+ "upload_files", // Will show for users with this capability
+ "giglog", // menu slug
+ array( 'GiglogAdmin_AdminPage', 'render_html' ), // callable
+ 'dashicons-tickets-alt', // Icon url
+ 11); // Position, just below 'Media'
+
+ add_action( 'load-' . $top, array( 'GiglogAdmin_AdminPage', 'update' ) );
+
+ $import_hook = add_submenu_page(
+ "giglog", // parent slug
+ "Import gigs", // page title
+ "Import gigs", // menu title
+ "upload_files", // required capability
+ "giglog_import", // menu slug
+ array( 'GiglogAdmin_ImportGigsPage', 'render_html' )); // callable
+
+ if ($import_hook !== false) {
+ add_action(
+ 'load-' . $import_hook,
+ array( 'GiglogAdmin_ImportGigsPage', 'submit_form' ) );
+ }
+
+ wp_register_style( 'css_style', plugins_url( '/includes/css/main.css', __FILE__ ) );
+ wp_enqueue_style('css_style');
+ }
+
+ static function add_help_pages(): void {
+ if ( ! current_user_can( 'manage_options' ) ) {
+ return;
+ }
+ add_menu_page(
+ "Help for ET users", // Page title
+ "Help for ET users", // Menu title
+ "upload_files", // Will show for users with this capability
+ "helpfiles", // menu slug
+ array( 'Instructions_Page', 'render_instr_html' ), // callable
+ 'dashicons-tickets-alt', // Icon url
+ 10); // Position, just below 'Media'
+
+ add_submenu_page(
+ "helpfiles", // parent slug
+ "Reviewer help files", // page title
+ "Reviewer help files", // menu title
+ "upload_files", // required capability
+ "reviewer_help", // menu slug
+ array( 'Instructions_Reviewers', 'render_instr_rev_html' )); // callable
+
+ add_submenu_page(
+ "helpfiles", // parent slug
+ "Photogalleries help files", // page title
+ "Photogalleries help files", // menu title
+ "upload_files", // required capability
+ "photog_help", // menu slug
+ array( 'Instructions_Photogs', 'render_instr_photo_html' )); // callable
+ }
+
+ /*
+ * Show menus based on whether user is logged in or not.
+ *
+ * Giglog admin pages should only be visible for logged in users/can eventually
+ * be customized by role if needed
+ */
+ static function nav_menu_args( array $args = [] ) : array {
+ if ( is_user_logged_in() ) {
+ $args['menu'] = 'Loggedusers';
+ } else {
+ $args['menu'] = 'Notloggedusers';
+ }
+
+ return $args;
+ }
+
+ }
+
+ register_activation_hook( __FILE__, array( 'GiglogAdmin_Plugin', 'activate' ));
+ register_deactivation_hook( __FILE__, array( 'GiglogAdmin_Plugin', 'deactivate' ));
+
+ GiglogAdmin_Plugin::init();
+}
+
diff --git a/includes/venue.php b/includes/class-giglogadmin-venue.php
index a436f91..ed148c2 100644
--- a/includes/venue.php
+++ b/includes/class-giglogadmin-venue.php
@@ -1,10 +1,19 @@
<?php
-// SPDX-FileCopyrightText: 2021 Andrea Chirulescu <andrea.chirulescu@gmail.com>
-// SPDX-FileCopyrightText: 2021 Harald Eilertsen <haraldei@anduin.net>
-//
-// SPDX-License-Identifier: AGPL-3.0-or-later
+/**
+ * Class representing venues.
+ *
+ * @package giglogadmin
+ *
+ * SPDX-FileCopyrightText: 2021 Andrea Chirulescu <andrea.chirulescu@gmail.com>
+ * SPDX-FileCopyrightText: 2021 Harald Eilertsen <haraldei@anduin.net>
+ *
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
if ( ! class_exists( 'GiglogAdmin_Venue' ) ) {
+ /**
+ * Class representing venues.
+ */
class GiglogAdmin_Venue {
private ?int $id;
diff --git a/includes/giglog_visitor_display.php b/includes/giglog_visitor_display.php
deleted file mode 100644
index b803bec..0000000
--- a/includes/giglog_visitor_display.php
+++ /dev/null
@@ -1,13 +0,0 @@
-<?php declare(strict_types=1);
-// SPDX-FileCopyrightText: 2022 Andrea Chirulescu <andrea.chirulescu@gmail.com>
-// SPDX-FileCopyrightText: 2022 Harald Eilertsen <haraldei@anduin.net>
-//
-// SPDX-License-Identifier: AGPL-3.0-or-later
-
-function display_giglog() : string {
- $c = new GiglogAdmin_ConcertsTable();
- return $c->render();
-}
-
-add_shortcode( 'getconcerts', 'display_giglog' );
-
diff --git a/includes/giglogadmin-shortcodes.php b/includes/giglogadmin-shortcodes.php
new file mode 100644
index 0000000..5070a3e
--- /dev/null
+++ b/includes/giglogadmin-shortcodes.php
@@ -0,0 +1,30 @@
+<?php
+/**
+ * Shortcodes for GiglogAdmin.
+ *
+ * @package giglogadmin
+ *
+ * SPDX-FileCopyrightText: 2022 Andrea Chirulescu <andrea.chirulescu@gmail.com>
+ * SPDX-FileCopyrightText: 2022 Harald Eilertsen <haraldei@anduin.net>
+ *
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+declare(strict_types=1);
+
+if ( ! function_exists( 'giglogadmin_shortcode_public' ) ) {
+
+ /**
+ * Shortcode that displays the public concert list.
+ *
+ * Usage: `[getconcerts]`
+ *
+ * This shortcode does not have any attributes.
+ */
+ function giglogadmin_shortcode_public() : string {
+ $c = new GiglogAdmin_ConcertsTable();
+ return $c->render();
+ }
+
+ add_shortcode( 'getconcerts', 'giglogadmin_shortcode_public' );
+}