Jump to content

Recommended Posts

Hi,

 

I am working on a University server where they do not have Zend Framework installed and trying to get the ZendGdata client library working as a stand alone version.  So I have been following the directions at

https://developers.google.com/gdata/articles/php_client_lib

I installed the ZendGdata in a folder in my websites root folder and started to run the php installation checker to make sure the library was accesible when I hit a roadblock.  The installation checker does not work - it stops running midscript and spits out 1/2 the script on the screen instead of giving me the checker.  Here is the script I copied from several different sites (none work)

"

<?php

/**

* Zend Framework

*

* LICENSE

*

* This source file is subject to the new BSD license that is bundled

* with this package in the file LICENSE.txt.

* It is also available through the world-wide-web at this URL:

* http://framework.zend.com/license/new-bsd

* If you did not receive a copy of the license and are unable to

* obtain it through the world-wide-web, please send an email

* to license@zend.com so we can send you a copy immediately.

*

* @category  Zend

* @package    Zend_Gdata

* @subpackage Demos

* @copyright  Copyright © 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)

* @license    http://framework.zend.com/license/new-bsd    New BSD License

*/

 

/**

* Simple class to verify that the server that this is run on has a correct

* installation of the Zend Framework Gdata component.

*/

class InstallationChecker {

 

    const CSS_WARNING = '.warning { color: #fff; background-color: #AF0007;}';

    const CSS_SUCCESS = '.success { color: #000; background-color: #69FF4F;}';

    const CSS_ERROR = '.error { color: #fff; background-color: #FF9FA3;}';

    const PHP_EXTENSION_ERRORS = 'PHP Extension Errors';

    const PHP_MANUAL_LINK_FRAGMENT = 'http://us.php.net/manual/en/book.';

    const PHP_REQUIREMENT_CHECKER_ID = 'PHP Requirement checker v0.1';

    const SSL_CAPABILITIES_ERRORS = 'SSL Capabilities Errors';

    const YOUTUBE_API_CONNECTIVITY_ERRORS = 'YouTube API Connectivity Errors';

    const ZEND_GDATA_INSTALL_ERRORS = 'Zend Framework Installation Errors';

    const ZEND_SUBVERSION_URI = 'http://framework.zend.com/download/subversion';

 

    private static $REQUIRED_EXTENSIONS = array(

        'ctype', 'dom', 'libxml', 'spl', 'standard', 'openssl');

 

    private $_allErrors = array(

        self::PHP_EXTENSION_ERRORS => array(

            'tested' => false, 'errors' => null),

        self::ZEND_GDATA_INSTALL_ERRORS => array(

            'tested' => false, 'errors' => null),

        self::SSL_CAPABILITIES_ERRORS => array(

            'tested' => false, 'errors' => null),

        self::YOUTUBE_API_CONNECTIVITY_ERRORS => array(

            'tested' => false, 'errors' => null)

            );

 

    private $_sapiModeCLI = null;

 

    /**

    * Create a new InstallationChecker object and run verifications.

    * @return void

    */

    public function __construct()

    {

        $this->determineIfInCLIMode();

        $this->runAllVerifications();

        $this->outputResults();

    }

 

    /**

    * Set the sapiModeCLI variable to true if we are running CLI mode.

    *

    * @return void

    */

    private function determineIfInCLIMode()

    {

        if (php_sapi_name() == 'cli') {

            $this->_sapiModeCLI = true;

        }

    }

 

    /**

    * Getter for sapiModeCLI variable.

    *

    * @return boolean True if we are running in CLI mode.

    */

    public function runningInCLIMode()

    {

        if ($this->_sapiModeCLI) {

            return true;

        } else {

            return false;

        }

    }

 

    /**

    * Run verifications, stopping at each step if there is a failure.

    *

    * @return void

    */

    public function runAllVerifications()

    {

        if (!$this->validatePHPExtensions()) {

            return;

        }

        if (!$this->validateZendFrameworkInstallation()) {

            return;

        }

        if (!$this->testSSLCapabilities()) {

            return;

        }

        if (!$this->validateYouTubeAPIConnectivity()) {

            return;

        }

    }

 

    /**

    * Validate that the required PHP Extensions are installed and available.

    *

    * @return boolean False if there were errors.

    */

    private function validatePHPExtensions()

