This repository has been archived by the owner on Jan 4, 2019. It is now read-only.
forked from lukemorton/publicize
/
publicize.php
90 lines (81 loc) · 1.93 KB
/
publicize.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php defined('SYSPATH') or die('No direct script access.');
/**
* Publicize is a small helper class that provides routing
* functionality that enables modules to include files that are
* publically available via your htdocs, public, html, www,
* %%insert another public folder variation%%.
*
* @package Publicize
* @category Helpers
* @author Luke Morton
* @copyright Luke Morton, 2011
* @license MIT
*/
class Kohana_Publicize {
const PUBLIC_FOLDER = 'public';
/**
* Should we copy to docroot? We should if not in the
* development environment.
*
* @return boolean
*/
public static function should_copy_to_docroot()
{
return Kohana::$environment !== Kohana::DEVELOPMENT;
}
/**
* Should we set route? We should if not in the
* production environment.
*
* @return boolean
*/
public static function should_set_route()
{
return Kohana::$environment !== Kohana::PRODUCTION;
}
/**
* Set route functionality.
*
* @return void
*/
public static function set_route()
{
Route::set('Publicize', array('Publicize', 'route_callback'));
}
/**
* Route callback sends request to [Controller_Publicize].
*
* @param string URI to search for
* @return array Params for Controler_Publicize::action_redirect()
* @return void If no file found
*/
public static function route_callback($uri)
{
if ($asset = Kohana::find_file(self::PUBLIC_FOLDER, $uri, FALSE))
{
return array(
'controller' => 'publicize',
'action' => 'copy',
'asset' => $asset,
'uri' => $uri,
);
}
}
/**
* Copying functionality.
*
* @param string Full path to asset
* @param string The URI
* @return void
*/
public static function copy_to_docroot($asset, $uri)
{
$public_asset = DOCROOT.$uri;
$public_asset_dir = dirname($public_asset);
if ( ! is_dir($public_asset_dir))
{
mkdir($public_asset_dir, 0777, TRUE);
}
copy($asset, $public_asset);
}
}