Commit 8a24d792 authored by zaufi's avatar zaufi

Don't make instance of Integrator till it really neccessary

parent 55fbf68f
<?php
/** \file
* $Header: /cvsroot/tikiwiki/tiki/lib/integrator/integrator.php,v 1.19 2003-11-10 04:33:18 zaufi Exp $
* $Header: /cvsroot/tikiwiki/tiki/lib/integrator/integrator.php,v 1.20 2003-11-12 01:00:57 zaufi Exp $
*
* \brief Tiki integrator support class
*
......@@ -26,7 +26,7 @@ class TikiIntegrator
return $ret;
}
/// Add/Update
function add_replace_repository($repID, $name, $path, $start, $css, $vis, $cacheable, $descr)
function add_replace_repository($repID, $name, $path, $start, $css, $vis, $cacheable, $exp, $descr)
{
global $tikilib;
$name = addslashes($name);
......@@ -35,13 +35,14 @@ class TikiIntegrator
$css = addslashes($css);
$descr = addslashes($descr);
if (strlen($repID) == 0 || $repID == 0)
$query = "insert into tiki_integrator_reps(name,path,start_page,css_file,visibility,cacheable,description)
values('$name','$path','$start','$css','$vis','$cacheable','$descr')";
$query = "insert into tiki_integrator_reps(name,path,start_page,css_file,
visibility,cacheable,expiration,description)
values('$name','$path','$start','$css','$vis','$cacheable','$exp','$descr')";
else
$query = "update tiki_integrator_reps
set name='$name',path='$path',start_page='$start',
css_file='$css',visibility='$vis',cacheable='$cacheable',
description='$descr' where repID='$repID'";
expiration='$exp',description='$descr' where repID='$repID'";
$result = $tikilib->query($query);
// Invalidate cached repository if needed
if (isset($this->c_rep["repID"]) && ($this->c_rep["repID"] == $repID))
......@@ -208,13 +209,14 @@ class TikiIntegrator
return $p.'/'.((strlen($file) > 0) ? $file : $rep["start_page"]);
}
/// Return CSS file for given repository
function get_rep_css($rep)
function get_rep_css($repID)
{
global $style;
global $style_base;
// Return if no CSS file defined for repository
if (strlen($rep["css_file"]) == 0) return '';
$rep = $this->get_repository($repID);
if (!isset($rep["css_file"]) || strlen($rep["css_file"]) == 0) return '';
$tiki_root = $_SERVER['DOCUMENT_ROOT'].dirname($_SERVER['SCRIPT_NAME']);
// Fill array of dirs to scan (local filesystem, and web based)
......@@ -289,13 +291,27 @@ class TikiIntegrator
function get_file($repID, $file, $use_cache = 'y', $url = '')
{
global $tikilib;
// global $debugger;
$data = '';
// Try to get data from cache
$cacheId = 0;
if ($use_cache == 'y' && $url != '' && $tikilib->is_cached($url))
$data = $tikilib->get_cache($tikilib->get_cache_id($url));
$data = $tikilib->get_cache($cacheId = $tikilib->get_cache_id($url));
$rep = $this->get_repository($repID);
// $debugger->msg("exp: ".$rep["expiration"]);
// If smth found in cache return it... else try to get it by usual way.
if ($data != '' && isset($data["data"]) && ($data["data"] != '')) return $data["data"];
// \todo Smbd can explain why to use date('U') instead of time()???
if ($data != '' && isset($data["data"]) && ($data["data"] != '')
&& ($rep["expiration"] > 0 ? (time() - $data["refresh"]) < $rep["expiration"] : true))
return $data["data"];
// {
// $debugger->msg("Get page ".$url." from cache");
// $debugger->msg("Age of page (sec.): ".(time() - $data["refresh"]));
// return $data["data"];
// }
// else $debugger->msg("No cached page for ".$url);
// Get file content to string
$data = @file_get_contents($file);
......@@ -305,7 +321,8 @@ class TikiIntegrator
{
// Now we need to hack this file by applying all configured rules...
$data = $this->apply_all_rules($repID, $data);
// Add result to cache
// Add result to cache (remove prev if needed)
if ($cacheId != 0) $tikilib->remove_cache($cacheId);
$tikilib->cache_url($url, $data);
}
return $data;
......@@ -330,6 +347,4 @@ class TikiIntegrator
}
}
$integrator = new TikiIntegrator($dbTiki);
?>
\ No newline at end of file
<?php
/**
* $Header: /cvsroot/tikiwiki/tiki/tiki-admin_integrator.php,v 1.12 2003-11-12 00:32:25 zaufi Exp $
* $Header: /cvsroot/tikiwiki/tiki/tiki-admin_integrator.php,v 1.13 2003-11-12 01:00:56 zaufi Exp $
*
* Admin interface for repositories management
*
......@@ -34,6 +34,8 @@ $description = isset($_REQUEST["description"]) ? $_REQUEST["description"] : '';
$vis = isset($_REQUEST["vis"]) ? ($_REQUEST["vis"] == 'on' ? 'y' : 'n') : 'n';
$cacheable = isset($_REQUEST["cacheable"]) ? ($_REQUEST["cacheable"] == 'on' ? 'y' : 'n') : 'n';
// Create instance of integrator
$integrator = new TikiIntegrator($dbTiki);
// Check if 'submit' pressed ...
if (isset($_REQUEST["save"]))
......
<?php
/**
* $Header: /cvsroot/tikiwiki/tiki/tiki-admin_integrator_rules.php,v 1.18 2003-11-12 00:32:25 zaufi Exp $
* $Header: /cvsroot/tikiwiki/tiki/tiki-admin_integrator_rules.php,v 1.19 2003-11-12 01:00:57 zaufi Exp $
*
* Admin interface for rules management
*
......@@ -50,6 +50,10 @@ if (!isset($_REQUEST["repID"]) || $repID <= 0)
$smarty->display("styles/$style_base/error.tpl");
die;
}
// Create instance of integrator
$integrator = new TikiIntegrator($dbTiki);
// Check if copy button pressed
if (isset($_REQUEST["copy"]) && ($srcrep > 0))
$integrator->copy_rules($srcrep, $repID);
......
<?php
/**
* $Header: /cvsroot/tikiwiki/tiki/tiki-integrator.php,v 1.13 2003-11-12 00:32:25 zaufi Exp $
* $Header: /cvsroot/tikiwiki/tiki/tiki-integrator.php,v 1.14 2003-11-12 01:00:57 zaufi Exp $
*
* Integrated files viewer (wrapper)
*
......@@ -31,6 +31,8 @@ if (!isset($_REQUEST["repID"]) && ($repID <= 0))
$smarty->display("styles/$style_base/error.tpl");
die;
}
// Create instance of integrator
$integrator = new TikiIntegrator($dbTiki);
// Get repository configuration data
$rep = $integrator->get_repository($repID);
......
<?php
/**
* $Header: /cvsroot/tikiwiki/tiki/tiki-list_integrator_repositories.php,v 1.9 2003-11-12 00:32:25 zaufi Exp $
* $Header: /cvsroot/tikiwiki/tiki/tiki-list_integrator_repositories.php,v 1.10 2003-11-12 01:00:57 zaufi Exp $
*
* Admin interface for repositories management
*
......@@ -23,6 +23,9 @@ if (($tiki_p_view_integrator != 'y') && ($tiki_p_admin_integrator != 'y') && ($t
die;
}
// Create instance of integrator
$integrator = new TikiIntegrator($dbTiki);
// Fill list of repositories
$repositories = $integrator->list_repositories(true);
$smarty->assign_by_ref('repositories', $repositories);
......
<?php
// $Header: /cvsroot/tikiwiki/tiki/tiki-setup.php,v 1.157 2003-11-11 14:47:16 luciash Exp $
// $Header: /cvsroot/tikiwiki/tiki/tiki-setup.php,v 1.158 2003-11-12 01:00:57 zaufi Exp $
// Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
......@@ -1677,12 +1677,16 @@ $smarty->assign_by_ref('num_queries',$tikilib->num_queries);
/*
* Check location for Tiki Integrator script and setup aux CSS file if needed by repository
*/
if ($feature_integrator == 'y') {
include_once('lib/integrator/integrator.php');
if ((strpos($_SERVER['REQUEST_URI'], 'tiki-integrator.php') != 0) && isset($_REQUEST['repID'])) {
$integrator_css_file = $integrator->get_rep_css($integrator->get_repository($_REQUEST['repID']));
$smarty->assign('integrator_css_file', $integrator_css_file);
}
if ($feature_integrator == 'y')
{
include_once('lib/integrator/integrator.php');
if ((strpos($_SERVER['REQUEST_URI'], 'tiki-integrator.php') != 0) && isset($_REQUEST['repID']))
{
// Create instance of integrator
$integrator = new TikiIntegrator($dbTiki);
$integrator_css_file = $integrator->get_rep_css($_REQUEST['repID']);
$smarty->assign('integrator_css_file', $integrator_css_file);
}
}
/*
......
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