Community @ The Turning Gate

Support community for TTG plugins and products.

NOTICE

The Turning Gate's Community has moved to a new home, at https://discourse.theturninggate.net.

This forum is now closed, and exists here as a read-only archive.

  • New user registrations are disabled.
  • Users cannot create new topics.
  • Users cannot reply to existing topics.

You are not logged in.

#1 2019-05-28 07:00:17

Nico3939
Member
From: France
Registered: 2016-10-05
Posts: 235
Website

Old Php and new PHP

For the checkout, in Backlight 1, my custom php code is the following code, but what is the right new code for Backlight 2:

<?php function page_match($gallery) {
   if (substr($_SERVER["REQUEST_URI"], 0, strlen($gallery)) == $gallery) {
      return 1;
   }  else {
      return 0;
   }
}
function ttg_scripts($style, $path) {
      echo'
          <script>
    function moveNumbers(number){
        document.getElementsByName("paiement")[0].value=number;
    }
</script>
    ';
     if ( page_match('/backlight/cart') ) {
      echo '
      <script>
         $("input[name=paiement]").before(\'<br>Veuillez s&eacute;lectionner votre m&eacute;thode de r&egrave;glement:<br><input type="radio" name="no" value="Virement" onclick="moveNumbers(this.value)"> Virement<br> <input type="radio" name="no" value="Cheque" onclick="moveNumbers(this.value)"> Ch&egrave;que (Ch&egrave;que d&apos;un &eacute;tablissement bancaire situ&eacute; sur le territoire fran&ccedil;ais uniquement)<br> <input type="radio" name="no" value="Mandat" onclick="moveNumbers(this.value)"> Mandat Administratif (France Uniquement)<br> <input type="radio" name="no" value="Devis" onclick="moveNumbers(this.value)"> Je souhaites recevoir un devis (Pour les commande en quantit&eacute; ou &eacute;tablir un bon de commande)\');
         $("input[name=paiement]").hide();
      </script>	
      ';
   }
   echo '
		<a href="#top" class="btn-scroll-to-top" title="Top of page" ><i class="fa fa-arrow-up fa-lg"></i></a>
	<script>
		$(document).ready(function() {
			$(".btn-scroll-to-top").click(function() {
				$("html, body").animate({ scrollTop: 0 }, "slow");
				return false;
			});
			$(window).scroll(function() {
				if ($(this).scrollTop() > 200) {
					$(".btn-scroll-to-top").fadeIn();
				} else {
					$(".btn-scroll-to-top").fadeOut();
				}
			});
		});
		</script>
		';
    echo '
		<script>
			$("<div class=\'cart-instructions\'><p>Note:</p></div>").insertBefore("form#cart #cart-buttons");
		</script>
	
	';
	echo '<script>	
		$( "<div class=\'my-cart-message\'><p>Vous pourrez vérifier votre commande avant de finaliser votre achat. / You will be able to review your order before you complete your purchase</p></div>" ).insertBefore( "form#cart #cart-buttons" );
		</script>
		';
		echo '<script>
var acc = document.getElementsByClassName("accordion");
var i;

for (i = 0; i < acc.length; i++) {
  acc[i].addEventListener("click", function() {
    this.classList.toggle("active");
    var panel = this.nextElementSibling;
    if (panel.style.maxHeight){
      panel.style.maxHeight = null;
    } else {
      panel.style.maxHeight = panel.scrollHeight + "px";
    } 
  });
}
</script>
		';
               return false;
}
?>

I try to put that at the beginning, and a } at the end, but nothing happen:

<?php

