Why is my plugin for Joomla 2.5 not executed? - joomla2.5

I am developing a plugin (still a newby to development for 2.5) but somehow I don't even get the beast to do the most basic thing - it seems it is not launched at all. However, PHP's parsor-errors are shown on the Frontend, but when this code is triggered nothing happens - none of diagnostice message are shown on screen or in my logfile...
Where's the problem?
<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport('joomla.plugin.plugin');
class plgContentSIMPLE_Plugin extends JPlugin
{
function plgContentSIMPLE_Plugin( &$subject , $config ) {
echo "constructor!";
parent::__construct( $subject , $config );
}
function onPrepareContent ($article , $params, $limitstart)
{
oBDC ("oPC",$article , $params, $limitstart);
}
function onBeforeDisplayContent ($article , $params, $limitstart)
{
oBDC ("oBDC",$article , $params, $limitstart);
}
function onAfterDisplayContent ($article , $params, $limitstart)
{
oBDC ("oADC",$article , $params, $limitstart);
}
function oBDC($whoscalling,$article , $params, $limitstart)
{
echo "whoscalling = " . $whoscalling;
$myFile = "./obdc.log";
$fh = fopen($myFile, 'a'); // or die("can't open file");
$stringData = "\n whoscalling = " . $whoscalling;
fwrite($fh, $stringData);
fclose($fh);
}
}

How are you installing the plugin? Have you read the Joomla Plugin tutorial? Here is a pretty good tutorial, try getting this to work first -
https://www.inmotionhosting.com/support/edu/joomla-25/create-plugin

