Cakephp link image to external site - image

New to cakephp, I'm trying to make an icon that is link to an external site, I tried to surf the cookbook and some forums but I seem to can't find what I'm looking for.
Here's my current code:
echo $this->Html->link($this->Html->image('ex_vi.png', array('height' => '40', 'width' => '40')) . '' . ('Example'), array('http://examples.com'), array('escape' => false));
Any help is appreciated, a little bit frustrated first time to code with a framework, everything is quite different

You can use following code to add external link to image
echo $this->Html->link($this->Html->image('ex_vi.png', array('height' => '40', 'width' => '40')) . '' . ('Example'), 'http://examples.com', array('escape' => false));
Just Pass URL directly without array

Related

Laravel Invention Image - How to DELETE image from Storage

I created Laravel app where I wanted to upload images + resize and crop them, for that I used Invention Image
Here is my code how I'm storing images:
/*just image cropping + resizing*/
$light_image = Image::make($request->file('startup_screenshot'));
$light_image->resize(300, null, function ($constraint) {
$constraint->aspectRatio();
});
$light_image->crop(300, 275, 0, 0);
$light_image->encode('jpg');
/*just image cropping + resizing*/
/*image storing*/
$hashed_light_image = md5($light_image->__toString());
$light_image_name = $hashed_light_image . time() . '.jpg';
Storage::put('public/images/startups-screenshots/light_previews/' . $light_image_name, $light_image->__toString());
$path_to_light_image = '/storage/images/startups-screenshots/light_previews/' . $light_image_name;
/*image storing*/
I tried to use this code to delete images but it doesn't work:
...
$startup_to_update = Startup::find($request->id);
Storage::delete($startup_to_update->screenshot);
Storage::delete($startup_to_update->screenshot_light); // pay attention
...
How Can I delete those images ?
Thank you all very much for any ideas!
I realy appreciate this ))
From what you write we can only get conjetures but well, are you sure that you are storing the correct path?, remember that Storage will be storage/app (you can check it in config->filesystem) so it would be stored in
storage/app/public/images/startups-screenshots/light_previews/ . $light_image_name
But for what i can see/think you are looking inside of
/storage/images/startups-screenshots/light_previews/' . $light_image_name
in any case if you think that what is inside $startup_to_update is the real path then you can check if it exist with
Storage::has($direction)
if it return true, then the file exist and you may have a problem with permissions.
ProTip, for these cases i use to make my own disk inside config->filesystems.php
'light_previews' => [
'driver' => 'local',
'root' => storage_path('/app/public/images/startups-screenshots/light_previews/'),
'url' => env('APP_URL').'storage/app/public/images/startups-screenshots/light_previews/',
'visibility' => 'public',
],
And then i use it like these
Storage::disk('light_previews')->put($fileName, file_get_contents($file));//store
Storage::disk('light_previews')->delete($fileName);//delete
You don't have to use intervention to delete images from storage. Intervention only acts as a image helper, not a file system helper.
use Illuminate\Support\Facades\Storage;
Storage::delete(file_path_of_image);
I fixed this, path wasn't correct,
I used this type of path to store my images: "/storage/images/startups-screenshots/light_previews/image_name.jpg" , you can see code example below:
Storage::put('public/images/startups-screenshots/light_previews/' . $light_image_name, $light_image->__toString());
As you can see I used "public/images/...." on the begining, but when I tried to delete this I couldn't because I should point path of that type "public/images/...." , not that one which I used: "/storage/images/...."
so I just changed path from "public/images/...." to "public/images/...."
and it works now
Thanks all for good ideas!

How to create laravel custom storage:link?

How to create laravel custom storage:link?
I would like to point
project/public/storage >> project/storage/app/tenancy/tenants
In config/filesystems.php :
'links' => [
public_path() . '_html\storage' => storage_path('app/public'),
],
after following this tutorial to change /public to /public_html
https://developerhowto.com/2018/11/12/how-to-change-the-laravel-public-folder/
At this moment it is not possible to customize the path with this command. I looked at the source code and couldn't find any hints regarding to this issue.
The simplest thing you can do is make the symbolic link yourself.
The only thing this command does is create that symlink with PHP. This is the source code:
if (! windows_os()) {
return symlink($target, $link);
}
$mode = $this->isDirectory($target) ? 'J' : 'H';
exec("mklink /{$mode} \"{$link}\" \"{$target}\"");
If you really need to make a command for it. You can create your own. If you want to see how Taylor did it, you can look in the following file:
vendor/laravel/framework/src/Illuminate/Foundation/Console/StorageLinkCommand.php

