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,444 @@
<?php
class OPanda_LeadsListTable extends WP_List_Table
{
public function __construct( $options = array() ) {
$options['singular'] = __( 'Lead', 'bizpanda' );
$options['plural'] = __( 'Leads', 'bizpanda' );
$options['ajax'] = false;
parent::__construct( $options );
$this->bulk_delete();
}
public function get_views() {
$counts = OPanda_Leads::getCountByStatus();
$link = 'edit.php?post_type=' . OPANDA_POST_TYPE . '&page=leads-bizpanda';
$currentStatus = isset( $_GET['opanda_status'] ) ? $_GET['opanda_status'] : 'all';
if ( !in_array( $currentStatus, array('all', 'confirmed', 'not-confirmed') ) ) $currentStatus = 'all';
$items = array(
'view-all' => array(
'title' => __('All', 'bizpanda'),
'link' => $link,
'count' => array_sum($counts),
'current' => $currentStatus == 'all'
),
'view-confirmed' => array(
'title' => __('Confirmed', 'bizpanda'),
'link' => add_query_arg( 'opanda_status', 'confirmed', $link ),
'count' => $counts['confirmed'],
'current' => $currentStatus == 'confirmed'
),
'view-not-confirmed' => array(
'title' => __('Not Confirmed', 'bizpanda'),
'link' => add_query_arg( 'opanda_status', 'not-confirmed', $link ),
'count' => $counts['not-confirmed'],
'current' => $currentStatus == 'not-confirmed'
)
);
$views = array();
foreach( $items as $name => $data ) {
$views[$name] = "<a href='" . $data['link'] . "' class='" . ( $data['current'] ? 'current' : '' ) . "'>" . $data['title'] . " <span class='count'>(" . number_format_i18n( $data['count'] ) . ")</span></a>";
}
return $views;
}
public function no_items() {
echo __( 'No leads found. ', 'bizpanda');
$view = isset( $_GET['opanda_status'] ) ? $_GET['opanda_status'] : 'all';
if ( 'all' !== $view ) return;
if ( BizPanda::isSinglePlugin() ) {
if ( BizPanda::hasPlugin('optinpanda') ) {
printf('To start generating leads, create <a href="%s"><strong>Email Locker</strong></a> or <a href="%s"><strong>Sign-In Locker</strong></a> and lock with them some content on your website.', opanda_get_help_url('what-is-email-locker'), opanda_get_help_url('what-is-signin-locker'));
} else {
printf('To start generating leads, create <a href="%s"><strong>Sign-In Locker</strong></a> and lock with it some content on your website.', opanda_get_help_url('what-is-signin-locker'));
}
} else {
printf('To start generating leads, create <a href="%s"><strong>Email Locker</strong></a> or <a href="%s"><strong>Sign-In Locker</strong></a> and lock with them some content on your website.', opanda_get_help_url('what-is-email-locker'), opanda_get_help_url('what-is-signin-locker'));
}
}
public function search_box($text, $input_id) {
if( !count($this->items) && !isset($_GET['s']) ) return;
$postType = isset( $_GET['post_type'] ) ? htmlspecialchars( $_GET['post_type'] ) : '';
$page = isset( $_GET['page'] ) ? htmlspecialchars( $_GET['page'] ) : '';
$currentStatus = isset( $_GET['opanda_status'] ) ? htmlspecialchars( $_GET['opanda_status'] ) : 'all';
if ( !in_array( $currentStatus, array('all', 'confirmed', 'not-confirmed') ) ) $currentStatus = 'all';
$s = isset( $_GET['s'] ) ? htmlspecialchars( $_GET['s'] ) : '';
?>
<form id="searchform" action method="GET">
<?php if(isset($_GET['post_type'])) : ?><input type="hidden" name="post_type" value="<?php echo $postType ?>"><?php endif; ?>
<?php if(isset($_GET['page'])) : ?><input type="hidden" name="page" value="<?php echo $page ?>"><?php endif; ?>
<?php if(isset($_GET['opanda_status'])) : ?><input type="hidden" name="opanda_status" value="<?php echo $currentStatus ?>"><?php endif; ?>
<p class="search-box">
<label class="screen-reader-text" for="sa-search-input"><?php echo $text; ?></label>
<input type="search" id="<?php echo $input_id ?>" name="s" value="<?php echo $s ?>">
<input type="submit" name="" id="search-submit" class="button" value="<?php echo $text; ?>">
</p>
</form>
<?php
}
/**
* Define the columns that are going to be used in the table
* @return array $columns, the array of columns to use with the table
*/
function get_columns() {
return $columns = array(
'cb' => '<input type="checkbox" />',
'avatar' => '',
'name' => __('Name', 'bizpanda'),
'channel' => __('Channel', 'bizpanda'),
'added' => __('Added', 'bizpanda'),
'status' => __('Status', 'bizpanda'),
);
}
/**
* Decide which columns to activate the sorting functionality on
* @return array $sortable, the array of columns that can be sorted by the user
*/
public function get_sortable_columns() {
return array(
'name' => 'name',
'channel' => 'channel',
'added' => 'added',
'status' => 'status'
);
}
public function get_bulk_actions() {
$actions = array(
'delete' => __('Delete', 'mymail')
);
return $actions;
}
/**
* Checks and runs the bulk action 'delete'.
*/
public function bulk_delete() {
$action = $this->current_action();
if ( 'delete' !== $action ) return;
if ( empty( $_POST['opanda_leads'] ) ) return;
$ids = array();
foreach( $_POST['opanda_leads'] as $leadId ) {
$ids[] = intval( $leadId );
}
global $wpdb;
$wpdb->query("DELETE FROM {$wpdb->prefix}opanda_leads WHERE ID IN (" . implode(',', $ids) . ")");
$wpdb->query("DELETE FROM {$wpdb->prefix}opanda_leads_fields WHERE lead_id IN (" . implode(',', $ids) . ")");
}
/**
* Prepare the table with different parameters, pagination, columns and table elements
*/
function prepare_items() {
global $wpdb;
$query = "SELECT * FROM {$wpdb->prefix}opanda_leads";
// where
$where = array();
if ( isset( $_GET['opanda_status'] ) && in_array( $_GET['opanda_status'], array('confirmed', 'not-confirmed') ) ) {
$where[] = 'lead_email_confirmed = ' . ( ( $_GET['opanda_status'] == 'confirmed' ) ? '1' : '0' );
}
if ( isset( $_GET['s'] ) ) {
$search = trim(addcslashes(esc_sql($_GET['s']), '%_'));
$search = explode(' ', $search);
$searchSql = " (";
$terms = array();
foreach($search as $term){
if(substr($term, 0,1) == '-'){
$term = substr($term,1);
$operator = 'AND';
$like = 'NOT LIKE';
$end = '(1=1)';
}else{
$operator = 'OR';
$like = 'LIKE';
$end = '(1=0)';
}
$termsql = " ( ";
$termsql .= " (lead_display_name $like '%".$term."%') $operator ";
$termsql .= " (lead_name $like '%".$term."%') $operator ";
$termsql .= " (lead_family $like '%".$term."%') $operator ";
$termsql .= " (lead_email $like '%".$term."%') $operator ";
$termsql .= " $end )";
$terms[] = $termsql;
}
$searchSql .= implode(' AND ', $terms) .')';
$where[] = $searchSql;
}
if ( !empty( $where ) ) {
$query .= ' WHERE ' . implode(' AND ', $where);
}
// order
$allowed = apply_filters( 'opanda_leads_allowed_orderby_columns', array( 'name', 'channel', 'added', 'status' ) );
$orderby = !empty($_GET["orderby"]) ? $_GET["orderby"] : 'added';
if ( !in_array( $orderby, $allowed ) ) $orderby = 'added';
$order = !empty($_GET["order"]) ? $_GET["order"] : 'desc';
if ( !in_array( $orderby, array('asc','desc') ) ) $order = 'desc';
if ( 'name' === $orderby ) $dbOrderBy = array( 'lead_display_name', 'lead_email');
elseif ( 'channel' === $orderby ) $dbOrderBy = array( 'lead_item_id' );
elseif ( 'added' === $orderby ) $dbOrderBy = array( 'lead_date' );
elseif ( 'status' === $orderby ) $dbOrderBy = array( 'lead_confirmed' );
else $dbOrderBy = array( $orderby );
foreach( $dbOrderBy as $index => $orderField ) {
$dbOrderBy[$index] .= ' ' . strtoupper( $order );
}
if( !empty($dbOrderBy) & !empty($order) )
$query.=' ORDER BY ' . implode ( ', ', $dbOrderBy );
$totalitems = $wpdb->get_var(str_replace("SELECT *", "SELECT COUNT(id)", $query));
$perpage = 20;
$paged = !empty($_GET["paged"]) ? intval($_GET["paged"]) : 1;
if(empty($paged) || !is_numeric($paged) || $paged<=0 ){ $paged=1; }
$totalpages = ceil($totalitems/$perpage);
if(!empty($paged) && !empty($perpage)){
$offset=($paged-1)*$perpage;
$query.=' LIMIT '.(int)$offset.','.(int)$perpage;
}
$this->set_pagination_args( array(
"total_items" => $totalitems,
"total_pages" => $totalpages,
"per_page" => $perpage,
));
$this->items = $wpdb->get_results($query);
}
/**
* Shows a checkbox.
*
* @since 1.0.7
* @return void
*/
public function column_cb($record) {
return sprintf(
'<input type="checkbox" name="opanda_leads[]" value="%s" />', $record->ID
);
}
/**
* Shows an avatar of the lead.
*
* @since 1.0.7
* @return void
*/
public function column_avatar($record) {
$url = admin_url('/edit.php?post_type=opanda-item&page=leads-bizpanda&action=leadDetails&leadID=' . $record->ID);
$avatar = '';
if ( !empty( $url ) ) $avatar .= '<a href="' .$url . '" class="opanda-avatar">';
else $avatar .= '<span class="opanda-avatar">';
$avatar .= OPanda_Leads::getAvatar( $record->ID, $record->lead_email, 40 );
if ( !empty( $url ) ) $avatar .= '</a>';
else $avatar .= '</span>';
echo $avatar;
}
/**
* Shows a name of the lead.
*
* @since 1.0.7
* @return void
*/
public function column_name($record) {
$name = '';
$url = admin_url('/edit.php?post_type=opanda-item&page=leads-bizpanda&action=leadDetails&leadID=' . $record->ID);
if ( !empty( $url ) ) $name .= '<a href="' . $url . '" class="opanda-name">';
else $name .= '<strong class="opanda-name">';
if ( !empty( $record->lead_display_name ) ) {
$name .= htmlspecialchars( $record->lead_display_name );
} else {
$name .= htmlspecialchars( $record->lead_email );
}
if ( !empty( $url ) ) $name .= '</a>';
else $name .= '</strong>';
/**
Social Icons
*/
$fields = OPanda_Leads::getLeadFields( $record->ID );
if ( isset( $fields['facebookUrl'] ) ) {
$name .= sprintf( '<a href="%s" target="_blank" class="opanda-social-icon opanda-facebook-icon"><i class="fa fa-facebook"></i></a>', $fields['facebookUrl'] );
}
if ( isset( $fields['twitterUrl'] ) ) {
$name .= sprintf( '<a href="%s" target="_blank" class="opanda-social-icon opanda-twitter-icon"><i class="fa fa-twitter"></i></a>', $fields['twitterUrl'] );
}
if ( isset( $fields['googleUrl'] ) ) {
$name .= sprintf( '<a href="%s" target="_blank" class="opanda-social-icon opanda-google-icon"><i class="fa fa-google-plus"></i></a>', $fields['googleUrl'] );
}
if ( isset( $fields['linkedinUrl'] ) ) {
$name .= sprintf( '<a href="%s" target="_blank" class="opanda-social-icon opanda-linkedin-icon"><i class="fa fa-linkedin"></i></a>', $fields['linkedinUrl'] );
}
/**/
if ( !empty( $record->lead_display_name ) ) {
$name .= '<br />' . $record->lead_email;
}
echo $name;
}
/**
* Shows how the lead was generated.
*
* @since 1.0.7
* @return void
*/
public function column_channel($record) {
$itemId = $record->lead_item_id;
$itemTitle = $record->lead_item_title;
$item = get_post( $itemId );
$itemTitle = empty( $item )
? '<i>' . __('(unknown)', 'bizpanda') . '</i>'
: $item->post_title;
$via = empty( $item )
? $itemTitle
: '<a href="' . opanda_get_admin_url('stats', array('opanda_id' => $itemId)) . '"><strong>' . $itemTitle. '</strong></a>';
$via = sprintf( __("Via: %s", 'bizpanda'), $via );
$postUrl = $record->lead_referer;
$postTitle = $record->lead_post_title;
$post = get_post( $record->lead_post_id );
if ( !empty( $post) ){
$postUrl = get_permalink( $post->ID );
$postTitle = $post->post_title;
}
if ( empty( $postTitle) ) $postTitle = '<i>' . __('(no title)', 'bizpanda') . '</i>';
$referer = '<a href="' . $postUrl . '"><strong>' . $postTitle . '</strong></a>';
$where = sprintf( __("On Page: %s", 'bizpanda'), $referer );
$text = $via . '<br />' . $where;
echo $text;
}
/**
* Shows when the lead was added.
*
* @since 1.0.7
* @return void
*/
public function column_added($record) {
echo date_i18n( get_option('date_format') . ' ' . get_option('time_format'), $record->lead_date + (get_option('gmt_offset')*3600));
}
/**
* Shows a status of the lead.
*
* @since 1.0.7
* @return void
*/
public function column_status($record) {
if ( BizPanda::hasPlugin('optinpanda') ) {
if ( $record->lead_email_confirmed) { ?>
<span class="opanda-status-help" title="<?php _e('This email is real. It was received from social networks or the user confirmed it by clicking on the link inside the confirmation email.', 'bizpanda') ?>">
<i class="fa fa-check-circle-o"></i><i><?php _e('email', 'optinapnda') ?></i>
</span>
<?php } else { ?>
<span class="opanda-status-help" title="<?php _e('This email was not confirmed. It means that actually this email address may be owned by another user.', 'bizpanda') ?>">
<i class="fa fa-circle-o"></i><i><?php _e('email', 'optinapnda') ?></i>
</span>
<?php }
echo '<br />';
if ( $record->lead_subscription_confirmed) { ?>
<span class="opanda-status-help" title="<?php _e('This user confirmed his subscription.', 'bizpanda') ?>">
<i class="fa fa-check-circle-o"></i><i><?php _e('subscription', 'optinapnda') ?></i>
</span>
<?php } else { ?>
<span class="opanda-status-help" title="<?php _e('This user has not confirmed his subscription.', 'bizpanda') ?>">
<i class="fa fa-circle-o"></i><i><?php _e('subscription', 'optinapnda') ?></i>
</span>
<?php }
} else {
if ( $record->lead_email_confirmed) { ?>
<span class="opanda-status-help" title="<?php _e('This email is real. It was received from social networks.', 'bizpanda') ?>">
<i class="fa fa-check-circle-o"></i><i><?php _e('email', 'optinapnda') ?></i>
</span>
<?php } else { ?>
<span class="opanda-status-help" title="<?php _e('This email was not confirmed. It means that actually this email address may be owned by another user.', 'bizpanda') ?>">
<i class="fa fa-circle-o"></i><i><?php _e('email', 'optinapnda') ?></i>
</span>
<?php }
}
}
public function column_default( $item, $column_name ) {
$value = '';
return apply_filters('opanda_leads_column', $value, $item, $column_name );
}
}

