Commit inicial - WordPress Análisis de Precios Unitarios

- WordPress core y plugins
- Tema Twenty Twenty-Four configurado
- Plugin allow-unfiltered-html.php simplificado
- .gitignore configurado para excluir wp-config.php y uploads

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-11-03 21:04:30 -06:00
commit a22573bf0b
24068 changed files with 4993111 additions and 0 deletions

View File

@@ -0,0 +1,208 @@
<?php
class Thrive_Ult_Display_Settings_Manager {
/** @var int */
protected $campaign_id;
/** @var Thrive_Ult_Campaign_Options */
protected $saved_options;
public function __construct( $campaign_id = null ) {
if ( isset( $campaign_id ) ) {
$this->campaign_id = $campaign_id;
}
}
public function initHangers( $campaign_id ) {
$hangers[] = new Thrive_Ult_Hanger( 'show_options', $campaign_id );
$hangers[] = new Thrive_Ult_Hanger( 'hide_options', $campaign_id );
$tabs = array(
'other_screens' => __( 'Basic Settings', 'thrive-ult' ),
'taxonomy_terms' => __( 'Categories etc.', 'thrive-ult' ),
'posts' => __( 'Posts', 'thrive-ult' ),
'pages' => __( 'Pages', 'thrive-ult' ),
'page_templates' => __( 'Page Templates', 'thrive-ult' ),
'post_types' => __( 'Post Types', 'thrive-ult' ),
'taxonomy_archives' => __( 'Archive Pages', 'thrive-ult' ),
'others' => __( 'Other', 'thrive-ult' ),
);
/**
* @var $hanger Thrive_Ult_Hanger
*/
foreach ( $hangers as $hanger ) {
$hanger->initTabs( $tabs, $this->saved_options );
}
return $hangers;
}
/**
* Call this only once
* Saved options for a campaign are the same for all tabs
*/
protected function load_saved_options() {
$this->saved_options = new Thrive_Ult_Campaign_Options( $this->campaign_id );
$this->saved_options->initOptions();
}
public function get_popup_data() {
$this->load_dependencies();
$this->load_saved_options();
$group = isset( $_GET['campaign_id'] ) ? $_GET['campaign_id'] : $this->campaign_id;
$hangers = $this->initHangers( $group );
//used in file included at the end of this function
$saved_templates = apply_filters( 'thrive_display_options_get_templates', array() );
return array(
'hangers' => $hangers,
'savedTemplates' => $saved_templates,
);
}
public function load_template() {
$this->load_dependencies();
$templates = new Thrive_Ult_Saved_Options();
$template_id = $_REQUEST['template_id'];
if ( strpos( $template_id, 'TU-' ) === 0 ) {
$template_id = str_replace( 'TU-', '', $template_id );
} else {
$template = apply_filters( 'thrive_display_options_get_template', array(), $template_id );
}
$templates->initOptions( isset( $template ) ? false : $template_id, isset( $template ) ? $template : null );
$hangers = array(
new Thrive_Ult_Hanger( 'show_options', $_REQUEST['campaign_id'] ),
new Thrive_Ult_Hanger( 'hide_options', $_REQUEST['campaign_id'] ),
);
$identifiers = array(
'other_screens' => __( 'Basic Settings', 'thrive-ult' ),
'taxonomy_terms' => __( 'Categories etc.', 'thrive-ult' ),
'posts' => __( 'Posts', 'thrive-ult' ),
'pages' => __( 'Pages', 'thrive-ult' ),
'page_templates' => __( 'Page Templates', 'thrive-ult' ),
'post_types' => __( 'Post Types', 'thrive-ult' ),
'taxonomy_archives' => __( 'Archive Pages', 'thrive-ult' ),
'others' => __( 'Other', 'thrive-ult' ),
);
/**
* @var $hanger Thrive_Ult_Hanger
*/
foreach ( $hangers as $hanger ) {
/**
* @var $tab Thrive_Ult_Tab
*/
foreach ( $identifiers as $identifier => $label ) {
$tab = Thrive_Ult_Tab_Factory::build( $identifier );
$tab->setGroup( $_REQUEST['campaign_id'] )
->setIdentifier( $identifier )
->setSavedOptions( new Thrive_Ult_Campaign_Options( $_REQUEST['campaign_id'], $templates->getShowGroupOptions(), $templates->getHideGroupOptions() ) )
->setLabel( $label )
->setHanger( $hanger->identifier )
->initOptions()
->initFilters();
$hanger->tabs[] = $tab;
}
}
wp_send_json( $hangers );
}
public function getSavedTemplates() {
$savedTemplates = new Thrive_Ult_Saved_Options();
$templates = $savedTemplates->getAll();
foreach ( $templates as $template ) {
$template->id = TVE_Dash_Product_LicenseManager::TU_TAG . $template->id;
$template->show_options = $this->processTpl( json_decode( stripcslashes( $template->show_options ), true ) );
$template->hide_options = $this->processTpl( json_decode( stripcslashes( $template->hide_options ), true ) );
}
return $templates;
}
protected function processTpl( $savedOptions ) {
$return = array();
foreach ( $savedOptions['tabs'] as $index => $tab ) {
$options = $this->checkBackwardsComp( $tab['options'] );
$return[] = array(
'options' => $options,
'index' => $index,
);
}
return $return;
}
public function checkBackwardsComp( $options ) {
$return = array();
foreach ( $options as $o ) {
if ( is_array( $o ) ) {
if ( ! empty( $o['isChecked'] ) || ( ! empty( $o['type'] ) && $o['type'] == 'direct_url' ) ) {
$return [] = $o['id'];
}
} else {
$return [] = $o;
}
}
return $return;
}
public function save_options() {
if ( empty( $_POST['options'] ) || empty( $_POST['campaign_id'] ) ) {
return __( 'Empty values', 'thrive-ult' );
}
require_once plugin_dir_path( __FILE__ ) . 'class-thrive-ult-campaign-options.php';
$campaign_id = new Thrive_Ult_Campaign_Options( $_POST['campaign_id'], $_POST['options'][0], $_POST['options'][1] );
return $campaign_id->save();
}
public function save_template() {
if ( empty( $_POST['options'] ) || empty( $_POST['name'] ) ) {
return false;
}
require_once plugin_dir_path( __FILE__ ) . 'class-thrive-ult-saved-options.php';
$template = new Thrive_Ult_Saved_Options( $_POST['name'], $_POST['options'][0], $_POST['options'][1], '' );
return $template->save();
}
/**
* Load all the dependencies that are needed for this manager
*/
public function load_dependencies() {
require_once plugin_dir_path( __FILE__ ) . 'class-thrive-ult-filter.php';
require_once plugin_dir_path( __FILE__ ) . 'class-thrive-ult-action.php';
require_once plugin_dir_path( __FILE__ ) . 'class-thrive-ult-option.php';
require_once plugin_dir_path( __FILE__ ) . 'class-thrive-ult-hanger.php';
require_once plugin_dir_path( __FILE__ ) . 'class-thrive-ult-tab-interface.php';
require_once plugin_dir_path( __FILE__ ) . 'class-thrive-ult-tab.php';
require_once plugin_dir_path( __FILE__ ) . 'class-thrive-ult-tab-factory.php';
require_once plugin_dir_path( __FILE__ ) . 'class-thrive-ult-posts-tab.php';
require_once plugin_dir_path( __FILE__ ) . 'class-thrive-ult-pages-tab.php';
require_once plugin_dir_path( __FILE__ ) . 'class-thrive-ult-page-templates-tab.php';
require_once plugin_dir_path( __FILE__ ) . 'class-thrive-ult-post-types-tab.php';
require_once plugin_dir_path( __FILE__ ) . 'class-thrive-ult-taxonomy-archives-tab.php';
require_once plugin_dir_path( __FILE__ ) . 'class-thrive-ult-taxonomy-terms-tab.php';
require_once plugin_dir_path( __FILE__ ) . 'class-thrive-ult-other-screens-tab.php';
require_once plugin_dir_path( __FILE__ ) . 'class-thrive-ult-direct-urls-tab.php';
require_once plugin_dir_path( __FILE__ ) . 'class-thrive-ult-visitors-status-tab.php';
require_once plugin_dir_path( __FILE__ ) . 'class-thrive-ult-campaign-options.php';
require_once plugin_dir_path( __FILE__ ) . 'class-thrive-ult-saved-options.php';
require_once plugin_dir_path( __FILE__ ) . 'class-thrive-others-tab.php';
}
}

