Skip to content

Commit eb9ccde

Browse files
author
shin
committed
fix: conflicts
2 parents 9e30b9f + 2efb586 commit eb9ccde

File tree

40 files changed

+448
-842
lines changed

40 files changed

+448
-842
lines changed

cherry-core.php

Lines changed: 66 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* Class Cherry Core
4-
* Version: 1.4.3.1
4+
* Version: 1.5.0
55
*
66
* @package Cherry_Framework
77
* @subpackage Class
@@ -59,25 +59,29 @@ class Cherry_Core {
5959
* Constructor.
6060
*
6161
* @since 1.0.0
62-
* @since 1.1.1 Using dirname( __FILE__ ) instead of __DIR__.
6362
*/
6463
public function __construct( $settings = array() ) {
65-
$base_dir = trailingslashit( dirname( __FILE__ ) );
66-
$base_url = trailingslashit( $this->base_url( '', __FILE__ ) );
64+
global $chery_core_version;
6765

6866
$defaults = array(
6967
'framework_path' => 'cherry-framework',
7068
'modules' => array(),
71-
'base_dir' => $base_dir,
72-
'base_url' => $base_url,
73-
'extra_base_dir' => '',
69+
'base_dir' => '',
70+
'base_url' => '',
7471
);
7572

7673
$this->settings = array_merge( $defaults, $settings );
7774

78-
$this->settings['extra_base_dir'] = trailingslashit( $this->settings['base_dir'] );
79-
$this->settings['base_dir'] = $base_dir;
80-
$this->settings['base_url'] = $base_url;
75+
if ( isset( $chery_core_version ) && 0 < sizeof( $chery_core_version ) ) {
76+
$core_paths = array_values( $chery_core_version );
77+
$path_parts = pathinfo( $core_paths[0] );
78+
$this->settings['base_dir'] = trailingslashit( $path_parts['dirname'] );
79+
} else {
80+
// This condition and the using of the function dirname is due to core backwards compatibility with old framework versions
81+
$this->settings['base_dir'] = trailingslashit( dirname( __FILE__ ) );
82+
}
83+
84+
$this->settings['base_url'] = trailingslashit( $this->base_url( '', $this->settings['base_dir'] ) );
8185

8286
$this->run_collector();
8387

@@ -118,30 +122,10 @@ private function run_collector() {
118122
}
119123

120124
foreach ( $this->settings['modules'] as $module => $settings ) {
121-
$priority = $this->get_module_priority( $module );
122-
$path = $this->get_module_path( $module );
125+
$file_path = $this->get_module_file( $module );
123126

124127
if ( ! array_key_exists( $module, self::$all_modules ) ) {
125-
self::$all_modules[ $module ] = array(
126-
$priority => $path,
127-
);
128-
129-
} else {
130-
$old_priority = array_keys( self::$all_modules[ $module ] );
131-
132-
if ( ! is_array( $old_priority ) || ! isset( $old_priority[0] ) ) {
133-
continue;
134-
}
135-
136-
$compare = version_compare( $old_priority[0], $priority, '<' );
137-
138-
if ( $compare ) {
139-
continue;
140-
}
141-
142-
self::$all_modules[ $module ] = array(
143-
$priority => $path,
144-
);
128+
self::$all_modules[ $module ] = $file_path;
145129
}
146130
}
147131

@@ -160,10 +144,8 @@ private function run_collector() {
160144
* @since 1.1.0
161145
*/
162146
public static function load_all_modules() {
147+
foreach ( self::$all_modules as $module => $path ) {
163148

164-
foreach ( self::$all_modules as $module => $data ) {
165-
166-
$path = current( $data );
167149
$loaded = self::load_module( $module, $path );
168150

169151
if ( ! $loaded ) {
@@ -178,7 +160,7 @@ public static function load_all_modules() {
178160
* @since 1.4.0
179161
*/
180162
public function load_textdomain() {
181-
$mo_file_path = dirname( __FILE__ ) . '/languages/' . get_locale() . '.mo';
163+
$mo_file_path = $this->settings['base_dir'] . 'languages/' . get_locale() . '.mo';
182164

183165
load_textdomain( 'cherry-framework', $mo_file_path );
184166
}
@@ -213,7 +195,6 @@ public function init_required_modules() {
213195
* @since 1.1.0
214196
*/
215197
public function init_autoload_modules() {
216-
217198
if ( empty( $this->modules ) ) {
218199
return;
219200
}
@@ -229,6 +210,7 @@ public function init_autoload_modules() {
229210
}
230211

231212
$args = ! empty( $settings['args'] ) ? $settings['args'] : array();
213+
232214
$this->init_module( $module, $args );
233215
}
234216
}
@@ -242,6 +224,12 @@ public function init_autoload_modules() {
242224
* @return mixed
243225
*/
244226
public function init_module( $module, $args = array() ) {
227+
228+
if ( empty( $args[ 'module_path' ] ) ) {
229+
$get_module_path = $this->get_module_path( $module );
230+
$args['module_path'] = ( $get_module_path ) ? $get_module_path : '';
231+
}
232+
245233
$this->modules[ $module ] = $this->get_module_instance( $module, $args );
246234

247235
/**
@@ -279,14 +267,14 @@ public function is_module_autoload( $module ) {
279267
public static function load_module( $module, $path ) {
280268
$class_name = self::get_class_name( $module );
281269

282-
if ( class_exists( $class_name ) ) {
283-
return true;
284-
}
285-
286270
if ( ! $path ) {
287271
return false;
288272
}
289273

274+
if ( class_exists( $class_name ) ) {
275+
return true;
276+
}
277+
290278
require_once( $path );
291279

292280
return true;
@@ -336,72 +324,31 @@ public static function get_class_name( $slug = '' ) {
336324
*/
337325
public function get_module_path( $module ) {
338326
$abs_path = false;
339-
$rel_path = 'modules/' . $module . '/' . $module . '.php';
327+
$rel_path = 'modules/' . $module . '/';
340328

341-
if ( file_exists( $this->settings['extra_base_dir'] . $rel_path ) ) {
342-
$abs_path = $this->settings['extra_base_dir'] . $rel_path;
343-
} else if ( file_exists( $this->settings['base_dir'] . $rel_path ) ) {
329+
if ( file_exists( $this->settings['base_dir'] . $rel_path ) ) {
344330
$abs_path = $this->settings['base_dir'] . $rel_path;
345331
}
346332

347333
return $abs_path;
348334
}
349335

350336
/**
351-
* Get module priority from it's version.
352-
* Version information should be provided as a value stored in the header notation.
337+
* Get path to main file for passed module.
353338
*
354-
* @link https://developer.wordpress.org/reference/functions/get_file_data/
355-
* @since 1.0.0
356-
* @param string $module Module slug or path.
357-
* @param bool $is_path Set this as true, if `$module` contains a path.
358-
* @return int
339+
* @since 1.0.1
340+
* @param string $module Module slug.
341+
* @return string
359342
*/
360-
public function get_module_priority( $module, $is_path = false ) {
361-
362-
// Default phpDoc headers.
363-
$default_headers = array(
364-
'version' => 'Version',
365-
);
366-
367-
// Maximum version number (major, minor, patch).
368-
$max_version = array(
369-
99,
370-
99,
371-
999,
372-
);
373-
374-
// If `$module` is a slug, get module path.
375-
if ( ! $is_path ) {
376-
$module = $this->get_module_path( $module );
377-
}
378-
379-
$version = '1.0.0';
380-
381-
/* @TODO: Add smart check */
382-
if ( ! $module ) {
383-
return $version;
384-
}
385-
386-
$data = get_file_data( $module , $default_headers );
387-
388-
// Check if version string has a valid value.
389-
if ( isset( $data['version'] ) && false !== strpos( $data['version'], '.' ) ) {
390-
391-
// Clean the version string.
392-
preg_match( '/[\d\.]+/', $data['version'], $version );
393-
$version = $version[0];
394-
}
395-
396-
// Convert version into integer.
397-
$parts = explode( '.', $version );
343+
public function get_module_file( $module ) {
344+
$abs_path = false;
345+
$rel_path = 'modules/' . $module . '/' . $module . '.php';
398346

399-
// Calculate priority.
400-
foreach ( $parts as $index => $part ) {
401-
$parts[ $index ] = $max_version[ $index ] - (int) $part;
347+
if ( file_exists( $this->settings['base_dir'] . $rel_path ) ) {
348+
$abs_path = $this->settings['base_dir'] . $rel_path;
402349
}
403350

404-
return (int) join( '', $parts );
351+
return $abs_path;
405352
}
406353

407354
/**
@@ -416,15 +363,24 @@ public function get_module_priority( $module, $is_path = false ) {
416363
*/
417364
public static function base_url( $file_path = '', $module_path ) {
418365
$module_path = wp_normalize_path( $module_path );
419-
$module_dir = dirname( $module_path );
366+
preg_match( '/\..*$/', $module_path, $ext );
367+
368+
if ( empty( $ext ) ) {
369+
$module_dir = $module_path;
370+
} else {
371+
// This condition and the using of the function dirname is due to core backwards compatibility with old framework versions
372+
$module_dir = dirname( $module_path );
373+
}
420374

421375
$plugin_dir = wp_normalize_path( WP_PLUGIN_DIR );
422376
$stylesheet = get_stylesheet();
423377
$theme_root = get_raw_theme_root( $stylesheet );
424378
$theme_dir = "$theme_root/$stylesheet";
425379

426-
if ( 0 === strpos( $module_path, $plugin_dir ) ) {
427-
$url = plugin_dir_url( $module_path );
380+
if ( 0 === strpos( $module_dir, $plugin_dir ) ) {
381+
$home_url = home_url();
382+
$abs_path = wp_normalize_path( ABSPATH );
383+
$url = str_replace( untrailingslashit( $abs_path ), $home_url, $module_dir );
428384
} else if ( false !== strpos( $module_path, $theme_dir ) ) {
429385
$explode = explode( $theme_dir, $module_dir );
430386
$url = get_stylesheet_directory_uri() . end( $explode );
@@ -452,7 +408,7 @@ public static function base_url( $file_path = '', $module_path ) {
452408
*/
453409
public function pass_core_to_widgets( $core, $path ) {
454410
$path = str_replace( '\\', '/', $path );
455-
$current_core = str_replace( '\\', '/', $this->settings['extra_base_dir'] );
411+
$current_core = str_replace( '\\', '/', $this->settings['base_dir'] );
456412

457413
if ( false !== strpos( $path, $current_core ) ) {
458414
return self::get_instance();
@@ -461,11 +417,22 @@ public function pass_core_to_widgets( $core, $path ) {
461417
return $core;
462418
}
463419

420+
/**
421+
* Get core version.
422+
*
423+
* @since 1.5.0
424+
* @return string
425+
*/
426+
public function get_core_version() {
427+
global $chery_core_version;
428+
429+
return key( $chery_core_version );
430+
}
431+
464432
/**
465433
* Get path to the core directory.
466434
*
467435
* @since 1.0.0
468-
* @deprecated 1.1.0 Use constant `dirname( __FILE__ )`
469436
* @return string
470437
*/
471438
public function get_core_dir() {

config.json

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,6 @@
115115
"required" : false,
116116
"dependencies" : [ "cherry-interface-builder" ]
117117
},
118-
"cherry-template-manager" : {
119-
"name" : "Template Manager",
120-
"description" : "Module for load and parse *.tmpl files.",
121-
"version" : "1.0.2",
122-
"doc_link" : "https://github.com/CherryFramework/cherry-framework-docs/blob/master/05.%20cherry-template-manager.md",
123-
"git_link" : "https://github.com/CherryFramework/cherry-framework/tree/master/modules/cherry-template-manager",
124-
"compatible" : ["theme", "plugin"],
125-
"wordpress_org" : true,
126-
"required" : false,
127-
"dependencies" : []
128-
},
129118
"cherry-term-meta" : {
130119
"name" : "Term Meta",
131120
"description" : "Manage term metadata.",

modules/cherry-breadcrumbs/cherry-breadcrumbs.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
/**
33
* Module Name: Breadcrumb Trail
44
* Description: A breadcrumb menu script for WordPress
5-
* Version: 1.1.5
65
* Author: Cherry Team
76
* Author URI: http://www.cherryframework.com/
87
* License: GPLv3
@@ -1256,10 +1255,9 @@ public function add_search_items() {
12561255
if ( is_paged() ) {
12571256
$url = get_search_link();
12581257
$this->_add_item( 'link_format', $label, $url );
1259-
1258+
} else {
1259+
$this->_add_item( 'target_format', $label );
12601260
}
1261-
1262-
$this->_add_item( 'target_format', $label );
12631261
}
12641262

12651263
/**

0 commit comments

Comments
 (0)