newscoop installation error - php

When trying to install the Newscoop 4 Script ob my website...I get this Error:
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/content/24/8222924/html/newscoop4/application.php on line 65
Parse error: syntax error, unexpected T_FUNCTION in /home/content/24/8222924/html/newscoop4/application.php on line 68
and the file it shows error in is this, i think it has something to do with the back slashes because php cant render it completely but my php version is 5.3 hopefully:
<?php
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', __DIR__ . '/application');
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
// goes to install process if configuration files does not exist yet
if (!defined('INSTALL') && (!file_exists(APPLICATION_PATH . '/../conf/configuration.php')
|| !file_exists(APPLICATION_PATH . '/../conf/database_conf.php'))) {
$subdir = substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], '/', -2));
if (strpos($subdir, 'install') === false) {
header("Location: $subdir/install/");
exit;
}
}
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
realpath(APPLICATION_PATH . '/../include'),
get_include_path(),
)));
if (!function_exists('stream_resolve_include_paths')) {
function stream_resolve_include_paths($filename) {
foreach (explode(PATH_SEPARATOR, get_include_path()) as $include_path) {
$realpath = realpath("{$include_path}/{$filename}");
if ($realpath !== false) {
return $realpath;
}
}
return false;
}
}
if (!stream_resolve_include_paths('Zend/Application.php')) {
// include libzend if we don't have zend_application
set_include_path(implode(PATH_SEPARATOR, array(
'/usr/share/php/libzend-framework-php',
get_include_path(),
)));
}
/** Zend_Application */
require_once 'Zend/Application.php';
if (defined('INSTALL')) {
$oldErrorReporting = error_reporting();
error_reporting(0);
if (!class_exists('Zend_Application', FALSE)) {
die('Missing dependency! Please install Zend Framework library!');
}
error_reporting($oldErrorReporting);
}
// Create application, bootstrap, and run
$application = new \Zend_Application(APPLICATION_ENV);
// Set config
$setConfig = function(Zend_Application $application) {
require_once 'Zend/Config/Ini.php';
$defaultConfig = new \Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini-dist', APPLICATION_ENV);
$config = $defaultConfig->toArray();
if (is_readable(APPLICATION_PATH . '/configs/application.ini')) {
try {
$userConfig = new \Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV);
$config = $application->mergeOptions($config, $userConfig->toArray());
} catch (\Zend_Config_Exception $e) { // ignore missing section
}
}
$application->setOptions($config);
};
$setConfig($application);
unset($setConfig);
>

Related

Fatal error: Uncaught LogicException: Function autooad not found

I would know if there something speficic in php 7.3.3-1+0~20190307202245.32+stretch~1.gbp32ebb2
because I have this error when I try to install a software.
:autoload' not found (class 'Core\\OM\\CORE' not found)
Got error 'PHP message: PHP Fatal error: Uncaught LogicException: Function 'Core\\OM\\CORE::autoload' not found (class 'Core\\OM\\CORE' not found) in /var/www/.........../application.php:21\nStack trace:\n#0 /var/www/........./application.php(21): spl_autoload_register('Core\\\\OM...')\n#1 /var/www/clients/........./install/index.php(12): require('/var/www/client...')\n#2 {main}\n thrown in /var/www/........../install/includes/application.php on line 21'
On my localhost under linux, I have not this problem and everything works fine.
php : PHP Version 7.3.2-3
Thank you
For example in install.php directory :
use Core\OM\CORE;
use Core\OM\HTML;
// set the level of error reporting
error_reporting(E_ALL & ~E_DEPRECATED);
define('CORE_BASE_DIR', realpath(__DIR__ . '/../../includes/') . '/Core/');
require(CORE_BASE_DIR . 'OM/CORE.php');
spl_autoload_register('Core\OM\CORE::autoload')
about CORE.PHP
public static function autoload($class) {
$prefix = 'Core\\';
if (strncmp($prefix, $class, strlen($prefix)) !== 0) {
return false;
}
if (strncmp($prefix . 'OM\Module\\', $class, strlen($prefix . 'OM\Module\\')) === 0) { // TODO remove and fix namespace
$file = dirname(CORE_BASE_DIR) . '/' . str_replace(['Core\OM\\', '\\'], ['', '/'], $class) . '.php';
$custom = dirname(CORE_BASE_DIR) . '/' . str_replace(['Core\OM\\', '\\'], ['Core\Custom\OM\\', '/'], $class) . '.php';
} else {
$file = dirname(CORE_BASE_DIR) . '/' . str_replace('\\', '/', $class) . '.php';
$custom = str_replace('Core/OM/', 'Core/Custom/OM/', $file);
}
if (is_file($custom)) {
require($custom);
} elseif (is_file($file)) {
require($file);
}
}

