tiki-admin_integrator_rules.php 6.09 KB
Newer Older
1
<?php
changi67's avatar
changi67 committed
2 3 4
/**
 * @package tikiwiki
 */
5
// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
rjsmelo's avatar
rjsmelo committed
6
//
7 8
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
changi67's avatar
changi67 committed
9 10
// $Id$

rjsmelo's avatar
rjsmelo committed
11 12
require_once('tiki-setup.php');
require_once('lib/integrator/integrator.php');
zaufi's avatar
zaufi committed
13
// If Integrator is ON, check permissions...
14
$access->check_feature('feature_integrator');
rjsmelo's avatar
rjsmelo committed
15
$access->check_permission(['tiki_p_admin_integrator']);
16
// Setup local variables from request or set default values
changi67's avatar
changi67 committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
$repID = (isset($_REQUEST["repID"]) && strlen($_REQUEST["repID"]) > 0) ? $_REQUEST["repID"] : 0;
$ruleID = (isset($_REQUEST["ruleID"]) && strlen($_REQUEST["ruleID"]) > 0) ? $_REQUEST["ruleID"] : 0;
$ord = (isset($_REQUEST["ord"]) && strlen($_REQUEST["ord"]) > 0) ? $_REQUEST["ord"] : 0;
$srcrep = (isset($_REQUEST["srcrep"]) && strlen($_REQUEST["srcrep"]) > 0) ? $_REQUEST["srcrep"] : 0;
$srch = isset($_REQUEST["srch"]) ? $_REQUEST["srch"] : '';
$repl = isset($_REQUEST["repl"]) ? $_REQUEST["repl"] : '';
$description = isset($_REQUEST["description"]) ? $_REQUEST["description"] : '';
$rxmod = isset($_REQUEST["rxmod"]) ? $_REQUEST["rxmod"] : '';
$file = isset($_REQUEST["file"]) ? $_REQUEST["file"] : '';
$type = isset($_REQUEST["type"]) ? ($_REQUEST["type"] == 'on' ? 'y' : 'n') : 'n';
$casesense = isset($_REQUEST["casesense"]) ? ($_REQUEST["casesense"] == 'on' ? 'y' : 'n') : 'n';
$code = isset($_REQUEST["code"]) ? ($_REQUEST["code"] == 'on' ? 'y' : 'n') : 'n';
$html = isset($_REQUEST["html"]) ? ($_REQUEST["html"] == 'on' ? 'y' : 'n') : 'n';
$all = isset($_REQUEST["all"]) ? ($_REQUEST["all"] == 'on' ? 'y' : 'n') : 'n';
$enabled = isset($_REQUEST["enabled"]) ? ($_REQUEST["enabled"] == 'on' ? 'y' : 'n') : 'n';
rjsmelo's avatar
rjsmelo committed
32
if (! isset($_REQUEST["repID"]) || $repID <= 0) {
33 34 35
	$smarty->assign('msg', tra("No repository"));
	$smarty->display("error.tpl");
	die;
36
}
37 38
// Create instance of integrator
$integrator = new TikiIntegrator($dbTiki);
zaufi's avatar
zaufi committed
39
// Check if copy button pressed
rjsmelo's avatar
rjsmelo committed
40 41 42
if (isset($_REQUEST["copy"]) && ($srcrep > 0)) {
	$integrator->copy_rules($srcrep, $repID);
}
43
// Check if 'save' button pressed ...
changi67's avatar
changi67 committed
44
if (isset($_REQUEST["save"])) {
45
	// ... and all mandatory paramaters r OK
rjsmelo's avatar
rjsmelo committed
46 47 48
	if (strlen($srch) > 0) {
		$integrator->add_replace_rule($repID, $ruleID, $ord, $srch, $repl, $type, $casesense, $rxmod, $enabled, $description);
	} else {
49 50 51 52
		$smarty->assign('msg', tra("Search is mandatory field"));
		$smarty->display("error.tpl");
		die;
	}
53 54
}
// Check if 'preview' button pressed ...
changi67's avatar
changi67 committed
55
if (isset($_REQUEST["preview"])) {
56
	// Prepeare rule data
rjsmelo's avatar
rjsmelo committed
57
	$rule = [];
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
	$rule["repID"] = $repID;
	$rule["ruleID"] = $ruleID;
	$rule["ord"] = $ord;
	$rule["srch"] = $srch;
	$rule["repl"] = $repl;
	$rule["type"] = $type;
	$rule["casesense"] = $casesense;
	$rule["rxmod"] = $rxmod;
	$rule["enabled"] = $enabled;
	$rule["description"] = $description;
	// Reassign values in form
	$smarty->assign('ruleID', $rule["ruleID"]);
	$smarty->assign('ord', $rule["ord"]);
	$smarty->assign('srch', $rule["srch"]);
	$smarty->assign('repl', $rule["repl"]);
	$smarty->assign('type', $rule["type"]);
	$smarty->assign('casesense', $rule["casesense"]);
	$smarty->assign('rxmod', $rule["rxmod"]);
	$smarty->assign('enabled', $rule["enabled"]);
	$smarty->assign('description', $rule["description"]);
	// Have smth to show?
	if (($html != 'y' || $code != 'y')) {
		// Get repository configuration data
		$rep = $integrator->get_repository($repID);
		// Check if file given and present at configured location
		$f = $integrator->get_rep_file($rep, $file);
rjsmelo's avatar
rjsmelo committed
84
		if ((substr($rep["path"], 0, 7) != 'http://') && (substr($rep["path"], 0, 8) != 'https://') && ! file_exists($f)) {
85 86 87 88 89 90
			$smarty->assign('msg', tra("File not found ") . $f);
			$smarty->display("error.tpl");
			die;
		}
		// Get file content to string
		$data = @file_get_contents($f);
rjsmelo's avatar
rjsmelo committed
91 92 93
		if (isset($php_errormsg)) {
			$data .= "ERROR: " . $php_errormsg;
		} else {
94 95 96
			// Should we apply all configured rules or only current one?
			if ($all == 'y') {
				$rules = $integrator->list_rules($repID);
rjsmelo's avatar
rjsmelo committed
97 98 99 100 101 102 103
				if (is_array($rules)) {
					foreach ($rules as $r) {
						if (($r["ruleID"] !== $ruleID) && $r["enabled"]) {
												$data = $integrator->apply_rule($rep, $r, $data);
						}
					}
				}
104 105 106 107 108 109 110 111 112
			}
			// Apply rule (make this rule 'enabled' :)
			$se = $rule["enabled"];
			$rule["enabled"] = 'y';
			$data = $integrator->apply_rule($rep, $rule, $data);
			$rule["enabled"] = $se;
		}
		$smarty->assign_by_ref('preview_data', $data);
	}
113 114
}
// Whether some action requested?
changi67's avatar
changi67 committed
115
if (isset($_REQUEST["action"])) {
116 117 118 119 120 121 122 123 124 125 126 127 128 129
	switch ($_REQUEST["action"]) {
		case 'edit':
			if ($ruleID != 0) {
				$rule = $integrator->get_rule($ruleID);
				$smarty->assign('ruleID', $rule["ruleID"]);
				$smarty->assign('ord', $rule["ord"]);
				$smarty->assign('srch', $rule["srch"]);
				$smarty->assign('repl', $rule["repl"]);
				$smarty->assign('type', $rule["type"]);
				$smarty->assign('casesense', $rule["casesense"]);
				$smarty->assign('rxmod', $rule["rxmod"]);
				$smarty->assign('enabled', $rule["enabled"]);
				$smarty->assign('description', $rule["description"]);
			}
rjsmelo's avatar
rjsmelo committed
130
			break;
131 132 133

		case 'rm':
			if ($ruleID != 0) {
134 135
				$access->check_authenticity();
				$integrator->remove_rule($ruleID);
136
			}
rjsmelo's avatar
rjsmelo committed
137
			break;
138 139 140 141 142

		default:
			$smarty->assign('msg', tra("Requested action in not supported on repository"));
			$smarty->display("error.tpl");
			die;
rjsmelo's avatar
rjsmelo committed
143
			break;
144
	}
145 146 147 148
}
// Get repository name
$r = $integrator->get_repository($repID);
$smarty->assign('name', $r["name"]);
zaufi's avatar
zaufi committed
149
// Reassign checkboxes
150 151 152
$smarty->assign('file', $file);
$smarty->assign('code', $code);
$smarty->assign('html', $html);
changi67's avatar
changi67 committed
153
$smarty->assign('all', $all);
zaufi's avatar
zaufi committed
154
// Fill list of rules
155 156 157
$rules = $integrator->list_rules($repID);
$smarty->assign_by_ref('rules', $rules);
$smarty->assign('repID', $repID);
zaufi's avatar
zaufi committed
158
// Fill list of possible source repositories
159
$allreps = $integrator->list_repositories(false);
rjsmelo's avatar
rjsmelo committed
160 161 162 163
$reps = [];
foreach ($allreps as $rep) {
	$reps[$rep["repID"]] = $rep["name"];
}
zaufi's avatar
zaufi committed
164
$smarty->assign_by_ref('reps', $reps);
165 166
// disallow robots to index page:
$smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');
167
// Display the template
changi67's avatar
changi67 committed
168
$smarty->assign('mid', 'tiki-admin_integrator_rules.tpl');
169
$smarty->display("tiki.tpl");