Source for file mambofunc.php

Documentation is available at mambofunc.php

  1. <?php
  2. /**
  3. @package Mambo
  4. @copyright Refer to copyright.php
  5. @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  6. @author Mambo Foundation Inc see README.php
  7. */
  8.  
  9. /**
  10. * Sorts an Array of objects
  11. * sort_direction [1 = Ascending] [-1 = Descending]
  12. */
  13. function SortArrayObjects&$a$k$sort_direction={
  14.     $sorter =new mosObjectSorter($a$k$sort_direction);
  15. }
  16.  
  17. /**
  18. * Sends mail to admin
  19. * Deprecated - not used in Mambo (code copied into weblinks.php)
  20. * Could do with a better facility that works out who to send it to as well
  21. * Note the "email" parameter was not used in the earlier version
  22. */
  23. function mosSendAdminMail$adminName$adminEmail$email$type$title$author {
  24.     $mosConfig_live_site mamboCore::get('mosConfig_live_site');
  25.     $from mamboCore::get('mosConfig_mailfrom');
  26.     $fromname mamboCore::get('mosConfig_fromname');
  27.     $subject sprintf(T_("User Submitted '%s'")$type);
  28.     $message T_("Hello %s,\n\n
  29. A user submitted %s:\n[ %s ]\n
  30. has been just been submitted by user:\n[ %s ]\n\n
  31. for %\n\nPlease go to %s/administrator to view and approve this %s\n\n
  32. Please do not respond to this message as it is automatically generated and is for information purposes only.");
  33.     $message sprintf($message$adminName ,$type$title$author$mosConfig_live_site$mosConfig_live_site$type);
  34.     require_once(mamboCore::get('mosConfig_absolute_path').'/includes/phpmailer/class.phpmailer.php');
  35.     $mail =new mosMailer ($from$fromname$subject$message);
  36.     return $mail->mosMail($adminEmail);
  37. }
  38.  
  39. /*
  40. * Includes pathway file
  41. * Needed by templates
  42. */
  43. function mosPathWay({
  44.     $pathway =mosPathway::getInstance();
  45.     echo $pathway->makePathway();
  46. }
  47.  
  48. /**
  49. * Displays a not authorised message
  50. *
  51. * If the user is not logged in then an addition message is displayed.
  52. */
  53. function mosNotAuth({
  54.     global $my;
  55.  
  56.     echo T_('You are not authorized to view this resource.');
  57.     if ($my->id 1{
  58.         echo "<br />" T_('You need to login.');
  59.     }
  60. }
  61.  
  62. /**
  63. * Replaces &amp; with & for xhtml compliance
  64. *
  65. * Needed to handle unicode conflicts due to unicode conflicts
  66. * Deprecated - simply code the line below
  67. */
  68. function ampReplace$text {
  69.  
  70.     $text str_replace'&#''*-*'$text );
  71.     $text str_replace'&''&amp;'$text );
  72.     $text str_replace'*-*''&#'$text );
  73.  
  74.     return $text;
  75.     //return preg_replace('/(&)([^#]|$)/','&amp;$2', $text);
  76. }
  77.  
  78. /**
  79. * Chmods files and directories recursively to given permissions. Available from 4.5.2 up.
  80. @param path The starting file or directory (no trailing slash)
  81. @param filemode Integer value to chmod files. NULL = dont chmod files.
  82. @param dirmode Integer value to chmod directories. NULL = dont chmod directories.
  83. @return TRUE=all succeeded FALSE=one or more chmods failed
  84. */
  85. function mosChmodRecursive($path$filemode=NULL$dirmode=NULL)
  86. {
  87.     $fileman =mosFileManager::getInstance();
  88.     return $fileman->mosChmodRecursive($path$filemode$dirmode);
  89. }
  90.  
  91. /**
  92. * Chmods files and directories recursively to mos global permissions. Available from 4.5.2 up.
  93. @param path The starting file or directory (no trailing slash)
  94. @param filemode Integer value to chmod files. NULL = dont chmod files.
  95. @param dirmode Integer value to chmod directories. NULL = dont chmod directories.
  96. @return TRUE=all succeeded FALSE=one or more chmods failed
  97. */
  98. function mosChmod($path)
  99. {
  100.     $fileman =mosFileManager::getInstance();
  101.     return $fileman->mosChmod($path);
  102. // mosChmod
  103.  
  104. /**
  105.  * Function to convert array to integer values
  106.  * Deprecated - not used within Mambo
  107.  */
  108. function mosArrayToInts&$array$default=null {
  109.     if (is_array$array )) {
  110.         $n count$array );
  111.         for ($i 0$i $n$i++{
  112.             $array[$iintval$array[$i);
  113.         }
  114.     else {
  115.         if (is_null$default )) {
  116.             return array();
  117.         else {
  118.             return array$default );
  119.         }
  120.     }
  121. }
  122.  
  123. /**
  124. * Strip slashes from strings or arrays of strings
  125. @param value the input string or array
  126. */
  127. function mosStripslashes(&$value)
  128. {
  129.     $database =mamboDatabase::getInstance();
  130.     return $database->mosStripslashes($value);
  131. }
  132.  
  133. /**
  134. * Copy the named array content into the object as properties
  135. * only existing properties of object are filled. when undefined in hash, properties wont be deleted
  136. @param array the input array
  137. @param obj byref the object to fill of any class
  138. @param string 
  139. @param boolean 
  140. */
  141. function mosBindArrayToObject$array&$obj$ignore=''$prefix=NULL$checkSlashes=true {
  142.     $database =mamboDatabase::getInstance();
  143.     return $database->mosBindArrayToOBject($array$obj$ignore=''$prefix=NULL$checkSlashes=true);
  144. }
  145.  
  146. /**
  147. * Utility function to read the files in a directory
  148. @param string The file system path
  149. @param string A filter for the names
  150. @param boolean Recurse search into sub-directories
  151. @param boolean True if to prepend the full path to the file name
  152. */
  153. function mosReadDirectory$path$filter='.'$recurse=false$fullpath=false  {
  154.     if (@is_dir($path)) {
  155.         $dir =new mosDirectory($path);
  156.         $arr =$dir->listFiles ($filter$type='both'$recurse$fullpath);
  157.     }
  158.     else $arr array();
  159.     return $arr;
  160. }
  161.  
  162. /**
  163. * Utility function redirect the browser location to another url
  164. *
  165. * Can optionally provide a message.
  166. @param string The file system path
  167. @param string A filter for the names
  168. */
  169. function mosRedirect$url$msg='' {
  170.     mamboCore::redirect($url$msg);
  171. }
  172.  
  173. /**
  174. * Function to strip additional / or \ in a path name
  175. @param string The path
  176. @param boolean Add trailing slash
  177. */
  178. function mosPathName($p_path,$p_addtrailingslash true{
  179.     $fileman =mosFileManager::getInstance();
  180.     return $fileman->mosPathName($p_path,$p_addtrailingslash);
  181. }
  182.  
  183. /**
  184. * Checks the user agent string against known browsers
  185. */
  186. function mosGetBrowser$agent {
  187.     require"includes/agent_browser.php" );
  188.  
  189.     if (preg_match"/msie[\/\sa-z]*([\d\.]*)/i"$agent$m )
  190.     && !preg_match"/webtv/i"$agent )
  191.     && !preg_match"/omniweb/i"$agent )
  192.     && !preg_match"/opera/i"$agent )) {
  193.         // IE
  194.         return "MS Internet Explorer $m[1]";
  195.     else if (preg_match"/netscape.?\/([\d\.]*)/i"$agent$m )) {
  196.         // Netscape 6.x, 7.x ...
  197.         return "Netscape $m[1]";
  198.     else if preg_match"/mozilla[\/\sa-z]*([\d\.]*)/i"$agent$m )
  199.     && !preg_match"/gecko/i"$agent )
  200.     && !preg_match"/compatible/i"$agent )
  201.     && !preg_match"/opera/i"$agent )
  202.     && !preg_match"/galeon/i"$agent )
  203.     && !preg_match"/safari/i"$agent )) {
  204.         // Netscape 3.x, 4.x ...
  205.         return "Netscape $m[2]";
  206.     else {
  207.         // Other
  208.         $found false;
  209.         foreach ($browserSearchOrder as $key{
  210.             if (preg_match"/$key.?\/([\d\.]*)/i"$agent$m )) {
  211.                 $name "$browsersAlias[$key] $m[1]";
  212.                 return $name;
  213.                 break;
  214.             }
  215.         }
  216.     }
  217.  
  218.     return 'Unknown';
  219. }
  220.  
  221. /**
  222. * Checks the user agent string against known operating systems
  223. */
  224. function mosGetOS$agent {
  225.     require"includes/agent_os.php" );
  226.  
  227.     foreach ($osSearchOrder as $key{
  228.         if (preg_match"/$key/i"$agent )) {
  229.             return $osAlias[$key];
  230.             break;
  231.         }
  232.     }
  233.  
  234.     return 'Unknown';
  235. }
  236.  
  237. /**
  238. * Makes a variable safe to display in forms
  239. *
  240. * Object parameters that are non-string, array, object or start with underscore
  241. * will be converted
  242. @param object An object to be parsed
  243. @param int The optional quote style for the htmlspecialchars function
  244. @param string|arrayAn optional single field name or array of field names not
  245. *                      to be parsed (eg, for a textarea)
  246. */
  247. function mosMakeHtmlSafe&$mixed$quote_style=ENT_QUOTES$exclude_keys='' {
  248.     if (is_object$mixed )) {
  249.         foreach (get_object_vars$mixed as $k => $v{
  250.             if (is_array$v || is_object$v || $v == NULL || substr$k1== '_' {
  251.                 continue;
  252.             }
  253.             if (is_string$exclude_keys && $k == $exclude_keys{
  254.                 continue;
  255.             else if (is_array$exclude_keys && in_array$k$exclude_keys )) {
  256.                 continue;
  257.             }
  258.             $mixed->$k htmlspecialchars$v$quote_style );
  259.         }
  260.     }
  261. }
  262.  
  263. /**
  264. * Checks whether a menu option is within the users access level
  265. @param int Item id number
  266. @param string The menu option
  267. @param int The users group ID number
  268. @param database A database connector object
  269. @return boolean True if the visitor's group at least equal to the menu access
  270. */
  271. function mosMenuCheck$Itemid$menu_option$task$gid {
  272.     $menuhandler =mosMenuHandler::getInstance();
  273.     return $menuhandler->menuCheck($Itemid$menu_option$task$gid);
  274. }
  275.  
  276. /**
  277. * Returns formated date according to current local and adds time offset
  278. @param string date in datetime format
  279. @param string format optional format for strftime
  280. @param offset time offset if different than global one
  281. @returns formated date
  282. */
  283. function mosFormatDate$date$format=""$offset=""$jalali ){
  284.     $core mamboCore::getMamboCore();
  285.     $lang mamboCore::get('mosConfig_lang');
  286.     
  287.     switch($lang{
  288.         case 'persian':
  289.         case 'fa_IR':
  290.         case 'farsi':
  291.         case 'fa':
  292.             $farsi 1;
  293.         break;
  294.         
  295.         default$farsi 0;
  296.     }
  297.     if $format == '' {
  298.         // %Y-%m-%d %H:%M:%S
  299.         $format $core->current_language->date_format;
  300.     }
  301.     $faint 1;
  302.     if(ereg("^Q"$format)){
  303.         $format substr($format,1);
  304.         $faint 0;
  305.     }
  306.  
  307.     if $format == '%x' {
  308.         $format 'H:i d/m/y';
  309.     }
  310.  
  311.     if !$offset {
  312.         $offset $core->mosConfig_offset;
  313.     }
  314.     
  315.     if $farsi && $date && ereg"([0-9]{4})-([0-9]{2})-([0-9]{2})[ ]([0-9]{2}):([0-9]{2}):([0-9]{2})"$date$regs ) ) {
  316.         $date mktime$regs[4]$regs[5]$regs[6]$regs[2]$regs[3]$regs[1);
  317.         if($jalali == 1){
  318.             $date $date > -jdate$format$date ($offset*60*60),$faint '-';
  319.         }else{
  320.             $date $date > -$core->current_language->getDate($format,  $date ($offset*60*60)) '-';
  321.  
  322.         }
  323.     else if !$farsi && $date && ereg"([0-9]{4})-([0-9]{2})-([0-9]{2})[ ]([0-9]{2}):([0-9]{2}):([0-9]{2})"$date$regs ) ) {
  324.         $date mktime$regs[4]$regs[5]$regs[6]$regs[2]$regs[3]$regs[1);
  325.         $date $date > -$core->current_language->getDate($format,  $date ($offset*60*60)) '-';
  326.     }
  327.     return $date;
  328. }
  329.  
  330. /**
  331. * Returns current date according to current local and time offset
  332. @param string format optional format for strftime
  333. @returns current date
  334. */
  335. function mosCurrentDate$format="" {
  336.     $core =mamboCore::getMamboCore();
  337.     $offset mamboCore::get('mosConfig_offset');
  338.     if ($format==""{
  339.         $format $format $core->current_language->date_format;
  340.     }
  341.     $date $core->current_language->getDate($format,  time(($offset*60*60));
  342.     return $date;
  343. }
  344.  
  345. /**
  346. * Utility function to provide ToolTips
  347. @param string ToolTip text
  348. @param string Box title
  349. @returns HTML code for ToolTip
  350. */
  351. function mosToolTip$tooltip$title=''$width=''$image='tooltip.png'$text=''$href='#' {
  352.     global $mosConfig_live_site;
  353.  
  354.     if $width {
  355.         $width ', WIDTH, \''.$width .'\'';
  356.     }
  357.     if $title {
  358.         $title ', CAPTION, \''.$title .'\'';
  359.     }
  360.     if !$text {
  361.         $image     $mosConfig_live_site '/includes/js/ThemeOffice/'$image;
  362.         $text     '<img src="'$image .'" border="0" />';
  363.     }
  364.     $style 'style="text-decoration: none; color: #333;"';
  365.     if $href {
  366.         $style '';
  367.     }
  368.     $tip     "<a href=\""$href ."\" onMouseOver=\"return overlib('" $tooltip "'"$title .", BELOW, RIGHT"$width .");\" onmouseout=\"return nd();\" "$style .">"$text ."</a>";
  369.     return $tip;
  370. }
  371.  
  372. /**
  373. * Utility function to provide Warning Icons
  374. @param string Warning text
  375. @param string Box title
  376. @returns HTML code for Warning
  377. */
  378. function mosWarning($warning$title=null{
  379.     if (is_null($title)) $title T_('Mambo Warning');
  380.     $mosConfig_live_site mamboCore::get('mosConfig_live_site');
  381.     $tip "<a href=\"#\" onMouseOver=\"return overlib('" $warning "', CAPTION, '$title', BELOW, RIGHT);\" onmouseout=\"return nd();\"><img src=\"$mosConfig_live_site "/includes/js/ThemeOffice/warning.png\" border=\"0\" /></a>";
  382.     return $tip;
  383. }
  384.  
  385. function mosCreateGUID(){
  386.     srand((double)microtime()*1000000);
  387.     $r rand ;
  388.     $u uniqid(getmypid($r . (double)microtime()*1000000,1);
  389.     $m md5 ($u);
  390.     return($m);
  391. }
  392.  
  393. function mosCompressID$ID ){
  394.     return(Base64_encode(pack("H*",$ID)));
  395. }
  396.  
  397. function mosExpandID$ID {
  398.     return implode(unpack("H*",Base64_decode($ID))'') );
  399. }
  400.  
  401. /**
  402. * Mail function (uses phpMailer)
  403. @param string From e-mail address
  404. @param string From name
  405. @param string/array Recipient e-mail address(es)
  406. @param string E-mail subject
  407. @param string Message body
  408. @param boolean false = plain text, true = HTML
  409. @param string/array CC e-mail address(es)
  410. @param string/array BCC e-mail address(es)
  411. @param string/array Attachment file name(s)
  412. @param string/array Reply-to e-mail address
  413. @param string/array Reply-to name
  414. */
  415. function mosMail($from$fromname$recipient$subject$body$mode=0$cc=NULL$bcc=NULL$attachment=NULL$replyto=NULL$replytoname=NULL {
  416.     require_once(mamboCore::get('mosConfig_absolute_path').'/includes/phpmailer/class.phpmailer.php');
  417.     $mail =new mosMailer ($from$fromname$subject$body);
  418.     $result $mail->mosMail($recipient$mode$cc$bcc$attachment$replyto$replytoname);
  419.     return $result;
  420. // mosMail
  421.  
  422. /**
  423. * Create mail object
  424. @return mail object
  425. */
  426. function &mosCreateMail ($from$fromname$subject$body{
  427.     require_once(mamboCore::get('mosConfig_absolute_path').'/includes/phpmailer/class.phpmailer.php');
  428.     $mail =new mosMailer ($from$fromname$subject$body);
  429.     return $mail;
  430. }
  431.  
  432. /**
  433. * Random password generator
  434. @return password 
  435. */
  436. function mosMakePassword({
  437.     require_once(mamboCore::get('mosConfig_absolute_path').'/includes/authenticator.php');
  438.     $authenticator =mamboAuthenticator::getInstance();
  439.     return $authenticator->mosMakePassword();
  440. }
  441.  
  442. if (!function_exists('html_entity_decode')) {
  443.     /**
  444.     * html_entity_decode function for backward compatability in PHP
  445.     * @param string 
  446.     * @param string 
  447.     */
  448.     function html_entity_decode ($string$opt ENT_COMPAT{
  449.  
  450.         $trans_tbl get_html_translation_table (HTML_ENTITIES);
  451.         $trans_tbl array_flip ($trans_tbl);
  452.  
  453.         if ($opt 1// Translating single quotes
  454.             // Add single quote to translation table;
  455.             // doesn't appear to be there by default
  456.             $trans_tbl["&apos;""'";
  457.         }
  458.  
  459.         if (!($opt 2)) // Not translating double quotes
  460.             // Remove double quote from translation table
  461.             unset($trans_tbl["&quot;"]);
  462.         }
  463.  
  464.         return strtr ($string$trans_tbl);
  465.     }
  466. }
  467.  
  468. /**
  469. @param string 
  470. @return string 
  471. *  Deprecated - use the code within this function instead - not used in Mambo
  472. */
  473. function mosParseParams$txt {
  474.     $pparser new mosParameters($txt);
  475.     return $pparser->getParams();
  476. }
  477.  
  478. class mosEmpty {
  479.     function def$key$value='' {
  480.         return 1;
  481.     }
  482.     function get$key$default='' {
  483.         return 1;
  484.     }
  485. }
  486.  
  487. function mosIsRTL(){
  488.     $core mamboCore::getMamboCore();
  489.     if $core->current_language->text_direction == "rtl" ){
  490.         return true;
  491.     else {
  492.         return false;
  493.     }
  494. }
  495. function utf8_substr($str,$start){
  496.     preg_match_all("/./u"$str$ar);
  497.     if(func_num_args(>= 3{
  498.         $end func_get_arg(2);
  499.         return join("",array_slice($ar[0],$start,$end));
  500.     else {
  501.         return join("",array_slice($ar[0],$start));
  502.     }
  503. }
  504. ?>

Documentation generated on Mon, 05 May 2008 16:21:00 +0400 by phpDocumentor 1.4.0