Cakephp 3 crop files - cakephp-3.0

I have a method. It checks which type of files I get. Then I have to convert it. If I have video I convert it to .mp4, if image to png. I put this code in controller.
Controller
public function add()
{
$data = $this->request->data();
$this->Posts->create($data);
$this->_checkMultimedia($data);
}
/**
* #param $data
* check file
*/
private function _checkMultimedia($data)
{
if (!empty($data['file-img']['name'])) {
$this->_cropImage($data['file-img']['name']);
}
if (!empty($data['file-video']['name'])) {
$this->_cropVideo($data['file-video']['name']);
}
}
/**
* #param $file
* crop video
*/
private function _cropVideo($file)
{
///
}
/**
* #param $file
* crop image
*/
private function _cropImage($file)
{
////
}`
How can I convert this files. Maybe you cap give me some link or simple examples, becouse I can't search some information

The most widly used tool is
http://www.ffmpeg.org/
You have to download and install it on your server. And instead of writing all this code in controller, write one Compoenent for each of your tasks mentioned above.

Related

PhpStorm - How to define usages of a function or method manually

For simplicity sake, I have these functions.
/**
* #param array
*/
function master($options) {
if (!empty($options["post_function"])) {
form_callables($options["post_function"], $data);
}
}
/**
* #param callable $function
* #param $data
*/
function form_callables(callable $function, $data) {
if (is_callable($function)) {
call_user_func($function, $data);
} else {
fusion_stop("Custom function could not be found.");
}
}
Now, if i use them like this.
master( array( "post_function", "my_function"));
/**
What do I need to doc here so that PhpStorm can show usages of either master or form_callables?
*/
function my_function() {
echo "OK";
}
My problem is my_function shows no usages. I've tried #see, #mixin, #uses, PhpStorm still outlined as grey and No Usages in All Places.
How do I solve this?
Unfortunately I can't see a better solution rather than
/**
* #uses \my_function()
*/
master(["post_function", "my_function"]);

Laravel ajax response issue returning with html content

I am using ajax for ratings. Rating successfully but return response with html code above the json. And it is because of send mail function.
The this code alwasy attached when return response and may be it was from send mail function.
When I am removing Mail function it will return proper result and its working well.
If i were in your place i will work with jobs.
So Here is how it goes
php artisan make:job SendingEmail
App\Jobs\SendingEmail.php
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Facades\Mail;
class SendingEmail implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $admin_email;
protected $email_data;
/**
* Create a new job instance.
*
* #return void
*/
public function __construct($admin_email,$email_data)
{
$this->email_data = $email_data;
$this->admin_email = $admin_email;
}
/**
* Execute the job.
*
* #return void
*/
public function handle()
{
Mail::to($this->admins_email)->send(new RateNotification($this->email_data));
}
}
App\Jobs\SendingEmail::dispatch($podcast);
In Your Controller add this
App\Jobs\SendingEmail::dispatch($admin_email,$email_data);

ZF2 How to access event manager in controller's constructor

How to access event manager in controller constructor ? when I call event manager in constructor , this error appears :
Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for event
You don't have access to the service manager at this point, as it's injected once the object has been instantiated.
You could always move you code to be triggered onDispatch() rather than in the contructor:
/**
* Execute the request
*
* #param MvcEvent $e
* #return mixed
* #throws Exception\DomainException
*/
public function onDispatch(MvcEvent $e)
{
// do something here
// or you could use the events system to attach to the onDispatch event
// rather than putting your code directly into the controller, which would be
// a better option
return parent::onDispatch($e);
}
I would just use Events to attach what ever you need, rather than using the controller
Module.php
/**
* Initialize
*
* #param \Mis\ModuleManager
*/
public function init(ModuleManager $manager)
{
$events = $manager->getEventManager();
$sharedEvents = $events->getSharedManager();
$sharedEvents->attach(__NAMESPACE__, 'dispatch', function($e) {
/* #var $e \Zend\Mvc\MvcEvent */
// fired when an ActionController under the namespace is dispatched.
$controller = $e->getTarget();
$routeMatch = $e->getRouteMatch();
/* #var $routeMatch \Zend\Mvc\Router\RouteMatch */
$routeName = $routeMatch->getMatchedRouteName();
// Attach a method here to do what you need
}, 100);
}

How to tell PhpStorm about implementation details? (magic methods)

I have an object "User" that has attributes whose accessability is declared as protected but which can be set directly via a magic __set-method.
Now PhpStorm signals this apparent inconsistency with a big red column on the right side.
Is it possible to explain to PhpStorm what is going on so this is not shown as an error any more?
EDIT :
I use PhpStorm 2.1.4
okay here is some code that exemplifies the issue (together with the so far suggested workaround from Alexey which sadly doesn't do it for me):
c.php:
<?php
/**
* #property mixed $a
*/
class c1
{
protected $a;
public function __construct() { $this->a = __CLASS__; }
public function __get($n) { return $this->{$n}; }
}
/**
* #property $a mixed
*/
class c2
{
protected $a;
public function __construct() { $this->a = __CLASS__; }
public function __get($n) { return $this->{$n}; }
}
test.php
<?php
require "c.php";
$c1 = new c1();
var_dump($c1->a);
$c2 = new c2();
var_dump($c2->a);
and the output:
string 'c1' (length=2)
string 'c2' (length=2)
and how it looks like in PhpStorm:
my goal:
either having PhpStorm "understand" the design or just getting rid of those annoying red marks everywhere while not impairing the error detection apart from this issue.
This is now working in PHPStorm 3 :)
Unfortunately this is a open request in our tracker, see
http://youtrack.jetbrains.net/issue/WI-4468
The only way to avoid this warnings now, is to add #property to $user's class declaration. i.e.
/**
* #property $name string
*/
class User {
protected $name;
}
$user = new User();
$user->name = "me";

AS3 for Facebook - why is my login callback not being called?

We're developing a Flash site that integrates with Facebook heavily.
We've noticed a bug where, if a user is not logged into Facebook, and we try to log them in via Facebook.login in the AS3 classes provided by Adobe, the callback is invoked, but the parameters result:Object and fail:Object are BOTH null. If our user then tries to login again, it all works fine, returning the userid in result:Object if successful.
Is this a bug with Facebook itself? Has anyone seen this before? We're sure this wasn't happening about a week ago.
Facebook.login(onLogin, {perms:Config.FB_PERMISSIONS});
private function onLogin(result:Object, fail:Object):void {
// first time this is called after the popup closes returns
// result == null and fail == null
// second time around, results are as expected
}
Cheers,
Mark.
this is a way to connect to Facebook using Graph API. Everything is explained in comment. This is actually the connecting to facebook, no posting to walls or anything. That part can be found below this class.
package com.DAL
{
import com.facebook.graph.Facebook;
import flash.events.Event;
import com.facebook.graph.data.FacebookSession;
import flash.events.EventDispatcher;
import flash.events.MouseEvent;
import com.fbLoginButton;
import com.adobe.serialization.json.JSON;
public class FBConnect extends EventDispatcher
{
/******************************************
* Variables
******************************************/
private var _applicationID:String;
private var _extendedPermissions:Object;
/******************************************
* Constants
******************************************/
public static const CONNECTED:String = "CONNECTED";
/******************************************
* Properties
******************************************/
public function get applicationID():String
{
return _applicationID;
}
/******************************************
* Constructor
******************************************/
public function FBConnect()
{
super();
//Set applicationid
_applicationID = "YOUR_ID";
//Set permissions to ask for
_extendedPermissions = {perms:"read_stream, publish_stream, user_about_me, read_friendlists, user_photos"};
//Initialize facebook
Facebook.init(_applicationID);
}
/******************************************
* Methods
******************************************/
public function login(e:MouseEvent):void
{
Facebook.login(handleLogin, _extendedPermissions);
}
private function handleLogin(response:Object, fail:Object):void
{
dispatchEvent(new Event(CONNECTED));
}
}
}
That should take care of connecting to facebook. If you want to post to walls or anything, you can find a small example below.
/******************************************
* Constructor
******************************************/
public function FBLogic()
{
super();
_connect = new FBConnect();
_connect.addEventListener(FBConnect.CONNECTED, startLoaders);
initLoaders();
}
/******************************************
* Methods
******************************************/
...
public function post(message:String):void
{
var _params:Object = new Object();
_params.access_token = Facebook.getSession().accessToken;
_params.message = message;
Facebook.api("/" + _userID + "/feed", messagePosted, _params, "POST");
}
public function messagePosted(response:Object, fail:Object):void
{
dispatchEvent(new Event(MESSAGEPOSTED));
}
public function login(e:MouseEvent):void
{
var _loginButton:fbLoginButton = e.target as fbLoginButton;
_loginButton.alpha = 0;
_loginButton.visible = false;
_connect.login(e);
}
If this doesn't do the trick you might have forgotten to add some code to your html file. Be sure to add the following code to the head of your html file:
<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
And you also need a div called fb-root, declared like this.
<body>
<div id="fb-root"></div>
<div id="flashContent">
</div>
</body>
This is kinda dirty, but for me a timeout before calling login worked fine:
setTimeout(Facebook.login, 200, onLogin, {perms:Config.FB_PERMISSIONS});
_extendedPermissions = {perms:"read_stream, publish_stream, user_about_me, read_friendlists, user_photos"};
Blockquote
"perms" is now "scope"
{scope:"read_stream, publish_stream, user_about_me, read_friendlists, user_photos"};
This is not very well documented on the Adobe Facebook API page.
SHORT ANSWER
Just keep Facebook.init() looping every 0.5 seconds until it finds a valid credential cookie.
LONG ANSWER
The docs describe Facebook.init() as a setup function. But it does more than that, it looks for valid fb logon cookie. As does Facebook.login().
The idea is call Facebook.init() at startup and see if user already have access. Else use Facebook.login() to make the user logon.
Not executable code:
/**
* Start the app, and see if there are any valid credentials
**/
public function startApp() {
Facebook.init(fbAppid, handleFbLogin);
}
/**
* This is a method to call the app didnt login successfully
* at startup.
**/
private function tryLogin() {
Facebook.login(handleFbLogin, {});
}
private var lastLoginSuccess:Object; //being a bit pedantic maybe
/**
* This is the callback that is <i>supposed</i> to run
* ones the user has logged in.
* Unfortunately the callback assoc. with the login/init
* goes off almost instantly; and so often fails before
* valid credentials have been creations >:(
**/
public function handleFbLogin(success:Object, fail:Object) {
lastLoginSuccess = success;
if(success){
//yay!
} else {
//taps foot impatiently...
flash.utils.setTimeout(tryFbInitIfLastFailed, 500);
}
}
/**
* And also the user could be taking their sweet time
* typing in their password.
* Oh and giving their device informative names like 'qwe'
*
* So when they finally login, and the regularly executing
* handleFbLogin() will finally find some valid credentials
**/
private function tryFbInitIfLastFailed() {
if (lastLoginSuccess == null)
Facebook.init(view.fbApp.id, handleFbLogin);
}
Any why not keep calling Facebook.login()? because the opens the Facebook login popup - so you will have a steady stream of popups.
This works for me, either if im not logged in or if im already:
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
Facebook.init("APPID", onInit);
}
private function onInit(response:Object, fail:Object):void
{
if(response)
{
handleLoginResponse(true, null);
}
else
{
Facebook.login(handleLoginResponse, { scope: "email, user_photos, publish_stream" } );
}
}
private function handleLoginResponse(result:Object, fail:Object):void
{
if (result != null) {
// Logged in
} else {
// Goodbye :(
}
}
Add https for all.js in the tag you use in the html file