Jump to content


fnode

Member Since 06 Sep 2011
Offline Last Active Sep 28 2012 10:35 AM
-----

Topics I've Started

$pages scope

06 August 2012 - 09:41 AM

Hello Community,

I have a directory structure like this:

[website]
|- libs // This folder is not part of PW
|- paypal
|- ipn.php
|- site
|- wire

The problem is that I cannot access $pages inside /website/libs/paypal/ipn.php.

Paypal IPN will point to this file: http://mysite.com/libs/paypal/ipn.php

<?php

$productid = $pages->get(1332);
var_dump($productid);


// read the post from PayPal system and add 'cmd'
$req = 'cmd=' . urlencode('_notify-validate');

foreach ($_POST as $key => $value) {
  $value = urlencode(stripslashes($value));
  $req .= "&$key=$value";
}

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.paypal.com/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: www.paypal.com'));
$res = curl_exec($ch);
curl_close($ch);


// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];

if (strcmp ($res, "VERIFIED") == 0) {
   // check the payment_status is Completed
   // check that txn_id has not been previously processed
   // check that receiver_email is your Primary PayPal email
   // check that payment_amount/payment_currency are correct
   // process payment
}
else if (strcmp ($res, "INVALID") == 0) {
   // log for manual investigation
}
?>

Thanks!

excluding parent's title

28 March 2012 - 12:51 PM

Hello Community,

SETUP:
Fields I have (uses:Page), (instances:Page) and (categories:Page). Please see the attached file.

[ uses ] Selection of fields to render. See the attached file # 2
[ instances ] "Default" data for pages. See the attached file # 2
[ categories ] A bunch of items :)

CODE:
Renders the selected field from [ uses ] to the template. It's a simple way of not hard-coding the fields in your page. NOTE: Pagefields() is a function inside /site/templates/home.php

ISSUE:
I do not know how to exclude the parent's field ($fo->title) from field ($page->instances) (Categories). Which is foreach($page->{strtolower($p->title)} as $fo){} thus returning $fielddata. I want to get only the titles from ($fo->categories) and not the (Categories) title. I hope I am making sence. See the attached file # 3.

Field (uses)
Example: I select a field called (categories) from [ uses ] it outputs the title "2D". For this to work the current page or template has to have that field from [uses] or it will not work. See the attached file # 2

<?php
function Pagefields(Page $page, Pages $pages, Fields $fields){  
   $fielddata = array();
  
   foreach($page->uses as $p){
	  
	  var_dump($p->title); // OUTPUTS. instances, categories
	  
	  foreach($page->{strtolower($p->title)} as $fo){
		 $fieldr = strtolower($fo->title);
		
		 var_dump($fo->title); // OUTPUTS. Categories, 2D
		
		 $fielddata[] = $fo; // Returns the title (Categories) which I don't want. I do need to return the titles inside Categories with a field called (categories).
		
		 if($page->get($fieldr)!=NULL){
			foreach($fo->{$fieldr} as $f1){
			   $fielddata[] = $f1;
			   var_dump($f1->title); // OUTPUTS. Blender (software), CSS 3, HTML 5, Design, Development, 2D, 3D, Vehicle Design. See the attached file # 3
			}
		 }#endof: if($page->get($fieldr)!=NULL){}
	  }
	  
   } #endof: foreach($page->uses as $p){}
  
   return (object) $fielddata;
}

foreach(Pagefields($page, $pages, $fields) as $p){
   var_dump($p->title);
}

HARD-CODED VERSION: This is the other way of doing my code above. I do not want to hard-code the field names in my home.php file
I have debug set to TRUE and I get the following error.

<?php
foreach($page->instances as $p){
   foreach($p->categories as $cat){
	  var_dump($cat->title); // OUTPUTS. Blender (software), CSS 3, HTML 5, Design, Development, 2D, 3D, Vehicle Design. See the attached file # 3
   }
}
## Warning: Invalid argument supplied for foreach() in line 2 foreach($p->categories as $cat){}

Field issue

19 September 2011 - 09:23 PM

Hello, PW Community

I have 2 fields, one called "fileimages" typeof [Image], second field is called "assets" typeof [Page].
The field "assets" contains the children of "Static" Page, please see structure below.

Home
|- Static
|- test_01
|- test_02

Setup > Fields
|- fileimages // typeof Image
|- assets // typeof Page # Containing the data of "Static" from above

Setup > Templates
|- page // Contains "assets"

<?php
// site/templates/page.php
foreach ($page->assets as $inc) {
  echo $inc->title // prints test_01, test_02
  echo $inc->fileimages->basename; // Getting no value
}
?>

The issue is that I cannot access a field inside of another field which contains data. # $inc->fileimages->basename.

Great community! Thanks to Ryan for this awesome Framework!