PHP autoload looking in current php file

In file: deckclass.php , with DOCROOT set to /var/www/Proj/application/controllers
getting error: Fatal error: Class 'Cardclass' not found in /var/www/Proj/application/controllers/deckclass.php on line 38
Why is it searching current php file and not DOCROOT folder?
function __autoload($class_name)
{
//class directories
$filename = DOCROOT .strtolower($class_name) . ".php";
if ( file_exists($filename) )
{
require_once ($filename);
}
else {
throw new Exception("Unable to load $class_name.");
}
}
$card = new Cardclass();
You can use define('ROOT', dirname(__FILE__)); and define('DS', DIRECTORY_SEPARATOR);
Tip
spl_autoload_register() provides a more flexible alternative for
autoloading classes. For this reason, using __autoload() is
discouraged and may be deprecated or removed in the future.
So do code should look like this:
<?php
define('DS', DIRECTORY_SEPARATOR);
define('ROOT', dirname(__FILE__)); //This is full path
spl_autoload_register('Autoloader'); //You can use annonymous function here
function Autoloader($class_name){
$filename = ROOT.DS.strtolower($class_name).".php";
var_dump($filename);
if(file_exists($filename)){
require_once ($filename);
}else{
throw new Exception("Unable to load ".$class_name."in".$filename);
}
}
$card = new Cardclass();
With __autoload:
<?php
define('DS', DIRECTORY_SEPARATOR);
define('ROOT', dirname(__FILE__)); //This is full path
function __autoload($class_name){
$filename = ROOT.DS.strtolower($class_name).".php";
var_dump($filename);
if(strpos($class, 'CI_') !== 0) {
if(file_exists($filename)){
require_once ($filename);
}else{
throw new Exception("Unable to load ".$class_name."in".$filename);
}
}
}
$card = new Cardclass();

Class not found in Bootstrap.php in CLI mode (Zend)

