.
---------------------------------------------------------------------
*/
//useful variables
$uploads = wp_upload_dir();
$GLOBALS['AAPLimages'] = $uploads['basedir'] . '/AAPL';
$GLOBALS['AAPLimagesurl'] = $uploads['baseurl'] . '/AAPL';
if(!function_exists('get_option'))
require_once('../../../wp-config.php');
//install - uninstall
register_activation_hook(__FILE__, 'install_AAPL');
//register_deactivation_hook(__FILE__, 'uninstall_AAPL'); not required yet
//admin panel
if (is_admin()) {
add_action('admin_init', 'admin_init_AAPL');
add_action('admin_menu', 'admin_menu_AAPL');
function admin_init_AAPL() {
register_setting('AAPL', 'AAPL_upload_error');
register_setting('AAPL', 'AAPL_version');
register_setting('AAPL', 'AAPL_content_id');
register_setting('AAPL', 'AAPL_search_class');
register_setting('AAPL', 'AAPL_loading_img');
register_setting('AAPL', 'AAPL_reload_code');
register_setting('AAPL', 'AAPL_data_code'); /* eag */
register_setting('AAPL', 'AAPL_click_code');
register_setting('AAPL', 'AAPL_ignore_list');
register_setting('AAPL', 'AAPL_loading_code');
register_setting('AAPL', 'AAPL_loading_error_code');
register_setting('AAPL', 'AAPL_sponsor');
register_setting('AAPL', 'AAPL_commercial');
register_setting('AAPL', 'AAPL_js_debug');
register_setting('AAPL', 'AAPL_jquery_check');
register_setting('AAPL', 'AAPL_track_analytics');
register_setting('AAPL', 'AAPL_scroll_top');
//Update all tick box's that are unchecked
if (get_option('AAPL_sponsor') == '') {
update_option('AAPL_sponsor', 'false');
}
if (get_option('AAPL_commercial') == '') {
update_option('AAPL_commercial', 'false');
}
if (get_option('AAPL_js_debug') == '') {
update_option('AAPL_js_debug', 'false');
}
if (get_option('AAPL_jquery_check') == '') {
update_option('AAPL_jquery_check', 'false');
}
if (get_option('AAPL_track_analytics') == '') {
update_option('AAPL_track_analytics', 'false');
}
if (get_option('AAPL_scroll_top') == '') {
update_option('AAPL_scroll_top', 'false');
}
update_option('AAPL_upload_error', '');
update_option('AAPL_loading_img', AAPL_options_validate());
//will this fix various problems? hope so.
install_AAPL();
//upgrade checks :o
$AAPLupdate = false;
if (AAPL_get_version() != get_option('AAPL_version')) {
//version update - inform of update
update_option('AAPL_version', AAPL_get_version());
update_option('AAPL_upload_error', 'Stuff was updated for ' . AAPL_get_version() . ' mate!
');
$AAPLupdate = true;
} else if (isset($_GET['settings-updated'])) {
$AAPLupdate = true;
}
//move important file settings to files
if ($AAPLupdate === true) {
//perform updates to files
$data = get_option('AAPL_reload_code');
$data2 = get_option('AAPL_click_code');
$data3 = get_option('AAPL_data_code'); /* eag */
//this is probably better
$data = 'function AAPL_reload_code() {' . "\n" . '//This file is generated from the admin panel - dont edit here! ' . "\n" . $data . "\n" . '}'. "\n". "\n";
$data .= 'function AAPL_click_code(thiss) {' . "\n" . '//This file is generated from the admin panel - dont edit here! ' . "\n" . $data2 . "\n" . '}'. "\n". "\n";
$data .= 'function AAPL_data_code(dataa) {' . "\n" . '//This file is generated from the admin panel - dont edit here! ' . "\n" . $data3 . "\n" . '}'; /* eag */
$file = fopen(plugin_dir_path(__FILE__) . '/reload_code.js', 'w');
fwrite($file, $data);
fclose($file);
}
}
function admin_menu_AAPL() {
add_options_page('Advanced Ajax Page Loader', 'Advanced Ajax Page Loader', 'manage_options', 'AdvancedAjaxPageLoader', 'options_page_AAPL');
}
function options_page_AAPL() {
include(plugin_dir_path(__FILE__) . '/options.php');
}
function AAPL_options_validate() {
//print_r($_FILES);
if (isset($_FILES['AAPLuploadloader']['name'])) {
if ($_FILES['AAPLuploadloader']['error'] > 0) {
update_option('AAPL_upload_error', 'Error: ' . $_FILES['AAPLuploadloader']['error'] . '
');
} else {
if (($_FILES['AAPLuploadloader']['type'] == 'image/gif') || ($_FILES['AAPLuploadloader']['type'] == 'image/jpeg') || ($_FILES['AAPLuploadloader']['type'] == 'image/png') || ($_FILES['AAPLuploadloader']['type'] == 'image/apng')) {
if (file_exists($GLOBALS['AAPLimages'] . '/loaders/' . $_FILES['AAPLuploadloader']['name'])) {
update_option('AAPL_upload_error', 'Exists: ' . $_FILES['AAPLuploadloader']['name'] . '
');
} else {
move_uploaded_file($_FILES['AAPLuploadloader']['tmp_name'],
$GLOBALS['AAPLimages'] . '/loaders/' . $_FILES['AAPLuploadloader']['name']);
update_option('AAPL_loading_img', $_FILES['AAPLuploadloader']['name']);
return $_FILES['AAPLuploadloader']['name'];
//echo "Stored in: " . $GLOBALS['AAPLimages'] . '/loaders/' . $_FILES['AAPLuploadloader']['name'];
}
} else {
update_option('AAPL_upload_error', 'Bad type: ' . $_FILES['AAPLuploadloader']['type'] . '
');
}
}
}
return get_option('AAPL_loading_img');
}
}
// Set Hook for outputting JavaScript
add_action('wp_head', 'insert_head_AAPL');
add_action('wp_footer', 'insert_foot_AAPL');
add_action('wp_enqueue_scripts', 'enqueue_AAPL');
function enqueue_AAPL() {
//Make sure we use latest jquery?
wp_deregister_script('jquery');
wp_register_script('jquery', plugins_url( 'jquery.js' , __FILE__ ));
wp_enqueue_script('jquery');
}
function insert_foot_AAPL() {
if (strcmp(get_option('AAPL_sponsor'), 'true') == 0) {
?>
Loading... Please Wait...
' . "\n\t" . '' . "\n\t\t" .
'' . "\n\t" .
'
Error!
' . "\n\t" . '' . "\n\t\t" . 'There was a problem and the page didnt load.' . "\n\t" . '
' . "\n" . '