When a plugin is registered in joomla observer? - plugins

I have done a plugin for a simple debug purpose, print some data ( avoiding the code to be delete on each update ) .
I have build a plugin following official tutorial, but code does not go there ( seen with xdebug )
THe plugin isn't registered among observers, so it's action is not thrown. I image that plugin are registered while the plugin is installed? or I can change code after being installed?
Thanks
class plgSystemVmdataprint extends JPlugin
{
function onAfterRender()
{
$data = JRequest::get('post');
if(!($_REQUEST['option']='com_virtuemart' && $_REQUEST['view']='product' && $_REQUEST['task']='edit') )
{
$textFIleSave = JPATH_VM_SITE . DS . 'plugins'. DS . 'vmdataprint' . DS . 'productsaveprint'. DS . 'productsave.txt';
file_put_contents($textFIleSave, print_r($data, true));
}
}
}

Related

Using Zend Framework 1 Service Window Azure Standalone

I am using zend service for window azure wrapper class standaline in my custom application. I would like to know how do i connect to my window azure storage. there seems to be no way i can specify the connection details (storage key etc)
$storageClient = new Zend_Service_WindowsAzure_Storage_Blob();
$result = $storageClient->createContainer('testcontainer');
echo 'Container name is: ' . $result->Name;
I am taking refernces from http://framework.zend.com/manual/1.12/en/zend.service.windowsazure.storage.blob.html
zend/Azure expert advice appreciated. thanks
Just add this code to the IndexController in your application
public function indexAction()
{
$auth = Zend_Auth::getInstance();
if($auth->hasIdentity())
{
$this->view->content = '<h1>Welcome to TestIndex!</h1>';
// Need to change
}
else
{
$storageClient = new Zend_Service_WindowsAzure_Storage_Blob('blob.core.windows.net', 'YOURNAME', 'YOURCODE');
$result = $storageClient->createContainer('container');
echo 'Container name is: ' . $result->Name;
var_dump($result->Name);
exit();
}
}

WordPress 3.5 Changed User.php Which Breaks Plugin, Can this function be the issue? Can it be fixed?

A plugin provides login for a WordPress multi-site network. This plugin now fails under WP 3.5 because the user.php file was changed. The old lines in /wp-includes/user.php can be added back in and the plugin would work. Obviously this is not a long term solution.
This is the old code from user.php
if ( empty( $user ) )
$user = wp_get_current_user();
else
$user = new WP_User( $user );
if ( ! isset( $user->ID ) )
return false;
This is the new code from 3.5
if ( empty( $user ) )
$user = get_current_user_id();
if ( ! $user = get_userdata( $user ) )
return false;
I'm a beginner trying to learn php and so I'm not sure on all of the meanings. However, I think this is the code in the plugin causing issue:
function get_userdata( $user_id ) {
global $wpdb;
if ( ! is_numeric( $user_id ) )
return false;
$user_id = absint( $user_id );
if ( ! $user_id )
return false;
$user = wp_cache_get( $user_id, 'users' ); //check to see if the cache object already has the user
if ( $user )
{
return $user; //it was in the cache
}
$user = new StdClass ();
global $XF;
XF_User_Data::fillUserData($XF->visitor, $user, $user_id);
update_user_caches($user);
return $user;
}
The new StdClass can be commented out and the error is removed but then no one can login.
How could I re-write this function to not cause the error?
*Fatal error: Call to undefined method stdClass::has_prop() /wp-includes/user.php*
The developer of the plugin is 'on vacation' and hasn't updated. He's waiting for some other changes, however, this needs to be fixed.
Any suggestions on fixing the code? Am I looking in the wrong place? Are other details needed before someone can help?
Even if you are a skilled PHP programmer, modifying WP core or any plugin script is really a bad idea. In my opinion, you should downgrade to previous version and wait for the plugin's update. Check this link to do it easily. In fact, many plugins had problems with version 3.5, including the popular CKEditor, but they are being updated and in this case, waiting seems to be the best option. Make sure all plugins are compatible with 3.5 before trying another update.
If you post which plugin you're using and a link to download it I'll take a look at it and see what the issue is.

