Jump to content

Adding custom tabs to PeepSo to output JReviews content


Alejandro

Recommended Posts

Using existing PeepSo filters it's easy to add new links to the user profile navigation to show different type of content associated with the profile. While the JReviews PeepSo Add-on has functionality to add My Listings, My Favorites and My Reviews links, these link to JReviews pages, rather than showing the content within the profile page.

You can disable those links if you want directly within the add-on settings, and use code below to output the content directly within the profile page. The code can be added to your theme's functions.php file or to a custom plugin.

<?php

function jreviews_peepso_profile_header($active) {
    echo PeepSoTemplate::exec_template('general', 'navbar');
    echo PeepSoTemplate::exec_template('profile', 'focus', ['current'=> $active]);
}

function jreviews_peepso_profile_userid() {
    $profile = PeepSoProfile::get_instance();
    return $profile->user->get_id();
}

/**
 * Adds the My Listings, My Favorites and My Reviews links to profile navigation
 */
add_filter('peepso_navigation_profile', function($links) {
    $links['mylistings'] = [
        'label' => __( 'My Listings', 'jreviews' ), 
        'href' => 'mylistings',
        'icon' => 'gcis gci-file-alt'
    ];

    $links['myreviews'] = [
        'label' => __( 'My Reviews', 'jreviews' ), 
        'href' => 'myreviews',
        'icon' => 'gcis gci-star'
    ];

    $links['myfavorites'] = [
        'label' => __( 'My Favorites', 'jreviews' ), 
        'href' => 'myfavorites',
        'icon' => 'gcis gci-bookmark'
    ];

    return $links;
});

/**
 * Registers profile segment mylistings
 */
add_action('peepso_profile_segment_mylistings', function() {
    ?>

    <div class='peepso ps-page-profile'>
        <section id='mainbody' class='ps-page-unstyled'>
            <section id='component' role='article' class='ps-clearfix'>
                
                <?php echo jreviews_peepso_profile_header('mylistings'); ?>

                <div class="peepso-jreviews">
                    <?php
                    require_once( ABSPATH . 'wp-content/plugins/jreviews/jreviews/framework.php');

                    $query_vars = array('module'=> [],'data'=> []);

                    $params = [
                        'community' => 1,
                        'show_numbers'=> 0,
                        'listings_order' => 'latest',
                        'fields'=>'',
                        'summary' => 1,
                        'summary_words' => 50,
                        'show_category' => 0,
                        'tn_mode' => 'crop',
                        'tn_size' => '125x125',
                        'tn_show' => 1,
                        'tn_position' => 'left',
                        'columns' => 1,
                        'orientation' => 'horizontal',
                        'slideshow' => 0,
                        'slideshow_interval' => 6,
                        'limit' => 10,
                        'module_total' => 10,
                        'nav_position'=>'bottom',
                    ];

                    $query_vars['module'] = $params;

                    $query_vars['user'] = jreviews_peepso_profile_userid();

                    $query_vars['module_id'] = 'mylistings'.$query_vars['user'];

                    $query_vars[S2_QVAR_PAGE] = 1;

                    $query_vars['secret'] = cmsFramework::getConfig('secret');

                    $query_vars['token'] = cmsFramework::formIntegrityToken($query_vars, ['module','module_id','form','data'], false);

                    $query_vars['data']['controller'] = 'community_listings';

                    $query_vars['data']['action'] = 'mylistings';

                    $Dispatcher = new S2Dispatcher('jreviews');

                    $content = $Dispatcher->dispatch($query_vars);

                    echo $content;      
                ?>
                </div>

            </section>
        </section>
    </div>   

    <?php
});

/**
 * Registers profile segment myfavorites
 */
add_action('peepso_profile_segment_myfavorites', function() {
    ?>

    <div class='peepso ps-page-profile'>
        <section id='mainbody' class='ps-page-unstyled'>
            <section id='component' role='article' class='ps-clearfix'>
                
                <?php echo jreviews_peepso_profile_header('myfavorites'); ?>

                <div class="peepso-jreviews">
                    <?php
                    require_once( ABSPATH . 'wp-content/plugins/jreviews/jreviews/framework.php');

                    $query_vars = array('module'=> [],'data'=> []);

                    $params = [
                        'community' => 1,
                        'show_numbers'=> 0,
                        'listings_order' => 'latest',
                        'fields'=>'',
                        'summary' => 1,
                        'summary_words' => 50,
                        'show_category' => 0,
                        'tn_mode' => 'crop',
                        'tn_size' => '125x125',
                        'tn_show' => 1,
                        'tn_position' => 'left',
                        'columns' => 1,
                        'orientation' => 'horizontal',
                        'slideshow' => 0,
                        'slideshow_interval' => 6,
                        'limit' => 10,
                        'module_total' => 10,
                        'nav_position'=>'bottom',
                    ];

                    $query_vars['module'] = $params;

                    $query_vars['user'] = jreviews_peepso_profile_userid();

                    $query_vars['module_id'] = 'favorites'.$query_vars['user'];

                    $query_vars[S2_QVAR_PAGE] = 1;

                    $query_vars['secret'] = cmsFramework::getConfig('secret');

                    $query_vars['token'] = cmsFramework::formIntegrityToken($query_vars, ['module','module_id','form','data'], false);

                    $query_vars['data']['controller'] = 'community_listings';

                    $query_vars['data']['action'] = 'favorites';

                    $Dispatcher = new S2Dispatcher('jreviews');

                    $content = $Dispatcher->dispatch($query_vars);

                    echo $content;      
                ?>
                </div>

            </section>
        </section>
    </div>    
    
    <?php
});

/**
 * Registers profile segment myreviews
 */
add_action('peepso_profile_segment_myreviews', function() {
    ?>

    <div class='peepso ps-page-profile'>
        <section id='mainbody' class='ps-page-unstyled'>
            <section id='component' role='article' class='ps-clearfix'>
                
                <?php echo jreviews_peepso_profile_header('myreviews'); ?>

                <div class="peepso-jreviews">
                    <?php
                    require_once( ABSPATH . 'wp-content/plugins/jreviews/jreviews/framework.php');

                    $query_vars = array('module'=> [],'data'=> []);

                    $params = [
                        'community' => 1,
                        'reviews_order' =>'latest',
                        'show_numbers' => 0,
                        'fields' => '',
                        'show_comments' => 1,
                        'comments_words' => 50,
                        'tn_mode' => 'crop',
                        'tn_size' => '125x125',
                        'tn_show' => 1,
                        'tn_position' => 'left',
                        'orientation' => 'horizontal',
                        'slideshow' => 0,
                        'slideshow_interval' => 6,
                        'columns' => 1,
                        'limit' => 10,
                        'module_total' => 20,
                        'nav_position' => 'bottom'
                    ];

                    $query_vars['module'] = $params;

                    $query_vars['user'] = jreviews_peepso_profile_userid();

                    $query_vars['module_id'] = 'myreviews'.$query_vars['user'];

                    $query_vars[S2_QVAR_PAGE] = 1;

                    $query_vars['secret'] = cmsFramework::getConfig('secret');

                    $query_vars['token'] = cmsFramework::formIntegrityToken($query_vars, ['module','module_id','form','data'], false);

                    $query_vars['data']['controller'] = 'community_reviews';

                    $query_vars['data']['action'] = 'index';

                    $Dispatcher = new S2Dispatcher('jreviews');

                    $content = $Dispatcher->dispatch($query_vars);

                    echo $content;      
                ?>
                </div>

            </section>
        </section>
    </div>    
    
    <?php
});

 

Link to comment
  • Alejandro unlocked this topic
×
×
  • Create New...