View File

@@ -0,0 +1,102 @@
<?php
/**
* Created by PhpStorm.
* User: radu
* Date: 22.01.2015
* Time: 11:50
*/
class Thrive_Ult_Others_Tab extends Thrive_Ult_Tab {
/** @var Thrive_Ult_Visitors_Status_Tab */
protected $visitor_status;
/** @var Thrive_Ult_Direct_Urls_Tab */
protected $direct_urls;
public function __construct() {
$this->visitor_status = new Thrive_Ult_Visitors_Status_Tab();
$this->direct_urls = new Thrive_Ult_Direct_Urls_Tab();
$this->direct_urls->setExclusions( $this->visitor_status->getItems() );
parent::__construct();
}
/**
* Specific tab has to implement this function which transforms
* items(pages, posts, post types) into Option models
*
* @return array
*/
protected function matchItems() {
$this->visitor_status->matchItems();
$this->direct_urls->matchItems();
$this->options = array_merge(
$this->visitor_status->options,
$this->direct_urls->options
);
return $this;
}
/**
* Has to get the Option from json string based on the $item
*
* @param $item
*
* @return Option
*/
protected function getSavedOption( $item ) {
return new Thrive_Ult_Option();
}
/**
* Read items from the database and initiate them
*
* @return $this
*/
protected function initItems() {
$this->visitor_status->getItems();
$this->direct_urls->getItems();
return $this;
}
public function setHanger( $hanger ) {
$this->hanger = $hanger;
$this->visitor_status->setHanger( $hanger );
$this->direct_urls->setHanger( $hanger );
return $this;
}
/**
* @param string $campaign_id
*
* @return $this
*/
public function setGroup( $campaign_id ) {
$this->campaign_id = $campaign_id;
$this->visitor_status->setGroup( $campaign_id );
$this->direct_urls->setGroup( $campaign_id );
return $this;
}
/**
* set the options individually for the 2 subtabs from here
*
* @param Thrive_Ult_Campaign_Options $savedOptions
*
* @return $this
*/
public function setSavedOptions( Thrive_Ult_Campaign_Options $savedOptions ) {
$this->visitor_status->setSavedOptions( $savedOptions );
$this->direct_urls->setSavedOptions( $savedOptions );
return parent::setSavedOptions( $savedOptions );
}
}

View File

@@ -0,0 +1,75 @@
<?php
/**
* Class Action Model
*/
class Thrive_Ult_Action {
/**
* @var string css class
*/
public $cssClass;
/**
* @var string html element id
*/
public $identifier;
/**
* @var string html text
*/
public $label;
/**
* @param string $cssClass
* @param string $identifier
* @param string $label
*/
public function __construct( $cssClass = '', $identifier = '', $label = '' ) {
$this->cssClass = $cssClass;
$this->identifier = $identifier;
$this->label = $label;
}
/**
* @param mixed $cssClass
*/
public function setCssClass( $cssClass ) {
$this->cssClass = $cssClass;
}
/**
* @return mixed
*/
public function getCssClass() {
return $this->cssClass;
}
/**
* @param mixed $identifier
*/
public function setIdentifier( $identifier ) {
$this->identifier = $identifier;
}
/**
* @return mixed
*/
public function getIdentifier() {
return $this->identifier;
}
/**
* @param mixed $label
*/
public function setLabel( $label ) {
$this->label = $label;
}
/**
* @return mixed
*/
public function getLabel() {
return $this->label;
}
}

View File

