コード例 #1
0
 /**
  * returns an element value formatted for display or storage
  * 
  * this supplants the function Participants_Db::prep_field_for_display
  * 
  * @param object $field a Field_Item object
  * @param bool   $html  if true, retuns the value wrapped in HTML, false returns 
  *                      the formatted value alone
  * @return string the object's current value, formatted
  */
 public static function get_field_value_display($field, $html = true)
 {
     $return = '';
     if (has_filter(Participants_Db::$prefix . 'before_display_field')) {
         $return = Participants_Db::set_filter('before_display_field', $return, $field->value, $field->form_element);
     }
     if (empty($return)) {
         switch ($field->form_element) {
             case 'image-upload':
                 $image = new PDb_Image(array('filename' => $field->value, 'link' => isset($field->link) ? $field->link : '', 'mode' => 'both', 'module' => $field->module));
                 if ($html) {
                     if (isset($field->module) and in_array($field->module, array('single', 'list'))) {
                         $image->display_mode = 'image';
                     } elseif (isset($field->module) and in_array($field->module, array('signup', 'admin-edit'))) {
                         $image->display_mode = $image->image_defined ? 'both' : 'none';
                         $image->link = false;
                     }
                     $image->set_image_wrap();
                     $return = $image->get_image_html();
                 } elseif ($image->file_exists) {
                     $return = $image->get_image_file();
                 } else {
                     $return = $field->value;
                 }
                 break;
             case 'file-upload':
                 if ($html and !empty($field->value)) {
                     if ($field->module == 'signup') {
                         $field->link = false;
                         $return = $field->value;
                     } else {
                         $field->link = xnau_Image_Handler::concatenate_directory_path(get_bloginfo('url'), Participants_Db::$plugin_options['image_upload_location']) . $field->value;
                         $return = self::make_link($field);
                     }
                     break;
                 } else {
                     $return = $field->value;
                     break;
                 }
             case 'date':
             case 'timestamp':
                 $return = '';
                 if (self::is_empty($field->value) === false) {
                     $date = Participants_Db::parse_date($field->value, $field);
                     $format = Participants_Db::$date_format;
                     if (Participants_Db::$plugin_options['show_time'] == '1' and $field->form_element == 'timestamp') {
                         $format .= ' ' . get_option('time_format');
                     }
                     $return = date_i18n($format, $date);
                 } else {
                     $return = '';
                 }
                 break;
             case 'multi-checkbox':
             case 'multi-select-other':
                 /*
                  * these elements are stored as serialized arrays of values, the data is displayed 
                  * a comma-separated string of the values, using the value titles if defined
                  */
                 $multivalues = Participants_Db::unserialize_array($field->value);
                 // remove empty elements and convert to string for display
                 $multivalues = array_filter((array) $multivalues, array(__CLASS__, 'is_displayable'));
                 $titles = array();
                 foreach ($multivalues as $value) {
                     $titles[] = self::get_value_title($value, $field->name);
                 }
                 $return = implode(', ', $titles);
                 break;
             case 'link':
                 $linkdata = Participants_Db::unserialize_array($field->value);
                 if (!is_array($linkdata)) {
                     $return = '';
                     break;
                 }
                 if (empty($linkdata[1])) {
                     $linkdata[1] = str_replace('http://', '', $linkdata[0]);
                 }
                 if ($html) {
                     $return = vsprintf(empty($linkdata[0]) ? '%1$s%2$s' : '<a href="%1$s">%2$s</a>', $linkdata);
                 } else {
                     $return = $linkdata[0];
                 }
                 break;
             case 'text-line':
                 if ($html) {
                     $field->value = self::get_value_title($field->value, $field->name);
                     $return = self::make_link($field);
                     break;
                 } else {
                     $return = $field->value;
                     break;
                 }
             case 'text-area':
             case 'textarea':
                 $return = sprintf('<span class="textarea">%s</span>', $field->value);
                 break;
             case 'rich-text':
                 $return = sprintf('<span class="textarea richtext">%s</span>', Participants_Db::process_rich_text($field->value));
                 break;
             default:
                 $field->value = self::get_value_title($field->value, $field->name);
                 $return = self::make_link($field);
         }
     }
     return $return;
 }
