get_col( "SELECT blog_id FROM $wpdb->blogs" );
// Loop all blogs and run update routine
foreach ( $blog_ids as $blog_id ) {
switch_to_blog( $blog_id );
alm_update_template_files();
restore_current_blog();
}
} else {
alm_update_template_files();
}
update_option( "alm_version", ALM_VERSION ); // Update the WP Option tbl with the new version num
}
/**
* alm_update_template_files
* Update routine for template files
*
* @since 2.7.2
*/
function alm_update_template_files(){
global $wpdb;
$table_name = $wpdb->prefix . "alm";
$blog_id = $wpdb->blogid;
// Get all templates ($rows) where name is 'default'
$rows = $wpdb->get_results("SELECT * FROM $table_name WHERE name = 'default'");
if($rows){
foreach( $rows as $row ) { // Loop $rows
$data = $wpdb->get_var("SELECT repeaterDefault FROM $table_name WHERE name = 'default'");
if($blog_id > 1){
$dir = ALM_PATH. 'core/repeater/'. $blog_id;
if( !is_dir($dir) ){
mkdir($dir);
}
$f = ALM_PATH. 'core/repeater/'. $blog_id .'/default.php';
}else{
$f = ALM_PATH. 'core/repeater/default.php';
}
try {
$o = fopen($f, 'w+'); //Open file
if ( !$o ) {
throw new Exception(__('[Ajax Load More] Error opening default repeater template - Please check your file path and ensure your server is configured to allow Ajax Load More to read and write files within the /ajax-load-more/core/repeater directory', ALM_NAME));
}
$w = fwrite($o, $data); //Save the file
if ( !$w ) {
throw new Exception(__('[Ajax Load More] Error updating default repeater template - Please check your file path and ensure your server is configured to allow Ajax Load More to read and write files within the /ajax-load-more/core/repeater directory.', ALM_NAME));
}
fclose($o); //now close it
} catch ( Exception $e ) {
// Display error message in console.
if(!isset($options['_alm_error_notices']) || $options['_alm_error_notices'] == '1'){
echo '';
}
}
}
}
}
/**
* alm_admin_menu
* Create Admin Menu
*
* @since 2.0.0
*/
add_action( 'admin_menu', 'alm_admin_menu' );
function alm_admin_menu() {
$icon = 'dashicons-plus-alt';
$icon = ALM_ADMIN_URL . "/img/alm-logo-16x16.png";
$alm_page = add_menu_page(
'Ajax Load More',
'Ajax Load More',
'edit_theme_options',
'ajax-load-more',
'alm_settings_page',
$icon
);
$alm_settings_page = add_submenu_page(
'ajax-load-more',
'Settings',
'Settings',
'edit_theme_options',
'ajax-load-more',
'alm_settings_page'
);
$alm_template_page = add_submenu_page(
'ajax-load-more',
'Repeater Templates',
'Repeater Templates',
'edit_theme_options',
'ajax-load-more-repeaters',
'alm_repeater_page'
);
$alm_shortcode_page = add_submenu_page(
'ajax-load-more',
'Shortcode Builder',
'Shortcode Builder',
'edit_theme_options',
'ajax-load-more-shortcode-builder',
'alm_shortcode_builder_page'
);
$alm_examples_page = add_submenu_page(
'ajax-load-more',
'Examples',
'Examples',
'edit_theme_options',
'ajax-load-more-examples',
'alm_example_page'
);
$alm_addons_page = add_submenu_page(
'ajax-load-more',
'Add-ons',
'Add-ons',
'edit_theme_options',
'ajax-load-more-add-ons',
'alm_add_ons_page'
);
$alm_licenses_page = add_submenu_page(
'ajax-load-more',
'Licenses',
'Licenses',
'edit_theme_options',
'ajax-load-more-licenses',
'alm_licenses_page'
);
if(has_action('alm_cache_installed')){
$alm_cache_page = add_submenu_page(
'ajax-load-more',
'Cache',
'Cache',
'edit_theme_options',
'ajax-load-more-cache',
'alm_cache_page'
);
add_action( 'load-' . $alm_cache_page, 'alm_load_admin_js' );
add_action( 'load-' . $alm_cache_page, 'alm_load_cache_admin_js' );
}
//Add our admin scripts
add_action( 'load-' . $alm_settings_page, 'alm_load_admin_js' );
add_action( 'load-' . $alm_template_page, 'alm_load_admin_js' );
add_action( 'load-' . $alm_shortcode_page, 'alm_load_admin_js' );
add_action( 'load-' . $alm_examples_page, 'alm_load_admin_js' );
add_action( 'load-' . $alm_addons_page, 'alm_load_admin_js' );
add_action( 'load-' . $alm_licenses_page, 'alm_load_admin_js' );
}
/**
* alm_load_admin_js
* Load Admin JS
*
* @since 2.0.15
*/
function alm_load_admin_js(){
add_action( 'admin_enqueue_scripts', 'alm_enqueue_admin_scripts' );
}
function alm_load_cache_admin_js(){
add_action( 'admin_enqueue_scripts', 'alm_enqueue_cache_admin_scripts' );
}
/**
* alm_enqueue_admin_scripts
* Enqueue Admin JS
*
* @since 2.0.15
*/
function alm_enqueue_admin_scripts(){
//Load Admin CSS
wp_enqueue_style( 'alm-admin-css', ALM_ADMIN_URL. 'css/admin.css');
wp_enqueue_style( 'alm-select2-css', ALM_ADMIN_URL. 'css/select2.css');
wp_enqueue_style( 'alm-core-css', ALM_URL. '/core/css/ajax-load-more.css');
wp_enqueue_style( 'alm-font-awesome', '//netdna.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css');
//Load CodeMirror Syntax Highlighting if on Repater Template page
$screen = get_current_screen();
if ( in_array( $screen->id, array( 'ajax-load-more_page_ajax-load-more-repeaters') ) ){
//CodeMirror CSS
wp_enqueue_style( 'alm-codemirror-css', ALM_ADMIN_URL. 'codemirror/lib/codemirror.css' );
//CodeMirror JS
wp_enqueue_script( 'alm-codemirror', ALM_ADMIN_URL. 'codemirror/lib/codemirror.js');
wp_enqueue_script( 'alm-codemirror-matchbrackets', ALM_ADMIN_URL. 'codemirror/addon/edit/matchbrackets.js' );
wp_enqueue_script( 'alm-codemirror-htmlmixed', ALM_ADMIN_URL. 'codemirror/mode/htmlmixed/htmlmixed.js' );
wp_enqueue_script( 'alm-codemirror-xml', ALM_ADMIN_URL. 'codemirror/mode/xml/xml.js' );
wp_enqueue_script( 'alm-codemirror-javascript', ALM_ADMIN_URL. 'codemirror/mode/javascript/javascript.js' );
wp_enqueue_script( 'alm-codemirror-mode-css', ALM_ADMIN_URL. 'codemirror/mode/css/css.js' );
wp_enqueue_script( 'alm-codemirror-clike', ALM_ADMIN_URL. 'codemirror/mode/clike/clike.js' );
wp_enqueue_script( 'alm-codemirror-php', ALM_ADMIN_URL. 'codemirror/mode/php/php.js' );
}
//Load JS
wp_enqueue_script( 'jquery-form' );
wp_enqueue_script( 'alm-select2', ALM_ADMIN_URL. 'js/libs/select2.min.js', array( 'jquery' ));
wp_enqueue_script( 'alm-drops', ALM_ADMIN_URL. 'js/libs/jquery.drops.js', array( 'jquery' ));
wp_enqueue_script( 'alm-admin', ALM_ADMIN_URL. 'js/admin.js', array( 'jquery' ));
wp_enqueue_script( 'alm-shortcode-builder', ALM_ADMIN_URL. 'shortcode-builder/js/shortcode-builder.js', array( 'jquery' ));
}
function alm_enqueue_cache_admin_scripts(){
wp_enqueue_script( 'alm-cache-admin', ALM_CACHE_URL. '/js/alm-cache.js', array( 'jquery' ));
}
/*
* alm_settings_page
* Settings page
*
* @since 2.0.0
*/
function alm_settings_page(){
include_once( ALM_PATH . 'admin/views/settings.php');
}
/*
* alm_repeater_page
* Custom Repeaters
*
* @since 2.0.0
*/
function alm_repeater_page(){
include_once( ALM_PATH . 'admin/views/repeater-templates.php');
}
/*
* alm_shortcode_builder_page
* Shortcode Builder
*
* @since 2.0.0
*/
function alm_shortcode_builder_page(){
include_once( ALM_PATH . 'admin/views/shortcode-builder.php');
}
/*
* alm_example_page
* Examples Page
*
* @since 2.0.0
*/
function alm_example_page(){
include_once( ALM_PATH . 'admin/views/examples.php');
}
/*
* alm_add_ons_page
* Ajax Load More Add-ons
*
* @since 2.0.0
*/
function alm_add_ons_page(){
include_once( ALM_PATH . 'admin/views/add-ons.php');
}
/*
* alm_licenses_page
* Ajax Load More Licenses
*
* @since 2.7.0
*/
function alm_licenses_page(){
include_once( ALM_PATH . 'admin/views/licenses.php');
}
/*
* alm_cache_page
* Cache Add-on page
*
* @since 2.6.0
*/
function alm_cache_page(){
include_once( ALM_CACHE_PATH . 'admin/views/cache.php');
}
/*
* alm_delete_cache
* Delete induvidual cached items
*
* @return null
* @since 2.6.0
*/
function alm_delete_cache(){
$nonce = $_POST["nonce"];
$cache = $_POST["cache"];
// Check our nonce, if they don't match then bounce!
if (! wp_verify_nonce( $nonce, 'alm_repeater_nonce' ))
die('Get Bounced!');
$dir = ALM_CACHE_PATH .'_cache/'.$cache;
if (is_dir($dir)) {
foreach (glob($dir."/*.*") as $filename) {
if (is_file($filename)) {
unlink($filename);
}
}
rmdir($dir);
}
die();
}
/*
* alm_save_repeater
* Repeater Save function
*
* @return response
* @since 2.0.0
*/
function alm_save_repeater(){
global $wpdb;
$table_name = $wpdb->prefix . "alm";
$blog_id = $wpdb->blogid;
$options = get_option( 'alm_settings' ); //Get plugin options
$nonce = $_POST["nonce"];
// Check our nonce, if they don't match then bounce!
if (! wp_verify_nonce( $nonce, 'alm_repeater_nonce' ))
die('Error - unable to verify nonce, please try again.');
// Get _POST Vars
$c = Trim(stripslashes($_POST["value"])); // Repeater Value
$n = Trim(stripslashes($_POST["repeater"])); // Repeater name
$t = Trim(stripslashes($_POST["type"])); // Repeater name
$a = Trim(stripslashes($_POST["alias"])); // Repeater alias
// Write to repeater templates
// (Default)
if($t === 'default'){
if($blog_id > 1){
$dir = ALM_PATH. 'core/repeater/'. $blog_id;
if( !is_dir($dir) ){
mkdir($dir);
}
$f = ALM_PATH. 'core/repeater/'. $blog_id .'/default.php';
}else{
$f = ALM_PATH. 'core/repeater/default.php';
}
}
// (Unlimited)
elseif($t === 'unlimited'){
if($blog_id > 1){
$dir = ALM_UNLIMITED_PATH. 'repeaters/'. $blog_id;
if( !is_dir($dir) ){
mkdir($dir);
}
$f = ALM_UNLIMITED_PATH. 'repeaters/'. $blog_id .'/'.$n .'.php';
}else{
$f = ALM_UNLIMITED_PATH. 'repeaters/'.$n .'.php';
}
}
// (Unlimited v1)
else{
$f = ALM_REPEATER_PATH. 'repeaters/'.$n .'.php';
}
try {
$o = fopen($f, 'w+'); //Open file
if ( !$o ) {
throw new Exception(__('[Ajax Load More] Unable to open repeater template - '.$f.' - Please check your file path and ensure your server is configured to allow Ajax Load More to read and write files.', ALM_NAME));
}
$w = fwrite($o, $c); //Save the file
if ( !$w ) {
throw new Exception(__('[Ajax Load More] Error saving repeater template - '.$f.' - Please check your file path and ensure your server is configured to allow Ajax Load More to read and write files.', ALM_NAME));
}
fclose($o); //now close it
} catch ( Exception $e ) {
// Display error message in console.
if(!isset($options['_alm_error_notices']) || $options['_alm_error_notices'] == '1'){
echo '';
}
}
//Save to database
if($t === 'default') {
$data_update = array('repeaterDefault' => "$c", 'pluginVersion' => ALM_VERSION);
$data_where = array('name' => "default");
}
elseif($t === 'unlimited'){ // Unlimited Repeaters
$table_name = $wpdb->prefix . "alm_unlimited";
$data_update = array('repeaterDefault' => "$c", 'alias' => "$a", 'pluginVersion' => ALM_UNLIMITED_VERSION);
$data_where = array('name' => $n);
}
else{ // Custom Repeaters
$data_update = array('repeaterDefault' => "$c", 'alias' => "$a", 'pluginVersion' => ALM_REPEATER_VERSION);
$data_where = array('name' => $n);
}
$wpdb->update($table_name , $data_update, $data_where);
//Our results
if($w){
echo 'Template Saved Successfully';
} else {
echo ''. __('Error Writing File', ALM_NAME) .' No terms exist within this taxonomy ' . __('Customize the user experience of Ajax Load More by updating the fields below.', ALM_NAME) . ' ' . __('The following settings affect the WordPress admin area only.', ALM_NAME) . '
Something went wrong and the data could not be saved.';
}
die();
}
/*
* alm_update_repeater
* Update repeater template from database
*
* - User story: User deletes plugin, the installs again and the version has not change - their default repeater will be in the default state and unable to be updated.
*
* @return DB value
* @since 2.5.0
*/
function alm_update_repeater(){
$nonce = $_POST["nonce"];
// Check our nonce, if they don't match then bounce!
if (! wp_verify_nonce( $nonce, 'alm_repeater_nonce' ))
die('Error - unable to verify nonce, please try again.');
// Get _POST Vars
$n = Trim(stripslashes($_POST["repeater"])); // Repeater name
$t = Trim(stripslashes($_POST["type"])); // Repeater type (default | unlimited)
// Get value from database
global $wpdb;
$table_name = $wpdb->prefix . "alm";
if($t === 'default') $n = 'default';
if($t === 'unlimited') $table_name = $wpdb->prefix . "alm_unlimited";
$the_repeater = $wpdb->get_var("SELECT repeaterDefault FROM " . $table_name . " WHERE name = '$n'");
echo $the_repeater; // Return repeater value
die();
}
/*
* alm_get_tax_terms
* Get taxonomy terms for shortcode builder
*
* @return Taxonomy Terms
* @since 2.1.0
*/
function alm_get_tax_terms(){
$nonce = $_GET["nonce"];
// Check our nonce, if they don't match then bounce!
if (! wp_verify_nonce( $nonce, 'alm_repeater_nonce' ))
die('Get Bounced!');
$taxonomy = (isset($_GET['taxonomy'])) ? $_GET['taxonomy'] : '';
$tax_args = array(
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => false
);
$terms = get_terms($taxonomy, $tax_args);
$returnVal = '';
if ( !empty( $terms ) && !is_wp_error( $terms ) ){
$returnVal .= '';
foreach ( $terms as $term ) {
//print_r($term);
$returnVal .='';
}
$returnVal .= '
';
echo $returnVal;
die();
}else{
echo "
';
$html .= '';
$html .= '';
$html .= '';
echo $html;
}
/*
* alm_class_callback
* Add classes to the Ajax Load More wrapper
*
* @since 2.0.0
*/
function alm_class_callback(){
$options = get_option( 'alm_settings' );
$html = '
';
$html .= ' ';
echo $html;
}
/*
* alm_btn_color_callback
* Get button color
*
* @since 2.0.0
*/
function alm_btn_color_callback() {
$options = get_option( 'alm_settings' );
$color = $options['_alm_btn_color'];
if(!isset($color))
$options['_alm_btn_color'] = '0';
$selected0 = '';
if($color == 'default') $selected0 = 'selected="selected"';
$selected1 = '';
if($color == 'blue') $selected1 = 'selected="selected"';
$selected2 = '';
if($color == 'green') $selected2 = 'selected="selected"';
$selected3 = '';
if($color == 'red') $selected3 = 'selected="selected"';
$selected4 = '';
if($color == 'purple') $selected4 = 'selected="selected"';
$selected5 = '';
if($color == 'grey') $selected5 = 'selected="selected"';
$selected6 = '';
if($color == 'white') $selected6 = 'selected="selected"';
$html = '
';
$html .= '';
$html .= '