"; } } if($debug){ echo "plug fold ".$fo."--
"; } if( substr($fo,strlen($fo)-1,1)=='/'){ $fo=substr($fo,0,strlen($fo)-1); } define( 'WP_PLUGIN_FOLDER', $fo); define( 'APPLICATION_MAKER_LIB_PATH', APPLICATION_MAKER_PATH . 'lib/' ); define( 'APPLICATION_MAKER_VIEWS_PATH', APPLICATION_MAKER_PATH . 'views/' ); define( 'APPLICATION_MAKER_JS_PATH', APPLICATION_MAKER_PATH . 'js/' ); define( 'APPLICATION_MAKER_CSS_PATH', APPLICATION_MAKER_PATH . 'css/' ); $apm_settings=array( 'plugin' => array( 'name'=>WP_PLUGIN_FOLDER ), );// $apm_settings=array_merge($apm_settings, array( 'paths' => array( 'js'=>site_url().'/wp-content/plugins/'.$apm_settings['plugin']['name'].'/js/', 'css'=>site_url().'/wp-content/plugins/'.$apm_settings['plugin']['name'].'/css/', 'img'=>site_url().'/wp-content/plugins/'.$apm_settings['plugin']['name'].'/img/', 'includes'=>site_url().'/wp-includes' ), 'configs' => array( 'default_currency'=>$main_config['default_currency'], 'widget_latest_default_max'=>$main_config['widget_latest_default_max'], 'from_email'=>$main_config['from_email'], ) ) ); // class Application_Maker { protected $textdomain = 'application-maker'; protected $args; public $post_types; protected $metaboxes; protected $url; // CONSTRUCTOR /** * Kicks things off * @param */ public function __construct() { global $post_types, $oThis,$show_help,$apm_settings; require_once APPLICATION_MAKER_PATH . 'application-maker-custom_fields.php'; require_once APPLICATION_MAKER_PATH . 'application-maker-default_fields.php'; require_once APPLICATION_MAKER_PATH . 'lib/SimpleImage.php'; require_once APPLICATION_MAKER_PATH . 'application-maker-default_application.php'; require_once APPLICATION_MAKER_PATH . 'application-maker-custom_applications.php'; $this->site_email = ( is_email($this->settings['email']) && $this->settings['email'] != 'email@example.com' ) ? $this->settings['email'] : get_bloginfo('admin_email'); $this->site_name = ( $this->settings['name'] != 'YOUR NAME' && !empty($this->settings['name']) ) ? stripslashes($this->settings['name']) : get_bloginfo('name'); $this->simple_image = new SimpleImage(); /* * by default a field is field_type textfield is not precised * default label_position=left * default label_width=150 * */ $this->default_fields=array_merge($default_fields,$my_custom_fields); $this->applications=array_merge($default_application,$custom_applications); $this->post_types=array(); $this->all_categories=array(); $this->all_tags=array(); $this->all_modules=array(); foreach( $this->applications as $key => $application ){ $this->post_types=array_merge($this->post_types,$application['modules']); if(isset($application['categories']) ){ $this->all_categories=array_merge($this->all_categories,$application ['categories']); } if(isset($application['tags']) ){ $this->all_tags=array_merge($this->all_tags,$application ['tags']); } if(isset($application['modules']) ){ $this->all_modules=array_merge($this->all_modules,$application ['modules']); } if(isset($application['option_sections']) ){ ///SET DEFAULT OPTIONS foreach( $application['option_sections'] as $subkey => $option_sections ){ foreach( $option_sections['fields'] as $subsubkey => $option_section ){ if(count($option_section)>2){ if(esc_attr(get_option($subsubkey))!==false and esc_attr(get_option($subsubkey))!==''){ $option=esc_attr(get_option($subsubkey)); //echo '
---'.$subsubkey.'-'.$option; } else { $option=$option_section[2]; //echo '
---'.$subsubkey.'-'.$option; update_option($subsubkey,$option); } } } } } } if(esc_attr(get_option('default_currency'))!==false){ $apm_settings['configs']['default_currency']=esc_attr(get_option('default_currency')); } if(esc_attr(get_option('widget_latest_default_max'))!==false){ $apm_settings['configs']['widget_latest_default_max']=esc_attr(get_option('widget_latest_default_max')); } if(esc_attr(get_option('from_email'))!==false){ $apm_settings['configs']['from_email']=esc_attr(get_option('from_email')); } $post_types=$this->post_types; $oThis=$this; $this->textdomain = apply_filters( 'application-maker_textdomain', $this->textdomain ); $this->url = site_url().'/wp-content/plugins/application-maker'; add_action( 'admin_init', array($this, 'init'), 0 ); add_action('admin_menu', array($this, 'my_appmaker_menu'),0); add_action( 'init', array($this, 'create_main_post_types') ); add_action('admin_menu', array($this, 'my_categ_menu'),0); add_action( 'add_meta_boxes',array($this, 'myplugin_add_custom_box' )); add_action( 'wp_dashboard_setup',array($this, 'myplugin_add_dashboard_widgets' )); add_action('post_edit_form_tag', array($this,'post_edit_form_tag')); add_action( 'save_post', array($this,'myplugin_save_postdata' )); //add_action( 'tiny_mce_before_init', array($this,'my_add_editor_style' )); add_action('in_admin_header',array($this,'my_admin_head')); /*MANAGE the COLUMN in the POST DATA GRIDS **/ foreach($this->post_types as $key=> $post_type_obj){ if(isset($post_type_obj['module_columns']) ){ add_filter('manage_edit-'.$key.'_columns', array($this, 'create_my_custom_columns')); add_filter('manage_edit-'.$key.'_sortable_columns', array($this, 'create_my_custom_columns_register_sortable')); } } add_action('manage_posts_custom_column', array($this, 'my_show_columns')); if(isset($_GET['post_type']) and $_GET['post_type']!=='page'){ add_action('request', array($this, 'my_column_orderby')); } if($show_help){ add_action('admin_menu', 'application_maker_do_help_menu'); function application_maker_do_help_menu() { add_options_page(_('Applications Maker Plugin Help'), _('Applications Maker Plugin Help'), 'manage_options', 'application-maker-help', 'application_maker_help'); } function application_maker_help() { require_once APPLICATION_MAKER_VIEWS_PATH . 'application-maker-help.php'; } } // add_filter( 'get_meta_sql', array($this, 'test1')); // add_filter( 'posts_orderby', array($this, 'testposts_orderby')); require_once APPLICATION_MAKER_LIB_PATH . 'apm-shortcodes.class.php'; $this->AM_Shortcodes=new Application_Maker_Shortcodes(); $this->AM_Shortcodes->Parent=$this; $this->AM_Shortcodes->init(); require_once APPLICATION_MAKER_LIB_PATH . 'apm-portal.class.php'; $this->AM_Portal=new Application_Maker_Portal(); $this->AM_Portal->Parent=$this; require_once APPLICATION_MAKER_LIB_PATH . 'apm-datagrid.class.php'; $this->AM_Datagrid=new Application_Maker_Datagrid(); $this->AM_Datagrid->Parent=$this; } public function init() { global $apm_settings ,$wpdb, $current_user; // echo "---".$current_user->ID; $user_rich_text=get_user_meta($current_user->ID,'rich_editing',true); require_once APPLICATION_MAKER_LIB_PATH . 'application-maker-core.class.php'; $this->AM_Core=new Application_Maker_Core(); $this->AM_Core->default_fields=$this->default_fields; $this->AM_Core->post_types=$this->post_types; $this->AM_Core->applications=$this->applications; //add_editor_style('editor-buttons.css' ); wp_tiny_mce(false, // true makes the editor "teeny" array( "editor_selector" => "apm-editor", "height" => 150 ) ); wp_register_script( 'application_tab_script', $apm_settings['paths']['js']. 'admin/jquery-ilc-tabs.js', array('jquery-ui-sortable') ); wp_enqueue_script( 'application_tab_script' ); wp_register_script( 'application_font_script', $apm_settings['paths']['js']. 'admin/typeface-0.15.js' ); wp_enqueue_script( 'application_font_script' ); wp_register_script( 'application_font_gotham_script', $apm_settings['paths']['js']. 'admin/gotham_rounded_light.typeface.js' ); wp_enqueue_script( 'application_font_gotham_script' ); //wp_register_script( 'application_maker_jqueryui18_script', $apm_settings['paths']['js']. 'admin/multiselect_jquery/jquery-ui-1.8.custom.min.js' ); //wp_enqueue_script( 'application_maker_jqueryui18_script' ); wp_register_script( 'application_maker_script_libs', $apm_settings['paths']['js']. 'admin/scripts_libs.js', array('jquery-ui-sortable') ); wp_enqueue_script( 'application_maker_script_libs' ); wp_register_script( 'application_maker_script', $apm_settings['paths']['js']. 'admin/scripts.js', array('jquery-ui-sortable') ); wp_enqueue_script( 'application_maker_script' ); wp_register_script( 'application_maker_localization_script', $apm_settings['paths']['js']. 'admin/multiselect_jquery/plugins/localisation/jquery.localisation-min.js', array('jquery-ui-sortable') ); wp_enqueue_script( 'application_maker_localization_script' ); wp_register_script( 'application_maker_scrollto_script', $apm_settings['paths']['js']. 'admin/multiselect_jquery/plugins/scrollTo/jquery.scrollTo-min.js', array('jquery-ui-sortable') ); wp_enqueue_script( 'application_maker_scrollto_script' ); wp_register_script( 'application_maker_multiselect_script', $apm_settings['paths']['js']. 'admin/multiselect_jquery/ui.multiselect.js', array('jquery-ui-sortable') ); wp_enqueue_script( 'application_maker_multiselect_script' ); wp_enqueue_style( 'application_maker_style', $apm_settings['paths']['css']. 'admin/style.css' ); wp_enqueue_style( 'application_maker_multiselect_style', $apm_settings['paths']['css']. 'admin/ui.multiselect.css' ); wp_enqueue_style( 'application_maker_style_editor', $apm_settings['paths']['includes']. '/css/editor-buttons.css' ); //wp_enqueue_style( 'jqueryui_style_editor', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/themes/ui-lightness/jquery-ui.css' ); $this->manage_featured_images(); function get_my_suggestions_ajax_autocomplete() { global $wpdb; // This function should query the database and get results as an array of rows: // GET the 'term' (what has been typed by the user) $suggestions_array = array(); // echo JSON to page and exit. $selected_post_type=$_GET["post_type"]; $fieldname=$_GET["fieldname"]; $term = $_GET['query']; $query = " SELECT * FROM $wpdb->posts WHERE $wpdb->posts.post_title LIKE '%$term%' AND $wpdb->posts.post_type = '$selected_post_type' ORDER BY $wpdb->posts.post_title "; $posts_list= $wpdb->get_results($query); //echo $query.'-'.count($posts_list); $suggestions=array(); $data=array(); foreach ($posts_list as $key => $value) { $suggestions[]=$value->post_title; $data[]=$value->ID; } //echo var_dump($posts_list); $str="{query:'".$term."', suggestions:".json_encode($suggestions).", data:".json_encode($data)."}";// json_encode($suggestions_array) // $response = $_GET["callback"]."(".$str.")"; echo $str; exit; } add_action( 'wp_ajax_amp-ajax-autocomplete', 'get_my_suggestions_ajax_autocomplete' ); function apm_save_comments() { global $wpdb, $current_user, $oThis,$meta_marker; $post_id=$_POST['post_id']; $post=get_post($post_id); $post_type=get_post_type( $post_id ); $post_type_label=''; foreach( $oThis->applications as $mainkey => $application ){ $modules=$application ['modules']; foreach($modules as $key=> $module){ if($key==$post_type){ $post_type_label=$module['singular_name']; } } } $comment=$_POST['comment']; $fieldname=$_POST['fieldname']; require_once APPLICATION_MAKER_VIEWS_PATH . 'apm-comments-tpl.php'; require_once APPLICATION_MAKER_VIEWS_PATH . 'apm-comments-email-tpl.php'; get_currentuserinfo(); //$current_user->ID $time = current_time('mysql'); $lang_str=''; $lang=''; if(isset($_POST['lang'])){ $lang=$_POST['lang']; $lang_str=' - Language: '.$lang; } $data = array( 'comment_post_ID' => $post_id, 'comment_author' =>$current_user->user_login, 'comment_author_email' => $lang,//$current_user->user_email, 'comment_content' =>$comment, 'comment_type' => '', // 'comment_parent' => 0, 'user_id' => $current_user->ID, 'comment_date' => $time, 'comment_approved' => 1 ); $com_id=wp_insert_comment($data); $view=str_replace('[[username]]',$current_user->user_login, $view); $view=str_replace('[[id]]',$com_id, $view); $view=str_replace('[[comment_author_email]]', $current_user->user_email, $view); $view=str_replace('[[date]]', 'Today', $view); $view=str_replace('[[lang_zone]]', $lang_str, $view); $view=str_replace('[[time]]', date('H:i').' hrs', $view); $view=str_replace('[[comment]]', $comment, $view); $view=str_replace('[[fieldname]]', '"'.$fieldname.'"', $view);// $view=str_replace('\"', '***', $view); echo $view; $company_name=esc_attr(get_option('company_name')); $system_name=esc_attr(get_option('system_name')); if($system_name==false){ $system_name='Application Maker'; } $emailview=str_replace('[[company_name]]',$company_name, $emailview); $emailview=str_replace('[[system_name]]',$system_name, $emailview); $emailview=str_replace('[[username]]',$current_user->user_login, $emailview); $emailview=str_replace('[[id]]',$com_id, $emailview); $emailview=str_replace('[[comment_author_email]]', $current_user->user_email, $emailview); $emailview=str_replace('[[date]]', 'Today', $emailview); $emailview=str_replace('[[time]]', date('H:i').' hrs', $emailview); $emailview=str_replace('[[lang_zone]]', $lang_str, $emailview); $emailview=str_replace('[[comment]]', $comment, $emailview); $emailview=str_replace('[[post_type]]', $post_type_label, $emailview); $emailview=str_replace('[[post_title]]', $post->post_title, $emailview); $emailview=str_replace('[[post_url]]', site_url()."/wp-admin/post.php?post=".$post->ID."&action=edit", $emailview); $subject='['.$post->post_title.'] comment: '.substr(strip_tags($comment),0,30).'...'; $message=$emailview; $notifications_comments=get_post_meta($post->ID, 'notifications_comments'.$meta_marker, true); $notifications_rules=get_post_meta($post->ID, 'notifications_rules'.$meta_marker, true); $notifications_comments_list=explode(',',$notifications_comments); if(is_array($notifications_rules) and count($notifications_rules)>0){ foreach($notifications_rules as $key=>$value){ if($value=="not_assi_com_yes"){ $assignee_id=get_post_meta($post->ID, 'assign_to'.$meta_marker, true); if(!empty($assignee_id)){ if(in_array($assignee_id, $notifications_comments_list)){ } else { array_push($notifications_comments_list,$assignee_id); } } //$assignee=get_user($assignee_id); } if($value=="not_team_com_yes"){ $team_ids=get_post_meta($post->ID, 'team_assignments'.$meta_marker, true); if(!empty($team_ids)){ $team_array=explode(',',$team_ids); foreach($team_array as $key=>$member_id){ if(in_array($member_id, $notifications_comments_list)){ } else { array_push($notifications_comments_list,$member_id); } } } } if($value=="not_selec_yes"){ $users_ids=get_post_meta($post->ID, 'notifications'.$meta_marker, true); if(!empty($users_ids)){ $users_array=explode(',',$users_ids); foreach($users_array as $key=>$member_id){ if(in_array($member_id, $notifications_comments_list)){ } else { array_push($notifications_comments_list,$member_id); } } } } } } $notifications_comments=implode(',',$notifications_comments_list); //$message='---'.$notifications_comments.'---'.$message; if($notifications_comments!==""){ $notify_to_list=get_users(array('include' =>$notifications_comments)); $oThis->apmSendMail($current_user->user_email, $subject, $message) ; foreach($notify_to_list as $user){ if(intval($user->ID)!==intval($current_user->ID)){ $oThis->apmSendMail($user->user_email, $subject, $message) ; } } } } add_action( 'wp_ajax_apm_save_comments', 'apm_save_comments' ); function apm_delete_comments() { global $wpdb, $current_user; $comment_id=$_POST['comment_id']; wp_delete_comment( $comment_id ); echo $comment_id; } add_action( 'wp_ajax_apm_delete_comments', 'apm_delete_comments' ); function apm_manage_grid_data() { global $oThis; $oThis->AM_Datagrid->manage_grid_data($_POST); } add_action( 'wp_ajax_apm_manage_grid_data', 'apm_manage_grid_data' ); function apm_add_category() { global $wpdb, $current_user; $name=$_REQUEST['name']; $slug=$_REQUEST['slug']; $description=$_REQUEST['description']; $tagcateg=$_REQUEST['tagcateg']; /*$cat_defaults = array( 'cat_ID' => 0, 'cat_name' =>$name , 'category_description' => $description, 'category_nicename' =>$slug , 'category_parent' =>'' ); wp_insert_category( $cat_defaults );*/ $ret=wp_insert_term( $name, // the term $tagcateg, // the taxonomy array( 'description'=> $description, 'slug' => $slug, 'parent'=> '' ) ); echo $ret['term_id']; } add_action( 'wp_ajax_apm_add_category', 'apm_add_category' ); //apm_save_comments add_action('admin_footer', array($this,'apm_set_footer')); //ADD a hidden field to know if we are in edit or create post function apm_edit_form_advanced() { global $wpdb, $current_user; if(isset($_GET['post'])){ $act='updated'; } else { $act='created'; } echo ""; } add_action('edit_form_advanced', 'apm_edit_form_advanced'); // add_submenu_page('options-general.php',_('Applications Maker Plugin Help'), _('Applications Maker Plugin Help'), 'administrator', 'application-maker-help', array($this, 'application_maker_help')); /***START MANAGE AUTO COMBO ON POST COLUMN, for CATEGORIES */ function todo_restrict_manage_posts() { global $typenow, $post_type,$oThis; $args=array( 'public' => true, '_builtin' => false ); $post_types = get_post_types($args); if ( in_array($typenow, $post_types) ) { $filters = get_object_taxonomies($typenow); $nb_of_filters=0; echo 'Advanced Search: (Show)
'; foreach ($filters as $tax_slug) { $nb_of_filters++; $tax_obj = get_taxonomy($tax_slug); echo ' '.$tax_obj->label .':'; wp_dropdown_categories(array( 'show_option_all' => __('Show All '), 'taxonomy' => $tax_slug, 'name' => $tax_obj->name, 'orderby' => 'term_order', 'selected' => $_GET[$tax_obj->query_var], 'hierarchical' => $tax_obj->hierarchical, 'show_count' => false, 'hide_empty' => true )); } echo '
'; //add custom dropdown comboboxes for custom fields, for "module_columns_filters" in the array $post_type_object=$oThis->post_types[$post_type]; if( isset( $post_type_object['module_columns_filters'] ) ) { foreach($post_type_object['module_columns_filters'] as $object){ $nb_of_filters++; $field=$oThis->default_fields[$object]; switch($field['field_type']){ case 'select': if( isset( $field['field_config']['post_type'] ) ){ show_custom_post_dropdown($field['field_config']['post_type'],$field['label']); } else if ( isset( $field['field_config']['use_values']) and $field['field_config']['use_values']==true){ echo ' '.$field['label'].': '; } break; case 'autocomplete': if( isset( $field['field_config']['post_type'] ) ){ $select_post_type=$field['field_config']['post_type'] ; $value=''; $valueDisplay=''; if(isset( $_GET['key_'.$object] ) ){ $value=$_GET['key_'.$object] ; } if(isset( $_GET['keydisplay_'.$object] ) ){ $valueDisplay=$_GET['keydisplay_'.$object] ; } echo ' '.$field['label'].":"; echo ''; echo ''; $help_image = WP_PLUGIN_URL.'/'.WP_PLUGIN_FOLDER.'/img/bugsqa_16.png'; echo ''._('AutoSuggest field, please enter the first 3 characters.').''; } break; case 'checkbox': show_custom_post_checkbox_dropdown($field['label'],$object); break; case 'userslist': show_userlist_dropdown($field,$object); break; case 'assignee': show_userlist_dropdown($field,$object); break; } } } echo '
'; if($nb_of_filters==0){ echo ''; } } } //CREATE A CUSTOM DROP DOWN COMBO FILTER FOR A CHECKBOX CUSTOM FIELD function show_custom_post_checkbox_dropdown($label,$object){ global $post, $wpdb, $oThis; echo ' '.$label.': '; } //CREATE A CUSTOM DROP DOWN COMBO FILTER FOR A CUSTOM FIELD function show_custom_post_dropdown($post_type, $post_type_label){ global $post, $wpdb, $oThis; $posts_list= $oThis->AM_Core->get_posts_list_alone($post_type); echo ' '.$post_type_label.': '; } //SHOW USERS DROPDOWN COMBO function show_userlist_dropdown($field,$object){ global $post, $wpdb, $oThis; echo " Assign to: "; wp_dropdown_users(array( 'show_option_all' => __('Show All' ), 'name' => 'key_'.$object ,'selected' => $_GET['key_'.$object] )); echo ' '; } //MANAGE THE DATAGRIDS COMBO DROPDOWNS FILTERING function my_filter($query) { global $pagenow, $post_type, $oThis,$meta_marker; if( $pagenow == 'edit.php' ){ $post_type_object=$oThis->post_types[$post_type]; if( isset( $post_type_object['module_columns_filters'] ) ) { foreach($post_type_object['module_columns_filters'] as $object){ $field=$oThis->default_fields[$object]; //echo "---".$field['field_config']['post_type']; if(isset( $_GET['key_'.$field['field_config']['post_type']] ) and $_GET['key_'.$field['field_config']['post_type']] !=='all'){ set_query_var('meta_value',$_GET['key_'.$field['field_config']['post_type']]) ; set_query_var('meta_key',$object.$meta_marker) ; switch($field['field_type']){ case 'select': set_query_var('meta_compare','=') ; break; } } else if( isset( $_GET['key_'.$object] ) and $_GET['key_'.$object] !=='all' ){ set_query_var('meta_value',$_GET['key_'.$object]) ; set_query_var('meta_key',$object.$meta_marker) ; set_query_var('meta_compare','=') ; }else if(isset($field['field_type']) and $field['field_type']=='userslist' and isset( $_GET['key_'.$object] ) and $_GET['key_'.$object] !=='all'){ set_query_var('meta_value',$_GET['key_'.$object]) ; set_query_var('meta_key',$object.$meta_marker) ; set_query_var('meta_compare','=') ; }else if(isset($field['field_type']) and $field['field_type']=='checkbox' and isset( $_GET['key_'.$object] ) and $_GET['key_'.$object] !=='all'){ $v=$_GET['key_'.$object]; if($v=='1'){ set_query_var('meta_value',$v) ; set_query_var('meta_key',$object.$meta_marker) ; set_query_var('meta_compare','=') ; } else { //set_query_var('meta_value','') ; set_query_var('meta_value','1') ; set_query_var('meta_key',$object.$meta_marker) ; set_query_var('meta_compare','!=') ; } } } } } } add_action( 'parse_query', 'my_filter' ); function todo_convert_restrict($query) { global $pagenow, $oThis; global $typenow; if ($pagenow=='edit.php') { $filters = get_object_taxonomies($typenow); foreach ($filters as $tax_slug) { $var = &$query->query_vars[$tax_slug]; if ( isset($var) ) { $term = get_term_by('id',$var,$tax_slug); $var = $term->slug; } } } } add_action( 'restrict_manage_posts', 'todo_restrict_manage_posts' ); add_filter('parse_query','todo_convert_restrict'); /***END MANAGE AUTO COMBO ON POST COLUMN, for CATEGORIES */ }///END INIT //MAKE THE CUSTOM COLUMNS SORTABLE //Register the columns to display as sortable function create_my_custom_columns_register_sortable($columns) { global $post, $wpdb; if(isset( $_GET['post_type'] ) ){ $selected_post_type=$_GET['post_type']; $post_type_obj=$this->post_types[$selected_post_type]; $columns_list=$post_type_obj['module_columns']; //echo var_dump($columns_list); foreach ($columns_list as $column) { $columns[$column] = $column; } } return $columns; } //Process the sorting for one column function my_column_orderby($vars) { global $wpdb, $wp_query,$oThis,$meta_marker; //Is it a category? (look in our array listing all the custom categories) if(isset($this->all_categories[$vars['orderby']])){ } else { //Is not a category, so we process sort by the meta value of the column. //note: currently sorting on ly the the meta_value that is a number ID value in case of related or Select combo data... Not sorting yet on the text value... if ( isset( $vars['orderby'] ) ) { $fieldname=$vars['orderby'] ; $selected_post_type=$_GET['post_type']; $field=$this->default_fields[$fieldname]; isset($field['field_type']) ? $field_type=$field['field_type'] : $field_type='textfield'; if($field_type=='select'){ if(isset($field['field_config']) ){ if(isset($field['field_config']['use_values']) or isset($field['field_config']['autoid']) or isset($field['field_config']['post_type'])){ //SO it is a number ID $vars = array_merge( $vars, array( 'meta_key' => $fieldname.$meta_marker, 'orderby' => 'meta_value_num' ) ); } else { $vars = array_merge( $vars, array( 'meta_key' => $fieldname.$meta_marker, 'orderby' => 'meta_value' ) ); } } else { $vars = array_merge( $vars, array( 'meta_key' => $fieldname.$meta_marker, 'orderby' => 'meta_value' ) ); } //echo "



". var_dump($vars); } else if($field_type=='datefield') { $vars = array_merge( $vars, array( 'meta_key' => $fieldname.$meta_marker, 'orderby' => 'meta_value' //'orderby' =>'(SELECT STR_TO_DATE(meta_value,’%m/%d/%Y’) FROM '.$wpdb->postmeta.' WHERE post_id = '.$wpdb->posts.ID.' AND meta_key = ‘'.$fieldname.'_value.’)' . $wp_query->get(‘order’) ) ); //echo "



". '(SELECT STR_TO_DATE(meta_value,’%m/%d/%Y’) FROM '.$wpdb->postmeta.' WHERE post_id = '.$wpdb->posts.ID.' AND meta_key = ‘'.$fieldname.'_value.’)' . $wp_query->get(‘order’); } else { $vars = array_merge( $vars, array( 'meta_key' => $fieldname.$meta_marker, 'orderby' => 'meta_value' ) ); } } } return $vars; } function test1($meta_sql) { echo '




TEST '; echo var_dump($meta_sql); return $meta_sql; } function testposts_orderby($orderby ) { echo '




TEST order '; echo var_dump($orderby); return $orderby ; } //CREATE CUSTOM COLUMNS ON DATA GRIDS function create_my_custom_columns($columns) { global $post, $wpdb,$apm_settings; if(isset( $_GET['post_type'] ) ){ $selected_post_type=$_GET['post_type']; $post_type_obj=$this->post_types[$selected_post_type]; $columns_list=$post_type_obj['module_columns']; foreach ($columns_list as $column) { if(isset($this->default_fields[$column])){ $label=$this->default_fields[$column]['label']; $label=str_replace("{{currency}}", $apm_settings['configs']['default_currency'], $label); $columns[$column] = $label; } elseif (isset($this->all_categories[$column])){ $columns[$column] = $this->all_categories[$column]['name']; } } } return $columns; } //DISPLAY THE CONTENT OF THE CUSTOM DATA GRIDS COLUMNS function my_show_columns($name) { global $post, $wpdb; $field_type='textfield'; if(isset($this->default_fields[$name]['field_type'])){ $field_type=$this->default_fields[$name]['field_type']; } $val= $this->get_field_value($field_type,$name,$post) ; echo $val;//.$field_type; } function get_field_value($field_type,$name,$post_obj) { global $wpdb,$meta_marker,$apm_settings; //echo " +".$post_obj->ID."+ "; $val='-'; switch ($field_type) { case 'textfield': $val= get_post_meta($post_obj->ID, $name.$meta_marker, true); break; case 'currencyfield': $val= get_post_meta($post_obj->ID, $name.$meta_marker, true)." ".$apm_settings['configs']['default_currency']; break; case 'numberfield': $val= get_post_meta($post_obj->ID, $name.$meta_marker, true); break; case 'userslist': $valid= get_post_meta($post_obj->ID, $name.$meta_marker, true); $users=get_users( array('include'=>array($valid)) ); $val=$users[0]->display_name; $val= sprintf( '%s', esc_url( add_query_arg( array( 'user_id' => $valid), 'user-edit.php' ) ),$val); break; case 'assignee': $valid= get_post_meta($post_obj->ID, $name.$meta_marker, true); $users=get_users( array('include'=>array($valid)) ); $val=$users[0]->display_name; $val= sprintf( '%s', esc_url( add_query_arg( array( 'user_id' => $valid), 'user-edit.php' ) ),$val); break; case 'autocomplete': $valid= get_post_meta($post_obj->ID, $name.$meta_marker, true); if(is_array($valid)){ $valid=implode(',',$valid); } if( isset( $this->default_fields[$name]['field_config']['post_type'] ) ){ $query = "SELECT post_title, ID FROM $wpdb->posts ". "WHERE post_type='".$this->default_fields[$name]['field_config']['post_type']."' AND ID in (".$valid.")"; $posts_list= $wpdb->get_results($query); $val=$this->AM_Core->get_posts_list_titles($posts_list,true); } break; case 'select': $valid= get_post_meta($post_obj->ID, $name.$meta_marker, true); //$val.=" ".$this->default_fields[$name]['field_config']['post_type']; if(is_array($valid)){ $valid=implode(',',$valid); } if( isset( $this->default_fields[$name]['field_config']['post_type'] ) ){ $query = "SELECT post_title, ID FROM $wpdb->posts ". "WHERE post_type='".$this->default_fields[$name]['field_config']['post_type']."' AND ID in (".$valid.")"; $posts_list= $wpdb->get_results($query); $val=$this->AM_Core->get_posts_list_titles($posts_list,true); } else if ( isset( $this->default_fields[$name]['field_config']['use_values'] ) ){ $val=_('None'); $values=$this->default_fields[$name]['options']; foreach($values as $key => $value){ if($key==$valid){ $val=$value; } } } break; case 'checkbox': $val= get_post_meta($post_obj->ID, $name.$meta_marker, true); $txt='No'; if($val=='1'){ $txt='Yes'; } $val=$txt; break; case 'datefield': $val= get_post_meta($post_obj->ID, $name.$meta_marker, true); break; } if(isset($this->all_categories[$name])){ //$categ=$this->all_categories[$name]; $val = ''; $_taxonomy = $name; $terms = get_the_terms( $post_obj->ID, $_taxonomy ); //echo $_taxonomy; if ( !empty( $terms ) ) { $out = array(); foreach ( $terms as $c ) $out[] = $c->name; $val.= join( ', ', $out ); } else { $val=' None'; } } return $val; } function post_edit_form_tag() { echo ' enctype="multipart/form-data"'; } //MANAGE THE FEATURED IMAGES SIZE AND EXTRA FEATURED IMAGES BLOCKS public function manage_featured_images() { foreach( $this->applications as $mainkey => $application ){ $modules=$application ['modules']; foreach($modules as $key=> $module){ if(isset($module['custom_featured_image'])){ if(isset($module['custom_featured_image']['sizes'])){ foreach($module['custom_featured_image']['sizes'] as $size_key => $size){ if(isset($size[2]) and $size[2]==true){ add_image_size( $size_key, $size[0], $size[1], true ); ///CROPPING } else { add_image_size( $size_key, $size[0], $size[1] ); } } } if(isset($module['custom_featured_image']['blocks']) and class_exists('MultiPostThumbnails')){ foreach($module['custom_featured_image']['blocks'] as $block_key => $block){ new MultiPostThumbnails(array( 'label' => $block, 'id' => $block_key, 'post_type' => $key ) ); } } } } } } //ADD THE CUSTOM METABOXES public function myplugin_add_custom_box() { global $current_user; foreach($this->post_types as $key=> $post_type_obj){ if(isset($post_type_obj['metaboxes'])){ foreach($post_type_obj['metaboxes'] as $metaboxkey=> $metabox_obj){ if(isset($metabox_obj['fields']) or isset($metabox_obj['positioning'])){ if(count($metabox_obj['fields'])>0 or count($metabox_obj['positioning'])>0){ $module_name=$key; add_meta_box( $metaboxkey, $metabox_obj['title'], 'myplugin_inner_custom_box', $key,$metabox_obj['context'],$metabox_obj['priority'], array( 'post_type' => $key)); } } } } } function myplugin_inner_custom_box( $post, $metabox ) { global $post_types, $oThis; // Use nonce for verification wp_nonce_field( plugin_basename( __FILE__ ), 'app-maker-nonce'); // The actual fields for data entry $current_post_type=$post_types[$metabox['args']['post_type']]; $oThis->AM_Core->setFieldsBox($key,$current_post_type['metaboxes'] ); foreach($current_post_type['metaboxes'] as $key=> $metabox_obj){ if($key==$metabox['id'] ){//and isset($metabox_obj['fields']) /*foreach($metabox_obj['fields'] as $field){ $oThis->AM_Core->setField($field); }*/ $oThis->AM_Core->setFieldsBox($key,$metabox_obj); } } } } //CREATE ALL THE CUSTOM POST TYPES FROM $this->applications public function create_main_post_types() { global $apm_settings; foreach( $this->applications as $mainkey => $application ){ $appli_post_types=$application ['modules']; foreach($appli_post_types as $key=> $post_type_obj){ $supports= array('title'); if(isset($post_type_obj['show_editor']) and $post_type_obj['show_editor']==true){ array_push($supports,'editor'); } if(isset($post_type_obj['hide_featured_image']) and $post_type_obj['hide_featured_image']==true){ } else { array_push($supports,'thumbnail'); } if(isset($post_type_obj['hide_author']) and $post_type_obj['hide_author']==true){ } else { array_push($supports,'author'); } if(isset($post_type_obj['is_page']) and $post_type_obj['is_page']==true){ $is_page=true; } else { $is_page=false; } if(isset($post_type_obj['hide_attributes']) and $post_type_obj['hide_attributes']==true){ } else { array_push($supports,'page-attributes'); } if(isset($post_type_obj['show_editor']) and $post_type_obj['show_editor']==true){ array_push($supports,'editor'); } if(isset($post_type_obj['module_categories']) ){ $module_categories=$post_type_obj['module_categories']; } else { $module_categories=array(); } if(isset($post_type_obj['module_tags']) ){ $module_tags=$post_type_obj['module_tags']; } else { $module_tags=array(); } if(isset($post_type_obj['slug']) ){ $post_slug=$post_type_obj['slug']; } else { $post_slug=$key; } $icon=''; if(isset($post_type_obj['icon'])){ $icon=" "; } //echo '


----'.$key; register_post_type($key, array( 'labels' => array( 'name' =>$post_type_obj['name'], 'singular_name' => $post_type_obj['singular_name'], 'menu_name' => _('List ')." ".$post_type_obj['name'], 'add_new' => _('Add New')." ".$post_type_obj['singular_name'], 'add_new_item' => _('Add New')." ".$post_type_obj['singular_name'], 'new_item' => _('New')." ".$post_type_obj['singular_name'], 'edit_item' => _('Edit')." ".$post_type_obj['singular_name'], 'all_items' => ' '.$icon.$post_type_obj['menu_name'].'
', //'all_items' => ''.$icon.$post_type_obj['menu_name'].'
', 'view_item' => _('View')." ".$post_type_obj['singular_name'], 'search_items' => _('Search')." ".$post_type_obj['singular_name'], 'not_found' => _('No')." ".$post_type_obj['singular_name']." "._('found') ), 'public' => true, 'show_ui' => true, 'show_in_menu' => false,//$mainkey.'-main-menu',//false,// 'publicly_queryable' => true, //'capability_type' => 'post', //'capabilities' =>array( 'administrator' ), //'hierarchical' => $is_page, 'exclude_from_search' => false, 'rewrite' => array('slug' =>$post_slug), 'supports' =>$supports //,'taxonomies' =>array('cat_module_types')//$module_categories ) ); //echo '
-///---'.$mainkey .'-main-menu'; } } foreach( $this->applications as $key => $application ){ if(isset($application['categories'] )){ foreach( $application['categories'] as $catkey => $category ){ register_taxonomy( $catkey, null, array( 'labels' => array( 'name' => $category['name'], 'singular_name' => $category['name'] ), //'capabilities' =>array( 'administrator' ), 'hierarchical' => true ) ); }; } if(isset($application['tags'] )){ //echo '







****'.var_dump($application['tags']); foreach( $application['tags'] as $catkey => $category ){ //echo $category['name'].'-'.$catkey; register_taxonomy( $catkey, null, array( 'labels' => array( 'name' => $category['name'], 'singular_name' => $category['name'] ), //'capabilities' =>array( 'administrator' ), 'hierarchical' => false ) ); }; } //echo '
----'.$key .'-main-menu'; } foreach( $this->applications as $key => $application ){ $appli_post_types=$application ['modules']; foreach($appli_post_types as $subkey=> $post_type_obj){ if(isset($post_type_obj['module_categories'])){ foreach($post_type_obj['module_categories'] as $categ_name){ register_taxonomy_for_object_type($categ_name, $subkey); } } if(isset($post_type_obj['module_tags'])){ foreach($post_type_obj['module_tags'] as $categ_name){ register_taxonomy_for_object_type($categ_name, $subkey); } } } } } //ADD MAIN APPLICATIONS TOP MENUS public function my_admin_head() { global $current_user; $user_rich_text=get_user_meta($current_user->ID,'rich_editing',true); if($user_rich_text=='false'){ echo "
The APM plugin is requiring to have you user set to allow using Rich Text Editor, and the editor must be TinyMce.
Your current settings will generate a bug in our plugin. We are working to change this but for the moment please adapt your user settings.
"; } if(wp_default_editor()!=='tinymce'){ echo "
The APM plugin is requiring to have you default Rich Text Editor activated and set to TinyMce.
Your current settings will generate a bug in our plugin. We are working to change this but for the moment please adapt your settings.
"; } } //ADD MAIN APPLICATIONS TOP MENUS public function my_appmaker_menu() { global $main_config,$apm_settings; $oThis=$this; $this->toto='llll'; foreach( $this->applications as $key => $application ){ add_menu_page($application ['name'],$application ['menuname'], $main_config['default_role_minimum'], $key .'-main-menu', array($this, 'my_appmaker_menu_do')); $appli_post_types=$application ['modules']; foreach($appli_post_types as $subkey=> $post_type_obj){ $icon=''; if(isset($post_type_obj['icon'])){ $icon=" "; } $menu=''; $menu.=' '.$icon.$post_type_obj['menu_name'].'
'; add_submenu_page($key.'-main-menu',$key.'_'.$subkey,$menu, $main_config['default_role_minimum'],$key.'-'.$subkey, create_function('', 'return apm_do_list("'.$key.'","'.$subkey.'");') ); }; } //ADD CUSTOM CATEGORIES IN THE APPLICATION MENU function apm_do_list($appkey,$modulekey) { global $main_config, $oThis; $app=$oThis->applications[$appkey]; $module=$app['modules'][$modulekey]; $oThis->AM_Datagrid->config=array( 'appkey'=>$appkey, 'modulekey'=>$modulekey, 'app'=>$app, 'module'=>$module, ); $oThis->AM_Datagrid->default_fields=$oThis->default_fields; $oThis->AM_Datagrid->set_top_modules_list(); $oThis->AM_Datagrid->set_page_header(); $oThis->AM_Datagrid->set_tabs(); $oThis->AM_Datagrid->set_footer(); } } //ADD CUSTOM CATEGORIES IN THE APPLICATION MENU public function my_categ_menu() { global $main_config; foreach( $this->applications as $key => $application ){ if( isset( $application['categories'] ) and isset( $application['show_categories_in_menu'] ) and $application['show_categories_in_menu'] == true ){ foreach( $application['categories'] as $catkey => $category ){ add_submenu_page($key.'-main-menu',$category['name'], 'Category '.$category['menu_name'], $main_config['default_role_minimum'], $catkey, array($this, 'my_categories_redirect_do')); }; } } } //REDIRECT TO A TAXNOMONY PAGE FORM A LINK IN THE APPLICATION MENU public function my_categories_redirect_do() { /*if (!current_user_can('administrator')) { wp_die( __('You do not have sufficient permissions to access this page.') ); }*/ //echo site_url().'/wp-admin/'; wp_redirect(site_url().'/wp-admin/edit-tags.php?taxonomy='.$_GET['page']); //header("Location: ".site_url().'/wp-admin/edit-tags.php?taxonomy='.$_GET['page'], true); echo "
Redirecting to the category
.

If you are not auto redirected to your category, please click here. (You need to activate your javascript for using Wordpress)

"; exit; //echo 'after redirect wp'; } ///DISPLAY THE CONVERTOR PAGE //DEPRECATED!!!!! /*public function my_appmaker_convert_apps_do($args) { global $oThis, $apm_settings,$meta_marker; if (!current_user_can('administrator')) { wp_die( __('>>>You do not have sufficient permissions to access this page.') ); } $appName=str_replace('toplevel_page_', '', current_filter()); $appNameArr=explode('_',$appName); $appName=$appNameArr[2]; $appName=str_replace('-convert', '', $appName); $appLabel=$oThis->applications[$appName]['name']; require_once APPLICATION_MAKER_PATH . 'views/apm-converter.php'; }*/ //DISPLAY THE MAIN PAGE OF THE APPLICATION public function my_appmaker_menu_do($args) { global $oThis, $apm_settings,$meta_marker,$wpdb; $appName=str_replace('toplevel_page_', '', current_filter()); $appName=str_replace('-main-menu', '', $appName); $appLabel=$oThis->applications[$appName]['name']; ///-main-menu if(isset($_GET['action-type'])){ $action_type=$_GET['action-type']; switch($action_type){ case 'convert': require_once APPLICATION_MAKER_PATH . 'views/apm-converter.php'; break; } } else { $appIntrotext=''; if( isset( $oThis->applications[$appName]['intro_page_text'] ) ){ $appIntrotext='

'.$oThis->applications[$appName]['intro_page_text'].'

'; } require_once APPLICATION_MAKER_PATH . 'views/apm-home-top.php'; if(isset($oThis->applications[$appName]['options_form'])){ if (current_user_can('administrator')) { require_once APPLICATION_MAKER_PATH . 'views/'.$oThis->applications[$appName]['options_form'].'.php';//apm-home-options //wp_die( __('You do not have sufficient permissions to access this page.') ); } } } } //CREATE CUSTOM DASHBOARD WIDGETS function get_word_from_number($name){ $name=str_replace(' ', '_', $name); $name=str_replace('1', 'one_', $name); $name=str_replace('2', 'two_', $name); $name=str_replace('3', 'three_', $name); $name=str_replace('4', 'four_', $name); $name=str_replace('5', 'five_', $name); $name=str_replace('6', 'six_', $name); $name=str_replace('7', 'seven__', $name); $name=str_replace('8', 'height', $name); $name=str_replace('9', 'nine_', $name); $name=str_replace('0', 'zero_', $name); return $name; } function myplugin_add_dashboard_widgets(){ // foreach( $this->applications as $mainkey => $application ){ $appli_post_types=$application ['modules']; foreach($appli_post_types as $key=> $post_type_obj){ if(isset($post_type_obj['module_dashboard_widgets']) ){ foreach($post_type_obj['module_dashboard_widgets'] as $widgetkey=> $widget){ $name=strtolower($post_type_obj["name"]); $name=$this->get_word_from_number($name); //$name=preg_replace('%[0-9]%', '_', $name, 1); wp_add_dashboard_widget('fgl_dashboard_widget_'.$key."_".$widgetkey, $widget['label'], create_function('', 'return myplugin_do_dashboard_widgets("'.$key.'",'.$name.',"'.$widgetkey.'");'), create_function('', 'return myplugin_control_dashboard_widgets("'.$key.'",'.$name.',"'.$widgetkey.'");') ); //, array($this, 'myplugin_control_dashboard_widgets'));//array($this, 'myplugin_do_dashboard_widgets') } } } } remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' ); remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'normal' ); remove_meta_box( 'dashboard_plugins', 'dashboard', 'normal' ); remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' ); remove_meta_box( 'dashboard_right_now', 'dashboard', 'normal' ); remove_meta_box( 'dashboard_recent_drafts', 'dashboard', 'normal' ); remove_meta_box( 'dashboard_primary', 'dashboard', 'normal' ); remove_meta_box( 'dashboard_secondary', 'dashboard', 'normal' ); $oThis=$this; function myplugin_do_dashboard_widgets ($post_type,$post_type_label,$widgetkey){ global $oThis; $oThis->myplugin_do_dashboard_widgets($post_type,$post_type_label,$widgetkey); }; function myplugin_control_dashboard_widgets ($post_type,$post_type_label,$widgetkey){ global $oThis; $oThis->myplugin_control_dashboard_widgets($post_type,$post_type_label,$widgetkey); }; } function myplugin_do_dashboard_widgets($post_type,$post_type_label,$widgetkey){ global $oThis, $wpdb,$meta_marker,$apm_settings; //$post_type='fgl_invoices'; //$post_type_label='Invoices';'15_green_leaves' foreach($oThis->applications as $appli){ $applications=$appli['modules'][$post_type]; $widgObject=$applications['module_dashboard_widgets'][$widgetkey]; $widgType=$widgObject['type'] ; $widgets = get_option( 'dashboard_widget_options' ); // Get the dashboard widget options $widget_id = 'fgl_dashboard_widget_'.$post_type."_".$widgetkey; // This must be the same ID we set in wp_add_dashboard_widget $widget_latest_default_max=esc_attr(get_option('widget_latest_default_max')); if($widget_latest_default_max==false){ $widget_latest_default_max=15; } $total_items = isset( $widgets[$widget_id] ) && isset( $widgets[$widget_id]['items'] ) ? absint( $widgets[$widget_id]['items'] ) : $widget_latest_default_max; $calculs_array=array(); /* * Check whether we have set the post count through the controls. * If we didn't, set the default to 5 */ switch($widgType){ case 'latest_list': break; case 'filtered_list': $total_items=1000000; break; case 'calculs_only': $total_items=1000000; break; } //END switch($widgType){ $q=array( // Leave this as "post" if you just want blog posts 'post_type' => $post_type, 'post_status' => 'publish', 'posts_per_page' => $total_items, // 'orderby' => $sortby, 'order' => 'DESC' ); $sortby='date'; if(isset($widgObject['sortby']) ){ $sortby=$widgObject['sortby']; if(isset($widgObject['sortbymetavalue']) and $widgObject['sortbymetavalue']==true){ $sortby='meta_value'; $q['meta_key']=$widgObject['sortby'].$meta_marker; } if(isset($widgObject['sortbymetavalue_num']) and $widgObject['sortbymetavalue_num']==true){ $sortby='meta_value_num'; $q['meta_key']=$widgObject['sortby'].$meta_marker; } } $q['orderby']=$sortby; if(isset($widgObject['filters']) ){ $mq=array(); foreach ( $widgObject['filters'] as $filterkey => $filterobj ) { $filtervalue=$filterobj['value']; if(is_array($filtervalue)){ $in=join(',',$filtervalue); array_push($mq,array('key' => $filterkey.$meta_marker, 'value' => $filtervalue, 'compare' => 'IN' )); } else { array_push($mq,array('key' => $filterkey.$meta_marker, 'value' => $filtervalue )); } } if(isset($widgObject['filters_relation_is_or']) and $widgObject['filters_relation_is_or']==true){ $mq['value'] = 'OR'; } $q['meta_query']= $mq; } //echo var_dump($q); $posts_query = new WP_Query( $q ); $posts =& $posts_query->posts; $total_items_result=0; if ( $posts && is_array( $posts ) ) { $list = array(); foreach ( $posts as $post ) { // Loop through our array $total_items_result++; $url = get_edit_post_link( $post->ID ); // The URL to the "Edit" post page $title = get_the_title( $post->ID ); // The title of the post $chars = 30; // Our character limit $date=""; if(isset($widgObject['show_date'] ) and $widgObject['show_date'] ==true){ $date="" . get_the_time( get_option( 'date_format' ), $post ) . ''; } $special_fields_str=""; if(isset($widgObject['fields'] ) ){ $fields=$widgObject['fields']; foreach ( $fields as $field ) { $field_type='textfield'; $field_label=""; if(isset($this->default_fields[$field]['field_type'])){ $field_type=$this->default_fields[$field]['field_type']; $field_label=$this->default_fields[$field]['label']; } if(isset($this->all_categories[$field])){ $field_label=$this->all_categories[$field]['singular_name']; } if(isset($this->all_tags[$field])){ $field_label=$this->all_tags[$field]['singular_name']; } $val= $this->get_field_value($field_type,$field,$post) ; $field_label=str_replace("{{currency}}", $apm_settings['configs']['default_currency'], $field_label); $special_fields_str.="".$field_label.": ".$val." | "; // echo '///'.$field.'-'.$field_type.'-'.$val.'//'; } $special_fields_str=" - ".$special_fields_str.""; } $item = "

