Joomla Custom Content Not Saving - joomla

I have written a simple plugin to include custom content against Joomla articles. Here's the code:
defined ( '_JEXEC' ) or die ( 'Restricted access' );
class plgContentHomegrid extends JPlugin {
protected $autoloadLanguage = true;
function onContentPrepareForm($form, $data) {
$app = JFactory::getApplication();
$option = $app->input->get('option');
switch($option) {
case 'com_content':
if ($app->isAdmin()) {
JForm::addFormPath(__DIR__ . '/forms');
$form->loadFile('homegrid', false);
}
return true;
}
return true;
}
}
This works fine, the additional fields are displayed as a separate tab in admin, data saves correctly and everything's perfect. So far so good...however, I only want to display the additional tab on the home page. So, I amended the code so the additional form is only displayed for the home page:
if( $data->featured == 1 ){
$form->loadFile('homegrid', false);
}
The form now only displays on the home page admin screen as needed BUT the data is not saved.
What am I doing wrong?

OK, the problem comes because my conditional references the $data item, which is not populated during save, just display (as recorded here)
So, a little investigation finds this solution works fine:
if( $data->featured == 1 || $_POST['jform']['featured'] == 1 ){
$form->loadFile('homegrid', false);
}
There seems to be no documentation anywhere on this!!

Related

#9073 ImageUpload callback can not be called cross-domain CKEditor

https://dev.ckeditor.com/ticket/9073
I had a unique scenario that requires my image uploader/image management system to be hosted on a separate sever. Because of this, I ran into the security-error-blocked-a-frame-with-origin-from-accessing-a-cross-origin-frame error.
Through my research I was not able to identify a clear answer to solving this problem; although there may already be a way to do this/better way, I wanted to post my workaround here in case anyone else can use it.
CKEDITOR.on( 'dialogDefinition', function( ev ) {
console.log('dialof def');
var dialogName = ev.data.name,
dialog = ev.data.definition.dialog;
//verify dialog is of name image
if ( dialogName == 'image' ) {
//on show create click event listener
dialog.on('show', function(){
window.addEventListener("click", evalClickEventType, false);
})
//evaluate click event to ensure it is Browse Server button
function evalClickEventType(event){
if(event.srcElement.innerText == 'Browse Server'){
createMessageListener();
}
//if either type of close, or ok, remove clickEventListener
else if (event.srcElement.innerText == 'OK' || event.srcElement.innerText == 'X' || event.srcElement.innerText == 'Cancel'){
window.removeEventListener("click", evalClickEventType, false);
}
}
//add event listener for type message
function createMessageListener()
{
window.addEventListener("message", receiveMessage, false);
}
//set value to txtUrl when event message is emitted.
function receiveMessage(event){
CKEDITOR.dialog.getCurrent().setValueOf( 'info', 'txtUrl', event.data );
window.removeEventListener("message", receiveMessage, false);
}
}});
then simply replace
window.opener.CKEDITOR.tools.callFunction( funcNum, fileUrl );
with this in your image management solution to pass the url from cross-origin server.
var targetWindow = window.opener;
targetWindow.postMessage(imgSrc, "*")
https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage

Magneto - block orders from specific state

