OSDN Git Service

embrj
[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.loading{background-color:#fff;background-image:url(../img/ajax.gif);background-position:50% 50%;background-repeat:no-repeat;border:1px solid #eee;cursor:default!important}
32 .more::-moz-focus-inner{border:0}
33 .round{-moz-border-radius:8px;border-radius:8px}
34 #shareBtn{color:#666;display:block;height:45px;margin:0 auto;text-shadow:0 1px 0 #FFF;vertical-align:top;width:300px;line-height:1em}
35 </style>
36 <script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-1.8.3.min.js"></script>
37 <script src="js/jquery.js"></script>
38 <script>
39 $(function(){leaveWord();
40         $("#textbox").focus().bind("keyup","keydown",function(){leaveWord()});
41 });
42
43 function leaveWord(num){
44         if (!num) num = 140;
45         var leave = num-$("#textbox").val().length;
46         if (leave < 0){
47                 $("#tip").html("<b>-" + (-leave) + "</b>");
48         } else{
49                 $("#tip").html("<b>" + leave + "</b>");
50                 if (leave > 40){ 
51                         $("#tip, #tip b").css("color","#CCC");
52                 } else if(leave > 20){
53                         $("#tip, #tip b").css("color","#CAA");
54                 } else if(leave > 10){
55                         $("#tip, #tip b").css("color","#C88");
56                 } else if(leave > 0){
57                         $("#tip, #tip b").css("color","#C44");
58                 } else{
59                         $("#tip, #tip b").css("color","#E00");
60                 }
61         }
62 }
63 </script>
64 </head>
65
66 <body>
67 <?php
68         $t = getTwitter();
69         if ( isset($_POST['status']) ){
70                 $status = $_POST['status'];
71                 if (mb_strlen($status,'utf-8') > 140){
72                         $status = mb_substr($status, 0, 140, 'utf-8');
73                 }
74                 $status .= $_POST['url'];
75                 $result = $t->update($status);
76         }
77         
78         $text = '';
79         
80         if ( isset($_GET['u']) ){
81                 $url = $_GET['u'];
82         }
83         
84         if ( isset($_GET['t']) ){
85                 $title = $_GET['t'];
86                 $text = $_GET['t'];
87         }
88         
89         if ( isset($_GET['d']) ){
90                 $select = $_GET['d'];
91                 if ( trim($select) != "" ) $text = $select;
92         }
93         
94         $text = $text;  
95         $siteUrl = str_replace('share', 'index', 'http://' . $_SERVER ['HTTP_HOST'] . $_SERVER['PHP_SELF']);
96         ?>
97 <div id="share">
98
99         <?php if ( !$t->username ){?>
100                 <div id="message">Please <a href="login.php" target="_blank">login</a> first.</div>
101         <?php } else if ( isset($_POST['status']) ){ 
102                         if ($result){
103         ?>
104                                 <div id="message">Successfully shared your stuff on Embr! <a href="javascript:window.close()">Close</a></div>
105                                         <script type="text/javascript">
106                                         setTimeout("window.close()",1000);
107                                         </script>
108                 <?php } else{ ?>
109                                 <div id="message">Failed to share your stuff, please try again. <a href="javascript:window.history.go(-1)">Go Back</a></div>
110                 <?php 
111                         }
112            } else{ 
113         ?>
114                 <form action="share.php" method="post">
115                 <table>
116                         <tr>
117                                 <td colspan="2"><h2>Share to Embr</h2><span id="tip"><b>140</b></span></td>
118                         </tr>
119                         <tr>
120                                 <td><input type="text" name="url" id="url" disabled="ture" value="<?php echo $url?>"/></td>
121                         </tr>
122                         <tr>
123                         <td><textarea name="status" id="textbox"><?php echo $text?> <?php if (strlen($url)>30) echo urlshorten($url); else echo $url ?></textarea></td>
124                         </tr>
125                         <tr>
126                         <td>
127                                 <input class="more round" id="shareBtn" type="submit" value="Share" />
128                                 </td>
129                         </tr>
130                 </table>
131                 </form>
132         <?php } ?>
133 </div>
134 </body>
135 </html>