/** * Updates fields and custom fields used by this widget * * @return Boolean * @access private */ function updateFields($args) { extract($args); if (is_array($this->fields) || is_array($this->customFields)) { if (TDOMF_Widget::isEditForm($mode)) { $edit = tdomf_get_edit($edit_id); if (is_array($this->fields)) { if (!isset($edit->data[TDOMF_KEY_FIELDS]) || !is_array($edit->data[TDOMF_KEY_FIELDS])) { $edit->data[TDOMF_KEY_FIELDS] = $this->fields; } else { $currentFields = array_merge($edit->data[TDOMF_KEY_FIELDS], $this->fields); $edit->data[TDOMF_KEY_FIELDS] = $currentFields; } } if (is_array($this->customFields)) { if (!isset($edit->data[TDOMF_KEY_CUSTOM_FIELDS]) || !is_array($edit->data[TDOMF_KEY_CUSTOM_FIELDS])) { $edit->data[TDOMF_KEY_CUSTOM_FIELDS] = $this->customFields; } else { $currentFields = array_merge($edit->data[TDOMF_KEY_CUSTOM_FIELDS], $this->customFields); $edit->data[TDOMF_KEY_CUSTOM_FIELDS] = $currentFields; } } // do update once tdomf_set_data_edit($edit->data, $edit_id); // update the post id and not revision's list $id = $edit->post_id; } else { // submit form, so just update the post $id = $post_ID; } if (is_array($this->fields)) { $currentFields = get_post_meta($id, TDOMF_KEY_FIELDS, true); if (!is_array($currentFields)) { add_post_meta($id, TDOMF_KEY_FIELDS, $this->fields, true); } else { $currentFields = array_merge($currentFields, $this->fields); update_post_meta($id, TDOMF_KEY_FIELDS, $currentFields); } } if (is_array($this->customFields)) { $currentFields = get_post_meta($id, TDOMF_KEY_CUSTOM_FIELDS, true); if (!is_array($currentFields)) { add_post_meta($id, TDOMF_KEY_CUSTOM_FIELDS, $this->customFields, true); } else { $currentFields = array_merge($currentFields, $this->customFields); update_post_meta($id, TDOMF_KEY_CUSTOM_FIELDS, $currentFields); } } } return true; }
/** * Validate widget input * * @access public * @return Mixed */ function validate($args, $options, $preview) { if ($preview) { return NULL; } extract($args); $form_data = tdomf_get_form_data($tdomf_form_id); $form_tag = $tdomf_form_id; if (TDOMF_Widget::isEditForm($mode, $tdomf_form_id)) { $form_tag = $tdomf_form_id . '_' . $tdomf_post_id; } // all freeCap words are lowercase. // font #4 looks uppercase, but trust me, it's not... if ($form_data['hash_func_' . $form_tag](strtolower($args["imagecaptcha_" . $form_tag])) == $form_data['freecap_word_hash_' . $form_tag]) { // reset freeCap session vars // cannot stress enough how important it is to do this // defeats re-use of known image with spoofed session id $form_data['freecap_attempts_' . $form_tag] = 0; $form_data['freecap_word_hash_' . $form_tag] = false; tdomf_save_form_data($tdomf_form_id, $form_data); } else { return __("You must enter the word in the image as you see it.", "tdomf"); } return NULL; }
/** * Validate widget input * * @access public * @return Mixed */ function validate($args, $options, $preview) { if (!$options['title-enable'] && !$options['text-enable']) { return ""; } extract($args); $output = ""; if (TDOMF_Widget::isEditForm($mode, $tdomf_form_id)) { // when it goes to validation, the tdomf_post_id will be the // real post id $post =& get_post($tdomf_post_id); // set default texts to the original post contents $options['content-text-default-text'] = $post->post_content; $options['content-title-default-text'] = $post->post_title; } if ($options['title-enable']) { $tf_output = $this->textfield->validate($args, $options, $preview, 'content_title'); if (!empty($tf_output)) { if ($output != "") { $output .= "<br/>"; } $output .= $tf_output; } } if ($options['text-enable']) { $ta_output = $this->textarea->validate($args, $options, $preview, 'content_content'); if (!empty($ta_output)) { if ($output != "") { $output .= "<br/>"; } $output .= $ta_output; } } // return output if any if ($output != "") { return $output; } else { return NULL; } }
/** * Process form input for widget * * @access public * @return Mixed */ function post($args, $options) { global $current_user; get_currentuserinfo(); extract($args); // if sumbitting a new post (as opposed to editing) // make sure to *append* to post_content. For editing, overwrite. // if (TDOMF_Widget::isEditForm($mode)) { $edit_data = tdomf_get_data_edit($edit_id); if (isset($whoami_name)) { $edit_data[TDOMF_KEY_NAME] = tdomf_protect_input($whoami_name); } else { $whoami_name = ""; } if (isset($whoami_webpage)) { $edit_data[TDOMF_KEY_WEB] = $whoami_webpage; } else { $whoami_webpage = ""; } if (isset($whoami_email)) { $edit_data[TDOMF_KEY_EMAIL] = $whoami_email; } else { $whoami_email = ""; } if (is_user_logged_in()) { if ($current_user->ID != get_option(TDOMF_DEFAULT_AUTHOR)) { $edit_data[TDOMF_KEY_USER_ID] = $current_user->ID; $edit_data[TDOMF_KEY_USER_NAME] = $current_user->user_login; $edit_data[TDOMF_KEY_NAME] = $current_user->display_name; $edit_data[TDOMF_KEY_EMAIL] = $current_user->user_email; $edit_data[TDOMF_KEY_WEB] = $current_user->user_url; update_usermeta($current_user->ID, TDOMF_KEY_FLAG, true); } } tdomf_set_data_edit($edit_data, $edit_id); } else { if (isset($whoami_name)) { add_post_meta($post_ID, TDOMF_KEY_NAME, tdomf_protect_input($whoami_name), true); } else { $whoami_name = ""; } if (isset($whoami_webpage)) { add_post_meta($post_ID, TDOMF_KEY_WEB, $whoami_webpage, true); } else { $whoami_webpage = ""; } if (isset($whoami_email)) { add_post_meta($post_ID, TDOMF_KEY_EMAIL, $whoami_email, true); } else { $whoami_email = ""; } if (is_user_logged_in()) { if ($current_user->ID != get_option(TDOMF_DEFAULT_AUTHOR)) { add_post_meta($post_ID, TDOMF_KEY_USER_ID, $current_user->ID, true); add_post_meta($post_ID, TDOMF_KEY_USER_NAME, $current_user->user_login, true); add_post_meta($post_ID, TDOMF_KEY_NAME, $current_user->display_name, true); add_post_meta($post_ID, TDOMF_KEY_EMAIL, $current_user->user_email, true); add_post_meta($post_ID, TDOMF_KEY_WEB, $current_user->user_url, true); update_usermeta($current_user->ID, TDOMF_KEY_FLAG, true); } } } TDOMF_WidgetWhoami::tdomf_widget_whoami_store_cookies(tdomf_protect_input($whoami_name), $whoami_email, $whoami_webpage); return NULL; }
function formHack($args, $options, $postfix = '') { $output = ""; $field = $this->getField($options['type'], $this->index); if ($field != false) { extract($args); $options = $this->updateFieldOptions($options, $options['type'], $this->index); if (TDOMF_Widget::isEditForm($mode, $tdomf_form_id)) { #$fieldPrefix = $this->getFieldPrefix($options['type'],$this->index); $original_value = get_post_meta($args['post_ID'], $options['key'], true); $output .= "\t\t" . '<?php if(strpos($mode,\'-preview\') === false) {' . "\n"; $output .= "\t\t\t" . '$post = get_post($post_id); if($post) {' . "\n"; $output .= "\t\t\t\t" . 'if(!isset($post_args[\'' . $field->getId() . '\'])) {' . "\n"; $output .= "\t\t\t\t\t" . '$post_args[\'' . $field->getId() . '\'] = get_post_meta($post_id,\'' . $options['key'] . '\',true); }' . "\n"; $output .= "\t\t" . '} } ?>' . "\n\n"; } $output .= $field->formHack($args, $options); } else { tdomf_log_message('TDOMF_WidgetCustomFields->formHack(): ERROR: Cant find field', TDOMF_LOG_ERROR); } return $output; }
function tdomf_get_message_default($key, $mode) { switch ($key) { case TDOMF_OPTION_MSG_SUB_PUBLISH: $retVal = __("Your submission \"%%SUBMISSIONTITLE%%\" has been automatically published. You can see it <a href='%%SUBMISSIONURL%%'>here</a>. Thank you for using this service.", "tdomf"); break; case TDOMF_OPTION_MSG_SUB_FUTURE: $retVal = __("Your submission has been accepted and will be published on %%SUBMISSIONDATE%% at %%SUBMISSIONTIME%%. Thank you for using this service.", "tdomf"); break; case TDOMF_OPTION_MSG_SUB_SPAM: $retVal = __("Your submission is being flagged as spam! Sorry", "tdomf"); break; case TDOMF_OPTION_MSG_SUB_MOD: $retVal = __("Your post submission has been added to the moderation queue. It should appear in the next few days. Thank you for using this service.", "tdomf"); break; case TDOMF_OPTION_MSG_SUB_ERROR: $retVal = __("Your submission contained errors:<br/><br/>%%SUBMISSIONERRORS%%<br/><br/>Please correct and resubmit.", "tdomf"); break; case TDOMF_OPTION_MSG_PERM_BANNED_USER: $retVal = __("You (%%USERNAME%%) are banned from using this form.", "tdomf"); break; case TDOMF_OPTION_MSG_PERM_BANNED_IP: $retVal = __("Your IP %%IP%% does not currently have permissions to use this form.", "tdomf"); break; case TDOMF_OPTION_MSG_PERM_THROTTLE: $retVal = __("You have hit your submissions quota. Please wait until your existing submissions are approved.", "tdomf"); break; case TDOMF_OPTION_MSG_PERM_INVALID_USER: $retVal = __("You (%%USERNAME%%) do not currently have permissions to use this form.", "tdomf"); break; case TDOMF_OPTION_MSG_PERM_INVALID_NOUSER: $retVal = __("Unregistered users do not currently have permissions to use this form.", "tdomf"); break; case TDOMF_OPTION_ADD_EDIT_LINK_TEXT: $retVal = __("Edit", "tdomf"); break; case TDOMF_OPTION_MSG_INVALID_POST: $retVal = __("That post you are attempting to edit is invalid", 'tdomf'); break; case TDOMF_OPTION_MSG_INVALID_FORM: $retVal = __("You cannot use this form to edit this post", 'tdomf'); break; case TDOMF_OPTION_MSG_SPAM_EDIT_ON_POST: $retVal = __("You cannot edit this post as there is a pending contribution to be resolved.", 'tdomf'); break; case TDOMF_OPTION_MSG_UNAPPROVED_EDIT_ON_POST: $retVal = __("You cannot edit this post as there is a pending contribution to be approved.", 'tdomf'); break; case TDOMF_OPTION_MSG_LOCKED_POST: $retVal = __("You cannot edit this post as it has been locked from editing.", 'tdomf'); break; default: $retVal = ""; break; } // Edit form changes some of the defaults if ($mode && TDOMF_Widget::isEditForm($mode)) { switch ($key) { case TDOMF_OPTION_MSG_SUB_PUBLISH: $retVal = __("Your contribution on post \"%%SUBMISSIONTITLE%%\" has been automatically approved. You can see it <a href='%%SUBMISSIONURL%%'>here</a>. Thank you for using this service.", "tdomf"); break; case TDOMF_OPTION_MSG_SUB_FUTURE: $retVal = __("Your contribution has been approved and will be published on %%SUBMISSIONDATE%% at %%SUBMISSIONTIME%%. Thank you for using this service.", "tdomf"); break; case TDOMF_OPTION_MSG_SUB_SPAM: $retVal = __("Your contribution has being flagged as spam! Sorry", "tdomf"); break; case TDOMF_OPTION_MSG_SUB_MOD: $retVal = __("Your contribution has been added to the moderation queue. It should appear in the next few days. Thank you for using this service.", "tdomf"); break; case TDOMF_OPTION_MSG_SUB_ERROR: $retVal = __("Your contribution contained errors:<br/><br/>%%SUBMISSIONERRORS%%<br/><br/>Please correct and resubmit.", "tdomf"); break; case TDOMF_OPTION_MSG_PERM_THROTTLE: $retVal = __("You have hit your contributions quota. Please wait until your existing contributions are approved.", "tdomf"); break; } } return $retVal; }