Call function inside Joomla articles - joomla

I am facing a problem. I have created a article in Joomla administrator and i have created a function in a php file. I have to call that function in that article . I don't know how do i call function in article.
Here is the code:
class modVodesbalanceHelper {
function deductBalance()
{
$db = JFactory::getDBO();
$result = null;
$user = JFactory::getUser();
if ($user->guest) {
return false;
}
$query = 'SELECT credit' .
' FROM #__vodes_credits' .
' WHERE userid = ' . (int) $user->id
;
$db->setQuery($query);
$result = $db->loadResult();
$result_final=$result-10;
$query = 'update #__vodes_credits SET credit='.$result_final.
' WHERE userid = ' . (int) $user->id
;
//echo $query;
$db->setQuery($query);
$result = $db->loadResult();
}
}
In admin panel, in article i have write this code:
<script>
window.onload=function()
{
var a=confirm("do you want to purchase this credit");
if(a)
{
document.location.href ="index.php?option=com_content&view=featured";
}
else
{
document.location.href="index.php?option=com_content&view=article&id=3";
}
}
</script>
I have to call deductBalance when user click on the "OK" of comfirm box.
Please tell me to sought it .

You can't add PHP to Joomla article by default. For this you need to use a 3rd party plugin. Personally, I would recommend using Sourcerer. Once installed and enabled, you can use the following in your article:
{source}
<?php
// All your PHP code
?>
{/source}
Don't include PHP files inside your article

I would use Sourcerer to add php code inside joomla article.
Check the sourcerer plugin to be enabled (check plugin enabled status here: extensions->plugin manager->sourcerer).
Then, use the "Insert Code" button at the bottom of your WYSIWYG editor when adding your PHP scripts. Your code should be wrapped with
{source}
//php code wrapped by <?php ?>
{/source}

If you need to use code directly within Joomla article then use Sourcerer as in above questions. If you feel to keep the PHP code in seperate module. Use Blank Module
Or mod_php module. Then in your Joomla Article you can place the code like this,
{loadposition}*Your Custom Module Position*{/loadposition}

Related

add product to wishlist in magento API

I have checked in magento soap API but I can not find API for add product to wish list so I am developing own API but I don't know what is the problem with my code so please help me to find solution.
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
require_once '../app/Mage.php';
Mage::app();
$customer_id = $_GET['customer_id'];
$product_id = $_GET['product_id'];
$customer = Mage::getModel('customer/customer');
$wishlist = Mage::getModel('wishlist/wishlist');
$product = Mage::getModel('catalog/product');
$customer->load($customer_id);
$wishlist->loadByCustomer($customer_id);
$res = $wishlist->addNewItem($product->load($product_id));
if($res)
{
$status =1;
$message = "your product has been added in wishlist";
}
else
{
$status =0;
$message = "wrong data send";
}
$result = array("status" =>$status,"message"=>$message);
header('Content-type: application/json; charset=utf-8');
echo json_encode($result);
?>
There is a similar question you might want to check.
In your code you are not extending Magento API in any way but creating a standalone hackish script that inserts items to wishlist. I suggest that you take a look on how to develop a magento extension or if you need to create a backend (CLI) script, at least use the same structure as in shell/abstract.php and extend the shell base class - you will save yourself loads of headaches.
Moreover, your code is not secure, maintainable and removes all the benefits of using Magento as an ecommerce platform/framework (security, authorization & authentication etc)
Inchoo have quite some blog posts that could give you an idea where to begin
http://inchoo.net/magento/magento-api-v2/
http://inchoo.net/magento/extending-the-magento-api/
/* error_reporting(E_ALL);
ini_set("display_errors", 1);*/
You Have Comment This line And Write this
require_once './app/Mage.php';

Displaying list of logged in users in Front side using Joomla 2.5 component

I would like to display all login user list in Front side using Joomla 2.5 component.
Can any body tell me how do do this?
I would also want to develop change password and news subscription module.
Try this,
$db =JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('*')
->from('#__users');
$db->setQuery($query);
$rows = $db->loadObjectList();
foreach ($rows as $row) {
$user = JFactory::getUser($row->id);
$status = $user->guest;
if(!$status){
echo $row->name.'---Email'.$row->email;
}
}
Use this extension to implement its in your site if you need quick solution.
Hope it helps..

How to call a joomla module in virtuemart shop.browse page