@@ -0,0 +1,556 @@
<?php
/**
* Class GroupOptions
* JSON options saved by user in database
* Mapper model over database table
*/
class Thrive_Ult_Campaign_Options {
private $table_name = 'settings_campaign';
private $campaign_id;
private $description;
public $show_options;
public $hide_options;
private $db;
protected $init_done = false;
/**
* Store a cache of saved options per request
*
* @var array
*/
protected static $option_cache = [];
public function __construct( $campaign_id, $show_options = '', $hide_options = '' ) {
/**
* @var $wpdb wpdb
*/
global $wpdb;
$this->db = $wpdb;
$this->table_name = tve_ult_table_name( $this->table_name );
$this->campaign_id = $campaign_id;
$this->show_options = $show_options;
$this->hide_options = $hide_options;
}
protected function _processPreSave( $jsonOptions ) {
$options = @json_decode( stripcslashes( $jsonOptions ), true );
if ( empty( $options ) || empty( $options['tabs'] ) ) {
return json_encode( array( 'identifier' => $jsonOptions['identifier'] ) );
}
$clean_options = array();
foreach ( $options['tabs'] as $index => $tabOptions ) {
$clean_options['tabs'][ $index ]['options'] = $tabOptions;
}
return json_encode( $clean_options );
}
public function save() {
if ( $this->delete() === false ) {
return $this->db->last_error;
}
$this->db->suppress_errors();
$show_options = $this->_processPreSave( $this->show_options );
$hide_options = $this->_processPreSave( $this->hide_options );
return $this->db->insert( $this->table_name, array(
'campaign_id' => $this->campaign_id,
'description' => $this->description,
'show_options' => $show_options,
'hide_options' => $hide_options,
) ) !== false ? true : $this->db->last_error;
}
/**
* Deletes Group
*
* @return false|int Affected rows on success or false on error
*/
public function delete() {
//new code for WP 4.1.2
$result = $this->db->query(
$this->db->prepare( "DELETE FROM `{$this->table_name}` WHERE `campaign_id` = %d", $this->campaign_id )
);
return $result;
}
/**
* Reads settings from db / cache.
* Saves a bunch of sql queries in frontend requests
*
* @param int|string $campaign_id
*
* @return stdClass
*/
public static function get( $campaign_id ) {
$campaign_id = (int) $campaign_id;
if ( ! isset( static::$option_cache[ $campaign_id ] ) ) {
global $wpdb;
$table = tve_ult_table_name( 'settings_campaign' );
$sql = "SELECT * FROM {$table} WHERE `campaign_id` = %d";
static::$option_cache[ $campaign_id ] = $wpdb->get_row( $wpdb->prepare( $sql, $campaign_id ) );
}
return static::$option_cache[ $campaign_id ];
}
/**
* Read options from database
*
* @return $this
*/
public function initOptions() {
if ( ! $this->init_done ) {
$row = static::get( $this->campaign_id );
if ( $row ) {
$this->show_options = $row->show_options;
$this->hide_options = $row->hide_options;
$this->description = $row->description;
}
$this->init_done = true;
}
return $this;
}
/**
* copy options from database to new campaign
*
* @Param int|string $from contains id of campaign to copy options from
*
* @return true|error
*/
public function copyOptions( $from ) {
$from = (int) $from;
$sql = "SELECT * FROM {$this->table_name} WHERE `campaign_id` = '{$from}'";
$row = $this->db->get_row( $sql );
if ( $row ) {
$this->show_options = $row->show_options;
$this->hide_options = $row->hide_options;
$this->description = $row->description;
}
return $this->db->insert( $this->table_name, array(
'campaign_id' => $this->campaign_id,
'description' => $this->description,
'show_options' => $this->show_options,
'hide_options' => $this->hide_options,
) ) !== false ? true : $this->db->last_error;
}
/**
* @return string
*/
public function getShowGroupOptions() {
return $this->show_options;
}
/**
* @return string
*/
public function getHideGroupOptions() {
return $this->hide_options;
}
/**
* @param mixed $description
*/
public function setDescription( $description ) {
$this->description = $description;
return $this;
}
/**
* @return mixed
*/
public function getDescription() {
return $this->description;
}
// get current URL
public function get_current_URL() {
$requested_url = is_ssl() ? 'https://' : 'http://';
$requested_url .= $_SERVER['HTTP_HOST'];
$requested_url .= $_SERVER['REQUEST_URI'];
return $requested_url;
}
/**
* Check if any option is checked
*
* @return bool
*/
public function checkForAnyOptionChecked() {
$this->initOptions();
$showingOptions = @json_decode( stripcslashes( $this->getShowGroupOptions() ) );
if ( empty( $showingOptions ) ) {
return false;
}
$optionsChecked = strpos( $this->getShowGroupOptions(), "true" );
if ( $optionsChecked ) {
return true;
}
foreach ( $showingOptions->tabs as $tab ) {
if ( ! empty( $tab->options ) ) {
foreach ( $tab->options as $opt ) {
if ( ! is_object( $opt ) ) {
return true;
}
}
}
}
if ( empty( $showingOptions->tabs[7] ) ) {
return false;
}
foreach ( $showingOptions->tabs[7]->options as $item ) {
if ( is_object( $item ) ) {
if ( $item->isChecked || $item->type == 'direct_url' ) {
return true;
}
} else {
return true;
}
}
return false;
}
/**
* @return bool
*/
public function displayCampaign() {
$display = true;
/**
* if none of the options is not selected do not sow the campaign
*/
if ( ! $this->checkForAnyOptionChecked() ) {
return false;
}
if ( is_front_page() ) {
/* @var $otherScreensTab OtherScreensTab */
$otherScreensTab = Thrive_Ult_Tab_Factory::build( 'other_screens' );
$otherScreensTab->setSavedOptions( $this );
/* @var $directUrlsTab DirectUrlsTab */
$directUrlsTab = Thrive_Ult_Tab_Factory::build( 'direct_urls' );
$directUrlsTab->setSavedOptions( $this );
/* @var $visitorsStatusTab VisitorsStatusTab */
$visitorsStatusTab = Thrive_Ult_Tab_Factory::build( 'visitors_status' );
$visitorsStatusTab->setSavedOptions( $this );
$visitorsStatus = is_user_logged_in() ? 'logged_in' : 'logged_out';
$inclusion = $otherScreensTab->isScreenAllowed( 'front_page' )
|| $directUrlsTab->isUrlAllowed( $this->get_current_URL() )
|| $visitorsStatusTab->isStatusAllowed( $visitorsStatus );
if ( $inclusion === false ) {
return false;
}
$exclusion = $otherScreensTab->isScreenDenied( 'front_page' )
|| $directUrlsTab->isUrlDenied( $this->get_current_URL() )
|| $visitorsStatusTab->isStatusDenied( $visitorsStatus );
if ( $exclusion === true ) {
$display = false;
}
//endif is_front_page
} else if ( is_home() ) {
/* @var $otherScreensTab OtherScreensTab */
$otherScreensTab = Thrive_Ult_Tab_Factory::build( 'other_screens' );
$otherScreensTab->setSavedOptions( $this );
/* @var $directUrlsTab DirectUrlsTab */
$directUrlsTab = Thrive_Ult_Tab_Factory::build( 'direct_urls' );
$directUrlsTab->setSavedOptions( $this );
/* @var $visitorsStatusTab VisitorsStatusTab */
$visitorsStatusTab = Thrive_Ult_Tab_Factory::build( 'visitors_status' );
$visitorsStatusTab->setSavedOptions( $this );
$visitorsStatus = is_user_logged_in() ? 'logged_in' : 'logged_out';
$inclusion = $otherScreensTab->isScreenAllowed( 'blog_index' )
|| $directUrlsTab->isUrlAllowed( $this->get_current_URL() )
|| $visitorsStatusTab->isStatusAllowed( $visitorsStatus );
if ( $inclusion === false ) {
return false;
}
$exclusion = $otherScreensTab->isScreenDenied( 'blog_index' )
|| $directUrlsTab->isUrlDenied( $this->get_current_URL() )
|| $visitorsStatusTab->isStatusDenied( $visitorsStatus );
if ( $exclusion === true ) {
$display = false;
}
} else if ( is_page() ) {
/* @var $post WP_Post */
global $post;
/**
* Filter current post that is used for the display manager
*
* @param WP_Post $post
*/
$_post = apply_filters( 'tve_display_manager_current_post', $post );
/** @var Thrive_Ult_Other_Screens_Tab $otherScreensTab */
$otherScreensTab = Thrive_Ult_Tab_Factory::build( 'other_screens' );
$otherScreensTab->setSavedOptions( $this );
/* @var $pagesTab PagesTab */
$pagesTab = Thrive_Ult_Tab_Factory::build( 'pages' );
$pagesTab->setSavedOptions( $this );
/* @var $pageTemplatesTab PageTemplatesTab */
$pageTemplatesTab = Thrive_Ult_Tab_Factory::build( 'page_templates' );
$pageTemplatesTab->setSavedOptions( $this );
/* @var $postTypesTab PostTypesTab */
$postTypesTab = Thrive_Ult_Tab_Factory::build( 'post_types' );
$postTypesTab->setSavedOptions( $this );
/* @var $directUrlsTab DirectUrlsTab */
$directUrlsTab = Thrive_Ult_Tab_Factory::build( 'direct_urls' );
$directUrlsTab->setSavedOptions( $this );
/* @var $visitorsStatusTab VisitorsStatusTab */
$visitorsStatusTab = Thrive_Ult_Tab_Factory::build( 'visitors_status' );
$visitorsStatusTab->setSavedOptions( $this );
$visitorsStatus = is_user_logged_in() ? 'logged_in' : 'logged_out';
/* @var $taxonomyTermsTab Thrive_Ult_Taxonomy_Terms_Tab */
$taxonomyTermsTab = Thrive_Ult_Tab_Factory::build( 'taxonomy_terms' );
$taxonomyTermsTab->setSavedOptions( $this );
$inclusion = $otherScreensTab->allTypesAllowed( get_post_type() ) || $pagesTab->isPageAllowed( $_post )
|| $postTypesTab->isTypeAllowed( get_post_type() )
|| $directUrlsTab->isUrlAllowed( $this->get_current_URL() )
|| $pageTemplatesTab->isTemplateAllowed( basename( get_page_template() ) )
|| $visitorsStatusTab->isStatusAllowed( $visitorsStatus )
|| $taxonomyTermsTab->isPostAllowed( $_post );
if ( $inclusion === false ) {
return false;
}
$exclusion = $otherScreensTab->allTypesDenied( get_post_type() ) || $pagesTab->isPageDenied( $_post )
|| $postTypesTab->isDeniedType( get_post_type() )
|| $directUrlsTab->isUrlDenied( $this->get_current_URL() )
|| $pageTemplatesTab->isTemplateDenied( basename( get_page_template() ) )
|| $visitorsStatusTab->isStatusDenied( $visitorsStatus )
|| $taxonomyTermsTab->isPostDenied( $_post );
if ( $exclusion === true ) {
$display = false;
}
//endif is_page
} else if ( is_single() ) {
/* @var $post WP_Post */
global $post;
/** @var Thrive_Ult_Other_Screens_Tab $otherScreensTab */
$otherScreensTab = Thrive_Ult_Tab_Factory::build( 'other_screens' );
$otherScreensTab->setSavedOptions( $this );
/* @var $postsTab PostsTab */
$postsTab = Thrive_Ult_Tab_Factory::build( 'posts' );
$postsTab->setSavedOptions( $this );
/* @var $postTypesTab PostTypesTab */
$postTypesTab = Thrive_Ult_Tab_Factory::build( 'post_types' );
$postTypesTab->setSavedOptions( $this );
/* @var $directUrlsTab DirectUrlsTab */
$directUrlsTab = Thrive_Ult_Tab_Factory::build( 'direct_urls' );
$directUrlsTab->setSavedOptions( $this );
/* @var $visitorsStatusTab VisitorsStatusTab */
$visitorsStatusTab = Thrive_Ult_Tab_Factory::build( 'visitors_status' );
$visitorsStatusTab->setSavedOptions( $this );
$visitorsStatus = is_user_logged_in() ? 'logged_in' : 'logged_out';
/* @var $taxonomyTermsTab Thrive_Ult_Taxonomy_Terms_Tab */
$taxonomyTermsTab = Thrive_Ult_Tab_Factory::build( 'taxonomy_terms' );
$taxonomyTermsTab->setSavedOptions( $this );
$inclusion = $otherScreensTab->allTypesAllowed( get_post_type() ) || $postsTab->isPostAllowed( $post )
|| $postTypesTab->isTypeAllowed( get_post_type() )
|| $directUrlsTab->isUrlAllowed( $this->get_current_URL() )
|| $visitorsStatusTab->isStatusAllowed( $visitorsStatus )
|| $taxonomyTermsTab->isPostAllowed( $post );
if ( $inclusion === false ) {
return false;
}
$exclusion = $otherScreensTab->allTypesDenied( get_post_type() ) || $postsTab->isPostDenied( $post )
|| $postTypesTab->isDeniedType( get_post_type() )
|| $directUrlsTab->isUrlDenied( $this->get_current_URL() )
|| $visitorsStatusTab->isStatusDenied( $visitorsStatus )
|| $taxonomyTermsTab->isPostDenied( $post );
if ( $exclusion === true ) {
$display = false;
}
//endif is_single
} else if ( is_archive() ) {
$taxonomy = get_queried_object();
/* @var $taxonomyArchivesTab TaxonomyArchivesTab */
$taxonomyArchivesTab = Thrive_Ult_Tab_Factory::build( 'taxonomy_archives' );
$taxonomyArchivesTab->setSavedOptions( $this );
/* @var $directUrlsTab DirectUrlsTab */
$directUrlsTab = Thrive_Ult_Tab_Factory::build( 'direct_urls' );
$directUrlsTab->setSavedOptions( $this );
/* @var $visitorsStatusTab VisitorsStatusTab */
$visitorsStatusTab = Thrive_Ult_Tab_Factory::build( 'visitors_status' );
$visitorsStatusTab->setSavedOptions( $this );
$visitorsStatus = is_user_logged_in() ? 'logged_in' : 'logged_out';
$inclusion = $taxonomyArchivesTab->isTaxonomyAllowed( $taxonomy )
|| $directUrlsTab->isUrlAllowed( $this->get_current_URL() )
|| $visitorsStatusTab->isStatusAllowed( $visitorsStatus );
if ( $inclusion === false ) {
return false;
}
$exclusion = $taxonomyArchivesTab->isTaxonomyDenied( $taxonomy )
|| $directUrlsTab->isUrlDenied( $this->get_current_URL() )
|| $visitorsStatusTab->isStatusDenied( $visitorsStatus );
if ( $exclusion === true ) {
$display = false;
}
//endif is_archive
} else if ( is_404() ) {
/* @var $otherScreensTab Thrive_Ult_Other_Screens_Tab */
$otherScreensTab = Thrive_Ult_Tab_Factory::build( 'other_screens' );
$otherScreensTab->setSavedOptions( $this );
/* @var $directUrlsTab DirectUrlsTab */
$directUrlsTab = Thrive_Ult_Tab_Factory::build( 'direct_urls' );
$directUrlsTab->setSavedOptions( $this );
/* @var $visitorsStatusTab VisitorsStatusTab */
$visitorsStatusTab = Thrive_Ult_Tab_Factory::build( 'visitors_status' );
$visitorsStatusTab->setSavedOptions( $this );
$visitorsStatus = is_user_logged_in() ? 'logged_in' : 'logged_out';
$inclusion = $otherScreensTab->isScreenAllowed( '404_error_page' )
|| $directUrlsTab->isUrlAllowed( $this->get_current_URL() )
|| $visitorsStatusTab->isStatusAllowed( $visitorsStatus );
if ( $inclusion === false ) {
return false;
}
$exclusion = $otherScreensTab->isScreenDenied( '404_error_page' )
|| $directUrlsTab->isUrlDenied( $this->get_current_URL() )
|| $visitorsStatusTab->isStatusDenied( $visitorsStatus );
if ( $exclusion === true ) {
$display = false;
}
//endif is_404
} else if ( is_search() ) {
/* @var $otherScreensTab OtherScreensTab */
$otherScreensTab = Thrive_Ult_Tab_Factory::build( 'other_screens' );
$otherScreensTab->setSavedOptions( $this );
/* @var $directUrlsTab DirectUrlsTab */
$directUrlsTab = Thrive_Ult_Tab_Factory::build( 'direct_urls' );
$directUrlsTab->setSavedOptions( $this );
/* @var $visitorsStatusTab VisitorsStatusTab */
$visitorsStatusTab = Thrive_Ult_Tab_Factory::build( 'visitors_status' );
$visitorsStatusTab->setSavedOptions( $this );
$visitorsStatus = is_user_logged_in() ? 'logged_in' : 'logged_out';
$inclusion = $otherScreensTab->isScreenAllowed( 'search_page' )
|| $directUrlsTab->isUrlAllowed( $this->get_current_URL() )
|| $visitorsStatusTab->isStatusAllowed( $visitorsStatus );
if ( $inclusion === false ) {
return false;
}
$exclusion = $otherScreensTab->isScreenDenied( 'search_page' )
|| $directUrlsTab->isUrlDenied( $this->get_current_URL() )
|| $visitorsStatusTab->isStatusDenied( $visitorsStatus );
if ( $exclusion === true ) {
$display = false;
}
//endif is_search
} else {
$current_url = $this->get_current_URL();
/* @var $directUrlsTab Thrive_Ult_Direct_Urls_Tab */
$directUrlsTab = Thrive_Ult_Tab_Factory::build( 'direct_urls' );
$directUrlsTab->setSavedOptions( $this );
$display = $directUrlsTab->isUrlAllowed( $current_url ) && ! $directUrlsTab->isUrlDenied( $current_url );
}
return $display;
}
public function getTabSavedOptions( $tabIndex, $hanger ) {
$options = json_decode( stripcslashes( $this->$hanger ) );
if ( empty( $options ) || empty( $options->tabs[ $tabIndex ] ) || empty( $options->tabs[ $tabIndex ]->options ) ) {
return array();
}
$opts = $options->tabs[ $tabIndex ]->options;
$return = array();
foreach ( $opts as $option ) {
if ( is_object( $option ) ) {
if ( ! $option->isChecked && $option->type != 'direct_url' ) {
continue;
}
$return [] = $option->id;
} else {
$return [] = $option;
}
}
return $return;
}
}

