OSDN Git Service

https://github.com/rahuldottech/Dabr
[embrj/master.git] / share.php
1 <?php
2         if(!isset($_SESSION)){
3                 session_start();
4         }
5         include ('lib/twitese.php');
6 ?>
7 <!DOCTYPE HTML>
8 <html xmlns="http://www.w3.org/1999/xhtml">
9 <head>
10 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
11 <title>Share to Embr</title>
12 <style>
13 body{background-color:#EEE;font-family:Tahoma,Helvetica,sans-serif;font-size:12px;margin:0}
14 h2{color:#666;display:block;float:left;font-family:Helvetica;font-weight:700;margin:8px 0 0;text-shadow:1px 1px #EEE}
15 p{margin:0;padding:0}
16 a:active, a:focus{outline:medium none}
17 a{color:#3280AB;text-decoration:none}
18 a:hover{color:#000;text-decoration:underline}
19 #tip{color:#999;float:right;font-size:12px}
20 #tip b{font-family:Tahoma,Helvetica,sans-serif;font-size:24px;margin:3px}
21 #share{border-radius:5px;box-shadow:0 0 5px #000;-moz-box-shadow:0 0 5px #000;-webkit-box-shadow:0 0 5px #000;background:url("../img/bg-front.gif") repeat-x scroll 0 0 transparent;height:230px;margin:20px 30px 0;padding:10px 20px;width:500px}
22 #textbox{border-radius:2px;background-color:#FBFBFB;border:1px solid #A7A6AA;font-family:'Lucida Grande',Tahoma,sans-serif;font-size:14px;height:80px;margin:0;overflow:hidden;padding:3px;width:490px}
23 #url{border-radius:2px;background-color:#FBFBFB;border:1px solid #A7A6AA;font-family:'Lucida Grande',Tahoma,sans-serif;font-size:12px;padding:3px;width:490px}
24 .title{display:block;width:40px}
25 table tr td{padding:5px 0}
26 #message{font-size:14px;margin-top:100px;text-align:center}
27 #textbox:hover, #url:hover{background-color:#FFF}
28 .more{background-color:#FFF;background-image:url("../img/more.gif");background-position:left top;background-repeat:repeat-x;border-color:#DDD #AAA #AAA #DDD;border-style:solid;border-width:1px;display:block;font-family:Helvetica;font-size:18px;font-weight:700;height:22px;letter-spacing:1px;line-height:2em;margin-bottom:6px;outline-style:none;outline-width:medium;padding:6px 0;width:100%}
29 .more:hover{background-position:left -78px;border:1px solid #bbb;text-decoration:none}
30 .more:active{background-position:left -38px;color:#666}
31 .more::-moz-focus-inner{border:0}
32 .round{-moz-border-radius:8px;border-radius:8px}
33 #shareBtn{color:#666;display:block;height:45px;margin:0 auto;text-shadow:0 1px 0 #FFF;vertical-align:top;width:300px;line-height:1em}
34 </style>
35 <script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.1.min.js"></script>
36 <script src="js/jquery.embrr.utils.js"></script>
37 <script>
38 $(function(){leaveWord();
39         $("#textbox").focus().bind("keyup","keydown",function(){leaveWord()});
40 });
41
42 function leaveWord(num){
43         if (!num) num = 140;
44         var leave = num-$("#textbox").val().length;
45         if (leave < 0){
46                 $("#tip").html("<b>-" + (-leave) + "</b>");
47         } else{
48                 $("#tip").html("<b>" + leave + "</b>");
49                 if (leave > 40){ 
50                         $("#tip, #tip b").css("color","#CCC");
51                 } else if(leave > 20){
52                         $("#tip, #tip b").css("color","#CAA");
53                 } else if(leave > 10){
54                         $("#tip, #tip b").css("color","#C88");
55                 } else if(leave > 0){
56                         $("#tip, #tip b").css("color","#C44");
57                 } else{
58                         $("#tip, #tip b").css("color","#E00");
59                 }
60         }
61 }
62 </script>
63 </head>
64
65 <body>
66 <?php
67         $t = getTwitter();
68         if ( isset($_POST['status']) ){
69                 $status = $_POST['status'];
70                 if (mb_strlen($status,'utf-8') > 140){
71                         $status = mb_substr($status, 0, 140, 'utf-8');
72                 }
73                 $status .= $_POST['url'];
74                 $result = $t->update($status);
75         }
76         
77         $text = '';
78         
79         if ( isset($_GET['u']) ){
80                 $url = $_GET['u'];
81         }
82         
83         if ( isset($_GET['t']) ){
84                 $title = $_GET['t'];
85                 $text = $_GET['t'];
86         }
87         
88         if ( isset($_GET['d']) ){
89                 $select = $_GET['d'];
90                 if ( trim($select) != "" ) $text = $select;
91         }
92         
93         $text = $text;  
94         $siteUrl = str_replace('share', 'index', 'http://' . $_SERVER ['HTTP_HOST'] . $_SERVER['PHP_SELF']);
95         ?>
96 <div id="share">
97
98         <?php if ( !$t->username ){?>
99                 <div id="message">Please <a href="login.php" target="_blank">login</a> first.</div>
100         <?php } else if ( isset($_POST['status']) ){ 
101                         if ($result){
102         ?>
103                                 <div id="message">Successfully shared your stuff on Embr! <a href="javascript:window.close()">Close</a></div>
104                                         <script type="text/javascript">
105                                         setTimeout("window.close()",1000);
106                                         </script>
107                 <?php } else{ ?>
108                                 <div id="message">Failed to share your stuff, please try again. <a href="javascript:window.history.go(-1)">Go Back</a></div>
109                 <?php 
110                         }
111            } else{ 
112         ?>
113                 <form action="share.php" method="post">
114                 <table>
115                         <tr>
116                                 <td colspan="2"><h2>Share to Embr</h2><span id="tip"><b>140</b></span></td>
117                         </tr>
118                         <tr>
119                                 <td><input type="text" name="url" id="url" disabled="ture" value="<?php echo $url?>"/></td>
120                         </tr>
121                         <tr>
122                         <td><textarea name="status" id="textbox"><?php echo $text?> <?php if (strlen($url)>30) echo urlshorten($url); else echo $url ?></textarea></td>
123                         </tr>
124                         <tr>
125                         <td>
126                                 <input class="more round" id="shareBtn" type="submit" value="Share" />
127                                 </td>
128                         </tr>
129                 </table>
130                 </form>
131         <?php } ?>
132 </div>
133 </body>
134 </html>