コード例 #2
0
 /**
  * returns an element value formatted for display or storage
  * 
  * this supplants the function Participants_Db::prep_field_for_display
  * 
  * @param object $field a Field_Item object
  * @param bool   $html  if true, retuns the value wrapped in HTML, false returns 
  *                      the formatted value alone
  * @return string the object's current value, formatted
  */
 public static function get_field_value_display($field, $html = true)
 {
     $return = '';
     /**
      * filter: pdb-before_display_form_element
      * 
      * @since 1.6
      * 
      * @param string $return the value display
      * @param object $field the field object
      * 
      * formerly, this was set as "pdb-before_display_field" and included a more limited set of arguments
      */
     if (has_filter(Participants_Db::$prefix . 'before_display_form_element')) {
         $return = Participants_Db::set_filter('before_display_form_element', $return, $field);
     } elseif (has_filter(Participants_Db::$prefix . 'before_display_field')) {
         // provided for backward-compatibility
         $return = Participants_Db::set_filter('before_display_field', $return, $field->value, $field->form_element);
     }
     if (empty($return)) {
         switch ($field->form_element) {
             case 'image-upload':
                 $image = new PDb_Image(array('filename' => $field->value, 'link' => isset($field->link) ? $field->link : false, 'mode' => 'both', 'module' => $field->module));
                 if ($html) {
                     if (isset($field->module) and in_array($field->module, array('single', 'list'))) {
                         $image->display_mode = 'image';
                     } elseif (isset($field->module) and in_array($field->module, array('signup'))) {
                         $image->display_mode = $image->image_defined ? 'both' : 'none';
                         $image->link = false;
                     }
                     $image->set_image_wrap();
                     $return = $image->get_image_html();
                 } elseif ($image->file_exists) {
                     $return = $image->get_image_file();
                 } else {
                     $return = $field->value;
                 }
                 break;
             case 'file-upload':
                 if ($html and !empty($field->value)) {
                     if ($field->module == 'signup') {
                         $field->link = false;
                         $return = $field->value;
                     } else {
                         $field->link = PDb_Path::files_uri() . $field->value;
                         $return = self::make_link($field);
                     }
                     break;
                 } else {
                     $return = $field->value;
                     break;
                 }
             case 'date':
             case 'timestamp':
                 $return = '';
                 if (self::is_empty($field->value) === false) {
                     $date = Participants_Db::parse_date($field->value, $field);
                     $format = Participants_Db::$date_format;
                     if (Participants_Db::plugin_setting_is_true('show_time') and $field->form_element === 'timestamp') {
                         $format .= ' ' . get_option('time_format');
                     }
                     $return = date_i18n($format, $date);
                 } else {
                     $return = '';
                 }
                 break;
             case 'multi-checkbox':
             case 'multi-select-other':
                 /*
                  * these elements are stored as serialized arrays of values, the data is displayed 
                  * a comma-separated string of the values, using the value titles if defined
                  */
                 $return = self::array_display($field);
                 break;
             case 'link':
                 $linkdata = maybe_unserialize($field->value);
                 if (!is_array($linkdata)) {
                     $return = '';
                     break;
                 }
                 if (empty($linkdata[1])) {
                     $linkdata[1] = str_replace('http://', '', $linkdata[0]);
                 }
                 if ($html) {
                     $return = vsprintf(empty($linkdata[0]) ? '%1$s%2$s' : '<a href="%1$s">%2$s</a>', $linkdata);
                 } else {
                     $return = $linkdata[0];
                 }
                 break;
             case 'text-line':
                 if ($html) {
                     $field->value = self::get_value_title($field->value, $field->name);
                     $return = self::make_link($field);
                     break;
                 } else {
                     $return = $field->value;
                     break;
                 }
             case 'text-area':
             case 'textarea':
                 $pattern = $html ? '<span ' . self::class_attribute('textarea') . '>%s</span>' : '%s';
                 $return = sprintf($pattern, $field->value);
                 break;
             case 'rich-text':
                 if ($html) {
                     $return = sprintf('<span ' . self::class_attribute('textarea richtext') . '>%s</span>', Participants_Db::process_rich_text($field->value));
                 } else {
                     $return = strip_tags($field->value);
                 }
                 break;
             case 'dropdown':
             case 'radio':
             case 'checkbox':
             case 'dropdown-other':
             case 'select-other':
                 $field->value = self::array_display($field);
                 if ($html) {
                     $return = sprintf('<span %s>%s</span>', self::class_attribute($field->form_element), self::make_link($field));
                 } else {
                     $return = $field->value;
                 }
                 break;
             case 'placeholder':
                 $field->value = $field->default;
                 $return = $html ? self::make_link($field) : $field->value;
                 break;
             case 'hidden':
                 if ($field->value === $field->default) {
                     $field->value = '';
                 } elseif (!Participants_Db::is_dynamic_value($field->default)) {
                     $field->value = $field->default;
                 }
             default:
                 $return = $html ? self::make_link($field) : $field->value;
         }
     }
     return $return;
 }
