"can't read",
'CANT_PARSE' => "can't parse",
'DOWNLOADED' => "downloaded"
);
function PluginWonderful() {}
/**
* Wrapper around file_get_contents for testing purposes.
*/
function _retrieve_url($url) {
return @file_get_contents($url);
}
/**
* Initialize the object if it isn't already.
*/
function init() {
if (empty($this->adboxes_client)) {
$this->messages = array();
$this->adboxes_client = new PWAdboxesClient();
$this->_get_publisher_info();
$this->_update_database_version();
if (!empty($_POST)) { $this->handle_action(); }
}
}
/**
* Wrapper around PublisherInfo generation for testing.
*/
function _get_new_publisher_info_object() {
return new PublisherInfo();
}
/**
* Check to see if the database schema needs to be updated.
*/
function _update_database_version() {
$result = get_option('plugin-wonderful-database-version');
if (empty($result) || ($result < PLUGIN_WONDERFUL_DATABASE_VERSION)) {
if ($this->adboxes_client->initialize(true)) {
update_option('plugin-wonderful-database-version', PLUGIN_WONDERFUL_DATABASE_VERSION);
} else {
$this->messages[] = "Unable to update database schema!";
}
}
}
/**
* Get publisher info (adboxes) from cache or from Project Wonderful.
* @return PublisherInfo|boolean The PublisherInfo object with adbox information, or false if there was a problem.
*/
function _get_publisher_info() {
$this->publisher_info = false;
$member_id = get_option('plugin-wonderful-memberid');
if (is_numeric($member_id)) {
$member_id = (int)$member_id;
$this->publisher_info = $this->adboxes_client->get_ads($member_id);
$last_update = get_option('plugin-wonderful-last-update') ;
if (!is_numeric($last_update)) { $last_update = 0; }
$last_update = (int)$last_update;
if (($last_update + PLUGIN_WONDERFUL_UPDATE_TIME) < time()) {
$this->_download_project_wonderful_data($member_id);
}
}
return $this->publisher_info;
}
function insert_rss_feed_ads($content) {
if (is_feed()) {
if ($this->publisher_info !== false) {
foreach ($this->publisher_info->adboxes as $adbox) {
if ($adbox->in_rss_feed == 1) {
if (preg_match("##mis", $adbox->advancedcode, $matches) > 0) {
echo $matches[1];
}
}
}
}
}
return $content;
}
/**
* Inject ads into the body copy of posts.
* @param string $body The body to search for PW() tags.
* @return string The modified body.
*/
function inject_ads_into_body_copy($body) {
if ($this->publisher_info !== false) {
if (get_option("plugin-wonderful-enable-body-copy-embedding") == 1) {
return $this->publisher_info->inject_ads_into_body_copy($body, (get_option("plugin-wonderful-use-standardcode") == 1));
}
}
return $body;
}
function set_up_menu() {
add_options_page('Plugin Wonderful', __("Plugin Wonderful", 'plugin-wonderful'), 5, __FILE__, array($this, "plugin_wonderful_main"));
}
function handle_activation() {
$this->init();
$this->adboxes_client->initialize();
}
function plugin_wonderful_main() {
$this->get_view(__FUNCTION__);
}
function show_messages() {
if (count($this->messages) > 0) {
echo '
';
foreach ($this->messages as $message) { echo '
' . $message . '
'; }
echo '
';
}
}
function _create_target($name, $source) {
return dirname(__FILE__) . "/../{$source}/{$name}.php";
}
function _include($target) { include($target); }
function _file_exists($target) { return @file_exists($target); }
function get_view($function_name) {
$target = $this->_create_target(str_replace('plugin_wonderful_', '', $function_name), "views");
if ($this->_file_exists($target)) {
$info = get_plugin_data(realpath(__FILE__));
echo '