Advertisement
Guest User

Untitled

a guest
May 30th, 2014
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 51.47 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. * @ This file is created by deZender.Net
  5. * @ deZender (PHP5 Decoder for ionCube Loader)
  6. *
  7. * @ Version : 2.0.0.3
  8. * @ Author : DeZender
  9. * @ Release on : 06.05.2013
  10. * @ Official site : http://DeZender.Net
  11. *
  12. */
  13.  
  14. /**
  15. * Calculation of Microtime
  16. *
  17. * @package time
  18. * @author Pulkit Gupta
  19. * @return Returns $usec and $sec
  20. * @since 1.0
  21. */
  22. function microtime_float() {
  23.  
  24. list($usec, $sec) = explode(" ", microtime());
  25. return (double)$usec + (double)$sec;
  26. }
  27.  
  28. /**
  29. * Is a substitute for the date() function. Will return the date in GMT by default.
  30. *
  31. * @package time
  32. * @author Pulkit Gupta
  33. * @param int $timestamp The timestamp to format
  34. * @param bool $today If true then a Today will be added instead of the date if the date is today
  35. * @param bool $adjust If true then the time will be adjusted to GMT
  36. * @param string $format The date() funtions format style
  37. * @return string The Date in the format given
  38. * @since 1.0
  39. */
  40. function datify($timestamp, $today = true, $adjust = true, $format = false) {
  41.  
  42. global $l;
  43. global $user;
  44. global $globals;
  45. if (!empty($adjust))
  46. {
  47. $timestamp = max(0, $timestamp - (date("Z", time()) / 3600 - $globals["pgtimezone"]) * 3600);
  48. }
  49. if (!empty($format))
  50. {
  51. return date($format, $timestamp);
  52. }
  53. $todaytime = max(0, time() - (date("Z", time()) / 3600 - $globals["pgtimezone"]) * 3600);
  54. if ($today && date("F j, Y", $timestamp) == date("F j, Y", $todaytime))
  55. {
  56. $time = date("g:i a", $timestamp);
  57. return $l["today"] . $time;
  58. }
  59. return date("F j, Y, g:i a", $timestamp);
  60. }
  61.  
  62. /**
  63. * Generate a random string for the given length
  64. *
  65. * @package string
  66. * @author Pulkit Gupta
  67. * @param int $length The number of charactes that should be returned
  68. * @return string Randomly geterated string of the given number of charaters
  69. * @since 1.0
  70. */
  71. function generateRandStr($length, $special = 0) {
  72.  
  73. global $globals;
  74. global $softpanel;
  75. $randstack = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");
  76. $specialchars = array("!", "[", "]", "(", ")", ".", "-", "@");
  77. if (!empty($softpanel["special_pass_chars"]))
  78. {
  79. $specialchars = $softpanel->special_pass_chars;
  80. }
  81. $randstr = "";
  82. while (strlen($randstr) < $length)
  83. {
  84. $randstr .= $randstack[array_rand($randstack)];
  85. if (!(!empty($special) && strlen($randstr) < $length && strlen($randstr) % 2 == 0))
  86. {
  87. continue;
  88. }
  89. $randstr .= $specialchars[array_rand($specialchars)];
  90. continue;
  91. }
  92. return str_shuffle($randstr);
  93. }
  94.  
  95. /**
  96. * Takes care of Slashes
  97. *
  98. * @package string
  99. * @author Pulkit Gupta
  100. * @param string $string The string that will be processed
  101. * @return string A string that is safe to use for Database Queries, etc
  102. * @since 1.0
  103. */
  104. function inputsec($string) {
  105.  
  106. if (!get_magic_quotes_gpc())
  107. {
  108. $string = addslashes($string);
  109. }
  110. else
  111. {
  112. $string = stripslashes($string);
  113. $string = addslashes($string);
  114. }
  115. $string = str_replace("`", "\\`", $string);
  116. return $string;
  117. }
  118.  
  119. /**
  120. * Converts Special characters to html entities
  121. *
  122. * @package string
  123. * @author Pulkit Gupta
  124. * @param string $string The string containing special characters
  125. * @return string A string containing special characters replaced by html entities of the format &#ASCIICODE;
  126. * @since 1.0
  127. */
  128. function htmlizer($string) {
  129.  
  130. global $globals;
  131. $string = htmlentities($string, ENT_QUOTES, $globals["charset"]);
  132. $string = preg_replace("/(&amp;#(\\d{1,7}|x[0-9a-fA-F]{1,6});)/e", "entity_check(\\2);", $string);
  133. return $string;
  134. }
  135.  
  136. /**
  137. * Used in function htmlizer()
  138. *
  139. * @package string
  140. * @author Pulkit Gupta
  141. * @param string $string
  142. * @return string
  143. * @since 1.0
  144. */
  145. function entity_check($string) {
  146.  
  147. $num = substr($string, 0, 1) === "x" ? (hexdec(substr($string, 1))) : ((int)$string);
  148. $string = ((1114111 < $num) && (55296 <= $num && $num < 57343)) && $num < 32 ? "" : ("&#" . $num . ";");
  149. return $string;
  150. }
  151.  
  152. /**
  153. * Cleans i.e. adds a slash (\) to a given variable
  154. *
  155. * @package string
  156. * @author Pulkit Gupta
  157. * @param array $var An array of arrays and strings
  158. * @return array
  159. * @since 1.0
  160. */
  161. function cleanVARS($var) {
  162.  
  163. if (is_string($var))
  164. {
  165. $var = array($var);
  166. }
  167. foreach ($var as $k => $v)
  168. {
  169. if (is_array($v))
  170. {
  171. $var[$k] = cleanVARS($v);
  172. continue;
  173. }
  174. if (get_magic_quotes_gpc())
  175. {
  176. $v = stripslashes($v);
  177. }
  178. $v = htmlizer($v);
  179. $var[$k] = $v;
  180. continue;
  181. }
  182. return $var;
  183. }
  184.  
  185. /**
  186. * This is used to make a query whenever required.
  187. *
  188. * @package database
  189. * @author Pulkit Gupta
  190. * @param string $query The MySQL QUERY String
  191. * @param boolean $count
  192. * @return resource The MySQL resource if the query was successful
  193. * @since 1.0
  194. */
  195. function makequery($query, $count = true) {
  196.  
  197. global $user;
  198. global $conn;
  199. global $dbtables;
  200. global $logged_in;
  201. global $globals;
  202. global $l;
  203. global $theme;
  204. $result = soft_mysql_query($query, $conn);
  205. if (!$result)
  206. {
  207. die("Could not make the Query.<br /><br /><br />" . $query . "<br /><br />MySQL Error No : " . soft_mysql_errno($conn) . "<br /><br />MySQL Error : " . soft_mysql_error($conn));
  208. }
  209. if ($count)
  210. {
  211. $globals["queries"]++;
  212. }
  213. $globals["output_queries"] = 0;
  214. if (!empty($globals["output_queries"]))
  215. {
  216. echo "Queries:&nbsp;" . $query . "<br /><br />";
  217. }
  218. return $result;
  219. }
  220.  
  221. /**
  222. * Checks if the given email is a VALID email address
  223. *
  224. * @package email
  225. * @author Pulkit Gupta
  226. * @param string $email The email address
  227. * @return boolean Returns true if valid, Returns False if invalid
  228. * @since 1.0
  229. */
  230. function emailvalidation($email) {
  231.  
  232. $puny_email = check_punycode($email);
  233. if (!preg_match("/^([a-zA-Z0-9+])+([a-zA-Z0-9+\\._-])*@([a-zA-Z0-9+_-])+([.])+([a-zA-Z0-9\\._-]+)+\$/", $puny_email))
  234. {
  235. return false;
  236. }
  237. return true;
  238. }
  239.  
  240. /**
  241. * Clean explode a string
  242. *
  243. * @package strings
  244. * @author Pulkit Gupta
  245. * @param string $chars The string to explode with
  246. * @param string $str The string to explode
  247. * @param int $int Are the results supposed to be integers
  248. * @return array Returns the exploded array after trimming
  249. * @since 1.0
  250. */
  251. function cexplode($chars, $str, $int = 0) {
  252.  
  253. $r = explode($chars, $str);
  254. foreach ($r as $k => $v)
  255. {
  256. if ($int)
  257. {
  258. $r[$k] = (int)trim($v);
  259. continue;
  260. }
  261. $r[$k] = trim($v);
  262. continue;
  263. }
  264. return $r;
  265. }
  266.  
  267. /**
  268. * Sends email(s) using PHP's mail() function or using SMTP.
  269. *
  270. * @package email
  271. * @author Pulkit Gupta
  272. * @param array $array, $array stands for mail(s). It loops on the basis of number of elements in it.
  273. * @return boolean
  274. * @since 1.0
  275. */
  276. function _mail($array) {
  277.  
  278. global $user;
  279. global $globals;
  280. global $theme;
  281. global $conn;
  282. global $dbtables;
  283. include_once $globals["mainfiles"] . "/functions/mail_functions.php";
  284. hooks("pre_mail", $array);
  285. return _mail_fn($array);
  286. }
  287.  
  288. /**
  289. * A funtion to insert an array within a array after a particular position
  290. *
  291. * @package arrays
  292. * @author Pulkit Gupta
  293. * @param array $array
  294. * @param int $position
  295. * @param array $insert_array
  296. * @return array The resulting array
  297. * @since 1.0
  298. */
  299. function array_insert(&$array, $position, $insert_array) {
  300.  
  301. $first_array = array_splice($array, 0, $position);
  302. $array = array_merge($first_array, $insert_array, $array);
  303. return;
  304. }
  305.  
  306. /**
  307. * This is complementary to the function array_insert() as it finds the position of a key
  308. *
  309. * @package arrays
  310. * @author Pulkit Gupta
  311. * @param array $array
  312. * @param int $index
  313. * @return int
  314. * @since 1.0
  315. */
  316. function find_pos($array, $index) {
  317.  
  318. $keys = array_keys($array);
  319. $key = array_search($index, $keys);
  320. return $key + 1;
  321. }
  322.  
  323. /**
  324. * Converts htmlentities to their real characters
  325. *
  326. * @package string
  327. * @author Pulkit Gupta
  328. * @param string $string The string containing htmlentities
  329. * @return string Returns translated string
  330. * @since 1.0
  331. */
  332. function unhtmlentities($string) {
  333.  
  334. $string = preg_replace("~&#x([0-9a-f]+);~ei", "chr(hexdec(\"\\1\"))", $string);
  335. $string = preg_replace("~&#([0-9]+);~e", "chr(\"\\1\")", $string);
  336. $trans_tbl = get_html_translation_table(HTML_ENTITIES);
  337. $trans_tbl = array_flip($trans_tbl);
  338. return strtr($string, $trans_tbl);
  339. }
  340.  
  341. /**
  342. * This function just redirects to the Location specified and dies
  343. * Primary Base $globals['index_url']
  344. *
  345. * @package headers
  346. * @author Pulkit Gupta
  347. * @param string $location The location to redirect to
  348. * @param boolean $header If true the header() function is used otherwise the HTML <meta> tag is used
  349. * @return NULL
  350. * @since 1.0
  351. */
  352. function redirect($location, $header = true, $raw = false) {
  353.  
  354. global $globals;
  355. global $redirect;
  356. global $softpanel;
  357. $redirect = true;
  358. $prefix = empty($raw) ? ($globals["index"]) : "";
  359. if (((isset($_SERVER["argv"])) && isset($argv)) && isset($softpanel["softredirect"]))
  360. {
  361. $header = false;
  362. }
  363. if ($header)
  364. {
  365. header("Location: " . $prefix . $location);
  366. return null;
  367. }
  368. echo "<meta http-equiv=\"Refresh\" content=\"0;url=" . $prefix . $location . "\">";
  369. return;
  370. }
  371.  
  372. /**
  373. * Returns the extension for the filename given
  374. *
  375. * @package files
  376. * @author Pulkit Gupta
  377. * @param string $fname The filename e.g. filename.php
  378. * @return string Returns extension of file e.g. php
  379. * @since 1.0
  380. */
  381. function get_extension($fname) {
  382.  
  383. $temp_r = explode(".", $fname);
  384. $ext = $temp_r[count($temp_r) - 1];
  385. return $ext;
  386. }
  387.  
  388. /**
  389. * Detects whether the BROWSER has the capability to handle gzip or x-gzip compression
  390. *
  391. * @package browser
  392. * @author Pulkit Gupta
  393. * @return string The supported compression or false if no compression is supported
  394. * @since 1.0
  395. */
  396. function can_gzip() {
  397.  
  398. global $isbot;
  399. if ((headers_sent() || connection_aborted()) && !empty($isbot))
  400. {
  401. return 0;
  402. }
  403. if (strpos($_SERVER["HTTP_ACCEPT_ENCODING"], "x-gzip") !== false)
  404. {
  405. return "x-gzip";
  406. }
  407. if (strpos($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip") !== false)
  408. {
  409. return "gzip";
  410. }
  411. return 0;
  412. }
  413.  
  414. /**
  415. * Output buffer that controls the output of a page. ATM is not in use
  416. *
  417. * @package buffer
  418. * @author Pulkit Gupta
  419. * @param string $buffer
  420. * @return string The output buffer
  421. * @since 1.0
  422. */
  423. function softaculous_buffer($buffer) {
  424.  
  425. global $globals;
  426. global $redirect;
  427. if (!empty($redirect))
  428. {
  429. return null;
  430. }
  431. if (!empty($globals["stop_buffer_process"]))
  432. {
  433. return $buffer;
  434. }
  435. if (preg_match("/\\<html(.*?)/is", $buffer))
  436. {
  437. if (empty($globals["lictype"]))
  438. {
  439. if (!preg_match("/" . preg_quote(unhtmlentities(strrev(";tg&a/;tl&.cnI suolucatfoS;tg&;touq&moc.suolucatfos.www//:ptth;touq&=ferh a;tl& 9002 ;ypoc;pma& ;tg&a/;tl&0.1 suolucatfoS eerF yB derewoP;tg&;touq&moc.suolucatfos.www//:ptth;touq&=ferh a;tl&")), "/") . "/", $buffer))
  440. {
  441. return null;
  442. }
  443. }
  444. if (!preg_match("/" . preg_quote(unhtmlentities(strrev(";tg&a/;tl&.cnI suolucatfoS;tg&;touq&moc.suolucatfos.www//:ptth;touq&=ferh a;tl& 9002 ;ypoc;pma& ;tg&a/;tl&0.1 suolucatfoS yB derewoP;tg&;touq&moc.suolucatfos.www//:ptth;touq&=ferh a;tl&")), "/") . "/", $buffer))
  445. {
  446. return null;
  447. }
  448. }
  449. if ($globals["gzip"])
  450. {
  451. if (extension_loaded("zlib") && @ini_get("zlib.output_compression") !== "1" || can_gzip())
  452. {
  453. $buffer = ob_gzhandler($buffer, 1);
  454. }
  455. }
  456. return $buffer;
  457. }
  458.  
  459. /**
  460. * Loads the Language file specified.
  461. *
  462. * @package language
  463. * @author Pulkit Gupta
  464. * @param string $file The file name e.g. 'software' (The file extension is not required)
  465. * @return boolean false on error. Incase of failure a MAJOR ERROR is displayed
  466. * @since 1.0
  467. */
  468. function load_lang($file, $returnpath = false) {
  469.  
  470. global $theme;
  471. global $globals;
  472. global $l;
  473. global $user;
  474. $file = $file . "_lang.php";
  475. $language = $globals["language"];
  476. if (!empty($user["language"]))
  477. {
  478. $language = $user["language"];
  479. }
  480. if (optGET("lang"))
  481. {
  482. $language = optGET("lang");
  483. }
  484. $path = $globals["enduser"] . "/languages/" . $language . "/" . $file;
  485. if ($returnpath)
  486. {
  487. return $path;
  488. }
  489. if ((empty($file)) && !(include_once $path))
  490. {
  491. if (!(include_once $globals["enduser"] . "/languages/english/" . $file))
  492. {
  493. reporterror("", "Unable to load the language files.");
  494. return false;
  495. }
  496. }
  497. return true;
  498. }
  499.  
  500. /**
  501. * Replaces the Soft Variables with the supplied ones
  502. *
  503. * @package language
  504. * @author Pulkit Gupta
  505. * @param string $str The string containing the soft variable e.g. &soft-1;
  506. * @param array $array The array that will replace corresponding values in the string. $array[0] replaces &soft-1; and so on
  507. * @return string Returns the formatted string
  508. * @since 1.0
  509. */
  510. function lang_vars($str, $array) {
  511.  
  512. $string = "";
  513. $str = preg_replace("/&soft-(\\d{1,2});/i", "&soft-\\1;", $str);
  514. $count = 0;
  515. foreach ($array as $v)
  516. {
  517. ++$count;
  518. $str = str_replace("&soft-" . $count . ";", $v, $str);
  519. continue;
  520. }
  521. return $str;
  522. }
  523.  
  524. /**
  525. * This should be called first to initialize the theme file.
  526. *
  527. * @package theme
  528. * @author Pulkit Gupta
  529. * @param string $file Just the name and not trailing '_theme.php'
  530. * @param string $theme_file_name The Name of the file if a major error occurs
  531. * @return boolean false on failure and a major error is displayed
  532. * @since 1.0
  533. */
  534. function init_theme($file, $theme_file_name) {
  535.  
  536. global $theme;
  537. global $globals;
  538. global $l;
  539. if (!(include_once $theme["path"] . "/" . $file . "_theme.php"))
  540. {
  541. if (!(include_once $globals["euthemes"] . "/default/" . $file . "_theme.php"))
  542. {
  543. reporterror($l["init_theme_error_t"], lang_vars($l["init_theme_error"], array($theme_file_name)));
  544. return false;
  545. }
  546. }
  547. return true;
  548. }
  549.  
  550. /**
  551. * This should be called to check all the necessary functions exist in a theme
  552. *
  553. * @package theme
  554. * @author Pulkit Gupta
  555. * @param array $function_r The array of the functions
  556. * @param string $theme_file_name The Name for major error
  557. * @return boolean false on failure and a major error is displayed
  558. * @since 1.0
  559. */
  560. function init_theme_func($function_r, $theme_file_name) {
  561.  
  562. global $theme;
  563. global $globals;
  564. global $act;
  565. global $load_hf;
  566. global $l;
  567. $i = 0;
  568. while ($i <= count($function_r))
  569. {
  570. if (!function_exists($function_r[$i]))
  571. {
  572. reporterror($l["init_theme_func_error_t"], lang_vars($l["init_theme_func_error"], array($theme_file_name)));
  573. return false;
  574. }
  575. ++$i;
  576. continue;
  577. }
  578. return true;
  579. }
  580.  
  581. /**
  582. * This is to load a theme's settings. Call how many ever times required
  583. *
  584. * @package theme
  585. * @author Pulkit Gupta
  586. * @param string $folder
  587. * @return boolean
  588. * @since 1.0
  589. */
  590. function load_theme_settings($folder) {
  591.  
  592. global $user;
  593. global $conn;
  594. global $dbtables;
  595. global $logged_in;
  596. global $globals;
  597. global $l;
  598. global $theme;
  599. global $softpanel;
  600. global $act;
  601. global $load_hf;
  602. $skins = array();
  603. $skin = array();
  604. $load_hf = true;
  605. $theme["path"] = $globals["euthemes"] . "/" . $folder;
  606. if (!(include_once $theme["path"] . "/theme_settings.php"))
  607. {
  608. $theme["path"] = $globals["euthemes"] . "/default";
  609. $globals["theme_folder"] = "default";
  610. if (!(include_once $theme["path"] . "/theme_settings.php"))
  611. {
  612. reporterror("", $l["load_theme_settings_error"]);
  613. $load_hf = false;
  614. return false;
  615. }
  616. }
  617. return true;
  618. }
  619.  
  620. /**
  621. * Report a fatal error to the user
  622. *
  623. * @package error
  624. * @author Pulkit Gupta
  625. * @param string $title The <title> of the browser
  626. * @param string $text The text / error that will be shown
  627. * @param string $heading The heading of the error box
  628. * @param string $icon An icon will also be displayed
  629. * @return Returns boolean
  630. * @since 1.0
  631. */
  632. function reporterror($title, $text, $heading = "", $icon = "") {
  633.  
  634. global $theme;
  635. global $globals;
  636. global $act;
  637. global $errortitle;
  638. global $errormessage;
  639. global $errorheading;
  640. global $erroricon;
  641. $act = "error_break";
  642. $errortitle = $title;
  643. $errormessage = $text;
  644. $errorheading = $heading;
  645. $erroricon = $icon;
  646. $globals["stop_buffer_process"] = true;
  647. return true;
  648. }
  649.  
  650. /**
  651. * Reports a message and will stop every other process
  652. *
  653. * @package message
  654. * @author Pulkit Gupta
  655. * @param string $title The <title> of the browser
  656. * @param string $heading The heading of the message box
  657. * @param string $icon An icon will also be displayed
  658. * @param string $text The text that will be shown
  659. * @return Returns boolean
  660. * @since 1.0
  661. */
  662. function reportmessage($title, $heading, $icon, $text) {
  663.  
  664. global $theme;
  665. global $globals;
  666. global $act;
  667. global $messagetitle;
  668. global $messagetext;
  669. global $messageheading;
  670. global $messageicon;
  671. $act = "error_break";
  672. $messagetitle = $title;
  673. $messagetext = $text;
  674. $messageheading = $heading;
  675. $messageicon = $icon;
  676. return true;
  677. }
  678.  
  679. /**
  680. * Gives Copyright information
  681. *
  682. * @package copyright
  683. * @author Pulkit Gupta
  684. * @return string Returns copyright
  685. * @since 1.0
  686. */
  687. function copyright() {
  688.  
  689. global $globals;
  690. if ($globals["softpanel"] == "ampps")
  691. {
  692. return "<a href=\"http://www.ampps.com\">Powered By" . (empty($globals["lictype"]) ? " FREE" : "") . " AMPPS " . $globals["ampps_version"] . "</a> &copy; " . datify(time(), 0, 1, "Y") . " <a href=\"http://www.softaculous.com\">Softaculous Ltd.</a>";
  693. }
  694. if (defined("NEW_COPYRIGHT"))
  695. {
  696. return NEW_COPYRIGHT;
  697. }
  698. if ($globals["softpanel"] == "webuzo")
  699. {
  700. return "<a href=\"http://www.webuzo.com\">Powered By Webuzo " . $globals["webuzo_version"] . "</a> &copy; " . datify(time(), 0, 1, "Y") . " <a href=\"http://www.softaculous.com\">Softaculous Ltd.</a>";
  701. }
  702. return "<a href=\"http://www.softaculous.com\">Powered By" . (empty($globals["lictype"]) ? " Free" : "") . " Softaculous " . $globals["version"] . "</a> &copy; " . datify(time(), 0, 1, "Y") . " <a href=\"http://www.softaculous.com\">Softaculous Ltd.</a>";
  703. }
  704.  
  705. /**
  706. * A Function to compress files and folders
  707. *
  708. * @package files
  709. * @author Pulkit Gupta
  710. * @param string $path Path of file / dir to be compressed
  711. * @param string $name
  712. * @param string $method Method of compression zip, bz2, gzip
  713. * @return Returns compressed file
  714. * @since 1.0
  715. */
  716. function compress($path, $name, $method) {
  717.  
  718. global $globals;
  719. include_once $globals["mainfiles"] . "/functions/compress_functions.php";
  720. return compress_fn($path, $name, $method);
  721. }
  722.  
  723. /**
  724. * This function will find the extension and try to decomress zip, tar, tgz, tbz
  725. *
  726. * @package files
  727. * @author Pulkit Gupta
  728. * @param string $file
  729. * @param string $destination
  730. * @param int $overwrite
  731. * @param array $include
  732. * @param array $exclude
  733. * @return boolean
  734. * @since 1.0
  735. */
  736. function decompress($file, $destination, $overwrite = 0, $include = array(), $exclude = array()) {
  737.  
  738. global $globals;
  739. include_once $globals["mainfiles"] . "/functions/compress_functions.php";
  740. return decompress_fn($file, $destination, $overwrite, $include, $exclude);
  741. }
  742.  
  743. /**
  744. * A Function to create a ZIP file
  745. *
  746. * @package files
  747. * @author Pulkit Gupta
  748. * @param string $file The file that will be created
  749. * @param string $dir The directory to ZIP
  750. * @param boolean $overwrite
  751. * @return boolean False on failure
  752. * @since 1.0
  753. */
  754. function zip($file, $dir, $overwrite = 0) {
  755.  
  756. global $globals;
  757. if (!defined("PCLZIP_TEMPORARY_DIR"))
  758. {
  759. define("PCLZIP_TEMPORARY_DIR", $globals["os"] == "linux" ? "/tmp/" : "");
  760. }
  761. if (!class_exists("PclZip"))
  762. {
  763. include_once $globals["mainfiles"] . "/classes/pclzip.php";
  764. }
  765. $archive = new PclZip($file);
  766. $rempath = is_dir($dir) ? $dir : (dirname($dir));
  767. $result = $archive->create($dir, PCLZIP_OPT_REMOVE_PATH, $rempath, PCLZIP_OPT_TEMP_FILE_ON);
  768. if ($result == 0)
  769. {
  770. return false;
  771. }
  772. return true;
  773. }
  774.  
  775. /**
  776. * A Function to add file to a ZIP file
  777. *
  778. * @package files
  779. * @author Pulkit Gupta
  780. * @param string $file The existing ZIP file Path
  781. * @param string $dir The file / directory to add
  782. * @param string $addpath The path in the zip of the new file(s)
  783. * @param string $pre
  784. * @return boolean
  785. * @since 1.0
  786. */
  787. function add_to_zip($file, $dir, $addpath = "", $pre = "") {
  788.  
  789. global $globals;
  790. if (!defined("PCLZIP_TEMPORARY_DIR"))
  791. {
  792. define("PCLZIP_TEMPORARY_DIR", $globals["os"] == "linux" ? "/tmp/" : "");
  793. }
  794. if (!class_exists("softpclzip"))
  795. {
  796. include_once $globals["mainfiles"] . "/classes/softaculous.pclzip.php";
  797. }
  798. $archive = new softpclzip($file);
  799. $rempath = is_dir($dir) ? $dir : (dirname($dir));
  800. if (empty($pre))
  801. {
  802. $result = $archive->_add($dir, PCLZIP_OPT_REMOVE_PATH, $rempath, PCLZIP_OPT_ADD_PATH, $addpath, PCLZIP_OPT_TEMP_FILE_ON);
  803. }
  804. else
  805. {
  806. $result = $archive->_add($dir, PCLZIP_OPT_REMOVE_PATH, $rempath, PCLZIP_OPT_ADD_PATH, $addpath, PCLZIP_CB_PRE_ADD, $pre, PCLZIP_OPT_TEMP_FILE_ON);
  807. }
  808. if ($result == 0)
  809. {
  810. if (!empty($_GET["debug"]) && $_GET["debug"] == "soft")
  811. {
  812. echo $archive->errorInfo();
  813. }
  814. return false;
  815. }
  816. return true;
  817. }
  818.  
  819. /**
  820. * A Function to unzip a ZIP file
  821. *
  822. * @package files
  823. * @author Pulkit Gupta
  824. * @param string $file The ZIP File
  825. * @param string $destination The Final destination where the file will be unzipped
  826. * @param int $overwrite Whether to Overwrite existing files
  827. * @param array $include include files of the given pattern
  828. * @param array $exclude exclude files of the given pattern
  829. * @return boolean
  830. * @since 1.0
  831. */
  832. function unzip($file, $destination, $overwrite = 0, $include = array(), $exclude = array(), $ftemp = 0) {
  833.  
  834. global $globals;
  835. global $unzip_inc;
  836. global $unzip_exc;
  837. if (!empty($include))
  838. {
  839. foreach ($include as $ik => $iv)
  840. {
  841. if (empty($iv))
  842. {
  843. unset($include[$ik]);
  844. continue;
  845. }
  846. $include[$ik] = preg_quote($iv, "/");
  847. $include[$ik] = str_replace("\\*", "([a-zA-Z0-9\\._-])*", $include[$ik]);
  848. continue;
  849. }
  850. }
  851. if (!empty($exclude))
  852. {
  853. foreach ($exclude as $ek => $ev)
  854. {
  855. if (empty($ev))
  856. {
  857. unset($exclude[$ek]);
  858. continue;
  859. }
  860. $exclude[$ek] = preg_quote($ev, "/");
  861. $exclude[$ek] = str_replace("\\*", "([a-zA-Z0-9\\._-])*", $exclude[$ek]);
  862. continue;
  863. }
  864. }
  865. $unzip_inc = $include;
  866. $unzip_exc = $exclude;
  867. if (!class_exists("softpclzip"))
  868. {
  869. include_once $globals["mainfiles"] . "/classes/softaculous.pclzip.php";
  870. }
  871. $archive = new softpclzip($file);
  872. if ($ftemp)
  873. {
  874. $result = $archive->_extract(PCLZIP_OPT_PATH, $destination, PCLZIP_CB_PRE_EXTRACT, "inc_exc", PCLZIP_OPT_REPLACE_NEWER, PCLZIP_OPT_TEMP_FILE_ON);
  875. }
  876. else
  877. {
  878. $result = $archive->_extract(PCLZIP_OPT_PATH, $destination, PCLZIP_CB_PRE_EXTRACT, "inc_exc", PCLZIP_OPT_REPLACE_NEWER);
  879. }
  880. if ($result == 0)
  881. {
  882. return false;
  883. }
  884. return true;
  885. }
  886.  
  887. /**
  888. * Process includes and excludes of function unzip
  889. *
  890. * @package files
  891. * @author Pulkit Gupta
  892. * @param $p_event
  893. * @param $v
  894. * @return Returns boolean
  895. * @since 1.0
  896. */
  897. function inc_exc($p_event, &$v) {
  898.  
  899. global $globals;
  900. global $unzip_inc;
  901. global $unzip_exc;
  902. $include = $unzip_inc;
  903. $exclude = $unzip_exc;
  904. if (!empty($include))
  905. {
  906. foreach ($include as $ik => $iv)
  907. {
  908. if (!!preg_match("/^" . $iv . "\$/is", $v["stored_filename"]))
  909. {
  910. continue;
  911. }
  912. return 0;
  913. }
  914. }
  915. if (!empty($exclude))
  916. {
  917. foreach ($exclude as $ek => $ev)
  918. {
  919. if (!preg_match("/^" . $ev . "\$/is", $v["stored_filename"]))
  920. {
  921. continue;
  922. }
  923. return 0;
  924. }
  925. }
  926. }
  927.  
  928. /**
  929. * This function will decomress zip
  930. *
  931. * @package files
  932. * @author Pulkit Gupta
  933. * @param string $file
  934. * @param string $destination
  935. * @param int $overwrite
  936. * @param array $include
  937. * @param array $exclude
  938. * @return boolean
  939. * @since 1.0
  940. */
  941. function decompress_zip($file, $destination, $overwrite = 0, $include, $exclude) {
  942.  
  943. global $globals;
  944. include_once $globals["mainfiles"] . "/functions/compress_functions.php";
  945. return decompress_zip_fn($file, $destination, $overwrite, $include, $exclude);
  946. }
  947.  
  948. /**
  949. * A Function to decompress a TGZ flie
  950. *
  951. * @package files
  952. * @author Pulkit Gupta
  953. * @param string $file
  954. * @param string $destination
  955. * @param int $overwrite
  956. * @return boolean
  957. * @since 1.0
  958. */
  959. function decompress_tgz($file, $destination, $overwrite = 0) {
  960.  
  961. global $globals;
  962. include_once $globals["mainfiles"] . "/functions/compress_functions.php";
  963. return decompress_tgz_fn($file, $destination, $overwrite);
  964. }
  965.  
  966. /**
  967. * A Function to decompress a TAR flie
  968. *
  969. * @package files
  970. * @author Pulkit Gupta
  971. * @param string $file
  972. * @param string $destination
  973. * @param int $overwrite
  974. * @return boolean
  975. * @since 1.0
  976. */
  977. function decompress_tar($file, $destination, $overwrite = 0) {
  978.  
  979. global $globals;
  980. include_once $globals["mainfiles"] . "/functions/compress_functions.php";
  981. return decompress_tar_fn($file, $destination, $overwrite);
  982. }
  983.  
  984. /**
  985. * A Function to decompress a TBZIP2 flie
  986. *
  987. * @package files
  988. * @author Pulkit Gupta
  989. * @param string $file
  990. * @param string $destination
  991. * @param int $overwrite
  992. * @return boolean
  993. * @since 1.0
  994. */
  995. function decompress_tbz($file, $destination, $overwrite = 0) {
  996.  
  997. global $globals;
  998. include_once $globals["mainfiles"] . "/functions/compress_functions.php";
  999. return decompress_tbz_fn($file, $destination, $overwrite);
  1000. }
  1001.  
  1002. /**
  1003. * A Function that creates a file for the given data
  1004. *
  1005. * @package files
  1006. * @author Pulkit Gupta
  1007. * @param string $file Path of the file
  1008. * @param string $data The data to be written
  1009. * @param int $overwrite Overwrite if existing
  1010. * @param octal $chmod The CHMOD value
  1011. * @param string $dchmod The Directory CHMOD if a directory will be created recursively
  1012. * @return boolean
  1013. * @since 1.0
  1014. */
  1015. function writefile($file, $data, $overwrite = 0, $chmod = 0, $dchmod = 0) {
  1016.  
  1017. global $globals;
  1018. include_once $globals["mainfiles"] . "/functions/file_functions.php";
  1019. return writefile_fn($file, $data, $overwrite, $chmod, $dchmod);
  1020. }
  1021.  
  1022. /**
  1023. * A Function that lists files and folders in a folder
  1024. *
  1025. * @package files
  1026. * @author Pulkit Gupta
  1027. * @param string $startdir The starting directory to scan
  1028. * @param int $searchSubdirs Search Subdirectories
  1029. * @param int $directoriesonly List only directories
  1030. * @param int $maxlevel The maximum level to scan
  1031. * @param int $level Starting Level
  1032. * @return array Returns list of file & folder
  1033. * @since 1.0
  1034. */
  1035. function filelist($startdir = "./", $searchSubdirs = 1, $directoriesonly = 0, $maxlevel = "all", $level = 1) {
  1036.  
  1037. global $globals;
  1038. include_once $globals["mainfiles"] . "/functions/file_functions.php";
  1039. return filelist_fn($startdir, $searchSubdirs, $directoriesonly, $maxlevel, $level);
  1040. }
  1041.  
  1042. /**
  1043. * A Function that reset lists files
  1044. *
  1045. * @package files
  1046. * @author Pulkit Gupta
  1047. * @since 1.0
  1048. */
  1049. function resetfilelist() {
  1050.  
  1051. global $directorylist;
  1052. $directorylist = array();
  1053. return;
  1054. }
  1055.  
  1056. /**
  1057. * Removes a Directory Recursively
  1058. *
  1059. * @package files
  1060. * @author Pulkit Gupta
  1061. * @param string $path The path of the folder to be removed
  1062. * @return boolean
  1063. * @since 1.0
  1064. */
  1065. function rmdir_recursive($path) {
  1066.  
  1067. global $globals;
  1068. include_once $globals["mainfiles"] . "/functions/file_functions.php";
  1069. return rmdir_recursive_fn($path);
  1070. }
  1071.  
  1072. /**
  1073. * Copy a Directory from one folder to another
  1074. *
  1075. * @package files
  1076. * @author Pulkit Gupta
  1077. * @param string $source The source directory
  1078. * @param string $destination The destination directory
  1079. * @return boolean
  1080. * @since 1.0
  1081. */
  1082. function copydir($source, $destination) {
  1083.  
  1084. global $globals;
  1085. include_once $globals["mainfiles"] . "/functions/file_functions.php";
  1086. return copydir_fn($source, $destination);
  1087. }
  1088.  
  1089. /**
  1090. * Copies Recrsively a File / Folder and also maintains the PERMISSIONS and UID and GID
  1091. *
  1092. * @package softaculous
  1093. * @subpackage settings
  1094. * @author Pulkit Gupta
  1095. * @param string $path The Source Path
  1096. * @param string $dest The Destination Path
  1097. * @return bool
  1098. * @since 1.0
  1099. */
  1100. function copy_r($path, $dest) {
  1101.  
  1102. if (is_dir($path))
  1103. {
  1104. @mkdir($dest);
  1105. $stat = stat($path);
  1106. if (!empty($stat["mode"]))
  1107. {
  1108. @chmod($dest, $stat["mode"]);
  1109. }
  1110. if (!empty($stat["uid"]))
  1111. {
  1112. @chown($dest, $stat["uid"]);
  1113. }
  1114. if (!empty($stat["gid"]))
  1115. {
  1116. @chgrp($dest, $stat["gid"]);
  1117. }
  1118. $objects = scandir($path);
  1119. if (0 < sizeof($objects))
  1120. {
  1121. foreach ($objects as $file)
  1122. {
  1123. if (($file == ".") && $file == "..")
  1124. {
  1125. continue;
  1126. }
  1127. copy_r($path . "/" . $file, $dest . "/" . $file);
  1128. continue;
  1129. }
  1130. }
  1131. return true;
  1132. }
  1133. if (is_file($path))
  1134. {
  1135. $ret = copy($path, $dest);
  1136. $stat = stat($path);
  1137. if (!empty($stat["mode"]))
  1138. {
  1139. @chmod($dest, $stat["mode"]);
  1140. }
  1141. if (!empty($stat["uid"]))
  1142. {
  1143. @chown($dest, $stat["uid"]);
  1144. }
  1145. if (!empty($stat["gid"]))
  1146. {
  1147. @chgrp($dest, $stat["gid"]);
  1148. }
  1149. return $ret;
  1150. }
  1151. return false;
  1152. }
  1153.  
  1154. /**
  1155. * A function to load a file from the net
  1156. *
  1157. * @package files
  1158. * @author Pulkit Gupta
  1159. * @param string $url The URL to read
  1160. * @param string $writefilename Instead of returning the data save it to the path given
  1161. * @return string The data fetched
  1162. * @since 1.0
  1163. */
  1164. function get_web_file($url, $writefilename = "") {
  1165.  
  1166. global $globals;
  1167. include_once $globals["mainfiles"] . "/functions/file_functions.php";
  1168. return get_web_file_fn($url, $writefilename);
  1169. }
  1170.  
  1171. /**
  1172. * A function to save a web file in a file
  1173. *
  1174. * @package files
  1175. * @author Pulkit Gupta
  1176. * @param string $url The URL to read
  1177. * @param string $path Save the fetched data to the path given
  1178. * @return boolean
  1179. * @since 1.0
  1180. */
  1181. function save_web_file($url, $path) {
  1182.  
  1183. global $globals;
  1184. include_once $globals["mainfiles"] . "/functions/file_functions.php";
  1185. return save_web_file_fn($url, $path);
  1186. }
  1187.  
  1188. /**
  1189. * A function to display preformatted array. Basically adds the <pre> before and after the print_r() output.
  1190. *
  1191. * @package arrays
  1192. * @author Pulkit Gupta
  1193. * @param array $array
  1194. * @return string Best for HTML dump of an array.
  1195. * @since 1.0
  1196. */
  1197. function r_print($array) {
  1198.  
  1199. echo "<pre>";
  1200. print_r($array);
  1201. echo "</pre>";
  1202. return;
  1203. }
  1204.  
  1205. /**
  1206. * A function to find the String Length of a UTF-8 string
  1207. *
  1208. * @package string
  1209. * @author Pulkit Gupta
  1210. * @param string $string
  1211. * @return int Returns length of string
  1212. * @since 1.0
  1213. */
  1214. function _strlen($string) {
  1215.  
  1216. global $globals;
  1217. return strlen(utf8_decode($string));
  1218. }
  1219.  
  1220. /**
  1221. * substr() for a UTF-8 string
  1222. *
  1223. * @package string
  1224. * @author Pulkit Gupta
  1225. * @param string $string The UTF-8 string
  1226. * @param int $start The position to start at
  1227. * @param int $length The length after the start
  1228. * @return string Returns string
  1229. * @since 1.0
  1230. */
  1231. function _substr($string, $start, $length = null) {
  1232.  
  1233. global $globals;
  1234. $r = preg_split("/(.)/" . ($globals["charset"] == "UTF-8" ? "u" : ""), $string, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
  1235. if ($length === null)
  1236. {
  1237. return implode("", array_slice($r, $start));
  1238. }
  1239. return implode("", array_slice($r, $start, $length));
  1240. }
  1241.  
  1242. /**
  1243. * Function to convert a UTF-8 string into lower case
  1244. *
  1245. * @package string
  1246. * @author Pulkit Gupta
  1247. * @param string $string
  1248. * @return string Returns a lower case string
  1249. * @since 1.0
  1250. */
  1251. function _strtolower($string) {
  1252.  
  1253. global $globals;
  1254. global $lower_upper;
  1255. global $upper_lower;
  1256. if ($globals["charset"] != "UTF-8")
  1257. {
  1258. return strtolower($string);
  1259. }
  1260. if (function_exists("mb_strtolower"))
  1261. {
  1262. return mb_strtolower($string, $globals["charset"]);
  1263. }
  1264. include_once $globals["mainfiles"] . "/functions/utf8_functions.php";
  1265. return _strtolower_fn($string);
  1266. }
  1267.  
  1268. /**
  1269. * Function to convert a UTF-8 string into upper case
  1270. *
  1271. * @package string
  1272. * @author Pulkit Gupta
  1273. * @param string $string
  1274. * @return string Returns a upper case string
  1275. * @since 1.0
  1276. */
  1277. function _strtoupper($string) {
  1278.  
  1279. global $globals;
  1280. global $upper_lower;
  1281. global $lower_upper;
  1282. if ($globals["charset"] != "UTF-8")
  1283. {
  1284. return strtoupper($string);
  1285. }
  1286. if (function_exists("mb_strtoupper"))
  1287. {
  1288. return mb_strtoupper($string, $globals["charset"]);
  1289. }
  1290. include_once $globals["mainfiles"] . "/functions/utf8_functions.php";
  1291. return _strtoupper_fn($string);
  1292. }
  1293.  
  1294. /**
  1295. * Make the first charater upper case of a UTF-8 string
  1296. *
  1297. * @package string
  1298. * @author Pulkit Gupta
  1299. * @param string $string
  1300. * @return string Returns a string
  1301. * @since 1.0
  1302. */
  1303. function _ucfirst($string) {
  1304.  
  1305. global $globals;
  1306. if ($globals["charset"] != "UTF-8")
  1307. {
  1308. return ucfirst($string);
  1309. }
  1310. return _strtoupper(_substr($string, 0, 1)) . _substr($string, 1);
  1311. }
  1312.  
  1313. /**
  1314. * Functions to find string position in a UTF-8 string
  1315. *
  1316. * @package string
  1317. * @author Pulkit Gupta
  1318. * @param string $haystack
  1319. * @param string $needle
  1320. * @param int $offset
  1321. * @return int Returns an integer of the position of the string found or false if not found
  1322. * @since 1.0
  1323. */
  1324. function _strpos($haystack, $needle, $offset = 0) {
  1325.  
  1326. $c = 0;
  1327. $length = null;
  1328. while ((is_null($length)) && $length < $offset)
  1329. {
  1330. $pos = strpos($haystack, $needle, $offset + $c);
  1331. if ($pos === false)
  1332. {
  1333. return false;
  1334. }
  1335. $length = _strlen(substr($haystack, 0, $pos));
  1336. if (!($length < $offset))
  1337. {
  1338. continue;
  1339. }
  1340. $c = $pos * $length;
  1341. continue;
  1342. }
  1343. return $length;
  1344. }
  1345.  
  1346. /**
  1347. * Unserialize a string and also fixes any broken serialized string before unserializing
  1348. *
  1349. * @package string
  1350. * @author Pulkit Gupta
  1351. * @param string $str
  1352. * @return array Returns an array if successful otherwise false
  1353. * @since 1.0
  1354. */
  1355. function _unserialize($str) {
  1356.  
  1357. $var = @unserialize($str);
  1358. if (empty($var))
  1359. {
  1360. $str = preg_replace("!s:(\\d+):\"(.*?)\";!se", "'s:'._strlen('\$2').':\"\$2\";'", $str);
  1361. $var = @unserialize($str);
  1362. }
  1363. if ($var === false)
  1364. {
  1365. return false;
  1366. }
  1367. return $var;
  1368. }
  1369.  
  1370. /**
  1371. * A compulsory POST which issues a error if the POST[$name] is not there
  1372. *
  1373. * @package forms
  1374. * @subpackage post
  1375. * @author Pulkit Gupta
  1376. * @param string $name The key of the $_POST array i.e. the name of the input / textarea text
  1377. * @param string $e Error to throw if the POST is not made
  1378. * @return string Returns the string if the POST is there otherwise will populate array $error and return false
  1379. * @since 1.0
  1380. */
  1381. function POST($name, $e) {
  1382.  
  1383. global $error;
  1384. if ((!isset($_POST[$name])) && strlen(trim($_POST[$name])) < 1)
  1385. {
  1386. $error[$name] = $e;
  1387. return null;
  1388. }
  1389. return inputsec(htmlizer(trim($_POST[$name])));
  1390. }
  1391.  
  1392. /**
  1393. * OPTIONAL Post of the given POST Key
  1394. *
  1395. * @package forms
  1396. * @subpackage post
  1397. * @author Pulkit Gupta
  1398. * @param string $name The key of the $_POST array i.e. the name of the input / textarea text
  1399. * @param string $default The value to return if the $_POST[$name] is NOT SET
  1400. * @return string Returns the string if the POST is there otherwise the default value given.
  1401. * @since 1.0
  1402. */
  1403. function optPOST($name, $default = "") {
  1404.  
  1405. global $error;
  1406. if (isset($_POST[$name]))
  1407. {
  1408. return inputsec(htmlizer(trim($_POST[$name])));
  1409. }
  1410. return $default;
  1411. }
  1412.  
  1413. /**
  1414. * Check if a POST Checkbox is checked or not
  1415. *
  1416. * @package forms
  1417. * @subpackage post
  1418. * @author Pulkit Gupta
  1419. * @param string $name The name of the checkbox
  1420. * @return boolean
  1421. */
  1422. function checkbox($name) {
  1423.  
  1424. global $error;
  1425. if (isset($_POST[$name]))
  1426. {
  1427. return true;
  1428. }
  1429. return false;
  1430. }
  1431.  
  1432. /**
  1433. * A compulsory GET which issues a error if the GET[$name] is not there
  1434. *
  1435. * @package forms
  1436. * @subpackage get
  1437. * @author Pulkit Gupta
  1438. * @param string $name The key of the $_GET array i.e. the name of the input / textarea text
  1439. * @param string $e Error to throw if the GET is not made
  1440. * @return string Returns the string if the GET is there otherwise will populate array $error and return false
  1441. * @since 1.0
  1442. */
  1443. function GET($name, $e) {
  1444.  
  1445. global $error;
  1446. if ((!isset($_GET[$name])) && strlen(trim($_GET[$name])) < 1)
  1447. {
  1448. $error[$name] = $e;
  1449. return null;
  1450. }
  1451. return inputsec(htmlizer(trim($_GET[$name])));
  1452. }
  1453.  
  1454. /**
  1455. * OPTIONAL GET of the given GET Key i.e. dont throw a error if not there
  1456. *
  1457. * @package forms
  1458. * @subpackage get
  1459. * @author Pulkit Gupta
  1460. * @param string $name The key of the $_GET array i.e. the name of the input / textarea text
  1461. * @param string $default The value to return if the $_GET[$name] is NOT SET
  1462. * @return string Returns the string if the GET is there otherwise the default value given.
  1463. * @since 1.0
  1464. */
  1465. function optGET($name, $default = "") {
  1466.  
  1467. global $error;
  1468. if (isset($_GET[$name]))
  1469. {
  1470. return inputsec(htmlizer(trim($_GET[$name])));
  1471. }
  1472. return $default;
  1473. }
  1474.  
  1475. /**
  1476. * Return the value of the POSTED key i.e. $_POST[$key]. Is mainly used for Themes to fill the forms again automatically.
  1477. *
  1478. * @package forms
  1479. * @subpackage post
  1480. * @author Pulkit Gupta
  1481. * @param string $name The key of the $_POST array i.e. the name of the input / textarea / select text
  1482. * @param string $default (Optional) Default value when the POST is empty
  1483. * @return string The value of the POSTED Key or the $default value when the POST is empty
  1484. * @since 1.0
  1485. */
  1486. function POSTval($name, $default = "") {
  1487.  
  1488. return !empty($_POST) ? (empty($_POST[$name]) ? "" : (inputsec(htmlizer(trim($_POST[$name]))))) : $default;
  1489. }
  1490.  
  1491. /**
  1492. * Return the value of the POSTED key i.e. $_POST[$key]. Is mainly used for Themes to fill the forms again automatically.
  1493. * The difference betweern aPOSTval() and POSTval() is that aPOSTval() just trims the value while POSTval will do
  1494. * inputsec(htmlizer(trim($_POST[$name]))))
  1495. *
  1496. * @package forms
  1497. * @subpackage post
  1498. * @author Pulkit Gupta
  1499. * @param string $name The key of the $_POST array i.e. the name of the input / textarea / select text
  1500. * @param string $default (Optional) Default value when the POST is empty
  1501. * @return string The value of the POSTED Key or the $default value when the POST is empty
  1502. * @since 1.0
  1503. */
  1504. function aPOSTval($name, $default = "") {
  1505.  
  1506. return !empty($_POST) ? (empty($_POST[$name]) ? "" : (trim($_POST[$name]))) : $default;
  1507. }
  1508.  
  1509. /**
  1510. * Was the Checkbox checked or not when the previous post was made.
  1511. *
  1512. * @package forms
  1513. * @subpackage post
  1514. * @author Pulkit Gupta
  1515. * @param string $name The name of the checkbox
  1516. * @param bool $default (Optional) Should it be on or off by default
  1517. * @return string If on then checked="checked" is returned else nothing is returned
  1518. * @since 1.0
  1519. */
  1520. function POSTchecked($name, $default = false) {
  1521.  
  1522. return !empty($_POST) ? (isset($_POST[$name]) ? "checked=\"checked\"" : "") : (!empty($default) ? "checked=\"checked\"" : "");
  1523. }
  1524.  
  1525. /**
  1526. * Which radio box was checked when the previous post was made.
  1527. *
  1528. * @package forms
  1529. * @subpackage post
  1530. * @author Pulkit Gupta
  1531. * @param string $name The name of the checkbox
  1532. * @param bool $default (Optional) Should it be on or off by default
  1533. * @return string If on then checked="checked" is returned else nothing is returned
  1534. * @since 1.0
  1535. */
  1536. function POSTradio($name, $val, $default = false) {
  1537.  
  1538. return !empty($_POST) ? ($_POST[$name] == $val ? "checked=\"checked\"" : "") : (!empty($default) && $default == $val ? "checked=\"checked\"" : "");
  1539. }
  1540.  
  1541. /**
  1542. * Was the OPTION selected or not when the previous post was made. If it is then the selected="selected" is returned
  1543. *
  1544. * @package forms
  1545. * @subpackage post
  1546. * @author Pulkit Gupta
  1547. * @param string $name The name of the select box
  1548. * @param string $value The value to match against the POSTED value
  1549. * @param bool $default Should it be selected or not by default
  1550. * @return string If the $value matches then selected="selected" is returned else nothing is returned
  1551. * @since 1.0
  1552. */
  1553. function POSTselect($name, $value, $default = false) {
  1554.  
  1555. if (empty($_POST))
  1556. {
  1557. if (!empty($default))
  1558. {
  1559. return "selected=\"selected\"";
  1560. }
  1561. }
  1562. if (isset($_POST[$name]))
  1563. {
  1564. if (trim($_POST[$name]) == $value)
  1565. {
  1566. return "selected=\"selected\"";
  1567. }
  1568. }
  1569. return;
  1570. }
  1571.  
  1572. /**
  1573. * OPTIONAL REQUEST of the given REQUEST Key
  1574. *
  1575. * @package forms
  1576. * @subpackage request
  1577. * @author Pulkit Gupta
  1578. * @param string $name The key of the $_REQUEST array i.e. the name of the input / textarea text
  1579. * @param string $default The value to return if the $_REQUEST[$name] is NOT SET
  1580. * @return string Returns the string if the REQUEST is there otherwise the default value given.
  1581. * @since 1.0
  1582. */
  1583. function optREQ($name, $default = "") {
  1584.  
  1585. global $error;
  1586. if (isset($_REQUEST[$name]))
  1587. {
  1588. return inputsec(htmlizer(trim($_REQUEST[$name])));
  1589. }
  1590. return $default;
  1591. }
  1592.  
  1593. /**
  1594. * Save the Global Settings of universal.php
  1595. *
  1596. * @package softaculous
  1597. * @subpackage settings
  1598. * @author Pulkit Gupta
  1599. * @param array $rawdata An array of the new values against the keys
  1600. * @param boolean $reload Reload the whole universal.php or not !
  1601. * @return bool
  1602. * @since 1.0
  1603. */
  1604. function saveglobals($rawdata = array(), $reload = false) {
  1605.  
  1606. global $globals;
  1607. global $softpanel;
  1608. global $user;
  1609. $data = @implode(file($globals["enduser"] . "/_universal.php"));
  1610. if (empty($data))
  1611. {
  1612. return false;
  1613. }
  1614. $final_data = array();
  1615. $final_data["path"] = $globals["path"];
  1616. $final_data["softscripts"] = $globals["softscripts"];
  1617. $final_data["sn"] = $globals["sn"];
  1618. $final_data["cookie_name"] = $globals["cookie_name"];
  1619. $final_data["gzip"] = $globals["gzip"];
  1620. $final_data["language"] = $globals["language"];
  1621. $final_data["soft_email"] = $globals["soft_email"];
  1622. $final_data["from_email"] = $globals["from_email"];
  1623. $final_data["theme_folder"] = $globals["theme_folder"];
  1624. $final_data["timezone"] = $globals["timezone"];
  1625. $final_data["mail"] = $globals["mail"];
  1626. $final_data["mail_server"] = $globals["mail_server"];
  1627. $final_data["mail_port"] = $globals["mail_port"];
  1628. $final_data["mail_user"] = $globals["mail_user"];
  1629. $final_data["mail_pass"] = $globals["mail_pass"];
  1630. $final_data["off"] = $globals["off"];
  1631. $final_data["off_subject"] = $globals["off_subject"];
  1632. $final_data["off_message"] = $globals["off_message"];
  1633. $final_data["update"] = $globals["update"];
  1634. $final_data["update_softs"] = $globals["update_softs"];
  1635. $final_data["add_softs"] = $globals["add_softs"];
  1636. $final_data["email_update"] = $globals["email_update"];
  1637. $final_data["email_update_softs"] = $globals["email_update_softs"];
  1638. $final_data["cron_time"] = $globals["cron_time"];
  1639. $final_data["chmod_files"] = $globals["chmod_files"];
  1640. $final_data["chmod_dir"] = $globals["chmod_dir"];
  1641. $final_data["is_vps"] = $globals["is_vps"];
  1642. $final_data["eu_news_off"] = $globals["eu_news_off"];
  1643. $final_data["eu_email_off"] = $globals["eu_email_off"];
  1644. $final_data["random_username"] = $globals["random_username"];
  1645. $final_data["random_pass"] = $globals["random_pass"];
  1646. $final_data["off_demo_link"] = $globals["off_demo_link"];
  1647. $final_data["off_screenshot_link"] = $globals["off_screenshot_link"];
  1648. $final_data["off_rating_link"] = $globals["off_rating_link"];
  1649. $final_data["off_review_link"] = $globals["off_review_link"];
  1650. $final_data["off_email_link"] = $globals["off_email_link"];
  1651. $final_data["random_dbprefix"] = $globals["random_dbprefix"];
  1652. $final_data["logo_url"] = $globals["logo_url"];
  1653. $final_data["php_bin"] = $globals["php_bin"];
  1654. $final_data["chmod_conf_file"] = $globals["chmod_conf_file"];
  1655. $final_data["off_sync_link"] = $globals["off_sync_link"];
  1656. $final_data["off_panel_link"] = $globals["off_panel_link"];
  1657. $final_data["no_prefill"] = $globals["no_prefill"];
  1658. $final_data["footer_link"] = $globals["footer_link"];
  1659. $final_data["remote_mysql"] = $globals["remote_mysql"];
  1660. $final_data["perl_scripts"] = $globals["perl_scripts"];
  1661. $final_data["show_top_scripts"] = $globals["show_top_scripts"];
  1662. $final_data["append_apps"] = $globals["append_apps"];
  1663. $final_data["user_mod_dir"] = $globals["user_mod_dir"];
  1664. $final_data["show_in_notice"] = $globals["show_in_notice"];
  1665. $final_data["disable_classes"] = $globals["disable_classes"];
  1666. $final_data["panel_hf"] = $globals["panel_hf"];
  1667. $final_data["disable_backup_restore"] = $globals["disable_backup_restore"];
  1668. $final_data["nolabels"] = $globals["nolabels"];
  1669. $final_data["group_order"] = $globals["group_order"];
  1670. $final_data["disable_reseller_panel"] = $globals["disable_reseller_panel"];
  1671. $final_data["default_protocol"] = $globals["default_protocol"];
  1672. $final_data["network_interface"] = $globals["network_interface"];
  1673. $final_data["proxy_ip"] = $globals["proxy_ip"];
  1674. $final_data["proxy_port"] = $globals["proxy_port"];
  1675. $final_data["proxy_user"] = $globals["proxy_user"];
  1676. $final_data["proxy_pass"] = $globals["proxy_pass"];
  1677. $final_data["proxy_check"] = $globals["proxy_check"];
  1678. $final_data["bandwidth_limit"] = $globals["bandwidth_limit"];
  1679. $final_data["adomain_path"] = $globals["adomain_path"];
  1680. $final_data["empty_pass"] = $globals["empty_pass"];
  1681. $final_data["empty_username"] = $globals["empty_username"];
  1682. $final_data["show_cscript_in_top"] = $globals["show_cscript_in_top"];
  1683. $final_data["pass_strength"] = $globals["pass_strength"];
  1684. $final_data["off_remove_mail"] = $globals["off_remove_mail"];
  1685. $final_data["off_backup_mail"] = $globals["off_backup_mail"];
  1686. $final_data["off_install_mail"] = $globals["off_install_mail"];
  1687. $final_data["off_edit_mail"] = $globals["off_edit_mail"];
  1688. $final_data["admin_prefix"] = $globals["admin_prefix"];
  1689. $final_data["disable_auto_backup"] = $globals["disable_auto_backup"];
  1690. $final_data["bandwidth_up_limit"] = $globals["bandwidth_up_limit"];
  1691. $final_data["webuzo_disable_username"] = $globals["webuzo_disable_username"];
  1692. $final_data["off_clone_mail"] = $globals["off_clone_mail"];
  1693. $final_data["disable_clone"] = $globals["disable_clone"];
  1694. $final_data["disable_backup_upgrade"] = $globals["disable_backup_upgrade"];
  1695. $final_data["ephp_bin"] = $globals["ephp_bin"];
  1696. $final_data["no_strong_mysql_pass"] = $globals["no_strong_mysql_pass"];
  1697. $final_data["install_tweet_off"] = $globals["install_tweet_off"];
  1698. $final_data["install_tweet"] = $globals["install_tweet"];
  1699. $final_data["upgrade_tweet_off"] = $globals["upgrade_tweet_off"];
  1700. $final_data["upgrade_tweet"] = $globals["upgrade_tweet"];
  1701. $final_data["clone_tweet_off"] = $globals["clone_tweet_off"];
  1702. $final_data["clone_tweet"] = $globals["clone_tweet"];
  1703. $final_data["no_ftp_encrypted"] = $globals["no_ftp_encrypted"];
  1704. $final_data["salt"] = $globals["salt"];
  1705. $final_data["pre_download_all"] = $globals["pre_download_all"];
  1706. $final_data["session_timeout"] = $globals["session_timeout"];
  1707. $final_data["eu_enable_themes"] = $globals["eu_enable_themes"];
  1708. $final_data["auto_backup_limit"] = $globals["auto_backup_limit"];
  1709. $final_data["disable_cats"] = $globals["disable_cats"];
  1710. $final_data["remove_dir"] = $globals["remove_dir"];
  1711. $final_data["remove_db"] = $globals["remove_db"];
  1712. $final_data["remove_datadir"] = $globals["remove_datadir"];
  1713. $final_data["remove_wwwdir"] = $globals["remove_wwwdir"];
  1714. if (!empty($globals["ampps_enabled"]))
  1715. {
  1716. $final_data["no_ampps"] = $globals["no_ampps"];
  1717. }
  1718. foreach ($final_data as $k => $v)
  1719. {
  1720. if (isset($rawdata[$k]))
  1721. {
  1722. $final_data[$k] = $rawdata[$k];
  1723. }
  1724. if (asperapp(0, 0, 1))
  1725. {
  1726. if ($k == "path")
  1727. {
  1728. $data = str_replace("\$globals['" . $k . "'] = '';", "\$globals['" . $k . "'] = dirname(dirname(__FILE__));", $data);
  1729. continue;
  1730. }
  1731. if ($k == "softscripts")
  1732. {
  1733. $data = str_replace("\$globals['" . $k . "'] = '';", "\$globals['" . $k . "'] = dirname(dirname(dirname(__FILE__))).'/scripts';", $data);
  1734. continue;
  1735. }
  1736. }
  1737. if (is_string($final_data[$k]))
  1738. {
  1739. $data = str_replace("\$globals['" . $k . "'] = '';", "\$globals['" . $k . "'] = '" . $final_data[$k] . "';", $data);
  1740. continue;
  1741. }
  1742. if (is_int($final_data[$k]) || is_float($final_data[$k]))
  1743. {
  1744. $data = str_replace("\$globals['" . $k . "'] = '';", "\$globals['" . $k . "'] = " . $final_data[$k] . ";", $data);
  1745. continue;
  1746. }
  1747. if (!is_bool($final_data[$k]))
  1748. {
  1749. continue;
  1750. }
  1751. $data = str_replace("\$globals['" . $k . "'] = '';", "\$globals['" . $k . "'] = " . ($final_data[$k] ? "true" : "false") . ";", $data);
  1752. continue;
  1753. }
  1754. $path = str_replace($globals["path"], $final_data["path"], $globals["enduser"]);
  1755. writefile($path . "/universal.php", $data, 1);
  1756. if (!empty($reload))
  1757. {
  1758. include $path . "/universal.php";
  1759. }
  1760. return true;
  1761. }
  1762.  
  1763. /**
  1764. * Add a CRON JOB of softaculous. It creates a file /etc/cron.d/softaculous
  1765. *
  1766. * @package softaculous
  1767. * @subpackage cron
  1768. * @author Pulkit Gupta
  1769. * @param string $time The CRON Time setting
  1770. * @return bool
  1771. * @since 1.0
  1772. */
  1773. function add_cron($time) {
  1774.  
  1775. global $globals;
  1776. global $l;
  1777. $data = $time . " root " . (empty($globals["php_bin"]) ? "/usr/bin/php" : ($globals["php_bin"])) . " " . $globals["path"] . "/cron.php >> /dev/null 2>&1" . "\n";
  1778. if ($globals["softpanel"] == "webuzo")
  1779. {
  1780. $data .= "*/8 * * * * root " . (empty($globals["php_bin"]) ? "/usr/bin/php" : ($globals["php_bin"])) . " " . $globals["path"] . "/webuzocron.php >> /dev/null 2>&1" . "\n";
  1781. }
  1782. $data .= "\n";
  1783. $data = str_replace("\r", "", $data);
  1784. writefile("/etc/cron.d/softaculous", $data, 1);
  1785. @chmod("/etc/cron.d/softaculous", 420);
  1786. return true;
  1787. }
  1788.  
  1789. /**
  1790. * Delete the CRON JOB of softaculous. It deletes the file /etc/cron.d/softaculous
  1791. *
  1792. * @package softaculous
  1793. * @subpackage cron
  1794. * @author Pulkit Gupta
  1795. * @return bool
  1796. * @since 1.0
  1797. */
  1798. function del_cron() {
  1799.  
  1800. global $globals;
  1801. global $l;
  1802. @unlink("/etc/cron.d/softaculous");
  1803. return true;
  1804. }
  1805. .......................................................................................
  1806. ...........................................
  1807. .............
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement