-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathModule.php
135 lines (118 loc) · 3.74 KB
/
Module.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
/**
* MIT License
* Copyright (c) 2017 Electronic Student Services @ Appalachian State University
*
* See LICENSE file in root directory for copyright and distribution permissions.
*
* @author Matthew McNaney <[email protected]>
*
*/
namespace stories;
use Canopy\Request;
use Canopy\Response;
use Canopy\Server;
class Module extends \Canopy\Module implements \Canopy\SettingDefaults
{
public function __construct()
{
parent::__construct();
$this->loadDefines();
$this->setTitle('stories');
$this->setProperName('Stories');
spl_autoload_register('\stories\Module::autoloader', true, true);
}
public function getSettingDefaults()
{
// listStoryFormat : 0 - summary, 1 - full
// featureFormat : 0 - dynamic, 1 - horizontal, 2 - portrait
$settings = array(
'commentCode' => '',
'hideDefault' => 0,
'image_max_width' => 1920,
'image_max_height' => 1080,
'listStories' => 1,
'listStoryAmount' => 6,
'listStoryFormat' => 0,
'showComments' => 0,
'showAuthor' => 0,
'featureCutOff' => 2,
'summaryAnchor' => 0,
'twitterDefault' => '');
return $settings;
}
public function getController(Request $request)
{
try {
$controller = new Controller\BaseController($this, $request);
return $controller;
} catch (\Exception $e) {
if (STORIES_FRIENDLY_ERROR) {
\phpws2\Error::log($e);
$controller = new Controller\FriendlyError($this);
return $controller;
} else {
throw $e;
}
}
}
private function friendlyController()
{
$error_controller = new Controller\FriendlyError($this);
return $error_controller;
}
private function loadDefines()
{
$dist = PHPWS_SOURCE_DIR . 'mod/stories/config/defines.dist.php';
$custom = PHPWS_SOURCE_DIR . 'mod/stories/config/defines.php';
if (is_file($custom)) {
require_once $custom;
} else {
require_once $dist;
}
}
public function runTime(Request $request)
{
if (\Current_User::allow('stories')) {
\stories\Factory\StoryMenu::addStoryLink();
\stories\Factory\StoryMenu::listStoryLink();
\stories\Factory\StoryMenu::addShareLink();
\stories\Factory\StoryMenu::featureLink();
}
$this->frontPage($request);
}
private function frontPage(Request $request)
{
if (!empty($request->getModule())) {
return;
}
$featureView = new \stories\View\FeatureView;
$settings = new \phpws2\Settings;
\Layout::add($featureView->show($request), 'stories', 'features', true);
if ($settings->get('stories', 'listStories')) {
$view = new \stories\View\PublishedView;
\Layout::add($view->listing($request), 'stories', 'stories', true);
}
}
public static function autoloader($class_name)
{
static $not_found = array();
if (strpos($class_name, 'stories') !== 0) {
return;
}
if (isset($not_found[$class_name])) {
return;
}
$class_array = explode('\\', $class_name);
array_shift($class_array);
$class_dir = implode('/', $class_array);
$class_path = PHPWS_SOURCE_DIR . 'mod/stories/class/' . $class_dir . '.php';
if (is_file($class_path)) {
require_once $class_path;
return true;
} else {
$not_found[] = $class_name;
return false;
}
}
}