Advertisement
Guest User

eblimgedit edits

a guest
Jan 28th, 2015
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.82 KB | None | 0 0
  1. if (@txpinterface == 'admin')
  2. {
  3. add_privs('eblimgeditext', '1');
  4. register_tab("extensions", "eblimgeditext", "Image Edit");
  5. register_callback("ebl_image_edit_ext", "eblimgeditext");
  6.  
  7. switch (gps('event'))
  8. {
  9. case 'eblrotateleft':
  10. ebl_img_edit(gps('imgid'), 'left', 'rotate'); exit();
  11. break;
  12. case 'eblrotateright':
  13. ebl_img_edit(gps('imgid'), 'right', 'rotate'); exit();
  14. break;
  15. case 'eblrotateup':
  16. ebl_img_edit(gps('imgid'), 'up', 'rotate'); exit();
  17. break;
  18. case 'eblimgcrop':
  19. ebl_img_edit(gps('imgid'), '', 'crop'); exit();
  20. break;
  21. case 'eblimgcrop':
  22. ebl_processUpload(gps('uploadType'));
  23. break;
  24. case 'ebltmbcrop':
  25. ebl_img_edit(gps('imgid'), '', 'thumbnail'); exit();
  26. break;
  27. case 'eblrszimg':
  28. ebl_img_edit(gps('imgid'), '', 'rsz'); exit();
  29. break;
  30. case 'eblbackupimg':
  31. eblbackupimg(gps('imgid'));
  32. break;
  33. case 'eblrestoreimg':
  34. eblrestoreimg(gps('imgid'));
  35. break;
  36. }
  37. }
  38.  
  39. function ebl_image_edit_ext()
  40. {
  41.  
  42. $step = gps('step');
  43.  
  44. $message = (is_callable($step)) ? $step() : '';
  45.  
  46. echo pagetop("EBL Image Edit Preferences", $message);
  47.  
  48. echo '<div style="margin: 0 auto; width: 400px;">'.n.
  49. ebl_list_cropStyles().
  50. '</div>';
  51. }
  52.  
  53. function ebl_list_cropStyles()
  54. {
  55. global $txp_user, $path_to_site, $img_dir;
  56.  
  57. $backupdir = $path_to_site . '/' . $img_dir . '/backup/';
  58. if(!file_exists($backupdir)) {
  59.  
  60. $createEBLtable = safe_query("CREATE TABLE `".PFX."ebl_crop` (".
  61. "`name` varchar(64) NOT NULL,".
  62. "`width` varchar(16) NOT NULL,".
  63. "`height` varchar(16) NOT NULL,".
  64. "`thumb` varchar(1) NOT NULL default '0',".
  65. "UNIQUE KEY `name` (`name`)".
  66. ");");
  67.  
  68. $rs = safe_insert('ebl_crop', "`name` = 'Image Crop', `width` = '500',`height` = '500', `thumb` = '0'");
  69. $rs = safe_insert('ebl_crop', "`name` = 'Thumbnail Square', `width` = '100',`height` = '100', `thumb` = '1'");
  70.  
  71. $mkdir = (@mkdir($backupdir)) ? TRUE : FALSE;
  72. if($mkdir) {
  73. echo "<p style=\"text-align: center; \">$backupdir did not exist previously. Now created.</p>";
  74. } else {
  75. echo "<p style=\"text-align: center; font-weight: bold; \">Unable to create $backupdir. Please check your folder permissions.</p>";
  76. }
  77. }
  78.  
  79.  
  80.  
  81. echo n.n.hed(gTxt('Crop Styles'), 1, ' style="text-align: center; margin-top:2em; font-weight: bold;"').
  82. n.n.startTable('list','','txp-list').
  83. n.'<thead>'.tr(
  84. n.hCell(gTxt('name')).
  85. n.hCell(gTxt('width')).
  86. n.hCell().
  87. n.hCell(gTxt('height')).
  88. n.hCell(gTxt('thumbnail')).
  89. n.hCell(gTxt('delete'))
  90. ).'</thead>';
  91.  
  92. $rs = safe_rows_start('*', 'ebl_crop', '1=1 ORDER BY `name`');
  93.  
  94. $out = '';
  95.  
  96. if ($rs)
  97. {
  98. while ($a = nextRow($rs))
  99. {
  100. $isChecked = ($a['thumb'] == 1) ? 'yes' : 'no';
  101. $out .= n.tr(
  102. td( htmlspecialchars($a['name'])).
  103. td( htmlspecialchars($a['width'])).
  104. td( htmlspecialchars(' X ')).
  105. td( htmlspecialchars($a['height'])).
  106. td( $isChecked).
  107. td(
  108. dLink('eblimgeditext', 'ebl_cropdelete', 'stylename', $a['name'])
  109. )
  110. );
  111. }
  112. }
  113.  
  114. echo form($out);
  115.  
  116. echo n.tr(
  117. form(
  118. td( fInput('text', 'name', '', 'edit','','',10) ).
  119. td( fInput('text', 'width', '', 'edit','','',5) ).
  120. td().
  121. td( fInput('text', 'height', '', 'edit','','',5) ).
  122. td( '<input name="eblistmb" class="checkbox" type="checkbox">').
  123. td( fInput('submit', 'add', gTxt('add'), 'smallerbox') ).
  124. n.eInput('eblimgeditext').
  125. n.sInput('ebl_cropsavenew')
  126. )
  127. );
  128.  
  129. echo n.endTable();
  130. }
  131.  
  132. function selectStyles($thumb = '0') {
  133.  
  134. $rs = safe_rows_start('*', 'ebl_crop', 'thumb='.$thumb.' ORDER BY `name`');
  135.  
  136. $out = "<select name=\"customsize\" id=\"customsize$thumb\">' + ".n.
  137. "'<option value=\"Custom\">Custom</option>' + ".n;
  138.  
  139. if ($rs)
  140. {
  141. while ($a = nextRow($rs))
  142. {
  143. $width = $a['width'];
  144. $height = $a['height'];
  145. $name = $a['name'];
  146.  
  147. $out .= "'<option value=".$width."x".$height."\>".htmlspecialchars($name)." : $width x $height </option>' + ".n;
  148. }
  149. }
  150. $out .= "'</select>";
  151.  
  152. return $out;
  153. }
  154. function ebl_cropsavenew()
  155. {
  156.  
  157. extract(doSlash(psa(array('name', 'width','height','eblistmb'))));
  158.  
  159. if ($name && is_numeric($width) && is_numeric($height))
  160. {
  161. $eblistmb = ($eblistmb == "on") ? 1 : 0;
  162.  
  163. $rs = @safe_insert('ebl_crop', "
  164. `name` = '$name',
  165. `width` = '$width',
  166. `height` = '$height',
  167. `thumb` = '$eblistmb'");
  168.  
  169. return ($rs) ?
  170. "New crop style created" :
  171. "<b>Error:</b> Duplicate Name";
  172.  
  173. } else {
  174.  
  175. return "<b>Width</b> and <b>Height</b> must be numeric values";
  176. }
  177.  
  178. return FALSE;
  179. }
  180.  
  181. function ebl_cropdelete()
  182. {
  183. $name = ps('stylename');
  184. return (safe_delete('ebl_crop', "`name` = '".doSlash($name)."'")) ?
  185. "<b>Deleted</b> $name" :
  186. "<b>Error</b> Unable to delete $name";
  187. }
  188.  
  189.  
  190. if(gps('step') == 'image_edit' || gps('step') == 'thumbnail_insert' || gps('step') == 'image_replace' || gps('step') == 'thumbnail_create' || gps('step') == 'thumbnail_delete') {
  191. register_callback('ebl_imgcrop', 'admin_side', 'head_end');
  192. }
  193.  
  194. function ebl_imgcrop() {
  195.  
  196. global $path_to_site,$img_dir;
  197.  
  198. $id=gps('id');
  199. $imagedir = hu . $img_dir . '/';
  200.  
  201. $rs = @safe_row("*, unix_timestamp(date) as uDate", "txp_image", "id = $id");
  202.  
  203. if ($rs) {
  204. extract($rs);
  205. $filename = $id.$ext;
  206. $imgsrc = $imagedir.$filename;
  207. $tmbsrc = $imagedir.$id.'t'.$ext;
  208. }
  209.  
  210. $customThumbSize = selectStyles(1);
  211. $customImgSize = selectStyles(0);
  212.  
  213. echo <<< EOF
  214. <script src="jcrop/jquery.Jcrop.pack.js"></script>
  215. <link href="jcrop/jquery.Jcrop.css" rel="stylesheet" type="text/css" />
  216. <style type="text/css">
  217. #eblimgprocess {
  218. margin: 5px;
  219. font-weight: bold;
  220. font-size: 14pt;
  221. color: #550000;
  222. padding: 0 0 0 20px;
  223. background: url('jcrop/processing.gif') left no-repeat;
  224. }
  225. a { padding: 0 0 3px;}
  226. a:visited {} a:hover {} a:active { border: 0; }
  227. a:focus { outline: 0; text-decoration: none;}
  228. .jcrop-holder{margin:20px auto 40px}
  229. .fit img { max-width: 60%; } // Stacey's edit to style the full size img so that it isn't too big on screen
  230. </style>
  231. <script type="text/javascript">
  232. $(document).ready(function() { // init everything
  233.  
  234. $("#image_container .fullsize-image img").attr('id','mainImg'); // Give our image an ID
  235. $("#image_container .fullsize-image").attr('class','fullsize-image fit'); // Stacey's edit to give div class 'fit'
  236.  
  237. $('.thumbnail-edit img').attr('id','thumb'); // Give our thumbnail image an ID
  238. $('.thumbnail-edit').attr('id','thumbTD'); // name the TD that contains the image so we can swap it out.
  239.  
  240. if(! $('#thumbTD').length ) { $(".thumbnail-upload").attr('id','thumbTD'); }
  241.  
  242. $('#image_container').prepend('<section id="eblcropui" class="txp-edit"></section>');
  243.  
  244. $('#eblcropui').append('<section role="region" id="eblcontainer_group" class="txp-details" aria-labelledby="eblcontainer_group-label"><h3 id="eblcontainer_group-label">Edit Image</h3><div role="group" id="eblcontainer"></div></section>');
  245.  
  246. $('#eblcontainer').append(
  247. '<p class="nav-tertiary">' +
  248. '<a href="#" id="eblcroplnk" class="navlink">Crop</a>' +
  249. '<a href="#" id="ebltmblnk" class="navlink">Thumbnail</a>' +
  250. '<a href="#" id="eblrotatelnk" class="navlink">Rotate</a>' +
  251. '<a href="#" id="eblresizelnk" class="navlink">Resize</a>' +
  252. '<a href="#" id="eblbackuplnk" class="navlink">Backup</a>' +
  253. '</p>'
  254. );
  255.  
  256. $('#eblcontainer').append('<div id="eblcropdata"></div><div id="eblcropctrl"></div><div id="ebltmbctrl"></div><div id="eblrotatectrl"></div><div id="eblresize"></div><div id="eblbackupimg"></div><div id="eblhiddendata"></div><div id="eblimgprocess"> Processing...</div>');
  257.  
  258. $('#eblcropctrl').append(
  259. '<input type="hidden" id="eblcropHh" name="eblcropH" value="" />' +
  260. '<input type="hidden" id="eblcropWh" name="eblcropW" value="" />' +
  261. '<input type="hidden" id="eblcropXh" name="eblcropXh" value="" />' +
  262. '<input type="hidden" id="eblcropYh" name="eblcropYh" value="" />'
  263. );
  264.  
  265. $('#eblcropctrl').append(
  266. '<p>Use predefined size: $customImgSize | <input name="aspectratio" type="checkbox" id="imgaspectratio" value="" /> Lock Aspect Ratio </p>' +
  267. '<p><input type="submit" name="$id" id="eblimgcrop" value="Crop Original" class="smallerbox" /></p>'
  268. );
  269.  
  270. $('#ebltmbctrl').append(
  271. '</p><p>Use predefined size: $customThumbSize | ' +
  272. '<input name="aspectratio" type="checkbox" id="tmbaspectratio" value="" /> Lock Aspect Ratio </p></p><p> Thumbnail Dimensions: ' +
  273. '( W: <input name="ebltmbW" type="text" id="ebltmbW" size="5" maxlength="4" value="100" /> ) x ' +
  274. '( H: <input name="ebltmbH" type="text" id="ebltmbH" size="5" maxlength="4" value="100" /> )' +
  275. '| <input name="cropthumb" type="checkbox" id="cropthumb" checked="true"/> Resize Thumbnail ' +
  276. '</p><p>' +
  277. '<input type="button" name="$id" id="ebltmbcrop" value="Create Thumbnail" class="smallerbox" />' +
  278. '</p>'
  279. );
  280.  
  281. $('#eblrotatectrl').append(
  282. '<p>Rotate <input type="button" name="$id" id="rotateright" value="Clockwise 90&deg;" class="smallerbox" /> ' +
  283. '<input type="button" name="$id" id="rotateleft" value="Counterclockwise 90&deg; " class="smallerbox" /> ' +
  284. '<input type="button" name="$id" id="rotateup" value="180 &deg; " class="smallerbox" />' +
  285. '</p>'
  286. );
  287.  
  288. $('#eblbackupimg').append(
  289. '<p><input type="button" name="$id" id="eblbackup" value="Backup" class="smallerbox" /> ' +
  290. '<input type="button" name="$id" id="eblrestore" value="Restore" class="smallerbox" />' +
  291. '</p>'
  292. );
  293.  
  294. $('#eblresize').append(
  295. '<p>Current Image Size : W[ <span id="origW"></span> ] x H[ <span id="origH"></span> ]</p>' +
  296. '<p><label for="eblrszW">Width: </label><input type="text" name="eblrszW" id="eblrszW" /> x ' +
  297. '<label for="eblrszH">Height: </label><input type="text" name="eblrszH" id="eblrszH" /> ' +
  298. '<input type="button" name="$id" id="eblrszimg" value="Resize" class="smallerbox" />' +
  299. '</p>'
  300. );
  301.  
  302. $('#eblcropdata').append(
  303. '<p>Current Crop Area (W: <span style="font-weight: bold;" id="eblcropW">0</span>) x (H: <span style="font-weight: bold;" id="eblcropH">0</span>)</p>'
  304. );
  305.  
  306. $('#eblcropctrl,#eblrotatectrl,#eblresize,#ebltmbctrl,#eblcropdata,#eblimgprocess,#eblbackupimg').hide();
  307.  
  308.  
  309. // set our defaults
  310. window.crop = false;
  311. window.tmbcrop = false;
  312.  
  313. $('#mainImg').wrap('<div id="imgDiv"></div');
  314. $('#imgaspectratio,#tmbaspectratio').attr('disabled', true).attr('checked', false);
  315.  
  316.  
  317. function removeCrop() {
  318. // Removes jCrop if found.
  319. if ( $('.jcrop-holder').length ) {
  320. var x = $('#imgDiv');
  321.  
  322. // generate random number to append to img url to avoid cache issues
  323. var rand = Math.random();
  324.  
  325. // hide Width/Height data
  326. $('#eblcropdata').hide();
  327.  
  328. // replace removed content with just the image.
  329. x.empty().append('<img src="$imgsrc?' + rand +'" id="mainImg" />');
  330. window.myCrop = '';
  331. }
  332.  
  333. window.cropOn = false;
  334. window.crop = false;
  335. window.tmbcrop = false;
  336. }
  337.  
  338. function addCrop() {
  339. // Bind jCrop to #mainImg
  340. var aspectratio = $('#aspectratio').attr('checked') ? 1 : 0; // Thanks Manfre
  341.  
  342. // Display H X W
  343. $('#eblcropdata').show();
  344.  
  345. // check if the jcrop holder is already active. Load if not active.
  346. if (! $('.jcrop-holder').length ) {
  347. window.myCrop = $.Jcrop('#mainImg',{
  348. onSelect: showCoords,
  349. onChange: showCoords,
  350. onDblClick: function(){
  351. if($('#eblcropctrl').is(':visible')){
  352. $('#eblimgcrop').click();
  353. }else if($('#ebltmbctrl').is(':visible')){
  354. $('#ebltmbcrop').click();
  355. }
  356. },
  357. aspectRatio: aspectratio
  358. });
  359. myCrop.setSelect([ 0, 0, 100, 150 ]);
  360. }
  361. window.cropOn = true;
  362. }
  363.  
  364. $('#eblcroplnk').click(function () {
  365. $(this).css({'font-weight':'bold'});
  366. $('#image_container .fullsize-image').toggleClass('fit'); // Stacey's edit to make image full size for cropping
  367. $('#eblresizelnk,#eblrotatelnk,#ebltmblnk,#eblbackuplnk').css('font-weight','normal');
  368. $('#eblrotatectrl,#ebltmbctrl,#eblresize,#eblrotatectrl,#eblbackupimg').hide();
  369. $('#eblcropctrl').toggle();
  370.  
  371.  
  372. if(window.crop && window.cropOn) { // user closed main crop function
  373. window.crop = false;
  374. removeCrop(); // remove the crop binding
  375. } else if (!window.crop && window.cropOn) { // user switched from thumb crop
  376. window.tmbcrop = false;
  377. window.crop = true;
  378. $('#imgaspectratio,#tmbaspectratio').attr('disabled', true).attr('checked', false);
  379. $('#customsize0').val('Custom');
  380. myCrop.setOptions({aspectRatio: 0});
  381. myCrop.animateTo([ 0, 0, 100, 150 ]);
  382. } else { // user opened main crop function
  383. addCrop(); // add crop binding
  384. window.crop = true;
  385. }
  386. });
  387.  
  388. $('#ebltmblnk').click(function () {
  389. $(this).css('font-weight', 'bold');
  390. $('#eblresizelnk,#eblrotatelnk,#eblcroplnk,#eblbackuplnk').css('font-weight','normal');
  391. $('#ebltmbctrl').toggle();
  392. $('#eblrotatectrl,#eblcropctrl,#eblresize,#eblrotatectrl,#eblbackupimg').hide();
  393.  
  394. if(window.tmbcrop && window.cropOn) { // user closed thumb crop
  395. window.tmbcrop = false;
  396. removeCrop();
  397. } else if (!window.tmbcrop && window.cropOn) { // user switched from main crop
  398. window.tmbcrop = true;
  399. window.crop = false;
  400. $('#imgaspectratio,#tmbaspectratio').attr('disabled', true).attr('checked', false);
  401. $('#customsize1').val('Custom');
  402. myCrop.setOptions({aspectRatio: 0});
  403. myCrop.animateTo([ 0, 0, 100, 150 ]);
  404. } else { // user opens thumb crop
  405. addCrop();
  406. window.tmbcrop = true;
  407. }
  408.  
  409. });
  410.  
  411. $('#eblrotatelnk').click(function () {
  412. $(this).css('font-weight', 'bold');
  413. $('#eblresizelnk,#ebltmblnk,#eblcroplnk,#eblbackuplnk').css('font-weight','normal');
  414. $('#eblcropctrl,#ebltmbctrl,#eblresize,#eblcropdata,#eblbackupimg').hide();
  415. $('#eblrotatectrl').toggle();
  416.  
  417. removeCrop();
  418. window.myCrop = ' ';
  419. window.crop = false;
  420. });
  421.  
  422. $('#eblresizelnk').click(function () {
  423. $(this).css('font-weight', 'bold');
  424. $('#eblrotatelnk,#ebltmblnk,#eblcroplnk,#eblbackuplnk').css('font-weight','normal');
  425. $('#eblrotatectrl,#eblcropctrl,#ebltmbctrl,#eblrotatectrl,#eblcropdata,#eblbackupimg').hide();
  426. $('#eblresize').toggle();
  427.  
  428. var imgW = $('#mainImg').width();
  429. var imgH = $('#mainImg').height();
  430.  
  431. $('#origW').text(imgW);
  432. $('#origH').text(imgH);
  433.  
  434. removeCrop();
  435. });
  436.  
  437. $('#rotateleft').click(function () {
  438. removeCrop();
  439. var id = $('#rotateright').attr('name');
  440.  
  441. var rand = Math.random();
  442. $('#eblimgprocess').show();
  443. $.ajax({
  444. type: "POST",
  445. url: "index.php?event=eblrotateleft&imgid="+id,
  446. success: function(html){
  447. if(html.match(/success/)) {
  448. $('#eblimgprocess').hide();
  449. var x = $('#imgDiv');
  450. x.empty().append('<img src="$imgsrc?' + rand +'" id="mainImg" />');
  451. } else {
  452. alert(html);
  453. }
  454. }
  455. });
  456. });
  457.  
  458. $('#rotateright').click(function () {
  459. removeCrop();
  460. var id = $('#rotateright').attr('name');
  461. var rand = Math.random();
  462. $('#eblimgprocess').show();
  463. $.ajax({
  464. type: "POST",
  465. url: "index.php?event=eblrotateright&imgid="+id,
  466. success: function(html){
  467. if(html.match(/success/)) {
  468. $('#eblimgprocess').hide();
  469. var x = $('#imgDiv');
  470. x.empty().append('<img src="$imgsrc?' + rand +'" id="mainImg" />');
  471. } else {
  472. alert(html);
  473. }
  474. }
  475. });
  476. });
  477.  
  478. $('#rotateup').click(function () {
  479. removeCrop();
  480. var id = $('#rotateright').attr('name');
  481. var rand = Math.random();
  482. $('#eblimgprocess').show();
  483. $.ajax({
  484. type: "POST",
  485. url: "index.php?event=eblrotateup&imgid="+id,
  486. success: function(html){
  487. if(html.match(/success/)) {
  488. $('#eblimgprocess').hide();
  489. var x = $('#imgDiv');
  490. x.empty().append('<img src="$imgsrc?' + rand +'" id="mainImg" />');
  491. } else {
  492. alert(html);
  493. }
  494. }
  495. });
  496. });
  497.  
  498. $('#eblimgcrop').click(function () {
  499. var id = $('#eblimgcrop').attr('name');
  500. var H = $('#eblcropHh').attr('value');
  501. var W = $('#eblcropWh').attr('value');
  502. var X = $('#eblcropXh').attr('value');
  503. var Y = $('#eblcropYh').attr('value');
  504. $('#eblimgprocess').show();
  505. var rand = Math.random();
  506. $.ajax({
  507. type: "POST",
  508. url: "index.php?event=eblimgcrop&imgid="+id,
  509. data: "&eblcropXh=" + X + "&eblcropYh=" + Y + "&eblcropW=" + W + "&eblcropH=" + H,
  510. success: function(html){
  511. $('#eblimgprocess').hide();
  512. if(html.match(/success/)) {
  513. removeCrop();
  514. $('#eblcropctrl').toggle();
  515. } else {
  516. alert(html);
  517. }
  518. }
  519. });
  520. });
  521.  
  522. $('#ebltmbcrop').click(function () {
  523. var id = $('#eblimgcrop').attr('name');
  524. var H = $('#eblcropHh').attr('value');
  525. var W = $('#eblcropWh').attr('value');
  526. var X = $('#eblcropXh').attr('value');
  527. var Y = $('#eblcropYh').attr('value');
  528.  
  529. var tH = $('#ebltmbH').attr('value');
  530. var tW = $('#ebltmbW').attr('value');
  531.  
  532. $('#eblimgprocess').show();
  533. var rszTmb = $('#cropthumb').attr('checked') ? 'rsz' : 'no';
  534.  
  535. var rand = Math.random();
  536. $.ajax({
  537. type: "POST",
  538. url: "index.php?event=ebltmbcrop&imgid="+id,
  539. data: "&rszTmb=" + rszTmb + "&eblcropXh=" + X + "&eblcropYh=" + Y + "&eblcropW=" + W + "&eblcropH=" + H + "&ebltmbH=" + tH + "&ebltmbW=" + tW,
  540. success: function(html){
  541. $('#eblimgprocess').hide();
  542. if(html.match(/success/)) {
  543. removeCrop();
  544. $('#thumbTD #thumb').remove();
  545. $('#thumbTD').prepend('<img src="$tmbsrc?' + rand +'" id="thumb" class="content-image" />'); $('#ebltmbctrl').toggle();
  546. } else {
  547. alert(html);
  548. }
  549. }
  550. });
  551. });
  552.  
  553. $('#eblrszimg').click(function () {
  554. var id = $('#eblrszimg').attr('name');
  555. var H = $('#eblrszH').attr('value');
  556. var W = $('#eblrszW').attr('value');
  557.  
  558. $('#eblimgprocess').show();
  559.  
  560. var rand = Math.random();
  561. $.ajax({
  562. type: "POST",
  563. url: "index.php?event=eblrszimg&imgid="+id,
  564. data: "&eblrszH=" + H + "&eblrszW=" + W,
  565. success: function(html){
  566. $('#eblimgprocess').hide();
  567. if(html.match(/success/)) {
  568. var x = $('#imgDiv');
  569. x.empty().append('<img src="$imgsrc?' + rand +'" id="mainImg" />');
  570. //
  571. } else {
  572. alert(html);
  573. }
  574. }
  575. });
  576. });
  577.  
  578.  
  579. $('#eblbackuplnk').click(function () {
  580. $(this).css('font-weight', 'bold');
  581. $('#eblrotatelnk, #eblresizelnk,#ebltmblnk,#eblcroplnk').css('font-weight','normal');
  582. $('#eblrotatectrl,#eblcropctrl,#ebltmbctrl,#eblresize,#eblrotatectrl,#eblcropdata').hide();
  583. $('#eblbackupimg').toggle();
  584.  
  585. removeCrop();
  586. window.myCrop = ' ';
  587. window.crop = false;
  588. });
  589.  
  590. $('#eblbackup').click(function () {
  591. var id = $(this).attr('name');
  592. $('#eblimgprocess').show();
  593. $.ajax({
  594. type: "POST",
  595. url: "index.php?event=eblbackupimg&imgid="+id,
  596. success: function(html){
  597. if(html.match(/success/)) {
  598. $('#eblimgprocess').hide();
  599. alert("image backed up");
  600. } else {
  601. $('#eblimgprocess').hide();
  602. alert("Error : " + id + " | " + html);
  603. }
  604. }
  605. });
  606. });
  607.  
  608. $('#eblrestore').click(function () {
  609. var id = $(this).attr('name');
  610. $('#eblimgprocess').show();
  611. var rand = Math.random();
  612. $.ajax({
  613. type: "POST",
  614. url: "index.php?event=eblrestoreimg&imgid="+id,
  615. success: function(html){
  616. if(html.match(/success/)) {
  617. $('#eblimgprocess').hide();
  618. var x = $('#imgDiv');
  619. x.empty().append('<img src="$imgsrc?' + rand +'" id="mainImg" />');
  620. alert("image restored");
  621. } else {
  622. $('#eblimgprocess').hide();
  623. alert("Error : " + html);
  624. }
  625. }
  626. });
  627. });
  628.  
  629. $('#customsize0,#customsize1').change(function () {
  630. var size = $(this).val();
  631. if(!size.match("Custom")) {
  632. $('#imgaspectratio,#tmbaspectratio').attr('disabled', false).attr('checked', true);
  633. var x = size.split('x')[0];
  634. var y = size.split('x')[1];
  635.  
  636. myCrop.animateTo([ 0, 0, x, y ]);
  637.  
  638. var aspectratio = x / y;
  639.  
  640. var opt = {
  641. aspectRatio: aspectratio
  642. }
  643.  
  644. myCrop.setOptions(opt);
  645. } else {
  646. $('#imgaspectratio,#tmbaspectratio').attr('disabled', true).attr('checked', false);
  647. myCrop.setOptions({aspectRatio: 0});
  648. }
  649.  
  650. });
  651.  
  652. $('#imgaspectratio,#tmbaspectratio').change(function () {
  653. if($(this).attr('checked'))
  654. {
  655. if(this.id === 'imgaspectratio')
  656. {
  657. var size = $('#customsize0').val();
  658. } else {
  659. var size = $('#customsize1').val();
  660. }
  661.  
  662. var x = size.split('x')[0];
  663. var y = size.split('x')[1];
  664.  
  665. var aspectratio = x / y;
  666. myCrop.animateTo([ 0, 0, x, y ]);
  667.  
  668. } else {
  669. var aspectratio = 0;
  670.  
  671. }
  672.  
  673. var opt = {
  674. aspectRatio: aspectratio
  675. }
  676. myCrop.setOptions(opt);
  677. });
  678.  
  679. $('#cropthumb').change(function () {
  680. var cropthumb = $(this).attr('checked') ? false : true;
  681.  
  682. if(cropthumb) {
  683. $('#ebltmbW, #ebltmbH').attr({disabled:"disabled",value:"###"});
  684. } else {
  685. $('#ebltmbW, #ebltmbH').removeAttr("disabled");
  686. $('#ebltmbW, #ebltmbH').attr("value","100");
  687. }
  688. });
  689.  
  690. });
  691.  
  692. function showCoords(c) {
  693. $('#eblcropX').text(c.x);
  694. $('#eblcropXh').val(c.x);
  695. $('#eblcropY').text(c.y);
  696. $('#eblcropYh').val(c.y);
  697. $('#eblcropX2').text(c.x2);
  698. $('#eblcropX2h').val(c.x2);
  699. $('#eblcropY2').text(c.y2);
  700. $('#eblcropY2h').val(c.y2);
  701.  
  702. var imgW = zeroPad(c.w,4);
  703. var imgH = zeroPad(c.h,4);
  704.  
  705. $('#eblcropW').text(imgW);
  706. $('#eblcropWh').val(c.w);
  707. $('#eblcropH').text(imgH);
  708. $('#eblcropHh').val(c.h);
  709. };
  710.  
  711. function zeroPad(num,count) {
  712. var numZeropad = num + '';
  713. while(numZeropad.length < count) {
  714. numZeropad = "0" + numZeropad;
  715. }
  716. return numZeropad;
  717. }
  718.  
  719. </script>
  720. EOF;
  721.  
  722. }
  723.  
  724. function eblrestoreimg($id)
  725. {
  726.  
  727. global $path_to_site,$img_dir;
  728.  
  729. $rs = safe_row("*, unix_timestamp(date) as uDate", "txp_image", "id = $id");
  730.  
  731. if ($rs) {
  732. $backupdir = $path_to_site . '/' . $img_dir . '/backup/';
  733. $imagedir = $path_to_site . '/' . $img_dir . '/';
  734.  
  735. extract($rs);
  736. $filename = $id.$ext;
  737. $imgsrc = $imagedir.$filename;
  738.  
  739. if(copy($backupdir.$filename, $imagedir.$filename))
  740. {
  741. list($width, $height) = getimagesize($backupdir.$filename);
  742. if(safe_update('txp_image', "w = '".$width."', h = '".$height."'", "id = $id"))
  743. {
  744. echo "success"; exit();
  745. } else {
  746. echo "File Copied but db not updated";
  747. }
  748. }
  749. } else {
  750. echo "Database Error";
  751. }
  752.  
  753. exit();
  754. }
  755.  
  756. function eblbackupimg($id)
  757. {
  758. global $path_to_site,$img_dir;
  759.  
  760. $rs = safe_row("*, unix_timestamp(date) as uDate", "txp_image", "id = $id");
  761.  
  762. if ($rs) {
  763. $backupdir = $path_to_site . '/' . $img_dir . '/backup/';
  764. $imagedir = $path_to_site . '/' . $img_dir . '/';
  765.  
  766. extract($rs);
  767. $filename = $id.$ext;
  768. $imgsrc = $imagedir.$filename; echo $imagedir.$filename;
  769.  
  770. $cr = copy($imagedir.$filename,$backupdir.$filename);
  771. echo "success";
  772. } else {
  773. echo "Database Error";
  774. }
  775.  
  776. exit();
  777. }
  778.  
  779. function ebl_img_edit ($id, $direction, $action)
  780. {
  781. global $path_to_site,$img_dir;
  782.  
  783. $imagedir = $path_to_site . '/' . $img_dir . '/';
  784.  
  785. $rs = safe_row("*, unix_timestamp(date) as uDate", "txp_image", "id = $id");
  786.  
  787. if ($rs) {
  788. extract($rs);
  789. $filename = $id.$ext;
  790.  
  791. switch (strtolower($ext)) {
  792. case '.jpg':
  793. $srcimage = imagecreatefromjpeg($imagedir . $filename);
  794. break;
  795. case '.gif':
  796. $srcimage = imagecreatefromgif($imagedir . $filename);
  797. break;
  798. case '.png':
  799. $srcimage = imagecreatefrompng($imagedir . $filename);
  800. break;
  801. }
  802.  
  803. if($action == 'rotate') { // rotate image
  804.  
  805. /** Ternary equivalent of if / elseif / else : Done for simple shorthand. Assumes anything not right / left = 180 **/
  806. $degrees = ($direction == 'right') ? -90 : (($direction == 'left') ? 90 : 180);
  807. $newimg = imagerotate($srcimage, $degrees, 0);
  808. } elseif ($action == 'crop') { // primary image cropping
  809.  
  810. //gather crop variables from hidden fields.
  811. $cropX = gps('eblcropXh');
  812. $cropY = gps('eblcropYh');
  813. $targW = $cropW = gps('eblcropW');
  814. $targH = $cropH = gps('eblcropH');
  815.  
  816. // prevents division by zero & invalid crop widths.
  817. $value = (int)$targH + (int)$targW;
  818. if($value < 30) {
  819. echo "invalid crop values detected";
  820. imagedestroy($srcimage);
  821. exit();
  822. }
  823.  
  824. /** Create base canvas **/
  825. $newimg = imagecreatetruecolor($targW,$targH);
  826.  
  827. /** Use the X/Y coords to plot the initial point, width/height take care of the rest **/
  828. imagecopyresampled($newimg, $srcimage,0,0, $cropX, $cropY, $targW, $targH, $cropW, $cropH);
  829.  
  830. } elseif ($action == 'thumbnail') { // create thumbnail
  831.  
  832. //gather crop variables from hidden fields.
  833. $cropX = gps('eblcropXh');
  834. $cropY = gps('eblcropYh');
  835. $cropH = gps('eblcropH');
  836. $cropW = gps('eblcropW');
  837.  
  838. // prevents division by zero & invalid crop widths.
  839. $value = (int)$cropH + (int)$cropW;
  840. if($value < 4) {
  841. echo "invalid crop values detected";
  842. imagedestroy($srcimage);
  843. exit();
  844. }
  845.  
  846. if(gps('rszTmb') == "rsz") { // are we resizing the the thumbnail?
  847. $targH = gps('ebltmbH');
  848. $targW = gps('ebltmbW');
  849.  
  850. // did someone forget to input a height or width? If so, default to crop width
  851. if($targH < 1) { $targH = $cropH; }
  852. if($targW < 1) { $targW = $cropW; }
  853.  
  854. // determine the correct scale value
  855. $scale = min($targW / $cropW,$targH / $cropH);
  856. // are the sides equal? If not, scale to fit.
  857. if ($scale < 1) {
  858. $targW = ceil($scale * $cropW);
  859. $targH = ceil($scale * $cropH);
  860. }
  861. } elseif (gps('rszTmb') != 'rsz') { // if not, we'll just use the crop-area size to create our thumbnail
  862. $targH = $cropH;
  863. $targW = $cropW;
  864. }
  865.  
  866. /** Create base canvas **/
  867. $newimg = imagecreatetruecolor($targW,$targH);
  868. /** Use the X/Y coords to plot the initial point, width/height take care of the rest **/
  869. imagecopyresampled($newimg, $srcimage,0,0, $cropX, $cropY, $targW, $targH, $cropW, $cropH);
  870.  
  871. } elseif ($action == 'rsz') { // general resize
  872. $targH = gps('eblrszH');
  873. $targW = gps('eblrszW');
  874.  
  875. if(($targH + $targW) < 1) {
  876. echo " ERROR : Dimensions must be entered.";
  877. return false;
  878. }
  879. // did someone forget to input a height or width? If so, we'll default to the original size for the missing value.
  880. if($targH < 1) { $targH = $h; }
  881. if($targW < 1) { $targW = $w; }
  882. // checks to see if the targeted values are larger than the original, if so, reset to original value as the longest side.
  883. if($targH > $h) { $targH = $h; }
  884. if($targW > $w) { $targW = $w; }
  885.  
  886. $scale = min($targW / $w, $targH / $h);
  887. // are the sides equal? If not, scale to fit.
  888. if ($scale < 1) {
  889. $targW = ceil($scale * $w);
  890. $targH = ceil($scale * $h);
  891. } else { // image is smaller than requested scale. Abort.
  892. imagedestroy($srcimage);
  893. echo "Image smaller than parameters entered";
  894. return;
  895. }
  896.  
  897. /** Create base canvas **/
  898. $newimg = imagecreatetruecolor($targW,$targH);
  899. /** Use the X/Y coords to plot the initial point, width/height take care of the rest **/
  900. imagecopyresampled($newimg, $srcimage,0,0,0,0, $targW, $targH, $w, $h);
  901. }
  902.  
  903. $t = ($action == 'thumbnail') ? 't' : '';
  904.  
  905. $filename = $id.$t.$ext;
  906.  
  907. switch (strtolower($ext)) {
  908. case ($ext == '.jpg' || $ext == '.jpeg'):
  909. $fileresult = imagejpeg($newimg,$imagedir . $filename,'100');
  910. break;
  911. case ".gif":
  912. $fileresult = imagegif($newimg,$imagedir . $filename);
  913. break;
  914. case ".png":
  915. $fileresult = imagepng($newimg,$imagedir . $filename);
  916. break;
  917. }
  918.  
  919. imagedestroy($srcimage);
  920. }
  921.  
  922. if($action != 'thumbnail')
  923. {
  924. list ($width,$height) = getimagesize($imagedir . $filename);
  925. $rs = safe_update('txp_image', "h = '$height', w = '$width'", "id = $id");
  926. } else {
  927. list ($width,$height) = getimagesize($imagedir . $filename);
  928. $rs = safe_update('txp_image', "thumb_h = '$height', thumb_w = '$width', thumbnail = '1'", "id = $id");
  929. }
  930.  
  931. echo ($fileresult && $rs) ? "success" : 'ERROR ';
  932. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement