Error Use of exit language construct is discouraged - magento2

Use of exit language construct is discouraged.
if ($attribute_name == $customerGroup) {
if ($dropdown_field > $Quantity) {
$this->messageManager->addError($this->helper->getGeneralConfig('minimum_alertmsg') . $dropdown_field);
$cartUrl = $this->_url->getUrl('checkout/cart');
$this->_responseFactory->create()->setRedirect($cartUrl)->sendResponse();
Exit();
}
}
need to redirect in check out page without using exit(); and die();

i Got The Solution
Using Javascript We Can Remove Error "Use of exit language construct is discouraged"
if ($attribute_name == $customerGroup) {
if ($dropdown_field > $Quantity) {
$this -> messageManager -> addError($this -> helper -> getGeneralConfig('minimum_alertmsg').$dropdown_field);
$cartUrl = $this -> _url -> getUrl('checkout/cart');
?
>
<
script type = "text/javascript" >
window.location.href = "<?= $cartUrl; ?> "; <
/script>
<
? php
}
}

Related

get pagename in my wordpress plugin

I am adding specific js file to the front end from my wordpress plugin.
For Example :
if($wp->query_vars["pagename"] == 'pagename1'){
include js file 1.
}else if($wp->query_vars["pagename"] == 'pagename1'){
include js file 2.
}
But now i am not able to get the page name in$wp->query_vars.
Thank you
Balaji
Try this:
$post = get_post();
$post_name = $post->post_name;
To add javascript you could do this:
add_action( 'wp_enqueue_scripts', 'addSomescripts' );
function addSomeScripts() {
$post = get_post( );
$post_name = $post->post_name;
if($post_name == 'pagename1') {
wp_enqueue_script('script1', '/pathtoscript1.js');
} else if($post_name == 'pagename2') {
wp_enqueue_script('script2', '/pathtoscript2.js');
}
}

Joomla website is getting 303 redirect loop

