function index($tweet = '', $error = '', $message_id = '') { if (session_id() == "") { session_start(); } logger($script_path . " index start:"); //configuration parameters: $config_params = Config::getConfigParams(); $hostname = $config_params['hostname']; $watch_demo = $config_params['watch_demo']; $docroot = $config_params['docroot']; $debug = $config_params['debug']; $enable_stats = $config_params['enable_stats']; $header = header_html(); // $footer = $config_params['footer']; $doctype = $config_params['doctype']; $html_attribute = $config_params['html_attribute']; $css = $config_params['css']; $google_analytics = $config_params['google_analytics']; $godaddy_analytics = $config_params['godaddy_analytics']; $cookie_name = $config_params['cookie_name']; $ep4 = $config_params['ep4']; $show_maintenance_page = $config_params['show_maintenance_page']; $fb_app_id = $config_params['fb_app_id']; $search_count_offset = $config_params['search_count_offset']; if ($show_maintenance_page == 1) { maintenance_page(); } if (isset($_REQUEST['screen_name_reply'])) { $screen_name_reply = $_REQUEST['screen_name_reply']; } else { $screen_name_reply = ''; } if (isset($_REQUEST['message_id_reply'])) { $message_id_reply = $_REQUEST['message_id_reply']; } else { $message_id_reply = ''; } logger($script_path . " index page: "); logger($script_path . " cookie:", $_COOKIE); //--------------------------------------------------- $model = new TwextraModel(); $message_totals = $model->get_message_totals(); //round to nearest thousand: $message_totals = $message_totals - $message_totals % 1000; //$message_totals = $message_totals - $search_count_offset; $message_totals = number_format($message_totals); //format into human readable form //--------------------------------------------------- //get twitter credentials and store in session variables for use in banner if (isset($_COOKIE[$cookie_name])) { $controller = new TwextraController(); $result_t = $controller->getTwCredentials($_COOKIE[$cookie_name]); // $screen_name = $result_t['screen_name']; logger($script_path . " result_t:", $result_t); } $script_path = __FUNCTION__; logger($script_path . " session: ", $_SESSION); logger($script_path . " request: ", $_REQUEST); //save logs if ($enable_stats) { $model = new TwextraModel(); $model->saveStat(); } //set error flag if a twitter error, or any other error if (isset($_REQUEST['error']) && $_REQUEST['error'] == 'twitter_error') { $error = "Twitter is returning an error right now. Please try again later. \n\t\tFollow <a href='http://twitter.com/twextradotcom' target='_blank' >@twextradotcom</a> for updates."; } else { if (isset($_REQUEST['error']) && $_REQUEST['error'] == 'ep4') { $error = $ep4; } else { if (isset($_REQUEST['error'])) { $error = urldecode($_REQUEST['error']); } else { if (isset($_REQUEST['signout'])) { $error = "You are now signed out of Twextra, but you may still be signed in on Twitter. " . $error; $_SESSION['user'] = ''; } else { if (isset($_SESSION['error_size'])) { $error = $_SESSION['error_size']; unset($_SESSION['error_size']); } } } } } if (isset($_SESSION['tweet'])) { $tweet = $_SESSION['tweet']; unset($_SESSION['tweet']); } if (!empty($screen_name)) { $twitter_checked = 'checked'; $twextra_checked = ''; } else { if (!empty($screen_name_reply)) { $twitter_checked = 'checked'; $twextra_checked = ''; } else { $twitter_checked = ''; $twextra_checked = 'checked'; } } if (!empty($message_id)) { $model = new TwextraModel(); $result = $model->readTweet($message_id, false); // $tweet = $result['tweet']; } else { if ($screen_name_reply != '') { $tweet = '@' . $screen_name_reply . ' '; } } $docroot = $_SERVER['DOCUMENT_ROOT']; $useragent = $_SERVER['HTTP_USER_AGENT']; $useragent = strtolower($useragent); $useragent = " " . $useragent; //so that strpos works fine.. // $blackberry = preg_match ( "/blackberry/i", $useragent ); // $iphone = preg_match ( "/iphone/i", $useragent ); $blackberry = strpos($useragent, "blackberry"); $iphone = strpos($useragent, "iphone"); $symbian = strpos($useragent, "symbian"); $android = strpos($useragent, "android"); $nokia = strpos($useragent, "nokia"); $samsung = strpos($useragent, "samsung"); $sony = strpos($useragent, "sony"); $vodafone = strpos($useragent, "vodafone"); $nintendo = strpos($useragent, "nintendo"); $sprint = strpos($useragent, "sprint"); $playstation = strpos($useragent, "playstation"); $mot = strpos($useragent, "mot"); $docomo = strpos($useragent, "docomo"); $palm = strpos($useragent, "palm"); $avantgo = strpos($useragent, "avantgo"); if ($blackberry || $iphone || $symbian || $android || $nokia || $samsung || $sony || $vodafone || $nintendo || $sprint || $playstation || $mot || $docomo || $palm || $avantgo) { $editor = 'editorI'; $_SESSION['useragent'] = 'device'; } else { $editor = 'editor'; $_SESSION['useragent'] = 'desktop'; } header("Pragma: no-cache"); header("cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past print $doctype; print "<html {$html_attribute} >"; echo header_html(); $body_top = "<body>\n<div class='wrapper'>\n<div class='page'>"; echo $body_top; if (!empty($error)) { $screen_name = ''; $twitter_checked = ''; $twextra_checked = 'checked'; } $banner = banner($screen_name, 'banner_index'); //(user, banner_class) echo $banner; logger("index/hostname:", $hostname); $message = ''; ?> <div class='p1main'> <div class='p1main_inner'> <div class='p1desc'> <?php //print any error messages here: if (!empty($error)) { ?> <div class='p1main_form_label' id='p1main_form_label' style='border: solid 2px red; padding: 10px; background-color: pink; width: 744px; margin: 10px 0;'> <?php echo $error; ?> <a href='javascript: hide_message_status("p1main_form_label")' style='float: right; font-size: 0.8em;'>Close</a></div> <?php } ?> <div style='float: left; width: 768px; padding-bottom: 10px;'> <h4 class='p1main_form_label'>Type your message below: </h4> <div style='font-size: 11px; float: left;'>(<a href=<?php echo $hostname . '/howto.php'; ?> >Tips for Videos, Images, etc</a>)</div> <br style='clear: both' /> </div> <?php $bookmarklet = "\n<div class='bookmarklet_outer' style='width: 300px;line-height: 150%;'>\n <div>\n <a class='bookmarklet_inner' href=\"javascript:(function(){_twextra_bookmarklet=document.createElement('SCRIPT');\n _twextra_bookmarklet.type='text/javascript';_twextra_bookmarklet.src='http://twetest.com/scripts/twextra_bookmarklet.js?\n x='+(Math.random());document.getElementsByTagName('head')[0].appendChild(_twextra_bookmarklet);})();\">\n Twextra Bookmarklet</a>\n </div>\n</div>"; //echo $bookmarklet; ?> <?php //form and editor; ?> <form method='post' action='/router.php' id='tweet_post' accept-charset="utf-8" class='p1form'><textarea class='ckeditor' id="<?php echo $editor; ?> " name="<?php echo $editor; ?> " rows="15" cols="100" style="width: 768px"><?php echo $tweet; ?> </textarea> <script type="text/javascript"> CKEDITOR.replace( 'editor' ); </script> <input type='hidden' name='route' value='tweet_post'></input> <input type='hidden' name='message_id_reply' value="<?php echo $message_id_reply; ?> "></input> <input type='hidden' name='message_id' value="<?php echo $message_id; ?> "></input> <div class='p1form_buttons'><input type="submit" name="save" id="save" value="Post Message" class='button'></input></div><?php //p1form_buttons; ?> <?php //show buttons: ?> <div class='p1form_social_buttons'> <div style='font-size: 18px; border-bottom: 1px solid black; margin-bottom: 10px;'>Post message to:</div> <div style='margin-top: 5px;'><input type="radio" name="social" value="twitter" <?php echo $twitter_checked; ?> style="margin-left: 0px; float: left; margin-top: 5px; margin-right: 10px;"></input> <img src="/images/twitter_100px.png" /></div> <div style='margin-top: 5px; margin-bottom: 5px;'><input type="radio" name="social" value="linkedin" style="margin-left: 0px; float: left; margin-top: 7px; margin-right: 10px;"></input> <img src="/images/linkedin_100px.png" /></div> <div style='margin-top: 5px; margin-bottom: 5px;'><input type="radio" name="social" value="twextra" <?php echo $twextra_checked; ?> style="margin-left: 0px; float: left; margin-top: 7px; margin-right: 10px;"></input> <img src="/images/twextra_100px.png" /></div> </div> </form> <br style='clear: both;' /> <?php $message .= "<div class='p1_buttons' >"; //tweet button $message .= "<div class='p1_twitter_button' style='float:right;' >"; //p1_twitter_button $message .= '<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" >Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>'; $message .= "</div>"; //p1_twitter_button //facebook like button $message .= "<div class='p1_facebook_button' style='float:right;' >"; //p1_facebook_button $message .= "\n<fb:like href=\"http://twextra.com\" layout=\"button_count\" show_faces=\"false\" width=\"100px\"></fb:like>\n\n <div id=\"fb-root\"></div>\n <script>\n window.fbAsyncInit = function() {\n FB.init({appId: '{$fb_app_id}', status: true, cookie: true, \n xfbml: true});\n };\n (function() {\n var e = document.createElement('script');\n e.type = 'text/javascript';\n e.src = document.location.protocol +\n '//connect.facebook.net/en_US/all.js';\n e.async = true;\n document.getElementById('fb-root').appendChild(e);\n }());\n </script>\n\t\t"; $message .= "</div>"; //p1_facebook_button //$message .= "<br style='clear:both;' />"; $message .= "</div>"; //p1_buttons $message .= " <h4 style='text-align:center'>Over {$message_totals} messages created</h4>"; echo $message; ?> </div> </div> </div> <!-- p1main --> <a style='margin: 20px auto 20px auto; display: block; text-align: center;' href='http://twitter.com/melaniejane88'> <img src='/images/twex.jpg' style='width: 600px; height: 100px' /></a> <?php echo $footer; ?> </div> </div> <?php echo $godaddy_analytics; ?> </body> </html> <?php }
function showTweet($data) { $script_path = __FUNCTION__; //configuration parameters: $config_params = Config::getConfigParams(); $hostname = $config_params['hostname']; $debug = $config_params['debug']; $enable_stats = $config_params['enable_stats']; //save logs if ($enable_stats) { $model = new TwextraModel(); $model->saveStat(); } if (!empty($data)) { //get the url string $message_id = $data['url']; logger($script_path . " message_id: ", $message_id); //get data from the database $model = new TwextraModel(); $result = $model->readTweet($message_id, false); $tweet = $result['tweet']; $url_ln2 = $this->getPrefix($tweet, $message_id); $_SESSION['prefix'] = $url_ln2; $view_count = $result['view_count']; $url = $hostname . "router.php?url={$message_id}&route=tweet_show"; //display tweet and success message $this->updateTwitter($data); $view = new TwextraView(); $view->displayTweet($tweet, $url, $view_count, $this->language_list); } }
function displayTranslatedTweet($src_lang, $src_lang_value = '', $tgt_lang, $tgt_lang_value = '', $message_id) { //configuration parameters: $config_params = Config::getConfigParams(); $css = $config_params['css']; $tweet_size_max_google = $config_params['tweet_size_max_google']; $hostname = $config_params['hostname']; $doctype = $config_params['doctype']; $html_attribute = $config_params['html_attribute']; //$header = $config_params['header'];// //$banner = $config_params['banner'];// $banner = banner('', 'banner'); //(user, banner_class) $footer = $config_params['footer']; // $docroot = $config_params['docroot']; $godaddy_analytics = $config_params['godaddy_analytics']; $show_maintenance_page = $config_params['show_maintenance_page']; if ($show_maintenance_page == 1) { maintenance_page(); } $url = $hostname . "tweet_display.php?message_id={$message_id}&mthd=displayTweet"; $url_rewrite = "{$hostname}/{$message_id}"; $src_lang_value = $this->language_list[$src_lang]; $tgt_lang_value = $this->language_list[$tgt_lang]; //get src_tweet from model; $model = new TwextraModel(); $result = $model->readTweet($message_id, false); $src_tweet = $result['tweet']; //embed @replies for all cases $pattern_to_embed = 'at_reply'; $embed = new EmbedInLink($src_tweet, $pattern_to_embed); $src_tweet = $embed->embedPattern(); //embed links for all cases (Twitter, LinkedIn, Twextra) $pattern_to_embed = 'link'; $embed = new EmbedInLink($src_tweet, $pattern_to_embed); $src_tweet = $embed->embedPattern(); $created = $result['created']; $controller = new TwextraController(); $prefix = $controller->getPrefix($src_tweet, $message_id); $header = header_html($prefix); // //get tgt_tweet from google service //CHECK MAX SIZE, AND FREQUENCY OF TRANSLATIONS.. if (trim($src_tweet) != '') { $tgt_tweet = $this->translate($src_lang, $tgt_lang, $src_tweet); $tweet_object = json_decode($tgt_tweet); if (isset($tweet_object->responseData->translatedText)) { $tgt_tweet = $tweet_object->responseData->translatedText; } else { $tgt_tweet = ''; } } else { $tgt_tweet = ''; $url = ''; } header("Pragma: no-cache"); header("cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past $message = ''; $message .= $doctype; $message .= "<html {$html_attribute} >\n"; $message .= $header; $message .= "<body>"; $message .= "<div class='p3_wrapper'>"; $message .= "<div class='page'>"; $message .= $banner; $message .= "<div class='p3main'>\n"; $message .= "<div class='p3main_inner'>\n"; $message .= "<div class='p3main_text'>\n"; $message .= "<div class='p3tweet_header'>\n"; $message .= "<div class='p3count'> Created: " . $created . " (Pacific Time)</div>\n"; $message .= "<div style='float:left;'>\n"; $message .= "<div class='p3tweet_url'>Message URL: </div>\n"; $message .= "<div class='p3url_outer'><a href='{$url_rewrite}'>" . $url_rewrite . "</a></div>\n"; $message .= "</div>\n"; $message .= "<br style='clear:both;' />\n"; $message .= "</div>\n"; $message .= "<div>"; $message .= "<div class='p3tweet_title'>Source language ({$src_lang_value}):</div>\n"; $message .= "<div style='float:right; text-align:center;padding-bottom:5px;'><a href='{$hostname}' >\n New</a> | <a href='{$hostname}/index.php?message_id={$message_id}'>Edit</a></div>"; $message .= "<br style='clear:both;' />"; $message .= "</div>"; $message .= "<div class='p3tweet'>{$src_tweet}</div>"; $message .= "<div class='p3tweet_title_tr'>Target language ({$tgt_lang_value}):</div>\n"; $message .= "<div class='p3tweet'>{$tgt_tweet}</div>"; $message .= "</div>\n"; //main_text $message .= "<div class='p3main_form'>\n"; $message .= "<div class='p3main_form_inner'>\n"; $message .= "<form method='post' action='{$hostname}/router.php' name='tweet_translate' >\n"; $message .= "<div class='p3main_trans'>\n"; $message .= "Translate again: \n"; $message .= "</div>\n"; $message .= "<div class='p3_src_tgt_tran'>"; $message .= "<div class='p3main_src' >Source Language: \n"; $message .= "<select name='src_lang'>\n"; $selected = ''; foreach ($this->language_list as $key => $val) { if ($src_lang == $key) { $selected = "selected='selected'"; } $option = "<option value='{$key}' {$selected} >{$val}</option>\n"; $message .= $option; $selected = ''; } $message .= "</select>\n"; $message .= "</div>\n"; $message .= "<div class='p3main_tgt' >Target Language: \n"; $message .= "<select name='tgt_lang'>\n"; foreach ($this->language_list as $key => $val) { $option = "<option value='{$key}'>{$val}</option>\n"; $message .= $option; } $message .= "</select>\n"; $message .= "<input type='hidden' name='route' value='tweet_translate' ></input>\n"; $message .= "<input type='hidden' name='url' value='{$url}' ></input>\n"; $message .= "<input type='hidden' name='message_id' value='{$message_id}' ></input>\n"; $message .= "</div>\n"; $message .= "<div class='p3sub'>\n"; $message .= "<input class='button_translate' type='submit' name='submit' value='Translate' />\n"; $message .= "</div>\n"; //p3sub $message .= "<br style='clear:both;' />"; $message .= "</div>"; //p3_src_tgt_tran $message .= "</form>\n"; $message .= "<br style='clear:both' />\n"; $message .= "</div>\n"; //p3main_form_inner $message .= "</div>\n"; //p3main_form $message .= "</div>\n"; //main_inner $message .= "</div>\n"; //main $message .= $footer; $message .= "</div>\n"; //page $message .= "</div>\n"; //wrapper $message .= $godaddy_analytics; $message .= "</body></html>\n"; echo $message; }