DokuWiki Plugin - Read/Write configuration from conf/metadata.php - php

I am trying to read/write my configuration in the DokuWiki.
The problem that occurs is when I am trying to call $this->getConf('url'); I always get the response from the conf/default.php file.
This is how my files look like:
admin.php
$url = $this->getConf('url');
conf/default.php
$conf['url'] = 'https://www.example.com';
conf/metadata.php
$meta['url'] = array('string', 'url' => 'https://correct-url.com');
And the value of $url always is:
https://www.example.com
I am not sure what I do wrong.
Thanks!

You may have some misunderstanding to DokuWiki's config system.
The config, which is editable by users, will be saved at /conf/local.php (not inside plugins!). The plugin can only provide a default value at default.php, while the metadata.php is to define how the value is shown on the frontend settings manager.
In your case, the correct URL will be shown, if the DokuWiki global config file (/conf/local.php for example) includes $conf["your_plugin_name"]["url"] = "https://correct-url.com";.
For more: https://www.dokuwiki.org/devel:configuration

Related

Moodle plugin : check if admin + add link to plugin in administration

I'm new to moodle plugin development and am trying to create a plugin that displays a page to the admin where I can add my on php code.
In brief, what I want the plugin to do I have already achieved in a standard php file that I upload to the moodle root. From here you can call the file e.g. yourdomain.co.uk/moodlelocation/myfile.php and it will run as expected.
The problem with this is it isn't secure since anyone can load the myfile.php and in turn run the scripts on the page. It also means any one else using this script (it will be given away for free when complete) would need to FTP into their hosting and upload two php files to their moodle install.
Due to this, I thought a plugin (a very very basic plugin) may be the best solution. They could then load the page in the admin via the "site administration". e.g. site administration > Development > MyPlugin. I am assuming I could then also restrict the plugin's main page to admins only (??).
So to recap, I can create a php page that has my script all rocking and rolling BUT I need to make this into a plugin.
I did some reading and I think a "local" plugin was the easiest way to go (??).
I have managed to get the local plugin up and running using the below in local/webguides/inex.php :
<?php
// Standard config file and local library.
require_once(__DIR__ . '/../../config.php');
// Setting up the page.
$PAGE->set_context(context_system::instance());
$PAGE->set_pagelayout('standard');
$PAGE->set_title("webguides");
$PAGE->set_heading("webguides");
$PAGE->set_url(new moodle_url('/local/webguides/index.php'));
// Ouput the page header.
echo $OUTPUT->header();
echo 'MY php CODE here etc';
?>
This works fine but with two problems:
Anyone can access it via http://domain/local/webguides/index.php
There is no link to it in the site administration (so the user would need to type the URL in).
Can anyone shed any light how I would achieve the two steps above?
Thanks in advance
p.s. ideally I'd like to keep the plugin to as few files as possible so if the required code could be added to the local/webguides/index.php file it would be preferred.
You need to create a capability, then require that capability before displaying the page.
First, have a look at local/readme.txt - this gives an overview of the files needed for a local plugin.
Or read the documentation at https://docs.moodle.org/dev/Local_plugins
Also have a look at existing local plugins so you can see how they are created - https://moodle.org/plugins/?q=type:local
At a bare minimum, you need
local/webguides/db/access.php - this will have the capability
local/webguides/lang/en/local_webguides.php
local/webguides/version.php
Plus your index file
local/webguides/index.php
In the db/access.php file have something like
defined('MOODLE_INTERNAL') || die();
$capabilities = array(
'local/webguides:view' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
),
),
);
You might also need 'riskbitmask' => RISK_XXX depending on if there are any risks in you code. Such as RISK_CONFIG, RISK_PERSONAL, etc.
In lang/en/local_webguides.php have something like
defined('MOODLE_INTERNAL') || die();
$string['pluginname'] = 'Webguides';
$string['webguides:view'] = 'Able to view webguids';
In version.php have something like
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2020051901; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2015051109; // Requires this Moodle version.
$plugin->component = 'local_webguides'; // Full name of the plugin (used for diagnostics).
Replace 2015051109 with the version of Moodle you are using - this will be in version.php in the root folder.
Then in your index.php file use this near the top.
require_capability('local/webguides:view', context_system::instance());
So only users with that capability will have access to the page.
EDIT:
You can add a link via settings.php using something like
defined('MOODLE_INTERNAL') || die;
if ($hassiteconfig) {
$page = new admin_externalpage(
'local_webguides',
get_string('pluginname', 'local_webguides'),
new moodle_url('/local/webguides/index.php'),
'local/webguides:view'
);
$ADMIN->add('localplugins', $page);
}
Then in your index page ad this
require_once($CFG->libdir.'/adminlib.php');
and remove require_login() and require_capability() and replace with
admin_externalpage_setup('local_webguides');

