Classes

File phpboost/member/extended-fields/field/MemberShortTextExtendedField.class.php

File phpboost/member/extended-fields/field/MemberShortTextExtendedField.class.php

  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 
<?php
/**
 * @package     PHPBoost
 * @subpackage  Member\extended-fields\field
 * @copyright   &copy; 2005-2019 PHPBoost
 * @license     https://www.gnu.org/licenses/gpl-3.0.html GNU/GPL-3.0
 * @author      Kevin MASSY <reidlos@phpboost.com>
 * @version     PHPBoost 5.2 - last update: 2018 05 05
 * @since       PHPBoost 3.0 - 2010 12 08
 * @contributor Julien BRISWALTER <j1.seth@phpboost.com>
 * @contributor Arnaud GENET <elenwii@phpboost.com>
*/

class MemberShortTextExtendedField extends AbstractMemberExtendedField
{
    public static $brands_pictures_list = array(
        'bitbucket' => array('title' => 'Bitbucket', 'picture' => 'fa-bitbucket'),
        'deviantart' => array('title' => 'Deviantart', 'picture' => 'fa-deviantart'),
        'facebook' => array('title' => 'Facebook', 'picture' => 'fa-facebook'),
        'github' => array('title' => 'Github', 'picture' => 'fa-github'),
        'google' => array('title' => 'Google+', 'picture' => 'fa-google-plus-g'),
        'hotmail' => array('title' => 'Hotmail', 'picture' => 'fa-windows'),
        'instagram' => array('title' => 'Instagram', 'picture' => 'fa-instagram'),
        'linkedin' => array('title' => 'Linkedin', 'picture' => 'fa-linkedin'),
        'live' => array('title' => 'MSN', 'picture' => 'fa-windows'),
        'msn' => array('title' => 'MSN', 'picture' => 'fa-windows'),
        'outlook' => array('title' => 'Outlook', 'picture' => 'fa-windows'),
        'skype' => array('title' => 'Skype', 'picture' => 'fa-skype'),
        'steam' => array('title' => 'Steam', 'picture' => 'fa-steam'),
        'twitch' => array('title' => 'Twitch', 'picture' => 'fa-twitch'),
        'twitter' => array('title' => 'Twitter', 'picture' => 'fa-twitter'),
        'yahoo' => array('title' => 'Yahoo', 'picture' => 'fa-yahoo'),
        'youtube' => array('title' => 'Youtube', 'picture' => 'fa-youtube')
    );

    public function __construct()
    {
        parent::__construct();
        $this->lang = LangLoader::get('admin-user-common');
        $this->set_disable_fields_configuration(array('possible_values'));
        $this->set_name(LangLoader::get_message('type.short-text','admin-user-common'));
    }

    public function display_field_create(MemberExtendedField $member_extended_field)
    {
        $fieldset = $member_extended_field->get_fieldset();
        $regex = $member_extended_field->get_regex();

        switch ($regex)
        {
            case 1:
                $field_class = 'FormFieldNumberEditor';
                $display_constraint = false;
                break;
            case 4:
                $field_class = 'FormFieldMailEditor';
                $display_constraint = false;
                break;
            case 5:
                $field_class = 'FormFieldUrlEditor';
                $display_constraint = false;
                break;
            case 8:
                $field_class = 'FormFieldTelEditor';
                $display_constraint = false;
                break;
            default:
                $field_class = 'FormFieldTextEditor';
                $display_constraint = true;
        }

        $fieldset->add_field(new $field_class($member_extended_field->get_field_name(), $member_extended_field->get_name(), $member_extended_field->get_default_value(), array(
            'required' => (bool)$member_extended_field->get_required(), 'description' => $member_extended_field->get_description()),
            ($display_constraint ? array($this->constraint($regex)) : array())
        ));
    }

    public function display_field_update(MemberExtendedField $member_extended_field)
    {
        $fieldset = $member_extended_field->get_fieldset();
        $regex = $member_extended_field->get_regex();

        switch ($regex)
        {
            case 1:
                $field_class = 'FormFieldNumberEditor';
                $display_constraint = false;
                break;
            case 4:
                $field_class = 'FormFieldMailEditor';
                $display_constraint = false;
                break;
            case 5:
                $field_class = 'FormFieldUrlEditor';
                $display_constraint = false;
                break;
            case 8:
                $field_class = 'FormFieldTelEditor';
                $display_constraint = false;
                break;
            default:
                $field_class = 'FormFieldTextEditor';
                $display_constraint = true;
        }

        $fieldset->add_field(new $field_class($member_extended_field->get_field_name(), $member_extended_field->get_name(), $member_extended_field->get_value(), array(
            'required' => (bool)$member_extended_field->get_required(), 'description' => $member_extended_field->get_description()),
            ($display_constraint ? array($this->constraint($regex)) : array())
        ));
    }

    public function display_field_profile(MemberExtendedField $member_extended_field)
    {
        $value = $member_extended_field->get_value();
        if ($value !== null && !empty($value))
        {
            return array('name' => $member_extended_field->get_name(), 'value' => $this->get_value($member_extended_field, $value));
        }
    }

    private function get_value(MemberExtendedField $member_extended_field, $value)
    {
        if ($member_extended_field->get_regex() == 4)
        {
            $displayed_value = '<a href="mailto:' . $value . '" class="basic-button smaller">' . $this->lang['regex.mail'] . '</a>';

            foreach (self::$brands_pictures_list as $id => $parameters)
            {
                if (TextHelper::strstr($value, $id))
                    $displayed_value = '<a href="mailto:' . $value . '" class="basic-button smaller"><i class="fab ' . $parameters['picture'] . '"></i> ' . $parameters['title'] . '</a>';
            }
        }
        else if ($member_extended_field->get_regex() == 5)
        {
            $displayed_value = '<a href="' . $value . '" class="basic-button smaller">' . $this->lang['regex.website'] . '</a>';

            foreach (self::$brands_pictures_list as $id => $parameters)
            {
                if (TextHelper::strstr($value, $id))
                    $displayed_value = '<a href="' . $value . '" class="basic-button smaller"><i class="fab ' . $parameters['picture'] . '"></i> ' . $parameters['title'] . '</a>';
            }
        }
        else
            $displayed_value = $value;

        return $displayed_value;
    }
}
?>