* @license GPL-3.0+
* @link https://puvox.software
* @copyright 2018-2019 Puvox.software
*
*/
if(!trait_exists('default_methods__Puvox_Software'))
{
trait default_methods__Puvox_Software
{
public function __construct($arg1=false)
{
$this->is_development = defined("_puvox_machine_") ; // set in devmachine (in "my_superglobals.php" and in "EnvVariables")
if($this->is_development) $this->display_errors();
// #### Because this is a trait, we don't use "__FILE__" & "__DIR__" here, but "Reflection". ####
$reflection = (new \ReflectionClass(__CLASS__));
$this->plugin_NAMESPACE = $reflection->getNamespaceName(); // get parent's namespace name
$this->prefix = strtolower( preg_replace('![^A-Z]+!', '', $this->plugin_NAMESPACE) );// get prefix from current namespace initials (i.e. xyz)
$this->prefix_ = $this->prefix .'_';
$this->plugin_FILE = $reflection->getFileName(); // set plugin's main file path
$this->plugin_DIR = dirname($this->plugin_FILE); // set plugin's dir path
$this->plugin_URL = plugin_dir_url($this->plugin_FILE); // get plugin's dir URL
$this->wp_URL = network_home_url('/'); // WP installation home
$this->wp_FOLDER = network_home_url('/', 'relative'); // WP folder
$this->home_URL = home_url('/'); // current sub/site home url
$this->home_FOLDER = home_url('/', 'relative'); // current sub/site home folder
$this->is_https = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS']!=='off') || $_SERVER['SERVER_PORT']==443);
$this->httpsCurrent = $this->is_https ? 'https://' : 'http://';
$this->httpsReal = preg_replace('/(http(s|):\/\/)(.*)/i', '$1', $this->home_URL);
$this->domainCurrent = $_SERVER['HTTP_HOST'];
$this->domainReal = $this->getDomain($this->home_URL);
$this->domain = $this->httpsReal.$this->domainReal;
$this->siteslug = str_ireplace('.','_', $this->domainReal);
$this->requestURI = $_SERVER["REQUEST_URI"];
$this->urlAfterHome = substr($this->requestURI, strlen($this->home_FOLDER) );
$this->pathAfterHome = parse_url($this->urlAfterHome, PHP_URL_PATH);
$this->current_URL = $this->domain . $this->requestURI;
$this->currentURL = $this->current_URL; //shortand
$this->homeUrlStripped = $this->stripUrlPrefixes($this->home_URL);
$this->is_localhost = (stripos($this->home_URL,'://127.0.0.1')!==false || stripos($this->home_URL,'://localhost')!==false );
$this->is_settings_page = false;
$this->wpdb = $GLOBALS['wpdb'];
$this->options_tabs = [];
if ($this->old_version()){
register_activation_hook( $this->plugin_FILE, function(){ exit( __("Sorry, your PHP version ". phpversion() ." is very old. We suggest changing your hosting's PHP version.") ); } );
return;
}
// initial variables
$this->my_plugin_vars();
$this->newtork_managed = is_multisite() && $this->getNetworkedState();
$this->opts = $this->refresh_options(); // Setup final variables
$this->refresh_options_TimeGone();
$this->logs_table_name = $GLOBALS['wpdb']->base_prefix . $this->plugin_slug_u.'-error_logs';
$this->check_if_pro_plugin();
$this->__construct_my(); // All other custom construction hooks
$pgnm = property_exists($this,'customOptsPageUrl') ? $this->customOptsPageUrl : $this->slug;
$this->settingsPHP_page = ( array_key_exists('menu_button_level', $this->static_settings) && $this->static_settings['menu_button_level']=="mainmenu" ) ? 'admin.php' : (is_network_admin() || $this->newtork_managed ? 'settings.php' : 'options-general.php');
$this->plugin_page_url_current = ( is_network_admin() || $this->newtork_managed ? network_admin_url($this->settingsPHP_page) : admin_url($this->settingsPHP_page) ) .'?page='.$pgnm;
$this->plugin_page_url_main = ( is_multisite() ? network_admin_url($this->settingsPHP_page) : admin_url($this->settingsPHP_page) ) .'?page='.$pgnm;
$this->plugin_files = array_merge( (property_exists($this, 'plugin_files') ? $this->plugin_files : [] ), ['index.php'] );
$this->translation_phrases= $this->get_phrases();
$this->ip = $this->get_visitor_ip();
$this->isMobile = false;
$this->is_in_customizer = (stripos($this->currentURL, admin_url('customize.php')) !== false);
$this->myplugin_class = 'myplugin postbox version_'. (!$this->static_settings['has_pro_version'] ? "free" : ($this->is_pro_legal ? "pro" : "not_pro") );
$this->addon_namepart = 'puvox.software';
$this->define_option_tabs();
//activation & deactivation (empty hooks by default. all important things migrated into `refresh_options`)
register_activation_hook( $this->plugin_FILE, [$this, 'activate'] );
register_deactivation_hook( $this->plugin_FILE, [$this, 'deactivate'] );
//translation hook
add_action('init', [$this, 'load_textdomain'] );
//==== my other default hooks ===//
$this->setupLinksAndMenus();
//shortcodes
$this->shortcodes_initialize();
// if buttons needed
$this->tinymce_funcs();
// for backend ajax
add_action( 'wp_ajax_'.$this->plugin_slug_u.'_all', [$this, 'ajax_backend_call'] );
add_action( 'admin_head', [$this,'admin_head_func']);
add_action( 'current_screen', function(){ $this->admin_scripts(null); } );
//add uninstaller file
if(is_admin()) $this->add_default_uninstall(); //add_action( 'shutdown', [$this, 'my_shutdown_for_versioning']);
add_action('wp', [$this, 'flush_checkpoint'], 999);
// functions for PRO-ADDON upload
// add_filter( 'pre_move_uploaded_file', function( $null, $file, $new_file, $type ){ return $path; }, 10, 4);
$this->pro_file_part = 'puvox-software';
if($this->static_settings['has_pro_version']) {
add_filter( 'upload_mimes', [$this,'upload_mimes_filter'], 1);
add_filter( 'wp_handle_upload', [$this,'wp_handle_upload_filter'], 10, 2);
}
}
public function setupLinksAndMenus()
{
// If plugin has options
if($this->static_settings['show_opts'])
{
//add admin menu
if (is_multisite()){
add_action('network_admin_menu', [$this, 'register_menus'] );
if (!$this->newtork_managed)
add_action('admin_menu', [$this, 'register_menus'] );
}
else {
add_action('admin_menu', [$this, 'register_menus'] );
}
//redirect to settings page after activation (if not bulk activation)
add_action('activated_plugin', function($plugin) { if ($this->is_not_bulk_activation($plugin)) { exit( wp_redirect($this->plugin_page_url_main.'&isactivation') ); } } );
}
// add Settings & Donate buttons in plugins list
add_filter( (is_network_admin() ? 'network_admin_' : ''). 'plugin_action_links_'.plugin_basename($this->plugin_FILE), function($links){
if(!$this->static_settings['has_pro_version']) { $links[] = ''.$this->static_settings['menu_text']['donate'].''; }
if($this->static_settings['show_opts']){ $links[] = ''.$this->static_settings['menu_text']['settings'].''; }
if(isset($this->opts['custom_opts_page'])){ $links[] = ''.$this->static_settings['menu_text']['settings'].''; }
//if(is_network_admin() && $this->initial_static_options['allowed_on'] =='singlesite'){ unset($links['activate']); $links[] = ''.$this->static_settings['menu_text']['deactivated_only_from'].' SUB-SITES'; }
return $links;
});
}
public function register_menus()
{
$menu_button_name = (array_key_exists('menu_button_name', $this->static_settings) ? $this->static_settings['menu_button_name'] : $this->opts['name'] );
if( array_key_exists('menu_button_level', $this->static_settings) && $this->static_settings['menu_button_level']=="mainmenu" )
// icons: https://goo.gl/WXAYCi
add_menu_page($menu_button_name, $menu_button_name, $this->static_settings['required_role'] , $this->slug, [$this, 'opts_page_output_parent'], $this->static_settings['menu_icon'] );
else
add_submenu_page($this->settingsPHP_page, $menu_button_name, $menu_button_name, $this->static_settings['required_role'] , $this->slug, [$this, 'opts_page_output_parent'] );
// if target is custom link (not options page)
if(array_key_exists('menu_button_link', $this->opts)){
add_action( 'admin_footer', function (){
?>
'.$this->opts['name'].': '. $this->static_settings['menu_text']['activated_only_from']. ' NETWORK DASHBOARD';
//$text .= '';
die($text);
}
//$this->plugin_updated_hook();
if(method_exists($this, 'activation_funcs') ) { $this->activation_funcs(); }
}
/*
public function activate_old($network_wide){
$actKey = $this->slug.'_activat';
$show_die=isset($_GET['action']) && $_GET['action']=='error_scrape';
//if activation allowed from only on multisite or singlesite or Both?
if(!$show_die)
{
if (get_site_option($actKey))
{
$show_die=true;
delete_site_option($actKey);
}
else
{
$show_die= ! $this->if_correct_activable($network_wide) ;
if($show_die)
{
//update_site_option($actKey,true);
}
}
}
if($show_die) {
$text= '
';
if( empty($array) ){
$array = [];
}
echo '
';
if (is_array($array))
{
if (!$pairs)
{
foreach ($array as $fieldKey=>$value)
{
echo $this->field_out_helper1($parent, $fieldKey, $value, $pairs) ;
}
}
else
{
foreach ($array as $fieldKey=>$value)
{
echo $this->field_out_helper1($parent, $fieldKey, $value, $pairs) ;
}
}
}
$fieldKey= "abc_".rand(1,999999)*rand(1,999999);
$sample_field = $this->field_out_helper1($parent, $fieldKey, "", $pairs, true);
//echo $sample_field;
echo '
';
?>
sanitizer($parent); ?>
';
}
public function field_out_helper1($parent, $key, $value, $pairs, $sample=false)
{
$output='
';
if (!$pairs) {
$output .= '';
} else {
$output .= '';
$output .= '';
}
$output .='
';
return $output;
}
public function arrayFieldsResort($ar)
{
$new=[];
foreach($ar as $key=>$val)
{
$new[ sanitize_text_field($val["name"]) ] = sanitize_text_field($val["value"]);
}
return $new;
}
public function get_fb_name_regex($fb_url){
preg_match('/'.preg_quote('^(?:https?://)?(?:www.|m.|touch.)?(?:facebook.com|fb(?:.me|.com))/(?!$)(?:(?:\w)#!/)?(?:pages/)?(?:[\w-]/)?(?:/)?(?:profile.php?id=)?([^/?\s])(?:/|&|?)?.*$/'), $fb_url, $n);
return $n[1];
}
// public function NonceCheck($value, $action_name){if ( !isset($value) || !wp_verify_nonce($value, $action_name) ) { die("error_5151, Refresh the page");}}
public function shortcode_alternative_message($name, $params_name=false)
{
?>
<?php echo do_shortcode('[.....]'); ?>
or
<?php if (function_exists('')) { echo (["arg1"=>"value1", ...]); } ?>
slug . '_transl_lastvers');
if( ! $last_vers || $last_vers != $this->static_settings["Version"] ){
update_site_option('transl_lastvers', $this->static_settings["Version"]);
$res = !empty($this->phrases_array());
update_site_option($this->slug . '_transl_exists', $res);
return $res;
}
return get_site_option($this->slug . '_transl_exists');
}
// settings page
public function define_option_tabs(){
if(!is_admin()) return;
$this->show_tabs = $this->static_settings['display_tabs'];
$this->options_tabs = array_merge(
["Options"],
$this->options_tabs,
property_exists($this,'shortcodes') ? ['Shortcodes'] : [],
( $this->define_translations_exist() ? ["Translations & Phrases"] : [] ),
["Errors-Log & Reset"] //( ! property_exists($this, 'errors_tab') || $this->errors_tab ? ['Errors log'] : [] )
);
}
public function options_tab($tabs_array =false){
if(!$tabs_array) $tabs_array = $this->options_tabs;
$this->active_tab = $tabs_array[0];
foreach($tabs_array as $each_tab){
if (isset($_GET['tab']) && sanitize_key($each_tab)==$_GET['tab'])
$this->active_tab=$each_tab;
}
echo '
';
foreach($tabs_array as $each_tab){
$tab_TITLE = $each_tab=="Shortcodes" ? "Shortcodes & Api" : $each_tab;
echo '
'. __( $tab_TITLE).'';
}
echo '
';
}
public function opts_page_output_parent($args=false)
{
if(is_network_admin())
{
if( !empty( $_POST["mng_nonce"] ) && check_admin_referer( "nonce_mng_" . $this->slug, "mng_nonce" ) )
{
if(isset( $_POST[$this->slug]['managed_from_changer'] ) ){
$val = sanitize_key($_POST[$this->slug]['managed_from_site']) == "network";
$this->newtork_managed = $val;
$this->updateNetworkedState($val);
$this->js_redirect();
}
}
?>
newtork_managed) || (!is_network_admin() && !$this->newtork_managed) )
{
$this->opts_page_output();
}
else{
echo '
'.__("Plugin is set to be managed per: ". ($this->newtork_managed ? "Network": "Sub-sites") ).'
';
}
}
public function settings_page_part($type)
{
$this->is_settings_page = true;
if($type=="start")
{
if( !empty( $_POST["_wpnonce"] ) && check_admin_referer( "nonce_" . $this->slug, "_wpnonce" ) )
{
if(!empty($_POST[$this->slug]) ) {
$this->opts['last_update_time'] = time();
$this->update_opts();
}
if(isset( $_POST[$this->slug]['clear_error_logs'] ) ){
$this->clear_errorslog();
}
if(isset( $_POST[$this->slug]['reset_plugin_defaults'] ) ){
$this->reset_plugin_to_defaults(); $this->js_redirect();
}
if(isset( $_POST[$this->slug]['update_transl_phrases'] ) ){
$this->translation_phrases = array_map('sanitize_text_field', $_POST[$this->slug]['translation_phrases']);
$this->update_phrases( $this->translation_phrases ) ;
}
}
if( !empty( $_GET["_wpnonce"] ) && check_admin_referer( "nonce_" . $this->slug, "_wpnonce" ) )
{
if(isset($_GET[$this->slug.'-remove-pro']) ) {
delete_site_option($this->license_keyname());
$this->js_redirect(remove_query_arg($this->slug.'-remove-pro'));
}
}
?>
opts['name'];?>
options_tab(); ?>
active_tab == "Shortcodes")
{
echo '
'. __('Shortcodes Usage').'
';
foreach($this->shortcodes as $key=>$value)
{
$this->shortcodes_table($key, $value);
$this->shortcode_alternative_message($key);
}
echo '
';
echo '
'. __('Available hooks (to modify from external functions)') .'
';
if ( property_exists($this, "hooks_examples") ) {
foreach ($this->hooks_examples as $key=>$block){
echo '
';
if ($block['type']=='filter'){
echo '
'. __($block['description']) .':
';
echo '
add_filter("'.$key.'", "yourFunc", 10, '. count($block['parameters'] ) .' ); function yourFunc($'. implode(', $', $block['parameters'] ).') { ... return $'.$block['parameters'][0].';} ';
}
echo '
';
}
}
echo '
';
}
if ($this->active_tab == "Translations & Phrases")
{ ?>
active_tab == "Errors-Log & Reset")
{ ?>
get_errorslog();
if(!empty($errors)){
rsort($errors); //reverse order, last added to top
$column_count = count(array_keys( ((array)$errors[0]) ));
foreach ($errors as $each_err ) {
$each_err= (array) $each_err;
echo '';
for($i=0; $i<$column_count; $i++){
$out='';
$current = $each_err[ array_keys($each_err)[$i]];
if (!empty($current) )
{
$out = $current;
}
echo ''. htmlentities($out).' | ';
}
echo '
';
}
}
?>
endStyles();?>
myplugin_class.'">';
}
?>
-
Must have free plugins for everyone'), $this->static_settings['musthave_plugins'] ).'.'; ?>
static_settings['show_rating_message'])
{ ?>
show_author_block)
{ ?>
purchase_pro_block();
?>
'_save_button'] ); ?>
'; ?>
slug ] = $this->home_URL . '?tinymce_buttons_'.$this->slug;
return $plugin_array;
}
public function register_buttons( $buttons ) {
$button_names = array_map( function($ar){ return $ar['button_name']; }, $this->tinymce_buttons );
return array_merge( $buttons, $button_names );
}
public function replace_slashes($path){
return str_replace( ['/','\\',DIRECTORY_SEPARATOR], '/', $path);
}
public function remove_extra_slashes($path){
return str_replace( '//', '/', $path);
}
public function tinymce_buttons_body( )
{
if( ! isset($_GET['tinymce_buttons_'. $this->slug] ) ) return;
session_cache_limiter('none');
// http://stackoverflow.com/a/1385982/2377343
//Caching with "CACHE CONTROL"
header('Cache-control: max-age='. ($year=60*60*24*365) .', public');
//Caching with "EXPIRES" (no need of EXPIRES when CACHE-CONTROL enabled)
//header('Expires: '.gmdate(DATE_RFC1123,time()+$year));
//To get best cacheability, send Last-Modified header and ...
header('Last-Modified: '.gmdate(DATE_RFC1123,filemtime(__file__))); //i.e. 1467220550 [it's 30 june,2016]
//reply using: status 304 (with empty body) if browser sends If-Modified-Since header.... This is cheating a bit (doesn't verify the date), but remove if you dont want to be cached forever:
// if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { header('HTTP/1.1 304 Not Modified'); die(); }
header("Content-type: application/javascript; charset=utf-8");
?>
// ************ these useful scripts got from: https://github.com/tazotodua/useful-javascript/ **********
// "
';
$out .= '['. $array['name'].'
'; foreach($array['atts'] as $key=>$value){ $out .= " ".$value[0].'="'. $this->truefalse_to_string($value[1]).'"';} $out .=']';
$out = ( $strip_tags ? strip_tags($out) : $out);
$out = ( $htmlentities ? htmlentities($out) : $out);
if( $ended )
$out .= "...[/".$array['name']."]";
$out .= '';
return $out;
}
public function shortcode_example($shortcode, $array, $ended=false){
$out="[$shortcode "; foreach($array as $key=>$value){ $out .= $key.'="'.$this->valueToString($value) .'" '; } $out = trim($out). "]";
if( $ended )
$out .= "...[/$shortcode]";
return $out;
}
public function shortcode_atts($shortcode, $atts){
$new_arr=[];
foreach($this->shortcodes[$shortcode]['atts'] as $x){
$new_arr[ $x[0] ] = $this->stringToValue($x[1]) ;
}
if (!empty($atts)) {
$filtered_atts=[];
foreach($atts as $key=>$value){
$filtered_atts[$key] = $this->stringToValue($value) ;
}
$new_arr = array_merge($new_arr, $filtered_atts);
}
if (array_key_exists("...", $new_arr)) unset($new_arr["..."]);
if (array_key_exists("___", $new_arr)) unset($new_arr["___"]);
if (array_key_exists(0, $new_arr)) unset($new_arr[0]);
$new_atts = shortcode_atts($new_arr, [] );
return $new_atts;
}
public function valueToString( $value ){
return is_bool($value) ? ($value ? 'true' : 'false' ) : strip_tags( $value ) ;
}
public function stringToValue( $value ){
return is_bool($value) ? $value : ( !is_string($value) ? $value : ( $value =='true' ? true : ( $value =='false' ? false : $value) ) );
}
public function shortcodes_initialize(){
if(property_exists($this,'shortcodes'))
{
//enable shortcodes (if it's disabled)
add_filter( 'widget_text', 'do_shortcode' );
foreach($this->shortcodes as $name=>$val)
{
//add "name" manually as name
$this->shortcodes[$name]['name']=$name;
add_shortcode($name, [$this, $name]);
}
}
}
public function get_phrases()
{
return $this->get_option_CHOSEN('`translated_phrases', []);
}
public function update_phrases($array=null)
{
if(!isset($array)) $array=$this->translation_phrases;
return $this->update_option_CHOSEN('`translated_phrases', $array);
}
public function phrases_array()
{
$cont='';
foreach( $this->plugin_files as $each)
{
$cont .= file_get_contents(__DIR__.'/'.$this->slug.'/'.$each);
}
preg_match_all( '/\$this\-\>phrase\((.*?)\)/si', $cont, $matches );
$phrases_array = $this->get_phrases();
foreach($matches[1] as $value) {
$value=trim($value);
//if not variable
if(substr($value, 0, 1) != '$')
{
$sanitized_value = preg_replace("/[\"\']/", "", $value);
$phrases_array[$sanitized_value] = $sanitized_value;
}
}
return $phrases_array;
}
public function shortcodes_table($name, $array)
{
/*======= example ========
$this->shortcodes_table( "breadcrumbs", [
[ 'id', '', __('Post ID (you can ignore that parameter if you want to get for current post)', 'breadcrumbs-shortcode') ],
[ 'delimiter', 'hello', __('Your desired delimiter', 'breadcrumbs-shortcode') ],
]);
*/
?>
application/x-gzip
// [rar] => application/rar
// [7z] => application/x-7z-compressed
return $mime_types;
}
//move uploaded addon to it's folder
public function wp_handle_upload_filter( $array=['file' => 'path/to/wp-content/uploads/2018/12/example.ext', 'url' => 'https://.....example.ext', 'type' => 'application/zip'], $action= 'sideload|upload' )
{
$file = $array['file'];
if($array['type']=="application/zip" || $array['type']=="application/x-zip")
{
$filename = basename($file);
$found = false;
$found_files=[];
if (function_exists('zip_open'))
{
$zip = zip_open($file);
if (is_resource($zip))
{
while ($zip_entry = zip_read($zip))
{
$found_files[]=zip_entry_name($zip_entry);
//if (zip_entry_open($zip, $zip_entry))
//{
//echo zip_entry_read($zip_entry);
//zip_entry_close($zip_entry);
//}
}
zip_close($zip);
}
}
elseif (class_exists('\ZipArchive'))
{
$za = new ZipArchive();
$za->open($file);
for( $i = 0; $i < $za->numFiles; $i++ ){
$stat = $za->statIndex( $i );
$found_files[] = basename( $stat['name'] ) ;
}
}
//elseif( stripos($filename, $this->pro_file_part) !== false)
//{
// $found = true;
//}
//if contains
if(!empty($found_files))
{
foreach(array_filter($found_files) as $each)
{
if( stripos($each, $this->addon_namepart.'/'.$this->slug)!==false)
{
$found = true;
}
}
}
if($found)
{
$this->unzip($file, $this->addons_dir);
$this->move_folder_contents($this->addons_dir.'/'. $this->addon_namepart, $this->addons_dir);
$this->rmdir_recursive($this->addons_dir.'/'. $this->addon_namepart);
$need_space = stripos($_SERVER['REQUEST_URI'], 'upload.php') !== false ? ' ' : '';
return ['error'=> $need_space."Thank You ⭐ Addon has been installed, you can activate it with the key !"];
}
}
return $array;
}
public function move_folder_contents($from, $to)
{
foreach( glob($from ."/*") as $each)
{
$target=$to."/".basename($each);
if(is_dir($target)) {
//$this->rmdir_recursive($target);
}
elseif(is_file($target))
{
@unlink($target);
//rename($each, $target);
}
}
}
public function ajax_backend_call()
{
if(isset($_POST['action']) && $_POST['action']==$this->plugin_slug_u .'_all')
{
if(isset($_POST['PRO_check_key'])){
echo $this->license_status($_POST['PRO_check_key'], "activate");
}
elseif(isset($_POST['PRO_save_results'])){
}
elseif(method_exists($this, 'backend_call')){
$this->backend_call( sanitize_key($_POST['act']) );
}
wp_die();
}
exit( __('Unknown-action') );
}
public function insert_code_in_file($filepath, $replace_what, $replace_with)
{
if(is_admin())
{
if(file_exists($filepath))
{
$content= file_get_contents($filepath);
if(stripos($content, $replace_with) === false) //if it doesnt contain
{
file_put_contents( $filepath, str_replace($replace_what, $replace_with, $content) );
}
}
}
}
public function admin_scripts($hook) //i.e. edit.php
{
if($this->is_this_settings_page()){
$this->admin_scripts_out($hook);
}
}
public function admin_scripts_out($hook) //i.e. edit.php
{
$where='admin';
$this->register_stylescript($where, 'script', 'jquery');
//jquery ui
$this->register_stylescript($where, 'style', 'wp-jquery-ui-core');
$this->register_stylescript($where, 'script', 'jquery-ui-core');
$this->register_stylescript($where, 'script', 'jquery-effects-core');
$this->register_stylescript($where, 'style', 'ui-css', 'https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css', false, '1.1');
$this->register_stylescript($where, 'style', 'wp-jquery-ui-dialog');
$this->register_stylescript($where, 'script', 'jquery-ui-dialog');
$this->register_stylescript($where, 'script', 'jquery-ui-tooltip');
// spin.js
//$this->register_stylescript($where, 'script', 'spin', 'https://cdnjs.cloudflare.com/ajax/libs/spin.js/2.3.2/spin.min.js', ['jquery'], '2.3.2', true);
// touch-punch.js
//$this->register_stylescript($where, 'script', 'touch-punch', 'https://cdnjs.cloudflare.com/ajax/libs/jqueryui-touch-punch/0.2.3/jquery.ui.touch-punch.min.js', ['jquery'], '0.2.3', true );
//add_action('admin_footer', function() { } );
}
public function register_stylescript($admin_or_wp, $type, $handle=false, $url=false, $dependant=null, $version=false, $target=false)
{
add_action( $admin_or_wp.'_enqueue_scripts', function() use($type, $handle, $url, $dependant, $version, $target) {
$this->enqueue($type, $handle, $url, $dependant, $version, $target);
}
);
}
public function enqueue($type, $handle=false, $url=false, $dependant=null, $version=false, $target=false)
{
//lets allow shorthanded start
$localstart = 'assets';
if( substr($url,0, strlen($localstart) ) == $localstart )
$url = $this->plugin_URL. $url;
if ( ! call_user_func("wp_".$type."_is", $handle, "registered" ) ){
call_user_func("wp_register_".$type, $handle, $url, $dependant, $version, $target ); //,'jquery-migrate'
}
if ( ! call_user_func("wp_".$type."_is", $handle, "enqueued" ) ){
call_user_func("wp_enqueue_".$type, $handle);
}
}
public function add_localscript($handle, $string){
$is_js = stripos($string,'';
$this->reload_without_query();
}
}
public function add_default_uninstall(){
if( is_admin() && !$this->is_development)
{
$wp_uninstall_file = $this->plugin_DIR.'/uninstall.php';
if( !file_exists($wp_uninstall_file) )
{
$content=
'<'.'?php
// If uninstall not called from WordPress, then exit
if ( ! defined( "WP_UNINSTALL_PLUGIN" ) ) {
exit;
}
$lib = dirname(__DIR__)."/'.basename(__FILE__).'";
if(file_exists($lib)){
//@unlink($lib);
}';
file_put_contents($wp_uninstall_file, $content);
}
}
}
// ========= my functions for PRO plugins ========== //
public function addon_path()
{
return WP_PLUGIN_DIR .'/_addons/'.$this->slug .'-addon/addon.php';
}
public function addon_exists()
{
return (file_exists($this->addon_path()));
}
public function load_pro()
{
if ($this->is_pro)
{
if ($this->is_pro_legal)
{
$puvox_last_class = $this;
if($this->addon_exists())
include_once($this->addon_path());
}
}
}
public function check_if_pro_plugin()
{
$this->is_pro = null;
$this->is_pro_legal = null;
if( $this->static_settings['has_pro_version'] ){
//$this->has_pro_version = true; // it is price of plugin
$ar= $this->get_license();
$this->is_pro = $ar['status'];
$this->is_pro_legal = $ar['legal'];
}
if(is_admin())
{
if ($this->is_pro)
{
if (!$this->is_pro_legal)
{
add_action('network_admin_notices', [$this, 'admin_error_notice_pro'] );
add_action('admin_notices', [$this, 'admin_error_notice_pro'] );
}
else{
$this->pro_check_once_in_a_while();
}
}
}
$this->addons_dir = WP_PLUGIN_DIR.'/_addons'; //wp_plugins_dir();
}
public function license_keyname(){
return $this->plugin_slug_u ."_l_key";
}
public function get_license($key=false){
$def_array = [
'status' => false,
'legal' => false,
'key' => '',
'last_error'=>''
];
$license_arr = get_site_option($this->license_keyname(), $def_array );
return ($key ? $license_arr[$key] : $license_arr);
}
public function update_license($val, $val1=false){
if(is_array($val)){
$array = $val;
}
else{
$array= $this->get_license();
$array[$val]=$val1;
}
update_site_option( $this->license_keyname(), $array );
}
public function license_answer($key, $type="check/or/activate")
{
$this->info_arr = ['key' => $key] + ['siteurl'=>home_url(), 'plugin_slug'=>$this->slug ] + $this->pluginvars() + $this->opts;
$answer =
wp_remote_retrieve_body(
wp_remote_post($this->static_settings['purchase_check'].$type,
[
'method' => 'POST',
'timeout' => 25,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'headers' => [],
'body' => $this->info_arr,
'cookies' => []
]
)
);
return $answer;
}
public function license_status($license, $type="check/or/activate")
{
$key = sanitize_text_field($license);
$answer = $this->license_answer($key, $type);
if(!$this->is_JSON_string($answer)){
$result = [];
$result['error'] = $answer;
}
else{
$result = json_decode($answer, true);
}
//
if(isset($result['valid'])){
if($result['valid']){
$ar['status']= true;
$ar['legal']= true;
$ar['key']= $key;
$ar['last_error']= '';
$this->update_license($ar);
}
else {
//
$this->update_license( 'legal', false );
$this->update_license( 'last_error', json_encode($result['response']) );
$result['error'] = json_encode($result['response']);
}
}
else{
$result['error'] = $answer;
$this->log('Error while calling to vendor', $result['error']);
}
return json_encode($result);
}
public function pro_check_once_in_a_while( $time_length = 864000 )
{
$name= '`_last_license_check';
$value= $this->get_transient_CHOSEN($name);
if( !$value || time() - $value > $time_length )
{
$lic = $this->get_license();
$res= $this->license_status($lic['key'], 'activate');
$this->update_transient_CHOSEN($name, time() );
}
}
public function unregistered_pro() { return $this->static_settings['has_pro_version'] && !$this->is_pro_legal; }
public function admin_error_notice_pro(){ ?>
%s is invalidated, so it\'s PRO functionality has been disabled.', $this->static_settings['Name']) );?>
unregistered_pro()){
$res= 'data-pro-overlay="pro_overlay"';
if($echo) echo $res;
else return $res;
//echo '
';
}
}
public function purchase_pro_block(){
if ( !$this->static_settings['has_pro_version']) return;
if ( $this->is_pro_legal ) return;
?>
is_pro )
{
if ( !$this->addon_exists() )
{ ?>
( )
is_pro_legal)
{
$need_to_enter_key=true;
?>
( . ( %s ', $this->get_license('last_error') ) ); ?> ) )
addon_exists()) { ?>
static_settings['has_pro_version'];?>$
( )
plugin_scripts();
}
public function plugin_scripts(){
?>