class_name = sanitize_title( get_class($this) );
// get plugin slug based on directory
if( empty( $this->strPluginSlug ) ) {
$this->strPluginSlug = basename( dirname( __FILE__ ) );
}
if( empty( $this->strPluginName ) ) {
$this->strPluginName = $this->strPluginSlug;
}
if( empty( $this->strPluginPath ) ) {
$this->strPluginPath = basename(dirname(__FILE__)).'/plugin.php';
if( !file_exists( WP_PLUGIN_DIR.'/'.$this->strPluginPath ) ) {
$this->strPluginPath = basename(dirname(__FILE__)).'/'.$this->strPluginSlug.'.php';
}
}
add_action( 'admin_enqueue_scripts', array( $this, 'pointers_enqueue' ) );
// store cookie for each dimissed notice first
add_action( 'wp_ajax_fv_foliopress_ajax_pointers', array( $this, 'pointers_ajax_cookie' ), 0 );
// TODO: What about the actual processing of the Ajax? Does it have to be in the plugin for real?
add_action( 'wp_ajax_fv_foliopress_ajax_pointers', array( $this, 'pointers_ajax' ), 999 );
add_filter( 'plugins_api_result', array( $this, 'changelog_filter' ), 5, 3 );
add_filter( 'pre_set_transient_'.$this->strPluginSlug . '_license', array( $this, 'object_cache_disable' ) );
add_filter( 'pre_transient_'.$this->strPluginSlug . '_license', array( $this, 'object_cache_disable' ) );
add_action( 'delete_transient_'.$this->strPluginSlug . '_license', array( $this, 'object_cache_disable' ) );
add_action( 'set_transient_'.$this->strPluginSlug . '_license', array( $this, 'object_cache_disable' ) );
add_filter( 'transient_'.$this->strPluginSlug . '_license', array( $this, 'object_cache_enable' ) );
add_action( 'deleted_transient_'.$this->strPluginSlug . '_license', array( $this, 'object_cache_disable' ) );
//add_action('admin_head', array($this, 'welcome_screen_remove_menus'));
}
public function get_filesystem() {
if ( ! class_exists( 'WP_Filesystem_Direct' ) ) {
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php';
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php';
}
return new WP_Filesystem_Direct( new StdClass() );
}
public function log( $message = '' ) {
if ( $this->log_file && $this->log_is_writable ) {
$fs = $this->get_filesystem();
$message = gmdate( 'Y-n-d H:i:s' ) . ' - ' . $message . "\r\n";
$content = $this->log_file_get_content();
$content .= $message;
$fs->put_contents( $this->log_file, $content, FILE_APPEND );
$fs->chmod( $this->log_file, 0664 );
}
}
public function log_file_delete() {
$fs = $this->get_filesystem();
if ( $this->log_file && $this->log_is_writable ) {
return $fs->delete( $this->log_file );
}
return false;
}
public function log_file_get_content() {
$fs = $this->get_filesystem();
if ( $this->log_file && $this->log_is_writable ) {
return $fs->get_contents( $this->log_file );
}
return false;
}
public function log_file_settings_field() {
if ( ! empty( $this->log_file ) && $this->log_is_writable ) : ?>
Logging into log_file ); ?>. Disabling Debug will delete the log file.
log_file ) && ! $this->log_is_writable ) : ?>
Unable to write the log file.
Log file failed to create for unknown reasons.
get_filesystem();
if ( ! empty( $fs ) ) {
$upload_dir = wp_upload_dir();
$filename = $this->strPluginSlug . '-debug-' . wp_hash( home_url( '/' ) ) . '.log';
$this->log_file = trailingslashit( $upload_dir['basedir'] ) . $filename;
$this->log_file_url = trailingslashit( $upload_dir['baseurl'] ) . $filename;
if ( $fs->is_writable( $upload_dir['basedir'] ) ) {
$this->log_is_writable = true;
$content = $this->log_file_get_content();
if ( empty( $content ) ) {
$this->log( "Log file created." );
}
}
}
}
function object_cache_disable($value=null){
global $_wp_using_ext_object_cache;
$this->_wp_using_ext_object_cache_prev = $_wp_using_ext_object_cache;
$_wp_using_ext_object_cache = false;
return $value;
}
function object_cache_enable($value=null){
global $_wp_using_ext_object_cache;
$_wp_using_ext_object_cache = $this->_wp_using_ext_object_cache_prev;
return $value;
}
function http_request_args( $params ) {
$aArgs = func_get_args();
$url = $aArgs[1];
if( stripos($url,'foliovision.com') === false ) {
return $params;
}
add_filter( 'https_ssl_verify', '__return_false' );
return $params;
}
function is_min_wp( $version ) {
return version_compare( $GLOBALS['wp_version'], $version. 'alpha', '>=' );
}
public static function get_plugin_path( $slug ){
$aPluginSlugs = get_transient('plugin_slugs');
$aPluginSlugs = is_array($aPluginSlugs) ? $aPluginSlugs : array( $slug.'/'.$slug.'.php');
$aActivePlugins = get_option('active_plugins');
$aInactivePlugins = array_diff($aPluginSlugs,$aActivePlugins);
if( !$aPluginSlugs )
return false;
foreach( $aActivePlugins as $item ){
if( stripos($item,$slug.'.php') !== false && !is_wp_error(validate_plugin($item)) )
return $item;
}
$sPluginFolder = plugin_dir_path( dirname( dirname(__FILE__) ) );
foreach( $aInactivePlugins as $item ){
if( stripos($item,$slug.'.php') !== false && file_exists($sPluginFolder.$item) )
return $item;
}
return false;
}
private function check_license_remote( $args = array() ) {
if( !isset($this->strPluginSlug) || empty($this->strPluginSlug)
|| !isset($this->version) || empty($this->version)
|| !isset($this->license_key) || $this->license_key === FALSE ) {
return false;
}
$defaults = array(
'action' => 'check',
'core_ver' => false,
'key' => !empty( $this->license_key) ? $this->license_key : false,
'plugin' => $this->strPluginSlug,
'type' => home_url(),
'version' => $this->version,
);
$body_args = wp_parse_args( $args, $defaults );
$post = array(
'body' => $body_args,
'timeout' => 20,
'user-agent' => $this->strPluginSlug.'-'.$this->version
);
$resp = wp_remote_post( 'https://license.foliovision.com/?fv_remote=true', $post );
if( !is_wp_error($resp) && isset($resp['body']) && $resp['body'] && $data = json_decode( preg_replace( '~[\s\s]*?
Try again' ), $request->get_error_message() ); }else{ $res = unserialize( preg_replace( '~^/\*[\s\S]*?\*/\s+~', '', $request['body'] ) ); if( $res === false ) $res = new WP_Error( 'plugins_api_failed', __( 'An unknown error occurred' ), $request['body'] ); } return $res; } public function plugin_update_message() { if( $this->readme_URL ) { $data = $this->get_readme_url_remote( $this->readme_URL ); if( $data ) { $matches = null; /// not sure if this works for more than one last changelog //if (preg_match('~==\s*Changelog\s*==\s*=\s*[0-9.]+\s*=(.*)(=\s*[0-9.]+\s*=|$)~Uis', $data, $matches)) { if (preg_match('~==\s*Upgrade Notice\s*==\s*=\s*[0-9.]+\s*=(.*)(=\s*[0-9.]+\s*=|$)~Uis', $data, $matches)) { $changelog = (array) preg_split('~[\r\n]+~', trim($matches[1])); $ul = false; foreach ($changelog as $index => $line) { if (preg_match('~^\s*\*\s*~', $line) && 1<0 ) { if (!$ul) { //echo '
' .$strong. htmlspecialchars($line) .$strongEnd. '
'; } } if ($ul) { $changelogOut .= ''; } $changelogOut .= ''; } $res = (object) array( 'name' => $plugin_data['Name'], 'slug' => false, 'version' => $version, 'author' => $plugin_data['Author'], 'requires' => $pluginReq, 'tested' => $pluginUpto, 'homepage' => $plugin_data['PluginURI'], 'sections' => array ( 'support' => 'Use support forum at foliovison.com/support', 'changelog' => $changelogOut, ), 'donate_link' => NULL ); return $res; } //notification boxes function pointers_init_scripts() { if( !isset($this->pointer_boxes) || !$this->pointer_boxes ) { return; } ?> pointers_get_cookie(); foreach( $this->pointer_boxes AS $key => $args ) { // Some users are experiencing issues when dismissing the notices // So we use cookies as a backup to not show the same notice twice if( !empty($cookie[$key]) ) { continue; } $nonce = wp_create_nonce( $key ); $args = wp_parse_args( $args, array( 'button1' => false, // req 'button2' => false, 'function1' => $this->class_name.'_store_answer("'.$key.'", "' . ( ! empty( $args['value1'] ) ? esc_js( $args['value1'] ) : 'true' ) . '","' . $nonce . '")', 'function2' => $this->class_name.'_store_answer("'.$key.'", "false","' . $nonce . '")', 'heading' => false, // req 'id' => false, // req 'content' => false, // req 'position' => array( 'edge' => 'top', 'align' => 'center' ), ) ); extract($args); $html = ''.$content.'
'; } ?> check_license_remote( array('action' => 'key_update') ); if( isset($data->domain) ) { // todo: test if( $data->domain && $data->key && stripos( home_url(), $data->domain ) !== false ) { $this->license_key = $data->key; do_action( $this->strPluginSlug.'_admin_key_update', $this->license_key ); $this->change_transient_expiration( $this->strPluginSlug."_license", 1 ); // change the expiration to license renew by: $this->setLicenseTransient( true ); //fv_wp_flowplayer_delete_extensions_transients(5); return $data->key; } } else if( isset($data->expired) && $data->expired && isset($data->message) ){ update_option( 'fv_'.$this->strPluginSlug.'_deferred_notices', $data->message ); return false; } else { $message = 'FV Player License upgrade failed - please check if you are running the plugin on your licensed domain.'; update_option( 'fv_'.$this->strPluginSlug.'_deferred_notices', $message ); return false; } } function pro_install_talk( $content, $url ) { $content = preg_replace( '~As a license holder, we would like to automatically install our Pro extension for you.
', $content ); $content = preg_replace( '~(]*?type="submit"[^>]*?>)~', '$1 Skip the Pro addon install', $content ); return $content; } //search for plugin path with {slug}.php function get_extension_path( $slug ){ $aPluginSlugs = get_transient('plugin_slugs'); $aPluginSlugs = is_array($aPluginSlugs) ? $aPluginSlugs : array( 'fv-player-pro/fv-player-pro.php'); $aActivePlugins = get_option('active_plugins'); $aInactivePlugins = array_diff($aPluginSlugs,$aActivePlugins); if( !$aPluginSlugs ) return false; foreach( $aActivePlugins as $item ){ if( stripos($item,$slug.'.php') !== false ) return $item; } foreach( $aInactivePlugins as $item ){ if( stripos($item,$slug.'.php') !== false ) return $item; } return false; } public static function install_form_text( $html, $name ) { $tag = stripos($html,'') !== false ? 'h3' : 'h2'; $html = preg_replace( '~<'.$tag.'.*?'.$tag.'>~', '<'.$tag.'>'.$name.' auto-installation'.$tag.'>', $html ); $html = preg_replace( '~(]*?type="submit"[^>]*?>)~', '$1 Skip the '.$name.' install', $html ); return $html; } public static function install_plugin( $name, $plugin_package, $plugin_basename, $download_url, $settings_url, $option, $nonce ) { // 'FV Player Pro', 'fv-player-pro', '/wp-admin/admin.php?page=fvplayer', download URL (perhaps from the license), settings URL (use admin_url(...), should also contain some GET which will make it install the extension if present) and option where result message should be stored and a nonce which should be passed global $hook_suffix; $plugin_path = self::get_plugin_path( str_replace( '_', '-', $plugin_package ) ); if( !defined('PHPUnitTestMode') && $plugin_path ) { $result = activate_plugin( $plugin_path, $settings_url ); if ( is_wp_error( $result ) ) { update_option( $option, $name.' extension activation error: '.$result->get_error_message() ); return false; } else { update_option( $option, $name.' extension activated' ); return true; // already installed } } $plugin_basename = $plugin_path ? $plugin_path : $plugin_basename; $url = wp_nonce_url( $settings_url, $nonce, 'nonce_'.$nonce ); set_current_screen(); ob_start(); if ( false === ( $creds = request_filesystem_credentials( $url, '', false, false, false ) ) ) { $form = ob_get_clean(); include( ABSPATH . 'wp-admin/admin-header.php' ); echo self::install_form_text($form, $name); include( ABSPATH . 'wp-admin/admin-footer.php' ); die; } if ( ! WP_Filesystem( $creds ) ) { ob_start(); request_filesystem_credentials( $url, $method, true, false, false ); $form = ob_get_clean(); include( ABSPATH . 'wp-admin/admin-header.php' ); echo self::install_form_text($form, $name); include( ABSPATH . 'wp-admin/admin-footer.php' ); die; } require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; $result = true; if( !$plugin_path || is_wp_error(validate_plugin($plugin_basename)) ) { $sTaskDone = $name.__( ' extension installed successfully!', 'fv-player' ); echo ''; wp_cache_flush(); if ( is_wp_error( $objInstaller->skin->result ) ) { update_option( $option, $name.__( ' extension install failed - ', 'fv-player' ) . $objInstaller->skin->result->get_error_message() ); $result = false; } else { if ( $objInstaller->plugin_info() ) { $plugin_basename = $objInstaller->plugin_info(); } $activate = activate_plugin( $plugin_basename ); if ( is_wp_error( $activate ) ) { update_option( $option, $name.__( ' extension install failed - ', 'fv-player' ) . $activate->get_error_message()); $result = false; } } } else if( $plugin_path ) { $sTaskDone = $name.__( ' extension upgraded successfully!', 'fv-player' ); echo ''; // explanation: extra closing tag just to be safe (in case of "The plugin is at the latest version.") wp_cache_flush(); if ( is_wp_error( $objInstaller->skin->result ) ) { update_option( $option, $name.' extension upgrade failed - '.$objInstaller->skin->result->get_error_message() ); $result = false; } else { if ( $objInstaller->plugin_info() ) { $plugin_basename = $objInstaller->plugin_info(); } $activate = activate_plugin( $plugin_basename ); if ( is_wp_error( $activate ) ) { update_option( $option, $name.' Pro extension upgrade failed - '.$activate->get_error_message() ); $result = false; } } } if( $result ) { update_option( $option, $sTaskDone ); echo ""; } return $result; } function install_pro_version( $plugin_package = false, $target_url = false ) { $aPluginInfo = get_transient( $this->strPluginSlug.'_license' ); if( $plugin_package && isset( $aPluginInfo->{$plugin_package} ) ) { $plugin_basename = $aPluginInfo->{$plugin_package}->slug; $download_url = $aPluginInfo->{$plugin_package}->url; } else { $plugin_basename = file_exists( WP_PLUGIN_DIR.'/'.$this->strPluginSlug.'/plugin.php' ) ? $this->strPluginSlug.'/plugin.php' : $this->strPluginSlug.'/'.$this->strPluginSlug.'.php'; $download_url = $aPluginInfo->url; $plugin_package = $this->strPluginSlug; } $aInstalled = get_option( $this->strPluginSlug.'_extension_install', array() ); $aInstalled = array_merge( $aInstalled, array( $plugin_package => false ) ); update_option( $this->strPluginSlug.'_extension_install', $aInstalled ); $sPluginBasenameReal = $this->get_extension_path( str_replace( '_', '-', $plugin_package ) ); $plugin_basename = $sPluginBasenameReal ? $sPluginBasenameReal : $plugin_basename; $url = ( $target_url ) ? $target_url : site_url().'/wp-admin/plugins.php'; $url = wp_nonce_url( $url ); set_current_screen(); ob_start(); if ( false === ( $creds = request_filesystem_credentials( $url, '', false, false, false ) ) ) { $form = ob_get_clean(); include( ABSPATH . 'wp-admin/admin-header.php' ); echo wp_kses_post( $this->pro_install_talk( $form, $target_url ) ); include( ABSPATH . 'wp-admin/admin-footer.php' ); die; } if ( ! WP_Filesystem( $creds ) ) { ob_start(); request_filesystem_credentials( $url, $method, true, false, false ); $form = ob_get_clean(); include( ABSPATH . 'wp-admin/admin-header.php' ); echo wp_kses_post( $this->pro_install_talk( $form, $target_url ) ); include( ABSPATH . 'wp-admin/admin-footer.php' ); die; } require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; if( !$sPluginBasenameReal || is_wp_error(validate_plugin($plugin_basename)) ) { $sTaskDone = $this->strPluginName.' has been installed!'; echo ''; wp_cache_flush(); if ( is_wp_error( $objInstaller->skin->result ) ) { update_option( $this->strPluginSlug.'_deferred_notices', $this->strPluginName.' install failed - '. $objInstaller->skin->result->get_error_message() ); $bResult = false; } else { if ( $objInstaller->plugin_info() ) { $plugin_basename = $objInstaller->plugin_info(); } $activate = activate_plugin( $plugin_basename ); if ( is_wp_error( $activate ) ) { update_option( $this->strPluginSlug.'_deferred_notices', $this->strPluginName.' install failed - '. $activate->get_error_message() ); $bResult = false; } } } else if( $sPluginBasenameReal ) { $sTaskDone = $this->strPluginName.' upgraded successfully!'; echo ''; // explanation: extra closing tag just to be safe (in case of "The plugin is at the latest version.") wp_cache_flush(); if ( is_wp_error( $objInstaller->skin->result ) ) { update_option( $this->strPluginSlug.'_deferred_notices', $this->strPluginName.' extension upgrade failed - '.$objInstaller->skin->result->get_error_message() ); $bResult = false; } else { if ( $objInstaller->plugin_info() ) { $plugin_basename = $objInstaller->plugin_info(); } $activate = activate_plugin( $plugin_basename ); if ( is_wp_error( $activate ) ) { update_option( $this->strPluginSlug.'_deferred_notices', $this->strPluginName.' extension upgrade failed - '.$activate->get_error_message() ); $bResult = false; } } } if( empty( $bResult ) ) { update_option( $this->strPluginSlug.'_deferred_notices', $sTaskDone ); $bResult = true; } $aInstalled = array_merge( $aInstalled, array( $plugin_package => $bResult ) ); update_option( $this->strPluginSlug.'_extension_install', $aInstalled ); return $bResult; } }