Example #1
0
 function cp_get_ad_details($post_id, $category_id, $location = 'list')
 {
     $form_id = cp_get_form_id($category_id);
     $form_fields = cp_get_custom_form_fields($form_id);
     $post = get_post($post_id);
     if (!$post) {
         return;
     }
     if (!$form_fields) {
         _e('No ad details found.', APP_TD);
         return;
     }
     // allows to hook before ad details
     cp_action_before_ad_details($form_fields, $post, $location);
     foreach ($form_fields as $field) {
         // external plugins can modify or disable field
         $field = apply_filters('cp_ad_details_field', $field, $post, $location);
         if (!$field) {
             continue;
         }
         $disallow_fields = array('cp_price', 'cp_currency');
         if (in_array($field->field_name, $disallow_fields)) {
             continue;
         }
         $post_meta_val = get_post_meta($post->ID, $field->field_name, true);
         if (empty($post_meta_val)) {
             continue;
         }
         if ($location == 'list') {
             if ($field->field_type == 'text area') {
                 continue;
             }
             if ($field->field_type == 'checkbox') {
                 $post_meta_val = get_post_meta($post->ID, $field->field_name, false);
                 $post_meta_val = implode(", ", $post_meta_val);
             }
             $args = array('value' => $post_meta_val, 'label' => $field->field_label, 'id' => $field->field_name, 'class' => '');
             $args = apply_filters('cp_ad_details_' . $field->field_name, $args, $field, $post, $location);
             if ($args) {
                 echo '<li id="' . $args['id'] . '" class="' . $args['class'] . '"><span>' . esc_html(translate($args['label'], APP_TD)) . ':</span> ' . appthemes_make_clickable($args['value']) . '</li>';
             }
         } elseif ($location == 'content') {
             if ($field->field_type != 'text area') {
                 continue;
             }
             $args = array('value' => $post_meta_val, 'label' => $field->field_label, 'id' => $field->field_name, 'class' => 'custom-text-area dotted');
             $args = apply_filters('cp_ad_details_' . $field->field_name, $args, $field, $post, $location);
             if ($args) {
                 echo '<div id="' . $args['id'] . '" class="' . $args['class'] . '"><h3>' . esc_html(translate($args['label'], APP_TD)) . '</h3> ' . wpautop(appthemes_make_clickable($args['value'])) . '</div>';
             }
         }
     }
     // allows to hook after ad details
     cp_action_after_ad_details($form_fields, $post, $location);
 }
Example #2
0
 public function get_custom_form_fields()
 {
     // get the ad category ID
     $category_id = appthemes_get_custom_taxonomy($this->get_post_id(), APP_TAX_CAT, 'term_id');
     // get the form id based on category ID
     $form_id = !empty($category_id) ? cp_get_form_id($category_id) : false;
     $form_fields = cp_get_custom_form_fields($form_id);
     return $form_fields;
 }
Example #3
0
/**
 * Retrieves Listing object.
 *
 * @param int $listing_id The listing ID.
 * @param int $checkout_listing Optional. Is this a valid checkout listing or an auto draft.
 *
 * @return object
 */
