character-twitter.php
117 lines
| 3.8 KiB
| text/x-php
|
XmlPhpLexer
| r1 | <?php | |||
| require_once('include/admin.inc.php'); | ||||
| auth_redirect(); // Require logged in user to access this page. | ||||
| #Actual logic. Only trigger if something submitted. | ||||
| if('post_twitter' == $_REQUEST['action']) | ||||
| { | ||||
| check_nonce('new-character-twitter'); | ||||
| r5 | ||||
| r1 | #Fetch the password from the DB. | |||
| r30 | $stmt = $dbConnection->executeQuery('SELECT username, password FROM twitter_user WHERE id = ?', array($_REQUEST['twitter-account'])); | |||
| $acct = $stmt->fetch(); | ||||
| r5 | ||||
| r1 | $post_at = strtotime($_REQUEST['date18']); | |||
| r5 | ||||
| r1 | if($post_at) | |||
| { | ||||
| if($post_at <= strtotime('now')) | ||||
| { | ||||
| #If we can post immediately, do so. Bypass the scheduler whenever possible. | ||||
| #Treat a date/time in the past as immediate. | ||||
| $ret = twitterpost($_REQUEST['message'], $acct->username, $acct->password); | ||||
| r5 | ||||
| r1 | if($ret) | |||
| { | ||||
| $info.='Update posted to Twitter. <a href="http://www.twitter.com/'.$acct->username.'">View Twitter</a>.'; | ||||
| adminlog('New manual post to Twitter for user '. $acct->username .'.', MTS_TWITTER, MTA_ADD); | ||||
| } | ||||
| else | ||||
| { | ||||
| $error.='There was an error posting to Twitter.'; | ||||
| } | ||||
| } | ||||
| else | ||||
| { | ||||
| #No luck, gotta schedule. | ||||
| r30 | $dbConnection->executeUpdate('INSERT INTO twitter_post (status, user, time, text) VALUES (\'scheduled\', ?, FROM_UNIXTIME(?), ?)', | |||
| array($_REQUEST['twitter-account'], $post_at, $_REQUEST['message'])); | ||||
| r1 | $info .= "Your tweet for user " . htmlentities($acct->username) . " has been scheduled."; | |||
| adminlog('Tweet for account ' . $acct->username . ' has been scheduled.', MTS_TWITTER, MTA_ADD); | ||||
| } | ||||
| } | ||||
| else | ||||
| { | ||||
| $error .= 'Could not make sense of your designated time/date. Please try again.'; | ||||
| } | ||||
| } | ||||
| r30 | $characters = $dbConnection->fetchAll('SELECT id, username FROM twitter_user ORDER BY username'); | |||
| r1 | ||||
| r30 | $scheduled = $dbConnection->fetchAll('SELECT username, text, status, twitter_post.id AS id, time ' . | |||
| 'FROM twitter_post JOIN twitter_user ON twitter_post.user = twitter_user.id ' . | ||||
| 'WHERE twitter_post.status = \'scheduled\' ORDER BY time'); | ||||
| r1 | ||||
| adminhead('Manage Character Twitters'); | ||||
| adminmenu(); | ||||
| ?> | ||||
| <h2>Manage Character Twitters</h2> | ||||
| <form method="post" action="character-twitter.php"> | ||||
| <?php nonce_field('new-character-twitter'); ?> | ||||
| <input type="hidden" name="action" value="post_twitter" /> | ||||
| <p><select name="twitter-account"> | ||||
| <option value="">Select twitter</option> | ||||
| <?php foreach($characters as $c) { | ||||
| printf( '<option value="%s">%s</option>', htmlentities($c->id), htmlentities($c->username) ); | ||||
| } ?> | ||||
| </select></p> | ||||
| <p style="padding-bottom:1em;"> | ||||
| <input type="text" name="message" maxlength="140" size="70" /> | ||||
| At: <script type="text/javascript" src="CalendarPopup.js" ></script> | ||||
| <script type="text/javascript"> | ||||
| var cal18 = new CalendarPopup("testdiv1"); | ||||
| cal18.setCssPrefix("TEST"); | ||||
| </script> | ||||
| <INPUT TYPE="text" NAME="date18" VALUE="now" SIZE=25> | ||||
| <A HREF="#" onClick="cal18.select(document.forms[0].date18,'anchor18','yyyy/MM/dd'); return false;" TITLE="cal18.select(document.forms[0].date18,'anchor18','MM/dd/yyyy'); return false;" NAME="anchor18" ID="anchor18">select</A> | ||||
| <DIV ID="testdiv1" STYLE="position:absolute;visibility:hidden;background-color:white;layer-background-color:white;"></DIV> | ||||
| <input type="submit" value="Send" /> | ||||
| </p> | ||||
| </form> | ||||
| <table class="widefat"> | ||||
| <thead> | ||||
| <tr> | ||||
| <th scope="col">User</th> | ||||
| <th scope="col">Tweet</th> | ||||
| <th scope="col">Time</th> | ||||
| <th scope="col"></th> | ||||
| </tr> | ||||
| </thead> | ||||
| <tbody id="the-list"> | ||||
| <?php | ||||
| $alternate=false; | ||||
| foreach( $scheduled as $s ) { | ||||
| $alternate=!$alternate; | ||||
| ?> | ||||
| <tr <?php if($alternate) echo 'class="alternate"'; ?>> | ||||
| <td><?php echo $s->username; ?></td> | ||||
| <td><?php echo $s->text; ?></td> | ||||
| <td><?php echo htmlentities($s->time); ?></td> | ||||
| <td style="text-align: center;"><a class="delete" href="delete-tweet.php?tweet_id=<?php echo $s->id; ?>">Delete</a></td> | ||||
| </tr> | ||||
| <?php | ||||
| } | ||||
| ?> | ||||
| </tbody> | ||||
| </table> | ||||
| <script type="text/javascript" src="<?php echo SITE_HOST.SITE_PATH; ?>/resources.js"></script> | ||||
| <?php | ||||
| adminfooter(); | ||||
| r5 | ?> | |||
