Update layout files
This commit is contained in:
parent
8ff0d9ee86
commit
df6bd2c282
4 changed files with 1125 additions and 1105 deletions
|
@ -1,17 +1,15 @@
|
|||
<?php
|
||||
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName
|
||||
/**
|
||||
* Includes the Plugin settings menu.
|
||||
*
|
||||
* @filesource
|
||||
* @author Stefan Herndler
|
||||
* @package footnotes
|
||||
* @since 1.5.0 12.09.14 10:26
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Handles the Settings interface of the Plugin.
|
||||
*
|
||||
* @author Stefan Herndler
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class MCI_Footnotes_Layout_Init {
|
||||
|
@ -19,68 +17,60 @@ class MCI_Footnotes_Layout_Init {
|
|||
/**
|
||||
* Slug for the Plugin main menu.
|
||||
*
|
||||
* @author Stefan Herndler
|
||||
* @since 1.5.0
|
||||
* @var string
|
||||
*/
|
||||
const C_STR_MAIN_MENU_SLUG = "mfmmf";
|
||||
const C_STR_MAIN_MENU_SLUG = 'mfmmf';
|
||||
|
||||
/**
|
||||
* Plugin main menu name.
|
||||
*
|
||||
* @author Stefan Herndler
|
||||
* @since 1.5.0
|
||||
* @var string
|
||||
*/
|
||||
const C_STR_MAIN_MENU_TITLE = "ManFisher";
|
||||
const C_STR_MAIN_MENU_TITLE = 'ManFisher';
|
||||
|
||||
/**
|
||||
* Contains layout engine sub classes.
|
||||
*
|
||||
* @author Stefan Herndler
|
||||
* @since 1.5.0
|
||||
* @var array
|
||||
*/
|
||||
private $a_arr_SubPageClasses = array();
|
||||
private $a_arr_sub_page_classes = array();
|
||||
|
||||
/**
|
||||
* Class Constructor. Initializes all WordPress hooks for the Plugin Settings.
|
||||
*
|
||||
* @author Stefan Herndler
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public function __construct() {
|
||||
// iterate through each class define in the current script
|
||||
foreach(get_declared_classes() as $l_str_ClassName) {
|
||||
// accept only child classes of the layout engine
|
||||
if(is_subclass_of($l_str_ClassName, 'MCI_Footnotes_LayoutEngine')) {
|
||||
/** @var MCI_Footnotes_LayoutEngine $l_obj_Class */
|
||||
$l_obj_Class = new $l_str_ClassName();
|
||||
// append new instance of the layout engine sub class
|
||||
$this->a_arr_SubPageClasses[$l_obj_Class->getPriority()] = $l_obj_Class;
|
||||
foreach ( get_declared_classes() as $l_str_class_name ) {
|
||||
if ( is_subclass_of( $l_str_class_name, 'MCI_Footnotes_Layout_Engine' ) ) {
|
||||
$l_obj_class = new $l_str_class_name();
|
||||
// Append new instance of the layout engine sub class.
|
||||
$this->a_arr_sub_page_classes[ $l_obj_class->get_priority() ] = $l_obj_class;
|
||||
}
|
||||
}
|
||||
ksort($this->a_arr_SubPageClasses);
|
||||
ksort( $this->a_arr_sub_page_classes );
|
||||
|
||||
// register hooks/actions
|
||||
add_action('admin_init', array($this, 'initializeSettings'));
|
||||
add_action('admin_menu', array($this, 'registerMainMenu'));
|
||||
// register AJAX callbacks for Plugin information
|
||||
add_action("wp_ajax_nopriv_footnotes_getPluginInfo", array($this, "getPluginMetaInformation"));
|
||||
add_action("wp_ajax_footnotes_getPluginInfo", array($this, "getPluginMetaInformation"));
|
||||
// Register hooks/actions.
|
||||
add_action( 'admin_init', array( $this, 'initialize_settings' ) );
|
||||
add_action( 'admin_menu', array( $this, 'register_main_menu' ) );
|
||||
// register AJAX callbacks for Plugin information.
|
||||
add_action( 'wp_ajax_nopriv_footnotes_get_plugin_info', array( $this, 'get_plugin_meta_information' ) );
|
||||
add_action( 'wp_ajax_footnotes_get_plugin_info', array( $this, 'get_plugin_meta_information' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes all sub pages and registers the settings.
|
||||
*
|
||||
* @author Stefan Herndler
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public function initializeSettings() {
|
||||
MCI_Footnotes_Settings::instance()->RegisterSettings();
|
||||
// iterate though each sub class of the layout engine and register their sections
|
||||
/** @var MCI_Footnotes_LayoutEngine $l_obj_LayoutEngineSubClass */
|
||||
foreach($this->a_arr_SubPageClasses as $l_obj_LayoutEngineSubClass) {
|
||||
$l_obj_LayoutEngineSubClass->registerSections();
|
||||
public function initialize_settings() {
|
||||
MCI_Footnotes_Settings::instance()->register_settings();
|
||||
// iterate though each sub class of the layout engine and register their sections.
|
||||
foreach ( $this->a_arr_sub_page_classes as $l_obj_layout_engine_sub_class ) {
|
||||
$l_obj_layout_engine_sub_class->register_sections();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,123 +78,123 @@ class MCI_Footnotes_Layout_Init {
|
|||
* Registers the new main menu for the WordPress dashboard.
|
||||
* Registers all sub menu pages for the new main menu.
|
||||
*
|
||||
* @author Stefan Herndler
|
||||
* @since 1.5.0
|
||||
* @see http://codex.wordpress.org/Function_Reference/add_menu_page
|
||||
*/
|
||||
public function registerMainMenu() {
|
||||
public function register_main_menu() {
|
||||
global $menu;
|
||||
// iterate through each main menu
|
||||
foreach($menu as $l_arr_MainMenu) {
|
||||
// iterate through each main menu attribute
|
||||
foreach($l_arr_MainMenu as $l_str_Attribute) {
|
||||
// main menu already added, append sub pages and stop
|
||||
if ($l_str_Attribute == self::C_STR_MAIN_MENU_SLUG) {
|
||||
$this->registerSubPages();
|
||||
// iterate through each main menu.
|
||||
foreach ( $menu as $l_arr_main_menu ) {
|
||||
// iterate through each main menu attribute.
|
||||
foreach ( $l_arr_main_menu as $l_str_attribute ) {
|
||||
// main menu already added, append sub pages and stop.
|
||||
if ( self::C_STR_MAIN_MENU_SLUG === $l_str_attribute ) {
|
||||
$this->register_sub_pages();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add a new main menu page to the WordPress dashboard
|
||||
// add a new main menu page to the WordPress dashboard.
|
||||
add_menu_page(
|
||||
self::C_STR_MAIN_MENU_TITLE, // page title
|
||||
self::C_STR_MAIN_MENU_TITLE, // menu title
|
||||
'manage_options', // capability
|
||||
self::C_STR_MAIN_MENU_SLUG, // menu slug
|
||||
array($this, "displayOtherPlugins"), // function
|
||||
plugins_url('footnotes/img/main-menu.png'), // icon url
|
||||
null // position
|
||||
self::C_STR_MAIN_MENU_TITLE, // page title.
|
||||
self::C_STR_MAIN_MENU_TITLE, // menu title.
|
||||
'manage_options', // capability.
|
||||
self::C_STR_MAIN_MENU_SLUG, // menu slug.
|
||||
array( $this, 'display_other_plugins' ), // function.
|
||||
plugins_url( 'footnotes/img/main-menu.png' ), // icon url.
|
||||
null // position.
|
||||
);
|
||||
$this->registerSubPages();
|
||||
$this->register_sub_pages();
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers all SubPages for this Plugin.
|
||||
*
|
||||
* @author Stefan Herndler
|
||||
* @since 1.5.0
|
||||
*/
|
||||
private function registerSubPages() {
|
||||
// first registered sub menu page MUST NOT contain a unique slug suffix
|
||||
// iterate though each sub class of the layout engine and register their sub page
|
||||
/** @var MCI_Footnotes_LayoutEngine $l_obj_LayoutEngineSubClass */
|
||||
foreach($this->a_arr_SubPageClasses as $l_obj_LayoutEngineSubClass) {
|
||||
$l_obj_LayoutEngineSubClass->registerSubPage();
|
||||
private function register_sub_pages() {
|
||||
// first registered sub menu page MUST NOT contain a unique slug suffix.
|
||||
// iterate though each sub class of the layout engine and register their sub page.
|
||||
foreach ( $this->a_arr_sub_page_classes as $l_obj_layout_engine_sub_class ) {
|
||||
$l_obj_layout_engine_sub_class->register_sub_page();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays other Plugins from the developers.
|
||||
*
|
||||
* @author Stefan Herndler
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public function displayOtherPlugins() {
|
||||
printf("<br/><br/>");
|
||||
// load template file
|
||||
$l_obj_Template = new MCI_Footnotes_Template(MCI_Footnotes_Template::C_STR_DASHBOARD, "manfisher");
|
||||
echo $l_obj_Template->getContent();
|
||||
public function display_other_plugins() {
|
||||
printf( '<br/><br/>' );
|
||||
// load template file.
|
||||
$l_obj_template = new MCI_Footnotes_Template( MCI_Footnotes_Template::C_STR_DASHBOARD, 'manfisher' );
|
||||
echo wp_kses_post( $l_obj_template->get_content() );
|
||||
|
||||
printf('<em>visit <a href="https://cheret.de/plugins/footnotes-2/" target="_blank">Mark Cheret</a></em>');
|
||||
printf("<br/><br/>");
|
||||
printf( '<em>visit <a href="https://cheret.de/plugins/footnotes-2/" target="_blank">Mark Cheret</a></em>' );
|
||||
printf( '<br/><br/>' );
|
||||
|
||||
printf('</div>');
|
||||
printf( '</div>' );
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX call. returns a JSON string containing meta information about a specific WordPress Plugin.
|
||||
*
|
||||
* @author Stefan Herndler
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public function getPluginMetaInformation() {
|
||||
// get plugin internal name from POST data
|
||||
$l_str_PluginName = array_key_exists("plugin", $_POST) ? $_POST["plugin"] : null;
|
||||
if (empty($l_str_PluginName)) {
|
||||
echo json_encode(array("error" => "Plugin name invalid."));
|
||||
public function get_plugin_meta_information() {
|
||||
// TODO: add nonce verification.
|
||||
|
||||
// get plugin internal name from POST data.
|
||||
if ( isset( $_POST['plugin'] ) && 'true' === $_POST['plugin'] ) {
|
||||
$l_str_plugin_name = santitize_option( wp_unslash( $_POST['plugin'] ) );
|
||||
}
|
||||
|
||||
if ( empty( $l_str_plugin_name ) ) {
|
||||
echo wp_json_encode( array( 'error' => 'Plugin name invalid.' ) );
|
||||
exit;
|
||||
}
|
||||
$l_str_Url = "https://api.wordpress.org/plugins/info/1.0/".$l_str_PluginName.".json";
|
||||
// call URL and collect data
|
||||
$l_arr_Response = wp_remote_get($l_str_Url);
|
||||
// check if response is valid
|
||||
if (is_wp_error($l_arr_Response)) {
|
||||
echo json_encode(array("error" => "Error receiving Plugin Information from WordPress."));
|
||||
$l_str_url = 'https://api.wordpress.org/plugins/info/1.0/' . $l_str_plugin_name . '.json';
|
||||
// call URL and collect data.
|
||||
$l_arr_response = wp_remote_get( $l_str_url );
|
||||
// check if response is valid.
|
||||
if ( is_wp_error( $l_arr_response ) ) {
|
||||
echo wp_json_encode( array( 'error' => 'Error receiving Plugin Information from WordPress.' ) );
|
||||
exit;
|
||||
}
|
||||
if (!array_key_exists("body", $l_arr_Response)) {
|
||||
echo json_encode(array("error" => "Error reading WordPress API response message."));
|
||||
if ( ! array_key_exists( 'body', $l_arr_response ) ) {
|
||||
echo wp_json_encode( array( 'error' => 'Error reading WordPress API response message.' ) );
|
||||
exit;
|
||||
}
|
||||
// get the body of the response
|
||||
$l_str_Response = $l_arr_Response["body"];
|
||||
// get plugin object
|
||||
$l_arr_Plugin = json_decode($l_str_Response, true);
|
||||
if (empty($l_arr_Plugin)) {
|
||||
echo json_encode(array("error" => "Error reading Plugin meta information.<br/>URL: " . $l_str_Url . "<br/>Response: " . $l_str_Response));
|
||||
// get the body of the response.
|
||||
$l_str_response = $l_arr_response['body'];
|
||||
// get plugin object.
|
||||
$l_arr_plugin = json_decode( $l_str_response, true );
|
||||
if ( empty( $l_arr_plugin ) ) {
|
||||
echo wp_json_encode( array( 'error' => 'Error reading Plugin meta information.<br/>URL: ' . $l_str_url . '<br/>Response: ' . $l_str_response ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
$l_int_NumRatings = array_key_exists("num_ratings", $l_arr_Plugin) ? intval($l_arr_Plugin["num_ratings"]) : 0;
|
||||
$l_int_Rating = array_key_exists("rating", $l_arr_Plugin) ? floatval($l_arr_Plugin["rating"]) : 0.0;
|
||||
$l_int_Stars = round(5 * $l_int_Rating / 100.0, 1);
|
||||
$l_int_num_ratings = array_key_exists( 'num_ratings', $l_arr_plugin ) ? intval( $l_arr_plugin['num_ratings'] ) : 0;
|
||||
$l_int_rating = array_key_exists( 'rating', $l_arr_plugin ) ? floatval( $l_arr_plugin['rating'] ) : 0.0;
|
||||
$l_int_stars = round( 5 * $l_int_rating / 100.0, 1 );
|
||||
|
||||
// return Plugin information as JSON encoded string
|
||||
echo json_encode(
|
||||
// return Plugin information as JSON encoded string.
|
||||
echo wp_json_encode(
|
||||
array(
|
||||
"error" => "",
|
||||
"PluginDescription" => array_key_exists("short_description", $l_arr_Plugin) ? html_entity_decode($l_arr_Plugin["short_description"]) : "Error reading Plugin information",
|
||||
"PluginAuthor" => array_key_exists("author", $l_arr_Plugin) ? html_entity_decode($l_arr_Plugin["author"]) : "unknown",
|
||||
"PluginRatingText" => $l_int_Stars . " " . __("rating based on", MCI_Footnotes_Config::C_STR_PLUGIN_NAME) . " " . $l_int_NumRatings . " " . __("ratings", MCI_Footnotes_Config::C_STR_PLUGIN_NAME),
|
||||
"PluginRating1" => $l_int_Stars >= 0.5 ? "star-full" : "star-empty",
|
||||
"PluginRating2" => $l_int_Stars >= 1.5 ? "star-full" : "star-empty",
|
||||
"PluginRating3" => $l_int_Stars >= 2.5 ? "star-full" : "star-empty",
|
||||
"PluginRating4" => $l_int_Stars >= 3.5 ? "star-full" : "star-empty",
|
||||
"PluginRating5" => $l_int_Stars >= 4.5 ? "star-full" : "star-empty",
|
||||
"PluginRating" => $l_int_NumRatings,
|
||||
"PluginLastUpdated" => array_key_exists("last_updated", $l_arr_Plugin) ? $l_arr_Plugin["last_updated"] : "unknown",
|
||||
"PluginDownloads" => array_key_exists("downloaded", $l_arr_Plugin) ? $l_arr_Plugin["downloaded"] : "---"
|
||||
'error' => '',
|
||||
'PluginDescription' => array_key_exists( 'short_description', $l_arr_plugin ) ? html_entity_decode( $l_arr_plugin['short_description'] ) : 'Error reading Plugin information',
|
||||
'PluginAuthor' => array_key_exists( 'author', $l_arr_plugin ) ? html_entity_decode( $l_arr_plugin['author'] ) : 'unknown',
|
||||
'PluginRatingText' => $l_int_stars . ' ' . __( 'rating based on', 'footnotes' ) . ' ' . $l_int_num_ratings . ' ' . __( 'ratings', 'footnotes' ),
|
||||
'PluginRating1' => $l_int_stars >= 0.5 ? 'star-full' : 'star-empty',
|
||||
'PluginRating2' => $l_int_stars >= 1.5 ? 'star-full' : 'star-empty',
|
||||
'PluginRating3' => $l_int_stars >= 2.5 ? 'star-full' : 'star-empty',
|
||||
'PluginRating4' => $l_int_stars >= 3.5 ? 'star-full' : 'star-empty',
|
||||
'PluginRating5' => $l_int_stars >= 4.5 ? 'star-full' : 'star-empty',
|
||||
'PluginRating' => $l_int_num_ratings,
|
||||
'PluginLastUpdated' => array_key_exists( 'last_updated', $l_arr_plugin ) ? $l_arr_plugin['last_updated'] : 'unknown',
|
||||
'PluginDownloads' => array_key_exists( 'downloaded', $l_arr_plugin ) ? $l_arr_plugin['downloaded'] : '---',
|
||||
)
|
||||
);
|
||||
exit;
|
||||
|
|
Reference in a new issue