Zend Search Lucene And Persian Language ! - zend-framework

i have the following code in my zf project :
$index = Zend_Search_Lucene::open(APPLICATION_PATH . '/cache/search_index');
$doc = new Zend_Search_Lucene_Document();
$title = "سلام سینا xxx sad";
$doc->addField(Zend_Search_Lucene_Field::Text('title', $title));
$index->addDocument($doc);
$index->commit();
$index->optimize();
echo "Index contains " . $index->count() . " documents.\n\n";
$results = $index->find('xxx');
foreach ($results as $res) {
var_dump($res->title);
}
when var_dump performs output ->
string(39) "سینا جان xxx sad"
when i user utf_decode
string(25) "س�?ا�? س�?�?ا xxx sad"
how can i decode that correctly ! :(?
i already used the solution in this SOF quesion -> lucene encoding problem in zend framework
but not works and a notice error added about iconv !
plz help :)

Fixed by this code:
$index = Zend_Search_Lucene::open(APPLICATION_PATH . '/cache/search_index');
$doc = new Zend_Search_Lucene_Document();
$title = "سلام سینا xxx sad";
$doc->addField(Zend_Search_Lucene_Field::Text('title', $title,"UTF8"));
$index->addDocument($doc);
$index->commit();
$index->optimize();
echo "Index contains " . $index->count() . " documents.\n\n";
var_dump($index->getDocument(9));
echo "Search";
$results = $index->find('سینا');
foreach ($results as $res) {
var_dump($res->title);
}
die(1);

Related

How to retrieve the column from relation in YII2

I am using ajax to call a method from the server that returns a string data. However I get the following error.
PHP Notice 'yii\base\ErrorException' with message 'Trying to get
property of non-object'
probably this line $first_day=$row->tblStaff2->first_day_service; gives the error.
public function actionGet_loyalty() {
$model = \common\models\staffs\TblStaff::find()->joinWith('tblStaff2')->all();
$string = "<table class='table table-striped'><tr><th>Name</th><th>Number of Years</th></tr>";
foreach ($model as $row) {
$first_day=$row->tblStaff2->first_day_service;
$midname = ucwords($row->midname);
$name = ucwords($row->firstname) . " " . $midname[0] . ". " . ucwords($row->lastname);
$string.="<tr>"
. "<td>" . $name . "</td>"
. "<td>" . $first_day . "</td>"
. "</tr>";
}
$string.="</table>";
return $string;
}
TblStaff relation
public function getTblStaff2() {
return $this->hasOne(TblStaff2::className(), ['staff_id' => 'id']);
}
I have modified your code. Find it below
public function actionGet_loyalty() {
$model = \common\models\staffs\TblStaff::find()->all();
$string = "<table class='table table-striped'><tr><th>Name</th><th>Number of Years</th></tr>";
foreach ($model as $row) {
//What I added
foreach($row->tblStaff2 as $value){
$first_day = $value->first_day_service;
//Here is where it stopped
$midname = ucwords($row->midname);
$name = ucwords($row->firstname) . " " . $midname[0] . ". " . ucwords($row->lastname);
$string.="<tr>"
. "<td>" . $name . "</td>"
. "<td>" . $first_day . "</td>"
. "</tr>";
}
}
$string.="</table>";
return $string;
}
You can remove the comments i added to it when you get it working.

STDOUT from Pidgin plugin script

