bbclone counter in G2: here the solution!

firepol
firepol's picture

Joined: 2004-05-19
Posts: 99
Posted: Fri, 2005-03-11 14:22

Hi there, I was thinking that implementing bbclone in G2 would be easy as implementing bbclone in G1. It's not the case.

I started by understanding how to get the photo and album variables, to be included in _BBC_PAGE_NAME.

To summarize what I did.

- I've insalled the last version of bbclone in my g2 folder: /var/www/gallery2/bbclone/
- I've created a "local" folder inside the "templates" folder and I've copied the global.tpl file there, in order to edit it
- In global.tpl, just before this line: {* If debugging or profiling is enabled, we'll display it here *} I've added the following code:

{if isset($ShowItem)}
{php}
define("_BBC_PAGE_NAME", $this->_tpl_vars['ShowItem']['item']['title']);
define("_BBCLONE_DIR", "/var/www/gallery2/bbclone/");
define("COUNTER", _BBCLONE_DIR."mark_page.php");
if (is_readable(COUNTER)) include_once(COUNTER);
{/php}
{/if}

Results: the counter doesn't count anything and the debugging doesn't show me any error.

I've tried to create a test php file, in the g2 root folder, I called it testcount.php which includes the following code:

<?php

define("_BBC_PAGE_NAME", "Test Count");
define("_BBCLONE_DIR", "/var/www/gallery2/bbclone/");
define("COUNTER", _BBCLONE_DIR."mark_page.php");
if (is_readable(COUNTER)) include_once(COUNTER);

?>

Browsing to the testcount.php page, bbclone counts it.

What's the problem, why doesn't bbclone work when called from the global.tpl file?

Thanks for letting me know and for sharing your bbclone implementation tests in this thread.

 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7994
Posted: Sat, 2005-03-12 07:57
firepol wrote:
Results: the counter doesn't count anything and the debugging doesn't show me any error.

What do you see in your HTML source at that location? There should be some clue there as to what went wrong...

 
firepol
firepol's picture

Joined: 2004-05-19
Posts: 99
Posted: Sat, 2005-03-12 11:53

At that source location I just see 2 blank lines:

    </div>


          </body>
</html>

But this is correct, as bbclone is a hidden counter. It simply logs results that can be viewed using the bbclone interface.

The problem is that in this case it doesn't log anything.

I activated the bbclone debug mode and what I get is:

Quote:
BBClone unknown debug mode:
BBClone isn't able to read its configuration data. This is likely because you embedded BBClone's code snippet into a function. Please use BBClone as suggested in the documentation.

 
firepol
firepol's picture

Joined: 2004-05-19
Posts: 99
Posted: Sat, 2005-03-12 12:31

I tried to implement bbclone as implemented in G1, by creating a file called bbclone.php:

<?PHP
define("_BBCLONE_DIR", "bbclone/");
define("COUNTER", _BBCLONE_DIR . "mark_page.php");
if(file_exists(COUNTER)) { include (COUNTER); }
?>

and copying that file in the root folder of G2.

i edited local copy of global.tpl and added:

{if isset($ShowItem)}
{php}
define("_BBC_PAGE_NAME", $this->_tpl_vars['ShowItem']['item']['title']);
virtual("bbclone.php");
{/php}
{/if}

I get no errors and the counter doesn't work. If i activate the debug mode of bbclone, I get the same message as reported in the previous post.

 
firepol
firepol's picture

Joined: 2004-05-19
Posts: 99
Posted: Sat, 2005-03-12 13:13

I started a topic also in the bbclone forum

Olliver, the chief and main bbclone developer told me:

Quote:
Unless the snippet can be put elsewhere it won't ever work this way with the current stable version. This will be addressed in the rewrite of BBClone I'm currently working on, but for now there's no workaround.

I will try to put the code, again, inside main.php or somewhere else, but not inside a function, else it won't work...

Edit: I tried to put the code in main.php, at the end of the file: it doesn't work.

 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7994
Posted: Sun, 2005-03-13 22:19

I took a look at the bbclone code. He's right; the way that it's written it's going to be hard to get it to work that way.

However, I did get it working by editing main.php. This isn't a great solution since upgrading G2 will trash your changes, but it works. I added the following to the bottom of main.php:

if (defined("_BBC_PAGE_NAME")) { 
    define("_BBCLONE_DIR", "/usr/home/bharat/public_html/gallery2/tmp/bbclone/"); 
    define("COUNTER", _BBCLONE_DIR."mark_page.php"); 
    if (is_readable(COUNTER)) include_once(COUNTER); 
}

Then in my local global.tpl I added:

{if isset($ShowItem)} 
{php}                            
define("_BBC_PAGE_NAME", $this->_tpl_vars['ShowItem']['item']['title']); 
{/php}                                                     
{/if}                                                         

The template sets the page name, and then main.php detects if the page name is set and if so, runs the counter code.

 
firepol
firepol's picture

Joined: 2004-05-19
Posts: 99
Posted: Sun, 2005-03-13 23:21

Mitico bharat! Grazie mille!!! ok, now back in English ;)...