function cp_get_listing_obj($listing_id = 0, $checkout_listing = true)
{
    $listing_id = $listing_id ? $listing_id : get_the_ID();
    $listing = get_post($listing_id);
    if (!$listing) {
        return false;
    }
    if ($checkout_listing) {
        $categories = wp_get_post_terms($listing->ID, APP_TAX_CAT);
    }
    $listing->category = !empty($categories) ? $categories[0]->term_id : false;
    $form_id = cp_get_form_id($listing->category);
    $form_fields = cp_get_custom_form_fields($form_id);
    foreach ($form_fields as $field) {
        if (in_array($field->field_name, array('post_title', 'post_content'))) {
            continue;
        } else {
            if ($field->field_name == 'tags_input') {
                $listing->{$field->field_name} = rtrim(trim(cp_get_the_term_list($listing->ID, APP_TAX_TAG)), ',');
            } else {
                $is_single = $field->field_type != 'checkbox';
                $listing->{$field->field_name} = get_post_meta($listing->ID, $field->field_name, $is_single);
            }
        }
    }
    // Clear the default 'Auto Draft' title
    if ($listing->post_title == __('Auto Draft')) {
        $listing->post_title = '';
    }
    return $listing;
}
Example #4
0
 /**
  * Processing form.
  *
  * @param object $order
  * @param object $checkout
  *
  * return void
  */
 public function process($order, $checkout)
 {
     // if no category data move step backward
     if (!$checkout->get_data('category_id')) {
         $checkout->cancel_step();
         return;
     }
     if (!isset($_POST['action']) || !in_array($_POST['action'], array('create-listing', 'renew-listing'))) {
         return;
     }
     check_admin_referer($checkout->get_checkout_type());
     $this->category_id = $checkout->get_data('category_id');
     $this->form_id = $checkout->get_data('form_id');
     $this->form_fields = cp_get_custom_form_fields($this->form_id);
     $this->posted_fields = $this->clean_expected_fields();
     $this->errors = $this->validate_fields($this->errors);
     $this->errors = apply_filters('cp_listing_validate_fields', $this->errors);
     $this->update_listing($order, $checkout);
     if ($this->errors->get_error_codes()) {
         return false;
     }
     $this->set_internal_data();
     $checkout->add_data('posted_fields', $this->posted_fields);
     $this->finish_step();
 }
Example #5
0
/**
 * Handles form layouts admin page.
 *
 * @return void
 */
