NOTE: This question has been asked on the kohana forums at: http://forum.kohanaframework.org/comments.php?DiscussionID=6451
Hey everyone!
I am attempting to use HTML Purifier - I have it installed and working correctly. I have two helper functions, clean_all and clean_whitelist.
/config/purifier.php
<?php defined('SYSPATH') or die('No direct access allowed.'); return array( 'settings' => array( 'HTML.Allowed' =>'b,i,p,ul,ol,li' ), ); ?>
Clean_whitelist -
public static function clean_whitelist($dirty_data) { //Whitelist is defined at APPPATH/config/purifier.php return Security::xss_clean($dirty_data); }
This works as intended, as I have setup the htmlpurifier config file with the HTML.Allowed directive configured for my needs.
Clean_all should work similarly, except I want my configuration to set the HTML.Allowed to none.
QUESTION: Is there a way for me to change the configuration file at runtime?
Thanks, all!
I'm the guy who answered you on the message board (Colonel-Rosa).
Straightforward
$config->set($key, $new_value);
OR ...
Pass the config data as an argument or store it as a class member then merge this data with the config file data.
Related
Based on a video with Codeigniter4, I created the Modules folder on the ROOTPATH and the Controllers, Views..etc folders in the Modules folder. It works fine, but when I want to call my view file inside the module
<?php
namespace Modules\Giris\Controllers;
use App\Controllers\BaseController;
class IndexController extends BaseController
{
public function index(){
return view('Modules\Giris\Views\index');
}
}
I need to specify a very long path like How can I make it just like view('index') and call the file from the Views folder in that module if I write it in a module? I don't want to write "Modules\Login\Views" in short is this possible?
Thanks in advance for all the kind replies.
Because view requires a string you couldn't provide a namespaced reference as you might think you should. Furthermore the code adds a .php extension and the "view path" (defined in your config\paths file) as part of its process (see system/View/View.php and render()). Therefore without modifying Codeigniter (which could be done but would affect all your code) the easiest way is to simply declare a public property or constant and make reference to that instead. Also helps if you need to change the path at any point.
I.e. protected $path = 'Modules\Giris\Views\' and then view($this->path.'index'); is probably the easiest way.
I am passing a BASE64 encoded string to a twig template that I would like to have a twig extension de-code.
I installed twig with composer and I'm not using any other frameworks and most of the extension examples I've found seem to assume you are, and I think that that is causing me trouble. I can't seem to get twig to find my extension.
So I think I'm having a name space issue. my setup:
root/
-index.php
-vendor/
-twig/
Given this setup, where should I put the extension file and what name space should be at the top of the file? What is the proper way to load it?
Many thanks in advance!
If your app isn't too complex, you can simply add extension in place where you register and load Twig itself.
// index.php
require_once __DIR__ . '/vendor/autoload.php';
$loader = new Twig_Loader_Filesystem('/path/to/templates');
$twig = new Twig_Environment($loader, array(
'cache' => '/path/to/compilation_cache',
));
// an anonymous function:
$base64Decode = new Twig_Filter('base64_decode', function ($string) {
return base64_decode($string);
});
// or a simple PHP function:
$base64Decode = new Twig_Filter('base64_decode', 'base64_decode');
// add the function to your Twig environment:
$twig->addFilter($base64Decode);
I assumed this would be easy but I am stumped.
I have a custom content type that includes an id field. I render these with a basic page template.
I have written a small module that creates a block which is populated with data from an external API. Everything works except I cannot seem to figure out how to pass the value of the id from the content of a given page to my module so it can make the API call.
It would be a couple of lines of code in straight php, it can't be that complicated in Drupal 8 and twig can it?
I managed to find a solution here
I am re-posting it in case it is useful to anyone else.
If you are generating a custom block you can access content fields via the routing system inside your block build function like this:
public function build() {
if ($node = \Drupal::routeMatch()->getParameter('node')) {
$field_my_custom_value = $node->field_my_custom_value->value;
}
//do something with the variable, like make the API call
//Make sure to set the cache to the context or even to zero if you need
return array(
'#markup' => $this->t('my content to render'),
'#cache' => array(
'contexts' => ['contexts' => ['route']],
),
);
}
I think you can reach what you want with a HOOK_preprocess.
use:
YOUR_MODULE_preprocess_node(&$variables){ ... } or
YOUR_MODULE_preprocess_block(&$variables){ ... }
to access your variable from the content type and pass it to your function oder template.
I am working on project whose build logic is defined in gradle and has a build.gradle file for it. Now, we would like to manage property of the project using groovy's config Sluper. And, I have placed config.groovy file in folder that contains all the Helper class for the project. The content of the conf.groovy file is below:
categories {
includeCategories = defaultIncludeCategories()
excludeCategories = defaultExcludeCategories()
}
String defaultIncludeCategories() {
def include = 'default'
if( isAbcJob() ) {
include = 'tier0'
}
logger.info "defaultIncludeCategories: $include"
include
}
Now, as you can see there is a method name isAbcJob() that I need to use in the configuration file but this method is present in build.gradle, which is the file that call conf.groovy file for property management.
Bottom line is how would conf.groovy script would know where isAbcJob() method is?
Please advice.
I found the following question that has been asked on Gradle forums very helpful. And, it looks like that accessing other gradle script's methods is not possible unless you access them through tasks:
https://discuss.gradle.org/t/multiple-apply-froms-dont-seem-to-import-all-methods/2274/6
I have a website on cakephp 1.3, with facebook integration. On my localhost(with windows os) it works fine, but on real hosting(with linux os) it gives this error Fatal error: Class 'Facebook' not found in /home/username/public_html/app/plugins/facebook/libs/f_b.php on line 22.
This is f_b.php
App::import('Vendor', 'Facebook.facebook/src/facebook');
App::import('Lib', 'Facebook.FacebookInfo');
class FB {
/**
* Facebook Api
*/
public static $Facebook = null;
public function __construct() {
if (empty(self::$Facebook)) {
self::$Facebook = new Facebook(FacebookInfo::getConfig()); } // 22 line
}
so, apparently it can not load Vender, I think there is a problem with paths, though this does not work either App::import('Vendor', 'Facebook.facebook'.DS.'src'.DS.'facebook');
f_b.php located in plugins/facebook/libs/ folder and this Facebook.php vendor is located in plugins/facebook/vendors/facebook/src folder
Thanks
Finally I found the solution of my problem, in order to work both on windows and linux it is necessary write like this
App::import('Vendor', 'Facebook.Facebook', array('file' => 'facebook/src/Facebook.php' ));
Here, are couple of example for that - Vendor examples
I’d say your paths don’t look right (why is there a dot?).
When I’ve used plugins with CakePHP, I’ve had to enable them by un-commenting the Plugins::loadAll() line in app/config/bootstrap.php. This will then make my library available in my CakePHP application.