Skip to content

Commit

Permalink
Further refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
seebeen committed Nov 11, 2020
1 parent 063edcd commit 492d859
Show file tree
Hide file tree
Showing 17 changed files with 67 additions and 367 deletions.
12 changes: 10 additions & 2 deletions lib/Admin/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,19 @@ function(){},

public function settings_page()
{

printf(
'<h1>%s</h1>',
get_admin_page_title()
);

$template_file = PATH."templates/settings/page.php";
echo '<form method="POST" action="options.php">';

include $template_file;
settings_fields('stl_settings');
do_settings_sections('stl_settings');
submit_button();

echo '</form>';
}


Expand Down
2 changes: 1 addition & 1 deletion lib/Admin/Settings/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use const SGI\STL\DOMAIN;

use function SGI\STL\Core\Utils\is_wpml_active;
use function SGI\STL\Utils\is_wpml_active;

trait Menu
{
Expand Down
26 changes: 9 additions & 17 deletions lib/Core/LanguageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,35 +115,27 @@ private function determine_script()

$req_script = $_REQUEST[$this->opts['core']['param']] ?? false;


if ($req_script) :

if ($this->opts['core']['cookie']) :

return $this->set_cookie($req_script);

else :

return $req_script;

endif;

else :
if (!$req_script) :

if ($this->opts['core']['cookie']) :

return ($lang = $this->get_cookie()) ?
$lang :
$this->set_cookie($this->opts['core']['script']);

else :
endif;

return $this->opts['core']['script'];
return $this->opts['core']['script'];

endif;
endif;

if ($this->opts['core']['cookie']) :

return $this->set_cookie($req_script);

endif;

return $req_script;

}

Expand Down
158 changes: 44 additions & 114 deletions lib/Frontend/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,29 @@

namespace SGI\STL\Frontend;

use SGI\STL\Core\LanguageManager as LM,
SGI\STL\Shortcode\Cyrilizer as Cyrilizer,
SGI\STL\Shortcode\Translator as Translator,
simplehtmldom\HtmlDocument as sHTMLd;
use SGI\STL\Core\LanguageManager as LM,
SGI\STL\Shortcode\Cyrilizer as Cyrilizer,
SGI\STL\Shortcode\Translator as Translator,
simplehtmldom\HtmlDocument as sHTMLd;

use function SGI\STL\Utils\getOptions,
SGI\STL\Utils\transliterate,
SGI\STL\Utils\multiscript_sql_query;

SGI\STL\Utils\transliterate;

class Core
{

private $opts;

/**
* @var LM
* @var LM Language Manager class
*
* @since 2.0
*/
private $lm;

/**
* @var array List of shortcode uuid-content pairs
*/
private $shortcodes;

/**
Expand Down Expand Up @@ -66,43 +69,36 @@ public function __construct()
*/
$filter_priority = apply_filters('sgi/stl/filter_priority', $filter_priority);

add_filter('posts_search', [&$this,'fix_search'], $filter_priority, 2);

if ($this->lm->is_wpml_active() && $this->opts['ml']['wpml']) :
add_filter('icl_ls_languages', [&$this, 'extend_wpml_ls'], $filter_priority, 1);
if ( $this->lm->get_script() != 'lat' && !$this->lm->in_serbian) :
return;
endif;


if ($this->lm->get_script() == 'lat' && $this->lm->in_serbian) :

foreach (self::$actions as $function => $hooks) :
foreach ($hooks as $hook) :
add_action($hook, [&$this, $function], $filter_priority);
endforeach;
endforeach;

foreach (self::$filters as $function => $hooks) :
foreach ($hooks as $hook) :
add_filter($hook, [&$this, $function], $filter_priority);
endforeach;
endforeach;

// Change Page title on latin
if (!current_theme_supports( 'title-tag' )) :
add_filter('wp_title', [&$this,'convert_title'], $filter_priority, 3);
else :
add_filter('pre_get_document_title', [&$this,'convert_title'], $filter_priority, 3);
add_filter('document_title_parts', [&$this,'convert_title_parts'], $filter_priority, 3);
endif;

// Change Script Specific images in content
if ($this->opts['file']['translit'] && $this->opts['file']['content']) :
add_filter('the_content', [&$this, 'change_image_urls'], $filter_priority, 1);
endif;

add_action('wp_head', [&$this, 'buffer_start'], $filter_priority);
add_action('wp_footer', [&$this, 'buffer_end'], $filter_priority);

add_action('rss_head', [&$this, 'buffer_start'], $filter_priority);
add_action('rss_footer', [&$this, 'buffer_end'], $filter_priority);

add_action('atom_head', [&$this, 'buffer_start'], $filter_priority);
add_action('atom_footer', [&$this, 'buffer_end'], $filter_priority);

add_action('rdf_head', [&$this, 'buffer_start'], $filter_priority);
add_action('rdf_footer', [&$this, 'buffer_end'], $filter_priority);

add_action('rss2_head', [&$this, 'buffer_start'], $filter_priority);
add_action('rss2_footer', [&$this, 'buffer_end'], $filter_priority);

add_filter('gettext', [&$this, 'convert_script'], $filter_priority);
add_filter('ngettext', [&$this, 'convert_script'], $filter_priority);
add_filter('gettext_with_context', [&$this, 'convert_script'], $filter_priority);
add_filter('ngettext_with_context', [&$this, 'convert_script'], $filter_priority);

// Change Script Specific images in content
if ($this->opts['file']['translit'] && $this->opts['file']['content']) :
add_filter('the_content', [&$this, 'change_image_urls'], $filter_priority, 1);
endif;



}

