File: /var/www/virtual/mariaellingsen.com/htdocs/wp-content/plugins/soliloquy/soliloquy.php
<?php
/**
* Plugin Name: Soliloquy
* Plugin URI: https://soliloquywp.com
* Description: Soliloquy is the best responsive WordPress slider plugin.
* Author: Soliloquy Team
* Author URI: https://soliloquywp.com
* Version: 2.7.2
* Text Domain: soliloquy
* Domain Path: languages
*
* @package SoliloquyWP
*
* Soliloquy is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* any later version.
*
* Soliloquy is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Soliloquy. If not, see <http://www.gnu.org/licenses/>.
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Main plugin class.
*
* @since 1.0.0
*
* @package Soliloquy
* @author SoliloquyWP Team <support@soliloquywp.com>
*/
class Soliloquy {
/**
* Holds the class object.
*
* @since 1.0.0
*
* @var object
*/
public static $instance;
/**
* Plugin version, used for cache-busting of style and script file references.
*
* @since 1.0.0
*
* @var string
*/
public $version = '2.7.2';
/**
* The name of the plugin.
*
* @since 1.0.0
*
* @var string
*/
public $plugin_name = 'Soliloquy';
/**
* Unique plugin slug identifier.
*
* @since 1.0.0
*
* @var string
*/
public $plugin_slug = 'soliloquy';
/**
* Plugin file.
*
* @since 1.0.0
*
* @var string
*/
public $file = __FILE__;
/**
* Primary class constructor.
*
* @since 1.0.0
*/
public function __construct() {
$this->setup_constants();
// Fire a hook before the class is setup.
do_action( 'soliloquy_pre_init' );
// Load the plugin textdomain.
add_action( 'plugins_loaded', array( $this, 'load_plugin_textdomain' ) );
// Load the plugin widget.
add_action( 'widgets_init', array( $this, 'widget' ) );
// Load the plugin.
add_action( 'init', array( $this, 'init' ), 0 );
}
/**
* Loads the plugin textdomain for translation.
*
* @since 1.0.0
*/
public function load_plugin_textdomain() {
load_plugin_textdomain( $this->plugin_slug, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
/**
* Registers the Soliloquy widget.
*
* @since 1.0.0
*/
public function widget() {
register_widget( 'Soliloquy_Widget' );
}
/**
* Loads the plugin into WordPress.
*
* @since 1.0.0
*/
public function init() {
// Run hook once Soliloquy has been initialized.
do_action( 'soliloquy_init' );
// Load admin only components.
if ( is_admin() ) {
$this->require_admin();
$this->require_updater();
}
// Load global components.
$this->require_global();
}
public function is_soliloquy_page() {
if ( ! is_admin() ) {
return false;
}
if ( ! function_exists( 'get_current_screen' ) ) {
return false;
}
$current_screen = get_current_screen();
if ( ! isset( $current_screen->post_type ) || 'soliloquy' !== $current_screen->post_type ) {
return false;
}
return true;
}
/**
* Loads all admin related files into scope.
*
* @since 1.0.0
*/
public function require_admin() {
require plugin_dir_path( __FILE__ ) . 'includes/admin/license_check.php';
require plugin_dir_path( __FILE__ ) . 'includes/admin/ajax.php';
require plugin_dir_path( __FILE__ ) . 'includes/admin/common.php';
require plugin_dir_path( __FILE__ ) . 'includes/admin/editor.php';
require plugin_dir_path( __FILE__ ) . 'includes/admin/export.php';
require plugin_dir_path( __FILE__ ) . 'includes/admin/import.php';
require plugin_dir_path( __FILE__ ) . 'includes/admin/license.php';
require plugin_dir_path( __FILE__ ) . 'includes/admin/media-view.php';
require plugin_dir_path( __FILE__ ) . 'includes/admin/metaboxes.php';
require plugin_dir_path( __FILE__ ) . 'includes/admin/posttype.php';
require plugin_dir_path( __FILE__ ) . 'includes/admin/settings.php';
require plugin_dir_path( __FILE__ ) . 'includes/admin/addons.php';
require plugin_dir_path( __FILE__ ) . 'includes/admin/vimeo.php';
require plugin_dir_path( __FILE__ ) . 'includes/admin/blocks.php';
require plugin_dir_path( __FILE__ ) . 'includes/admin/review.php';
require plugin_dir_path( __FILE__ ) . 'includes/admin/notifications.php';
}
/**
* Loads Admin Partial
*
* @since 2.5.0
*
* @access public
* @param string $template Template to load.
* @param array $data (default: array()).
* @return bool
*/
public function load_admin_partial( $template, $data = array() ) {
$dir = trailingslashit( plugin_dir_path( __FILE__ ) . 'includes/admin/partials' );
if ( file_exists( $dir . $template ) ) {
require_once $dir . $template;
return true;
}
return false;
}
/**
* Loads all updater related files and functions into scope.
*
* @since 1.0.0
*
* @return null Return early if the license key is not set or there are key errors.
*/
public function require_updater() {
// Retrieve the license key. If it is not set, return early.
$key = $this->get_license_key();
if ( ! $key ) {
return;
}
// If there are any errors with the key itself, return early.
if ( $this->get_license_key_errors() ) {
return;
}
// Load the updater class.
require plugin_dir_path( __FILE__ ) . 'includes/admin/updater.php';
// Go ahead and initialize the updater.
$args = array(
'plugin_name' => $this->plugin_name,
'plugin_slug' => $this->plugin_slug,
'plugin_path' => plugin_basename( __FILE__ ),
'plugin_url' => trailingslashit( WP_PLUGIN_URL ) . $this->plugin_slug,
'remote_url' => 'http://soliloquywp.com/',
'version' => $this->version,
'key' => $key,
);
$soliloquy_updater = new Soliloquy_Updater( $args );
// Fire a hook for Addons to register their updater since we know the key is present.
do_action( 'soliloquy_updater', $key );
}
/**
* Loads all global files into scope.
*
* @since 1.0.0
*/
public function require_global() {
require_once plugin_dir_path( __FILE__ ) . 'includes/global/common.php';
require_once plugin_dir_path( __FILE__ ) . 'includes/global/truncateHtml.php';
require_once plugin_dir_path( __FILE__ ) . 'includes/global/legacy.php';
require_once plugin_dir_path( __FILE__ ) . 'includes/global/posttype.php';
require_once plugin_dir_path( __FILE__ ) . 'includes/global/shortcode.php';
require_once plugin_dir_path( __FILE__ ) . 'includes/global/widget.php';
require_once plugin_dir_path( __FILE__ ) . 'includes/global/tracking.php';
( new Soliloquy_Tracking() )->hooks();
}
/**
* Returns a slider based on ID.
*
* Honors the slider post's status (publish, draft etc)
*
* @since 1.0.0
*
* @param int $id The slider ID used to retrieve a slider.
* @return array|bool Array of slider data or false if none found.
*/
public function get_slider( $id ) {
$slider = get_transient( '_sol_cache_' . $id );
// Attempt to return the transient first, otherwise generate the new query to retrieve the data.
if ( false === $slider ) {
$slider = $this->_get_slider( $id );
if ( $slider ) {
set_transient( '_sol_cache_' . $id, $slider, DAY_IN_SECONDS );
}
}
// Check status of slider.
if ( isset( $slider['status'] ) ) {
if ( in_array( $slider['status'], array( 'pending', 'draft', 'trash' ), true ) ) {
// Public site, slider is set to draft, so don't display it.
return false;
}
}
// Return the slider data.
return $slider;
}
/**
* Internal method that returns a slider based on ID.
*
* Ignores the slider post's status (publish, draft etc), so can be used for admin previews etc.
*
* @since 1.0.0
*
* @param int $id The slider ID used to retrieve a slider.
* @return array|bool Array of slider data or false if none found.
*/
// @codingStandardsIgnoreStart
public function _get_slider( $id ) {
// @codingStandardsIgnoreEnd
// check if the current user can edit others posts if status is draft.
$slider = get_post( $id );
if ( in_array( $slider->post_status, array( 'pending', 'draft', 'trash' ), true ) && ! current_user_can( 'edit_others_posts' ) ) {
return false;
}
return get_post_meta( $id, '_sol_slider_data', true );
}
/**
* Returns a slider based on slug.
*
* @since 1.0.0
*
* @param string $slug The slider slug used to retrieve a slider.
* @return array|bool Array of slider data or false if none found.
*/
public function get_slider_by_slug( $slug ) {
$slider = get_transient( '_sol_cache_' . $slug );
// Attempt to return the transient first, otherwise generate the new query to retrieve the data.
if ( false === $slider ) {
$slider = $this->_get_slider_by_slug( $slug );
if ( $slider ) {
set_transient( '_sol_cache_' . $slug, $slider, DAY_IN_SECONDS );
}
}
// Check status of slider.
if ( isset( $slider['status'] ) ) {
if ( 'draft' === $slider['status'] || 'pending' === $slider['status'] ) {
return;
}
}
// Return the slider data.
return $slider;
}
/**
* Internal method that returns a slider based on slug.
*
* @since 1.0.0
*
* @param string $slug The slider slug used to retrieve a slider.
* @return array|bool Array of slider data or false if none found.
*/
// @codingStandardsIgnoreStart
public function _get_slider_by_slug( $slug ) {
// @codingStandardsIgnoreEnd
$sliders = $this->get_sliders();
if ( ! $sliders ) {
return false;
}
// Loop through the sliders to find a match by slug.
$ret = false;
foreach ( $sliders as $data ) {
if ( empty( $data['config']['slug'] ) ) {
continue;
}
if ( $data['config']['slug'] === $slug ) {
$ret = $data;
break;
}
}
// Return the slider data.
return $ret;
}
/**
* Returns all sliders created on the site.
*
* @since 1.0.0
*
* @param bool $skip_empty Skip empty sliders.
* @param bool $ignore_cache Ignore Transient cache.
* @return array|bool Array of slider data or false if none found.
*/
public function get_sliders( $skip_empty = true, $ignore_cache = false ) {
$sliders = get_transient( '_sol_cache_all' );
// Attempt to return the transient first, otherwise generate the new query to retrieve the data.
if ( $ignore_cache || false === $sliders ) {
$sliders = $this->_get_sliders( $skip_empty );
if ( $sliders ) {
set_transient( '_sol_cache_all', $sliders, DAY_IN_SECONDS );
}
}
// Return the slider data.
return $sliders;
}
/**
* Internal method that returns all sliders created on the site.
*
* @since 1.0.0
*
* @param bool $skip_empty Skip Empty Sliders.
* @return array|bool Array of slider data or false if none found.
*/
// @codingStandardsIgnoreStart
public function _get_sliders( $skip_empty = true ) {
// @codingStandardsIgnoreEnd
$sliders = new WP_Query(
array(
'post_type' => 'soliloquy',
'post_status' => 'publish',
'posts_per_page' => apply_filters( 'soliloquy_get_limit', 99 ),
'fields' => 'ids',
// Ignore Meta Query.
// @codingStandardsIgnoreStart
'meta_query' => array(
array(
'key' => '_sol_slider_data',
'compare' => 'EXISTS',
),
),
// @codingStandardsIgnoreEnd
)
);
if ( ! isset( $sliders->posts ) || empty( $sliders->posts ) ) {
return false;
}
// Now loop through all the sliders found and only use sliders that have images in them.
$ret = array();
foreach ( $sliders->posts as $id ) {
$data = get_post_meta( $id, '_sol_slider_data', true );
$content_sliders = $this->content_type_sliders();
if ( ! class_exists( 'Soliloquy_Common' ) ) {
require plugin_dir_path( __FILE__ ) . 'includes/global/common.php';
}
if ( ! class_exists( 'Soliloquy_Shortcode' ) ) {
require plugin_dir_path( __FILE__ ) . 'includes/global/shortcode.php';
}
if ( ! in_array( Soliloquy_Shortcode::get_instance()->get_config( 'type', $data ), $content_sliders, true ) ) {
if ( $skip_empty && empty( $data['slider'] ) ) {
continue;
}
}
// Skip Defaults and Dynamic Sliders.
if ( 'defaults' === Soliloquy_Shortcode::get_instance()->get_config( 'type', $data ) || 'dynamic' === Soliloquy_Shortcode::get_instance()->get_config( 'type', $data ) ) {
continue;
}
$ret[] = $data;
}
// Return the slider data.
return $ret;
}
/**
* Array of Content Type Sliders
*
* @since 2.4.4.3
*
* @param array $array (default: array()).
* @return array
*/
public function content_type_sliders( $array = array() ) {
$array = array(
'wc',
'fc',
'testimonial',
'default',
);
return apply_filters( 'soliloquy_content_sliders', $array );
}
/**
* Returns the license key for Soliloquy.
*
* @since 1.0.0
*
* @return string $key The user's license key for Soliloquy.
*/
public function get_license_key() {
$option = get_option( 'soliloquy' );
$key = false;
if ( empty( $option['key'] ) ) {
if ( defined( 'SOLILOQUY_LICENSE_KEY' ) ) {
$key = SOLILOQUY_LICENSE_KEY;
}
} else {
$key = $option['key'];
}
return apply_filters( 'soliloquy_license_key', $key );
}
/**
* Returns the license key type for Soliloquy.
*
* @since 1.0.0
*
* @return string $type The user's license key type for Soliloquy.
*/
public function get_license_key_type() {
$option = get_option( 'soliloquy' );
return $option['type'];
}
/**
* Returns possible license key error flag.
*
* @since 1.0.0
*
* @return bool True if there are license key errors, false otherwise.
*/
public function get_license_key_errors() {
$option = get_option( 'soliloquy' );
return isset( $option['is_expired'] ) && $option['is_expired'] || isset( $option['is_disabled'] ) && $option['is_disabled'] || isset( $option['is_invalid'] ) && $option['is_invalid'];
}
/**
* Loads the default plugin options.
*
* @since 1.0.0
*
* @return array Array of default plugin options.
*/
public static function default_options() {
$ret = array(
'key' => '',
'type' => '',
'is_expired' => false,
'is_disabled' => false,
'is_invalid' => false,
);
return apply_filters( 'soliloquy_default_options', $ret );
}
/**
* Getter method for retrieving the main plugin filepath.
*
* @since 1.2.0
*/
public static function get_file() {
return self::$file;
}
/**
* Helper flag method for any Soliloquy screen.
*
* @since 1.2.0
*
* @return bool True if on a Soliloquy screen, false if not.
*/
public static function is_soliloquy_screen() {
$current_screen = get_current_screen();
if ( ! $current_screen ) {
return false;
}
if ( 'soliloquy' === $current_screen->post_type ) {
return true;
}
return false;
}
/**
* Helper flag method for the Add/Edit Soliloquy screens.
*
* @since 1.2.0
*
* @return bool True if on a Soliloquy Add/Edit screen, false if not.
*/
public static function is_soliloquy_add_edit_screen() {
$current_screen = get_current_screen();
if ( ! $current_screen ) {
return false;
}
if ( 'soliloquy' === $current_screen->post_type && 'post' === $current_screen->base ) {
return true;
}
return false;
}
/**
* Setup enviromental constants for Envira.
*
* @since 1.7.0
*
* @access public
* @return void
*/
public function setup_constants() {
$this->define( 'SOLILOQUY_VERSION', $this->version );
$this->define( 'SOLILOQUY_SLUG', $this->plugin_slug );
$this->define( 'SOLILOQUY_FILE', $this->file );
$this->define( 'SOLILOQUY_DIR', plugin_dir_path( __FILE__ ) );
$this->define( 'SOLILOQUY_URL', plugin_dir_url( __FILE__ ) );
}
public function define( $name, $value ) {
if ( ! defined( $name ) ) {
define( $name, $value );
}
}
/**
* Returns the singleton instance of the class.
*
* @since 1.0.0
*
* @return object The Soliloquy object.
*/
public static function get_instance() {
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Soliloquy ) ) {
self::$instance = new Soliloquy();
}
return self::$instance;
}
}
register_activation_hook( __FILE__, 'soliloquy_activation_hook' );
/**
* Fired when the plugin is activated.
*
* @since 1.0.0
*
* @global int $wp_version The version of WordPress for this install.
* @global object $wpdb The WordPress database object.
* @param boolean $network_wide True if WPMU superadmin uses "Network Activate" action, false otherwise.
*/
function soliloquy_activation_hook( $network_wide ) {
global $wp_version;
// Deactivate lite.
deactivate_plugins( 'soliloquy-lite/soliloquy-lite.php' );
if ( version_compare( $wp_version, '3.5.1', '<' ) && ! defined( 'SOLILOQUY_FORCE_ACTIVATION' ) ) {
deactivate_plugins( plugin_basename( __FILE__ ) );
wp_die( sprintf( esc_html__( 'Sorry, but your version of WordPress does not meet Soliloquy\'s required version of <strong>3.5.1</strong> to run properly. The plugin has been deactivated. <a href="%s">Click here to return to the Dashboard</a>.', 'soliloquy' ), esc_url( get_admin_url() ) ) );
}
$instance = Soliloquy::get_instance();
$over_time = get_option( 'soliloquy_over_time', [] );
if ( empty( $over_time['installed_pro'] ) ) {
$over_time['installed_version'] = $instance->version;
$over_time['installed_date'] = wp_date( 'U' );
$over_time['installed_pro'] = $over_time['installed_date'];
if ( ! isset( $over_time['installed_lite'] ) ) {
$over_time['installed_lite'] = false;
}
update_option( 'soliloquy_over_time', $over_time );
}
if ( is_multisite() && $network_wide ) {
global $wpdb;
$site_list = $wpdb->get_results( "SELECT * FROM $wpdb->blogs ORDER BY blog_id" );
foreach ( (array) $site_list as $site ) {
switch_to_blog( $site->blog_id );
// Set default license option.
$option = get_option( 'soliloquy' );
if ( ! $option || empty( $option ) ) {
update_option( 'soliloquy', Soliloquy::default_options() );
}
restore_current_blog();
}
} else {
// Set default license option.
$option = get_option( 'soliloquy' );
if ( ! $option || empty( $option ) ) {
update_option( 'soliloquy', Soliloquy::default_options() );
}
}
}
register_uninstall_hook( __FILE__, 'soliloquy_uninstall_hook' );
/**
* Fired when the plugin is uninstalled.
*
* @since 1.0.0
*
* @global object $wpdb The WordPress database object.
*/
function soliloquy_uninstall_hook() {
$instance = Soliloquy::get_instance();
if ( is_multisite() ) {
global $wpdb;
$site_list = $wpdb->get_results( "SELECT * FROM $wpdb->blogs ORDER BY blog_id" );
foreach ( (array) $site_list as $site ) {
switch_to_blog( $site->blog_id );
delete_option( 'soliloquy' );
restore_current_blog();
}
} else {
delete_option( 'soliloquy' );
}
}
// Load the main plugin class.
$soliloquy = Soliloquy::get_instance();
/**
* Helper Method to check license status
*
* @return bool
*/
function soliloquy_license_checker() {
$core = Soliloquy::get_instance();
$key = $core->get_license_key();
$option = get_option( 'soliloquy' );
if ( ! $key || ( isset( $option['is_expired'] ) && $option['is_expired'] ) ) {
return false;
}
return true;
}
// Conditionally load the template tag.
if ( ! function_exists( 'soliloquy' ) ) {
/**
* Primary template tag for outputting Soliloquy sliders in templates.
*
* @since 1.0.0
*
* @param int $id The ID of the slider to load.
* @param string $type The type of field to query.
* @param array $args Associative array of args to be passed.
* @param bool $return Flag to echo or return the slider HTML.
*/
function soliloquy( $id, $type = 'id', $args = array(), $return = false ) {
// If we have args, build them into a shortcode format.
$args_string = '';
if ( ! empty( $args ) ) {
foreach ( (array) $args as $key => $value ) {
$args_string .= ' ' . $key . '="' . $value . '"';
}
}
// Build the shortcode.
$shortcode = ! empty( $args_string ) ? '[soliloquy ' . $type . '="' . $id . '"' . $args_string . ']' : '[soliloquy ' . $type . '="' . $id . '"]';
// Return or echo the shortcode output.
if ( $return ) {
return do_shortcode( $shortcode );
} else {
echo do_shortcode( $shortcode );
}
}
}