• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

CB Fabrikitem Plugin

  • Views Views: 6,048
  • Last updated Last updated:
  • PHP:
    use CBLib\Application\Application;
    /** ensure this file is being included by a parent file */
    if ( ! ( defined( '_VALID_CB' ) || defined( '_JEXEC' ) || defined( '_VALID_MOS' ) ) ) { die( 'Direct Access to this location is not allowed.' ); }

    global $_PLUGINS;
    $_PLUGINS->loadPluginGroup( 'user', array( (int) 1 ) );
    $_PLUGINS->registerUserFieldTypes( array( 'fabrikitem' => 'CBfield_fabrikitem' ) );
    $_PLUGINS->registerUserFieldParams();

    class CBfield_fabrikitem extends CBfield_text {
    /**
    * Returns a field in specified format
    *
    * @param moscomprofilerFields $field
    * @param moscomprofilerUser $user
    * @param string $output 'html', 'xml', 'json', 'php', 'csvheader', 'csv', 'rss', 'fieldslist', 'htmledit'
    * @param string $reason 'profile' for user profile view, 'edit' for profile edit, 'register' for registration, 'list' for user-Lists
    * @param int $list_compare_types IF reason == 'search' : 0 : simple 'is' search, 1 : advanced search with modes, 2 : simple 'any' search
    * @return mixed
    */
    function getField( &$field, &$user, $output, $reason, $list_compare_types ) {
    global $_CB_framework, $ueConfig, $_CB_database;
    $value = $user->get( $field->name );
    if ( strlen($value) > 0 ) {
    /* Get the stored label/value pairs */
    $db = JFactory::getDBO();
    $query = $db->getQuery(true);
    $query
    ->select("params")
    ->from("#__fabrik_elements")
    ->where("name='member_interests'");
    $db->setQuery($query);
    $Options = json_decode($db->loadResult())->sub_options;
    /* transform the CB values to display values */
    $interests = array_map('trim',explode(",",$value));
    foreach ($interests as $key => $interest) {
    $interests[$key] = $Options->sub_labels[array_search($interest, $Options->sub_values)];
    }
    $interests = implode(", ", $interests);
    } else $interests = "";
    switch ( $output ) {
    case 'html':
    case 'rss':
    return $this->_formatFieldOutput( $field->name, $interests, $output, false );
    case 'htmledit':
    $modal = "  {modal index.php?option=com_fabrik&task=form.view&formid="
    . $field->params->get( 'formId', '' )
    . "&rowid=-1&usekey=user_id|iframe=1}Click Here to Change{/modal}";

    /* First render the field */
    if ($reason == 'search' ) {
    $type = 'text';
    $search = '/>';
    } else {
    $type = 'textarea';
    $search = '">';
    }
    $content = $this->_fieldEditToHtml($field, $user, $reason, 'input', $type, $value, '');
    /* hide the CB textarea */
    $pos = strpos($content, $search);
    if ( $reason != 'search' ) {
    $content = substr_replace($content, '" style="display:none;', $pos, 0 );
    /* Get the users display interests */
    $content = '<textarea name="cb_member_interests_disp" id="cb_member_interests_disp" class="form-control" disabled>' . $interests . '</textarea>' . $content;
    if ( !JFactory::getApplication()->isAdmin() ) {
    /* add the modal link and Javascript */
    $content .= Application::Cms()->prepareHtmlContentPlugins($modal);
    }
    } else {
    $content = substr_replace($content, ' style="display:none;"', $pos, 0 );
    // Render the dropdown for interest selection
    // Javascript to push the selection to CB's hidden search field
    $content .= '<script type="text/Javascript">'
    . 'function pushInterest(sel) {'
    . ' el = document.getElementById("cb_member_interests");'
    . ' if ( sel.value == "Please select" )'
    . ' el.value = "";'
    . ' else el.value = sel.value;'
    . '};'
    . '</script>';
    // Render the dropdown control
    $content .= '<div class="col-sm-3" style="padding-left: 0px; padding-right: 0px;"><select name="interestid" id="interestid" class="form-control input-block" onchange="pushInterest(this);">
    <option value="" id="interestid__" selected="selected">Please select</option>';

    // Now get the Options
    $db = JFactory::getDBO();
    $query = $db->getQuery(true);
    $query
    ->select("params")
    ->from("#__fabrik_elements")
    ->where("name='member_interests'");
    $db->setQuery($query);
    $params = json_decode(htmlspecialchars_decode($db->loadResult()));
    $values = $params->sub_options->sub_values;
    asort($values);
    // Add each interest to the dropdown
    foreach ($values as $key => $value) {
    $label = $params->sub_options->sub_labels[$key];
    $content .= '<option value="' . $value . '" id="interestid__' . $value . '">' . $label . '</option>';
    }
    $content .= '</select></div>';
    }
    return $content;
    break;
    default:
    return $this->_formatFieldOutput( $field->name, $value, $output, false );
    break;
    }
    }
    }
    ?>
Back
Top