Expand Down Expand Up @@ -139,6 +135,13 @@ public function convert_title($title,$sep = '',$location = '')

}

public function convert_script($content)
{

return transliterate($content);

}

public function convert_title_parts($title)
{

Expand Down Expand Up @@ -169,79 +172,6 @@ public function change_image_urls($output)

return $shtmld->root->innertext;

}

public function fix_search(string $search, \WP_Query $query)
{

if (is_admin())
return $search;

if (!$this->opts['fixes']['search'])
return $search;

if ( !$query->is_main_query())
return $search;

$g = $_GET['s'] ?? '';

if ($g == '')
return $search;

if (!is_search())
return $search;

return multiscript_sql_query($search);

}

public function convert_script($content)
{

return transliterate($content);

}

public function extend_wpml_ls($languages)
{


$active = $this->lm->get_script();

$cir = $lat = $languages['sr'];

if ($active == 'cir') :

$primary = 'sr';
$secondary = 'sr@lat';

else :

$primary = 'sr@cir';
$secondary = 'sr';

endif;

$serbian = [
$primary => array_replace($cir, [
'native_name' => do_shortcode('[stl_cyr]српски (ћир)[/stl_cyr]'),
'translated_name' => "{$languages['sr']['translated_name']} (cyr)",
'url' => add_query_arg($this->opts['core']['param'], 'cir', $languages['sr']['url']),
'active' => ($active == 'cir') ? 1 : 0
]),
$secondary => array_replace($lat, [
'native_name' => 'srpski (lat)',
'translated_name' => "{$languages['sr']['translated_name']} (lat)",
'url' => add_query_arg($this->opts['core']['param'], 'lat', $languages['sr']['url']),
'active' => ($active == 'lat') ? 1 : 0
])
];

unset($languages['sr']);

return $serbian + $languages;


}
}

}
2 changes: 0 additions & 2 deletions lib/Shortcode/Cyrilizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ class Cyrilizer
public function __construct()
{

$this->name = 'lang';

add_shortcode('stl_cyr', [&$this, 'shortcodeCallback']);
add_shortcode('stl_cyrillic', [&$this, 'shortcodeCallback']);

Expand Down
7 changes: 0 additions & 7 deletions lib/Shortcode/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@

namespace SGI\STL\Shortcode;

// use function SGI\STL\Core\Compat\{
// stl_get_script_identifier,
// stl_get_current_script,
// stl_get_cyrillic_id,
// stl_get_latin_id
// };

use function SGI\STL\Utils\{
get_script,
get_script_param
Expand Down
4 changes: 2 additions & 2 deletions lib/Shortcode/SelectiveOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ class SelectiveOutput
public function __construct()
{

add_shortcode('stl_show', [&$this, 'shortcode_callback']);
add_shortcode('stl_show', [&$this, 'shortcodeCallback']);

}


public function shortcode_callback($atts, $content)
public function shortcodeCallback($atts, $content)
{

shortcode_atts([
Expand Down
1 change: 1 addition & 0 deletions lib/Utils/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SGI\STL\Utils;

use const SGI\STL\VERSION;
use const SGI\STL\PATH;

/**
* Return current version of the plugin
Expand Down
27 changes: 0 additions & 27 deletions templates/selector/list.php

This file was deleted.

21 changes: 0 additions & 21 deletions templates/selector/oneline.php

This file was deleted.

Loading

0 comments on commit 492d859

Please sign in to comment.