JFIF $ d d 7 * Z qn )ZP 0 !1 A "#a$2Qr D8 a Ri [f \m I ykI w0 c u F c Rı?lO7 к _f˓ [C $殷WF< _W ԣ s Kc ëI zyQy /_LK ℂ ;C",p F A : /] =H ~ , l s / 9 ć: [=/#f ; ) x { ٛE Q )~ = 𘙲r*2~ a _V = ' ku m F D } KYYC )( { * g& f `툪 r y ` = ^ c J. I ]( * `wq 1dđ #̩ ͑ 0 ; H ] u 搂 @:~ ו K L N s h } O I R* 8 :2 ! lD JV o ( 3 = M ( z Ȱ+i *N A r6K n S l ) ! J J Ӂ* % ݉?|D } d5: eP0 R; {$X' x F @ .ÊB {,WJ uQ ɲRI ;9 Q E琯 6 2fT .DU J ;*c P A\IL Nj! J ۱+ O\ ͔ ] ޒ S J ȧ c%A N ol ՎprU L Zԛe r E2= X D Xg VQeӓ k y P7 U* o m Q I s ,K `) 6\G3t?pgjr m ۛجw luGt f h 9uyP 0D;Uڽ"OXl i f $ ) &|ML 0 Z rm1 [ H XP l P R0 'G=i 2N +0 e 2 ]] 9 VT P O 7 h(F * 癈 ' = Q VZD F,d ߬ ~ T X G[ `le 69C R(!S2! P < 0 x < !1AQ "Raq 02Br #S CTb ? Ζ "]mH5WR 7 k.ۛ ! } Q~ + yԏ z |@ T20 S~ K e k *zF f^2X *( @ 8 r ? C I uI|֓>^Ex LgNU Y+{.R Ѫ τV YT D I 6 2 '8Y2 7'\T P.6 d &˦ @V q i |8 -O Ε ] ʔ U= T L 8= ;6c | !qfF3 a ů& ~$ l} 'NW U s$U k^S V : U#6w + +s &r+n ڐ { @ 29gL u " T Ù M=6 (^ "7 r}=6Yݾ lC u hquymp Ǧ G jhs ǜNl ɻ} o 7 #S6 a w 4 ! OS r D 5 7 % | ?x> L | / nD 6?/8 w # [ ) L 7 +6〼T A T g ! %5 Mm Z /c -{1_Je "| ^$ 'O & ޱմ < H vNqϡQ$ < 6 &Nݛ ֨tǻN (9 n ru~'όN sMG& ,uH Kw *Ī 5@ u6 BԒ i YN * f 0 _ GhKW u lT <nj- 0{ M L~ | /a v\ E = ?1 \ɟuq Ђ Y O a K ޡP q $ H8o Q˼EV ~ k 0 h' L Pp M -M" m^ !6l nմ 쮝C U T . ! :vMǨb h ډ Vc r @~p # !1QAa q ? AL0L x LU 4 d ; x " 16ad0 7.\ߋ 0 = P l v/ " c A Ay A|2pO8"d MV #1] = \ " ˡ ] k v I9 d ۓ & q ) ǐq E ꞅ v "P )q X &Q З non]я u ג./ ; gZ$ M QР 2M ]h ni 0 P $ێ 3CɏGjώy : m c # S_ l@ '_ \m|C 2`K _ 1 cIvGc $? PCQ S+D ? K aײ k Fr b 8 ύ NEدg ĝ U 3 6 #Ik+ v { v i ( ވ ? a e) X xy/*@Q Ǽ Ծ ) $ IWO l c G; !i k{ gOŀ L ('x T rb $ w) R $ & N1E td U3Uȉ1p M"N* (DNy d96.(jQ) X 5 c QɎMy W ? Q *!R > 6=7)Xj 5`J ] e 8%t ! + ' ! 1Q 5 !1 AQaq ё #2 "0BRb ? G t^ ## .l lQ T $ v , ,m 㵜5u bV =sY+ @d { N ! dn O < .- B; _w J t 6;Q Jd. Q c%p{ 1 ,sND dF H I0 Гo X ш e黅X ۢ F :)[ F G X ƹ / w _c MeD ,ʡc c . W D tA $ j@ : ) - #u c1< @ۗ9F ) KJ- hpP] _ x [ q B lb p ʖ w q " LFGd ƶ * s +ډ_Zc " ? % t[I P 6 J ]# =ɺ V v v CGs Gh1 > )6 |e y ? L ӣ m,4 G W Ui ` ] uJVo VDG< SB 6ϏQ @ TiU l y O U 0 kfV ~ ~}S Z @ *WU Ui ## ; s /[ = ! 7}" W N ] ' (L ! ~ y5 g9T̅J kbM' +s :S +B) v @ M j e C f j E 0 Y\Qn z G 1 д~ W o{T 9?` Rm yhsy3 !HAD ] m c1 ~ 2 L S u7x T ;j$ `} 4-> L# vzŏ I L S ֭ T { r jGK C ; b pU= - ` Bs K. S F w4 M q] Z dH S 0 ) tLg
<?php
namespace Code_Snippets;
use Code_Snippets\Admin\Bootstrap_Admin;
use Code_Snippets\Controller\Cloud_Search_Controller;
use Code_Snippets\Core\DB;
use Code_Snippets\Core\Licensing;
use Code_Snippets\Core\Upgrader;
use Code_Snippets\Integration\Admin_Bar;
use Code_Snippets\Integration\Classic_Editor\MCE_Plugin;
use Code_Snippets\Integration\Evaluate_Content;
use Code_Snippets\Integration\Evaluate_Functions;
use Code_Snippets\Integration\Promotions\Promotion_Manager;
use Code_Snippets\Integration\Shortcodes;
use Code_Snippets\Model\Basic_Cloud_Connection;
use Code_Snippets\REST_API\Cloud\Cloud_Snippets_REST_Controller;
use Code_Snippets\REST_API\Import\File_Import_REST_Controller;
use Code_Snippets\REST_API\Import\Plugins_Import_REST_Controller;
use Code_Snippets\REST_API\Snippets\Preferences_REST_Controller;
use Code_Snippets\REST_API\Snippets\Recently_Active_REST_Controller;
use Code_Snippets\REST_API\Snippets\Snippets_REST_Controller;
use function Code_Snippets\Settings\are_settings_unified;
/**
* The main plugin class
*
* @package Code_Snippets
*/
class Plugin {
/**
* Current plugin version number
*
* @deprecated Use the PLUGIN_VERSION constant instead.
*
* @var string
*/
public string $version = PLUGIN_VERSION;
/**
* Filesystem path to the main plugin file
*
* @deprecated Use the PLUGIN_FILE constant instead.
*
* @var string
*/
public string $file = PLUGIN_FILE;
/**
* Database class
*
* @var DB
*/
public DB $db;
/**
* Class for managing shortcodes.
*
* @var Shortcodes
*/
public Shortcodes $shortcodes;
/**
* Administration area class
*
* @var Bootstrap_Admin
*/
public Bootstrap_Admin $admin;
/**
* Handles licensing and plugin updates.
*
* @var Licensing
*/
public Licensing $licensing;
/**
* Handles snippet handler registration.
*
* @var Flat_Files\Handler_Registry
*/
public Flat_Files\Handler_Registry $snippet_handler_registry;
/**
* Instance of connection to Code Snippets Cloud.
*
* @var Basic_Cloud_Connection
*/
public Basic_Cloud_Connection $cloud_connection;
/**
* Class constructor
*/
public function __construct() {
wp_cache_add_global_groups( CACHE_GROUP );
add_action( 'allowed_redirect_hosts', [ $this, 'allow_code_snippets_redirect' ] );
}
/**
* Load the plugin utilities.
*/
private function load_utilities() {
require_once __DIR__ . '/Utils/editor.php';
require_once __DIR__ . '/Utils/options.php';
require_once __DIR__ . '/Settings/settings.php';
require_once __DIR__ . '/snippet-ops.php';
}
/**
* Initialise the plugin and load all necessary classes.
*/
public function load_plugin() {
$this->load_utilities();
$this->db = new DB();
$this->licensing = new Licensing();
$this->cloud_connection = new Basic_Cloud_Connection();
new Evaluate_Content( $this->db );
new Evaluate_Functions( $this->db );
$this->shortcodes = new Shortcodes();
if ( is_admin() ) {
$this->admin = new Bootstrap_Admin();
new Promotion_Manager();
}
new Shortcodes();
new MCE_Plugin();
new Upgrader( PLUGIN_VERSION, $this->db );
new Admin_Bar();
if ( is_admin() ) {
new Promotion_Manager();
}
$this->init_snippet_files();
add_action( 'rest_api_init', [ $this, 'init_rest_api' ], 1 );
}
/**
* Load REST API controller classes when serving REST API requests.
*
* @return void
*/
public function init_rest_api() {
$cloud_search = new Cloud_Search_Controller( $this->cloud_connection );
new Snippets_REST_Controller();
new Recently_Active_REST_Controller();
new Preferences_REST_Controller();
new Plugins_Import_REST_Controller();
new File_Import_REST_Controller();
new Cloud_Snippets_REST_Controller( $cloud_search );
}
/**
* Initialises the snippet files component.
*
* @return void
*/
private function init_snippet_files() {
$this->snippet_handler_registry = new Flat_Files\Handler_Registry(
[
'php' => new Flat_Files\Handlers\Functions_Snippet_Handler(),
'html' => new Flat_Files\Handlers\Content_Snippet_Handler(),
]
);
$fs = new Flat_Files\WP_Filesystem_Adapter();
$config_repo = new Flat_Files\Flat_File_Config_Repository( $fs );
$snippet_files = new Flat_Files\Snippet_Files( $this->snippet_handler_registry, $fs, $config_repo );
$snippet_files->register_hooks();
}
/**
* Determine whether the menu is full or compact.
*
* @return bool
*/
public function is_compact_menu(): bool {
return ! is_network_admin() && apply_filters( 'code_snippets_compact_menu', false );
}
/**
* Fetch the admin menu slug for a menu.
*
* @param string $menu Name of menu to retrieve the slug for.
*
* @return string The menu's slug.
*/
public function get_menu_slug( string $menu = '' ): string {
$add = [ 'single', 'add', 'add-new', 'add-snippet', 'new-snippet', 'add-new-snippet' ];
$edit = [ 'edit', 'edit-snippet' ];
$import = [ 'import', 'import-snippets', 'import-code-snippets' ];
$settings = [ 'settings', 'snippets-settings' ];
$cloud = [ 'cloud', 'cloud-snippets' ];
$welcome = [ 'welcome', 'getting-started', 'code-snippets' ];
if ( in_array( $menu, $edit, true ) ) {
return 'edit-snippet';
} elseif ( in_array( $menu, $add, true ) ) {
return 'add-snippet';
} elseif ( in_array( $menu, $import, true ) ) {
return 'import-code-snippets';
} elseif ( in_array( $menu, $settings, true ) ) {
return 'snippets-settings';
} elseif ( in_array( $menu, $cloud, true ) ) {
return 'snippets&subpage=cloud-community';
} elseif ( in_array( $menu, $welcome, true ) ) {
return 'code-snippets-welcome';
} else {
return 'snippets';
}
}
/**
* Fetch the URL to a snippets admin menu.
*
* @param string $menu Name of menu to retrieve the URL to.
* @param string $context URL scheme to use.
*
* @return string The menu's URL.
*/
public function get_menu_url( string $menu = '', string $context = 'self' ): string {
$slug = $this->get_menu_slug( $menu );
if ( $this->is_compact_menu() && 'network' !== $context ) {
$base_slug = $this->get_menu_slug();
$url = 'tools.php?page=' . $base_slug;
if ( $slug !== $base_slug ) {
$url .= '&sub=' . $slug;
}
} else {
$url = 'admin.php?page=' . $slug;
}
if ( 'snippets-settings' === $slug && are_settings_unified() ) {
return network_admin_url( $url );
}
switch ( $context ) {
case 'network':
return network_admin_url( $url );
case 'admin':
return admin_url( $url );
default:
return self_admin_url( $url );
}
}
/**
* Allow redirecting to the Code Snippets site.
*
* @param string[] $hosts Allowed hosts.
*
* @return array Modified allowed hosts.
*/
public function allow_code_snippets_redirect( array $hosts ): array {
$hosts[] = 'codesnippets.pro';
$hosts[] = 'snipco.de';
return $hosts;
}
/**
* Determine whether the current user can perform actions on snippets.
*
* @return bool Whether the current user has the required capability.
*
* @since 2.8.6
*/
public function current_user_can(): bool {
return current_user_can( $this->get_cap() );
}
/**
* Retrieve the name of the capability required to manage sub-site snippets.
*
* @return string
*/
public function get_cap_name(): string {
return apply_filters( 'code_snippets_cap', 'manage_options' );
}
/**
* Retrieve the name of the capability required to manage network snippets.
*
* @return string
*/
public function get_network_cap_name(): string {
return apply_filters( 'code_snippets_network_cap', 'manage_network_options' );
}
/**
* Determine if a subsite user menu is enabled via *Network Settings > Enable administration menus*.
*
* @return bool
*/
public function is_subsite_menu_enabled(): bool {
if ( ! is_multisite() ) {
return true;
}
$menu_perms = get_site_option( 'menu_items', array() );
return ! empty( $menu_perms['snippets'] );
}
/**
* Determine if the current user should have the network snippets capability.
*
* @return bool
*/
public function user_can_manage_network_snippets(): bool {
return is_super_admin() || current_user_can( $this->get_network_cap_name() );
}
/**
* Get the required capability to perform a certain action on snippets.
* Does not check if the user has this capability or not.
*
* If multisite, adjusts the capability based on whether the user is viewing
* the network dashboard or a subsite and whether the menu is enabled for subsites.
*
* @return string The capability required to manage snippets.
*
* @since 2.0
*/
public function get_cap(): string {
return is_multisite() && ( is_network_admin() || ! $this->is_subsite_menu_enabled() )
? $this->get_network_cap_name()
: $this->get_cap_name();
}
/**
* Localise a plugin script to provide the CODE_SNIPPETS object.
*
* @param string $handle Script handle.
*
* @return void
*/
public function localize_script( string $handle ) {
wp_localize_script(
$handle,
'CODE_SNIPPETS',
[
'debug' => defined( 'WP_DEBUG' ) && WP_DEBUG,
'isLicensed' => $this->licensing->is_licensed(),
'isCloudConnected' => $this->cloud_connection->is_authenticated(),
'hideUpsell' => Settings\get_setting( 'general', 'hide_upgrade_menu' ),
'snippetView' => Preferences_REST_Controller::get_snippet_view(),
'restAPI' => [
'base' => esc_url_raw( rest_url() ),
'snippets' => esc_url_raw( rest_url( Snippets_REST_Controller::get_base_route() ) ),
'recentlyActive' => esc_url_raw( rest_url( Recently_Active_REST_Controller::get_base_route() ) ),
'preferences' => esc_url_raw( rest_url( Preferences_REST_Controller::get_base_route() ) ),
'importPlugins' => esc_url_raw( rest_url( Plugins_Import_REST_Controller::get_base_route() ) ),
'importFiles' => esc_url_raw( rest_url( File_Import_REST_Controller::get_base_route() ) ),
'nonce' => wp_create_nonce( 'wp_rest' ),
'cloud' => [
'token' => $this->cloud_connection->get_local_token(),
'snippets' => esc_url_raw( rest_url( Cloud_Snippets_REST_Controller::get_base_route() ) ),
],
],
'urls' => [
'plugin' => esc_url_raw( plugins_url( '', PLUGIN_FILE ) ),
'manage' => esc_url_raw( $this->get_menu_url() ),
'edit' => esc_url_raw( $this->get_menu_url( 'edit' ) ),
'addNew' => esc_url_raw( $this->get_menu_url( 'add' ) ),
'welcome' => esc_url_raw( $this->get_menu_url( 'welcome' ) ),
'import' => esc_url_raw( $this->get_menu_url( 'import' ) ),
'cloud' => esc_url_raw( $this->cloud_connection->get_base_url() ),
'settings' => ! are_settings_unified() || is_super_admin()
? esc_url_raw( $this->get_menu_url( 'settings' ) )
: null,
],
]
);
}
}