-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
135 lines (124 loc) · 3.1 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
require_once('lib/require.php');
$css = Twicture()->getURL(true) . 'css/style.css';
if( !Twicture()->isInstalled() )
{
$install = new Install();
if( $install->hasError() )
{
Page()->addCss( $css );
$errors = $install->getErrors();
if( count($errors) )
{
$out = '';
foreach ($errors as $error) {
$out .= $error;
}
Page()->addContent(sprintf( '<div id="error"><h3>%s</h3>%s</div>', ngettext( _('Error'), _('Errors'), count($errors)), $out) );
}
$warns = $install->getWarns();
if( count($warns) )
{
$out = '';
foreach ($warns as $warn) {
$out .= $warn;
}
Page()->addContent( $out );
}
die();
}
}
if( array_key_exists('media', $_FILES) )
{
$upload = new Upload( $_FILES['media'] );
if ( !$upload->hasError() && !Auth()->checkUser( getParam('username'), getParam('password') ) )
{
$upload->addError( 1001, _('Invalid twitter username or password') );
}
else if( $picture = Twicture()->addPicture( $upload->getFile() ) )
{
$upload->writeElement( 'mediaurl', $picture->getShortenURL() );
}
else
{
$upload->addError( 1007, _('Failed to add image to Twicture') );
}
echo $upload->getXML();
die();
}
switch( getParam('action') )
{
case 'view':
$picture = Twicture()->getPictureFromName( getParam('item') );
if($picture)
{
Page()->setTitle( $picture->getUserName() );
Page()->addCss( $css );
$pic = '<img src="'.$picture->getImageURL(true).'" alt="'.$picture->getFilename().'" id="picture"/>'."\n";
Page()->addContent($pic);
if ( !Page()->browserIsIPhone() )
{
if( $picture->getMessage() )
{
Page()->addContent( sprintf('<div id="message" style="width: %dpx;">❝ %s ❞</div>', $picture->getWidth(), $picture->getMessage() ) );
}
Page()->addContent( sprintf('<div id="date" style="width: %dpx;">%s</div>', $picture->getWidth(), $picture->getDate() ) );
}
}
else
{
Page()->setTitle( _('Huh ?') );
Page()->addCss( $css );
Page()->addContent( sprintf( '<div id="notfound"><h1>%s</h1></div>', _('Picture not found') ) );
}
break;
case 'help':
PageHelp()->addCss( $css );
break;
case 'backup':
case 'delete':
case 'empty':
case 'admin':
if( !Auth()->check() )
{
PageAdmin()->addCss( $css );
}
else
{
switch( getParam('action') )
{
case 'backup':
return Twicture()->getBackup();
break;
case 'delete':
$picture = Twicture()->getPictureFromName( getParam('item') );
if( $picture )
{
$picture->delete();
}
redirect( Twicture()->getAdminURL() );
break;
case 'empty':
foreach ( Twicture()->getPictures() as $picture ) {
$picture->delete();
}
redirect( Twicture()->getAdminURL() );
break;
default:
PageAdmin()->addCss( $css );
break;
}
}
break;
default:
$pictures = Twicture()->getPictures();
Page()->addCss( $css );
foreach ($pictures as $picture) {
$link = '<a href="'.$picture->getURL().'">'."\n";
$link .= '<img src="data/'.$picture->getThumbFilename().'.png" alt="'.$picture->getThumbFilename().'"/>'."\n";
$link .= '</a>'."\n";
Page()->addContent($link);
}
break;
}
?>