<?php
/*              
 * Plugin Name: Genolve AI Business Graphics, AI Images
 * Version: 6.0.0
 * Plugin URI: https://www.genolve.com/
 * Description: Create professional business graphics, product images, social media, slide shows, flyers, brochures, infographics, podcasts with AI.
 * Author: Genolve
 * Author URI:  https://www.genolve.com/
 * License:     GPL2
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 */
?>
<?php
defined( 'ABSPATH' ) || exit;
define( 'GENOLVE_PLUGIN_DIR', plugin_dir_url( __FILE__ ));
// production: functions.php
// JQuery callbacks NEED To come before init
// if we define this in a class ( see external media upload function)
// CLAS MODE use   array( $this , 'genolve_savefile' )
// quick test http://localhost/wp-admin/admin-ajax.php?action=genolve_savefile&thelink=blah
add_action( 'wp_ajax_genolve_savefile' , 'genolve_savefile'  );
add_action( 'wp_ajax_genolve_add2list' , 'genolve_add2list'  );
add_action( 'wp_ajax_genolve_setOpt' , 'genolve_setOpt'  );
add_action( 'wp_ajax_genolve_setMet' , 'genolve_setMet'  );
add_action( 'wp_ajax_genolve_delit' , 'genolve_delit'  );
// THE BAD REQUEST  error was:
//  NEED BOTH OF THESE
add_action( 'wp_ajax_genolve_proxy' , 'genolve_proxy'  );
add_action( 'wp_ajax_nopriv_genolve_proxy' , 'genolve_proxy'  );
//Add necessary includes
require_once(dirname(__FILE__) . '/inc/functions.php');
require_once(dirname(__FILE__) . '/inc/settings.php');
// 20190512  remove auto update for official launch
// from here https://github.com/omarabid/Self-Hosted-WordPress-Plugin-repository
// https://code.tutsplus.com/tutorials/a-guide-to-the-wordpress-http-api-automatic-plugin-updates--wp-25181
//require_once(dirname(__FILE__) . '/wp_autoupdate.php' );
require_once(dirname(__FILE__) . '/bseparator/index.php');
require_once(dirname(__FILE__) . '/bimage/index.php');
require_once(dirname(__FILE__) . '/bwidgetai/index.php');

// Add the header code (css & javascript) to WordPress page
add_action('init', 'genolve_addHeaderCode'); // functions.php

// Runs functions.php->genolve_install when plugin is activated
register_activation_hook(__FILE__,'genolve_install'); 

// Runs functions.php->genolve_remove on plugin deactivation
register_deactivation_hook( __FILE__, 'genolve_deactivate' );
register_uninstall_hook(__FILE__, 'genolve_remove');

// Add the widget	
// 20190429 disabled
#add_action('widgets_init', 'genolve_registerWidget');

//Register the shortcode 
add_shortcode("dnh32pw75k", "genolve_shortcodeHandler");

// userbasic
add_action( 'wp_footer', 'genolve_userbasic',10 );

//Welcome message
add_action( 'admin_notices', 'genolve_admin_notice' );
function genolve_admin_notice(){
    /* Check transient, if available display notice */
    if( get_transient( 'genolve-transient-notice' ) ){
        ?>
        <div class="updated notice is-dismissible">
            <p>Thank you for using Genolve Toolkit! <strong>Find it in the side-bar menu</strong>.</p>
        </div>
        <?php
        /* Delete transient, only display this notice once. */
        delete_transient( 'genolve-transient-notice' );
    }
}


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
disable_wp_emojicons - emojis get injected in SVG and mess things up
 */
function genolve_disable_emojicons() {
  // all actions related to emojis
  remove_action( 'admin_print_styles', 'print_emoji_styles' );
  remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
  remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
  remove_action( 'wp_print_styles', 'print_emoji_styles' );
  remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
  remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
  remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
  // filter to remove TinyMCE emojis
  //20181219 throwing errors   add_filter( 'tiny_mce_plugins', 'disable_emojicons_tinymce' );
	}
add_action( 'init', 'genolve_disable_emojicons' );


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
genolve_add2cutomize - add Genolve options to admin menu for falling snow, etc. 
  
   ref http://blog.rutwick.com/add-items-anywhere-to-the-wp-3-3-admin-bar
	 https://codex.wordpress.org/Class_Reference/WP_Admin_Bar/add_node
	 
 */
function genolve_add2cutomize($admin_bar){
	/* This print_r will show you the current contents of the admin menu bar, use it if you want to examine the $admin_bar array
	* echo "<pre>";
	* print_r($admin_bar);
	* echo "</pre>";
	*/
	if(!is_admin() ){
		/* INITIAL BUTTON */
		$args = array(
        'id' => 'gnlv_menu',
        'title' => '<div id="geno-logo-icon" class="gnlv-icon-logo gnlv-logo-bg"></div><span class="gnlv-text">Genolve</span>', 
        'href' => '#', 
        'meta' => array(
            'class' => 'gnlv_wpadmin_top', 
            'title' => 'Genolve Custom Backgrounds'
            )
    		);
    $admin_bar->add_node($args);
		/* SUB MENU */
		$args = array(
					'id'    => 'gnlv_help',
					'parent'=> 'gnlv_menu',
					'title' => 'Help using tool',
					'href'  => admin_url( 'options-general.php' )."?page=genolve-toolkit-settings&tab=help&section=backgrounds",
					'meta'  => array(
									'title' => __('Launch Genolve Customizer'),
									'class' => 'gnlv_wpadmin'  // < do not change jq uses this
									),
					);
		$admin_bar->add_menu( $args);
		$args = array(
					'id'    => 'gnlv_backgrounds',
					'parent'=> 'gnlv_menu',
					'title' => 'Set Page Background',
					'href'  => admin_url( 'admin-ajax.php' ),
					'meta'  => array(
									'title' => __('Launch Genolve Customizer'),
									'class' => 'gnlv_wpadmin_links'  // < do not change jq uses this
									),
					);
		if( get_option('genolve_enabled')=="TRUE" ){
			//page background
			$admin_bar->add_menu( $args);
			// any element
			$args['title']='Background for any Element';
			$args['id']='gnlv_element';
			$admin_bar->add_menu( $args);
			// falling snow, leaves, more
			$args['title']='Falling snow, leaves, more';
			$args['id']='gnlv_falling';
			$admin_bar->add_menu( $args);
			/* button reveal
			$args['title']='Cover button, show on scroll';
			$args['id']='gnlv_coverNshow';
			$admin_bar->add_menu( $args);
			*/
			}
		else{
			$args['title']='Genolve is disabled in dashboard';
			$args['id']='disabled';
			$admin_bar->add_menu( $args);
			}
		}
	} // end genolve_add2cutomize
//these features retired ater version 4.0.7
//add_action('admin_bar_menu', 'genolve_add2cutomize',  100);


?>
