Advertisement:

Author Topic: Most Viewed Ads  (Read 56625 times)

SuperAtic

  • Full Member
  • ***
  • Posts: 196
Re: Most Viewed Ads
« Reply #30 on: March 11, 2012, 03:46:31 am »
Very interessant!

 :)

Ghosthawk

  • Newbie
  • *
  • Posts: 15
Re: Most Viewed Ads
« Reply #31 on: March 21, 2012, 06:31:14 pm »
I keep getting this error on my main page,

Warning: Illegal offset type in isset or empty in oc-includes/osclass/helpers/hUtils.php on line 65
 

newads

  • Newbie
  • *
  • Posts: 34
Re: Most Viewed Ads
« Reply #32 on: May 02, 2012, 03:33:49 pm »
Thank you for this plugin, this was the think I loved the most in open classifieds and now it is here too.

Evelyne

  • Full Member
  • ***
  • Posts: 134
Re: Most Viewed Ads
« Reply #33 on: May 04, 2012, 12:39:28 am »
I tried this one (I'm using BCute theme), but it didn't work.

But I took a look on your wiki page and saw some cool things there, thanks!

Although I noticed that the code to change cities to countries in the sidebar (which I've been looking for!) is the same as the cities, nothing changes!

And I tried to change the word "cities" to "countries" but it didn't work. Probably needs to work some extra stuff too, but as I'm new here I don't know where to look.

Help please? :)

Thanks

Evelyne

  • Full Member
  • ***
  • Posts: 134
Re: Most Viewed Ads
« Reply #34 on: May 10, 2012, 09:29:34 am »
Thanks Jesse for your efforts for the plugin.

I have used it on my site on sidebar........with bCute theme. It was not looking nice so I made some changes to the code as below. now you can see the attached image for the changes affected.

Code: [Select]
(...)
Anyways it is a great plugin. Thanks once again Jesse.

Freeadz,

I am also using BCute and I loved the way the "most popular" ads looked on the picture of your site. I tried to insert your code but I I got this error message instead of each ad that was supposed to be displayed.

Quote
Warning: Illegal offset type in isset or empty in (...)/OSClass/oc-includes/osclass/helpers/hUtils.php on line 65
   

I looked on this line and this is what I found there:

Code: [Select]
                if(isset($item["locale"]) && !empty($item['locale']) && isset($item["locale"][$locale]) && isset($item["locale"][$locale][$field])) {
                    return $item["locale"][$locale][$field] ;
                }else{

do you (or anyone more experienced than me) know how to fix this?

Thanks!

dev0005

  • Newbie
  • *
  • Posts: 28
Re: Most Viewed Ads
« Reply #35 on: May 15, 2012, 12:54:18 pm »
Hi,
jesse I tried this plugin and code but what I am getting is, only pictures with link and price with location and date rather than it will be batter if shows title with link in place of location. the user will not be able to identify that for what is that ad without title.
I am attaching a screenshot of that .


Hi all,

I've got a working plugin that's ready to be tested. It's called, Popular Ads.

To use the plugin, there are two functions that must be called before and after your "most popular ads" section. The format is like this:

Basic structure:

Code: [Select]
<?php popular_ads_start(); ?>

    .... write your code here ....

<?php popular_ads_end(); ?>

The above code will basically load all data for the "popular ads" into a OSClass array, which can be accessed by the standard OSClass Helper functions, here: http://wiki.osclass.org/HItems.php



Basic Example:
Here is a simple loop that will cycle through the entire array and display some information:
If you're wanting to try this plugin, this is a GREAT example to try!  :D
Code: [Select]
<?php popular_ads_start(); ?>
    <?php if( osc_count_items() > 0) {
        while ( 
osc_has_items() ) {
            echo 
'Item ID: '.osc_item_id().' Title: '.osc_item_title().' Views: '.osc_item_views().'<br>';
        }
    }
    
?>

<?php popular_ads_end(); ?>


Complete Working Example:

This is a complete, working example taken directly from the "Latest Items" section on the Main page (I used BCute theme):
Code: [Select]
<?php popular_ads_start(); ?>
    <div class="pop_ads">
<h1><strong><?php _e('Most Popular Ads''bcute') ; ?></strong></h1>
    <?php if( osc_count_items() == 0) { ?>
<p class="empty"><?php _e('No Popular Ads''bcute') ; ?></p>
    <?php } else { ?>
<table border="0" cellspacing="0">
    <tbody>
<?php $class "even"?>
<?php while ( osc_has_items() ) { ?>
<tr class="<?php echo $class. (osc_item_is_premium()?" premium":"") ; ?>">
<?php if( osc_images_enabled_at_items() ) { ?>
    <td class="photo">
<?php if( osc_item_is_premium() ){ ?>
<div id="premium_img"></div>
<?php }?>
<?php if( osc_count_item_resources() ) { ?>
    <a href="<?php echo osc_item_url() ; ?>">
<img src="<?php echo osc_resource_thumbnail_url() ; ?>" width="75" height="56" title="" alt="" />
    </a>
<?php } else { ?>
    <a href="<?php echo osc_item_url() ; ?>">
<img src="<?php echo osc_current_web_theme_url('images/no_photo.gif') ; ?>" alt="" title=""/>
    </a>
    <?php ?>
    </td>
<?php ?>
    <td class="text">
<div class="price-wrap"><span class="tag-head"></span><p class="price"><?php if( osc_price_enabled_at_items() ) echo osc_item_formated_price() ; ?></p></div>
<h3><a href="<?php echo osc_item_url() ; ?>"><?php echo osc_item_title() ; ?></a></h3>
<p><strong><?php if( osc_price_enabled_at_items() ) { echo osc_item_formated_price() ; ?> - <?php } echo osc_item_city(); ?> (<?php echo osc_item_region();?>) - <?php echo osc_format_date(osc_item_pub_date()); ?></strong></p>
<p><?php echo osc_highlightstrip_tagsosc_item_description() ) ) ; ?></p>
    </td>                                       
</tr>
<?php $class = ($class == 'even') ? 'odd' 'even' ?>
<?php ?>
    </tbody>
</table>
<?php if( osc_count_latest_items() == osc_max_latest_items() ) { ?>
    <p class="see_more_link"><a href="<?php echo osc_search_show_all_url();?>"><strong><?php _e("See all offers"'modern'); ?> &raquo;</strong></a></p>
<?php ?>
    <?php ?>
    </div>
<?php popular_ads_end(); ?>

Within the plugin folder is a CSS file that should have all the needed CSS for the above example. Feel free to modify the CSS file for your own styling and format.



Set the number of ads to display

In the admin panel, there is a Configuration page where you can set the desired number of popular ads to display.



Other notes:

This is a work in progress, which means there could be bugs, snakes, alligators, bears and sheep hiding inside this plugin. Please feel free to report anything you feel isn't working correctly. It's possible that some Helper functions will not work. That is because I've not included every bit of item data into the array (I did my best to include ALL important data). Should this be the case, it's an easy fix.  :)


Good luck my fellow OSClass'ers!  8)

PartySan

  • Newbie
  • *
  • Posts: 22
Re: Most Viewed Ads
« Reply #36 on: May 20, 2012, 11:24:40 pm »
I get only this after putting everthing in places = Parse error: syntax error, unexpected $end in /home/delonsho/public_html/sska.lv/oc-content/themes/bcute/main.php on line 168

airpk

  • Newbie
  • *
  • Posts: 13
Re: Most Viewed Ads
« Reply #37 on: June 11, 2012, 07:10:57 pm »
i figure out how to fix this problem

goto plugin index.php and find bellow line

$desc=$conn->osc_dbFetchResult("SELECT fk_c_locale_code, s_title, s_description, s_what FROM %st_item_description WHERE fk_i_item_id = %d", DB_TABLE_PREFIX, $item_id);

change it to

$desc=$conn->osc_dbFetchResult("SELECT fk_c_locale_code, s_title, s_description FROM %st_item_description WHERE fk_i_item_id = %d", DB_TABLE_PREFIX, $item_id);

you just need to remove , s_what and it worked.

Thanks


Thanks Jesse for your efforts for the plugin.

I have used it on my site on sidebar........with bCute theme. It was not looking nice so I made some changes to the code as below. now you can see the attached image for the changes affected.

Code: [Select]
(...)
Anyways it is a great plugin. Thanks once again Jesse.

Freeadz,

I am also using BCute and I loved the way the "most popular" ads looked on the picture of your site. I tried to insert your code but I I got this error message instead of each ad that was supposed to be displayed.

Quote
Warning: Illegal offset type in isset or empty in (...)/OSClass/oc-includes/osclass/helpers/hUtils.php on line 65
   

I looked on this line and this is what I found there:

Code: [Select]
                if(isset($item["locale"]) && !empty($item['locale']) && isset($item["locale"][$locale]) && isset($item["locale"][$locale][$field])) {
                    return $item["locale"][$locale][$field] ;
                }else{

do you (or anyone more experienced than me) know how to fix this?

Thanks!

rmarques

  • Newbie
  • *
  • Posts: 26
Re: Most Viewed Ads
« Reply #38 on: June 26, 2012, 04:18:36 am »
Thanks for the tip! I just removed that part you suggested - , s_what - from index.php and most viewed ads are working fine on my website. Thanks a LOT!!!

artesanato.com

airpk

  • Newbie
  • *
  • Posts: 13
Re: Most Viewed Ads
« Reply #39 on: June 30, 2012, 01:38:10 pm »
i have also modified the function to stop showing expire ads, code is as bellow

Code: [Select]
// function for displaying text on the Item page
function popular_ads_start() {

    $num_ads = popular_ads_num_ads(); // SETS HOW MANY POPULAR ADS TO DISPLAY


    $conn = getConnection();
    $results=$conn->osc_dbFetchResults("SELECT fk_i_item_id, i_num_views FROM %st_item_stats ORDER BY fk_i_item_id ASC", DB_TABLE_PREFIX);

    if(count($results)>0){

foreach($results as $result){
    $view_count[$result['fk_i_item_id']] += $result['i_num_views']; // Add-up all item views stored in database
}

arsort($view_count); // sorts array by highest number of item views first

foreach($view_count as $item_id=>$views)
{
    $result=$conn->osc_dbFetchResult("SELECT fk_i_user_id, fk_i_category_id, dt_pub_date, dt_mod_date, f_price, b_active, i_price, fk_c_currency_code, b_premium, s_secret,s_contact_name FROM %st_item WHERE pk_i_id = %d", DB_TABLE_PREFIX, $item_id); //Get active status of item


$result1=$conn->osc_dbFetchResult("SELECT i_expiration_days FROM %st_category WHERE pk_i_id = %d", DB_TABLE_PREFIX, $result['fk_i_category_id']); //Get expiration days of category

$result2=$conn->osc_dbFetchResult("SELECT DATEDIFF('". date('Y-m-d H:i:s')."','". $result['dt_pub_date']."') as DiffDate"); //Get expiration days difference
$bactive=0;

if($result1['i_expiration_days']==0 || $result2['DiffDate'] <=$result1['i_expiration_days'])
{
$bactive=1;
}


//if($result['b_active']==1){ //if active...
if($bactive==1){ //if active...
        //echo 'Item ID: '.$item_id.' Views: '.$views.'<br>'; // display only if item is active
$index++;

// get description
     
    //$desc=$conn->osc_dbFetchResult("SELECT fk_c_locale_code, s_title, s_description, s_what FROM %st_item_description WHERE fk_i_item_id = %d", DB_TABLE_PREFIX, $item_id);

$desc=$conn->osc_dbFetchResult("SELECT fk_c_locale_code, s_title, s_description FROM %st_item_description WHERE fk_i_item_id = %d", DB_TABLE_PREFIX, $item_id);


//Get active status of item
        $location=$conn->osc_dbFetchResult("SELECT fk_c_country_code, s_country, fk_i_region_id, s_region, fk_i_city_id, s_city FROM %st_item_location WHERE fk_i_item_id = %d", DB_TABLE_PREFIX, $item_id); //Get active status of item


// store the data in an array...
$item_array[] =   array('fk_i_user_id'=>$result['fk_i_user_id'],
'fk_i_category_id'=>$result['fk_i_category_id'],
'dt_pub_date'=>$result['dt_pub_date'],
'dt_mod_date'=>$result['dt_mode_date'],
'f_price'=>$result['f_price'],
's_contact_name'=>$result['s_contact_name'],
'fk_i_item_id'=>$item_id,
'pk_i_id'=>$item_id,
'b_active'=>$result['b_active'],
'i_price'=>$result['i_price'],
'fk_c_currency_code'=>$result['fk_c_currency_code'],
'b_premium'=>$result['b_premium'],
'fk_c_locale_code'=>$desc['fk_c_locale_code'],
's_title'=>$desc['s_title'],
's_description'=>$desc['s_description'],
's_what'=>$desc['s_what'],
'fk_c_country_code'=>$location['fk_c_country_code'],
's_country'=>$location['s_country'],
'fk_i_region_id'=>$location['fk_i_region_id'],
's_region'=>$location['s_region'],
'fk_i_city_id'=>$location['fk_i_city_id'],
's_city'=>$location['s_city'],
's_secret'=>$result['s_secret'],
'locale'=>array('en_US'=>array('fk_i_item_id'=>$item_id,
'fk_c_locale_code'=>$desc['fk_c_locale_code'],
's_title'=>$desc['s_title'],
's_description'=>$desc['s_description'],
's_what'=>$desc['s_what']
)
)
);
        }
    if($index>=$num_ads) break; // limit number of ads to display
}

GLOBAL $stored_items;
$stored_items = View::newInstance()->_get('items') ; //save existing item array
View::newInstance()->_exportVariableToView('items', $item_array);

    } else echo 'No Results.';
}

Evelyne

  • Full Member
  • ***
  • Posts: 134
Re: Most Viewed Ads
« Reply #40 on: June 30, 2012, 07:39:40 pm »
i figure out how to fix this problem

you just need to remove , s_what and it worked.

Thanks


Yes, the ads do show when the "s_what" is removed!

But I get the same "look" as the "Latest ads" (BCute), not the same look as the picture shown in the first post here... :(

any ideas on what to change to get that look?

shakeelstha

  • Newbie
  • *
  • Posts: 2
Re: Most Viewed Ads
« Reply #41 on: July 25, 2012, 08:18:08 am »
I am getting this warning. I am using OSclass 3.0

   
Warning: Illegal offset type in isset or empty in C:\xampp\htdocs\osclass.3.0.rc\oc-includes\osclass\helpers\hUtils.php on line 65

666999

  • Jr. Member
  • **
  • Posts: 53
Re: Most Viewed Ads
« Reply #42 on: August 30, 2012, 04:28:48 pm »
Everyone using ver 3.0 follow post from @airpk , tested on Modern theme. Default plugin code is not displaying ads description and title (only price , date and city/region).

Tnx @airpk

and Big tnx to @Jesse  for this plugin.

atrifa81

  • Jr. Member
  • **
  • Posts: 57
Re: Most Viewed Ads
« Reply #43 on: October 10, 2012, 11:43:50 am »
i have also modified the function to stop showing expire ads, code is as bellow

Code: [Select]
// function for displaying text on the Item page
function popular_ads_start() {

    $num_ads = popular_ads_num_ads(); // SETS HOW MANY POPULAR ADS TO DISPLAY


    $conn = getConnection();
    $results=$conn->osc_dbFetchResults("SELECT fk_i_item_id, i_num_views FROM %st_item_stats ORDER BY fk_i_item_id ASC", DB_TABLE_PREFIX);

    if(count($results)>0){

foreach($results as $result){
    $view_count[$result['fk_i_item_id']] += $result['i_num_views']; // Add-up all item views stored in database
}

arsort($view_count); // sorts array by highest number of item views first

foreach($view_count as $item_id=>$views)
{
    $result=$conn->osc_dbFetchResult("SELECT fk_i_user_id, fk_i_category_id, dt_pub_date, dt_mod_date, f_price, b_active, i_price, fk_c_currency_code, b_premium, s_secret,s_contact_name FROM %st_item WHERE pk_i_id = %d", DB_TABLE_PREFIX, $item_id); //Get active status of item


$result1=$conn->osc_dbFetchResult("SELECT i_expiration_days FROM %st_category WHERE pk_i_id = %d", DB_TABLE_PREFIX, $result['fk_i_category_id']); //Get expiration days of category

$result2=$conn->osc_dbFetchResult("SELECT DATEDIFF('". date('Y-m-d H:i:s')."','". $result['dt_pub_date']."') as DiffDate"); //Get expiration days difference
$bactive=0;

if($result1['i_expiration_days']==0 || $result2['DiffDate'] <=$result1['i_expiration_days'])
{
$bactive=1;
}


//if($result['b_active']==1){ //if active...
if($bactive==1){ //if active...
        //echo 'Item ID: '.$item_id.' Views: '.$views.'<br>'; // display only if item is active
$index++;

// get description
     
    //$desc=$conn->osc_dbFetchResult("SELECT fk_c_locale_code, s_title, s_description, s_what FROM %st_item_description WHERE fk_i_item_id = %d", DB_TABLE_PREFIX, $item_id);

$desc=$conn->osc_dbFetchResult("SELECT fk_c_locale_code, s_title, s_description FROM %st_item_description WHERE fk_i_item_id = %d", DB_TABLE_PREFIX, $item_id);


//Get active status of item
        $location=$conn->osc_dbFetchResult("SELECT fk_c_country_code, s_country, fk_i_region_id, s_region, fk_i_city_id, s_city FROM %st_item_location WHERE fk_i_item_id = %d", DB_TABLE_PREFIX, $item_id); //Get active status of item


// store the data in an array...
$item_array[] =   array('fk_i_user_id'=>$result['fk_i_user_id'],
'fk_i_category_id'=>$result['fk_i_category_id'],
'dt_pub_date'=>$result['dt_pub_date'],
'dt_mod_date'=>$result['dt_mode_date'],
'f_price'=>$result['f_price'],
's_contact_name'=>$result['s_contact_name'],
'fk_i_item_id'=>$item_id,
'pk_i_id'=>$item_id,
'b_active'=>$result['b_active'],
'i_price'=>$result['i_price'],
'fk_c_currency_code'=>$result['fk_c_currency_code'],
'b_premium'=>$result['b_premium'],
'fk_c_locale_code'=>$desc['fk_c_locale_code'],
's_title'=>$desc['s_title'],
's_description'=>$desc['s_description'],
's_what'=>$desc['s_what'],
'fk_c_country_code'=>$location['fk_c_country_code'],
's_country'=>$location['s_country'],
'fk_i_region_id'=>$location['fk_i_region_id'],
's_region'=>$location['s_region'],
'fk_i_city_id'=>$location['fk_i_city_id'],
's_city'=>$location['s_city'],
's_secret'=>$result['s_secret'],
'locale'=>array('en_US'=>array('fk_i_item_id'=>$item_id,
'fk_c_locale_code'=>$desc['fk_c_locale_code'],
's_title'=>$desc['s_title'],
's_description'=>$desc['s_description'],
's_what'=>$desc['s_what']
)
)
);
        }
    if($index>=$num_ads) break; // limit number of ads to display
}

GLOBAL $stored_items;
$stored_items = View::newInstance()->_get('items') ; //save existing item array
View::newInstance()->_exportVariableToView('items', $item_array);

    } else echo 'No Results.';
}

Hi...i did everything like u said but i still get this hputyuils error...can u help me?...i'm using osclass 3.0.1 and the bcute theme  :'(

biohardware

  • Newbie
  • *
  • Posts: 5
Re: Most Viewed Ads
« Reply #44 on: October 12, 2012, 02:23:52 am »
Hi!

The resolve is not osc_dbFetchResult while osc_dbFetchResults ! :)


Code: [Select]
$desc1=$conn->osc_dbFetchResult("SELECT fk_c_locale_code, s_title, s_description FROM %st_item_description WHERE fk_i_item_id = %d", DB_TABLE_PREFIX, $item_id);
       
           $desc=$conn->osc_dbFetchResults("SELECT fk_c_locale_code, s_title, s_description FROM %st_item_description WHERE fk_i_item_id = %d", DB_TABLE_PREFIX, $item_id);
       
        $item_array[] = array('fk_i_user_id'=>$result['fk_i_user_id'],
'fk_i_category_id'=>$result['fk_i_category_id'],
'dt_pub_date'=>$result['dt_pub_date'],
'f_price'=>$result['f_price'],
'fk_i_item_id'=>$item_id,
'pk_i_id'=>$item_id,
'b_active'=>$result['b_active'],
'i_price'=>$result['i_price'],
'fk_c_currency_code'=>$result['fk_c_currency_code'],
'b_premium'=>$result['b_premium'],
'fk_c_locale_code'=>$desc1['fk_c_locale_code'],
's_title'=>$desc1['s_title'],
's_description'=>$desc1['s_description'],
'fk_c_country_code'=>$location['fk_c_country_code'],
's_country'=>$location['s_country'],
'fk_i_region_id'=>$location['fk_i_region_id'],
's_region'=>$location['s_region'],
'fk_i_city_id'=>$location['fk_i_city_id'],
's_city'=>$location['s_city'],
's_secret'=>$result['s_secret'],
                'locale'=>array('en_US'=>array('fk_i_item_id'=>$item_id,
'fk_c_locale_code'=>$desc[1]['fk_c_locale_code'],
's_title'=>$desc[1]['s_title'],
's_description'=>$desc[1]['s_description']
),
                                    'hu_HU'=>array('fk_i_item_id'=>$item_id,
'fk_c_locale_code'=>$desc[2]['fk_c_locale_code'],
's_title'=>$desc[2]['s_title'],
's_description'=>$desc[2]['s_description']
),
                                    'de_DE'=>array('fk_i_item_id'=>$item_id,
'fk_c_locale_code'=>$desc[0]['fk_c_locale_code'],
's_title'=>$desc[0]['s_title'],
's_description'=>$desc[0]['s_description']
)
)     
               );