-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patheditor.php
More file actions
187 lines (187 loc) · 8.02 KB
/
editor.php
File metadata and controls
187 lines (187 loc) · 8.02 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
if(!isset($_SESSION[ME])) {
$_SESSION['redir'] = "foros/?nuevo=".__($_GET['nuevo']);
die("Debe estar <a href=\"".$sitio."?entrar=1\">identificado</a>.");
}
?>
<h1>Escribir nuevo post</h1>
<?php
/* tinymce {{{ */
if(!$mobile) {
?>
<script src="tinymce/tinymce.min.js"></script>
<script>
tinymce.init({
selector: 'textarea', // change this value according to your html
language: 'es_MX',
entity_encoding: 'raw',
relative_urls : false,
plugins: [
'advlist autolink lists link image charmap print preview anchor textcolor',
'searchreplace visualblocks code codesample fullscreen',
'insertdatetime media table contextmenu paste help'
],
toolbar: 'insert | undo redo | bold italic backcolor | alignleft aligncenter alignright alignjustify | bullist numlist | removeformat | link image code | codesample | help',
images_upload_url: 'postimg.php',
images_upload_credentials: true,
menubar:false,
image_class_list: [
{ title: "Adaptable", value: "img-fluid" }
],
codesample_languages: [
{text: 'HTML/XML', value: 'markup'},
{text: 'JavaScript', value: 'javascript'},
{text: 'CSS', value: 'css'},
{text: 'PHP', value: 'php'},
{text: 'C++', value: 'cpp'},
{text: 'Swift', value: 'swift'},
{text: 'SQL', value: 'sql'},
],
});
</script>
<?php
} /* }}} */
//
if(isset($_POST['contenido']) && !empty($_POST['contenido'])) {
$image=null;
$debug=false;
/* post image {{{ */
if(isset($_FILES['archivo']['tmp_name']) && is_uploaded_file($_FILES['archivo']['tmp_name']) && substr($_FILES['archivo']['type'],0,6) == 'image/') {
$imageFolder = __DIR__."/up/";
if($debug) echo "<pre> --- \n";
$pato = $imageFolder.date('Y/m/');
$ext = strtolower(pathinfo($_FILES['archivo']['name'], PATHINFO_EXTENSION));
$file = uniqid()."_o.".$ext;
$filet= str_replace("_o","",$file);
$filete=str_replace("_o","_t",$file);
//
if(!preg_match("/\.jpg$/",$filet)) { $filet = str_replace(".".$ext,".jpg",$filet); }
if(!preg_match("/\.jpg$/",$filete)) { $filete = str_replace(".".$ext,".jpg",$filete); }
//
if(!is_dir($pato)) mkdir($pato,0755,true);
$filetowrite = $pato.$file;
move_uploaded_file($_FILES['archivo']['tmp_name'], $filetowrite);
if($debug) echo " filetowrite = $filetowrite \n";
$t = `/usr/bin/identify $filetowrite`;
$s = explode(" ",$t);
if($debug) {
echo "size: \n";
print_r($t);
print_r($s);
echo "\n";
}
if(in_array($s[1],['JPG','JPEG','PNG','GIF'])) {
$ext = trim(strtolower($s[1]));
$ss = explode("x",$s[2]);
if($ss[0]>=720 && $ext!='gif') {
//
$cmd = "convert -thumbnail 720 -flatten -quality 70 -background white -auto-orient ".$filetowrite."[0] ".$pato.$filet;
if($debug) echo "$cmd\n";
$cmd = `$cmd`;
$cmd = "convert -thumbnail 200 -flatten -quality 60 ".$pato.$filet." ".$pato.$filete;
if($debug) echo "$cmd\n";
$cmd = `$cmd`;
$size=720;
} elseif($ss[0]>=200 && $ext!='gif') {
$cmd = "convert -thumbnail ".$ss[0]." -flatten -quality 70 -background white -auto-orient ".$filetowrite."[0] ".$pato.$filet;
if($debug) echo "$cmd\n";
$cmd = `$cmd`;
$cmd = "convert -thumbnail 200 -flatten -quality 60 ".$pato.$filet." ".$pato.$filete;
if($debug) echo "$cmd\n";
$cmd = `$cmd`;
$size=$ss[0];
} else {
if(!empty($ss[0])) $size=$ss[0];
copy($filetowrite,$filet);
$cmd = "convert -thumbnail 200 -flatten -quality 60 -background white ".$filetowrite."[0] ". $pato.$filete;
if($debug) echo "$cmd\n";
$cmd = `$cmd`;
}
}
$image = "<p class=\"text-center\"><img class=\"img-fluid\" src=\"".$sitio."up/".date('Y/m/').$filet."\" alt=\"imagen\" /></p>";
}
/* }}} */
if($mobile) $body = $image.nl2br($_POST['contenido']);
else $body = $image.$_POST['contenido'];
//
$padre=(isset($_POST['padre']))?__($_POST['padre']):0;
//
if(!isset($_POST['edit'])) {
$q = sprintf("INSERT INTO posts (id,padre, me, foro, fecha, titulo, contenido) values(null,'%d','%s','%s',now(),'%s','%s')",$padre,$_SESSION[ME], __($_POST['cat']), __($_POST['titulo']), addslashes($body));
$sql->Query($q);
if(!empty($sql->error)) echo "SQL ERROR: ".$sql->error;
$ID = $sql->insert_id;
} else {
$ID = __($_POST['edit']);
$q= sprintf("UPDATE posts SET padre='%d', foro='%d', titulo='%s', contenido='%s' WHERE id ='%d' and me = '%s'", $padre, __($_POST['cat']), __($_POST['titulo']), addslashes($body), $ID, $_SESSION[ME]);
$sql->Query($q);
if(!empty($sql->error)) echo "SQL ERROR: ".$sql->error;
}
if($debug) print_r($_FILES);echo "</pre>";
?>
<h3>¡Gracias!</h3>
<div class="alert alert-success" role="alert">
<p class="lead">
Su post ha sido almacenado y publicado.
</p>
</div>
<a class="btn btn-light" href="<?php echo $sitio;?>?nuevo=1&edit=<?php echo $ID;?>">volver a editar</a>
<?php
$urlt = ($padre>0) ? "view=".$padre."#r".$ID : "view=".$ID;
?>
<a class="btn btn-secondary" href="<?php echo $sitio;?>?<?php echo $urlt;?>">ver escrito</a>
<script>
$(function() { setTimeout(function() { window.location = '<?php echo $sitio."?".$urlt;?>'; },5000); });
</script>
<?php
exit();
}
if(isset($_GET['edit'])) {
$edit = sprintf("SELECT * FROM posts WHERE id = '%d' AND me = '%s'",__($_GET['edit']),__($_SESSION[ME]));
$edit = $sql->Query($edit);
if($edit->num_rows>0) $edit = $edit->fetch_object();
else unset($edit);
}
?>
<form method="post" enctype="multipart/form-data">
<?php
if(isset($edit->id)) printf('<input type="hidden" name="edit" value="%d" />',$edit->id);
if(isset($edit->padre) && $edit->padre>0) printf('<input type="hidden" name="padre" value="%d" />',$edit->padre);
?>
<div class="form-row">
<div class="form-group col-md-8">
<input type="text" name="titulo" class="form-control" placeholder="Título del post" value="<?php if(isset($edit->id)) echo stripslashes($edit->titulo); ?>" autofocus />
</div>
<div class="form-group col-md-4">
<select class="form-control" name="cat">
<?php
$master=$sql->Query("SELECT * FROM forotes");
while($ma = $master->fetch_object()) {
$res = $sql->Query("SELECT id,titulo FROM foros where master='".$ma->id."'");
printf('<optgroup label="%s" />',$ma->nombre);
while($k = $res->fetch_object()) {
$tmp =(isset($edit->id) && $edit->foro == $k->id) ? ' selected ':null;
if(empty($tmp) && $_GET['nuevo'] == $k->id) $tmp = " selected";
printf('<option value="%s"%s>%s</option>', $k->id,$tmp,$k->titulo);
}
}
?>
</select>
</div>
</div>
<textarea name="contenido" class="form-control" rows="<?php echo ($mobile)?10:20;?>"><?php if(isset($edit->id)) echo stripslashes($edit->contenido); ?></textarea>
<?php
if($mobile) {
?>
<div class="form-group">
<label>Agregar imagen</label>
<input type="file" name="archivo" class="form-control" placeholder="archivo" accept="image/*">
</div>
<?php
}
?>
<br />
<div class="form-group text-center">
<button class="btn btn-lg btn-primary">Almacenar escrito</button>
</div>
</form>