    {

        $phpExtensionErrors = array();

        foreach (self::$REQUIRED_EXTENSIONS as $requiredExtension) {

            if (!extension_loaded($requiredExtension)) {

                $requiredExtensionError = $requiredExtension .

                    ' extension missing';

                $documentationLink = null;

                if ($requiredExtension != 'standard') {

                    $documentationLink = self::PHP_MANUAL_LINK_FRAGMENT .

                        $requiredExtension . '.php';

                        $documentationLink =

                            $this->checkAndAddHTMLLink($documentationLink);

                } else {

                    $documentationLink = self::PHP_MANUAL_LINK_FRAGMENT .

                        'spl.php';

                    $documentationLink =

                        $this->checkAndAddHTMLLink($documentationLink);

                }

 

                if ($documentationLink) {

                    $phpExtensionErrors[] = $requiredExtensionError .

                        ' - refer to ' . $documentationLink;

                }

            }

        }

        $this->_allErrors[self::PHP_EXTENSION_ERRORS]['tested'] = true;

        if (count($phpExtensionErrors) > 0) {

            $this->_allErrors[self::PHP_EXTENSION_ERRORS]['errors'] =

                $phpExtensionErrors;

            return false;

        }

        return true;

    }

 

    /**

    * Validate that the Gdata component of Zend Framework is installed

    * properly. Also checks that the required YouTube API helper methods are

    * found.

    *

    * @return boolean False if there were errors.

    */

    private function validateZendFrameworkInstallation()

    {

        $zendFrameworkInstallationErrors = array();

        $zendLoaderPresent = false;

        try {

            $zendLoaderPresent = @fopen('Zend/Loader.php', 'r', true);

        } catch (Exception $e) {

            $zendFrameworkInstallationErrors[] = 'Exception thrown trying to ' .

                'access Zend/Loader.php using \'use_include_path\' = true ' .

                'Make sure you include the Zend Framework in your ' .

                'include_path which currently contains: "' .

                ini_get('include_path') . '"';

        }

 

        if ($zendLoaderPresent) {

            @fclose($zendLoaderPresent);

            require_once('Zend/Loader.php');

            require_once('Zend/Version.php');

            Zend_Loader::loadClass('Zend_Gdata_YouTube');

            Zend_Loader::loadClass('Zend_Gdata_YouTube_VideoEntry');

            $yt = new Zend_Gdata_YouTube();

            $videoEntry = $yt->newVideoEntry();

            if (!method_exists($videoEntry, 'setVideoTitle')) {

                $zendFrameworkMessage = 'Your version of the ' .

                    'Zend Framework ' . Zend_Version::VERSION . ' is too old' .

                    ' to run the YouTube demo application and does not' .

                    ' contain the new helper methods. Please check out a' .

                    ' newer version from Zend\'s repository: ' .

                    checkAndAddHTMLLink(self::ZEND_SUBVERSION_URI);

                $zendFrameworkInstallationErrors[] = $zendFrameworkMessage;

            }

        } else {

            if (count($zendFrameworkInstallationErrors) < 1) {

                $zendFrameworkInstallationErrors[] = 'Exception thrown trying' .

                    ' to access Zend/Loader.php using \'use_include_path\' =' .

                    ' true. Make sure you include Zend Framework in your' .

                    ' include_path which currently contains: ' .

                    ini_get('include_path');

            }

        }

 

        $this->_allErrors[self::ZEND_GDATA_INSTALL_ERRORS]['tested'] = true;

 

        if (count($zendFrameworkInstallationErrors) > 0) {

            $this->_allErrors[self::ZEND_GDATA_INSTALL_ERRORS]['errors'] =

                $zendFrameworkInstallationErrors;

            return false;

        }

        return true;

    }

 

    /**

    * Create HTML link from an input string if not in CLI mode.

    *

    * @param string The error message to be converted to a link.

    * @return string Either the original error message or an HTML version.

    */

    private function checkAndAddHTMLLink($inputString) {

        if (!$this->runningInCLIMode()) {

            return $this->makeHTMLLink($inputString);

        } else {

            return $inputString;

        }

    }

 

    /**

    * Create an HTML link from a string.

    *

    * @param string The string to be made into link text and anchor target.

    * @return string HTML link.

    */

    private function makeHTMLLink($inputString)

    {

        return '<a href="'. $inputString . '" target="_blank">' .

            $inputString . '</a>';

    }

 

    /**

    * Validate that SSL Capabilities are available.

    *

    * @return boolean False if there were errors.

    */

    private function testSSLCapabilities()

    {

        $sslCapabilitiesErrors = array();

        require_once 'Zend/Loader.php';

        Zend_Loader::loadClass('Zend_Http_Client');

 

        $httpClient = new Zend_Http_Client(

            'https://www.google.com/accounts/AuthSubRequest');

        $response = $httpClient->request();

        $this->_allErrors[self::SSL_CAPABILITIES_ERRORS]['tested'] = true;

 

        if ($response->isError()) {

            $sslCapabilitiesErrors[] = 'Response from trying to access' .

                ' \'https://www.google.com/accounts/AuthSubRequest\' ' .

                $response->getStatus() . ' - ' . $response->getMessage();

        }

 

        if (count($sslCapabilitiesErrors) > 0) {

            $this->_allErrors[self::SSL_CAPABILITIES_ERRORS]['errors'] =

                $sslCapabilitiesErrors;

            return false;

        }

        return true;

    }

 

