Using phplugins in CE4

Hi @rod_barbee - (sigh) I’m losing my mind. For some reason this is now not working. Here’s my code in Ted Weinstein Photography – Ted Weinstein Photography

(https://www.tedweinstein.com/pics/phplugins/path.php correctly yields: “/home/tedweins/public_html/pics/phplugins” )

/
function ttg_user_load( $style, $path ) {
$g_tsvrl = explode( ’ ‘, $style ); // Extract gallery type
define ( ‘G_STYLE’, strtoupper($g_tsvrl[1]) ); // and set global for later
$g_path = str_ireplace(’\’,’/’,$path); // change \ to /
$chunks = explode(’/’,$g_path); // and put into array
define ( ‘G_PATH’, strtoupper($chunks[count($chunks)-2]) ); // gallery folder name is second to last
//define ( ‘TTG_SITE’, ‘’); // set new site root for navigation, resources, etc.
}
/

and

function ttg_head_end( $style, $path ) {
echo ’

';
}

And here’s the top of index.php for an example gallery:
https://www.tedweinstein.com/pics/2024/20240605_LeedsCastleTour/

<?php /* * * TTG Core Elements - "PHPlugins" User Hook interface * designed by john bishop images (http://johnbishopimages.com) * for Matthew Campagna of The Turning Gate (http://theturninggate.net) * */ // Begin hook processing define( 'TTG_ROOT', __FILE__ ); define( 'TTG_HOOK', 'https://www.tedweinstein.com/pics/phplugins' ); define( 'TTG_COMP', 'TTG CE4-Gallery 4.0' ); if (file_exists( TTG_HOOK . '/phplugins.php')) { require_once TTG_HOOK . '/phplugins.php'; } if (function_exists('ttg_user_load')) { $void = ttg_user_load( TTG_COMP, TTG_ROOT ); } ?><?php

if (!function_exists(‘currentPageURL’)) {
// Gets current page URL
function currentPageURL() {
$pageURL = ‘http’;

  	if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {$pageURL .= "s";}
  	$pageURL .= "://";

  	if ($_SERVER["SERVER_PORT"] != "80") {
  		$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
  	} else {
  		$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
  	}

  	return $pageURL;
  }

}

if (!function_exists(‘currentPageLocation’)) {
// Gets current page parent location
function currentPageLocation() {

  	$currentPageURL = currentPageURL();
  	$returnURL = '';

  	$finalSlash = strrpos(currentPageURL(), '/');
  	if (strrpos($currentPageURL, '.') > strrpos($currentPageURL, '/')) // has a file after the final slash, e.g. http://url/directory/index.php
  		$returnURL = substr($currentPageURL, 0, $finalSlash);
  	else if (strrpos($currentPageURL, '?') > strrpos($currentPageURL, '/')) // has a ? after the final slash, e.g. http://url/directory/index.php
  		$returnURL = substr($currentPageURL, 0, $finalSlash);
  	else if ($finalSlash == strlen($currentPageURL)-1) // final character is a slash, e.g. http://url/directory/
  		$returnURL = substr($currentPageURL, 0, $finalSlash);
  	else // final character is not a slash, e.g. http://url/directory
  		$returnURL = $currentPageURL;

  	return $returnURL;
  }

}

if (!function_exists(‘currentPageName’)) {
// Gets current page name.
function currentPageName() {
return substr($_SERVER[“SCRIPT_NAME”],strrpos($_SERVER[“SCRIPT_NAME”],"/")+1);
}
}

if (!function_exists(‘truncate’)) {
// Truncates string to length.
function truncate($str, $len=70) {
if (strlen($str) > $len) {
return substr($str, 0, $len-2) . ‘&#133’;
} else {
return $str;
}
}
}

// Set constants for use in PHPlugins
define(“PAGEIMAGE”, “photos/20240605_IMG_2959.jpg”);
define(“CURRENTPAGEURL”, currentPageURL());
define(“CURRENTPAGELOCATION”, currentPageLocation());
define(“CURRENTPAGENAME”, currentPageName());
define(“ALBUMTITLE”, ‘Leeds Castle Artist-Curator Tour’);
if (!defined(‘TTG_SITE’)) {
define(“TTG_SITE”, “http://www.tedweinstein.com/”);
}
?>

Leeds Castle Artist-Curator Tour - Ted Weinstein Photography <?php $add_mode = true; if ( function_exists('ttg_style_navigation') ) { if ( !(ttg_style_navigation( TTG_COMP, TTG_ROOT )) ) { $add_mode = false; } } if ( $add_mode ) { ?> <?php } ?> <?php if ( function_exists('ttg_head_end') ) { $void = ttg_head_end( TTG_COMP, TTG_ROOT ); } ?>

But as you can see when going to
Leeds Castle Artist-Curator Tour - Ted Weinstein Photography and viewing source, the Google Analytics code isn’t being inserted. Any idea what I’m doing wrong here now?

@Matthew will need to take a look.

But, I don’t see any Google Analytics code in the code you posted

function ttg_head_end( $style, $path ) {
echo ’

';
}

And it could be that your host updated the version of php running on your site and some of the phplugins code is now deprecated.

Sorry, I don’t really have an answer for you. Though I will say that Backlight 5 has support for Google Analytics built in so no need for phplugins.

If your host has updated php, it may only be a matter of time before you start seeing errors on your site. O

Oh, funny - pasting in to these message boards stripped the code - here’s an image:

then my guess is deprecated php. @Matthew may know.

What version is your host using?

alt-php74, and I can select up to 8.3

did you by chance export and upload new albums? If so, do they all have the correct path to phplugins?

Yes, all are using the same template, with php path set to
https://www.tedweinstein.com/pics/phplugins

OLD - from a few months ago - works fine - here’s top of index.php for

(Angel Island Jaunt - Ted Weinstein Photography) - if you view page source you can see the Google tracking code is correctly embedded in the page head.

> <?php
/*
 *
 * TTG Core Elements - "PHPlugins" User Hook interface
 * designed by john bishop images (http://johnbishopimages.com)
 * for Matthew Campagna of The Turning Gate (http://theturninggate.net)
 *
 */

// Begin hook processing

define( 'TTG_ROOT', __FILE__ );

define( 'TTG_HOOK', '/home/tedweins/public_html/pics/phplugins' );

define( 'TTG_COMP', 'TTG CE4-Gallery 4.0' );

if (file_exists( TTG_HOOK . '/phplugins.php')) {
	require_once TTG_HOOK . '/phplugins.php';
}

if (function_exists('ttg_user_load')) {
	$void = ttg_user_load( TTG_COMP, TTG_ROOT );
}

?><?php
	if (!function_exists('currentPageURL')) {
		// Gets current page URL
		function currentPageURL() {
			$pageURL = 'http';

			if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {$pageURL .= "s";}
			$pageURL .= "://";

			if ($_SERVER["SERVER_PORT"] != "80") {
				$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
			} else {
				$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
			}

			return $pageURL;
		}
	}

	if (!function_exists('currentPageLocation')) {
		// Gets current page parent location
		function currentPageLocation() {

			$currentPageURL = currentPageURL();
			$returnURL = '';

			$finalSlash = strrpos(currentPageURL(), '/');
			if (strrpos($currentPageURL, '.') > strrpos($currentPageURL, '/')) // has a file after the final slash, e.g. http://url/directory/index.php
				$returnURL = substr($currentPageURL, 0, $finalSlash);
			else if (strrpos($currentPageURL, '?') > strrpos($currentPageURL, '/')) // has a ? after the final slash, e.g. http://url/directory/index.php
				$returnURL = substr($currentPageURL, 0, $finalSlash);
			else if ($finalSlash == strlen($currentPageURL)-1) // final character is a slash, e.g. http://url/directory/
				$returnURL = substr($currentPageURL, 0, $finalSlash);
			else // final character is not a slash, e.g. http://url/directory
				$returnURL = $currentPageURL;

			return $returnURL;
		}
	}

	if (!function_exists('currentPageName')) {
		// Gets current page name.
		function currentPageName() {
			return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
		}
	}

	if (!function_exists('truncate')) {
		// Truncates string to length.
		function truncate($str, $len=70) {
			if (strlen($str) > $len) {
				return substr($str, 0, $len-2) . '&#133';
			} else {
				return $str;
			}
		}
	}

	// Set constants for use in PHPlugins
	define("PAGEIMAGE", "photos/20240316_768C8205.jpg");
	define("CURRENTPAGEURL", currentPageURL());
	define("CURRENTPAGELOCATION", currentPageLocation());
	define("CURRENTPAGENAME", currentPageName());
	define("ALBUMTITLE", 'Angel Island Jaunt');
	if (!defined('TTG_SITE')) {
		define("TTG_SITE", "http://www.tedweinstein.com/");
	}
?><!DOCTYPE html>
<!--[if lt IE 7]><html class="ce4 no-js lt-ie9 lt-ie8 lt-ie7" dir="ltr" lang="en" xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml"><![endif]-->
<!--[if IE 7]><html class="ce4 no-js lt-ie9 lt-ie8" dir="ltr" lang="en" xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml"><![endif]-->
<!--[if IE 8]><html class="ce4 no-js lt-ie9" dir="ltr" lang="en" xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml"><![endif]-->
<!--[if gt IE 8]><!--><html class="ce4 no-js gt-ie8" dir="ltr" lang="en" xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml"><!--<![endif]-->

<head>
	<meta charset="utf-8" />
	<!--[if IE]><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><![endif]-->
	<meta name="robots" content="noarchive, noindex, nofollow" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

	<meta name="author" content="Ted Weinstein Photography" />
 
	<meta name="title" content="Angel Island Jaunt - Ted Weinstein Photography" />
	<meta name="generator" content="CE4 Gallery 6.1.6, 28 published images" />

	<meta name="apple-mobile-web-app-capable" content="yes" />
	<meta name="HandheldFriendly" content="True" />
	<meta name="MobileOptimized" content="320" />
	<meta name="viewport" content="width=device-width, height=device-height, maximum-scale=1.0, minimum-scale=1.0, initial-scale=1.0" />

	<title>Angel Island Jaunt - Ted Weinstein Photography</title>

 
	<link rel="apple-touch-icon-precomposed" href="./lib/images/apple-touch-icon.png" />
 
	<link rel="icon" type="image/x-icon" href="./lib/images/favicon.ico" />
 

	<script>
	if (screen.width < 768 || navigator.userAgent.match(/Android|Blackberry|SymbianOS|iPhone|iPod|iPad/i)){ 
		window.location.replace('mobile.php'); }
	</script>

	<link rel="stylesheet" type="text/css" media="all" href="./lib/css/scaffolding.min.css" />	
	<link rel="stylesheet" type="text/css" media="all" href="./lib/css/font-awesome.min.css" />	
	<link rel="stylesheet" type="text/css" media="all" href="./lib/css/style-common.css" />
	<link rel="stylesheet" type="text/css" media="all" href="./lib/css/style-component.css" />
	
<?php
$add_mode = true;
if ( function_exists('ttg_style_navigation') ) {
	if ( !(ttg_style_navigation( TTG_COMP, TTG_ROOT )) ) {
		$add_mode = false;
	}
}
if ( $add_mode ) { ?>	<link rel="stylesheet" type="text/css" media="screen" href="./lib/css/navigation.css" />	
<?php } ?> 

	<link rel="stylesheet" type="text/css" media="print" href="./lib/css/print.css" />	

	<script src="./lib/js/modernizr.custom.79601.js"></script>
	<script src="./lib/js/jquery-1.11.3.min.js"></script>
	<script src="./lib/js/jquery.ba-throttle-debounce.min.js"></script>
	<script src="./lib/js/init.head.min.js"></script>





	<!--[if (gte IE 6)&(lte IE 8)]>
	<script src="./lib/js/respond.min.js"></script>
	<![endif]-->
	<!--[if (lte IE 10)]>

	<![endif]-->

<?php
if ( function_exists('ttg_head_end') ) {
	$void = ttg_head_end( TTG_COMP, TTG_ROOT );
} ?> 

</head> 

And here is NEW - ** DOESN’T WORK** - here’s top of index.php for

(Two Days in Oxford with the Chenery Gals - Ted Weinstein Photography) - if you view source, you can see the Google code is NOT inserted in the head.


<?php
/*
 *
 * TTG Core Elements - "PHPlugins" User Hook interface
 * designed by john bishop images (http://johnbishopimages.com)
 * for Matthew Campagna of The Turning Gate (http://theturninggate.net)
 *
 */

// Begin hook processing

define( 'TTG_ROOT', __FILE__ );

define( 'TTG_HOOK', '/home/tedweins/public_html/pics/phplugins' );

define( 'TTG_COMP', 'TTG CE4-Gallery 4.0' );

if (file_exists( TTG_HOOK . '/phplugins.php')) {
	require_once TTG_HOOK . '/phplugins.php';
}

if (function_exists('ttg_user_load')) {
	$void = ttg_user_load( TTG_COMP, TTG_ROOT );
}

?><?php
	if (!function_exists('currentPageURL')) {
		// Gets current page URL
		function currentPageURL() {
			$pageURL = 'http';

			if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {$pageURL .= "s";}
			$pageURL .= "://";

			if ($_SERVER["SERVER_PORT"] != "80") {
				$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
			} else {
				$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
			}

			return $pageURL;
		}
	}

	if (!function_exists('currentPageLocation')) {
		// Gets current page parent location
		function currentPageLocation() {

			$currentPageURL = currentPageURL();
			$returnURL = '';

			$finalSlash = strrpos(currentPageURL(), '/');
			if (strrpos($currentPageURL, '.') > strrpos($currentPageURL, '/')) // has a file after the final slash, e.g. http://url/directory/index.php
				$returnURL = substr($currentPageURL, 0, $finalSlash);
			else if (strrpos($currentPageURL, '?') > strrpos($currentPageURL, '/')) // has a ? after the final slash, e.g. http://url/directory/index.php
				$returnURL = substr($currentPageURL, 0, $finalSlash);
			else if ($finalSlash == strlen($currentPageURL)-1) // final character is a slash, e.g. http://url/directory/
				$returnURL = substr($currentPageURL, 0, $finalSlash);
			else // final character is not a slash, e.g. http://url/directory
				$returnURL = $currentPageURL;

			return $returnURL;
		}
	}

	if (!function_exists('currentPageName')) {
		// Gets current page name.
		function currentPageName() {
			return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
		}
	}

	if (!function_exists('truncate')) {
		// Truncates string to length.
		function truncate($str, $len=70) {
			if (strlen($str) > $len) {
				return substr($str, 0, $len-2) . '&#133';
			} else {
				return $str;
			}
		}
	}

	// Set constants for use in PHPlugins
	define("PAGEIMAGE", "photos/20240529_IMG_2169.jpg");
	define("CURRENTPAGEURL", currentPageURL());
	define("CURRENTPAGELOCATION", currentPageLocation());
	define("CURRENTPAGENAME", currentPageName());
	define("ALBUMTITLE", 'Two Days in Oxford with the Chenery Gals');
	if (!defined('TTG_SITE')) {
		define("TTG_SITE", "http://www.tedweinstein.com/");
	}
?><!DOCTYPE html>
<!--[if lt IE 7]><html class="ce4 no-js lt-ie9 lt-ie8 lt-ie7" dir="ltr" lang="en" xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml"><![endif]-->
<!--[if IE 7]><html class="ce4 no-js lt-ie9 lt-ie8" dir="ltr" lang="en" xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml"><![endif]-->
<!--[if IE 8]><html class="ce4 no-js lt-ie9" dir="ltr" lang="en" xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml"><![endif]-->
<!--[if gt IE 8]><!--><html class="ce4 no-js gt-ie8" dir="ltr" lang="en" xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml"><!--<![endif]-->

<head>
	<meta charset="utf-8" />
	<!--[if IE]><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><![endif]-->
	<meta name="robots" content="noarchive, noindex, nofollow" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

	<meta name="author" content="Ted Weinstein Photography" />
 
	<meta name="title" content="Two Days in Oxford with the Chenery Gals - Ted Weinstein Photography" />
	<meta name="generator" content="CE4 Gallery 6.1.6, 60 published images" />

	<meta name="apple-mobile-web-app-capable" content="yes" />
	<meta name="HandheldFriendly" content="True" />
	<meta name="MobileOptimized" content="320" />
	<meta name="viewport" content="width=device-width, height=device-height, maximum-scale=1.0, minimum-scale=1.0, initial-scale=1.0" />

	<title>Two Days in Oxford with the Chenery Gals - Ted Weinstein Photography</title>

 
	<link rel="apple-touch-icon-precomposed" href="./lib/images/apple-touch-icon.png" />
 
	<link rel="icon" type="image/x-icon" href="./lib/images/favicon.ico" />
 

	<script>
	if (screen.width < 768 || navigator.userAgent.match(/Android|Blackberry|SymbianOS|iPhone|iPod|iPad/i)){ 
		window.location.replace('mobile.php'); }
	</script>

	<link rel="stylesheet" type="text/css" media="all" href="./lib/css/scaffolding.min.css" />	
	<link rel="stylesheet" type="text/css" media="all" href="./lib/css/font-awesome.min.css" />	
	<link rel="stylesheet" type="text/css" media="all" href="./lib/css/style-common.css" />
	<link rel="stylesheet" type="text/css" media="all" href="./lib/css/style-component.css" />
	
<?php
$add_mode = true;
if ( function_exists('ttg_style_navigation') ) {
	if ( !(ttg_style_navigation( TTG_COMP, TTG_ROOT )) ) {
		$add_mode = false;
	}
}
if ( $add_mode ) { ?>	<link rel="stylesheet" type="text/css" media="screen" href="./lib/css/navigation.css" />	
<?php } ?> 

	<link rel="stylesheet" type="text/css" media="print" href="./lib/css/print.css" />	

	<script src="./lib/js/modernizr.custom.79601.js"></script>
	<script src="./lib/js/jquery-1.11.3.min.js"></script>
	<script src="./lib/js/jquery.ba-throttle-debounce.min.js"></script>
	<script src="./lib/js/init.head.min.js"></script>





	<!--[if (gte IE 6)&(lte IE 8)]>
	<script src="./lib/js/respond.min.js"></script>
	<![endif]-->
	<!--[if (lte IE 10)]>

	<![endif]-->

<?php
if ( function_exists('ttg_head_end') ) {
	$void = ttg_head_end( TTG_COMP, TTG_ROOT );
} ?> 

</head> 

I have looked line-by-line - what is the difference between the two index.php files for these two parallel, identically-generated galleries that is leading to different behavior?

Try this as the path to phplugins:

/home/tedweins/public_html/pics/phplugins

I realize that you said above that the url works (that hasn’t been my experience), but try entering the server path instead

Actually my bad. Looking at the header code in both index.php files, it looks like they are using, as you suggest,

define( ‘TTG_HOOK’, ‘/home/tedweins/public_html/pics/phplugins’ );