コード例 #1
0
+--------------------------------------------------------+
| Filename: user_geo_include.php
| Author: Chan (Frederick MC Chan)
+--------------------------------------------------------+
| This program is released as free software under the
| Affero GPL license. You can redistribute it and/or
| modify it under the terms of this license which you
| can read by viewing the included agpl.txt or online
| at www.gnu.org/licenses/agpl.html. Removal of this
| copyright header is strictly prohibited without
| written permission from the original author(s).
+--------------------------------------------------------*/
if (!defined("IN_FUSION")) {
    die("Access Denied");
}
// Display user field input
if ($profile_method == "input") {
    $options += array('inline' => true);
    $user_fields = form_geo('user_geo', $locale['uf_geo'], $field_value, $options);
} elseif ($profile_method == "display") {
    if ($field_value) {
        $address = explode('|', $field_value);
        $field_value = '';
        foreach ($address as $value) {
            $field_value .= "{$value}<br/>\n";
        }
    } else {
        $field_value = $locale['na'];
    }
    $user_fields = array('title' => $locale['uf_geo'], 'value' => $field_value);
}
コード例 #2
0
 /**
  * Display fields for each fieldDB record entry
  * @param array  $data The array of the user field.
  * @param        $callback_data
  * @param string $method input or display. In case of any other value
  *                       the method return FALSE. See the description of return for more details.
  * @param array  $options
  *                       <ul>
  *                       <li><strong>deactivate</strong> (boolean): FALSE by default.
  *                       disable fields</li>
  *                       <li><strong>debug</strong> (bolean): FALSE by default.
  *                       Show some information to debug.</li>
  *                       <li><strong>encrypt</strong> (boolean): FALSE by default.
  *                       encrypt field names</li>
  *                       <li><strong>error_text</strong> (string): empty string by default.
  *                       sets the field error text</li>
  *                       <li><strong>hide_value</strong> (boolean): FALSE by default.
  *                       input value is not shown on fields render</li>
  *                       <li><strong>inline</strong> (boolean): FALSE by default.
  *                       sets the field inline</li>
  *                       <li><strong>required</strong> (boolean): FALSE by default.
  *                       input must be filled when validate</li>
  *                       <li><strong>show_title</strong> (boolean): FALSE by default.
  *                       display field label</li>
  *                       <li><strong>placeholder</strong> (string): empty string by default.
  *                       helper text in field value</li>
  *                       <li><strong>plugin_folder</strong> (string): INCLUDES.'user_fields/' by default
  *                       The folder's path where the field's source files are.</li>
  *                       <li><strong>plugin_locale_folder</strong> (string): LOCALE.LOCALESET.'/user_fields/' by default.
  *                       The folder's path where the field's locale files are.</li>
  *                       </ul>
  * @return array|bool|string
  *                       <ul>
  *                       <li>FALSE on failure</li>
  *                       <li>string if $method 'display'</li>
  *                       <li>array if $method is 'input'</li>
  *                       </ul>
  */
 public function display_fields(array $data, $callback_data, $method = 'input', array $options = array())
 {
     // Add compatibality to V7's UF module.
     // Security concerns: remove all password hashes and salt
     unset($callback_data['user_algo']);
     unset($callback_data['user_salt']);
     unset($callback_data['user_password']);
     unset($callback_data['user_admin_algo']);
     unset($callback_data['user_admin_salt']);
     unset($callback_data['user_admin_password']);
     $data += array('field_required' => TRUE, 'field_error' => '', 'field_default' => '');
     $default_options = array('hide_value' => FALSE, 'encrypt' => FALSE, 'show_title' => $method == "input" ? TRUE : FALSE, 'deactivate' => FALSE, 'inline' => FALSE, 'error_text' => $data['field_error'], 'required' => (bool) $data['field_required'], 'placeholder' => $data['field_default'], 'plugin_folder' => INCLUDES . 'user_fields/', 'plugin_locale_folder' => LOCALE . LOCALESET . '/user_fields/', 'debug' => FALSE);
     $options += $default_options;
     if (!$options['plugin_folder']) {
         $options['plugin_folder'] = $default_options['plugin_folder'];
     }
     if (!$options['plugin_locale_folder']) {
         $options['plugin_locale_folder'] = $default_options['plugin_locale_folder'];
     }
     if (substr($options['plugin_folder'], -1) !== '/') {
         $options['plugin_folder'] .= '/';
     }
     if (substr($options['plugin_locale_folder'], -1) !== '/') {
         $options['plugin_locale_folder'] .= '/';
     }
     // Sets callback data automatically.
     $option_list = $data['field_options'] ? explode(',', $data['field_options']) : array();
     // Format Callback Data
     $field_value = isset($callback_data[$data['field_name']]) ? $callback_data[$data['field_name']] : '';
     if (isset($_POST[$data['field_name']]) && !$options['hide_value']) {
         $field_value = $_POST[$data['field_name']];
     } elseif ($options['hide_value']) {
         $field_value = '';
     }
     switch ($data['field_type']) {
         case 'file':
             // Do not remove it. It is used in included files.
             $user_data = $callback_data;
             $profile_method = $method;
             // can access options vars
             if (file_exists($options['plugin_locale_folder'] . $data['field_name'] . ".php")) {
                 include $options['plugin_locale_folder'] . $data['field_name'] . ".php";
             }
             if (file_exists($options['plugin_folder'] . $data['field_name'] . "_include.php")) {
                 include $options['plugin_folder'] . $data['field_name'] . "_include.php";
             }
             if (isset($options['debug']) && $options['debug']) {
                 print_p("Finding " . $options['plugin_locale_folder'] . $data['field_name'] . ".php");
                 if (file_exists($options['plugin_locale_folder'] . $data['field_name'] . ".php")) {
                     print_p($data['field_name'] . " locale loaded");
                 }
                 print_p("Finding " . $options['plugin_folder'] . $data['field_name'] . "_include.php");
                 if (file_exists($options['plugin_folder'] . $data['field_name'] . "_include.php")) {
                     print_p($data['field_name'] . " module loaded");
                 }
             }
             if (isset($user_fields)) {
                 return $user_fields;
             }
             break;
         case 'textbox':
             if ($method == 'input') {
                 return form_text($data['field_name'], $options['show_title'] ? self::parse_label($data['field_title']) : '', $field_value, $options);
             } elseif ($method == 'display' && $field_value) {
                 return array('title' => self::parse_label($data['field_title']), 'value' => $field_value);
             }
             break;
         case 'number':
             if ($method == 'input') {
                 $options += array('type' => 'number');
                 return form_text($data['field_name'], $options['show_title'] ? self::parse_label($data['field_title']) : '', $field_value, $options);
             } elseif ($method == 'display' && $field_value) {
                 return array('title' => self::parse_label($data['field_title']), 'value' => $field_value);
             }
             break;
         case 'url':
             if ($method == 'input') {
                 $options += array('type' => 'url');
                 return form_text($data['field_name'], $options['show_title'] ? self::parse_label($data['field_title']) : '', $field_value, $options);
             } elseif ($method == 'display' && $field_value) {
                 return array('title' => self::parse_label($data['field_title']), 'value' => $field_value);
             }
             break;
         case 'email':
             if ($method == 'input') {
                 $options += array('type' => 'email');
                 return form_text($data['field_name'], $options['show_title'] ? self::parse_label($data['field_title']) : '', $field_value, $options);
             } elseif ($method == 'display' && $field_value) {
                 return array('title' => self::parse_label($data['field_title']), 'value' => $field_value);
             }
             break;
         case 'select':
             if ($method == 'input') {
                 $options['options'] = $option_list;
                 return form_select($data['field_name'], self::parse_label($data['field_title']), $field_value, $options);
             } elseif ($method == 'display' && $field_value) {
                 $options_value = explode(",", $data['field_options']);
                 return array('title' => self::parse_label($data['field_title']), 'value' => !empty($options_value[$field_value]) ? $options_value[$field_value] : $field_value);
             }
             break;
         case 'tags':
             if ($method == 'input') {
                 $options += array('options' => $option_list, 'tags' => 1, 'multiple' => 1, 'width' => '100%');
                 return form_select($data['field_name'], $options['show_title'] ? self::parse_label($data['field_title']) : '', $field_value, $options);
             } elseif ($method == 'display' && $field_value) {
                 return array('title' => self::parse_label($data['field_title']), 'value' => $field_value);
             }
             break;
         case 'location':
             if ($method == 'input') {
                 $options += array('width' => '100%');
                 return form_location($data['field_name'], self::parse_label($data['field_title']), $field_value, $options);
             } elseif ($method == 'display' && $field_value) {
                 return array('title' => self::parse_label($data['field_title']), 'value' => $field_value);
             }
             break;
         case 'textarea':
             if ($method == 'input') {
                 return form_textarea($data['field_name'], $options['show_title'] ? self::parse_label($data['field_title']) : '', $field_value, $options);
             } elseif ($method == 'display' && $field_value) {
                 return array('title' => self::parse_label($data['field_title']), 'value' => $field_value);
             }
             break;
         case 'checkbox':
             if ($method == 'input') {
                 return form_checkbox($data['field_name'], $options['show_title'] ? self::parse_label($data['field_title']) : '', $field_value, $options);
             } elseif ($method == 'display' && $field_value) {
                 return array('title' => self::parse_label($data['field_title']), 'value' => $field_value);
             }
             break;
         case 'datepicker':
             if ($method == 'input') {
                 return form_datepicker($data['field_name'], $options['show_title'] ? self::parse_label($data['field_title']) : '', $field_value, $options);
             } elseif ($method == 'display' && $field_value) {
                 return array('title' => self::parse_label($data['field_title']), 'value' => showdate('shortdate', $field_value));
             }
             break;
         case 'colorpicker':
             if ($method == 'input') {
                 return form_colorpicker($data['field_name'], $options['show_title'] ? self::parse_label($data['field_title']) : '', $field_value, $options);
             } elseif ($method == 'display' && $field_value) {
                 return array('title' => self::parse_label($data['field_title']), 'value' => $field_value);
             }
             break;
         case 'uploader':
             if ($method == 'input') {
                 return form_fileinput($data['field_name'], self::parse_label($data['field_title']), $field_value, $options);
             } elseif ($method == 'display' && $field_value) {
                 return array('title' => self::parse_label($data['field_title']), 'value' => $field_value);
             }
             break;
         case 'hidden':
             if ($method == 'input') {
                 return form_hidden($data['field_name'], self::parse_label($data['field_title']), $field_value, $options);
             } elseif ($method == 'display' && $field_value) {
                 return array('title' => self::parse_label($data['field_title']), 'value' => $field_value);
             }
             break;
         case 'address':
             if ($method == 'input') {
                 return form_geo($data['field_name'], $options['show_title'] ? self::parse_label($data['field_title']) : '', $field_value, $options);
             } elseif ($method == 'display' && $field_value) {
                 return array('title' => self::parse_label($data['field_title']), 'value' => implode('|', $field_value));
             }
             break;
         case 'toggle':
             $options['toggle'] = 1;
             $options['toggle_text'] = array($this->locale['off'], $this->locale['on']);
             if ($method == 'input') {
                 return form_checkbox($data['field_name'], $options['show_title'] ? self::parse_label($data['field_title']) : '', $field_value, $options);
             } elseif ($method == 'display' && $field_value) {
                 return array('title' => self::parse_label($data['field_title']), 'value' => $field_value);
             }
             break;
     }
     return FALSE;
 }