Yesterday, I wrote a perl plugin script for Pidgin 2.10.9, running on Windows 7, and using Strawberry Perl 5.10.1.5
Basically, on the receipt of an IM, it uses backticks to call a console application (written in .NET) and returns the console output to the sender as an IM.
I had to reboot this morning, but ever since I rebooted, it has stopped working.
So, I changed the backticks to use "capture". That didn't work either, but it at least gave me this error:
(15:00:33) Plugin: Error: Error in IPC::System::Simple plumbing: "Can't dup STDOUT" - "Bad file descriptor" at (eval 12) line 53
I have no idea what's changed from yesterday to today, and wondered if anybody knew what might be causing the error?
Thanks
Edit: Thought I'd add my code
use Purple;
#use IPC::System::Simple qw(system systemx capture capturex);
use IPC::System::Simple qw(capture capturex);
%PLUGIN_INFO = (
perl_api_version => 2,
name => "PlugIn",
version => "0.1",
summary => "AutoResp",
description => "PlugIn",
author => "Mark Watkin",
url => "http://",
load => "plugin_load",
unload => "plugin_unload"
);
sub plugin_init {
return %PLUGIN_INFO;
}
sub plugin_load {
my $plugin = shift;
Purple::Debug::info("PlugIn", "plugin_load()\n");
$data = "";
$conversation_handle = Purple::Conversations::get_handle();
Purple::Signal::connect($conversation_handle, "received-im-msg", $plugin, \&signal_chat_callback, $data);
}
sub plugin_unload {
my $plugin = shift;
Purple::Debug::info("PlugIn", "plugin_unload()\n");
}
sub signal_chat_callback {
# The signal data and the user data come in as arguments
my ($account, $sender, $message, $conv, $flags) = #_;
Purple::Debug::info("PlugIn", "Account Alias \"" . $account->get_alias() . "\"\n");
if( $account->get_alias() eq "PlugIn" )
{
Purple::Debug::info("PlugIn", "Request: \"" . $message . "\"\n");
if(!$conv)
{
Purple::Debug::info("PlugIn", "No conversation\n");
$conv = Purple::Conversation->new(1, $account, $sender);
}
$im = $conv->get_im_data();
$im->send( "One moment please..." );
my $query = "";
# eval {
# $query = capture("\"D:\\SourceCode\\PlugInNET\\bin\\Debug\\PlugInNET.exe\" \"" . $message . "\"");
# #$query = capture("\"D:\\SourceCode\\PlugInNET\\bin\\Debug\\PlugInNET.exe\"", "\"" . $message . "\"");
# #my $query = capture("D:\\SourceCode\\PlugInNET\\bin\\Debug\\PlugInNET.exe");
# #my $query = `\"D:\\SourceCode\\PlugInNET\\bin\\Debug\\PlugInNET.exe\" \"$message\"`;
# #my $query = `dir /b`;
# };
# if( $# )
# {
# Purple::Debug::info("PlugIn", "Error: " . $# . "\n");
# }
Purple::Debug::info("PlugIn", "Query: " . $query . "\n");
open ( my $fh, "-|", "D:\\SourceCode\\PlugInNET\\bin\\Debug\\PlugInNET.exe \"$message\"" ) or die "Cannot run free, $ERRNO";
while (<$fh>)
{
Purple::Debug::info("PlugIn", "Read: Line " . $_ . "\n");
$query = $query . $_ . "\n";
}
close $fh;
Purple::Debug::info("PlugIn", "Query: " . $query . "\n");
if( $query eq "" )
{
$im->send( "I'm sorry, my brain doesn't seem to be functioning at the moment" );
} else {
#msgs = split(/-----------\n/, $query);
foreach( #msgs )
{
Purple::Debug::info("PlugIn", "Result Msg: \"" . $_ . "\"\n");
$im->send( "<BODY>" . $_ . "</BODY>" );
}
}
}
}
The plan was to fix up the paths once I had it working properly
Please consider using file handles instead of backticks to capture stdout from another source. You'll be able collect errors.
#!/usr/bin/perl
use strict;
use warnings;
use English;
# No taint protection in this example
open ( my $fh, '-|', '/usr/bin/free' ) or die "Cannot run free, $ERRNO";
while (<$fh>)
{
print;
}
close $fh;

CGI script not displaying results in browser

I am attempting to display some info from an infoblox device. When I run this code in a browser using an html post, the table that displays MAC address entries does not display the values from the api. When I run this code in the unix command-line, the variables show up appropriately. Any Advice?
#!/usr/bin/perl
use strict;
use Infoblox;
use CGI;
my $cgi = new CGI;
print
$cgi->header() .
$cgi->start_html( -title => 'Form Results') .
$cgi->h1('Form Results') . "\n";
my #params = $cgi->param();
my $username = $cgi->param('username');
print '<table border="1" cellspacing="0" cellpadding="0">' . "\n";
foreach my $parameter (sort #params) {
print "<tr><th>$parameter</th><td>" . $cgi->param($parameter) . "</td></tr>\n";
}
print "</table>\n";
print "<p>$username</p>";
print $cgi->end_html . "\n";
#Create a session to the Infoblox appliance
my $session = Infoblox::Session->new(
master => "server", #appliance host ip
username => "username", #appliance user login
password => "password" #appliance password
);
unless ($session) {
die("Construct session failed: ",
Infoblox::status_code() . ":" . Infoblox::status_detail());
}
print "Session created successfully\n<br>";
my #list = $session->get(
object => "Infoblox::DHCP::MAC",
filter => "macfilter",
);
my $nextobject = $list[0];
print <<EOF;
<br>
<table>
<tr>
<th>MAC</th>
<th>Description</th>
<th>UserID</th>
<th>Expiration</th>
</tr>
EOF
foreach my $test ( #list ) {
print "<tr>";
print "<td> $test->mac()</td>";
print "<td>" . scalar($test->comment()) . "</td>\n";
print "<td>" . scalar($test->username()) . "</td>\n";
print "<td>" . scalar(localtime(scalar($test->expiration_time()))) . "</td>\n";
print "</tr>";
}
exit (0);
I had incorrect permissions. The script was running as user nobody and would not display the items correctly on the web page.

