Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

merge dev into master

  • Loading branch information...
commit be66fbf7b04ac30b526ffb2bd9397c6f6872be5c 2 parents 906eaff + f9f3645
Kevin Dees authored
View
4 .gitignore
@@ -1,3 +1,7 @@
+# ACPT #
+########
+config.php
+
# Compiled source #
###################
*.com
View
10 README.md
@@ -12,13 +12,15 @@ New to WordPress? Use Plugins!
Usage
===
-Use a php include to add the file init.php to your plugin or functions.php theme file. For more advanced users look at the code comments for help on what args are available. ACPT also comes with its own plugin system so you don't have to muck up your functions.php file and can import others work with ease.
+1) Use a php include to add the file init.php to your plugin or functions.php theme file. For more advanced users look at the code comments for help on what args are available. ACPT also comes with its own plugin system so you don't have to muck up your functions.php file and can import others work with ease.
```php
include('acpt/init.php');
```
-For custom settings see the config.php file. Set DEV_MODE to true for forms API help.
+2) Copy and rename sample-config.php to config.php
+
+For custom settings see the config.php file. Set DEV_MODE to true for forms API help when theming.
```php
define('DEV_MODE', true);
@@ -188,6 +190,10 @@ function meta_details() {
$form->textarea('address',array('label' => 'Textarea'));
$form->select('rooms', array('one', 'two', 'three'), array('label' => 'Select List'));
$form->radio('baths', array('blue', 'green', 'red'), array('label' => 'Radio Buttons'));
+
+ // When outputting editor data you may want to apply "the_content" filter
+ // apply_filters('the_content', $content_var)
+ // note that $content_var must be set to the content by you manually
$form->editor('baths', 'WYSIWYG Editor');
}
```
View
87 core/acpt.php
@@ -19,9 +19,9 @@
* @global string $acpt_version
*/
class acpt {
-
+
function __construct() {
-
+
}
public function __get($property) {
@@ -48,22 +48,29 @@ function make_computer_name($name) {
static function set_messages($messages) {
global $post, $post_ID;
$post_type = get_post_type( $post_ID );
-
+
$obj = get_post_type_object($post_type);
$singular = $obj->labels->singular_name;
-
+
+ // if($obj->public == false) {
+ // $link = false;
+ // } else {
+ $link_view = '<a href="%s">View '.strtolower($singular).'</a>';
+ $link_pre = '<a target="_blank" href="%s">Preview '.strtolower($singular).'</a>';
+ // }
+
$messages[$post_type] = array(
0 => '', // Unused. Messages start at index 1.
- 1 => sprintf( __($singular.' updated. <a href="%s">View '.strtolower($singular).'</a>'), esc_url( get_permalink($post_ID) ) ),
+ 1 => sprintf( __($singular.' updated. ' . $link_view ), esc_url( get_permalink($post_ID) ) ),
2 => __('Custom field updated.'),
3 => __('Custom field deleted.'),
4 => __($singular.' updated.'),
5 => isset($_GET['revision']) ? sprintf( __($singular.' restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
- 6 => sprintf( __($singular.' published. <a href="%s">View '.strtolower($singular).'</a>'), esc_url( get_permalink($post_ID) ) ),
+ 6 => sprintf( __($singular.' published. ' . $link_view ), esc_url( get_permalink($post_ID) ) ),
7 => __('Page saved.'),
- 8 => sprintf( __($singular.' submitted. <a target="_blank" href="%s">Preview '.strtolower($singular).'</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
- 9 => sprintf( __($singular.' scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview '.strtolower($singular).'</a>'), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
- 10 => sprintf( __($singular.' draft updated. <a target="_blank" href="%s">Preview '.strtolower($singular).'</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
+ 8 => sprintf( __($singular.' submitted. ' . $link_pre ), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
+ 9 => sprintf( __($singular.' scheduled for: <strong>%1$s</strong>. ' . $link_pre ), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
+ 10 => sprintf( __($singular.' draft updated. ' . $link_pre ), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
);
return $messages;
}
@@ -77,8 +84,9 @@ static function save_form($postID) {
foreach($_POST as $cf_name => $cf_data) {
// only new meta
if( preg_match('/^acpt_.*/' , $cf_name) ) { // change to your prefix
- // sanitize data from custom fields
- $cf_data = trim($_POST[$cf_name]); $cf_data = esc_sql($cf_data);
+ // validate data from custom fields
+ $cf_data = trim($_POST[$cf_name]);
+ $cf_data = acpt::validate($cf_name, $cf_data);
$cf_meta = get_post_meta($postID, $cf_name, true);
if ($cf_data) { // add and update
@@ -91,18 +99,63 @@ static function save_form($postID) {
endif; // end nonce
}
+ /*
+ * Validate Types
+ *
+ * 0 -> sql
+ * 1 -> text
+ * 2 -> html
+ * 3 -> url
+ * 4 -> img
+ * default - > none
+ * */
+ static function validate($key, $value) {
+
+ if( preg_match('/^acpt_validate0.*/' , $key) ) {
+ $value = $value;
+ }
+ else if( preg_match('/^acpt_validate1.*/' , $key) ) {
+ $value = sanitize_text_field($value);
+ }
+ else if( preg_match('/^acpt_validate2.*/' , $key) ) {
+ $html = force_balance_tags($value);
+ $value = $html;
+ }
+ else if( preg_match('/^acpt_validate3.*/' , $key) ) {
+ $value = esc_url($value);
+ }
+ else if( preg_match('/^acpt_validate4.*/' , $key) ) {
+ $value = esc_url($value);
+ }
+ else {
+ $value = $value;
+ }
+ return $value;
+ }
+
static function apply_css() {
wp_register_style( 'acpt-styles', ACPT_LOCATION . '/acpt/core/css/style.css' );
wp_enqueue_style( 'acpt-styles' );
}
static function upload_scripts() {
- wp_enqueue_script('plupload');
- wp_enqueue_script('media-upload');
- wp_enqueue_style('thickbox');
- wp_enqueue_script('thickbox');
- wp_register_script('upload', ACPT_LOCATION .'/acpt/core/js/upload.js', array('jquery','media-upload','thickbox'));
- wp_enqueue_script('upload');
+ if(function_exists( 'wp_enqueue_media' )){
+ wp_enqueue_media();
+ wp_register_script('upload', ACPT_LOCATION .'/acpt/core/js/upload-3.5.js', array('jquery'));
+ wp_enqueue_script('upload');
+ wp_enqueue_script('plupload');
+ wp_enqueue_script('media-upload');
+ wp_enqueue_style('thickbox');
+ wp_enqueue_script('thickbox');
+ }
+ else {
+ wp_enqueue_script('plupload');
+ wp_enqueue_script('media-upload');
+ wp_enqueue_style('thickbox');
+ wp_enqueue_script('thickbox');
+ wp_register_script('upload', ACPT_LOCATION .'/acpt/core/js/upload.js', array('jquery','media-upload','thickbox'));
+ wp_enqueue_script('upload');
+ }
}
}
View
57 core/form.php
@@ -85,6 +85,35 @@ function end($name=null, $opts=array()) {
if(isset($field)) echo $field;
}
+ function get_field_name($name, $opts, $type) {
+ $san = '';
+
+ if( isset($opts['validate'])) {
+ $sanType = $opts['validate'];
+ switch($sanType) {
+ case 'text' :
+ $san = 'validate1_';
+ break;
+ case 'html' :
+ $san = 'validate2_';
+ break;
+ case 'url' :
+ $san = 'validate3_';
+ break;
+ case 'img' :
+ $san = 'validate4_';
+ break;
+ case 'sql' :
+ $san = 'validate0_';
+ break;
+ default :
+ $san = '';
+ }
+ }
+
+ return 'acpt_'.$san.$this->formName.'_'.$type.'_'.$name;
+ }
+
function get_opts($name, $opts, $fieldName, $label) {
if(empty($opts['labelTag'])) $opts['labelTag'] = 'label';
@@ -152,7 +181,8 @@ function text($name, $opts=array(), $label = true) {
global $post;
$dev_note = null;
- $fieldName = 'acpt_'.$this->formName.'_text_'.$name;
+ $fieldName = $this->get_field_name($name, $opts, 'text');
+ //$fieldName = 'acpt_'.$this->formName.'_text_'.$name;
// value
if($value = get_post_meta($post->ID, $fieldName, true)) :
@@ -179,7 +209,8 @@ function url($name, $opts=array(), $label = true) {
global $post;
$dev_note = null;
- $fieldName = 'acpt_'.$this->formName.'_url_'.$name;
+ $fieldName = $this->get_field_name($name, $opts, 'url');
+ //$fieldName = 'acpt_'.$this->formName.'_url_'.$name;
// value
if($value = get_post_meta($post->ID, $fieldName, true)) :
@@ -206,7 +237,8 @@ function textarea($name, $opts=array(), $label = true) {
global $post;
$dev_note = null;
- $fieldName = 'acpt_'.$this->formName.'_textarea_'.$name;
+ $fieldName = $this->get_field_name($name, $opts, 'textarea');
+ // $fieldName = 'acpt_'.$this->formName.'_textarea_'.$name;
// value
if($value = get_post_meta($post->ID, $fieldName, true)) :
@@ -234,7 +266,8 @@ function select($name, $options=array('Key' => 'Value'), $opts=array(), $label =
global $post;
$dev_note = null;
- $fieldName = 'acpt_'.$this->formName.'_select_'.$name;
+ $fieldName = $this->get_field_name($name, $opts, 'select');
+ //$fieldName = 'acpt_'.$this->formName.'_select_'.$name;
// get options HTML
if(isset($options)) :
@@ -276,7 +309,8 @@ function radio($name, $options=array('Key' => 'Value'), $opts=array(), $label =
$dev_note = null;
$opts['labelTag'] = 'span';
- $fieldName = 'acpt_'.$this->formName.'_radio_'.$name;
+ $fieldName = $this->get_field_name($name, $opts, 'radio');
+ //$fieldName = 'acpt_'.$this->formName.'_radio_'.$name;
// name
if ( is_string($fieldName) ) :
@@ -316,11 +350,12 @@ function radio($name, $options=array('Key' => 'Value'), $opts=array(), $label =
* @param string $singular singular name is required
* @param array $opts args override and extend
*/
- function editor($name, $label=null, $opts=array()) {
+ function editor($name, $label=null, $opts=array(), $settings=array('validate'=>'none')) {
if(!$this->formName) exit('Making Form: You need to make the form first.');
if(!$name) exit('Making Editor: You need to enter a singular name.');
global $post;
- $fieldName = 'acpt_'.$this->formName.'_editor_'.$name;
+ $fieldName = $this->get_field_name($name, $settings, 'editor');
+ //$fieldName = 'acpt_'.$this->formName.'_editor_'.$name;
if($value = get_post_meta($post->ID, $fieldName, true))
$content = $value;
@@ -334,7 +369,7 @@ function editor($name, $label=null, $opts=array()) {
wp_editor(
$content,
'wysisyg_'.$this->formName.'_'.$name,
- array_merge($opts,array('textarea_name' => 'acpt_'.$this->formName.'_editor_'.$name))
+ array_merge($opts,array('textarea_name' => $fieldName))
);
echo $this->dev_message($fieldName);
echo '</div>';
@@ -352,7 +387,8 @@ function image($name, $opts=array(), $label = true) {
global $post;
$dev_note = null;
- $fieldName = 'acpt_'.$this->formName.'_image_'.$name;
+ $fieldName = $this->get_field_name($name, $opts, 'image');
+ //$fieldName = 'acpt_'.$this->formName.'_image_'.$name;
$placeHolderImage = null;
// value
@@ -391,7 +427,8 @@ function file($name, $opts=array(), $label = true) {
global $post;
$dev_note = null;
- $fieldName = 'acpt_'.$this->formName.'_image_'.$name;
+ $fieldName = $this->get_field_name($name, $opts, 'file');
+ //$fieldName = 'acpt_'.$this->formName.'_file_'.$name;
$placeHolderImage = null;
// value
View
49 core/js/upload-3.5.js
@@ -0,0 +1,49 @@
+jQuery(document).ready(function($) {
+
+ function set_uploader(button, url, container, type) {
+ $(button).click(function() {
+
+ var send_attachment_bkp = wp.media.editor.send.attachment;
+
+ wp.media.editor.send.attachment = function(props, attachment) {
+
+ var placeholder = $(container).find('.image-placeholder img');
+ if(placeholder.length > 0) {
+ $(placeholder).attr('src', attachment.url);
+ } else {
+ $(container).find('.image-placeholder').append($('<img>').attr('src', attachment.url));
+ }
+
+ $(url).val(attachment.url);
+
+ wp.media.editor.send.attachment = send_attachment_bkp;
+ }
+
+ wp.media.editor.open();
+
+ return false;
+ });
+ }
+
+ // place set_uploader functions below, button then field
+ $('.control-group').each(function(index, el) {
+ var button = $(el).find('.upload-button'), uploadUrl = $(el).find('.upload-url'), type = null;
+
+ if($(uploadUrl).hasClass('file')) {
+ type = 'file';
+ } else if($(uploadUrl).hasClass('image')) {
+ type = 'image';
+ }
+
+ //console.log(type);
+
+ if(button){ set_uploader(button[0], uploadUrl[0], el, type);}
+
+ $(el).on('click', '.image-placeholder .remove-image', function(){
+ $(this).parent().parent().find('.upload-url').attr('value', '');
+ $(this).parent().remove();
+ $(el).append('<div class="image-placeholder"><div class="remove-image"></div></div>');
+ });
+ });
+
+});
View
2  plugins/basic-slider/README.md
@@ -80,4 +80,4 @@ Configuring and Editing Files
If you need more control over the slider output see the template.php file and make edits there. There are a few places you can edit HTML without breaking anything and should be apparent (like the wrapper vars). You will want to do the more than likely simple because jQuery sliders require different types of HTML and classes to work.
-The only issues with editing these files is of course when an update is made on the plugin and you may have conflicts. I recommend renaming the plugin to avoid your custom changes being removed on an update.
+The only issues with editing these files is of course when an update is made on the plugin and you may have conflicts. I recommend renaming the plugin to avoid your custom changes being removed on an update.
View
4 plugins/basic-slider/index.php
@@ -1,7 +1,7 @@
<?php
add_action('init', 'acpt_slider');
function acpt_slider() {
-include('shortcodes.php');
+//include('shortcodes.php');
$args = array(
'supports' => array( 'title', 'page-attributes', 'acpt_slide_options' ),
@@ -19,7 +19,7 @@ function acpt_slider() {
add_action( 'add_meta_boxes', 'acpt_slider_meta' );
function acpt_slider_meta() {
- new meta_box('acpt_slide_options', array('sample'), array('label' => 'Slide'));
+ new meta_box('acpt_slide_options', array('slide'), array('label' => 'Slide'));
}
function meta_acpt_slide_options() {
View
2  plugins/sample/index.php
@@ -25,7 +25,7 @@ function meta_custom() {
$form->text('name', array('label' => 'Text Field'));
$form->image('image', array('label' => 'Image Field', 'button' => 'Add Your Image'));
$form->file('file', array('label' => 'File Field', 'button' => 'Select a File'));
- $form->textarea('address',array('label' => 'Textarea'));
+ $form->textarea('address',array('label' => 'Textarea', 'validate' => 'html'));
$form->select('rooms', array('one', 'two', 'three'), array('label' => 'Select List'));
$form->radio('baths', array('blue', 'green', 'red'), array('label' => 'Radio Buttons'));
$form->editor('baths', 'WYSIWYG Editor');
View
0  config.php → sample-config.php
File renamed without changes
Please sign in to comment.
Something went wrong with that request. Please try again.