    /**

    * Validate that we can connect to the YouTube API.

    *

    * @return boolean False if there were errors.

    */

    private function validateYouTubeAPIConnectivity()

    {

        $connectivityErrors = array();

        require_once 'Zend/Loader.php';

        Zend_Loader::loadClass('Zend_Gdata_YouTube');

        $yt = new Zend_Gdata_YouTube();

        $topRatedFeed = $yt->getTopRatedVideoFeed();

        if ($topRatedFeed instanceof Zend_Gdata_YouTube_VideoFeed) {

            if ($topRatedFeed->getTotalResults()->getText() < 1) {

                $connectivityErrors[] = 'There was less than 1 video entry' .

                    ' in the \'Top Rated Video Feed\'';

            }

        } else {

            $connectivityErrors[] = 'The call to \'getTopRatedVideoFeed()\' ' .

                'did not result in a Zend_Gdata_YouTube_VideoFeed object';

        }

 

        $this->_allErrors[self::YOUTUBE_API_CONNECTIVITY_ERRORS]['tested'] =

            true;

        if (count($connectivityErrors) > 0) {

            $this->_allErrors[self::YOUTUBE_API_CONNECTIVITY_ERRORS]['tested'] =

                $connectivityErrors;

            return false;

        }

        return true;

    }

 

    /**

    * Dispatch a call to outputResultsInHTML or outputResultsInText pending

    * the current SAPI mode.

    *

    * @return void

    */

    public function outputResults()

    {

        if ($this->_sapiModeCLI) {

          print $this->getResultsInText();

        } else {

          print $this->getResultsInHTML();

        }

    }

 

 

    /**

    * Return a string representing the results of the verifications.

    *

    * @return string A string representing the results.

    */

    private function getResultsInText()

    {

        $output = "== Ran PHP Installation Checker using CLI ==\n";

 

        $error_count = 0;

        foreach($this->_allErrors as $key => $value) {

            $output .= $key . ' -- ';

            if (($value['tested'] == true) && (count($value['errors']) == 0)) {

                $output .= "No errors found\n";

            } elseif ($value['tested'] == true) {

                $output .= "Tested\n";

                $error_count = 0;

                foreach ($value['errors'] as $error) {

                    $output .= "Error number: " . $error_count . "\n--" .

                        $error . "\n";

                }

            } else {

                $output .= "Not tested\n";

            }

            $error_count++;

        }

        return $output;

    }

 

    /**

    * Return an HTML table representing the results of the verifications.

    *

    * @return string An HTML string representing the results.

    */

    private function getResultsInHTML()

    {

        $html = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" " .

            "\"http://www.w3.org/TR/html4/strict.dtd\">\n".

            "<html><head>\n<title>PHP Installation Checker</title>\n" .

            "<style type=\"text/css\">\n" .

            self::CSS_WARNING . "\n" .

            self::CSS_SUCCESS . "\n" .

            self::CSS_ERROR . "\n" .

            "</style></head>\n" .

            "<body>\n<table class=\"verification_table\">" .

            "<caption>Ran PHP Installation Checker on " .

            gmdate('c') . "</caption>\n";

 

        $error_count = 0;

        foreach($this->_allErrors as $key => $value) {

            $html .= "<tr><td class=\"verification_type\">" . $key . "</td>";

            if (($value['tested'] == true) && (count($value['errors']) == 0)) {

                $html .= "<td class=\"success\">Tested</td></tr>\n" .

                    "<tr><td colspan=\"2\">No errors found</td></tr>\n";

            } elseif ($value['tested'] == true) {

                $html .= "<td class=\"warning\">Tested</td></tr>\n";

                $error_count = 0;

                foreach ($value['errors'] as $error) {

                    $html .= "<tr><td class=\"error\">" . $error_count . "</td>" .

                        "<td class=\"error\">" . $error . "</td></tr>\n";

                }

            } else {

                $html .= "<td class=\"warning\">Not tested</td></tr>\n";

            }

            $error_count++;

        }

        $html .= "</body></html>";

        return $html;

    }

}

 

$installationChecker = new InstallationChecker();

"

all I am supposed to add to the top to make it work is an include statement to make the library accesible & here it is

"

$clientLibraryPath = '/www/ttunrm/ZendGdata/library';

set_include_path(get_include_path() . PATH_SEPARATOR . $clientLibraryPath);

"

 

So my question is am I doing something wrong or does the university have the include ability turned off in their php.ini file (it kind of looked like that to me but I need to be sure of the code first).

 

Thanks,

 

Kate :confused:

So you want a bunch of strangers to validate your code rather than just either checking the config yourself or checking with your sysadmins?

So my question is am I doing something wrong or does the university have the include ability turned off in their php.ini file (it kind of looked like that to me but I need to be sure of the code first).

