Update database code in a few more script files.
darkmorford -
104fb88d66f8
Not Reviewed
Show More
Add another comment
TODOs: 0 unresolved 0 Resolved
COMMENTS: 0 General 0 Inline
@@ -30,7 +30,7 if( isset($_REQUEST['action']) && 'edit_twitter' == $_REQUEST['action']) {
30 }
30 }
31 }
31 }
32
32
33 $statuses = $mtdb->getAll('SELECT id, position, message FROM twitter_status ORDER BY position, id');
33 $statuses = $dbConnection->fetchAll('SELECT id, position, message FROM twitter_status ORDER BY position, id');
34
34
35 adminhead('Manage Twitter Presets');
35 adminhead('Manage Twitter Presets');
36 adminmenu();
36 adminmenu();
@@ -6,7 +6,7 auth_redirect(); // Require logged in user to access this page.
6
6
7 check_nonce('new-scratchpad');
7 check_nonce('new-scratchpad');
8
8
9 $mtdb->query( sprintf( 'INSERT INTO scratchpad (contributor, message) VALUES (%d, "%s")', (int)$currentuser->id, mysqli_real_escape_string($mtdb->link, $_REQUEST['message'])) );
9 $dbConnection->executeUpdate('INSERT INTO scratchpad (contributor, message) VALUES (?, ?)', array($currentuser->id, $_REQUEST['message']));
10
10
11 adminlog("User posted to scratchpad.", MTS_SCRATCH, MTA_INSERT);
11 adminlog("User posted to scratchpad.", MTS_SCRATCH, MTA_INSERT);
12 _redirect( ADMIN_PATH . '/index.php' );
12 _redirect( ADMIN_PATH . '/index.php' );
@@ -14,13 +14,13 if('post_twitter' == $_REQUEST['action'])
14 if( strlen($_REQUEST['message']) ) $postmessage = trim($_REQUEST['message']);
14 if( strlen($_REQUEST['message']) ) $postmessage = trim($_REQUEST['message']);
15
15
16 #string replacement macros
16 #string replacement macros
17 $next_strip_id = $mtdb->getOne( 'SELECT MAX(id) FROM strip' );
17 $next_strip_id = $dbConnection->fetchColumn('SELECT MAX(id) FROM strip');
18 $next_strip_id += 1;
18 $next_strip_id += 1;
19 $postmessage = str_replace("#nextcomic", $next_strip_id, $postmessage);
19 $postmessage = str_replace("#nextcomic", $next_strip_id, $postmessage);
20
20
21 if('' == $postmessage) _redirect( ADMIN_PATH . '/post-twitter.php?tweet=missing');
21 if('' == $postmessage) _redirect( ADMIN_PATH . '/post-twitter.php?tweet=missing');
22 $username = sanitize_username($_REQUEST['twitter_user']);
22 $username = sanitize_username($_REQUEST['twitter_user']);
23 $postasuser = $mtdb->getOne( sprintf('SELECT username FROM twitter_user WHERE username="%s"', mysqli_real_escape_string($mtdb->link, $username)));
23 $postasuser = $dbConnection->fetchColumn('SELECT username FROM twitter_user WHERE username = ?', array($username));
24
24
25 if( in_array('twitter', $_REQUEST['service']) )
25 if( in_array('twitter', $_REQUEST['service']) )
26 $rc = twitterpost( numeric_entities(utfentities($postmessage)), $postasuser );
26 $rc = twitterpost( numeric_entities(utfentities($postmessage)), $postasuser );
@@ -43,8 +43,8 if( isset($_REQUEST['tweet']) && 'missing' == $_REQUEST['tweet'] )
43 $error.='Oops~ Looks like you forgot to enter a message.';
43 $error.='Oops~ Looks like you forgot to enter a message.';
44
44
45
45
46 $statuses = $mtdb->getAll('SELECT id, position, message FROM twitter_status ORDER BY position, id');
46 $statuses = $dbConnection->fetchAll('SELECT id, position, message FROM twitter_status ORDER BY position, id');
47 $twitter_users = $mtdb->getAll('SELECT id, username, oauth_token, oauth_token_secret, oauth_access_token FROM twitter_user ORDER BY username');
47 $twitter_users = $dbConnection->fetchAll('SELECT id, username, oauth_token, oauth_token_secret, oauth_access_token FROM twitter_user ORDER BY username');
48
48
49 adminhead('Update Twitter');
49 adminhead('Update Twitter');
50 adminmenu();
50 adminmenu();
@@ -86,7 +86,6 adminmenu();
86 </form>
86 </form>
87
87
88 <script type="text/javascript">
88 <script type="text/javascript">
89 <!--
90 function copyPreset() {
89 function copyPreset() {
91 var preset = document.statusform.stdmessage;
90 var preset = document.statusform.stdmessage;
92 var status = document.statusform.message
91 var status = document.statusform.message
@@ -98,7 +97,6 adminmenu();
98 var charactersremaining = document.getElementById('charactersremaining');
97 var charactersremaining = document.getElementById('charactersremaining');
99 charactersremaining.innerHTML = 140 - status.value.length
98 charactersremaining.innerHTML = 140 - status.value.length
100 }
99 }
101 -->
102 </script>
100 </script>
103
101
104 <?php /*?>
102 <?php /*?>
@@ -6,7 +6,7 auth_basic();
6
6
7 $count = isset($_REQUEST['count']) && ctype_digit($_REQUEST['count']) ? $_REQUEST['count'] : 25;
7 $count = isset($_REQUEST['count']) && ctype_digit($_REQUEST['count']) ? $_REQUEST['count'] : 25;
8
8
9 $entries = $mtdb->getAll("SELECT UNIX_TIMESTAMP(l.logdate) AS logdate, c.name AS cname, c.email AS cmail, s.name AS section, action, level, message FROM admin_log l JOIN admin_section s ON l.section = s.id LEFT JOIN contributor c ON l.contributor = c.id ORDER BY l.logdate DESC LIMIT $count");
9 $entries = $dbConnection->fetchAll("SELECT UNIX_TIMESTAMP(l.logdate) AS logdate, c.name AS cname, c.email AS cmail, s.name AS section, action, level, message FROM admin_log l JOIN admin_section s ON l.section = s.id JOIN contributor c ON l.contributor = c.id ORDER BY l.logdate DESC LIMIT ?", array($count), array(PDO::PARAM_INT));
10
10
11 header("Content-Type: application/rss+xml;charset=utf-8");
11 header("Content-Type: application/rss+xml;charset=utf-8");
12
12
@@ -6,7 +6,7 auth_basic();
6
6
7 $count = isset($_REQUEST['count']) && ctype_digit($_REQUEST['count']) ? $_REQUEST['count'] : 25;
7 $count = isset($_REQUEST['count']) && ctype_digit($_REQUEST['count']) ? $_REQUEST['count'] : 25;
8
8
9 $entries = $mtdb->getAll("SELECT UNIX_TIMESTAMP(s.published) AS pubdate, c.name AS cname, c.email AS cmail, message FROM scratchpad s JOIN contributor c ON s.contributor = c.id ORDER BY s.published DESC LIMIT $count");
9 $entries = $dbConnection->fetchAll('SELECT UNIX_TIMESTAMP(s.published) AS pubdate, c.name AS cname, c.email AS cmail, message FROM scratchpad s JOIN contributor c ON s.contributor = c.id ORDER BY published DESC LIMIT ?', array($count), array(PDO::PARAM_INT));
10
10
11 header("Content-Type: application/rss+xml;charset=utf-8");
11 header("Content-Type: application/rss+xml;charset=utf-8");
12
12
@@ -4,7 +4,7 require_once('include/admin.inc.php');
4
4
5 $count = isset($_REQUEST['count']) && ctype_digit($_REQUEST['count']) ? $_REQUEST['count'] : 25;
5 $count = isset($_REQUEST['count']) && ctype_digit($_REQUEST['count']) ? $_REQUEST['count'] : 25;
6
6
7 $entries = $mtdb->getAll("SELECT UNIX_TIMESTAMP(l.logdate) AS logdate, s.name AS section, action, message FROM admin_log l JOIN admin_section s ON l.section = s.id WHERE s.name = 'strip' ORDER BY l.logdate DESC LIMIT $count");
7 $entries = $dbConnection->fetchAll('SELECT UNIX_TIMESTAMP(l.logdate) AS logdate, s.name AS section, action, message FROM admin_log l JOIN admin_section s ON l.section = s.id WHERE s.name = \'strip\' ORDER BY l.logdate DESC LIMIT ?', array($count), array(PDO::PARAM_INT));
8
8
9 header("Content-Type: application/rss+xml;charset=utf-8");
9 header("Content-Type: application/rss+xml;charset=utf-8");
10
10
@@ -4,13 +4,8 require_once('include/admin.inc.php');
4
4
5 // First, the quick hack way. May become neccessary to parallelize later.
5 // First, the quick hack way. May become neccessary to parallelize later.
6
6
7 $tweets = $mtdb->getAll("SELECT username, password, text, status, twitter_post.id AS id
7 $tweets = $dbConnection->fetchAll('SELECT username, password, text, status, tp.id AS id FROM twitter_post tp JOIN twitter_user tu ON tp.user = tu.id ' .
8 FROM twitter_post JOIN twitter_user
8 'WHERE tp.status = \'scheduled\' AND time >= NOW() AND time < TIMESTAMPADD(?, NOW())', array(RUN_INTERVAL));
9 ON twitter_post.user = twitter_user.id
10 WHERE twitter_post.status = 'scheduled'
11 AND time >= NOW()
12 AND time < TIMESTAMPADD(" . RUN_INTERVAL . ", NOW())
13 ");
14
9
15 // Check if we actually have any tweets. If not, bail.
10 // Check if we actually have any tweets. If not, bail.
16 if(count($tweets) === 0)
11 if(count($tweets) === 0)
@@ -23,7 +18,7 if(count($tweets) === 0)
23 foreach($tweets as $t)
18 foreach($tweets as $t)
24 {
19 {
25 // Lock the tweet
20 // Lock the tweet
26 $mtdb->query("UPDATE twitter_post SET status = 'locked' WHERE id = ".(int)$t->id." AND status = 'scheduled'", false);
21 $dbConnection->executeUpdate('UPDATE twitter_post SET status = \'locked\' WHERE id = ? AND status = \'scheduled\'', array($t->id));
27
22
28 if(twitterpost($t->text, $t->username, $t->password))
23 if(twitterpost($t->text, $t->username, $t->password))
29 {
24 {
@@ -39,7 +34,7 foreach($tweets as $t)
39 }
34 }
40
35
41 // Unlock tweet, update db.
36 // Unlock tweet, update db.
42 $mtdb->query("UPDATE twitter_post SET status = '".mysqli_real_escape_string($mtdb->link, $t->status)."' WHERE status = 'locked' AND id = ".(int)$t->id, false);
37 $dbConnection->executeUpdate('UPDATE twitter_post SET status = ? WHERE status = \'locked\' AND id = ?', array($t->status, $t->id));
43 }
38 }
44
39
45 ?>
40 ?>
@@ -15,7 +15,7 if( isset($_POST['edit']) ) {
15
15
16 copy(RANTIMG.'default', RANTIMG.$username.'.png');
16 copy(RANTIMG.'default', RANTIMG.$username.'.png');
17
17
18 $mtdb->query( 'INSERT INTO contributor (name, default_image) VALUES ("' . mysqli_real_escape_string($mtdb->link, $username) . '", "'.$username.'.png")' );
18 $dbConnection->executeUpdate('INSERT INTO contributor (name, default_image) VALUES (?, ?)', array($username, $username . '.png'));
19 $user = get_userdatabylogin( $username );
19 $user = get_userdatabylogin( $username );
20 $userid = $user->id;
20 $userid = $user->id;
21 $info.='<p>User Account Created</p>';
21 $info.='<p>User Account Created</p>';
@@ -37,7 +37,7 if( isset($_POST['edit']) ) {
37 $error.='<p>New passwords do not match.</p>';
37 $error.='<p>New passwords do not match.</p>';
38 } else {
38 } else {
39 /* password change */
39 /* password change */
40 if( ! $mtdb->getOne( 'SELECT id FROM contributor WHERE id = "' . (int)$user->id . '" AND (password = SHA1("' . mysqli_real_escape_string($mtdb->link, $_POST['password_old']) . '") OR password = "")' )) {
40 if( ! $dbConnection->fetchColumn('SELECT id FROM contributor WHERE id = ? AND (password = SHA1(?) OR password = "")', array((int)$user->id, $_POST['password_old']))) {
41 $error.='<p>Specified password is incorrect.</p>';
41 $error.='<p>Specified password is incorrect.</p>';
42 } else {
42 } else {
43 /* Password match */
43 /* Password match */
@@ -10,11 +10,11 adminhead('Users');
10 adminmenu();
10 adminmenu();
11 ?>
11 ?>
12 <h2>User Administration</h2>
12 <h2>User Administration</h2>
13 <p>Make changes to accounts for contributers to the website.</p>
13 <p>Make changes to accounts for contributors to the website.</p>
14
14
15 <?php
15 <?php
16
16
17 $users = $mtdb->getAll("SELECT id,name,email,nameplate FROM contributor");
17 $users = $dbConnection->fetchAll('SELECT id, name, email, nameplate FROM contributor');
18
18
19 ?>
19 ?>
20
20
@@ -17,10 +17,11 $page = 1;
17 if( isset($_GET['page'] )) $page = (int) $_GET['page'];
17 if( isset($_GET['page'] )) $page = (int) $_GET['page'];
18
18
19 $perpage = 15;
19 $perpage = 15;
20 $start = ($page-1) * $perpage;
20 $start = ($page - 1) * $perpage;
21
21
22 $total = ceil( $mtdb->getOne("SELECT COUNT(*) FROM admin_log") / $perpage );
22 $total = ceil( $dbConnection->fetchColumn('SELECT COUNT(*) FROM admin_log') / $perpage );
23 $entries = $mtdb->getAll("SELECT UNIX_TIMESTAMP(l.logdate) AS logstamp, l.logdate AS logdate, c.name AS cname, c.email AS cmail, s.name AS section, action, level, message FROM admin_log l JOIN admin_section s ON l.section = s.id LEFT JOIN contributor c ON l.contributor = c.id ORDER BY l.logdate DESC LIMIT $start,$perpage");
23 $entries = $dbConnection->fetchAll('SELECT UNIX_TIMESTAMP(l.logdate) AS logstamp, l.logdate AS logdate, c.name AS cname, s.name AS section, action, level, message ' .
24 'FROM admin_log l JOIN admin_section s ON l.section = s.id JOIN contributor c ON l.contributor = c.id ORDER BY l.logdate DESC LIMIT ?, ?', array($start, $perpage), array(PDO::PARAM_INT, PDO::PARAM_INT));
24
25
25 pagination( $page, $total );
26 pagination( $page, $total );
26
27
Comments 0
You need to be logged in to leave comments. Login now