PHP - Class 'HbaseClient' not found even though it is included - php

Been scratching my head for a while on this one. I'm just getting started with using PHP/Thrift to communicate with HBase (I can do it fine w/Python). For some reason the code below is generating class 'HbaseClient' not found on the $client = new line:
$GLOBALS['THRIFT_ROOT'] = 'thrift';
require_once( $GLOBALS['THRIFT_ROOT'] . '/Thrift.php' );
require_once( $GLOBALS['THRIFT_ROOT'] . '/transport/TSocket.php' );
require_once( $GLOBALS['THRIFT_ROOT'] . '/transport/TBufferedTransport.php' );
require_once( $GLOBALS['THRIFT_ROOT'] . '/protocol/TBinaryProtocol.php' );
require_once( $GLOBALS['THRIFT_ROOT'] . '/Hbase/Hbase.php' );
try
{
$socket = new TSocket('127.0.0.1', 9090);
$transport = new TBufferedTransport($socket, 1024, 1024);
$protocol = new TBinaryProtocolAccelerated($transport);
$client = new HbaseClient( $protocol );
$transport->open();
}
catch (Exception $e)
{
echo "Exception: %e\r\n";
}
I have literally no idea why. In the Hbase.php include file the client is defined as such:
class HbaseClient implements \Hbase\HbaseIf {
Am I missing something glaringly simple here? (Full HBase.php here: http://pastebin.com/6kd9r2Se )
Thanks in advance!

I believe this is a namespace issue. Try putting :
namespace Hbase;
in the file instantiating the object or use the fully qualified name:
$client = new Hbase\HbaseClient( $protocol );

Are you sure you have placed the HBase folder under THRIFT_ROOT directory or outside?

Related

Wordpress file upload media_handle_upload fatal error

I wrote a PHP script to process files sent to it via POST.
On the frontend js script, I create a Formdata object, and append images to it...like:
formdata.append('image0', image0);
formdata.append('image1', image1);
etc
This is my PHP code, the code is in the wordpress root directory
<?php
header("Access-Control-Allow-Origin: *");
require_once('wp-admin/includes/image.php' );
require_once('wp-admin/includes/file.php' );
require_once('wp-admin/includes/media.php' );
$id_array = array();
$c = 0;
foreach ($_FILES as $file) {
$id_array[] = media_handle_upload('image' . $c, 0);
$c++;
}
echo implode(',', $id_array);
However when I run this code, I get the following error:
Fatal error: Call to undefined function __() in /home/website/public_html/wp-admin/includes/file.php on line 16
Am i missing to include additional files in the script? I used the documentation on wordpress and it said:
These files need to be included as dependencies when on the front end.
require_once( ABSPATH . 'wp-admin/includes/image.php' );
require_once( ABSPATH . 'wp-admin/includes/file.php' );
require_once( ABSPATH . 'wp-admin/includes/media.php' );
I would appreciate any help!
In order to use the native Wordpress functions, such as __() wp-config.php needs to be included additionally.
Adding wp-config.php solved the issue
I'm also facing same issue.
Adding this in functions.php will fix the error.
Some time it will show as "http error"
add_filter( 'wp_image_editors', 'raj_change_graphic_library' );
function raj_change_graphic_library($array) {
return array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' );
}

Joomla 3 load template in external file

I have created an external file. I want to load joomla default template in that file. I used below code, and it caused an error:
Fatal error: Call to protected method JApplicationSite::render() from
context ' '
define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define('JPATH_BASE', realpath(dirname(__FILE__) ));
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe = JFactory::getApplication('site');
JPluginHelper::importPlugin('system');
$mainframe->initialise();
$myContent = "Hello World!!";
$document = JFactory::getDocument();
$document->setBuffer($myContent, 'component');
$mainframe->render();
echo $mainframe;
At the least you need to let the Joomla app know which template you'd like to render.
//normal external script initialisation
define( '_JEXEC', 1 );
define( 'JPATH_BASE', realpath('/home/somepath/public_html/somedirectory/'));
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php');
require_once( JPATH_LIBRARIES .DS.'joomla'.DS.'factory.php');
$app = JFactory::getApplication('site');
$app->initialise();
//jimport( 'joomla.document.html.html' ); required in certain cases
//initialise the doc to use the Html renderer
$doc = new JDocumentHtml();
//minimal info required
$options['directory'] = "/my/template/directory";
$options["template"] = $app->getTemplate();//get the template name
$options["file"] = "index.php";//usually
//Optional: Manually set params
//$params = new JRegistry();
//$params->colorVariation = "blue";
//$params->widthStyle = "fluid";
//$params->showComponent = "1";
//$options["params"] = $params;
//you may initialise the document object here and set the buffers
//$document = JFactory::getDocument();
//$document->setBuffer($contents, 'module', $name);
// $document->setHeadData($data['head']);etc
echo $doc->render(false, $options);
$app->close();
Of course dont expect it to display the same way esp if you use relative urls. Can be used for other purposes though like examining the scripts in a document template. tested on Joomla 3.3 PHP 5.5 . It will not work on lower versions like 1.5.

require_once in kohana3.3 showing the Server error

In kohana 3.3 i need to include one of the controller file in the another controller
I used require_once( realpath(dirname(FILE) . '/Twitteroauth.php' ) );
Its showing the server error.
Thanks in advance.
You should do this:
require_once( realpath(dirname(__FILE__) . '/Twitteroauth.php' ) );
Function realpath returns false when file does not exist, so you should maybe check result before require:
$path = realpath(dirname(__FILE__) . '/Twitteroauth.php' );
if(!empty($path))
require_once($path);
else
die("$path not found!");

Get current article id Joomla! 2.5

I'm trying to retrieve the "current" article id from an external script in Joomla! 2.5
Firstly, I included Joomla core files:
define( '_JEXEC', 1 );
defined('_JEXEC') or die('Restricted access');
define( 'JPATH_BASE', realpath(dirname(__FILE__).'/..' ));
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
Then, initialized the session:
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
Now, I know that for Joomla 2.5 I have to use Jinput instead of JRequest (deprecated), so:
$jAp = JFactory::getApplication();
$jInput = $jAp->input;
As already told, I'm trying to retrieve the article id.
I tried many instances but nothing seems to work.
$id = $jInput->get('id', 0); // doesn't work
$idInt = $jInput->getInt('id',0); //doesn't work
Also with JRequest... I can't get current article id.
This works only if I would request data for logged in users, example:
$user = JFactory::getUser();
echo $user->username; // this works...
What I am missing?
Where is my fault?
Thanks a lot to all!
Debugging AJAX can be complex. I often find adding some logging in my handler helps a lot, for example adding the following to the start of your code...
# logging of all hits
$log_file = realpath(dirname(__FILE__)) . '/ajax_debug.log';
$fh = fopen($log_file, 'a') or die();
$log_string = "Backend Hit \n" . date("Y-m-d H:i:s") . "\n";
$log_string .= "POST: " . print_r($_POST, true) . "\n";
$log_string .= "GET: " . print_r($_GET, true) . "\n";
$log_string .= "Hit by: " . $_SERVER['REMOTE_ADDR'] . "\n";
$log_string .= "\n\n\n";
fwrite($fh, $log_string);
fclose($fh);
You didn't mention how/where your AJAX code was implemented. It sounds like it might be an implementation outwith Joomla. I would tend to put this in a plug-in if it is quite stand-alone, though module or component AJAX handlers also work well in Joomla. There are some good docs and code at https://docs.joomla.org/Using_Joomla_Ajax_Interface

Using jimport in my own script

When i try to use jimport('joomla.user.helper') it gives me this error.
Fatal error: Call to undefined function jimport() in /home/joomclan/public_html/quiz/pop_fetching.php on line 223
This is my code where i use this:
function addJoomlaUser($name, $username, $password, $email) {
jimport('joomla.user.helper');
$salt = JUserHelper::genRandomPassword(32);
$crypted = JUserHelper::getCryptedPassword($password, $salt);
$cpassword = $crypted.':'.$salt;
$data = array(
"name"=>$name,
"username"=>$username,
"password"=>$password,
"password2"=>$password,
"email"=>$email,
"block"=>0,
"groups"=>array("1","2")
);
add at the top
include(JPATH_BASE.'libraries/loader.php')
but, afraid, something wrong with your code
http://www.webdeveloper.com/forum/showthread.php?226904-jimport-in-Joomla-how-does-it-work
It's defined in "libraries/loader.php", which is included by "libraries/joomla/import.php", which is included by "includes/framework.php", which is included by "index.php" (all paths relative to the base Joomla directory).
Probably this will be helpful as well
jimport not working in Joomla 1.5
in your script, at the top, initialise joomla framework as below.
`define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__) );
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$app =& JFactory::getApplication('site');
$app->initialise();
jimport( 'joomla.user.user' );`
I always use that.

Categories