View File

@@ -0,0 +1,151 @@
<?php
/**
* Class DirectUrlsTab
*/
class Thrive_Ult_Direct_Urls_Tab extends Thrive_Ult_Tab implements Thrive_Ult_Tab_Interface {
const OPTION_TYPE = 'direct_url';
protected $exclusions = array();
public function __construct() {
//override the construct just to reset the actions array
}
public function setExclusions( $exclusions ) {
$this->exclusions = $exclusions;
}
protected function matchItems() {
if ( ! $this->getItems() ) {
return array();
}
foreach ( $this->getItems() as $id => $link ) {
$option = new Thrive_Ult_Option();
$option->setLabel( $link );
$option->setId( $id );
$option->setType( self::OPTION_TYPE );
$this->options[] = $option;
}
}
/**
* WordPress doesnt have a list of direct URLs
* and we dont have to match any item with any saved option
*
* @param $item
*
* @return Option|void
*/
protected function getSavedOption( $item ) {
}
/**
* User adds options|links
* Read them from DB and set as items
*
* @return $this
*/
protected function initItems() {
$savedOptions = $this->getSavedOptions()->getTabSavedOptions( 7, $this->hanger );
if ( ! $savedOptions ) {
$this->setItems( array() );
return $this;
}
$items = array();
foreach ( $savedOptions as $option ) {
if ( array_key_exists( $option, $this->exclusions ) ) {
continue;
}
$items[ $option ] = $option;
}
$this->setItems( $items );
return $this;
}
/**
* @param $url string
*
* @return bool
*/
public function displayWidget( $url ) {
$this->hanger = 'show_options';
$display = false;
foreach ( $this->getItems() as $showingUrl ) {
if ( $url === $showingUrl ) {
$display = true;
}
}
if ( $display === true ) {
$this->hanger = 'hide_options';
$this->initItems();
foreach ( $this->getItems() as $hidingUrl ) {
if ( $url === $hidingUrl ) {
$display = false;
}
}
}
return $display;
}
public function isUrlDenied( $url ) {
$denied = false;
$this->hanger = 'hide_options';
$this->initItems();
foreach ( $this->getItems() as $hidingUrl ) {
if ( $this->clearUrl( $url ) === $this->clearUrl( $hidingUrl ) ) {
$denied = true;
}
}
return $denied;
}
public function isUrlAllowed( $url ) {
$allowed = false;
$this->hanger = 'show_options';
$this->initItems();
foreach ( $this->getItems() as $hidingUrl ) {
if ( $this->clearUrl( $url ) === $this->clearUrl( $hidingUrl ) ) {
$allowed = true;
}
}
return $allowed;
}
protected function clearUrl( $url ) {
if ( strpos( $url, 'http://' ) !== false ) {
$url = substr( $url, strlen( 'http://' ) );
}
if ( strpos( $url, 'https://' ) !== false ) {
$url = substr( $url, strlen( 'https://' ) );
}
if ( strpos( $url, 'www.' ) !== false ) {
$url = substr( $url, strlen( 'www.' ) );
}
/**
* this allows urls to have query strings
*/
if ( strpos( $url, '?' ) !== false ) {
$url = explode( '?', $url );
$url = $url[0];
}
return trim( $url, '/ ' );
}
}

