Joomla changing active menu - joomla

How can the menu be changed using code?
I have found that:
$currentMenuId = JSite::getMenu()->getActive()->id ;
Returns the current active Menu item
However,
$menu->setActive( $menuitemid );
Does not do anything,
Whether I use,
$app = JFactory::getApplication(); $menu = $app->getMenu();
$menu->setActive( $menuitemid );
or,
$menu = JSite::getMenu(); $menu->setActive( $menuitemid );
How can I change the menu?

Related

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 Custom Content Not Saving

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!!

Set the focus to the editor after a widget is added in ckeditor

How can I set the focus to the editor in CKEditor after a widget is added?
I don't want that the widget stays in focus
have you added startupFocus : true to your config file?
Look up: http://ckeditor.com/forums/CKEditor-3.x/Set-focus-load
An excerpt from my custom config file looks something like this
CKEDITOR.editorConfig = function( config ) {
// Define changes to default configuration here. For example:
config.extraPlugins = 'confighelper';
config.autoGrow_onStartup = true;
config.autogrow_minheight = 50;
config.autogrow_maxheight = 200;
config.contentsLangDirection = 'ui';
config.startupFocus = true;
//more options...
};

Tumblr 'loading more' button

In the first place I want to say sorry for my bad english . I'm trying to develop a tumblr theme , and add a 'loading more' button . I used JavaScript to determinate the current page and the next one . When 'Loading More' button is pressed , I use jQuery to make a request to next tumblr page ex ( sitename.tumblr.ro/page/next-page ) , get the html , extract the posts html and append it to current page . But the problem is that the like button is not working on the appended posts . When I click the button , noting is happening . The cursor is not even pointing ... Here's my javascript code :
var $holder = $('div.posts_holder');
var page = null;
$(document).on('click','div.loading_more.loading_trigger',function(){
if(page == null)
{
page = window.location.href.search('page') > -1 ? window.location.href.split('/')[window.location.href.split('/').length-1] : 1;
}
page = Number(page)+1;
$(this).text('Please Wait..');
var load_page = '{BlogURL}page/'+page;
var $saved = $(this);
//get the page
$.get(load_page,function(response)
{
var $append_html = $(response).find('div.posts_holder');
if($append_html.html().replace(' ','').trim() == '')
{
$saved.removeClass('loading_trigger');
}
$saved.text('Loading More');
$holder.append($append_html.html()).masonry();
$holder.masonry( 'reloadItems' );
$holder.masonry( 'layout' );
setTimeout(function(){
$holder.masonry( 'reloadItems' );
$holder.masonry( 'layout' );
},800);
});
});
I found the answer . You must add :Tumblr.LikeButton.get_status_by_page(page); to your javascript after you added new items ,where 'page' is the number of page you just added.

How to render this Joomla module to another position without loosing its connection to the article

This is code from the Dizi-images module (plugin/content/images/images.php) for Joomla. This works, it publishes a image or image gallery at the end of a specific article.
But if I want to publish the image/image gallery to another position (by changing its position in Joomla admin and the getModules-value in the code below) it looses its "connection" to the article. It shows up on every article on the site.
Is it possible to make this code below to be able to publish the image/image gallery to another position without loosing its connection to the specific article?
/*
* load front end images module
*/
public function onContentAfterDisplay( $context, &$row, &$params, $limitstart = null )
{
$jinput = JFactory::getApplication()->input;
$option = $jinput->get('option', '', '');
$view = $jinput->get('view', '', '');
if( $context == 'com_content.article' && ( $modules = JModuleHelper::getModules( 'images' ) ) )
{
return JModuleHelper::renderModule( $modules[ 0 ] );
}
return '';
}
Thanks
Magnus
Screenshot of the modules that I change position on (Joomla Admin/Extensions/Module Manager/)
The plug-in I use is "Dizi images gallery"-extension.
This shows the Dizi-images Tab. Where you add images/image gallery to the article your in.
These three lines of code will allow you load and render any existing modules as needed.
jimport( 'joomla.application.module.helper' );
$module = JModuleHelper::getModule('mod_myimagemodulename', 'Images Gallery');
echo JModuleHelper::renderModule($module, array('style' => 'xhtml'));
If you want to manage from the back end, you will need to make a duplicate of the existing module with different menu position assignments. It sounds like the only limitation is the source images folder, so the module should not mind!
** EDIT **
To create a new position like "right", you would need to add a new jdoc element to your templates index.php where you would like the new position:
<jdoc:include type="moduels" name="right" style="xhtml" />
Then in your templates manifest XML file, add the new position to list of existing positions:
<position>right</position>
Now if you navigate to the module copy you want to place there, you would be able to select the newly created "right" position.
** EDIT **
Noticed something in how the module instance is being loaded, the name should reflect the the module type and name.
$modules = JModuleHelper::getModules( 'images', 'Images gallery' )
And definitely migrate away from JRequest.
Why not just create a new instance of the module for the other position? That way this module stays just as it is and the new module is published elsewhere without conflicting with the code you have.
Also agree with Lodder, use JInput.

Resources