ArcadePress is an open source arcade plugin for Wordpress that allows you to turn any Wordpress site into a full arcade site, including flash game uploads, categories, highscores, game feeds & more.
Version: 0.65
Author: skybox3d.com
Author URI: http://www.skybox3d.com/
License: GPL2
*/
/*
Copyright 2010 Skybox3d.com (email : admin@skybox3d.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
//Global variables:
$arcadepress_version = 0.65;
$arcadepress_db_version = 0.65;
$APjavascriptQueue = NULL;
// Pre-2.6 compatibility, which is actually frivilous since we use the 2.8+ widget technique
if ( ! defined( 'WP_CONTENT_URL' ) )
define( 'WP_CONTENT_URL', get_option( 'siteurl' ) . '/wp-content' );
if ( ! defined( 'WP_CONTENT_DIR' ) )
define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
if ( ! defined( 'WP_PLUGIN_URL' ) )
define( 'WP_PLUGIN_URL', WP_CONTENT_URL. '/plugins' );
if ( ! defined( 'WP_PLUGIN_DIR' ) )
define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
// Create the proper directory structure if it is not already created
if(!is_dir(WP_CONTENT_DIR . '/uploads/')) {
mkdir(WP_CONTENT_DIR . '/uploads/', 0777, true);
}
if(!is_dir(WP_CONTENT_DIR . '/uploads/arcadepress/')) {
mkdir(WP_CONTENT_DIR . '/uploads/arcadepress/', 0777, true);
}
if(!is_dir(WP_CONTENT_DIR . '/uploads/arcadepress/games/')) {
mkdir(WP_CONTENT_DIR . '/uploads/arcadepress/games/', 0777, true);
}
if(!is_dir(WP_CONTENT_DIR . '/uploads/arcadepress/images/')) {
mkdir(WP_CONTENT_DIR . '/uploads/arcadepress/images/', 0777, true);
}
/**
* ===============================================================================================================
* Main ArcadePress Class
*/
if (!class_exists("ArcadePress")) {
class ArcadePress {
var $adminOptionsName = "ArcadePressAdminOptions";
function ArcadePress() { //constructor
}
function init() {
$this->getAdminOptions();
}
//Returns an array of admin options
function getAdminOptions() {
$apAdminOptions = array('mainpage' => '',
'turnon_arcadepress' => 'true',
'height' => '300',
'width' => '400',
'alt' => '
'.__('The Flash plugin is required to view this object.', 'arcadepress').'
',
'required_player_version' => '8.0.0',
'express_install_swf' => WP_PLUGIN_URL.'/arcadepress/swf/expressInstall.swf',
'allowfullscreen' => 'true',
'wmode' => 'window',
'showgamethumbnail' => 'true',
'showgamedescription' => 'true',
'creategameundercategory' => 'false'
);
$devOptions = get_option($this->adminOptionsName);
if (!empty($devOptions)) {
foreach ($devOptions as $key => $option)
$apAdminOptions[$key] = $option;
}
update_option($this->adminOptionsName, $apAdminOptions);
return $apAdminOptions;
}
//Prints out the admin page ================================================================================
function printAdminPage() {
global $wpdb;
$devOptions = $this->getAdminOptions();
if ( function_exists('current_user_can') && !current_user_can('manage_options') ) {
die(__('Cheatin’ uh?'));
}
if (isset($_POST['update_arcadePressSettings'])) {
if (isset($_POST['arcadePressmainpage'])) {
$devOptions['mainpage'] = $wpdb->escape($_POST['arcadePressmainpage']);
}
if (isset($_POST['turnArcadePressOn'])) {
$devOptions['turnon_arcadepress'] = $wpdb->escape($_POST['turnArcadePressOn']);
}
if (isset($_POST['allowfullscreen'])) {
$devOptions['allowfullscreen'] = $wpdb->escape($_POST['allowfullscreen']);
}
if (isset($_POST['arcadePressalt'])) {
$devOptions['alt'] = apply_filters('content_save_pre', $_POST['arcadePressalt']);
}
if (isset($_POST['arcadePresswidth'])) {
$devOptions['width'] = $wpdb->escape($_POST['arcadePresswidth']);
}
if (isset($_POST['arcadePressheight'])) {
$devOptions['height'] = $wpdb->escape($_POST['arcadePressheight']);
}
if (isset($_POST['arcadePresswmode'])) {
$devOptions['wmode'] = $wpdb->escape($_POST['arcadePresswmode']);
}
if (isset($_POST['arcadePressrequired_player_version'])) {
$devOptions['required_player_version'] = $wpdb->escape($_POST['arcadePressrequired_player_version']);
}
if (isset($_POST['arcadePressexpress_install_swf'])) {
$devOptions['express_install_swf'] = $wpdb->escape($_POST['arcadePressexpress_install_swf']);
}
if (isset($_POST['showgamethumbnail'])) {
$devOptions['showgamethumbnail'] = $wpdb->escape($_POST['showgamethumbnail']);
}
if (isset($_POST['showgamedescription'])) {
$devOptions['showgamedescription'] = $wpdb->escape($_POST['showgamedescription']);
}
if (isset($_POST['creategameundercategory'])) {
$devOptions['creategameundercategory'] = $wpdb->escape($_POST['creategameundercategory']);
}
update_option($this->adminOptionsName, $devOptions);
echo '
';
_e("Settings Updated.", "ArcadePress");
echo '
';
}
echo '
';
}
//END Prints out the admin page ================================================================================
//Prints out the Add Games admin page =======================================================================
function printAdminPageAddGames() {
global $wpdb, $user_level;
//Apparently this code doesn't work:
//get_currentuserinfo();
//if ($user_level < 8) {die('This page is not for you, but thanks for being sneaky and trying');};
if ( function_exists('current_user_can') && !current_user_can('manage_options') ) {
die(__('Cheatin’ uh?'));
}
$devOptions = $this->getAdminOptions();
$table_name = $wpdb->prefix . "arcadepress_games";
if(!isset($devOptions['mainpage']) || !is_numeric($devOptions['mainpage'])) {
echo '
ERROR: ArcadePress is configured incorrectly. Visit the ArcadePress options page and set the main page to the numeric POST ID of a dedicated PAGE that you have created for your arcade.
';
echo "There was a problem loading the game you wish to edit. The query was: {$grabrecord} ";
echo '
';
}
}
if (isset($_POST['addNewArcadePress_Game']) && $isanedit == false) {
if (isset($_POST['arcadePressgame_name']) && isset($_POST['arcadePressgame_description']) && isset($_POST['arcadePressgame_type']) && isset($_POST['arcadePressgame_file']) && $_POST['arcadePressgame_width'] && $_POST['arcadePressgame_height'] && is_numeric($_POST['arcadePressgame_width']) && is_numeric($_POST['arcadePressgame_height']) && isset($_POST['arcadePressgame_thumbnail']) && isset($_POST['arcadePressgame_tags']) ) {
$arcadePressgame_name = $wpdb->escape($_POST['arcadePressgame_name']);
$arcadePressgame_description = $wpdb->escape($_POST['arcadePressgame_description']);
$arcadePressgame_type = $wpdb->escape($_POST['arcadePressgame_type']);
$arcadePressgame_file = $wpdb->escape($_POST['arcadePressgame_file']);
$arcadePressgame_width = $wpdb->escape($_POST['arcadePressgame_width']);
$arcadePressgame_height = $wpdb->escape($_POST['arcadePressgame_height']);
$timestamp = date('Ymd');
$arcadePressgame_thumbnail = $wpdb->escape($_POST['arcadePressgame_thumbnail']);
$arcadePressgame_tags = $wpdb->escape($_POST['arcadePressgame_tags']);
$devOptions = $this->getAdminOptions();
// Create our PAGE in draft mode in order to get the POST ID
$my_post = array();
$my_post['post_title'] = stripslashes($arcadePressgame_name);
$my_post['post_type'] = 'page';
$my_post['post_content'] = '';
$my_post['post_status'] = 'draft';
$my_post['post_author'] = 1;
// Create the page as either directly under the main page or underneath a category page
if($devOptions['creategameundercategory']==false) {
$my_post['post_parent'] = $devOptions['mainpage'];
} else {
$theCategories = explode(',',$arcadePressgame_tags);
if(isset($theCategories[0])) {
$catSQL = "SELECT `ID` FROM `{$wpdb->prefix}posts` WHERE `post_title` LIKE '%{$theCategories[0]}%' AND `post_parent`={$devOptions['mainpage']} AND `post_status`='publish';";
$catResults = $wpdb->get_results( $catSQL , ARRAY_A );
if(!isset($catResults[0]['ID'])) {
$my_cat_post = array();
$my_cat_post['post_title'] = stripslashes($theCategories[0]);
$my_cat_post['post_type'] = 'page';
$my_cat_post['post_content'] = '[arcadepress category="'.stripslashes($theCategories[0]).'"]';
$my_cat_post['post_status'] = 'publish';
$my_cat_post['post_author'] = 1;
$my_cat_post['post_parent'] = $devOptions['mainpage'];
$theCatPostID = wp_insert_post( $my_cat_post );
} else {
$theCatPostID = $catResults[0]['ID'];
}
$my_post['post_parent'] = $theCatPostID;
} else {
$my_post['post_parent'] = $devOptions['mainpage'];
}
}
// Insert the PAGE into the WP database
$thePostID = wp_insert_post( $my_post );
if($thePostID==0) {
echo '
';
_e("ERROR 4: Wordpress didn't like your data and failed to create a page for it!", "ArcadePress");
echo $wpdb->print_error();
echo '
';
return false;
}
// Now insert the game into the ArcadePress database
$insert = "INSERT INTO {$table_name} (`primkey`, `name`, `description`, `type`, `file`, `tags`, `gameplays`, `dateadded`, `width`, `height`, `thumbnail`, `url`, `postid`)
VALUES (NULL, '{$arcadePressgame_name}', '{$arcadePressgame_description}', '{$arcadePressgame_type}', '{$arcadePressgame_file}', '{$arcadePressgame_tags}', '0', '{$timestamp}', '{$arcadePressgame_width}', '{$arcadePressgame_height}', '{$arcadePressgame_thumbnail}', '', '{$thePostID}');";
$results = $wpdb->query( $insert );
$lastID = $wpdb->insert_id;
// Now that we've inserted both the PAGE and the GAME, let's update and publish our post with the correct content
$my_post = array();
$my_post['ID'] = $thePostID;
$my_post['post_content'] = '[arcadepress display="game" primkey="'.$lastID.'"]';
$my_post['post_status'] = 'publish';
wp_update_post( $my_post );
if($results===false) {
echo '
';
_e("ERROR 2: There was a problem with your form! The database query was invalid. ", "ArcadePress");
echo $wpdb->print_error();
echo '
';
} else { // If we get this far, we are still successful
echo '
';
_e("Your game details have been saved.", "ArcadePress");
echo '
';
}
} else {
echo '
';
_e("There was a problem with your form! Did not save data.", "ArcadePress");
echo '
';
}
}
echo '
';
if($isanedit==true) { // An edit's REQUEST_URL will already have the key appended, while a new game won't
$codeForKeyToEdit = NULL;
} else {
$codeForKeyToEdit = '&keytoedit='.$keytoedit;
}
if(isset($lastID)) {
$codeForKeyToEdit = '&keytoedit='.$lastID;
}
echo '
';
}
// END Prints out the Add Games admin page =======================================================================
//Prints out the Edit Games admin page =======================================================================
function printAdminPageEditGames() {
global $wpdb, $user_level;
// Apparently this code doesn't work
//get_currentuserinfo();
//if ($user_level < 8) {die('This page is not for you, but thanks for being sneaky and trying');};
if ( function_exists('current_user_can') && !current_user_can('manage_options') ) {
die(__('Cheatin’ uh?'));
}
$table_name = $wpdb->prefix . "arcadepress_games";
if(isset($_GET['keytodelete']) && is_numeric($_GET['keytodelete'])) {
$sqlbeforedelete = "SELECT `postid` FROM {$table_name} WHERE `primkey`={$_GET['keytodelete']};";
$theDeleteResults = $wpdb->get_results( $sqlbeforedelete , ARRAY_A );
if(isset($theDeleteResults)) { // Delete the post
wp_delete_post($theDeleteResults[0]['postid']);
}
$wpdb->query("DELETE FROM `{$table_name}` WHERE `primkey`={$_GET['keytodelete']};");
echo '
';
_e("Game was removed from the database.", "ArcadePress");
echo '
";
}
// Create the function use in the action hook
function arcadepress_main_add_dashboard_widgets() {
wp_add_dashboard_widget('arcadepress_main_dashboard_widgets', 'ArcadePress Overview', array(&$this, 'arcadepress_main_dashboard_widget_function'));
}
function addHeaderCode() {
echo '';
}
function addContent($content = '') {
$content .= "
ArcadePress
";
return $content;
}
// Installation ==============================================================================================
function arcadepress_install() {
global $wpdb;
global $arcadepress_db_version;
$table_name = $wpdb->prefix . "arcadepress_games";
if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
$sql = "
CREATE TABLE {$table_name} (
`primkey` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
`name` VARCHAR(255) NOT NULL,
`description` TEXT NOT NULL,
`type` VARCHAR(32) NOT NULL,
`file` VARCHAR(512) NOT NULL,
`tags` VARCHAR(512) NOT NULL,
`gameplays` INT(11) NOT NULL,
`dateadded` INT(8) NOT NULL,
`width` INT(4) NOT NULL,
`height` INT(4) NOT NULL,
`thumbnail` VARCHAR(255) NOT NULL,
`url` VARCHAR(255) NOT NULL,
`postid` int(11) NOT NULL);
";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
add_option("arcadepress_db_version", $arcadepress_db_version);
}
}
// END Installation ==============================================================================================
// Shortcode =========================================
function arcadepress_mainshortcode($atts) {
global $wpdb;
$table_name = $wpdb->prefix . "arcadepress_games";
$devOptions = $this->getAdminOptions();
extract(shortcode_atts(array(
'display' => 'categories',
'primkey' => '0',
'quantity' => '10',
'usetext' => 'true',
'usepictures' => 'false',
'category' => ''
), $atts));
$output = '';
if($category!='') {
if(is_numeric($quantity)){
$sql = "SELECT * FROM `{$table_name}` WHERE `tags` LIKE '%{$category}%' ORDER BY `dateadded` DESC LIMIT 0, {$quantity};";
$results = $wpdb->get_results( $sql , ARRAY_A );
if(isset($results)) {
foreach ($results as $result) {
$permalink = get_permalink( $result['postid'] ); // Grab the permalink based on the post id associated with the game
if($usepictures=='true') {
$output .= '';
}
if($usetext=='true') {
$output .= '
';
}
}
}
} else {
$output .= 'ArcadePress did not like your category shortcode! The quantity field contained non-numeric data. Please fix your page or consult the ArcadePress documentation for help.';
}
}
switch ($display) {
case 'recentgames': // Recent game shortcode =========================================================
if(is_numeric($quantity)){
$sql = "SELECT * FROM `{$table_name}` ORDER BY `dateadded` DESC LIMIT 0, {$quantity};";
$results = $wpdb->get_results( $sql , ARRAY_A );
if(isset($results)) {
foreach ($results as $result) {
$permalink = get_permalink( $result['postid'] ); // Grab the permalink based on the post id associated with the game
if($usepictures=='true') {
$output .= '';
}
if($usetext=='true') {
$output .= '
';
}
}
}
} else {
$output .= 'ArcadePress did not like your recentgames shortcode! The quantity field contained non-numeric data. Please fix your page or consult the ArcadePress documentation for help.';
}
break;
case 'topgames': // Top game shortcode =========================================================
if(is_numeric($quantity)){
$sql = "SELECT * FROM `{$table_name}` ORDER BY `gameplays` DESC LIMIT 0, {$quantity};";
$results = $wpdb->get_results( $sql , ARRAY_A );
if(isset($results)) {
foreach ($results as $result) {
$permalink = get_permalink( $result['postid'] ); // Grab the permalink based on the post id associated with the game
if($usepictures=='true') {
$output .= '';
}
if($usetext=='true') {
$output .= '
';
}
}
}
} else {
$output .= 'ArcadePress did not like your topgames shortcode! The quantity field contained non-numeric data. Please fix your page or consult the ArcadePress documentation for help.';
}
break;
case 'categories': // Categories shortcode =========================================================
if($devOptions['creategameundercategory']==true) {
$sql = "SELECT `ID`, `post_title` FROM `{$wpdb->prefix}posts` WHERE `post_parent`={$devOptions['mainpage']} AND `post_status`='publish' ORDER BY `post_title` ASC";
$results = $wpdb->get_results( $sql , ARRAY_A );
if(isset($results)) {
$output .= '
';
foreach ($results as $result) {
$permalink = get_permalink( $result['ID'] ); // Grab the permalink based on the post id associated with the game
$output .= '
';
}
} else {
$output .= 'ArcadePress is configured to not use categories.';
}
break;
case 'game': // Individual game shortcode =========================================================
if(isset($primkey) && is_numeric($primkey)) {
$sql = "SELECT * FROM `{$table_name}` WHERE `primkey`={$primkey};";
$results = $wpdb->get_results( $sql , ARRAY_A );
if(isset($results)) {
$newGamePlayValue = $results[0]['gameplays'] + 1; // Increment the play counter
$updatedSQL = "UPDATE `{$table_name}` SET `gameplays` = '{$newGamePlayValue}' WHERE `primkey` ={$primkey} LIMIT 1 ;";
$wpdb->query($updatedSQL);
$output .= '
';
if($devOptions['showgamethumbnail']=='true') {
$output .= ' ';
}
if($devOptions['showgamedescription']=='true') {
$output .= $results[0]['description'];
}
} else {
$output .= 'This game has been removed, but the shortcode associated with it was not.';
}
} else {
$output .= 'ArcadePress did not like the primkey in your shortcode! The primkey field contained non-numeric data. Please fix your page or consult the ArcadePress documentation for help.';
}
break;
}
return $output;
}
// END SHORTCODE ================================================
function add_script_swfobject($posts){
if (empty($posts)) return $posts;
wp_enqueue_script('swfobject');
return $posts;
}
function my_admin_scripts(){
global $APjavascriptQueue;
wp_enqueue_script('swfupload');
if (session_id() == "") {@session_start();};
$APjavascriptQueue .= '
';
}
function placeAdminHeaderCode() {
global $APjavascriptQueue;
echo $APjavascriptQueue;
}
}
/**
* ===============================================================================================================
* End Main ArcadePress Class
*/
}
// The end of the IF statement
/**
* ===============================================================================================================
* ArcadePressTopGamesWidget SIDEBAR WIDGET
*/
if (class_exists("WP_Widget")) {
class ArcadePressTopGamesWidget extends WP_Widget {
/** constructor */
function ArcadePressTopGamesWidget() {
parent::WP_Widget(false, $name = 'ArcadePress Top Games');
}
/** @see WP_Widget::widget */
function widget($args, $instance) {
global $wpdb;
$table_name = $wpdb->prefix . "arcadepress_games";
extract( $args );
$title = apply_filters('widget_title', $instance['title']);
$numberOfGamesToDisplay = empty($instance['numberOfGamesToDisplay']) ? '10' : $instance['numberOfGamesToDisplay'];
$widgetShowGameImages = empty($instance['widgetShowGameImages']) ? 'false' : $instance['widgetShowGameImages'];
echo $before_widget;
if ( $title ) { echo $before_title . $title . $after_title; }
if(is_numeric($numberOfGamesToDisplay)){
$sql = "SELECT * FROM `{$table_name}` ORDER BY `gameplays` DESC LIMIT 0, {$numberOfGamesToDisplay};";
$results = $wpdb->get_results( $sql , ARRAY_A );
if(isset($results)) {
foreach ($results as $result) {
$permalink = get_permalink( $result['postid'] ); // Grab the permalink based on the post id associated with the game
if($widgetShowGameImages=='true') {
$output .= '';
}
$output .= '
';
}
}
} else {
$output .= 'ArcadePress did not like your widget! The number of games to display contained non-numeric data. Please fix your widget or consult the ArcadePress documentation for help.';
}
echo $output;
echo $after_widget;
}
/** @see WP_Widget::update */
function update($new_instance, $old_instance) {
$instance['title']= strip_tags(stripslashes($new_instance['title']));
$instance['numberOfGamesToDisplay'] = strip_tags(stripslashes($new_instance['numberOfGamesToDisplay']));
$instance['widgetShowGameImages'] = strip_tags(stripslashes($new_instance['widgetShowGameImages']));
return $instance;
}
/** @see WP_Widget::form */
function form($instance) {
$title = esc_attr($instance['title']);
$numberOfGamesToDisplay = htmlspecialchars($instance['numberOfGamesToDisplay']);
$widgetShowGameImages = htmlspecialchars($instance['widgetShowGameImages']);
echo '
'; _e('Title:'); echo '
';
echo '
' . __('Number of games to display:') . '
';
//echo '
' . __('Show images:') . '
';
echo '
' . __('Show images:') . ' Yes No
';
}
}
}
/**
* ===============================================================================================================
* END ArcadePressTopGamesWidget SIDEBAR WIDGET
*/
/**
* ===============================================================================================================
* ArcadePressCategoryGamesWidget SIDEBAR WIDGET
*/
if (class_exists("WP_Widget")) {
class ArcadePressCategoryGamesWidget extends WP_Widget {
/** constructor */
function ArcadePressCategoryGamesWidget() {
parent::WP_Widget(false, $name = 'ArcadePress Category List');
}
/** @see WP_Widget::widget */
function widget($args, $instance) {
global $wpdb, $arcadePress;
$devOptions = $arcadePress->getAdminOptions();
extract( $args );
$title = apply_filters('widget_title', $instance['title']);
echo $before_widget;
if ( $title ) { echo $before_title . $title . $after_title; }
if($devOptions['creategameundercategory']==true) {
$sql = "SELECT `ID`, `post_title` FROM `{$wpdb->prefix}posts` WHERE `post_parent`={$devOptions['mainpage']} AND `post_status`='publish' ORDER BY `post_title` ASC";
$results = $wpdb->get_results( $sql , ARRAY_A );
if(isset($results)) {
$output .= '
';
foreach ($results as $result) {
$permalink = get_permalink( $result['ID'] ); // Grab the permalink based on the post id associated with the game
$output .= '