View File

@@ -0,0 +1,69 @@
<?php
/**
* Class Filter Model
*/
class Thrive_Ult_Filter {
/**
* @var string css class
*/
public $cssClass;
/**
* @var string html element id attribute
*/
public $identifier;
/**
* @var string html element's text
*/
public $label;
public function __construct( $cssClass = '', $identifier = '', $label = '' ) {
$this->cssClass = $cssClass;
$this->identifier = $identifier;
$this->label = $label;
}
/**
* @param mixed $cssClass
*/
public function setCssClass( $cssClass ) {
$this->cssClass = $cssClass;
}
/**
* @return mixed
*/
public function getCssClass() {
return $this->cssClass;
}
/**
* @param mixed $identifier
*/
public function setIdentifier( $identifier ) {
$this->identifier = $identifier;
}
/**
* @return mixed
*/
public function getIdentifier() {
return $this->identifier;
}
/**
* @param mixed $label
*/
public function setLabel( $label ) {
$this->label = $label;
}
/**
* @return mixed
*/
public function getLabel() {
return $this->label;
}
}

View File

@@ -0,0 +1,33 @@
<?php
class Thrive_Ult_Hanger {
public $identifier;
public $tabs = array();
protected $campaign_id;
public function __construct( $identifier, $campaign_id ) {
$this->identifier = $identifier;
$this->campaign_id = $campaign_id;
}
public function initTabs( array $identifiers, $saved_options = null ) {
$is_instance = $saved_options instanceof Thrive_Ult_Campaign_Options;
foreach ( $identifiers as $identifier => $label ) {
/** @var $tab Thrive_Ult_Tab */
$tab = Thrive_Ult_Tab_Factory::build( $identifier );
if ( $is_instance ) {
$tab->setSavedOptions( $saved_options );
}
$tab->setGroup( $this->campaign_id )
->setIdentifier( $identifier )
->setLabel( $label )
->setHanger( $this->identifier )
->initOptions()
->initFilters();
$this->tabs[] = $tab;
}
}
}

View File

@@ -0,0 +1,75 @@
<?php
/**
* Class Option Model
*/
class Thrive_Ult_Option {
/* These data members are public just for the serialization(json_encode/json_decode) */
public $id;
public $label;
public $isChecked = false;
/**
* Used to filter options by filters
* Used to render a specific template
*
* @var string
*/
public $type = '';
/**
* @param mixed $id
*/
public function setId( $id ) {
$this->id = $id;
}
/**
* @return mixed
*/
public function getId() {
return $this->id;
}
/**
* @param boolean $isChecked
*/
public function setIsChecked( $isChecked ) {
$this->isChecked = $isChecked;
}
/**
* @return boolean
*/
public function getIsChecked() {
return $this->isChecked;
}
/**
* @param mixed $label
*/
public function setLabel( $label ) {
$this->label = $label;
}
/**
* @return mixed
*/
public function getLabel() {
return $this->label;
}
/**
* @param string $type
*/
public function setType( $type ) {
$this->type = $type;
}
/**
* @return string
*/
public function getType() {
return $this->type;
}
}

View File

@@ -0,0 +1,101 @@
<?php
/**
* Class OtherScreensTab
*/
class Thrive_Ult_Other_Screens_Tab extends Thrive_Ult_Tab implements Thrive_Ult_Tab_Interface {
/**
* Predefined screens
*
* @var array
*/
protected $items;
protected function matchItems() {
if ( ! $this->getItems() ) {
return array();
}
$options = $this->getSavedOptions();
$optionArr = $options->getTabSavedOptions( 0, $this->hanger );
foreach ( $this->getItems() as $id => $label ) {
$option = new Thrive_Ult_Option();
$option->setLabel( $label );
$option->setId( $id );
$option->setIsChecked( in_array( $id, $optionArr ) );
$this->options[] = $option;
}
}
/**
* @param string $item
*
* @return Option|Thrive_Ult_Option
*/
protected function getSavedOption( $item ) {
return $this->getSavedOptionForTab( 0, $item );
}
/**
* All the $items are hardcoded in class property
*
* @return $this
*/
protected function initItems() {
$this->items = array(
'front_page' => __( 'Front Page', 'thrive-ult' ),
'all_post' => __( 'All Posts', 'thrive-ult' ),
'all_page' => __( 'All Pages', 'thrive-ult' ),
'blog_index' => __( 'Blog Index', 'thrive-ult' ),
'404_error_page' => __( '404 Error Page', 'thrive-ult' ),
'search_page' => __( 'Search page', 'thrive-ult' ),
);
return $this;
}
/**
* @param $screen string
*
* @return bool
*/
public function displayWidget( $screen ) {
$this->hanger = 'show_options';
$showOption = $this->getSavedOption( $screen );
$display = $showOption->isChecked;
if ( $display === true ) {
$this->hanger = 'hide_options';
$display = ! $this->getSavedOption( $screen )->isChecked;
}
return $display;
}
public function isScreenAllowed( $screen ) {
$this->hanger = 'show_options';
return $this->getSavedOption( $screen )->isChecked;
}
public function isScreenDenied( $screen ) {
$this->hanger = 'hide_options';
return $this->getSavedOption( $screen )->isChecked;
}
public function allTypesAllowed( $post_type = 'post' ) {
$this->hanger = 'show_options';
return $this->getSavedOption( 'all_' . $post_type )->isChecked;
}
public function allTypesDenied( $post_type = 'post' ) {
$this->hanger = 'hide_options';
return $this->getSavedOption( 'all_' . $post_type )->isChecked;
}
}