Several issues:
Naming conventions:
class plgContentSimple extends JPlugin
{
function __construct( &$subject , $config ) {
Event is called "onContentAfterDisplay"...

Related

Screen scraper script won't write to ouptut file

I can't get the Perl script below to write to the file output.html.
I doesn't need to be a CGI script yet, but that is the ultimate intention.
Can anyone tell me why it isn't writing any text to output.html?
#!/usr/bin/perl
#-----------------------------------------------------------------------
# This script should work as a CGI script, if I get it correctly.
# Most CGI scripts for Perl begin with the same line and must be
# stored in your servers cgi-bin directory. (I think this is set by
# your web server.
#
# This scripts will scrape news sites for stories about topics input
# by the users.
#
# Lara Landis
# Sinister Porpoise Computing
# 1/4/2018
# Personal Perl Project
#-----------------------------------------------------------------------
#global_sites = ();
print( "Starting program.\n" );
if ( !( -e "sitedata.txt" ) ) {
enter_site_info( #global_sites );
}
if ( !( -e "scrpdata.txt" ) ) {
print( "scrpdata.txt does not exist. Creating file now.\n" );
print( "Enter the search words you wish to search for below. Press Ctrl-D to finish.\n" );
open( SCRAPEFILE, ">scrpdata.txt" );
while ( $line = <STDIN> ) {
chop( $line );
print SCRAPEFILE ( "$line\n" );
}
close( SCRAPEFILE );
}
print( "Finished getting site data..." );
scrape_sites( #global_sites );
#----------------------------------------------------------------------
# This routine gets information from the user after the file has been
# created. It also has some basic checking to make sure that the lines
# fed to it are legimate domains. This is not an exhaustive list of
# all domains in existence.
#----------------------------------------------------------------------
sub enter_site_info {
my ( #sisites ) = #_;
$x = 1;
open( DATAFILE, ">sitedata.txt" ) || die( "Could not open datafile.\n" );
print( "Enter websites below. Press Crtl-D to finish.\n" );
while ( $x <= #sisites ) {
$sisites[$x] = <STDIN>;
print( "$sisites[$x] added.\n" );
print DATAFILE ( "$sisites[$x]\n" );
$x++;
}
close( DATAFILE );
return #sisites;
}
#----------------------------------------------------------------------
# If the file exists, just get the information from it. Read info in
# from the sites. Remember to create a global array for the sites
# data.
#-----------------------------------------------------------------------
#-----------------------------------------------------------------------
# Get the text to find in the sites that are being scraped. This requires
# nested loops. It starts by going through the loops for the text to be
# scraped, and then it goes through each of the websites listend in the
# sitedata.txt file.
#-----------------------------------------------------------------------
sub scrape_sites {
my ( #ss_info ) = #_;
#gsi_info = ();
#toscrape = ();
$y = 1;
#---------------------------
# Working code to be altered
#---------------------------
print( "Getting site info..." );
$x = 1;
open( DATAFILE, "sitedata.txt" ) || die( "Can't open sitedata.txt.txt\n" );
while ( $gsi_info[$x] = <DATAFILE> ) {
chop( $gsi_info[$x] );
print( "$gsi_info[$x]\n" );
$x++;
}
close( DATAFILE );
open( SCRAPEFILE, "scrpdata.txt" ) || die( "Can't open scrpdata.txt\n" );
print( "Getting scrape data.\n" );
$y = 1;
while ( $toscrape[$y] = <SCRAPEFILE> ) {
chop( $toscrape[$y] );
$y++;
}
close( SCRAPEFILE );
print( "Now opening the output file.\n" );
$z = 1;
open( OUTPUT, ">output.html" );
print( "Now scraping sites.\n" );
while ( $z <= #gsi_info ) { #This loop contains SITES
system( "rm -f index.html.*" );
system( "wget $gsi_info[$z]" );
$z1 = 1;
print( "Searching site $gsi_info[$z] for $toscrape[$z1]\n" );
open( TEMPFILE, "$gsi_info[$z]" );
$comptext = <TEMPFILE>;
while ( $comptext =~ /$toscrape[z1]/ig ) { # This loop fetches data from the search terms
print( "Now scraping $gsi_info[$z] for $toscrape[$z1]\n" );
print OUTPUT ( "$toscrape[$z1]\n" );
$z1++;
}
close( TEMPFILE );
$z++;
}
close( OUTPUT );
return ( #gsi_info );
}
You're making assumptions about the current work directory that are often incorrect. You seem to assume the current work directory is the directory in which the script resides, but that's never guaranteed, and it's often / for CGI scripts.
"sitedata.txt"
should be
use FindBin qw( $RealBin );
"$RealBin/sitedata.txt"
There could also be a permission error. You should include the error cause ($!) in your error message when open fails so you know what is causing the problem!
While you're checking some, you're not checking all of your open or system calls. If they fail, the program will keep going without an error message telling you why.
You can add checks to all of these, but it's easy to forget. Instead, use autodie to do the checks for you.
You'll also want to use strict to ensure you haven't made any variable typos, and use warnings to warn you about small mistakes. See this answer for more.
Also #global_sites is empty so enter_site_info() isn't going to do anything. And scrape_sites() does nothing with its argument, #ss_info.
All of these things are helpful. Thank you. I found the problem. I was opening the wrong file. It was putting the error-checking in on the file that let me spot the error. It should have been
open (TEMPFILE, "index.html") || die ("Cannot open index.html\n");
I have taken as many of the suggestions as I remembered and included them in the code. I still need to implement the directory advice, but it should not be difficult.

How to fetch data from cursor array in facebook From ads insights api call

While calling getInsights() method,it gives an object.so i want to access some data from it.
Here is the api call
$account->getInsights($fields, $params);
echo '<pre>';print_r($resultArr);die;
it will gives result like
FacebookAds\Cursor Object
(
[response:protected] => FacebookAds\Http\Response Object
(
[request:protected] => FacebookAds\Http\Request Object
(
[client:protected] => FacebookAds\Http\Client Object
(
[requestPrototype:protected] => FacebookAds\Http\Request Object
(
Thanks in advance.
The following should work:
$resultArr = $account->getInsights($fields, $params)[0]->getData();
echo '<pre>';
print_r($resultArr);
die;
If you have more than one object in the cursor, you can just loop over it:
foreach ($account->getInsights($fields, $params) as $obj) {
$resultArr = $obj->getData();
echo '<pre>';
print_r($resultArr);
}
die;
In this case, if you set the implicitFetch option to true by default with:
Cursor::setDefaultUseImplicitFetch(true);
you will be sure you are looping over all the results.
I using this piece of code and It works for me, I hope works for you ...
$adset_insights = $ad_account->getInsights($fields,$params_c);
do {
$adset_insights->fetchAfter();
} while ($adset_insights->getNext());
$adsets = $adset_insights->getArrayCopy(true);
Maybe try:
$insights = $account->getInsights($fields, $params);
$res = $insights->getResponse()->getContent();
and then go for the usual stuff:
print_r($res['data']);
Not sure if my method differs from Angelina's because it's a different area of the SDK or if it's because it's been changed since her answer, but below is the code that works for me, and hopefully will be useful for someone else:
$location_objects = $cursor->getArrayCopy();
$locations = array();
foreach($location_objects as $loc)
{
$locations[] = $loc->getData();
}
return $locations;
Calling getArrayCopy returns an array of AbstractObjects and then calling getData returns an an array of the objects props.

Joomla 2.5 - component fatal error [duplicate]

This question already exists:
imade a simple component aboutus with table contactus when i click on publish/unpublish get this errore
Closed 7 years ago.
When I make component in Joomla 2.5 I had this error:
Fatal error: Call to a member function reset() on a non-object in
/var/www/html/joomla/libraries/joomla/application/component/modeladmin.php
on line 850
I found‌ :when click on publish or unpublish first run this controller quite in my project this name is :
notic:run first this file
com_contactus/controllers/categories.php
<?php
defined( '_JEXEC' ) or die();
jimport ('joomla.application.component.controlleradmin');
echo "run first this file ";
class contactusControllerCategories extends JControllerAdmin
{
public function getModel($name='Category',$prefix='contactusModel',$config=array('ignore_request'=>true))
{
$model = parent::getModel($name,$prefix,$config);
return $model;
}
}
after run that Top file rund this file Of course gettable method
com_contactus/models/category.php
<?php
defined( '_JEXEC' ) or die();
jimport ('joomla.application.component.modeladmin');
class contactusModelCategory extends JModelAdmin
{
public function getTable($type='Category',$prefix='contactusTable',$config=array())
{
echo "second ";
return JTable::getInstance ($type,$prefix,$config);
}
protected function loadFormData()
{
$data = JFactory::getApplication()->getUserState('com_contactus.edit.category.data',array());
if (empty($data))
{
$data = $this->getItem();
}
return $data;
}
function getForm($data=array(),$loadData=true)
{
$form = $this->loadForm('com_contactus.category','Category',array('control'=>'jform' , 'load_data'=>$loadData));
return $form;
}
}
after that run towice files rund this file for run
com_contactus/tables/category.php
<?php
defined( '_JEXEC' ) or die();
jimport ('joomla.database.table');
echo "three ";
die();
class contactusTableCategory extends JTable
{
public function __construct (&$db)
{
parent::__construct('#__contactus','id',$db);
}
}
one of my wrong:
. I put the wrong tabels instead tables name in project

Class 'SQLiteDatabase' not found in includes\modules\ultimate_seo_urls5\cache_system\sqlite.php on line 99

in oscommerce we used ULTIMATE Seo Urls 5 Plugin , in this we are facing a issue like When we go to
admin->
Configuration->Seo url5->select your chosen cache system we changed mysql to sqlite when changed home page client site shows Class 'SQLiteDatabase' not found in includes\modules\ultimate_seo_urls5\cache_system\sqlite.php on line 99
at this line i found
protected static function createDatabase() {
if ( !is_readable( self::$sqlite_db_file ) ) {
self::$db = new SQLiteDatabase( self::$sqlite_db_file, 0666, $error )
or trigger_error( 'Failed: ' . $error, E_USER_WARNING );
self::createTables();
} else {
self::$db = new SQLiteDatabase( self::$sqlite_db_file, 0666, $error )
or trigger_error( 'Failed: ' . $error, E_USER_WARNING );
}
}
this how to solve this
In file
includes\modules\ultimate_seo_urls5\cache_system\sqlite.php,
at line 99 Use
self::$db = new SQLite3( self::$sqlite_db_file, 0666, $error );
For both lines for php 5.4 and above
In file
includes/modules/ultimate_seo_urls5/main/usu5.php
at line no 308 use fetchArray() rather fetch() function.
$row = $result->fetchArray();
I have faced the same problem and corrected it by this way. oscommerce version 2.3

Accessing tabs on Firefox with a C++ XPCOM extension

What XPCOM interfaces should I use to detect opening, closing and switching of tabs and also get their associated URL from a firefox extension?
I have seen instances of code that manage tabs in JS, but how about from C++ ?
You can write small JS component that will reroute tab events to your C++ component using nsIObserverService.
In C++ code you can use this snippet to register your component as observer to user defined events that is used for rerouting tab events.
NS_IMETHODIMP MyCppComponent::Observe(nsISupports *aSubject,
const char *aTopic,
const PRUnichar *aData)
{
if( !strcmp( aTopic, "xpcom-startup" ) )
{
nsCOMPtr<nsIObserverService> observerService =
do_GetService( "#mozilla.org/observer-service;1" );
observerService->AddObserver( this, "my-tab-open", false );
observerService->AddObserver( this, "my-tab-close", false );
observerService->AddObserver( this, "my-tab-select", false );
}
else if( !strcmp( aTopic, "my-tab-open" ) )
{
/* . . . */
}
else if( !strcmp( aTopic, "my-tab-close" ) )
{
/* . . . */
}
else if( !strcmp( aTopic, "my-tab-select" ) )
{
/* . . . */
}
/* . . . */
}
And in helper JS component you should to subscribe to tab events and in event handlers you can extract desired data and raise user defined events to execute C++ code.
function tabOpened(event) {
var obsSvc = CC["#mozilla.org/observer-service;1"].
getService(CI.nsIObserverService);
obsSvc.notifyObservers(event.target.linkedBrowser.contentWindow,
"my-tab-open", "some data");
}
function tabClosed(event) {
var obsSvc = CC["#mozilla.org/observer-service;1"].
getService(CI.nsIObserverService);
obsSvc.notifyObservers(event.target.linkedBrowser.contentWindow,
"my-tab-close", "some data");
}
function tabSelected(event) {
var obsSvc = CC["#mozilla.org/observer-service;1"].
getService(CI.nsIObserverService);
obsSvc.notifyObservers(event.target.linkedBrowser.contentWindow,
"my-tab-select", "some data");
}
function contentWndLoad(event) {
var obsSvc = CC["#mozilla.org/observer-service;1"].
getService(CI.nsIObserverService);
var browser = getMostRecentBrowserWindow().getBrowser();
browser.tabContainer.addEventListener("TabOpen", tabOpened, false);
browser.tabContainer.addEventListener("TabClose", tabClosed, false);
browser.tabContainer.addEventListener("TabSelect", tabSelected, false);
}
MyJsComponent.prototype = {
/* . . . */
observe: function(aSubject, aTopic, aData) {
switch(aTopic) {
case "xpcom-startup":
var obsSvc = CC["#mozilla.org/observer-service;1"].
getService(CI.nsIObserverService);
obsSvc.addObserver(this, "toplevel-window-ready", false);
break;
case "toplevel-window-ready":
aSubject.addEventListener("load", contentWndLoad, false);
break;
}
}
/* . . . */
}
Also there are some additional code that you should add to handle specific cases. For instance when user close browser window you won't receive TabClose events for opened tabs in that window... And don’t forget to unregister your observers when you longer need them.