config = array(
/*
!! IMPORTANT !!
The following settings are automatically overridden by values from the database on page load.
Any changes made here will not take any effect.
!! IMPORTANT !!
*/
// 'max_size' is the amount of asset slots to fill. Each asset can be set to take up any amount of slots.
'max_size' => 5,
// 'before' is displayed directly BEFORE the assets are shown on the screen
'before' => '
';
// edit asset
if (isset($_GET['ed']))
{
$ed_id = preg_replace("/\D/", "", $_GET['ed']);
if (is_numeric($ed_id) && $ed_id != '')
{
if (isset($_POST['23fy894ifgh']))
{
if ($_POST['23fy894ifgh'] == "r312ogr23hr")
{
$at_error_fields = "";
if ($_POST['field_title'] == "") $at_error_fields .= ", Title";
if ($_POST['field_link'] == "") $at_error_fields .= ", Link";
if ($_POST['field_imageurl'] == "") $at_error_fields .= ", Image URL";
if ($_POST['field_size'] == "") $at_error_fields .= ", Size";
if ($_POST['field_tags'] == "") $at_error_fields .= ", Tags";
if ($at_error_fields != "")
{
echo '
Edit Asset
';
echo "
Error!
The following fields were not filled out: " . trim($at_error_fields, ", ") . "
";
$this->asset_form("tools.php?page=asset-tracker-list&ed=$ed_id", $_POST['field_title'], $_POST['field_link'], $_POST['field_imageurl'], $_POST['field_size'], $_POST['field_tags']);
return 1;
}
$field_title = mysql_real_escape_string(htmlentities($_POST['field_title']));
$field_link = mysql_real_escape_string(htmlentities($_POST['field_link']));
$field_imageurl = mysql_real_escape_string(htmlentities($_POST['field_imageurl']));
$field_size = mysql_real_escape_string(htmlentities($_POST['field_size']));
$field_tags = mysql_real_escape_string(str_replace(" ", ",", str_replace(",,", ",", htmlentities($_POST['field_tags']))));
$wpdb->query("UPDATE {$wpdb->prefix}asset_tracker_assets SET
`title` = '$field_title',
`link` = '$field_link',
`imageurl` = '$field_imageurl',
`size` = $field_size,
`tags` = '$field_tags'
WHERE `id`=$ed_id limit 1");
$at_edited = true;
}
}
else
{
echo '
Edit Asset
';
$asset = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}asset_tracker_assets where `id`=$ed_id limit 1");
$this->asset_form("tools.php?page=asset-tracker-list&ed=$ed_id", $asset->title, $asset->link, $asset->imageurl, $asset->size, $asset->tags);
return 1;
}
}
}
// add asset
if (isset($_GET['add']))
{
if (isset($_POST['23fy894ifgh']))
{
if ($_POST['23fy894ifgh'] == "r312ogr23hr")
{
$at_error_fields = "";
if ($_POST['field_title'] == "") $at_error_fields .= ", Title";
if ($_POST['field_link'] == "") $at_error_fields .= ", Link";
if ($_POST['field_imageurl'] == "") $at_error_fields .= ", Image URL";
if ($_POST['field_size'] == "") $at_error_fields .= ", Size";
if ($_POST['field_tags'] == "") $at_error_fields .= ", Tags";
if ($at_error_fields != "")
{
echo '
Add Asset
';
echo "
Error!
The following fields were not filled out: " . trim($at_error_fields, ", ") . "
";
showAssetTrackerForm("tools.php?page=asset-tracker-list&add=1", $_POST['field_title'], $_POST['field_link'], $_POST['field_imageurl'], $_POST['field_size'], $_POST['field_tags']);
return 1;
}
$field_title = mysql_real_escape_string($_POST['field_title']);
$field_link = mysql_real_escape_string($_POST['field_link']);
$field_imageurl = mysql_real_escape_string($_POST['field_imageurl']);
$field_size = mysql_real_escape_string($_POST['field_size']);
$field_tags = mysql_real_escape_string(str_replace(" ", ",", str_replace(",,", ",", $_POST['field_tags'])));
$wpdb->query("INSERT INTO {$wpdb->prefix}asset_tracker_assets
(`title`,
`link`,
`imageurl`,
`size`,
`tags`)
values('$field_title',
'$field_link',
'$field_imageurl',
$field_size,
'$field_tags')");
$at_added = true;
}
}
else
{
echo '
Add Asset
';
$this->asset_form("tools.php?page=asset-tracker-list&add=1", "", "", "", "", "");
return 1;
}
}
if (isset($_GET['settings'])) {
echo '
Asset Tracker Settings
Back
';
if (isset($_POST['ht6jh7kte88j'])) {
if ($_POST['ht6jh7kte88j'] == '0kflmk3ef3wsf') {
foreach(array('max_size', 'before', 'after', 'display', 'noshow', 'noshow_type', 'cvar_slot', 'ganew') as $i) {
if (isset($_POST['field_'.$i])) {
$the_result[$i] = stripslashes($_POST['field_'.$i]);
}
}
update_option("asset_tracker", $the_result);
$this->load_settings();
echo "
Settings saved!
Asset Tracker settings saved. Note: some settings may require you to clear the plugin's cache before they will take effect.
";
}
}
$this->settings_form(array(
'field_max_size' => $this->config['max_size'],
'field_before' => $this->config['before'],
'field_after' => $this->config['after'],
'field_display' => $this->config['display'],
'field_noshow' => $this->config['noshow'],
'field_noshow_type' => $this->config['noshow_type'],
'field_cvar_slot' => $this->config['cvar_slot'],
'field_ganew' => $this->config['ganew']
));
return 1;
}
// content header
echo '
Asset Tracker
';
// delete asset
if (isset($_GET['del']))
{
$del_id = preg_replace("/\D/", "", $_GET['del']);
if (is_numeric($del_id) && $del_id != '')
if ($wpdb->query("DELETE FROM {$wpdb->prefix}asset_tracker_assets WHERE `id`=$del_id limit 1") > 0)
echo "
Asset Deleted!
Asset #$del_id has been deleted.
";
}
// clear cache
if (isset($_GET['cc']))
{
if ($_GET['cc'] == 1)
{
$wpdb->query("DELETE FROM {$wpdb->prefix}asset_tracker_cache");
echo "
Cache Cleared!
The asset tracker cache has been deleted.
";
}
}
// edited message
if (isset($at_edited))
echo "
Asset Edited!
Asset #" . $_GET['ed'] . " has been edited.
";
// added message
if (isset($at_added))
echo "
Asset Added!
Asset added.
";
// show list
$total_cached = $wpdb->get_var("SELECT count(*) FROM {$wpdb->prefix}asset_tracker_cache");
echo "
There are currently $total_cached cached asset tracker sets. Clear cache
";
echo "
Add asset | Settings
| Title | Link | Image URL | Size | Tags |
";
$assets = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}asset_tracker_assets");
foreach ($assets as $asset)
{
echo "
$asset->title
|
$asset->link |
$asset->imageurl |
$asset->size |
$asset->tags |
";
}
echo '
';
}
// Backend menu item
public function backend_menu() {
add_submenu_page('tools.php', 'Assets', 'Asset Tracker', 'administrator', 'asset-tracker-list', array($this, "options"));
}
// Show assets
public function show() {
global $post, $wpdb;
$noshow_ids = explode(",", str_replace(",,", ",", str_replace(" ", ",", $this->config['noshow'])));
$display = false;
if (is_array($noshow_ids)) {
if ($this->config['noshow_type'] == '1') { // include
if (in_array($post->ID, $noshow_ids)) {
$display = true;
}
} else if (!in_array($post->ID, $noshow_ids)) { // exclude
$display = true;
}
}
else {
$display = true;
}
if ($post->ID > 0 && $display)
{
echo $this->config['before'];
$act_output = $wpdb->get_var("SELECT `content` FROM {$wpdb->prefix}asset_tracker_cache WHERE `post_id` = $post->ID");
if ($act_output == "")
{
$page_tags = str_replace(" ", "", str_replace("\n", "", str_replace("\r", "", strip_tags($post->post_content))));
$page_tags = strtolower(ereg_replace("[^A-Za-z0-9]", ",", $page_tags));
$page_tags = str_replace(",,", ",", $page_tags);
$a_page_tag = explode(",", $page_tags);
$act_output = "";
$act_space = $this->config['max_size'];
$total_acts = 0;
for ($i=0;$i<$this->config['max_size'];$i++)
for ($a=0;$a<6;$a++)
$top_act[$i][$a] = 0;
$assets = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}asset_tracker_assets where `link`!='" . $this->get_url() . "' and `link`!='" . $this->get_url(false) . "' and `link`!='" . $this->get_rel_url() . "' and `link`!='" . $this->get_rel_url(false) . "' order by rand()");
foreach ($assets as $asset)
{
$act_score = 0;
$a_at_tag = explode(",", strtolower($asset->tags));
foreach($a_page_tag as $page_tag)
{
foreach($a_at_tag as $at_tag)
{
if (strcasecmp($page_tag, $at_tag) == 0)
{
$act_score++;
}
}
}
if ($act_space >= $asset->size && $act_score > 0)
{
for ($i=0;$i<$act_space;$i++)
{
if ($act_score > $top_act[$i][0])
{
for ($z=($act_space-1);$z>0;$z--)
{
if ($i < $z)
{
$top_act[$z][0] = $top_act[$z-1][0];
$top_act[$z][1] = $top_act[$z-1][1];
$top_act[$z][2] = $top_act[$z-1][2];
$top_act[$z][3] = $top_act[$z-1][3];
$top_act[$z][4] = $top_act[$z-1][4];
$top_act[$z][5] = $top_act[$z-1][5];
}
}
$top_act[$i][0] = $act_score;
$top_act[$i][1] = $asset->id;
$top_act[$i][2] = $asset->title;
$top_act[$i][3] = $asset->imageurl;
$top_act[$i][4] = $asset->size;
$top_act[$i][5] = $asset->link;
$act_space -= $asset->size;
$total_acts++;
break;
}
}
}
}
// Here is the javascript code which sends the pageview info to Google Analytics
if ($this->config['cvar_slot'] != '0') {
if ($this->config['ganew'] == '1') {
$onclick = 'javascript:var _gaq=_gaq||[];_gaq.push([\'_setCustomVar\','.$at_config['cvar_slot'].',\''.$at_config['cvar_title'].'\',\'%s\',3]);';
} else {
$onclick = 'javascript:pageTracker._setCustomVar('.$this->config['cvar_slot'].', \''.$this->config['cvar_title'].'\',\'%s\',3); pageTracker._trackPageview();';
}
}
$act_space = $this->config['max_size'];
for ($i=0;$i<$act_space;$i++)
{
if ($top_act[$i][0] > 0 && $act_space >= $top_act[$i][4])
{
$act_output .= $this->config['item_html'][0] . $top_act[$i][5] . $this->config['item_html'][1] . $wpdb->prepare($onclick, array($top_act[$i][2])) . $this->config['item_html'][2] . $top_act[$i][3] . $this->config['item_html'][3] . $top_act[$i][2] . $this->config['item_html'][4];
$act_space -= intval($top_act[$i][4]);
}
}
if ($act_space > 0)
{
$at_query = "SELECT * FROM {$wpdb->prefix}asset_tracker_assets where `size` <= $act_space and `link`!='" . $this->get_url() . "' and `link`!='" . $this->get_url(false) . "' and `link`!='" . $this->get_rel_url() . "' and `link`!='" . $this->get_rel_url(false) . "' order by rand()";
$at_query = $wpdb->get_results($at_query);
foreach ($assets as $asset)
{
if ($asset->size <= $act_space && $asset->id != $top_act[0][1] && $asset->id != $top_act[1][1] && $asset->id != $top_act[2][1])
{
$act_output .= $this->config['item_html'][0] . $asset->link . $this->config['item_html'][1] . $wpdb->prepare($onclick, array($asset->title)) . $this->config['item_html'][2] . $asset->imageurl . $this->config['item_html'][3] . $asset->title . $this->config['item_html'][4];
$act_space -= $asset->size;
if (!$act_space) break;
}
}
}
$wpdb->insert("{$wpdb->prefix}asset_tracker_cache", array('post_id' => $post->ID, 'content' => $act_output), array('%d', '%s'));
}
echo $act_output;
echo $this->config['after'];
}
}
}
$v_asset_tracker = new asset_tracker;
function at_show_assets() {
global $v_asset_tracker;
$v_asset_tracker->show();
}
?>