Really really thanks, I did as you suggested and it worked fine! I think that this post will be really helpful for who wants to use bbclone in G2.

That's really a little big result. Thanks again. Isn't there a way to update via cvs and merge the last lines in the main.php? Else, no problem, I'll delete main.php before updating and add that code to the new main.php downloaded via CVS...

A minor addon, to make it perfect, would be to add the string "Album:" before the $this->_tpl_vars['ShowItem']['item']['title'] variable... IF it's an album. (As I'm doing with G1).

So an album called "Family" will be logged as "Album: Family" and it will be easier to distinguish albums from pictures in the counter statistics.

I'll try to figure out how to do it and post the results here.

Sincerely,

Paolo

 
esieens

Joined: 2005-06-24
Posts: 65
Posted: Thu, 2005-07-21 11:23

As someone managed to get it working with the new themes (not using the global.tpl file)??

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-07-21 11:42

it shouldn't be different from previous versions, just edit themes/matrix/templates/theme.tpl instead of global.tpl

 
esieens

Joined: 2005-06-24
Posts: 65
Posted: Thu, 2005-07-21 11:54

Here is what i did:

Added following code to main.php at the bottom before the ?>:

Quote:
if (defined("_BBC_PAGE_NAME")) {
define("_BBCLONE_DIR", "/bbclone/");
define("COUNTER", _BBCLONE_DIR."mark_page.php");
if (is_readable(COUNTER)) include_once(COUNTER);
}

Then I copied the theme.tpl in the local directory and added the following code just before the <div id="gsFooter">:

Quote:
{if isset($ShowItem)}
{php}
define("_BBC_PAGE_NAME", $this->_tpl_vars['ShowItem']['item']['title']);
{/php}
{/if}

I have also modified the sidebar.tpl so that it displays some stats:

Quote:
{php}
//------ Display Total Page Downloads -----------------------
require("bbclone/var/access.php");
$totalvisits = $access["stat"]["totalvisits"];
echo "Total de Visites: $totalvisits<br />";
$totalcount = $access["stat"]["totalcount"];
echo "Total Visiteurs Uniques: $totalcount<br />";
{/php}
<a href="bbclone">Statistiques</a>

My stats are not getting updated - last IP recorded by bbclone is just before I upgraded to 0.9.31.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-07-21 12:07

i don't think your paths are correct:
replace
if (defined("_BBC_PAGE_NAME")) {
define("_BBCLONE_DIR", "/bbclone/");
define("COUNTER", _BBCLONE_DIR."mark_page.php");
if (is_readable(COUNTER)) include_once(COUNTER);
}
by
if (defined("_BBC_PAGE_NAME")) {
define("_BBCLONE_DIR", "/bbclone/");
define("COUNTER", _BBCLONE_DIR."mark_page.php");
require_once(COUNTER);
}
then it should give you an error if the path if wrong. in this case, change /bbclone/ in the line
define("_BBCLONE_DIR", "/bbclone/");
to the correct path.

 
esieens

