Skip to content

Commit 9aff950

Browse files
author
kevin
committed
Initial revision
0 parents  commit 9aff950

File tree

282 files changed

+45367
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

282 files changed

+45367
-0
lines changed

.cvsignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
config.inc.php
2+
build
3+
temp
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php
2+
3+
/**
4+
* JournalSiteSettingsForm.inc.php
5+
*
6+
* Copyright (c) 2003-2004 The Public Knowledge Project
7+
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
8+
*
9+
* @package admin.form
10+
*
11+
* Form for site administrator to edit basic journal settings.
12+
*
13+
* $Id$
14+
*/
15+
16+
class JournalSiteSettingsForm extends Form {
17+
18+
/** The ID of the journal being edited */
19+
var $journalId;
20+
21+
/**
22+
* Constructor.
23+
* @param $journalId omit for a new journal
24+
*/
25+
function JournalSiteSettingsForm($journalId = null) {
26+
parent::Form('admin/journalSettings.tpl');
27+
28+
$this->journalId = $journalId;
29+
30+
// Validation checks for this form
31+
$this->addCheck(new FormValidator(&$this, 'title', 'required', 'admin.journals.form.titleRequired'));
32+
$this->addCheck(new FormValidator(&$this, 'path', 'required', 'admin.journals.form.pathRequired'));
33+
$this->addCheck(new FormValidatorAlphaNum(&$this, 'path', 'required', 'admin.journals.form.pathAlphaNumeric'));
34+
$this->addCheck(new FormValidatorCustom(&$this, 'path', 'required', 'admin.journals.form.pathExists', array(DAORegistry::getDAO('JournalDAO'), 'journalExistsByPath'), true));
35+
}
36+
37+
/**
38+
* Display the form.
39+
*/
40+
function display() {
41+
$templateMgr = &TemplateManager::getManager();
42+
$templateMgr->assign('journalId', $this->journalId);
43+
44+
parent::display();
45+
}
46+
47+
/**
48+
* Initialize form data from current settings.
49+
*/
50+
function initData() {
51+
if (isset($this->journalId)) {
52+
$journalDao = &DAORegistry::getDAO('JournalDAO');
53+
$journal = &$journalDao->getJournal($this->journalId);
54+
55+
if ($journal != null) {
56+
$this->_data = array(
57+
'title' => $journal->getTitle(),
58+
'path' => $journal->getPath()
59+
);
60+
}
61+
}
62+
}
63+
64+
/**
65+
* Assign form data to user-submitted data.
66+
*/
67+
function readInputData() {
68+
$this->_data = array(
69+
'title' => Request::getUserVar('title'),
70+
'path' => Request::getUserVar('path')
71+
);
72+
}
73+
74+
/**
75+
* Save journal settings.
76+
*/
77+
function execute() {
78+
$journalDao = &DAORegistry::getDAO('JournalDAO');
79+
80+
if (isset($this->journalId)) {
81+
$journal = &$journalDao->getJournal($this->journalId);
82+
}
83+
84+
if (!isset($journal)) {
85+
$journal = &new Journal();
86+
}
87+
88+
$journal->setTitle($this->getData('title'));
89+
$journal->setPath($this->getData('path'));
90+
91+
if ($journal->getJournalId() != null) {
92+
$journalDao->updateJournal($journal);
93+
94+
} else {
95+
$journalDao->insertJournal($journal);
96+
$journalId = $journalDao->getInsertJournalId();
97+
$journalDao->resequenceJournals();
98+
99+
// Make the site administrator the journal manager of newly created journals
100+
$sessionManager = &SessionManager::getManager();
101+
$userSession = &$sessionManager->getUserSession();
102+
if ($userSession->getUserId() != null && $userSession->getUserId() != 0 && !empty($journalId)) {
103+
$role = &new Role();
104+
$role->setJournalId($journalId);
105+
$role->setUserId($userSession->getUserId());
106+
$role->setRoleId(ROLE_ID_JOURNAL_MANAGER);
107+
108+
$roleDao = DAORegistry::getDAO('RoleDAO');
109+
$roleDao->insertRole($role);
110+
}
111+
}
112+
}
113+
114+
}
115+
116+
?>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
/**
4+
* SiteSettingsForm.inc.php
5+
*
6+
* Copyright (c) 2003-2004 The Public Knowledge Project
7+
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
8+
*
9+
* @package admin.form
10+
*
11+
* Form to edit site settings.
12+
*
13+
* $Id$
14+
*/
15+
16+
class SiteSettingsForm extends Form {
17+
18+
/**
19+
* Constructor.
20+
*/
21+
function SiteSettingsForm() {
22+
parent::Form('admin/settings.tpl');
23+
24+
// Validation checks for this form
25+
$this->addCheck(new FormValidator(&$this, 'title', 'required', 'admin.settings.form.titleRequired'));
26+
}
27+
28+
/**
29+
* Display the form.
30+
*/
31+
function display() {
32+
parent::display();
33+
}
34+
35+
/**
36+
* Initialize form data from current settings.
37+
*/
38+
function initData() {
39+
$siteDao = &DAORegistry::getDAO('SiteDAO');
40+
$site = &$siteDao->getSite();
41+
42+
$this->_data = array(
43+
'title' => $site->getTitle(),
44+
'intro' => $site->getIntro()
45+
);
46+
}
47+
48+
/**
49+
* Assign form data to user-submitted data.
50+
*/
51+
function readInputData() {
52+
$this->_data = array(
53+
'title' => Request::getUserVar('title'),
54+
'intro' => Request::getUserVar('intro')
55+
);
56+
}
57+
58+
/**
59+
* Save site settings.
60+
*/
61+
function execute() {
62+
$siteDao = &DAORegistry::getDAO('SiteDAO');
63+
$site = &$siteDao->getSite();
64+
65+
$site->setTitle($this->getData('title'));
66+
$site->setIntro($this->getData('intro'));
67+
68+
$siteDao->updateSite($site);
69+
}
70+
71+
}
72+
73+
?>