function cp_form_layouts()
{
    global $options_new_form, $wpdb, $current_user;
    $current_user = wp_get_current_user();
    // check to prevent php "notice: undefined index" msg when php strict warnings is on
    if (isset($_GET['action'])) {
        $theswitch = $_GET['action'];
    } else {
        $theswitch = '';
    }
    $admin_fields_url = get_admin_url('', 'edit.php?post_type=' . APP_POST_TYPE . '&amp;page=layouts');
    ?>

		<script type="text/javascript">
		/* <![CDATA[ */
		/* initialize the form validation */
		jQuery(document).ready(function($) {
			$("#mainform").validate({errorClass: "invalid"});
		});
		/* ]]> */
		</script>

		<?php 
    switch ($theswitch) {
        case 'addform':
            ?>

				<div class="wrap">
					<h2><?php 
            _e('New Form Layout', APP_TD);
            ?>
</h2>

					<?php 
            // check and make sure the form was submitted and the hidden fcheck id matches the cookie fcheck id
            if (isset($_POST['submitted'])) {
                if (!isset($_POST['post_category'])) {
                    wp_die('<p style="color:red;">' . __('Error: Please select at least one category.', APP_TD) . " <a href='#' onclick='history.go(-1);return false;'>" . __('Go back', APP_TD) . '</a></p>');
                }
                $data = array('form_name' => cp_make_custom_name($_POST['form_label'], 'forms'), 'form_label' => appthemes_clean($_POST['form_label']), 'form_desc' => appthemes_clean($_POST['form_desc']), 'form_cats' => serialize($_POST['post_category']), 'form_status' => appthemes_clean($_POST['form_status']), 'form_owner' => appthemes_clean($_POST['form_owner']), 'form_created' => current_time('mysql'));
                $insert = $wpdb->insert($wpdb->cp_ad_forms, $data);
                if ($insert) {
                    ?>

							<p style="text-align:center;padding-top:50px;font-size:22px;"><?php 
                    _e('Creating your form.....', APP_TD);
                    ?>
<br /><br /><img src="<?php 
                    echo get_template_directory_uri();
                    ?>
/images/loader.gif" alt="" /></p>
							<meta http-equiv="refresh" content="0; URL=<?php 
                    echo $admin_fields_url;
                    ?>
">

						<?php 
                }
                // end $insert
            } else {
                ?>

				<form method="post" id="mainform" action="">

					<?php 
                echo cp_admin_db_fields($options_new_form);
                ?>

					<p class="submit"><input class="btn button-primary" name="save" type="submit" value="<?php 
                _e('Create New Form', APP_TD);
                ?>
" />&nbsp;&nbsp;&nbsp;
					<input class="btn button-secondary" name="cancel" type="button" onClick="location.href='<?php 
                echo $admin_fields_url;
                ?>
'" value="<?php 
                esc_attr_e('Cancel', APP_TD);
                ?>
" /></p>
					<input name="submitted" type="hidden" value="yes" />
					<input name="form_owner" type="hidden" value="<?php 
                echo $current_user->user_login;
                ?>
" />

				</form>

			<?php 
            }
            // end isset $_POST
            ?>

			</div><!-- end wrap -->

		<?php 
            break;
        case 'editform':
            ?>

				<div class="wrap">
					<h2><?php 
            _e('Edit Form Properties', APP_TD);
            ?>
</h2>

					<?php 
            if (isset($_POST['submitted']) && $_POST['submitted'] == 'yes') {
                if (!isset($_POST['post_category'])) {
                    wp_die('<p style="color:red;">' . __('Error: Please select at least one category.', APP_TD) . " <a href='#' onclick='history.go(-1);return false;'>" . __('Go back', APP_TD) . '</a></p>');
                }
                $data = array('form_label' => appthemes_clean($_POST['form_label']), 'form_desc' => appthemes_clean($_POST['form_desc']), 'form_cats' => serialize($_POST['post_category']), 'form_status' => appthemes_clean($_POST['form_status']), 'form_owner' => appthemes_clean($_POST['form_owner']), 'form_modified' => current_time('mysql'));
                $wpdb->update($wpdb->cp_ad_forms, $data, array('id' => $_GET['id']));
                ?>

						<p style="text-align:center;padding-top:50px;font-size:22px;"><?php 
                _e('Saving your changes.....', APP_TD);
                ?>
<br /><br /><img src="<?php 
                echo get_template_directory_uri();
                ?>
/images/loader.gif" alt="" /></p>
						<meta http-equiv="refresh" content="0; URL=<?php 
                echo $admin_fields_url;
                ?>
">

					<?php 
            } else {
                ?>

				<form method="post" id="mainform" action="">

					<?php 
                echo cp_admin_db_fields($options_new_form, 'cp_ad_forms', 'id');
                ?>

					<p class="submit"><input class="btn button-primary" name="save" type="submit" value="<?php 
                _e('Save changes', APP_TD);
                ?>
" />&nbsp;&nbsp;&nbsp;
					<input class="btn button-secondary" name="cancel" type="button" onClick="location.href='<?php 
                echo $admin_fields_url;
                ?>
'" value="<?php 
                esc_attr_e('Cancel', APP_TD);
                ?>
" /></p>
					<input name="submitted" type="hidden" value="yes" />
					<input name="form_owner" type="hidden" value="<?php 
                echo $current_user->user_login;
                ?>
" />

				</form>

			<?php 
            }
            // end isset $_POST
            ?>

			</div><!-- end wrap -->

		<?php 
            break;
            /**
             * Form Builder Page
             * Where fields are added to form layouts
             */
        /**
         * Form Builder Page
         * Where fields are added to form layouts
         */
        case 'formbuilder':
            ?>
				<div class="wrap">
					<h2><?php 
            _e('Edit Form Layout', APP_TD);
            ?>
</h2>

					<?php 
            // add fields to page layout on left side
            if (isset($_POST['field_id'])) {
                // take selected checkbox array and loop through ids
                foreach ($_POST['field_id'] as $value) {
                    $data = array('form_id' => appthemes_clean($_POST['form_id']), 'field_id' => appthemes_clean($value), 'field_pos' => '99');
                    $insert = $wpdb->insert($wpdb->cp_ad_meta, $data);
                }
                // end foreach
            }
            // end $_POST
            // update form layout positions and required fields on left side.
            if (isset($_POST['formlayout'])) {
                // loop through the post array and update the required checkbox and field position
                foreach ($_POST as $key => $value) {
                    // since there's some $_POST values we don't want to process, only give us the
                    // numeric ones which means it contains a meta_id and we want to update it
                    if (is_numeric($key)) {
                        // quick hack to prevent php "notice: undefined index:" msg when php strict warnings is on
                        if (!isset($value['field_req'])) {
                            $value['field_req'] = '0';
                        }
                        if (!isset($value['field_search'])) {
                            $value['field_search'] = '0';
                        }
                        $data = array('field_req' => appthemes_clean($value['field_req']), 'field_search' => appthemes_clean($value['field_search']));
                        $wpdb->update($wpdb->cp_ad_meta, $data, array('meta_id' => $key));
                    }
                    // end if_numeric
                }
                // end for each
                echo scb_admin_notice(__('Your changes have been saved.', APP_TD));
            }
            // end isset $_POST
            // check to prevent php "notice: undefined index" msg when php strict warnings is on
            if (isset($_GET['del_id'])) {
                $theswitch = $_GET['del_id'];
            } else {
                $theswitch = '';
            }
            // Remove items from form layout
            if ($theswitch) {
                $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->cp_ad_meta} WHERE meta_id = %s", $_GET['del_id']));
            }
            //update the forms modified date
            $data = array('form_modified' => current_time('mysql'));
            $wpdb->update($wpdb->cp_ad_forms, $data, array('id' => $_GET['id']));
            ?>

			<div class="edit-fields-panel">

				<h3><?php 
            _e('Form Name', APP_TD);
            ?>
 - <?php 
            echo ucfirst(urldecode($_GET['title']));
            ?>
&nbsp;&nbsp;&nbsp;&nbsp;<span id="loading"></span></h3>
				<br/>

				<form method="post" id="mainform" action="">
					<table class="widefat wp-list-table fixed striped">
						<thead>
							<tr>
								<th scope="col" class="manage-columns column-form-preview"><?php 
            _e('Form Preview', APP_TD);
            ?>
</th>
								<th scope="col" class="manage-columns column-form-field">&nbsp;</th>
								<th scope="col" class="manage-columns column-form-options" style="text-align:center;" title="<?php 
            _e('Show field in the category refine search sidebar', APP_TD);
            ?>
"><?php 
            _e('Adv. Search', APP_TD);
            ?>
</th>
								<th scope="col" class="manage-columns column-form-required" style="text-align:center;"><?php 
            _e('Required', APP_TD);
            ?>
</th>
								<th scope="col" class="manage-columns column-form-remove" style="text-align:center;"><?php 
            _e('Remove', APP_TD);
            ?>
</th>
							</tr>
						</thead>

						<tbody class="sortable">
							<?php 
            // If this is the first time this form is being customized then auto
            // create the core fields and put in cp_meta db table
            echo cp_add_core_fields($_GET['id']);
            $form_fields = cp_get_custom_form_fields($_GET['id']);
            if ($form_fields) {
                echo cp_admin_formbuilder($form_fields);
            } else {
                ?>
									<tr>
										<td colspan="5" style="text-align: center;"><p><br /><?php 
                _e('No fields have been added to this form layout yet.', APP_TD);
                ?>
<br /><br /></p></td>
									</tr>
							<?php 
            }
            // end $results
            ?>
						</tbody>
					</table>

					<div class="clear"></div>

					<p class="submit">
						<input class="btn button-primary" name="save" type="submit" value="<?php 
            _e('Save Changes', APP_TD);
            ?>
" />&nbsp;&nbsp;&nbsp;
						<input class="btn button-secondary" name="cancel" type="button" onClick="location.href='<?php 
            echo $admin_fields_url;
            ?>
'" value="<?php 
            esc_attr_e('Cancel', APP_TD);
            ?>
" />
						<input name="formlayout" type="hidden" value="yes" />
						<input name="form_owner" type="hidden" value="<?php 
            $current_user->user_login;
            ?>
" />
					</p>
				</form>
			</div>

			<div class="fields-panel">

				<h3><?php 
            _e('Available Fields', APP_TD);
            ?>
</h3>
				<br/>

				<form method="post" id="mainform" action="">
					<table class="widefat wp-list-table fixed striped">
						<thead>
							<tr>
								<th id="cb" scope="col" class="manage-column column-cb check-column"><input type="checkbox"/></th>
								<th scope="col" class="manage-column column-field-name"><?php 
            _e('Field Name', APP_TD);
            ?>
</th>
								<th scope="col" class="manage-column column-field-type"><?php 
            _e('Type', APP_TD);
            ?>
</th>
							</tr>
						</thead>
						<tbody>
							<?php 
            // Select all available fields not currently on the form layout.
            // Also exclude any core fields since they cannot be removed from the layout.
            $sql = $wpdb->prepare("SELECT f.field_id,f.field_label,f.field_type " . "FROM {$wpdb->cp_ad_fields} f " . "WHERE f.field_id " . "NOT IN (SELECT m.field_id " . "FROM {$wpdb->cp_ad_meta} m " . "WHERE m.form_id =  %s) " . "AND f.field_perm <> '1'", $_GET['id']);
            $results = $wpdb->get_results($sql);
            if ($results) {
                foreach ($results as $result) {
                    ?>
									<tr class="even">
										<th class="check-column" scope="row"><input type="checkbox" value="<?php 
                    echo esc_attr($result->field_id);
                    ?>
" name="field_id[]"/></th>
										<td class="column-field-name"><?php 
                    echo esc_html(translate($result->field_label, APP_TD));
                    ?>
</td>
										<td class="column-field-type"><?php 
                    echo $result->field_type;
                    ?>
</td>
									</tr>
								<?php 
                }
                // end foreach
            } else {
                ?>
								<tr>
									<td colspan="4" style="text-align: center;"><p><br /><?php 
                _e('No fields are available.', APP_TD);
                ?>
<br /><br /></p></td>
								</tr>
							<?php 
            }
            // end $results
            ?>
						</tbody>
					</table>

					<div class="clear"></div>

					<p class="submit">
						<input class="btn button-primary" name="save" type="submit" value="<?php 
            esc_attr_e('Add Fields to Form Layout', APP_TD);
            ?>
" />
						<input name="form_id" type="hidden" value="<?php 
            echo esc_attr($_GET['id']);
            ?>
" />
						<input name="submitted" type="hidden" value="yes" />
					</p>
				</form>
			</div>
		</div><!-- /wrap -->
		<?php 
            break;
        case 'delete':
            // delete the form based on the form id
            cp_delete_form($_GET['id']);
            ?>
			<p style="text-align:center;padding-top:50px;font-size:22px;"><?php 
            _e('Deleting form layout.....', APP_TD);
            ?>
<br /><br /><img src="<?php 
            echo get_template_directory_uri();
            ?>
/images/loader.gif" alt="" /></p>
			<meta http-equiv="refresh" content="0; URL=<?php 
            echo $admin_fields_url;
            ?>
">
		<?php 
            break;
        default:
            $results = $wpdb->get_results("SELECT * FROM {$wpdb->cp_ad_forms} ORDER BY id desc");
            ?>
			<div class="wrap">
				<h2><?php 
            _e('Form Layouts', APP_TD);
            ?>
&nbsp;<a class="add-new-h2" href="<?php 
            echo esc_url(add_query_arg('action', 'addform', $admin_fields_url));
            ?>
"><?php 
            _e('Add New', APP_TD);
            ?>
</a></h2>

				<p class="admin-msg"><?php 
            _e('Form layouts allow you to create your own custom ad submission forms. Each form is essentially a container for your fields and can be applied to one or all of your categories. If you do not create any form layouts, the default one will be used. To change the default form, create a new form layout and apply it to all categories.', APP_TD);
            ?>
</p>

				<table id="tblspacer" class="wp-list-table widefat fixed">

					<thead>
						<tr>
							<th scope="col" style="width:35px;">#</th>
							<th scope="col" class="manage-column column-name"><?php 
            _e('Name', APP_TD);
            ?>
</th>
							<th scope="col" class="manage-column column-description"><?php 
            _e('Description', APP_TD);
            ?>
</th>
							<th scope="col" class="manage-column column-categories"><?php 
            _e('Categories', APP_TD);
            ?>
</th>
							<th scope="col" class="manage-column column-modified" style="width:150px;"><?php 
            _e('Modified', APP_TD);
            ?>
</th>
							<th scope="col" class="manage-column column-status" style="width:75px;"><?php 
            _e('Status', APP_TD);
            ?>
</th>
							<th scope="col" class="manage-column column-actions" style="text-align:center;width:100px;"><?php 
            _e('Actions', APP_TD);
            ?>
</th>
						</tr>
					</thead>

					<?php 
            if ($results) {
                $rowclass = '';
                $i = 1;
                ?>

					<tbody id="list">
					<?php 
                foreach ($results as $result) {
                    $rowclass = 'even' == $rowclass ? 'alt' : 'even';
                    ?>
							<tr class="<?php 
                    echo $rowclass;
                    ?>
">
								<td style="padding-left:10px;"><?php 
                    echo $i;
                    ?>
.</td>
								<td class="column-name"><a href="<?php 
                    echo esc_url(add_query_arg(array('action' => 'editform', 'id' => $result->id), $admin_fields_url));
                    ?>
"><strong><?php 
                    echo $result->form_label;
                    ?>
</strong></a></td>
								<td class="column-description"><?php 
                    echo $result->form_desc;
                    ?>
</td>
								<td class="column-categories"><?php 
                    echo cp_match_cats(unserialize($result->form_cats));
                    ?>
</td>
								<td class="column-modified"><?php 
                    echo appthemes_display_date('0000-00-00 00:00:00' != $result->form_modified ? $result->form_modified : $result->form_created);
                    ?>
 <?php 
                    _e('by', APP_TD);
                    ?>
 <?php 
                    echo $result->form_owner;
                    ?>
</td>
								<td class="column-status"><?php 
                    echo cp_get_status_i18n($result->form_status);
                    ?>
</td>
								<td class="column-actions" style="text-align:center"><a href="<?php 
                    echo esc_url(add_query_arg(array('action' => 'formbuilder', 'id' => $result->id, 'title' => urlencode($result->form_label)), $admin_fields_url));
                    ?>
"><i class="dashicons-before custom-forms-ico edit-layout wp-ui-text-highlight" title="<?php 
                    _e('Edit form layout', APP_TD);
                    ?>
"></i></a>&nbsp;&nbsp;&nbsp;
									<a href="<?php 
                    echo esc_url(add_query_arg(array('action' => 'editform', 'id' => $result->id), $admin_fields_url));
                    ?>
"><i class="dashicons-before custom-forms-ico edit-properties wp-ui-text-highlight" title="<?php 
                    _e('Edit form properties', APP_TD);
                    ?>
"></i></a>&nbsp;&nbsp;&nbsp;
									<a onclick="return confirmBeforeDelete();" href="<?php 
                    echo esc_url(add_query_arg(array('action' => 'delete', 'id' => $result->id), $admin_fields_url));
                    ?>
"><i class="dashicons-before custom-forms-ico remove" title="<?php 
                    _e('Delete form layout', APP_TD);
                    ?>
"></i></a>
								</td>
							</tr>
					  <?php 
                    $i++;
                }
                // end for each
                ?>
					  </tbody>
					<?php 
            } else {
                ?>
						<tr>
							<td colspan="7"><?php 
                _e('No form layouts found.', APP_TD);
                ?>
</td>
						</tr>
					<?php 
            }
            // end $results
            ?>
				</table>
			</div><!-- end wrap -->

		<?php 
    }
    // end switch
    ?>
		<script type="text/javascript">
			/* <![CDATA[ */
				function confirmBeforeDelete() { return confirm("<?php 
    _e('Are you sure you want to delete this?', APP_TD);
    ?>
"); }
				function confirmBeforeRemove() { return confirm("<?php 
    _e('Are you sure you want to remove this?', APP_TD);
    ?>
"); }
			/* ]]> */
		</script>
<?php 
}