Joined: 2005-06-24
Posts: 65
Posted: Thu, 2005-07-21 12:19

No error - I have set BBC_DEBUG="1" as well to try to get some more info but get nothing.

I have given the full path to my bbclone folder and so I'm 100% sure it is correct.

 
esieens

Joined: 2005-06-24
Posts: 65
Posted: Thu, 2005-07-21 13:44

To me it looks like the _BBC_PAGE_NAME does not get defined but I might be wrong...

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-07-21 14:19

yep, the

{if isset($ShowItem)}
{php}
define("_BBC_PAGE_NAME", $this->_tpl_vars['ShowItem']['item']['title']);
{/php}
{/if}

part needs to be changed for the current g2 version.

{if isset($this->_tpl_vars['theme']['item']['title'])}
{php}
define("_BBC_PAGE_NAME", $this->_tpl_vars['theme']['item']['title']);
{/php}
{/if} 
 
esieens

Joined: 2005-06-24
Posts: 65
Posted: Thu, 2005-07-21 15:00

Many Thanks valiant for your help today!

I copy/past your code in a fresh theme.tpl file and put it in my local folder.

I get the following error:
Fatal error: Smarty error: [in gallery:themes/matrix/templates/theme.tpl line 61]: syntax error: unbalanced parenthesis in if statement (Smarty_Compiler.class.php, line 1251) in /srv/www/htdocs/gallery2/lib/smarty/Smarty.class.php on line 1088

I put the code just before the <div id="gsFooter">:

I've read and reread your few lines and can't see anything wrong with it!

Any idea - as you can guess I'm far from being a PHP expert and your help today is much appreciated.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-07-21 15:24
{php}
if (isset($this->_tpl_vars['theme']['item']['title'])) {
    define("_BBC_PAGE_NAME", $this->_tpl_vars['theme']['item']['title']);
}
{/php}
{/if}
 
esieens

Joined: 2005-06-24
Posts: 65
Posted: Thu, 2005-07-21 15:50

It's working! Thanks valiant.

Final code was:

Quote:
{php}
if (isset($this->_tpl_vars['theme']['item']['title'])) {
define("_BBC_PAGE_NAME", $this->_tpl_vars['theme']['item']['title']);
}
{/php}

The {/if} was not necessary.

 
hekacyr

Joined: 2004-10-21
Posts: 2
Posted: Tue, 2005-07-26 15:12

hi *,

i alos tried my luck with bbclone and the current gallery2 cvs code. so here is my addition to themes/matrix/templates/theme.tpl with different log for albums and photos. does anybody know, how to give bbclone a better url to log, than just http://.../../main.php ? please let me know.

thx
-j

    {* stuff for bbclone *}
    {php}
    if ($this->_tpl_vars['theme']['pageType'] == 'album' ||
        $this->_tpl_vars['theme']['pageType'] == 'photo') {
      if ($this->_tpl_vars['theme']['item']['entityType'] == "GalleryAlbumItem"
)
        $log_name = 'Album: ';
      else
        $log_name = '';

      $parents = $this->_tpl_vars['theme']['parents'];
      $parent_list = '';
      foreach ($parents as $i) {
        $parent_list = $parent_list . ' / ';
          if ($i['pathComponent'] == '') {
          $parent_list = $parent_list . $i['title'];
        } else {
          $parent_list = $parent_list . $i['pathComponent'];
        }
      }

      $log_name = $log_name . $parent_list . ' / ' .
                  $this->_tpl_vars['theme']['item']['pathComponent'];
      define("_BBC_PAGE_NAME", $log_name);
    }
    {/php}

and the addition to main.php as in the posting above

/* addition for bbclone */

