/** 
  * 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;
 }
예제 #2
0
 /**
  * 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;
 }