Bootstrap.php

First of all excuse me for my weak english skill.
Ive read in http://piwik.org/docs/include-piwik-in-your-project/ that i can use PIWIK_USER_PATH and PIWIK_INCLUDE_PATH to change where all piwik files are located. So ive made an test:


/public/[domain root]
/public/index.php
/public/bootstrap.php
/public/plugins/[all plugins]
/public/themes/[all themes]
/lib/piwik/[all piwik files]

Now in bootsrap i set PIWIK_USER_PATH and PIWIK_INCLUDE_PATH to ‘…/lib/piwik/’. When i enter whatever.domain/index.php piwik loads without css i look around in AssetManager and found that assets path is tested using PIWIK_DOCUMENT_ROOT so i tried to override PIWIK_DOCUMENT_ROOT instead (in index.php)
After this all assets loaded and piwik is working.
(important to reproduce this bug you must clear tmp/assets)

The whole problems comes probably from getAbsoluteLocation in AssetManager which uses PIWIK_DOCUMENT_ROOT instead of PIWIK_USER_PATH when used in self::validateCssFile or self::validateJsFile


private static function getAbsoluteLocation ($relativePath)
{
	// served by web server directly, so must be a public path
	return PIWIK_DOCUMENT_ROOT . "/" . $relativePath;
}

shouldn`t it be ?


private static function getAbsoluteLocation ($relativePath)
{
	// served by web server directly, so must be a public path
	return PIWIK_USER_PATH . "/" . $relativePath;
}

Am i doing something wrong or should i create new bug ticket?

By the way shouldnt there be some distinction between plugin frontend and backend for example images css from plugins put into themes or some other place for front end?

Thanks. I’ll look into this tonight.

Re: backend vs frontend. Right now, it is what it is until the Theming plugin is implemented.

You shouldn’t be overriding PIWIK_DOCUMENT_ROOT.

Just keep a copy of “libs” in the public folder as some 3rd party libraries contain static resources (e.g., jquery and jquery-ui).

Also missing from your public folder: “piwik.php” for tracking, and optionally, the “js” folder if you want to use the proxy.

At which point, you can use something like this to remove .php files from the libs and plugins folders:


    find some_path/public/libs . -name '*.php' -exec rm {} \;
    find some_path/public/plugins -name '*.php' -exec rm {} \;

I know i left them in public directory and removed all tpl and php scripts from it. I only changed getAbsoluteLocation to use PIWIK_USER_PATH instead of PIWIK_DOCUMENT_ROOT all seams to work properly.

No, what I’m saying is that this isn’t a bug. You shouldn’t have to change the code to use PIWIK_USER_PATH. I just verified it, setting only PIWIK_USER_PATH and PIWIK_INCLUDE_PATH in my bootstrap.php.

The reason you’re seeing a problem is because you moved the /public/piwik/libs folder into /lib/piwik/libs. This folder is expected to be public because it contains static resources, and that’s where Apache will serve it directly from if disable_merged_assets is set to 1 in the config.

In situation like this below and lets say i dont want to disable merging but keep temporary files and php scripts and other templates outside of public folder?
With my modification its still works but when i revert it to PIWIK_DOCUMENT_ROOT it does not…


frontend:
/public/piwik/[domain]
/public/piwik/index.php
/public/piwik/bootstrap.php
/public/piwik/piwik.php
/public/piwik/piwik.js
/public/piwik/libs/[css, images other downloadable files]
/public/piwik/plugins/[css, images other downloadable files]
/public/piwik/themes/[css, images other downloadable files]
/public/[..other domains/subdomains]
backend:
/app/piwik/config/[config files]
/app/piwik/libs/[all files]
/app/piwik/plugins/[all plugins]
/app/piwik/themes/[all themes]
/app/piwik/tmp/
/app/[..other domain/subdomains specific backends]
libraries:
/vendor/piwik
/vendor/symfony
/vendor/zend
/vendor/...

Its a little bit modificated symfony2 structure (multiple projects in app and public folder and public folder is web folder in standard symfony2).

I setup in bootsrap.php:


PIWIK_USER_PATH = '/app/piwik'
PIWIK_INCLUDE_PATH = '/vendor/piwik'
PIWIK_DOCUMENT_ROOT = '/public/piwik'

Note that it all is an example and i will probably change it. For example i dont like that ‘/piwik/libs/’ lies under ‘/app/’ probably i will put whole piwik into vendor at least until i will need to have multiple configurations for it.

Of topic

Another problem that i found is that you are assuming that both libraries and core piwik classes must always be in subfolders of PIWIK_INCLUDE_PATH but what if libs are under ‘/vendor’ and piwik core under /vendor/piwik/core’ ?
I have seen that a lot of scripts assume that structure and use


require_once PIWIK_INCLUDE_PATH . '/core/...'
require_once PIWIK_INCLUDE_PATH . '/libs/...'

to include other scripts maybe it would be better to have two constants to set directory to PIWIK_LIBS_PATH and to PIWIK_CORE_PATH.

Default they could be set to:


if (!defined('PIWIK_LIBS_PATH')) {
	define('PIWIK_LIBS_PATH', PIWIK_INCLUDE_PATH . '/libs');
}
if (!defined('PIWIK_CORE_PATH')) {
	define('PIWIK_CORE_PATH', PIWIK_INCLUDE_PATH . '/core');
}

It would be a lot easier to move all libs to other directory where maybe some of them already exist.
For example I have seen you use zend and I am also using zend but with such assumption about libs placment i would have to link to ‘/vendor/piwiki/libs/zend/’ instead of ‘/vendor/zend/’ to have only one copy of zend same goes for tcpdf.

I dont expect you change anything, i only wanted to show you how sometimes people may want to use your work.

Thank you for your time, maybe something of this will be useful.

Splitting the include path between core and libs is doable, but for
backward compatibility with community plugins, we can’t do this until 2.0.

In practice, we don’t advise symlinking 3rd party libs that we distribute with Piwik, against libs you already have, because we have local mods that aren’t merged upstream (yet?).

This is my bootstrap.php; it works whether or not I merge assets.


<?php
define('PIWIK_USER_PATH', __DIR__.'/../private-siteA'); // config and tmp
define('PIWIK_INCLUDE_PATH', __DIR__.'/../piwik.shared'); // a copy of everything

Thanks for help know i understand it better:
PIWIK_USER_PATH - config temp
PIWIK_INCLUDE_PATH - whole piwik as backend
PIWIK_DOCUMENT_ROOT - place where all down loadable assets are placed (in sub folders libs, plugins, themes)

In the begging ive missed libs as folder with down loadable content now i cleared it out of php scripts and it works.

Did i miss anything?

Can anyone please help? I followed the instructions on Include & Customize Piwik for your Project - Analytics Platform - Matomo and changed PIWIK_USER_PATH and PIWIK_INCLUDE_PATH to directories outside of the www-folder in order to increase security. Unfortunately I dont know from the docs exactly, which folders to place where.

Is it:

private directory (outside www)
/temp
/config
/core

rest inside www-folder?

Thanks for any help!

I’m answering from my phone, so I have to be terse. Sorry.

The simplest thing is to copy everything outside. Then within the public folder, remove all the .php files, with the exception of bootstrap.php, index.php, piwik.php, and js/index.php.

If you’re using cron archiving, you’d obviously reference the script located outside the public folder.