public function getCustomField($get, $post)
 {
     $popup_close = 'false';
     $fm = CRED_Loader::get('MODEL/Fields');
     $fields = $fm->getTypesDefaultFields(true);
     if (isset($post['field']) && is_array($post['field'])) {
         $fm = CRED_Loader::get('MODEL/Fields');
         $fm->setCustomField($post['field']);
         $popup_close = 'true';
     }
     if (isset($get['field_name'])) {
         $field_name = $get['field_name'];
         $post_type = isset($get['post_type']) ? $get['post_type'] : 'post';
         if (isset($get['_reset_']) && '1' == $get['_reset_']) {
             $fm->ignoreCustomFields($post_type, array($field_name), 'reset');
             $popup_close = 'true';
             $data = array();
             $field_type = '';
             //__('Not Set','wp-cred');
         } else {
             $data = $fm->getCustomField($post_type, $field_name);
             if (isset($get['field'])) {
                 $field_type = $get['field'];
                 if (isset($data['type']) && $data['type'] != $field_type) {
                     $data = array();
                 }
             } else {
                 $field_type = isset($data['type']) ? $data['type'] : 'textfield';
             }
         }
         echo CRED_Loader::renderTemplate('custom-field-setup', array('field' => $fields[$field_type], 'data' => $data, 'popup_close' => $popup_close, 'field_name' => $field_name, 'post_type' => $post_type, 'url' => cred_route('/Generic_Fields/getCustomField?post_type=' . $post_type . '&field_name=' . $field_name), 'fields' => $fields));
     }
     die;
 }
 /**
  * method forms the data output style 
  * 
  */
 function display_rows()
 {
     $path = admin_url('admin.php') . '?page=CRED_Fields';
     $setfieldpath = cred_route('/Generic_Fields/getCustomField');
     $editfieldpath = cred_route('/Generic_Fields/getCustomField');
     $removefieldpath = cred_route('/Generic_Fields/removeCustomField');
     //Get the records registered in the prepare_items method
     $records = $this->items;
     $cred_fields = CRED_Loader::get('MODEL/Fields')->getCustomFields($this->_post_type);
     $default_types = CRED_Loader::get('MODEL/Fields')->getTypesDefaultFields(true);
     //Get the columns registered in the get_columns and get_sortable_columns methods
     list($columns, $hidden) = $this->get_column_info();
     //Loop for each record
     if (empty($records)) {
         return false;
     }
     foreach ($records as $rec) {
         //Open the line
         $field_id = $rec;
         $ignore = false;
         $credfieldtype = __('Not Set', 'wp-cred');
         $credfieldname = __('Not Set', 'wp-cred');
         if (isset($cred_fields[$rec])) {
             $credfieldtype = $cred_fields[$rec]['type'];
             $credfieldname = isset($default_types[$cred_fields[$rec]['type']]) ? $default_types[$cred_fields[$rec]['type']]['title'] : $credfieldname;
             if (isset($cred_fields[$rec]['_cred_ignore'])) {
                 $ignore = true;
             }
         }
         //if ($ignore)
         //  echo '<tr id="'.$field_id.'" class="cred-ignore-field">';
         //else
         echo '<tr id="' . $field_id . '">';
         //$checkbox_id =  "checkbox_" . $field_id;
         //$checkbox = "<input type='checkbox' name='checked[]' value='" . $field_id . "' id='" . $checkbox_id . "' /><label class='screen-reader-text' for='" . $checkbox_id . "' >" . __('Select') . " " . $rec . "</label>";
         /*$ignorecheckbox_id =  "ignorecheckbox_" . $field_id;
                     $unignorecheckbox_id =  "unignorecheckbox_" . $ignorecheckbox_id;
                     if ($ignore)
                         $ignorecheckbox = "<input checked='checked' type='checkbox' name='ignorechecked[]' value='" . $field_id . "' id='" . $ignorecheckbox_id . "' /><label style='margin-left:10px;' for='" . $ignorecheckbox_id . "' >" . __('Not include in Scaffold','wp-cred') . "</label>";
                     else
                         $ignorecheckbox = "<input type='checkbox' name='ignorechecked[]' value='" . $field_id . "' id='" . $ignorecheckbox_id . "' /><label style='margin-left:10px;' for='" . $ignorecheckbox_id . "' >" . __('Not include in Scaffold','wp-cred') . "</label>";
                     
                     $unignorecheckbox = "<input style='display:none;' type='checkbox' name='unignorechecked[]' value='" . $field_id . "' id='" . $unignorecheckbox_id . "' />";
                     $resetcheckbox_id =  "resetcheckbox_" . $field_id;
                     $resetcheckbox = "<input type='checkbox' name='resetchecked[]' value='" . $field_id . "' id='" . $resetcheckbox_id . "' /><label style='margin-left:10px;' for='" . $resetcheckbox_id . "' >" . __('Reset CRED settings','wp-cred') . "</label>";
         */
         foreach ($columns as $column_name => $column_display_name) {
             //Style attributes for each col
             $class = "class='{$column_name} column-{$column_name}'";
             $style = "";
             if (in_array($column_name, $hidden)) {
                 $style = ' style="display:none;"';
             }
             $attributes = $class . $style;
             //Display the cell
             switch ($column_name) {
                 /*case "cb":
                   echo "<th scope='row' class='check-column'>$checkbox</th>";
                   break;*/
                 case "col_field_name":
                     //$actions = array();
                     //$actions['edit'] = '<a class="submitedit thickbox" href="'.$editfieldpath.'&post_type='.$this->_post_type.'&field_name='.$rec.'&TB_iframe=true&width=600&height=450" title="'.__('Edit','wp-cred').'">'.__('Edit','wp-cred').'</a>';
                     echo '<td ' . $attributes . '><strong><a class="thickbox" href="' . $editfieldpath . '?post_type=' . $this->_post_type . '&field_name=' . $rec . '&TB_iframe=true&width=600&height=450" title="" title="' . __('Edit', 'wp-cred') . '">' . stripslashes($rec) . '</a>';
                     //echo $this->row_actions( $actions );
                     echo '</td>';
                     break;
                     /*case "col_post_type": 
                       echo '<td '.$attributes.'>'.$this->_post_type.'</td>'; 
                       break;*/
                 /*case "col_post_type": 
                   echo '<td '.$attributes.'>'.$this->_post_type.'</td>'; 
                   break;*/
                 case "col_cred_type":
                     echo '<td ' . $attributes . '><span class="cred-field-type" style="margin-right:15px">' . $credfieldname . '</span></td>';
                     break;
                 case "col_actions":
                     $actions = array('<a style="margin-right:10px" class="cred-field-actions _cred-field-set thickbox" href="' . $setfieldpath . '?post_type=' . $this->_post_type . '&field_name=' . $rec . '&TB_iframe=true&width=600&height=450" title="' . __('Set field type', 'wp-cred') . '">' . __('Add', 'wp-cred') . '</a>', '<a style="margin-right:10px" class="cred-field-actions _cred-field-edit thickbox" href="' . $editfieldpath . '?post_type=' . $this->_post_type . '&field_name=' . $rec . '&TB_iframe=true&width=600&height=450" title="' . __('Edit field settings', 'wp-cred') . '">' . __('Edit', 'wp-cred') . '</a>', '<a style="margin-right:10px" class="cred-field-actions _cred-field-remove" href="' . $removefieldpath . '?post_type=' . $this->_post_type . '&field_name=' . $rec . '" title="' . __('Remove this field as a CRED field type', 'wp-cred') . '">' . __('Remove', 'wp-cred') . '</a>');
                     $act_out = implode('', $actions);
                     //.'<br />'.$unignorecheckbox.$ignorecheckbox.'<br />'.$resetcheckbox;
                     echo '<td ' . $attributes . '>' . $act_out . '</td>';
                     break;
             }
         }
         echo '</tr>';
     }
 }
