Skip to content

Commit 6fdbac5

Browse files
committed
2.0.0
1 parent 46d2496 commit 6fdbac5

9 files changed

+243
-280
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
.svn*
1+
.DS_Store

code/Module.class.php

+146
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
<?php
2+
3+
4+
namespace FormTools\Modules\JsErrorLogs;
5+
6+
use FormTools\Core;
7+
use FormTools\General;
8+
use FormTools\Hooks;
9+
use FormTools\Module as FormToolsModule;
10+
use Exception, PDO;
11+
12+
13+
class Module extends FormToolsModule
14+
{
15+
protected $moduleName = "JS Error Logs";
16+
protected $moduleDesc = "This module tracks all javascript errors and logs them in a database table for easy browsing. This is handy for alpha/beta releases and to help locate problems with your Form Tools installation.";
17+
protected $author = "Ben Keen";
18+
protected $authorEmail = "[email protected]";
19+
protected $authorLink = "https://formtools.org";
20+
protected $version = "2.0.0";
21+
protected $date = "2017-12-15";
22+
protected $originLanguage = "en_us";
23+
24+
protected $nav = array(
25+
"module_name" => array("index.php", false)
26+
);
27+
28+
29+
public function install($module_id)
30+
{
31+
$db = Core::$db;
32+
33+
if (Core::getReleaseDate() < 20110426) {
34+
return array(false, "Sorry, this module only works with Form Tools 2.1.0 or later.");
35+
}
36+
37+
try {
38+
$db->query("
39+
CREATE TABLE {PREFIX}module_js_error_logs (
40+
log_id mediumint NOT NULL AUTO_INCREMENT PRIMARY KEY,
41+
error_datetime datetime NOT NULL,
42+
msg mediumtext NULL,
43+
url mediumtext NULL,
44+
line varchar(7) NULL,
45+
stacktrace mediumtext NULL
46+
) DEFAULT CHARSET=utf8
47+
");
48+
$db->execute();
49+
} catch (Exception $e) {
50+
return array(false, "There was a problem installing the module: " . $e->getMessage());
51+
}
52+
53+
Hooks::registerHook("template", "js_error_logs", "modules_head_top", "", "includeJs");
54+
Hooks::registerHook("template", "js_error_logs", "head_top", "", "includeJs");
55+
56+
return array(true, "");
57+
}
58+
59+
60+
public function uninstall($module_id)
61+
{
62+
$db = Core::$db;
63+
64+
try {
65+
$db->query("DROP TABLE {PREFIX}module_js_error_logs");
66+
$db->execute();
67+
} catch (Exception $e) {
68+
69+
}
70+
return array(true, "");
71+
}
72+
73+
74+
// this just includes the error catching JS
75+
public function includeJs()
76+
{
77+
$root_url = Core::getRootUrl();
78+
echo "<script src=\"$root_url/modules/js_error_logs/scripts/errors.js\"></script>\n";
79+
}
80+
81+
82+
/**
83+
* @param integer $page
84+
* @param string $search - a string to search any database field
85+
* @return array
86+
*/
87+
public function getErrorLogs($page = 1, $search = "")
88+
{
89+
$db = Core::$db;
90+
91+
$per_page = 20;
92+
93+
// determine the LIMIT clause
94+
$first_item = ($page - 1) * $per_page;
95+
$limit_clause = "LIMIT $first_item, $per_page";
96+
97+
// our main search query
98+
$db->query("
99+
SELECT *
100+
FROM {PREFIX}module_js_error_logs
101+
ORDER BY log_id DESC
102+
$limit_clause
103+
");
104+
$db->execute();
105+
$info = $db->fetchAll();
106+
107+
$db->query("
108+
SELECT count(*)
109+
FROM {PREFIX}module_js_error_logs
110+
");
111+
$db->execute();
112+
113+
return array(
114+
"results" => $info,
115+
"num_results" => $db->fetch(PDO::FETCH_COLUMN)
116+
);
117+
}
118+
119+
120+
public function clearLogs()
121+
{
122+
$db = Core::$db;
123+
$db->query("TRUNCATE {PREFIX}module_js_error_logs");
124+
$db->execute();
125+
}
126+
127+
128+
public function logError($msg, $url, $line, $stacktrace)
129+
{
130+
$db = Core::$db;
131+
132+
$db->query("
133+
INSERT INTO {PREFIX}module_js_error_logs (error_datetime, msg, url, line, stacktrace)
134+
VALUES (:error_datetime, :msg, :url, :line, :stacktrace)
135+
");
136+
$db->bindAll(array(
137+
"error_datetime" => General::getCurrentDatetime(),
138+
"msg" => $msg,
139+
"url" => $url,
140+
"line" => $line,
141+
"stacktrace" => $stacktrace
142+
));
143+
$db->execute();
144+
}
145+
146+
}

code/logs.php

+5-7
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22

33
require_once("../../../global/library.php");
44

5-
$_POST = ft_sanitize($_POST);
5+
use FormTools\Modules;
6+
7+
$module = Modules::initModulePage();
8+
69
$msg = $_POST["msg"];
710
$url = $_POST["url"];
811
$line = $_POST["line"];
912
$stacktrace = isset($_POST["stacktrace"]) ? $_POST["stacktrace"] : "";
1013

11-
$now = ft_get_current_datetime();
12-
13-
mysql_query("
14-
INSERT INTO {$g_table_prefix}module_js_error_logs (error_datetime, msg, url, line, stacktrace)
15-
VALUES ('$now', '$msg', '$url', '$line', '$stacktrace')
16-
");
14+
$module->logError($msg, $url, $line, $stacktrace);

database_integrity.php

-66
This file was deleted.

index.php

+15-13
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
<?php
22

33
require_once("../../global/library.php");
4-
ft_init_module_page();
5-
$request = array_merge($_POST, $_GET);
64

7-
if (isset($request["clear"]))
8-
{
9-
jsel_clear_logs();
5+
use FormTools\General;
6+
use FormTools\Modules;
7+
8+
$module = Modules::initModulePage("admin");
9+
10+
if (isset($request["clear"])) {
11+
$module->clearLogs();
1012
$_GET["page"] = 1;
1113
}
1214

13-
$page = ft_load_module_field("js_error_logs", "page", "page", 1);
14-
15-
$results = jsel_get_error_logs($page);
15+
$page = Modules::loadModuleField("js_error_logs", "page", "page", 1);
16+
$results = $module->getErrorLogs($page);
1617

17-
$page_vars = array();
18-
$page_vars["lines"] = $results["results"];
19-
$page_vars["num_results"] = $results["num_results"];
20-
$page_vars["pagination"] = ft_get_page_nav($results["num_results"], 20, $page);
18+
$page_vars = array(
19+
"lines" => $results["results"],
20+
"num_results" => $results["num_results"],
21+
"pagination" => General::getPageNav($results["num_results"], 20, $page)
22+
);
2123

22-
ft_display_module_page("templates/index.tpl", $page_vars);
24+
$module->displayPage("templates/index.tpl", $page_vars);

library.php

+1-105
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,3 @@
11
<?php
22

3-
4-
function js_error_logs__install($module_id)
5-
{
6-
global $g_table_prefix;
7-
8-
// check the version. If this is earlier than 2.1.0, throw an error
9-
$version_info = ft_get_core_version_info();
10-
if ($version_info["release_date"] < 20110426)
11-
{
12-
return array(false, "Sorry, this module only works with Form Tools 2.1.0 or later.");
13-
}
14-
15-
$query = mysql_query("
16-
CREATE TABLE {$g_table_prefix}module_js_error_logs (
17-
log_id mediumint NOT NULL AUTO_INCREMENT PRIMARY KEY,
18-
error_datetime datetime NOT NULL,
19-
msg mediumtext NULL,
20-
url mediumtext NULL,
21-
line varchar(7) NULL,
22-
stacktrace mediumtext NULL
23-
) DEFAULT CHARSET=utf8
24-
");
25-
26-
if (!$query)
27-
{
28-
return array(false, "There was a problem installing the module: " . mysql_error());
29-
}
30-
31-
ft_register_hook("template", "js_error_logs", "modules_head_top", "", "jsel_include_js");
32-
ft_register_hook("template", "js_error_logs", "head_top", "", "jsel_include_js");
33-
return array(true, "");
34-
}
35-
36-
37-
function js_error_logs__uninstall($module_id)
38-
{
39-
global $g_table_prefix;
40-
41-
// our create table query
42-
mysql_query("DROP TABLE {$g_table_prefix}module_js_error_logs");
43-
44-
return array(true, "");
45-
}
46-
47-
48-
// this just includes the error catching JS
49-
function jsel_include_js()
50-
{
51-
global $g_root_url;
52-
echo "<script src=\"$g_root_url/modules/js_error_logs/scripts/errors.js\"></script>\n";
53-
}
54-
55-
56-
/**
57-
* @param integer $page
58-
* @param string $search - a string to search any database field
59-
* @return array
60-
*/
61-
function jsel_get_error_logs($page = 1, $search = "")
62-
{
63-
global $g_table_prefix, $L;
64-
65-
$per_page = 20;
66-
67-
// determine the LIMIT clause
68-
$limit_clause = "";
69-
$first_item = ($page - 1) * $per_page;
70-
$limit_clause = "LIMIT $first_item, $per_page";
71-
72-
// later, perhaps
73-
$search = ft_sanitize($search);
74-
$search_clause = "";
75-
76-
77-
// our main search query
78-
$query = mysql_query("
79-
SELECT *
80-
FROM {$g_table_prefix}module_js_error_logs
81-
ORDER BY log_id DESC
82-
$limit_clause
83-
");
84-
85-
$info = array();
86-
while ($row = mysql_fetch_assoc($query))
87-
$info[] = $row;
88-
89-
$count_result = mysql_query("
90-
SELECT count(*) as c
91-
FROM {$g_table_prefix}module_js_error_logs
92-
");
93-
$count_hash = mysql_fetch_assoc($count_result);
94-
95-
$return_hash["results"] = $info;
96-
$return_hash["num_results"] = $count_hash["c"];
97-
98-
return $return_hash;
99-
}
100-
101-
102-
function jsel_clear_logs()
103-
{
104-
global $g_table_prefix;
105-
106-
mysql_query("TRUNCATE {$g_table_prefix}module_js_error_logs");
107-
}
3+
require_once(__DIR__ . "/code/Module.class.php");

0 commit comments

Comments
 (0)