dokuwiki - bypass core or template function from template - php

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.

Related

Prestashop Quick Address Links to external URL

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

How to know if web page is returned from another website

I have website link http://example.com/link/
How can I handle if it returns from such as: http://facebook.com
I want to check and process event by something like this:
if(return from facebook) {
}
Jquery or PHP is ok.Thank you for your advice.
You could find the referer in PHP using:
$_SERVER['HTTP_REFERER']
if($_SERVER['HTTP_REFERER'] == 'https://facebook.com'){
}
However, you'd probably want to catch anything from facebook;
$sReg = '.facebook.+[a-zA-Z](\/*)';
if(preg_match( $sReg, $_SERVER['HTTP_REFERER'] == 1 ){
}
Note that HTTP_REFERER isn't a sure way of getting the referrer. Often it'll be missing.
See PHP manual for more info
The solution in javascript
if(document.referrer == 'https://facebook.com') {
/* Do somethings */
}
Using Regular Expression:
var myRe = new RegExp('facebook.+[a-zA-Z](\/*)');
if(myRe.test(document.referrer)) {
/* Do somethings */
}

PHP URL Variable Redirect

I have a login page that submits to another page while adding a string to the end of the url. Would look something like this 'http://example.com?klc' I know I can use $_SERVER["QUERY_STRING"] to get the string, but now I need to use it in a function to direct the user to a different page, based on the string. This is what I have written in the target file
<?php
$access = $_SERVER["QUERY_STRING"];
function user_admin_redirect($access){
if ($access = "ppl"){
redirect_to("ppl_admin.html");}
else ($access = "klc"){
redirect_to("klc_admin.html");}
}
}
user_admin_redirect($access);
but for some reason the script dies. Any tips would be welcomed. Also, I have the system setup on my website, contact me if you are willing to help I can give you a test login.
$access = $_SERVER["QUERY_STRING"];
function user_admin_redirect($access){
if ($access == "ppl"){
redirect_to("ppl_admin.html");}
else if($access == "klc"){
redirect_to("klc_admin.html");}
}
}
user_admin_redirect($access);
You need to use == and not = when using if
You need to use else if and not just else
I am assuming redirect_to is some custom function that you have written which will redirect you to the mentioned page. If not, you should use header('Location: ' . $location);
I don't think redirect_to is a built-in PHP function.
You might need to use
header("Location:".$myPhpScript);
or you could define redirect_to, like:
function redirect_to($location){
header("Location:".$location);
}
See more here:
php redirect_to() function undefined
How to make a redirect in PHP?

How to target specific options pages in WordPress

I'm trying to remove screen options from a specific page and I've got something that removes screen options from all pages so I just need to check for "when page == {x}" How do I check what page I'm on in wordpress though?
function remove_screen_options(){
return false;
}
add_filter('screen_options_show_screen', 'remove_screen_options');
Thought it would be as easy as:
function remove_screen_options(){
global $pagename;
if( $pagename == "admin_faucet_settings") {
return false;
}
}
add_filter('screen_options_show_screen', 'remove_screen_options');
But that is not working - seems to fire all the time too which is strange and off...any ideas?
So, if you need to target any particular page of wordpress admin area, such as plugin page then you can use admin enqueue script hook like this:
function my_admin_enqueue($hook_suffix) {
if($hook_suffix == 'faucet_admin_settings') {
// your code that should be executed if we are on the right page.
}
}
add_action('admin_enqueue_scripts', 'my_admin_enqueue');
Reference: https://wordpress.stackexchange.com/questions/7278/how-can-you-check-if-you-are-in-a-particular-page-in-the-wp-admin-section-for-e

PHP How to implement flash messages

I'm working on a small custom CMS and would like to implement flash messages. I have searched for hours, but I can't find anything that behaves the way I want. And I can't seem to make anything work.
I want to be able to pass a variable (via $_SESSION) to another page and, on that next request, it will be removed. I want to be able to use a keep_flash function, in case I don't want the message to be removed with the next server request.
Can anyone send me in the right direction? I can't really make anything work.
Thanks.
EDIT: Here is some code I am playing with. It sort-of works. When you first visit the page, it sets the $_SESSION and everything is fine. But if you refresh, now it deletes the $_SESSION. If you refresh again, it adds it back...etc. So, if you were to visit the page, refresh, then go to another page the flash message wouldn't be in the $_SESSION. So how can I fix this?
class flash
{
private $current = array();
private $keep = array();
public function __construct()
{
if (isset($_SESSION['flash'])) {
foreach($_SESSION['flash'] as $k=>$v)
{
$this->current[$k] = $v;
}
}
}
public function __destruct()
{
foreach ($this->current as $k=>$v)
{
if (array_key_exists($k,$this->keep) && $this->keep[$k] == $v) {
// keep flash
$_SESSION['flash'][$k] = $v;
} else {
// delete flash
unset($_SESSION['flash'][$k]);
unset($this->current[$k]);
unset($this->keep[$k]);
}
}
}
public function setFlash($key,$value)
{
$_SESSION['flash'][$key] = $value;
}
public function keepFlash($key)
{
$this->keep[$key] = $this->getFlash($key);
}
public function getFlash($key)
{
if (array_key_exists($key,$this->current)) return $this->current[$key];
return null;
}
}
basic idea is to have script always check specific variable in session (usually called 'flash') for content - if not empty display and delete it from session. When message is needed just place is same variable in session and next check would pick it up....
keep_flash in your case would not proceed with delete, or move to other place based on your needs.
for implementation just google it - usually it wrapped in some kind of class - I personally like phpclasses.org or part of framework

Categories