commit 9387d15c4b2d49de9d2c1a9cee6271b13b58ccc8 Author: dcooperdalrymple Date: Fri Sep 6 16:21:20 2024 -0500 Initial commit. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..174b54b --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +*.js +*.map +*.css +ogre-issuu.zip +/ogre-issuu +composer.phar +/vendor/ +/lib/* +/node_modules/ diff --git a/.vscode/ftp-sync.json b/.vscode/ftp-sync.json new file mode 100644 index 0000000..020e84f --- /dev/null +++ b/.vscode/ftp-sync.json @@ -0,0 +1,32 @@ +{ + "remotePath": "./public_html/wp-content/plugins/ogre-issuu/", + "host": "og5.cleverogre.com", + "username": "summatio", + "password": "TV0#h0)T622}T", + "port": 22, + "secure": true, + "protocol": "sftp", + "uploadOnSave": true, + "passive": false, + "debug": false, + "privateKeyPath": null, + "passphrase": null, + "agent": null, + "allow": [], + "ignore": [ + "\\.vscode", + "\\.git", + "\\.DS_Store", + "\\.gitignore", + "\\Makefile", + "\\ogre-issuu.zip" + ], + "generatedFiles": { + "extensionsToInclude": [ + ".js", + ".css", + ".map" + ], + "path": "" + } +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..25773a2 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "java.project.sourcePaths": [ + "" + ] +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..d0a0ae4 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,25 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Package", + "type": "shell", + "command": "make", + "group": "build", + "presentation": { + "reveal": "silent", + "panel": "shared", + } + }, + { + "label": "Compile", + "type": "shell", + "command": "make compile", + "group": "build", + "presentation": { + "reveal": "silent", + "panel": "shared", + } + } + ] +} diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..afb8e1d --- /dev/null +++ b/Makefile @@ -0,0 +1,38 @@ +PACKAGE = ogre-issuu + +COMPOSER = composer + +all: $(PACKAGE).zip + +$(PACKAGE).zip: clean composer dir copy zip + +composer: + $(COMPOSER) update + +dir: + mkdir ./$(PACKAGE) + +copy: + cp -RT ./assets ./$(PACKAGE)/assets + cp -RT ./includes ./$(PACKAGE)/includes + cp -RT ./lang ./$(PACKAGE)/lang + cp -RT ./lib ./$(PACKAGE)/lib + cp -RT ./vendor ./$(PACKAGE)/vendor + cp -f ./* ./$(PACKAGE) || true + + rm ./$(PACKAGE)/composer.json + rm ./$(PACKAGE)/composer.lock + rm ./$(PACKAGE)/Makefile + rm ./$(PACKAGE)/phpcs.xml + rm ./$(PACKAGE)/$(PACKAGE).zip || true + +zip: + zip -r ./$(PACKAGE).zip ./$(PACKAGE) + rm -r ./$(PACKAGE) || true + +clean: + rm -r ./$(PACKAGE) || true + rm ./$(PACKAGE).zip || true + for file in $(SASS_SCSS) ; do \ + rm ./assets/css/$${file}.css || true ; \ + done diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..7759a1e --- /dev/null +++ b/composer.json @@ -0,0 +1,27 @@ +{ + "name": "cleverogre/ogreissuu", + "description": "WordPress integration with Issuu API v2.", + "repositories": [ + { + "type": "composer", + "url": "https://wpackagist.org", + "only": [ + "wpackagist-plugin/*", + "wpackagist-theme/*" + ] + } + ], + "require": { + "magicoli/wp-package-updater-lib": "^0.1.9" + }, + "config": { + "allow-plugins": { + "composer/installers": true + } + }, + "scripts": { + "post-update-cmd": [ + "php vendor/magicoli/wp-package-updater-lib/install.php" + ] + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..22f5f5c --- /dev/null +++ b/composer.lock @@ -0,0 +1,53 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "0aa90b123730bd76a4343609105f8be7", + "packages": [ + { + "name": "magicoli/wp-package-updater-lib", + "version": "v0.1.10", + "source": { + "type": "git", + "url": "https://github.com/magicoli/wp-package-updater-lib.git", + "reference": "e822132741c08d054fb97f249b1143c220f30e6f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/magicoli/wp-package-updater-lib/zipball/e822132741c08d054fb97f249b1143c220f30e6f", + "reference": "e822132741c08d054fb97f249b1143c220f30e6f", + "shasum": "" + }, + "require-dev": { + "froger-me/wp-plugin-update-server": "*" + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "AGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Magiiic" + } + ], + "description": "Composer package for wp-package-updater library.", + "support": { + "issues": "https://github.com/magicoli/wp-package-updater-lib/issues", + "source": "https://github.com/magicoli/wp-package-updater-lib/tree/v0.1.10" + }, + "time": "2023-06-09T12:42:28+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [], + "plugin-api-version": "2.6.0" +} diff --git a/includes/abstract-plugin-base.php b/includes/abstract-plugin-base.php new file mode 100644 index 0000000..4f2ce61 --- /dev/null +++ b/includes/abstract-plugin-base.php @@ -0,0 +1,239 @@ +file = $file; + $this->requirements = []; + $this->files = []; + $this->plugin_data = []; + + // Load composer packages + $this->setup_composer(); + + // Setup Plugin Updates + $this->setup_updater(); + + // Set Text Domain + load_plugin_textdomain($this->get_textdomain(), false, plugin_basename(dirname($this->file)) . '/lang'); + + // Requirements Check + add_action('plugins_loaded', [$this, 'check_requirements'], 1, 0); + + $this->enable(); + } + + // Plugin Initialization + + protected function enable() { + add_action('plugins_loaded', [$this, 'load'], 10, 0); + add_filter('acf/settings/load_json', [$this, 'register_acf_json'], 10, 1); + } + protected function disable() { + remove_action('plugins_loaded', [$this, 'load'], 10, 0); + remove_filter('acf/settings/load_json', [$this, 'register_acf_json'], 10, 1); + } + + public function load() { + $this->load_files(); + } + + public function register_acf_json(array $paths):array { + $path = $this->get_path() . 'acf-json'; + if (!in_array($path, $paths)) $paths[] = $path; + return $paths; + } + + // Setup + + protected function setup_composer() { + require_once($this->get_path() . 'vendor/autoload.php'); + } + + protected function setup_updater() { + global $wppul_plugin_file, $wppul_server, $wppul_license_required; + $wppul_plugin_file = $this->get_file(); + $wppul_server = 'https://plugins.cleverogre.com'; + $wppul_license_required = false; + if (!class_exists('Puc_v4_Factory')) require_once($this->get_path() . 'lib/wp-package-updater-lib/plugin-update-checker/plugin-update-checker.php'); + require_once($this->get_path() . 'lib/wp-package-updater-lib/package-updater.php'); + } + + // Requirements + + protected function add_requirement(string $key, array $data) { + $this->requirements[$key] = wp_parse_args($data, [ + 'name' => '', + 'url' => '', + 'type' => self::REQUIREMENT_NONE, + 'plugin' => '', + 'class' => '', + ]); + } + + public function check_requirements() { + $invalid = false; + foreach ($this->requirements as $key => $data) { + if ($data['type'] & self::REQUIREMENT_NONE) continue; + if ($data['type'] & self::REQUIREMENT_PLUGIN && !empty($data['plugin']) && function_exists('is_plugin_active') && is_plugin_active($data['plugin'])) continue; + if ($data['type'] & self::REQUIREMENT_CLASS && !empty($data['class']) && class_exists($data['class'])) continue; + + $this->add_requirement_notice($data); + $invalid = true; + } + + if (!!$invalid) $this->disable(); + } + + protected function add_requirement_notice($data) { + add_action('admin_notices', function () use ($data) { + $message = sprintf( + __('In order to use the %1$s plugin, it is required that you install and activate the %3$s plugin. You can do this on the plugins page when logged in as an administrator. To download this plugin, visit the %3$s website.', $this->get_textdomain()), + $this->get_title(), + esc_url(admin_url('plugins.php')), + esc_html($data['name']), + esc_url($data['url']) + ); + printf('

%s

', esc_attr('notice notice-error'), wpautop(wp_kses_post($message))); + }); + } + + // Plugin Files + + protected function add_file(string $relpath):bool { + if (!is_string($relpath) || empty($relpath)) return false; + $this->files[] = $relpath; + return true; + } + protected function add_files(array $relpaths):bool { + $valid = true; + foreach ($relpaths as $relpath) { + if (!$this->add_file($relpath)) $valid = false; + } + return $valid; + } + + protected function load_files():bool { + if (empty($this->files)) return false; + $valid = true; + foreach ($this->files as $relpath) { + $path = rtrim($this->get_path(), '/') . '/' . ltrim($relpath, '/'); + if (!file_exists($path)) $valid = false; + else include_once($path); + } + return $valid; + } + + // Plugin Data Accessors + + private function get_data(string $key):string { + if (!function_exists('get_plugin_data')) require_once(ABSPATH . 'wp-admin/includes/plugin.php'); + if (!is_array($this->plugin_data) || empty($this->plugin_data)) { + $this->plugin_data = get_plugin_data($this->file); + } + if (!array_key_exists($key, $this->plugin_data)) return ''; + return $this->plugin_data[$key]; + } + + public function get_textdomain():string { + return $this->get_data('TextDomain'); + } + + public function get_id():string { + return $this->get_textdomain(); + } + + public function get_version():string { + return $this->get_data('Version'); + } + + public function get_title():string { + return __($this->get_data('Name'), $this->get_textdomain()); + } + + public function get_description():string { + return __($this->get_data('Description'), $this->get_textdomain()); + } + + // Plugin File Path Calculations + + public function get_file():string { + return $this->file; + } + + public function get_path(string $file = ''):string { + if (empty($file)) $file = $this->file; + return trailingslashit(dirname($file)); + } + + public function get_dir(string $file = ''):string { + $dir = $this->get_path($file); + $count = 0; + + // Sanitize for Win32 installs + $dir = str_replace('\\', '/', $dir); + + // If file is in plugins folder + $wp_plugin_dir = str_replace('\\', '/', WP_PLUGIN_DIR); + $dir = str_replace($wp_plugin_dir, plugins_url(), $dir, $count); + + if ($count < 1) { + // If file is in wp-content folder + $wp_content_dir = str_replace('\\', '/', WP_CONTENT_DIR); + $dir = str_replace($wp_content_dir, content_url(), $dir, $count); + } + + if ($count < 1) { + // If file is in ??? folder + $wp_dir = str_replace('\\', '/', ABSPATH); + $dir = str_replace($wp_dir, site_url('/'), $dir); + } + + return $dir; + } + + public function get_hook(string $file = ''):string { + if (empty($file)) $file = $this->file; + return basename(dirname($file)) . '/' . basename($file); + } + + public function get_url(string $file = ''):string { + if (empty($file)) $file = $this->file; + return plugin_dir_url($file); + } + + // Static Translation Functions + + public static function __(string $text):string { + return __($text, self::instance()->get_textdomain()); + } + + public static function esc_html__(string $text):string { + return esc_html__($text, self::instance()->get_textdomain()); + } + + public static function esc_attr__(string $text):string { + return esc_attr__($text, self::instance()->get_textdomain()); + } + +} diff --git a/includes/class-settings.php b/includes/class-settings.php new file mode 100644 index 0000000..f8805e3 --- /dev/null +++ b/includes/class-settings.php @@ -0,0 +1,159 @@ +get_file()), [$this, 'plugin_action_links'], 10, 1); + } + + private function get_menu_slug():string { + return Plugin::instance()->get_id(); + } + + private function get_menu_title():string { + return Plugin::instance()->get_title(); + } + + private function get_page_title():string { + return sprintf( + Plugin::__('%s Settings'), + Plugin::instance()->get_title() + ); + } + + // Register settings page + public function admin_menu():void { + add_submenu_page( + self::PARENT_SLUG, + $this->get_page_title(), + $this->get_menu_title(), + self::CAPABILITY, + $this->get_menu_slug(), + [$this, 'render'] + ); + } + + // Register settings fields + + private function get_option_group():string { + return Plugin::instance()->get_id(); + } + + private function get_option_name():string { + return Plugin::instance()->get_id(); + } + + public function register_settings():void { + register_setting($this->get_option_group(), $this->get_option_name(), [ + 'type' => 'array', + 'label' => $this->get_page_title(), + 'sanitize_callback' => [$this, 'sanitize'], + 'default' => [ + 'client_id' => '', + 'client_secret' => '', + 'token' => '', + ], + ]); + + add_settings_section( + 'api', + Plugin::__('API Settings'), + function () { + printf( + '

%s

', + Plugin::__('See Issuu API documentation to learn how to generate an API client with your Issuu account.') + ); + }, + $this->get_menu_slug() + ); + + add_settings_field( + 'client_id', + Plugin::__('Client ID'), + [$this, 'the_field'], + $this->get_menu_slug(), + 'api' + ); + + add_settings_field( + 'client_secret', + Plugin::__('Client Secret'), + [$this, 'the_field'], + $this->get_menu_slug(), + 'api' + ); + + add_settings_field( + 'token', + Plugin::__('Token'), + [$this, 'the_field'], + $this->get_menu_slug(), + 'api' + ); + + } + + public function the_field(array $args):void { + printf( + '', + esc_attr($args['name']), + esc_attr($args['option_group']), + esc_attr($args['name']), + esc_attr($this->options[$args['name']] ?? '') + ); + if (isset($args['description']) && !empty($args['description'])) { + printf('

%s

', esc_html($args['description'])); + } + } + + // Output settings page + + public function render():void { + $this->options = get_option($this->get_option_group()); + echo '
'; + printf('

%s

', esc_html($this->get_page_title())); + echo '
'; + settings_fields($this->get_option_group()); + do_settings_sections($this->get_menu_slug()); + submit_button(); + echo '
'; + echo '
'; + } + + // Add plugin link + public function plugin_action_links(array $links):array { + array_unshift($links, sprintf( + '%s', + esc_url($this->get_url()), + Plugin::esc_html__('Settings') + )); + return $links; + } + + public function get_url():string { + return add_query_arg(array_filter([ + 'page' => $this->get_menu_slug(), + ]), admin_url(self::PARENT_SLUG)); + } + +} + +Settings::instance(); diff --git a/includes/index.php b/includes/index.php new file mode 100644 index 0000000..eea59b9 --- /dev/null +++ b/includes/index.php @@ -0,0 +1,2 @@ +add_files([ + 'includes/class-settings.php', + ]); + } + +} + +Plugin::instance(); diff --git a/package.json b/package.json new file mode 100644 index 0000000..2ee3643 --- /dev/null +++ b/package.json @@ -0,0 +1,12 @@ +{ + "name": "ogre-issuu", + "title": "OgreIssuu", + "version": "0.1.0", + "author": "CleverOgre", + "license": "GPL-3.0+", + "keywords": [], + "engines": { + "node": ">=6.9.4", + "npm": ">=1.1.0" + } +} diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..3130395 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,56 @@ + + + SomewhereWarm Coding Standards + + + tests/ + */node_modules/* + */assets/* + */src/* + */vendor/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + tests/ + + + + + + + + + + + + + + diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..152aa4c --- /dev/null +++ b/readme.txt @@ -0,0 +1,31 @@ +=== OgreIssuu === +Contributors: ogrecooper +Donate link: https://cleverogre.com/ +Tags: gravityforms, feed, jobs, resume, application +Requires at least: 6.0.0 +Tested up to: 6.4.3 +Stable tag: 0.1.0 +License: GPLv2 or later +License URI: https://www.gnu.org/licenses/gpl-2.0.html + +WordPress integration with Issuu API v2. + +== Description == + +TODO + +== Installation == + +1. Upload the plugin files to the `/wp-content/plugins/ogre-issuu` directory and ensure that it is active. +2. Activate the plugin through the 'Plugins' screen in WordPress. + +== FAQ == + += What is this plugin? = + +If you do know what plugin you have downloaded, please contact [CleverOgre](team@cleverogre.com) for more information. This plugin is only developed for a small, private audience. + +== Changelog == + += 0.1.0 - 2024-09-06 = +* Initial build of OgreIssuu plugin.