" . esc_html($title) . " ".$date.$special_fields_str.'

'; if ( $the_content = preg_split( '#\s#', strip_tags( $post->post_content ), $chars+1 , PREG_SPLIT_NO_EMPTY ) ) $item .= '

' . join( ' ', array_slice( $the_content, 0, $chars ) ) . ( $chars < count( $the_content ) ? '…' : '' ) . '

'; $list[] = $item; ///Check if having functions to display and calculate, and proceed if(isset($widgObject['calculs']) ){ //echo '
****calculs**** '; foreach ( $widgObject['calculs'] as $calculkey => $calcul) { //echo '
calculstype '.$calcul['type']; switch($calcul['type']){ case 'sum': if(isset($calculs_array[$calculkey])){ $v=get_post_meta($post->ID, $calculkey.$meta_marker, true); $calculs_array[$calculkey]=intval($calculs_array[$calculkey]+intval($v)); //echo $calculkey.":".$v.' - '.intval($calculs_array[$calculkey]+intval($v)).' - '; } else { $v=get_post_meta($post->ID, $calculkey.$meta_marker, true); $calculs_array[$calculkey]=intval($v); //echo $calculkey.": ".$v.' - '; } break; } } } }//END LIST ALL POSTS $post_type_label=str_replace("{{currency}}", $apm_settings['configs']['default_currency'], $post_type_label); $default_top_str="";//

