/** * Register and enqueue admin-specific style sheet. * * * @return null */ public function enqueue_admin_stylescripts() { $screen = get_current_screen(); wp_enqueue_style($this->plugin_slug . '-admin-icon-styles', CFCORE_URL . 'assets/css/dashicon.css', array(), self::VERSION); if ($screen->base === 'post') { wp_enqueue_style($this->plugin_slug . '-modal-styles', CFCORE_URL . 'assets/css/modals.css', array(), self::VERSION); wp_enqueue_script($this->plugin_slug . '-shortcode-insert', CFCORE_URL . 'assets/js/shortcode-insert.min.js', array('jquery'), self::VERSION); //add_editor_style( CFCORE_URL . 'assets/css/caldera-form.css' ); add_editor_style(CFCORE_URL . 'assets/css/caldera-grid.css'); add_editor_style(CFCORE_URL . 'assets/css/dashicon.css'); // get fields $field_types = Caldera_Forms::get_field_types(); foreach ($field_types as $field_type) { //enqueue styles if (!empty($field_type['styles'])) { foreach ($field_type['styles'] as $style) { add_editor_style($style); } } } } if (!in_array($screen->base, $this->screen_prefix)) { return; } wp_enqueue_media(); wp_enqueue_script('wp-pointer'); wp_enqueue_style('wp-pointer'); wp_enqueue_script('password-strength-meter'); wp_enqueue_style($this->plugin_slug . '-admin-styles', CFCORE_URL . 'assets/css/admin.css', array(), self::VERSION); wp_enqueue_style($this->plugin_slug . '-modal-styles', CFCORE_URL . 'assets/css/modals.css', array(), self::VERSION); wp_enqueue_style($this->plugin_slug . '-field-styles', CFCORE_URL . 'assets/css/fields.min.css', array(), self::VERSION); /* standalone scripts wp_enqueue_script( $this->plugin_slug .'-admin-scripts', CFCORE_URL . 'assets/js/admin.js', array(), self::VERSION ); wp_enqueue_script( $this->plugin_slug .'-handlebars', CFCORE_URL . 'assets/js/handlebars.js', array(), self::VERSION ); wp_enqueue_script( $this->plugin_slug .'-baldrick-handlebars', CFCORE_URL . 'assets/js/handlebars.baldrick.js', array($this->plugin_slug .'-baldrick'), self::VERSION ); wp_enqueue_script( $this->plugin_slug .'-baldrick-modals', CFCORE_URL . 'assets/js/modals.baldrick.js', array($this->plugin_slug .'-baldrick'), self::VERSION ); wp_enqueue_script( $this->plugin_slug .'-baldrick', CFCORE_URL . 'assets/js/jquery.baldrick.js', array('jquery'), self::VERSION ); */ wp_enqueue_script($this->plugin_slug . '-baldrick', CFCORE_URL . 'assets/js/wp-baldrick-full.js', array('jquery'), self::VERSION); wp_enqueue_script($this->plugin_slug . '-admin-scripts', CFCORE_URL . 'assets/js/admin.min.js', array($this->plugin_slug . '-baldrick'), self::VERSION); if (!empty($_GET['edit'])) { /*// editor specific styles wp_enqueue_script( $this->plugin_slug .'-edit-fields', CFCORE_URL . 'assets/js/edit.js', array('jquery'), self::VERSION ); */ wp_enqueue_script($this->plugin_slug . '-edit-fields', CFCORE_URL . 'assets/js/fields.min.js', array('jquery'), self::VERSION); wp_enqueue_script($this->plugin_slug . '-edit-editor', CFCORE_URL . 'assets/js/edit.min.js', array('jquery'), self::VERSION); wp_enqueue_script('jquery-ui-users'); wp_enqueue_script('jquery-ui-sortable'); wp_enqueue_script('jquery-ui-droppable'); } if (!empty($_GET['edit-entry'])) { wp_enqueue_style('cf-grid-styles', CFCORE_URL . 'assets/css/caldera-grid.css', array(), self::VERSION); } // Load Field Types Styles & Scripts $field_types = apply_filters('caldera_forms_get_field_types', array()); // load panels $panel_extensions = apply_filters('caldera_forms_get_panel_extensions', array()); // load processors $form_processors = apply_filters('caldera_forms_get_form_processors', array()); // merge a list $merged_types = array_merge($field_types, $panel_extensions, $form_processors); foreach ($merged_types as $type => &$config) { // set context if (!empty($_GET['edit'])) { $context =& $config['setup']; } else { $context =& $config; } /// Styles if (!empty($context['styles'])) { foreach ($context['styles'] as $location => $styles) { // front only scripts if ($location === 'front') { continue; } foreach ((array) $styles as $style) { $key = $type . '-' . sanitize_key(basename($style)); // is url if (false === strpos($style, "/")) { // is reference wp_enqueue_style($style); } else { // is url - if ('//' != substr($style, 0, 2) && file_exists($style)) { // local file wp_enqueue_style($key, plugin_dir_url($style) . basename($style), array(), self::VERSION); } else { // most likely remote wp_enqueue_style($key, $style, array(), self::VERSION); } } } } } /// scripts if (!empty($context['scripts'])) { foreach ($context['scripts'] as $location => $scripts) { // front only scripts if ($location === 'front') { continue; } foreach ((array) $scripts as $script) { $key = $type . '-' . sanitize_key(basename($script)); // is url if (false === strpos($script, "/")) { // is reference wp_enqueue_script($script); } else { // is url - if ('//' != substr($script, 0, 2) && file_exists($script)) { // local file wp_enqueue_script($key, plugin_dir_url($script) . basename($script), array('jquery'), self::VERSION); } else { // most likely remote wp_enqueue_script($key, $script, array('jquery'), self::VERSION); } } } } } } //} }
/** * Get The entries from a Caldera Form * * @since 1.0.0 * * @param string $form_id form ID * @param int $page. Optional. Page number for results. Default is 1 * @param int $perpage Optional. Results per page. Default is 1000 * @param array $get_fields Optional. Array of fields to get. Default is an empty array, which returns all fields. * * @return array entries returned */ public static function get_cf_entries($form_id, $page = 1, $perpage = 1000, $get_fields = array()) { if (!class_exists('\\Caldera_Forms')) { return; } $form = \Caldera_Forms::get_form($form_id); if (isset($form['ID'])) { $form_id = $form['ID']; } else { return; } global $wpdb; $field_labels = array(); $backup_labels = array(); $selects = array(); // get all fieldtype $field_types = \Caldera_Forms::get_field_types(); $fields = array(); if (!empty($form['fields'])) { foreach ($form['fields'] as $fid => $field) { $fields[$field['slug']] = $field; $selects[] = "'" . $field['slug'] . "'"; if (empty($get_fields) || in_array($field['ID'], $get_fields)) { $field_labels[$field['slug']] = $field['label']; } $has_vars = array(); if (!empty($form['variables']['types'])) { $has_vars = $form['variables']['types']; } } } if (empty($field_labels)) { $field_labels = $backup_labels; } $data = array(); $filter = null; $status = 'active'; $data['active'] = (int) $wpdb->get_var($wpdb->prepare("SELECT COUNT(`id`) AS `total` FROM `" . $wpdb->prefix . "cf_form_entries` WHERE `form_id` = %s AND `status` = 'active';", $form_id)); // set current total $data['total'] = $data['active']; if (!empty($perpage)) { $data['pages'] = ceil($data['total'] / $perpage); } else { $data['pages'] = 1; } if (!empty($page)) { $page = abs($page); if ($page > $data['pages']) { $page = $data['pages']; } } $data['current_page'] = $page; $gmt_offset = get_option('gmt_offset'); if ($data['total'] > 0) { $data['form'] = $form_id; $data['label'] = $field_labels; $offset = ($page - 1) * $perpage; $limit = null; if (!empty($perpage)) { $limit = "LIMIT " . $offset . ',' . $perpage; } $rawdata = $wpdb->get_results($wpdb->prepare("\n\t\t\tSELECT\n\t\t\t\t`id`,\n\t\t\t\t`form_id`\n\t\t\tFROM `" . $wpdb->prefix . "cf_form_entries`\n\n\t\t\tWHERE `form_id` = %s AND `status` = %s ORDER BY `datestamp` DESC " . $limit . ";", $form_id, $status)); if (!empty($rawdata)) { $ids = array(); foreach ($rawdata as $row) { $ids[] = $row->id; } $rawdata = $wpdb->get_results("\n\t\t\t\tSELECT\n\t\t\t\t\t`entry`.`id` as `_entryid`,\n\t\t\t\t\t`entry`.`form_id` AS `_form_id`,\n\t\t\t\t\t`entry`.`datestamp` AS `_date_submitted`,\n\t\t\t\t\t`entry`.`user_id` AS `_user_id`,\n\t\t\t\t\t`value`.*\n\n\t\t\t\tFROM `" . $wpdb->prefix . "cf_form_entries` AS `entry`\n\t\t\t\tLEFT JOIN `" . $wpdb->prefix . "cf_form_entry_values` AS `value` ON (`entry`.`id` = `value`.`entry_id`)\n\n\t\t\t\tWHERE `entry`.`id` IN (" . implode(',', $ids) . ")\n\t\t\t\t" . $filter . "\n\t\t\t\tORDER BY `entry`.`datestamp` DESC;"); $data['entry'] = array(); $dateformat = get_option('date_format'); $timeformat = get_option('time_format'); foreach ($rawdata as $row) { if (!empty($row->_user_id)) { $user = get_userdata($row->_user_id); if (!empty($user)) { $data['entry']['E' . $row->_entryid]['user']['ID'] = $user->ID; $data['entry']['E' . $row->_entryid]['user']['name'] = $user->data->display_name; $data['entry']['E' . $row->_entryid]['user']['email'] = $user->data->user_email; $data['entry']['E' . $row->_entryid]['user']['avatar'] = get_avatar($user->ID, 64); } } $data['entry']['E' . $row->_entryid]['_entry_id'] = $row->_entryid; $data['entry']['E' . $row->_entryid]['_date'] = date_i18n($dateformat . ' ' . $timeformat, get_date_from_gmt($row->_date_submitted, 'U')); // setup default data array if (!isset($data['entry']['E' . $row->_entryid]['data'])) { if (isset($field_labels)) { foreach ($field_labels as $slug => $label) { // setup labels ordering $data['entry']['E' . $row->_entryid]['data'][$slug] = null; } } } if (!empty($field_labels[$row->slug])) { $label = $field_labels[$row->slug]; // check view handler $field = $fields[$row->slug]; // filter the field to get field data $field = apply_filters('caldera_forms_render_get_field', $field, $form); $field = apply_filters('caldera_forms_render_get_field_type-' . $field['type'], $field, $form); $field = apply_filters('caldera_forms_render_get_field_slug-' . $field['slug'], $field, $form); // maybe json? $is_json = json_decode($row->value, ARRAY_A); if (!empty($is_json)) { $row->value = $is_json; } if (is_string($row->value)) { $row->value = esc_html(stripslashes_deep($row->value)); } else { $row->value = stripslashes_deep(\Caldera_Forms_Sanitize::sanitize($row->value)); } $row->value = apply_filters('caldera_forms_view_field_' . $field['type'], $row->value, $field, $form); if (isset($data['entry']['E' . $row->_entryid]['data'][$row->slug])) { // array based - add another entry if (!is_array($data['entry']['E' . $row->_entryid]['data'][$row->slug])) { $tmp = $data['entry']['E' . $row->_entryid]['data'][$row->slug]; $data['entry']['E' . $row->_entryid]['data'][$row->slug] = array($tmp); } $data['entry']['E' . $row->_entryid]['data'][$row->slug][] = $row->value; } else { $data['entry']['E' . $row->_entryid]['data'][$row->slug] = $row->value; } } if (!empty($form['variables']['types'])) { foreach ($form['variables']['types'] as $var_key => $var_type) { if ($var_type == 'entryitem') { $data['label'][$form['variables']['keys'][$var_key]] = ucwords(str_replace('_', ' ', $form['variables']['keys'][$var_key])); $data['entry']['E' . $row->_entryid]['data'][$form['variables']['keys'][$var_key]] = \Caldera_Forms::do_magic_tags($form['variables']['values'][$var_key], $row->_entryid); } } } } } } return $data; }