How can a joomla module be called inside the virtuemart shop.browse page. I tried the following code inside the browse_layouttable.tpl.php but it is not working for me. I am using joomla1.5.23 and the virtuemart version is 1.1.8. Any suggestion?
<?php
$modules =& JModuleHelper::getModules('logo');
foreach ($modules as $module)
{
echo JModuleHelper::renderModule($module)
}
?>
Try this
$document = &JFactory::getDocument();
$renderer = $document->loadRenderer('module');
$Module = &JModuleHelper::getModule('mod_fmDataGrid');
$Params = "param1=bruno\n\rparam2=chris"; //if you want to pass params
$Module->params = $Params;
echo $renderer->render($Module);
I would suggest you use "Modules Anywhere" from NoNumber:
http://extensions.joomla.org/extensions/core-enhancements/coding-a-scripts-integration/embed-a-include/6402
After you install this plugin you can add module positions directly in your browse page PHP using this example:
{modulepos mynewposition}
This is a must have plugin for all Joomla users, because you can use it throughout your site.

Code to display articles from category ID?

What would be the code to display articles from category (specified by ID)?
In Wordpress this is fairly easy by doing:
<?php
query_posts('cat=1');
while (have_posts()) : the_post();
the_title();
endwhile;
?>
I'm looking for similar code for Joomla.
$db = JFactory::getDbo();
$id = 50;//example
$query = $db->getQuery(true);
$query->select('*');
$query->from('#__content');
$query->where('catid="'.$id.'"');
$db->setQuery((string)$query);
$res = $db->loadObjectList();
foreach($res as $r){
echo '<h3>'.$r->title.'</h3>';
echo $r->introtext;
}
You can use next code template:
$categoryId = $[category id];
require_once("components/com_content/models/category.php");
$category = new ContentModelCategory();
$category->hit($categoryId);
$articles = $category->getItems();
print_r($articles);
There is no direct code for getting this in joomla like word press.
If you want to check the code you can check the code for achieving this by following path.
components/com_content/view/category/view.html.php
and
components/com_content/view/category/tmpl/blog.php
According to my Guess your requirement is to display the articles from same category.
then in joomla you dont need to edit in any code.
for achieving this you can simply create a menu.
and menu layout type should be category blog and Choose your category from the right side category options.
This will get the complete article from that category.
If you want to manage it in your style you can add style based on blog.php file .
Hope this will help you..
Try this:
$articles = JFactory::getDBO()->setQuery("SELECT * FROM #__content WHERE catid = '21'")->loadObjectList();
Of course replace '21' with id of your category.
This is quite easy in Joomla. You can find the code in /components/com_content/models/category.php under getItems()
Below is an example
$model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
$model->setState('params', JFactory::getApplication()->getParams());
$model->setState('filter.category_id', $category_id);
$articles = $model->getItems();

How to make link in joomla

hi i am new in joomla.I need the dynamic link in view file.
//no direct access
defined('_JEXEC') or die('Direct Access to this location is not allowed.');
// include the helper file
require_once(dirname(FILE).DS.'helper.php');
// get a parameter from the module's configuration
$userCount = 5;
// get the items to display from the helper
$items = ModNewHelper::getItems($userCount);
//link of the component
// include the template for display
require(JModuleHelper::getLayoutPath('mod_new'));
this is main file
/**
* #author Raju Gautam
* #copyright 2011
*/
defined('_JEXEC') or die('Direct Access to this location is not allowed.');
class ModNewHelper
{
/**
* Returns a list of post items
*/
public function getItems($userCount)
{
// get a reference to the database
$db = &JFactory::getDBO();
// get a list of $userCount randomly ordered users
$query = 'SELECT name,id FROM `#__hello` ORDER BY ordering LIMIT ' . $userCount . '';
$db->setQuery($query);
$items = ($items = $db->loadObjectList())?$items:array();
return $items;
} //end getItems
} //end ModHelloWorld2Helper
this is helper file
defined('JEXEC') or die('Restricted access'); // no direct access
echo JText::('Latest News');
//echo ""; print_r($items); exit;
foreach ($items as $item) {
echo JText::sprintf($item->name);
} this is view file
I need the link on echo JText::sprintf($item->name); this line. can i helped please?
change your this line from view file:
echo JText::sprintf($item->name);
to :
echo "<a href='".$item->link."'>". JText::sprintf($item->name)."</a>";
assuming, link is the field name of your link else change it according to the field name you've used for link. this may help, i guess .. good luck with it.
use
echo "<a href='".JRoute::_($item->link, false)."'>". JText::sprintf($item->name)."</a>";
JRoute will take care of routing also, if routing is enabled.

Resources