View File

@@ -0,0 +1,72 @@
<?php
/**
* Class PagesTab
*/
class Thrive_Ult_Page_Templates_Tab extends Thrive_Ult_Tab implements Thrive_Ult_Tab_Interface {
protected function matchItems() {
if ( ! $this->getItems() ) {
return array();
}
$optionArr = $this->getSavedOptions()->getTabSavedOptions( 4, $this->hanger );
foreach ( $this->getItems() as $pageFile => $pageName ) {
$option = new Thrive_Ult_Option();
$option->setLabel( $pageName );
$option->setId( basename( $pageFile ) );
$option->setIsChecked( in_array( basename( $pageFile ), $optionArr ) );
$this->options[] = $option;
}
}
protected function getSavedOption( $item ) {
return $this->getSavedOptionForTab( 4, $item );
}
/**
* @return $this
*/
protected function initItems() {
$templates = wp_get_theme()->get_page_templates();
$templates['page.php'] = __( 'Default', 'thrive-ult' );
$this->setItems( $templates );
return $this;
}
/**
* @param $template string
*
* @return bool
*/
public function displayWidget( $template ) {
$templateLabel = $this->getTemplateLabel( $template );
$this->hanger = 'show_options';
$showOption = $this->getSavedOption( $templateLabel );
$display = $showOption->isChecked;
if ( $display === true ) {
$this->hanger = 'hide_options';
$templateLabel = $this->getTemplateLabel( $template );
$display = ! $this->getSavedOption( $templateLabel )->isChecked;
}
return $display;
}
public function isTemplateDenied( $template ) {
$this->hanger = 'hide_options';
return $this->getSavedOption( $template )->isChecked;
}
public function isTemplateAllowed( $template ) {
$this->hanger = 'show_options';
return $this->getSavedOption( $template )->isChecked;
}
}

View File

@@ -0,0 +1,72 @@
<?php
/**
* Class PagesTab
*/
class Thrive_Ult_Pages_Tab extends Thrive_Ult_Tab implements Thrive_Ult_Tab_Interface {
protected function matchItems() {
if ( ! $this->getItems() ) {
return array();
}
$optionArr = $this->getSavedOptions()->getTabSavedOptions( 3, $this->hanger );
foreach ( $this->getItems() as $page ) {
$option = new Thrive_Ult_Option();
$option->setLabel( $page->post_title );
$option->setId( $page->ID );
$option->setType( 'item_page' );
$option->setIsChecked( in_array( $page->ID, $optionArr ) );
$this->options[] = $option;
}
}
protected function getSavedOption( $item ) {
return $this->getSavedOptionForTab( 3, $item->ID );
}
/**
* @return $this
*/
protected function initItems() {
$this->setItems( get_pages( array(
'sort_column' => 'post_title',
'sort_order' => 'ASC',
'hierarchical' => 0,
) ) );
return $this;
}
/**
* @param $post WP_Post
*
* @return bool
*/
public function displayWidget( WP_Post $post ) {
$this->hanger = 'show_options';
$showOption = $this->getSavedOption( $post );
$display = $showOption->isChecked;
if ( $display === true ) {
$this->hanger = 'hide_options';
$display = ! $this->getSavedOption( $post )->isChecked;
}
return $display;
}
public function isPageDenied( $page ) {
$this->hanger = 'hide_options';
return $this->getSavedOption( $page )->isChecked;
}
public function isPageAllowed( $page ) {
$this->hanger = 'show_options';
return apply_filters( 'tu_is_page_allowed', $this->getSavedOption( $page )->isChecked, $page, $this );
}
}

View File

@@ -0,0 +1,79 @@
<?php
/**
* Class PostTypesTab
*/
class Thrive_Ult_Post_Types_Tab extends Thrive_Ult_Tab implements Thrive_Ult_Tab_Interface {
protected function matchItems() {
if ( ! $this->getItems() ) {
return array();
}
$optionArr = $this->getSavedOptions()->getTabSavedOptions( 5, $this->hanger );
foreach ( $this->getItems() as $key => $item ) {
$option = new Thrive_Ult_Option();
$option->setLabel( $item );
$option->setId( $item );
$option->setIsChecked( in_array( $item, $optionArr ) );
$this->options[] = $option;
}
}
protected function getSavedOption( $item ) {
return $this->getSavedOptionForTab( 5, $item );
}
/**
* @return $this
*/
protected function initItems() {
$post_types = get_post_types( array(
'public' => true,
) );
$blacklist = apply_filters( 'tve_ult_settings_post_types_blacklist', array() );
if ( is_array( $blacklist ) && ! empty( $blacklist ) ) {
foreach ( $blacklist as $item ) {
unset( $post_types[ $item ] );
}
}
$this->setItems( $post_types );
return $this;
}
/**
* @param $type string
*
* @return bool
*/
public function displayWidget( $type ) {
$this->hanger = 'show_options';
$showOption = $this->getSavedOption( $type );
$display = $showOption->isChecked;
if ( $display === true ) {
$this->hanger = 'hide_options';
$display = ! $this->getSavedOption( $type )->isChecked;
}
return $display;
}
public function isDeniedType( $type ) {
$this->hanger = 'hide_options';
return $this->getSavedOption( $type )->isChecked;
}
public function isTypeAllowed( $type ) {
$this->hanger = 'show_options';
return $this->getSavedOption( $type )->isChecked;
}
}

View File

@@ -0,0 +1,91 @@
<?php
/**
* Class PostsTab
*/
class Thrive_Ult_Posts_Tab extends Thrive_Ult_Tab implements Thrive_Ult_Tab_Interface {
protected function matchItems() {
if ( ! $this->getItems() ) {
return array();
}
$optionArr = $this->getSavedOptions()->getTabSavedOptions( 2, $this->hanger );
foreach ( $this->getItems() as $post ) {
$option = new Thrive_Ult_Option();
$option->setLabel( $post->post_title );
$option->setId( $post->ID );
$option->setIsChecked( in_array( $post->ID, $optionArr ) );
$this->options[] = $option;
}
}
/**
* Overwrite this method to set a specific list of actions
*
* @return array of Action
*/
public function getActions() {
return array();
}
/**
* @param $item WP_Post
*
* @return Option
*/
protected function getSavedOption( $item ) {
return $this->getSavedOptionForTab( 2, $item->ID );
}
/**
* @return $this
*/
protected function initItems() {
$items = array();
$options = $this->getSavedOptions()->getTabSavedOptions( 2, $this->hanger );
if ( ! empty( $options ) ) {
$items = get_posts( array(
'posts_per_page' => - 1,
'include' => $options,
) );
}
$this->setItems( $items );
return $this;
}
/**
* @param $post WP_Post
*
* @return bool
*/
public function displayWidget( WP_Post $post ) {
$this->hanger = 'show_options';
$showOption = $this->getSavedOption( $post );
$display = $showOption->isChecked;
if ( $display === true ) {
$this->hanger = 'hide_options';
$display = ! $this->getSavedOption( $post )->isChecked;
}
return $display;
}
public function isPostDenied( $post ) {
$this->hanger = 'hide_options';
return $this->getSavedOption( $post )->isChecked;
}
public function isPostAllowed( $post ) {
$this->hanger = 'show_options';
return $this->getSavedOption( $post )->isChecked;
}
}

View File

