Commit ec7822b9 authored by metzlerd's avatar metzlerd
Browse files

Basic working include function but still need to correct db_sync.

parent 9deecc74
......@@ -111,13 +111,13 @@ class FrxDrupalApplication {
$r_text = '';
if ($report_name) {
$i_report_name = $report_name;
$report_path = Frx::File()->path('');
$int_filename = $language->language . '/' . $report_name . '.frx';
$filename = $report_name . '.frx';
if (Frx::File()->exists($int_filename) && @$_GET['language']!= 'en') {
$i_report_name = $language->language . '/' . $report_name;
$r_text = file_get_contents($int_filename);
$modified = filemtime($int_filename);
$r_text = Frx::File()->contents($int_filename);
$full_path = Frx::File()->path($int_filename);
$modified = filemtime($full_path);
$filename = $int_filename;
}
elseif (Frx::File()->exists($filename)) {
......
......@@ -6,6 +6,8 @@
*/
class FrxFile {
public $dir; // Path to directoy containing report paths.
public $writable;
public $includes = array(); //Other places to look for a directory.
/**
* Constructor
......@@ -17,14 +19,28 @@ class FrxFile {
$report_path = variable_get('file_' . file_default_scheme() . '_path', conf_path() . '/files/reports');
}
$this->dir = rtrim($report_path, '/');
$directories = module_invoke_all('forena_report_directory');
foreach ($directories as $dir) {
$this->includes[] = rtrim($dir, '/');
}
// Check to see if directory is writable
$this->writable = is_writable($this->dir);
}
/**
* Return the full path to the filename
* @param $filename
*/
public function path($filename) {
return $this->dir . '/' . $filename;
public function path($filename, $use_include = TRUE) {
$path = $this->dir . '/' . $filename;
if ($use_include && !file_exists($path)) {
foreach ($this->includes as $dir) {
if (file_exists($dir . '/' . $filename)) {
$path = $dir . '/' . $filename;
}
}
}
return $path;
}
/**
......@@ -44,8 +60,8 @@ class FrxFile {
* Return whether the file exists.
* @param unknown_type $filename
*/
public function exists($filename) {
return file_exists($this->dir . '/' . $filename);
public function exists($filename, $use_include = TRUE) {
return file_exists($this->path($filename, $use_include));
}
/**
......@@ -53,14 +69,56 @@ class FrxFile {
* @param $filename filename and extension for report file.
*/
public function contents($filename) {
if ($this->exists($filename)) {
return file_get_contents($this->path($filename));
$path = $this->path($filename);
if (file_exists($path)) {
return file_get_contents($path);
}
else {
return '';
}
}
/**
* Save a file into the report directory.
* @param unknown_type $filename
* @param unknown_type $data
*/
public function save($filename, $data) {
$path = $this->dir . '/' . $filename;
if (is_writable($path)) {
file_put_contents($path, $data);
}
else {
Frx::error(t('Insufficient privileges to write file.'));
}
}
/**
* Delete a file from the directory.
* @param unknown_type $filename
* @return boolean
*/
public function delete($filename) {
$filepath = $this->path($filename, FALSE);
$info = pathinfo($filepath);
$do = TRUE;
if (file_exists($filepath)) {
chdir($info['dirname']);
if ($delete_file) $do = unlink($info['basename']);
}
return $do;
}
/**
* Retrieve path info
* @param $filename filename used for data
* @param $use_include boolean value determining whether to search include path.
* @return mixed
*/
public function pathinfo($filename, $use_include = TRUE) {
return pathinfo($this->path($filename, $use_include));
}
}
\ No newline at end of file
......@@ -100,7 +100,7 @@ class FrxMenu {
$desc['name'] = $this->name = $name;
$desc['directory'] = Frx::File()->directory($filename);
$desc['filename'] = Frx::File()->path($filename);
$desc['filename'] = $filename;
$desc['base_name'] = $this->base_name = $base_name;
$desc['exists'] = Frx::File()->exists($filename);
$desc['link'] = $this->link = 'reports/' . str_replace('/' , '.', $name);
......
......@@ -55,12 +55,8 @@ function forena_delete_report($report_name, $delete_file = TRUE) {
$filepath = $report_path . '/' . $report_name . '.frx';
$info = pathinfo($filepath);
$do = TRUE;
if (file_exists($filepath)) {
chdir($info['dirname']);
if ($delete_file) $do = unlink($info['basename']);
}
$info = Frx::File()->pathinfo($filepath);
$do = Frx::File()->delete($filepath);
if (module_exists('locale')) {
@list($tlang, $tname) = explode('/', $report_name, 2);
if (array_key_exists($tlang, language_list())) {
......@@ -134,10 +130,8 @@ function forena_get_report_editor($report_name) {
if ($report_name) {
$r_text='';
$report_path = forena_report_path();
$filename = $report_path . '/' . $report_name . '.frx';
if (file_exists($filename)) {
$r_text = file_get_contents($filename);
}
$filename = $report_name . '.frx';
$r_text = Frx::File()->contents($filename);
$r = new FrxEditor($r_text);
return $r;
}
......@@ -621,10 +615,6 @@ function forena_layout_form_submit($form, &$form_state) {
$r->save_attributes_by_id($values['attributes']);
}
//determine redirection.
$report_path = forena_report_path();
$filename = $report_path . '/' . $report_name . '.frx';
if (forena_save_report($report_name, $r->asXML(), TRUE) == 1) {
drupal_set_message(t('Your report, %s has been saved.', array('%s' => $report_name)));
}
......@@ -743,14 +733,12 @@ function forena_add_report_form_validate($form, &$form_state) {
$values = $form_state['values'];
$regexp = "/^[A-Za-z0-9\/\_\-]*$/";
$save_report_name = $values['save_report_name'];
$desc = Frx::Menu()->parseURL($save_report_name);
//comparing the report names to see if they have changed.
//If they have, making sure the new name does not already exist.
$report_path = forena_report_path();
$filename = $report_path . '/' . $save_report_name . '.frx';
if (@$desc['exists']) {
form_set_error('save_report_name', t('The file ' . $save_report_name . ' already exists. Please enter another name.'));
$filename = $save_report_name . '.frx';
if (Frx::File()->exists($filename, FALSE)) {
form_set_error('save_report_name', t('The report ' . $save_report_name . ' already exists. Please enter another name.'));
}
}
......@@ -863,7 +851,7 @@ function forena_create_trans_form_submit($form, &$form_state) {
//determine redirection.
if (file_exists($filename)) {
if (Frx::File()->exists($filename, FALSE)) {
drupal_set_message(t('Report %s already exists', array('%s' => $new_name)), 'error');
return;
}
......@@ -1317,7 +1305,7 @@ function forena_fields_form($formid, $form_state, $report_name) {
$filename = $desc['filename'];
@$format = $desc['format'];
if ($name) {
if (file_exists($filename)) {
if (Frx::File()->exists($filename)) {
$r = forena_get_report_editor($name);
drupal_set_title($r->title);
$regexp = FRX_TOKEN_EXP;
......@@ -1981,18 +1969,17 @@ function forena_report_translations($name_in='') {
if (array_key_exists($lang, $languages)) {
$name = $base_name;
}
elseif ($cur_lang && file_exists(FrxReportGenerator::instance()->report_path() . '/' . $cur_lang . '/' . str_replace('.', '/', $name_in) . '.frx')) {
elseif ($cur_lang && Frx::File()->exists( $cur_lang . '/' . str_replace('.', '/', $name_in) . '.frx')) {
$name_in = $cur_lang . '.' . $name_in;
}
$data = array();
$headers = array(t('Language'), t('Title'), t('Last Modified'), t('Operation'));
// Generate list of all existing tranlsations and their status.
$report_path = FrxReportGenerator::instance()->report_path();
foreach ($languages as $key => $language) {
$i_name = ($key=='en') ? $name : $key . '/' . $name;
$i_link = $key . '.' . $name;
if (file_exists($report_path . '/' . $i_name . '.frx')) {
$modified = format_date(filemtime($report_path . '/' . $i_name . '.frx'));
if (Frx::File()->exists($report_path . '/' . $i_name . '.frx')) {
$modified = format_date(filemtime(Frx::File()->path($i_name . '.frx')));
$r = forena_get_report_editor($i_name);
$title = $r->title;
$edit = l(t('Edit'), 'reports/' . str_replace('/', '.', $i_link) . '/edit', array('query' => array('language' => $key)));
......
......@@ -318,18 +318,11 @@ function forena_save_report($report_name, $report, $save_file = FALSE, $altered
$data['altered'] = $altered;
$r_xml = $report->asXML();
$name = $data['name'];
$filepath = $report_path . '/' . $report_name . '.frx';
$filepath = $report_name . '.frx';
// If we need to save this to the file system
if ($save_file) {
if (!file_exists($filepath) || is_writeable($filepath)) {
// Serialize the report for saving
file_put_contents($filepath, $r_xml);
}
else {
Frx::error(t('Insufficient privileges to write file.'));
}
Frx::File()->save($filepath, $r_xml);
}
// Get the security caches from the reports
......@@ -360,8 +353,8 @@ function forena_save_report($report_name, $report, $save_file = FALSE, $altered
// Save to the Database
if (file_exists($filepath)) {
$modified = filemtime($filepath);
if (Frx::File()->exists($filepath, FALSE)) {
$modified = filemtime(Frx::File()->path($filepath));
$result = db_query("SELECT report_name FROM {forena_reports} WHERE report_name=:report_name AND language=:language", array(':report_name' => $name, 'language' => $lang) );
$path = isset($cache['menu']) ? @$cache['menu']['path'] : '';
if ($rpt = $result->fetchObject() ) {
......
......@@ -1300,7 +1300,6 @@ function _forena_copy_reports($src_dir, $overwrite=FALSE, $subdir=FALSE) {
return $i;
}
/**
* Load cache files from the database
*/
......@@ -1310,7 +1309,8 @@ function forena_db_sync($subdir='') {
if (!$subdir) {
$prefix = '';
db_delete('forena_reports')
->execute();
->execute();
}
$save_count=0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment