Pro PHP- Patterns, Frameworks, Testing and More

(vip2019) #1

(^256) CHAPTER 16 ■ ADVANCED ZEND FRAMEWORK
//Set calculation variables
$dpi = 300; //The image DPI is important
$pointsPerInch = 72; //PDF standard points per inch is 72
//Calculate image width and height in points
$imageWidth = ($image->getPixelWidth() / $dpi) $pointsPerInch;
$imageHeight = ($image->getPixelHeight() / $dpi)
$pointsPerInch;
//Set the drawing offset
$x = 100;
$y = ($page->getHeight()-150); //Find page top and go down 150 points
//Draw the image to the PDF (x1,y1,x2,y2) [bottom left coordinate system]
$page->drawImage($image, $x, ($y - $imageHeight), ($x + $imageWidth), $y);


Integrating with Web Services


The Zend Framework ships with a number of model classes that make integration with various
web services quick and painless. Currently, it includes built-in facilities for Akismet, Amazon,
Flickr, and Yahoo APIs.
As an example, let’s focus on the Akismet service, which is used to determine if a comment
to a web site is spam or legitimate. You will need an API key from WordPress.com to use this
web service. Once you have your key, instantiation is fairly simple:

$akismet = new Zend_Service_Akismet($apiKey, 'http://your.com');

After you have an Akismet object, you can check if something is spam, report spam that
got past the filter, and report ham (good comments) that were falsely flagged as spam.
To check if a comment is spam, you need to pass a certain amount of data about your
commenter to Akismet. This includes HTTP headers, like the browser’s user-agent, IP address,
and so on. This information is used with the filter to determine if a comment is spam. The more
data you pass, the more reliable a spam prediction you will get back.
This information is in the form of a key=>value array. Table 16-3 shows the keys that
Akismet supports.

Ta b l e 16 - 3. Akismet Keys
Key Data Required
user_agent $_SERVER['HTTP_USER_AGENT'] Yes
user_ip $_SERVER['REMOTE_ADDR'] Yes
blog URL to your main page No
comment_author First Last No
comment_author_email [email protected] No
comment_author_url A URL for the commenter No

McArthur_819-9C16.fm Page 256 Friday, February 29, 2008 5:07 PM

Free download pdf