@@ -0,0 +1,99 @@
<?php
class Thrive_Ult_Saved_Options {
private $table_name = 'settings_templates';
private $db;
private $name;
private $description;
public $show_options;
public $hide_options;
public function __construct( $name = '', $show_options = '', $hide_options = '', $description = '' ) {
/**
* @var $wpdb wpdb
*/
global $wpdb;
$this->db = $wpdb;
$this->table_name = tve_ult_table_name( $this->table_name );
$this->name = $name;
$this->description = $description;
$this->show_options = $show_options;
$this->hide_options = $hide_options;
}
protected function _processPreSave( $jsonOptions ) {
$options = @json_decode( stripcslashes( $jsonOptions ), true );
if ( empty( $options ) || empty( $options['tabs'] ) ) {
return json_encode( array( 'identifier' => $jsonOptions['identifier'] ) );
}
$clean_options = array();
foreach ( $options['tabs'] as $index => $tabOptions ) {
$clean_options['tabs'][ $index ]['options'] = $tabOptions;
}
return json_encode( $clean_options );
}
public function save() {
$this->delete();
$this->db->suppress_errors();
$show_options = $this->_processPreSave( $this->show_options );
$hide_options = $this->_processPreSave( $this->hide_options );
return $this->db->insert( $this->table_name, array(
'name' => $this->name,
'description' => $this->description,
'show_options' => $show_options,
'hide_options' => $hide_options,
) ) !== false ? true : $this->db->last_error;
}
public function delete() {
$this->db->delete( $this->table_name, array( 'name' => $this->name ) );
}
/**
* Read options from database
*
* @return $this
*/
public function initOptions( $byId = false, $from_data = null ) {
if ( $from_data !== null ) {
$row = $from_data;
} else {
$where = $byId === false ? "name = '{$this->name}'" : "id = {$byId}";
$sql = "SELECT * FROM {$this->table_name} WHERE {$where}";
$row = $this->db->get_row( $sql );
}
if ( $row ) {
$this->show_options = $row->show_options;
$this->hide_options = $row->hide_options;
}
return $this;
}
/**
* @return string
*/
public function getShowGroupOptions() {
return $this->show_options;
}
/**
* @return string
*/
public function getHideGroupOptions() {
return $this->hide_options;
}
public function getAll() {
$sql = "SELECT * FROM {$this->table_name} ORDER BY name";
$results = $this->db->get_results( $sql );
return $results;
}
}

View File

@@ -0,0 +1,18 @@
<?php
/**
* Class Thrive_Ult_Tab_Factory
* Based on $type a specific tab object is returned
*/
class Thrive_Ult_Tab_Factory {
public static function build( $type ) {
$class = "Thrive_Ult_";
$chunks = explode( "_", $type );
foreach ( $chunks as $chunk ) {
$class .= ucfirst( $chunk ) . "_";
}
$class .= "Tab";
return new $class;
}
}

View File

@@ -0,0 +1,9 @@
<?php
/**
* Interface TabInterface
* Any class that implements this interface has to have options to be displayed
*/
interface Thrive_Ult_Tab_Interface {
public function getOptions();
}

View File

@@ -0,0 +1,284 @@
<?php
/**
* Class Tab
* Basic implementation of a tab
*/
abstract class Thrive_Ult_Tab implements Thrive_Ult_Tab_Interface {
/**
* @var array of items from the wordpress database
*/
protected $items = array();
/**
* @var array of Options build based on the items
*/
public $options = array();
/**
* @var array "Select All, Select None, etc"
*/
public $actions = array();
/**
* @var array
*/
public $filters = array();
/**
* @var int campaign post ID identifier
*/
protected $campaign_id;
/**
* @var Thrive_Ult_Campaign_Options saved by user
*/
protected $savedOptions;
/**
* @var string tab identifier
*/
public $identifier;
/**
* @var string tab label
*/
public $label;
/**
* @var string hanger identifier
*/
protected $hanger;
public function __construct() {
$this->actions = $this->getActions();
}
/**
* @return array of Option models
*/
final public function getOptions() {
if ( empty( $this->options ) ) {
$this->matchItems();
}
return $this->options;
}
/**
* Get the items from database once
* If the $items is not initialized initItems is called which is an abstract method
* and has to be implemented for each tab
*
* @return array
*/
protected function getItems() {
if ( empty( $this->items ) ) {
$this->initItems();
}
return $this->items;
}
/**
* Read the options from the database once
* Init GroupOptions with json strings
*
* @return Thrive_Ult_Campaign_Options
*/
protected function getSavedOptions() {
if ( $this->savedOptions ) {
return $this->savedOptions;
}
$campaign_idOptions = new Thrive_Ult_Campaign_Options( $this->getGroup() );
$campaign_idOptions->initOptions();
$this->savedOptions = $campaign_idOptions;
return $campaign_idOptions;
}
public function setSavedOptions( Thrive_Ult_Campaign_Options $savedOptions ) {
$this->savedOptions = $savedOptions;
return $this;
}
/**
* Overwrite this method to set a specific list of actions
*
* @return array of Action
*/
public function getActions() {
return array(
new Thrive_Ult_Action( 'selectAll tvd-btn-flat-primary', '', 'Select All' ),
new Thrive_Ult_Action( 'selectNone tvd-btn-flat-secondary', '', 'Select None' ),
);
}
/**
* Overwrite this method for specific list of filters
*
* @return array empty
*/
public function getFilters() {
return $this->filters;
}
/**
* Set the items outside the box
*
* @param array $items
*
* @return $this
*/
public function setItems( array $items ) {
$this->items = $items;
return $this;
}
/**
* Can be called outside the box
*
* @return $this
*/
public function initFilters() {
$this->filters = $this->getFilters();
return $this;
}
/**
* @param string $campaign_id
*
* @return $this
*/
public function setGroup( $campaign_id ) {
$this->campaign_id = $campaign_id;
return $this;
}
/**
* @return string
*/
public function getGroup() {
return $this->campaign_id;
}
/**
* @param mixed $identifier
*
* @return $this
*/
public function setIdentifier( $identifier ) {
$this->identifier = $identifier;
return $this;
}
/**
* @return string
*/
public function getIdentifier() {
return $this->identifier;
}
/**
* @param string $label
*
* @return $this;
*/
public function setLabel( $label ) {
$this->label = $label;
return $this;
}
/**
* @return string
*/
public function getLabel() {
return $this->label;
}
/**
* @param string $hanger
*
* @return $this
*/
public function setHanger( $hanger ) {
$this->hanger = $hanger;
return $this;
}
/**
* @return string
*/
public function getHanger() {
return $this->hanger;
}
/**
* Callable from outside the box
* Init the items and options in one call
*
* @return $this
*/
public function initOptions() {
$this->initItems();
$this->matchItems();
return $this;
}
protected function getSavedOptionForTab( $tabIndex, $id ) {
$savedOptions = $this->getSavedOptions();
$optionArr = $savedOptions->getTabSavedOptions( $tabIndex, $this->hanger );
$tlOption = new Thrive_Ult_Option();
if ( empty( $optionArr ) ) {
return $tlOption;
}
$hanger = $this->hanger;
$options = json_decode( stripcslashes( $savedOptions->$hanger ) );
if ( ! $options ) {
return new Thrive_Ult_Option();
}
$tlOption->setId( $id );
$tlOption->setLabel( isset( $this->items[ $id ] ) ? $this->items[ $id ] : '' );
$tlOption->setIsChecked( in_array( $id, $optionArr ) );
return $tlOption;
}
/**
* Specific tab has to implement this function which transforms
* items(pages, posts, post types) into Option models
*
* @return void
*/
abstract protected function matchItems();
/**
* Has to get the Option from json string based on the $item
*
* @param $item
*
* @return Option
*/
abstract protected function getSavedOption( $item );
/**
* Read items from the database and initiate them
*
* @return $this
*/
abstract protected function initItems();
}

View File

