How to make a utf-8 report? - birt

My report does not write exactly accentuated letters ( french ) , so there are unreadable characters displayed on the report. The runReport.php file is :
<?php
define("ROOT_PATH", "../");
require_once ROOT_PATH . 'config.inc.php';
require_once("java/Java.inc");
class runReport {
function runReport($report, $param, $output) {
$pth = "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"];
$path_parts = pathinfo($pth);
$imageURLPrefix = $path_parts['dirname'] ."/images/";
session_start();
$here = getcwd();
$ctx = java_context()->getServletContext();
$birtReportEngine = java("org.eclipse.birt.php.birtengine.BirtEngine")->getBirtEngine($ctx);
java_context()->onShutdown(java("org.eclipse.birt.php.birtengine.BirtEngine")->getShutdownHook());
try{
$thereport = $birtReportEngine->openReportDesign(RP_REPORT.$report);
$task = $birtReportEngine->createRunAndRenderTask($thereport);
$task->setParameterValue("province", new java("java.lang.Integer", read_post_int("province"));
$taskOptions = new java("org.eclipse.birt.report.engine.api.HTMLRenderOption");
$outputStream = new java("java.io.ByteArrayOutputStream");
$taskOptions->setOutputStream($outputStream);
$taskOptions->setOutputFormat("html");
$ih = new java( "org.eclipse.birt.report.engine.api.HTMLServerImageHandler");
$taskOptions->setImageHandler($ih);
$taskOptions->setEnableAgentStyleEngine(true);
$taskOptions->setBaseImageURL($imageURLPrefix . session_id());
$taskOptions->setImageDirectory($here . "/images/" . session_id());
$task->setRenderOption( $taskOptions );
$task->run();
$task->close();
}
catch (JavaException $e) {
echo $e; //"Error Calling BIRT";
}
echo $outputStream;
}
}
?>
So how to make the report support utf-8 encoding ?

Don't know PHP, but this could just be a problem of your encoding HTTP header. What does the HTML source generated by BIRT look like.
Does it contain a <meta charset="xxx"/> tag?
If it does, this should match the Content-Encoding HTTP header (sent by your server, probably settable with PHP).

Related

I need webp image on Opencart 3. It is possible?