classes/config/Config.inc.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
/**
4+
* Config.inc.php
5+
*
6+
* Copyright (c) 2003-2004 The Public Knowledge Project
7+
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
8+
*
9+
* @package config
10+
*
11+
* Config class for accessing configuration parameters.
12+
*
13+
* $Id$
14+
*/
15+
16+
/** The path to the configuration file */
17+
define('CONFIG_FILE', Core::getBaseDir() . '/' . 'config.inc.php');
18+
19+
class Config {
20+
21+
/**
22+
* Retrieve a specified configuration variable.
23+
* @param $section string
24+
* @param $key string
25+
* @return string
26+
*/
27+
function getVar($section, $key) {
28+
static $configData;
29+
30+
if (!isset($configData)) {
31+
// Load configuration data only once per request
32+
$configData = Config::reloadData();
33+
}
34+
35+
return isset($configData[$section][$key]) ? $configData[$section][$key] : null;
36+
}
37+
38+
/**
39+
* Load configuration data from a file.
40+
* The file is assumed to be formatted in php.ini style.
41+
* @return array the configuration data (see http://php.net/parse_ini_file for the array format)
42+
*/
43+
function &reloadData() {
44+
if (!file_exists(CONFIG_FILE)) {
45+
die(sprintf('Cannot read configuration file %s', CONFIG_FILE));
46+
}
47+
48+
return parse_ini_file(CONFIG_FILE, true);
49+
}
50+
51+
/**
52+
* Return the path to the configuration file.
53+
* @return string
54+
*/
55+
function getConfigFileName() {
56+
return CONFIG_FILE;
57+
}
58+
59+
}
60+
?>

classes/config/ConfigParser.inc.php

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php
2+
3+
/**
4+
* ConfigParser.inc.php
5+
*
6+
* Copyright (c) 2003-2004 The Public Knowledge Project
7+
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
8+
*
9+
* @package config
10+
*
11+
* Class for parsing and modifying php.ini style configuration files.
12+
*
13+
* $Id$
14+
*/
15+
16+
class ConfigParser {
17+
18+
/** Contents of the config file currently being parsed */
19+
var $content;
20+
21+
/**
22+
* Constructor.
23+
*/
24+
function ConfigParser() {
25+
}
26+
27+
/**
28+
* Read a configuration file and update variables.
29+
* This method stores the updated configuration but does not write it out.
30+
* Use writeConfig() or getFileContents() afterwards to do something with the new config.
31+
* @param $file string full path to the config file
32+
* @param $params array an associative array of configuration parameters to update. If the value is an associative array (of variable name/value pairs) instead of a scalar, the key is treated as a section instead of a variable. Parameters not in $params remain unchanged
33+
* @return boolean true if file could be read, false otherwise
34+
*/
35+
function updateConfig($file, $params) {
36+
if (!file_exists($file) || !is_readable($file)) {
37+
return false;
38+
}
39+
40+
$this->content = '';
41+
$lines = file($file);
42+
43+
// Parse each line of the configuration file
44+
for ($i=0, $count=count($lines); $i < $count; $i++) {
45+
$line = $lines[$i];
46+
47+
if (preg_match('/^;/', $line) || preg_match('/^\s*$/', $line)) {
48+
// Comment or empty line
49+
$this->content .= $line;
50+
51+
} else if (preg_match('/^\s*\[(\w+)\]/', $line, $matches)) {
52+
// Start of new section
53+
$currentSection = $matches[1];
54+
$this->content .= $line;
55+
56+
} else if (preg_match('/^\s*(\w+)\s*=/', $line, $matches)) {
57+
// Variable definition
58+
$key = $matches[1];
59+
60+
if (!isset($currentSection) && array_key_exists($key, $params) && !is_array($params[$key])) {
61+
// Variable not in a section
62+
$value = $params[$key];
63+
64+
} else if (isset($params[$currentSection]) && is_array($params[$currentSection]) && array_key_exists($key, $params[$currentSection])) {
65+
// Variable in a section
66+
$value = $params[$currentSection][$key];
67+
68+
} else {
69+
// Variable not to be changed, do not modify line
70+
$this->content .= $line;
71+
continue;
72+
}
73+
74+
$this->content .= "$key = $value\n";
75+
76+
} else {
77+
$this->content .= $line;
78+
}
79+
}
80+
81+
return true;
82+
}
83+
84+
/**
85+
* Write contents of current config file
86+
* @param $file string full path to output file
87+
* @return boolean file write is successful
88+
*/
89+
function writeConfig($file) {
90+
if (!(file_exists($file) && is_writable($file))
91+
&& !(is_dir(dirname($file)) && is_writable(dirname($file)))) {
92+
// File location cannot be written to
93+
return false;
94+
}
95+
96+
$fp = fopen($file, 'w');
97+
if (!$fp) {
98+
return false;
99+
}
100+
101+
fwrite($fp, $this->content);
102+
fclose($fp);
103+
return true;
104+
}
105+
106+
/**
107+
* Return the contents of the current config file.
108+
* @return string
109+
*/
110+
function getFileContents() {
111+
return $this->content;
112+
}
113+
114+
}
115+
116+
?>

0 commit comments

Comments
 (0)