Exemple #3
0
 public static function addFormsButton($context, $text_area = 'textarea#content')
 {
     global $wp_version, $post;
     //static $add_only_once=0;
     if (!isset($post) || empty($post)) {
         return '';
     }
     if ($post->post_type == CRED_FORMS_CUSTOM_POST_NAME) {
         // WP 3.3 changes ($context arg is actually a editor ID now)
         if (version_compare($wp_version, '3.1.4', '>') && !empty($context)) {
             $text_area = $context;
         }
         $addon_buttons = array();
         $shortcode_but = '';
         $shortcode_but = CRED_Loader::renderTemplate('insert-field-shortcode-button', array('help' => self::$help, 'help_target' => self::$help_link_target));
         $shortcode2_but = '';
         $fm = CRED_Loader::get('MODEL/Fields');
         $shortcode2_but = CRED_Loader::renderTemplate('insert-generic-field-shortcode-button', array('gfields' => $fm->getTypesDefaultFields(), 'url' => cred_route('/Generic_Fields/getField'), 'help' => self::$help, 'help_target' => self::$help_link_target));
         $forms_model = CRED_Loader::get('MODEL/Forms');
         $settings = $forms_model->getFormCustomField($post->ID, 'form_settings');
         $scaffold_but = '';
         $scaffold_but = CRED_Loader::renderTemplate('scaffold-button', array('include_captcha_scaffold' => isset($settings['include_captcha_scaffold']) ? $settings['include_captcha_scaffold'] : false, 'include_wpml_scaffold' => isset($settings['include_wpml_scaffold']) ? $settings['include_wpml_scaffold'] : false, 'help' => self::$help, 'help_target' => self::$help_link_target));
         $preview_but = '';
         $preview_but = CRED_Loader::renderTemplate('preview-form-button');
         //$syntax_highlight_but='';
         //$syntax_highlight_but = CRED_Loader::renderTemplate('syntax-highlight-button');
         //$addon_buttons[] = $syntax_highlight_but;
         $addon_buttons[] = $scaffold_but;
         $addon_buttons[] = $shortcode_but;
         $addon_buttons[] = $shortcode2_but;
         $addon_buttons[] = $preview_but;
         $addon_buttons = implode('&nbsp;', $addon_buttons);
         $out = $addon_buttons;
         // WP 3.3 changes
         if (version_compare($wp_version, '3.1.4', '>')) {
             echo $out;
         } else {
             return $context . $out;
         }
     } else {
         if (is_string($context) && 'content' != $context) {
             $out = '';
             //self::addCREDButton('', $context);
             // WP 3.3 changes
             if (version_compare($wp_version, '3.1.4', '>')) {
                 echo $out;
                 return;
             } else {
                 return $context . $out;
             }
         }
         $fm = CRED_Loader::get('MODEL/Forms');
         $forms = $fm->getFormsForTable(0, -1);
         // WP 3.3 changes ($context arg is actually a editor ID now)
         if (version_compare($wp_version, '3.1.4', '>') && !empty($context)) {
             $text_area = $context;
         }
         $addon_buttons = array();
         $shortcode_but = '';
         $shortcode_but = CRED_Loader::renderTemplate('insert-form-shortcode-button', array('forms' => $forms, 'help' => self::$help, 'help_target' => self::$help_link_target));
         $addon_buttons[] = $shortcode_but;
         $addon_buttons = implode('&nbsp;', $addon_buttons);
         $out = $addon_buttons;
         // WP 3.3 changes
         if (version_compare($wp_version, '3.1.4', '>')) {
             echo $out;
         } else {
             return $context . $out;
         }
     }
 }
 /**
  * method forms the data output style 
  * 
  */
 function display_rows()
 {
     $path = admin_url('admin.php') . '?page=CRED_Forms';
     $editpath = admin_url('post.php') . '?action=edit';
     $exportpath = cred_route('/Forms/exportForm');
     //Get the records registered in the prepare_items method
     $records = $this->items;
     //Get the columns registered in the get_columns and get_sortable_columns methods
     list($columns, $hidden) = $this->get_column_info();
     //Loop for each record
     if (empty($records)) {
         return false;
     }
     foreach ($records as $rec) {
         $settings = isset($rec->meta) ? maybe_unserialize($rec->meta) : false;
         //Open the line
         echo '<tr id="record_' . $rec->ID . '">';
         $checkbox_id = "checkbox_" . $rec->ID;
         $checkbox = "<input type='checkbox' name='checked[]' value='" . $rec->ID . "' id='" . $checkbox_id . "' /><label class='screen-reader-text' for='" . $checkbox_id . "' >" . __('Select') . " " . $rec->post_title . "</label>";
         foreach ($columns as $column_name => $column_display_name) {
             //Style attributes for each col
             $class = "class='{$column_name} column-{$column_name}'";
             $style = "";
             if (in_array($column_name, $hidden)) {
                 $style = ' style="display:none;"';
             }
             $attributes = $class . $style;
             //Display the cell
             switch ($column_name) {
                 case "cb":
                     echo "<th scope='row' class='check-column'>{$checkbox}</th>";
                     break;
                     /*case "col_form_id": 
                                         $editlink = $editpath."&post=$rec->ID";
                                         echo '<td '.$attributes.'><strong><a href="'.$editlink.'" title="Edit">'.stripslashes($rec->ID).'</a></strong>';
                     		echo '</td>';
                                         break;*/
                 /*case "col_form_id": 
                                     $editlink = $editpath."&post=$rec->ID";
                                     echo '<td '.$attributes.'><strong><a href="'.$editlink.'" title="Edit">'.stripslashes($rec->ID).'</a></strong>';
                 		echo '</td>';
                                     break;*/
                 case "col_form_name":
                     $editlink = $editpath . "&post={$rec->ID}";
                     $exportlink = $exportpath . "?form={$rec->ID}&_wpnonce=" . wp_create_nonce('cred-export-' . $rec->ID);
                     $onclick_delete = "if(confirm('" . esc_js(sprintf(__("Are you sure that you want to delete this form '%s'?\n\n Click [Cancel] to stop, [OK] to delete.", 'wp-cred'), $rec->post_title)) . "' ) ) { return true;}return false;";
                     $onclick_clone = "var cred_form_title=prompt('" . __('Title of New Form ', 'wp-cred') . "','" . $rec->post_title . ' Copy' . "'); if (cred_form_title) {this.href+='&cred_form_title='+encodeURI(cred_form_title); return true;} else return false;";
                     $actions = array();
                     $actions['edit'] = '<a class="submitedit" href="' . $editlink . '" title="' . __('Edit', 'wp-cred') . '">' . __('Edit', 'wp-cred') . '</a>';
                     $actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url($path . "&action=delete&amp;id={$rec->ID}", 'delete-form_' . $rec->ID) . "' onclick=\"" . $onclick_delete . "\">" . __('Delete', 'wp-cred') . "</a>";
                     $actions['clone'] = "<a class='submitclone' href='" . wp_nonce_url($path . "&action=clone&amp;id={$rec->ID}", 'clone-form_' . $rec->ID) . "' onclick=\"" . $onclick_clone . "\">" . __('Clone', 'wp-cred') . "</a>";
                     $actions['export'] = '<a class="submitexport" target="_blank" href="' . $exportlink . '" title="' . __('Export', 'wp-cred') . '">' . __('Export', 'wp-cred') . '</a>';
                     echo '<td ' . $attributes . '><strong><a href="' . $editlink . '" title="Edit">' . stripslashes($rec->post_title) . '</a>&nbsp;&nbsp;(ID:&nbsp;' . $rec->ID . ')</strong>';
                     echo $this->row_actions($actions);
                     echo '</td>';
                     break;
                 case "col_form_type":
                     if ($settings && !empty($settings->form_type)) {
                         $_form_type = stripslashes($settings->form_type);
                         if ($_form_type == 'new') {
                             echo '<td ' . $attributes . '>' . __('Create Content', 'wp-cred') . '</td>';
                         } else {
                             echo '<td ' . $attributes . '>' . __('Edit Content', 'wp-cred') . '</td>';
                         }
                     } else {
                         echo '<td ' . $attributes . '>' . __('Not Set', 'wp-cred') . '</td>';
                     }
                     break;
                 case "col_post_type":
                     if ($settings && !empty($settings->post_type)) {
                         echo '<td ' . $attributes . '>' . stripslashes($settings->post_type) . '</td>';
                     } else {
                         echo '<td ' . $attributes . '>' . __('Not Set', 'wp-cred') . '</td>';
                     }
                     break;
             }
         }
         echo '</tr>';
     }
 }
Exemple #5
0
                    alert('<?php 
_e('An error occurred please try again', 'wp-cred');
?>
');
                }
            });
            return false; //this is critical to stop the click event which will trigger a normal file download!
        });
        
        $('form#list').submit(function(event){
            var action=$('form#list select[name="action"]').val();
            if (action=='export-selected')
            {
                event.preventDefault();
                $.fileDownload('<?php 
echo cred_route('/Forms/exportSelected?ajax=1');
?>
',{
                    successCallback:function()
                    {//$('.cred_ajax_loader_small').hide();
                    overlay_loader.hide();},
                    beforeDownloadCallback:function()
                    {$('.cred_ajax_loader_small').show();
                    overlay_loader.show();},
                    failCallback:function()
                    {
                        //$('.cred_ajax_loader_small').hide();
                        overlay_loader.hide();
                        alert('<?php 
_e('An error occurred please try again', 'wp-cred');
?>