Zend Framework: Rename upload file

I have problem with rename file. I need new file name be cyrillic but, when rename img in img folder new name is "Христо Ботев.jpg". That is my code:
$newName = $formdata['name'];
try {
$ext = end(explode('.', $form->img3->getFileName()));
path = (APPLICATION_PATH . '/../public/imgs/' . $newName . '.') . $ext;
$form->img3->addFilter('Rename', array('target' => $path,
'overwrite' => true));
$form->img3->receive();
$form->reset();
}
catch (Exception $e)
{
$editMessage[][] = 'Invalid image.';
}
Try:
$path = (APPLICATION_PATH . '/../public/imgs/' . $newName . '.') . $ext;
$path = iconv('utf-8', 'cp1251', $path);
Try using iconv() function to convert the encoding of the file name.
More info about iconv()

Adding an attachment to this mail form

I have this simple php mail form. It is working and I can use it for making my forms, but I have a problem:
I want to add 2 or 3 attachments to this form. I tried a lot reading about mail at php.net, but I cannot do it by my self.
<?php
$name=$_POST['name'];
$email=$_POST['email'];
$address=$_POST['address'];
$phone=$_POST['phone'];
$fax=$_POST['fax'];
$mobile=$_POST['mobile'];
$subject=$_POST['subject'];
$website=$_POST['website'];
$message=$_POST['message'];
$fulltext = "
______________________________________________
|
| This Is $name Information:
|______________________________________________
| Name : $name
|______________________________________________
| E-Mail : $email
|______________________________________________
| Address : $address
|______________________________________________
| Phone : $phone
|______________________________________________
| FAX : $fax
|______________________________________________
| Mobile : $mobile
|______________________________________________
| Subject : $subject
|______________________________________________
| Website : $website
|______________________________________________
| Message : $message
|______________________________________________
";
$to = 'support#site.com';
$subject = 'Connect FORM <<';
$headers = 'From: contactform#site.com' . "\r\n" .
$message = $fulltext;
mail($to, $subject, $message, $headers);
echo 'file ersal shod';
?>
I improved code from http://ru.php.net/manual/ru/function.mail.php#105661 :
<?php
function multi_attach_mail($to, $subject, $message, $files, $sendermail){
// email fields: to, from, subject, and so on
$from = "Files attach <".$sendermail.">";
//$subject = date("d.M H:i")." F=".count($files);
$message .= "\n".count($files)." attachments";
$headers = "From: $from";
// boundary
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// headers for attachment
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
// multipart boundary
$message = "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
// preparing attachments
for($i=0;$i<count($files);$i++){
if(is_file($files[$i])){
$message .= "--{$mime_boundary}\n";
$fp = #fopen($files[$i],"rb");
$data = #fread($fp,filesize($files[$i]));
#fclose($fp);
$data = chunk_split(base64_encode($data));
$message .= "Content-Type: application/octet-stream; name=\"".basename($files[$i])."\"\n" .
"Content-Description: ".basename($files[$i])."\n" .
"Content-Disposition: attachment;\n" . " filename=\"".basename($files[$i])."\"; size=".filesize($files[$i]).";\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
}
}
$message .= "--{$mime_boundary}--";
$returnpath = "-f" . $sendermail;
$ok = #mail($to, $subject, $message, $headers, $returnpath);
if($ok){ return $i; } else { return 0; }
}
multi_attach_mail("to#somebody.dom",
"Subject of mail" ,
"Hello world!!!",
array($_SERVER["DOCUMENT_ROOT"] . "/first.file", // one file in root of your site
$_SERVER["DOCUMENT_ROOT"] . "/second.file" // another one
),
"from#someone");
?>