PluginProbe ʕ •ᴥ•ʔ
Robin Image Optimizer – Unlimited Image Optimization, WebP & AVIF / trunk
Robin Image Optimizer – Unlimited Image Optimization, WebP & AVIF vtrunk
2.0.5 trunk 1.3.7 1.4.0 1.4.1 1.4.2 1.4.6 1.5.0 1.5.3 1.5.6 1.5.8 1.6.5 1.6.6 1.6.9 1.7.0 1.7.4 1.8.1 1.8.2 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4
robin-image-optimizer / libs / factory / pages / includes / page.class.php
robin-image-optimizer / libs / factory / pages / includes Last commit date
admin-page.class.php 4 months ago index.php 6 months ago page.class.php 5 months ago
page.class.php
174 lines
1 <?php
2 /**
3 * Admin page class
4 *
5 * @since 1.0.0
6 * @package factory-core
7 */
8
9 // Exit if accessed directly
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit;
12 }
13
14 if ( ! class_exists( 'Wbcr_FactoryPages600_Page' ) ) {
15
16 class Wbcr_FactoryPages600_Page {
17
18
19 /**
20 * Уникальный ID страницы
21 *
22 * ID страницы используется для формирования ссылки на страницу.
23 *
24 * Ссылки выглядят примерно так:
25 * http://clearfy-test.loc/wp-admin/admin.php?page=components-wbcr_clearfy
26 *
27 * Чтобы не было конфликтов с другими плагинами, используйте префиксы.
28 *
29 * @since 1.0.0
30 * @see FactoryPages600_AdminPage
31 *
32 * @var string
33 */
34 public $id;
35
36 /**
37 * Current Factory Plugin.
38 *
39 * @var Wbcr_Factory600_Plugin
40 */
41 public $plugin;
42 protected $scripts;
43 protected $styles;
44 protected $request;
45
46 /**
47 * @var string
48 */
49 public $result;
50
51 // private $default_actions = array();
52
53 /**
54 * @param Wbcr_Factory600_Plugin $plugin
55 *
56 * @throws Exception
57 */
58 public function __construct( Wbcr_Factory600_Plugin $plugin ) {
59 $this->plugin = $plugin;
60
61 if ( $plugin ) {
62 $this->scripts = $this->plugin->newScriptList();
63 $this->styles = $this->plugin->newStyleList();
64 $this->request = $plugin->request;
65 }
66 }
67
68 /*
69 public function __call($name, $arguments) {
70
71
72 if(!empty($custom_action)) {
73
74 }
75
76 }*/
77
78 public function assets( $scripts, $styles ) {
79 }
80
81 /**
82 * Shows page.
83 */
84 public function show() {
85
86 if ( $this->result ) {
87 echo $this->result;
88 } else {
89 $action = isset( $_GET['action'] ) ? $_GET['action'] : 'index';
90 $this->executeByName( $action );
91 }
92 }
93
94 /**
95 * @param string $action
96 *
97 * @throws Exception
98 */
99 public function executeByName( $action ) {
100 $raw_action_name = $action;
101
102 if ( preg_match( '/[-_]+/', $action ) ) {
103 $action = $this->dashesToCamelCase( $action, false );
104 }
105 $actionFunction = $action . 'Action';
106
107 $cancel = $this->OnActionExecuting( $action );
108
109 if ( $cancel === false ) {
110 return;
111 }
112
113 if ( ! method_exists( $this, $actionFunction ) ) {
114 // todo: продумать и доработать выполнение произвольны�
115 и глобальны�
116 дейтсвия для все�
117 страниц
118 /*
119 $custom_actions = apply_filters('wbcr/factory_pages_600/custom_actions', array(), $raw_action_name);
120
121 if(isset($custom_actions[$raw_action_name])) {
122 $custom_actions[$raw_action_name]();
123 $this->OnActionExected($action);
124 return;
125 } else {*/
126 $actionFunction = 'indexAction';
127 // }
128 }
129
130 call_user_func_array( [ $this, $actionFunction ], [] );
131 $this->OnActionExected( $action );
132 }
133
134 /**
135 * @param string $string
136 * @param bool $capitalizeFirstCharacter
137 *
138 * @return mixed
139 * @throws Exception
140 */
141 protected function dashesToCamelCase( $string, $capitalizeFirstCharacter = false ) {
142 $str = str_replace( ' ', '', ucwords( preg_replace( '/[-_]/', ' ', $string ) ) );
143
144 if ( ! $capitalizeFirstCharacter ) {
145 $str[0] = strtolower( $str[0] );
146 }
147
148 if ( empty( $str ) ) {
149 throw new Exception( 'Dashed to camelcase parse error.' );
150 }
151
152 return $str;
153 }
154
155 /**
156 * @param $action
157 *
158 * @return bool
159 */
160 protected function OnActionExecuting( $action ) {
161 }
162
163 protected function OnActionExected( $action ) {
164 }
165
166 /**
167 * @param $path
168 */
169 protected function script( $path ) {
170 wp_enqueue_script( $path, $path, [ 'jquery' ], false, true );
171 }
172 }
173 }
174