1 <style type="text/css">
\r
4 font-family: Courier New, Courier, monospace;
\r
17 include('../../../config.php');
\r
18 include_once(dirname(__FILE__).'/config.php'); //gallery config
\r
19 include_once($DIR_LIBS . 'ITEM.php');
\r
22 class NPG_PROMO_ACTIONS extends BaseActions {
\r
29 function NPG_PROMO_ACTIONS() {
\r
30 $this->BaseActions();
\r
33 function getdefinedActions() {
\r
37 'centeredtopmargin',
\r
43 function setTemplate(&$template) {$this->template = &$template;}
\r
44 function setParser(&$parser) {$this->parser =& $parser; }
\r
45 function setCurrentThumb(&$CurrentThumb) {$this->CurrentThumb = &$CurrentThumb;}
\r
47 function addimagethumbnail($thumbnails) {$this->thumbnails = $this->thumbnails . $thumbnails;}
\r
48 function needtoaddpromo() {if($this->thumbnails <> '') return true; return false;}
\r
50 function parse_images() { echo $this->thumbnails; }
\r
51 function parse_description() {echo $this->CurrentThumb->getdescription(); }
\r
52 function parse_thumbnail() {echo $this->CurrentThumb->getthumbfilename();}
\r
53 function parse_picturelink() {echo '<%gallery(link,picture,'.$this->CurrentThumb->getID().')%>';}
\r
54 function parse_centeredtopmargin($height = 140,$adjustment = 0) {
\r
55 $image_size = getimagesize($this->CurrentThumb->getthumbfilename());
\r
56 $topmargin = ((intval($height) - intval($image_size[1])) / 2) + intval($adjustment);
\r
57 echo 'margin-top: '.$topmargin.'px;';
\r
61 //globals for add_picture.php
\r
62 global $NPG_CONF,$gmember,$manager,$NP_BASE_DIR;
\r
64 if(!$NPG_CONF['temp_table']) {
\r
65 $NPG_CONF['temp_table'] = 'gallery_temp';
\r
66 setNPGoption('temp_table','gallery_temp');
\r
69 if(!$NPG_CONF['batch_add_num']) $NPG_CONF['batch_add_num'] = 10;
\r
71 //todo: display header
\r
73 if (!preg_match('/^([a-z0-9_]+|`[^`]+`)$/i',$NPG_CONF['temp_table'])) exit;
\r
74 $type = requestvar('type');
\r
77 $exist_temp_table = mysql_query('SELECT 1 FROM '.$NPG_CONF['temp_table'].' LIMIT 0');
\r
78 if ($exist_temp_table) sql_query('drop table '. $NPG_CONF['temp_table']);
\r
79 if(requestVar('id')) $albumid = requestVar('id'); else $albumid = 0;
\r
80 $number_of_uploads=$NPG_CONF['batch_add_num'];
\r
81 addPictureForm($albumid, $number_of_uploads);
\r
84 if(requestVar('id')) $albumid = requestVar('id'); else $albumid = 0;
\r
85 $result = mysql_query('create table '.$NPG_CONF['temp_table']
\r
86 .'(tempid int unsigned not null auto_increment PRIMARY KEY, '
\r
87 .'memberid int unsigned, '
\r
88 .'albumid int unsigned, '
\r
89 .'filename varchar(60), '
\r
90 .'intfilename varchar(60), '
\r
91 .'thumbfilename varchar(60), '
\r
92 .'title varchar(40), '
\r
93 .'description varchar(255), '
\r
94 .'promote tinyint unsigned default 0, '
\r
95 .'error varchar(60) default NULL)' );
\r
98 while ($uploadInfo = postFileInfo('uploadpicture'.$i)) {
\r
99 if ($filename = $uploadInfo['name']) {
\r
100 $filetype = $uploadInfo['type'];
\r
101 $filesize = $uploadInfo['size'];
\r
102 $filetempname = $uploadInfo['tmp_name'];
\r
103 //this gets picasa captions from ITPC metadata
\r
104 $size = getimagesize($filetempname, $info);
\r
105 if (isset($info["APP13"])) {
\r
106 $iptc = iptcparse($info["APP13"]);
\r
107 $description = $iptc["2#120"][0];
\r
109 //adds a picture to the temp table so user can add description, etc before actually adding to database
\r
110 add_temp($albumid, $filename, $filetype, $filesize, $filetempname,$description);
\r
114 addTempPictureForm($albumid);
\r
116 case 'massupload' :
\r
117 //if the referring address is not this page, drop the table.
\r
118 if(!stristr($_SERVER['HTTP_REFERER'],'add_picture.php')) {
\r
119 $exist_temp_table = mysql_query('SELECT 1 FROM '.$NPG_CONF['temp_table'].' LIMIT 0');
\r
120 if ($exist_temp_table) sql_query('drop table '. $NPG_CONF['temp_table']);
\r
121 echo 'starting a fresh massupload batch </br>';
\r
123 else echo '...continuing a massupload batch </br>';
\r
124 //create a table (if the table is already there, mysql just adds to the table)
\r
125 if(requestVar('id')) $albumid = requestVar('id'); else $albumid = 0;
\r
126 $result = mysql_query('create table '.$NPG_CONF['temp_table']
\r
127 .'(tempid int unsigned not null auto_increment PRIMARY KEY, '
\r
128 .'memberid int unsigned, '
\r
129 .'albumid int unsigned, '
\r
130 .'filename varchar(60), '
\r
131 .'intfilename varchar(60), '
\r
132 .'thumbfilename varchar(60), '
\r
133 .'title varchar(40), '
\r
134 .'description varchar(255), '
\r
135 .'promote tinyint unsigned default 0, '
\r
136 .'error varchar(60) default NULL)' );
\r
137 //checks to see how many files are in the upload directory
\r
138 if ($handle = opendir($NP_BASE_DIR.'upload')) {
\r
139 while (false !== ($filename = readdir($handle))) {
\r
140 if (stristr($filename,'jpeg') or stristr($filename,'jpg')){
\r
141 $scandir[] = $filename;
\r
145 $numpics = count($scandir);
\r
147 echo 'there are ' . $numpics .' pictures(jpg) left in the upload directory </br>';
\r
148 echo 'the massupload script will loop though '.$NPG_CONF['batch_add_num'].' pictures per time to prevent timeouts</br>';
\r
149 //if there are more than 10 files, remember to refresh,
\r
150 //this is to solve the incomplete database writes when scripts timeout
\r
151 //have to reopen the directory so it starts from the first file again
\r
152 $handle = opendir($NP_BASE_DIR.'upload');
\r
153 for ( $i=0; false !==($file=readdir($handle)) and $i<=$NPG_CONF['batch_add_num']; $i++ ) {
\r
154 if (stristr($file,'jpeg') or stristr($file,'jpg')){
\r
156 //echo $filename . 'uploaded </br>';
\r
157 $filetype = filetype($NP_BASE_DIR.'upload/' . $file);
\r
158 $filesize = filesize($NP_BASE_DIR.'upload/' . $file);
\r
159 $filetempname = $NP_BASE_DIR.'upload/' . $file;
\r
160 $size = getimagesize($filetempname, $info);
\r
161 //this gets picasa captions from ITPC metadata
\r
162 if (isset($info["APP13"])) {
\r
163 $iptc = iptcparse($info["APP13"]);
\r
164 $description = $iptc["2#120"][0];
\r
165 $description = addslashes($description);
\r
167 //adds a picture to the temp table so user can add description, etc before actually adding to database
\r
168 echo 'creating thumbnail for ';
\r
170 add_temp($albumid, $filename, $filetype, $filesize, $filetempname,$description);
\r
171 echo '.... done. </br>';
\r
176 //if there were more than 10 files, refresh, else proceed.
\r
177 if($numpics > $NPG_CONF['batch_add_num']){
\r
178 echo "<SCRIPT LANGUAGE=\"JavaScript\">window.location=\" ".$_SERVER['SCRIPT_NAME']."?type=massupload&id=".$albumid." \";</script>";
\r
180 addTempPictureForm($albumid);
\r
183 case 'addpictures':
\r
185 $promoallowed = postvar('promopost');
\r
186 $promo_ids = array();
\r
187 $setorpromo = $NPG_CONF['setorpromo'];
\r
189 if(!$NPG_CONF['template']) $NPG_CONF['template'] = 1;
\r
190 $template = & new NPG_TEMPLATE($NPG_CONF['template']);
\r
192 $actions = new NPG_PROMO_ACTIONS();
\r
193 $parser = new PARSER($actions->getdefinedActions(),$actions);
\r
194 $actions->setparser($parser);
\r
195 $actions->settemplate($template);
\r
197 while($tempid = postvar('tid'.$i)) {
\r
198 $title = postvar('title'.$i);
\r
199 $description = postvar('description'.$i);
\r
200 $promote = postvar('promote'.$i);
\r
201 $albumid = postvar('album'.$i);
\r
203 $filename = $NPG_CONF['galleryDir'].'/'.postvar('filename'.$i);
\r
204 $int_filename = postvar('intfilename'.$i);
\r
205 $thumb_filename = postvar('thumbfilename'.$i);
\r
206 $keywords = postvar('keywords'.$i);
\r
208 //check permissions to add
\r
209 if($gmember->canAddPicture($albumid)) {
\r
210 $pict = new PICTURE(0);
\r
211 $newid = $pict->add_new($albumid, $filename, $title, $description, $int_filename, $thumb_filename,$keywords);
\r
212 echo "$filename added<br/>";
\r
215 if ($promoallowed == '1' && $promote == 'yes') {
\r
217 $actions->setCurrentThumb($pict);
\r
218 $parser->parse($template->section['PROMO_IMAGES']);
\r
219 $capt = ob_get_contents();
\r
221 $actions->addimagethumbnail($capt);
\r
222 array_push($promo_ids, $newid);
\r
226 $manager->notify('NPgPostAddPicture',array('pictureid' => $newid));
\r
229 echo "$filename not added due to bad album permissions<br/>";
\r
231 if(file_exists($galleryDir.'/'.$filename)) unlink($galleryDir.'/'.$filename);
\r
232 if(file_exists($int_filename)) unlink($int_filename);
\r
233 if(file_exists($thumb_filename)) unlink($thumb_filename);
\r
240 if ($promoallowed == '1' && $actions->needtoaddpromo() ) {
\r
242 $today = getdate();
\r
243 $hour = $today['hours'];
\r
244 $minutes = $today['minutes'];
\r
245 $day = $today['mday'];
\r
246 $month = $today['mon'];
\r
247 $year = $today['year'];
\r
251 $parser->parse($template->section['PROMO_TITLE']);
\r
252 $title = ob_get_contents();
\r
254 if ($setorpromo=='promo'){
\r
256 $parser->parse($template->section['PROMO_BODY']);
\r
257 $body = ob_get_contents();
\r
260 if ($setorpromo=='sets'){
\r
261 $body = '<%gallery(keywords,'.$promokeywords.',desc)%>';
\r
266 <form><input type="button" value="<?php echo __NPG_PROMO_FORM_CANCEL; ?>" onclick="window.close()"/></form>
\r
267 <form method="post" action="add_picture.php"><div>
\r
268 <input type="hidden" name="type" value="promopost" />
\r
269 <input type="hidden" name="catid" value="<?php echo $NPG_CONF['blog_cat']; ?>" />
\r
270 <input type="hidden" name="hour" value="<?php echo $hour; ?>" />
\r
271 <input type="hidden" name="minutes" value="<?php echo $minutes; ?>" />
\r
272 <input type="hidden" name="day" value="<?php echo $day; ?>" />
\r
273 <input type="hidden" name="year" value="<?php echo $year; ?>" />
\r
274 <input type="hidden" name="month" value="<?php echo $month; ?>" />
\r
275 <input type="hidden" name="ids" value="<?php echo implode(",",$promo_ids); ?>" />
\r
277 <p><label for "title_f"><?php echo __NPG_PROMO_FORM_TITLE.'<br/>'; ?></label>
\r
278 <input type="text" name="title" id="title_f" value="<?php echo $title; ?>" /></p>
\r
280 <p><label for "body_f"><?php echo __NPG_PROMO_FORM_BODY.'<br/>'; ?></label>
\r
281 <textarea rows="10" cols="50" name="body" id="body_f" >
\r
282 <?php echo $body; ?></textarea></p>
\r
283 <input type="submit" value="<?php echo __NPG_PROMO_FORM_SUBMIT; ?>" />
\r
290 echo '<br/><hr/><br/>';
\r
291 echo '<form><input type="button" value="'.__NPG_PROMO_FORM_CLOSE.'" onclick="window.close()"/></form>';
\r
295 $exist_temp_table = mysql_query('SELECT 1 FROM '.$NPG_CONF['temp_table'].' LIMIT 0');
\r
296 if ($exist_temp_table) sql_query('drop table '. $NPG_CONF['temp_table']);
\r
302 $ids = explode(",", postvar('ids'));
\r
303 $result = ITEM::createFromRequest();
\r
304 if ($result['status'] == 'error')
\r
305 echo $result['message'];
\r
309 $query = 'insert into '.sql_table('plug_gallery_promo').' values ('.intval($ids[$j]).', '.intval($result['itemid']).')';
\r
313 echo __NPG_PROMO_FORM_SUCCESS.'<br/>';
\r
314 echo '<form><input type="button" value="' . __NPG_PROMO_FORM_CLOSE . '" onclick="window.close()"/></form>';
\r
320 if(requestVar('id')) $albumid = requestVar('id'); else $albumid = 0;
\r
321 $result = mysql_query('create temporary table '.$NPG_CONF['temp_table']
\r
322 .'(tempid int unsigned not null auto_increment PRIMARY KEY, '
\r
323 .'memberid int unsigned, '
\r
324 .'albumid int unsigned, '
\r
325 .'filename varchar(60), '
\r
326 .'intfilename varchar(60), '
\r
327 .'thumbfilename varchar(60), '
\r
328 .'title varchar(40), '
\r
329 .'description varchar(255), '
\r
330 .'promote tinyint unsigned default 0, '
\r
331 .'error varchar(60) default NULL)' );
\r
332 //creates an xml parser and puts the xml into an array
\r
333 $p = xml_parser_create();
\r
334 if (!($fp = fopen($NP_BASE_DIR."upload/index.xml", "r"))) {die("unable to open XML");}
\r
335 $contents = fread($fp, filesize($NP_BASE_DIR."upload/index.xml"));
\r
336 xml_parse_into_struct($p,$contents,$vals,$index);
\r
338 xml_parser_free($p);
\r
339 //get album item count and loop through the pictures, putting filename and description into the temp database
\r
340 $count = $index["ALBUMITEMCOUNT"][0];
\r
341 $albumitemcount = $vals[$count]["value"];
\r
342 for ($i=0; $i<$albumitemcount;$i++) {
\r
343 $count = $index["ITEMNAME"][$i];
\r
344 $filename = $vals[$count]["value"];
\r
345 $count = $index["ITEMCAPTION"][$i];
\r
346 $description = $vals[$count]["value"];
\r
347 $filename = trim($filename);
\r
348 $filetempname = $NP_BASE_DIR.'upload/images/' . $filename ;
\r
349 $filetype = filetype($filetempname);
\r
350 $filesize = filesize($filetempname);
\r
351 //adds a picture to the temp table so user can add description, etc before actually adding to database
\r
352 add_temp($albumid, $filename, $filetype, $filesize, $filetempname, $description);
\r
364 //adds a picture to the temp table so user can add description, etc before actually adding to database
\r
366 function add_temp($albumid = 0, $filename, $filetype, $filesize, $filetempname, $description = '') {
\r
367 global $NPG_CONF, $gmember, $NP_BASE_DIR,$manager;
\r
368 $memberid = $gmember->getID();
\r
369 if (!preg_match('/^([a-z0-9_]+|`[^`]+`)$/i',$NPG_CONF['temp_table'])) exit;
\r
370 $temp_table = $NPG_CONF['temp_table'];
\r
371 $int_filename = '';
\r
372 $thumb_filename = '';
\r
374 $defaulttitle = $filename;
\r
375 $NPG_CONF['randomprefix'] = 6;
\r
377 //add prefix to filename -- from http://www.phpdig.net/ref/rn22re349.html
\r
378 //or add current date to filename , option set in plugin admin
\r
379 $dateorrandom = $NPG_CONF['dateorrandom'];
\r
381 if ($dateorrandom == 'randomprefix'){
\r
383 for ($i = 0; $i < $NPG_CONF['randomprefix']; ++$i) {
\r
384 $str .= chr(rand() % 26 + 97);
\r
386 $filename = $str . $filename;
\r
388 if ($dateorrandom == 'dateprefix'){
\r
390 $str = date('Y-m-d');
\r
391 $filename = $str . $filename;
\r
395 if ($filesize > $NPG_CONF['max_filesize'])
\r
396 $error = 'FILE_TOO_BIG';
\r
398 //check filetype -- currently only jpeg supported
\r
399 if (eregi("\.jpeg$",$filename)) $ok = 1;
\r
400 if (eregi("\.jpg$",$filename)) $ok = 1;
\r
402 $error='BADFILETYPE';
\r
404 //check if gallery directory exists, try to create if it doesn't, check write permssions
\r
405 $mediadir = $NPG_CONF['galleryDir'];
\r
406 if (!@is_dir($NP_BASE_DIR.$mediadir)) {
\r
407 $error = 'Disallowed';
\r
408 $oldumask = umask(0000);
\r
409 if (!@mkdir($NP_BASE_DIR.$mediadir, 0777)) $error='Cannot create gallery directory';
\r
416 if (!is_writeable($NP_BASE_DIR.$mediadir)) $error = 'Gallery directory not writable';
\r
418 // add trailing slash (don't add it earlier since it causes mkdir to fail on some systems)
\r
420 //check if file already exists -- todo:if it does, add it to the database?
\r
421 if (file_exists($NP_BASE_DIR.$mediadir . $filename)) $error = 'UPLOADDUPLICATE';
\r
423 //move file : courtesy of Leslie Holmes www.CyberSparrow.com
\r
424 if (is_file($filetempname)) {
\r
425 if (@rename($filetempname,$NP_BASE_DIR. $mediadir . $filename)){
\r
426 // it worked, no problems
\r
427 } elseif (copy($filetempname,$NP_BASE_DIR. $mediadir . $filename)){
\r
428 // rename didn't work, so we tried copy and it worked, now delete original upload file
\r
429 unlink($filetempname);
\r
431 // neither method worked, so report error
\r
432 $error = 'ERROR_UPLOADCOPY,ERROR_UPLOADMOVE' ;
\r
436 $oldumask = umask(0000);
\r
437 @chmod($NP_BASE_DIR.$mediadir . $filename, 0644);
\r
440 if(($NPG_CONF['graphics_library']=='gd' && GDisPresent()) || ($NPG_CONF['graphics_library']=='im' && IMisPresent()) ) {
\r
441 //make intermediate file and thumbnail
\r
442 $int_filename = resizeImage($mediadir.$filename, $NPG_CONF['maxwidth'], $NPG_CONF['maxheight'], $mediadir.$NPG_CONF['int_prefix'].$filename);
\r
443 $thumb_filename = resizeImage($mediadir.$filename, $NPG_CONF['thumbwidth'], $NPG_CONF['thumbheight'], $mediadir.$NPG_CONF['thumb_prefix'].$filename);
\r
446 $error = 'Graphics library not configured properly';
\r
458 $query = 'insert into '
\r
460 .'(tempid,memberid,albumid,filename,intfilename,thumbfilename,title,description,promote,error)'
\r
461 ." values (NULL, ".intval($memberid).", ".intval($albumid).", '".addslashes($filename)."', '".addslashes($int_filename)."', '".addslashes($thumb_filename)."', '".addslashes($defaulttitle)."', '".addslashes($description)."', 0, '".addslashes($error)."') ";
\r
462 //echo $query.'<br/>';
\r
463 $result = sql_query($query);
\r