/**
  * Nonces exist in the $_POST array using the key named like this:
  * conroller_name + _nonce.  The nonce is always named "ajax_nonce".
  * WARNING: The response returned by the ajax-controllers *must* be wrapped in
  * some kind of HTML tag, otherwise you can't use jQuery('#target_id').html(x)
  * to write it.
  *
  * @param string $name of the method being called
  * @param mixed $args sent to that method
  */
 public function __call($name, $args)
 {
     if (!isset($this->controllers[$name])) {
         CCTM::log(sprintf(__('Invalid Ajax controller: %s', CCTM_TXTDOMAIN), "<em>{$name}</em>"), __FILE__, __LINE__);
         die(sprintf(__('Invalid Ajax controller: %s', CCTM_TXTDOMAIN), "<em>{$name}</em>"));
     }
     $nonce = CCTM::get_value($_REQUEST, $name . '_nonce');
     if (!wp_verify_nonce($nonce, 'ajax_nonce')) {
         CCTM::log(sprintf(__('Invalid nonce for %s', CCTM_TXTDOMAIN), "<em>{$name}</em>"), __FILE__, __LINE__);
         die(sprintf(__('Invalid nonce for %s', CCTM_TXTDOMAIN), "<em>{$name}</em>"));
     }
     include $this->controllers[$name];
     exit;
 }
 /**
  * Thickbox support
  *
  * @param array $fieldlist (optional)
  */
 public function admin_init($fieldlist = array())
 {
     wp_enqueue_script('media-upload');
     wp_enqueue_script('thickbox');
     wp_register_script('cctm_relation', CCTM_URL . '/js/relation.js', array('jquery', 'media-upload', 'thickbox'));
     wp_enqueue_script('cctm_relation');
     // Bit of a wormhole here: organize into fieldtypes, then load up the children's req's (req's fieldtype)
     $fieldtypes = array();
     foreach ($fieldlist as $f) {
         $metafields = CCTM::get_value(CCTM::$data['custom_field_defs'][$f], 'metafields');
         foreach ($metafields as $mf) {
             $type = CCTM::get_value(CCTM::$data['custom_field_defs'][$mf], 'type');
             $fieldtypes[$type][] = $mf;
         }
     }
     foreach ($fieldtypes as $ft => $list) {
         if ($FieldObj = CCTM::load_object($ft, 'fields')) {
             $FieldObj->admin_init($list);
         }
     }
 }
 /**
  * The preview data object is stored nextdoor in a neighboring option:
  */
 public static function import_from_preview()
 {
     $settings = get_option(CCTM::db_key_settings, array());
     $candidate = CCTM::get_value($settings, 'candidate');
     $new_data = CCTM::get_value($candidate, 'payload');
     // Clean up icon URLs: make them absolute again. See the ImportExport::export_to_desktop function
     // and issue 64:http://code.google.com/p/wordpress-custom-content-type-manager/issues/detail?id=64
     foreach ($new_data as $post_type => $def) {
         if (isset($new_data[$post_type]['menu_icon']) && !empty($new_data[$post_type]['menu_icon'])) {
             $new_data[$post_type]['menu_icon'] = self::make_img_path_abs($new_data[$post_type]['menu_icon']);
         }
     }
     update_option(CCTM::db_key, $new_data);
 }
    // same effect as adding a hidden field
    $FieldObj->set_props($field_data);
    // used for repopulating on errors
    // Any errors?
    if (!empty($FieldObj->errors)) {
        $data['msg'] = $FieldObj->format_errors();
    } else {
        // die(print_r($field_data,true));
        // Unset the old field if the name changed ($field_name is passed via $_GET)
        if ($field_name != $field_data['name']) {
            unset(self::$data['custom_field_defs'][$field_name]);
            // update database... but what if the new name is taken?
        }
        self::$data['custom_field_defs'][$field_data['name']] = $field_data;
        update_option(self::db_key, self::$data);
        $continue_editing = CCTM::get_value($_POST, 'continue_editing');
        unset($_POST);
        $data['msg'] = sprintf('<div class="updated"><p>%s</p></div>', sprintf(__('The %s custom field has been edited.', CCTM_TXTDOMAIN), '<em>' . $field_name . '</em>'));
        self::set_flash($data['msg']);
        if (!$continue_editing) {
            include CCTM_PATH . '/controllers/list_custom_fields.php';
            return;
        }
        $FieldObj->set_props($field_data);
    }
}
$data['icon'] = sprintf('<img src="%s" class="cctm-field-icon" id="cctm-field-icon-%s"/>', $FieldObj->get_icon(), $field_type);
$data['url'] = $FieldObj->get_url();
if (empty($FieldObj->label)) {
    $data['name'] = $FieldObj->get_name();
} else {
if (!defined('CCTM_PATH')) {
    exit('No direct script access allowed');
}
// See https://code.google.com/p/wordpress-summarize-posts/issues/detail?id=39
$post_type = CCTM::get_value($_POST, 'post_type', 'post');
$cap = 'edit_posts';
if (isset($GLOBALS['wp_post_types'][$post_type]->cap->edit_posts)) {
    $cap = $GLOBALS['wp_post_types'][$post_type]->cap->edit_posts;
}
if (!current_user_can($cap)) {
    die('<pre>You do not have permission to do that.</pre>');
}
require_once CCTM_PATH . '/includes/GetPostsQuery.php';
//print '<div>'. print_r($_POST, true).'</div>';
$post_id = CCTM::get_value($_POST, 'post_id');
$target_id = CCTM::get_value($_POST, 'target_id');
// Will be either the single or the multi, depending.
$tpl = '';
$tpl = CCTM::load_tpl('widgets/post_item.tpl');
// Just in case...
if (empty($tpl)) {
    print '<p>' . __('Formatting template not found!', CCTM_TXTDOMAIN) . '</p>';
    return;
}
$Q = new GetPostsQuery();
$post = $Q->get_post($post_id);
$post['edit_selected_post_label'] = __('Edit Selected Post', CCTM_TXTDOMAIN);
$post_type = $post['post_type'];
$post['post_icon'] = CCTM::get_thumbnail($post_id);
if ($post_type == 'attachment') {
    $post['edit_url'] = get_admin_url('', 'media.php') . "?attachment_id={$post_id}&action=edit";
Example #6
0
    /**
     * Note that the HTML in $option_html should match the JavaScript version of
     * the same HTML in js/dropdown.js (see the append_dropdown_option() function).
     * I couldn't think of a clean way to do this, but the fundamental problem is
     * that both PHP and JS need to draw the same HTML into this form:
     * PHP draws it when an existing definition is *edited*, whereas JS draws it
     * when you dynamically *create* new dropdown options.
     *
     * @param array   $def nested array of existing definition.
     * @return string
     */
    public function get_edit_field_definition($def)
    {
        // Standard
        $out = $this->format_standard_fields($def, false);
        $is_checked = '';
        $is_sql_checked = '';
        $readonly_str = ' readonly="readonly"';
        if (isset($def['use_key_values']) && $def['use_key_values']) {
            $is_checked = 'checked="checked"';
            $readonly_str = '';
        }
        if (isset($def['is_sql']) && $def['is_sql']) {
            $is_sql_checked = 'checked="checked"';
        }
        // Options
        $out .= '
			<div class="postbox">
				<div class="handlediv" title="Click to toggle"><br /></div>
				<h3 class="hndle"><span>' . __('Options', CCTM_TXTDOMAIN) . '</span></h3>
				<div class="inside">
					<table><tr><td width="600" style="vertical-align:top">';
        // Use Key => Value Pairs?  (if not, the simple usage is simple options)
        $out .= '
			<input type="hidden" name="use_key_values" value="0"/>
			<div class="' . self::wrapper_css_class . '" id="use_key_values_wrapper">
				 <label for="use_key_values" class="cctm_label cctm_checkbox_label" id="use_key_values_label">' . __('Distinct options/values?', CCTM_TXTDOMAIN) . '</label>
				 <br />
				 <input type="checkbox" name="use_key_values" class="cctm_checkbox" id="use_key_values" value="1" onclick="javascript:toggle_readonly();" ' . $is_checked . '/> <span>' . $this->descriptions['use_key_values'] . '</span>

			 	</div>';
        // OPTIONS
        $option_cnt = 0;
        if (isset($def['options'])) {
            $option_cnt = count($def['options']);
        }
        // using the parse function because this got too crazy with escaping single quotes
        $hash = array();
        $hash['option_cnt'] = $option_cnt;
        $hash['delete'] = __('Delete');
        $hash['options'] = __('Options', CCTM_TXTDOMAIN);
        $hash['values'] = __('Stored Values', CCTM_TXTDOMAIN);
        $hash['add_option'] = __('Add Option', CCTM_TXTDOMAIN);
        $hash['set_as_default'] = __('Set as Default', CCTM_TXTDOMAIN);
        $tpl = '
			<script type="text/javascript">
				jQuery(function() {
					jQuery( "#dropdown_options2" ).sortable();
					// jQuery( "#dropdown_options2" ).disableSelection();
				});			
			</script>
			<table id="dropdown_options">
				<thead>
				<td scope="col" id="sorter" class=""  style="">&nbsp;</td>	
				<td width="200"><label for="options" class="cctm_label cctm_select_label" id="cctm_label_options">[+options+]</label></td>
				<td width="200"><label for="options" class="cctm_label cctm_select_label" id="cctm_label_options">[+values+]</label></td>
				<td>
				 <span class="button" onclick="javascript:append_dropdown_option(\'dropdown_options\',\'[+delete+]\',\'[+set_as_default+]\',\'[+option_cnt+]\');">[+add_option+]</span>
				</td>
				</thead>
				<tbody id="dropdown_options2">';
        $out .= CCTM::parse($tpl, $hash);
        // this html should match up with the js html in dropdown.js
        $option_html = '
			<tr id="%s">
				<td><span class="ui-icon ui-icon-arrowthick-2-n-s"></span></td>
				<td><input type="text" name="options[]" id="option_%s" value="%s"/></td>
				<td><input type="text" name="values[]" id="value_%s" value="%s" class="possibly_gray"' . $readonly_str . '/></td>
				<td><span class="button" onclick="javascript:remove_html(\'%s\');">%s</span>
				<span class="button" onclick="javascript:set_as_default(\'%s\');">%s</span></td>
			</tr>';
        $opt_i = 0;
        // used to uniquely ID options.
        if (!empty($def['options']) && is_array($def['options'])) {
            $opt_cnt = count($def['options']);
            for ($i = 0; $i < $opt_cnt; $i++) {
                // just in case the array isn't set
                $option_txt = '';
                if (isset($def['options'][$i])) {
                    $option_txt = htmlspecialchars(trim($def['options'][$i]));
                }
                $value_txt = '';
                if (isset($def['values'][$i])) {
                    $value_txt = htmlspecialchars(trim($def['values'][$i]));
                }
                $option_css_id = 'cctm_dropdown_option' . $opt_i;
                $out .= sprintf($option_html, $option_css_id, $opt_i, $option_txt, $opt_i, $value_txt, $option_css_id, __('Delete'), $opt_i, __('Set as Default'));
                $opt_i = $opt_i + 1;
            }
        }
        $out .= '
			</tbody>
		</table>';
        // close id="dropdown_options"
        // Display as Radio Button or as Dropdown?
        $out .= '<div class="' . self::wrapper_css_class . '" id="display_type_wrapper">
				 <label class="cctm_label cctm_checkbox_label" id="display_type_label">' . __('How should the field display?', CCTM_TXTDOMAIN) . '</label>
				 <br />
				 <input type="radio" name="display_type" class="cctm_radio" id="display_type_dropdown" value="dropdown" ' . CCTM::is_radio_selected('dropdown', CCTM::get_value($this->props, 'display_type', 'dropdown')) . '/>
				 <label for="display_type_dropdown" class="cctm_label cctm_radio_label" id="display_type_dropdown_label">' . __('Dropdown', CCTM_TXTDOMAIN) . '</label><br />
				 <input type="radio" name="display_type" class="cctm_radio" id="display_type_radio" value="radio" ' . CCTM::is_radio_selected('radio', CCTM::get_value($this->props, 'display_type', 'dropdown')) . '/>
				 <label for="display_type_radio" class="cctm_label cctm_radio_label" id="display_type_radio_label">' . __('Radio Button', CCTM_TXTDOMAIN) . '</label><br />
			 	</div>';
        // Secondary Input options
        $out .= '</td><td style="vertical-align:top">
			<label class="cctm_label cctm_textarea_label" id="advanced_label">' . __('Alternate Input', CCTM_TXTDOMAIN) . '</label>
			<span>' . __('Use this input if you want to options in bulk. 
				Separate options and values using double-pipes "||" with the visible option on the left, the corresponding value
				to be stored on the right (if present).  You may also enter a valid MySQL query. This field overrides 
				other inputs!', CCTM_TXTDOMAIN) . '</span><br/>
			<textarea name="alternate_input" id="alternate_input" cols="50" rows="10">' . CCTM::get_value($def, 'alternate_input') . '</textarea>';
        // Execute as MySQL?
        $out .= '<div class="' . self::wrapper_css_class . '" id="is_sql_wrapper">
				<input type="hidden" name="is_sql" value="0"/>
				 <input type="checkbox" name="is_sql" class="cctm_checkbox" id="is_sql" value="1"' . $is_sql_checked . '/> 				 <label for="is_sql" class="cctm_label cctm_checkbox_label" id="is_sql_label">' . __('Execute as a MySQL query?', CCTM_TXTDOMAIN) . '</label> <span>' . __('Select up to 2 columns: the 1st column will be the visible label and the 2nd column (if present) will represent the value stored in the database.
				 	Use [+table_prefix+] instead of hard-coding your WordPress database table prefix.', CCTM_TXTDOMAIN) . '</span>
			 	</div>';
        $out .= '
					</td></tr></table>		
				</div><!-- /inside -->
			</div><!-- /postbox -->';
        // Validations / Required
        $out .= $this->format_validators($def, false);
        // Output Filter
        $out .= $this->format_available_output_filters($def);
        return $out;
    }
 add_filter('plugin_action_links', 'CCTM::add_plugin_settings_link', 10, 2);
 // Standardize Fields
 add_action('do_meta_boxes', 'StandardizedCustomFields::remove_default_custom_fields', 10, 3);
 add_action('add_meta_boxes', 'StandardizedCustomFields::create_meta_box');
 add_action('save_post', 'StandardizedCustomFields::save_custom_fields', 1, 2);
 //! TODO: register this action conditionally
 // Customize the page-attribute box for custom page hierarchies
 add_filter('wp_dropdown_pages', 'StandardizedCustomFields::customized_hierarchical_post_types', 100, 1);
 // FUTURE: Highlght which themes are CCTM-compatible (if any)
 // add_filter('theme_action_links', 'CCTM::highlight_cctm_compatible_themes');
 add_action('admin_notices', 'CCTM::print_warnings');
 // Used to modify the large post icon
 add_action('in_admin_header', 'StandardizedCustomFields::print_admin_header');
 // Handle Custom Columns: this is only relevant for the edit.php?post_type=xxxx pages (i.e. the list view)
 if (substr($_SERVER['SCRIPT_NAME'], strrpos($_SERVER['SCRIPT_NAME'], '/') + 1) == 'edit.php') {
     $post_type = CCTM::get_value($_GET, 'post_type');
     if (isset(CCTM::$data['post_type_defs'][$post_type]['cctm_custom_columns_enabled']) && CCTM::$data['post_type_defs'][$post_type]['cctm_custom_columns_enabled'] == 1 && isset(CCTM::$data['post_type_defs'][$post_type]['cctm_custom_columns']) && !empty(CCTM::$data['post_type_defs'][$post_type]['cctm_custom_columns'])) {
         require_once 'includes/CCTM_Columns.php';
         require_once 'includes/functions.php';
         CCTM::$Columns = new CCTM_Columns();
         CCTM::$Columns->post_type = $post_type;
         // Draw the column headers
         add_filter("manage_{$post_type}_posts_columns", array(CCTM::$Columns, $post_type));
         // Handle the data in each cell
         add_action('manage_posts_custom_column', array(CCTM::$Columns, 'populate_custom_column_data'));
         add_action('manage_pages_custom_column', array(CCTM::$Columns, 'populate_custom_column_data'));
         // Forces custom post types to sort correctly
         add_filter('posts_orderby', 'CCTM::order_posts');
         add_filter('posts_join', 'CCTM::posts_join');
     }
 }
 /**
  * Save the new Custom Fields values. If the content type is not active in the 
  * CCTM plugin or its custom fields are not being standardized, then this function 
  * effectively does nothing.
  *
  * WARNING: This function is also called when the wp_insert_post() is called, and
  * we don't want to step on its toes. We want this to kick in ONLY when a post 
  * is inserted via the WP manager. 
  * see http://code.google.com/p/wordpress-custom-content-type-manager/issues/detail?id=52
  * 
  * @param	integer	$post_id id of the post these custom fields are associated with
  * @param	object	$post  the post object
  */
 public static function save_custom_fields($post_id, $post)
 {
     // Bail if you're not in the admin editing a post
     if (!self::_is_existing_post() && !self::_is_new_post()) {
         return;
     }
     // Bail if this post-type is not active in the CCTM
     if (!isset(CCTM::$data['post_type_defs'][$post->post_type]['is_active']) || CCTM::$data['post_type_defs'][$post->post_type]['is_active'] == 0) {
         return;
     }
     // Bail if there are no custom fields defined in the CCTM
     if (empty(CCTM::$data['post_type_defs'][$post->post_type]['custom_fields'])) {
         return;
     }
     // See issue http://code.google.com/p/wordpress-custom-content-type-manager/issues/detail?id=80
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return $post_id;
     }
     // Use this to ensure you save custom fields only when saving from the edit/create post page
     $nonce = CCTM::get_value($_POST, '_cctm_nonce');
     if (!wp_verify_nonce($nonce, 'cctm_create_update_post')) {
         return;
     }
     if (!empty($_POST)) {
         $custom_fields = self::_get_custom_fields($post->post_type);
         $validation_errors = array();
         foreach ($custom_fields as $field_name) {
             if (!isset(CCTM::$data['custom_field_defs'][$field_name]['type'])) {
                 continue;
             }
             $field_type = CCTM::$data['custom_field_defs'][$field_name]['type'];
             if ($FieldObj = CCTM::load_object($field_type, 'fields')) {
                 $FieldObj->set_props(CCTM::$data['custom_field_defs'][$field_name]);
                 $value = $FieldObj->save_post_filter($_POST, $field_name);
                 CCTM::log("Saving field Type: {$field_type}  with value: {$value}", __FILE__, __LINE__);
                 // Custom fields can return a literal null if they don't save data to the db.
                 if ($value !== null) {
                     // Check for empty json arrays, e.g. [""], convert them to empty PHP array()
                     $value_copy = $value;
                     if ($FieldObj->is_repeatable) {
                         $value_copy = json_decode(stripslashes($value), true);
                         if (is_array($value_copy)) {
                             foreach ($value_copy as $k => $v) {
                                 if (empty($v)) {
                                     unset($value_copy[$k]);
                                 }
                             }
                         }
                     }
                     // We do some more work to ensure the database stays lean
                     if (is_array($value_copy) && empty($value_copy) && !CCTM::get_setting('save_empty_fields')) {
                         delete_post_meta($post_id, $field_name);
                     }
                     if (!is_array($value_copy) && !strlen(trim($value_copy)) && !CCTM::get_setting('save_empty_fields')) {
                         // Delete the row from wp_postmeta, or don't write it at all
                         delete_post_meta($post_id, $field_name);
                     } else {
                         update_post_meta($post_id, $field_name, $value);
                     }
                 }
             } else {
                 // error!  Can't include the field class.  WTF did you do?
             }
         }
         // Pass validation errors like this: fieldname => validator, e.g. myfield => required
         if (!empty($validation_errors)) {
             CCTM::log('Validation errors: ' . json_encode($validation_errors), __FILE__, __LINE__);
             CCTM::set_flash(json_encode($validation_errors));
         }
     }
 }
        $nonce = wp_create_nonce('cctm_download_definition');
        $save_me = CCTM_ImportExport::get_payload_from_data(CCTM::$data);
        $save_me = json_encode($save_me);
        $data['msg'] = sprintf('<div class="updated"><p>%s</p></div>', sprintf(__('Your Custom Content Type definition %s should begin downloading shortly.  If there is a problem downloading, you can copy the text below into a text editor and save it with a <code>.cctm.json</code> extension.', CCTM_TXTDOMAIN), '<strong>' . CCTM_ImportExport::get_download_title($sanitized['title']) . '</strong>'));
        $data['msg'] .= "<textarea rows='10' cols='100'>{$save_me}</textarea>";
        // Save the options: anything that's in the form is considered a valid "info" key.
        self::$data['export_info'] = $sanitized;
        update_option(self::db_key, self::$data);
        // Fire off a request to download the file:
        //$data['msg'] .= sprintf('<script type="text/javascript" src="%s"></script>', CCTM_URL.'/js/download_def.js');
        $data['msg'] .= sprintf('<script type="text/javascript">window.location="%s"</script>', CCTM_URL . '/ajax-controllers/download_def.php');
    } elseif ($_POST['export_type'] == 'to_library') {
        // Save the options: anything that's in the form is considered a valid "info" key.
        self::$data['export_info'] = $sanitized;
        update_option(self::db_key, self::$data);
        if (CCTM_ImportExport::export_to_local_webserver()) {
            $data['msg'] = sprintf('<div class="updated"><p>%s</p></div>', __('Your Custom Content Type definition has been saved to your library. <a href="?page=cctm_tools&a=import_def">Click here</a> to view your library.', CCTM_TXTDOMAIN));
        } else {
            $data['msg'] = CCTM::format_errors();
        }
    }
}
// Populate the values
$data['title'] = CCTM::get_value(self::$data['export_info'], 'title');
$data['author'] = CCTM::get_value(self::$data['export_info'], 'author');
$data['url'] = CCTM::get_value(self::$data['export_info'], 'url');
$data['description'] = CCTM::get_value(self::$data['export_info'], 'description');
$data['template_url'] = CCTM::get_value(self::$data['export_info'], 'template_url');
$data['content'] = CCTM::load_view('export.php', $data);
print CCTM::load_view('templates/default.php', $data);
/*EOF*/
if (!current_user_can($cap)) {
    die('<pre>You do not have permission to do that.</pre>');
}
$fieldname = CCTM::get_value($_POST, 'fieldname');
$fieldtype = CCTM::get_value($_POST, 'fieldtype');
$type = '';
// set once we know if we've got a fieldname or a fieldtype
if (empty($fieldname) && empty($fieldtype)) {
    print '<p>' . __('fieldname or fieldtype required.', CCTM_TXTDOMAIN) . '</p>';
    return;
}
$def = CCTM::get_value(CCTM::$data['custom_field_defs'], $fieldname);
if (empty($def)) {
    $type = $fieldtype;
} else {
    $type = CCTM::get_value($def, 'type');
}
$search_parameters_str = '';
if (isset($_POST['search_parameters'])) {
    $search_parameters_str = $_POST['search_parameters'];
}
//print '<pre>'.$search_parameters_str. '</pre>'; return;
$existing_values = array();
parse_str($search_parameters_str, $existing_values);
//print '<pre>'.print_r($existing_values, true) . '</pre>';
require_once CCTM_PATH . '/includes/SummarizePosts.php';
require_once CCTM_PATH . '/includes/GetPostsQuery.php';
require_once CCTM_PATH . '/includes/GetPostsForm.php';
$Form = new GetPostsForm();
// What options should be displayed on the form that defines the search?
// Load up the config...
$raw_fieldname = CCTM::get_value($_POST, 'fieldname');
if (empty($raw_fieldname)) {
    print '<p>' . sprintf(__('Invalid fieldname: %s', CCTM_TXTDOMAIN), '<em>' . htmlspecialchars($raw_fieldname) . '</em>') . '</p>';
    return;
}
$fieldname = preg_replace('/^' . CCTM_FormElement::css_id_prefix . '/', '', $raw_fieldname);
$def = CCTM::get_value(CCTM::$data['custom_field_defs'], $fieldname);
if (empty($def)) {
    print '<p>' . sprintf(__('Invalid fieldname: %s', CCTM_TXTDOMAIN), '<em>' . htmlspecialchars($fieldname) . '</em>') . '</p>';
    return;
}
$instance = CCTM::get_value($_POST, 'instance');
// Will be either the single or the multi, depending.
$tpl = '';
// Use multi - tpls
if (CCTM::get_value($def, 'is_repeatable')) {
    $tpl = CCTM::load_tpl(array('fields/elements/' . $def['name'] . '.tpl', 'fields/elements/_' . $def['type'] . '_multi.tpl'));
} else {
    $tpl = CCTM::load_tpl(array('fields/elements/' . $def['name'] . '.tpl', 'fields/elements/_' . $def['type'] . '.tpl'));
}
// Just in case...
if (empty($tpl)) {
    print '<p>' . __('Formatting template not found!', CCTM_TXTDOMAIN) . '</p>';
    return;
}
$FieldObj = CCTM::load_object($def['type'], 'fields');
if (!$FieldObj) {
    return;
}
$def['id'] = $fieldname;
$def['i'] = $instance;
    /**
     * This should return (not print) form elements that handle all the controls required to define this
     * type of field.  The default properties correspond to this class's public variables,
     * e.g. name, label, etc. The form elements you create should have names that correspond
     * with the public $props variable. A populated array of $props will be stored alongside
     * the custom-field data for the containing post-type.
     *
     * @param unknown $def
     * @return string HTML input fields
     */
    public function get_edit_field_definition($def)
    {
        // Used to fetch the default value.
        require_once CCTM_PATH . '/includes/GetPostsQuery.php';
        // Standard
        $out = $this->format_standard_fields($def);
        // Options
        $Q = new GetPostsQuery();
        $out .= '
			<div class="postbox">
				<div class="handlediv" title="Click to toggle"><br /></div>
				<h3 class="hndle"><span>' . __('Options', CCTM_TXTDOMAIN) . '</span></h3>
				<div class="inside">';
        // Note fieldtype: used to set the default value on new fields
        $out .= '<input type="hidden" id="fieldtype" value="image" />';
        // Initialize / defaults
        $preview_html = '';
        $click_label = __('Choose Image');
        $label = __('Default Value', CCTM_TXTDOMAIN);
        $remove_label = __('Remove');
        // Handle the display of the default value
        if (!empty($def['default_value'])) {
            $hash = CCTM::get_thumbnail($def['default_value']);
            $fieldtpl = CCTM::load_tpl(array('fields/elements/' . $this->name . '.tpl', 'fields/elements/_media.tpl', 'fields/elements/_relation.tpl'));
            $preview_html = CCTM::parse($fieldtpl, $hash);
        }
        // Button Label
        $out .= '<div class="' . self::wrapper_css_class . '" id="button_label_wrapper">
			 		<label for="button_label" class="' . self::label_css_class . '">' . __('Button Label', CCTM_TXTDOMAIN) . '</label>
			 		<input type="text" name="button_label" class="' . self::css_class_prefix . 'text" id="button_label" value="' . htmlspecialchars($def['button_label']) . '"/>
			 		' . $this->get_translation('button_label') . '
			 	</div>';
        // Set Search Parameters
        $search_parameters_str = CCTM::get_value($def, 'search_parameters');
        parse_str($search_parameters_str, $args);
        $Q = new GetPostsQuery($args);
        $search_parameters_visible = $Q->get_args();
        $out .= '
			<div class="cctm_element_wrapper" id="search_parameters_wrapper">
				<label for="name" class="cctm_label cctm_text_label" id="search_parameters_label">' . __('Search Parameters', CCTM_TXTDOMAIN) . '</label>
				<span class="cctm_description">' . __('Define which posts are available for selection by narrowing your search parameters.', CCTM_TXTDOMAIN) . '</span>
				<br/>
				<span class="button" onclick="javascript:search_form_display(\'' . $def['name'] . '\',\'' . $def['type'] . '\');">' . __('Set Search Parameters', CCTM_TXTDOMAIN) . '</span>
				<div id="cctm_thickbox"></div>
				<span id="search_parameters_visible">' . $search_parameters_visible . '</span>
				<input type="hidden" id="search_parameters" name="search_parameters" value="' . CCTM::get_value($def, 'search_parameters') . '" />
				<br/>
			</div>';
        $out .= '</div><!-- /inside -->
			</div><!-- /postbox -->';
        // Validations / Required
        $out .= $this->format_validators($def, false);
        // Output Filter
        $out .= $this->format_available_output_filters($def);
        return $out;
    }
 /**
  * Sanitize data
  * @param array
  * @return array
  */
 public static function sanitize($posted_data)
 {
     $data = array();
     $data['id'] = CCTM::get_value($posted_data, 'id');
     $data['old_id'] = CCTM::get_value($posted_data, 'old_id');
     $data['title'] = CCTM::get_value($posted_data, 'title');
     $data['context'] = CCTM::get_value($posted_data, 'context');
     $data['priority'] = CCTM::get_value($posted_data, 'priority');
     $data['callback'] = CCTM::get_value($posted_data, 'callback');
     $data['callback_args'] = CCTM::get_value($posted_data, 'callback_args');
     // See https://code.google.com/p/wordpress-custom-content-type-manager/issues/detail?id=511
     $data['visibility_control'] = isset($posted_data['visibility_control']) ? $posted_data['visibility_control'] : '';
     $data['post_types'] = CCTM::get_value($posted_data, 'post_types', array());
     $data = CCTM::striptags_deep($data);
     $data = CCTM::stripslashes_deep($data);
     return $data;
 }
