Skip to content

Commit

Permalink
little refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
bologer committed Nov 18, 2018
1 parent 742c5a0 commit 47982c8
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 19 deletions.
6 changes: 6 additions & 0 deletions anycomment.php
Expand Up @@ -26,6 +26,12 @@
}

function AnyComment() {
defined( 'ANYCOMMENT_PLUGIN_FILE' ) or define( 'ANYCOMMENT_PLUGIN_FILE', __FILE__ );
defined( 'ANYCOMMENT_LANG' ) or define( 'ANYCOMMENT_LANG', __FILE__ );
defined( 'ANYCOMMENT_ABSPATH' ) or define( 'ANYCOMMENT_ABSPATH', dirname( __FILE__ ) );
defined( 'ANYCOMMENT_PLUGIN_BASENAME' ) or define( 'ANYCOMMENT_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
defined( 'ANYCOMMENT_DEBUG' ) or define( 'ANYCOMMENT_DEBUG', false );

return \AnyComment\AnyCommentCore::instance();
}

Expand Down
20 changes: 3 additions & 17 deletions includes/AnyCommentCore.php
Expand Up @@ -56,7 +56,6 @@ public function __construct() {
* Init method to invoke starting scripts.
*/
public function init() {
$this->define_constants();
$this->includes();
$this->init_textdomain();
$this->init_hooks();
Expand Down Expand Up @@ -119,33 +118,20 @@ public static function uninstall() {
( new AnyCommentMigrationManager() )->dropAll();
}

/**
* Define AnyComment Constants.
*/
private function define_constants() {

defined( 'ANYCOMMENT_PLUGIN_FILE' ) or define( 'ANYCOMMENT_PLUGIN_FILE', __FILE__ );
defined( 'ANYCOMMENT_LANG' ) or define( 'ANYCOMMENT_LANG', __FILE__ );
defined( 'ANYCOMMENT_ABSPATH' ) or define( 'ANYCOMMENT_ABSPATH', dirname( __FILE__ ) . '/../' );
defined( 'ANYCOMMENT_PLUGIN_BASENAME' ) or define( 'ANYCOMMENT_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
defined( 'ANYCOMMENT_VERSION' ) or define( 'ANYCOMMENT_VERSION', $this->version );
defined( 'ANYCOMMENT_DEBUG' ) or define( 'ANYCOMMENT_DEBUG', false );
}

/**
* Get the plugin url.
* @return string
*/
public function plugin_url() {
return untrailingslashit( plugins_url( '/../', __FILE__ ) );
return untrailingslashit( plugins_url( '/', ANYCOMMENT_PLUGIN_FILE ) );
}

/**
* Get the plugin path.
* @return string
*/
public function plugin_path() {
return untrailingslashit( plugin_dir_path( __FILE__ ) . '../' );
return untrailingslashit( plugin_dir_path( ANYCOMMENT_PLUGIN_FILE ) );
}

/**
Expand All @@ -156,7 +142,7 @@ public function includes() {
* Some plugin already have such class.
*/
if ( ! class_exists( 'Hybridauth' ) ) {
include_once( ANYCOMMENT_ABSPATH . 'includes/hybridauth/src/autoload.php' );
include_once( ANYCOMMENT_ABSPATH . '/includes/hybridauth/src/autoload.php' );
}

AnyCommentLoader::load();
Expand Down
26 changes: 25 additions & 1 deletion includes/Helpers/AnyCommentInflector.php
Expand Up @@ -81,6 +81,30 @@ public static function transliterate( $string, $transliterator = null ) {
* @return array
*/
public static function get_dictionary() {
return require __DIR__ . '/data/transliterate.php';
return require __DIR__ . '/Data/transliterate.php';
}

/**
* Returns a string with all spaces converted to given replacement,
* non word characters removed and the rest of characters transliterated.
*
* If intl extension isn't available uses fallback that converts latin characters only
* and removes the rest. You may customize characters map via $transliteration property
* of the helper.
*
* @param string $string An arbitrary string to convert
* @param string $replacement The replacement to use for spaces
* @param bool $lowercase whether to return the string in lowercase or not. Defaults to `true`.
* @return string The converted string.
*/
public static function slug($string, $replacement = '-', $lowercase = true)
{
$parts = explode($replacement, static::transliterate($string));
$replaced = array_map(function ($element) use ($replacement) {
$element = preg_replace('/[^a-zA-Z0-9=\s—–]+/u', '', $element);
return preg_replace('/[=\s—–]+/u', $replacement, $element);
}, $parts);
$string = trim(implode($replacement, $replaced), $replacement);
return $lowercase ? strtolower($string) : $string;
}
}
2 changes: 1 addition & 1 deletion includes/Helpers/AnyCommentTemplate.php
Expand Up @@ -18,7 +18,7 @@ class AnyCommentTemplate {
*/
public static function render( $name ) {
ob_start();
include ANYCOMMENT_ABSPATH . "templates/$name.php";
include ANYCOMMENT_ABSPATH . "/templates/{$name}.php";
$content = ob_get_contents();
ob_end_clean();

Expand Down
File renamed without changes.

0 comments on commit 47982c8

Please sign in to comment.