PluginProbe
Premmerce / 1.3.12
Premmerce v1.3.12
trunk 1.0 1.1 1.2 1.2.1 1.3 1.3.10 1.3.11 1.3.12 1.3.13 1.3.14 1.3.15 1.3.16 1.3.17 1.3.18 1.3.19 1.3.2 1.3.20 1.3.21 1.3.22 1.3.23 1.3.3 1.3.4 1.3.5 1.3.6 All 28 releases
premmerce / src / Admin / Admin.php

Admin.php in Premmerce 1.3.12, at src/Admin/Admin.php

167 lines 6.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Premmerce\Premmerce\Admin;
4
5 use Premmerce\Premmerce\Container ;
6 use Premmerce\Premmerce\PremmercePlugin ;
7 /**
8 * Class Admin
9 *
10 * @package Premmerce\Premium\Admin
11 */
12 class Admin
13 {
14 /**
15 * @var Container
16 */
17 private $container ;
18 /**
19 * Admin constructor.
20 *
21 * Register menu items and handlers
22 *
23 * @param Container $container
24 */
25 public function __construct( Container $container )
26 {
27 $this->container = $container;
28 $this->addActions();
29 }
30
31 /**
32 * Add plugin actions
33 */
34 public function addActions()
35 {
36 add_action( 'admin_menu', array( $this, 'addMenuPage' ), 1 );
37 add_action( 'admin_enqueue_scripts', array( $this, 'enqueueScripts' ) );
38 add_action( 'wp_enqueue_scripts', array( $this, 'enqueueScripts' ) );
39 add_action( 'admin_post_premmerce_actions', function () {
40 call_user_func( array( $this->container->getPluginsHandler(), 'runAction' ) );
41 } );
42 add_action( 'wp_ajax_premmerce_actions', function () {
43 call_user_func( array( $this->container->getPluginsHandler(), 'runAction' ) );
44 } );
45 add_action( 'wp_ajax_premmerce_wizard_actions', function () {
46 call_user_func( array( $this->container->getWizardHandler(), 'runAction' ) );
47 } );
48 add_action( 'wp_before_admin_bar_render', function () {
49 call_user_func( array( $this->container->getToolbarHandler(), 'renderAdminBarItem' ) );
50 } );
51 }
52
53 /**
54 * Add premmerce to menu
55 */
56 public function addMenuPage()
57 {
58 $tips = $this->container->getWizardApi()->getUncompletedTipsCount();
59 add_menu_page(
60 __( 'Premmerce', 'premmerce' ),
61 __( 'Premmerce', 'premmerce' ) . " <span class='update-plugins count-{$tips} premmerce-wizard-counter' ><span class='plugin-count' data-premmerce-count>{$tips}</span></span>",
62 'manage_options',
63 'premmerce',
64 array( $this, 'optionsPage' ),
65 $this->getIcon()
66 );
67 //Remove notifications from hook
68 global $admin_page_hooks ;
69 $admin_page_hooks['premmerce'] = 'premmerce';
70 }
71
72 /**
73 * Manage plugins page
74 */
75 public function optionsPage()
76 {
77 $current = $this->getCurrentTab();
78 $data = array(
79 'current' => $current,
80 'tabs' => $this->getTabs(),
81 'url' => menu_page_url( PremmercePlugin::SLUG, false ),
82 );
83 switch ( $current ) {
84 case 'wizard':
85 $data['wizard'] = $this->container->getWizardApi();
86 break;
87 case 'plugins':
88 $data['dep'] = $this->container->getPluginsApi();
89 break;
90 case 'addons':
91 $data['addons'] = $this->container->getAddonsManager();
92 break;
93 }
94 $this->container->getFileManager()->includeTemplate( 'admin/main.php', $data );
95 }
96
97 /**
98 * @param string $hook
99 */
100 public function enqueueScripts( $hook )
101 {
102 $fm = $this->container->getFileManager();
103 wp_enqueue_style( 'premmerce-wizard-bar', $fm->locateAsset( 'admin/css/wizard-admin-bar.css' ) );
104
105 if ( $hook == 'toplevel_page_premmerce' ) {
106 wp_enqueue_style( 'premmerce-tabs', $fm->locateAsset( 'admin/css/premmerce-tabs.css' ) );
107 wp_register_script( 'premmerce_actions', $fm->locateAsset( 'admin/js/premmerce_actions.js' ), array( 'updates' ) );
108 wp_register_style( 'premmerce-spinner', $fm->locateAsset( 'admin/css/spinner.css' ) );
109 switch ( $this->getCurrentTab() ) {
110 case 'wizard':
111 wp_enqueue_script( 'premmerce-wizard', $fm->locateAsset( 'admin/js/wizard.js' ), array( 'premmerce_actions', 'jquery-ui-sortable' ) );
112 wp_enqueue_style( 'premmerce-wizard', $fm->locateAsset( 'admin/css/wizard.css' ), array( 'premmerce-spinner' ) );
113 break;
114 case 'plugins':
115 wp_enqueue_script( 'premmerce_plugins', $fm->locateAsset( 'admin/js/plugins.js' ), array( 'premmerce_actions' ) );
116 wp_enqueue_style( 'premmerce-plugins', $fm->locateAsset( 'admin/css/plugins.css' ), array( 'premmerce-spinner' ) );
117 break;
118 case 'settings':
119 }
120 }
121
122 }
123
124 /**
125 *
126 * @return array
127 */
128 private function getTabs()
129 {
130 $tabs['wizard'] = __( 'Wizard', 'premmerce' );
131 $tabs['plugins'] = __( 'Plugins', 'premmerce' );
132 $tabs['settings'] = __( 'Settings', 'premmerce' );
133 $tabs['addons'] = __( 'Addons', 'premmerce' );
134
135 if ( function_exists( 'premmerce_pwk_fs' ) ) {
136 if ( premmerce_pwk_fs()->is_registered() ) {
137 $tabs['account'] = __( 'Account', 'premmerce' );
138 }
139 $tabs['contact'] = __( 'Contact Us', 'premmerce' );
140 // $tabs['pricing'] = __('Pricing', 'premmerce');
141 }
142
143 return $tabs;
144 }
145
146 /**
147 * Tab from get parameter of default
148 * @return string
149 */
150 private function getCurrentTab()
151 {
152 return ( isset( $_GET['tab'] ) ? $_GET['tab'] : 'wizard' );
153 }
154
155 /**
156 * Inline svg icon
157 *
158 * @return string
159 */
160 private function getIcon()
161 {
162 $svg = '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="20" height="16" style="fill:#82878c" viewBox="0 0 20 16"><g id="Rectangle_7"> <path d="M17.8,4l-0.5,1C15.8,7.3,14.4,8,14,8c0,0,0,0,0,0H8h0V4.3C8,4.1,8.1,4,8.3,4H17.8 M4,0H1C0.4,0,0,0.4,0,1c0,0.6,0.4,1,1,1 h1.7C2.9,2,3,2.1,3,2.3V12c0,0.6,0.4,1,1,1c0.6,0,1-0.4,1-1V1C5,0.4,4.6,0,4,0L4,0z M18,2H7.3C6.6,2,6,2.6,6,3.3V12 c0,0.6,0.4,1,1,1c0.6,0,1-0.4,1-1v-1.7C8,10.1,8.1,10,8.3,10H14c1.1,0,3.2-1.1,5-4l0.7-1.4C20,4,20,3.2,19.5,2.6 C19.1,2.2,18.6,2,18,2L18,2z M14,11h-4c-0.6,0-1,0.4-1,1c0,0.6,0.4,1,1,1h4c0.6,0,1-0.4,1-1C15,11.4,14.6,11,14,11L14,11z M14,14 c-0.6,0-1,0.4-1,1c0,0.6,0.4,1,1,1c0.6,0,1-0.4,1-1C15,14.4,14.6,14,14,14L14,14z M4,14c-0.6,0-1,0.4-1,1c0,0.6,0.4,1,1,1 c0.6,0,1-0.4,1-1C5,14.4,4.6,14,4,14L4,14z"/></g></svg>';
163 $svg = 'data:image/svg+xml;base64,' . base64_encode( $svg );
164 return $svg;
165 }
166
167 }