if (defined("_BBC_PAGE_NAME")) {
   define("_BBCLONE_DIR", "/...../public_html/bbclone/");
   define("COUNTER", _BBCLONE_DIR."mark_page.php");
   if (is_readable(COUNTER)) {
      include_once(COUNTER);
}
}
 
nikk0s

Joined: 2003-10-14
Posts: 6
Posted: Wed, 2005-08-24 14:49

Hi,

Have somebody ever tried the smarty native function {include_php} ? http://smarty.php.net/manual/en/language.function.include.php.php
it seems more efficient for your problem

I try to include an anover statistic tools too, but my customization don't work yet (but I didn't try the function {include_php} for the moment)

For the page name I use :
$page_name = $theme->parents[parent]->title;
with this instruction i have the full path of an item, like this :
"Album root name > Album name > sub-album name > ... > Item name"

nikk0s

 
nikk0s

Joined: 2003-10-14
Posts: 6
Posted: Wed, 2005-08-24 18:10
nikk0s wrote:
For the page name I use :
$page_name = $theme->parents[parent]->title;
with this instruction i have the full path of an item, like this :
"Album root name > Album name > sub-album name > ... > Item name"

Sorry for this information : it's wrong and don't work... :oops:

nikk0s

 
edge

Joined: 2002-08-23
Posts: 4
Posted: Thu, 2005-08-25 20:39

Thanks to all these great suggestions, I got my bbclone working with the latest G2.

I ended up using include statements in both theme.tpl and main.php. This will make it much, much easier to handle cvs updates going forward.

I created 2 files (bbclone_main.php and bbclone_theme.php) and put them in my g2/mymods directory.

They look like this:

bbclone_theme.php


<?php

// Addition to Gallery2 - theme.tpl for bbclone Integration

if ($this->_tpl_vars['theme']['pageType'] == 'album' ||
        $this->_tpl_vars['theme']['pageType'] == 'photo') {
      if ($this->_tpl_vars['theme']['item']['entityType'] == "GalleryAlbumItem"
      )
        $log_name = 'Album: ';
      else
        $log_name = '';

      $parents = $this->_tpl_vars['theme']['parents'];
      $parent_list = '';
      foreach ($parents as $i) {
        $parent_list = $parent_list . ' / ';
          if ($i['pathComponent'] == '') {
          $parent_list = $parent_list . $i['title'];
        } else {
          $parent_list = $parent_list . $i['pathComponent'];
        }
      }

      $log_name = $log_name . $parent_list . ' / ' .
                  $this->_tpl_vars['theme']['item']['pathComponent'];
      define("_BBC_PAGE_NAME", $log_name);
    }

?>

bbclone_main.php

<?php

// Addition to Gallery2 - main.php for bbclone integration

if (defined("_BBC_PAGE_NAME")) {
 define("_BBCLONE_DIR", "/home/httpd/myrootdir/g2/bbclone/");
 define("COUNTER", _BBCLONE_DIR."mark_page.php");
 if (is_readable(COUNTER)) {
 include_once(COUNTER);
 }
}
?>

Then I added include statements in the following files:
g2/main.php

include("/home/httpd/myrootdir/g2/mymods/bbclone_main.php")

g2/themes/matrix/templates/local/theme.tpl

 {include_php file="/home/httpd/myrootdir/g2/mymods/bbclone_theme.php"}

Now, whenever I upgrade, I just need to add these 2 include statements to main.php and theme.tpl. I can keep all the bbclone code in my own files.

Hope that helps others.
Edge

 
shocksll
shocksll's picture

Joined: 2005-06-22
Posts: 352
Posted: Thu, 2005-08-25 20:49

Another idea is to just have one file that you include into the main.php. Check out the pathway function in the mambo gallery2 component. It takes the itemid and generates the path. That way you are only modding one file and it doesn't matter what theme you choose.

 
shocksll
shocksll's picture

