Browse Source

organize php and js includes better, update translations

Andrew Dolgov 7 years ago
parent
commit
2d9c80574f

+ 8 - 0
backend.php

@@ -1,4 +1,7 @@
 <?php
+	set_include_path(get_include_path() . PATH_SEPARATOR .
+		dirname(__FILE__) ."/include");
+
 	/* remove ill effects of magic quotes */
 
 	if (get_magic_quotes_gpc()) {
@@ -499,6 +502,11 @@
 		print json_encode(array("status" => get_twitter_lines($link, $connection_id)));
 		break;
 
+	case "logout":
+		logout_user();
+		header("Location: index.php");
+		break;
+
 	case "notify":
 		header("Content-type: text/html; charset=utf-8");
 		$message = $_REQUEST["msg"];

db-prefs.php → include/db-prefs.php


db.php → include/db.php


errors.php → include/errors.php


functions.php → include/functions.php


login_form.php → include/login_form.php


message_types.php → include/message_types.php


sanity_check.php → include/sanity_check.php


sessions.php → include/sessions.php


version.php → include/version.php


+ 8 - 5
index.php

@@ -1,4 +1,7 @@
 <?php
+	set_include_path(get_include_path() . PATH_SEPARATOR .
+		dirname(__FILE__) ."/include");
+
 	require_once "functions.php";
 	require_once "sessions.php";
 	require_once "sanity_check.php";
@@ -32,10 +35,10 @@
 	<script type="text/javascript" charset="utf-8" src="localized_js.php?<?php echo $dt_add ?>"></script>
 	<script type="text/javascript" src="lib/prototype.js"></script>
 	<script type="text/javascript" src="lib/scriptaculous/scriptaculous.js?load=effects,dragdrop,controls"></script>
-		<script type="text/javascript" charset="utf-8" src="tt-irc.js?<?php echo $dt_add ?>"></script>
-		<script type="text/javascript" charset="utf-8" src="prefs.js?<?php echo $dt_add ?>"></script>
-	<script type="text/javascript" charset="utf-8" src="users.js?<?php echo $dt_add ?>"></script>
-	<script type="text/javascript" charset="utf-8" src="functions.js?<?php echo $dt_add ?>"></script>
+		<script type="text/javascript" charset="utf-8" src="js/tt-irc.js?<?php echo $dt_add ?>"></script>
+		<script type="text/javascript" charset="utf-8" src="js/prefs.js?<?php echo $dt_add ?>"></script>
+	<script type="text/javascript" charset="utf-8" src="js/users.js?<?php echo $dt_add ?>"></script>
+	<script type="text/javascript" charset="utf-8" src="js/functions.js?<?php echo $dt_add ?>"></script>
 
 	<?php	$user_theme = get_user_theme_path($link);
 		if ($user_theme) { ?>
@@ -129,7 +132,7 @@
 	<?php } ?>
 
 	<?php if (!SINGLE_USER_MODE) { ?>
-			| <a href="logout.php"><?php echo __('Logout') ?></a>
+			| <a href="backend.php?op=logout"><?php echo __('Logout') ?></a>
 	<?php } ?>
 
 	</div>

functions.js → js/functions.js


prefs.js → js/prefs.js


tt-irc.js → js/tt-irc.js


users.js → js/users.js


File diff suppressed because it is too large
+ 306 - 273
locale/es_MX/LC_MESSAGES/messages.po


File diff suppressed because it is too large
+ 304 - 271
locale/fr_FR/LC_MESSAGES/messages.po


BIN
locale/xx_XX/LC_MESSAGES/messages.mo


File diff suppressed because it is too large
+ 291 - 262
locale/xx_XX/LC_MESSAGES/messages.po


+ 5 - 2
localized_js.php

@@ -1,9 +1,12 @@
 <?php
 	define('DISABLE_SESSIONS', true);
 
+	set_include_path(get_include_path() . PATH_SEPARATOR .
+		dirname(__FILE__) ."/include");
+
 	require "functions.php";
 	header("Content-Type: text/plain; charset=UTF-8");
-	
+
 	function T_js_decl($s1, $s2) {
 		if ($s1 && $s2) {
 			$s1 = preg_replace("/\n/", "", $s1);
@@ -36,7 +39,7 @@ function __(msg) {
 		for ($i = 0; $i < $l10n->total; $i++) {
 			$orig = $l10n->get_original_string($i);
 			$translation = __($orig);
-	
+
 			print T_js_decl($orig, $translation);
 		}
 	}

+ 0 - 10
logout.php

@@ -1,10 +0,0 @@
-<?php
-	require_once "functions.php"; 
-	require_once "sessions.php";
-	require_once "sanity_check.php";
-	require_once "version.php"; 
-	require_once "config.php";
-
-	logout_user();
-	header("Location: index.php");
-?>

+ 3 - 0
prefs.php

@@ -1,4 +1,7 @@
 <?php
+	set_include_path(get_include_path() . PATH_SEPARATOR .
+		dirname(__FILE__) ."/include");
+
 	require_once "functions.php";
 
 	function css_editor($link) {

+ 3 - 0
snippet.php

@@ -1,4 +1,7 @@
 <?php
+	set_include_path(get_include_path() . PATH_SEPARATOR .
+		dirname(__FILE__) ."/include");
+
 	/* remove ill effects of magic quotes */
 
 	if (get_magic_quotes_gpc()) {

+ 11 - 8
twitter.php

@@ -1,20 +1,23 @@
 <?php
+	set_include_path(get_include_path() . PATH_SEPARATOR .
+		dirname(__FILE__) ."/include");
+
 	require_once "functions.php";
 	require_once "sessions.php";
 	require_once "sanity_check.php";
 	require_once "config.php";
 	require_once "db.php";
 	require_once "lib/twitteroauth/twitteroauth.php";
-	
-	$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);	
 
-	init_connection($link);	
+	$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
+
+	init_connection($link);
 	login_sequence($link);
-	
+
 	$owner_uid = $_SESSION["uid"];
 	$op = $_REQUEST['op'];
 
-	if (!SINGLE_USER_MODE && !$_SESSION['uid']) { 
+	if (!SINGLE_USER_MODE && !$_SESSION['uid']) {
 		render_login_form($link);
 		exit;
 	}
@@ -33,7 +36,7 @@
 
 	if ($op == 'callback') {
 		/* If the oauth_token is old redirect to the connect page. */
-		if (isset($_REQUEST['oauth_token']) && 
+		if (isset($_REQUEST['oauth_token']) &&
 				$_SESSION['oauth_token'] !== $_REQUEST['oauth_token']) {
 
 		  $_SESSION['oauth_status'] = 'oldtoken';
@@ -68,14 +71,14 @@
 
 		/* Get temporary credentials. */
 		$request_token = $connection->getRequestToken($callback_url);
-		
+
 		/* Save temporary credentials to session. */
 		$_SESSION['oauth_token'] = $token = $request_token['oauth_token'];
 		$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
 
 		if ($connection->http_code == 200) {
 		    $url = $connection->getAuthorizeURL($token);
-			 header('Location: ' . $url); 
+			 header('Location: ' . $url);
 			 return;
 		}
 	}

+ 2 - 2
update-translations.sh

@@ -1,9 +1,9 @@
 #!/bin/sh
 TEMPLATE=messages.pot
 
-xgettext -kT_js_decl -kT_sprintf -kT_ngettext:1,2 -k__ -L PHP -o $TEMPLATE *.php
+xgettext -kT_js_decl -kT_sprintf -kT_ngettext:1,2 -k__ -L PHP -o $TEMPLATE *.php include/*.php
 
-xgettext --from-code utf-8 -k__ -L Java -j -o $TEMPLATE *.js
+xgettext --from-code utf-8 -k__ -L Java -j -o $TEMPLATE js/*.js
 
 update_lang() {
 	if [ -f $1.po ]; then

+ 36 - 33
update.php

@@ -1,18 +1,21 @@
 <?php
+	set_include_path(get_include_path() . PATH_SEPARATOR .
+		dirname(__FILE__) ."/include");
+
 	require_once "functions.php";
 	require_once "sessions.php";
 	require_once "sanity_check.php";
 	require_once "config.php";
 	require_once "db.php";
-	
-	$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);	
 
-	init_connection($link);	
+	$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
+
+	init_connection($link);
 	login_sequence($link);
-	
+
 	$owner_uid = $_SESSION["uid"];
-	
-	if (!SINGLE_USER_MODE && $_SESSION["access_level"] < 10) { 
+
+	if (!SINGLE_USER_MODE && $_SESSION["access_level"] < 10) {
 		$_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script.");
 		render_login_form($link);
 		exit;
@@ -45,7 +48,7 @@ function confirmOP() {
 		$result = "";
 		while(!feof($fp)) {
 			$tmp = fgetc($fp);
-	
+
 			if($tmp == $delim) {
 				return $result;
 			}
@@ -53,26 +56,26 @@ function confirmOP() {
 		}
 		return $result;
 	}
-	
+
 	$op = $_POST["op"];
 
-	$version = get_schema_version($link);	
-	
+	$version = get_schema_version($link);
+
 	$update_files = glob("schema/versions/".DB_TYPE."/*sql");
 	$update_versions = array();
-	
+
 	foreach ($update_files as $f) {
 		$m = array();
 		preg_match_all("/schema\/versions\/".DB_TYPE."\/(\d*)\.sql/", $f, $m,
 			PREG_PATTERN_ORDER);
-	
+
 		if ($m[1][0]) {
 			$update_versions[$m[1][0]] = $f;
 		}
 	}
-	
+
 	ksort($update_versions, SORT_NUMERIC);
-	
+
 	$latest_version = max(array_keys($update_versions));
 
 	if ($version == $latest_version) {
@@ -80,7 +83,7 @@ function confirmOP() {
 		if ($version != SCHEMA_VERSION) {
 			print_error(__("Could not update database"));
 
-			print "<p>" . 
+			print "<p>" .
 				__("Could not find necessary schema file, need version:") .
 				" " . SCHEMA_VERSION . __(", found: ") . $latest_version . "</p>";
 
@@ -93,33 +96,33 @@ function confirmOP() {
 
 		return;
 	}
-	
+
 	if (!$op) {
 		print_warning(__("Please backup your database before proceeding."));
-	
+
 		print "<p>" . T_sprintf("Your Tiny Tiny RSS database needs update to the latest version (<b>%d</b> to <b>%d</b>).", $version, $latest_version) . "</p>";
-	
+
 	/*		print "<p>Available incremental updates:";
-	
+
 		foreach (array_keys($update_versions) as $v) {
 			if ($v > $version) {
 				print " <a href='$update_versions[$v]'>$v</a>";
 			}
 		} */
-	
+
 		print "</p>";
-	
+
 		print "<form method='POST'>
 			<input type='hidden' name='op' value='do'>
 			<input type='submit' onclick='return confirmOP()' value='".__("Perform updates")."'>
 			</form>";
-	
+
 	} else if ($op == "do") {
-	
+
 		print "<p>".__("Performing updates...")."</p>";
-	
+
 		$num_updates = 0;
-	
+
 		foreach (array_keys($update_versions) as $v) {
 			if ($v == $version + 1) {
 				print "<p>".T_sprintf("Updating to version %d...", $v)."</p>";
@@ -134,32 +137,32 @@ function confirmOP() {
 					}
 				}
 				fclose($fp);
-	
+
 				print "<p>".__("Checking version... ");
-	
+
 				$result = db_query($link, "SELECT schema_version FROM ttirc_version");
 				$version = db_fetch_result($result, 0, "schema_version");
-	
+
 				if ($version == $v) {
 					print __("OK!");
 				} else {
 					print "<b>".__("ERROR!")."</b>";
 					return;
 				}
-	
+
 				$num_updates++;
 			}
 		}
-	
+
 		print "<p>".T_sprintf("Finished. Performed <b>%d</b> update(s) up to schema
 			version <b>%d</b>.", $num_updates, $version)."</p>";
-	
-		print "<form method=\"GET\" action=\"logout.php\">
+
+		print "<form method=\"GET\" action=\"backend.php?op=logout\">
 			<input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
 			</form>";
 
 	}
-	
+
 ?>
 
 </body>

+ 3 - 0
users.php

@@ -1,4 +1,7 @@
 <?php
+	set_include_path(get_include_path() . PATH_SEPARATOR .
+		dirname(__FILE__) ."/include");
+
 	require_once "functions.php";
 
 	function format_users($link) {