Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
Register FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 07-09-2010, 11:45 AM
dvsDave's Avatar
dvsDave dvsDave is offline
 
Join Date: Nov 2005
Posts: 107
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default My Friends Widget Edit myfriends.php

The My Friends widget is pretty awesome. Once configured, it can show you your friends recent activity on Posts, Threads, blogs, etc.

However, I was wondering if the widget could be expanded to include your contacts as well as friends. There are people I would like to follow but don't neccessarily want to be a full "friend" with.

Any ideas on how I might edit myfriends.php to accomplish this?
Reply With Quote
  #2  
Old 07-19-2010, 01:52 PM
alfanexus alfanexus is offline
 
Join Date: Dec 2008
Posts: 51
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Great idea. Then contacts could be used as followers
Reply With Quote
  #3  
Old 07-19-2010, 02:08 PM
dvsDave's Avatar
dvsDave dvsDave is offline
 
Join Date: Nov 2005
Posts: 107
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

yup! That is what my users want! Anybody have any ideas how to accomplish this?

I think this is the section of the code that needs editing, but I might be wrong:
PHP Code:
    /**
     * This sets up the search parameters, gets the query results,
     * and renders them
     *
     * @param array $config
     * @return string
     */
    private function getResults($config)
    {
        include_once DIR . '/includes/functions_misc.php';
        $search_core = vB_Search_Core::get_instance();

        //first see if we can get cached results
        $hashkey = $this->getHash();
        $cache_data = vB_Cache::instance()->read($hashkey, false, false);
        if ($cache_data)
        {

            //If there are no id's, we're done.
            if (empty($cache_data['ids']))
            {
                return false;
            }

            $controller = vB_Search_Core::get_instance()->get_search_type_from_id($config['contenttypeid']);

            if (method_exists($controller, 'create_array'))
            {
                $results = $controller->create_array($cache_data['ids']);
            }
            else if(method_exists($controller, 'create_item'))
            {
                $results = array();
                foreach ($cache_data['ids'] as $resultid)
                {
                    $result = $controller->create_item($resultid);
                    if ($result)
                    {
                        $results[] = $result;
                    }
                }
            }
            else
            {
                return false;
            }
            return array('results' => $results, 'criteria' => $cache_data['criteria']);
        }

        $rst = vB::$vbulletin->db->query_read("SELECT relationid FROM "
        . TABLE_PREFIX . "userlist WHERE friend='yes' AND userid = "
        . vB::$vbulletin->userinfo['userid']
        );

        if (!$rst)
        {
            return false;
        }
        $userids = array();

        while($row = vB::$vbulletin->db->fetch_row($rst))
        {
            $userids[] = $row[0];
        }

        //If there are no friends there's no friend information.
        if (! count($userids))
        {
            return '';
        }

        if ($config['contenttypeid'] == null)
        {
            $config['contenttypeid']= array();
        }
        else if (!is_array($config['contenttypeid']))
        {
            $config['contenttypeid'] = array($config['contenttypeid']);
        }

        if (!count($userids))
        {
            new vB_Phrase('global', 'your_friends_list_is_empty');
        }

        $criteria = vB_Search_Core::get_instance()->create_criteria(vB_Search_Core::SEARCH_ADVANCED);
        $criteria->add_contenttype_filter($config['contenttypeid']);
        $criteria->set_advanced_typeid($contenttypeid);

        $criteria->add_userid_filter($userids, false);
        $criteria->set_grouped(vB_Search_Core::GROUP_NO);
        $timelimit = TIMENOW - (86400 * $config['days']);
        $criteria->add_date_filter(vB_Search_Core::OP_GT, $timelimit);
        $criteria->set_sort('dateline', 'desc');
        $current_user = new vB_Legacy_CurrentUser();
        $results = vB_Search_Results::create_from_cache($current_user, $criteria);

        if (!$results)
        {
            $results = vB_Search_Results::create_from_criteria($current_user, $criteria);
        }

        if (empty($results))
        {
            return false;
        }

        $page_results = $results->get_page(1, $config['count'], 1);
        //prepare types for render
        $items_by_type = array();
        foreach ($page_results as $item)
        {
            $typeid = $item->get_contenttype();

            if ($typeid)
            {
                $items_by_type[$typeid][] =  $item;
                $ids[] = $item->get_id();
            }
        }

        foreach ($items_by_type as $contenttype => $items)
        {
            $type = vB_Search_Core::get_instance()->get_search_type_from_id($contenttype);
            $type->prepare_render($results->get_user(), $items);

        }

        vB_Cache::instance()->write($hashkey, array('ids' => $ids,
            'criteria' =>$criteria), $this->cache_ttl,
                'widget_config_' . $this->widget->getId());

        return array('results' => $page_results, 'criteria' => $criteria);
    } 
Reply With Quote
  #4  
Old 07-19-2010, 02:36 PM
alfanexus alfanexus is offline
 
Join Date: Dec 2008
Posts: 51
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Just change

PHP Code:
. TABLE_PREFIX . "userlist WHERE friend='yes' AND userid = " 
to

PHP Code:
. TABLE_PREFIX . "userlist WHERE type='buddy' AND userid = " 
Then the widget also displays contacts
Reply With Quote
  #5  
Old 07-19-2010, 06:14 PM
dvsDave's Avatar
dvsDave dvsDave is offline
 
Join Date: Nov 2005
Posts: 107
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Awesome! Thanks much!
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:56 AM.


Powered by vBulletin® Version 3.9.0
Copyright ©2000 - 2017, vBulletin Solutions Inc.