Laravel localization file format error: array() versus [] format

I am struggling a bit with localization in Laravel 5.3 (with php 7). The default localizaiton file format in Laravel 5.3 is using brackets, as in this example:
return [
'footer.contact.email' => 'Email:',
]
That's what I have been using in my app and it's working fine. But now I am trying to work with some packages to help with translations, for example:
https://github.com/potsky/laravel-localization-helpers
https://github.com/barryvdh/laravel-translation-manager
But both of those generate localization files in the "old" laravel 4.x array format. For example
return array(
'footer' => array(
'contact' => array(
'email' => 'Email:',
),
),
);
As I understand it I should have no issue with this localization file format in my laravel 5.3 app, however it's always throwing an exception:
[2016-12-02 13:26:01] local.ERROR: ErrorException: htmlspecialchars() expects parameter 1 to be string, array given in C:\100_source_code\consulting_platform_laravel\maingig\vendor\laravel\framework\src\Illuminate\Support\helpers.php:519
Stack trace:
#0 C:\100_source_code\consulting_platform_laravel\maingig\vendor\sentry\sentry\lib\Raven\Breadcrumbs\ErrorHandler.php(36): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'htmlspecialchar...', 'C:\\100_source_c...', 519, Array)
I really cant understand why this format is not working with my app. I bet it is something trivial that I am missing, but any help would be very welcome!
Thanks,
Christian
After a few extra hours of stepping through the code I found the source of the problem.
For example, I got these in my original lang file:
'footer.subscribe' => 'SUBSCRIBE TO OUR NEWSLETTER',
'footer.subscribe.intro' => 'Be the first to know about our latest news...',
'footer.subscribe.privacy' => 'Privacy Policy',
'footer.subscribe.tos' => 'Terms of Service',
'footer.subscribe.tac' => 'Terms and Conditions',
As I tried to use both of the packages mentioned in my original question they produced the following output:
'footer' =>
array (
'subscribe' =>
array (
'intro' => 'TODO: intro',
'privacy' => 'TODO: privacy',
'tos' => 'TODO: tos',
'tac' => 'TODO: tac',
),
),
As you can see the generated file dropped the value for the text footer.subscribe and only kept the child element, intro, privacy, tos and tas in this case. Therefore a request for trans('footer.subscribe') returns an array and not the text.
Now that I know this I will change the format of my original translation file!
c.

Using Laravel core in scripts built without it

I have built a Laravel 3 application, it involves a lot of per-user content management.
For prototype and internal testing I got away with plain configuration of KCFinder, now we're about to start a closed beta.
Firstly, I must lock the KCFinder behind Laravel applications Auth system.
Secondly, I must configure the KCF with a per-user settings.
While it may seem like those are two questions, I doubt they are.
My Laravel is installed in /srv/http/, KCFinder in /srv/http/public/php/kcfinder/.
KCFinder exposes two incoming files - browse.php and upload.php. These files include core/autoload.php, that ultimately ties the KCF together.
I tried requiring Laravel's public/index.php inside it, then tried to access something KCF (/php/kcfinder/browse.php) through browser. Got redirected to a mix of the request path and Laravel applications root route: /php/kcfinder/browser.
How could I prevent the Routing from Laravel and be able to use Laravel inside the KCF scope?
P.S. I did try to go the Bundle way, but apparently KCF is so poorly written that it appears that in order to Bundle it up, I'll have to rewrite everything there.
I managed to do it with a very, very dirty hack.
In /srv/http/public/php/kcfinder/core/autoload.php I appended the lines:
require '../../../paths.php';
require path('sys').'core.php';
\Laravel\Bundle::start(DEFAULT_BUNDLE);
$KCFinderRoot = addslashes(realpath(dirname(__FILE__). '/../') . DS);
\Laravel\Autoloader::map(array(
'browser' => $KCFinderRoot . 'core/browser.php',
'uploader' => $KCFinderRoot . 'core/uploader.php',
'type_img' => $KCFinderRoot . 'core/types/type_img.php',
'type_mime' => $KCFinderRoot . 'core/types/type_mime.php',
'gd' => $KCFinderRoot . 'lib/class_gd.php',
'input' => $KCFinderRoot . 'lib/class_input.php',
'zipFolder' => $KCFinderRoot . 'lib/class_zipFolder.php',
'dir' => $KCFinderRoot . 'lib/helper_dir.php',
'file' => $KCFinderRoot . 'lib/helper_file.php',
'httpCache' => $KCFinderRoot . 'lib/helper_httpCache.php',
'path' => $KCFinderRoot . 'lib/helper_path.php',
'text' => $KCFinderRoot . 'lib/helper_text.php',
));
if (!\Laravel\Auth::check())
{
die('no user :(');
}
Wherever KCF had some file inclusions, I had to squeeze in $KCFinderRoot, in some methods even requiring to global them before.
In KCF's config I added:
// ...
'uploadURL' => "/useruploads/" . sha1(Auth::user()->id . Auth::user()->email),
'uploadDir' => path('public') . "useruploads/" . sha1(Auth::user()->id . Auth::user()->email),
// ...
The end result works like I wanted it to, except I have no idea how "smart" this is.
P.S. In the following days I'm going to try to bundle, IoC this up while leaving KCF files intact.

