e8f47b53 by Marty Penner

Convert tabs to spaces in 3 files

1 parent d569850b
......@@ -17,54 +17,54 @@ const ADMIN_PAGE = "canspam_admin";
$role->add_cap(CAPABILITY);
$role->add_cap(MANAGE_SYSTEM_NOTIFICATIONS);
//$role->remove_cap(SUB_ADMIN_CAPABILITY);
Vars::$settings = new Tools\WP_Option(SETTING_NS);
Tools\add_actions(__NAMESPACE__ . '\Actions');
});
function display_page() {
if (isset($_GET['action']) && $_GET['action']=="edit") {
global $wpdb;
$entry = get_post($_GET['page_id']);
$id = $entry->ID;
$details = get_post_meta($id,'details',true);
$email = get_post_meta($id,'email',true);
$system = get_post_meta($id,'system',true);
$entry->details = $details;
$entry->email = $email;
$entry->system = $system;
// here
$validation = new Notifications\Validation;
$validation->set_rules('type','Notification Type','required');
$validation->set_rules('title','Description','trim|required|min_length[4]');
$validation->set_rules('type','Notification Type','required');
$validation->set_rules('sendto','Send To','required');
$type_val = ($_POST && $_POST['type'] == "scheduled") ? 'required' : '';
$validation->set_rules('execute_date','Execute Date', $type_val);
$trigger_val = ($_POST && $_POST['type'] == "triggered") ? 'required' : '';
$validation->set_rules('trigger','Trigger',$trigger_val);
$validation->set_rules('subject','Subject','trim');
$validation->set_rules('text','Text Version','trim|min_length[16]');
$validation->set_rules('html','HTML Version','trim|min_length[16]');
$validation->set_rules('system_message_type','System Message Type','trim');
$validation->set_rules('system','System Message','trim|min_length[16]');
//details
if ($validation->run() == TRUE) {
......@@ -77,7 +77,7 @@ function display_page() {
$sendto = $_POST['sendto'];
$execute_date = ($type=="scheduled") ? $_POST['execute_date'] : "0000-00-00 00:00:00";
$trigger = ($type=="scheduled") ? "scheduled-cron-job" : $_POST['trigger'];
// email
$subject = $_POST['subject'];
$text = $_POST['text'];
......@@ -87,22 +87,20 @@ function display_page() {
fixFilesArray($_FILES['attachment']);
foreach ($_FILES['attachment'] as $position => $file) {
// should output array with indices name, type, tmp_name, error, size
if($file['name'] != "") {
if($file['name'] != "") {
move_uploaded_file($file['tmp_name'],$upload_dir . $file['name']);
$attachments[] = $file['name'];
}
}
// system
$system_message_type = $_POST['system_message_type'];
$system = $_POST['system'];
update_post_meta($id, 'notif_type', $type);
update_post_meta($id, 'execute_date', mysqldatetime_to_timestamp($execute_date));
update_post_meta($id, 'trigger', $trigger);
update_post_meta($id, "details", array(
'type' => $type
, 'sendto' => $sendto
......@@ -110,13 +108,13 @@ function display_page() {
, 'trigger' => $trigger
, 'execute_date' => $execute_date
));
update_post_meta($id,'send_status',$entry->details['status']);
if ( count( $entry->email['attachments'] ) > 0 ) {
$attachments = array_merge($entry->email['attachments'], $attachments);
}
update_post_meta($id, "email", array(
'subject' => $subject
, 'text' => $text
......@@ -127,56 +125,56 @@ function display_page() {
'system_message_type' => $system_message_type
, 'message' => $system
));
$update = array();
$update['ID'] = $id;
$update['post_title'] = $title;
wp_update_post($update);
$id = $entry->ID;
$details = get_post_meta($id,'details',true);
$email = get_post_meta($id,'email',true);
$system = get_post_meta($id,'system',true);
$entry->details = $details;
$entry->email = $email;
$entry->system = $system;
$flash = "<strong>Notification Saved Successfully!</strong><br /><a href='/wp-admin/admin.php?page=notifications'>Click here</a> to view all notifications.</a>";
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'form.php');
} else {
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'form.php');
}
} else {
if (isset($_GET['action']) && $_GET['action']=="delete") {
wp_delete_post($_GET['page_id'],true);
} elseif (isset($_GET['action']) && $_GET['action']=="archive") {
$id = $_GET['page_id'];
$postdata = get_post_meta($id,'details',true);
$postdata['status'] = "archived";
update_post_meta($id,'details',$postdata);
update_post_meta($id,'send_status',$postdata['status']);
}
}
// get all the notifications that status != "archived";
$notifications = array();
$notifications['triggered'] = array();
$notifications['scheduled'] = array();
$args = array(
'post_type' => 'notifications'
, 'numberposts' => -1
......@@ -186,45 +184,45 @@ function display_page() {
, 'meta_compare' => '='
, 'meta_value' => 'pending'
);
$entries = get_posts($args);
foreach($entries as $entry) {
$id = $entry->ID;
$details = get_post_meta($id,'details',true);
$email = get_post_meta($id,'email',true);
$system = get_post_meta($id,'system',true);
$entry->trigger = $details['trigger'];
$entry->status = isset($details['status']) ? $details['status'] : "active";
$entry->type = $details['type'];
$entry->sendto = $details['sendto'];
$entry->is_email = (($email['text'] != "" || $email['html'] != "")) ? true : false;
$entry->is_system = (isset($system['message']) && $system['message'] != "") ? true : false;
$entry->execute_date = $details['execute_date'];
if ($entry->status != "archived") {
$notifications[$entry->type][] = $entry;
}
}
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'admin.php');
}
}
}
function mysqldatetime_to_timestamp($datetime = "")
......@@ -273,59 +271,59 @@ function fixFilesArray(&$files)
function notification_settings() {
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'settings.php');
}
function create_notification() {
global $wpdb;
// here
$validation = new Notifications\Validation;
$validation->set_rules('type','Notification Type','required');
$validation->set_rules('title','Description','trim|required|min_length[16]');
$validation->set_rules('type','Notification Type','required');
$validation->set_rules('sendto','Send To','required');
$type_val = ($_POST && $_POST['type'] == "scheduled") ? 'required' : '';
$validation->set_rules('execute_date','Execute Date', $type_val);
$trigger_val = ($_POST && $_POST['type'] == "triggered") ? 'required' : '';
$validation->set_rules('trigger','Trigger',$trigger_val);
$validation->set_rules('subject','Subject','trim');
$validation->set_rules('text','Text Version','trim|min_length[16]');
$validation->set_rules('html','HTML Version','trim|min_length[16]');
$validation->set_rules('system','System Message','trim|min_length[16]');
if ($_POST && ($_POST['subject']=="" && $_POST['system']=="")) {
if ($_POST && ($_POST['subject']=="" && $_POST['system']=="")) {
$form_error = true;
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'create.php');
} else {
if ($validation->run() == TRUE) {
// ok, so now we need to create the notification.
class postTemplate {
var $post_title = '';
var $post_content = '';
var $post_status = 'publish';
var $post_type = 'notifications';
var $post_type = 'notifications';
var $comment_status = 'closed';
}
//details
$type = $_POST['type'];
$title = $_POST['title'];
$sendto = $_POST['sendto'];
$execute_date = ($type=="scheduled") ? $_POST['execute_date'] : "0000-00-00 00:00:00";
$trigger = ($type=="scheduled") ? "scheduled-cron-job" : $_POST['trigger'];
// email
$subject = $_POST['subject'];
$text = $_POST['text'];
......@@ -335,32 +333,32 @@ function create_notification() {
fixFilesArray($_FILES['attachment']);
foreach ($_FILES['attachment'] as $position => $file) {
// should output array with indices name, type, tmp_name, error, size
if($file['name'] != "") {
if($file['name'] != "") {
move_uploaded_file($file['tmp_name'],$upload_dir . $file['name']);
$attachments[] = $file['name'];
}
}
// system
$system_message_type = $_POST['system_message_type'];
$system = $_POST['system'];
// make post...
$notification = new postTemplate();
$notification->post_title = $title;
$notification->post_content = "Notification created ".date('Y-m-d H:i:s')." --- to be sent on $execute_date";
$notification->post_date_gmt = date("Y-m-d H:i:s",time());
$id = wp_insert_post($notification);
update_post_meta($id, 'notif_type', $type);
update_post_meta($id, 'execute_date', mysqldatetime_to_timestamp($execute_date));
update_post_meta($id, 'trigger', $trigger);
add_post_meta($id, "details", array(
'type' => $type
, 'sendto' => $sendto
......@@ -368,9 +366,9 @@ function create_notification() {
, 'trigger' => $trigger
, 'execute_date' => $execute_date
));
update_post_meta($id,'send_status','pending');
add_post_meta($id, "email", array(
'subject' => $subject
, 'text' => $text
......@@ -380,16 +378,16 @@ function create_notification() {
update_post_meta($id, "system", array(
'system_message_type' => $system_message_type
, 'message' => $system
));
));
$flash = "<strong>Notification Saved Successfully!</strong><br /><a href='/wp-admin/admin.php?page=notifications'>Click here</a> to view all notifications.</a>";
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'create.php');
} else {
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'create.php');
}
}
}
......@@ -398,7 +396,7 @@ class Actions {
public static function init() {
global $wpdb;
$wpdb->show_errors();
register_post_type( 'notifications', array(
'label' => __('Notifs')
, 'public' => true
......@@ -406,16 +404,16 @@ class Actions {
, 'hierarchical' => false
, 'exclude_from_search' => true
));
}
public static function admin_menu() {
add_menu_page('Notifications','Notifications',CAPABILITY,'notifications',__NAMESPACE__ . '\display_page' );
add_submenu_page('notifications','New Notification', 'New Notification',CAPABILITY,'notifications-create-new',__NAMESPACE__ . '\create_notification');
//add_options_page('CAN-SPAM Settings', 'CAN-SPAM Settings', CAPABILITY, ADMIN_PAGE, __NAMESPACE__ . '\notification_settings');
//add_submenu_page('notifications','CAN-SPAM Settings', 'CAN-SPAM Settings',CAPABILITY,'notifications-settings',__NAMESPACE__ . '\notification_settings');
//add_submenu_page('notifications','CAN-SPAM Settings', 'CAN-SPAM Settings',CAPABILITY,'notifications-settings',__NAMESPACE__ . '\notification_settings');
}
public function admin_init() {
// register_setting(Notifications\OPTION_NAME, Notifications\OPTION_NAME);
register_setting(SETTING_NS, SETTING_NS);
......
......@@ -8,22 +8,22 @@ use Tz\WordPress\Tools\Notifications;
class Validation {
protected $_field_data = array();
protected $_field_data = array();
protected $_config_rules = array();
protected $_error_array = array();
protected $_error_messages = array();
protected $_error_messages = array();
protected $_error_prefix = '<div class="lblError">';
protected $_error_suffix = '</div>';
protected $error_string = '';
protected $_safe_form_data = FALSE;
function __construct($rules = array())
{
{
// Validation rules can be stored in a config file.
$this->_config_rules = $rules;
$this->_config_rules = $rules;
}
public function get_error_message($key) {
$lang = array();
$lang['required'] = "The %s field is required.";
......@@ -44,19 +44,19 @@ class Validation {
$lang['matches'] = "The %s field does not match the %s field.";
$lang['is_natural'] = "The %s field must contain only positive numbers.";
$lang['is_natural_no_zero'] = "The %s field must contain a number greater than zero.";
if (isset($lang[$key])) {
return $lang[$key];
} else {
return FALSE;
}
}
// --------------------------------------------------------------------
/**
* Set Rules
*
......@@ -75,7 +75,7 @@ class Validation {
{
return;
}
// If an array was passed via the first parameter instead of indidual string
// values we cycle through it and recursively call this function.
if (is_array($field))
......@@ -96,7 +96,7 @@ class Validation {
}
return;
}
// No fields? Nothing to do...
if ( ! is_string($field) OR ! is_string($rules) OR $field == '')
{
......@@ -108,9 +108,9 @@ class Validation {
// Is the field name an array? We test for the existence of a bracket "[" in
// the field name to determine this. If it is an array, we break it apart
// into its components so that we can fetch the corresponding POST data later
// into its components so that we can fetch the corresponding POST data later
if (strpos($field, '[') !== FALSE AND preg_match_all('/\[(.*?)\]/', $field, $matches))
{
{
// Note: Due to a bug in current() that affects some versions
// of PHP we can not pass function call directly into it
$x = explode('[', $field);
......@@ -123,19 +123,19 @@ class Validation {
$indexes[] = $matches['1'][$i];
}
}
$is_array = TRUE;
}
else
{
$indexes = array();
$is_array = FALSE;
$is_array = FALSE;
}
// Build our master array
// Build our master array
$this->_field_data[$field] = array(
'field' => $field,
'label' => $label,
'field' => $field,
'label' => $label,
'rules' => $rules,
'is_array' => $is_array,
'keys' => $indexes,
......@@ -145,7 +145,7 @@ class Validation {
}
// --------------------------------------------------------------------
/**
* Set Error Message
*
......@@ -163,12 +163,12 @@ class Validation {
{
$lang = array($lang => $val);
}
$this->_error_messages = array_merge($this->_error_messages, $lang);
}
// --------------------------------------------------------------------
/**
* Set The Error Delimiter
*
......@@ -178,7 +178,7 @@ class Validation {
* @param string
* @param string
* @return void
*/
*/
function set_error_delimiters($prefix = '<p>', $suffix = '</p>')
{
$this->_error_prefix = $prefix;
......@@ -186,7 +186,7 @@ class Validation {
}
// --------------------------------------------------------------------
/**
* Get Error Message
*
......@@ -195,14 +195,14 @@ class Validation {
* @access public
* @param string the field name
* @return void
*/
*/
function error($field = '', $prefix = '', $suffix = '')
{
{
if ( ! isset($this->_field_data[$field]['error']) OR $this->_field_data[$field]['error'] == '')
{
return '';
}
if ($prefix == '')
{
$prefix = $this->_error_prefix;
......@@ -217,7 +217,7 @@ class Validation {
}
// --------------------------------------------------------------------
/**
* Error String
*
......@@ -227,7 +227,7 @@ class Validation {
* @param string
* @param string
* @return str
*/
*/
function error_string($prefix = '', $suffix = '')
{
// No errrors, validation passes!
......@@ -235,7 +235,7 @@ class Validation {
{
return '';
}
if ($prefix == '')
{
$prefix = $this->_error_prefix;
......@@ -245,7 +245,7 @@ class Validation {
{
$suffix = $this->_error_suffix;
}
// Generate the error string
$str = '';
foreach ($this->_error_array as $val)
......@@ -255,12 +255,12 @@ class Validation {
$str .= $prefix.$val.$suffix."\n";
}
}
return $str;
}
// --------------------------------------------------------------------
/**
* Run the Validator
*
......@@ -268,7 +268,7 @@ class Validation {
*
* @access public
* @return bool
*/
*/
function run($group = '')
{
// Do we even have any data to process? Mm?
......@@ -276,7 +276,7 @@ class Validation {
{
return FALSE;
}
// Does the _field_data array containing the validation rules exist?
// If not, we look to see if they were assigned via a config file
if (count($this->_field_data) == 0)
......@@ -286,10 +286,10 @@ class Validation {
{
return FALSE;
}
// Is there a validation rule for the particular URI being accessed?
$uri = ($group == '') ? trim($this->CI->uri->ruri_string(), '/') : $group;
if ($uri != '' AND isset($this->_config_rules[$uri]))
{
$this->set_rules($this->_config_rules[$uri]);
......@@ -298,21 +298,21 @@ class Validation {
{
$this->set_rules($this->_config_rules);
}
// We're we able to set the rules correctly?
if (count($this->_field_data) == 0)
{
return FALSE;
}
}
// Cycle through the rules for each field, match the
// Cycle through the rules for each field, match the
// corresponding $_POST item and test for errors
foreach ($this->_field_data as $field => $row)
{
{
// Fetch the data from the corresponding $_POST array and cache it in the _field_data array.
// Depending on whether the field name is an array or a string will determine where we get it from.
if ($row['is_array'] == TRUE)
{
$this->_field_data[$field]['postdata'] = $this->_reduce_array($_POST, $row['keys']);
......@@ -324,8 +324,8 @@ class Validation {
$this->_field_data[$field]['postdata'] = $_POST[$field];
}
}
$this->_execute($row, explode('|', $row['rules']), $this->_field_data[$field]['postdata']);
$this->_execute($row, explode('|', $row['rules']), $this->_field_data[$field]['postdata']);
}
// Did we end up with any errors?
......@@ -338,7 +338,7 @@ class Validation {
// Now we need to re-set the POST data with the new, processed data
$this->_reset_post_array();
// No errors, validation passes!
if ($total_errors == 0)
{
......@@ -350,7 +350,7 @@ class Validation {
}
// --------------------------------------------------------------------
/**
* Traverse a multidimensional $_POST array index until the data is found
*
......@@ -359,7 +359,7 @@ class Validation {
* @param array
* @param integer
* @return mixed
*/
*/
function _reduce_array($array, $keys, $i = 0)
{
if (is_array($array))
......@@ -380,18 +380,18 @@ class Validation {
return $array;
}
}
return $array;
}
// --------------------------------------------------------------------
/**
* Re-populate the _POST array with our finalized and processed data
*
* @access private
* @return null
*/
*/
function _reset_post_array()
{
foreach ($this->_field_data as $field => $row)
......@@ -409,7 +409,7 @@ class Validation {
{
// start with a reference
$post_ref =& $_POST;
// before we assign values, make a reference to the right POST key
if (count($row['keys']) == 1)
{
......@@ -443,7 +443,7 @@ class Validation {
}
// --------------------------------------------------------------------
/**
* Executes the Validation routines
*
......@@ -453,21 +453,21 @@ class Validation {
* @param mixed
* @param integer
* @return mixed
*/
*/
function _execute($row, $rules, $postdata = NULL, $cycles = 0)
{
// If the $_POST data is an array we will run a recursive call
if (is_array($postdata))
{
{
foreach ($postdata as $key => $val)
{
$this->_execute($row, $rules, $val, $cycles);
$cycles++;
}
return;
}
// --------------------------------------------------------------------
// If the field is blank, but NOT required, no further tests are necessary
......@@ -487,7 +487,7 @@ class Validation {
}
// --------------------------------------------------------------------
// Isset Test. Typically this rule will only apply to checkboxes.
if (is_null($postdata) AND $callback == FALSE)
{
......@@ -495,31 +495,31 @@ class Validation {
{
// Set the message type
$type = (in_array('required', $rules)) ? 'required' : 'isset';
if ( ! isset($this->_error_messages[$type]))
{
if (FALSE === ($line = $this->get_error_message($type)))
{
$line = 'The field was not set';
}
}
}
else
{
$line = $this->_error_messages[$type];
}
// Build the error message
$message = sprintf($line, $this->_translate_fieldname($row['label']));
// Save the error message
$this->_field_data[$row['field']]['error'] = $message;
if ( ! isset($this->_error_array[$row['field']]))
{
$this->_error_array[$row['field']] = $message;
}
}
return;
}
......@@ -529,7 +529,7 @@ class Validation {
foreach ($rules As $rule)
{
$_in_array = FALSE;
// We set the $postdata variable with the current data in our master array so that
// each cycle of the loop is dealing with the processed data from the last cycle
if ($row['is_array'] == TRUE AND is_array($this->_field_data[$row['field']]['postdata']))
......@@ -540,7 +540,7 @@ class Validation {
{
continue;
}
$postdata = $this->_field_data[$row['field']]['postdata'][$cycles];
$_in_array = TRUE;
}
......@@ -550,15 +550,15 @@ class Validation {
}
// --------------------------------------------------------------------
// Is the rule a callback?
// Is the rule a callback?
$callback = FALSE;
if (substr($rule, 0, 9) == 'callback_')
{
$rule = substr($rule, 9);
$callback = TRUE;
}
// Strip the parameter (if exists) from the rule
// Rules can contain a parameter: max_length[5]
$param = FALSE;
......@@ -567,15 +567,15 @@ class Validation {
$rule = $match[1];
$param = $match[2];
}
// Call the function that corresponds to the rule
if ($callback === TRUE)
{
if ( ! method_exists($this->CI, $rule))
{
{
continue;
}
// Run the function and grab the result
$result = $this->CI->$rule($postdata, $param);
......@@ -588,7 +588,7 @@ class Validation {
{
$this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result;
}
// If the field isn't required and we just processed a callback we'll move on...
if ( ! in_array('required', $rules, TRUE) AND $result !== FALSE)
{
......@@ -596,15 +596,15 @@ class Validation {
}
}
else
{
{
if ( ! method_exists($this, $rule))
{
// If our own wrapper function doesn't exist we see if a native PHP function does.
// If our own wrapper function doesn't exist we see if a native PHP function does.
// Users can use any native PHP function call that has one param.
if (function_exists($rule))
{
$result = $rule($postdata);
if ($_in_array == TRUE)
{
$this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata : $result;
......@@ -614,7 +614,7 @@ class Validation {
$this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result;
}
}
continue;
}
......@@ -629,40 +629,40 @@ class Validation {
$this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result;
}
}
// Did the rule test negatively? If so, grab the error.
if ($result === FALSE)
{
{
if ( ! isset($this->_error_messages[$rule]))
{
if (FALSE === ($line = $this->get_error_message($rule)))
{
$line = 'Unable to access an error message corresponding to your field name.';
}
}
}
else
{
$line = $this->_error_messages[$rule];
}
// Is the parameter we are inserting into the error message the name
// of another field? If so we need to grab its "field label"
if (isset($this->_field_data[$param]) AND isset($this->_field_data[$param]['label']))
{
$param = $this->_field_data[$param]['label'];
}
// Build the error message
$message = sprintf($line, $this->_translate_fieldname($row['label']), $param);
// Save the error message
$this->_field_data[$row['field']]['error'] = $message;
if ( ! isset($this->_error_array[$row['field']]))
{
$this->_error_array[$row['field']] = $message;
}
return;
}
}
......@@ -670,25 +670,25 @@ class Validation {
function form_error($field = '', $prefix = '', $suffix = '')
{
return $this->error($field, $prefix, $suffix);
}
function validation_errors($prefix = '', $suffix = '')
{
return $this->error_string($prefix, $suffix);
}
// --------------------------------------------------------------------
/**
* Translate a field name
*
* @access private
* @param string the field name
* @return string
*/
*/
function _translate_fieldname($fieldname)
{
// Do we need to translate the field name?
......@@ -696,8 +696,8 @@ class Validation {
if (substr($fieldname, 0, 5) == 'lang:')
{
// Grab the variable
$line = substr($fieldname, 5);
$line = substr($fieldname, 5);
// Were we able to translate the field name? If not we use $line
if (FALSE === ($fieldname = $this->get_error_message($line)))
{
......@@ -709,7 +709,7 @@ class Validation {
}
// --------------------------------------------------------------------
/**
* Get the value from a form
*
......@@ -720,19 +720,19 @@ class Validation {
* @param string the field name
* @param string
* @return void
*/
*/
function set_value($field = '', $default = '')
{
if ( ! isset($this->_field_data[$field]))
{
return $default;
}
return $this->_field_data[$field]['postdata'];
}
// --------------------------------------------------------------------
/**
* Set Select
*
......@@ -743,9 +743,9 @@ class Validation {
* @param string
* @param string
* @return string
*/
*/
function set_select($field = '', $value = '', $default = FALSE)
{
{
if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata']))
{
if ($default === TRUE AND count($this->_field_data) === 0)
......@@ -754,9 +754,9 @@ class Validation {
}
return '';
}
$field = $this->_field_data[$field]['postdata'];
if (is_array($field))
{
if ( ! in_array($value, $field))
......@@ -771,12 +771,12 @@ class Validation {
return '';
}
}
return ' selected="selected"';
}
// --------------------------------------------------------------------
/**
* Set Radio
*
......@@ -787,7 +787,7 @@ class Validation {
* @param string
* @param string
* @return string
*/
*/
function set_radio($field = '', $value = '', $default = FALSE)
{
if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata']))
......@@ -798,9 +798,9 @@ class Validation {
}
return '';
}
$field = $this->_field_data[$field]['postdata'];
if (is_array($field))
{
if ( ! in_array($value, $field))
......@@ -815,12 +815,12 @@ class Validation {
return '';
}
}
return ' checked="checked"';
}
// --------------------------------------------------------------------
/**
* Set Checkbox
*
......@@ -831,7 +831,7 @@ class Validation {
* @param string
* @param string
* @return string
*/
*/
function set_checkbox($field = '', $value = '', $default = FALSE)
{
if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata']))
......@@ -842,9 +842,9 @@ class Validation {
}
return '';
}
$field = $this->_field_data[$field]['postdata'];
if (is_array($field))
{
if ( ! in_array($value, $field))
......@@ -859,12 +859,12 @@ class Validation {
return '';
}
}
return ' checked="checked"';
}
// --------------------------------------------------------------------
/**
* Required
*
......@@ -883,9 +883,9 @@ class Validation {
return ( ! empty($str));
}
}
// --------------------------------------------------------------------
/**
* Match one field to another
*
......@@ -898,16 +898,16 @@ class Validation {
{
if ( ! isset($_POST[$field]))
{
return FALSE;
return FALSE;
}
$field = $_POST[$field];
return ($str !== $field) ? FALSE : TRUE;
}
// --------------------------------------------------------------------
/**
* Minimum Length
*
......@@ -915,7 +915,7 @@ class Validation {
* @param string
* @param value
* @return bool
*/
*/
function min_length($str, $val)
{
if (preg_match("/[^0-9]/", $val))
......@@ -925,14 +925,14 @@ class Validation {
if (function_exists('mb_strlen'))
{
return (mb_strlen($str) < $val) ? FALSE : TRUE;
return (mb_strlen($str) < $val) ? FALSE : TRUE;
}
return (strlen($str) < $val) ? FALSE : TRUE;
}
// --------------------------------------------------------------------
/**
* Max Length
*
......@@ -940,7 +940,7 @@ class Validation {
* @param string
* @param value
* @return bool
*/
*/
function max_length($str, $val)
{
if (preg_match("/[^0-9]/", $val))
......@@ -950,14 +950,14 @@ class Validation {
if (function_exists('mb_strlen'))
{
return (mb_strlen($str) > $val) ? FALSE : TRUE;
return (mb_strlen($str) > $val) ? FALSE : TRUE;
}
return (strlen($str) > $val) ? FALSE : TRUE;
}
// --------------------------------------------------------------------
/**
* Exact Length
*
......@@ -965,7 +965,7 @@ class Validation {
* @param string
* @param value
* @return bool
*/
*/
function exact_length($str, $val)
{
if (preg_match("/[^0-9]/", $val))
......@@ -975,42 +975,42 @@ class Validation {
if (function_exists('mb_strlen'))
{
return (mb_strlen($str) != $val) ? FALSE : TRUE;
return (mb_strlen($str) != $val) ? FALSE : TRUE;
}
return (strlen($str) != $val) ? FALSE : TRUE;
}
// --------------------------------------------------------------------
/**
* Valid Email
*
* @access public
* @param string
* @return bool
*/
*/
function valid_email($str)
{
return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
}
// --------------------------------------------------------------------
/**
* Valid Emails
*
* @access public
* @param string
* @return bool
*/
*/
function valid_emails($str)
{
if (strpos($str, ',') === FALSE)
{
return $this->valid_email(trim($str));
}
foreach(explode(',', $str) as $email)
{
if (trim($email) != '' && $this->valid_email(trim($email)) === FALSE)
......@@ -1018,12 +1018,12 @@ class Validation {
return FALSE;
}
}
return TRUE;
}
// --------------------------------------------------------------------
/**
* Validate IP Address
*
......@@ -1037,56 +1037,56 @@ class Validation {
}
// --------------------------------------------------------------------
/**
* Alpha
*
* @access public
* @param string
* @return bool
*/
*/
function alpha($str)
{
return ( ! preg_match("/^([a-z])+$/i", $str)) ? FALSE : TRUE;
}
// --------------------------------------------------------------------
/**
* Alpha-numeric
*
* @access public
* @param string
* @return bool
*/
*/
function alpha_numeric($str)
{
return ( ! preg_match("/^([a-z0-9])+$/i", $str)) ? FALSE : TRUE;
}
// --------------------------------------------------------------------
/**
* Alpha-numeric with underscores and dashes
*
* @access public
* @param string
* @return bool
*/
*/
function alpha_dash($str)
{
return ( ! preg_match("/^([-a-z0-9_-])+$/i", $str)) ? FALSE : TRUE;
}
// --------------------------------------------------------------------
/**
* Numeric
*
* @access public
* @param string
* @return bool
*/
*/
function numeric($str)
{
return (bool)preg_match( '/^[\-+]?[0-9]*\.?[0-9]+$/', $str);
......@@ -1105,22 +1105,22 @@ class Validation {
function is_numeric($str)
{
return ( ! is_numeric($str)) ? FALSE : TRUE;
}
}
// --------------------------------------------------------------------
/**
* Integer
*
* @access public
* @param string
* @return bool
*/
*/
function integer($str)
{
return (bool)preg_match( '/^[\-+]?[0-9]+$/', $str);
}
// --------------------------------------------------------------------
/**
......@@ -1131,7 +1131,7 @@ class Validation {
* @return bool
*/
function is_natural($str)
{
{
return (bool)preg_match( '/^[0-9]+$/', $str);
}
......@@ -1150,17 +1150,17 @@ class Validation {
{
return FALSE;
}
if ($str == 0)
{
return FALSE;
}
return TRUE;
}
// --------------------------------------------------------------------
/**
* Valid Base64
*
......@@ -1175,9 +1175,9 @@ class Validation {
{
return (bool) ! preg_match('/[^a-zA-Z0-9\/\+=]/', $str);
}
// --------------------------------------------------------------------
/**
* Prep data for form
*
......@@ -1196,10 +1196,10 @@ class Validation {
{
$data[$key] = $this->prep_for_form($val);
}
return $data;
}
if ($this->_safe_form_data == FALSE OR $data === '')
{
return $data;
......@@ -1207,68 +1207,68 @@ class Validation {
return str_replace(array("'", '"', '<', '>'), array("&#39;", "&quot;", '&lt;', '&gt;'), stripslashes($data));
}
// --------------------------------------------------------------------
/**
* Prep URL
*
* @access public
* @param string
* @return string
*/
*/
function prep_url($str = '')
{
if ($str == 'http://' OR $str == '')
{
return '';
}
if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://')
{
$str = 'http://'.$str;
}
return $str;
}
// --------------------------------------------------------------------
/**
* Strip Image Tags
*
* @access public
* @param string
* @return string
*/
*/
function strip_image_tags($str)
{
return $this->CI->input->strip_image_tags($str);
}
// --------------------------------------------------------------------
/**
* XSS Clean
*
* @access public
* @param string
* @return string
*/
*/
function xss_clean($str)
{
return $this->CI->input->xss_clean($str);
}
// --------------------------------------------------------------------
/**
* Convert PHP tags to entities
*
* @access public
* @param string
* @return string
*/
*/
function encode_php_tags($str)
{
return str_replace(array('<?php', '<?PHP', '<?', '?>'), array('&lt;?php', '&lt;?PHP', '&lt;?', '?&gt;'), $str);
......
......@@ -4,7 +4,7 @@ use Tz\WordPress\Tools\Notifications;
use Tz\WordPress\Tools;
?>
<link type="text/css" href="<?php echo Tools\url('assets/css/smoothness/jquery-ui-1.8.4.custom.css', __FILE__)?>" rel="stylesheet" />
<link type="text/css" href="<?php echo Tools\url('assets/css/smoothness/jquery-ui-1.8.4.custom.css', __FILE__)?>" rel="stylesheet" />
<script type="text/javascript" src="<?php echo Tools\url('assets/scripts/jquery-1.4.2.min.js', __FILE__)?>"></script>
<script type="text/javascript" src="<?php echo Tools\url('assets/scripts/jquery-ui-1.8.4.custom.min.js', __FILE__)?>"></script>
<script type="text/javascript" src="<?php echo Tools\url('assets/scripts/datetimepicker.js', __FILE__)?>"></script>
......@@ -13,7 +13,7 @@ use Tz\WordPress\Tools;
<div id="" class="wrap">
<h2>Notifications - Edit</h2>
<?php if (isset($flash) && $flash !=""): ?>
<div class="post-success">
<?php echo $flash; ?>
......@@ -27,15 +27,15 @@ use Tz\WordPress\Tools;
<?php endif; ?>
</div>
<?php endif;?>
<form enctype="multipart/form-data" method="post" action="/wp-admin/admin.php?page=notifications&action=edit&page_id=<?php echo $_GET['page_id']?>">
<input type="hidden" name="_POSTED_" value="yes" />
<table cellspacing="0" class="widefat post fixed" style="margin-top:15px;">
<thead>
<tr>
......@@ -63,7 +63,7 @@ use Tz\WordPress\Tools;
<tr class="scheduled_sendto">
<td>Sent To:</td>
<td>
<?php
if ($entry->details['sendto'] == "report" ): ?>
<input type="hidden" name="sendto" value="<?php echo $entry->details['sendto']; ?>"/>
......@@ -78,25 +78,25 @@ use Tz\WordPress\Tools;
</optgroup>
</select>
<?php endif; ?>
<?php echo $validation->form_error('sendto');?>
</td>
</tr>
<tr class="scheduled-extended">
<td>Execute Date / Time</td>
<td><input type="text" name="execute_date" id="execute_date" class="wide-input-field date-pick" readonly="readonly" value="<?php echo $validation->set_value('execute_date',$entry->details['execute_date']);?>" /><?php echo $validation->form_error('execute_date');?></td>
</tr>
<tr class="trigger-extended">
<td>Trigger</td>
<td><input type="text" name="trigger" id="trigger" class="wide-input-field" value="<?php echo $validation->set_value('trigger',$entry->details['trigger']);?>" /><?php echo $validation->form_error('trigger');?></td>
</tr>
</tbody>
</table>
<table cellspacing="0" class="widefat post fixed expandable" style="margin-top:15px;">
<thead>
<tr>
......@@ -117,12 +117,12 @@ use Tz\WordPress\Tools;
<td>HTML Version (optional)</td>
<td><textarea name="html" id="htmlversion" class="wide-input-field" rows="10" style="width:100%;"><?php echo $validation->set_value('html',$entry->email['html']);?></textarea><?php echo $validation->form_error('html');?></td>
</tr>
<tr>
<td width="150">Attachments</td>
<td>&nbsp;</td>
</tr>
<?php
$attachements = $entry->email['attachments'];
$allowed_attachments = 3;
......@@ -132,18 +132,18 @@ use Tz\WordPress\Tools;
<td><?php echo $attachment; ?> &nbsp; (<a href="#" entry_id="<?php echo $_GET['page_id']?>" class="attachment" rel="<?php echo $attachment; ?>">remove</a>)</td>
</tr>
<?php $allowed_attachments--; endforeach; ?>
<?php for($a = 1; $a <= $allowed_attachments; $a++): ?>
<tr>
<td>&nbsp;</td>
<td><input type="file" name="attachment[]" /></td>
</tr>
<?php endfor; ?>
</tbody>
</table>
<table cellspacing="0" class="widefat post fixed expandable" style="margin-top:15px;">
<thead>
<tr>
......@@ -169,15 +169,15 @@ use Tz\WordPress\Tools;
</tr>
</tbody>
</table>
<p>
<input type="submit" value=" Update " /><input type="button" value=" Cancel " onclick="document.location.href='/wp-admin/admin.php?page=notifications';" />
</p>
</form>
</div>
<script type="text/javascript">
......@@ -190,9 +190,9 @@ jQuery(document).ready(function($) {
, dateFormat: 'yy-mm-dd'
, timeFormat: 'hh:mm:ss'
});
updateNotificationType();
$('.attachment').live('click', function(e) {
e.preventDefault();
var $link = $(this);
......@@ -202,11 +202,11 @@ jQuery(document).ready(function($) {
, id: $link.attr('entry_id')
, file: $link.attr('rel')
};
var file_element = '<input type="file" name="attachment[]" />';
var c = confirm('Are you sure you want to remove this attachment?');
if (c) {
$.ajax({
......@@ -221,11 +221,11 @@ jQuery(document).ready(function($) {
}
});
}
return false;
});
//jQuery('table.expandable tbody').hide();
jQuery('table.expandable thead th').click(function() {
var $table = jQuery(this).parent().parent().parent();
......@@ -237,12 +237,12 @@ jQuery(document).ready(function($) {
jQuery('tbody',$table).fadeIn();
}
});
});
function updateNotificationType() {
var type = jQuery('#notif_type').val();
if (type=="triggered") {
jQuery('.scheduled-extended').hide();
jQuery('.trigger-extended').show();
......@@ -252,9 +252,6 @@ function updateNotificationType() {
jQuery('.trigger-extended').hide();
jQuery('.scheduled_sendto').show();
}
}
}
</script>
\ No newline at end of file
......