View File

@@ -0,0 +1,163 @@
<?php
class OPanda_ItemsViewTable extends FactoryViewtables320_Viewtable
{
public function configure()
{
/**
* Columns
*/
$this->columns->clear();
$this->columns->add('stats', __('<span title="Unlocks / Impressions / Conversion">U / I / %', 'bizpanda'));
$this->columns->add('title', __('Locker Title', 'bizpanda'));
if ( !BizPanda::isSinglePlugin() ) {
$this->columns->add('type', __('Type', 'bizpanda'));
}
$this->columns->add('shortcode', __('Shortcode', 'bizpanda'));
$this->columns->add('theme', __('Theme', 'bizpanda'));
$this->columns->add('bulk', __('Bulk Lock', 'bizpanda'));
$this->columns->add('visibility', __('Visibility Conditions', 'bizpanda'));
/**
* Scripts & styles
*/
$this->scripts->add(OPANDA_BIZPANDA_URL . '/assets/admin/js/item-view.010000.js');
$this->styles->add(OPANDA_BIZPANDA_URL . '/assets//admin/css/item-view.010000.css');
}
/**
* Column 'Title'
*/
public function columnTitle( $post, $isFullMode ) {
if ($isFullMode ) {
$url = get_post_meta($post->ID, 'opanda_theme', true);
if ( empty($url) ) $url = '<i>[current page]</i>';
echo '<p>' . $post->post_title . '</p>';
echo '<p>' . $url . '</p>';
} else {
echo $post->post_title;
}
}
/**
* Column 'Type'
*/
public function columnType( $post, $isFullMode ) {
$item = get_post_meta($post->ID, 'opanda_item', true);
echo $item;
}
/**
* Column 'Shortcode'
*/
public function columnShortcode( $post, $isFullMode ) {
$isSystem = get_post_meta( $post->ID, 'opanda_is_system', true);
$itemTypeName = get_post_meta( $post->ID, 'opanda_item', true);
$item = OPanda_Items::getItem( $itemTypeName );
$shortcodeName = $item['shortcode'];
$shortcode = '[' . $shortcodeName . '] [/' . $shortcodeName . ']';
if (!$isSystem) $shortcode = '[' . $shortcodeName . ' id="' . $post->ID . '"] [/' . $shortcodeName . ']';
?>
<input class="shortcode" type="text" value='<?php echo $shortcode ?>' />
<?php
}
/**
* Column 'Shortcode'
*/
public function columnBulk( $post, $isFullMode ) {
?>
<div class='onp-sl-inner-wrap'>
<?php opanda_print_bulk_locking_state( $post->ID ); ?>
</div>
<?php
}
/**
* Column 'Theme'
*/
public function columnTheme( $post, $isFullMode ) {
$theme = get_post_meta($post->ID, 'opanda_style', true);
echo $theme;
}
/**
* Column 'Visibility Conditions'
*/
public function columnVisibility( $post, $isFullMode ) {
$mode = get_post_meta($post->ID, 'opanda_visibility_mode', true);
if ( empty( $mode) ) $mode = 'simple';
?>
<div class='onp-sl-inner-wrap'>
<?php if ( $mode === 'simple' ) { ?>
<?php opanda_print_simple_visibility_options( $post->ID ); ?>
<?php } else { ?>
<?php opanda_print_visibility_conditions( $post->ID ); ?>
<?php } ?>
</div>
<?php
}
/**
* Column 'Created'
*/
public function columnStats( $post ) {
global $optinpanda;
$imperessions = intval( get_post_meta($post->ID, 'opanda_imperessions', true) );
$conversion = '0';
$unlocks = intval( get_post_meta($post->ID, 'opanda_unlocks', true) );
if ( !empty( $imperessions )) {
$conversion = round( $unlocks / $imperessions * 100, 2 );
} elseif ( !empty( $unlocks ) ) {
$conversion = 100;
}
$strong = ( $unlocks > 0 );
$url = opanda_get_admin_url('stats', array('opanda_id' => $post->ID));
if ( $strong ) {
echo '<a href="' . $url . '"><strong>' . $unlocks . '</strong> / ' . $imperessions . ' / ' . sprintf( '%.02f', $conversion ) . '%' . '</a>';
} else {
echo '<a href="' . $url . '" class="opanda-empty">' . $unlocks . ' / ' . $imperessions . ' / ' . sprintf( '%.02f', $conversion ) . '%' . '</a>';
}
?>
<?php
}
public function actionPostRowActions( $actions ) {
global $post;
if( $post->post_type !== $this->type->name ) return $actions;
$temporaryActions = array(
'edit' => $actions['edit'],
'clone' => '<a href="' . wp_nonce_url( get_admin_url() . 'post.php?post_type=opanda-item&amp;post=' . $post->ID . '&amp;action=opanda-clone-item', 'opanda-clone-item-nonce' ) . '" title="' . __("Clone this element", 'optinpanda') . '">' . __("Clone", 'bizpanda') . '</a>',
'trash' => $actions['trash']
);
return parent::actionPostRowActions( $temporaryActions );
}
}

