Skip to content

Commit

Permalink
2.4.89 final changes
Browse files Browse the repository at this point in the history
  • Loading branch information
minimus committed Sep 25, 2014
1 parent d503c41 commit 2f1fed5
Show file tree
Hide file tree
Showing 11 changed files with 171 additions and 56 deletions.
28 changes: 25 additions & 3 deletions ad.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ public function __construct($args = null, $useCodes = false, $crawler = false) {
$this->ad = $this->buildAd($this->args, $this->useCodes);
}

public function init($args = null, $useCodes = false, $crawler = false) {
if(!defined('SAM_OPTIONS_NAME')) define('SAM_OPTIONS_NAME', 'samPluginOptions');
$this->args = $args;
$this->useCodes = $useCodes;
$this->crawler = $crawler;
$this->ad = $this->buildAd($this->args, $this->useCodes);
}

private function getSettings() {
$options = get_option(SAM_OPTIONS_NAME, '');
return $options;
Expand Down Expand Up @@ -160,8 +168,22 @@ public function __construct($args = null, $useCodes = false, $crawler = false, $
else $this->clauses = $clauses;
$this->force = $ajax;

$this->ad = $this->buildAd2($this->args, $this->useCodes);
$this->ad = $this->buildAd($this->args, $this->useCodes);
}

public function init($args = null, $useCodes = false, $crawler = false, $clauses = null, $ajax = false) {
global $SAM_Query;

if(!defined('SAM_OPTIONS_NAME')) define('SAM_OPTIONS_NAME', 'samPluginOptions');
$this->args = $args;
$this->useCodes = $useCodes;
$this->crawler = $crawler;
if(is_null( $clauses )) $this->clauses = $SAM_Query['clauses'];
else $this->clauses = $clauses;
$this->force = $ajax;

$this->ad = $this->buildAd($this->args, $this->useCodes);
}

private function getSettings() {
$options = get_option(SAM_OPTIONS_NAME, '');
Expand Down Expand Up @@ -218,7 +240,7 @@ private function errorWrite($eTable, $rTable, $eSql = null, $eResult = null, $la
//}
}

private function buildAd( $args = null, $useCodes = false ) {
private function buildAdOld( $args = null, $useCodes = false ) {
if(is_null($args)) return '';
if(empty($args['id']) && empty($args['name'])) return '';
if( is_null($this->clauses) ) return '';
Expand Down Expand Up @@ -435,7 +457,7 @@ private function buildAd( $args = null, $useCodes = false ) {
return $output;
}

private function buildAd2( $args = null, $useCodes = false ) {
private function buildAd( $args = null, $useCodes = false ) {
if(is_null($args)) return '';
if(empty($args['id']) && empty($args['name'])) return '';
if( is_null($this->clauses) ) return '';
Expand Down
16 changes: 14 additions & 2 deletions admin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,8 @@ public function getTablesDefs( $prefix = 'wp_' ) {
'id' => array('Type' => 'int(10) unsigned', 'Null' => 'YES', 'Key' => '', 'Default' => '', 'Extra' => ''),
'pid' => array('Type' => 'int(10) unsigned', 'Null' => 'YES', 'Key' => '', 'Default' => '', 'Extra' => ''),
'event_time' => array('Type' => 'datetime', 'Null' => 'YES', 'Key' => '', 'Default' => '', 'Extra' => ''),
'event_type' => array('Type' => 'tinyint(1)', 'Null' => 'YES', 'Key' => '', 'Default' => '', 'Extra' => '')
'event_type' => array('Type' => 'tinyint(1)', 'Null' => 'YES', 'Key' => '', 'Default' => '', 'Extra' => ''),
'remote_addr' => array('Type' => 'varchar(15)', 'Null' => 'YES', 'Key' => '', 'Default' => '', 'Extra' => '')
);

$pIndexDef = array(
Expand Down Expand Up @@ -436,6 +437,16 @@ public function getTablesDefs( $prefix = 'wp_' ) {
);
}

private function getSearchesModel() {
return array(
'posts' => array(
array('field' => 'id', 'caption' => 'ID', 'type' => 'int'),
array('field' => 'title', 'caption' => __("Publication Title", SAM_DOMAIN), 'type' => 'text'),
array('field' => 'type', 'caption' => __("Publication Type", SAM_DOMAIN), 'type' => 'text')
)
);
}

private function getColumnsModels() {
return array(
'comboGrid' => array(
Expand Down Expand Up @@ -884,14 +895,15 @@ public function loadScripts($hook) {
wp_enqueue_script('pointLabels', SAM_URL . 'js/jqplot.pointLabels.min.js', array('jquery', 'jqPlot'), '1.0.2');

wp_enqueue_script('wp-pointer');
wp_enqueue_script('adminEditScript', SAM_URL.'js/sam-admin-edit-item.js', array('jquery', 'jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-position'), SAM_VERSION);
wp_enqueue_script('adminEditScript', SAM_URL.'js/sam-admin-edit-item.min.js', array('jquery', 'jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-position'), SAM_VERSION);
wp_localize_script('adminEditScript', 'samEditorOptions', array(
'places' => array('enabled' => $pointers['places'], 'title' => __('Name of Ads Place', SAM_DOMAIN), 'content' => __('This is not required parameter. But it is strongly recommended to define it if you plan to use Ads Blocks, plugin\'s widgets or autoinserting of ads.', SAM_DOMAIN)),
'ads' => array('enabled' => $pointers['ads'], 'title' => __('Name of Ad', SAM_DOMAIN), 'content' => __('This is not required parameter. But it is strongly recommended to define it if you plan to use Ads Blocks or plugin\'s widgets.', SAM_DOMAIN)),
'media' => array('title' => __('Select Banner Image', SAM_DOMAIN), 'button' => __('Select', SAM_DOMAIN)),
'samAjaxUrl' => SAM_URL . 'sam-ajax-admin.php',
'samStatsUrl' => SAM_URL . 'sam-ajax-admin-stats.php',
'models' => self::getColumnsModels(),
'searches' => self::getSearchesModel(),
'data' => self::getGridsData(),
'strings' => array(
'uploading' => __('Uploading', SAM_DOMAIN).' ...',
Expand Down
2 changes: 2 additions & 0 deletions css/w2ui.css
Original file line number Diff line number Diff line change
Expand Up @@ -1968,6 +1968,8 @@ button.btn-red.clicked {
width: 100%;
color: black;
padding: 0px 15px 0px 5px;
line-height: 20px;
font-size: 11px;
-webkit-appearance: none;
-moz-appearance: none;
-ms-appearance: none;
Expand Down
2 changes: 1 addition & 1 deletion css/w2ui.min.css

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions js/sam-admin-edit-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ var sam = sam || {};
samAjaxUrl = samEditorOptions.samAjaxUrl,
samStatsUrl = samEditorOptions.samStatsUrl,
models = samEditorOptions.models,
searches = samEditorOptions.searches,
gData = samEditorOptions.data,
samStrs = samEditorOptions.strings,
sPost = encodeURI(samStrs.posts), sPage = encodeURI(samStrs.page);
Expand Down Expand Up @@ -171,7 +172,7 @@ var sam = sam || {};
}
};

function buildLGrid(name, grid, vi, field, gc, url) {
function buildLGrid(name, grid, vi, field, gc, url, ss) {
var iVal = vi.val();
grid.w2grid({
name: name,
Expand All @@ -180,6 +181,8 @@ var sam = sam || {};
toolbar: true,
footer: true
},
multiSearch: true,
searches: ss,
multiSelect: true,
columns: gc,
url: url,
Expand Down Expand Up @@ -425,8 +428,8 @@ var sam = sam || {};
samAjaxUrl +
'?action=load_posts&cstr=' + samEditorOptions.data.custList +
'&sp=' + sPost + '&spg=' + sPage + '&limit=10000';
buildLGrid('posts-grid', postsGrid, postsIn, 'id', models.posts, postAjax);
buildLGrid('x-posts-grid', xpostsGrid, xpostsIn, 'id', models.posts, postAjax);
buildLGrid('posts-grid', postsGrid, postsIn, 'id', models.posts, postAjax, searches.posts);
buildLGrid('x-posts-grid', xpostsGrid, xpostsIn, 'id', models.posts, postAjax, searches.posts);

$('#tabs').tabs({
activate: function( event, ui ) {
Expand Down
2 changes: 1 addition & 1 deletion js/sam-admin-edit-item.min.js

Large diffs are not rendered by default.

99 changes: 59 additions & 40 deletions js/sam-layout.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,63 @@
(function($) {
$(document).ready(function() {
var hits = [];
if(samAjax.load) {
if(samAjax.mailer) $.post(samAjax.ajaxurl, {action: 'sam_maintenance'});

// Loading Ads
var ads = [];
$('div.sam-place').each(function(i, el) {
var codes = $(el).data('sam');
if('undefined' == typeof codes) codes = 0;
var
ids = this.id.split('_'),
id = ids[1],
pid = ids[2];
$.ajax({
url: samAjax.loadurl,
data: {
action: 'load_place',
id: id,
pid: pid,
codes: codes,
wc: samAjax.clauses,
level: samAjax.level
},
type: 'POST'/*,
crossDomain: true*/
}).done(function(data) {
$(el).replaceWith(data.ad);
$.post(samAjax.ajaxurl, {
action: 'sam_hit',
id: data.id,
pid: data.pid,
level: samAjax.level
});
$('#' + data.cid).find('a').bind('click', function(e) {
$.post(samAjax.ajaxurl, {
action: 'sam_click',
id: data.id,
pid: data.pid,
level: samAjax.level

ads.push([pid, id, codes, this.id]);
});

if(ads.length > 0) {
$.post(samAjax.loadurl, {
action: 'load_ads',
ads: ads,
wc: samAjax.clauses,
level: samAjax.level
}).done(function (data) {
if (data.success) {
var hits = [];
$.each(data.ads, function (i, ad) {
$('#' + ad.eid).replaceWith(ad.ad);
$('#' + ad.cid).find('a').bind('click', function (e) {
$.post(samAjax.ajaxurl, {
action: 'sam_click',
id: ad.id,
pid: ad.pid,
level: samAjax.level
});
});
hits.push([ad.pid, ad.id]);
});
});
if (hits.length > 0) {
$.post(samAjax.ajaxurl, {
action: 'sam_hits',
hits: hits,
level: samAjax.level
});
}
}
});
});
}

// Ads loaded by PHP
$('div.sam-ad').each(function(i, el) {
var
ids = this.id.split('_'),
id = ids[1],
pid = ids[2];
$.post(samAjax.ajaxurl, {
action: 'sam_hit',
id: id,
pid: pid,
level: samAjax.level
});

hits.push([pid, id]);

$(el).find('a').bind('click', function(e) {
$.post(samAjax.ajaxurl, {
action: 'sam_click',
Expand All @@ -60,19 +67,23 @@
});
});
});

if(hits.length > 0) {
$.post(samAjax.ajaxurl, {
action: 'sam_hits',
hits: hits,
level: samAjax.level
});
}
}
else {
$('div.sam-container').each(function(i, el) {
var
ids = this.id.split('_'),
id = ids[1],
pid = ids[2];
$.post(samAjax.ajaxurl, {
action: 'sam_hit',
id: id,
pid: pid,
level: samAjax.level
});

hits.push([pid, id]);

$(el).find('a').bind('click', function(e) {
$.post(samAjax.ajaxurl, {
Expand All @@ -83,6 +94,14 @@
});
});
});

if(hits.length > 0) {
$.post(samAjax.ajaxurl, {
action: 'sam_hits',
hits: hits,
level: samAjax.level
});
}
}
});
})(jQuery);
2 changes: 1 addition & 1 deletion js/sam-layout.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 38 additions & 2 deletions sam-ajax-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
//A bit of security
$allowed_actions = array(
'sam_ajax_load_place',
'sam_ajax_load_places',
'sam_ajax_load_ads',
'sam_ajax_load_zone'
);

Expand All @@ -67,8 +67,44 @@
//'sql' => $ad->sql
));
}
else json_encode(array('success' => false, 'error' => 'Bad input data.'));
break;

case 'sam_ajax_load_ads':
if((isset($_POST['ads']) && is_array($_POST['ads'])) && isset($_POST['wc'])) {
$clauses = unserialize(base64_decode($_POST['wc']));
$places = $_POST['ads'];
$ads = array();
$ad = null;
include_once('ad.class.php');
foreach($places as $value) {
$placeId = $value[0];
$adId = $value[1];
$codes = $value[2];
$elementId = $value[3];
$args = array('id' => ($adId == 0) ? $placeId : $adId);

if($adId == 0) $ad = new SamAdPlace($args, $codes, false, $clauses, true);
else $ad = new SamAd($args, $codes, false, true);

array_push($ads, array(
'ad' => $ad->ad,
'id' => $ad->id,
'pid' => $ad->pid,
'cid' => $ad->cid,
'eid' => $elementId,
//'clauses' => $clauses,
//'sql' => $ad->sql
));
}
echo json_encode(array(
'success' => true,
'ads' => $ads
));
}
else json_encode(array('success' => false, 'error' => 'Bad input data.'));
break;
}
}
else echo json_encode(array('success' => false, 'error' => 'Not allowed'));
else echo json_encode(array('success' => false, 'error' => 'Not allowed.'));
wp_die();
23 changes: 22 additions & 1 deletion sam-ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function sanitize_option($option, $value) {
/*if($id > 0) $sql = "UPDATE $aTable sa SET sa.ad_hits = sa.ad_hits + 1 WHERE sa.id = %d;";
elseif($id == 0) $sql = "UPDATE $pTable sp SET sp.patch_hits = sp.patch_hits + 1 WHERE sp.id = %d;";
else $sql = '';*/
$sql = "INSERT HIGH_PRIORITY INTO $sTable (id, pid, event_time, event_type) VALUES (%d, %d, NOW(), 0);";
$sql = "INSERT INTO $sTable (id, pid, event_time, event_type) VALUES (%d, %d, NOW(), 0);";
if(!empty($sql)) $result = $wpdb->query($wpdb->prepare($sql, $id, $pid));
if($result === 1) echo json_encode(array('success' => true, 'id' => $id, 'pid' => $pid));
else echo json_encode(array(
Expand All @@ -106,6 +106,27 @@ function sanitize_option($option, $value) {
else echo json_encode(array('success' => false));
break;

case 'sam_ajax_sam_hits':
if(isset($_POST['hits']) && is_array($_POST['hits'])) {
$hits = $_POST['hits'];
$values = '';
$remoteAddr = $_SERVER['REMOTE_ADDR'];
foreach($hits as $hit) {
$values .= ((empty($values)) ? '' : ', ') . "({$hit[1]}, {$hit[0]}, NOW(), 0, \"{$remoteAddr}\")";
}
$sql = "INSERT INTO $sTable (id, pid, event_time, event_type, remote_addr) VALUES {$values};";
$result = $wpdb->query($sql);
if($result > 0) echo json_encode(array('success' => true, 'sql' => $sql, 'addr' => $_SERVER['REMOTE_ADDR']));
else echo json_encode(array(
'success' => false,
'result' => $result,
'sql' => $sql,
'hits' => $hits,
'values' => $values
));
}
break;

case 'sam_ajax_sam_maintenance':
if(false === ($mDate = get_transient( 'sam_maintenance_date' )) && $options['mailer']) {
include_once('sam.tools.php');
Expand Down
Loading

0 comments on commit 2f1fed5

Please sign in to comment.