Editor in custom code doesn't work - joomla

I've inherited some custom code running in Joomla 3.0.2 - we it's actually some standalone php/javascript that's run using Sourcerer (ie not a proper component).
I need it to display an rich-text editor, so I'm trying to use the standard editors which come with joomla. I've written some PHP based on this tutorial:
$document =& JFactory::getDocument();
$document->addScript('includes/js/joomla.javascript.js');
$editor =& JFactory::getEditor();
echo $editor->display('content', 'some content', '550', '400', '60', '20', false);
However all I get is a standard textarea without the toolbars. I've tried setting all pre-installed editors (CodeMirror, TinyMCE) to the default editor, plus I've tried the JCE and JoomlaCK plugins - all with the same result.
I guess the problem is that the code example is for an older version of Joomla, as includes/js/joomla.javascript.js doesn't exist. But I can't find an updated example anywhere... please help!

Try using the following:
$document = JFactory::getDocument();
$document->addScript(JURI::root() . 'includes/js/joomla.javascript.js');
$editor = JFactory::getEditor();
echo $editor->display('content', 'some content', '550', '400', '60', '20', false);

Related

Programmatically get Turpentine to apply VCL to Varnish from the commandline

I'm deploying a server using Ansible. I would like to get Turpentine to apply VCL from the command line so that when I first visit the new server it's already using the correctly compiled VCL for that environment.
Run a command like php ~/applyvcl.php
and in the php file:
<?php
require_once '/path/to/magento/app/Mage.php';
Mage::app('admin');
$res = Nexcessnet_Turpentine_Model_Varnish_Admin::applyConfig();
var_dump($res);
?>
You should see success message from that.

Accessing php files out of root folder(Laravel)

Inside my Magento Project folder I want to install laravel so that I can access Mage from laravel. Directory structure is following
Magento(root)
--laravel
--app
...
...
How can I achieve That? Or suggest any other way so that I can access magento from laravel like following.
require_once ('../app/Mage.php');
Mage::app();
Mage::getSingleton('core/session', array('name' => 'frontend'));
$collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
UPDATE
Controller Location relative to magento
D:\xampp\htdocs\magento\custom\app\controllers\ProductsController.php
Make sure the path is correct, it should work.
Use this one
require_once (realpath(dirname(__FILE__) . '/../app/Mage.php'));
Your path ( require_once ('../app/Mage.php'); ) is not correct that's why you are facing this issue.Except this logic wise your code is correct.
If you are running your code from somefile.php in laravel then it should work.
Magento(root)
--laravel
|__somefile.php
--app
...
...
I have used dirname() function to solve this problem.
require_once (dirname(dirname(dirname(dirname(realpath(__FILE__))))).'/app/Mage.php');
I don't think this the nice or smart way, but it works. Thanks.
Maybe someone useful:
require_once (dirname(dirname(dirname(dirname(realpath(__FILE__))))).'/../app/Mage.php');
\Mage::app();
$blocks = \Mage::getModel('cms/block')->getCollection();
foreach ($blocks as $block) {
echo $block->getTitle()."<br>";
}

Get Magento Session in Directory that is outside Magento

I want to get customer session in a dir which is outside of my magento main dir. For e.g. root/magento/ => is my installation dir
root/temp/ => is my test folder
root/checksession.php => is the file on root of magento installation
root/temp/checksession.php => is the file outside of magento dir and inside of external dir.
Here i am getting the customer session in root/checksession.php but i dont know why the same coding is not working with root/temp/checksession.php
Have tried include, define and php session method, but still its not working.
Do any one have idea, how it is possible to get magento session in root/temp/checksession.php file???
require_once 'app/Mage.php';
Mage::app("default");
$coreSession = Mage::getSingleton('core/session', array('name' => 'frontend'));
session_start();
$_SESSION["coreSession"] = $coreSession;
echo "<pre>";print_r($coreSession);
I think you forgot the following:
Mage::app('admin')->setUseSessionInUrl(false);

Laravel 3 Snappy bundle Class Snappy not found

I'm struggling to get the Snappy bundle to work.
It keeps telling me that the Snappy Class is not found.
I've installed the bundle and added it to the bundles.php file for auto loading.
But still nothing.
All help is appreciated :) Thanks
I found the solution,
I had everything installed correctly but the issue was I should be using namespaces. On the bundle page it says the usage is something like this.
Bundle::start('snappy');
$snappy = Snappy::make('/usr/bin/wkhtmltopdf');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="file.pdf"');
echo $snappy->getOutput('http://laravel.com');
exit;
The correct way to do this is to use the namespace like so
Bundle::start('snappy');
// the following two lines is added
use Knp\Snappy\Pdf;
$snappy = new Pdf('/usr/local/bin/wkhtmltopdf');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="file.pdf"');
echo $snappy->getOutput('http://laravel.com');
exit;
If you have installed the bundle using Artisan then (from a quick look at the bundles GitHub repository) you need to rename the folder bundles/snappy-laravel-bundle to just snappy. Or you can add in a location key in the bundles registration in application/bundles.php.
'snappy' => array('auto' => true, 'location' => 'snappy-laravel-bundle')
Laravel, by default, will assume that the key of the array (in this case snappy) is the directory that the bundle is stored in in the bundles directory.

Joomla include js using jumi

I can't manage to include a javascript in an article(directly in the wysiwyg editor) using jumi.
What I've tried:
{jumi /path/to/file.js}
{jumi [/path/to/file.js]}
{jumi /path/to/file.js}{/jumi}
{jumi [/path/to/file.js]}{/jumi}
"file.js" is located in a folder in the same directory as Joomla.
I'm using joomla v. 1.7.3 and Jumi 2.0.6.
Is there something I'm missing?
I'm not sure if this solution is much different than yours, but you can got to the Jumi Application Manager and create a new entry like this:
<?php
$document =& JFactory::getDocument();
$document->addStyleSheet('path/file.css');
$document->addScript('path/file.js');
?>
Then add this to your article:
{jumi[*5]}
Where "5" is the id of the Jumi entry.
At least this is how I do it in Joomla 1.5...
I've found a workaround, it's not elegant, but it works:
create two files, 1 php which will echo a script element and a javascript file that you wish to include
in the article put:
{jumi [path/to/a/php/file.php]}
the php file should be
<?php
echo "<script type=\"text/javascript\" language=\"javascript\" src=\"path/to/js/file.js\"></script>"
?>
Enjoy!

Resources