cakephp3 plugin not load my translation file - plugins

my cakephp3 plugin with name "AdminTheme" has a localisation file.
AdminTheme
/src
/Locale
/de
AdminTheme.po
The locale change perfectly. In my templates I use the function
__d('AdminTheme', 'Sign In')
The function
\Cake\I18n\MessagesFileLoader::__invoke()
says in line 122 (is_file()): File not found.
pathToMyCake/plugins/AdminTheme/src/Locale/de/AdminTheme.po
public function __invoke()
{
$package = new Package('default');
$folders = $this->translationsFolders();
$ext = $this->_extension;
$file = false;
$fileName = $this->_name;
$pos = strpos($fileName, '/');
if ($pos !== false) {
$fileName = substr($fileName, $pos + 1);
}
foreach ($folders as $folder) {
$path = $folder . $fileName . ".$ext";
if (is_file($path)) {
$file = $path;
break;
}
}
if (!$file) {
return $package;
}
$name = ucfirst($ext);
$class = App::classname($name, 'I18n\Parser', 'FileParser');
if (!$class) {
throw new RuntimeException(sprintf('Could not find class %s', "{$name}FileParser"));
}
$messages = (new $class)->parse($file);
$package->setMessages($messages);
return $package;
}
Why?
The file is correctly?
Please help me. Very thank's.
The debugger screens
I'm confused.

Related

Slim upload file by directory file

i have problem with file upload. i want to upload file by name or path file in local.
i tried to use
$app->post('/books/cover/{id}', function (Request $request, Response $response, array $args) {
$path = "d:\\1.jpg";
$file = basename($path);
$uploadedFile = $file;
if ($uploadedFile->getError() === UPLOAD_ERR_OK) {
$extension = pathinfo($uploadedFile->getClientFilename(), PATHINFO_EXTENSION);
$filename = sprintf('%s.%0.8s', $args["id"], $extension);
$directory = $this->get('settings')['upload_directory'];
$uploadedFile->moveTo($directory . DIRECTORY_SEPARATOR . $filename);
return $response->withJson(["status" => "failed", "data" => "0"], 200);
}
});

Fetch and upload files and prefixed files to s3 using perl

I am trying to fetch files from s3 using Amazon::S3 module in Perl . I am successfully able to download files which are not prefixed but unable to fetch prefixed files like test/abc.txt.
I am using below code.
sub export_bucket {
my ($conn, $bucket, $directory) = #_;
$bucket = $conn->bucket($bucket);
my $response = $bucket->list();
print $response->{bucket}."\n";
for my $key (#{ $response->{keys} }) {
print "\t".$key->{key}."\n";
_export_file($conn,$bucket,$key->{key}, $directory.'/'.$key->{key});
}
}
sub _export_file {
my ($conn,$bucket,$name,$path) = #_;
print "Downloading $name file","\n";
my $test = $bucket->get_key_filename($name,'GET',$path);
print Dumper($test);
my $acl = $bucket->get_acl($name);
print Dumper($acl);
open my $acl_file, '>', $path.'.acl';
print $acl_file $acl;
close $acl_file;
}
Suggest me what changes should i make so that when a prefixed/folder comes i should be able to download the folder as well.
Thanks
You need to modify you code to create the target directory on your local filesystem if it does not already exist. It should look something like this:
use File::Path qw[make_path];
sub export_bucket {
my ( $conn, $bucket, $directory ) = #_;
$bucket = $conn->bucket($bucket);
my $response = $bucket->list();
print $response->{bucket} . "\n";
for my $key ( #{ $response->{keys} } ) {
print "\t" . $key->{key} . "\n";
_export_file( $conn, $bucket, $key->{key}, $directory . '/' . $key->{key} );
}
}
sub _export_file {
my ( $conn, $bucket, $name, $path ) = #_;
print "Downloading $name file", "\n";
my $test = $bucket->get_key_filename( $name, 'GET', $path );
print Dumper($test);
my $acl = $bucket->get_acl($name);
print Dumper($acl);
## get path directory part
my ($dir_part) = $path =~ /(.+)\/[^\/]+$/;
unless ( -d $dir_part ) {
make_path($dir_part);
}
open my $acl_file, '>', $path . '.acl';
print $acl_file $acl;
close $acl_file;
}
Perhaps $directory has a trailing "/" already in the case that is failing (or $key->{key} has a preceding slash)? Try debug-printing $directory and $path in the code to see exactly what your string arguments are.

A string replace with array