コード例 #3
0
 /**
  * returns an element value formatted for display or storage
  * 
  * @param object $field a Field_Item object
  * @param bool   $html  if true, retuns the value wrapped in HTML, false returns 
  *                      the formatted value alone
  * @return string the object's current value, formatted
  */
 public static function get_field_value_display($field, $html = true)
 {
     //error_log(__METHOD__.' field:'.print_r($field,1));
     switch ($field->form_element) {
         case 'image-upload':
             $image = new PDb_Image(array('filename' => $field->value, 'link' => isset($field->link) ? $field->link : '', 'mode' => 'both', 'module' => $field->module));
             if ($html and (!is_admin() or defined('DOING_AJAX') and DOING_AJAX)) {
                 if (isset($field->module) and in_array($field->module, array('single', 'list'))) {
                     $image->display_mode = 'image';
                 } elseif (isset($field->module) and $field->module == 'signup') {
                     $image->display_mode = $image->image_defined ? 'both' : 'none';
                     $image->link = false;
                 }
                 $image->set_image_wrap();
                 $return = $image->get_image_html();
             } elseif ($image->file_exists) {
                 $return = $image->get_image_file();
             } else {
                 $return = $field->value;
             }
             break;
         case 'file-upload':
             if ($html and !empty($field->value)) {
                 if ($field->module == 'signup') {
                     $field->link = false;
                     $return = $field->value;
                 } else {
                     $upload_dir = wp_upload_dir();
                     $field->link = get_bloginfo('url') . '/' . Participants_Db::$plugin_options['image_upload_location'] . $field->value;
                     $return = self::make_link($field);
                 }
                 break;
             } else {
                 $return = $field->value;
                 break;
             }
         case 'date':
         case 'timestamp':
             $return = '';
             if (self::is_empty($field->value) === false) {
                 $date = strtotime($field->value);
                 $format = get_option('date_format', 'r');
                 $return = date_i18n($format, $date);
             }
             break;
         case 'multi-checkbox':
         case 'multi-select-other':
             $multivalues = maybe_unserialize($field->value);
             if (is_array($multivalues) and empty($multivalues['other'])) {
                 unset($multivalues['other']);
             }
             $return = implode(', ', (array) $multivalues);
             break;
         case 'link':
             /*
              * value is indexed array: array( $url, $linktext )
              */
             if (!($linkdata = unserialize_array($field->value))) {
                 $return = '';
                 break;
             }
             if (empty($linkdata[1])) {
                 $linkdata[1] = str_replace('http://', '', $linkdata[0]);
             }
             if ($html) {
                 $return = vsprintf(empty($linkdata[0]) ? '%1$s%2$s' : '<a href="%1$s">%2$s</a>', $linkdata);
             } else {
                 $return = $linkdata[0];
             }
             break;
         case 'text-line':
             if ($html) {
                 $return = self::make_link($field);
                 break;
             } else {
                 $return = $field->value;
                 break;
             }
         case 'text-area':
         case 'textarea':
             $return = sprintf('<span class="textarea">%s</span>', $field->value);
             break;
         case 'rich-text':
             $return = '<span class="textarea richtext">' . $field->value . '</span>';
             break;
         default:
             $return = $field->value;
     }
     return $return;
 }