Search code examples
phpjoomlajoomla1.5joomla-extensions

How can I change this JomSocial PHP code to only display activity for logged in users?


JomSocial, by default, uses 3 files to display the "Index" page for its users:

frontpage.index.php -> Contains an if/then to check for logged in users, loads frontpage.members.php if logged in, or frontpage.guest.php if not logged in. Then it displays recent activity, regardless of whether the user is logged in or not.

frontpage.members.php -> Has no particular actions (code below)

frontpage.guest.php -> Displays a login box.

The problem with this default setup is this: It displays recent activity streams for everyone, including guests. I ONLY want logged in users to be able to see the activity stream. I have tried to recode it myself, but I keep getting PHP errors (I'm not a PHP coder)... so I'm hoping for some help.

frontpage.index.php contents

<script type="text/javascript">joms.filters.bind();</script>

<!-- begin: #cFrontpageWrapper -->
<div id="cFrontpageWrapper">
    <?php 
    /**
     * if user logged in 
     *      load frontpage.members.php
     * else 
     *      load frontpage.guest.php
     */  
    echo $header;
    ?>

    <!-- begin: .cLayout -->
    <div class="cLayout clrfix">
        <!-- begin: .cSidebar -->
        <div class="cSidebar clrfix">
            <?php $this->renderModules( 'js_side_top' ); ?>     
            <?php if( $this->params->get('showsearch') == '1' || ($this->params->get('showsearch') == '2' && $my->id != 0 ) ) { ?>
            <?php
            /**
             * ----------------------------------------------------------------------------------------------------------           
             * Searchbox section here
             * ----------------------------------------------------------------------------------------------------------            

            // A COUPLE HUNDRED LINES OF CODE TO DISPLAY SEARCH, RECENT ACTIVITIES, ETC.

            <!-- Recent Activities -->
            <?php } ?>

        </div>
        <!-- end: .cMain -->

    </div>
    <!-- end: .cLayout -->

</div>
<!-- begin: #cFrontpageWrapper -->

What I need is to figure out how to set things so that the .clayout section ONLY shows up if the user is logged in. The problem is, I can't figure out how to modify this code accordingly. It's the asterisks around the if/then/else section that are confusing me. Can someone show me how to recode it?

It should go more like this:

if user logged in
  load frontpage.members.php
  //DISPLAY CLAYOUT INFO
else
  load frontpage.guest.php

Solution

  • Include if condition to check whether user is a registered user or gust. Please see the following code.

    <script type="text/javascript">joms.filters.bind();</script>
    
    <!-- begin: #cFrontpageWrapper -->
    <div id="cFrontpageWrapper">
        <?php 
        /**
         * if user logged in 
         *      load frontpage.members.php
         * else 
         *      load frontpage.guest.php
         */  
        echo $header;
        ?>
    
        <?php 
        $user =& JFactory::getUser();
        if (!$user->guest) { 
        ?>
    
    
        <!-- begin: .cLayout -->
        <div class="cLayout clrfix">
            <!-- begin: .cSidebar -->
            <div class="cSidebar clrfix">
                <?php $this->renderModules( 'js_side_top' ); ?>     
                <?php if( $this->params->get('showsearch') == '1' || ($this->params->get('showsearch') == '2' && $my->id != 0 ) ) { ?>
                <?php
                /**
                 * ----------------------------------------------------------------------------------------------------------           
                 * Searchbox section here
                 * ----------------------------------------------------------------------------------------------------------            
    
                // A COUPLE HUNDRED LINES OF CODE TO DISPLAY SEARCH, RECENT ACTIVITIES, ETC.
    
                <!-- Recent Activities -->
                <?php } ?>
    
            </div>
            <!-- end: .cMain -->
    
        </div>
        <!-- end: .cLayout -->
    
    </div>
    <!-- begin: #cFrontpageWrapper -->
    
      <?php } ?>