Is it possible to use webp images in opencart 3? I mean automatic generation.
Not all the browsers accept WEBP image format
but you can type a code to check if the browser accept WEBP format then you will have to make a new images cache and convert the existing images to webp
on the fir dir catalog/model/tool/image.php
add
$image_new_webp = 'cachewebp/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . (int)$width . 'x' . (int)$height . '.webp';
after this
$image_new = 'cache/'
to check if the browser accept image.webp and to create your new images cache
in the same file: catalog/model/tool/image.php
add this code:
$gd = gd_info();
if ($gd['WebP Support']) {
if (!is_file(DIR_IMAGE . $image_new_webp) || (filectime(DIR_IMAGE . $image_new) > filectime(DIR_IMAGE . $image_new_webp))) {
$path = '';
$directories = explode('/', dirname($image_new_webp));
foreach ($directories as $directory) {
$path = $path . '/' . $directory;
if (!is_dir(DIR_IMAGE . $path)) {
#mkdir(DIR_IMAGE . $path, 0777);
}
}
$image_webp = new Image(DIR_IMAGE . $image_old);
$image_webp->resize($width, $height);
$image_webp->save_webp(DIR_IMAGE . $image_new_webp);
}
}
before this line: $image_new = str_replace(
now you need a function to save the images in new format
on file dir: system/library/image.php
add this function:
public function save_webp($file, $quality = 90) {
if (is_resource($this->image)) {
imagewebp($this->image, $file, $quality);
imagedestroy($this->image);
}
}
before this line: public function save($file, $quality = 90) {
output the webp images format
add this function on file system/library/response.php
public function webpRebuild($output) {
$gd = gd_info();
if ($gd['WebP Support']) {
$uri = '';
if (isset($_SERVER['REQUEST_URI'])) {
$uri = $_SERVER['REQUEST_URI'];
}
if (stripos($uri, 'admin') === false) { // admin is your dashboard url if you have different name jst change it
if (isset($_SERVER['HTTP_ACCEPT']) && isset($_SERVER['HTTP_USER_AGENT'])) {
if( strpos( $_SERVER['HTTP_ACCEPT'], 'image/webp' ) !== false ) {
$re = '/(cache)(.*)(\.jpg|\.png|.jpeg)/U';
$subst = '$1webp$2.webp';
$this->output = preg_replace($re, $subst, $this->output);
}
}
}
}
}
before this line: private function compress($data, $level = 0)
on the same file you have to output the webpRebuild function so add this code:
$this->webpRebuild($this->output);
after this line: $output = $this
Search the OpenCart extension marketplace for "webp":
https://www.opencart.com/index.php?route=marketplace/extension&filter_search=webp
Here are a couple, both free:
https://www.opencart.com/index.php?route=marketplace/extension/info&extension_id=36308
https://www.opencart.com/index.php?route=marketplace/extension/info&extension_id=34275
The best solution is at Design Cart. The extension generates additional webp images and displays them if the user's browser supports webp. Download.

Domain Meta Validation

I have a code set on Laravel. This is doing dns verification, I want to verify a specific field in the meta tag I want.
Example code
public function verifyDomainDns()
{
$fqdn = sprintf('%s.%s', $this->getVerificationTxtName(), $this->name);
$results = collect(dns_get_record($fqdn, DNS_TXT));
$results = $results->where('type', 'TXT')
->where('txt', $this->verification_token);
$this->domain_verified = $results->isEmpty() ? self::UNVERIFIED : self::VERIFIED;
$this->save();
}
verification_token Auto-generated numbers registered in database
The meta tag I want to verify.
<meta name="book" content="verification_token" />
There is no correlation between what your code is already doing and what you want to do.
One way you can achieve this is to get the contents of the URL with something like file_get_contents(), which will result in you getting the HTML content of the URL.
Once you have this, you can use something like DOMXpath to parse it and get the meta tag's contents.
$html = file_get_contents('https://example.com');
$dom = new DomDocument();
$dom->loadHTML($html);
$xpath = new DomXPath($dom);
$contents = $xpath->query('/html/head/meta[#name="book"]/#content');
if ($contents->length === 0) {
echo 'No tag found';
} else {
foreach ($contents as $content) {
echo $content->value;
}
}

SESSION varibales are not displayed after redirection used with memcache

I have a page session_config.php in that page I have following code
session_name('session_sw');
session_start();
$session_ID = session_id();
I have another page index.php in which I am including session_config.php ,the code as follows.
$email = $_REQUEST['email'];
$pass = $_REQUEST['pass'];
$error = 0;
if(!empty($email) && !empty($pass)) {
$url = "$SERVER/sw/apis/3rdpartylogin.php?advertiser_login=1&pass=$pass&email=$email";
$resp = file_get_contents($url);// it sends json encoded string.
$resp = json_decode($resp);
if ( $resp->status == 'success' ) {
if ( !isset($resp->mesg->profile) || $resp->mesg->profile == 0 ){
$error = '1';
} else {
include "session_config.php";
$_SESSION['user_id'] = $resp->mesg->user_id;
$_SESSION['customer_id'] = $resp->mesg->customer_id;
$_SESSION['customer_name'] = $resp->mesg->customer_name;
$_SESSION['logged_in_user_email'] = $_REQUEST['email'];
$_SESSION['agency_name'] = $resp->mesg->agency_name;
$_SESSION['profile'] = $resp->mesg->profile;
$_SESSION['metadata'] = $resp->mesg->metadata;
$_SESSION['show_archival'] = $resp->mesg->show_archival;
$_SESSION['show_live'] = $resp->mesg->show_live;
$_SESSION['show_sov'] = $resp->mesg->show_sov;
$_SESSION[$session_ID]['session_name'] = 'surewaves_agency_view';
header("Location: reach.php");exit;
}
} else {
$error = '1';
}
}
?>
// Here I am able fetch the correct data in '$resp' variable and also it is redirecting to reach.php
In reach.php , i have following code
<?php
include "session_config.php";
echo "<pre>";
print_r($_SESSION);exit;
?>
But in reach.php when I am fetching the session variables the session array is showing completely empty like this Array (). WHY?
I am using memcache for it and we are using ubuntu.
In My php.ini i have included following code..
extension = memcache.so;
session.save_handler = memcache
session.save_path = "http://localhost:11211"
I have also tried with "tcp ://localhost:11211" but nothing worked.
Try to remove the http:// part from session.save_path and replace localhost with 127.0.0.1:
session.save_path = "127.0.0.1:11211"
Take a look at the second example at http://br1.php.net/manual/en/memcache.examples-overview.php.

multi image upload in custom component for joomla

I have tried http://docs.joomla.org/Creating_a_file_uploader_in_your_component but first it shows Error: 500 after some research I have removed code
"'.$session->getName().'" : "'.$session->getId().'",
"format" : "raw"
and error is gone. Now Image is not uploading anywhere (I have set path '/images/' folder) I am confuse in code for uploading image PART 5 where to use this code?
function storeImageFile()
{
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.folder' );
$path = 'PATH_GOES_HERE'.'designs'.DS;
$folder_permissions = "0755";
$folder_permissions = octdec((int)$folder_permissions);
//create folder if not exists
if (!JFolder::exists($path)){
JFolder::create($path, $folder_permissions);
}
$file = JRequest::getVar('design_images', null, 'files',
$count = count($file['name']);
for($i=0;$i<$count;$i++)
{
//$i is the array position of the $_FILES array
if(empty($file['tmp_name'][$i]))
{
return false;
}
//Clean up filename to get rid of strange characters like spaces etc
$filename = JFile::makeSafe($file['name'][$i]);
//setting source and destination
$temporary_name = $file['tmp_name'][$i];
$filename = str_replace(' ', '_', $file['name'][$i]);
$dest = $path.$filename;
if(JFile::upload($temporary_name, $dest))
{
echo "File Upload Successful";
return true;
}
}
}

Auto refresh content in Mediawiki

I added a new tag (<news />) to my mediawiki to list the last modified pages.
Unfortunately the list is not updated unless I modify the page where the tag is.
I'm looking for a way to do it, and I think of AJAX. But I didn't manage to make AJAX refreshing my list.
Does anyone know a simple way to add an auto refresh feature on my Mediawiki ?
Here is my extension code :
$wgHooks['ParserFirstCallInit'][] = 'replaceTags';
function replaceTags( Parser $parser ) {
$parser->setHook( 'news', 'newsRender' );
return true;
}
function newsRender( $input, array $args, Parser $parser, PPFrame $frame ) {
// Titre =News=
$output = $parser->parse( "=News=", $parser->mTitle, $parser->mOptions, false, false )->getText();
$nb = 5;
$querySQL = "SELECT page_namespace, page_title, page_id, page_latest, rev_timestamp
FROM page, revision
WHERE page.page_latest = revision.rev_id
AND page_namespace = 0
ORDER BY rev_timestamp
DESC LIMIT 0,$nb";
$dbr = wfGetDB( DB_SLAVE );
$res = $dbr->query( $querySQL );
$count = $dbr->numRows( $res );
if( $count > 0 ) {
$output .= "<ul>";
while( $row = $dbr->fetchObject( $res ) )
{
$pageTitle = $row->page_title;
$nicerPageTitle = str_replace("_", " ", $pageTitle);
$pageNamespace = $row->page_namespace;
$title = Title::makeTitleSafe( $pageNamespace, $pageTitle );
$url = $title->getFullURL();
$date = $row->rev_timestamp;
$date = wfTimestamp( TS_RFC2822, $date );
$output .= "<li>$nicerPageTitle $date</li>";
}
$output .= "</ul>";
} else {
$output .= "A l'ouest rien de nouveau !!!";
}
return $output;
}
Thanks to nischayn22, I go into the cache problem in depth.
And I found that it's possible to deactivate it :
$parser->disableCache();
I tried it, and it works !!!
http://www.mediawiki.org/wiki/Extensions_FAQ#How_do_I_disable_caching_for_pages_using_my_extension.3F
This probably happens because MediaWiki uses Cache for pages. What you could rather do is make a SpecialPage for the feature needed. AFAIK Special Pages are not cached (confirm this on irc #mediawiki).
Also you might already find a similar implementation done by someone if you search the extensions that exist on Mediawiki.org .(Otherwise I would be happy to build one for you :)
Update: Extensions you could use Dynamic List(used in wikinews) and news . There could be more if you search mediawiki.org.

Resources