a bunch of changes

This commit is contained in:
John Bintz 2009-02-11 18:24:42 -05:00
parent f3068cd88e
commit 41a7d9d782
7 changed files with 100 additions and 23 deletions

View File

@ -26,6 +26,7 @@ class PWAdboxesClient {
type int(1) NOT NULL, type int(1) NOT NULL,
adboxid int(11) NOT NULL, adboxid int(11) NOT NULL,
sitename char(100) NOT NULL, sitename char(100) NOT NULL,
adtype char(30) NOT NULL,
url char(255) NOT NULL, url char(255) NOT NULL,
dimensions char(10) NOT NULL, dimensions char(10) NOT NULL,
rating char(10) NOT NULL, rating char(10) NOT NULL,

View File

@ -23,7 +23,9 @@ class PublisherInfo {
$this->current_type = $type; $this->current_type = $type;
$this->is_valid = true; $this->is_valid = true;
if (($result = xml_parse($this->parser, $string, true)) != 1) { $this->is_valid = false; } if (($result = xml_parse($this->parser, $string, true)) != 1) {
$this->is_valid = false;
}
xml_parser_free($this->parser); xml_parser_free($this->parser);
if ($this->is_valid) { if ($this->is_valid) {
@ -55,18 +57,21 @@ class PublisherInfo {
break; break;
case "PW:ADBOX": case "PW:ADBOX":
$new_attributes = array(); $new_attributes = array();
foreach (array('ADBOXID', 'SITENAME', 'URL', 'DIMENSIONS', 'RATING', 'CATEGORY') as $field) { $translated_attributes = array('TYPE' => 'adtype');
foreach (array('ADBOXID', 'SITENAME', 'TYPE', 'URL', 'DIMENSIONS', 'RATING', 'CATEGORY') as $field) {
if (!isset($attributes[$field])) { if (!isset($attributes[$field])) {
$this->is_valid = false; break; $this->is_valid = false; break;
} else { } else {
$new_attributes[strtolower($field)] = $attributes[$field]; $target_field = strtolower($field);
if (isset($translated_attributes[$field])) { $target_field = $translated_attributes[$field]; }
$new_attributes[$target_field] = $attributes[$field];
} }
} }
if ($this->is_valid) { if ($this->is_valid) {
if (!is_numeric($attributes['ADBOXID'])) { $this->is_valid = false; break; } if (!is_numeric($attributes['ADBOXID'])) { $this->is_valid = false; break; }
if (preg_match('#^[0-9]+x[0-9]+$#', $attributes['DIMENSIONS']) == 0) { $this->is_valid = false; break; } if (preg_match('#^[0-9]+x[0-9]+$#', $attributes['DIMENSIONS']) == 0) { $this->is_valid = false; break; }
if (($result = parse_url($attributes['URL'])) === false) { $this->is_valid = false; break; } if (($result = parse_url($attributes['URL'])) === false) { $this->is_valid = false; break; }
foreach (array('scheme', 'host', 'path') as $part) { foreach (array('scheme', 'host') as $part) {
if (!isset($result[$part])) { $this->is_valid = false; break; } if (!isset($result[$part])) { $this->is_valid = false; break; }
} }
@ -113,7 +118,7 @@ class PublisherInfo {
foreach ($this->adboxes as $adbox) { foreach ($this->adboxes as $adbox) {
$widgets[] = array( $widgets[] = array(
"id" => "project_wonderful_{$this->memberid}_{$adbox->adboxid}", "id" => "project_wonderful_{$this->memberid}_{$adbox->adboxid}",
"name" => sprintf(__('PW %1$s %2$s (%3$s)', 'comicpress-manager'), $adbox->dimensions, $adbox->sitename, $adbox->adboxid), "name" => sprintf(__('PW %1$s %2$s %3$s (%4$s)', 'comicpress-manager'), $adbox->adtype, $adbox->dimensions, $adbox->sitename, $adbox->adboxid),
"options" => array("adboxid" => $adbox->adboxid) "options" => array("adboxid" => $adbox->adboxid)
); );
} }

View File

@ -66,9 +66,11 @@ class PluginWonderful {
function set_up_widgets() { function set_up_widgets() {
if ($this->publisher_info !== false) { if ($this->publisher_info !== false) {
foreach ($this->publisher_info->get_sidebar_widget_info() as $widget_info) { if (($widgets = $this->publisher_info->get_sidebar_widget_info()) !== false) {
extract($widget_info); foreach ($widgets as $widget_info) {
wp_register_sidebar_widget($id, $name, array($this, 'render_widget'), "", $options['adboxid']); extract($widget_info);
wp_register_sidebar_widget($id, $name, array($this, 'render_widget'), "", $options['adboxid']);
}
} }
} }
} }
@ -119,22 +121,52 @@ class PluginWonderful {
if (method_exists($this, $action)) { call_user_func(array($this, $action)); } if (method_exists($this, $action)) { call_user_func(array($this, $action)); }
} }
function handle_action_rebuild_database() {
$this->adboxes_client->destroy();
$this->adboxes_client->initialize();
$this->messages[] = __("Adbox database destroyed and rebuilt.", 'plugin-wonderful');
if (get_option('plugin-wonderful-memberid') != "") {
if (($result = file_get_contents(sprintf(PLUGIN_WONDERFUL_XML_URL, (int)get_option('plugin-wonderful-memberid')))) !== false) {
$this->publisher_info = new PublisherInfo();
if ($this->publisher_info->parse($result)) {
$this->adboxes_client->post_ads($this->publisher_info);
$this->messages[] = sprintf(__('Adbox information redownloaded.', 'plugin-wonderful'), (int)$_POST['memberid']);
} else {
$this->messages[] = __("Unable to parse publisher data from Project Wonderful.", 'plugin-wonderful');
$this->publisher_info = false;
}
} else {
$this->messages[] = __("Unable to read publisher data from Project Wonderful.", 'plugin-wonderful');
$this->publisher_info = false;
}
}
}
function handle_action_change_memberid() { function handle_action_change_memberid() {
if (trim($_POST['memberid'])) { if (trim($_POST['memberid'])) {
if (trim($_POST['memberid']) === (string)(int)$_POST['memberid']) { if (trim($_POST['memberid']) === (string)(int)$_POST['memberid']) {
if (($result = file_get_contents(sprintf(PLUGIN_WONDERFUL_XML_URL, (int)$_POST['memberid']))) !== false) { if (($result = file_get_contents(sprintf(PLUGIN_WONDERFUL_XML_URL, (int)$_POST['memberid']))) !== false) {
update_option('plugin-wonderful-memberid', (int)$_POST['memberid']);
$this->publisher_info = new PublisherInfo(); $this->publisher_info = new PublisherInfo();
$this->publisher_info->parse($result); if ($this->publisher_info->parse($result)) {
update_option('plugin-wonderful-memberid', (int)$_POST['memberid']);
$this->adboxes_client->post_ads($publisher_info); $this->adboxes_client->post_ads($this->publisher_info);
$this->messages[] = sprintf(__('Member ID changed to %s and adbox information redownloaded.', 'plugin-wonderful'), (int)$_POST['memberid']); $this->messages[] = sprintf(__('Member number changed to %s and adbox information redownloaded.', 'plugin-wonderful'), (int)$_POST['memberid']);
} else {
$this->messages[] = __("Unable to parse publisher data from Project Wonderful.", 'plugin-wonderful');
update_option('plugin-wonderful-memberid', "");
$this->publisher_info = false;
}
} else { } else {
$this->messages[] = __("Unable to read publisher data from Project Wonderful.", 'plugin-wonderful'); $this->messages[] = __("Unable to read publisher data from Project Wonderful.", 'plugin-wonderful');
update_option('plugin-wonderful-memberid', "");
$this->publisher_info = false;
} }
} else { } else {
$this->messages[] = __("Member IDs need to be numeric.", 'plugin-wonderful'); $this->messages[] = __("Member numbers need to be numeric.", 'plugin-wonderful');
update_option('plugin-wonderful-memberid', "");
$this->publisher_info = false;
} }
} else { } else {
$this->messages[] = __("Existing adbox information removed.", 'plugin-wonderful'); $this->messages[] = __("Existing adbox information removed.", 'plugin-wonderful');
@ -159,4 +191,4 @@ function the_project_wonderful_ad($adboxid) {
$plugin_wonderful->render_widget(array(), $adboxid); $plugin_wonderful->render_widget(array(), $adboxid);
} }
?> ?>

18
readme.txt Normal file
View File

@ -0,0 +1,18 @@
=== Plugin Wonderful ===
Contributors: johncoswell
Tags: ads, sidebar, widget
Requires at least: 2.7
Tested up to: 2.7
Stable tag: 0.1
Plugin Wonderful lets Project Wonderful publishers quickly and easily add their adboxes to thier WordPress blog.
== Description ==
Plugin Wonderful downloads your adbox information from Project Wonderful and creates a series of widgets that can easily be added to your sidebars. It also adds a new template tag, <tt>the\_project\_wonderful\_ad()</tt>, that lets you embed Project Wonderful ads directly into your site. Adbox code is downloaded straight from Project Wonderful, so your adboxes are always displayed correctly.
== Frequently Asked Questions ==
= Where do I get my member number? =
Log in to your Project Wonderful account and view your profile by clicking on your profile picture on the right. Your member number is the first item listed in your profile.

View File

@ -13,7 +13,7 @@ class TestPWAdboxesClient extends PHPUnit_Framework_TestCase {
$this->sample_ad = (object)array('adboxid' => 1, 'sitename' => "a", 'url' => "http://meow.raow/", $this->sample_ad = (object)array('adboxid' => 1, 'sitename' => "a", 'url' => "http://meow.raow/",
'dimensions' => "1x1", 'rating' => "a", 'category' => "a", 'dimensions' => "1x1", 'rating' => "a", 'category' => "a",
'description' => "a", 'tags' => 'a', 'standardcode' => 'a', 'description' => "a", 'tags' => 'a', 'standardcode' => 'a',
'advancedcode' => 'a'); 'advancedcode' => 'a', 'adtype' => 'a');
} }
function testCreateTables() { function testCreateTables() {
@ -49,7 +49,7 @@ class TestPWAdboxesClient extends PHPUnit_Framework_TestCase {
$ads->adboxes = array($this->sample_ad); $ads->adboxes = array($this->sample_ad);
$wpdb->expects($this->exactly(10))->method('escape'); $wpdb->expects($this->exactly(11))->method('escape');
$wpdb->expects($this->exactly(2))->method('query')->will($this->returnCallback(array($this, 'postAdsCallback'))); $wpdb->expects($this->exactly(2))->method('query')->will($this->returnCallback(array($this, 'postAdsCallback')));
$this->database_client->post_ads($ads, PW_ADBOXES_PROJECT_WONDERFUL); $this->database_client->post_ads($ads, PW_ADBOXES_PROJECT_WONDERFUL);

View File

@ -11,6 +11,7 @@ class TestPublisherInfo extends PHPUnit_Framework_TestCase {
$this->default_data = array( $this->default_data = array(
array("3", 'adboxid'), array("3", 'adboxid'),
array("a", 'sitename'), array("a", 'sitename'),
array("a", 'adtype'),
array("http://meow.raow/", 'url'), array("http://meow.raow/", 'url'),
array("1x1", 'dimensions'), array("1x1", 'dimensions'),
array("a", 'rating'), array("a", 'rating'),
@ -47,7 +48,7 @@ class TestPublisherInfo extends PHPUnit_Framework_TestCase {
public static function goodDataProvider() { public static function goodDataProvider() {
return array( return array(
array('<pw:member memberid="1"><pw:adboxes></pw:adboxes></pw:member>'), array('<pw:member memberid="1"><pw:adboxes></pw:adboxes></pw:member>'),
array('<pw:member memberid="1"><pw:adboxes><pw:adbox adboxid="5" sitename="a" url="http://meow.raow/" dimensions="1x1" rating="a" category="a"><pw:description>a</pw:description><pw:tags>a</pw:tags><pw:standardcode>a</pw:standardcode><pw:advancedcode>a</pw:advancedcode></pw:adbox></pw:adboxes></pw:member>') array('<pw:member memberid="1"><pw:adboxes><pw:adbox adboxid="5" type="a" sitename="a" url="http://meow.raow/" dimensions="1x1" rating="a" category="a"><pw:description>a</pw:description><pw:tags>a</pw:tags><pw:standardcode>a</pw:standardcode><pw:advancedcode>a</pw:advancedcode></pw:adbox></pw:adboxes></pw:member>')
); );
} }
@ -59,7 +60,7 @@ class TestPublisherInfo extends PHPUnit_Framework_TestCase {
} }
public function testPWAPI() { public function testPWAPI() {
$this->parser->parse('<pw:member memberid="1"><pw:adboxes><pw:adbox adboxid="3" sitename="a" url="http://meow.raow/" dimensions="1x1" rating="a" category="a"><pw:description>a</pw:description><pw:tags>a</pw:tags><pw:standardcode>a</pw:standardcode><pw:advancedcode>a</pw:advancedcode></pw:adbox></pw:adboxes></pw:member>'); $this->parser->parse('<pw:member memberid="1"><pw:adboxes><pw:adbox type="a" adboxid="3" sitename="a" url="http://meow.raow/" dimensions="1x1" rating="a" category="a"><pw:description>a</pw:description><pw:tags>a</pw:tags><pw:standardcode>a</pw:standardcode><pw:advancedcode>a</pw:advancedcode></pw:adbox></pw:adboxes></pw:member>');
$this->assertEquals(1, $this->parser->memberid); $this->assertEquals(1, $this->parser->memberid);
$this->assertEquals(1, count($this->parser->adboxes)); $this->assertEquals(1, count($this->parser->adboxes));
@ -86,7 +87,7 @@ class TestPublisherInfo extends PHPUnit_Framework_TestCase {
$sidebar_info = array( $sidebar_info = array(
array( array(
"id" => "project_wonderful_1_{$default_data_as_hash['adboxid']}", "id" => "project_wonderful_1_{$default_data_as_hash['adboxid']}",
"name" => "PW {$default_data_as_hash['dimensions']} {$default_data_as_hash['sitename']} ({$default_data_as_hash['adboxid']})", "name" => "PW {$default_data_as_hash['sitename']} {$default_data_as_hash['dimensions']} {$default_data_as_hash['adtype']} ({$default_data_as_hash['adboxid']})",
"options" => array("adboxid" => $default_data_as_hash['adboxid']) "options" => array("adboxid" => $default_data_as_hash['adboxid'])
) )
); );

View File

@ -2,9 +2,10 @@
<input type="hidden" name="action" value="change-memberid" /> <input type="hidden" name="action" value="change-memberid" />
<table class="form-table"> <table class="form-table">
<tr> <tr>
<th scope="row">Your advertiser number</th> <th scope="row">Your member number</th>
<td> <td>
<input id="memberid" name="memberid" value="<?php echo get_option("plugin-wonderful-memberid") ?>" /> <input id="memberid" name="memberid" value="<?php echo get_option("plugin-wonderful-memberid") ?>" />
<em>(you can find your member number by logging in to Project Wonderful and clicking on your profile image in the upper right of the page)</em>
</td> </td>
</tr> </tr>
<tr> <tr>
@ -33,6 +34,7 @@
<tr> <tr>
<th width="20%" class="manage-column">Site Name</th> <th width="20%" class="manage-column">Site Name</th>
<th width="30%" class="manage-column">Description</th> <th width="30%" class="manage-column">Description</th>
<th class="manage-column" align="center">Size</th>
<th class="manage-column" align="center">Dimensions</th> <th class="manage-column" align="center">Dimensions</th>
<th class="manage-column" align="center">Category</th> <th class="manage-column" align="center">Category</th>
<th style="text-align: right !important" width="25%" class="manage-column">Template Tag <em>(for direct use in theme)</em></th> <th style="text-align: right !important" width="25%" class="manage-column">Template Tag <em>(for direct use in theme)</em></th>
@ -44,6 +46,7 @@
<tr> <tr>
<td><a href="<?php echo $adbox->url ?>" target="_top" title="Ad for use on <?php echo $adbox->url ?> (opens in new window)"><?php echo $adbox->sitename ?></a></td> <td><a href="<?php echo $adbox->url ?>" target="_top" title="Ad for use on <?php echo $adbox->url ?> (opens in new window)"><?php echo $adbox->sitename ?></a></td>
<td><?php echo $adbox->description ?></td> <td><?php echo $adbox->description ?></td>
<td><?php echo $adbox->adtype ?></td>
<td><?php echo $adbox->dimensions ?></td> <td><?php echo $adbox->dimensions ?></td>
<td><?php echo $adbox->category ?></td> <td><?php echo $adbox->category ?></td>
<td align="right"><tt>the_project_wonderful_ad(<?php echo $adbox->adboxid ?>)</tt></td> <td align="right"><tt>the_project_wonderful_ad(<?php echo $adbox->adboxid ?>)</tt></td>
@ -53,12 +56,29 @@
?> ?>
</table> </table>
<h3>Using Widgets to Put Ads on Your Site</h3>
<p>
Visit <a href="widgets.php">Appearance -> Widgets</a> to quickly add Project Wonderful advertisements to your site. Plugin Wonderful widgets start with &quot;PW&quot;.
</p>
<h3>Using the Template Tags in Your Theme</h3> <h3>Using the Template Tags in Your Theme</h3>
<p> <p>
Find the location in your theme where you want the ad to appear. Type in the template tag, surrounded in PHP tags, like this: Find the location in your theme where you want the ad to appear. Type in the template tag for that ad, surrounded in PHP tags, like this:
</p> </p>
<tt> <tt>
&lt;?php the_project_wonderful_ad(<?php echo $first_adboxid ?>) ?&gt; &lt;?php the_project_wonderful_ad(<?php echo $first_adboxid ?>) ?&gt;
</tt> </tt>
<?php if (isset($_GET['allow-destroy'])) { ?>
<h3>Rebuilding Your Project Wonderful Ad Database</h3>
<p>
If you are having issues with your ads not downloading correctly from Project Wonderful, click this button to destroy and rebuild the database that stores ad info.
</p>
<form id="pw-handler" action="" method="post">
<input type="hidden" name="action" value="rebuild-database" />
<input type="submit" value="Destroy and Rebuild Database" class="button" />
</form>
<?php } ?>
<?php } ?> <?php } ?>