View File

@@ -0,0 +1,241 @@
<?php
class OPanda_StatsScreen {
public function __construct( $options ) {
$this->options = $options;
}
public function getChart( $options ) {
require_once (OPANDA_BIZPANDA_DIR . '/admin/includes/stats.php');
$chartData = OPanda_Stats::getChartData( $options );
return new $this->options['chartClass']( $this, $chartData );
}
public function getTable( $options ) {
require_once (OPANDA_BIZPANDA_DIR . '/admin/includes/stats.php');
$tableData = OPanda_Stats::getViewTable( $options );
return new $this->options['tableClass']( $this, $tableData );
}
}
class OPanda_StatsChart {
public $type = 'area';
public function __construct( $screen, $data ) {
$this->screen = $screen;
$this->data = $data;
}
public function getFields() {
return array();
}
public function getSelectors() {
$fields = $this->getFields();
unset($fields['aggregate_date']);
return $fields;
}
public function hasSelectors() {
$selectors = $this->getSelectors();
return !empty( $selectors );
}
public function getSelectorsNames() {
$selectors = $this->getSelectors();
if ( empty( $selectors ) ) return array();
$result = array();
foreach( $selectors as $key => $selector ) {
$result[] = "'" . $key . "'";
}
return $result;
}
public function printData() {
$fields = $this->getFields();
$output = '';
foreach ( $this->data as $rowIndex => $dataRow ) {
$dataToPrint = array();
foreach( $fields as $field => $fieldData) {
if ( 'aggregate_date' == $field ) {
$dataToPrint['date'] = array(
'value' => 'new Date('.$dataRow['year'].','.$dataRow['mon'].','.$dataRow['day'].')'
);
} else {
$dataToPrint[$field] = array(
'value' => $this->getValue( $rowIndex, $field ),
'title' => isset( $fieldData['title'] ) ? $fieldData['title'] : '',
'color' => isset( $fieldData['color'] ) ? $fieldData['color'] : null
);
}
}
$rowDataToPrint = '';
foreach( $dataToPrint as $key => $data ) {
if ( !isset( $data['title'] )) $data['title'] = '';
if ( !isset( $data['color'] )) $data['color'] = '';
$rowDataToPrint .= "'$key': {'value': {$data['value']}, 'title': '{$data['title']}', 'color': '{$data['color']}'},";
}
$rowDataToPrint = rtrim($rowDataToPrint, ',');
$output .= '{' . $rowDataToPrint . '},';
}
$output = rtrim($output, ',');
echo $output;
}
public function getValue( $rowIndex, $fieldName ) {
$camelCase = str_replace('-', ' ', $fieldName);
$camelCase = str_replace('_', ' ', $camelCase);
$camelCase = str_replace(' ', '', ucwords( $camelCase) );
$camelCase[0] = strtoupper($camelCase[0]);
if ( method_exists( $this, 'field' . $camelCase ) ) {
return call_user_func( array( $this, 'field' . $camelCase ), $this->data[$rowIndex], $rowIndex );
} else {
if ( isset( $this->data[$rowIndex][$fieldName] ) ) {
return $this->data[$rowIndex][$fieldName];
} else {
return 0;
}
}
}
}
class OPanda_StatsTable {
public $orderBy = 'unlock';
public function __construct( $screen, $data ) {
$this->screen = $screen;
$this->data = $data;
usort($data['data'], array( $this, '_usort') );
$this->data['data'] = array_reverse($data['data']);
}
public function _usort( $a, $b ) {
$orderBy = $this->orderBy;
if ( !isset( $a[$orderBy] ) && !isset( $b[$orderBy] ) ) return 0;
if ( !isset( $a[$orderBy] ) ) return -1;
if ( !isset( $b[$orderBy] ) ) return 1;
if ( $a[$orderBy] == $b[$orderBy] ) return 0;
return ($a[$orderBy] < $b[$orderBy]) ? -1 : 1;
}
public function getColumns() {
return array();
}
public function getHeaderColumns( $level = 1 ) {
$columns = $this->getColumns();
if ( 2 === $level) {
$result = array();
foreach( $columns as $column ) {
if ( !isset( $column['columns'] ) ) continue;
$result = array_merge( $result, $column['columns'] );
}
return $result;
} else {
foreach( $columns as $n => $column ) {
$columns[$n]['rowspan'] = isset( $column['columns'] ) ? 1 : 2;
$columns[$n]['colspan'] = isset( $column['columns'] ) ? count( $column['columns'] ) : 1;
}
return $columns;
}
}
public function hasComplexColumns() {
$columns = $this->getHeaderColumns( 2 );
return !empty( $columns );
}
public function getDataColumns() {
$result = array();
foreach( $this->getColumns() as $name => $column ) {
if ( isset( $column['columns'] ) ) {
$result = array_merge( $result, $column['columns'] );
} else {
$result[$name] = $column;
}
}
return $result;
}
public function getColumnsCount() {
return count( $this->getColumns() );
}
public function getRowsCount() {
return count( $this->data['data'] );
}
public function printValue( $rowIndex, $columnName, $column ) {
$camelCase = str_replace('-', ' ', $columnName);
$camelCase = str_replace('_', ' ', $camelCase);
$camelCase = str_replace(' ', '', ucwords( $camelCase) );
$camelCase[0] = strtoupper($camelCase[0]);
if ( method_exists( $this, 'column' . $camelCase ) ) {
call_user_func( array( $this, 'column' . $camelCase ), $this->data['data'][$rowIndex], $rowIndex );
} else {
$value = isset( $this->data['data'][$rowIndex][$columnName] ) ? $this->data['data'][$rowIndex][$columnName] : 0;
if ( isset( $column['prefix'] ) && $value !== 0 ) echo $column['prefix'] ;
echo $value;
}
}
public function columnIndex( $row, $rowIndex ) {
echo $rowIndex + 1;
}
public function columnTitle( $row ) {
$title = !empty( $row['title'] ) ? $row['title'] : '<i>' . __('(untitled post)', 'bizpanda') . '</i>';
if ( !empty( $row['id'] ) ) {
echo '<a href="' . get_permalink( $row['id'] ) . '" target="_blank">' . $title . ' </a>';
} else {
echo $title;
}
}
public function columnConversion( $row ) {
if ( !isset( $row['impress'] )) $row['impress'] = 0;
if ( !isset( $row['unlock'] )) $row['unlock'] = 0;
if ( $row['impress'] == 0 ) { echo '0%'; return;}
if ( $row['unlock'] > $row['impress'] ) { echo '100%'; return;}
echo ( ceil( $row['unlock'] / $row['impress'] * 10000 ) / 100 ) . '%';
}
}