Thanks for the replies ChristianF & Jesirose. 

 

I am sorry I didn't put my code in the tags.  It has been a very long time since I have been here my twin 3 yr. olds are finally in preschool & I have a part time job working on website design.  I just included my code because I remember that when I don't someone asks me to.  Anyway I will be sure to put the code tags in in the future. 

 

Jesirose I actually spent the last 2 days working on this and bugging my sysAdmin (they seem suprisingly uninformed).  I have been through the code a couple times and I think it is correct (especially since the long bit was copied directly from the the website directions I am following).  The only thing I am unsure of is the stuff I have to write myself since it has been so long here it is again

$clientLibraryPath = '/www/ttunrm/ZendGdata/library';
set_include_path(get_include_path() . PATH_SEPARATOR . $clientLibraryPath);

I read the php.ini file but the php I do know is all self taught so I was not sure.  I have never written a php.ini file.

 

these are the 2 excerpts which seemed relevant

"When safe_mode is on, UID/GID checks are bypassed when
; including files from this directory and its subdirectories.
; (directory must also be in include_path or full path must
; be used when including)
; http://php.net/safe-mode-include-dir
safe_mode_include_dir ="

and

" Whether to allow include/require to open URLs (like http:// or ftp://) as files.
; http://php.net/allow-url-include
allow_url_include = Off" 

 

your help and your patience is much appreciated

 

Thanks

Kate

safe_mode_include_dir ="

This seems like it should be a 0 or a 1.

 

Also have you tried adding a trailing slash to

$clientLibraryPath = '/www/ttunrm/ZendGdata/library';

to make it

$clientLibraryPath = '/www/ttunrm/ZendGdata/library/';

safe_mode_include_dir is fine the way it is, unless safe_mode is actually set to 1. Then you might need to set a path on this, if you want to bypass the GUID/UID checks. So not necessarily required in then either.

 

However, upon going through the code a bit, I did notice that there were some instances where errors have been suppressed by using @ in front of the function call. Remove these instances, turn on error reporting (if you haven't already), and go through the script step by step until you find exactly where it fails.

Without this information and/or an error message, I'm afraid we really can't help you any further. At least not without replicating the exact environment in which you're experiencing the issue.

 

PS: Make sure you put those two lines you were supposed to add, before you include the loader script. Or rather, before you make the InstallationChecker object.

 

PPS: Also, I'm a bit confused as to why you're using the above class. Reason for this is that you noted that you don't have Zend Framework available, but the class in question relies upon Zend Framework and actually seems to exists solely to verify that the ZF installation is correct.

OK,

 

JesiRose I tried adding a slash with no results.  I can't actually change the php.ini file as I understand it because the values are set for everyone using the server so I can't alter the values for things like "safe_mode_include".  Of course the server folks emailed me to ask if I figured this out yet and apparently haven't checked to see if php_includes are turned off.  Fortunately I am not sure the problem is on their end.

 

Christian

I turned on error reporting and ran my script again.  It is reporting "no errors" but seems to be breaking (not sure if that is the right term) shortly after it gets started so what I get when I visit my installation_check website is a page full of most of the script code and at the bottom the report of no errors.

 

It is breaking right after the first arrow before the second 'array' in the following bit of code

   private $_allErrors = array(
        self::PHP_EXTENSION_ERRORS => array(
            'tested' => false, 'errors' => null),
        self::ZEND_GDATA_INSTALL_ERRORS => array(
            'tested' => false, 'errors' => null),
        self::SSL_CAPABILITIES_ERRORS => array(
            'tested' => false, 'errors' => null),
        self::YOUTUBE_API_CONNECTIVITY_ERRORS => array(
            'tested' => false, 'errors' => null)
            );

 

what I see printed/typed out on the screen is the text of the code starting with the first array in the code scrap above

 

I am still on a steep learning curve but all this bit is doing is setting up an array that contains 4 arrays with false or null values for the variables 'tested' &'errors' right?  I couldn't find any other instance of the $_allerrors array in the code.  I didn't write this I am just trying to use this code to figure out if my ZendGdata is correctly installed on the server so I am not sure what the $_allerrors array is for.

 

Thanks again for your help.

 

Kate

:shrug:

What happens if you click on "view source" in your browser?

Reason I ask is that it sounds like the PHP code is not parsed as PHP, which means that the file is either missing the correct extension (.php) or that there's some issue(s) on your server preventing PHP code from being parsed.

Christian,

 

I am pretty sure I looked at the code at one point with view source.  It looked fine.  I am also pretty sure that I created the file as a php file and it has the correct extension.  I will double check at work in the morning.  I know other php files seem to work OK on our server but this is the first one I have tried to create.  If I need to I can bug my administrator again tommorow.

 

Thanks for your help.

 

Kate

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.