set config params from database in yii 1

I have created CRUD for global configuration parameters. I want to apply this parameters value as main config params (main.php).
I have found some way like add value of these parameters to any .inc file and perform read/write operation. Can anybody help me how can I achieve this? I am beginner in yii.
I have created table structure :
global_config :
Field | Value
pageSize | 20
admin_email| admin#example.com
main.php file as below :
.
.
{
'params' = array(
'pageSize' => 10,
'admin_email' => 'admin#example.com',
);
}
.
.
I am using config file as show above, I want to change it dynamically that it should get value from database.
So that I can make changes in config file from front-end side. I don't need to perform open/write action on main.php
In yii1 you can use params you can set this in main.php
'params'=>array(
'your_param'=>'your_value ',
...
Yii::app()->params['your_param'];
and you can set this value like a simple array poplulating the value form database
$param['yuor_param' =>$your_db_value];
You can't do this for params. As Application parameters are not really meant to be altered and if you change a value, it does not persist across different requests.
These are treated as constant in Yii, So you can't define them after running the script as config files runs at first as your code runs.
Finally, I found solution as per my requirement. I followed given below link from yii forum.
Link : http://www.yiiframework.com/wiki/304/setting-application-parameters-dynamically-in-the-back-end/
Thanks.

The best approcach for Multi-Site Codeigniter projects?

Thanks for taking the time to read this.
Here's what I want:
I will have a main server, it will hold the client's package info, the themes they've ordered and a_ds they have attached from my marketplace.
I don't want their site to be a sub-domain, rather their own domain and it will be hosted by me in a shared environment.
Now, I want to set up my CI project in such a way, that these will happen. Each individual client will be given their own project space and database but I want their particular projects to derive their settings from my database/CI functions.
I know I wrote terribly, but even Google failed me on this. You guys are my last hope.
Thanks in advance!!
Do you intend to run these multitude of sites from one CodeIgniter source in your server, with application configurations varying depending on which domain is accessed?
If that is the case, then here is an option available for you off the top of my head:
Organize the varying configurations in application/config like this:
application/
config/
domains/
foo.com/
database.php
config.php
bar.net/
database.php
config.php
baz.org/
database.php
config.php
Each of these application/config/domains/*/(database|config).php files contain the configurations specific only for that particular domains (You have to generate these somehow).
Example:
//In database.php files
return array(
'username' => 'client1',
'password' => 'password!',
'database' => 'client1_db'
);
//In config.php files
return array(
'base_url' => 'http://baz.org'
);
Then its just a matter of including the right file depending on the domain used in the request:
In your application/config/database.php:
$client_vars = include __DIR__ . '/domains/' . $_SERVER['HTTP_HOST'] . '/database.php';
/* validate $client_vars to ensure that client is not overriding anything important. Throw an error to inform client. */
$db['default'] = array_replace($db['default'], $client_vars);
/* Rest of DB settings. */
In your application/config/config.php:
$client_vars = include __DIR__ . '/domains/' . $_SERVER['HTTP_HOST'] .'/database.php';
/* validate $client_vars to ensure that client is not overriding anything important. Throw an error to inform client */
$config = array_replace($config, $client_vars);
/* Rest of config settings */
This is a rough idea of a possible solution, though this is not very secure at all. Just two cents.

Is there a way we can build YII multisite application with one database for multiple domains

We are planned to host a single CMS for the multiple sites.
Is there are way in YII we can do that, The idea is simple we want to share single application and single database for all the domains but we will let them choose the different themes for the different website.
By website I mean totally different Domains.
What other setting will we have to do to point all the domains to single server ?
Edit::
I don't want the different serve directory for each domain. what I want to do it, keep the installation only one.
i.e.
/server/www/master
then all the domains
a.com, b.com, c.com read the same dir "/server/www/master" and same DB. and records get filer on the base of site.
I have done exactly that with Yii so yes it is possible.
In your Apache settings make sure to point all the domain names to the same directory (using ServerAlias - http://httpd.apache.org/docs/2.2/mod/core.html#serveralias).
In my database I created a table with a row for each website, storing the domain name as one of the fields.
In my ApplicationConfigBehavior.php::beginRequest (which is executed for every request), I did something like this:
/**
* Load configuration that cannot be put in config/main
*/
public function beginRequest()
{
if(empty(Yii::app()->session['community'])){
$current_community = Community::model()->with(array(
'communityHosts'=>array(
'joinType'=>'INNER JOIN',
'condition'=>'`communityHosts`.hostname= :hostname',
'params' => array(':hostname' => $_SERVER['SERVER_NAME'])
),
))->find();
Yii::app()->session['community'] = serialize($current_community);
}
else{
$current_community = unserialize(Yii::app()->session['community']);
}
if(!empty($current_community)){
Yii::app()->name = $current_community->name;
Yii::app()->params['currentCommunity'] = $current_community;
Yii::app()->language = $current_community->language;
}
else{
//TODO: Throw error
session_unset();
die('Hostname ' . $_SERVER['SERVER_NAME'] .' not found');
}
}
Which basically says, looks for this server name in my database, get the current "community" (my sites), and store all the settings (theme, site name, etc...) in the session.
The exact query might not be the same for you. It's just to give you the general idea. Adapt it to your database schema or however you store the settings for each website.
In the apache virtual host file, set the site name
SetEnv SITE_NAME "CMSA"
Get site name in the code using
defined('SITE_NAME') || define('SITE_NAME', ( getenv('SITE_NAME') );
Use the constant in the config and filter your records based on the site.
The same way theme can also be declared.

Magento 404 on Admin Page

About a week ago, I was working in a test environment for a new site. I left for an hour, came back, and now cannot get to the admin page, as in ‘http://magento.localhost.com/admin’ results in a No Route 404. I am the only one with access to this, it is not live in any sense. I am using VBox with Ubuntu to host the environment. In terms of possible fixes, so far I have tried…
Making sure core_store, core_store_group, core_website, and customer_group table ids are set to 0 (as described in this and many other articles - http://www.nude-webdesign.com/fix-for-magento-admin-error-404-page-not-found/)
Playing with the /app/code/core/Mage/Core/Controller/Varien/Front.php method _isAdminFrontNameMatched to display the adminPath (it’s ‘admin’)
Cleared the var folder, emptied browser cache. Site’s caching was and is turned off.
Adding 'index.php' to the url still results in a 404.
As per Magento Admin 404, the file 'app/etc/use_cache.ser' doesn't exist for me.
On the day of this occurring, I was simply playing around with some layout files I had copied to a module I made and the theme’s media queries (all of which were reverted to their original state even before this problem started to occur).
Does anyone have any suggestions as to what is wrong here? Any other possible reasons this could be happening?
Thanks for anything.
EDIT 1:06pm 9/10/2013: In response to Alan Storm's method of retrieving controller names that Standard.php is looking for, I was returned many "missing" controller files. However, after downloading a fresh copy of 1.7.0.2 to find those files, they weren't present in their either. Here is my output from Alan's var_dump suggestion in Standard.php:
..."/public_html/app/code/core/Mage/Index/controllers/Adminhtml/Controller.php"
..."/public_html/app/code/core/Mage/Paygate/controllers/Adminhtml/Controller.php"
..."/public_html/app/code/core/Mage/Paypal/controllers/Adminhtml/Controller.php"
..."/public_html/app/code/core/Mage/Widget/controllers/Adminhtml/Controller.php"
..."/public_html/app/code/core/Mage/Oauth/controllers/Adminhtml/Controller.php"
..."/public_html/app/code/core/Mage/Authorizenet/controllers/Adminhtml/Controller.php"
..."/public_html/app/code/core/Mage/Bundle/controllers/Adminhtml/Controller.php"
..."/public_html/app/code/core/Mage/Centinel/controllers/Adminhtml/Controller.php"
..."/public_html/app/code/core/Mage/Compiler/controllers/Adminhtml/Controller.php"
..."/public_html/app/code/core/Mage/Connect/controllers/Adminhtml/Controller.php"
..."/public_html/app/code/core/Mage/Downloadable/controllers/Adminhtml/Controller.php"
..."/public_html/app/code/core/Mage/ImportExport/controllers/Adminhtml/Controller.php"
..."/public_html/app/code/core/Mage/Api2/controllers/Adminhtml/Controller.php"
..."/public_html/app/code/core/Mage/PageCache/controllers/Adminhtml/Controller.php"
..."/public_html/app/code/core/Mage/XmlConnect/controllers/Adminhtml/Controller.php"
..."/public_html/app/code/core/Mage/Adminhtml/controllers/Controller.php"
..."/public_html/app/code/community/Phoenix/Moneybookers/controllers/Controller.php"
..."/public_html/app/code/core/Mage/Captcha/controllers/Adminhtml/Controller.php"
..."/public_html/app/code/core/Mage/CurrencySymbol/controllers/Adminhtml/Controller.php"
..."/public_html/app/code/core/Mage/CurrencySymbol/controllers/Adminhtml/IndexController.php"
Resolved 3:39pm 9/10/2013: Ok, it's fixed albeit rather bluntly. I took the output of Alan Storm's var_dump suggestion to mean I had created an error somewhere in the core code pool (which is not something I intended on doing, screwing with the default code that is). Unfortunately for sake of exact learning, I then replaced it all with the default core code pool of 1.7.0.2. This was done before Alan updated his original answer with more suggestions that I never investigated. Thanks Alan, you're rad.
A no route 404 error usually indicates Magento can't find the controller file it thinks it should load (usually due to a misconfiguration)
The easiest way to diagnose this is to hop to _validateControllerClassName
#File: app/code/core/Mage/Core/Controller/Varien/Router/Standard.php
protected function _validateControllerClassName($realModule, $controller)
{
$controllerFileName = $this->getControllerFileName($realModule, $controller);
if (!$this->validateControllerFileName($controllerFileName)) {
return false;
}
$controllerClassName = $this->getControllerClassName($realModule, $controller);
if (!$controllerClassName) {
return false;
}
// include controller file if needed
if (!$this->_includeControllerClass($controllerFileName, $controllerClassName)) {
return false;
}
return $controllerClassName;
}
and drop some logging or var_dumps around the return false statments. This should tell you which files Magento is looking for and can't find — it's usually enough to point to the problem.
if (!$this->validateControllerFileName($controllerFileName)) {
var_dump($controllerFileName);
return false;
}
$controllerClassName = $this->getControllerClassName($realModule, $controller);
if (!$controllerClassName) {
var_dump($controllerClassName);
return false;
}
// include controller file if needed
if (!$this->_includeControllerClass($controllerFileName, $controllerClassName)) {
var_dump("Couldn't include: $controllerFileName");
return false;
}
Update: It's normal for Magento look for the controller file in multiple places — every module that registered as containing adminhtml controller files needs to be checked.
However, almost all the controller files being looked for are named /Controller.php. For the default /admin index page this should be IndexController.php. This makes me think your system thinks it's supposed to look for a controller with a blank name, (likely the default controller value since /admin (and not admin/index) is the URL you're using)
There's myriad reasons this could happen — many revolving around a core file being changed or a configuration node in a module set to the wrong value. If the solutions below don't work for you you'll need to try diff-ing your code base vs. a clean one, disabling every custom module and if that fixing things turn modules back on until the problem module is found, or dive deep into debugging Magento routing code to figure out why your system is unhappy.
One common cause for this behavior is an invalid value (or no value at all) being set for a custom admin path at
System -> Configuration -> Admin -> Admin Base URL -> Use Custom Admin Path
If the value for "custom admin path" is blank, or contains and additional /, this could be interfering with the routing.
Since you can't access the admin, try running the following SQL query
select * from core_config_data where path like '%custom_path%';
...
292 default 0 admin/url/use_custom_path 1
293 default 0 admin/url/custom_path admin/
If you see results similar to the above, or admin/url/custom_path is blank/not-present but admin/url/use_custom_path is still 1 — then that's your problem.
Try deleting these configuration values (admin/url/use_custom_path) and (admin/url/use_custom_path) from core_config_data.
If that doesn't apply to your system, per my blank controller theroy my best guess would be for some unknown reason the code at
#File: app/code/core/Mage/Core/Controller/Varien/Router/Admin.php
public function fetchDefault()
{
// set defaults
$d = explode('/', $this->_getDefaultPath());
$this->getFront()->setDefault(array(
'module' => !empty($d[0]) ? $d[0] : '',
'controller' => !empty($d[1]) ? $d[1] : 'index',
'action' => !empty($d[2]) ? $d[2] : 'index'
));
}
is populating the controller key with a blank value.
In my case, my admin was giving me 404 because there's no store set.
I solved it by running the following query
SET SQL_SAFE_UPDATES=0;
SET FOREIGN_KEY_CHECKS=0;
UPDATE `core_store` SET store_id = 0 WHERE code='admin';
UPDATE `core_store_group` SET group_id = 0 WHERE name='Default';
UPDATE `core_website` SET website_id = 0 WHERE code='admin';
UPDATE `customer_group` SET customer_group_id = 0 WHERE customer_group_code='NOT LOGGED IN';
SET FOREIGN_KEY_CHECKS=1;
SET SQL_SAFE_UPDATES=1;
You can check if you get the below error logged in var/log/system.log
ERR (3): Recoverable Error: Argument 1 passed to Mage_Core_Model_Store::setWebsite() must be an instance of Mage_Core_Model_Website, null given, called in /.../app/code/core/Mage/Core/Model/App.php on line 634 and defined in /.../app/code/core/Mage/Core/Model/Store.php on line 395
Before anything check your configuration file ( app/etc/local.xml) and make sure that you have "admin" as value for the frontName tag.
ex.:
<adminhtml>
<args>
<frontName><![CDATA[admin]]></frontName>
</args>
</adminhtml>
Usually when you try http://yoursite.com/admin it gives you the admin area
Try using an url like that http://yoursite.com/index.php/admin
and if it works probably you need to only modify the rewrite rules or follow the suggestions (see the link below)
I got this problem on a shop with custom admin url www.shop.com/customadminroute/ and System -> Configuration -> Web -> URL options -> Add Store Code to Urls: Enabled
In this case the following module should fix it:
https://github.com/romfr/404adminlogin
Thanks to Blog post of Carmen Bremen:
http://neoshops.de/2012/09/07/magento-404-fehlerseite-beim-admin-login/

Categories