View File

@@ -0,0 +1,234 @@
<?php
abstract class OPanda_Subscription {
public $name;
public $title;
public $data;
public $deliveryError;
public function __construct( $data = array() ) {
$this->data = $data;
if ( isset( $data['name']) ) $this->name = $data['name'];
if ( isset( $data['title']) ) $this->title = $data['title'];
}
public function isEmail($email) {
return filter_var($email, FILTER_VALIDATE_EMAIL);
}
public function isTransactional() {
return isset( $this->data['transactional'] ) && $this->data['transactional'];
}
public function hasSingleOptIn() {
return in_array('quick', $this->data['modes'] );
}
public abstract function getLists();
public abstract function subscribe( $identityData, $listId, $doubleOptin, $contextData, $verified );
public abstract function check( $identityData, $listId, $contextData );
public abstract function getCustomFields( $listId );
public function prepareFieldValueToSave( $mapOptions, $value ) {
return $value;
}
public function getNameFieldIds() {
return array();
}
public function slugify($text, $separator = ' ')
{
// replace non letter or digits by -
$text = preg_replace('~[^\\pL\d]+~u', $separator, $text);
// trim
$text = trim($text, '-');
// transliterate
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
// lowercase
$text = strtolower($text);
// remove unwanted characters
$text = preg_replace('~[^-\w]+~', '', $text);
if (empty($text))
{
return 'n-a';
}
return $text;
}
public function refine( $identityData, $clearEmpty = false ) {
if ( empty( $identityData ) ) return $identityData;
unset( $identityData['html'] );
unset( $identityData['label'] );
unset( $identityData['separator'] );
unset( $identityData['name'] );
unset( $identityData['family'] );
unset( $identityData['displayName'] );
unset( $identityData['fullname'] );
if ( $clearEmpty ) {
foreach ($identityData as $key => $value) {
if ( empty($value) ) unset( $identityData[$key] );
}
}
return $identityData;
}
/**
* The function to subscribe an user through Wordpress.
*/
public function wpSubscribe( $identity, $serviceReady, $context, $listId, $verified ) {
require_once OPANDA_BIZPANDA_DIR . '/admin/includes/leads.php';
require_once OPANDA_BIZPANDA_DIR . '/admin/includes/stats.php';
$email = $identity['email'];
if ( empty( $email ) ) {
throw new OPanda_SubscriptionException( __('The email is not specified.','optinpanda') );
}
$temp = array(
'identity' => $identity,
'serviceReady' => $serviceReady,
'context' => $context,
'listId' => $listId,
'verified' => $verified
);
$lead = OPanda_Leads::getByEmail($email);
// already exists
if ( $lead ) {
if ( $lead->lead_subscription_confirmed ) return array('status' => 'subscribed');
OPanda_Leads::setTempData( $lead, $temp );
$this->sendConfirmation( $lead, $context );
return array('status' => 'pending');
} else {
$leadId = OPanda_Leads::add( $identity, $context, $verified, false, $temp );
$lead = OPanda_Leads::getById($leadId);
$lead->lead_email = $email;
$this->sendConfirmation( $lead, $context );
return array('status' => 'pending');
}
}
/**
* The function to subscribe an user through Wordpress.
*/
public function wpCheck( $identity, $serviceReady, $context, $listId, $verified ) {
$email = $identity['email'];
if ( empty( $email ) ) {
throw new OPanda_SubscriptionException( __('The email is not specified.','optinpanda') );
}
$lead = OPanda_Leads::getByEmail($email);
if ( !$lead ) throw new OPanda_SubscriptionException( __('The email is not found. Please try again.','optinpanda') );
return array('status' => $lead->lead_subscription_confirmed ? 'subscribed' : 'pending');
}
/**
* The function sends the confirmation email.
*/
public function sendConfirmation( $lead, $context ) {
if ( empty( $context['itemId'] ) )
throw new OPanda_SubscriptionException( __('Invalid request. Please contact the OnePress support.', 'optinpanda') );
$lockerId = (int)$context['itemId'];
$emailSubject = get_post_meta($lockerId, 'opanda_confirm_email_subject', true);
$emailBody = get_post_meta($lockerId, 'opanda_confirm_email_body', true);
$link = $this->getConfirmationLink($lead, $context);
$emailBody = str_replace('[link]', '<a href="' . $link . '" target="_blank">' . $link . '</a>', $emailBody);
if ( $this->isTransactional() ) {
$this->send( $lead->lead_email, $emailSubject, $emailBody );
} else {
add_action( 'wp_mail_failed', array($this, 'handleDeliveryError') );
add_filter( 'wp_mail_from', array($this, 'mailFrom'), 99 );
add_filter( 'wp_mail_from_name', array($this, 'mailFromName'), 99 );
$this->deliveryError = false;
$headers[] = 'Content-type: text/html; charset=utf-8';
$result = wp_mail( $lead->lead_email, $emailSubject, $emailBody, $headers );
if ( !$result ) {
if ( $this->deliveryError ) throw new OPanda_SubscriptionException( $this->deliveryError->get_error_message() );
else throw new OPanda_SubscriptionException( __('Unable to send a confirmation email to the specified email address.', 'optinpanda') );
}
remove_action('wp_mail_failed', array($this, 'handleDeliveryError'));
remove_action('wp_mail_failed', array($this, 'wp_mail_from'));
remove_action('wp_mail_failed', array($this, 'wp_mail_from_name'));
}
}
public function handleDeliveryError( $error ) {
$this->deliveryError = $error;
}
public function mailFrom( $from ) {
$value = get_option('opanda_sender_email', null);
return empty( $value ) ? $from : $value;
}
public function mailFromName( $fromName ) {
$value = get_option('opanda_sender_name', null);
return empty( $value ) ? $fromName : $value;
}
public function getConfirmationLink( $lead, $context ) {
$uri = $context['postUrl'];
if ( empty( $uri ) ) $uri = home_url();
$code = $lead->lead_confirmation_code;
if ( empty( $code ) ) {
$code = md5( NONCE_SALT . $lead->lead_email . time() );
OPanda_Leads::setConfirmationCode($lead, $code);
}
$args = array(
'opanda_confirm' => 1,
'opanda_lead' => $lead->ID,
'opanda_code' => $code
);
return add_query_arg($args, $uri);
}
}
/**
* A subscription service exception.
*/
class OPanda_SubscriptionException extends Exception {
public function __construct ($message) {
parent::__construct($message, 0, null);
}
}