More database updates.
darkmorford -
d3dc8cc67273
Not Reviewed
Show More
Add another comment
TODOs: 0 unresolved 0 Resolved
COMMENTS: 0 General 0 Inline
@@ -25,7 +25,6 function mt_get_cookie_login() {
25
25
26 // Store username and password in a cookie
26 // Store username and password in a cookie
27 function mt_setcookie($username, $password, $already_md5 = false, $siteurl = '', $remember = false) {
27 function mt_setcookie($username, $password, $already_md5 = false, $siteurl = '', $remember = false) {
28 global $mtdb;
29 if ( !$already_md5 )
28 if ( !$already_md5 )
30 $password = mt_hash_password($password);
29 $password = mt_hash_password($password);
31
30
@@ -73,7 +73,7 function wp_nonce_ays($action) {
73 }
73 }
74
74
75 function mt_explain_nonce($action) {
75 function mt_explain_nonce($action) {
76 global $mtdb;
76 global $dbConnection;
77 $c = explode('-',$action);
77 $c = explode('-',$action);
78 $i = (int)$c[2];
78 $i = (int)$c[2];
79
79
@@ -110,12 +110,12 function mt_explain_nonce($action) {
110 if( false !== strpos( $t, '%' ) ) {
110 if( false !== strpos( $t, '%' ) ) {
111
111
112 switch( $c[1] ) {
112 switch( $c[1] ) {
113 case 'rant': $v = $mtdb->getOne('SELECT title FROM rant WHERE id=' . $i); break;
113 case 'rant': $v = $dbConnection->fetchColumn('SELECT title FROM rant WHERE id = ?', array($i)); break;
114 case 'strip': $v = $mtdb->getOne('SELECT id FROM strip WHERE id=' . $i); break;
114 case 'strip': $v = $dbConnection->fetchColumn('SELECT id FROM strip WHERE id = ?', array($i)); break;
115 case 'type': $v = $mtdb->getOne('SELECT name FROM strip_t WHERE id=' . $i); break;
115 case 'type': $v = $dbConnection->fetchColumn('SELECT name FROM strip_t WHERE id = ?', array($i)); break;
116 case 'metatype':$v = $mtdb->getOne('SELECT name FROM meta_t WHERE id=' . $i); break;
116 case 'metatype':$v = $dbConnection->fetchColumn('SELECT name FROM meta_t WHERE id = ?', array($i)); break;
117 case 'extra': $temp = extra_file_from_inode($i); $v = $temp->name; break;
117 case 'extra': $temp = extra_file_from_inode($i); $v = $temp->name; break;
118 case 'twitteruser': $v = $mtdb->getOne('SELECT username FROM twitter_user WHERE id=' . $i); break;
118 case 'twitteruser': $v = $dbConnection->fetchColumn('SELECT username FROM twitter_user WHERE id = ?', array($i)); break;
119 default: $v = $i;
119 default: $v = $i;
120 }
120 }
121
121
@@ -3,8 +3,16
3 // Book: The offset from 0 at the beginning of time
3 // Book: The offset from 0 at the beginning of time
4 // Page: The offset from 0 at the beginning of the volume
4 // Page: The offset from 0 at the beginning of the volume
5
5
6 class Strip {
6 class Strip
7 var $id, $old_id, $published, $media, $type, $title, $book, $page;
7 {
8 public $id;
9 public $old_id;
10 public $published;
11 public $media;
12 public $type;
13 public $title;
14 public $book;
15 public $page;
8 }
16 }
9
17
10 // old_id is used to detect alterations to the strip id in forms. Not saved in database.
18 // old_id is used to detect alterations to the strip id in forms. Not saved in database.
@@ -12,29 +20,31 class Strip {
12
20
13 // Strip id is automatically incremented
21 // Strip id is automatically incremented
14 function insertstrip(&$strip) {
22 function insertstrip(&$strip) {
15 global $mtdb;
23 global $dbConnection;
16
24
17 $strip->book = ($strip->book == '') ? 'NULL' : (int)$strip->book;
25 $strip->book = ($strip->book == '') ? 'NULL' : (int)$strip->book;
18 $strip->page = ($strip->page == '') ? 'NULL' : (int)$strip->page;
26 $strip->page = ($strip->page == '') ? 'NULL' : (int)$strip->page;
19
27
20 $mtdb->query('START TRANSACTION');
28 $dbConnection->beginTransaction();
21 $newid = $mtdb->getOne('SELECT MAX(id) FROM strip') + 1;
29 $newid = $dbConnection->fetchColumn('SELECT MAX(id) FROM strip') + 1;
22 $sql = 'INSERT INTO strip ( id, published, media, type, title, book, page ) VALUES ('
30
23 . $newid
31 $sql = 'INSERT INTO strip (id, published, media, type, title, book, page) VALUES(?, FROM_UNIXTIME(?), ?, ?, ?, ?, ?)';
24 . ', FROM_UNIXTIME(' . (int)$strip->published
32 $stmt = $dbConnection->prepare($sql);
25 . '), '. (int)$strip->media
33
26 . ', ' . (int)$strip->type
34 $stmt->bindValue(1, $newid);
27 . ', "' . mysqli_real_escape_string( $mtdb->link, trim($strip->title) )
35 $stmt->bindValue(2, $strip->published, PDO::PARAM_INT);
28 . '", '. $strip->book
36 $stmt->bindValue(3, $strip->media, PDO::PARAM_INT);
29 . ', ' . $strip->page
37 $stmt->bindValue(4, $strip->type, PDO::PARAM_INT);
30 . ')';
38 $stmt->bindValue(5, trim($strip->title));
31
39 $stmt->bindValue(6, $strip->book);
32 $r = $mtdb->query( $sql );
40 $stmt->bindValue(7, $strip->page);
41
42 $r = $stmt->execute();
33 if( !$r ) {
43 if( !$r ) {
34 $mtdb->query('ROLLBACK');
44 $dbConnection->rollback();
35 return false;
45 return false;
36 }
46 }
37 $mtdb->query('COMMIT');
47 $dbConnection->commit();
38 adminlog("Comic ".$newid." posted.", MTS_STRIP, MTA_ADD);
48 adminlog("Comic ".$newid." posted.", MTS_STRIP, MTA_ADD);
39
49
40 $strip->id = $newid;
50 $strip->id = $newid;
@@ -43,22 +53,26 function insertstrip(&$strip) {
43 }
53 }
44
54
45 function updatestrip(&$strip) {
55 function updatestrip(&$strip) {
46 global $mtdb;
56 global $dbConnection;
47
57
48 $strip->book = ($strip->book === '') ? 'NULL' : (int)$strip->book;
58 $strip->book = ($strip->book === '') ? 'NULL' : (int)$strip->book;
49 $strip->page = ($strip->page === '') ? 'NULL' : (int)$strip->page;
59 $strip->page = ($strip->page === '') ? 'NULL' : (int)$strip->page;
50
60
51 $mtdb->query('START TRANSACTION');
61 $dbConnection->beginTransaction();
52 $sql = 'UPDATE strip SET
62
53 published = FROM_UNIXTIME(' . (int)$strip->published .')
63 $sql = 'UPDATE strip SET published = FROM_UNIXTIME(?), media = ?, type = ?, title = ?, book = ?, page = ? WHERE id = ?';
54 , media = '. (int)$strip->media .'
64 $stmt = $dbConnection->prepare($sql);
55 , type = ' . (int)$strip->type .'
65
56 , title = "' . mysqli_real_escape_string( $mtdb->link, trim($strip->title) ) .'"
66 $stmt->bindValue(1, $strip->published, PDO::PARAM_INT);
57 , book = ' . (int)$strip->book .'
67 $stmt->bindValue(2, $strip->media, PDO::PARAM_INT);
58 , page = ' . (int)$strip->page .'
68 $stmt->bindValue(3, $strip->type, PDO::PARAM_INT);
59 WHERE id = ' . (int)$strip->id;
69 $stmt->bindValue(4, trim($strip->title));
60 $mtdb->query( $sql );
70 $stmt->bindValue(5, $strip->book, PDO::PARAM_INT);
61 $mtdb->query('COMMIT');
71 $stmt->bindValue(6, $strip->page, PDO::PARAM_INT);
72 $stmt->bindValue(7, $strip->id, PDO::PARAM_INT);
73
74 $stmt->execute();
75 $dbConnection->commit();
62 adminlog("Comic ".$strip->id." modified.", MTS_STRIP, MTA_MODIFY);
76 adminlog("Comic ".$strip->id." modified.", MTS_STRIP, MTA_MODIFY);
63 return true;
77 return true;
64 }
78 }
@@ -66,12 +80,12 function updatestrip(&$strip) {
66 // Delete destination strip from DB and FS, and Update/Rename the source strip into place. Destructive Move!
80 // Delete destination strip from DB and FS, and Update/Rename the source strip into place. Destructive Move!
67 function move_strip($from_id, $to_id)
81 function move_strip($from_id, $to_id)
68 {
82 {
69 global $mtdb;
83 global $dbConnection;
70 $from_id = (int) $from_id;
84 $from_id = (int) $from_id;
71 $to_id = (int) $to_id;
85 $to_id = (int) $to_id;
72
86
73 // Ensure our source exists
87 // Ensure our source exists
74 $num_strips = $mtdb->getOne( "SELECT COUNT(*) FROM strip WHERE id = $from_id" );
88 $num_strips = $dbConnection->fetchColumn('SELECT COUNT(*) FROM strip WHERE id = ?', array($from_id));
75 if($num_strips < 1)
89 if($num_strips < 1)
76 mtdie("Cannot move strip number $from_id, because it cannot be found in database.");
90 mtdie("Cannot move strip number $from_id, because it cannot be found in database.");
77
91
@@ -79,8 +93,8 function move_strip($from_id, $to_id)
79 deletestrip( $to_id );
93 deletestrip( $to_id );
80
94
81 // Update database
95 // Update database
82 $mtdb->query( "UPDATE strip SET id = $to_id WHERE id = $from_id" );
96 $dbConnection->executeUpdate('UPDATE strip SET id = ? WHERE id = ?', array($to_id, $from_id));
83 $strip = $mtdb->getRow( "SELECT strip.id, extension FROM strip, media_t WHERE media_t.id = strip.media AND strip.id = $to_id" );
97 $strip = $dbConnection->executeQuery('SELECT strip.id, extension FROM strip, media_t WHERE media_t.id = strip.media AND strip.id = ?', array($to_id))->fetch();
84
98
85 // Update filesystem
99 // Update filesystem
86 foreach(glob(sprintf(SITE_PATH_ABS.'/'.SITE_STRIP.'/%04d.*', $from_id)) as $item) {
100 foreach(glob(sprintf(SITE_PATH_ABS.'/'.SITE_STRIP.'/%04d.*', $from_id)) as $item) {
@@ -101,8 +115,8 function deletestrip($id) {
101 $id = (int)$id;
115 $id = (int)$id;
102 if ( !$id ) return false;
116 if ( !$id ) return false;
103
117
104 global $mtdb;
118 global $dbConnection;
105 $r = $mtdb->query( 'DELETE FROM strip WHERE id=' . $id );
119 $r = $dbConnection->executeUpdate('DELETE FROM strip WHERE id = ?', array($id));
106 foreach(glob(sprintf(SITE_PATH_ABS.'/'.SITE_STRIP.'/%04d*.*', $id)) as $item)
120 foreach(glob(sprintf(SITE_PATH_ABS.'/'.SITE_STRIP.'/%04d*.*', $id)) as $item)
107 unlink($item);
121 unlink($item);
108 foreach(glob(sprintf(SITE_PATH_ABS.'/'.SITE_STRIP.'/restricted/%04d*.*', $id)) as $item)
122 foreach(glob(sprintf(SITE_PATH_ABS.'/'.SITE_STRIP.'/restricted/%04d*.*', $id)) as $item)
@@ -112,19 +126,19 function deletestrip($id) {
112 }
126 }
113
127
114 function getstrip($id) {
128 function getstrip($id) {
115 global $mtdb;
129 global $dbConnection;
116 return $mtdb->getRow( 'SELECT id, UNIX_TIMESTAMP(published) as published, type, media, title, book, page FROM strip WHERE id=' . (int)$id);
130 return $dbConnection->executeQuery('SELECT id, UNIX_TIMESTAMP(published) as published, type, media, title, book, page FROM strip WHERE id = ?', array($id))->fetch();
117 }
131 }
118
132
119 function get_stripimage_filename( $strip ) {
133 function get_stripimage_filename( $strip ) {
120 global $mtdb;
134 global $dbConnection;
121 $ext = $mtdb->getOne( 'SELECT extension FROM media_t WHERE id=' . (int)$strip->media ); // filename extension
135 $ext = $dbConnection->fetchColumn('SELECT extension FROM media_t WHERE id = ?', array($strip->media)); // filename extension
122 return sprintf( '%s/%04d.%s', SITE_STRIP, $strip->id, $ext );
136 return sprintf( '%s/%04d.%s', SITE_STRIP, $strip->id, $ext );
123 }
137 }
124
138
125 function get_stripid_by_rantid($rantid) {
139 function get_stripid_by_rantid($rantid) {
126 global $mtdb;
140 global $dbConnection;
127 return $mtdb->getOne('SELECT MAX(strip.id) FROM strip,rant WHERE strip.published<=rant.published AND rant.id=' . (int)$rantid);
141 return $dbConnection->fetchColumn('SELECT MAX(strip.id) FROM strip, rant WHERE strip.published <= rant.published AND rant.id = ?', array($rantid));
128 }
142 }
129
143
130 ?>
144 ?>
@@ -17,9 +17,9 function bracketbalance($line)
17 // Retrieve transcript for this strip from the database, modifying the strip object.
17 // Retrieve transcript for this strip from the database, modifying the strip object.
18 function gettranscript(&$strip)
18 function gettranscript(&$strip)
19 {
19 {
20 global $mtdb;
20 global $dbConnection;
21
21
22 $result = $mtdb->query('SELECT strip FROM transcript WHERE strip=' . (int)$strip->id );
22 $result = $dbConnection->executeQuery('SELECT strip FROM transcript WHERE strip = ?', array($strip->id));
23
23
24 if($result)
24 if($result)
25 {
25 {
@@ -30,16 +30,16 function gettranscript(&$strip)
30 # either way, I care not
30 # either way, I care not
31 Might be able to exchange this loop of getOne()s for a getAll() call.
31 Might be able to exchange this loop of getOne()s for a getAll() call.
32 */
32 */
33 $numPanels = $mtdb->getOne( 'SELECT MAX(panel) FROM transcript WHERE transcript.strip=' . (int)$strip->id );
33 $numPanels = $dbConnection->fetchColumn('SELECT MAX(panel) FROM transcript WHERE strip = ?', array($strip->id));
34 if( $numPanels ) {
34 if( $numPanels ) {
35 for($i = 1; $i <= $numPanels; $i++) {
35 for($i = 1; $i <= $numPanels; $i++) {
36 $result = $mtdb->query( 'SELECT speaker, speech FROM transcript WHERE transcript.strip=' . (int)$strip->id . ' AND panel=' .$i.' ORDER BY line')
36 $result = $dbConnection->executeQuery('SELECT speaker, speech FROM transcript WHERE transcript.strip = ? AND panel = ? ORDER BY line', array($strip->id, $i))
37 or mtdie("There was an error fetching the panel count in the transcript for $strip->id, panel $i. " . mysqli_error(), 'SQL Error');
37 or mtdie("There was an error fetching the panel count in the transcript for $strip->id, panel $i. " . $dbConnection->errorCode(), 'SQL Error');
38
38
39 if(!$result) continue;
39 if(!$result) continue;
40
40
41 $output.= "\nnewpanel\n";
41 $output.= "\nnewpanel\n";
42 while($row = mysqli_fetch_row($result)) {
42 while($row = $result->fetch(PDO::FETCH_NUM)) {
43 if(strlen($row[0]) < 1) continue;
43 if(strlen($row[0]) < 1) continue;
44
44
45 $output.= $row[0];
45 $output.= $row[0];
@@ -56,16 +56,17 function gettranscript(&$strip)
56
56
57 // Parse submitted transcript from strip object, and insert it into the database.
57 // Parse submitted transcript from strip object, and insert it into the database.
58 function savetranscript( &$strip ) {
58 function savetranscript( &$strip ) {
59 global $mtdb;
59 global $dbConnection;
60 $info = '';
60 $info = '';
61
61
62 $mtdb->query('START TRANSACTION');
62 $dbConnection->beginTransaction();
63
63
64 //remove any old transcript data - it's being replaced
64 //remove any old transcript data - it's being replaced
65 $mtdb->query( 'DELETE FROM transcript WHERE transcript.strip=' . (int)$strip->id );
65 $dbConnection->executeUpdate('DELETE FROM transcript WHERE transcript.strip = ?', array($strip->id)));
66
66
67 if( $strip->transcript_posted ) {
67 if( $strip->transcript_posted ) {
68 $inserter = 'INSERT INTO transcript (strip,panel,line,speaker,speech,search) VALUES (%d,%d,%d,"%s","%s","%s")';
68 $inserter = 'INSERT INTO transcript (strip, panel, line, speaker, speech, search) VALUES (?, ?, ?, ?, ?, ?)';
69 $inserter_types = array(PDO::PARAM_INT, PDO::PARAM_INT, PDO::PARAM_INT, PDO::PARAM_STR, PDO::PARAM_STR, PDO::PARAM_STR);
69
70
70 if(strpos($strip->transcript_posted, 'Panel <$n>') !== FALSE) {
71 if(strpos($strip->transcript_posted, 'Panel <$n>') !== FALSE) {
71 # This is probably a scrivener script
72 # This is probably a scrivener script
@@ -83,11 +84,11 function savetranscript( &$strip ) {
83 $has_spoken = true;
84 $has_spoken = true;
84
85
85 for($j = 0; $j < count($lines); $j++) {
86 for($j = 0; $j < count($lines); $j++) {
86 $insert_sql = '';
87 $inserter_values = array();
87
88
88 if(strpos($lines[$j], '(') === 0) {
89 if(strpos($lines[$j], '(') === 0) {
89 # Line is a note, add it as a comment
90 # Line is a note, add it as a comment
90 $insert_sql = sprintf($inserter, (int)$strip->id, $i, $j, '#', mysqli_real_escape_string($mtdb->link, $lines[$j]), '');
91 $inserter_values = array($strip->id, $i, $j, '#', $lines[$j], '');
91 } elseif(strpos($lines[$j], '[') === 0 || strlen($lines[$j]) == 0) {
92 } elseif(strpos($lines[$j], '[') === 0 || strlen($lines[$j]) == 0) {
92 # Line is an annotation or blank, do nothing
93 # Line is an annotation or blank, do nothing
93 continue;
94 continue;
@@ -95,13 +96,13 function savetranscript( &$strip ) {
95 # Line contains a list of nonspeaking characters
96 # Line contains a list of nonspeaking characters
96 array_splice($lines, $j, 1, array_map('_nospeaker', explode(',', substr($lines[$j], 11))));
97 array_splice($lines, $j, 1, array_map('_nospeaker', explode(',', substr($lines[$j], 11))));
97 $speaker = trim(substr($lines[$j], 11));
98 $speaker = trim(substr($lines[$j], 11));
98 $insert_sql = sprintf($inserter, (int)$strip->id, $i, $j, mysqli_real_escape_string($mtdb->link, $speaker), '', '');
99 $inserter_values = array($strip->id, $i, $j, $speaker, '', '');
99 } elseif($i > 0 && $lines[$j] == strtoupper($lines[$j])) {
100 } elseif($i > 0 && $lines[$j] == strtoupper($lines[$j])) {
100 # Line designates a new speaker, note speaker
101 # Line designates a new speaker, note speaker
101
102
102 # Handle speakers who did not say anything
103 # Handle speakers who did not say anything
103 if(null !== $speaker && !$has_spoken)
104 if(null !== $speaker && !$has_spoken)
104 $insert_sql = sprintf($inserter, (int)$strip->id, $i, $j, mysqli_real_escape_string($mtdb->link, $speaker), '', '');
105 $inserter_values = array($strip->id, $i, $j, $speaker, '', '');
105
106
106 $speaker = ucfirst(strtolower($lines[$j]));
107 $speaker = ucfirst(strtolower($lines[$j]));
107 $has_spoken = false;
108 $has_spoken = false;
@@ -111,25 +112,24 function savetranscript( &$strip ) {
111 $info .= "<p>Warning: Open brackets do not match close brackets in panel $i for speaker ".htmlentities($speaker).'</p>';
112 $info .= "<p>Warning: Open brackets do not match close brackets in panel $i for speaker ".htmlentities($speaker).'</p>';
112
113
113 $search = preg_replace( '/[[:punct:]]|(?<=\s)\s+/', ' ', strtolower($lines[$j]) );
114 $search = preg_replace( '/[[:punct:]]|(?<=\s)\s+/', ' ', strtolower($lines[$j]) );
114 $insert_sql = sprintf($inserter, (int)$strip->id, $i, $j, mysqli_real_escape_string($mtdb->link, $speaker),
115 $inserter_values = array($strip->id, $i, $j, $speaker, $lines[$j], $search);
115 mysqli_real_escape_string($mtdb->link, $lines[$j]), mysqli_real_escape_string($mtdb->link, $search));
116 $has_spoken = true;
116 $has_spoken = true;
117 } else {
117 } else {
118 # Line is unrecognized, add it as a comment
118 # Line is unrecognized, add it as a comment
119 $insert_sql = sprintf($inserter, (int)$strip->id, $i, $j, '#', mysqli_real_escape_string($mtdb->link, $lines[$j]), '');
119 $inserter_values = array($strip->id, $i, $j, '#', $lines[$j], '');
120 }
120 }
121
121
122 if( $insert_sql && false === $mtdb->query( $insert_sql ) ) {
122 if( $inserter_values && false === $dbConnection->executeUpdate($insert_sql, $inserter_values, $inserter_types) ) {
123 $mtdb->query('ROLLBACK');
123 $dbConnection->rollback();
124 mtdie (mysqli_error($mtdb->link), 'Error inserting transcript.');
124 mtdie ($dbConnection->errorCode(), 'Error inserting transcript.');
125 }
125 }
126 }
126 }
127
127
128 if(null !== $speaker && !$has_spoken) {
128 if(null !== $speaker && !$has_spoken) {
129 $insert_sql = sprintf($inserter, (int)$strip->id, $i, $j, mysqli_real_escape_string($mtdb->link, $speaker), '', '');
129 $inserter_values = array($strip->id, $i, $j, $speaker, '', '');
130 if( false === $mtdb->query( $insert_sql ) ) {
130 if( false === $dbConnection->executeUpdate($insert_sql, $inserter_values, $inserter_types) ) {
131 $mtdb->query('ROLLBACK');
131 $dbConnection->rollback();
132 mtdie (mysqli_error($mtdb->link), 'Error inserting transcript.');
132 mtdie ($dbConnection->errorCode(), 'Error inserting transcript.');
133 }
133 }
134 }
134 }
135 }
135 }
@@ -160,17 +160,16 function savetranscript( &$strip ) {
160 if(!bracketbalance($spoken[1]))
160 if(!bracketbalance($spoken[1]))
161 $info .= "<p>Warning: Open brackets do not match close brackets in panel $i for speaker ".htmlentities($spoken[0]).'</p>';
161 $info .= "<p>Warning: Open brackets do not match close brackets in panel $i for speaker ".htmlentities($spoken[0]).'</p>';
162
162
163 $insert_sql = sprintf($inserter, (int)$strip->id, (int)$i, (int)$j, mysqli_real_escape_string($mtdb->link, $spoken[0]),
163 $inserter_values = array($strip->id, $i, $j, $spoken[0], $spoken[1], $spoken[2]);
164 mysqli_real_escape_string($mtdb->link, $spoken[1]), mysqli_real_escape_string($mtdb->link, $spoken[2]) );
164 if( false === $dbConnection->executeUpdate($insert_sql, $inserter_values, $inserter_types) ) {
165 if( false === $mtdb->query( $insert_sql ) ) {
165 $dbConnection->rollback();
166 $mtdb->query('ROLLBACK');
166 mtdie ($dbConnection->errorCode(), 'Error inserting transcript.');
167 mtdie (mysqli_error($mtdb->link), 'Error inserting transcript.');
168 }
167 }
169 }
168 }
170 }
169 }
171 }
170 }
172 }
171 }
173 $mtdb->query('COMMIT');
172 $dbConnection->commit();
174 return $info;
173 return $info;
175 }
174 }
176
175
@@ -2,7 +2,7
2
2
3 function twitterpost($message, $user=TWITTER_USER, $password=TWITTER_PASS)
3 function twitterpost($message, $user=TWITTER_USER, $password=TWITTER_PASS)
4 {
4 {
5 global $mtdb, $info, $error;
5 global $dbConnection, $info, $error;
6 if( $user == '' ) {
6 if( $user == '' ) {
7 # preserve existing twitterpost(message) style posting until OAuth has been vetted.
7 # preserve existing twitterpost(message) style posting until OAuth has been vetted.
8 $user = TWITTER_USER;
8 $user = TWITTER_USER;
@@ -25,7 +25,7 function twitterpost($message, $user=TWITTER_USER, $password=TWITTER_PASS)
25
25
26 } else {
26 } else {
27 # OAuth Mode
27 # OAuth Mode
28 $row = $mtdb->getRow( sprintf('SELECT id, username, oauth_token, oauth_token_secret FROM twitter_user WHERE username="%s"', mysqli_real_escape_string($mtdb->link, $user)));
28 $row = $dbConnection->executeQuery('SELECT id, username, oauth_token, oauth_token_secret FROM twitter_user WHERE username = ?', array($user))->fetch();
29
29
30 $username = $row->username;
30 $username = $row->username;
31 $oauth_token = $row->oauth_token;
31 $oauth_token = $row->oauth_token;
@@ -55,7 +55,7 function twitterpost($message, $user=TWITTER_USER, $password=TWITTER_PASS)
55 function setOAuthTokens($userid,$oauth_token,$oauth_token_secret, $username) {
55 function setOAuthTokens($userid,$oauth_token,$oauth_token_secret, $username) {
56 global $mtdb;
56 global $mtdb;
57 $id = (int)$userid;
57 $id = (int)$userid;
58 if( $mtdb->query( sprintf('UPDATE twitter_user SET oauth_token="%s", oauth_token_secret="%s", username="%s" WHERE id=%d', mysqli_real_escape_string($mtdb->link, $oauth_token), mysqli_real_escape_string($mtdb->link, $oauth_token_secret), mysqli_real_escape_string($mtdb->link, $username), $id )) )
58 if ($dbConnection->executeUpdate('UPDATE twitter_user SET oauth_token = ?, oauth_token_secret = ?, username = ? WHERE id = ?', array($oauth_token, $oauth_token_secret, $username, $id)))
59 return true;
59 return true;
60 return false;
60 return false;
61 }
61 }
@@ -3,21 +3,23
3 /* Types */
3 /* Types */
4
4
5 function get_typeByID( $id ) {
5 function get_typeByID( $id ) {
6 global $mtdb;
6 global $dbConnection;
7 $id = (int)$id;
7 $id = (int)$id;
8 $r = $mtdb->getRow( 'SELECT id, name, description FROM strip_t WHERE id=' . $id );
8 $stmt = $dbConnection->executeQuery('SELECT id, name, description FROM strip_t WHERE id = ?', array($id));
9 $r->meta = $mtdb->getAll( 'SELECT meta as id from meta where type=' . $id);
9 $r = $stmt->fetch();
10 $r->meta = $dbConnection->fetchAll('SELECT meta AS id FROM meta WHERE type = ?', array($id));
10 return $r;
11 return $r;
11 }
12 }
12
13
13 function get_allTypes() {
14 function get_allTypes() {
14 global $mtdb;
15 global $dbConnection;
15 return $mtdb->getRow( 'SELECT id, name, description, meta FROM strip_t' );
16 $stmt = $dbConnection->executeQuery('SELECT id, name, description, meta FROM strip_t');
17 return $stmt->fetch();
16 }
18 }
17
19
18 function get_allMetaTypes() {
20 function get_allMetaTypes() {
19 global $mtdb;
21 global $dbConnection;
20 return $mtdb->getAll("SELECT id, name FROM meta_t");
22 return $dbConnection->fetchAll('SELECT id, name FROM meta_t');
21 }
23 }
22
24
23 function _getMetaNameFromObject($obj) {
25 function _getMetaNameFromObject($obj) {
@@ -86,11 +86,11 function save_upload_rant_image( $source, $rant ) {
86
86
87 function save_upload_rant_attachment( $source, $rant )
87 function save_upload_rant_attachment( $source, $rant )
88 {
88 {
89 global $mtdb;
89 global $dbConnection;
90
90
91 $image_data = getimagesize( $source );
91 $image_data = getimagesize( $source );
92 $mtdb->query( "INSERT INTO rant_attachment (rant, media) VALUES ($rant, $image_data[2])" );
92 $dbConnection->executeUpdate('INSERT INTO rant_attachment (rant, media) VALUES (?, ?)', array($rant, $image_data[2]));
93 $rant_attachment_id = mysqli_insert_id( $mtdb->link );
93 $rant_attachment_id = $dbConnection->lastInsertId();
94
94
95 if( move_uploaded_file($source, SITE_PATH_ABS.'/'.get_rantattachment_filename($rant_attachment_id) ) ) {
95 if( move_uploaded_file($source, SITE_PATH_ABS.'/'.get_rantattachment_filename($rant_attachment_id) ) ) {
96 $upload_info='<p>New rant attachment uploaded for rant '. $rant .'.</p>';
96 $upload_info='<p>New rant attachment uploaded for rant '. $rant .'.</p>';
@@ -1,6 +1,6
1 <?php
1 <?php
2
2
3 $currentuser=false;
3 $currentuser = false;
4
4
5 function getCurrentUser() {
5 function getCurrentUser() {
6 global $currentuser;
6 global $currentuser;
@@ -8,28 +8,28 function getCurrentUser() {
8 }
8 }
9
9
10 function get_userdatabyid( $id ) {
10 function get_userdatabyid( $id ) {
11 global $mtdb;
11 global $dbConnection;
12 return $mtdb->getRow( 'SELECT id,name,email,nameplate,default_image,default_link FROM contributor WHERE id = ' . (int)$id );
12 return $dbConnection->executeQuery('SELECT id, name, email, nameplate, default_image, default_link FROM contributor WHERE id = ?', array($id))->fetch();
13 }
13 }
14
14
15 function get_userdatabylogin( $username ) {
15 function get_userdatabylogin( $username ) {
16 global $mtdb;
16 global $dbConnection;
17 return $mtdb->getRow( 'SELECT id,name,email,nameplate,default_image,default_link FROM contributor WHERE name = "' . mysqli_real_escape_string($mtdb->link, $username) . '"' );
17 return $dbConnection->executeQuery('SELECT id, name, email, nameplate, default_image, default_link FROM contributor WHERE name LIKE ?', array($username))->fetch();
18 }
18 }
19
19
20 function save_userdata( $user ) {
20 function save_userdata( $user ) {
21 adminlog("Saved changes to user ".$user->id." (".$user->name.").", MTS_USER, MTA_UPDATE);
21 adminlog("Saved changes to user ".$user->id." (".$user->name.").", MTS_USER, MTA_UPDATE);
22 global $mtdb;
22 global $dbConnection;
23 return $mtdb->query( sprintf( 'UPDATE contributor SET email="%s", nameplate="%s", default_image="%s", default_link="%s" WHERE id=%d',
23
24 mysqli_real_escape_string($mtdb->link, $user->email), mysqli_real_escape_string($mtdb->link, $user->nameplate),
24 return $dbConnection->executeUpdate('UPDATE contributor SET email = ?, nameplate = ?, default_image = ?, default_link = ? WHERE id = ?',
25 mysqli_real_escape_string($mtdb->link, $user->default_image), mysqli_real_escape_string($mtdb->link, $user->default_link), $user->id) );
25 array($user->email, $user->nameplate, $user->default_image, $user->default_link, $user->id));
26 }
26 }
27
27
28 function change_password( $user ) {
28 function change_password( $user ) {
29 adminlog("Changed password for user ".$user->id." (".$user->name.").", MTS_USER, MTA_UPDATE);
29 adminlog("Changed password for user ".$user->id." (".$user->name.").", MTS_USER, MTA_UPDATE);
30 global $mtdb, $currentuser;
30 global $dbConnection, $currentuser;
31 if( $currentuser->id === $user->id ) mt_setcookie($user->name, $user->password, false, ADMINURL, FALSE );
31 if( $currentuser->id === $user->id ) mt_setcookie($user->name, $user->password, false, ADMINURL, FALSE );
32 return $mtdb->query( 'UPDATE contributor SET password=SHA1( "' . mysqli_real_escape_string($mtdb->link, $user->password) . '" ) WHERE id = "' . mysqli_real_escape_string($mtdb->link, $user->id) . '"' );
32 return $dbConnection->executeUpdate('UPDATE contributor SET password = SHA1(?) WHERE id = ?', array($user->password, $user->id));
33 }
33 }
34
34
35 ?>
35 ?>
Comments 0
You need to be logged in to leave comments. Login now