Joined: 2005-06-22
Posts: 352
Posted: Fri, 2005-09-09 17:37

I've recently setup this solution on my own website that doesn't involve any modification to the gallery2 code.

Create a file called gallery2.php and put it in the root of your gallery2

<?php
require_once(dirname(__FILE__) . "/main.php");

$Title = pathway($_GET['g2_itemId']);
if (strlen($Title) > 0){
	define("_BBC_PAGE_NAME", $Title);
	define("_BBCLONE_DIR", dirname(__FILE__) . "/bbclone/");
	define("COUNTER", _BBCLONE_DIR."mark_page.php");
	if (is_readable(COUNTER)) require (COUNTER);
}

function pathway($g2_itemId){
	//first get parent albums
	if (empty($g2_itemId)){
		//return "Gallery Root";
		$g2_itemId = 7;
	}
	list ($ret, $parents) = GalleryCoreApi::fetchParentSequence($g2_itemId);
	$parents[count($parents)+1]=$g2_itemId;
	$g2_s=0;
	//gogogo
	$path = '';
	$extend = "";
	$seperator = " -> ";
	foreach($parents as $items){
	list ($ret,	$item) = GalleryCoreApi::loadEntitiesById($items);
		$title = $item->getTitle() ? $item->getTitle() : $item->getPathComponent();
		//$titles[$item->getId()] = preg_replace('/\r\n/', ' ', $title);
		//print $title . "<BR>";
		//let's switch again
		if($g2_s == 0 AND count($parents) ==1){ //first and last
		
			$path .= $extend.$title;
			$extend = $seperator;
		} elseif($g2_s == 0 AND count($parents) !=1) {// first but not last
		
			$path .= $extend.$title;
			$extend = $seperator;
		} elseif($g2_s == count($parents)-1 AND $g2_s == 1){// second and last
		 
			$path .=$extend.$title;
			$extend = $seperator;
		} elseif($g2_s == count($parents)-1){ // not second but it is last
		
			$path .=$extend.$title;
			$extend = $seperator;
		} elseif($g2_s == 1) {// everything in between
		
			$path .=$extend.$title;
			$extend = $seperator;
		} else {
			$path .=$extend.$title;
			$extend = $seperator;
		}
		$g2_s++;
	}
	if (!empty($_GET['g2_view']))
		if ($_GET['g2_view'] == "imageframe.CSS")
			return "";
		else
			if ($_GET['g2_view'] != "core.ShowItem")
				$path .= " * " . $_GET['g2_view'];
	if (!empty($_GET['g2_subView']))
		$path .= " ~ " . $_GET['g2_subView'];
	return $path;		
}//end pathway function
?>

and then in your config.php include this line

define('GALLERY_MAIN_PHP', 'gallery2.php');
 
Dianoga

Joined: 2005-10-10
Posts: 9
Posted: Tue, 2005-10-25 18:36

This worked perfectly for me.

Thanks!

 
vcdgeek

Joined: 2005-08-20
Posts: 56
Posted: Thu, 2005-10-27 07:00

sorry for my dumbness but where can we find config.inc.php? Do we have to create this file?
I plan to use bbclone with G2.

 
shocksll
shocksll's picture

Joined: 2005-06-22
Posts: 352
Posted: Thu, 2005-10-27 10:27

Sorry, it should be the config.php in your gallery2 root.

Steve Lineberry

 
vcdgeek

Joined: 2005-08-20
Posts: 56
Posted: Thu, 2005-10-27 19:12
 
vcdgeek

Joined: 2005-08-20
Posts: 56
Posted: Fri, 2005-10-28 05:03

Ima having problems with this. I know nothing in php.
This is what I did, under gallery2 I copied bbclone directory and under bbclone/conf/config.php I added
"define('GALLERY_MAIN_PHP', 'gallery2.php'); "
and in gallery2 directory I created gallery2.php and added above mentioned code, but when I run the page, I see no stat conuter.
iam using PGTheme, if it matters.
Thanks

 
shocksll
shocksll's picture