I am getting an error when trying to run app in CLI mode. First of all I have daemon controller which allows to run daemon instances (objects with only one required method 'run' derived from my daemon interface) using url /daemon-cli/:Daemon_Class_To_Run. So there is nothing interesting from this side.
Also I have little sh script to run this controller in a simplified way like this:
# ./daemon.sh Ami_Daemon_EventParser
This returns me the next error:
<?
class System_Controller_Plugin_ModuleLayoutLoader extends Zend_Controller_Plugin_Abstract {
/**
* Array of layout paths associating modules with layouts
*/
protected $_moduleLayouts;
// here was the full code of this class
}
PHP Fatal error: Class 'System_Controller_Plugin_ModuleLayoutLoader' not found in /var/www/htdocs/application/Bootstrap.php on line 99
System namespace is located in application/library/System and this is just a set of toolkits and libraries. That is completely weird because it works well in apache2handler mode, but crashes in cli. I don't understand how the class cannot be found if the code of "not founded" class are returned in the error. I suppose I bootstrapped application in a wrong way.
Some of bootstrap code:
protected function _initAppModules()
{
$modules = array();
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('System_');
$includePath = '';
// Add model directories to include path
if ($dhApp = opendir(APPLICATION_PATH . '/modules')) {
while (($dirApp = readdir($dhApp)) !== false) {
if (substr($dirApp, 0, 1) != '.' && is_dir(APPLICATION_PATH . '/modules/' . $dirApp)) {
$modules [] = $dirApp;
if ($dhModule = opendir(APPLICATION_PATH . '/modules/' . $dirApp)) {
while (($dirModule = readdir($dhModule)) !== false) {
if ($dirModule == 'library' && is_dir(APPLICATION_PATH . '/modules/' . $dirApp . '/library')) {
$includePath .= PATH_SEPARATOR . APPLICATION_PATH . '/modules/' . $dirApp . '/library';
$autoloader->registerNamespace(ucfirst($dirApp));
}
}
closedir($dhModule);
}
}
}
closedir($dhApp);
}
ini_set('include_path', ini_get('include_path') . $includePath);
return $modules;
}
protected function _initResources()
{
Zend_Controller_Action_HelperBroker::addPrefix('System_Controller_Action_Helper');
$resourceLoader = new Zend_Loader_Autoloader_Resource(array('basePath' => APPLICATION_PATH . '/library/System', 'namespace' => ''));
$resourceLoader->addResourceTypes(array('form' => array('path' => 'Form/Resource/', 'namespace' => 'Form'), 'model' => array('path' => 'Model/Resource/', 'namespace' => 'Model')));
System_API_Abstract::load();
return $resourceLoader;
}
protected function _initView(array $options = array())
{
$this->bootstrap('AppModules');
$this->bootstrap('FrontController');
$view = new Zend_View();
$view->addScriptPath(APPLICATION_PATH . '/views/scripts');
$view->addHelperPath(APPLICATION_PATH . '/views/helpers', 'View_Helper');
$view->addHelperPath(APPLICATION_PATH . '/modules/gui/views/helpers', 'View_Helper');
$view->addHelperPath(APPLICATION_PATH . '/library/System/View/Helper', 'System_View_Helper');
// next line triggers the error
$layoutModulePlugin = new System_Controller_Plugin_ModuleLayoutLoader();
foreach ($this->getResource('AppModules') as $module) {
if (is_dir(APPLICATION_PATH . '/modules/' . $module . '/views/layouts')) {
$layoutModulePlugin->registerModuleLayout($module, APPLICATION_PATH . '/modules/' . $module . '/views/layouts');
}
if (is_dir(APPLICATION_PATH . '/modules/' . $module . '/views/helpers')) {
$view->addHelperPath(APPLICATION_PATH . '/modules/' . $module . '/views/helpers', ucfirst($module) . '_View_Helper');
}
}
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
$viewRenderer->setView($view);
Zend_Layout::startMvc(array('layoutPath' => '../application/views/layouts', 'layout' => 'layout'));
$this->getResource('FrontController')->registerPlugin($layoutModulePlugin);
return $view;
}
And in the index.php I bootstrap all modules.
if (php_sapi_name() == 'cli') {
$_SERVER['REQUEST_URI'] = $argv[1];
$_SERVER ['HTTP_HOST'] = 'mydomain.info';
ini_set('session.use_cookies', false);
$application->bootstrap()->run();// in case if I find the way to bootstrap partially
} else {
$application->bootstrap()->run();
}
I am fighting with this for a couple of weeks, so I hope somebody has an answer or a good advice. Any help is greatly appreciated. Thanks!
Finally I did that!
As you can see I had a php short tag in the error output. Php often uses separate php.ini for cli mode as my rackspace distributive does. Php distros for windows usually have the common ini file.

spl_autoload_reqister classes not getting loaded

I have a folder structure that looks like
base_dir-
Includes.php
Libs-
Database.php
Log.php
Cofing.php
Models-
someClass.php
Scheduled-
test.php
My Includes.php has
spl_autoload_register(NULL, FALSE);
spl_autoload_extensions('.php, .class.php, lib.php');
function libLoader($name) {
$file = 'Libs/' . $name . '.php';
if (!file_exists($file)) {
// throw new Exception("Error Loading Library: $file does not exists!", 1);
return FALSE;
}
require_once $file;
}
function modelLoader($name) {
$file = 'Models/' . $name . '.php';
if (!file_exists($file)) {
// throw new Exception("Error Loading Library: $file does not exists!", 1);
return FALSE;
}
require_once $file;
}
spl_autoload_register('libLoader');
spl_autoload_register('modelLoader');
My someClass.php has
require_once '../Includes.php';
class someClass extends Database
{
public function __construct() { return 'hello world'; }
}
And test.php has
require_once '../Includes.php';
try {
$loads = new someClass();
} catch (Exception $e) {
echo "Exception: " . $e->getMessage();
}
When I run test.php I get someClass not found on .../Scheduled/test.php
Does spl works with extended classes like someClass.php or do I need to include the class to be exended?
And why it wouldnt find someClass.php?
Thanks
Change
$file = 'Models/' . $name . '.php';
to
$file = __DIR__ . '/Models/' . $name . '.php';
in your models autoloader (and the equivalent in your libLoader) to ensure that it's searching from the correct directory, and not the directory where your test.php file is located

