Start
This commit is contained in:
93
src/API/File_Server.php
Normal file
93
src/API/File_Server.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\API;
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class File_Server {
|
||||
|
||||
const int FAV_SERVER_NEED_CHANGE = 3600; // In seconds.
|
||||
|
||||
const array ENDPOINTS = [
|
||||
'random-server' => "servers/take-a-random-server.php?return_type=%s",
|
||||
'server-by-id' => "servers/get-server-by-id.php?server_id=%s",
|
||||
];
|
||||
|
||||
private(set) public string $server_url;
|
||||
private(set) public int $server_id;
|
||||
|
||||
public function __construct( int $post_id = 0, bool $get_a_server = true ) {
|
||||
|
||||
if( $get_a_server ){
|
||||
$resp = self::get_favorite_server( $post_id );
|
||||
if( $resp !== null ) {
|
||||
$this->server_url = $resp[0];
|
||||
$this->server_id = intval($resp[1]);
|
||||
} else {
|
||||
$this->server_url = "";
|
||||
$this->server_id = -1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function print_js(){
|
||||
|
||||
echo sprintf( '<script>const chosenDownloadServer="%s";const chosenDownloadServerId="%d";</script>', $this->server_url, $this->server_id );
|
||||
|
||||
}
|
||||
|
||||
public function print(){
|
||||
|
||||
echo $this->server_url . "|" . $this->server_id;
|
||||
|
||||
}
|
||||
|
||||
public static function build_url( string $endpoint, ...$args ){
|
||||
|
||||
return sprintf( $_ENV['ROMHACKPLAZA_API_URL'] . $endpoint, ...$args );
|
||||
|
||||
}
|
||||
|
||||
public static function get_favorite_server( int $post_id ){
|
||||
|
||||
if( $post_id == 0 )
|
||||
return self::get_a_random_server();
|
||||
|
||||
$favorite_server = get_post_meta( $post_id, 'favorite_server', true ) ?? false;
|
||||
$favorite_server_timestamp = get_post_meta( $post_id, 'favorite_server_timestamp', true ) ?? false;
|
||||
|
||||
if( $favorite_server === false || $favorite_server_timestamp === false )
|
||||
return self::get_a_random_server();
|
||||
|
||||
$time = time() - intval( $favorite_server_timestamp );
|
||||
if( $time > self::FAV_SERVER_NEED_CHANGE )
|
||||
return self::get_a_random_server();
|
||||
|
||||
$server_url = wp_remote_get( self::build_url( self::ENDPOINTS['server-by-id'], $favorite_server ) )['body'];
|
||||
return [ $server_url, $favorite_server ];
|
||||
|
||||
}
|
||||
|
||||
public static function get_a_random_server( $return_type = "PHP" ){
|
||||
|
||||
switch( $return_type ) {
|
||||
case "PHP":
|
||||
case "JS":
|
||||
break;
|
||||
default:
|
||||
$return_type = "RAW";
|
||||
break;
|
||||
}
|
||||
|
||||
$resp = wp_remote_get( self::build_url( self::ENDPOINTS['random-server'], $return_type ) );
|
||||
if( !is_wp_error( $resp ) ) {
|
||||
if ($return_type === "PHP")
|
||||
return explode("|", $resp['body']);
|
||||
else
|
||||
echo $resp['body'];
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
14
src/API/Website_Scripts.php
Normal file
14
src/API/Website_Scripts.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\API;
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Website_Scripts {
|
||||
|
||||
public static function build_url( string $s ){
|
||||
|
||||
return home_url( $_ENV['ROMHACKPLAZA_SCRIPTS_FOLDER'] . $s );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
10
src/API/Website_Scripts_Constraints.php
Normal file
10
src/API/Website_Scripts_Constraints.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\API;
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
interface Website_Scripts_Constraints
|
||||
{
|
||||
public static function website_scripts_list();
|
||||
|
||||
}
|
||||
11
src/Database/Database_Table.php
Normal file
11
src/Database/Database_Table.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Database;
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
interface Database_Table {
|
||||
|
||||
public static function create_table();
|
||||
public static function verify_table();
|
||||
|
||||
}
|
||||
15
src/Database/Database_Tools.php
Normal file
15
src/Database/Database_Tools.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Database;
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
trait Database_Tools {
|
||||
|
||||
protected static function table_exists( $table_name ){
|
||||
|
||||
global $wpdb;
|
||||
return $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE %s", $table_name ) ) === $table_name;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
57
src/Extenders/Abstract_Extender.php
Normal file
57
src/Extenders/Abstract_Extender.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders;
|
||||
defined( '\ABSPATH' ) || exit;
|
||||
|
||||
abstract class Abstract_Extender {
|
||||
|
||||
/**
|
||||
* When launched. Check if extend car occur.
|
||||
* Launch extender.
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
if( !$this->can_extend() )
|
||||
return;
|
||||
|
||||
$this->extend();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for Wordpress function.
|
||||
* @param $name
|
||||
* @param $callback
|
||||
* @param $priority
|
||||
* @param $accepted_args
|
||||
* @return void
|
||||
*/
|
||||
protected function add_filter( $name, $callback, $priority = 10, $accepted_args = 1 ) {
|
||||
add_filter( $name, $callback, $priority, $accepted_args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for Wordpress function.
|
||||
* @param $name
|
||||
* @param $callback
|
||||
* @param $priority
|
||||
* @param $accepted_args
|
||||
* @return void
|
||||
*/
|
||||
protected function add_action( $name, $callback, $priority = 10, $accepted_args = 1 ) {
|
||||
add_action( $name, $callback, $priority, $accepted_args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the extender can be launched.
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function can_extend(): bool;
|
||||
|
||||
/**
|
||||
* The Extender.
|
||||
* @return void
|
||||
*/
|
||||
abstract protected function extend(): void;
|
||||
|
||||
}
|
||||
43
src/Extenders/Admin/Dashboard.php
Normal file
43
src/Extenders/Admin/Dashboard.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
namespace RomhackPlaza\Extenders\Admin;
|
||||
defined( '\ABSPATH' ) || exit;
|
||||
|
||||
use RomhackPlaza\Extenders\Abstract_Extender;
|
||||
|
||||
class Dashboard extends Abstract_Extender {
|
||||
|
||||
/**
|
||||
* Contains every childs class.
|
||||
* @var array
|
||||
*/
|
||||
public array $children = [];
|
||||
|
||||
public function can_extend(): bool {
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public function extend(): void {
|
||||
|
||||
$this->add_action( 'wp_dashboard_setup', [ $this, 'remove_meta_boxes' ] );
|
||||
$this->add_action( 'wp_dashboard_setup', [ $this, 'add_meta_boxes' ] );
|
||||
|
||||
}
|
||||
|
||||
public function remove_meta_boxes(): void {
|
||||
|
||||
remove_meta_box('dashboard_primary', 'dashboard', 'side'); // WordPress Events and News
|
||||
remove_meta_box('dashboard_quick_press', 'dashboard', 'side'); // Quick Draft
|
||||
remove_meta_box('dashboard_right_now', 'dashboard', 'normal'); // At a Glance
|
||||
|
||||
}
|
||||
|
||||
public function add_meta_boxes(): void {
|
||||
|
||||
$this->children['content_stats'] = new Meta_Boxes\Content_Stats();
|
||||
$this->children['rhpz-url'] = new Meta_Boxes\RHPZ_Url();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
189
src/Extenders/Admin/List_Table/Notifications_List.php
Normal file
189
src/Extenders/Admin/List_Table/Notifications_List.php
Normal file
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders\Admin\List_Table;
|
||||
use RomhackPlaza\API\Website_Scripts;
|
||||
use RomhackPlaza\Extenders\User_Notifications;
|
||||
use RomhackPlaza\Format;
|
||||
use WP_List_Table;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Notifications_List extends WP_List_Table {
|
||||
|
||||
private $table_data;
|
||||
|
||||
public function get_columns()
|
||||
{
|
||||
$columns = [
|
||||
'id' => '<input type="checkbox" />',
|
||||
'sender' => __('Sender', "romhackplaza"),
|
||||
'recipient' => __('Recipient', "romhackplaza"),
|
||||
'type' => __('Type', "romhackplaza"),
|
||||
'content' => __('Content', "romhackplaza"),
|
||||
'auto' => __('Auto', "romhackplaza"),
|
||||
'readed' => __('Readed', "romhackplaza"),
|
||||
'date' => __('Date', "romhackplaza")
|
||||
];
|
||||
|
||||
return $columns;
|
||||
|
||||
}
|
||||
|
||||
public function prepare_items()
|
||||
{
|
||||
|
||||
if ( isset($_POST['s']) ) {
|
||||
$this->table_data = $this->get_table_data($_POST['s']);
|
||||
} else {
|
||||
$this->table_data = $this->get_table_data();
|
||||
}
|
||||
|
||||
$columns = $this->get_columns();
|
||||
$hidden = array();
|
||||
$sortable = $this->get_sortable_columns();
|
||||
$primary = 'id';
|
||||
$this->_column_headers = array($columns, $hidden, $sortable);
|
||||
|
||||
usort($this->table_data, array(&$this, 'usort_reorder'));
|
||||
|
||||
/* pagination */
|
||||
$per_page = 100;
|
||||
$current_page = $this->get_pagenum();
|
||||
$total_items = count($this->table_data);
|
||||
|
||||
$this->table_data = array_slice($this->table_data, (($current_page - 1) * $per_page), $per_page);
|
||||
|
||||
$this->set_pagination_args(array(
|
||||
'total_items' => $total_items, // total number of items
|
||||
'per_page' => $per_page, // items to show on a page
|
||||
'total_pages' => ceil( $total_items / $per_page ) // use ceil to round up
|
||||
));
|
||||
|
||||
$this->items = $this->table_data;
|
||||
|
||||
}
|
||||
|
||||
private function get_table_data( $search = '' ) {
|
||||
|
||||
global $wpdb;
|
||||
$table_name = $wpdb->prefix . User_Notifications::TABLE_NAME;
|
||||
|
||||
if( ! empty( $search ) )
|
||||
return $wpdb->get_results(
|
||||
"SELECT * FROM {$table_name} WHERE id LIKE '%{$search}%' OR sender LIKE '%{$search}%' OR recipient LIKE '%{$search}%'", ARRAY_A
|
||||
);
|
||||
return $wpdb->get_results(
|
||||
"SELECT * FROM {$table_name}", ARRAY_A
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public function column_default( $item, $column_name ) {
|
||||
|
||||
switch ( $column_name ) {
|
||||
case 'id':
|
||||
case 'sender':
|
||||
case 'recipient':
|
||||
case 'type':
|
||||
case 'content':
|
||||
case 'auto':
|
||||
case 'readed':
|
||||
case 'date':
|
||||
default:
|
||||
return $item[ $column_name ];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function column_cb( $item ) {
|
||||
return sprintf(
|
||||
'<input type="checkbox" name="element[]" value="%s" />', $item['id']
|
||||
);
|
||||
}
|
||||
|
||||
protected function get_sortable_columns()
|
||||
{
|
||||
$sortable = [
|
||||
'id' => array('id', false),
|
||||
'date' => array('date', false),
|
||||
];
|
||||
return $sortable;
|
||||
}
|
||||
|
||||
public function usort_reorder( $a, $b ) {
|
||||
|
||||
// If no sort, default to user_login
|
||||
$orderby = (!empty($_GET['orderby'])) ? $_GET['orderby'] : 'id';
|
||||
|
||||
// If no order, default to asc
|
||||
$order = (!empty($_GET['order'])) ? $_GET['order'] : 'desc';
|
||||
|
||||
// Determine sort order
|
||||
$result = strcmp($a[$orderby], $b[$orderby]);
|
||||
|
||||
// Send final sort direction to usort
|
||||
return ($order === 'asc') ? $result : -$result;
|
||||
|
||||
}
|
||||
|
||||
public function column_id( $item ) {
|
||||
|
||||
$orderby = sanitize_text_field( $_GET['orderby'] ) ?? "id";
|
||||
$order = sanitize_text_field( $_GET['order'] ) ?? 'desc';
|
||||
|
||||
$callback = admin_url( sprintf( "admin.php?page=%s&orderby=%s&order=%s", $_REQUEST['page'], $orderby, $order ) );
|
||||
$delete_url = add_query_arg( [
|
||||
'id' => $item['id'],
|
||||
'_wpnonce' => wp_create_nonce( Format::format_nonce_name( 'delete-notification-' . $item['id'] ) ),
|
||||
'callback' => $callback,
|
||||
],
|
||||
Website_Scripts::build_url( User_Notifications::website_scripts_list()['delete'] )
|
||||
);
|
||||
|
||||
$actions = [
|
||||
'delete' => sprintf( '<a href="%s">%s</a>', $delete_url, __( 'Delete', 'romhackplaza' ) ),
|
||||
];
|
||||
|
||||
return sprintf( "%s %s", $item['id'], $this->row_actions( $actions ) );
|
||||
|
||||
}
|
||||
|
||||
public function column_sender( $item ) {
|
||||
|
||||
$user_name = get_the_author_meta( 'display_name', $item['sender'] ) ?? "Unknown";
|
||||
return sprintf( "%s (%s)", $item['sender'], $user_name );
|
||||
|
||||
}
|
||||
|
||||
public function column_recipient( $item ) {
|
||||
|
||||
$user_name = get_the_author_meta( 'display_name', $item['recipient'] ) ?? "Unknown";
|
||||
return sprintf( "%s (%s)", $item['recipient'], $user_name );
|
||||
|
||||
}
|
||||
|
||||
public function column_type( $item ) {
|
||||
|
||||
return User_Notifications::type_name( $item['type'] );
|
||||
|
||||
}
|
||||
|
||||
public function column_auto( $item ) {
|
||||
|
||||
return $item['auto'] == 1 ? __( "Yes", 'romhackplaza') : __( "No", 'romhackplaza' );
|
||||
|
||||
}
|
||||
|
||||
public function column_readed( $item ) {
|
||||
|
||||
return $item['readed'] == 1 ? __( "Yes", 'romhackplaza') : __( "No", 'romhackplaza' );
|
||||
|
||||
}
|
||||
|
||||
public function column_date( $item ) {
|
||||
|
||||
return wp_date( get_option( 'date_format' ), $item['date'] );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
109
src/Extenders/Admin/Meta_Boxes/Abstract_Meta_Box.php
Normal file
109
src/Extenders/Admin/Meta_Boxes/Abstract_Meta_Box.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders\Admin\Meta_Boxes;
|
||||
defined( '\ABSPATH' ) || exit;
|
||||
|
||||
abstract class Abstract_Meta_Box {
|
||||
|
||||
/**
|
||||
* Meta box name.
|
||||
* @var string
|
||||
*/
|
||||
final public string $name;
|
||||
|
||||
/**
|
||||
* Meta box key.
|
||||
* @var string
|
||||
*/
|
||||
final public string $key;
|
||||
|
||||
/**
|
||||
* Meta box admin page location.
|
||||
* @var Meta_Box_Location
|
||||
*/
|
||||
final public Meta_Box_Location $location;
|
||||
|
||||
/**
|
||||
* Prepare variables, call filters and register the meta box.
|
||||
* @param string $name
|
||||
* @param string $key
|
||||
* @param Meta_Box_Location $location
|
||||
*/
|
||||
public function __construct( string $name, string $key, Meta_Box_Location $location ) {
|
||||
|
||||
$this->name = $name;
|
||||
$this->key = $key;
|
||||
$this->location = $location;
|
||||
|
||||
if( $this->can_register() ) {
|
||||
$this->prepare_filters();
|
||||
$this->register();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* If the meta box can be registered or not.
|
||||
* @return bool
|
||||
*/
|
||||
protected function can_register(): bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare filters "Before content" and "After content" if needed.
|
||||
* @return void
|
||||
*/
|
||||
protected function prepare_filters(): void {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the meta box at the correct location.
|
||||
* @return void
|
||||
*/
|
||||
final public function register(): void {
|
||||
|
||||
switch( $this->location ){
|
||||
case Meta_Box_Location::Dashboard:
|
||||
wp_add_dashboard_widget( $this->name, $this->key, [$this, 'pre_render'] );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare render content.
|
||||
* @return void
|
||||
*/
|
||||
public function pre_render(): void {
|
||||
|
||||
$data = [];
|
||||
|
||||
/**
|
||||
* Add data that need to be loaded before the content.
|
||||
*
|
||||
* @param array - Data array.
|
||||
* @return array
|
||||
*/
|
||||
$data = \apply_filters( "RomhackPlaza\\Extenders\\Admin\\Meta_Boxes\\{$this->name}\\Before_Content", $data );
|
||||
|
||||
$this->content( $data );
|
||||
|
||||
/**
|
||||
* Declare data that need to be loaded after the meta box content.
|
||||
*
|
||||
* @param array - Data array.
|
||||
*/
|
||||
do_action( "RomhackPlaza\\Extenders\\Admin\\Meta_Boxes\\{$this->name}\\After_Content", $data );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Content of the meta box. Can be done with Timber.
|
||||
* /!\ Verify that Timber is available.
|
||||
* @param array $data
|
||||
* @return void
|
||||
*/
|
||||
abstract protected function content( array $data = [] ): void;
|
||||
|
||||
}
|
||||
183
src/Extenders/Admin/Meta_Boxes/Content_Stats.php
Normal file
183
src/Extenders/Admin/Meta_Boxes/Content_Stats.php
Normal file
@@ -0,0 +1,183 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders\Admin\Meta_Boxes;
|
||||
defined( '\ABSPATH' ) || exit;
|
||||
|
||||
class Content_Stats extends Abstract_Meta_Box {
|
||||
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(
|
||||
'romhackplaza-widget-content-stats',
|
||||
'Content Stats',
|
||||
Meta_Box_Location::Dashboard
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
protected function prepare_filters(): void {
|
||||
|
||||
add_filter( "RomhackPlaza\\Extenders\\Admin\\Meta_Boxes\\{$this->name}\\Before_Content", [ $this, 'prepare_data' ] );
|
||||
add_action( "RomhackPlaza\\Extenders\\Admin\\Meta_Boxes\\{$this->name}\\After_Content", [ $this, 'load_js' ] );
|
||||
|
||||
}
|
||||
|
||||
private function post_count_per_days( int $days, array $post_types ) {
|
||||
|
||||
if( $days > 31 || $days < 0 )
|
||||
$days = 7;
|
||||
|
||||
// Default value foreach days.
|
||||
$post_counts = [];
|
||||
foreach( $post_types as $a_post_type ){
|
||||
|
||||
$post_counts[ $a_post_type ] = array_fill( 0, $days, 0 );
|
||||
|
||||
}
|
||||
|
||||
for( $i = $days - 1; $i >= 0; $i-- ){
|
||||
|
||||
$date_query = [
|
||||
|
||||
'after' => date('Y-m-d', strtotime("-$i days")),
|
||||
'before' => date('Y-m-d', strtotime("-" . ($i - 1) . " days")),
|
||||
'inclusive' => true,
|
||||
|
||||
];
|
||||
|
||||
foreach( $post_types as $a_post_type ){
|
||||
|
||||
$wp_query_args = [
|
||||
|
||||
'post_type' => $a_post_type,
|
||||
'date_query' => $date_query,
|
||||
'posts_per_page' => -1
|
||||
|
||||
];
|
||||
|
||||
$wp_query = new \WP_Query( $wp_query_args );
|
||||
$post_counts[ $a_post_type ][ $days - 1 - $i ]= $wp_query->found_posts;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $post_counts;
|
||||
|
||||
}
|
||||
|
||||
public function prepare_data( array $data = [] ) {
|
||||
|
||||
global $_romhackplaza;
|
||||
$primary_cpt = $_romhackplaza->cpt->primary_cpt();
|
||||
|
||||
$count_week = $this->post_count_per_days( 7, $primary_cpt );
|
||||
$count_month = $this->post_count_per_days( 30, $primary_cpt );
|
||||
|
||||
return [
|
||||
'week' => json_encode( $count_week ),
|
||||
'month' => json_encode( $count_month ),
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Load JS needed for this widget.
|
||||
* @return void
|
||||
*/
|
||||
public function load_js( array $data = [] ) {
|
||||
|
||||
?>
|
||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||
<script>
|
||||
var dataWeek = <?php echo $data['week']; ?>;
|
||||
var dataMonth = <?php echo $data['month']; ?>;
|
||||
|
||||
function getDateLabels(days) {
|
||||
var labels = [];
|
||||
for (let i = days - 1; i >= 0; i--) {
|
||||
var date = new Date();
|
||||
date.setDate(date.getDate() - i);
|
||||
labels.push((date.getMonth() + 1) + '/' + date.getDate());
|
||||
}
|
||||
return labels;
|
||||
}
|
||||
|
||||
function createDataset(data, label, color) {
|
||||
return {
|
||||
label: label,
|
||||
data: data,
|
||||
backgroundColor: color,
|
||||
borderColor: color,
|
||||
borderWidth: 1
|
||||
};
|
||||
}
|
||||
|
||||
function updateChart() {
|
||||
if (window.myChart && typeof window.myChart.destroy === 'function') {
|
||||
window.myChart.destroy();
|
||||
}
|
||||
|
||||
var timeRange = document.getElementById('timeRange').value;
|
||||
var chartData = timeRange === 'week' ? dataWeek : dataMonth;
|
||||
var days = timeRange === 'week' ? 7 : 30;
|
||||
|
||||
var ctx = document.getElementById('myChart').getContext('2d');
|
||||
window.myChart = new Chart(ctx, {
|
||||
type: 'bar',
|
||||
data: {
|
||||
labels: getDateLabels(days),
|
||||
datasets: [
|
||||
createDataset(chartData.translations, 'Translations', 'rgba(255, 99, 132, 0.5)'),
|
||||
createDataset(chartData.homebrew, 'Homebrew', 'rgba(54, 162, 235, 0.5)'),
|
||||
createDataset(chartData.romhacks, 'Romhacks', 'rgba(255, 206, 86, 0.5)'),
|
||||
createDataset(chartData.utilities, 'Utilities', 'rgba(75, 192, 192, 0.5)'),
|
||||
createDataset(chartData.documents, 'Documents', 'rgba(153, 102, 255, 0.5)'),
|
||||
createDataset(chartData.news, 'News', 'rgba(240, 240, 240, 0.5)'),
|
||||
createDataset(chartData['lua-scripts'], 'LUA Scripts', 'rgba(240, 40, 145, 0.5)'),
|
||||
createDataset(chartData.tutorials, 'Tutorials', 'rgba(39, 245, 223, 0.5)')
|
||||
]
|
||||
},
|
||||
options: {
|
||||
scales: {
|
||||
x: { stacked: true },
|
||||
y: { stacked: true, beginAtZero: true }
|
||||
},
|
||||
maintainAspectRatio: false
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Initialize chart with week data
|
||||
document.addEventListener('DOMContentLoaded', updateChart);
|
||||
</script>
|
||||
<?php
|
||||
|
||||
}
|
||||
|
||||
protected function content( array $data = [] ): void {
|
||||
?>
|
||||
<style>
|
||||
#chart-container {
|
||||
width: 100%;
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
#myChart {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div>
|
||||
<select id="timeRange" onchange="updateChart()">
|
||||
<option value="week">This Week</option>
|
||||
<option value="month">Last 30 Days</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div id="chart-container">
|
||||
<canvas id="myChart"></canvas>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
}
|
||||
8
src/Extenders/Admin/Meta_Boxes/Meta_Box_Location.php
Normal file
8
src/Extenders/Admin/Meta_Boxes/Meta_Box_Location.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders\Admin\Meta_Boxes;
|
||||
defined( '\ABSPATH' ) || exit;
|
||||
enum Meta_Box_Location {
|
||||
case Dashboard;
|
||||
case Post_Edit;
|
||||
}
|
||||
71
src/Extenders/Admin/Meta_Boxes/RHPZ_Url.php
Normal file
71
src/Extenders/Admin/Meta_Boxes/RHPZ_Url.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders\Admin\Meta_Boxes;
|
||||
defined( '\ABSPATH' ) || exit;
|
||||
|
||||
use RomhackPlaza\Script;
|
||||
use RomhackPlaza\Script_Type;
|
||||
|
||||
class RHPZ_Url extends Abstract_Meta_Box {
|
||||
|
||||
const string RHPZ_URL = 'https://rhpz.org/';
|
||||
const string RHPZ_CREATE_URL = 'https://rhpz.org/f/qKHKfGPM2yMXLP5L/';
|
||||
|
||||
|
||||
public function __construct(){
|
||||
|
||||
parent::__construct(
|
||||
'romhackplaza-widget-create-a-rhpz-url',
|
||||
'Create a RHPZ URL',
|
||||
Meta_Box_Location::Dashboard
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
protected function can_register(): bool
|
||||
{
|
||||
return current_user_can( 'edit_others_posts' );
|
||||
}
|
||||
|
||||
protected function prepare_filters(): void
|
||||
{
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_js_script' ) );
|
||||
}
|
||||
|
||||
protected function content( array $data = [] ): void {
|
||||
|
||||
?>
|
||||
|
||||
<form id="Create-A-RHPZ-Url-Form">
|
||||
<label for="FormUrl"><?php _e( 'URL you want to be shortened', 'romhackplaza' ); ?></label>
|
||||
<input type="text" id="FormUrl" name="FormUrl" value="" required>
|
||||
<input type="submit" name="submitUrl" value="Submit URL">
|
||||
</form>
|
||||
<div id="Create-A-RHPZ-Url-Response" style="margin-top: 2%;"></div>
|
||||
|
||||
<?php
|
||||
|
||||
}
|
||||
|
||||
public function enqueue_js_script( string $call ): void {
|
||||
|
||||
if( $call != 'index.php' ) // Dashboard
|
||||
return;
|
||||
|
||||
new Script(
|
||||
Script_Type::JS,
|
||||
'romhackplaza-rhpz-url',
|
||||
ROMHACKPLAZA_PLUGIN_URI . '/assets/js/admin/widgets/rhpz-url.js',
|
||||
[],
|
||||
'20251102-4',
|
||||
args: [ 'defer' => true, 'in_footer' => true ]
|
||||
)
|
||||
->enqueue()
|
||||
->add_localize(
|
||||
'_romhackplaza_rhpz_url',
|
||||
[ 'create_url' => self::RHPZ_CREATE_URL ]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
37
src/Extenders/Admin/Pages.php
Normal file
37
src/Extenders/Admin/Pages.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
namespace RomhackPlaza\Extenders\Admin;
|
||||
use RomhackPlaza\Extenders\Abstract_Extender;
|
||||
|
||||
defined( '\ABSPATH' ) || exit;
|
||||
|
||||
class Pages extends Abstract_Extender {
|
||||
|
||||
/**
|
||||
* Page class children.
|
||||
* @var array
|
||||
*/
|
||||
public array $children = [];
|
||||
|
||||
protected function can_extend(): bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function extend(): void {
|
||||
|
||||
$this->children['main_page'] = new Pages\RomhackPlaza_Main();
|
||||
$this->children['settings_page'] = new Pages\Settings();
|
||||
|
||||
if( is_admin() ){
|
||||
|
||||
if( !class_exists( 'WP_List_Table' ) )
|
||||
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
|
||||
|
||||
}
|
||||
|
||||
$this->children['notifications_page'] = new Pages\Notifications_List();
|
||||
$this->children['send_notification_page'] = new Pages\Send_Notification();
|
||||
$this->children['admin_scripts_page'] = new Pages\Admin_Scripts();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
147
src/Extenders/Admin/Pages/Abstract_Page.php
Normal file
147
src/Extenders/Admin/Pages/Abstract_Page.php
Normal file
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders\Admin\Pages;
|
||||
defined( '\ABSPATH' ) || exit;
|
||||
|
||||
abstract class Abstract_Page {
|
||||
|
||||
/**
|
||||
* Page title at the tab.
|
||||
* @var string
|
||||
*/
|
||||
final public string $page_title;
|
||||
|
||||
/**
|
||||
* Short title in WP Admin menu
|
||||
* @var string
|
||||
*/
|
||||
final public string $menu_title;
|
||||
|
||||
/**
|
||||
* ?page slug.
|
||||
* @var string
|
||||
*/
|
||||
final public string $page_slug;
|
||||
|
||||
/**
|
||||
* Capability needed to see and access to this page.
|
||||
* @var string
|
||||
*/
|
||||
final public string $capability;
|
||||
|
||||
/**
|
||||
* ?page parent slug.
|
||||
* @var string|null
|
||||
*/
|
||||
final public string|null $parent_slug;
|
||||
|
||||
/**
|
||||
* Icon URL
|
||||
* @var string|null
|
||||
*/
|
||||
final public string|null $icon;
|
||||
|
||||
/**
|
||||
* Position in WP Admin menu
|
||||
* @var int|null
|
||||
*/
|
||||
public int|null $position;
|
||||
|
||||
/**
|
||||
* Setup page settings.
|
||||
* @param string $page_title
|
||||
* @param string $menu_title
|
||||
* @param string $page_slug
|
||||
* @param string $capability
|
||||
* @param string|null $icon
|
||||
* @param int|null $position
|
||||
*/
|
||||
public function __construct (
|
||||
string $page_title,
|
||||
string $menu_title,
|
||||
string $page_slug,
|
||||
string $capability,
|
||||
string|null $parent_slug = null,
|
||||
string|null $icon = null,
|
||||
int|null $position = null
|
||||
) {
|
||||
|
||||
$this->page_title = $page_title;
|
||||
$this->menu_title = $menu_title;
|
||||
$this->page_slug = $page_slug;
|
||||
$this->capability = $capability;
|
||||
$this->parent_slug = $parent_slug;
|
||||
$this->icon = $icon;
|
||||
$this->position = $position;
|
||||
|
||||
$this->prepare_filters();
|
||||
add_action( 'admin_menu', [ $this, 'add_page' ] );
|
||||
|
||||
if( method_exists( $this, 'enqueue_scripts' ) )
|
||||
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare filters "Before content" and "After content" if needed.
|
||||
* @return void
|
||||
*/
|
||||
protected function prepare_filters (): void {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register page.
|
||||
* @return void
|
||||
*/
|
||||
final public function add_page () {
|
||||
|
||||
if( !is_null( $this->parent_slug ) )
|
||||
add_submenu_page(
|
||||
$this->parent_slug,
|
||||
$this->page_title,
|
||||
$this->menu_title,
|
||||
$this->capability,
|
||||
$this->page_slug,
|
||||
[ $this, 'pre_content' ],
|
||||
$this->position
|
||||
);
|
||||
else
|
||||
add_menu_page(
|
||||
$this->page_title,
|
||||
$this->menu_title,
|
||||
$this->capability,
|
||||
$this->page_slug,
|
||||
[ $this, 'pre_content' ],
|
||||
$this->icon,
|
||||
$this->position
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare content and execute before content and after content hooks.
|
||||
* @return void
|
||||
*/
|
||||
public function pre_content () {
|
||||
|
||||
$data = [];
|
||||
|
||||
$data = \apply_filters( "RomhackPlaza\\Extenders\\Admin\\Pages\\{$this->page_slug}\\Before_Content", $data );
|
||||
$this->content( $data );
|
||||
|
||||
do_action( "RomhackPlaza\\Extenders\\Admin\\Pages\\{$this->page_slug}\\After_Content", $data );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The content. Can be done with Timber.
|
||||
* /!\ Verify that Timber is available.
|
||||
* @param array $data
|
||||
* @return void
|
||||
*/
|
||||
abstract public function content( mixed $data = [] ): void;
|
||||
|
||||
}
|
||||
58
src/Extenders/Admin/Pages/Admin_Scripts.php
Normal file
58
src/Extenders/Admin/Pages/Admin_Scripts.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders\Admin\Pages;
|
||||
use RomhackPlaza\Format;
|
||||
use RomhackPlaza\Script;
|
||||
use RomhackPlaza\Script_Type;
|
||||
use Timber\Timber;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Admin_Scripts extends Abstract_Page {
|
||||
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(
|
||||
__( 'Admin Scripts', 'romhackplaza' ),
|
||||
__( 'Admin Scripts', 'romhackplaza' ),
|
||||
'romhackplaza-admin-scripts',
|
||||
'manage_options',
|
||||
'tools.php'
|
||||
);
|
||||
|
||||
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
|
||||
}
|
||||
|
||||
public function enqueue_scripts( $hook ) {
|
||||
|
||||
if( $hook !== 'tools_page_' . $this->page_slug )
|
||||
return;
|
||||
|
||||
new Script(
|
||||
Script_Type::JS,
|
||||
'romhackplaza-admin-scripts',
|
||||
ROMHACKPLAZA_PLUGIN_URI . '/assets/js/admin/admin-scripts.js',
|
||||
[],
|
||||
'20260105',
|
||||
args: [ 'defer' => true, 'in_footer' => true ]
|
||||
)
|
||||
->enqueue()
|
||||
->add_localize(
|
||||
'_romhackplaza_admin_scripts',
|
||||
[
|
||||
'execute_url' => admin_url( 'admin-ajax.php' ),
|
||||
'execute_nonce' => wp_create_nonce( Format::format_nonce_name( 'load_admin_script' ) )
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function content( mixed $data = [] ): void {
|
||||
|
||||
$context = Timber::context();
|
||||
$context['scripts'] = \RomhackPlaza\Extenders\Admin_Scripts::get_scripts();
|
||||
|
||||
Timber::render( '@plugin/admin/pages/admin-scripts.twig', $context );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
42
src/Extenders/Admin/Pages/Notifications_List.php
Normal file
42
src/Extenders/Admin/Pages/Notifications_List.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders\Admin\Pages;
|
||||
use RomhackPlaza\Extenders\Admin\List_Table\Notifications_List as List_Table;
|
||||
|
||||
defined( '\ABSPATH' ) || exit;
|
||||
|
||||
class Notifications_List extends Abstract_Page {
|
||||
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(
|
||||
__( 'Notifications', 'romhackplaza' ),
|
||||
__( 'Notifications', 'romhackplaza' ),
|
||||
'romhackplaza-notifications-list',
|
||||
'edit_others_posts', // Only staff can see it
|
||||
icon: "dashicons-bell",
|
||||
position: 59
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public function content( mixed $data = [] ): void {
|
||||
|
||||
$table = new List_Table();
|
||||
|
||||
?>
|
||||
<style>.wp-list-table .column-id, .wp-list-table .column-auto, .wp-list-table .column-readed { width: 5%; } .wp-list-table .column-sender, .wp-list-table .column-recipient, .wp-list-table .column-type, .wp-list-table .column-date { width: 10%; }</style>
|
||||
<div class="wrap"><h2><?php _e( 'Notifications', 'romhackplaza' ); ?></h2>
|
||||
<form method="post">
|
||||
<?php
|
||||
$table->prepare_items();
|
||||
$table->search_box( __( 'Search by ID, sender or recipient', 'romhackplaza' ), 'search_id' );
|
||||
$table->display();
|
||||
?>
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
28
src/Extenders/Admin/Pages/RomhackPlaza_Main.php
Normal file
28
src/Extenders/Admin/Pages/RomhackPlaza_Main.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders\Admin\Pages;
|
||||
use \Timber\Timber;
|
||||
|
||||
defined( '\ABSPATH' ) || exit;
|
||||
|
||||
class RomhackPlaza_Main extends Abstract_Page {
|
||||
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(
|
||||
__( 'RomhackPlaza - Admin', 'romhackplaza' ),
|
||||
__( 'RomhackPlaza', 'romhackplaza' ),
|
||||
'romhackplaza-wp',
|
||||
'edit_posts', // Every member can see it.
|
||||
position: 59
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public function content( mixed $data = [] ): void {
|
||||
|
||||
$context = Timber::context();
|
||||
Timber::render( '@plugin/admin/pages/main.twig', $context );
|
||||
|
||||
}
|
||||
}
|
||||
74
src/Extenders/Admin/Pages/Send_Notification.php
Normal file
74
src/Extenders/Admin/Pages/Send_Notification.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders\Admin\Pages;
|
||||
use RomhackPlaza\Extenders\User_Notifications;
|
||||
use RomhackPlaza\Format;
|
||||
use RomhackPlaza\Modal;
|
||||
use RomhackPlaza\Script;
|
||||
use RomhackPlaza\Script_Type;
|
||||
use \Timber\Timber;
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Send_Notification extends Abstract_Page {
|
||||
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(
|
||||
__( 'Send Notification', 'romhackplaza' ),
|
||||
__( 'Send Notification', 'romhackplaza' ),
|
||||
'romhackplaza-send-notification',
|
||||
'edit_others_posts',
|
||||
'romhackplaza-notifications-list'
|
||||
);
|
||||
|
||||
add_action( "admin_head-notifications_page_{$this->page_slug}", array( $this, 'load_select2' ) );
|
||||
add_action( "admin_enqueue_scripts", array( $this, 'enqueue_scripts' ) );
|
||||
|
||||
}
|
||||
|
||||
public function load_select2() {
|
||||
|
||||
// Load select2
|
||||
?>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css">
|
||||
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
|
||||
<?php
|
||||
|
||||
}
|
||||
|
||||
public function enqueue_scripts( $hook ) {
|
||||
|
||||
if( $hook !== 'notifications_page_' . $this->page_slug )
|
||||
return;
|
||||
|
||||
new Script(
|
||||
Script_Type::JS,
|
||||
'romhackplaza-send-notification',
|
||||
ROMHACKPLAZA_PLUGIN_URI . '/assets/js/admin/send-notification.js',
|
||||
[ 'jquery' ],
|
||||
'20260101-4',
|
||||
args: [ 'defer' => true, 'in_footer' => true ]
|
||||
)
|
||||
->enqueue()
|
||||
->add_localize(
|
||||
'_romhackplaza_send_notification',
|
||||
[
|
||||
'fetch_url' => admin_url( 'admin-ajax.php' ),
|
||||
'fetch_nonce' => wp_create_nonce( Format::format_nonce_name( 'search_user' ) ),
|
||||
'submit_nonce' => wp_create_nonce( Format::format_nonce_name( 'submit_notification' ) ),
|
||||
],
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public function content( mixed $data = [] ): void {
|
||||
|
||||
$context = Timber::context();
|
||||
$context['type_list'] = User_Notifications::NOTIFICATIONS_TYPES;
|
||||
|
||||
new Modal( 'notifications', "", "" )->render();
|
||||
Timber::render( '@plugin/admin/pages/send-notification.twig', $context );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
209
src/Extenders/Admin/Pages/Settings.php
Normal file
209
src/Extenders/Admin/Pages/Settings.php
Normal file
@@ -0,0 +1,209 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders\Admin\Pages;
|
||||
use Timber\Timber;
|
||||
|
||||
defined( '\ABSPATH' ) || exit;
|
||||
|
||||
class Settings extends Abstract_Page {
|
||||
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(
|
||||
__( 'RomhackPlaza - Settings', 'romhackplaza' ),
|
||||
__( 'Settings', 'romhackplaza' ),
|
||||
'romhackplaza-config',
|
||||
'manage_options', // Only admins.
|
||||
'romhackplaza-wp',
|
||||
position: 59
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
protected function prepare_filters(): void
|
||||
{
|
||||
add_action( 'admin_init', [ $this, 'register_settings_sections_fields'], 11 );
|
||||
}
|
||||
|
||||
public function _generic_html_input_text( string $option_name ): void {
|
||||
|
||||
global $_romhackplaza;
|
||||
$value = esc_attr( $_romhackplaza->settings->get( $option_name ) ?? "" );
|
||||
|
||||
echo sprintf( '<input type="text" name="%1$s[%2$s]" value="%3$s" />', 'romhackplaza_plugin_options', $option_name, $value );
|
||||
|
||||
}
|
||||
|
||||
/* ---
|
||||
START SETTINGS REGISTRATION
|
||||
--- */
|
||||
|
||||
public function register_settings_sections_fields () {
|
||||
|
||||
add_settings_section(
|
||||
'nsfw',
|
||||
__( 'NSFW', 'romhackplaza' ),
|
||||
function(){}, // Change it to add style.
|
||||
'romhackplaza-config'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'nsfw_tag_id',
|
||||
__( 'Tag ID', 'romhackplaza' ),
|
||||
function(){ $this->_generic_html_input_text( 'nsfw_tag_id' ); },
|
||||
'romhackplaza-config',
|
||||
'nsfw',
|
||||
);
|
||||
|
||||
add_settings_section(
|
||||
'submissions',
|
||||
__( 'Submissions', 'romhackplaza' ),
|
||||
function(){ _e("All fields needs to be separated by a semi-colon WITHOUT SPACES !", 'romhackplaza' ); },
|
||||
'romhackplaza-config'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'complete_submissions_form_page_ids',
|
||||
__( 'Complete submissions page IDs', 'romhackplaza' ),
|
||||
function(){ $this->_generic_html_input_text( 'complete_submissions_form_page_ids' ); },
|
||||
'romhackplaza-config',
|
||||
'submissions',
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'simple_submissions_form_page_ids',
|
||||
__( 'Simple submissions page IDs (News)', 'romhackplaza' ),
|
||||
function(){ $this->_generic_html_input_text( 'simple_submissions_form_page_ids' ); },
|
||||
'romhackplaza-config',
|
||||
'submissions',
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'translations_acf_group',
|
||||
__( 'Translations ACF Group', 'romhackplaza' ),
|
||||
function(){ $this->_generic_html_input_text( 'translations_acf_group' ); },
|
||||
'romhackplaza-config',
|
||||
'submissions',
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'romhacks_acf_group',
|
||||
__( 'Romhacks ACF Group', 'romhackplaza' ),
|
||||
function(){ $this->_generic_html_input_text( 'romhacks_acf_group' ); },
|
||||
'romhackplaza-config',
|
||||
'submissions',
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'homebrew_acf_group',
|
||||
__( 'Homebrew ACF Group', 'romhackplaza' ),
|
||||
function(){ $this->_generic_html_input_text( 'homebrew_acf_group' ); },
|
||||
'romhackplaza-config',
|
||||
'submissions',
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'utilities_acf_group',
|
||||
__( 'Utilities ACF Group', 'romhackplaza' ),
|
||||
function(){ $this->_generic_html_input_text( 'utilities_acf_group' ); },
|
||||
'romhackplaza-config',
|
||||
'submissions',
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'documents_acf_group',
|
||||
__( 'Documents ACF Group', 'romhackplaza' ),
|
||||
function(){ $this->_generic_html_input_text( 'documents_acf_group' ); },
|
||||
'romhackplaza-config',
|
||||
'submissions',
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'lua_scripts_acf_group',
|
||||
__( 'LUA Scripts ACF Group', 'romhackplaza' ),
|
||||
function(){ $this->_generic_html_input_text( 'lua_scripts_acf_group' ); },
|
||||
'romhackplaza-config',
|
||||
'submissions',
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'tutorials_acf_group',
|
||||
__( 'Tutorials ACF Group', 'romhackplaza' ),
|
||||
function(){ $this->_generic_html_input_text( 'tutorials_acf_group' ); },
|
||||
'romhackplaza-config',
|
||||
'submissions',
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'news_acf_group',
|
||||
__( 'News ACF Group', 'romhackplaza' ),
|
||||
function(){ $this->_generic_html_input_text( 'news_acf_group' ); },
|
||||
'romhackplaza-config',
|
||||
'submissions',
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'reviews_acf_group',
|
||||
__( 'Reviews ACF Group', 'romhackplaza' ),
|
||||
function(){ $this->_generic_html_input_text( 'reviews_acf_group' ); },
|
||||
'romhackplaza-config',
|
||||
'submissions',
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'public_edit_disabled_tag_id',
|
||||
__( 'Public Edit Disabled Tag ID', 'romhackplaza' ),
|
||||
function(){ $this->_generic_html_input_text( 'public_edit_disabled_tag_id' ); },
|
||||
'romhackplaza-config',
|
||||
'submissions',
|
||||
);
|
||||
|
||||
add_settings_section(
|
||||
'discord',
|
||||
__( 'Discord', 'romhackplaza' ),
|
||||
function(){},
|
||||
'romhackplaza-config'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'discord_webhook_romhacks_translations',
|
||||
__( 'Discord webhook for Romhacks and Translations', 'romhackplaza' ),
|
||||
function(){ $this->_generic_html_input_text( 'discord_webhook_romhacks_translations' ); },
|
||||
'romhackplaza-config',
|
||||
'discord',
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'discord_webhook_global',
|
||||
__( 'Discord webhook for others submissions', 'romhackplaza' ),
|
||||
function(){ $this->_generic_html_input_text( 'discord_webhook_global' ); },
|
||||
'romhackplaza-config',
|
||||
'discord',
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/* ---
|
||||
END SETTINGS REGISTRATION
|
||||
--- */
|
||||
|
||||
public function content( mixed $data = [] ): void {
|
||||
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1><?php _e( 'RomhackPlaza - Configuration', 'romhackplaza' ); ?></h1>
|
||||
<form method="post" action="options.php">
|
||||
|
||||
<?php
|
||||
settings_fields( 'romhackplaza_plugin_options_group' );
|
||||
do_settings_sections( 'romhackplaza-config' );
|
||||
submit_button();
|
||||
?>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
54
src/Extenders/Admin_Scripts.php
Normal file
54
src/Extenders/Admin_Scripts.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders;
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Admin_Scripts extends Abstract_Extender {
|
||||
|
||||
protected function can_extend(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function extend(): void {
|
||||
|
||||
new Ajax\Load_Admin_Script();
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
public static function get_scripts(): array {
|
||||
|
||||
$scripts = self::get_scripts_list();
|
||||
$scripts = array_map( [ self::class, 'format_scripts_list' ], $scripts );
|
||||
return $scripts;
|
||||
|
||||
}
|
||||
|
||||
protected static function get_scripts_list(): array {
|
||||
|
||||
if( !file_exists( ABSPATH . $_ENV['ROMHACKPLAZA_SCRIPTS_ADMIN_FOLDER'] ) )
|
||||
return [];
|
||||
|
||||
$scripts_list = glob( ABSPATH . $_ENV['ROMHACKPLAZA_SCRIPTS_ADMIN_FOLDER'] . "*.php", GLOB_BRACE );
|
||||
return $scripts_list;
|
||||
|
||||
}
|
||||
|
||||
public static function format_scripts_list( string $script_path )
|
||||
{
|
||||
$arr = explode( '/', $script_path );
|
||||
return end( $arr );
|
||||
}
|
||||
|
||||
public static function execute( string $script_name ): bool {
|
||||
|
||||
if( in_array( $script_name, self::get_scripts() ) ) {
|
||||
include_once ABSPATH . $_ENV['ROMHACKPLAZA_SCRIPTS_ADMIN_FOLDER'] . $script_name;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
35
src/Extenders/Advanced_Custom_Fields_Pro.php
Normal file
35
src/Extenders/Advanced_Custom_Fields_Pro.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders;
|
||||
|
||||
defined( '\ABSPATH' ) || exit;
|
||||
|
||||
class Advanced_Custom_Fields_Pro extends Abstract_Extender {
|
||||
|
||||
protected function can_extend(): bool
|
||||
{
|
||||
return class_exists( 'acf_pro' ); // Required for plugin launch, so...
|
||||
}
|
||||
|
||||
protected function extend(): void {
|
||||
|
||||
$this->add_action( 'acf/save_post', [ $this, 'bind_post_parent_attachment_from_gallery' ] );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add post_parent for attachments added in a ACF gallery element.
|
||||
* Redirect to save_post class.
|
||||
* @see Post\Save_Post::bind_post_parent_attachment_from_gallery()
|
||||
* @param $post_id
|
||||
* @return void
|
||||
*/
|
||||
public function bind_post_parent_attachment_from_gallery( $post_id ) {
|
||||
|
||||
global $_romhackplaza;
|
||||
if( isset( $_romhackplaza->children['extend_save_post'] ) ) // Post\Save_Post.
|
||||
return $_romhackplaza->children['extend_save_post']->bind_post_parent_attachment_from_gallery( $post_id );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
40
src/Extenders/Ajax/Abstract_Ajax.php
Normal file
40
src/Extenders/Ajax/Abstract_Ajax.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders\Ajax;
|
||||
use RomhackPlaza\Format;
|
||||
|
||||
defined( '\ABSPATH' ) || exit;
|
||||
|
||||
abstract class Abstract_Ajax {
|
||||
|
||||
final public string $request_name;
|
||||
final public bool $public;
|
||||
final protected string|bool $nonce_field;
|
||||
|
||||
public function __construct(
|
||||
string $request_name,
|
||||
bool $public = false,
|
||||
string|bool $nonce_field = false
|
||||
) {
|
||||
|
||||
$this->request_name = $request_name;
|
||||
$this->public = $public;
|
||||
$this->nonce_field = $nonce_field;
|
||||
|
||||
if( $this->public )
|
||||
add_action('wp_ajax_no_priv_' . $this->request_name, [$this, 'pre_handle'] );
|
||||
|
||||
add_action( 'wp_ajax_' . $this->request_name, [$this, 'pre_handle'] );
|
||||
|
||||
}
|
||||
|
||||
public function pre_handle() {
|
||||
|
||||
check_ajax_referer( Format::format_nonce_name( $this->request_name ) );
|
||||
$this->handle();
|
||||
|
||||
}
|
||||
|
||||
abstract protected function handle();
|
||||
|
||||
}
|
||||
33
src/Extenders/Ajax/Load_Admin_Script.php
Normal file
33
src/Extenders/Ajax/Load_Admin_Script.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders\Ajax;
|
||||
use RomhackPlaza\Extenders\Admin_Scripts;
|
||||
use RomhackPlaza\Overrides\Roles;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Load_Admin_Script extends Abstract_Ajax {
|
||||
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(
|
||||
'load_admin_script',
|
||||
false
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
protected function handle()
|
||||
{
|
||||
global $_romhackplaza;
|
||||
if( $_romhackplaza->user_roles->current_upper() != Roles::Administrator )
|
||||
wp_send_json_error( [ 'message' => 'You don\'t have permission to execute an admin script.' ] );
|
||||
|
||||
define( 'ROMHACKPLAZA_ADMIN_SCRIPT', true );
|
||||
$script_name = isset( $_POST['script'] ) ? sanitize_text_field( wp_unslash( $_POST['script'] ) ) : '';
|
||||
|
||||
if( !Admin_Scripts::execute( $script_name ) )
|
||||
wp_send_json_error( [ 'message' => 'An error occured while executing your script.' ] );
|
||||
}
|
||||
|
||||
}
|
||||
40
src/Extenders/Ajax/Notifications_Contact.php
Normal file
40
src/Extenders/Ajax/Notifications_Contact.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders\Ajax;
|
||||
use RomhackPlaza\Extenders\User_Notifications as Notif;
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Notifications_Contact extends Abstract_Ajax
|
||||
{
|
||||
|
||||
public function __construct(){
|
||||
|
||||
parent::__construct(
|
||||
'notifications_contact',
|
||||
false
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
protected function handle()
|
||||
{
|
||||
|
||||
$to = isset( $_POST['user'] ) ? absint( $_POST['user'] ) : 0;
|
||||
$content = isset( $_POST['content'] ) ? sanitize_textarea_field( $_POST['content'] ) : "";
|
||||
|
||||
if( $to == 0 || $content == "" )
|
||||
wp_send_json_error( [ 'message' => "Wrong content or to." ] );
|
||||
|
||||
Notif::add([
|
||||
'sender' => get_current_user_id(),
|
||||
'recipient' => $to,
|
||||
'type' => 'message',
|
||||
'content' => $content,
|
||||
'auto' => 0,
|
||||
'readed' => 0,
|
||||
'date' => time()
|
||||
] );
|
||||
wp_send_json_success( [ 'message' => "Good." ] );
|
||||
|
||||
}
|
||||
}
|
||||
52
src/Extenders/Ajax/Notifications_Reply.php
Normal file
52
src/Extenders/Ajax/Notifications_Reply.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders\Ajax;
|
||||
use RomhackPlaza\Extenders\User_Notifications as Notif;
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Notifications_Reply extends Abstract_Ajax {
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct(
|
||||
'notifications_reply',
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
protected function handle(){
|
||||
|
||||
$notification_id = isset( $_POST['notification'] ) ? absint( $_POST['notification'] ) : 0;
|
||||
$content = isset( $_POST['content'] ) ? sanitize_textarea_field( $_POST['content'] ) : "";
|
||||
|
||||
if( $notification_id == 0 || $content == "" )
|
||||
wp_send_json_error( [ 'message' => "Wrong notification id" ] );
|
||||
|
||||
$notification = Notif::get_by_id( $notification_id );
|
||||
if( absint( $notification['recipient'] ) !== get_current_user_id() ) // It's not you.
|
||||
wp_send_json_error( [ 'message' => "Wrong recipient" ] );
|
||||
|
||||
// Message copy.
|
||||
Notif::add( [
|
||||
'sender' => $notification['recipient'],
|
||||
'recipient' => $notification['recipient'],
|
||||
'type' => 'copy_message',
|
||||
'content' => $content,
|
||||
'auto' => 1,
|
||||
'readed' => 1,
|
||||
'date' => time()
|
||||
] );
|
||||
|
||||
Notif::add( [
|
||||
'sender' => $notification['recipient'],
|
||||
'recipient' => $notification['sender'],
|
||||
'type' => 'reply_message',
|
||||
'content' => $content,
|
||||
'auto' => 0,
|
||||
'readed' => 0,
|
||||
'date' => time()
|
||||
] );
|
||||
|
||||
wp_send_json_success( [ 'message' => 'Good' ] );
|
||||
}
|
||||
|
||||
}
|
||||
34
src/Extenders/Ajax/Notifications_Unread_To_Read.php
Normal file
34
src/Extenders/Ajax/Notifications_Unread_To_Read.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace romhackplaza\Extenders\Ajax;
|
||||
use RomhackPlaza\Extenders\User_Notifications as Notif;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Notifications_Unread_To_Read extends Abstract_Ajax {
|
||||
|
||||
public function __construct(){
|
||||
|
||||
parent::__construct(
|
||||
'notifications_unread_to_read',
|
||||
false
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
protected function handle(){
|
||||
|
||||
$notification_id = isset( $_POST['notification'] ) ? absint( $_POST['notification'] ) : 0;
|
||||
if( $notification_id == 0 )
|
||||
wp_send_json_error( [ 'message' => "Wrong notification ID" ] );
|
||||
|
||||
$notification = Notif::get_by_id( $notification_id );
|
||||
if( absint( $notification['recipient'] ) !== get_current_user_id() ) // It's not you.
|
||||
wp_send_json_error( [ 'message' => "Wrong recipient" ] );
|
||||
|
||||
Notif::unread_to_read( $notification_id );
|
||||
wp_send_json_success( ['message' => 'Good' ] );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
38
src/Extenders/Ajax/Reserve_Post_ID.php
Normal file
38
src/Extenders/Ajax/Reserve_Post_ID.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders\Ajax;
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Reserve_Post_ID extends Abstract_Ajax {
|
||||
|
||||
public function __construct(){
|
||||
|
||||
parent::__construct(
|
||||
'reserve_post_id',
|
||||
false
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
protected function handle()
|
||||
{
|
||||
|
||||
$post_type = isset( $_POST['custom_post_type'] ) ? sanitize_text_field( $_POST['custom_post_type'] ) : 'translations';
|
||||
$entry = [
|
||||
'post_title' => "Temporary Title",
|
||||
'post_content' => "",
|
||||
'post_status' => 'auto-draft',
|
||||
'post_author' => get_current_user_id(),
|
||||
'post_type' => $post_type,
|
||||
];
|
||||
|
||||
$entry_id = wp_insert_post( $entry );
|
||||
|
||||
if( $entry_id && !is_wp_error( $entry_id ) )
|
||||
wp_send_json_success( [ 'post_id' => $entry_id, 'message' => 'good' ] );
|
||||
else
|
||||
wp_send_json_error( [ 'post_id' => 0, 'message' => 'Unable to reserve post ID' ] );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
30
src/Extenders/Ajax/Search_Author_Term.php
Normal file
30
src/Extenders/Ajax/Search_Author_Term.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders\Ajax;
|
||||
use RomhackPlaza\Fetch;
|
||||
use RomhackPlaza\Format;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Search_Author_Term extends Abstract_Ajax {
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(
|
||||
'search_author_term',
|
||||
false
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
protected function handle()
|
||||
{
|
||||
$arr = Fetch::get_terms_by_request( 'author-name' );
|
||||
$arr = Format::format_for_select2( $arr, 'term_id', 'name' );
|
||||
|
||||
echo json_encode( $arr );
|
||||
wp_die();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
30
src/Extenders/Ajax/Search_Game_Term.php
Normal file
30
src/Extenders/Ajax/Search_Game_Term.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders\Ajax;
|
||||
use RomhackPlaza\Fetch;
|
||||
use RomhackPlaza\Format;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Search_Game_Term extends Abstract_Ajax {
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(
|
||||
'search_game_term',
|
||||
false
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
protected function handle()
|
||||
{
|
||||
$arr = Fetch::get_terms_by_request( 'game' );
|
||||
$arr = Format::format_for_select2( $arr, 'term_id', 'name' );
|
||||
|
||||
echo json_encode( $arr );
|
||||
wp_die();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
31
src/Extenders/Ajax/Search_User.php
Normal file
31
src/Extenders/Ajax/Search_User.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders\Ajax;
|
||||
use RomhackPlaza\Fetch;
|
||||
use RomhackPlaza\Format;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Search_User extends Abstract_Ajax {
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(
|
||||
'search_user',
|
||||
false
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
protected function handle()
|
||||
{
|
||||
|
||||
$arr = Fetch::get_users_by_request();
|
||||
$arr = Format::format_for_select2( $arr, 'ID', 'display_name' );
|
||||
|
||||
echo json_encode( $arr );
|
||||
wp_die();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
43
src/Extenders/Ajax/Set_Favorite_Server.php
Normal file
43
src/Extenders/Ajax/Set_Favorite_Server.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders\Ajax;
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Set_Favorite_Server extends Abstract_Ajax {
|
||||
|
||||
public function __construct(){
|
||||
|
||||
parent::__construct(
|
||||
'set_favorite_server',
|
||||
false
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
protected function handle()
|
||||
{
|
||||
|
||||
$post_id = isset( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : 0;
|
||||
$favorite_server_id = isset( $_POST['favorite_server'] ) ? absint( $_POST['favorite_server'] ) : -1; // Favorite server can be 0.
|
||||
|
||||
if( $post_id == 0 || $favorite_server_id == -1 )
|
||||
wp_send_json_error( [ 'post_id' => 0, 'message' => 'Unable to get Post ID and/or favorite server ID for update the favorite server.'] );
|
||||
|
||||
update_post_meta( $post_id, 'favorite_server', $favorite_server_id );
|
||||
update_post_meta( $post_id, 'favorite_server_timestamp', time() );
|
||||
|
||||
if( function_exists( 'aal_insert_log' ) ) // Log function.
|
||||
// If there is a favorite server, every files are updated.
|
||||
aal_insert_log( [
|
||||
'action' => 'file_update',
|
||||
'object_type' => 'Posts',
|
||||
'object_subtype' => get_post_type( $post_id ),
|
||||
'object_id' => $post_id,
|
||||
'object_name' => get_the_title( $post_id ),
|
||||
] );
|
||||
|
||||
wp_send_json_success( [ 'message' => 'good', 'post_id' => $post_id ] );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
685
src/Extenders/Ajax/Submissions_Save_Entry.php
Normal file
685
src/Extenders/Ajax/Submissions_Save_Entry.php
Normal file
@@ -0,0 +1,685 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders\Ajax;
|
||||
use RomhackPlaza\Overrides\Roles;
|
||||
use stdClass;
|
||||
use RomhackPlaza\Extenders\Post\Save_Post;
|
||||
|
||||
defined( '\ABSPATH' ) || exit;
|
||||
|
||||
class Submissions_Save_Entry extends Abstract_Ajax {
|
||||
|
||||
/**
|
||||
* List of all platforms IDs with auto enabling online patcher.
|
||||
* TODO: Change that crappy hardcode.
|
||||
*/
|
||||
const AUTO_ENABLE_ONLINE_PATCHER = [
|
||||
460, 458, 754, 457, 797, 453, 454, 455, 456, 459, 461, 462, 463, 464, 467, 394, 469, 470, 801, 474, 475, 476, 798, 388, 480, 403, 402, 401, 484, 399, 485, 400, 483, 471, 486, 489, 708, 3790
|
||||
];
|
||||
|
||||
protected bool $edit;
|
||||
protected StdClass $entry;
|
||||
protected \WP_Post|bool|null $post_object;
|
||||
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(
|
||||
'submissions_save_entry',
|
||||
false
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
protected function stop_error( string $error ){
|
||||
echo json_encode( [
|
||||
'status' => 'error',
|
||||
'action' => 'none',
|
||||
'message' => $error
|
||||
]);
|
||||
wp_die();
|
||||
}
|
||||
|
||||
protected function handle() {
|
||||
|
||||
global $_romhackplaza;
|
||||
$this->entry = new StdClass;
|
||||
|
||||
// Edit mode or create mode.
|
||||
$this->edit = isset( $_POST['post_id'] ) && intval( $_POST['post_id'] ) > 0;
|
||||
|
||||
// Get previous post if edit mode.
|
||||
if( $this->edit )
|
||||
$this->find_previous_post(); // $this->post_object
|
||||
|
||||
// Check primary permissions. (Author, not Read-Only or staff)
|
||||
$this->check_permissions();
|
||||
|
||||
// Get post type.
|
||||
$this->entry->post_type = isset( $_POST['post_type'] ) ? sanitize_text_field( $_POST['post_type'] ) : 'post';
|
||||
if( !in_array( $this->entry->post_type, $_romhackplaza->cpt->primary_cpt() ) )
|
||||
$this->stop_error( 'Invalid post type provided.');
|
||||
|
||||
// Bind some checks.
|
||||
$this->entry->save_to_drafts = isset( $_POST['saveToDrafts'] ) && $_POST['saveToDrafts'] == 'yes';
|
||||
$this->entry->keep_current_status = isset( $_POST['keepCurrentStatus'] ) && $_POST['keepCurrentStatus'] == 'yes';
|
||||
$this->entry->nsfw = isset( $_POST['nsfwEntry'] ) && $_POST['nsfwEntry'] == 'yes';
|
||||
$this->entry->is_a_tutorial = $this->entry->post_type == 'tutorials';
|
||||
|
||||
// Check post status.
|
||||
$this->entry->post_status = 'draft'; // Default choice.
|
||||
$this->determine_post_status(); // $this->entry->post_status.
|
||||
|
||||
// Prepare Game term search.
|
||||
$this->entry->game_title = isset( $_POST['gameTitle'] ) ? sanitize_text_field( $_POST['gameTitle'] ) : '';
|
||||
$this->entry->game_title = $this->entry->game_title |> Save_Post::edit_minor_words_in_title( ... );
|
||||
|
||||
// Get game term or create it.
|
||||
if( !empty( $this->entry->game_title ) )
|
||||
$this->create_or_get_game_term(); // $this->entry->game_id|game_title
|
||||
|
||||
// Get languages terms.
|
||||
$this->get_language_terms();
|
||||
|
||||
// Get platform term.
|
||||
$this->get_platform_term();
|
||||
|
||||
// Get genre ID.
|
||||
$this->entry->genre_id = isset( $_POST['genre'] ) ? intval( $_POST['genre'] ) : 0;
|
||||
|
||||
// Build entry title.
|
||||
$this->build_entry_title();
|
||||
|
||||
// Tutorial specific fields.
|
||||
if( $this->entry->is_a_tutorial ){
|
||||
$this->entry->tutorial_content = $_POST['postContent'] |> Save_Post::header_and_edited_content_for_tutorial(...);
|
||||
$this->entry->post_content = $this->entry->tutorial_content["content"];
|
||||
} else {
|
||||
$this->entry->tutorial_content = [];
|
||||
$this->entry->post_content = $_POST['postContent'];
|
||||
}
|
||||
|
||||
// Reserved post ID or not.
|
||||
$reserved_post_id_flag = isset( $_POST['reserved_post_id'] ) && intval( $_POST['reserved_post_id'] ) > 0;
|
||||
|
||||
// Flags.
|
||||
$this->entry->version_updated = false; // Flag for new update.
|
||||
$this->entry->creation = true;
|
||||
|
||||
// Save the entry !!!
|
||||
if( $this->edit )
|
||||
$this->edit_an_entry();
|
||||
elseif( !$reserved_post_id_flag )
|
||||
$this->create_an_entry();
|
||||
else
|
||||
$this->stop_error( "No reserved post ID provided." );
|
||||
|
||||
if( !$this->entry->ID || is_wp_error( $this->entry->ID ) ){
|
||||
$this->stop_error( "The post could not be created/edited." );
|
||||
}
|
||||
|
||||
// Save meta values.
|
||||
$this->save_meta_values();
|
||||
$this->index_entry();
|
||||
|
||||
echo json_encode( [
|
||||
'status' => 'success',
|
||||
'action' => ( $this->edit ? 'edit' : 'submit' ),
|
||||
'message' => ""
|
||||
]);
|
||||
wp_die();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and register game term if needed.
|
||||
* $entry->game_id : Term ID.
|
||||
* $entry->game_title : Term title or old title if not changed.
|
||||
* @return void
|
||||
*/
|
||||
protected function create_or_get_game_term() {
|
||||
|
||||
// Try by ID and term name.
|
||||
$term = get_term_by( 'id', $this->entry->game_title, 'game' ) ?: get_term_by( 'name', $this->entry->game_title, 'game' );
|
||||
|
||||
if( $term ){
|
||||
|
||||
$this->entry->game_title = $term->name;
|
||||
$this->entry->game_id = $term->term_id;
|
||||
|
||||
} else {
|
||||
|
||||
// Term creation.
|
||||
$term = wp_insert_term( $this->entry->game_title, 'game' );
|
||||
if( !is_wp_error( $term ) )
|
||||
$this->entry->game_id = $term['term_id'];
|
||||
else
|
||||
$this->entry->game_title = ''; // Error or no game.
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get each languages names and bind it into $this->entry
|
||||
* $entry->language_ids : Term IDs
|
||||
* $entry->language_titles : Term titles.
|
||||
* @return void
|
||||
*/
|
||||
protected function get_language_terms() {
|
||||
|
||||
$this->entry->language_ids = isset( $_POST['language'] ) ? array_map( 'intval', (array) $_POST['language'] ) : [];
|
||||
$this->entry->language_titles = [];
|
||||
|
||||
foreach( $this->entry->language_ids as $language_id ) {
|
||||
|
||||
$language_term = get_term_by( 'id', $language_id, 'language' );
|
||||
if( $language_term && !is_wp_error( $language_term ) )
|
||||
$this->entry->language_titles[] = $language_term->name;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get platform for the current entry.
|
||||
* $entry->platform_id : Term ID
|
||||
* $entry->platform_title : Term title
|
||||
* @return void
|
||||
*/
|
||||
protected function get_platform_term() {
|
||||
|
||||
$this->entry->platform_id = isset( $_POST['platform'] ) ? intval( $_POST['platform'] ) : 0;
|
||||
$this->entry->platform_title = "";
|
||||
|
||||
$platform_term = get_term_by( 'id', $this->entry->platform_id, 'platform' );
|
||||
if( $platform_term && !is_wp_error( $platform_term ) ) {
|
||||
$this->entry->platform_title = $platform_term->name;
|
||||
$this->entry->platform_short_title = Save_Post::get_short_platform_name( $this->entry->platform_title );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Find and register previous post ID.
|
||||
* $entry->ID : Entry ID
|
||||
* $entry->post_object : WP_Post entry.
|
||||
* @return void
|
||||
*/
|
||||
protected function find_previous_post() {
|
||||
|
||||
$this->entry->ID = intval( $_POST['post_id'] );
|
||||
$this->post_object = get_post( $this->entry->ID );
|
||||
|
||||
if( !$this->post_object )
|
||||
$this->stop_error( 'Post not found.' );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a user can submit a content.
|
||||
* If it's a subscriber, no.
|
||||
* If it's not the previous author, no.
|
||||
* @return void
|
||||
*/
|
||||
protected function check_permissions() {
|
||||
|
||||
global $_romhackplaza;
|
||||
|
||||
if( $this->edit && $this->post_object ){
|
||||
|
||||
if( get_current_user_id() != $this->post_object->post_author && !$_romhackplaza->user_roles->current_is_staff() ) // Not the author or not a staff member.
|
||||
$this->stop_error( 'You are not allowed to edit this post.' );
|
||||
|
||||
}
|
||||
|
||||
if( $_romhackplaza->user_roles->current_is( Roles::Read_Only ) )
|
||||
$this->stop_error( 'You are not allowed to post an entry.' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine with post type, user main role and NSFW checks what is the best status for this entry.
|
||||
* $entry->post_status.
|
||||
* @return void
|
||||
*/
|
||||
protected function determine_post_status() {
|
||||
|
||||
global $_romhackplaza;
|
||||
|
||||
if( $this->edit && $this->entry->keep_current_status ){
|
||||
$this->entry->post_status = $this->post_object->post_status ?? 'draft'; // Don't change post status.
|
||||
return;
|
||||
}
|
||||
|
||||
if( $this->entry->save_to_drafts ){ // Mandatory to be a draft.
|
||||
$this->entry->post_status = 'draft';
|
||||
return;
|
||||
}
|
||||
|
||||
if( $this->edit ){
|
||||
|
||||
if( $this->entry->nsfw || $this->entry->is_a_tutorial ){
|
||||
|
||||
// Staff user -> Published in any case.
|
||||
if( $_romhackplaza->user_roles->current_is_staff() ){
|
||||
$this->entry->post_status = 'publish';
|
||||
return;
|
||||
}
|
||||
|
||||
// Normal user with published post -> Keep published.
|
||||
if(
|
||||
( $_romhackplaza->user_roles->current_is( Roles::Verified ) || $_romhackplaza->user_roles->current_is( Roles::Member ) )
|
||||
&& $this->post_object == 'publish'
|
||||
){
|
||||
$this->entry->post_status = 'publish';
|
||||
return;
|
||||
}
|
||||
|
||||
// Normal user with non-published post -> Go into the queue.
|
||||
if(
|
||||
( $_romhackplaza->user_roles->current_is( Roles::Verified ) || $_romhackplaza->user_roles->current_is( Roles::Member ) )
|
||||
&& $this->post_object != 'publish'
|
||||
){
|
||||
$this->entry->post_status = 'pending';
|
||||
return;
|
||||
}
|
||||
|
||||
// Error handle.
|
||||
$this->entry->post_status = 'draft';
|
||||
return;
|
||||
|
||||
} else {
|
||||
|
||||
// Staff or verified user -> Published in any case.
|
||||
if( $_romhackplaza->user_roles->current_is_staff() || $_romhackplaza->user_roles->current_is( Roles::Verified ) ){
|
||||
$this->entry->post_status = 'publish';
|
||||
return;
|
||||
}
|
||||
|
||||
// Normal user with published post -> Keep published.
|
||||
if( $_romhackplaza->user_roles->current_is( Roles::Member ) && $this->post_object == 'publish' ){
|
||||
$this->entry->post_status = 'publish';
|
||||
return;
|
||||
}
|
||||
|
||||
// Normal user with non-published post -> Go into the queue.
|
||||
if( $_romhackplaza->user_roles->current_is( Roles::Member ) && $this->post_object != 'publish' ){
|
||||
$this->entry->post_status = 'pending';
|
||||
return;
|
||||
}
|
||||
|
||||
// Error handle.
|
||||
$this->entry->post_status = 'draft';
|
||||
return;
|
||||
}
|
||||
|
||||
} else { // Creation mode.
|
||||
|
||||
if( $this->entry->nsfw || $this->entry->is_a_tutorial ){
|
||||
|
||||
// Staff user -> Published in any case.
|
||||
if( $_romhackplaza->user_roles->current_is_staff() ){
|
||||
$this->entry->post_status = 'publish';
|
||||
return;
|
||||
}
|
||||
|
||||
// Normal user -> Go into the queue.
|
||||
if(
|
||||
( $_romhackplaza->user_roles->current_is( Roles::Verified ) || $_romhackplaza->user_roles->current_is( Roles::Member ) )
|
||||
){
|
||||
$this->entry->post_status = 'pending';
|
||||
return;
|
||||
}
|
||||
|
||||
// Error handle.
|
||||
$this->entry->post_status = 'draft';
|
||||
return;
|
||||
|
||||
} else {
|
||||
|
||||
// Staff or verified user -> Published in any case.
|
||||
if( $_romhackplaza->user_roles->current_is_staff() || $_romhackplaza->user_roles->current_is( Roles::Verified ) ){
|
||||
$this->entry->post_status = 'publish';
|
||||
return;
|
||||
}
|
||||
|
||||
// Normal user -> Go into the queue.
|
||||
if( $_romhackplaza->user_roles->current_is( Roles::Member ) ) {
|
||||
$this->entry->post_status = 'pending';
|
||||
return;
|
||||
}
|
||||
|
||||
// Error handle.
|
||||
$this->entry->post_status = 'draft';
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Build primary post title
|
||||
* $entry->post_title
|
||||
* @return void
|
||||
*/
|
||||
protected function build_entry_title(){
|
||||
|
||||
$entry_title = "";
|
||||
if( isset( $_POST['entryTitle'] ) )
|
||||
$entry_title = $_POST['entryTitle'] |> sanitize_text_field(...) |> Save_Post::edit_minor_words_in_title(...);
|
||||
|
||||
$language_str = !empty( $this->entry->language_titles ) ? implode( ', ', $this->entry->language_titles ) : '';
|
||||
|
||||
if( $this->entry->post_type === 'translations' && $entry_title != '' ){
|
||||
$this->entry->post_title = sprintf( '%s (%s Translation) %s', $entry_title, $language_str, $this->entry->platform_short_name );
|
||||
}
|
||||
else if( $this->entry->post_type === 'translations' ){
|
||||
$this->entry->post_title = sprintf( '%s (%s Translation) %s', $this->entry->game_title, $language_str, $this->entry->platform_short_name );
|
||||
}
|
||||
else if( $this->entry->post_type === 'homebrew' ){
|
||||
$this->entry->post_title = sprintf( '%s (%s) Homebrew', $this->entry->game_title, $this->entry->platform_short_name );
|
||||
}
|
||||
else if( $this->entry->post_type === 'romhacks' ){
|
||||
$this->entry->post_title = sprintf('%s (%s) Romhack', $entry_title, $this->entry->platform_short_name );
|
||||
}
|
||||
else if( $this->entry->post_type === 'lua-scripts' ){
|
||||
$this->entry->post_title = sprintf( '%s (%s) LUA Script', $entry_title, $this->entry->platform_short_name );
|
||||
}
|
||||
else if( $this->entry->post_type === 'utilities' ){
|
||||
$this->entry->post_title = sprintf( '%s - Utility', $entry_title );
|
||||
}
|
||||
else if( $this->entry->post_type === 'documents' ){
|
||||
$this->entry->post_title = sprintf( '%s - Document', $entry_title );
|
||||
}
|
||||
else if( $this->entry->post_type === 'tutorials' ){
|
||||
$this->entry->post_title = sprintf( '%s - Tutorial', $entry_title );
|
||||
}
|
||||
else {
|
||||
$this->entry->post_title = $entry_title;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function create_an_entry(){
|
||||
|
||||
$post_data_for_wp = [
|
||||
'ID' => intval( $_POST['reserved_post_id'] ),
|
||||
'post_title' => sanitize_text_field( $this->entry->post_title ),
|
||||
'post_content' => wp_kses_post( $this->entry->post_content ),
|
||||
'post_status' => $this->entry->post_status,
|
||||
'post_type' => $this->entry->post_type,
|
||||
'comment_status' => 'open',
|
||||
];
|
||||
|
||||
$this->entry->creation = true; // We are in create mode.
|
||||
$this->entry->ID = wp_insert_post( $post_data_for_wp );
|
||||
|
||||
// TODO: Cache
|
||||
|
||||
}
|
||||
|
||||
protected function edit_an_entry(){
|
||||
|
||||
$post_name = isset( $_POST['entrySlug'] ) && !empty( $_POST['entrySlug'] ) ? sanitize_title( $_POST['entrySlug'] ) : sanitize_title( $this->entry->post_title );
|
||||
|
||||
$post_data_for_wp = [
|
||||
'ID' => intval( $this->entry->ID ),
|
||||
'post_title' => sanitize_text_field( $this->entry->post_title ),
|
||||
'post_content' => wp_kses_post( $this->entry->post_content ),
|
||||
'post_name' => $post_name,
|
||||
'post_status' => $this->entry->post_status,
|
||||
'post_type' => $this->entry->post_type,
|
||||
'comment_status' => 'open',
|
||||
];
|
||||
|
||||
if( $this->entry->post_type !== 'news' && !$this->entry->is_a_tutorial ){
|
||||
|
||||
// The version number changed or not ?
|
||||
$current_version_number = get_field( 'version_number', $this->entry->ID );
|
||||
$new_version_number = isset( $_POST['versionNumber' ] ) ? sanitize_text_field( $_POST['versionNumber'] ) : '';
|
||||
|
||||
if( $current_version_number === false || $current_version_number === null || $current_version_number !== $new_version_number ){
|
||||
// The version number changed.
|
||||
$current_time = current_time( 'mysql' );
|
||||
$post_data_for_wp['post_date'] = $current_time;
|
||||
$post_data_for_wp['post_date_gmt'] = get_gmt_from_date($current_time);
|
||||
$this->entry->version_updated = true;
|
||||
// TODO : Cache
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->entry->creation = false; // We are in edit mode.
|
||||
$this->entry->ID = wp_update_post( $post_data_for_wp );
|
||||
|
||||
}
|
||||
|
||||
protected function create_and_set_authors(){
|
||||
|
||||
$authors = isset( $_POST['author-name'] ) && is_array( $_POST['author-name'] ) ? $_POST['author-name'] : [];
|
||||
wp_set_object_terms( $this->entry->ID, [], 'author-name' ); // Reset authors.
|
||||
|
||||
foreach ( $authors as $author ) {
|
||||
if( is_numeric( $author ) ) // Already exists.
|
||||
wp_set_object_terms( $this->entry->ID, intval( $author ), 'author-name', true );
|
||||
else {
|
||||
$term = wp_insert_term( $author, 'author-name' ); // Create term.
|
||||
if( !is_wp_error( $term ) && isset( $term['term_id'] ) )
|
||||
wp_set_object_terms( $this->entry->ID, $term['term_id'], 'author-name', true );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function save_meta_values(){
|
||||
|
||||
global $_romhackplaza;
|
||||
|
||||
// Discord noticed field.
|
||||
$discord_noticed = get_post_meta( $this->entry->ID, 'discord_noticed', true );
|
||||
|
||||
$discord_new_post_flag = $this->entry->post_status === 'publish' && (
|
||||
$discord_noticed === "" || $discord_noticed === false || $discord_noticed === "no"
|
||||
) && $this->entry->post_type !== 'news';
|
||||
$discord_update_post_flag = $this->entry->post_status === 'publish' && $this->entry->version_updated && $this->entry->post_type !== 'news';
|
||||
|
||||
// ACF specific fields saving. Gallery + Featured image.
|
||||
if( function_exists( 'acf_save_post' ) )
|
||||
acf_save_post( $this->entry->ID );
|
||||
|
||||
// Custom featured image field.
|
||||
$featured_image_id = get_field( 'custom_featured_image', $this->entry->ID );
|
||||
if( $featured_image_id )
|
||||
set_post_thumbnail( $this->entry->ID, $featured_image_id ); // Set it as post thumbnail.
|
||||
|
||||
// Version number field
|
||||
if( isset( $_POST['versionNumber'] ) )
|
||||
update_field( 'version_number', sanitize_text_field( $_POST['versionNumber'] ), $this->entry->ID );
|
||||
|
||||
// Entry title field
|
||||
if( isset( $_POST['entryTitle'] ) )
|
||||
update_field( 'entry_title', Save_Post::edit_minor_words_in_title( sanitize_text_field( $_POST['entryTitle'] ) ), $this->entry->ID );
|
||||
|
||||
// Release date field
|
||||
if( isset( $_POST['release_date'] ) ){
|
||||
|
||||
$date = \DateTime::createFromFormat( 'Y-m-d', sanitize_text_field( $_POST['release_date'] ) );
|
||||
if( $date )
|
||||
update_field( 'release_date', $date->format( 'Ymd' ), $this->entry->ID );
|
||||
|
||||
}
|
||||
|
||||
// Project link field
|
||||
if( isset( $_POST['release_site'] ) )
|
||||
update_field( 'release_site', esc_url_raw( $_POST['release_site'] ), $this->entry->ID );
|
||||
|
||||
// YouTube video field
|
||||
if( isset( $_POST['youtube_video'] ) )
|
||||
update_field( 'youtube_video', esc_url_raw( $_POST['youtube_video'] ), $this->entry->ID );
|
||||
|
||||
// For News. Local Plaza project page link field.
|
||||
if( isset( $_POST['romhacks_page'] ) )
|
||||
update_field( 'romhacks_page', esc_url_raw( $_POST['romhacks_page'] ), $this->entry->ID );
|
||||
|
||||
// Hashes field.
|
||||
if( isset( $_POST['hashes'] ) ){
|
||||
$snz = sanitize_textarea_field( $_POST['hashes'] );
|
||||
update_field( 'hashes', $snz, $this->entry->ID );
|
||||
do_action( 'RomhackPlaza\\Extenders\\Post\\Hashes_Table\\Update_CRC32_SHA1', intval( $this->entry->ID ), $snz );
|
||||
}
|
||||
|
||||
// Credits field.
|
||||
if( isset( $_POST['staff'] ) )
|
||||
update_field( 'staff', sanitize_textarea_field( $_POST['staff'] ), $this->entry->ID );
|
||||
|
||||
// For tutorials. Summary as Post excerpt.
|
||||
if( isset( $_POST['summary'] ) )
|
||||
wp_update_post( [
|
||||
'ID' => $this->entry->ID,
|
||||
'post_excerpt' => sanitize_textarea_field( $_POST['summary'] ),
|
||||
] );
|
||||
|
||||
// For tutorials. TOC.
|
||||
if( $this->entry->tutorial_content !== [] && $this->entry->tutorial_content["headers"] != [] )
|
||||
update_field( 'table_of_contents', $this->entry->tutorial_content["headers"], $this->entry->ID );
|
||||
|
||||
// If there is an update of the entry
|
||||
if( $this->entry->version_updated )
|
||||
update_post_meta( $this->entry->ID, 'entry_version_updated_once', 1 );
|
||||
|
||||
// Update queue status. Add Edited by his author.
|
||||
if( get_post_status( $this->entry->ID ) === "pending" && !$_romhackplaza->user_roles->current_is_staff() ){
|
||||
|
||||
// Current user can edit the entry. It's in the queue and it's not a staff member.
|
||||
$queue_status = get_field( 'queue_status', $this->entry->ID );
|
||||
if( $queue_status && $queue_status !== "" && $queue_status !== "not checked" ){ // If this entry have a custom queue status.
|
||||
|
||||
$queue_status .= "\nEdited by his author";
|
||||
update_field( 'queue_status', $queue_status, $this->entry->ID );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Online patcher. Only check on create mode and for a romhack or a translation.
|
||||
if( $this->entry->creation && in_array( $this->entry->post_type, [ 'romhacks', 'translations' ] ) ){
|
||||
|
||||
// Can be auto enabled.
|
||||
if( in_array( intval( $this->entry->platform_id ), self::AUTO_ENABLE_ONLINE_PATCHER ) ) {
|
||||
|
||||
// Not a read-only or a member.
|
||||
if( $_romhackplaza->user_roles->current_is_staff() || $_romhackplaza->user_roles->current_is( Roles::Verified ) || $_romhackplaza->user_roles->current_is( Roles::Bot ) )
|
||||
update_post_meta( $this->entry->ID, 'online_patcher', 'enabled' );
|
||||
else
|
||||
update_post_meta( $this->entry->ID, 'online_patcher', 'disabled' );
|
||||
} else
|
||||
update_post_meta( $this->entry->ID, 'online_patcher', 'disabled' );
|
||||
|
||||
}
|
||||
|
||||
// Custom Taxonomies !
|
||||
|
||||
// Game term.
|
||||
if( $this->entry->game_id )
|
||||
wp_set_object_terms( $this->entry->ID, intval( $this->entry->game_id ), 'game', false );
|
||||
|
||||
// For romhacks.
|
||||
if( isset( $_POST['modifications'] ) ){
|
||||
$modifications = array_map( 'intval', $_POST['modifications'] );
|
||||
wp_set_object_terms( $this->entry->ID, $modifications, 'modifications', false );
|
||||
}
|
||||
|
||||
// For LUA scripts.
|
||||
if( isset( $_POST['lua-modifications'] ) ){
|
||||
$modifications = array_map( 'intval', $_POST['lua-modifications'] );
|
||||
wp_set_object_terms( $this->entry->ID, $modifications, 'lua-modifications', false );
|
||||
}
|
||||
|
||||
// For homebrew.
|
||||
if( isset( $_POST['homebrew-type'] ) ){
|
||||
$modifications = array_map( 'intval', $_POST['homebrew-type'] );
|
||||
wp_set_object_terms( $this->entry->ID, $modifications, 'homebrew-type', false );
|
||||
}
|
||||
|
||||
// Languages
|
||||
if( !empty( $_POST['language'] ) ){
|
||||
$langs = array_map( 'intval', $_POST['language'] );
|
||||
wp_set_object_terms( $this->entry->ID, $langs, 'language', false );
|
||||
}
|
||||
|
||||
if( $this->entry->platform_id && $this->entry->platform_id != 0 )
|
||||
wp_set_object_terms( $this->entry->ID, $this->entry->platform_id, 'platform', false );
|
||||
|
||||
if( $this->entry->genre_id && $this->entry->genre_id != 0 )
|
||||
wp_set_object_terms( $this->entry->ID, $this->entry->genre_id, 'genre', false );
|
||||
|
||||
if( isset( $_POST['hack-status'] ) ){
|
||||
$hks = intval( $_POST['hack-status'] );
|
||||
wp_set_object_terms( $this->entry->ID, $hks, 'hack-status', false );
|
||||
}
|
||||
|
||||
// Utilities.
|
||||
if( isset( $_POST['experience-level'] ) ){
|
||||
$exp_level = intval( $_POST['experience-level'] );
|
||||
wp_set_object_terms( $this->entry->ID, $exp_level, 'experience-level', false );
|
||||
}
|
||||
|
||||
if( !empty( $_POST['utility-category'] ) ){
|
||||
$cat = array_map( 'intval', $_POST['utility-category'] );
|
||||
wp_set_object_terms( $this->entry->ID, $cat, 'utility-category', false );
|
||||
}
|
||||
|
||||
if( !empty( $_POST['document-category'] ) ){
|
||||
$cat = array_map( 'intval', $_POST['document-category'] );
|
||||
wp_set_object_terms( $this->entry->ID, $cat, 'document-category', false );
|
||||
}
|
||||
|
||||
if( !empty( $_POST['tutorial-category'] ) ){
|
||||
$cat = array_map( 'intval', $_POST['tutorial-category'] );
|
||||
wp_set_object_terms( $this->entry->ID, $cat, 'tutorial-category', false );
|
||||
}
|
||||
|
||||
if( !empty( $_POST['news-category'] ) ){
|
||||
$cat = intval( $_POST['news-category'] );
|
||||
wp_set_object_terms( $this->entry->ID, $cat, 'news-category', false );
|
||||
}
|
||||
|
||||
if( isset( $_POST['utility-os'] ) ){
|
||||
$os = intval( $_POST['utility-os'] );
|
||||
wp_set_object_terms( $this->entry->ID, $os, 'utility-os', false );
|
||||
}
|
||||
|
||||
if( $this->entry->nsfw )
|
||||
wp_set_object_terms( $this->entry->ID, [ intval( $_romhackplaza->settings->get( 'nsfw_tag_id' ) ) ], 'post_tag', false );
|
||||
|
||||
$this->create_and_set_authors();
|
||||
|
||||
// For utilities & Documents.
|
||||
// TODO: Change order.
|
||||
if( isset( $_POST['removeGamePlatformTerms'] ) && $_POST['removeGamePlatformTerms'] === 'yes' ){
|
||||
wp_set_object_terms( $this->entry->ID, [], 'game', false );
|
||||
wp_set_object_terms( $this->entry->ID, [], 'platform', false );
|
||||
}
|
||||
|
||||
// Last update text.
|
||||
if( !is_null( wp_get_current_user() ) ) {
|
||||
$last_update = sprintf("Last updated on %s by %s.", current_time('mysql'), wp_get_current_user()->display_name);
|
||||
update_post_meta( $this->entry->ID, 'last_update_by', $last_update );
|
||||
}
|
||||
|
||||
do_action( 'RomhackPlaza\\Extenders\\Discord_Notification\\Send_Notification_After_Submission',
|
||||
$this->entry->ID,
|
||||
$this->entry->post_title,
|
||||
[ 'new_post' => $discord_new_post_flag, 'update_post' => $discord_update_post_flag ],
|
||||
isset( $_POST['versionNumber'] ) ? sanitize_text_field( $_POST['versionNumber'] ) : 0
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
protected function index_entry(){
|
||||
|
||||
if( function_exists( "FWP" ) ) // FacetWP
|
||||
FWP()->indexer->index( $this->entry->ID );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
52
src/Extenders/Ajax/Submit_Notification.php
Normal file
52
src/Extenders/Ajax/Submit_Notification.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders\Ajax;
|
||||
use RomhackPlaza\Extenders\User_Notifications;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Submit_Notification extends Abstract_Ajax {
|
||||
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(
|
||||
'submit_notification',
|
||||
false
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
protected function handle()
|
||||
{
|
||||
|
||||
global $_romhackplaza;
|
||||
if( !$_romhackplaza->user_roles->current_is_staff() )
|
||||
wp_send_json_error( [ 'message' => "You don't have permission to submit notifications." ] );
|
||||
|
||||
$type_select = isset( $_POST['type_select'] ) ? sanitize_text_field( $_POST['type_select'] ) : 'none';
|
||||
$anonymous = isset( $_POST['sender_anonymous'] ) ? sanitize_text_field( $_POST['anonymous'] ) : 'no';
|
||||
$all_users = isset( $_POST['recipients_all'] ) ? sanitize_text_field( $_POST['recipients_all'] ) : 'no';
|
||||
$recipients = isset( $_POST['recipients'] ) ? array_map( 'intval', $_POST['recipients'] ) : [];
|
||||
$content = isset( $_POST['content'] ) ? wp_kses_post( $_POST['content'] ) : '';
|
||||
|
||||
if( $all_users === "yes" || $all_users === "on" )
|
||||
$recipients = get_users( [ 'fields' => 'ID' ] );
|
||||
|
||||
$sender = $anonymous === "yes" || $anonymous === "on" ? $_ENV['ROMHACKPLAZA_DEFAULT_ACCOUNT'] : get_current_user_id();
|
||||
|
||||
foreach ( $recipients as $recipient )
|
||||
User_Notifications::add([
|
||||
'sender' => $sender,
|
||||
'recipient' => $recipient,
|
||||
'type' => $type_select,
|
||||
'content' => $content,
|
||||
'auto' => 0,
|
||||
'readed' => 0,
|
||||
'date' => time()
|
||||
]);
|
||||
|
||||
wp_send_json_success( [ 'message' => 'Good.' ] );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
22
src/Extenders/Ajax/Update_Entry_Mod_Fields.php
Normal file
22
src/Extenders/Ajax/Update_Entry_Mod_Fields.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders\Ajax;
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Update_Entry_Mod_Fields extends Abstract_Ajax {
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(
|
||||
'update_entry_mod_fields',
|
||||
false
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
protected function handle()
|
||||
{
|
||||
// TODO: Line 1023
|
||||
}
|
||||
|
||||
}
|
||||
42
src/Extenders/Custom_Post_Status.php
Normal file
42
src/Extenders/Custom_Post_Status.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders;
|
||||
defined( '\ABSPATH' ) || exit;
|
||||
|
||||
class Custom_Post_Status extends Abstract_Extender {
|
||||
|
||||
/**
|
||||
* Custom post status name.
|
||||
* @var string
|
||||
*/
|
||||
final public string $name;
|
||||
|
||||
/**
|
||||
* Custom post status args like register_post_status()
|
||||
* @var array
|
||||
*/
|
||||
final public array $args;
|
||||
|
||||
public function __construct(string $name, array $args = []){
|
||||
|
||||
$this->name = $name;
|
||||
$this->args = $args;
|
||||
|
||||
parent::__construct();
|
||||
|
||||
}
|
||||
|
||||
protected function can_extend(): bool
|
||||
{
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
protected function extend(): void {
|
||||
|
||||
$this->add_action('init', fn() => register_post_status($this->name, $this->args) );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
65
src/Extenders/Custom_Post_Type.php
Normal file
65
src/Extenders/Custom_Post_Type.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders;
|
||||
defined( '\ABSPATH' ) || exit;
|
||||
|
||||
class Custom_Post_Type extends Abstract_Extender {
|
||||
|
||||
/**
|
||||
* Custom post type name.
|
||||
* @var string
|
||||
*/
|
||||
final public string $name;
|
||||
|
||||
/**
|
||||
* Custom post type singular name.
|
||||
* @var string
|
||||
*/
|
||||
final public string $singular_name;
|
||||
|
||||
/**
|
||||
* Custom post type args like register_post_type()
|
||||
* @var array
|
||||
*/
|
||||
final public array $args;
|
||||
|
||||
/**
|
||||
* ACF field group key for forms.
|
||||
* @var string
|
||||
*/
|
||||
protected string $acf_field_group_key = "";
|
||||
|
||||
public function __construct(string $name, string $singular_name = "", array $args = []){
|
||||
|
||||
$this->name = $name;
|
||||
$this->singular_name = $singular_name;
|
||||
$this->args = $args;
|
||||
|
||||
parent::__construct();
|
||||
|
||||
}
|
||||
|
||||
public function getAcfFieldGroupKey(): string
|
||||
{
|
||||
return $this->acf_field_group_key;
|
||||
}
|
||||
|
||||
public function setAcfFieldGroupKey(string $acf_field_group_key): void
|
||||
{
|
||||
$this->acf_field_group_key = $acf_field_group_key;
|
||||
}
|
||||
|
||||
protected function can_extend(): bool
|
||||
{
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
protected function extend(): void {
|
||||
|
||||
$this->add_action('init', fn() => register_post_type($this->name, $this->args) );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
99
src/Extenders/Discord_Notification.php
Normal file
99
src/Extenders/Discord_Notification.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders;
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Discord_Notification extends Abstract_Extender {
|
||||
|
||||
protected function can_extend(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function extend(): void
|
||||
{
|
||||
$this->add_action( 'RomhackPlaza\\Extenders\\Discord_Notification\\Send_Notification_After_Submission', [ $this, 'send_notification_after_submission' ], 10, 4 );
|
||||
}
|
||||
|
||||
protected function get_webhook_url( string $type = 'global' ): string {
|
||||
|
||||
$webhook_type = "";
|
||||
switch( $type ) {
|
||||
case 'romhacks':
|
||||
case 'translations':
|
||||
$webhook_type = 'discord_webhook_romhacks_translations';
|
||||
break;
|
||||
default:
|
||||
$webhook_type = 'discord_webhook_global';
|
||||
break;
|
||||
}
|
||||
|
||||
global $_romhackplaza;
|
||||
|
||||
$webhook_url = $_romhackplaza->settings->get( $webhook_type );
|
||||
if( !$webhook_url || $webhook_url == "" )
|
||||
return "unknown";
|
||||
|
||||
return $webhook_url;
|
||||
|
||||
}
|
||||
|
||||
protected function send_to_discord( string $webhook, string $content ){
|
||||
|
||||
$curl = curl_init( $webhook );
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode( [ "content" => $content ] ) );
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
@curl_exec( $curl ); // Nevermind the answer.
|
||||
|
||||
}
|
||||
|
||||
public function send_notification_after_submission(
|
||||
int $post_id,
|
||||
string $post_title,
|
||||
array $flags = [ 'new_post' => false, 'update_post' => false ],
|
||||
int $new_version_number = 0
|
||||
): void {
|
||||
|
||||
if( !$flags['new_post'] && !$flags['update_post'] ) return;
|
||||
|
||||
$post_type = get_post_type( $post_id );
|
||||
if( !$post_type ) return;
|
||||
|
||||
$strings = [
|
||||
'new_post' => sprintf(
|
||||
"## A new entry has been posted.\n\n[%s](%s)\n\n%s",
|
||||
$post_title, $_ENV['ROMHACKPLAZA_SHORT_URL'] . $post_id, strip_tags( get_the_content( null, false, $post_id ) )
|
||||
),
|
||||
'update_post' => sprintf(
|
||||
"## A new version of this entry has been posted.\n\n[%s](%s)\n\n%s\n\n**New version number: %s**",
|
||||
$post_title, $_ENV['ROMHACKPLAZA_SHORT_URL'] . $post_id, strip_tags( get_the_content( null, false, $post_id ) ), $new_version_number
|
||||
)
|
||||
];
|
||||
|
||||
$webhook = null; $content = null;
|
||||
|
||||
if( $flags['new_post'] && in_array( $post_type, [ 'romhacks', 'homebrew' ] ) ){
|
||||
$webhook = $this->get_webhook_url( 'romhacks' );
|
||||
$content = $strings['new_post'];
|
||||
} else if( $flags['new_post'] ){
|
||||
$webhook = $this->get_webhook_url( 'global' );
|
||||
$content = $strings['new_post'];
|
||||
} else if( $flags['update_post'] && in_array( $post_type, [ 'romhacks', 'homebrew' ] ) ){
|
||||
$webhook = $this->get_webhook_url( 'romhacks' );
|
||||
$content = $strings['update_post'];
|
||||
} else if( $flags['update_post'] ){
|
||||
$webhook = $this->get_webhook_url( 'global' );
|
||||
$content = $strings['update_post'];
|
||||
}
|
||||
|
||||
if( $webhook == null || $content == null ) return;
|
||||
|
||||
$this->send_to_discord( $webhook, $content );
|
||||
update_post_meta( $post_id, 'discord_noticed', "yes" );
|
||||
|
||||
}
|
||||
}
|
||||
74
src/Extenders/Post/Hashes_Table.php
Normal file
74
src/Extenders/Post/Hashes_Table.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders\Post;
|
||||
use RomhackPlaza\Database\Database_Table;
|
||||
use RomhackPlaza\Database\Database_Tools;
|
||||
use RomhackPlaza\Extenders\Abstract_Extender;
|
||||
use RomhackPlaza\Fetch;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Hashes_Table extends Abstract_Extender implements Database_Table {
|
||||
|
||||
const string TABLE_NAME = "crc_entry";
|
||||
|
||||
use Database_Tools;
|
||||
|
||||
public static function create_table()
|
||||
{
|
||||
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
|
||||
global $wpdb;
|
||||
|
||||
$table_name = $wpdb->prefix . self::TABLE_NAME;
|
||||
$charset_collate = $wpdb->get_charset_collate();
|
||||
|
||||
$sql = "
|
||||
CREATE TABLE {$table_name} (
|
||||
entry_id INT(11) NOT NULL,
|
||||
crc VARCHAR(20) NOT NULL,
|
||||
sha VARCHAR(100) NOT NULL,
|
||||
PRIMARY KEY (entry_id)
|
||||
) {$charset_collate};
|
||||
)
|
||||
";
|
||||
|
||||
dbDelta( $sql );
|
||||
}
|
||||
|
||||
public static function verify_table()
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
if( !self::table_exists( $wpdb->prefix . self::TABLE_NAME ) ){
|
||||
self::create_table();
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Columns verif.
|
||||
|
||||
}
|
||||
|
||||
protected function can_extend(): bool
|
||||
{
|
||||
return true; // The table is created each time the plugin is activated if it does not exist.
|
||||
}
|
||||
|
||||
protected function extend(): void {
|
||||
|
||||
$this->add_action( 'RomhackPlaza\\Extenders\\Post\\Hashes_Table\\Update_CRC32_SHA1', [ $this, 'update_crc32_sha1_from_entry' ], 10, 2 );
|
||||
|
||||
}
|
||||
|
||||
public function update_crc32_sha1_from_entry( int $post_id, string $s ) {
|
||||
|
||||
global $wpdb;
|
||||
$table_name = $wpdb->prefix . self::TABLE_NAME;
|
||||
|
||||
$crc = Fetch::crc32_in_string( $s );
|
||||
$sha = Fetch::sha1_in_string( $s );
|
||||
if( $crc || $sha )
|
||||
$wpdb->replace( $table_name, [ 'entry_id' => $post_id, 'crc' => $crc[0] ?? false, 'sha' => $sha[0] ?? false ], [ '%d', '%s', '%s' ] );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
64
src/Extenders/Post/Properties.php
Normal file
64
src/Extenders/Post/Properties.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders\Post;
|
||||
use RomhackPlaza\Extenders\Abstract_Extender;
|
||||
use RomhackPlaza\Extenders\Advanced_Custom_Fields_Pro;
|
||||
defined( '\ABSPATH' ) || exit;
|
||||
|
||||
class Properties extends Abstract_Extender {
|
||||
|
||||
public static \WP_Post $current_post;
|
||||
|
||||
protected function can_extend(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function extend(): void {
|
||||
|
||||
$this->add_action( 'wp', function(){
|
||||
global $post;
|
||||
static::change_current_post( $post );
|
||||
}, 20 );
|
||||
|
||||
}
|
||||
|
||||
public static function change_current_post( \WP_Post $post ): void {
|
||||
|
||||
static::$current_post = $post;
|
||||
|
||||
}
|
||||
|
||||
private static function tag_exists_in_entry( string $setting ): bool {
|
||||
|
||||
global $_romhackplaza;
|
||||
$tag_id = absint( $_romhackplaza->settings->get( $setting ) );
|
||||
|
||||
if( $tag_id === 0 )
|
||||
return false; // Not enabled.
|
||||
|
||||
$post_tags = wp_get_post_tags( static::$current_post->ID );
|
||||
if( !$post_tags || $post_tags === [] )
|
||||
return false; // No tags.
|
||||
|
||||
foreach ( $post_tags as $post_tag ) {
|
||||
if( $post_tag->term_id == $tag_id )
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function public_edit_disabled(): bool {
|
||||
|
||||
return static::tag_exists_in_entry( 'public_edit_disabled_tag_id' );
|
||||
|
||||
}
|
||||
|
||||
public static function nsfw(): bool {
|
||||
|
||||
return static::tag_exists_in_entry( 'nsfw_tag_id' );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
153
src/Extenders/Post/Save_Post.php
Normal file
153
src/Extenders/Post/Save_Post.php
Normal file
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders\Post;
|
||||
use RomhackPlaza\Extenders\Abstract_Extender;
|
||||
use RomhackPlaza\Extenders\Advanced_Custom_Fields_Pro;
|
||||
|
||||
defined( '\ABSPATH' ) || exit;
|
||||
|
||||
class Save_Post extends Abstract_Extender {
|
||||
|
||||
protected function can_extend(): bool {
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
protected function extend(): void {
|
||||
|
||||
$this->add_filter( 'sanitize_title', [ $this, 'remove_words_from_slug' ] );
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove some keys words in post slug.
|
||||
* @param string $slug
|
||||
* @return string
|
||||
*/
|
||||
public function remove_words_from_slug( string $slug ): string {
|
||||
|
||||
$list = [
|
||||
'-romhack',
|
||||
'-homebrew',
|
||||
'-document',
|
||||
'-tutorial',
|
||||
'-lua-script'
|
||||
];
|
||||
|
||||
if( is_admin() )
|
||||
return $slug;
|
||||
|
||||
return str_replace( $list, '', $slug );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add post_parent for attachments added in a ACF gallery element.
|
||||
* @see Advanced_Custom_Fields_Pro
|
||||
* @param $post_id
|
||||
* @return void
|
||||
*/
|
||||
public function bind_post_parent_attachment_from_gallery( $post_id ) {
|
||||
|
||||
// Exclude autosave or non-ACF save.
|
||||
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return;
|
||||
if ( is_int(wp_is_post_revision($post_id)) ) return;
|
||||
if ( is_int(wp_is_post_autosave($post_id)) ) return;
|
||||
if ( empty($_POST['acf']) ) return;
|
||||
|
||||
$files = get_field( 'my_gallery', $post_id, false );
|
||||
if( $files ) {
|
||||
|
||||
foreach ($files as $file_id) {
|
||||
$attachment = [ 'ID' => $file_id, 'post_parent' => $post_id ];
|
||||
wp_update_post( $attachment ); // Update attachment.
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Capitalize only some minor words.
|
||||
* @param string $title
|
||||
* @return string
|
||||
* @see RomhackPlaza\Extenders\Ajax\Submissions_Save_Entry
|
||||
*/
|
||||
public static function edit_minor_words_in_title( string $title ): string {
|
||||
|
||||
/**
|
||||
* Change Minor words list.
|
||||
*
|
||||
* @param array - Minor words list.
|
||||
* @return array
|
||||
*/
|
||||
$minor_words_list = apply_filters( 'RomhackPlaza\\Extenders\\Post\\edit_minor_words_in_title\\List', [
|
||||
'a', 'an', 'and', 'at', 'but', 'by', 'for', 'in', 'nor', 'of', 'on', 'or', 'to'
|
||||
] );
|
||||
|
||||
$words = explode( ' ', $title );
|
||||
foreach( $words as $k => $word ) {
|
||||
|
||||
if( $k == 0 || $k == count( $words ) - 1 || !in_array( $word |> strtolower( ... ), $minor_words_list ) )
|
||||
$words[$k] = ucfirst( $word );
|
||||
|
||||
}
|
||||
|
||||
return implode( ' ', $words );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change platform name to short platform name.
|
||||
* @param string $platform_name
|
||||
* @return string
|
||||
* @see RomhackPlaza\Extenders\Ajax\Submissions_Save_Entry
|
||||
*/
|
||||
public static function get_short_platform_name( string $platform_name ): string {
|
||||
|
||||
$platform_changes = apply_filters( 'RomhackPlaza\\Extenders\\Post\\Save_Post\\get_short_platform_name', [
|
||||
'Family Computer Disk System' => 'FDS',
|
||||
'Nintendo Entertainment System' => 'NES',
|
||||
'Super Nintendo' => 'SNES',
|
||||
'Game Boy Color' => 'GBC',
|
||||
'SEGA Genesis' => 'Genesis',
|
||||
'SEGA Master System' => 'SMS',
|
||||
'SEGA Game Gear' => 'GG',
|
||||
'PlayStation Portable' => 'PSP'
|
||||
] );
|
||||
|
||||
if( empty( $platform_name ) )
|
||||
return '';
|
||||
|
||||
return $platform_changes[ $platform_name ] ?? $platform_name;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add some IDs to the HTML title (3 to 6) to be used in the TOC.
|
||||
* @param string $post_content
|
||||
* @return array
|
||||
*/
|
||||
public static function header_and_edited_content_for_tutorial( string $post_content ): array {
|
||||
|
||||
$headers = [];
|
||||
$content = preg_replace_callback( '/(\<h[3-6](.*))\>(.*)(<\/h[3-6]>)/i', function( $matches ) use ( &$headers ) {
|
||||
|
||||
// Add HTML ID if needed.
|
||||
if( !stripos( $matches[0], 'id=') ){
|
||||
$matches[0] = $matches[1] . $matches[2] . ' id="' . sanitize_title( $matches[3] ) . '">' . $matches[3] . $matches[4];
|
||||
}
|
||||
|
||||
$headers[] = [
|
||||
"title" => sanitize_title( $matches[3] ),
|
||||
"text" => $matches[3]
|
||||
];
|
||||
|
||||
}, $post_content);
|
||||
|
||||
return [ "content" => $content, "headers" => $headers ];
|
||||
}
|
||||
|
||||
}
|
||||
476
src/Extenders/Submissions.php
Normal file
476
src/Extenders/Submissions.php
Normal file
@@ -0,0 +1,476 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders;
|
||||
defined( '\ABSPATH' ) || exit;
|
||||
|
||||
use RomhackPlaza\API\File_Server;
|
||||
use RomhackPlaza\Extenders\Post\Properties;
|
||||
use RomhackPlaza\Format;
|
||||
use RomhackPlaza\Overrides\Roles;
|
||||
use RomhackPlaza\Script;
|
||||
use RomhackPlaza\Script_Type;
|
||||
|
||||
class Submissions extends Abstract_Extender {
|
||||
|
||||
/**
|
||||
* All Children from submissions.
|
||||
* @var array
|
||||
*/
|
||||
public array $children = [];
|
||||
|
||||
protected function can_extend(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function extend(): void {
|
||||
|
||||
$this->add_action( 'wp_enqueue_scripts', [ $this, 'load_assets' ] );
|
||||
$this->add_filter( 'timber/context', [ $this, 'fill_fields_for_timber' ], 5 );
|
||||
$this->add_action( 'RomhackPlaza\\Extenders\\Submissions\\Get_A_File_Server', [ $this, 'get_file_server' ] );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return list of IDs for submissions.
|
||||
* @param string $type 'simple', 'complete' or 'all' ( Default 'all' )
|
||||
* @return int[]
|
||||
*/
|
||||
public function get_all_forms_page_ids( string $type = 'all' ): array {
|
||||
|
||||
$option_name = '';
|
||||
|
||||
switch ( $type ) {
|
||||
case 'simple':
|
||||
$option_name = 'simple_submissions_form_page_ids';
|
||||
break;
|
||||
case 'complete':
|
||||
$option_name = 'complete_submissions_form_page_ids';
|
||||
break;
|
||||
default:
|
||||
$type = 'all'; // Make sure it's the affected value.
|
||||
break;
|
||||
}
|
||||
|
||||
global $_romhackplaza;
|
||||
|
||||
if( $type === 'simple' || $type === 'complete' ) {
|
||||
$string_list = $_romhackplaza->settings->get( $option_name );
|
||||
|
||||
$arr = explode( ';', $string_list );
|
||||
if( $arr[0] == '' )
|
||||
$arr = [];
|
||||
return array_map( 'intval', $arr );
|
||||
|
||||
}
|
||||
|
||||
$first_string_list = $_romhackplaza->settings->get( 'simple_submissions_form_page_ids' );
|
||||
$first_arr = explode( ';', $first_string_list );
|
||||
if( $first_arr[0] == '' )
|
||||
$first_arr = [];
|
||||
|
||||
$second_string_list = $_romhackplaza->settings->get( 'complete_submissions_form_page_ids' );
|
||||
$second_arr = explode( ';', $second_string_list );
|
||||
if( $second_arr[0] == '' )
|
||||
$second_arr = [];
|
||||
|
||||
$arr = array_merge( $first_arr, $second_arr );
|
||||
return array_map( 'intval', $arr );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Load CSS and JS scripts only on the good pages.
|
||||
* @return void
|
||||
*/
|
||||
public function load_assets(): void {
|
||||
|
||||
global $post;
|
||||
if( !isset( $post->ID ) )
|
||||
return;
|
||||
|
||||
$simple_page_ids = $this->get_all_forms_page_ids( 'simple' );
|
||||
$complete_page_ids = $this->get_all_forms_page_ids( 'complete' );
|
||||
|
||||
if( in_array( $post->ID, $complete_page_ids ) ){ // Translations, Romhacks, Homebrew, Utilities, Documents, LUA Scripts, Tutorials
|
||||
|
||||
$this->children['script_hash_calc'] = new Script(
|
||||
Script_Type::JS,
|
||||
'hash-calculator',
|
||||
ROMHACKPLAZA_PLUGIN_URI . '/assets/js/submissions/hashes.js',
|
||||
[],
|
||||
'20251106',
|
||||
args: [ 'defer' => true, 'in_footer' => true ]
|
||||
)->enqueue();
|
||||
|
||||
$this->children['script_uploader'] = new Script(
|
||||
Script_Type::JS,
|
||||
'submissions-uploader',
|
||||
ROMHACKPLAZA_PLUGIN_URI . '/assets/js/submissions/uploader.js',
|
||||
[],
|
||||
'20251106',
|
||||
args: [ 'defer' => true, 'in_footer' => true ]
|
||||
)->enqueue()->add_localize(
|
||||
'_romhackplaza_script_uploader',
|
||||
[ 'submit_url' => admin_url( 'admin-ajax.php' ) ],
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
if( in_array( $post->ID, $simple_page_ids ) ){ // News
|
||||
|
||||
$this->children['script_simple_uploader'] = new Script(
|
||||
Script_Type::JS,
|
||||
'submissions-simple-uploader',
|
||||
ROMHACKPLAZA_PLUGIN_URI . '/assets/js/submissions/simple-uploader.js',
|
||||
[],
|
||||
'20251106',
|
||||
args: [ 'defer' => true, 'in_footer' => true ]
|
||||
)->enqueue()->add_localize(
|
||||
'_romhackplaza_script_uploader',
|
||||
[ 'submit_url' => admin_url( 'admin-ajax.php' ) ],
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
if( in_array( $post->ID, $simple_page_ids ) || in_array( $post->ID, $complete_page_ids ) ){
|
||||
|
||||
$this->children['script_css'] = new Script(
|
||||
Script_Type::CSS,
|
||||
'submissions-css',
|
||||
ROMHACKPLAZA_PLUGIN_URI . '/assets/css/submissions.css',
|
||||
[],
|
||||
'20251106',
|
||||
)->enqueue();
|
||||
|
||||
$this->children['script_select2_css'] = new Script(
|
||||
Script_Type::CSS,
|
||||
'select2',
|
||||
'https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css'
|
||||
)->enqueue();
|
||||
|
||||
$this->children['script_select2_js'] = new Script(
|
||||
Script_Type::JS,
|
||||
'select2',
|
||||
'https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js',
|
||||
[ 'jquery' ],
|
||||
'',
|
||||
args: [ 'defer' => true, 'in_footer' => true ]
|
||||
)->enqueue();
|
||||
|
||||
wp_enqueue_media(); // WP Media Library scripts.
|
||||
|
||||
// ACF / ACF Pro Scripts.
|
||||
if( function_exists( 'acf_form_head' ) )
|
||||
acf_form_head();
|
||||
if( function_exists( 'acf_enqueue_scripts' ) )
|
||||
acf_enqueue_scripts();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function test_terms_array( mixed $terms_array ){
|
||||
|
||||
if( $terms_array && !is_wp_error( $terms_array ) )
|
||||
return $terms_array;
|
||||
return [];
|
||||
}
|
||||
|
||||
protected function priority_language_names(){
|
||||
|
||||
return [ 'English', 'French', 'German', 'Spanish', 'Italian', 'Japanese' ];
|
||||
|
||||
}
|
||||
|
||||
protected function priority_language_terms_obj( array $terms_array ): array{
|
||||
|
||||
$priority = $this->priority_language_names();
|
||||
return array_filter( $terms_array, function( $term ) use ( $priority ){
|
||||
return in_array( $term->name, $priority );
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
protected function add_and_format_language( &$context )
|
||||
{
|
||||
$terms = \get_terms([
|
||||
'taxonomy' => 'language',
|
||||
'hide_empty' => false,
|
||||
]);
|
||||
|
||||
$priority_names = $this->priority_language_names();
|
||||
$priority_terms = $this->priority_language_terms_obj( $terms );
|
||||
$other_terms = array_udiff( $terms, $priority_terms, function( $a, $b ) {
|
||||
return strcmp( $a->term_id, $b->term_id );
|
||||
});
|
||||
|
||||
usort( $priority_terms, function( $a, $b ) use( $priority_names ){
|
||||
$pos_a = array_search( $a->name, $priority_names );
|
||||
$pos_b = array_search( $b->name, $priority_names );
|
||||
return $pos_a - $pos_b;
|
||||
});
|
||||
|
||||
$context['terms_language'] = array_merge( $priority_terms, $other_terms );
|
||||
|
||||
$context['value_terms_language'] = $context['submission_post_id'] != 0 ? wp_get_post_terms( $context['submission_post_id'], 'language', [ 'fields' => 'ids' ] ) |> $this->test_terms_array(...) : [];
|
||||
|
||||
return $context;
|
||||
}
|
||||
|
||||
protected function add_and_format_game( &$context ){
|
||||
|
||||
$game_term = $context['submission_post_id'] != 0 ? get_the_terms( $context['submission_post_id'], 'game' ) : 0;
|
||||
$context['value_game_id'] = $game_term != 0 && !is_wp_error( $game_term ) ? $game_term[0]->term_id : '';
|
||||
$context['value_game_name'] = $game_term != 0 && !is_wp_error( $game_term ) ? $game_term[0]->name : '';
|
||||
|
||||
return $context;
|
||||
|
||||
}
|
||||
|
||||
protected function add_and_format_platform( &$context ){
|
||||
|
||||
$context['terms_platform'] = \Timber\Timber::get_terms([
|
||||
'taxonomy' => 'platform',
|
||||
'hide_empty' => false,
|
||||
]);
|
||||
|
||||
$platform_term = $context['submission_post_id'] != 0 ? wp_get_post_terms( $context['submission_post_id'], 'platform', ['fields' => 'ids'] ) : 0;
|
||||
$context['value_platform_id'] = $platform_term != 0 && !empty( $platform_term ) ? $platform_term[0] : '';
|
||||
|
||||
return $context;
|
||||
}
|
||||
|
||||
protected function add_and_format_hashes( &$context )
|
||||
{
|
||||
$context['value_hashes'] = $context['submission_post_id'] != 0 ? esc_textarea( get_post_meta( $context['submission_post_id'], 'hashes', true ) ) : '';
|
||||
return $context;
|
||||
}
|
||||
|
||||
protected function add_and_format_genre( &$context ){
|
||||
|
||||
$context['terms_genre'] = \Timber\Timber::get_terms([
|
||||
'taxonomy' => 'genre',
|
||||
'hide_empty' => false,
|
||||
]);
|
||||
|
||||
$genre_term = $context['submission_post_id'] != 0 ? wp_get_post_terms( $context['submission_post_id'], 'genre', ['fields' => 'ids'] ) : 0;
|
||||
$context['value_genre_id'] = $genre_term != 0 && !empty( $genre_term ) ? $genre_term[0] : '';
|
||||
|
||||
return $context;
|
||||
}
|
||||
|
||||
protected function add_and_format_status( &$context ){
|
||||
|
||||
$context['list_status'] = \Timber\Timber::get_terms([
|
||||
'taxonomy' => 'hack-status',
|
||||
'hide_empty' => false,
|
||||
]);
|
||||
$context['value_terms_status'] = $context['submission_post_id'] != 0 ? wp_get_post_terms( $context['submission_post_id'], 'hack-status', [ 'fields' => 'ids' ] ) |> $this->test_terms_array(...) : [];
|
||||
|
||||
return $context;
|
||||
}
|
||||
|
||||
protected function add_and_format_main_image_gallery( &$context ){
|
||||
|
||||
if( !function_exists( 'acf_form' ) ){
|
||||
$context['can_acf'] = false;
|
||||
return $context;
|
||||
}
|
||||
|
||||
$context['can_acf'] = true;
|
||||
$context['attachments_settings'] = [
|
||||
'post_id' => $context['submission_post_id'] != 0 ? $context['submission_post_id'] : 'new-post',
|
||||
'fields_groups' => "REPLACED",
|
||||
'fields' => [ 'custom_featured_image', 'my_gallery' ],
|
||||
'submit_value' => __( 'Add Images', 'romhackplaza' ),
|
||||
'updated_message' => __( "Images added!", 'romhackplaza' ),
|
||||
'form' => false
|
||||
];
|
||||
|
||||
return $context;
|
||||
|
||||
}
|
||||
|
||||
protected function add_and_format_author( &$context ){
|
||||
|
||||
$context['value_authors'] = $context['submission_post_id'] != 0 ? get_the_terms( $context['submission_post_id'], 'author' ) |> $this->test_terms_array(...) : [];
|
||||
return $context;
|
||||
|
||||
}
|
||||
|
||||
protected function add_and_format_credits( &$context ){
|
||||
|
||||
$context['value_credits'] = $context['submission_post_id'] != 0 ? esc_textarea( get_post_meta( $context['submission_post_id'], 'staff', true ) ) : '';
|
||||
return $context;
|
||||
|
||||
}
|
||||
|
||||
public function fill_fields_for_timber( $context ){
|
||||
|
||||
global $post;
|
||||
if( !isset( $post->ID ) )
|
||||
return $context;
|
||||
|
||||
$simple_page_ids = $this->get_all_forms_page_ids( 'simple' );
|
||||
$complete_page_ids = $this->get_all_forms_page_ids( 'complete' );
|
||||
|
||||
if( !in_array( $post->ID, $simple_page_ids ) && !in_array( $post->ID, $complete_page_ids ) )
|
||||
return $context;
|
||||
|
||||
/*
|
||||
* The filter is removed to avoid duplications.
|
||||
*/
|
||||
global $_romhackplaza_theme, $_romhackplaza;
|
||||
remove_filter( 'timber/context', [ $_romhackplaza_theme->children['template_context'], 'timber_context_handler_by_page' ] );
|
||||
|
||||
// General ones.
|
||||
|
||||
// If we are on the result page and why.
|
||||
$context['submission_result'] = isset( $_GET['result'] ) ? sanitize_text_field( $_GET['result'] ) : '';
|
||||
|
||||
// If we edit an entry, the post ID.
|
||||
$context['submission_post_id'] = isset( $_GET['edit_entry'] ) ? intval( $_GET['edit_entry'] ) : 0;
|
||||
|
||||
// If we edit an entry on the result page. URL.
|
||||
$context['submission_edit_entry'] = isset( $_GET['edit_entry'] ) ? add_query_arg( [ 'edit_entry' => intval( $_GET['edit_entry'] ) ], get_permalink() ) : '';
|
||||
|
||||
// If the current user is verified or staff.
|
||||
$context['submission_author_is_verified'] = $_romhackplaza->user_roles->current_is( Roles::Verified ) || $_romhackplaza->user_roles->current_is_staff();
|
||||
|
||||
// If the current user can edit this entry, if it already exist.
|
||||
$context['submission_can_edit'] = !isset($context['submission_post_id']) || $_romhackplaza->user_roles->current_can_edit_entry($context['submission_post_id']);
|
||||
|
||||
// If the current user can bypass a locked entry. Only if it is a staff member.
|
||||
$context['submission_can_bypass_locked'] = $_romhackplaza->user_roles->current_is_staff();
|
||||
|
||||
// If the current user can bypass a trashed entry and a private entry. Only an administrator can.
|
||||
$context['submission_can_bypass_trashed_private'] = $_romhackplaza->user_roles->current_is(Roles::Administrator);
|
||||
|
||||
// If the public edit is disabled or not.
|
||||
$context['submission_public_edit_disabled'] = Properties::public_edit_disabled();
|
||||
|
||||
// Submission team message, like queue status. Private message. Locked reason, etc...
|
||||
$context['submission_queue_status'] = isset( $context['submission_post_id'] ) ? get_field( 'queue_status', $context['submission_post_id'] ) : "";
|
||||
if( $context['submission_queue_status'] === "not checked" ) // Default message.
|
||||
$context['submission_queue_status'] = "";
|
||||
|
||||
// Save Nonce
|
||||
$context['submission_save_nonce'] = wp_nonce_field( Format::format_nonce_name( 'submissions_save_entry' ), display: false );
|
||||
|
||||
// Entry title field default name.
|
||||
$context['entry_title_field_name'] = __( "Name:", "romhackplaza" );
|
||||
|
||||
// Entry title value.
|
||||
$context['value_entry_title'] = $context['submission_post_id'] != 0 ? esc_attr( get_post_meta( $context['submission_post_id'], 'entry_title', true ) ) : "";
|
||||
|
||||
// Patch version label.
|
||||
$context['version_number_field_name'] = __( "Version:", "romhackplaza" );
|
||||
|
||||
// Patch version value
|
||||
$context['value_version_number'] = $context['submission_post_id'] != 0 ? esc_attr( get_post_meta( $context['submission_post_id'], 'versionNumber', true ) ) : "";
|
||||
|
||||
// Release date value
|
||||
$context['value_release_date'] = "";
|
||||
$release_date = $context['submission_post_id'] != 0 ? get_post_meta( $context['submission_post_id'], 'release_date', true ) : false;
|
||||
if( $release_date ) {
|
||||
$date = \DateTime::createFromFormat( 'Ymd', $release_date );
|
||||
if( $date )
|
||||
$context['value_release_date'] = $date->format( 'Y-m-d' );
|
||||
}
|
||||
|
||||
// Editor settings and value
|
||||
$context['value_post_content'] = $context['submission_post_id'] != 0 ? get_post_field( 'post_content', $context['submission_post_id'], 'edit' ) : "";
|
||||
$context['post_content_settings'] = [
|
||||
'textarea_name' => 'postContent',
|
||||
'media_buttons' => false,
|
||||
'textarea_rows' => 7,
|
||||
'tinymce' => array(
|
||||
'theme_advanced_buttons1' => 'formatselect,|,bold,italic,underline,|,' .
|
||||
'bullist,numlist,|,link,unlink,|,undo,redo,|,' .
|
||||
'removeformat,|,charmap,|,outdent,indent,|,cut,copy,paste',
|
||||
'content_css' => get_stylesheet_directory_uri() . '/editor.css'
|
||||
),
|
||||
'quicktags' => array('buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close'),
|
||||
];
|
||||
|
||||
$post_type_rhpz_obj = null;
|
||||
|
||||
if( str_contains( $post->post_name, 'translation' ) ){
|
||||
|
||||
$post_type_rhpz_obj = &$_romhackplaza->cpt->select->translations;
|
||||
$context['entry_title_field_name'] = __( "Custom Name:", "romhackplaza" );
|
||||
$context['version_number_field_name'] = __( "Patch Version:", "romhackplaza" );
|
||||
|
||||
$context = $this->add_and_format_status( $context );
|
||||
$context = $this->add_and_format_language( $context );
|
||||
$context = $this->add_and_format_game( $context );
|
||||
$context = $this->add_and_format_platform( $context );
|
||||
$context = $this->add_and_format_genre( $context );
|
||||
$context = $this->add_and_format_hashes( $context );
|
||||
$context = $this->add_and_format_main_image_gallery( $context );
|
||||
$context = $this->add_and_format_author( $context );
|
||||
$context = $this->add_and_format_credits( $context );
|
||||
|
||||
}
|
||||
|
||||
else if( str_contains( $post->post_name, 'romhack' ) ){
|
||||
|
||||
$post_type_rhpz_obj = &$_romhackplaza->cpt->select->romhacks;
|
||||
$context['version_number_field_name'] = __( "Patch Version:", "romhackplaza" );
|
||||
|
||||
$context = $this->add_and_format_status( $context );
|
||||
$context = $this->add_and_format_language( $context );
|
||||
$context = $this->add_and_format_game( $context );
|
||||
$context = $this->add_and_format_platform( $context );
|
||||
$context = $this->add_and_format_genre( $context );
|
||||
$context = $this->add_and_format_hashes( $context );
|
||||
$context = $this->add_and_format_main_image_gallery( $context );
|
||||
$context = $this->add_and_format_author( $context );
|
||||
$context = $this->add_and_format_credits( $context );
|
||||
|
||||
}
|
||||
|
||||
else if( str_contains( $post->post_name, 'news' ) ){
|
||||
|
||||
$post_type_rhpz_obj = &$_romhackplaza->cpt->select->news;
|
||||
$context['entry_title_field_name'] = __( "Title:", "romhackplaza" );
|
||||
|
||||
}
|
||||
|
||||
// General ones sequel.
|
||||
if( $post_type_rhpz_obj ) {
|
||||
|
||||
// Post type name.
|
||||
$context['post_type'] = $post_type_rhpz_obj->name;
|
||||
|
||||
// Post type singular name.
|
||||
$context['post_type_singular'] = $post_type_rhpz_obj->singular_name;
|
||||
|
||||
// ACF Field group.
|
||||
$context['post_type_acf'] = $post_type_rhpz_obj->getAcfFieldGroupKey();
|
||||
|
||||
// Add for main image and gallery
|
||||
if( isset( $context['attachments_settings'] ) )
|
||||
$context['attachments_settings']['field_groups'] = [ $context['post_type_acf'] ];
|
||||
|
||||
}
|
||||
|
||||
return $context;
|
||||
}
|
||||
|
||||
public function get_file_server( int $post_id = 0 ){
|
||||
|
||||
global $post;
|
||||
if( !isset( $post->ID ) )
|
||||
return;
|
||||
|
||||
$complete_page_ids = $this->get_all_forms_page_ids( 'complete' );
|
||||
|
||||
if( in_array( $post->ID, $complete_page_ids ) ) { // Translations, Romhacks, Homebrew, Utilities, Documents, LUA Scripts, Tutorials
|
||||
new File_Server($post_id)->print_js();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
49
src/Extenders/Taxonomy.php
Normal file
49
src/Extenders/Taxonomy.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders;
|
||||
defined( '\ABSPATH' ) || exit;
|
||||
|
||||
class Taxonomy extends Abstract_Extender {
|
||||
|
||||
/**
|
||||
* Taxonomy name.
|
||||
* @var string
|
||||
*/
|
||||
final public string $name;
|
||||
|
||||
/**
|
||||
* Taxonomy args like register_taxonomy()
|
||||
* @var array
|
||||
*/
|
||||
final public array $args;
|
||||
|
||||
/**
|
||||
* Post types linked to this taxonomy
|
||||
* @var array
|
||||
*/
|
||||
final public array $post_types;
|
||||
|
||||
public function __construct(string $name, array $post_types = [], array $args = []){
|
||||
|
||||
$this->name = $name;
|
||||
$this->post_types = $post_types;
|
||||
$this->args = $args;
|
||||
|
||||
parent::__construct();
|
||||
|
||||
}
|
||||
|
||||
protected function can_extend(): bool
|
||||
{
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
protected function extend(): void {
|
||||
|
||||
$this->add_action('init', fn() => register_taxonomy($this->name, $this->post_types, $this->args) );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
100
src/Extenders/Timber.php
Normal file
100
src/Extenders/Timber.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders;
|
||||
|
||||
use RomhackPlaza\Extenders\Timber\SubmissionAccordionTokenParser;
|
||||
|
||||
defined( '\ABSPATH' ) || exit;
|
||||
|
||||
class Timber extends Abstract_Extender {
|
||||
|
||||
protected function can_extend(): bool {
|
||||
|
||||
global $_romhackplaza;
|
||||
return class_exists( 'Timber\Timber' ) || $_romhackplaza->main_theme_enabled;
|
||||
|
||||
}
|
||||
|
||||
protected function extend(): void{
|
||||
|
||||
$this->add_filter( 'timber/twig', [ $this, 'add_token_parser'] );
|
||||
$this->add_filter( 'timber/locations', [ $this, 'add_views_locations' ] );
|
||||
$this->add_filter( 'timber/twig/functions', [ $this, 'add_functions' ] );
|
||||
$this->add_filter( 'timber/context', [ $this, 'add_conditional_tags' ] );
|
||||
$this->add_filter( 'timber/user/class', [ $this, 'override_user_class' ], 10, 2 );
|
||||
|
||||
}
|
||||
|
||||
public function add_token_parser( $twig ) {
|
||||
|
||||
$twig->addTokenParser( new SubmissionAccordionTokenParser() );
|
||||
return $twig;
|
||||
|
||||
}
|
||||
|
||||
//<start_add_views>
|
||||
public function add_views_locations( $paths ) {
|
||||
|
||||
$paths['plugin'] = [
|
||||
ROMHACKPLAZA_PLUGIN_DIR . '/views'
|
||||
];
|
||||
|
||||
return $paths;
|
||||
|
||||
}
|
||||
//<end_add_views>
|
||||
|
||||
public function add_functions( $functions ){
|
||||
|
||||
if( class_exists( 'RomhackPlaza\Theme\Snippets' ) ) {
|
||||
// <start_svg_icon>
|
||||
$functions['svg_icon'] = [
|
||||
'callable' => [ \RomhackPlaza\Theme\Snippets::class, 'svg_icon' ]
|
||||
];
|
||||
// <end_svg_icon>
|
||||
} else {
|
||||
$functions['svg_icon'] = [
|
||||
'callable' => '__return_empty_string'
|
||||
];
|
||||
}
|
||||
|
||||
if( class_exists( 'RomhackPlaza\Theme\Settings' ) ) {
|
||||
|
||||
// <start_theme_setting>
|
||||
global $_romhackplaza_theme;
|
||||
$functions['theme_setting'] = [
|
||||
'callable' => [ $_romhackplaza_theme->settings, 'get' ]
|
||||
];
|
||||
// <end_theme_setting>
|
||||
|
||||
} else {
|
||||
|
||||
$functions['theme_setting'] = [
|
||||
'callable' => '__return_empty_string'
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
return $functions;
|
||||
|
||||
}
|
||||
|
||||
// <start_cond_tags>
|
||||
public function add_conditional_tags( $context ){
|
||||
|
||||
$context['conditional_tag']['is_home'] = is_home();
|
||||
$context['conditional_tag']['is_customize_preview'] = is_customize_preview();
|
||||
$context['conditional_tag']['is_admin'] = is_admin();
|
||||
|
||||
return $context;
|
||||
|
||||
}
|
||||
// <end_cond_tags>
|
||||
|
||||
public function override_user_class( $class, \WP_User $user ){
|
||||
|
||||
return \RomhackPlaza\Extenders\Timber\User::class;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
84
src/Extenders/Timber/SubmissionAccordionNode.php
Normal file
84
src/Extenders/Timber/SubmissionAccordionNode.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders\Timber;
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use Timber;
|
||||
use Twig\Compiler;
|
||||
use Twig\Token;
|
||||
use Twig\Node\Node;
|
||||
|
||||
class SubmissionAccordionNode extends Node {
|
||||
|
||||
public static function get_sapretty_title( string $type_name ){
|
||||
|
||||
switch( $type_name ){
|
||||
case 'download-files':
|
||||
return __('Download Files', 'romhackplaza');
|
||||
break;
|
||||
case 'about-translation':
|
||||
return __('About the Patch', 'romhackplaza');
|
||||
break;
|
||||
case 'game-information':
|
||||
return __('Game Information', 'romhackplaza');
|
||||
break;
|
||||
case 'attachments':
|
||||
return __('Attachments', 'romhackplaza');
|
||||
break;
|
||||
case 'team-information':
|
||||
return __('Team Information', 'romhackplaza');
|
||||
break;
|
||||
}
|
||||
|
||||
return __( "Unknown", 'romhackplaza' );
|
||||
}
|
||||
|
||||
public static function get_safa_icon( mixed $type_name){
|
||||
|
||||
switch( $type_name ){
|
||||
case 'download-files':
|
||||
return 'fas fa-download';
|
||||
break;
|
||||
case 'about-translation':
|
||||
return 'fas fa-language';
|
||||
break;
|
||||
case 'game-information':
|
||||
return 'fas fa-gamepad';
|
||||
break;
|
||||
case 'attachments':
|
||||
return 'fas fa-paperclip';
|
||||
break;
|
||||
case 'team-information':
|
||||
return 'fas fa-users';
|
||||
break;
|
||||
}
|
||||
|
||||
return 'fas fa-question-circle';
|
||||
|
||||
}
|
||||
|
||||
public function compile( Compiler $compiler ) {
|
||||
|
||||
$compiler->addDebugInfo($this)
|
||||
->write( "ob_start();\n" )
|
||||
->subcompile( $this->getNode('body') )
|
||||
->write("\$content = ob_get_clean();\n")
|
||||
->write("\$type = ")
|
||||
->subcompile( $this->getNode('type') )
|
||||
->raw(";\n")
|
||||
->write("\$icon = \RomhackPlaza\Extenders\Timber\SubmissionAccordionNode::get_safa_icon( \$type );\n")
|
||||
->write("\$pretty_title = \RomhackPlaza\Extenders\Timber\SubmissionAccordionNode::get_sapretty_title( \$type );\n")
|
||||
->write("\$opened = \$context['accordion_opened'] ?? false;\n")
|
||||
->write("echo Timber::compile('@plugin/node/submission-accordion.twig', [\n")
|
||||
->indent()
|
||||
->write("'type' => \$type,\n")
|
||||
->write("'content' => \$content,\n")
|
||||
->write("'pretty_title' => \$pretty_title,\n")
|
||||
->write("'icon' => \$icon,\n")
|
||||
->write("'accordion_opened' => \$opened,\n")
|
||||
->outdent()
|
||||
->write("]);\n");
|
||||
;
|
||||
}
|
||||
|
||||
}
|
||||
42
src/Extenders/Timber/SubmissionAccordionTokenParser.php
Normal file
42
src/Extenders/Timber/SubmissionAccordionTokenParser.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders\Timber;
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use Timber;
|
||||
use Twig\Token;
|
||||
use Twig\TokenParser\AbstractTokenParser;
|
||||
|
||||
class SubmissionAccordionTokenParser extends AbstractTokenParser {
|
||||
|
||||
public function parse(Token $token) {
|
||||
|
||||
$line_no = $token->getLine();
|
||||
$type = $this->parser->getExpressionParser()->parseExpression();
|
||||
|
||||
$this->parser->getStream()->expect( Token::BLOCK_END_TYPE );
|
||||
$body = $this->parser->subparse( [$this, 'decide_submission_end'], true );
|
||||
$this->parser->getStream()->expect( Token::BLOCK_END_TYPE );
|
||||
|
||||
return new SubmissionAccordionNode(
|
||||
[
|
||||
'body' => $body,
|
||||
'type' => $type,
|
||||
],
|
||||
[],
|
||||
$line_no,
|
||||
$this->getTag()
|
||||
);
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'submission_accordion';
|
||||
}
|
||||
|
||||
public function decide_submission_end(Token $token) {
|
||||
|
||||
return $token->test( 'end_submission_accordion' );
|
||||
}
|
||||
|
||||
}
|
||||
16
src/Extenders/Timber/User.php
Normal file
16
src/Extenders/Timber/User.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders\Timber;
|
||||
defined( '\ABSPATH' ) || exit;
|
||||
|
||||
use Timber;
|
||||
|
||||
class User extends Timber\User {
|
||||
|
||||
public function profile_url(){
|
||||
|
||||
return \get_author_posts_url( $this->id );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
210
src/Extenders/User_Notifications.php
Normal file
210
src/Extenders/User_Notifications.php
Normal file
@@ -0,0 +1,210 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Extenders;
|
||||
use RomhackPlaza\API\Website_Scripts_Constraints;
|
||||
use RomhackPlaza\Database\Database_Table;
|
||||
use RomhackPlaza\Database\Database_Tools;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class User_Notifications extends Abstract_Extender implements Database_Table, Website_Scripts_Constraints {
|
||||
|
||||
const string TABLE_NAME = "notifications";
|
||||
const array NOTIFICATIONS_TYPES = [
|
||||
"extra" => "Extra",
|
||||
"announce" => "Important announce",
|
||||
"perm_change" => "Role changed",
|
||||
"new_review" => "New review",
|
||||
"entry_status" => "Entry status edited",
|
||||
"entry_author" => "Entry author changed",
|
||||
"locked_entry" => "Locked entry",
|
||||
"message" => "Message",
|
||||
"reply_message" => "Reply to a message",
|
||||
"copy_message" => "Copy from a reply",
|
||||
"report_response" => "Response from a report"
|
||||
];
|
||||
|
||||
use Database_Tools;
|
||||
|
||||
public static function create_table()
|
||||
{
|
||||
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
|
||||
global $wpdb;
|
||||
|
||||
$table_name = $wpdb->prefix . self::TABLE_NAME;
|
||||
$charset_collate = $wpdb->get_charset_collate();
|
||||
|
||||
$sql = "
|
||||
CREATE TABLE {$table_name} (
|
||||
id INT(11) NOT NULL AUTO_INCREMENT,
|
||||
sender INT(11) NOT NULL,
|
||||
recipient INT(11) NOT NULL,
|
||||
type VARCHAR(50) NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
auto INT(1) NOT NULL DEFAULT '0',
|
||||
readed INT(1) NOT NULL DEFAULT '0',
|
||||
date INT(11) NOT NULL,
|
||||
PRIMARY KEY (id)
|
||||
) {$charset_collate};
|
||||
)
|
||||
";
|
||||
|
||||
dbDelta( $sql );
|
||||
}
|
||||
|
||||
public static function verify_table()
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
if( !self::table_exists( $wpdb->prefix . self::TABLE_NAME ) ){
|
||||
self::create_table();
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Columns verif.
|
||||
|
||||
}
|
||||
|
||||
public static function website_scripts_list()
|
||||
{
|
||||
return ['delete' => 'delete-notification.php'];
|
||||
}
|
||||
|
||||
public static function type_name( string $type ){
|
||||
|
||||
return self::NOTIFICATIONS_TYPES[$type] ?? $type;
|
||||
|
||||
}
|
||||
|
||||
public static function get_by_id( int $id ){
|
||||
|
||||
global $wpdb;
|
||||
$table_name = $wpdb->prefix . self::TABLE_NAME;
|
||||
|
||||
$query = "SELECT * FROM {$table_name} WHERE id = {$id} LIMIT 1";
|
||||
$results = $wpdb->get_results( $query, ARRAY_A );
|
||||
|
||||
return $results[0] ?? $results ?? null;
|
||||
|
||||
}
|
||||
|
||||
public static function get( array $args = [] ){
|
||||
|
||||
global $wpdb;
|
||||
$table_name = $wpdb->prefix . self::TABLE_NAME;
|
||||
|
||||
$defaults = [
|
||||
'sender' => 0,
|
||||
'recipient' => 0,
|
||||
'type' => 'none',
|
||||
'auto' => -1,
|
||||
'readed' => -1,
|
||||
'orderby' => 'id',
|
||||
'order' => 'ASC',
|
||||
'number' => 5
|
||||
];
|
||||
|
||||
$args = wp_parse_args( $args, $defaults );
|
||||
|
||||
$conditions = [];
|
||||
|
||||
if( !empty( $args['sender'] ) && $args['sender'] != 0 )
|
||||
$conditions[] = "sender = {$args['sender']}";
|
||||
|
||||
if( !empty( $args['recipient'] ) && $args['recipient'] != 0 )
|
||||
$conditions[] = "recipient = {$args['recipient']}";
|
||||
|
||||
if( !empty( $args['type'] ) && $args['type'] !== 'none' )
|
||||
$conditions[] = "type = {$args['type']}";
|
||||
|
||||
if( !empty( $args['auto'] ) && ( $args['auto'] == 0 || $args['auto'] == 1 ) )
|
||||
$conditions[] = "auto = {$args['auto']}";
|
||||
|
||||
if( !empty( $args['readed'] ) && ( $args['readed'] == 0 || $args['readed'] == 1 ) )
|
||||
$conditions[] = "readed = {$args['readed']}";
|
||||
|
||||
$where = '';
|
||||
if( !empty( $conditions ) )
|
||||
$where = " WHERE " . implode( ' AND ', $conditions );
|
||||
|
||||
$orderby = '';
|
||||
if( !empty( $args['orderby'] ) ){
|
||||
|
||||
$order = $args['order'] === 'DESC' || $args['order'] === 'ASC' ? $args['order'] : 'ASC';
|
||||
$orderby = " ORDER BY {$args['orderby']} {$order}";
|
||||
|
||||
}
|
||||
|
||||
$limit = '';
|
||||
if( !empty( $args['number'] ) && is_int( $args['number'] ) )
|
||||
$limit = "LIMIT {$args['number']}";
|
||||
|
||||
$query = "SELECT * FROM {$table_name} {$where} {$orderby} {$limit}";
|
||||
return $wpdb->get_results( $query, ARRAY_A );
|
||||
|
||||
}
|
||||
|
||||
public static function get_unread( int $user_id = 0 ){
|
||||
|
||||
if( $user_id === 0 )
|
||||
$user_id = get_current_user_id();
|
||||
|
||||
return self::get( [
|
||||
'recipient' => $user_id,
|
||||
'readed' => 0,
|
||||
'number' => 'infinite'
|
||||
] );
|
||||
}
|
||||
|
||||
public static function add( array $args )
|
||||
{
|
||||
|
||||
global $wpdb;
|
||||
$table_name = $wpdb->prefix . self::TABLE_NAME;
|
||||
|
||||
$defaults = [
|
||||
'sender' => $_ENV['ROMHACKPLAZA_DEFAULT_ACCOUNT'],
|
||||
'recipient' => 0,
|
||||
'type' => 'none',
|
||||
'content' => 'None',
|
||||
'auto' => 1,
|
||||
'readed' => 0,
|
||||
'date' => time(),
|
||||
];
|
||||
|
||||
$args = wp_parse_args($args, $defaults);
|
||||
$args['content'] = stripslashes($args['content']);
|
||||
|
||||
$wpdb->insert($table_name, $args, ['%d', '%d', '%s', '%s', '%d', '%d', '%d']);
|
||||
|
||||
}
|
||||
|
||||
public static function delete( int $id ){
|
||||
|
||||
global $wpdb;
|
||||
$table_name = $wpdb->prefix . self::TABLE_NAME;
|
||||
|
||||
$wpdb->delete( $table_name, ['id' => $id] );
|
||||
|
||||
}
|
||||
|
||||
public static function unread_to_read( int $id ){
|
||||
|
||||
global $wpdb;
|
||||
$table_name = $wpdb->prefix . self::TABLE_NAME;
|
||||
|
||||
$wpdb->update( $table_name, ['readed' => 1], ['id' => $id] );
|
||||
|
||||
}
|
||||
|
||||
protected function can_extend(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function extend(): void
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
64
src/Fetch.php
Normal file
64
src/Fetch.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza;
|
||||
|
||||
class Fetch {
|
||||
|
||||
private function __construct(){}
|
||||
|
||||
public static function get_terms_by_request(
|
||||
string $tax_name,
|
||||
string $request_key = "q",
|
||||
int $number = 10
|
||||
){
|
||||
|
||||
$search = $_REQUEST[$request_key];
|
||||
|
||||
$terms = get_terms([
|
||||
'taxonomy' => $tax_name,
|
||||
'hide_empty' => false,
|
||||
'name__like' => $search,
|
||||
'number' => $number,
|
||||
] );
|
||||
|
||||
return $terms;
|
||||
|
||||
}
|
||||
|
||||
public static function get_users_by_request(
|
||||
string $request_key = "q",
|
||||
int $number = 10
|
||||
){
|
||||
$search = $_REQUEST[$request_key];
|
||||
|
||||
$users = get_users([
|
||||
'orderby' => 'display_name',
|
||||
'search' => $search,
|
||||
'search_columns' => [ 'ID', 'user_nicename', "display_name" ],
|
||||
'number' => $number,
|
||||
] );
|
||||
|
||||
return $users;
|
||||
|
||||
}
|
||||
|
||||
public static function crc32_in_string( string $s ): mixed {
|
||||
|
||||
$pattern = '/\b[a-fA-F0-9]{8}\b/';
|
||||
preg_match_all($pattern, $s, $matches);
|
||||
|
||||
return $matches[0] ?? false;
|
||||
|
||||
}
|
||||
|
||||
public static function sha1_in_string( string $s ): mixed {
|
||||
|
||||
$pattern = '/\b[a-fA-F0-9]{40}\b/';
|
||||
preg_match_all($pattern, $s, $matches);
|
||||
|
||||
return $matches[0] ?? false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
29
src/Format.php
Normal file
29
src/Format.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza;
|
||||
|
||||
class Format {
|
||||
|
||||
private function __construct(){}
|
||||
|
||||
public static function format_for_select2( array $elem_array, string $id_name, string $text_name ) : array {
|
||||
|
||||
$formatted_array = [];
|
||||
|
||||
foreach ($elem_array as $elem) {
|
||||
if( property_exists( $elem, $id_name ) ) {
|
||||
$formatted_array[] = ['id' => $elem->{$id_name}, 'text' => $elem->{$text_name} ?? "None" ];
|
||||
}
|
||||
}
|
||||
|
||||
return $formatted_array;
|
||||
|
||||
}
|
||||
|
||||
public static function format_nonce_name( string $action ){
|
||||
|
||||
return 'romhackplaza_' . $_ENV['ROMHACKPLAZA_NONCE_KEY'] . '_' . $action;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
230
src/Modal.php
Normal file
230
src/Modal.php
Normal file
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza;
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Modal {
|
||||
|
||||
public static bool $css_loaded = false;
|
||||
public static bool $modal_manage_loaded = false;
|
||||
|
||||
public final string $modal_id;
|
||||
public string $modal_title;
|
||||
public string $modal_content;
|
||||
|
||||
public function __construct(
|
||||
string $modal_id,
|
||||
string $modal_title = "",
|
||||
string $modal_html_content = "",
|
||||
) {
|
||||
$this->modal_id = $modal_id;
|
||||
$this->modal_title = $modal_title;
|
||||
$this->modal_content = $modal_html_content;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function the_modal_css(){
|
||||
|
||||
if( static::$css_loaded === false ){
|
||||
|
||||
?>
|
||||
<style>
|
||||
|
||||
#wpbody {
|
||||
|
||||
--text-color: #454545;
|
||||
--page-background-color: #fff;
|
||||
--link-color: #db7f00;
|
||||
--link-hover-color: #454545;
|
||||
--widget-title-color: #454545;
|
||||
--content-border-color: #454545;
|
||||
--light-border-color: rgba( 0, 0, 0, 15 );
|
||||
--widget-title-font: 'Magra'
|
||||
|
||||
}
|
||||
.rhpz-modal {
|
||||
display: none;
|
||||
position: fixed;
|
||||
z-index: 1;
|
||||
padding-top: 100px;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: auto;
|
||||
background-color: rgb(0,0,0);
|
||||
background-color: rgba(0,0,0,0.4);
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.rhpz-modal-content {
|
||||
position: relative;
|
||||
background-color: var(--page-background-color);
|
||||
margin: auto;
|
||||
padding: 0;
|
||||
border: 1px solid #888;
|
||||
border-radius: 0 0 10px 10px;
|
||||
width: 50%;
|
||||
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
|
||||
-webkit-animation-name: animatetop;
|
||||
-webkit-animation-duration: 0.4s;
|
||||
animation-name: animatetop;
|
||||
animation-duration: 0.4s
|
||||
}
|
||||
|
||||
@media (max-width: 850px) {
|
||||
.rhpz-modal-content {
|
||||
width: 90%;
|
||||
}
|
||||
}
|
||||
|
||||
.close {
|
||||
color: var(--link-color);
|
||||
float: right;
|
||||
font-size: 28px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.close:hover,
|
||||
.close:focus {
|
||||
color: var(--link-hover-color);
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.rhpz-modal-header {
|
||||
padding: 2px 16px;
|
||||
color: var(--widget-title-color);
|
||||
box-shadow: inset 0 2px var(--content-border-color);
|
||||
border-bottom: 1px solid;
|
||||
border-color: var(--light-border-color);
|
||||
font-family: var(--widget-title-font);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.rhpz-modal-body {
|
||||
padding: 10px 16px;
|
||||
}
|
||||
|
||||
@-webkit-keyframes animatetop {
|
||||
from {top:-300px; opacity:0}
|
||||
to {top:0; opacity:1}
|
||||
}
|
||||
|
||||
@keyframes animatetop {
|
||||
from {top:-300px; opacity:0}
|
||||
to {top:0; opacity:1}
|
||||
}
|
||||
|
||||
.rhpz-modal-iframe {
|
||||
|
||||
height: 450px !important;
|
||||
/* overflow: hidden; */
|
||||
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<?php
|
||||
|
||||
static::$css_loaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected function the_modal_js(){
|
||||
|
||||
if( static::$modal_manage_loaded === false ){
|
||||
|
||||
?>
|
||||
|
||||
<script>
|
||||
|
||||
function romhackplaza_manage_modal(
|
||||
modal_obj,
|
||||
new_css_display = "block",
|
||||
new_title = "",
|
||||
new_content = "",
|
||||
new_html_content = "",
|
||||
){
|
||||
modal_obj.modal.style.display = new_css_display;
|
||||
|
||||
if( new_title !== "" )
|
||||
modal_obj.title.textContent = new_title;
|
||||
|
||||
if( new_content !== "" && new_html_content === "" ){
|
||||
|
||||
modal_obj.html.innerHTML = "";
|
||||
modal_obj.content = document.createElement("p");
|
||||
modal_obj.content.id = modal_obj.id + "-content";
|
||||
modal_obj.html.appendChild( modal_obj.content );
|
||||
modal_obj.content.innerHTML = new_content;
|
||||
|
||||
}
|
||||
else if( new_html_content !== "" )
|
||||
modal_obj.html.innerHTML = new_html_content;
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<?php
|
||||
|
||||
static::$modal_manage_loaded = true;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<script defer>
|
||||
|
||||
const romhackplaza_modal_<?php echo $this->modal_id; ?> = (function(){
|
||||
|
||||
const MODAL_ID = "<?php echo $this->modal_id; ?>";
|
||||
let modal = document.getElementById( MODAL_ID );
|
||||
let close_button = document.getElementById( MODAL_ID + "-close" );
|
||||
let title = document.getElementById( MODAL_ID + "-title" );
|
||||
let html_iframe = document.getElementById( MODAL_ID + "-html-content" );
|
||||
let content = document.getElementById( MODAL_ID + "-content" );
|
||||
|
||||
let obj = {
|
||||
"id": MODAL_ID,
|
||||
"modal": modal,
|
||||
"title": title,
|
||||
"html": html_iframe,
|
||||
"content": content,
|
||||
"close_button": close_button,
|
||||
}
|
||||
|
||||
close_button.onclick = () => romhackplaza_manage_modal( obj, 'none' );
|
||||
window.addEventListener( 'click', (e) => { if( e.target === modal ) romhackplaza_manage_modal( obj, 'none' ) } );
|
||||
|
||||
return obj;
|
||||
|
||||
})();
|
||||
|
||||
</script>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$this->the_modal_css();
|
||||
?>
|
||||
<div id="<?php echo $this->modal_id; ?>" class="rhpz-modal">
|
||||
<div class="rhpz-modal-content">
|
||||
<div class="rhpz-modal-header">
|
||||
<span id="<?php echo $this->modal_id . '-close'; ?>" class="close">×</span>
|
||||
<h2 id="<?php echo $this->modal_id . '-title'; ?>"><?php echo $this->modal_title; ?></h2>
|
||||
</div>
|
||||
<div id="<?php echo $this->modal_id . '-html-content'; ?>" class="rhpz-modal-body">
|
||||
<?php echo $this->modal_content; ?>
|
||||
<p id="<?php echo $this->modal_id . '-content'; ?>"></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
$this->the_modal_js();
|
||||
}
|
||||
|
||||
}
|
||||
40
src/Overrides/Abstract_Overrider.php
Normal file
40
src/Overrides/Abstract_Overrider.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Overrides;
|
||||
use RomhackPlaza\Extenders\Abstract_Extender;
|
||||
|
||||
defined( '\ABSPATH' ) || exit;
|
||||
|
||||
abstract class Abstract_Overrider extends Abstract_Extender {
|
||||
|
||||
/**
|
||||
* Redirect to override functions.
|
||||
* @see Abstract_Overrider::can_override()
|
||||
* @return bool
|
||||
*/
|
||||
protected function can_extend(): bool {
|
||||
return $this->can_override();
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to override functions.
|
||||
* @see Abstract_Overrider::override()
|
||||
* @return bool
|
||||
*/
|
||||
protected function extend(): void {
|
||||
$this->override();
|
||||
}
|
||||
|
||||
/**
|
||||
* If the override can be executed or not.
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function can_override(): bool;
|
||||
|
||||
/**
|
||||
* Override content.
|
||||
* @return void
|
||||
*/
|
||||
abstract protected function override(): void;
|
||||
|
||||
}
|
||||
122
src/Overrides/Capabilities.php
Normal file
122
src/Overrides/Capabilities.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Overrides;
|
||||
defined( '\ABSPATH' ) || exit;
|
||||
|
||||
class Capabilities extends Abstract_Overrider {
|
||||
|
||||
/**
|
||||
* Current user roles
|
||||
* @var array ( [Roles] => [int/bool] )
|
||||
*/
|
||||
final public array $current;
|
||||
|
||||
protected function can_override(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function override(): void
|
||||
{
|
||||
$this->add_action( 'init', [ $this, 'bind_current_user_roles' ], 7 );
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind current user roles.
|
||||
* It's the most used...
|
||||
* @return void
|
||||
*/
|
||||
public function bind_current_user_roles(): void {
|
||||
|
||||
$current_user = wp_get_current_user();
|
||||
$roles = [];
|
||||
|
||||
foreach( Roles::cases() as $role ) {
|
||||
$roles[$role->value] = in_array($role->value, $current_user->roles);
|
||||
}
|
||||
|
||||
$this->current = $roles;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current user high level role.
|
||||
* @return Roles|string|null
|
||||
*/
|
||||
public function current_upper(): Roles|string|null {
|
||||
|
||||
return $this->current |> array_key_first(...)
|
||||
|> Roles::tryFrom(...);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if current user have specific role.
|
||||
* @param Roles $role
|
||||
* @return bool
|
||||
*/
|
||||
public function current_is( Roles $role ): bool {
|
||||
|
||||
if( !isset( $this->current[ $role->value ] ) )
|
||||
return false;
|
||||
|
||||
return $this->current[ $role->value ] == true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if current user is a staff member or not.
|
||||
* @return bool
|
||||
*/
|
||||
public function current_is_staff(): bool {
|
||||
|
||||
return current_user_can( 'edit_others_posts' );
|
||||
|
||||
}
|
||||
|
||||
public function current_can_edit_entry( int $post_id ): bool {
|
||||
|
||||
return $this->current_is_staff() || get_current_user_id() === intval( get_post_field( 'post_author', $post_id ) );
|
||||
|
||||
}
|
||||
|
||||
public function user_upper( int $user_id ): Roles|string|null {
|
||||
|
||||
$user = get_user( $user_id );
|
||||
if( !$user )
|
||||
return false;
|
||||
|
||||
$user_roles = $user->roles;
|
||||
if( empty( $user_roles ) )
|
||||
return null;
|
||||
|
||||
return $user_roles |> array_key_first(...)
|
||||
|> Roles::tryFrom(...);
|
||||
|
||||
}
|
||||
|
||||
public function user_is( int $user_id, Roles $role ): bool {
|
||||
|
||||
$user = get_user( $user_id );
|
||||
if( !$user )
|
||||
return false;
|
||||
|
||||
$user_roles = $user->roles;
|
||||
return in_array( $role->value, $user_roles );
|
||||
|
||||
}
|
||||
|
||||
public function user_is_staff( int $user_id ): bool {
|
||||
|
||||
return user_can( $user_id, 'edit_others_posts' );
|
||||
|
||||
}
|
||||
|
||||
public function user_can_edit_entry( int $user_id, int $post_id ): bool {
|
||||
|
||||
return $this->current_is_staff() || get_current_user_id() === $user_id;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
78
src/Overrides/Post_Announcements.php
Normal file
78
src/Overrides/Post_Announcements.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Overrides;
|
||||
defined( '\ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Replace 'post' default post type to announcements.
|
||||
*/
|
||||
class Post_Announcements extends Abstract_Overrider {
|
||||
|
||||
protected function can_override(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function override(): void {
|
||||
|
||||
$this->add_action( 'init', [ $this, 'rename_post_to_announcements' ], 20 );
|
||||
$this->add_action( 'admin_menu', [ $this, 'rename_post_to_announcements_menu' ], 20 );
|
||||
$this->add_action( 'save_post', [ $this, 'can_save_announcement' ], 5, 3 );
|
||||
|
||||
}
|
||||
|
||||
public function rename_post_to_announcements() {
|
||||
|
||||
global $_romhackplaza;
|
||||
if( !$_romhackplaza->user_roles->current_is( Roles::Administrator ) )
|
||||
return; // Don't change if the user is not an admin.
|
||||
|
||||
global $wp_post_types;
|
||||
$labels = &$wp_post_types['post']->labels;
|
||||
$labels->name = __( 'Announcements', 'romhackplaza' );
|
||||
$labels->singular_name = __( 'Announcement', 'romhackplaza' );
|
||||
$labels->add_new = __( 'Add Announce', 'romhackplaza' );
|
||||
$labels->add_new_item = __( 'Add Announce', 'romhackplaza' );
|
||||
$labels->edit_item = __( 'Edit Annonce', 'romhackplaza' );
|
||||
$labels->new_item = __( 'Announce', 'romhackplaza' );
|
||||
$labels->view_item = __( 'View Announce', 'romhackplaza' );
|
||||
$labels->search_items = __( 'Search Announcements', 'romhackplaza' );
|
||||
$labels->not_found = __( 'No Announce found', 'romhackplaza' );
|
||||
$labels->not_found_in_trash = __( 'No Announce found in Trash', 'romhackplaza' );
|
||||
|
||||
}
|
||||
|
||||
public function rename_post_to_announcements_menu() {
|
||||
|
||||
global $_romhackplaza;
|
||||
if( !$_romhackplaza->user_roles->current_is( Roles::Administrator ) )
|
||||
return; // Don't change if the user is not an admin.
|
||||
|
||||
global $menu;
|
||||
global $submenu;
|
||||
|
||||
$menu[5][0] = __( 'Announcements', 'romhackplaza' );
|
||||
$menu[5][6] = 'dashicons-megaphone';
|
||||
$submenu['edit.php'][5][0] = __( 'Announcements', 'romhackplaza' );
|
||||
$submenu['edit.php'][10][0] = __( 'Add Announce', 'romhackplaza' );
|
||||
echo '';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be moved in SavePost Extender ???
|
||||
* Only admin can send announcement.
|
||||
* @return void
|
||||
*/
|
||||
public function can_save_announcement( $post_id, $post, $update ) {
|
||||
|
||||
global $_romhackplaza;
|
||||
|
||||
// Get post type after to avoid conflict or pre-save.
|
||||
if( get_post_type( $post_id ) === 'post' && !$_romhackplaza->user_roles->current_is( Roles::Administrator ) ){
|
||||
wp_die( __( "You don't have the permission to post announcements.", 'romhackplaza' ), __( 'Permission error', 'romhackplaza'), [ 'response' => 403 ] );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
17
src/Overrides/Roles.php
Normal file
17
src/Overrides/Roles.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Overrides;
|
||||
defined( '\ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* /!\ High level role are the upper in the enum list.
|
||||
*/
|
||||
enum Roles: string {
|
||||
case Administrator = 'administrator';
|
||||
case Moderator = 'editor';
|
||||
case Bot = 'bot';
|
||||
case Verified = 'author';
|
||||
case Member = 'contributor';
|
||||
case Read_Only = 'subscriber';
|
||||
|
||||
}
|
||||
144
src/Plugin.php
Executable file
144
src/Plugin.php
Executable file
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
namespace RomhackPlaza;
|
||||
|
||||
defined( '\ABSPATH' ) || exit;
|
||||
|
||||
class Plugin {
|
||||
|
||||
/**
|
||||
* If the RomhackPlaza theme is enabled or not.
|
||||
* @var bool
|
||||
*/
|
||||
public bool $main_theme_enabled = false;
|
||||
|
||||
/**
|
||||
* Children created class.
|
||||
* ADD PREFIX FOR EACH STIUATION (Except if it's a direct child and unique, like Customizer)
|
||||
*
|
||||
* Extenders : extend_
|
||||
* Overriders : override_
|
||||
* Ajax elements : ajax_
|
||||
* ...
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public array $children = [];
|
||||
|
||||
/* ---
|
||||
* [INFO] Some children have their own separated attribute if there are frequently used.
|
||||
--- */
|
||||
|
||||
/**
|
||||
* Setting object.
|
||||
* @var Settings
|
||||
*/
|
||||
final public Settings $settings;
|
||||
|
||||
/**
|
||||
* Custom post types elements.
|
||||
* @var Registrars\Custom_Post_Types
|
||||
*/
|
||||
final public Registrars\Custom_Post_Types $cpt;
|
||||
|
||||
/**
|
||||
* Taxonomies elements.
|
||||
* @var Registrars\Taxonomies
|
||||
*/
|
||||
final public Registrars\Taxonomies $tax;
|
||||
|
||||
/**
|
||||
* Post status elements.
|
||||
* @var Registrars\Custom_Post_Status
|
||||
*/
|
||||
final public Registrars\Custom_Post_Status $post_status;
|
||||
|
||||
/**
|
||||
* User roles functions.
|
||||
* @var Overrides\Capabilities
|
||||
*/
|
||||
final public Overrides\Capabilities $user_roles;
|
||||
|
||||
/**
|
||||
* New plugin element, setup it.
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
add_action( 'after_setup_theme', [ $this, 'setup_after_theme' ] );
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Extenders setup directly after construct.
|
||||
* @return Plugin
|
||||
*/
|
||||
public function setup_extenders_direct(): Plugin {
|
||||
|
||||
$this->settings = new Settings();
|
||||
$this->cpt = new Registrars\Custom_Post_Types();
|
||||
$this->tax = new Registrars\Taxonomies();
|
||||
$this->post_status = new Registrars\Custom_Post_Status();
|
||||
$this->user_roles = new Overrides\Capabilities();
|
||||
|
||||
$this->children['extend_save_post'] = new Extenders\Post\Save_Post();
|
||||
$this->children['extend_post_properties'] = new Extenders\Post\Properties();
|
||||
|
||||
$this->children['extend_acf_pro'] = new Extenders\Advanced_Custom_Fields_Pro();
|
||||
|
||||
$this->children['override_post_announcements'] = new Overrides\Post_Announcements();
|
||||
|
||||
$this->children['extend_admin_pages'] = new Extenders\Admin\Pages();
|
||||
$this->children['extend_submissions'] = new Extenders\Submissions();
|
||||
$this->children['extend_discord'] = new Extenders\Discord_Notification();
|
||||
$this->children['extend_notifications'] = new Extenders\User_Notifications();
|
||||
$this->children['extend_admin_scripts'] = new Extenders\Admin_Scripts();
|
||||
|
||||
// Ajax requests
|
||||
$this->children['ajax_submissions_save_entry'] = new Extenders\Ajax\Submissions_Save_Entry();
|
||||
$this->children['ajax_reserve_post_id'] = new Extenders\Ajax\Reserve_Post_ID();
|
||||
$this->children['ajax_set_favorite_server'] = new Extenders\Ajax\Set_Favorite_Server();
|
||||
$this->children['ajax_search_game_term'] = new Extenders\Ajax\Search_Game_Term();
|
||||
$this->children['ajax_search_author_term'] = new Extenders\Ajax\Search_Author_Term();
|
||||
$this->children['ajax_search_user'] = new Extenders\Ajax\Search_User();
|
||||
$this->children['ajax_notifications_unread'] = new Extenders\Ajax\Notifications_Unread_To_Read();
|
||||
$this->children['ajax_notifications_reply'] = new Extenders\Ajax\Notifications_Reply();
|
||||
$this->children['ajax_notifications_contact'] = new Extenders\Ajax\Notifications_Contact();
|
||||
$this->children['ajax_submit_notification'] = new Extenders\Ajax\Submit_Notification();
|
||||
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Just after theme loaded.
|
||||
* @return void
|
||||
*/
|
||||
public function setup_after_theme() {
|
||||
$this->main_theme_enabled = $this->_is_theme_enabled();
|
||||
$this->setup_extenders_after_theme();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup hooks that need to be loaded after the theme is loaded and ensure it's the good one.
|
||||
* @return $this
|
||||
*/
|
||||
public function setup_extenders_after_theme(): Plugin {
|
||||
|
||||
$this->children['extend_timber'] = new Extenders\Timber();
|
||||
$this->children['extend_dashboard'] = new Extenders\Admin\Dashboard();
|
||||
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the RomhackPlaza plugin is enabled or not.
|
||||
* @return bool
|
||||
*/
|
||||
private function _is_theme_enabled(): bool {
|
||||
|
||||
return class_exists( 'RomhackPlaza\Theme' ) || defined( 'ROMHACKPLAZA_THEME' );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
28
src/Registrars/Custom_Post_Status.php
Normal file
28
src/Registrars/Custom_Post_Status.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Registrars;
|
||||
defined( '\ABSPATH' ) || exit;
|
||||
|
||||
use RomhackPlaza\Extenders\Custom_Post_Status as Status;
|
||||
final class Custom_Post_Status
|
||||
{
|
||||
|
||||
/**
|
||||
* Post status list and their object.
|
||||
* @var array
|
||||
*/
|
||||
final public object $select;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
$post_statuses = [];
|
||||
|
||||
$post_statuses['locked'] = new Status('locked', [ "label" => "Locked", "exclude_from_search" => true, "public" => false, "protected" => true ]);
|
||||
|
||||
$this->select = ( object)$post_statuses;
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
368
src/Registrars/Custom_Post_Types.php
Normal file
368
src/Registrars/Custom_Post_Types.php
Normal file
@@ -0,0 +1,368 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Registrars;
|
||||
defined( '\ABSPATH' ) || exit;
|
||||
|
||||
use RomhackPlaza\Extenders\Custom_Post_Type as CPT;
|
||||
final class Custom_Post_Types {
|
||||
|
||||
/**
|
||||
* Post type list and their object.
|
||||
* @var array
|
||||
*/
|
||||
final public object $select;
|
||||
|
||||
public function __construct() {
|
||||
|
||||
$post_types = [];
|
||||
|
||||
/* --- TRANSLATIONS --- */
|
||||
|
||||
$post_types['translations'] = new CPT( 'translations', "translation", [
|
||||
"label" => esc_html__( "Translations", "romhackplaza" ),
|
||||
"labels" => [
|
||||
"name" => esc_html__( "Translations", "romhackplaza" ),
|
||||
"singular_name" => esc_html__( "Translation", "romhackplaza" ),
|
||||
],
|
||||
"description" => "
|
||||
Fan translations of games are a fascinating aspect of gaming culture where enthusiasts take non-English games and translate them into different languages, primarily English. This process involves more than just translating text; it\'s about adapting a game\'s dialogue, story, and even cultural references to resonate with a wider audience while staying true to the original\'s essence.
|
||||
|
||||
This meticulous task is carried out by dedicated fans who possess skills in language translation, programming, and sometimes graphic editing. The process starts with extracting the text from the game, which can be a challenge in itself due to different coding structures in old games. Once extracted, the translation begins, paying close attention to nuances and context. After translation, the text is reinserted into the game, often requiring additional programming to ensure everything fits and works seamlessly – from dialogue boxes to character limits.
|
||||
|
||||
What makes fan translations truly special is the commitment to preserving the original game\'s feel and storytelling. It\'s not just about understanding the language, but also about capturing the tone, humor, and emotional beats of the game. This often involves creative solutions to convey cultural nuances that might not have a direct counterpart in the target language.
|
||||
|
||||
On our website, we host a repository of these translation patches. These are downloadable files that you can apply to your game files, enabling you to play them in the translated language. This repository is a testament to the hard work and passion of the fan translation community. It\'s a place where gamers from all over the world can come to find and enjoy games that were previously out of reach due to language barriers. Each patch in our collection represents hours of dedication and a deep love for gaming\'s rich and diverse history.",
|
||||
"public" => true,
|
||||
"publicly_queryable" => true,
|
||||
"show_ui" => true,
|
||||
"show_in_rest" => false,
|
||||
"rest_base" => "",
|
||||
"rest_controller_class" => "WP_REST_Posts_Controller",
|
||||
"rest_namespace" => "wp/v2",
|
||||
"has_archive" => true,
|
||||
"show_in_menu" => true,
|
||||
"show_in_nav_menus" => true,
|
||||
"delete_with_user" => false,
|
||||
"exclude_from_search" => false,
|
||||
"capability_type" => "post",
|
||||
"map_meta_cap" => true,
|
||||
"hierarchical" => false,
|
||||
"can_export" => false,
|
||||
"rewrite" => [ "slug" => "translations", "with_front" => true ],
|
||||
"query_var" => true,
|
||||
"supports" => [ "title", "editor", "thumbnail", "comments", "author" ],
|
||||
"taxonomies" => [ "category", "post_tag", "game", "hack-status", "language", "platform", "author-name" ],
|
||||
"show_in_graphql" => false,
|
||||
] );
|
||||
|
||||
/* --- ROMHACKS --- */
|
||||
|
||||
$post_types['romhacks'] = new CPT( 'romhacks', "romhack", [
|
||||
"label" => esc_html__( "Romhacks", "romhackplaza" ),
|
||||
"labels" => [
|
||||
"name" => esc_html__( "Romhacks", "romhackplaza" ),
|
||||
"singular_name" => esc_html__( "Romhack", "romhackplaza" ),
|
||||
],
|
||||
"description" => "The Romhacks section of our website is a hub for all kinds of game modifications created by fans. Here, enthusiasts and talented programmers take classic games and tweak them, adding new features, fixing bugs, or completely transforming the gameplay. These modifications or romhacks, are a way for fans to reimagine, enhance, and personalize their favorite games.
|
||||
|
||||
Our archives are a treasure trove of these fan-made creations, easily downloadable for gamers to explore. The variety of hacks available is vast, catering to different interests and gaming experiences:
|
||||
|
||||
<b>Bug Fix:</b> These hacks address glitches and bugs in the original game, providing a smoother gaming experience.
|
||||
<b>Gameplay:</b> Modifications that alter or improve the gameplay mechanics to offer a new experience or to fine-tune the existing one.
|
||||
<b>Graphics:</b> Hacks that update or change the game’s visual elements, like character designs, environments, and animations.
|
||||
<b>Levels:</b> New levels or redesigns of existing ones to add more challenges or fresh perspectives.
|
||||
<b>Music:</b> Changes or enhancements to the game’s soundtrack and audio elements.
|
||||
<b>Optimization:</b> Such as FastROM hacks for SNES games, these are focused on making the game run more efficiently without altering the gameplay itself.
|
||||
<b>Save/Load:</b> Adding saving functionality, like SRAM, to games that originally lacked this feature.
|
||||
<b>SFX:</b> These hacks modify the game’s sound effects.
|
||||
<b>Text:</b> Changes to the game script, including improvements in spelling and grammar or complete rewrites for a different narrative.
|
||||
<b>Undub:</b> A popular type of romhack that replaces localized voice acting with the original, often changing English back to Japanese.
|
||||
<b>Unlocker:</b> These hacks unlock features, secret characters, unused languages, and other inaccessible content.
|
||||
|
||||
Each hack in our repository is a testament to the creativity and technical skill of the romhacking community. Whether you\'re looking to revisit a beloved classic with new features or wanting to explore what could have been, our romhacks section is your gateway to a whole new world of gaming possibilities. Just download a hack, apply it to your game, and you\'re ready to experience your favorite games like never before.",
|
||||
"public" => true,
|
||||
"publicly_queryable" => true,
|
||||
"show_ui" => true,
|
||||
"show_in_rest" => false,
|
||||
"rest_base" => "",
|
||||
"rest_controller_class" => "WP_REST_Posts_Controller",
|
||||
"rest_namespace" => "wp/v2",
|
||||
"has_archive" => true,
|
||||
"show_in_menu" => true,
|
||||
"show_in_nav_menus" => true,
|
||||
"delete_with_user" => false,
|
||||
"exclude_from_search" => false,
|
||||
"capability_type" => "post",
|
||||
"map_meta_cap" => true,
|
||||
"hierarchical" => false,
|
||||
"can_export" => false,
|
||||
"rewrite" => [ "slug" => "romhacks", "with_front" => true ],
|
||||
"query_var" => true,
|
||||
"supports" => [ "title", "editor", "thumbnail", "comments", "author" ],
|
||||
"taxonomies" => [ "category", "post_tag", "game", "hack-status", "language", "platform", "author-name" ],
|
||||
"show_in_graphql" => false,
|
||||
]);
|
||||
|
||||
/* --- HOMEBREWS --- */
|
||||
|
||||
$post_types['homebrews'] = new CPT( 'homebrew', "homebrew", [
|
||||
"label" => esc_html__( "Homebrew", "romhackplaza" ),
|
||||
"labels" => [
|
||||
"name" => esc_html__( "Homebrew", "romhackplaza" ),
|
||||
"singular_name" => esc_html__( "Homebrew", "romhackplaza" ),
|
||||
],
|
||||
"description" => "The Homebrew section of our site is a celebration of creativity and innovation in the gaming world. Here, you\'ll find an impressive collection of fan-made games, lovingly crafted by passionate developers and enthusiasts. These games, often referred to as \"homebrew,\" are original creations that range from tributes to classic titles to entirely new concepts.
|
||||
|
||||
In this vibrant corner of our site, doujins also find their place. Doujin refers to indie games created by small teams or individuals, similar to the concept of fanfiction in literature. These are games born from a deep love of gaming and a desire to contribute something unique to the community.
|
||||
|
||||
Homebrew games cover a wide array of genres and styles, showcasing the diverse talents of their creators. From platformers that nod to the 8-bit era to innovative puzzle games that challenge the norms, each title is a fresh and exciting exploration of what gaming can be. These games aren\'t just about nostalgia; they\'re about pushing boundaries, experimenting with new ideas, and sharing personal visions with the world.
|
||||
|
||||
The beauty of the homebrew section lies in its inclusivity and the sense of community it fosters. It\'s a place where both seasoned developers and novices can showcase their work, learn from each other, and receive feedback from a community of gamers and enthusiasts. Whether you\'re a fan of retro gaming or looking for something entirely new, our homebrew section is sure to have something that piques your interest.
|
||||
|
||||
What\'s more, these games are easily accessible. You can download and play these homebrew titles, experiencing the innovation and dedication of fellow gamers. Each game is a labor of love, a testament to the creativity and technical skill of its creator, and a valuable addition to the world of gaming. So dive in, explore, and be inspired by the remarkable world of homebrew gaming on our site.",
|
||||
"public" => true,
|
||||
"publicly_queryable" => true,
|
||||
"show_ui" => true,
|
||||
"show_in_rest" => false,
|
||||
"rest_base" => "",
|
||||
"rest_controller_class" => "WP_REST_Posts_Controller",
|
||||
"rest_namespace" => "wp/v2",
|
||||
"has_archive" => true,
|
||||
"show_in_menu" => true,
|
||||
"show_in_nav_menus" => true,
|
||||
"delete_with_user" => false,
|
||||
"exclude_from_search" => false,
|
||||
"capability_type" => "post",
|
||||
"map_meta_cap" => true,
|
||||
"hierarchical" => false,
|
||||
"can_export" => false,
|
||||
"rewrite" => [ "slug" => "homebrew", "with_front" => true ],
|
||||
"query_var" => true,
|
||||
"supports" => [ "title", "editor", "thumbnail", "comments", "author" ],
|
||||
"taxonomies" => [ "category", "post_tag", "game", "hack-status", "language", "platform", "author-name" ],
|
||||
"show_in_graphql" => false,
|
||||
]);
|
||||
|
||||
/* --- UTILITIES --- */
|
||||
|
||||
$post_types['utilities'] = new CPT( 'utilities', "utility", [
|
||||
"label" => esc_html__( "Utilities", "romhackplaza" ),
|
||||
"labels" => [
|
||||
"name" => esc_html__( "Utilities", "romhackplaza" ),
|
||||
"singular_name" => esc_html__( "Utility", "romhackplaza" ),
|
||||
],
|
||||
"description" => "Our Utilities section is the toolkit of the romhacking world. It\'s stocked with an array of specialized tools designed to assist in the creation and implementation of romhacks. These utilities range from software for editing graphics and sound to programs that help modify game code. Whether you\'re a seasoned hacker or just starting, these tools are essential for anyone looking to dive into the intricacies of game modification. They streamline the process, making it more accessible and efficient. Our Utilities section is a testament to the community\'s ingenuity, offering the necessary resources to bring your gaming visions to life.",
|
||||
"public" => true,
|
||||
"publicly_queryable" => true,
|
||||
"show_ui" => true,
|
||||
"show_in_rest" => false,
|
||||
"rest_base" => "",
|
||||
"rest_controller_class" => "WP_REST_Posts_Controller",
|
||||
"rest_namespace" => "wp/v2",
|
||||
"has_archive" => true,
|
||||
"show_in_menu" => true,
|
||||
"show_in_nav_menus" => true,
|
||||
"delete_with_user" => false,
|
||||
"exclude_from_search" => false,
|
||||
"capability_type" => "post",
|
||||
"map_meta_cap" => true,
|
||||
"hierarchical" => false,
|
||||
"can_export" => false,
|
||||
"rewrite" => [ "slug" => "utilities", "with_front" => true ],
|
||||
"query_var" => true,
|
||||
"supports" => [ "title", "editor", "thumbnail", "comments", "author" ],
|
||||
"taxonomies" => [ "category", "post_tag", "game", "language", "platform", "author-name", "utility-category", "experience-level", "utility-os" ],
|
||||
"show_in_graphql" => false,
|
||||
] );
|
||||
|
||||
/* --- DOCUMENTS --- */
|
||||
|
||||
$post_types['documents'] = new CPT( 'documents', "document", [
|
||||
"label" => esc_html__( "Documents", "romhackplaza" ),
|
||||
"labels" => [
|
||||
"name" => esc_html__( "Documents", "romhackplaza" ),
|
||||
"singular_name" => esc_html__( "Document", "romhackplaza" ),
|
||||
],
|
||||
"description" => "The Documents section is the knowledge hub of our community. Here, you\'ll find an extensive library of text documentation, rich with insights and instructions on romhacking. These documents are a treasure trove of information, covering everything from basic hacking techniques to advanced concepts in game reverse engineering. Written by experienced members of the romhacking community, these guides are invaluable for anyone looking to understand how games function internally or wanting to create their own hacks. This section is not just about sharing information; it\'s about fostering a culture of learning and collaboration, enabling more gamers to become creators.",
|
||||
"public" => true,
|
||||
"publicly_queryable" => true,
|
||||
"show_ui" => true,
|
||||
"show_in_rest" => false,
|
||||
"rest_base" => "",
|
||||
"rest_controller_class" => "WP_REST_Posts_Controller",
|
||||
"rest_namespace" => "wp/v2",
|
||||
"has_archive" => true,
|
||||
"show_in_menu" => true,
|
||||
"show_in_nav_menus" => true,
|
||||
"delete_with_user" => false,
|
||||
"exclude_from_search" => false,
|
||||
"capability_type" => "post",
|
||||
"map_meta_cap" => true,
|
||||
"hierarchical" => false,
|
||||
"can_export" => false,
|
||||
"rewrite" => [ "slug" => "documents", "with_front" => true ],
|
||||
"query_var" => true,
|
||||
"supports" => [ "title", "editor", "thumbnail", "comments", "author" ],
|
||||
"taxonomies" => [ "game", "hack-status", "language", "platform", "author-name", "document-category" ],
|
||||
"show_in_graphql" => false,
|
||||
]);
|
||||
|
||||
/* --- NEWS --- */
|
||||
|
||||
$post_types['news'] = new CPT( 'news', "news", [
|
||||
"label" => esc_html__( "News", "romhackplaza" ),
|
||||
"labels" => [
|
||||
"name" => esc_html__( "News", "romhackplaza" ),
|
||||
"singular_name" => esc_html__( "News", "romhackplaza" ),
|
||||
],
|
||||
"description" => "",
|
||||
"public" => true,
|
||||
"publicly_queryable" => true,
|
||||
"show_ui" => true,
|
||||
"show_in_rest" => false,
|
||||
"rest_base" => "",
|
||||
"rest_controller_class" => "WP_REST_Posts_Controller",
|
||||
"rest_namespace" => "wp/v2",
|
||||
"has_archive" => true,
|
||||
"show_in_menu" => true,
|
||||
"show_in_nav_menus" => true,
|
||||
"delete_with_user" => false,
|
||||
"exclude_from_search" => false,
|
||||
"capability_type" => "post",
|
||||
"map_meta_cap" => true,
|
||||
"hierarchical" => false,
|
||||
"can_export" => false,
|
||||
"rewrite" => [ "slug" => "news", "with_front" => true ],
|
||||
"query_var" => true,
|
||||
"supports" => [ "title", "editor", "custom-fields", "comments", "author" ],
|
||||
"show_in_graphql" => false,
|
||||
] );
|
||||
|
||||
/* --- TUTORIALS --- */
|
||||
|
||||
$post_types['tutorials'] = new CPT( 'tutorials', "tutorial", [
|
||||
"label" => esc_html__( "Tutorials", "romhackplaza" ),
|
||||
"labels" => [
|
||||
"name" => esc_html__( "Tutorials", "romhackplaza" ),
|
||||
"singular_name" => esc_html__( "Tutorial", "romhackplaza" ),
|
||||
],
|
||||
"description" => "",
|
||||
"public" => true,
|
||||
"publicly_queryable" => true,
|
||||
"show_ui" => true,
|
||||
"show_in_rest" => true,
|
||||
"rest_base" => "",
|
||||
"rest_controller_class" => "WP_REST_Posts_Controller",
|
||||
"rest_namespace" => "wp/v2",
|
||||
"has_archive" => true,
|
||||
"show_in_menu" => true,
|
||||
"show_in_nav_menus" => true,
|
||||
"delete_with_user" => false,
|
||||
"exclude_from_search" => false,
|
||||
"capability_type" => "post",
|
||||
"map_meta_cap" => true,
|
||||
"hierarchical" => false,
|
||||
"can_export" => false,
|
||||
"rewrite" => [ "slug" => "tutorials", "with_front" => true ],
|
||||
"query_var" => true,
|
||||
"supports" => [ "title", "editor", "thumbnail", "excerpt", "comments", "author" ],
|
||||
"taxonomies" => [ "category", "post_tag", "game", "platform", "author-name", "experience-level" ],
|
||||
"show_in_graphql" => false,
|
||||
] );
|
||||
|
||||
/* --- LUA SCRIPTS --- */
|
||||
|
||||
$post_types['lua_scripts'] = new CPT( 'lua-scripts', "lua-script", [
|
||||
"label" => esc_html__( "LUA Scripts", "romhackplaza" ),
|
||||
"labels" => [
|
||||
"name" => esc_html__( "LUA Scripts", "romhackplaza" ),
|
||||
"singular_name" => esc_html__( "LUA Script", "romhackplaza" ),
|
||||
],
|
||||
"description" => "",
|
||||
"public" => true,
|
||||
"publicly_queryable" => true,
|
||||
"show_ui" => true,
|
||||
"show_in_rest" => true,
|
||||
"rest_base" => "",
|
||||
"rest_controller_class" => "WP_REST_Posts_Controller",
|
||||
"rest_namespace" => "wp/v2",
|
||||
"has_archive" => true,
|
||||
"show_in_menu" => true,
|
||||
"show_in_nav_menus" => true,
|
||||
"delete_with_user" => false,
|
||||
"exclude_from_search" => false,
|
||||
"capability_type" => "post",
|
||||
"map_meta_cap" => true,
|
||||
"hierarchical" => false,
|
||||
"can_export" => false,
|
||||
"rewrite" => [ "slug" => "lua-scripts", "with_front" => true ],
|
||||
"query_var" => true,
|
||||
"supports" => [ "title", "editor", "thumbnail", "comments", "author" ],
|
||||
"taxonomies" => [ "category", "post_tag", "game", "hack-status", "language", "platform", "author-name", "genre", "lua-modifications" ],
|
||||
"show_in_graphql" => false,
|
||||
] );
|
||||
|
||||
/* --- REVIEWS --- */
|
||||
|
||||
$post_types['reviews'] = new CPT( 'reviews', "review", [
|
||||
"labels" => [
|
||||
"name" => "Reviews",
|
||||
"singular_name" => "Review",
|
||||
],
|
||||
"public" => true,
|
||||
"menu_position" => 30,
|
||||
"menu_icon" => "dashicons-text",
|
||||
"supports" => [ "title", "editor", "author", "custom-fields" ],
|
||||
"has_archive" => false,
|
||||
"capability_type" => "post",
|
||||
"exclude_from_search" => true,
|
||||
] );
|
||||
|
||||
/* ADD YOUR NEW CUSTOM POST TYPE HERE */
|
||||
|
||||
/**
|
||||
* Can't be bind now.
|
||||
* Settings may not be loaded.
|
||||
*/
|
||||
add_action( 'RomhackPlaza\\Init', [ $this, 'add_acf_group_fields' ] );
|
||||
|
||||
$this->select = (object) $post_types;
|
||||
return $this;// END_CPT_CREATE
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* List every secondary CPTs.
|
||||
* @return string[]
|
||||
*/
|
||||
public function secondary_cpt(): array {
|
||||
|
||||
return ['reviews'];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* List every primary CPTs based on the secondary ones.
|
||||
* @return array
|
||||
*/
|
||||
public function primary_cpt(): array {
|
||||
|
||||
return $this->select |> get_object_vars(...)
|
||||
|> ( fn( $arr ) => array_keys( $arr ) )
|
||||
|> ( fn( $arr ) => array_diff( $arr, $this->secondary_cpt() ) );
|
||||
|
||||
}
|
||||
|
||||
public function add_acf_group_fields(): void {
|
||||
|
||||
global $_romhackplaza;
|
||||
|
||||
foreach ( $this->select as $key => $select ) {
|
||||
$select->setAcfFieldGroupKey( $_romhackplaza->settings->get( $select->name . "_acf_group" ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
400
src/Registrars/Taxonomies.php
Normal file
400
src/Registrars/Taxonomies.php
Normal file
@@ -0,0 +1,400 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza\Registrars;
|
||||
defined( '\ABSPATH' ) || exit;
|
||||
|
||||
use RomhackPlaza\Extenders\Taxonomy as Tax;
|
||||
final class Taxonomies {
|
||||
|
||||
/**
|
||||
* Taxonomies list and their object.
|
||||
* @var array
|
||||
*/
|
||||
final public object $select;
|
||||
|
||||
public function __construct() {
|
||||
|
||||
$taxonomies = [];
|
||||
|
||||
$taxonomies['game'] = new Tax( 'game', ["translations", "romhacks", "documents", "utilities"], [
|
||||
"label" => esc_html__( "Games", "romhackplaza" ),
|
||||
"labels" => [
|
||||
"name" => esc_html__( "Games", "romhackplaza" ),
|
||||
"singular_name" => esc_html__( "Game", "romhackplaza" ),
|
||||
],
|
||||
"public" => true,
|
||||
"publicly_queryable" => true,
|
||||
"hierarchical" => false,
|
||||
"show_ui" => true,
|
||||
"show_in_menu" => true,
|
||||
"show_in_nav_menus" => true,
|
||||
"query_var" => true,
|
||||
"rewrite" => [ 'slug' => 'game', 'with_front' => true, ],
|
||||
"show_admin_column" => false,
|
||||
"show_in_rest" => true,
|
||||
"show_tagcloud" => false,
|
||||
"rest_base" => "game",
|
||||
"rest_controller_class" => "WP_REST_Terms_Controller",
|
||||
"rest_namespace" => "wp/v2",
|
||||
"show_in_quick_edit" => false,
|
||||
"sort" => false,
|
||||
"show_in_graphql" => false,
|
||||
]
|
||||
);
|
||||
|
||||
$taxonomies['hack_status'] = new Tax( 'hack-status', ["translations", "romhacks", "homebrew"], [
|
||||
"label" => esc_html__( "Status", "romhackplaza" ),
|
||||
"labels" => [
|
||||
"name" => esc_html__( "Status", "romhackplaza" ),
|
||||
"singular_name" => esc_html__( "Status", "romhackplaza" ),
|
||||
],
|
||||
"public" => true,
|
||||
"publicly_queryable" => true,
|
||||
"hierarchical" => false,
|
||||
"show_ui" => true,
|
||||
"show_in_menu" => true,
|
||||
"show_in_nav_menus" => true,
|
||||
"query_var" => true,
|
||||
"rewrite" => [ 'slug' => 'hack-status', 'with_front' => true, ],
|
||||
"show_admin_column" => false,
|
||||
"show_in_rest" => true,
|
||||
"show_tagcloud" => false,
|
||||
"rest_base" => "hack-status",
|
||||
"rest_controller_class" => "WP_REST_Terms_Controller",
|
||||
"rest_namespace" => "wp/v2",
|
||||
"show_in_quick_edit" => false,
|
||||
"sort" => false,
|
||||
"show_in_graphql" => false,
|
||||
] );
|
||||
|
||||
$taxonomies['language'] = new Tax( 'language', [ "translations", "romhacks", "homebrew", "documents", "utilities" ], [
|
||||
"label" => esc_html__( "Langauges", "romhackplaza" ),
|
||||
"labels" => [
|
||||
"name" => esc_html__( "Langauges", "romhackplaza" ),
|
||||
"singular_name" => esc_html__( "Language", "romhackplaza" ),
|
||||
],
|
||||
"public" => true,
|
||||
"publicly_queryable" => true,
|
||||
"hierarchical" => false,
|
||||
"show_ui" => true,
|
||||
"show_in_menu" => true,
|
||||
"show_in_nav_menus" => true,
|
||||
"query_var" => true,
|
||||
"rewrite" => [ 'slug' => 'language', 'with_front' => true, ],
|
||||
"show_admin_column" => false,
|
||||
"show_in_rest" => true,
|
||||
"show_tagcloud" => false,
|
||||
"rest_base" => "language",
|
||||
"rest_controller_class" => "WP_REST_Terms_Controller",
|
||||
"rest_namespace" => "wp/v2",
|
||||
"show_in_quick_edit" => false,
|
||||
"sort" => false,
|
||||
"show_in_graphql" => false,
|
||||
]);
|
||||
|
||||
$taxonomies['platform'] = new Tax( 'platform', [ "translations", "romhacks", "homebrew" ], [
|
||||
"label" => esc_html__( "Platforms", "romhackplaza" ),
|
||||
"labels" => [
|
||||
"name" => esc_html__( "Platforms", "romhackplaza" ),
|
||||
"singular_name" => esc_html__( "Platform", "romhackplaza" ),
|
||||
],
|
||||
"public" => true,
|
||||
"publicly_queryable" => true,
|
||||
"hierarchical" => false,
|
||||
"show_ui" => true,
|
||||
"show_in_menu" => true,
|
||||
"show_in_nav_menus" => true,
|
||||
"query_var" => true,
|
||||
"rewrite" => [ 'slug' => 'platform', 'with_front' => true, ],
|
||||
"show_admin_column" => false,
|
||||
"show_in_rest" => true,
|
||||
"show_tagcloud" => false,
|
||||
"rest_base" => "platform",
|
||||
"rest_controller_class" => "WP_REST_Terms_Controller",
|
||||
"rest_namespace" => "wp/v2",
|
||||
"show_in_quick_edit" => false,
|
||||
"sort" => false,
|
||||
"show_in_graphql" => false,
|
||||
]);
|
||||
|
||||
$taxonomies['author_name'] = new Tax( 'author-name', [ "translations", "romhacks", "homebrew", "documents", "utilities" ], [
|
||||
"label" => esc_html__( "Authors", "romhackplaza" ),
|
||||
"labels" => [
|
||||
"name" => esc_html__( "Authors", "romhackplaza" ),
|
||||
"singular_name" => esc_html__( "Author", "romhackplaza" ),
|
||||
],
|
||||
"public" => true,
|
||||
"publicly_queryable" => true,
|
||||
"hierarchical" => false,
|
||||
"show_ui" => true,
|
||||
"show_in_menu" => true,
|
||||
"show_in_nav_menus" => true,
|
||||
"query_var" => true,
|
||||
"rewrite" => [ 'slug' => 'author-name', 'with_front' => true, ],
|
||||
"show_admin_column" => false,
|
||||
"show_in_rest" => true,
|
||||
"show_tagcloud" => false,
|
||||
"rest_base" => "author-name",
|
||||
"rest_controller_class" => "WP_REST_Terms_Controller",
|
||||
"rest_namespace" => "wp/v2",
|
||||
"show_in_quick_edit" => false,
|
||||
"sort" => false,
|
||||
"show_in_graphql" => false,
|
||||
] );
|
||||
|
||||
$taxonomies['utility_category'] = new Tax( 'utility-category', [ "utilities" ], [
|
||||
"label" => esc_html__( "Utility Category", "romhackplaza" ),
|
||||
"labels" => [
|
||||
"name" => esc_html__( "Utility Category", "romhackplaza" ),
|
||||
"singular_name" => esc_html__( "Utility Category", "romhackplaza" ),
|
||||
],
|
||||
"public" => true,
|
||||
"publicly_queryable" => true,
|
||||
"hierarchical" => false,
|
||||
"show_ui" => true,
|
||||
"show_in_menu" => true,
|
||||
"show_in_nav_menus" => true,
|
||||
"query_var" => true,
|
||||
"rewrite" => [ 'slug' => 'utility-category', 'with_front' => true, ],
|
||||
"show_admin_column" => false,
|
||||
"show_in_rest" => true,
|
||||
"show_tagcloud" => false,
|
||||
"rest_base" => "utility-category",
|
||||
"rest_controller_class" => "WP_REST_Terms_Controller",
|
||||
"rest_namespace" => "wp/v2",
|
||||
"show_in_quick_edit" => false,
|
||||
"sort" => false,
|
||||
"show_in_graphql" => false,
|
||||
]);
|
||||
|
||||
$taxonomies['experience_level'] = new Tax( 'experience-level', [ "utilities", "documents" ], [
|
||||
"label" => esc_html__( "Experience Level", "romhackplaza" ),
|
||||
"labels" => [
|
||||
"name" => esc_html__( "Experience Level", "romhackplaza" ),
|
||||
"singular_name" => esc_html__( "Experience Level", "romhackplaza" ),
|
||||
],
|
||||
"public" => true,
|
||||
"publicly_queryable" => true,
|
||||
"hierarchical" => false,
|
||||
"show_ui" => true,
|
||||
"show_in_menu" => true,
|
||||
"show_in_nav_menus" => true,
|
||||
"query_var" => true,
|
||||
"rewrite" => [ 'slug' => 'experience-level', 'with_front' => true, ],
|
||||
"show_admin_column" => false,
|
||||
"show_in_rest" => true,
|
||||
"show_tagcloud" => false,
|
||||
"rest_base" => "experience-level",
|
||||
"rest_controller_class" => "WP_REST_Terms_Controller",
|
||||
"rest_namespace" => "wp/v2",
|
||||
"show_in_quick_edit" => false,
|
||||
"sort" => false,
|
||||
"show_in_graphql" => false,
|
||||
]);
|
||||
|
||||
$taxonomies['utility_os'] = new Tax( 'utility-os', [ "utilities" ], [
|
||||
"label" => esc_html__( "Utility OS", "romhackplaza" ),
|
||||
"labels" =>[
|
||||
"name" => esc_html__( "Utility OS", "romhackplaza" ),
|
||||
"singular_name" => esc_html__( "Utility OS", "romhackplaza" ),
|
||||
],
|
||||
"public" => true,
|
||||
"publicly_queryable" => true,
|
||||
"hierarchical" => false,
|
||||
"show_ui" => true,
|
||||
"show_in_menu" => true,
|
||||
"show_in_nav_menus" => true,
|
||||
"query_var" => true,
|
||||
"rewrite" => [ 'slug' => 'utility-os', 'with_front' => true, ],
|
||||
"show_admin_column" => false,
|
||||
"show_in_rest" => true,
|
||||
"show_tagcloud" => false,
|
||||
"rest_base" => "utility-os",
|
||||
"rest_controller_class" => "WP_REST_Terms_Controller",
|
||||
"rest_namespace" => "wp/v2",
|
||||
"show_in_quick_edit" => false,
|
||||
"sort" => false,
|
||||
"show_in_graphql" => false,
|
||||
]);
|
||||
|
||||
$taxonomies['document_category'] = new Tax( 'document-category', [ "documents" ], [
|
||||
"label" => esc_html__( "Document Category", "romhackplaza" ),
|
||||
"labels" => [
|
||||
"name" => esc_html__( "Document Category", "romhackplaza" ),
|
||||
"singular_name" => esc_html__( "Document Category", "romhackplaza" ),
|
||||
],
|
||||
"public" => true,
|
||||
"publicly_queryable" => true,
|
||||
"hierarchical" => false,
|
||||
"show_ui" => true,
|
||||
"show_in_menu" => true,
|
||||
"show_in_nav_menus" => true,
|
||||
"query_var" => true,
|
||||
"rewrite" => [ 'slug' => 'document-category', 'with_front' => true, ],
|
||||
"show_admin_column" => false,
|
||||
"show_in_rest" => true,
|
||||
"show_tagcloud" => false,
|
||||
"rest_base" => "document-category",
|
||||
"rest_controller_class" => "WP_REST_Terms_Controller",
|
||||
"rest_namespace" => "wp/v2",
|
||||
"show_in_quick_edit" => false,
|
||||
"sort" => false,
|
||||
"show_in_graphql" => false,
|
||||
]);
|
||||
|
||||
$taxonomies['modifications'] = new Tax( 'modifications', ['romhacks'], [
|
||||
"label" => esc_html__( "Modifications", "romhackplaza" ),
|
||||
"labels" => [
|
||||
"name" => esc_html__( "Modifications", "romhackplaza" ),
|
||||
"singular_name" => esc_html__( "Modification", "romhackplaza" ),
|
||||
],
|
||||
"public" => true,
|
||||
"publicly_queryable" => true,
|
||||
"hierarchical" => false,
|
||||
"show_ui" => true,
|
||||
"show_in_menu" => true,
|
||||
"show_in_nav_menus" => true,
|
||||
"query_var" => true,
|
||||
"rewrite" => [ 'slug' => 'modifications', 'with_front' => true, ],
|
||||
"show_admin_column" => false,
|
||||
"show_in_rest" => true,
|
||||
"show_tagcloud" => false,
|
||||
"rest_base" => "modifications",
|
||||
"rest_controller_class" => "WP_REST_Terms_Controller",
|
||||
"rest_namespace" => "wp/v2",
|
||||
"show_in_quick_edit" => false,
|
||||
"sort" => false,
|
||||
"show_in_graphql" => false,
|
||||
] );
|
||||
|
||||
$taxonomies['homebrew_type'] = new Tax( 'homebrew-type', [ "homebrew" ], [
|
||||
"label" => esc_html__( "Homebrew Types", "romhackplaza" ),
|
||||
"labels" => [
|
||||
"name" => esc_html__( "Homebrew Types", "romhackplaza" ),
|
||||
"singular_name" => esc_html__( "Homebrew Type", "romhackplaza" ),
|
||||
],
|
||||
"public" => true,
|
||||
"publicly_queryable" => true,
|
||||
"hierarchical" => false,
|
||||
"show_ui" => true,
|
||||
"show_in_menu" => true,
|
||||
"show_in_nav_menus" => true,
|
||||
"query_var" => true,
|
||||
"rewrite" => [ 'slug' => 'homebrew-type', 'with_front' => true, ],
|
||||
"show_admin_column" => false,
|
||||
"show_in_rest" => true,
|
||||
"show_tagcloud" => false,
|
||||
"rest_base" => "homebrew-type",
|
||||
"rest_controller_class" => "WP_REST_Terms_Controller",
|
||||
"rest_namespace" => "wp/v2",
|
||||
"show_in_quick_edit" => false,
|
||||
"sort" => false,
|
||||
"show_in_graphql" => false,
|
||||
]);
|
||||
|
||||
$taxonomies['news_category'] = new Tax( 'news-category', [ "news" ], [
|
||||
"label" => esc_html__( "News Category", "romhackplaza" ),
|
||||
"labels" => [
|
||||
"name" => esc_html__( "News Category", "romhackplaza" ),
|
||||
"singular_name" => esc_html__( "News Category", "romhackplaza" ),
|
||||
],
|
||||
"public" => true,
|
||||
"publicly_queryable" => true,
|
||||
"hierarchical" => false,
|
||||
"show_ui" => true,
|
||||
"show_in_menu" => true,
|
||||
"show_in_nav_menus" => true,
|
||||
"query_var" => true,
|
||||
"rewrite" => [ 'slug' => 'news-category', 'with_front' => true, ],
|
||||
"show_admin_column" => false,
|
||||
"show_in_rest" => true,
|
||||
"show_tagcloud" => false,
|
||||
"rest_base" => "news-category",
|
||||
"rest_controller_class" => "WP_REST_Terms_Controller",
|
||||
"rest_namespace" => "wp/v2",
|
||||
"show_in_quick_edit" => false,
|
||||
"sort" => false,
|
||||
"show_in_graphql" => false,
|
||||
]);
|
||||
|
||||
$taxonomies['genre'] = new Tax( 'genre', [ "translations", "romhacks", "homebrew", "documents", "utilities" ], [
|
||||
"label" => esc_html__( "Genres", "romhackplaza" ),
|
||||
"labels" => [
|
||||
"name" => esc_html__( "Genres", "romhackplaza" ),
|
||||
"singular_name" => esc_html__( "Genre", "romhackplaza" ),
|
||||
],
|
||||
"public" => true,
|
||||
"publicly_queryable" => true,
|
||||
"hierarchical" => false,
|
||||
"show_ui" => true,
|
||||
"show_in_menu" => true,
|
||||
"show_in_nav_menus" => true,
|
||||
"query_var" => true,
|
||||
"rewrite" => [ 'slug' => 'genre', 'with_front' => true, ],
|
||||
"show_admin_column" => false,
|
||||
"show_in_rest" => true,
|
||||
"show_tagcloud" => false,
|
||||
"rest_base" => "genre",
|
||||
"rest_controller_class" => "WP_REST_Terms_Controller",
|
||||
"rest_namespace" => "wp/v2",
|
||||
"show_in_quick_edit" => false,
|
||||
"sort" => false,
|
||||
"show_in_graphql" => false,
|
||||
]);
|
||||
|
||||
$taxonomies['tutorial_category'] = new Tax( 'tutorial-category', [ "tutorials" ], [
|
||||
"label" => esc_html__( "Tutorial Category", "romhackplaza" ),
|
||||
"labels" => [
|
||||
"name" => esc_html__( "Tutorial Category", "romhackplaza" ),
|
||||
"singular_name" => esc_html__( "Tutorial Category", "romhackplaza" ),
|
||||
],
|
||||
"public" => true,
|
||||
"publicly_queryable" => true,
|
||||
"hierarchical" => false,
|
||||
"show_ui" => true,
|
||||
"show_in_menu" => true,
|
||||
"show_in_nav_menus" => true,
|
||||
"query_var" => true,
|
||||
"rewrite" => [ 'slug' => 'tutorial-category', 'with_front' => true, ],
|
||||
"show_admin_column" => false,
|
||||
"show_in_rest" => true,
|
||||
"show_tagcloud" => false,
|
||||
"rest_base" => "tutorial-category",
|
||||
"rest_controller_class" => "WP_REST_Terms_Controller",
|
||||
"rest_namespace" => "wp/v2",
|
||||
"show_in_quick_edit" => false,
|
||||
"sort" => false,
|
||||
"show_in_graphql" => false,
|
||||
] );
|
||||
|
||||
$taxonomies['lua_modifications'] = new Tax( 'lua-modifications', [ 'lua-scripts'], [
|
||||
"label" => esc_html__( "LUA Modifications", "romhackplaza" ),
|
||||
"labels" => [
|
||||
"name" => esc_html__( "LUA Modifications", "romhackplaza" ),
|
||||
"singular_name" => esc_html__( "LUA Modification", "romhackplaza" ),
|
||||
],
|
||||
"public" => true,
|
||||
"publicly_queryable" => true,
|
||||
"hierarchical" => false,
|
||||
"show_ui" => true,
|
||||
"show_in_menu" => true,
|
||||
"show_in_nav_menus" => true,
|
||||
"query_var" => true,
|
||||
"rewrite" => [ 'slug' => 'lua-modifications', 'with_front' => true, ],
|
||||
"show_admin_column" => false,
|
||||
"show_in_rest" => true,
|
||||
"show_tagcloud" => false,
|
||||
"rest_base" => "lua-modifications",
|
||||
"rest_controller_class" => "WP_REST_Terms_Controller",
|
||||
"rest_namespace" => "wp/v2",
|
||||
"show_in_quick_edit" => false,
|
||||
"sort" => false,
|
||||
"show_in_graphql" => false,
|
||||
]);
|
||||
|
||||
$this->select = (object) $taxonomies;
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
134
src/Script.php
Normal file
134
src/Script.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace Romhackplaza;
|
||||
defined( '\ABSPATH' ) || exit;
|
||||
|
||||
class Script {
|
||||
|
||||
/**
|
||||
* @var Script_Type
|
||||
*/
|
||||
final public Script_Type $type;
|
||||
|
||||
/**
|
||||
* Script name.
|
||||
* @var string
|
||||
*/
|
||||
final public string $handle;
|
||||
|
||||
/**
|
||||
* URL where the file is.
|
||||
* @var string
|
||||
*/
|
||||
final public string|bool $source;
|
||||
|
||||
/**
|
||||
* Dependencies from other scripts.
|
||||
* @var array
|
||||
*/
|
||||
final public array $deps;
|
||||
|
||||
/**
|
||||
* Version number. False if not.
|
||||
* @var string|bool
|
||||
*/
|
||||
final public string|bool $version;
|
||||
final public string|bool $media;
|
||||
|
||||
final public array|bool $args;
|
||||
|
||||
/**
|
||||
* Save values
|
||||
*
|
||||
* @param Script_Type $type
|
||||
* @param string $handle
|
||||
* @param string|bool $source
|
||||
* @param array $deps
|
||||
* @param string|bool $version
|
||||
* @param string|bool $media
|
||||
* @param array $args
|
||||
* @return Script - Itself.
|
||||
*/
|
||||
public function __construct(
|
||||
Script_Type $type,
|
||||
string $handle,
|
||||
string|bool $source = false,
|
||||
array $deps = [],
|
||||
string|bool $version = false,
|
||||
string|bool $media = false,
|
||||
array|bool $args = [],
|
||||
) {
|
||||
|
||||
$this->type = $type;
|
||||
$this->handle = $handle;
|
||||
$this->source = $source;
|
||||
$this->deps = $deps;
|
||||
|
||||
/**
|
||||
* Edit version number.
|
||||
* Like if we want to put plugin/theme version number.
|
||||
*
|
||||
* @since 0.0.1a
|
||||
*
|
||||
* @param string|bool - Current version number or false
|
||||
* @return string|bool
|
||||
*/
|
||||
$this->version = apply_filters( 'RomhackPlaza\\Theme\\Scripts\\Version', $version );
|
||||
|
||||
$this->media = $media;
|
||||
$this->args = $args;
|
||||
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue current script.
|
||||
* @return $this
|
||||
*/
|
||||
public function enqueue(): Script {
|
||||
|
||||
switch ( $this->type ) {
|
||||
case Script_Type::JS:
|
||||
wp_enqueue_script( $this->handle, $this->source, $this->deps, $this->version, $this->args );
|
||||
break;
|
||||
case Script_Type::CSS:
|
||||
wp_enqueue_style( $this->handle, $this->source, $this->deps, $this->version, $this->media );
|
||||
break;
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add some data to the script.
|
||||
*
|
||||
* @param string $key__or_css_data
|
||||
* @param string $value
|
||||
* @return $this
|
||||
*/
|
||||
public function add_data( string $key__or_css_data, string $value = "" ): Script{
|
||||
|
||||
if ( $this->type == Script_Type::JS && $value != "" )
|
||||
wp_script_add_data( $this->handle, $key__or_css_data, $value );
|
||||
else if( $this->type == Script_Type::CSS )
|
||||
wp_add_inline_style( $this->handle, $key__or_css_data );
|
||||
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add localisation to the script.
|
||||
* @param string $object_name
|
||||
* @param array $l10n
|
||||
* @return $this
|
||||
*/
|
||||
public function add_localize( string $object_name, array $l10n ): Script{
|
||||
if ( $this->type == Script_Type::JS )
|
||||
wp_localize_script( $this->handle, $object_name, $l10n );
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
6
src/Script_Type.php
Normal file
6
src/Script_Type.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Romhackplaza;
|
||||
defined( '\ABSPATH' ) || exit;
|
||||
|
||||
enum Script_Type { case JS; case CSS; };
|
||||
85
src/Settings.php
Normal file
85
src/Settings.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza;
|
||||
defined( '\ABSPATH' ) || exit;
|
||||
|
||||
class Settings {
|
||||
|
||||
private array $options;
|
||||
/**
|
||||
* Default settings.
|
||||
* @var array
|
||||
*/
|
||||
private array $defaults;
|
||||
|
||||
public function __construct () {
|
||||
|
||||
$this->defaults = [
|
||||
'nsfw_tag_id' => '',
|
||||
'complete_submissions_form_page_ids' => '',
|
||||
'simple_submissions_form_page_ids' => '',
|
||||
'translations_acf_group' => '',
|
||||
'romhacks_acf_group' => '',
|
||||
'homebrew_acf_group' => '',
|
||||
'utilities_acf_group' => '',
|
||||
'documents_acf_group' => '',
|
||||
'lua_scripts_acf_group' => '',
|
||||
'tutorials_acf_group' => '',
|
||||
'news_acf_group' => '',
|
||||
'reviews_acf_group' => '',
|
||||
'public_edit_disabled_tag_id' => '',
|
||||
'discord_webhook_romhacks_translations' => '',
|
||||
'discord_webhook_global' => '',
|
||||
];
|
||||
|
||||
$this->refresh();
|
||||
|
||||
add_action( 'admin_init', [ $this, '_register_settings' ] );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh from database option values.
|
||||
* @return void
|
||||
*/
|
||||
public function refresh () {
|
||||
|
||||
$this->options = wp_parse_args(
|
||||
get_option( 'romhackplaza_plugin_options', [] ),
|
||||
$this->defaults
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an option.
|
||||
* @param string $option_name
|
||||
* @return mixed - False if the option name doesn't exist.
|
||||
*/
|
||||
public function get( string $option_name ): mixed {
|
||||
|
||||
if( isset( $this->options[ $option_name ] ) )
|
||||
return $this->options[ $option_name ];
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a default option.
|
||||
* @param string $option_name
|
||||
* @return mixed - False if the option name doesn't exist.
|
||||
*/
|
||||
public function get_default( string $option_name ): mixed {
|
||||
if( isset( $this->defaults[ $option_name ] ) )
|
||||
return $this->defaults[ $option_name ];
|
||||
return false;
|
||||
}
|
||||
|
||||
public function _register_settings (): void {
|
||||
|
||||
register_setting( 'romhackplaza_plugin_options_group', 'romhackplaza_plugin_options' );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
8
src/Snippets.php
Normal file
8
src/Snippets.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace RomhackPlaza;
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Snippets {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user