Ejemplo n.º 1
0
function adrotate_activate()
{
    global $wpdb;
    $tables = array($wpdb->prefix . "adrotate", $wpdb->prefix . "adrotate_groups", $wpdb->prefix . "adrotate_tracker");
    if ($wpdb->has_cap('collation')) {
        if (!empty($wpdb->charset)) {
            $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}";
        }
        if (!empty($wpdb->collate)) {
            $charset_collate .= " COLLATE {$wpdb->collate}";
        }
    }
    if (!adrotate_mysql_table_exists($tables[0])) {
        // Add table if it's not there
        $add1 = "CREATE TABLE " . $tables[0] . " (\n\t\t\t  `id` mediumint(8) unsigned NOT NULL auto_increment,\n\t\t\t  `title` longtext NOT NULL,\n\t\t\t  `bannercode` longtext NOT NULL,\n\t\t\t  `thetime` int(15) NOT NULL default '0',\n\t\t\t  `updated` int(15) NOT NULL,\n\t\t\t  `author` varchar(60) NOT NULL default '',\n\t\t\t  `active` varchar(4) NOT NULL default 'yes',\n\t\t\t  `startshow` int(15) NOT NULL default '0',\n\t\t\t  `endshow` int(15) NOT NULL default '0',\n\t\t\t  `group` int(15) NOT NULL default '1',\n\t\t\t  `image` varchar(255) NOT NULL,\n\t\t\t  `link` longtext NOT NULL,\n\t\t\t  `tracker` varchar(5) NOT NULL default 'N',\n\t\t\t  `clicks` int(15) NOT NULL default '0',\n\t\t\t  `maxclicks` int(15) NOT NULL default '0',\n\t\t\t  `shown` int(15) NOT NULL default '0',\n\t\t\t  `maxshown` int(15) NOT NULL default '0',\t\t\t  \n\t\t\t  `magic` int(1) NOT NULL default '0',\n\t  \t\tPRIMARY KEY  (`id`)\n\t\t\t) " . $charset_collate;
        if (mysql_query($add1) !== true) {
            adrotate_mysql_warning();
        }
    }
    if (!adrotate_mysql_table_exists($tables[1])) {
        $add2 = "CREATE TABLE " . $tables[1] . " (\n\t\t\t\t`id` mediumint(8) unsigned NOT NULL auto_increment,\n\t\t\t\t`name` varchar(255) NOT NULL,\n\t\t\t\t`fallback` varchar(5) NOT NULL default '0',\n\t\t\t\tPRIMARY KEY  (`id`)\n\t\t\t) " . $charset_collate;
        if (mysql_query($add2) !== true) {
            adrotate_mysql_warning();
        }
    }
    if (!adrotate_mysql_table_exists($tables[2])) {
        $add3 = "CREATE TABLE " . $tables[2] . " (\n\t\t\t\t`id` mediumint(8) unsigned NOT NULL auto_increment,\n\t\t\t\t`ipaddress` varchar(255) NOT NULL,\n\t\t\t\t`timer` int(15) NOT NULL default '0',\n\t\t\t\t`bannerid` int(15) NOT NULL default '0',\n\t\t\t\tPRIMARY KEY  (`id`)\n\t\t\t) " . $charset_collate;
        if (mysql_query($add3) !== true) {
            adrotate_mysql_warning();
        }
    }
    if (adrotate_mysql_table_exists($tables[0])) {
        // Upgrade table if it is incomplete
        if (!($result = mysql_query("SHOW COLUMNS FROM `{$tables['0']}`"))) {
            echo 'Could not run query: ' . mysql_error();
        }
        $i = 0;
        while ($row = mysql_fetch_assoc($result)) {
            $field_array[] = mysql_field_name($row, $i);
            $i++;
        }
        if (!in_array('startshow', $field_array)) {
            $upgrade = adrotate_update_table('add', $tables[0], 'startshow', 'INT( 15 ) NOT NULL DEFAULT \'0\'', 'active');
        }
        if (!in_array('endshow', $field_array)) {
            $upgrade = adrotate_update_table('add', $tables[0], 'endshow', 'INT( 15 ) NOT NULL DEFAULT \'0\'', 'startshow');
        }
        if (!in_array('link', $field_array)) {
            $upgrade = adrotate_update_table('add', $tables[0], 'link', 'LONGTEXT NOT NULL', 'image');
        }
        if (!in_array('tracker', $field_array)) {
            $upgrade = adrotate_update_table('add', $tables[0], 'tracker', 'VARCHAR( 5 ) NOT NULL DEFAULT \'N\'', 'link');
        }
        if (!in_array('clicks', $field_array)) {
            $upgrade = adrotate_update_table('add', $tables[0], 'clicks', 'INT( 15 ) NOT NULL DEFAULT \'0\'', 'tracker');
        }
        if (!in_array('maxclicks', $field_array)) {
            $upgrade = adrotate_update_table('add', $tables[0], 'maxclicks', 'INT( 15 ) NOT NULL DEFAULT \'0\'', 'clicks');
        }
        if (!in_array('shown', $field_array)) {
            $upgrade = adrotate_update_table('add', $tables[0], 'shown', 'INT( 15 ) NOT NULL DEFAULT \'0\'', 'maxclicks');
        }
        if (!in_array('maxshown', $field_array)) {
            $upgrade = adrotate_update_table('add', $tables[0], 'maxshown', 'INT( 15 ) NOT NULL DEFAULT \'0\'', 'shown');
        }
        if (!in_array('magic', $field_array)) {
            $upgrade = adrotate_update_table('add', $tables[0], 'magic', 'VARCHAR( 1 ) NOT NULL DEFAULT \'0\'', 'maxshown');
        }
    } else {
        // Or send out epic fail!
        adrotate_mysql_warning();
    }
    if (adrotate_mysql_table_exists($tables[1])) {
        // Upgrade table if it is incomplete
        if (!($result = mysql_query("SHOW COLUMNS FROM `{$tables['1']}`"))) {
            echo 'Could not run query: ' . mysql_error();
        }
        $i = 0;
        while ($row = mysql_fetch_assoc($result)) {
            $field_array[] = mysql_field_name($row, $i);
            $i++;
        }
        if (!in_array('name', $field_array)) {
            $upgrade = adrotate_update_table('add', $tables[1], 'fallback', 'VARCHAR( 5 ) NOT NULL DEFAULT \'0\'', 'name');
        }
    } else {
        // Or send out epic fail!
        adrotate_mysql_warning();
    }
    if (adrotate_mysql_table_exists($tables[2])) {
        // Upgrade table if it is incomplete
        if (!($result = mysql_query("SHOW COLUMNS FROM `{$tables['2']}`"))) {
            echo 'Could not run query: ' . mysql_error();
        }
        $i = 0;
        while ($row = mysql_fetch_assoc($result)) {
            $field_array[] = mysql_field_name($row, $i);
            $i++;
        }
        if (!in_array('bannerid', $field_array)) {
            $upgrade = adrotate_update_table('add', $tables[2], 'bannerid', 'INT( 15 ) NOT NULL DEFAULT \'0\'', 'timer');
        }
    } else {
        // Or send out epic fail!
        adrotate_mysql_warning();
    }
    if (!is_dir(ABSPATH . '/wp-content/banners')) {
        mkdir(ABSPATH . '/wp-content/banners', 0755);
    }
    delete_option('adrotate_tracker');
}
Ejemplo n.º 2
0
function adrotate_manage_group()
{
    global $wpdb, $userdata;
    $message = $_GET['message'];
    if ($_GET['edit_group']) {
        $group_edit_id = $_GET['edit_group'];
    }
    ?>

	<div class="wrap">
		<h2>Banner groups</h2>

		<?php 
    if ($message == 'created') {
        ?>
			<div id="message" class="updated fade"><p>Group <strong>created</strong>.</p></div>
		<?php 
    } else {
        if ($message == 'updated') {
            ?>
			<div id="message" class="updated fade"><p>Group <strong>updated</strong>.</p></div>
		<?php 
        } else {
            if ($message == 'deleted') {
                ?>
			<div id="message" class="updated fade"><p>Group <strong>deleted</strong>.</p></div>
		<?php 
            } else {
                if ($message == 'deleted_banners') {
                    ?>
			<div id="message" class="updated fade"><p>Group <strong>deleted</strong>. Including all <strong>ads</strong> that were in that group.</p></div>
		<?php 
                }
            }
        }
    }
    ?>

		<?php 
    if (!$group_edit_id) {
        ?>
			<form name="groups" id="post" method="post" action="admin.php?page=adrotate4">
	    	<input type="hidden" name="adrotate_action" value="group_delete" />

			<div class="tablenav">

				<div class="alignleft">
					<select name='adrotate_action' id='cat' class='postform' >
				        <option value="">Bulk Actions</option>
				        <option value="group_delete">Delete Group</option>
				        <option value="group_delete_banners">Delete Group including ads</option>
					</select>
					<input type="submit" id="post-action-submit" value="Go" class="button-secondary" />
				</div>
			</div>

		   	<table class="widefat" style="margin-top: .5em">
	  			<thead>
	  				<tr>
						<th scope="col" class="check-column">&nbsp;</th>
						<th scope="col" width="5%"><center>ID</center></th>
						<th scope="col">Name</th>
						<th scope="col" width="10%"><center>Fallback</center></th>
						<th scope="col" width="10%"><center>Banners</center></th>
					</tr>
	  			</thead>
				<tbody>
	  			
			<?php 
        if (adrotate_mysql_table_exists($wpdb->prefix . 'adrotate_groups')) {
            ?>
				<?php 
            $groups = $wpdb->get_results("SELECT * FROM `" . $wpdb->prefix . "adrotate_groups` ORDER BY `id`");
            if ($groups) {
                foreach ($groups as $group) {
                    $banners_in_group = $wpdb->get_var("SELECT COUNT(*) FROM `" . $wpdb->prefix . "adrotate` WHERE `group` = {$group->id}");
                    $class = 'alternate' != $class ? 'alternate' : '';
                    ?>
					    <tr id='group-<?php 
                    echo $group->id;
                    ?>
' class=' <?php 
                    echo $class;
                    ?>
'>
							<th scope="row" class="check-column"><input type="checkbox" name="groupcheck[]" value="<?php 
                    echo $group->id;
                    ?>
" /></th>
							<td><center><?php 
                    echo $group->id;
                    ?>
</center></td>
							<td><strong><a class="row-title" href="<?php 
                    echo get_option('siteurl') . '/wp-admin/admin.php?page=adrotate4&amp;edit_group=' . $group->id;
                    ?>
" title="Edit"><?php 
                    echo $group->name;
                    ?>
</a></strong></td>
							<td><center><?php 
                    if ($group->fallback == 0) {
                        echo "No";
                    } else {
                        echo $group->fallback;
                    }
                    ?>
</center></td>
							<td><center><?php 
                    echo $banners_in_group;
                    ?>
</center></td>
						</tr>
		 			<?php 
                }
                ?>
				<?php 
            } else {
                ?>
					<tr id='no-groups'>
						<th scope="row" class="check-column">&nbsp;</th>
						<td colspan="3"><em>No groups created yet!</em></td>
					</tr>
				<?php 
            }
            ?>
			<?php 
        } else {
            ?>
				<tr id='no-id'><td scope="row" colspan="4"><span style="font-weight: bold; color: #f00;">There was an error locating the database table for the AdRotate groups. Please deactivate and re-activate AdRotate from the plugin page!!<br />If this does not solve the issue please seek support at <a href="http://meandmymac.net/support/">http://meandmymac.net support</a></span></td></tr>
			<?php 
        }
        ?>
	 			</tbody>
			</table>

			<br class="clear" />

		   	<table class="widefat" style="margin-top: .5em">
	  			<thead>
	  				<tr>
						<th scope="col" colspan="2">Create a new group</th>
					</tr>
	  			</thead>
				<tbody>
	  			
			<?php 
        if (adrotate_mysql_table_exists($wpdb->prefix . 'adrotate_groups')) {
            ?>
				<?php 
            $groups = $wpdb->get_results("SELECT * FROM `" . $wpdb->prefix . "adrotate_groups` ORDER BY `id`");
            ?>
				    <tr id='group-new'>
						<th scope="row">Name:</th>
						<td><input tabindex="1" name="adrotate_group" type="text" class="search-input" size="40" value="" autocomplete="off" /></td>
					</tr>
				    <tr id='group-new'>
						<th scope="row">Fallback ads?</th>
						<td><select name="adrotate_fallback">
				        <option value="0">No</option>
					<?php 
            if ($groups and count($groups) > 1) {
                ?>
						<?php 
                foreach ($groups as $group) {
                    ?>
					        <option value="<?php 
                    echo $group->id;
                    ?>
"><?php 
                    echo $group->id;
                    ?>
 - <?php 
                    echo $group->name;
                    ?>
</option>
			 			<?php 
                }
                ?>
					<?php 
            }
            ?>
						</select> <em>You need atleast two groups to use this feature!</em></td>
					</tr>
					
			<?php 
        } else {
            ?>
				<tr id='no-id'><td scope="row" colspan="4"><span style="font-weight: bold; color: #f00;">There was an error locating the database table for the AdRotate groups. Please deactivate and re-activate AdRotate from the plugin page!!<br />If this does not solve the issue please seek support at <a href="http://meandmymac.net/support/">http://meandmymac.net support</a></span></td></tr>
			<?php 
        }
        ?>
	 			</tbody>
			</table>
			
	    	<p class="submit">
				<input tabindex="3" type="submit" name="adrotate_group_submit" class="button-primary" value="Add Group" />
				<a href="admin.php?page=adrotate4" class="button">Cancel</a>
	    	</p>

			</form>

			<br class="clear" />
			<?php 
        adrotate_credits();
        ?>

		<?php 
    } else {
        ?>

			<?php 
        $edit_group = $wpdb->get_row("SELECT * FROM `" . $wpdb->prefix . "adrotate_groups` WHERE `id` = '{$group_edit_id}'");
        $groups = $wpdb->get_results("SELECT * FROM `" . $wpdb->prefix . "adrotate_groups` ORDER BY `id`");
        if ($message == 'field_error') {
            ?>
				<div id="message" class="updated fade"><p>Please fill in a name for your group!</p></div>
			<?php 
        }
        if ($group_edit_id > 0) {
            ?>
			  	<form method="post" action="admin.php?page=adrotate4">
			    	<input type="hidden" name="adrotate_id" value="<?php 
            echo $group_edit_id;
            ?>
" />

			    	<table class="widefat" style="margin-top: .5em">

						<thead>
						<tr valign="top">
							<th colspan="2" bgcolor="#DDD">You can change the name of the group here. The ID stays the same!</th>
						</tr>
						</thead>

						<tbody>
				      	<tr>
					        <th scope="row" width="25%">ID:</th>
					        <td><?php 
            echo $edit_group->id;
            ?>
</td>
				      	</tr>
				      	<tr>
					        <th scope="row" width="25%">Name:</th>
					        <td><input tabindex="1" name="adrotate_group" type="text" size="67" class="search-input" autocomplete="off" value="<?php 
            echo $edit_group->name;
            ?>
" /></td>
				      	</tr>
				      	<tr>
					        <th scope="row" width="25%">Fallback ads:</th>
					        <td><select name="adrotate_fallback">
						        <option value="0">No</option>
							<?php 
            if ($groups and count($groups) > 1) {
                ?>
								<?php 
                foreach ($groups as $group) {
                    ?>
							        <option value="<?php 
                    echo $group->id;
                    ?>
" <?php 
                    if ($group->id == $group_edit_id) {
                        echo 'disabled';
                    }
                    ?>
 <?php 
                    if ($group->id == $edit_group->fallback) {
                        echo 'selected';
                    }
                    ?>
><?php 
                    echo $group->id;
                    ?>
 - <?php 
                    echo $group->name;
                    ?>
</option>
					 			<?php 
                }
                ?>
							<?php 
            }
            ?>
								</select> <em>You need atleast two groups to use this feature!</em>
							</td>
				      	</tr>
				      	</tbody>

					</table>

			    	<p class="submit">
						<input tabindex="2" type="submit" name="adrotate_group_submit" class="button-primary" value="Save Group" />
						<a href="admin.php?page=adrotate4" class="button">Cancel</a>
			    	</p>

			  	</form>
			<?php 
        } else {
            ?>
			    <table class="widefat" style="margin-top: .5em">
			    	<thead>
					<tr valign="top">
						<th>Error!</th>
					</tr>
					</thead>

					<tbody>
			      	<tr>
				        <td>No valid group ID specified! <a href="admin.php?page=adrotate4">Continue</a>.</td>
			      	</tr>
			      	</tbody>
				</table>
			<?php 
        }
        ?>
		<?php 
    }
    ?>
	</div>
<?php 
}