I'm looking to restrict the ability for orders in Magento to specific states, or rather, block a specific state.
I'm selling products that I don't want local competition to be able to easily purchase.
It'd be even cooler to use some form of geo location to display a banner on the site, saying we don't allow orders from your state only if the IP seems to come from that state.
Or maybe a hack would be to use a geo location, and css hide the add to cart button if the IP was based from specific state?
any suggestions!
Thanks!
edit: I've been able to get the state like this:
but how to say "if state=X, then load this css file, which could hide add to cart, display a banner, etc."
<?php
function getClientIP(){
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
$ipaddress = getClientIP();
function ip_details($ip) {
$json = file_get_contents("http://ipinfo.io/{$ip}/geo");
$details = json_decode($json, true);
return $details;
}
$details = ip_details($ipaddress);
echo $details['region'];
?>
I'm against hiding a CTA button using css, what if someone just inspects the page and unhides it. I suggest you to do something similar to this.
//considering you can fetch the location using your php logic in your server side already.
$details = ip_details($ipaddress);
$loc = $details['region'];
blockedList = array(); //maintain the list of blocked states here.
if(in_array($loc,$blockedList){
//display banner, hide add-to-cart button
} else {
//display add-to-cart button
}
This magento extension wasn't easy to find for some reason, but it works!
http://www.magentocommerce.com/magento-connect/regions-manager.html

Joomla 3 Module Alternative Layout appears in dropdown but won't apply to module

I downloaded and installed a module called rQuotes which I'm trying to tweak using an alternative layout. At first I just copied over the default.php to a appropriate folder mod_rquotes under html in my template directory, changed it's name to testimonials.php and made my changes. The alternative layout appears correctly in the admin but when selected, the alternative layout is not used, instead it continues to use the default.php layout.
Following some notes on article templates, I tried copying over the mod_rquotes.xml and calling it testimonials.xml but that had no effect. I'm placing the module using the modules anywhere component to drop it directly into an article so I don't think the menu restriction should have any effect.
The mod_rquotes.php by request:
<?php
/**
* Rquotes main file
*
* #package Joomla.Rquotes
* #subpackage Modules
* #link www.mytidbits.us
* #license GNU/GPL-2
*/
//no direct access
defined('_JEXEC') or die('Restricted access');
if(!defined('DS')){
define('DS',DIRECTORY_SEPARATOR);
error_reporting(0);
}
//include helper file
require_once(dirname(__FILE__).DS.'helper.php');
$source=$params->get('source');
//text file params
$filename=$params->get('filename','rquotes.txt');
$randomtext=$params->get('randomtext');
//database params
$style = $params->get('style', 'default');
$category=$params->get('category','');
$rotate = $params->get('rotate');
$num_of_random= $params->get('num_of_random');
switch ($source)
{
case 'db':
if($rotate=='single_random')
{
$list = modRquotesHelper::getRandomRquote($category,$num_of_random);
}
elseif($rotate=='multiple_random')
{
$list = modRquotesHelper::getMultyRandomRquote($category,$num_of_random);
}
elseif($rotate=='sequential')
{
$list = modRquotesHelper::getSequentialRquote($category);
}
elseif($rotate=='daily')
{
$list= getDailyRquote($category);
}
elseif($rotate=='weekly')
{
$list= getWeeklyRquote($category);
}
elseif($rotate=='monthly')
{
$list= getMonthlyRquote($category);
}
elseif($rotate=='yearly')
{
$list= getYearlyRquote($category);
}
//start
elseif($rotate=='today')
{
$list= getTodayRquote($category);
}
//end
require(JModuleHelper::getLayoutPath('mod_rquotes', $style,'default'));
break;
case 'text':
if (!$randomtext)
{
$list=getTextFile($params,$filename);
}
else
{
$list=getTextFile2($params,$filename);
}
break;
default:
echo('Please choose a text file and Daily or Every page load and save it to display information.');
}
?>
This module is buggy, that's all.
Looking at the code it does hardcode the layout to the textfile layout in its helper if you are using a textfile as source.
If you're using the database as source it doesn't get better. It looks like it does get the module chrome (style) setting and applies this to the layout, which is bound to fail as well.
Personally I wouldn't use this module as it is written horrible. But if you need it you can just override the textfile layout with your own in your template. Name the file textfile.php as well and do your changes and it will work.

Tinymce is (sometimes) undefined

I'm using Tinymce (with jQuery) in a project I'm working at; we use a rich text editor for users to input information; however, sometimes when loading the page Firefox and Chrome will detect a 'tinymce is not defined' error (sometimes at different lines of the code), while other times the page will load just fine. What's weird is that it works perfectly with IE.
Here's a bit of the code I'm using:
view.find('textarea.rich-text').each(function () {
$(this).tinymce( /* ...rules... */);
});
And later on
_variable.find("#summary").tinymce().setContent(content);
This line is where the error (sometimes) gets caught. It seems to me that the problem is a loading issue, even though the tinyMCE plugin is initialized about 5000 lines prior this line.
Update: For now I have managed to 'solve' the problem with a setTimeout, but this seems like a really ugly way to do it.
A few points:
You don't mention whether or not the TinyMCE initialization is done within a jQuery ready event function. It should be of course.
You don't need the each loop. You can just say:
$('textarea.rich-text').tinymce({
script_url : '../js/tinymce/jscripts/tiny_mce/tiny_mce.js',
theme : "advanced",
...
});
You don't need the call to find since you are just selecting by id. Just do:
$("#summary").tinymce().setContent(content);
Your real issue is probably that tinymce has not finished initializing itself when you get the error. You see it has to load a script from the configured script_url. That may take a while. Therefore, you have to make use of a callback such as oninit.
If you do not have control over init method of TinyMCE then, you can follow this solution.
jQuery(document).ready(function($) {
function myCustomSetContent( id, content ) {
// Check if TinyMCE is defined or not.
if( typeof tinymce != "undefined" ) {
var editor = tinymce.get( id );
// Check if TinyMCE is initialized properly or not.
if( editor && editor instanceof tinymce.Editor ) {
editor.setContent( text );
editor.save( { no_events: true } );
} else {
// Fallback
// If TinyMCE is not initialized then directly set the value in textarea.
//TinyMCE will take up this value when it gets initialized.
jQuery( '#'+id ).val( text );
}
return true;
}
return false;
}
function myCustomGetContent( id ) {
// Check if TinyMCE is defined or not.
if( typeof tinymce != "undefined" ) {
var editor = tinymce.get( id );
// Check if TinyMCE is initialized properly or not.
if( editor && editor instanceof tinymce.Editor ) {
return editor.getContent();
} else {
// Fallback
// If TinyMCE is not initialized then directly set the value in textarea.
// TinyMCE will take up this value when it gets initialized.
return jQuery( '#'+id ).val();
}
}
return '';
}
$(".class-to-update-content").on("click", function(e) {
myCustomSetContent( "tinymce-editor-id", "New Content in Editor" );
});
$(".class-to-get-content").on("click", function(e) {
$("div.class-to-display-content").html( myCustomGetContent( "tinymce-editor-id" ) );
});
});
Ref : http://blog.incognitech.in/tinymce-undefined-issue/
EDIT: Solution included

Form validation on Facebook tab

I am using static FBML but I am having trouble debugging a form validation problem. I get the dialog which to me seems like it should return false, but the form submits anyway. I am using Firebug and I see a brief message in Red that I have no chance to read. I appreciate the help :-)
var txt ='Enter Zipcode';
//...
function setError(){
var obj=document.getElementById('mapsearch');
obj.setValue(txt);
obj.setStyle('color', '#FF0000');
}
function valform(){
var obj=document.getElementById('mapsearch');
var val = obj.getValue();
if(val!='' && !isNaN(val) && val.length>2 ){
return true;
} else {
setError();
(new Dialog()).showMessage('Zip Required', 'Please enter your zip code.');
return false;
}
}
//...
Try the "Persist" button if the Firebug/javascript error message in Firebug disappears too quickly. This way all messages are kept between page loads until you click "Clear".

Resources