I am trying to create a simple image gallery for joomla 3. I have managed to get the code working. The way it works is that, it detects the string {dGalley}stories{/dGallery} from article. I have done this so far. It works but it only prints one image. Any suggestion? Thanks in advance.
<?php
defined('_JEXEC') or die;
class PlgContentgallery extends JPlugin
{
public function onContentPrepare($content, $article, $params, $limit){
preg_match_all('/{dGallery}(.*?){\/dGallery}/is', $article->text, $matches);
$i=0;
foreach ($matches[1] as $value)
{
$result = array();
$dir = '/home/juniorwe/public_html/images/'.$matches[1][$i];
$cdir = scandir($dir);
foreach ($cdir as $key => $value)
{
if (!in_array($value,array(".","..")))
{
if (is_dir($dir . DIRECTORY_SEPARATOR . $value))
{
$result[$value] = dirToArray($dir . DIRECTORY_SEPARATOR . $value);
}
else
{
$article->text = str_replace('{dGallery}'.$matches[1][$i].'{/dGallery}','<img src="../images/'.$matches[1][$i].'/'.$value.'"/>
', $article->text);
}
}
}
$i++;
}
}
}
Updated code. It works but a bit dirty solution:
<?php
defined('_JEXEC') or die;
class PlgContentgallery extends JPlugin
{
public function onContentPrepare($content, $article, $params, $limit)
{
$document = JFactory::getDocument();
$document->addScript(JURI::base(). "plugins/content/gallery/jquery.colorbox.js");
$document->addScript(JURI::base(). "plugins/content/gallery/colorboxCall.js");
$document->addStyleSheet(JURI::base(). "plugins/content/gallery/colorbox.css");
preg_match_all('/{dGallery}(.*?){\/dGallery}/is', $article->text, $matches);
$i=0;
foreach ($matches[1] as $value)
{
$result .= '';
$dir = '/home/juniorwe/public_html/images/'.$matches[1][$i];
$cdir = scandir($dir);
foreach ($cdir as $key => $value)
{
if (!in_array($value,array(".","..")))
{
if (is_dir($dir . DIRECTORY_SEPARATOR . $value))
{
$result[$value] = dirToArray($dir . DIRECTORY_SEPARATOR . $value);
}else{
$result .='<a class="group4" href="../images/'.$matches[1][$i].'/'.$value.'" title=""><img src="../images/'.$matches[1][$i].'/'.$value.'" class="gallery"/></a>';
}
}
}
$article->text = str_replace('{dGallery}'.$matches[1][$i].'{/dGallery}',$result, $article->text);
$i++;
}
}
}
You want something more like this
public function onContentPrepare($content, $article, $params, $limit)
{
preg_match_all('/{dGallery}(.*?){\/dGallery}/is', $article->text, $matches);
foreach ($matches[0] as $folder)
{
$result = array();
$dir = '/home/juniorwe/public_html/images/' . $folder; // You might want to get the stored value for image path instead of hard coding
if (is_dir($dir))
{
$cdir = JFilesystem::files($dir);
foreach ($cdir as $value)
{
$article->text = str_replace('{dGallery}' . $folder .'{/dGallery}','<img src="/images/' . $folder . '/' . $value. ' "/>', $article->text);
}
}
}
}
Is it that you are trying to get the images from the sub folders also?

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()

How can I find the full URL from a relative URL in Perl?

I'm new to perl but was wondering if anyone know of a script that was similar to the following PHP version which works great!
private function resolve_href ( $base, $href ) {
if (!$href)
return $base;
$rel_parsed = parse_url($href);
if (array_key_exists('scheme', $rel_parsed))
return $href;
$base_parsed = parse_url("$base ");
if (!array_key_exists('path', $base_parsed))
$base_parsed = parse_url("$base/ ");
if ($href{0} === "/")
$path = $href;
else
$path = dirname($base_parsed['path']) . "/$href";
$path = preg_replace('~/\./~', '/', $path);
$parts = array();
foreach ( explode('/', preg_replace('~/+~', '/', $path)) as $part ) {
if ($part === "..")
array_pop($parts);
elseif ($part!="")
$parts[] = $part;
}
$dir = ( ( array_key_exists('scheme', $base_parsed)) ? $base_parsed['scheme'] . '://' . $base_parsed['host'] : "" ) . "/" . implode("/", $parts);
return str_replace( "\/", '', $dir );
}
Any help is much appreciated
See URI:
#!/usr/bin/perl
use strict; use warnings;
use URI;
my $u = URI->new_abs('../foobar', 'http://foo.com/bar/poo/');
print $u->canonical;
Output:
http://foo.com/bar/foobar