<?php

if (!defined('ABSPATH')) {
    die('Security check');
}
if (empty($settings_defaults)) {
    exit;
}
if (empty($settings)) {
    $settings = array();
}
$settings = CRED_PostExpiration::array_merge_distinct($settings_defaults, $settings);
?>
<div>
    <div class="cred-fieldset">
    	<p>
			<label>
				<input type="checkbox" name="<?php 
echo $field_name;
?>
[enable]" value="1" <?php 
if (1 == $settings['enable']) {
    echo 'checked="checked"';
}
?>
>
				<span><?php 
_e('Automatic expire date for this form', $cred_post_expiration->getLocalizationContext());
?>
</span>
			</label>
Beispiel #2
0
 private static function importUserForms($data, $options)
 {
     $results = array('settings' => 0, 'custom_fields' => 0, 'updated' => 0, 'new' => 0, 'failed' => 0, 'errors' => array());
     $newitems = array();
     if (isset($data['settings']) && isset($options['overwrite_settings']) && $options['overwrite_settings']) {
         $setmodel = CRED_Loader::get('MODEL/Settings');
         $oldsettings = $setmodel->getSettings();
         $newsettings = array();
         $fields = array('dont_load_cred_css', 'enable_post_expiration', 'export_custom_fields', 'export_settings', 'recaptcha', 'syntax_highlight', 'use_bootstrap', 'wizard');
         foreach ($fields as $key) {
             $newsettings[$key] = null;
             if (array_key_exists($key, $data['settings']) && isset($data['settings'][$key])) {
                 $newsettings[$key] = $data['settings'][$key];
             }
         }
         $setmodel->updateSettings($newsettings);
         //Import CRED Post Expiration to options table
         global $cred_post_expiration;
         if ($newsettings['enable_post_expiration'] && isset($data['post_expiration_settings']) && !empty($data['post_expiration_settings'])) {
             $oldsettings_expiration = $cred_post_expiration->getCredPESettings();
             $newsettings_expiration = $data['post_expiration_settings'];
             $newsettings_expiration['post_expiration_post_types'] = array();
             if (isset($data['post_expiration_settings']['post_expiration_post_types']['post_expiration_post_types_item'])) {
                 // make it array
                 if (!is_array($data['post_expiration_settings']['post_expiration_post_types']['post_expiration_post_types_item'])) {
                     $data['post_expiration_settings']['post_expiration_post_types']['post_expiration_post_types_item'] = array($data['post_expiration_settings']['post_expiration_post_types']['post_expiration_post_types_item']);
                 }
                 $newsettings_expiration['post_expiration_post_types'] = $data['post_expiration_settings']['post_expiration_post_types']['post_expiration_post_types_item'];
             }
             $newsettings_expiration = CRED_PostExpiration::array_merge_distinct($oldsettings_expiration, $newsettings_expiration);
             $cred_post_expiration->setCronSettings($newsettings_expiration);
         } else {
             $cred_post_expiration->deleteCredPESettings();
         }
         $results['settings'] = 1;
         unset($oldsettings);
     }
     if (isset($data['settings'])) {
         unset($data['settings']);
     }
     if (isset($data['post_expiration_settings'])) {
         unset($data['post_expiration_settings']);
     }
     if (isset($data['custom_fields']) && isset($options['overwrite_custom_fields']) && $options['overwrite_custom_fields']) {
         $custom_fields_model = CRED_Loader::get('MODEL/UserFields');
         $old_custom_fields = $custom_fields_model->getCustomFields();
         foreach ($data['custom_fields'] as $post_type => $field) {
             foreach ($field as $field_slug => $field_data) {
                 //TODO: complete custom fields in user
                 //$custom_fields_model->setCustomField($field_data);
                 $results['custom_fields']++;
             }
         }
         unset($old_custom_fields);
     }
     if (isset($data['custom_fields'])) {
         unset($data['custom_fields']);
     }
     $fmodel = CRED_Loader::get('MODEL/UserForms');
     if (isset($data['form']) && !empty($data['form']) && is_array($data['form'])) {
         if (!isset($options['items'])) {
             $items = false;
         } else {
             $items = $options['items'];
         }
         if (!isset($data['form'][0])) {
             $data['form'] = array($data['form']);
         }
         // make it array
         // create tmp upload dir, to handle imported media attached to forms
         $upload_dir = wp_upload_dir();
         $upload_path = $upload_dir['basedir'];
         $upload_directory = $upload_dir['baseurl'];
         $_tmp = $upload_path . DIRECTORY_SEPARATOR . '__cred__tmp__';
         $_tmpuri = $upload_directory . '/__cred__tmp__';
         if (!is_dir($_tmp)) {
             mkdir($_tmp);
         }
         if (is_dir($_tmp)) {
             // include only if necessary
             include_once ABSPATH . 'wp-admin/includes/file.php';
             include_once ABSPATH . 'wp-admin/includes/media.php';
             include_once ABSPATH . 'wp-admin/includes/image.php';
         }
         foreach ($data['form'] as $key => $form_data) {
             if (!isset($form_data['post_title'])) {
                 continue;
             }
             // import only selected items
             if (false !== $items && !in_array($form_data['ID'], $items)) {
                 continue;
             }
             $_form_id = self::importSingleUserForm($form_data, $fmodel, $options, $results);
             if ($_form_id) {
                 //Remove is_edited flag
                 delete_post_meta($_form_id, '_toolset_edit_last');
                 // add attached media (only images)
                 if (isset($form_data['media']['media_item']) && is_array($form_data['media']['media_item']) && !empty($form_data['media']['media_item']) && is_dir($_tmp)) {
                     $_att_results = self::importAttachedMedia($_form_id, $form_data['media']['media_item'], $_tmp, $_tmpuri);
                     //cred_log($_att_results);
                     if (!empty($_att_results['errors'])) {
                         $results['errors'] = array_merge($results['errors'], $_att_results['errors']);
                         $results['failed']++;
                     }
                     if (!empty($_att_results['data'])) {
                         // denormalize image hash placeholders
                         $form_data = self::denormalizeData($form_data, $_att_results['data']);
                         $fmodel->updateFormData(array('ID' => $_form_id, 'post_content' => $form_data['post_content']));
                     }
                 }
                 // for module manager
                 if (isset($options['return_ids']) && $options['return_ids']) {
                     $newitems[$form_data['ID']] = $_form_id;
                 }
             }
         }
         if (is_dir($_tmp)) {
             // remove custom tmp dir
             @rmdir($_tmp);
         }
     }
     // for module manager
     if (isset($options['return_ids']) && $options['return_ids']) {
         $results['items'] = $newitems;
     }
     return $results;
 }