My website is sometimes getting a 303 redirect loop on the main page. This gives me an error when trying to view the site "the webpage has a redirect loop", but most of the time is loads fine. But, the 303 redirect doesn't look good for SEO. I'm running the Joomla 3.2.3 with the Zo2 framework. I used the firefox live http headers tool and this is what it shows:
HTTP/1.1 303 See other
Date: Sat, 19 Apr 2014 06:42:44 GMT
Server: Apache mod_fcgid/2.3.10-dev
X-Powered-By: PHP/5.4.26
Set-Cookie: 81f5073a1f9d10dc244e07c98216335e=hb7mb5k3v0vftstcgtdbonikq6; path=/; HttpOnly
Location: /
Cache-Control: max-age=600
Expires: Sat, 19 Apr 2014 06:52:44 GMT
Content-Length: 0
Keep-Alive: timeout=5
Connection: Keep-Alive
I went through and disable every plugin in Joomla one at a time and when I disable the Zo2 framework plugin the 303 redirect went away. I've asked on their forums and they haven't been able to help me. So, I searched through all of the files in the zo2 plugin directory for the word redirect and this is what I found.
These two are in the site.megamenu.js
!function ($) {
$(document).ready(function ($) {
// when clicking on menu
redirect();
var duration = 0;
var $parent = $('.zo2-megamenu');
var hover_type = $parent.data('hover');
if ($parent.data('duration')) {
duration = $parent.data('duration');
}
function redirect() {
$('.dropdown-toggle').on('click',function(e){
if($(this).parent().hasClass('open') && this.href && this.href != '#'){
window.location.href = this.href;
e.preventDefault();
}
});
}
I have other website running on this server using the same .htaccess and php.ini files so I don't think that could be the problem, because they are not getting a redirect. I would appreciate some help with this. The website is http://www.betterfreestuff.com
/**
* Zo2 Framework (http://zo2framework.org)
*
* #link http://github.com/aploss/zo2
* #package Zo2
* #author Hiepvu
* #copyright Copyright ( c ) 2008 - 2013 APL Solutions
* #license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or Later
*/
!function ($) {
$(document).ready(function ($) {
// when clicking on menu
redirect();
var duration = 0;
var $parent = $('.zo2-megamenu');
var hover_type = $parent.data('hover');
if ($parent.data('duration')) {
duration = $parent.data('duration');
}
if (duration && (hover_type == 'hover')) {
var timeout = duration ? duration + 50 : 500;
$('.nav > li, li.mega').hover(
function(e) {
onMouseIn(this, timeout);
}
,
function (e) {
onMouseOut(this);
}
);
} else if (hover_type == 'click') {
$('.mega-nav').find('.dropdown-submenu').hover(
function(e) {
onMouseIn(this, 100);
}
,
function (e) {
onMouseOut(this);
}
);
}
// for first li tag
function redirect() {
$('.dropdown-toggle').on('click',function(e){
if($(this).parent().hasClass('open') && this.href && this.href != '#'){
window.location.href = this.href;
e.preventDefault();
}
});
}
function onMouseIn (e, timeout) {
var $this = $(e);
if ($this.hasClass('mega')) {
$this.addClass ('hovering');
clearTimeout ($this.data('hoverTime'));
$this.data('hoverTime',
setTimeout(function(){$this.removeClass ('hovering')}, timeout));
clearTimeout ($this.data('hoverTime'));
$this.data('hoverTime',
setTimeout(function(){$this.addClass ('open')}, 100));
} else {
clearTimeout($this.data('hoverTime'));
$this.data('hoverTime',
setTimeout(function () {
$this.addClass('open')
}, 100));
}
}
function onMouseOut (e) {
var $this = $(e);
clearTimeout($this.data('hoverTime'));
$this.data('hoverTime',
setTimeout(function () {
$this.removeClass('open')
}, 100));
}
/** BEGIN: off canvas menu **/
var showOffCanvasMenu = function () {
var $offcanvas = $('.offcanvas');
var $body = $('body');
var $wrapper = $('.wrapper');
$body.addClass('overflow-hidden');
$wrapper.addClass('offcanvas-push');
var $overlay = $('<div />').addClass('offcanvas-overlay').appendTo('body');
$overlay.css({
top:0,
right:0,
bottom:0
}).fadeIn();
$overlay.click(function() {
$body.removeClass('overflow-hidden');
$wrapper.removeClass('offcanvas-push');
$offcanvas.removeClass('active');
$('.offcanvas-overlay').remove();
});
};
var hideOffCanvasMenu = function () {
var $body = $('body');
var $wrapper = $('.wrapper');
var $offcanvas = $('.offcanvas');
$body.removeClass('overflow-hidden');
$wrapper.removeClass('offcanvas-push');
$offcanvas.removeClass('active');
$('.offcanvas-overlay').remove();
};
$('[data-toggle=offcanvas]').click(function() {
var $offcanvas = $('.offcanvas');
$offcanvas.toggleClass('active');
if ($offcanvas.hasClass('active')) {
showOffCanvasMenu();
}
else {
hideOffCanvasMenu();
}
});
$('body').on('click', '.sidebar-nav a', function() {
if (!$(this).hasClass('nav-oc-toggle')) hideOffCanvasMenu();
});
$('body').on('click', '.sidebar-close', function() {
hideOffCanvasMenu();
});
// new off canvas submenu
$('body').on('click', '.nav-oc-toggle', function() {
var $this = $(this);
var $parent = $this.closest('.nav-parent');
if ($parent.find('> .submenu').hasClass('in')) $this.removeClass('icon-caret-up').addClass('icon-caret-down');
else $this.removeClass('icon-caret-down').addClass('icon-caret-up');
});
/** END: off canvas menu **/
});
}(jQuery);
I searched for 303 in all of the files on my server and these files came back with redirect statements.
cms.php
public function redirect($url, $moved = false)
{
// Handle B/C by checking if a message was passed to the method, will be removed at 4.0
if (func_num_args() > 1)
{
$args = func_get_args();
/*
* Do some checks on the $args array, values below correspond to legacy redirect() method
*
* $args[0] = $url
* $args[1] = Message to enqueue
* $args[2] = Message type
* $args[3] = $moved
*/
if (isset($args[1]) && !empty($args[1]) && !is_bool($args[1]))
{
// Log that passing the message to the function is deprecated
JLog::add(
'Passing a message and message type to JFactory::getApplication()->redirect() is deprecated. '
. 'Please set your message via JFactory::getApplication()->enqueueMessage() prior to calling redirect().',
JLog::WARNING,
'deprecated'
);
$message = $args[1];
// Set the message type if present
if (isset($args[2]) && !empty($args[2]))
{
$type = $args[2];
}
else
{
$type = null;
}
// Enqueue the message
$this->enqueueMessage($message, $type);
// Reset the $moved variable
$moved = isset($args[3]) ? (boolean) $args[3] : false;
}
}
application.php
public function redirect($url, $msg = '', $msgType = 'message', $moved = false)
{
// Check for relative internal links.
if (preg_match('#^index2?\.php#', $url))
{
$url = JUri::base() . $url;
}
// Strip out any line breaks.
$url = preg_split("/[\r\n]/", $url);
$url = $url[0];
/*
* If we don't start with a http we need to fix this before we proceed.
* We could validly start with something else (e.g. ftp), though this would
* be unlikely and isn't supported by this API.
*/
if (!preg_match('#^http#i', $url))
{
$uri = JUri::getInstance();
$prefix = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
if ($url[0] == '/')
{
// We just need the prefix since we have a path relative to the root.
$url = $prefix . $url;
}
else
{
// It's relative to where we are now, so lets add that.
$parts = explode('/', $uri->toString(array('path')));
array_pop($parts);
$path = implode('/', $parts) . '/';
$url = $prefix . $path . $url;
}
}
// If the message exists, enqueue it.
if (trim($msg))
{
$this->enqueueMessage($msg, $msgType);
}
// Persist messages if they exist.
if (count($this->_messageQueue))
{
$session = JFactory::getSession();
$session->set('application.queue', $this->_messageQueue);
}
// If the headers have been sent, then we cannot send an additional location header
// so we will output a javascript redirect statement.
if (headers_sent())
{
echo "<script>document.location.href='" . str_replace("'", "&apos;", $url) . "';</script>\n";
}
else
{
$document = JFactory::getDocument();
jimport('phputf8.utils.ascii');
if (($this->client->engine == JApplicationWebClient::TRIDENT) && !utf8_is_ascii($url))
{
// MSIE type browser and/or server cause issues when url contains utf8 character,so use a javascript redirect method
echo '<html><head><meta http-equiv="content-type" content="text/html; charset=' . $document->getCharset() . '" />'
. '<script>document.location.href=\'' . str_replace("'", "&apos;", $url) . '\';</script></head></html>';
}
else
{
// All other browsers, use the more efficient HTTP header method
header($moved ? 'HTTP/1.1 301 Moved Permanently' : 'HTTP/1.1 303 See other');
header('Location: ' . $url);
header('Content-Type: text/html; charset=' . $document->getCharset());
}
}
$this->close();
}
web.php
public function redirect($url, $moved = false)
{
// Import library dependencies.
jimport('phputf8.utils.ascii');
// Check for relative internal links.
if (preg_match('#^index\.php#', $url))
{
// We changed this from "$this->get('uri.base.full') . $url" due to the inability to run the system tests with the original code
$url = JUri::base() . $url;
}
// Perform a basic sanity check to make sure we don't have any CRLF garbage.
$url = preg_split("/[\r\n]/", $url);
$url = $url[0];
/*
* Here we need to check and see if the URL is relative or absolute. Essentially, do we need to
* prepend the URL with our base URL for a proper redirect. The rudimentary way we are looking
* at this is to simply check whether or not the URL string has a valid scheme or not.
*/
if (!preg_match('#^[a-z]+\://#i', $url))
{
// Get a JUri instance for the requested URI.
$uri = JUri::getInstance($this->get('uri.request'));
// Get a base URL to prepend from the requested URI.
$prefix = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
// We just need the prefix since we have a path relative to the root.
if ($url[0] == '/')
{
$url = $prefix . $url;
}
// It's relative to where we are now, so lets add that.
else
{
$parts = explode('/', $uri->toString(array('path')));
array_pop($parts);
$path = implode('/', $parts) . '/';
$url = $prefix . $path . $url;
}
}
// If the headers have already been sent we need to send the redirect statement via JavaScript.
if ($this->checkHeadersSent())
{
echo "<script>document.location.href='" . str_replace("'", "&apos;", $url) . "';</script>\n";
}
else
{
// We have to use a JavaScript redirect here because MSIE doesn't play nice with utf-8 URLs.
if (($this->client->engine == JApplicationWebClient::TRIDENT) && !utf8_is_ascii($url))
{
$html = '<html><head>';
$html .= '<meta http-equiv="content-type" content="text/html; charset=' . $this->charSet . '" />';
$html .= '<script>document.location.href=\'' . str_replace("'", "&apos;", $url) . '\';</script>';
$html .= '</head><body></body></html>';
echo $html;
}
else
{
// All other cases use the more efficient HTTP header for redirection.
$this->header($moved ? 'HTTP/1.1 301 Moved Permanently' : 'HTTP/1.1 303 See other');
$this->header('Location: ' . $url);
$this->header('Content-Type: text/html; charset=' . $this->charSet);
}
}

Prevent render template in fuelphp

In fuelphp, we can render template from controller. But I want prevent render template from package.
Example:
Step 1: fuelphp run controlelr -> render template
Step 2: run package -> have a command to clear all data in step 1. and
render blank page.
Result with a blank page
$this->template->content = ...
\Package::removeTemplate();
I tried with
\Event::forge(array('shutdown'));
\Fuel::finish();
But it is not success. How can I do it?
You can always modify your template, inside the controller in every function just use
$this->template
Example
class Controller_lorem extends Controller_Main {
public $template = 'template_default';
public function action_ipsum()
{
//use customize template other than default
$this->template = View::forge('template_custom');
}
I found a solution. Rewrite \Fuel::finish()
public static function finishS()
{
if (\Config::get('caching', false))
{
\Finder::instance()->write_cache('FuelFileFinder');
}
if (static::$profiling and ! static::$is_cli)
{
// Grab the output buffer and flush it, we will rebuffer later
$output = ob_get_clean();
$headers = headers_list();
$show = true;
foreach ($headers as $header)
{
if (stripos($header, 'content-type') === 0 and stripos($header, 'text/html') === false)
{
$show = false;
}
}
if ($show)
{
\Profiler::mark('End of Fuel Execution');
if (preg_match("|</body>.*?</html>|is", $output))
{
$output = preg_replace("|</body>.*?</html>|is", '', $output);
$output .= \Profiler::output();
$output .= '</body></html>';
}
else
{
$output .= \Profiler::output();
}
}
// Restart the output buffer and send the new output
ob_start();
**/// Remove this line echo $output;**
}
}

Zend_navigation & Zend_translate href attribute dont switch with language change

I have a zend framework project with zend version 1.12.
I´m using zend_navigation with a xml file and zend_translation with the gettext adapter.
This code creates the main menu:
echo '<ul class="nav1">';
foreach ($this->container as $page) {
// check if it is active (not recursive)
$isActive = $page->isActive(false);
$liClass = $isActive ? ' class="active"' : '';
echo '<li ' . $liClass . '>' . $this->menu()->htmlify($page);
// subnavigation in second layer
if (sizeof($page) > 0) {
echo '<ul class="subNavHead">';
foreach ($page as $subpage) {
$isActive = $subpage->isActive(false);
$liClass = $isActive ? ' class="active"' : '';
echo '<li ' . $liClass . '>' . $this->menu()->htmlify($subpage) . '</li>';
}
echo '</ul>';
}
echo '</li>';
}
echo '</ul>';
And here is my language selector class:
class AW_Controller_Plugin_LangSelector extends Zend_Controller_Plugin_Abstract {
public function preDispatch(Zend_Controller_Request_Abstract $request) {
$lang = $request->getParam('lang', '');
if ($lang !== 'de' && $lang !== 'en' && $lang !== 'pl')
$request->setParam('lang', 'de');
switch ($request->getParam('lang')) {
case 'de':
$locale = 'de';
break;
case 'en':
$locale = 'en';
break;
case 'pl':
$locale = 'pl';
break;
default :
$locale = 'de';
break;
}
$zl = new Zend_Locale();
$zl->setLocale($locale);
Zend_Registry::set('Zend_Locale', $zl);
$translate = Zend_Registry::get('Zend_Translate');
$translate->setLocale($zl);
}
}
When I change the language with a select box the text on my site change the language, but the navigation targets don´t change. The navigationlabels changes too.
When I am in default language :
www.example.de/de/controller/action
And then I switch the language to English
-> the href attributes of my navigation are still on the old value (www.example.de/de/controller/action) but they should have www.example.de/en/controller/action
Where is my problem? Have I forget to re-render the menu?
I believe you are saying that the labels ('Home', 'Contact Us') are changing, but the links ('/', '/contact-us') aren't. The way Zend_Menu uses Zend_Translate only for the menu labels.
If your menu is created by MVC instead of URIs, you can make it take your language values by adding the line
$page->setParam('lang', Zend_Registry::get('Zend_Locale')->getLocale());
This would go in your navigation render, between "foreach ($page as $subpage) {" and "echo".
If your menu is using URIs, you can do a substitution on the page HREF at the same point.
Now, if I've misunderstood your question, and it's not translating links OR labels in the menu, then check and see if your menu is executing before your plugin's preDispatch.

Facebook login with Codeigniter stopped working suddenly

I am using Facebook with Codeigniter and was working fine
but suddenly stopped working, is facebook changed anything
the facebook function
public function takofacebook($page = TRUE, $name = TRUE) {
if (isset($page) and (($page != TRUE) or ($page != 1)) and isset($name)) {
$data['page'] = $page;
$data['name'] = $name;
}
$this -> load -> library('fb');
if (!$this -> fb -> is_connected()) {
redirect($this -> fb -> login_url(current_url()));
}
$fb_user = $this -> fb -> client -> api('/me');
if (empty($fb_user)) {
$error = "FACEBOOK LOGIN FAILED - USER US EMPTY. FILE: " . __FILE__ . " LINE: " . __LINE__;
$this -> session -> set_flashdata('register_error', $error);
} else {
$this -> user -> set_facebook_id($fb_user['id']);
$user = $this -> user -> get_by_facebook();
if (!empty($user) && !empty($user -> id) && is_numeric($user -> id)) {
//TODO: Make things a bit more secure here
//Login & Redirect home
$this -> _login($user -> id, 'facebook');
$this -> load -> view('users/redirect_home2', $data);
return;
}
}
//Go to the registeration page
$this -> load -> view('users/redirect2', array('method' => 'facebook'));
}
/**
* Logs user in with facebook
*/
//tako facebook
public function zangafacebook() {
$this -> load -> library('fb');
if (!$this -> fb -> is_connected()) {
redirect($this -> fb -> login_url(current_url()));
}
$fb_user = $this -> fb -> client -> api('/me');
if (empty($fb_user)) {
$error = "FACEBOOK LOGIN FAILED - USER US EMPTY. FILE: " . __FILE__ . " LINE: " . __LINE__;
$this -> session -> set_flashdata('register_error', $error);
} else {
$this -> user -> set_facebook_id($fb_user['id']);
$user = $this -> user -> get_by_facebook();
if (!empty($user) && !empty($user -> id) && is_numeric($user -> id)) {
//TODO: Make things a bit more secure here
//Login & Redirect home
$this -> _login($user -> id, 'facebook');
$this -> load -> view('users/redirect_home3');
return;
}
}
//Go to the registeration page
$this -> load -> view('users/redirect3', array('method' => 'facebook'));
}
I tested the official php sdk from Facebook that is on my CodeIgniter site and it works fine.
Is $fb_user empty? Where is the error? Are you using the official PHP SDK for Facebook? There are a lot of variables to figure out what is going wrong here.
Like ifaour suggests, use the official php sdk here if you are not already: https://github.com/facebook/facebook-php-sdk/tree/master/src
Drop the files in the library directory and call it normally
$this -> load -> library('facebook');
Then you can get the facebook data like this:
$fb_user = $this -> facebook -> api('/me');
again I am not sure where your error is so are you missing a parameter here?
$user = $this -> user -> get_by_facebook($fb_user['id']);
This is all I am doing on my site and it is working just fine. This also has the benifit that if Facebook does change anything you just need to download the new SDK and your code should remain unchanged.