Joomla plugin not being called

This is my 1st time I'm attempting to create a Joomla plugin and I need some help on getting this to work. The plugin is quite simple, I want to capture the HTTP_REFERER, check if the request was made from Google organic or paid results, pass the data to a session var and then submit it along with the values in a contact form. (there's a hidden field in my form and it gets the session var value). I use RSForms for creating my forms, just for the reference.
In the beginning, I hardcoded the following code into index.php at site root and it worked fine. Now, I'm trying to make a proper plugin but I can't get it to fire off when pages are loaded. I've tried all the system methods, still failing to get it to run.
This is my code:
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.plugin.plugin' );
class plgSystemRsformsGoogleReferer extends JPlugin
{
public function plgSystemRsformsGoogleReferer( &$subject, $config )
{
parent::__construct( $subject, $config );
}
function onAfterRender()
{
$session = & JFactory::getSession();
if (!$session->get('referrer', $origref, 'extref')) //If does not exist
{
$origref = $_SERVER['HTTP_REFERER'];
$session->set('referrer', $origref, 'extref');
$q = search_engine_query_string($session->get('referrer', $origref, 'extref'));
if(stristr($origref, 'aclk')) { // if referer is a google adwords link as opposed to an organic link
$type = ', paid link';
} else {
$type = ', organic result';
}
$ginfo = $q.$type;
$session->set('referrer', $ginfo, 'extref');
}
function search_engine_query_string($url = false) {
if(!$url && !$url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : false) {
return '';
}
$parts_url = parse_url($url);
$query = isset($parts_url['query']) ? $parts_url['query'] : (isset($parts_url['fragment']) ? $parts_url['fragment'] : '');
if(!$query) {
return '';
}
parse_str($query, $parts_query);
return isset($parts_query['q']) ? $parts_query['q'] : (isset($parts_query['p']) ? $parts_query['p'] : '');
}
}
}
And this is my manifest xml for the plugin installation (installation works fine):
<?xml version="1.0" encoding="utf-8"?>
<install version="1.5" type="plugin" group="system" method="upgrade">
<name>RSForm Google Referer v1.1</name>
<author>Me</author>
<creationDate>July 2012</creationDate>
<copyright>(C) 2004-2012 www.mysite.com</copyright>
<license>Commercial</license>
<authorEmail>info#mysite.com</authorEmail>
<authorUrl>www.mysite.com</authorUrl>
<version>1.1</version>
<description><![CDATA[Track visitor's search terms and and attaches the information to the RSForm! Pro Forms emails when sent.]]></description>
<files>
<filename plugin="rsform_google_referer">rsform_google_referer.php</filename>
</files>
</install>
I feel I'm close but I can't get it to run, any suggestions will be appreciated. Thanks!
The name of the class is wrong. It needs to match the name of the plugin folder and that name of the plugin file. It should be:
class plgSystemRsform_Google_Referer extends JPlugin
That is Rsform not Rsforms and the underscores.

how to show all VirtueMart Product list

i am creating a component in Joomla that shows a list of virtuemart Product
the requirement is that i can not use code directly from sql table.
so i use components/com_virtuemart/virtuemart_parser.php
for code i get the list of category in array , and code is
require_once( CLASSPATH . 'ps_product_category.php');
$ps_product_category = new ps_product_category();
$tpl = new $GLOBALS['VM_THEMECLASS']();
$category_childs = $ps_product_category->get_child_list(0);
$tpl->set( 'categories', $category_childs );
$categories = ps_product_category::getCategoryTreeArray(true);
from this code i get all published category, but how to get all products from category
how to show product list, how to get product list in array ?
The only existing function products_in_category(), but that doesn't meet your need because it only returns the number of products.
A non-SQL solution is to create a custom VM function and put it in
root\components\com_virtuemart\themes\default\theme.php
If you clone/modify ps_product::featuredProducts(), you should get what you want quite easily. (also, that file location assumes that you're using the default VM theme, as installed)
To show categories products in another component you can use this:
if (!class_exists( 'VmConfig' )) require(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart'.DS.'helpers'.DS.'config.php');
VmConfig::loadConfig();
if (!class_exists( 'VmModel' )) require(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart'.DS.'helpers'.DS.'vmmodel.php');
$categoryModel = VmModel::getModel('Category');
$cats = $categoryModel->getCategoryTree();//Params $parentId=0, $level = 0, $onlyPublished = true,$keyword = ''
if (!class_exists('VirtueMartModelProduct')) require(JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'product.php');
$product_model = new VirtueMartModelProduct();
for ($x = 0; $x < count($cats); $x++) {
echo $cats[$x]->category_name."<Br/>";
$products = $product_model->getProductsInCategory($cats[$x]->virtuemart_category_id);
for ($i = 0; $i < count($products); $i++) {
echo "- ".$products[$i]->product_name."<Br/>";
}
}

Integrating Zend Framework 1.11 with MongoDB using Doctrine ODM

Does any know of a way to integrate zend framework with Mongo using Doctrine 2 beta ODM?
I've viewed the zendcast video on integrating with Doctrine 2 ORM for MySQL but Bisna was never updated to support Mongo.
I guess I can try and hack Bisna to get it working but I'd like to know if someone else has already found a way to get it working.
It's pretty easy to write a Zend Bootstrap Resource.
Here is one I use:
<?php
namespace Cob\Application\Resource;
use Doctrine\Common\Annotations\AnnotationReader,
Doctrine\ODM\MongoDB\DocumentManager,
Doctrine\MongoDB\Connection,
Doctrine\ODM\MongoDB\Configuration,
Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver,
Doctrine\Common\EventManager;
/**
* Creates a MongoDB connection and DocumentManager instance
*
* #author Andrew Cobby <cobby#cobbweb.me>
*/
class Mongo extends \Zend_Application_Resource_ResourceAbstract
{
/**
* #return \Doctrine\ODM\MongoDB\DocumentManager
*/
public function init()
{
$options = $this->getOptions() + array(
'defaultDB' => 'my_database',
'proxyDir' => APPLICATION_PATH . '/domain/Proxies',
'proxyNamespace' => 'Application\Proxies',
'hydratorDir' => APPLICATION_PATH . '/domain/Hydrators',
'hydratorNamespace' => 'Application\Hydrators'
);
$config = new Configuration();
$config->setProxyDir($options['proxyDir']);
$config->setProxyNamespace($options['proxyNamespace']);
$config->setHydratorDir($options['hydratorDir']);
$config->setHydratorNamespace($options['hydratorNamespace']);
$config->setDefaultDB($options['defaultDB']);
$reader = new AnnotationReader();
$reader->setDefaultAnnotationNamespace('Doctrine\ODM\MongoDB\Mapping\\');
$config->setMetadataDriverImpl(new AnnotationDriver($reader, $this->getDocumentPaths()));
$evm = new EventManager();
$evm->addEventSubscriber(new SlugSubscriber());
return DocumentManager::create(new Connection(), $config, $evm);
}
public function getDocumentPaths()
{
$paths = array();
foreach(new \DirectoryIterator(APPLICATION_PATH . '/modules') as $module){
$path = $module->getPathname() . '/src/Domain/Document';
if((!$module->isDir() || $module->isDot()) || !is_dir($path)){
continue;
}
$paths[] = $path;
}
if(!count($paths)){
throw new \Exception("No document paths found");
}
return $paths;
}
}
Though you'll have to update the getDocumentPaths() method to suit your application directory structure.
I wrote my own very simple application resource plugin and container, using Guilherme's integration suite for inspiration.
I'm sure this could be much more featured in terms of capturing options but I figured I'll add those in as I need them.
See https://gist.github.com/891415