@@ -0,0 +1,78 @@
<?php
/**
* Class Thrive_Ult_Taxonomy_Archives_Tab
*/
class Thrive_Ult_Taxonomy_Archives_Tab extends Thrive_Ult_Tab implements Thrive_Ult_Tab_Interface {
protected function matchItems() {
if ( ! $this->getItems() ) {
return array();
}
$optionArr = $this->getSavedOptions()->getTabSavedOptions( 6, $this->hanger );
foreach ( $this->getItems() as $id => $taxonomy ) {
$option = new Thrive_Ult_Option();
$option->setLabel( $taxonomy->label );
$option->setId( $id );
$option->setIsChecked( in_array( $id, $optionArr ) );
$this->options[] = $option;
}
}
protected function getSavedOption( $item ) {
return $this->getSavedOptionForTab( 6, $item );
}
/**
* @return $this
*/
protected function initItems() {
$this->setItems( get_taxonomies( array(
'public' => true,
), 'objects' ) );
return $this;
}
/**
* @param $taxonomy
*
* @return bool
*/
public function displayWidget( $taxonomy = null ) {
if ( ! $taxonomy ) {
return false;
}
$this->hanger = 'show_options';
$showOption = $this->getSavedOption( $taxonomy->taxonomy );
$display = $showOption->isChecked;
if ( $display === true ) {
$this->hanger = 'hide_options';
$display = ! $this->getSavedOption( $taxonomy->taxonomy )->isChecked;
}
return $display;
}
public function isTaxonomyAllowed( $taxonomy = null ) {
$this->hanger = 'show_options';
if ( empty( $taxonomy->taxonomy ) ) {
return false;
}
return $this->getSavedOption( $taxonomy->taxonomy )->isChecked;
}
public function isTaxonomyDenied( $taxonomy = null ) {
if ( empty( $taxonomy->taxonomy ) ) {
return false;
}
$this->hanger = 'hide_options';
return $this->getSavedOption( $taxonomy->taxonomy )->isChecked;
}
}

View File

@@ -0,0 +1,168 @@
<?php
/**
* Class TaxonomyTermsTab
*/
class Thrive_Ult_Taxonomy_Terms_Tab extends Thrive_Ult_Tab implements Thrive_Ult_Tab_Interface {
public function __construct() {
}
protected function matchItems() {
if ( ! $this->getItems() ) {
return array();
}
$optionArr = $this->getSavedOptions()->getTabSavedOptions( 1, $this->hanger );
foreach ( $this->getItems() as $key => $term ) {
$option = new Thrive_Ult_Option();
$option->setLabel( $term->name );
$option->setId( $term->term_id );
$option->setType( $term->taxonomy );
$option->setIsChecked( in_array( $term->term_id, $optionArr ) );
$this->options[] = $option;
}
}
protected function getSavedOption( $item ) {
return $this->getSavedOptionForTab( 1, $item->term_id );
}
/**
* @return $this
*/
protected function initItems() {
$taxonomies = get_taxonomies( array( 'public' => true ) );
/* exclude taxonomies that can be "too many" - a user once had 10.000 tags => breaks the ajax */
$exclude = array( 'post_tag' );
$tag_found = false;
foreach ( $taxonomies as $i => $t ) {
if ( in_array( $t, $exclude ) !== false ) {
if ( empty( $tag_found ) ) {
$tag_found = $t;
}
unset( $taxonomies[ $i ] );
}
}
$this->setItems( get_terms( $taxonomies ) );
/**
* include the post_tag taxonomy
*/
$options = $this->getSavedOptions()->getTabSavedOptions( 1, $this->hanger );
if ( isset( $tag_found ) && ! empty( $options ) ) {
$this->items = array_merge( $this->items, get_terms( $tag_found, array(
'include' => $options,
) ) );
}
return $this;
}
/**
* For this case the filters are the taxonomies
*
* @return array of Filter elements
*/
public function getFilters() {
if ( ! empty( $this->filters ) ) {
return $this->filters;
}
$filters = array();
foreach ( get_taxonomies( array( 'public' => true ), 'objects' ) as $taxonomy ) {
$filters[] = new Thrive_Ult_Filter( 'taxonomyFilter', $taxonomy->name, $taxonomy->label );
}
return $filters;
}
/**
* @param $taxonomyName
*
* @return bool|object
*/
public function getTaxonomy( $taxonomyName ) {
return get_taxonomy( $taxonomyName );
}
/**
* @param $taxonomy
*
* @return bool
*/
public function displayWidget( $taxonomy = null ) {
if ( ! $taxonomy ) {
return false;
}
$this->hanger = 'show_options';
$showOption = $this->getSavedOption( $taxonomy );
$display = $showOption->isChecked;
if ( $display === true ) {
$this->hanger = 'hide_options';
$display = ! $this->getSavedOption( $taxonomy )->isChecked;
}
return $display;
}
public function isTaxonomyAllowed( $taxonomy = null ) {
$this->hanger = 'show_options';
return $this->getSavedOption( $taxonomy )->isChecked;
}
public function isTaxonomyDenied( $taxonomy = null ) {
$this->hanger = 'hide_options';
return $this->getSavedOption( $taxonomy )->isChecked;
}
public function isPostAllowed( $post ) {
//get all taxonomy terms for all taxonomies the $post has
$taxonomies = get_taxonomies( array( 'public' => true ) );
$post_terms = array();
foreach ( $taxonomies as $taxonomy ) {
foreach ( wp_get_post_terms( $post->ID, $taxonomy ) as $term ) {
$post_terms[] = $term;
}
}
//check if any of the posts taxonomy terms is checked
$this->hanger = 'show_options';
foreach ( $post_terms as $post_term ) {
if ( $this->getSavedOption( $post_term )->isChecked ) {
return true;
}
}
return false;
}
public function isPostDenied( $post ) {
//get all taxonomy terms for all taxonomies the $post has
$taxonomies = get_taxonomies( array( 'public' => true ) );
$post_terms = array();
foreach ( $taxonomies as $taxonomy ) {
foreach ( wp_get_post_terms( $post->ID, $taxonomy ) as $term ) {
$post_terms[] = $term;
}
}
//check if any of the posts taxonomy terms is checked
$this->hanger = 'hide_options';
foreach ( $post_terms as $post_term ) {
if ( $this->getSavedOption( $post_term )->isChecked ) {
return true;
}
}
return false;
}
}

View File

@@ -0,0 +1,65 @@
<?php
class Thrive_Ult_Visitors_Status_Tab extends Thrive_Ult_Tab {
protected $items;
/**
* Specific tab has to implement this function which transforms
* items(pages, posts, post types) into Option models
*
* @return void
*/
protected function matchItems() {
if ( ! $this->getItems() ) {
return;
}
$optionArr = $this->getSavedOptions()->getTabSavedOptions( 7, $this->hanger );
foreach ( $this->getItems() as $id => $label ) {
$option = new Thrive_Ult_Option();
$option->setLabel( $label );
$option->setId( $id );
$option->setIsChecked( in_array( $id, $optionArr ) );
$this->options[] = $option;
}
}
/**
* Has to get the Option from json string based on the $item
*
* @param $item
*
* @return Option
*/
protected function getSavedOption( $item ) {
return $this->getSavedOptionForTab( 7, $item );
}
/**
* Read items from the database and initiate them
*
* @return $this
*/
protected function initItems() {
$this->items = array(
'logged_in' => __( 'Logged in', 'thrive-ult' ),
'logged_out' => __( 'Logged out', 'thrive-ult' ),
);
return $this;
}
public function isStatusAllowed( $status ) {
$this->hanger = 'show_options';
return $this->getSavedOption( $status )->isChecked;
}
public function isStatusDenied( $status ) {
$this->hanger = 'hide_options';
return $this->getSavedOption( $status )->isChecked;
}
}