1
maxxy
User Profile Visitor ?
  • 2010/2/10 1:27

  • maxxy

  • Quite a regular

  • Posts: 286

  • Since: 2007/6/11


i would like to integrate the yogurt module profile visitor by the late suico in user profile module

i know i can use alfred module yogurt+profile..ive tested it and ive reason not to use it at the moment ..

a. there is bug that had not yet been fixed in the module..
b. same folder name with core profile module
c. i don't really need all the other extra feature
i know i can disable the feature such as friends, audio, album, wall etc

all i want now is a profile visitor and profile module thats all..

and i decided to stick with the stable profile module from the core

i made some search in the yogurt module to look for references to visitors....

anyone can help me to integrate this to profile module ?

in index.php

$xoopsTpl->assign('lang_visitors',_MD_YOGURT_VISITORS);




$controler->visitors_factory->purgeVisits();
/**

 * Visitors 

 */  



if ($controler->isAnonym==0){

    

    
/**

     * Fectching last visitors

     */

    
if ($controler->uidOwner != $xoopsUser->getVar('uid')){

        
$visitor_now $controler->visitors_factory->create();

        
$visitor_now->setVar('uid_owner'$controler->uidOwner);

        
$visitor_now->setVar('uid_visitor',$xoopsUser->getVar('uid'));

        
$visitor_now->setVar('uname_visitor',$xoopsUser->getVar('uname'));

        
$controler->visitors_factory->insert($visitor_now);

    }

    
$criteria_visitors = new criteria('uid_owner',  $controler->uidOwner);

    
//$criteria_visitors->setLimit(5);

    
$visitors_object_array $controler->visitors_factory->getObjects($criteria_visitors);



    
/**

     * Lets populate an array with the dati from visitors

     */  

    
$i 0;

    foreach (
$visitors_object_array as $visitor){

        

        

        
$indice                         $visitor->getVar("uid_visitor","s");

        
$visitors_array[$indice]        = $visitor->getVar("uname_visitor","s");

        

        

    
$i++;

    }

    

    
$xoopsTpl->assign('visitors'$visitors_array);

    
$xoopsTpl->assign('lang_visitors',_MD_YOGURT_VISITORS);




language/main.php definitions
define("_MD_YOGURT_VISITORS","Visitors who visited your profile recently");



SQL file

CREATE TABLE `yogurt_visitors` (

  `
cod_visitint(11NOT NULL auto_increment,

  `
uid_ownerint(11NOT NULL,

  `
uid_visitorint(11NOT NULL,

  `
uname_visitorvarchar(30NOT NULL,

`
datetimetimestamp NOT NULL default CURRENT_TIMESTAMP,

  
PRIMARY KEY  (`cod_visit`)

TYPE=MyISAM;




class/yogurt_visitors.php

// yogurt_visitors.php,v 1

//  ---------------------------------------------------------------- //

// Author: Bruno Barthez                                               //

// ----------------------------------------------------------------- //



include_once XOOPS_ROOT_PATH."/class/xoopsobject.php";

/**

* yogurt_visitors class.  

* $this class is responsible for providing data access mechanisms to the data source 

* of XOOPS user class objects.

*/





class yogurt_visitors extends XoopsObject



    var 
$db;



// constructor

    
function yogurt_visitors ($id=null)

    {

        
$this->db =& Database::getInstance();

        
$this->initVar("cod_visit",XOBJ_DTYPE_INT,null,false,10);

        
$this->initVar("uid_owner",XOBJ_DTYPE_INT,null,false,10);

        
$this->initVar("uid_visitor",XOBJ_DTYPE_INT,null,false,10);

        
$this->initVar("uname_visitor",XOBJ_DTYPE_TXTBOXnullfalse);

        if ( !empty(
$id) ) {

            if ( 
is_array($id) ) {

                
$this->assignVars($id);

            } else {

                    
$this->load(intval($id));

            }

        } else {

            
$this->setNew();

        }

        

    }



    function 
load($id)

    {

        
$sql 'SELECT * FROM '.$this->db->prefix("yogurt_visitors").' WHERE cod_visit='.$id;

        
$myrow $this->db->fetchArray($this->db->query($sql));

        
$this->assignVars($myrow);

        if (!
$myrow) {

            
$this->setNew();

        }

    }



    function 
getAllyogurt_visitorss($criteria=array(), $asobject=false$sort="cod_visit"$order="ASC"$limit=0$start=0)

    {

        
$db =& Database::getInstance();

        
$ret = array();

        
$where_query "";

        if ( 
is_array($criteria) && count($criteria) > ) {

            
$where_query " WHERE";

            foreach ( 
$criteria as $c ) {

                
$where_query .= $c AND";

            }

            
$where_query substr($where_query0, -4);

        } elseif ( !
is_array($criteria) && $criteria) {

            
$where_query " WHERE ".$criteria;

        }

        if ( !
$asobject ) {

            
$sql "SELECT cod_visit FROM ".$db->prefix("yogurt_visitors")."$where_query ORDER BY $sort $order";

            
$result $db->query($sql,$limit,$start);

            while ( 
$myrow $db->fetchArray($result) ) {

                
$ret[] = $myrow['yogurt_visitors_id'];

            }

        } else {

            
$sql "SELECT * FROM ".$db->prefix("yogurt_visitors")."$where_query ORDER BY $sort $order";

            
$result $db->query($sql,$limit,$start);

            while ( 
$myrow $db->fetchArray($result) ) {

                
$ret[] = new yogurt_visitors ($myrow);

            }

        }

        return 
$ret;

    }

}

// -------------------------------------------------------------------------

// ------------------yogurt_visitors user handler class -------------------

// -------------------------------------------------------------------------

/**

* yogurt_visitorshandler class.  

* This class provides simple mecanisme for yogurt_visitors object

*/



class Xoopsyogurt_visitorsHandler extends XoopsObjectHandler

{



    
/**

    * create a new yogurt_visitors

    * 

    * @param bool $isNew flag the new objects as "new"?

    * @return object yogurt_visitors

    */

    
function &create($isNew true)    {

        
$yogurt_visitors = new yogurt_visitors();

        if (
$isNew) {

            
$yogurt_visitors->setNew();

        }

        else{

        
$yogurt_visitors->unsetNew();

        }



        

        return 
$yogurt_visitors;

    }



    
/**

    * retrieve a yogurt_visitors

    * 

    * @param int $id of the yogurt_visitors

    * @return mixed reference to the {@link yogurt_visitors} object, FALSE if failed

    */

    
function &get($id)    {

            
$sql 'SELECT * FROM '.$this->db->prefix('yogurt_visitors').' WHERE cod_visit='.$id;

            if (!
$result $this->db->query($sql)) {

                return 
false;

            }

            
$numrows $this->db->getRowsNum($result);

            if (
$numrows == 1) {

                
$yogurt_visitors = new yogurt_visitors();

                
$yogurt_visitors->assignVars($this->db->fetchArray($result));

                return 
$yogurt_visitors;

            }

                return 
false;

    }



/**

* insert a new yogurt_visitors in the database



* @param object $yogurt_visitors reference to the {@link yogurt_visitors} object

* @param bool $force

* @return bool FALSE if failed, TRUE if already present and unchanged or successful

*/

    
function insert(&$yogurt_visitors$force false) {

        Global 
$xoopsConfig;

        if (
get_class($yogurt_visitors) != 'yogurt_visitors') {

                return 
false;

        }

        if (!
$yogurt_visitors->isDirty()) {

                return 
true;

        }

        if (!
$yogurt_visitors->cleanVars()) {

                return 
false;

        }

        foreach (
$yogurt_visitors->cleanVars as $k => $v) {

                ${
$k} = $v;

        }

        
$now "date_add(now(), interval ".$xoopsConfig['server_TZ']." hour)";

        if (
$yogurt_visitors->isNew()) {

            
// ajout/modification d'un yogurt_visitors

            
$yogurt_visitors = new yogurt_visitors();

            
$format "INSERT INTO %s (cod_visit, uid_owner, uid_visitor,uname_visitor)";

            
$format .= "VALUES (%u, %u, %u, %s)";

            
$sql sprintf($format 

            
$this->db->prefix('yogurt_visitors'), 

            
$cod_visit

            
,$uid_owner

            
,$uid_visitor

            
,$this->db->quoteString($uname_visitor)

            );

            
$force true;

        } else {

            
$format "UPDATE %s SET ";

            
$format .="cod_visit=%u, uid_owner=%u, uid_visitor=%u, uname_visitor=%s ";

            
$format .=" WHERE cod_visit = %u";

            
$sql sprintf($format$this->db->prefix('yogurt_visitors'),

            
$cod_visit

            
,$uid_owner

            
,$uid_visitor

            
,$this->db->quoteString($uname_visitor)

            , 
$cod_visit);

        }

        if (
false != $force) {

            
$result $this->db->queryF($sql);

        } else {

            
$result $this->db->query($sql);

        }

        if (!
$result) {

            return 
false;

        }

        if (empty(
$cod_visit)) {

            
$cod_visit $this->db->getInsertId();

        }

        
$yogurt_visitors->assignVar('cod_visit'$cod_visit);

        return 
true;

    }



    
/**

     * delete a yogurt_visitors from the database

     * 

     * @param object $yogurt_visitors reference to the yogurt_visitors to delete

     * @param bool $force

     * @return bool FALSE if failed.

     */

    
function delete(&$yogurt_visitors$force false)

    {

        if (
get_class($yogurt_visitors) != 'yogurt_visitors') {

            return 
false;

        }

        
$sql sprintf("DELETE FROM %s WHERE cod_visit = %u"$this->db->prefix("yogurt_visitors"), $yogurt_visitors->getVar('cod_visit'));

        if (
false != $force) {

            
$result $this->db->queryF($sql);

        } else {

            
$result $this->db->query($sql);

        }

        if (!
$result) {

            return 
false;

        }

        return 
true;

    }



    
/**

    * retrieve yogurt_visitorss from the database

    * 

    * @param object $criteria {@link CriteriaElement} conditions to be met

    * @param bool $id_as_key use the UID as key for the array?

    * @return array array of {@link yogurt_visitors} objects

    */

    
function &getObjects($criteria null$id_as_key false)

    {

        
$ret = array();

        
$limit $start 0;

        
$sql 'SELECT * FROM '.$this->db->prefix('yogurt_visitors');

        if (isset(
$criteria) && is_subclass_of($criteria'criteriaelement')) {

            
$sql .= ' '.$criteria->renderWhere();

        if (
$criteria->getSort() != '') {

            
$sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder();

        }

        
$limit $criteria->getLimit();

        
$start $criteria->getStart();

        }

        
$result $this->db->query($sql$limit$start);

        if (!
$result) {

            return 
$ret;

        }

        while (
$myrow $this->db->fetchArray($result)) {

            
$yogurt_visitors = new yogurt_visitors();

            
$yogurt_visitors->assignVars($myrow);

            if (!
$id_as_key) {

                
$ret[] =& $yogurt_visitors;

            } else {

                
$ret[$myrow['cod_visit']] =& $yogurt_visitors;

            }

            unset(
$yogurt_visitors);

        }

        return 
$ret;

    }



    
/**

    * count yogurt_visitorss matching a condition

    * 

    * @param object $criteria {@link CriteriaElement} to match

    * @return int count of yogurt_visitorss

    */

    
function getCount($criteria null)

    {

        
$sql 'SELECT COUNT(*) FROM '.$this->db->prefix('yogurt_visitors');

        if (isset(
$criteria) && is_subclass_of($criteria'criteriaelement')) {

            
$sql .= ' '.$criteria->renderWhere();

        }

        
$result $this->db->query($sql);

        if (!
$result) {

            return 
0;

        }

        list(
$count) = $this->db->fetchRow($result);

        return 
$count;

    } 



    
/**

    * delete yogurt_visitorss matching a set of conditions

    * 

    * @param object $criteria {@link CriteriaElement} 

    * @return bool FALSE if deletion failed

    */

    
function deleteAll($criteria null$force=false)

    {

        
$sql 'DELETE FROM '.$this->db->prefix('yogurt_visitors');

        if (isset(
$criteria) && is_subclass_of($criteria'criteriaelement')) {

            
$sql .= ' '.$criteria->renderWhere();

        }

        if (
false != $force) {

            if (!
$result $this->db->queryF($sql)) {

            return 
false;

        };

        } else {

            if (!
$result $this->db->query($sql)) {

            return 
false;

        }

        }

        

        return 
true;

    }

    

    function 
purgeVisits(){

        

        
$sql 'DELETE FROM '.$this->db->prefix('yogurt_visitors').' WHERE (datetime<(DATE_SUB(NOW(), INTERVAL 7 DAY))) ';



            if (!
$result $this->db->queryF($sql)) {

            return 
false;

        }

        

        

        return 
true;

        

    }

}





?>






template/yogurt_index.html

<{ if ($isOwner==1) }>



    <
div id="yogurt-album-visitors" class="outer">

        <
h2 class="head"><{$lang_visitors}>h2>

        <
p>

        <{foreach 
from=$visitors key=k item=v}>

             <
a href=index.php?uid=<{$k}> > <{$v}> a>&nbsp

        <{/foreach}> 

        p>

        div>

<{ /if }>





in

class yogurt_controller;

include_once("class/yogurt_visitors.php");
        function 
createFactories()

    {

 

$this->visitors_factory         = new Xoopsyogurt_visitorsHandler($this->db);
}



and maybe there is other..but that s what i've found so far



Help !

2
maxxy
Re: User Profile Visitor ?
  • 2010/3/5 23:04

  • maxxy

  • Quite a regular

  • Posts: 286

  • Since: 2007/6/11


i tried do this myslef but failed...

anyone can help ?

3
maxxy
Re: User Profile Visitor ?
  • 2010/5/29 1:09

  • maxxy

  • Quite a regular

  • Posts: 286

  • Since: 2007/6/11


bump

4
maxxy
Re: User Profile Visitor ?
  • 2012/12/25 12:57

  • maxxy

  • Quite a regular

  • Posts: 286

  • Since: 2007/6/11


can this be add to next core release ?

5
Dante7237
Re: User Profile Visitor ?
  • 2012/12/25 20:11

  • Dante7237

  • Friend of XOOPS

  • Posts: 294

  • Since: 2008/5/28


Yogurt is not secure, and pretty much orphaned.
Look for SmallWorld. Its a much better social mod.

Login

Who's Online

213 user(s) are online (141 user(s) are browsing Support Forums)


Members: 0


Guests: 213


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Jun 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits