I have a small problem on the prestashop on adding custom url into the quick address.
The current status of prestashop is 1.7.4.2 fresh install.
As stated from the image above, I would like to redirect it to external URL http://www.google.com, after done creating it is shown in the quick address menu as shown below:
But when I clicked it, just redirect to:
http://localhost:8080/prestashop_1.7.4.2/admin067c8ousl/index.php/http://www.google.com
Note I have deleted the token as it provided the same result
In other words the token is self generated and differs everytime
I have saw original documentation for that specific issue in here.
When you see on the very bottom, it shows the exact issue I am facing:
Note that you can create links to other websites, for instance your PayPal account or your webmail. Simply paste the complete URL in the "URL" field, including the http:// prefix.
As I have written correct url, but it still thinks it is a controller.
I have no modified any code yet, is there a way to fix it.
Thank You and Have a nice day.
That was for v1.6, v1.7 doesn't allow external urls by default. I submitted an improvement for this, hope they approve the merge. Meanwhile, if you want to use them you can modify the classes/QuickAccess.php or add to the override (better option) and change the function getQuickAccessesWithToken to the following:
public static function getQuickAccessesWithToken($idLang, $idEmployee)
{
$quickAccess = self::getQuickAccesses($idLang);
if (empty($quickAccess)) {
return false;
}
$baselink = Context::getContext()->link->getBaseLink();
foreach ($quickAccess as $index => $quick) {
if(strpos($quickAccess[$index]['link'], 'http') !== 0 or strpos($quickAccess[$index]['link'], $baselink) === 0){
if ('../' === $quick['link'] && Shop::getContext() == Shop::CONTEXT_SHOP) {
$url = Context::getContext()->shop->getBaseURL();
if (!$url) {
unset($quickAccess[$index]);
continue;
}
$quickAccess[$index]['link'] = $url;
} else{
// first, clean url to have a real quickLink
$quick['link'] = Context::getContext()->link->getQuickLink($quick['link']);
$tokenString = $idEmployee;
preg_match('/controller=(.+)(&.+)?$/', $quick['link'], $admin_tab);
if (isset($admin_tab[1])) {
if (strpos($admin_tab[1], '&')) {
$admin_tab[1] = substr($admin_tab[1], 0, strpos($admin_tab[1], '&'));
}
$quick_access[$index]['target'] = $admin_tab[1];
$tokenString = $admin_tab[1].(int)Tab::getIdFromClassName($admin_tab[1]).$idEmployee;
}
$quickAccess[$index]['link'] = $baselink.basename(_PS_ADMIN_DIR_).'/'.$quick['link'];
if (false === strpos($quickAccess[$index]['link'], 'token')) {
$separator = strpos($quickAccess[$index]['link'], '?') ? '&' : '?';
$quickAccess[$index]['link'] .= $separator.'token='.Tools::getAdminToken($tokenString);
}
}
}
}
return $quickAccess;
}
Override is not a clean solution.
You can use free module to adding jquery to your "admin header hook" and do it by jquery to change URL of new created quickAccess
Related
I would like to bypass core and plugin functions to customize them.
I didn't succeed to do it from template.
I try to add into my tpl_functions.php something like:
if (!function_exists('html_buildlist')) {
function html_buildlist($data,$class,$func,$lifunc='html_li_default',$forcewrapper=false){
// etc.
}
}
My first idea is to check if the page has been visited and then customize the indexmenu plugin.
For example, i make this function to check if a page has been visited:
function wt__pagevisited($id){
if ($id == null) {
global $INFO;
$id = $INFO['id'];
}
// get cookie session info
$crumbs = isset($_SESSION[DOKU_COOKIE]['bc']) ? $_SESSION[DOKU_COOKIE]['bc'] : array();
// check ID into breadcrumb
if( array_key_exists($id,$crumbs) ) {
return true;
}
return false;
}
Any help will be appreciated.
Thank you in advance.
Jean-baptiste
What you're asking has nothing to do with DokuWiki. You want to replace PHP functions. That's not possible without the help of certain PHP extensions. See Is it possible to replace a function in php (such as mail) and make it do something else? for more info.
I'd been working on a module where customer choose at the time of registration for which website he need to register. So far I'd done it working. A quick reference to that. On successful registration the customer is being redirected to customer/account/ in the current website regardless of which website he chosen. But I need him to be redirected to that particular website for which he had registered.
So far I'd tried overriding the Customer/AccountController's _welcomeCustomer():
protected function _welcomeCustomer($customer, $isJustConformed = false) {
$webid = $customer->getWebsiteId();
$successurl = parent::_welcomeCustomer($customer, $isJustConfirmed);
if (Mage::app()->getStore()->getWebsiteId() == $webid) {
return $successurl;
} else {
return Mage::app()->getWebsite($webid)->getDefaultStore()->getBaseUrl() . 'customer/account/index';
}
}
But instead of redirecting the customer to associated website it being redirected to home page of the current website. Any help? How could it be done? or this happening so?
Try adding the store code as a GET parameter to the URL (___store=xyz).
Probably you will also need to add the Session ID to the url (param name: SID).
this auto-login module helped me to achieve what I'm looking for.
Rest of the thing I've done to make it work proper is:
Overridden the Customer/AccountController's _welcomeCustomer()
protected function _welcomeCustomer($customer, $isJustConformed = false) {
$webid = $customer->getWebsiteId();
$encpw = ;//get customer password and encrypt it;
if (Mage::app()->getStore()->getWebsiteId() == $webid) {
return parent::_welcomeCustomer($customer, $isJustConfirmed);
} else {
$redr = Mage::app()->getWebsite($webid)->getDefaultStore()
->getBaseUrl() . 'customer/account/autoLogin/'
. 'user/' . $customer->getEmail() . '/pwd/' . $encpw .
'/';
return $redr;
}
}
One more thing might needed to be changed in _successProcessRegistration() is to replace $this->_redirectSuccess($url); with $this->_redirectUrl($url);
The question seems to be easy but after 3 days of searches I gave up. I thought that I will find it here and it seems to have similar ones but it doesn't work for this stuff.
Currently I have a customer that has a really advanced marketing based on his previos JS/AJAX driven website. All the back link to his website is like
SERVER /#! LINK
I have built a wordpress website and I need so that cross links open pages properly.
But if I get this link
SERVER /#! LINK
I get following URL when Wordpress process it
SERVER /
I have explored that the only way, or at least the only I know is to do it with wordpress but that doesn't seems to be easy.
I have following script that can ADD #! but is need to remove (just found it somewhere)
<?php
$webSiteUrl = get_bloginfo('url')."/";
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {
$pageURL .= "s";
};
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
};
if($webSiteUrl!=$pageURL){
$pageHash = substr($pageURL, strlen($webSiteUrl), strlen($pageURL));
header("location:".$webSiteUrl."#!/".$pageHash."");
exit;
};
?>
Thanks to squeamish ossifrage I am almost there.
I used this script as the one you provided had some issues with condition
if ('' !== window.location.hash && '#!' !== window.location.hash) {
hash = location.hash.match(/^#!(.*)/)[1];
/* ... do something with hash, like redirecting to */
/* another page, or loading page content via AJAX. */
/* If all you want to do is remove everything from */
/* the URL starting with `#!', then try this: */
location.href = location.protocol+'//'+location.host+location.pathname;
}
It seems to work but I get root page.
e.g. I open
myweb.com/#!thisone
and I get
myweb.com/
AND JUST TO SUMMARIZE so somebody can save lots of time - working script is
if ('' !== window.location.hash && '!' !== window.location.hash) {
hash = location.hash.match(/^#!(.*)/)[1];
/* ... do something with hash, like redirecting to */
/* another page, or loading page content via AJAX. */
/* If all you want to do is remove everything from */
/* the URL starting with `#!', then try this: */
location.href = location.protocol+'//'+location.host+location.pathname+'/'+hash;
}
You can't do this in PHP because the the server will never see the fragment part of the URL (i.e., the # symbol and everything that follows it).
You'll have to use client-side Javascript instead. Something like this perhaps:
if /^#!/.test(location.hash) {
hash = location.hash.match(/^#!(.*)/)[1];
/* ... do something with hash, like redirecting to */
/* another page, or loading page content via AJAX. */
/* If all you want to do is remove everything from */
/* the URL starting with `#!', then try this: */
location.href = location.protocol+'//'+location.host+location.pathname;
}
EDIT: If I understand correctly, you want to put the hash value at the end of the redirect URL. That's quite easily done. Just change the penultimate line of the above code to
`location.href = location.protocol+'//'+location.host+location.pathname+'/'+hash;`
The additional '/' may be unnecessary; I'll leave you to figure out the details :-)
Ok, am using traditional php, no frameworks, nothing, I am using simple procedural way, now my question is I was searching for a while but am not getting an answer to my question, I am not using .htaccess files as of now, but I really need to understand how 404 error works? I am having a website, where I show post's related to category, say category=php, so I pass this as a get request
$_GET['category'] == 'php';
Now currently what am doing is something like this :
$pocategory = $_GET['category'];
if($pocategory == 'php' || $pocategory == 'javascript') {
//Then show related posts
} else {
header('Location:404.php');
exit;
}
I mean I just want php and javascript as valid request's value, rest I want to redirect to 404 but am not understanding how to do it so I did this way, what if am having more than 50 categories? I cant list them all in this if condition, Inshort how to detect whether the given get request value is invalid or not..
Any help will be much appreciated.
.htaccess is the way to do this.
ErrorDocument 404 index.php?404
that line will tell apache what file to load. The example above calls the main index.php script.
add something like this to the top of your index.php file:
$error_404 = isset($_GET["404"]) ? true : false;
now you can detect if you have a 404 error request. $error_404 will be true, so why not add a simple function:
function error_404($error_404)
{
if($error_404 == true)
{
// do some error stuff here, like set headers, and some text to tell your visitor
}
}
now just call your function:
error_404($error_404);
best to do that immidiatley after the get handler:
error_404($error_404)
$error_404 = isset($_GET["404"]) ? true : false;
or combine the two into one line:
error_404($error_404 = isset($_GET["404"]) ? true : false);
to address the question, add this to the relevant script:
$pocategorys_ar = array("php","javascript");
if (!in_array($pocategory, $pocategorys_ar))
{
error_404(true);
}
Make sure it has access to the error_404() function.
You could put all categories inside an array like this:
$pocategories = array
(
'php',
'javascript'
);
if (in_array($pocategory, $pages))
{
// ...
}
else
{
header('Location:404.php');
}
Another thing you could do is creating a html/php file for every category and do it like so
if (is_file('sites/' . $popcategory . '.php')
{
include('sites/' . $popcategory . '.php');
}
else
{
header('Location:404.php');
}
I have a function that parses text form posts and if there's a link in the post it'll redirect the link to a page that warns a users about external link before they click it.
function url2link($txt) {
$setUrl = preg_replace("/(http:\/\/|(www\.))(([^\s<]{4,68})[^\s<]*)/", '$2$4', $txt);
return $setUrl;
}
I need to modify this function by adding a check for domain in the link. If the link is from my own domain, just convert it into clickable link like this:
$setUrl = preg_replace("/(http:\/\/|(www\.))(([^\s<]{4,68})[^\s<]*)/", '$2$4', $txt);
but if it is a link to an external domain -- make a link point to a warning page (top example).
I am sort of stuck here because I have no idea how to add this check. There could be multiple links in a post, some may have local, some external links and some a mix.
Try with preg_replace_callback, then you can process the matches to decide whether it's your own domain or some other.
OK, as it turned out preg_replace_callback was exactly what I needed in this case. php.net documentation sucks. I found another article that made it clear what it is and how it works. I modified my function but it doesn't work... What am I missing?
function url2link($txt) {
$checkDomain = preg_replace_callback('/(http:\/\/|(www\.))(([^\s<]{4,68})[^\s<]*)/', 'linkDomain', $txt);
function linkDomain($matches) {
$host = parse_url($matches[0], PHP_URL_HOST);
$host = ltrim($host, 'www.');
if ($host == 'mydomain.com') {
$setUrl = preg_replace("/(http:\/\/|(www\.))(([^\s<]{4,68})[^\s<]*)/", '$2$4', $matches[0]);
} else {
$setUrl = preg_replace("/(http:\/\/|(www\.))(([^\s<]{4,68})[^\s<]*)/", '$2$4', $matches[0]);
}
}
return $setUrl;
}