Joined: 2005-06-22
Posts: 352
Posted: Fri, 2005-10-28 20:52

No, you need to edit the gallery2 config.php not the bbclone config.php.

Steve Lineberry

 
timsohn

Joined: 2005-11-10
Posts: 1
Posted: Thu, 2005-11-10 09:18

I realized that this solution will not work if you have URL-rewrites turned on. Is there any way to use this solution and still have the rewrites enabled?

 
eosguy

Joined: 2005-07-27
Posts: 38
Posted: Sat, 2006-04-08 13:07

Anyway to turn off bbclone tracking of admin pages? Currrently using shocksll's way of implementing bbclone will also include my own visits in the admin pages.
-----
Photography gallery at http://www.kennyyeoh.com

 
firepol
firepol's picture

Joined: 2004-05-19
Posts: 99
Posted: Mon, 2006-04-24 21:54

eosguy: check this guide to avois logging your own visits: http://www.dullneon.com/tools/bbclone/block-bbclone-with-cookies.php

 
oxynaz

Joined: 2006-09-11
Posts: 3
Posted: Mon, 2006-09-11 18:23

hi,

just installed bbclone in my gallery2...

it works, exept I have lost my theme...

and if i rename gallery2.php to xxxgallery2.php, my theme is back, but no more bbclone recording stats...

how can i solve it ?

 
shocksll
shocksll's picture

Joined: 2005-06-22
Posts: 352
Posted: Mon, 2006-09-11 20:24

PM me the url to your website so I can take a look. Thanks.

Steve Lineberry

 
oxynaz

Joined: 2006-09-11
Posts: 3
Posted: Mon, 2006-09-11 22:10

i got it, it works, thanks

 
lightpainter

Joined: 2005-11-25
Posts: 64
Posted: Wed, 2009-09-09 18:52

Sorry for resuscitating such an old thread, but after years of having the method using gallery2.php working fine and recording every item a visitor looked at, I now cannot get this (or the method proposed by hekacyr) to work properly. I can get them to record a hit from the main page, but not any of the other pages visited. I can confirm that neither method calls bbclone from anything other than the site root access, either for recording hits or resetting the stats. The only thing I have changed is upgraded to Gallery 2.3.

I can see that when entering the site, gallery2.php is loaded in the url, but subsequent clicks all use main.php.

Could this have affected the requirements, and if so, can someone please update the code for the gallery2.php method? Sadly it is beyond my limited knowledge of PHP.

Cheers,

Tom
-----------------------------
www.lightpainter.co.uk

 
shocksll
shocksll's picture

Joined: 2005-06-22
Posts: 352
Posted: Wed, 2009-09-09 19:04

Maybe check your config.php and make sure this line is in there:

define('GALLERY_MAIN_PHP', 'gallery2.php');

Steve Lineberry

 
lightpainter

Joined: 2005-11-25
Posts: 64
Posted: Wed, 2009-09-09 21:29

Yes, that line is in there (pasted in literally, at the end just before the final ?>. It gets gallery2.php called up but only when the site root is hit, not any other pages- these all use main.php, and bbclone never gets any input from then on.

I tried inserting

define("_BBCLONE_DIR", "bbclone/");
define("COUNTER", _BBCLONE_DIR."mark_page.php");
if (is_readable(COUNTER)) include_once(COUNTER);

into main.php, but this results in 5 hits per page since it is called so often.

Tom
-----------------------------
www.lightpainter.co.uk

 
lightpainter

Joined: 2005-11-25
Posts: 64
Posted: Thu, 2009-09-10 12:49

I should add, that an using URL rewrite, and it worked fine with bbclone previousl. I do not have URL rewrite on of admin pages, and they do not trigger bbclone either. I tried deactivating it completely and flushing the caches, but that made no difference.
-----------------------------
www.lightpainter.co.uk