Activating a post type will cause it to show up in the WP menus and its custom
fields will be managed.
------------------------------------------------------------------------------*/
if (!defined('CCTM_PATH')) {
    exit('No direct script access allowed');
}
if (!current_user_can('administrator')) {
    exit('Admins only.');
}
require_once CCTM_PATH . '/includes/CCTM_PostTypeDef.php';
// Validate post type
if (!CCTM_PostTypeDef::is_existing_post_type($post_type)) {
    include CCTM_PATH . '/controllers/error.php';
    return;
}
$is_foreign = (int) CCTM::get_value($_GET, 'f');
if ($is_foreign) {
    self::$data['post_type_defs'][$post_type]['is_active'] = 2;
} else {
    self::$data['post_type_defs'][$post_type]['is_active'] = 1;
}
update_option(self::db_key, self::$data);
$msg = '
		<div class="updated">
			<p>' . sprintf(__('The %s post_type has been activated.', CCTM_TXTDOMAIN), '<em>' . $post_type . '</em>') . '</p>
		</div>';
self::set_flash($msg);
// Bonus: because the menus are drawn before we ever get here, we refresh the page via Javascript
// to ensure that active post types are added to menus. In other words, we sorta do a double-page load:
// WP has already sent headers, so we can't use PHP to redirect, so we use the browser to redirect.
$msg = '
         list($basename) = explode('.', $basename);
         $basename .= CCTM_ImportExport::extension;
     }
     if (!@move_uploaded_file($_FILES['cctm_settings_file']['tmp_name'], $dir . '/' . $basename)) {
         self::$errors['library'] = sprintf(__('We could not upload the definition file to your library. This may be due to permissions errors or some other server configuration.  Use FTP to upload your file to %', CCTM_TXTDOMAIN), "<code>{$dir}/{$basename}</code>");
     }
     // Any other errors?
     if (!empty(self::$errors)) {
         $data['msg'] = self::format_errors();
         self::set_flash($data['msg']);
     }
     // Refresh the list of files
     print '<script type="text/javascript">window.location.replace("?page=cctm_tools&a=import_def");</script>';
     return;
 } elseif (wp_verify_nonce($nonce, 'cctm_delete_defs')) {
     $defs = CCTM::get_value($_POST, 'defs', array());
     if (CCTM_ImportExport::delete_defs($defs)) {
         $data['msg'] = sprintf('<div class="updated"><p>%s</p></div>', __('Files have been removed from your library.', CCTM_TXTDOMAIN));
         CCTM::set_flash($data['msg']);
         print '<script type="text/javascript">window.location.replace("?page=cctm_tools&a=import_def");</script>';
         return;
     } else {
         $data['msg'] = CCTM::format_errors();
     }
 } elseif (wp_verify_nonce($nonce, 'cctm_activate_def')) {
     if (CCTM_ImportExport::activate_def($_POST['def'])) {
         $data['msg'] = sprintf('<div class="updated"><p>%s</p></div>', __('The definition was imported successfully!', CCTM_TXTDOMAIN));
         CCTM::set_flash($data['msg']);
         print '<script type="text/javascript">window.location.replace("?page=cctm_tools&a=import_def");</script>';
         return;
     } else {
Example #16
0
 /**
  * Custom joining on postmeta table for sorting on custom columns
  */
 public static function posts_join($join)
 {
     global $wpdb;
     // We don't want searches
     if (is_search()) {
         return $join;
     }
     $post_type = CCTM::get_value($_GET, 'post_type');
     if (empty($post_type)) {
         return $join;
     }
     if (isset(CCTM::$data['post_type_defs'][$post_type]['custom_orderby']) && !empty(CCTM::$data['post_type_defs'][$post_type]['custom_orderby'])) {
         $column = CCTM::$data['post_type_defs'][$post_type]['custom_orderby'];
         // Req'd to sort on custom column
         if (!in_array($column, CCTM::$reserved_field_names)) {
             $join .= $wpdb->prepare(" LEFT JOIN {$wpdb->postmeta} ON  {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = %s", $column);
         }
     }
     return $join;
 }
?>
</span>
			<!-- span style="color:red;"><?php 
_e('WARNING: improper key/value combinations can throw numerous errors!', CCTM_TXTDOMAIN);
?>
</span-->
		</div>

		<!-- register_meta_box_cb -->
		<div class="cctm_element_wrapper" id="custom_field_wrapper_register_meta_box_cb">			
			<label for="register_meta_box_cb" class="cctm_label cctm_text_label" id="cctm_label_register_meta_box_cb"><?php 
_e('Meta Box Callback', CCTM_TXTDOMAIN);
?>
</label>
			<input type="text" name="register_meta_box_cb" class="cctm_text" id="register_meta_box_cb" value="<?php 
print htmlspecialchars(CCTM::get_value($data['def'], 'register_meta_box_cb'));
?>
"/>
			<span class="cctm_description"><?php 
_e('Provide an optional callback function that will be called when setting up the meta boxes for the edit form.', CCTM_TXTDOMAIN);
?>
</span>
		</div>
		
		<!--!Can Export -->
		<div class="cctm_element_wrapper" id="custom_field_wrapper_can_export">
			<input type="checkbox" name="can_export" class="cctm_checkbox" id="can_export" value="1" <?php 
print CCTM::is_checked($data['def']['can_export']);
?>
 /> 
			<label for="can_export" class="cctm_label cctm_checkbox_label" id="cctm_label_can_export"><?php 
$data['content']:		Main content block
------------------------------------------------------------------------------*/
// CSS classes
$active = array();
$active['cctm'] = '';
$active['cctm_fields'] = '';
$active['cctm_metaboxes'] = '';
$active['cctm_settings'] = '';
$active['cctm_themes'] = '';
$active['cctm_tools'] = '';
$active['cctm_info'] = '';
$page = CCTM::get_value($_GET, 'page');
$active[$page] = ' cctm_active';
// active tab class
// for custom menu items, not registered via WP
$a = CCTM::get_value($_GET, 'a');
if ($a == 'info') {
    $active['cctm_info'] = ' cctm_active';
    $active['cctm'] = '';
}
// Default help page:
if (!isset($data['help']) || empty($data['help'])) {
    $data['help'] = 'http://code.google.com/p/wordpress-custom-content-type-manager/';
}
?>
<div class="wrap">

	<?php 
/*---------------- HEADER and TABS --------------------------- */
?>
	<div id="cctm_header">
    print '<p>' . __('Post Selector configuration file not found.', CCTM_TXTDOMAIN) . '</p>';
}
// This gets subsequent search data that gets passed when the user refines the search.
$args = array();
// Do not set defaults here! It causes any values set in the config/post_selector/ files
// to be ignored. See https://code.google.com/p/wordpress-custom-content-type-manager/issues/detail?id=537
//$args['orderby'] = 'ID';
//$args['order'] = 'ASC';
if (isset($_POST['search_parameters'])) {
    // e.g. fieldname=movie_clip&fieldtype=media&page_number=0&orderby=ID&order=ASC
    parse_str($_POST['search_parameters'], $args);
    //print '<pre>'.print_r($args,true).'</pre>'; exit;
    // Pass the "view" parameters to the view
    $d['page_number'] = CCTM::get_value($args, 'page_number', 0);
    $d['orderby'] = CCTM::get_value($args, 'orderby', 'ID');
    $d['order'] = CCTM::get_value($args, 'order', 'ASC');
    // Unsest these, otherwise the query will try to search them as custom field values.
    unset($args['page_number']);
    unset($args['fieldname']);
    unset($args['fieldtype']);
}
// Set search boundaries (i.e. the parameters used when nothing is specified)
// !TODO: put this configuration stuff into the /config/ files
// optionally get pages to exclude
if (isset($_POST['exclude'])) {
    CCTM::$post_selector['exclude'] = $_POST['exclude'];
}
$search_parameters_str = '';
// <-- read custom search parameters, if defined.
if (isset($def['search_parameters'])) {
    $search_parameters_str = $def['search_parameters'];
Example #20
0
		</div><!-- /inside -->
	</div><!-- /postbox -->

	<br />
	<input type="submit" class="button-primary" value="<?php 
_e('Save', CCTM_TXTDOMAIN);
?>
" />
	
	<input type="submit" class="button" onclick="javascript:set_continue_editing();" value="<?php 
_e('Save and Continue Editing', CCTM_TXTDOMAIN);
?>
" />

<?php 
if (CCTM::get_value($_GET, 'a') == 'edit_metabox') {
    ?>

	<a href="<?php 
    print get_admin_url(false, 'admin.php');
    ?>
?page=cctm&a=delete_metabox&id=<?php 
    print $data['id'];
    ?>
" title="<?php 
    _e('Delete');
    ?>
" class="button"><?php 
    _e('Delete');
    ?>
</a>
/*------------------------------------------------------------------------------
This adds a custom field row to the "Bulk Add" table. This handles 2 types of 
posting actions:
1. User selects a field type
2. User wants to automatically add fields based on a post_type and optional post-ids

Remember: the output here MUST be wrapped in HTML tags, otherwise jQuery's .html()
method will kack.
------------------------------------------------------------------------------*/
if (!defined('CCTM_PATH')) {
    exit('No direct script access allowed');
}
$desired_field_type = CCTM::get_value($_POST, 'field_type');
$post_type = CCTM::get_value($_POST, 'post_type');
$post_ids = CCTM::get_value($_POST, 'post_ids');
// Stuff we're using in our view...
$data = array();
$data['i'] = md5(uniqid());
// we just need a unique identifier for each row element
$data['name'] = '';
$data['label'] = '';
$data['type'] = '';
$data['field_types'] = '';
$data['name_class'] = '';
// 'cctm_validation_error';
// 1. User has specified a desired field type
if ($desired_field_type) {
    $elements = CCTM::get_available_helper_classes('fields');
    foreach ($elements as $field_type => $file) {
        if ($FieldObj = CCTM::load_object($field_type, 'fields')) {
<?php

/*------------------------------------------------------------------------------
Load up the validator and return the validator's options.

@param	string	validator
------------------------------------------------------------------------------*/
$validator = CCTM::get_value($_POST, 'validator');
$V = CCTM::load_object($validator, 'validators');
if ($V) {
    print $V->draw_options();
} else {
    print '<pre>' . __('Error loading validator.', CCTM_TXTDOMAIN) . '</pre>';
}
/*EOF*/
 /**
  * Everything when creating a new post type must be filtered here.
  *
  * Problems with:
  *  hierarchical
  *  rewrite_with_front
  *
  * This is janky... sorta doesn't work how it's supposed when combined with save_post_type_settings().
  *
  *
  * @param mixed   $raw unsanitized $_POST data
  * @return mixed filtered $_POST data (only white-listed are passed thru to output)
  */
 public static function sanitize_post_type_def($raw)
 {
     $sanitized = array();
     unset($raw['custom_content_type_mgr_create_new_content_type_nonce']);
     unset($raw['custom_content_type_mgr_edit_content_type_nonce']);
     $raw = CCTM::striptags_deep($raw);
     // WP always adds slashes: see http://kovshenin.com/archives/wordpress-and-magic-quotes/
     $raw = CCTM::stripslashes_deep($raw);
     // Handle unchecked checkboxes
     if (empty($raw['cctm_hierarchical_custom'])) {
         $sanitized['cctm_hierarchical_custom'] = '';
     }
     if (empty($raw['cctm_hierarchical_includes_drafts'])) {
         $sanitized['cctm_hierarchical_includes_drafts'] = '';
     }
     if (empty($raw['cctm_hierarchical_post_types'])) {
         $sanitized['cctm_hierarchical_post_types'] = array();
     }
     if (!isset($raw['cctm_custom_columns_enabled'])) {
         $sanitized['cctm_custom_columns_enabled'] = 0;
     }
     if (!isset($raw['cctm_enable_right_now'])) {
         $sanitized['cctm_enable_right_now'] = 0;
     }
     // This will be empty if no "supports" items are checked.
     if (!empty($raw['supports'])) {
         $sanitized['supports'] = $raw['supports'];
         unset($raw['supports']);
     } else {
         $sanitized['supports'] = array();
     }
     if (!empty($raw['taxonomies'])) {
         $sanitized['taxonomies'] = $raw['taxonomies'];
     } else {
         // do this so this will take precedence when you merge the existing array with the new one in the save_post_type_settings() function.
         $sanitized['taxonomies'] = array();
     }
     // You gotta unset arrays if you want the foreach thing below to work.
     unset($raw['taxonomies']);
     // Temporary thing... ????
     unset($sanitized['rewrite_slug']);
     // The main event
     // We grab everything except stuff that begins with '_', then override specific $keys as needed.
     foreach ($raw as $key => $value) {
         if (!preg_match('/^_.*/', $key)) {
             $sanitized[$key] = CCTM::get_value($raw, $key);
         }
     }
     // Specific overrides below:
     $sanitized['description'] = strip_tags($raw['description']);
     // post_type is the only required field
     $sanitized['post_type'] = CCTM::get_value($raw, 'post_type');
     $sanitized['post_type'] = strtolower($sanitized['post_type']);
     $sanitized['post_type'] = preg_replace('/[^a-z0-9_\\-]/', '_', $sanitized['post_type']);
     $sanitized['post_type'] = substr($sanitized['post_type'], 0, 20);
     // Our form passes integers and strings, but WP req's literal booleans,
     // so we do some type-casting here to ensure literal booleans.
     $sanitized['public'] = (bool) CCTM::get_value($raw, 'public');
     $sanitized['rewrite_with_front'] = (bool) CCTM::get_value($raw, 'rewrite_with_front');
     $sanitized['show_ui'] = (bool) CCTM::get_value($raw, 'show_ui');
     $sanitized['public'] = (bool) CCTM::get_value($raw, 'public');
     $sanitized['show_in_nav_menus'] = (bool) CCTM::get_value($raw, 'show_in_nav_menus');
     $sanitized['can_export'] = (bool) CCTM::get_value($raw, 'can_export');
     $sanitized['use_default_menu_icon'] = (bool) CCTM::get_value($raw, 'use_default_menu_icon');
     $sanitized['hierarchical'] = (bool) CCTM::get_value($raw, 'hierarchical');
     $sanitized['include_in_search'] = (bool) CCTM::get_value($raw, 'include_in_search');
     $sanitized['publicly_queryable'] = (bool) CCTM::get_value($raw, 'publicly_queryable');
     $sanitized['include_in_rss'] = (bool) CCTM::get_value($raw, 'include_in_rss');
     $sanitized['map_meta_cap'] = (bool) CCTM::get_value($raw, 'map_meta_cap');
     $sanitized['show_in_admin_bar'] = (bool) CCTM::get_value($raw, 'show_in_admin_bar');
     if (empty($sanitized['has_archive'])) {
         $sanitized['has_archive'] = false;
     } else {
         $sanitized['has_archive'] = true;
     }
     // *facepalm*... Special handling req'd here for menu_position because 0
     // is handled differently than a literal null.
     if ((int) CCTM::get_value($raw, 'menu_position')) {
         $sanitized['menu_position'] = (int) CCTM::get_value($raw, 'menu_position', null);
     } else {
         $sanitized['menu_position'] = null;
     }
     $sanitized['show_in_menu'] = CCTM::get_value($raw, 'show_in_menu');
     $sanitized['cctm_show_in_menu'] = CCTM::get_value($raw, 'cctm_show_in_menu');
     // menu_icon... the user will lose any custom Menu Icon URL if they save with this checked!
     // TODO: let this value persist.
     if ($sanitized['use_default_menu_icon']) {
         unset($sanitized['menu_icon']);
         // === null;
     }
     if (empty($sanitized['query_var'])) {
         $sanitized['query_var'] = false;
     }
     // Cleaning up the labels
     if (empty($sanitized['label'])) {
         $sanitized['label'] = ucfirst($sanitized['post_type']);
     }
     if (empty($sanitized['labels']['singular_name'])) {
         $sanitized['labels']['singular_name'] = ucfirst($sanitized['post_type']);
     }
     if (empty($sanitized['labels']['add_new'])) {
         $sanitized['labels']['add_new'] = __('Add New');
     }
     if (empty($sanitized['labels']['add_new_item'])) {
         $sanitized['labels']['add_new_item'] = __('Add New') . ' ' . ucfirst($sanitized['post_type']);
     }
     if (empty($sanitized['labels']['edit_item'])) {
         $sanitized['labels']['edit_item'] = __('Edit') . ' ' . ucfirst($sanitized['post_type']);
     }
     if (empty($sanitized['labels']['new_item'])) {
         $sanitized['labels']['new_item'] = __('New') . ' ' . ucfirst($sanitized['post_type']);
     }
     if (empty($sanitized['labels']['view_item'])) {
         $sanitized['labels']['view_item'] = __('View') . ' ' . ucfirst($sanitized['post_type']);
     }
     if (empty($sanitized['labels']['search_items'])) {
         $sanitized['labels']['search_items'] = __('Search') . ' ' . ucfirst($sanitized['labels']['menu_name']);
     }
     if (empty($sanitized['labels']['not_found'])) {
         $sanitized['labels']['not_found'] = sprintf(__('No %s found', CCTM_TXTDOMAIN), strtolower($raw['labels']['menu_name']));
     }
     if (empty($sanitized['labels']['not_found_in_trash'])) {
         $sanitized['labels']['not_found_in_trash'] = sprintf(__('No %s found in trash', CCTM_TXTDOMAIN), strtolower($raw['labels']['menu_name']));
     }
     if (empty($sanitized['labels']['parent_item_colon'])) {
         $sanitized['labels']['parent_item_colon'] = __('Parent Page');
     }
     // Rewrites. TODO: make this work like the built-in post-type permalinks
     switch ($sanitized['permalink_action']) {
         case '/%postname%/':
             $sanitized['rewrite'] = true;
             break;
         case 'Custom':
             $sanitized['rewrite']['slug'] = $raw['rewrite_slug'];
             $sanitized['rewrite']['with_front'] = isset($raw['rewrite_with_front']) ? (bool) $raw['rewrite_with_front'] : false;
             break;
         case 'Off':
         default:
             $sanitized['rewrite'] = false;
     }
     return $sanitized;
 }
if (!current_user_can('manage_options')) {
    exit('Admins only.');
}
/*------------------------------------------------------------------------------
Independent controller that displays the contents of a CCTM definition file

Output is the HTML required to display and format the def file.
This needed to live in a separate file because I needed to completely control
the entire request: if it were handled by WP, headers() would be sent.
------------------------------------------------------------------------------*/
//@require_once( realpath('../../../../').'/wp-load.php' );
//include_once('../includes/constants.php');
//include_once(CCTM_PATH.'/includes/CCTM.php');
include_once CCTM_PATH . '/includes/CCTM_ImportExport.php';
// Make sure a file was specified
$filename = CCTM::get_value($_REQUEST, 'file');
if (empty($filename)) {
    print CCTM::format_error_msg(__('Definition file not specified.', CCTM_TXTDOMAIN));
    exit;
}
// Make sure the filename is legit
if (!CCTM_ImportExport::is_valid_basename($filename)) {
    print CCTM::format_error_msg(__('Invalid filename: the definition filename should not contain spaces and should use an extension of <code>.cctm.json</code>.', CCTM_TXTDOMAIN));
    exit;
}
// Load up this thing... errors will be thrown
$upload_dir = wp_upload_dir();
$dir = $upload_dir['basedir'] . '/' . CCTM::base_storage_dir . '/' . CCTM::def_dir . '/';
$data = CCTM_ImportExport::load_def_file($dir . $filename);
$data['filename'] = $filename;
// Bail if there were errors
<?php

if (!defined('CCTM_PATH')) {
    exit('No direct script access allowed');
}
if (!current_user_can('administrator')) {
    exit('Admins only.');
}
//------------------------------------------------------------------------------
/**
 * Show all available types of Custom Fields
 *
 */
$data = array();
$data['page_title'] = __('List Metaboxes', CCTM_TXTDOMAIN);
$data['help'] = 'http://code.google.com/p/wordpress-custom-content-type-manager/wiki/Metaboxes';
$data['msg'] = self::get_flash();
$data['menu'] = sprintf('<a href="' . get_admin_url(false, 'admin.php') . '?page=cctm_metaboxes&a=create_metabox" class="button">%s</a>', __('Create Metabox', CCTM_TXTDOMAIN));
$data['content'] = '';
$data['rows'] = '';
$rows = CCTM::get_value(CCTM::$data, 'metabox_defs', array());
foreach ($rows as $r) {
    $data['rows'] .= CCTM::load_view('tr_metabox.php', $r);
}
if (empty($rows)) {
    $data['msg'] = sprintf('<div class="updated"><p>%s</p></div>', __('There are no custom metaboxes defined. Click the button below to add a custom metabox.', CCTM_TXTDOMAIN));
}
$data['content'] .= CCTM::load_view('list_metaboxes.php', $data);
print CCTM::load_view('templates/default.php', $data);
/*EOF*/
    self::$data['settings']['delete_posts'] = (int) CCTM::get_value($_POST, 'delete_posts', 0);
    self::$data['settings']['delete_custom_fields'] = (int) CCTM::get_value($_POST, 'delete_custom_fields', 0);
    self::$data['settings']['add_custom_fields'] = (int) CCTM::get_value($_POST, 'add_custom_fields', 0);
    self::$data['settings']['show_custom_fields_menu'] = (int) CCTM::get_value($_POST, 'show_custom_fields_menu', 0);
    self::$data['settings']['show_settings_menu'] = (int) CCTM::get_value($_POST, 'show_settings_menu', 0);
    self::$data['settings']['show_foreign_post_types'] = (int) CCTM::get_value($_POST, 'show_foreign_post_types', 0);
    self::$data['settings']['cache_thumbnail_images'] = (int) CCTM::get_value($_POST, 'cache_thumbnail_images', 0);
    self::$data['settings']['save_empty_fields'] = (int) CCTM::get_value($_POST, 'save_empty_fields', 0);
    self::$data['settings']['summarizeposts_tinymce'] = (int) CCTM::get_value($_POST, 'summarizeposts_tinymce', 0);
    self::$data['settings']['custom_fields_tinymce'] = (int) CCTM::get_value($_POST, 'custom_fields_tinymce', 0);
    self::$data['settings']['pages_in_rss_feed'] = (int) CCTM::get_value($_POST, 'pages_in_rss_feed', 0);
    self::$data['settings']['enable_right_now'] = (int) CCTM::get_value($_POST, 'enable_right_now', 0);
    self::$data['settings']['hide_posts'] = (int) CCTM::get_value($_POST, 'hide_posts', 0);
    self::$data['settings']['hide_pages'] = (int) CCTM::get_value($_POST, 'hide_pages', 0);
    self::$data['settings']['hide_links'] = (int) CCTM::get_value($_POST, 'hide_links', 0);
    self::$data['settings']['hide_comments'] = (int) CCTM::get_value($_POST, 'hide_comments', 0);
    update_option(self::db_key, self::$data);
    $data['msg'] = '<div class="updated"><p>' . __('Settings have been updated.', CCTM_TXTDOMAIN) . '</p></div>';
    self::set_flash($data['msg']);
    print '<script type="text/javascript">window.location.replace("?page=cctm_settings");</script>';
    return;
}
// Use Defaults by default...
$data['settings'] = CCTM::$default_settings;
// list all checkboxes here
$checkboxes = array('delete_posts', 'delete_custom_fields', 'add_custom_fields', 'show_custom_fields_menu', 'show_settings_menu', 'show_foreign_post_types', 'cache_directory_scans', 'cache_thumbnail_images', 'save_empty_fields', 'summarizeposts_tinymce', 'custom_fields_tinymce', 'pages_in_rss_feed', 'enable_right_now', 'hide_posts', 'hide_pages', 'hide_links', 'hide_comments');
// this only works for checkboxes...
foreach ($checkboxes as $k) {
    if (self::get_setting($k)) {
        $data['settings'][$k] = ' checked="checked"';
    }
$data['page_title'] = sprintf(__('Change Field Type: %s', CCTM_TXTDOMAIN), $field_name);
$data['help'] = 'http://code.google.com/p/wordpress-custom-content-type-manager/wiki/ChangeFieldType';
$data['msg'] = '';
$data['menu'] = sprintf('<a href="' . get_admin_url(false, 'admin.php') . '?page=cctm_fields&a=list_custom_fields" title="%s" class="button">%s</a>', __('Cancel'), __('Cancel'));
$data['submit'] = __('Save', CCTM_TXTDOMAIN);
$data['content'] = '';
$data['action_name'] = 'custom_content_type_mgr_edit_custom_field';
$data['nonce_name'] = 'custom_content_type_mgr_edit_custom_field_nonce';
$nonce = self::get_value($_GET, '_wpnonce');
if (!wp_verify_nonce($nonce, 'cctm_change_field_type')) {
    die(__('Invalid request.', CCTM_TXTDOMAIN));
}
// Save if submitted...
if (!empty($_POST) && check_admin_referer($data['action_name'], $data['nonce_name'])) {
    $new_field_type = CCTM::get_value($_POST, 'new_field_type');
    $old_field_type = CCTM::get_value($_POST, 'old_field_type');
    if ($FieldObj = CCTM::load_object($new_field_type, 'fields')) {
        $field_type_str = $FieldObj->get_name();
        $field_type_url = $FieldObj->get_url();
        self::$data['custom_field_defs'][$field_name]['type'] = $new_field_type;
        update_option(self::db_key, self::$data);
        $data['msg'] = sprintf('<div class="updated"><p>%s</p></div>', sprintf(__('The %s custom field has been converted to a %s field.', CCTM_TXTDOMAIN), '<em>' . $field_name . '</em>', $field_type_str));
        self::set_flash($data['msg']);
        include CCTM_PATH . '/controllers/list_custom_fields.php';
        return;
    } else {
        die(__('There was a problem converting the field type.', CCTM_TXTDOMAIN));
    }
}
$field_type = self::$data['custom_field_defs'][$field_name]['type'];
$field_data = self::$data['custom_field_defs'][$field_name];
<?php

/*------------------------------------------------------------------------------
This is what drives the search forms that pop when you define a Summarize Posts 
Widget: Appearance --> Widgets --> (add a Summarize Posts Widget to a widget area)
--> Click the "Define Search" button

Remember: the output here MUST be wrapped in HTML tags, otherwise jQuery's .html()
method will kack.
------------------------------------------------------------------------------*/
require_once CCTM_PATH . '/includes/SummarizePosts.php';
require_once CCTM_PATH . '/includes/GetPostsQuery.php';
require_once CCTM_PATH . '/includes/GetPostsForm.php';
// Id of the field that will store the values (we need to pass it through here
// because it is not static: there may be multiple instances of the widget)
$storage_field = CCTM::get_value($_POST, 'storage_field', 'storage_field');
$search_parameters_str = '';
if (isset($_POST['search_parameters'])) {
    $search_parameters_str = $_POST['search_parameters'];
}
$existing_values = array();
parse_str($search_parameters_str, $existing_values);
$Form = new GetPostsForm();
// What options should be displayed on the form that defines the search?
// Load up the config...
$possible_configs = array();
$possible_configs[] = '/config/search_parameters/_widget.php';
if (!CCTM::load_file($possible_configs)) {
    print '<p>' . __('Search parameter configuration file not found.', CCTM_TXTDOMAIN) . '</p>';
}
$form_tpl = CCTM::load_tpl('summarize_posts/widget.tpl');
if (!current_user_can('administrator')) {
    exit('Admins only.');
}
/*------------------------------------------------------------------------------
* Confirm Delete/Deletes a metabox definition
* @param string $id (unique name of metabox)
------------------------------------------------------------------------------*/
require_once CCTM_PATH . '/includes/CCTM_Metabox.php';
//print_r(CCTM::$data['metabox_defs']); exit;
// Page variables
$data = array();
$id = self::get_value($_GET, 'id');
if (!$id) {
    die(__('Invalid request.', CCTM_TXTDOMAIN));
}
$data = CCTM::get_value(CCTM::$data['metabox_defs'], $id);
if (empty($data)) {
    $msg_id = 'invalid_metabox_id';
    include CCTM_PATH . '/controllers/error.php';
    return;
}
$data['page_title'] = sprintf(__('Delete Metabox: %s', CCTM_TXTDOMAIN), $id);
$data['menu'] = '';
$data['msg'] = CCTM::get_flash();
$data['action_name'] = 'custom_content_type_mgr_delete_metabox';
$data['nonce_name'] = 'custom_content_type_mgr_delete_metabox';
$data['submit'] = __('Delete', CCTM_TXTDOMAIN);
$data['fields'] = '';
// If properly submitted, Proceed with deleting the metabox
if (!empty($_POST) && check_admin_referer($data['action_name'], $data['nonce_name'])) {
    // Remove the primary definition
<?php

/*------------------------------------------------------------------------------
This lists available custom fields so the user can easily choose one to insert
the corresponding [custom_field] shortcode
Remember: the output here MUST be wrapped in HTML tags, otherwise jQuery's .html()
method will kack.
------------------------------------------------------------------------------*/
if (!defined('CCTM_PATH')) {
    exit('No direct script access allowed');
}
$post_type = CCTM::get_value($_POST, 'post_type');
if (empty($post_type)) {
    printf('<div class="error"><table><tr><td><img src="%s/images/warning-icon.png" height="44" width="50"/></td><td><p>%s</p></td></tr></table></div>', CCTM_URL, __('No post-type detected. Cannot display custom fields.', CCTM_TXTDOMAIN));
    return;
}
if (!isset(CCTM::$data['post_type_defs'][$post_type]['is_active']) || !CCTM::$data['post_type_defs'][$post_type]['is_active']) {
    printf('<div class="error"><table><tr><td><img src="%s/images/warning-icon.png" height="44" width="50"/></td><td><p>%s <a href="http://code.google.com/p/wordpress-custom-content-type-manager/wiki/custom_field_shortcode"><img src="' . CCTM_URL . '/images/question-mark.gif" width="16" height="16" /></a></p></td></tr></table></div>', CCTM_URL, __('The custom fields for this post-type are not standardized. You can manually type in the shortcode to print the custom field value from another post using the following format:  <code>[custom_field name="name_of_field" filter="optional_output_filter" post_id="123"]</code>', CCTM_TXTDOMAIN));
    return;
}
// Template variables
$d = array();
$d['msg'] = '';
$d['page_title'] = __('Custom Fields', CCTM_TXTDOMAIN);
$d['content'] = '';
$custom_fields = array();
if (isset(CCTM::$data['post_type_defs'][$post_type]['custom_fields'])) {
    $custom_fields = CCTM::$data['post_type_defs'][$post_type]['custom_fields'];
}
if (empty($custom_fields)) {
    $d['content'] = '<div class="error"><p>' . __('This post-type does not have any custom fields associated with it.', CCTM_TXTDOMAIN) . '</p></div>';