InstantCommons not working in MediaWiki 1.19 and SELinux

I am setting my own MediaWiki website locally, and am not able to get the InstantCommons feature to work (used to directly embed files from commons.wikimedia.org).
I get no error message, the files I try to load from Commons using the following syntax:
[[File:Cervus elaphus Luc Viatour 1.jpg|Cervus elaphus Luc Viatour 1]]
are just not loaded, and I end up with a red link on my page, referring to a non-existing file. It has been 2 days now that I am looking for a solution, but so far without any success.
I am running:
MediaWiki v.1.19.1
Fedora 16 (with SElinux)
PHP 5.3.15
MySQL Ver 14.14 Distrib 5.5.25a, for Linux (x86_64)
I have tried the following two configurations in my LocalSettings.php, without success:
$wgUseInstantCommons = true;
AND
$wgForeignFileRepos[] = array(
'class' => 'ForeignAPIRepo',
'name' => 'shared',
'apibase' => 'http://commons.wikimedia.org/w/api.php',
'fetchDescription' => true, // Optional
'descriptionCacheExpiry' => 43200, // 12 hours, optional (values are seconds)
'apiThumbCacheExpiry' => 43200, // 12 hours, optional, but required for local thumb caching
);
Any suggestion is most welcome.
OK, this is not (yet) an answer, but a debugging suggestion. It looks to me like the HTTP request from your server to Commons is failing for some reason, but unfortunately ForeignAPIRepo doesn't indicate the cause of the error in any way.
This is really a bug in MediaWiki, and should be fixed, but in the mean time, could you please try applying the following diff (or just manually adding the line marked with the + sign) to your includes/filerepo/ForeignAPIRepo.php file:
Index: includes/filerepo/ForeignAPIRepo.php
===================================================================
--- includes/filerepo/ForeignAPIRepo.php (revision 97048)
+++ includes/filerepo/ForeignAPIRepo.php (working copy)
## -385,6 +385,7 ##
if ( $status->isOK() ) {
return $req->getContent();
} else {
+ wfDebug( "ForeignAPIRepo: HTTP GET failed: " . $status->getXML() );
return false;
}
}
After applying it, try loading the file description page for a Commons image and look at the MediaWiki debug log. There should now be a line starting with ForeignAPIRepo: HTTP GET failed: followed by a few lines of XML error dump. That error data should hopefully indicate what's going wrong; please copy and paste it here.
Mine is not a definitive answer either. Referring to Ilmari Karonen's post, I was unable to find or get the getXML() method to execute for my version of Mediawiki v1.23.0. I was looking at the reference documentation found here to try and find any other method calls on the Status class that would give me good troubleshooting info. I ended up finding the following and editing the same file as mentioned in Ilmari Karonen's post includes/filerepo/ForeignAPIRepo.php beginning at line #521:
if ( $status->isOK() ) {
return $req->getContent();
} else {
$error = $status->getErrorsArray();
$dump = print_r($error, true);
wfDebug("ForeignAPIRepo: HTTP GET failed: $dump\n");
return false;
}
The default InstantCommons configuration of older MediaWikis is a bit silly. Due to T114098 I recommend one of the following, which will hopefully fix your problems:
upgrade to MediaWiki 1.27 (when it's released), or
set your LocalSettings.php to hotlink images to save on server-side requests and processing.
$wgUseInstantCommons = false;
$wgForeignFileRepos[] = array(
'class' => 'ForeignAPIRepo',
'name' => 'commonshotlink',
'apibase' => 'https://commons.wikimedia.org/w/api.php',
'hashLevels' => 2,
'url' => 'https://upload.wikimedia.org/wikipedia/commons',
'thumbUrl' => 'https://upload.wikimedia.org/wikipedia/commons/thumb',
'transformVia404' => true,
'fetchDescription' => true,
'descriptionCacheExpiry' => 43200,
'apiThumbCacheExpiry' => 24 * 3600,
);

Resources