How to run a script which uses ZendFramework library from CLI

I intend to run a script using ZendFramework library from CLI.
My script is as following:
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Rest_Client');
It can run in a browser, but failed in a command prompt. How can I let the script run from CLI?
Thanks!
this post has some the info you are looking for: Running a Zend Framework action from command line
Below you will find complete functional code that I wrote and use for cron jobs within my apps...
Need to do the following:
pull required files in you cli file
initialize the application and bootstrap resources. Here you can capture cli params and setup request object so it is dispatched properly.
set controller directory
run the application
Here is documentation on Zend_Console_Getopt that will help you understand how to work with cli params.
code for cli.php
<?php
// Define path to application directory
defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Define application environment
defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'development');
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/libraries'),
get_include_path(),
)));
// initialize application
require_once 'My/Application/Cron.php';
$application = new My_Application_Cron(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
$application->bootstrap();
//
Zend_Controller_Front::getInstance()->setControllerDirectory(APPLICATION_PATH . '/../scripts/controllers');
//
$application->run();
My_Application_Cron class code:
<?php
// because we are extending core application file we have to explicitly require it
// the autoloading occurs in the bootstrap which is part of this class
require_once 'Zend/Application.php';
class My_Application_Cron extends Zend_Application
{
protected $_cliRequest = null;
protected function _bootstrapCliRequest()
{
$this->_isCliBootstapped = true;
try {
$opts = array(
'help|h' => 'Displays usage information.',
'action|a=s' => 'Action to perform in format of module.controller.action',
'params|p=p' => 'URL-encoded parameter list',
//'verbose|v' => 'Verbose messages will be dumped to the default output.',
);
$opts = new Zend_Console_Getopt($opts);
$opts->setOption('ignoreCase', true)
->parse();
} catch (Zend_Console_Getopt_Exception $e) {
exit($e->getMessage() . "\n\n" . $e->getUsageMessage());
}
// See if help needed
if (isset($opts->h)) {
$prog = $_SERVER['argv'][0];
$msg = PHP_EOL
. $opts->getUsageMessage()
. PHP_EOL . PHP_EOL
. 'Examples:' . PHP_EOL
. "php $prog -a index.index'" . PHP_EOL
. "php $prog -a index.index -p 'fname=John&lname=Smith'" . PHP_EOL
. "php $prog -a index.index -p 'name=John+Smith'" . PHP_EOL
. "php $prog -a index.index -p 'name=John%20Smith'" . PHP_EOL
. PHP_EOL;
echo $msg;
exit;
}
// See if controller/action are set
if (isset($opts->a)) {
// Prepare necessary variables
$params = array();
$reqRoute = array_reverse(explode('.', $opts->a));
#list($action, $controller, $module) = $reqRoute;
// check if request parameters were sent
if ($opts->p) {
parse_str($opts->p, $params);
}
//
$this->_cliRequest = new Zend_Controller_Request_Simple($action, $controller, $module);
$this->_cliRequest->setParams($params);
}
}
public function bootstrap($resource = null)
{
$this->_bootstrapCliRequest();
return parent::bootstrap($resource);
}
public function run()
{
// make sure bootstrapCliRequest was executed prior to running the application
if (!($this->_cliRequest instanceof Zend_Controller_Request_Simple)) {
throw new Exception('application required "bootstrapCliRequest"');
}
// set front controller to support CLI
$this->getBootstrap()->getResource('frontcontroller')
->setRequest($this->_cliRequest)
->setResponse(new Zend_Controller_Response_Cli())
->setRouter(new Custom_Controller_Router_Cli())
->throwExceptions(true);
// run the application
parent::run();
}
}
To lean how to run the cli scipt simply type command below in terminal:
#> php /path/to/cli.php -h
Hopefully this will help you and others!

Categories