"._('Show ').$total_items._(' latest item(s) for ').$post_type_label.":

$latest_str='Latest'; if($total_items_result!==0){ $total_items=$total_items_result; $default_top_str="

*"._('Show ').$total_items._(' latest record(s) for ').$post_type_label.":

"; if($widgType=='calculs_only' ){ $default_top_str="

*"._('Totals').":

"; } $latest_str='';//{latest} } if(isset($widgObject['top_string']) ){ $default_top_str="

*".$widgObject['top_string'].":

"; } if($widgType=='latest_list' or $widgType=='calculs_only' or $widgType=='filtered_list' ){ $default_top_str=str_replace('{latest}', $latest_str, $default_top_str); $default_top_str=str_replace('{label}', $post_type_label, $default_top_str); $default_top_str=str_replace('{total_items}', $total_items, $default_top_str); $default_top_str=str_replace("{{currency}}", $apm_settings['configs']['default_currency'], $default_top_str); echo $default_top_str; } if($widgType=='latest_list' or $widgType=='filtered_list'){ echo ""; } if($widgType=='latest_list' or $widgType=='calculs_only' or $widgType=='filtered_list' ){ if(isset($widgObject['calculs']) ){ echo '

_________________________________

'; foreach ( $widgObject['calculs'] as $key => $calcul) { switch($calcul['type']){ case 'sum': $calcul_label=$calcul['label']; $calcul_label=str_replace("{{currency}}", $apm_settings['configs']['default_currency'], $calcul_label); echo '

'.$calcul_label.': '.$calculs_array[$key].'

'; break; } } } if($widgType=='latest_list'){ echo ""._('Click on configure to change the nb of rows listed').''; } //echo ""._('Click on configure to change the nb of rows listed').''; } } else{ if($widgType=='latest_list' or $widgType=='calculs_only' or $widgType=='filtered_list' ){ _e('Sorry, there is no results.'); } } } ///Check if having functions to display and calculate, and proceed } function myplugin_control_dashboard_widgets($post_type,$post_type_label,$widgetkey){ global $oThis, $wpdb,$meta_marker; // This must be the same ID we set in wp_add_dashboard_widget $widget_id = 'fgl_dashboard_widget_'.$post_type."_".$widgetkey; // This must be the same ID we set in wp_add_dashboard_widget $form_id = 'fgl_dashboard_widget-posts-control_'.$post_type; // Set this to whatever you want //$post_type='fgl_invoices'; //$post_type_label='Invoices';'15_green_leaves' foreach($oThis->applications as $appli){ $applications=$appli['modules'][$post_type]; $widgObject=$applications['module_dashboard_widgets'][$widgetkey]; $widgType=$widgObject['type'] ; if ( !$widget_options = get_option( 'dashboard_widget_options' ) ) $widget_options = array(); // If not, we create a new array if ( !isset($widget_options[$widget_id]) ) $widget_options[$widget_id] = array(); // If not, we create a new array // Check whether our form was just submitted if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST[$form_id]) ) { /* * Get the value. In this case ['items'] is from the input * field with the name of '.$form_id.'[items] */ if($widgType=='latest_list'){ $number = absint( $_POST[$form_id]['items'] ); $widget_options[$widget_id]['items'] = $number; // Set the number of items update_option( 'dashboard_widget_options', $widget_options ); // Update our dashboard widget options so we can access later } } if($widgType=='latest_list'){ $number = isset( $widget_options[$widget_id]['items'] ) ? (int) $widget_options[$widget_id]['items'] : ''; // Create our form fields. Pay very close attention to the name part of the input field. echo '

'; echo '

'; } } } public function handle_upload_field($post_id,$key,$typeupload='default_file',$count=0) { global $meta_marker; $is_file=true; if($typeupload=='default_file'){ $file = $_FILES[$key.$meta_marker]; } else if($typeupload=='added_file'){ $file = $_FILES[$key.'_value_'.$count]; } else { return ''; } $filev=$file; $upload = wp_handle_upload($file, array('test_form' => false)); if(!isset($upload['error']) && isset($upload['file'])) { $filetype = wp_check_filetype(basename($upload['file']), null); $title = $file['name']; $ext = strrchr($title, '.'); $title = ($ext !== false) ? substr($title, 0, -strlen($ext)) : $title; $attachment = array( 'post_mime_type' => $wp_filetype['type'], 'post_title' => addslashes($title), 'post_content' => '', 'post_status' => 'inherit', 'post_parent' => $post_id ); if($typeupload=='default_file'){ $attach_key = $key.$meta_marker; } else if($typeupload=='added_file'){ $attach_key = $key.'_value_'.$count; } else { return ''; } $attach_id = wp_insert_attachment($attachment, $upload['file']); $existing_download = (int) get_post_meta($post_id, $attach_key, true); $data=$attach_id; if(is_numeric($existing_download)) { wp_delete_attachment($existing_download); } if(isset($this->default_fields[$key]['is_image']) and $this->default_fields[$key]['is_image']==true){ if(isset($this->default_fields[$key]['image_resize']) ){ $this->handle_image_resize($this->default_fields[$key]['image_resize'],$upload['file'],$post_id,$key) ; } } // update_post_meta($post_id, $attach_key, $attach_id); } return $data; } public function handle_image_resize($sizes,$file_path,$post_id,$key) { //$this->simple_image ->load($file_path); $file_path=str_replace('\\','/', $file_path); $path_arr=explode('/',$file_path); $separ='/'; $path_arr_new=array(); for($inc=0;$inc $size){ $this->simple_image ->load($file_path); if($size[2]=='crop:topleft' or $size[2]=='crop:center'){ $this->simple_image ->resize_crop($size[0],$size[1],$size[2]); } else { $this->simple_image ->resizeToSquareLimit($size[0],$size[1]); } $filenextarr=explode(".",$file_path); $ext=$filenextarr[count($filenextarr)-1]; $extlow=strtolower($ext); $this->simple_image ->save($path_only.$image_name_no_ext.'_'.$size_name.'.'.$extlow); } } public function apm_set_footer() { global $post, $module_name,$oThis, $apm_settings; $post_type=get_post_type( ); $post_type_object=$oThis->post_types[$post_type]; //echo var_dump($post_type_object); $categs_of_post=$post_type_object['module_categories']; $categ_arr=array(); echo "";// // } ////MANAGE SAVING THE DATA FROm A META BOX cutoms fields public function myplugin_save_postdata($post_id) { global $post, $module_name,$oThis,$meta_marker,$current_user; // verify if this is an auto save routine. // If it is our form has not been submitted, so we dont want to do anything if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; // verify this came from the our screen and with proper authorization, // because save_post can be triggered at other times if ( !wp_verify_nonce( $_POST['app-maker-nonce'], plugin_basename( __FILE__ ) ) ) return; // Check permissions if ( 'page' == $_POST['post_type'] ) { if ( !current_user_can( 'edit_page', $post_id ) ) return; } else { if ( !current_user_can( 'edit_post', $post_id ) ) return; } // OK, we're authenticated: we need to find and save the data $post_type_object=$oThis->post_types[$_POST['post_type']]; $fields_list=array(); foreach($post_type_object['metaboxes'] as $k =>$object){ if(isset($object['positioning'])){ $positioning=$object['positioning']; foreach($positioning['main'] as $fieldset){ foreach($fieldset as $field){ array_push( $fields_list,$field); } } if(isset($positioning['tabs'] )){ foreach($positioning['tabs'] as $subkey => $tab){ foreach($tab['items'] as $fieldset){ foreach($fieldset as $field){ array_push( $fields_list,$field); } } } } } else if(isset($object['fields'])){ foreach($object['fields'] as $subk=>$subobject){ array_push( $fields_list,$subk); } } } $action_done='updated'; if(isset($_REQUEST['apm_post_action'])){ $action_done=$_REQUEST['apm_post_action']; } $send_newletter=false; foreach($oThis->default_fields as $key=> $field){ if(in_array($key,$fields_list)){ if(isset($_POST[$key.$meta_marker])){ $data = $_POST[$key.$meta_marker]; } else if(get_post_meta($post_id, $key.$meta_marker) == ""){ $data=get_post_meta($post_id, $key.$meta_marker,true); } else { $data=''; } ///FILE UPLOAD MANAGEMENT $is_file=false; $filev='-'; if(!empty($_FILES[$key.$meta_marker])) { $data=$this->handle_upload_field($post_id,$key) ; } if($key=='newsletter_send_order' and $data=="true") { $data='sent' ; $send_newletter=true; } if(isset($_POST[$key.'_add_file'])){ $uploadfieldscount = $_POST[$key.'_add_file']; if($uploadfieldscount!=='false' and $uploadfieldscount!==false and intval($uploadfieldscount)>0){ if($data==''){ $data=get_post_meta($post_id, $key.$meta_marker,true); } for($i=1;$i0) { $data_added=$this->handle_upload_field($post_id,$key,'added_file',$i) ; $data.="*****".$data_added; } } } } if(isset($field['field_type']) and $field['field_type']=='checkbox'){ if($data=='on'){ $data='1'; } else { $data='0'; } } $do_update=true; $field_type=''; if(isset($field['field_type']) and $field['field_type']=='uploadfield' and $data==''){ $do_update=false; } if(get_post_meta($post_id, $key.$meta_marker) == ""){ add_post_meta($post_id, $key.$meta_marker, $data, true); } else if($data != get_post_meta($post_id, $key.$meta_marker, true)){ if($do_update) { update_post_meta($post_id, $key.$meta_marker, $data); } } else if($data == "" or empty($data)){ if($do_update) { delete_post_meta($post_id, $key.$meta_marker, get_post_meta($post_id, $key.$meta_marker, true)); } } if($data==""){ $data=get_post_meta($post_id, $key.$meta_marker,true); } if( isset( $_POST[$key.'_remove_file'] ) and $_POST[$key.'_remove_file'] !== "false" ){ /*if($data==""){ $data=get_post_meta($post_id, $key.$meta_marker,true); }*/ if(strpos($data, '*****')>-1){ $this->handle_image_removal($data,$post_id,$key); } else { delete_post_meta($post_id, $key.$meta_marker, get_post_meta($post_id, $key.$meta_marker, true)); } } else { if(strpos($data, '*****')>-1){ $this->handle_image_removal($data,$post_id,$key); } } if(strpos($data, '*****')>-1){ $this->handle_image_description($data,$post_id,$key); } else if( isset($_POST[$key.'_file_title_'.$data])){ $this->handle_file_description_update($key,$data) ; } if(isset($_POST[$key.$meta_marker.'_comment'])){ $comment=$_POST[$key.$meta_marker.'_comment']; $lang=''; if(isset($_POST[$key.'_lang'])){ $lang=$_POST[$key.'_lang']; } if($comment!=='' and $comment!=='

'){ get_currentuserinfo(); $time = current_time('mysql'); $data = array( 'comment_post_ID' => $post_id, 'comment_author' =>$current_user->user_login, 'comment_author_email' => $lang,//$current_user->user_email, 'comment_content' =>$comment, // 'comment_author_url'=>$url, 'comment_type' => '', // 'comment_parent' => 0, 'user_id' => $current_user->ID, 'comment_date' => $time, 'comment_approved' => 1 ); $com_id=wp_insert_comment($data); } } } } ////////////////SAVE NEWSLETTER if($send_newletter){ $oThis->handle_newsletter_sending($post_id); } /////////////// SAVE COMMENTS $comment=''; //if(!isset($_GET['action'])){ if(isset($_POST['comments'.$meta_marker.'_comment'])){ $comment=$_POST['comments'.$meta_marker.'_comment']; } //$comment='++'.$_POST['comments_value_comment'].'++'; //} /////////////////////// SAVE HANDLE NOTIFICATIONS require_once APPLICATION_MAKER_VIEWS_PATH . 'apm-post_save-email-tpl.php'; get_currentuserinfo(); $post=get_post($post_id); $post_type=get_post_type( $post_id ); $post_type_label=''; foreach( $this->applications as $mainkey => $application ){ $modules=$application ['modules']; foreach($modules as $key=> $module){ if($key==$post_type){ $post_type_label=$module['singular_name']; } } } $emailview=str_replace('[[username]]',$current_user->user_login, $emailview); $emailview=str_replace('[[comment_author_email]]', $current_user->user_email, $emailview); $emailview=str_replace('[[id]]',$post_id, $emailview); $emailview=str_replace('[[date]]', date('y'), $emailview); $emailview=str_replace('[[comment]]', $comment, $emailview); $emailview=str_replace('[[time]]', date('H:i').' hrs', $emailview); $emailview=str_replace('[[post_type]]', $post_type_label, $emailview); $emailview=str_replace('[[action]]', $action_done, $emailview); $emailview=str_replace('[[post_title]]', $post->post_title, $emailview); $emailview=str_replace('[[post_url]]', site_url()."/wp-admin/post.php?post=".$post_id."&action=edit", $emailview); $company_name=esc_attr(get_option('company_name')); $system_name=esc_attr(get_option('system_name')); if($system_name==false){ $system_name='Application Maker'; } $emailview=str_replace('[[company_name]]',$company_name, $emailview); $emailview=str_replace('[[system_name]]',$system_name, $emailview); $subject='['.$post->post_title.'] was '.$action_done; $message=$emailview; //$subject='tt '; //$message='oo'; $notifications=get_post_meta($post_id, 'notifications'.$meta_marker, true); $notifications_rules=get_post_meta($post_id, 'notifications_rules'.$meta_marker, true); $notifications_list=explode(',',$notifications); //CHECK NOTIFICATIONS RULES, IF EXISTING if(is_array($notifications_rules) and count($notifications_rules)>0){ foreach($notifications_rules as $key=>$value){ if($value=="not_ass_yes"){ $assignee_id=get_post_meta($post_id, 'assign_to'.$meta_marker, true); if(!empty($assignee_id)){ if(in_array($assignee_id, $notifications_list)){ } else { array_push($notifications_list,$assignee_id); } } } if($value=="not_team_yes"){ $team_ids=get_post_meta($post_id, 'team_assignments'.$meta_marker, true); if(!empty($team_ids)){ $team_array=explode(',',$team_ids); foreach($team_array as $key=>$member_id){ if(in_array($member_id, $notifications_list)){ } else { array_push($notifications_list,$member_id); } } } } if($value=="not_updat_yes"){ $curr_user_id=$current_user->ID; if(!empty($curr_user_id)){ if(in_array($curr_user_id, $notifications_list)){ } else { array_push($notifications_list,$curr_user_id); } } } } } ///CHECH NOTIFICATIONS OPTIONS $use_notifications=esc_attr(get_option('use_notifications')); $always_notify_assignee=esc_attr(get_option('always_notify_assignee')); $always_notify_current_user=esc_attr(get_option('always_notify_current_user')); if($always_notify_current_user==true){ $curr_user_id=$current_user->ID; if(in_array($curr_user_id, $notifications_list)){ } else { array_push($notifications_list,$curr_user_id); } } if($always_notify_assignee==true){ $assignee_id=get_post_meta($post_id, 'assign_to'.$meta_marker, true); if(!empty($assignee_id)){ if(in_array($assignee_id, $notifications_list)){ } else { array_push($notifications_list,$assignee_id); } } } /// $notifications=implode(',',$notifications_list); if($notifications!=="" and $use_notifications==true){ $notify_to_list=get_users(array('include' =>$notifications)); if(count($notify_to_list)>0){ foreach($notify_to_list as $user){ $this->apmSendMail($user->user_email, $subject, $message) ; } } } } public function handle_newsletter_sending($post_id) { global $meta_marker; $email_template=$_POST['email_template'.$meta_marker]; $newsletter_special_subject=$_POST['newsletter_special_subject'.$meta_marker]; $contact_parent=$_POST['contact_parent'.$meta_marker]; $account_parent=$_POST['account_parent'.$meta_marker]; $lead_parent=$_POST['lead_parent'.$meta_marker]; $tpl_post=get_post($email_template); $to_post=false; $contact_post=intval($account_parent)>0 ? get_post($contact_parent) : false; $account_post=intval($account_parent)>0 ? get_post($account_parent) : false; $lead_post=intval($account_parent)>0 ? get_post($lead_parent) : false; if(intval($contact_parent)>0){ $to_post=get_post($contact_parent); } if(intval($account_parent)>0){ $to_post=get_post($account_parent); } if(intval($lead_parent)>0){ $to_post=get_post($lead_parent); } $to_email=get_post_meta($to_post->ID, 'email'.$meta_marker, true); if($to_post==false){ return; } $email_body=get_post_meta($email_template, 'email_body'.$meta_marker, true); $email_footer=get_post_meta($email_template, 'email_footer'.$meta_marker, true); $from_parent_email='none'; $from_parent_id=get_post_meta($email_template, 'from_parent'.$meta_marker, true); $user_from=get_users(array('include' =>$from_parent_id)); $from_parent_email=$user_from[0]->user_email; $from_display_name=$user_from[0]->display_name; $reply_to_email=get_post_meta($email_template, 'reply_to_email'.$meta_marker, true); $email_subject=get_post_meta($email_template, 'email_subject'.$meta_marker, true); if($newsletter_special_subject==''){ $subject=$email_subject; } else { $subject=$newsletter_special_subject; } $reply_to_name=get_post_meta($email_template, 'reply_to_name'.$meta_marker, true); $add_user_signature=get_post_meta($email_template, 'add_user_signature'.$meta_marker, true); $signature=''; if($add_user_signature==true){ //$signature='signature'; } //{{contact_gender}} {{contact_last_name}} {{contact_first_name}} {{contact_email}} | {{lead_gender}} {{lead_name}} {{lead_first_name}} {{lead_lastname}} {{lead_email}} | {{account_name}} $tags=array( 'contact_gender'=>intval($account_parent)>0 ? get_post_meta($contact_parent, 'contact_gender'.$meta_marker, true) : "", 'contact_lastname'=> intval($account_parent)>0 ? get_post_meta($contact_parent, 'contact_lastname'.$meta_marker, true) : "", 'contact_firstname'=> intval($account_parent)>0 ? get_post_meta($contact_parent, 'contact_firstname'.$meta_marker, true) : "", 'contact_email'=> intval($account_parent)>0 ? get_post_meta($contact_parent, 'email'.$meta_marker, true) : "", 'lead_gender'=> intval($lead_parent)>0 ? get_post_meta($lead_parent, 'contact_gender'.$meta_marker, true) : "", 'lead_lastname'=> intval($lead_parent)>0 ? get_post_meta($lead_parent, 'contact_lastname'.$meta_marker, true) : "", 'lead_firstname'=> intval($lead_parent)>0 ? get_post_meta($lead_parent, 'contact_firstname'.$meta_marker, true) : "", 'lead_email'=> intval($lead_parent)>0 ? get_post_meta($lead_parent, 'email'.$meta_marker, true) : "", 'account_name'=> $account_post!==false ? $account_post->post_title : "", ); foreach($tags as $key => $value){ $email_body=str_replace('{{'.$key.'}}', $value, $email_body); } $message=$email_body.$email_footer.$signature; $charset = get_settings('blog_charset'); $headers = 'From: '.$from_display_name.' <'.$from_parent_email.'> ' . "\r\n";//$from_parent_email;//$from_display_name $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-Type: text/html; charset=\"{$charset}\"\n"; return wp_mail($to_email, $subject, $message, $headers); //update_post_meta($post_id, 'newsletter_info', $email_template."-".$subject.'-'.$tpl_post->post_title.'****'.$email_body.' ///// '.$signature.' +++ '.$to_post->post_title.' email to : '.$to_email.' email from : '.$from_parent_id.$from_parent_email);//var_export($user_from,true) } public function handle_image_description($data,$post_id,$key) { if(strpos($data, '*****')>-1){ $data_arr=explode('*****',$data); foreach( $data_arr as $id ){// $this->handle_file_description_update($key,$id) ; } } } public function handle_file_description_update($key,$id) { $file_arr=array(); if( isset($_POST[$key.'_file_title_'.$id])){ $file_arr['file_title']=$_POST[$key.'_file_title_'.$id]; } else{ $file_arr['file_title']=''; } if( isset($_POST[$key.'_file_descr_'.$id])){ $file_arr['file_description']=$_POST[$key.'_file_descr_'.$id]; } else{ $file_arr['file_description']=''; } $my_post = array(); $my_post['ID'] = intval($id); $my_post['post_content'] = $file_arr['file_description']; $my_post['post_excerpt'] = $file_arr['file_title']; wp_update_post( $my_post ); } public function handle_image_removal($data,$post_id,$key) { global $meta_marker; $data_arr=explode('*****',$data); $new_data_arr=array(); foreach( $data_arr as $id ){// if( $id !== $_POST[$key.'_remove_file'] and intval($id) !== intval($_POST[$key.'_remove_file_'.$id])){ $new_data_arr[]=$id; } } $data=join('*****',$new_data_arr); update_post_meta($post_id, $key.$meta_marker, $data); } /** * Sends email * @param string $to * @param string $subject * @param string $message * @access public */ public function apmSendMail($to, $subject, $message) { $from_email=esc_attr(get_option('from_email')); $site_name = str_replace('"', "'", $this->site_name); $site_email = str_replace(array('<', '>'), array('', ''), $this->site_email); if(esc_attr(get_option('notification_from_email'))!==false){ $site_email=esc_attr(get_option('notification_from_email')); } if($from_email!==false && $from_email!==''){ $from="From: \"{$from_email}\" <{$site_email}>\n"; } else { $from="From: \"{$site_name}\" <{$site_email}>\n"; } $notification_subject=esc_attr(get_option('notification_subject')); $company_name=esc_attr(get_option('company_name')); if($notification_subject!==false and $notification_subject!==''){ $subject='['.$notification_subject.']'.$subject; } if($company_name!==false and $company_name!==''){ $subject='['.$company_name.']'.$subject; } $charset = get_settings('blog_charset'); $headers = $from; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-Type: text/html; charset=\"{$charset}\"\n"; //$subject = '[15GL]'.$subject; $message="".$subject."".$message.""; return wp_mail($to, $subject, $message, $headers); } } $Application_Maker=new Application_Maker(); }