class PHPlugins extends APHPlugins
{

And replace:

function ttg_scripts($style, $path) {

by

function scripts() {

Last edited by Nico3939 (2019-05-28 07:07:21)

Offline

#2 2019-05-28 07:21:05

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Old Php and new PHP

Phplugins has changed in BL2.
You need to start with the phplugins-pangolin-sample.php file found in the backlight/custom/phplugins/ folder of your BL2 download.
You’ll see that the function names have changed.
Also see this sticky post from Daniel: http://community.theturninggate.net/vie … hp?id=8966


Rod 
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site

Offline

#3 2019-05-28 08:20:37

Nico3939
Member
From: France
Registered: 2016-10-05
Posts: 235
Website

Re: Old Php and new PHP

ok I'm moving slowly

is this function:

  if ( page_match('/backlight/cart') ) {

replaced by this one?

if( preg_match( '/^BACKLIGHT-PANGOLIN(.*)$/', $this->style ) ) {

Offline

#4 2019-05-28 08:21:57

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Old Php and new PHP

Matt, Ben, or maybe Daniel will know


Rod 
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site

Offline

#5 2019-05-28 16:39:31

Nico3939
Member
From: France
Registered: 2016-10-05
Posts: 235
Website

Re: Old Php and new PHP

I finally find the right code:


<?php
/*
 *  TTG Core Elements "PHPlugins" User Hooks v1.2 - initialization mainline
 *
 *  developed by john bishop images (http://johnbishopimages.com)
 *  for Matthew Campagna of The Turning Gate (http://theturninggate.net)
 *
 */

function 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.
}

if (defined('BACKLIGHT_HOOK')) {
	require_once(realpath(BACKLIGHT_HOOK).'/modules/module-designer/application/helpers/APHPlugins.php');
}

class PHPlugins extends APHPlugins
{
 function page_match($gallery) {
   if (substr($_SERVER["REQUEST_URI"], 0, strlen($gallery)) == $gallery) {
      return 1;
   }  else {
      return 0;
   }
}
function scripts() {
      echo '
          <script>
    function moveNumbers(number){
        document.getElementsByName("paiement")[0].value=number;
    }
</script>
    ';
     if ( $this->page_match('/backlight/cart') ) {
      echo '
      <script>
         $("input[name=paiement]").before(\'<br>Veuillez s&eacute;lectionner votre m&eacute;thode de r&egrave;glement:<br><input type="radio" name="no" value="Virement" onclick="moveNumbers(this.value)"> Virement<br> <input type="radio" name="no" value="Cheque" onclick="moveNumbers(this.value)"> Ch&egrave;que (Ch&egrave;que d&apos;un &eacute;tablissement bancaire situ&eacute; sur le territoire fran&ccedil;ais uniquement)<br> <input type="radio" name="no" value="Mandat" onclick="moveNumbers(this.value)"> Mandat Administratif (France Uniquement)<br> <input type="radio" name="no" value="Devis" onclick="moveNumbers(this.value)"> Je souhaites recevoir un devis (Pour les commande en quantit&eacute; ou &eacute;tablir un bon de commande)\');
         $("input[name=paiement]").hide();
		</script>
		';
	}
	echo '
		<a href="#top" class="btn-scroll-to-top" title="Top of page" ><i class="fa fa-arrow-up fa-lg"></i></a>
	<script>
		$(document).ready(function() {
			$(".btn-scroll-to-top").click(function() {
				$("html, body").animate({ scrollTop: 0 }, "slow");
				return false;
			});
			$(window).scroll(function() {
				if ($(this).scrollTop() > 200) {
					$(".btn-scroll-to-top").fadeIn();
				} else {
					$(".btn-scroll-to-top").fadeOut();
				}
			});
		});
		</script>
		';
    echo '
		<script>
			$("<div class=\'cart-instructions\'><p>Note:</p></div>").insertBefore("form#cart #cart-buttons");
		</script>
	
	';
	echo '<script>	
		$( "<div class=\'my-cart-message\'><p>Vous pourrez vérifier votre commande avant de finaliser votre achat. / You will be able to review your order before you complete your purchase</p></div>" ).insertBefore( "form#cart #cart-buttons" );
		</script>
		';
		echo '<script>
var acc = document.getElementsByClassName("accordion");
var i;

for (i = 0; i < acc.length; i++) {
  acc[i].addEventListener("click", function() {
    this.classList.toggle("active");
    var panel = this.nextElementSibling;
    if (panel.style.maxHeight){
      panel.style.maxHeight = null;
    } else {
      panel.style.maxHeight = panel.scrollHeight + "px";
    } 
  });
}
</script>
		';
               return false;
}
}
?>

Thanks for all Rod

Offline

#6 2019-05-28 23:51:26

Daniel Leu
Moderator
Registered: 2012-10-11
Posts: 1,624
Website

Re: Old Php and new PHP

Nico3939 wrote:

ok I'm moving slowly

is this function:

  if ( page_match('/backlight/cart') ) {

replaced by this one?

if( preg_match( '/^BACKLIGHT-PANGOLIN(.*)$/', $this->style ) ) {

You could use

 if ($this->page_match('/backlight/cart')) { 

corrected according to next post


Daniel Leu | Photography   
DanielLeu.com
My digital playground (eg, Backlight tips&tricks): lab.DanielLeu.com

Offline

#7 2019-05-29 00:28:51

Nico3939
Member
From: France
Registered: 2016-10-05
Posts: 235
Website

Re: Old Php and new PHP

Thanks Daniel,

with another ")"    wink

if ( $this->page_match('/backlight/cart') ) {

Offline

#8 2019-05-29 01:05:38

Daniel Leu
Moderator
Registered: 2012-10-11
Posts: 1,624
Website

Re: Old Php and new PHP

This is what happens when opening the computer before the first coffee.... smile


Daniel Leu | Photography   
DanielLeu.com
My digital playground (eg, Backlight tips&tricks): lab.DanielLeu.com

Offline

Board footer

Powered by FluxBB