includes/functions.php
changeset 345 4ccdfeee9a11
parent 343 eefe9ab7fe7c
child 359 e0787bb6285b
equal deleted inserted replaced
344:be6c5fdd9203 345:4ccdfeee9a11
   220 
   220 
   221   $baseprot = 'http' . ( isset($_SERVER['HTTPS']) ? 's' : '' ) . '://' . $_SERVER['HTTP_HOST'];
   221   $baseprot = 'http' . ( isset($_SERVER['HTTPS']) ? 's' : '' ) . '://' . $_SERVER['HTTP_HOST'];
   222   $url = $baseprot . $url;
   222   $url = $baseprot . $url;
   223 
   223 
   224   return ($escape) ? htmlspecialchars($url) : $url;
   224   return ($escape) ? htmlspecialchars($url) : $url;
       
   225 }
       
   226 
       
   227 /**
       
   228  * Enano replacement for date(). Accounts for individual users' timezone preferences.
       
   229  * @param string Date-formatted string
       
   230  * @param int Optional - UNIX timestamp value to use. If omitted, the current time is used.
       
   231  * @return string Formatted string
       
   232  */
       
   233 
       
   234 function enano_date($string, $timestamp = false)
       
   235 {
       
   236   if ( !is_int($timestamp) && !is_double($timestamp) && strval(intval($timestamp)) !== $timestamp )
       
   237     $timestamp = time();
       
   238   // FIXME: Offset $timestamp by user's timezone
       
   239   return gmdate($string, $timestamp);
   225 }
   240 }
   226 
   241 
   227 /**
   242 /**
   228  * Tells you the title for the given page ID string
   243  * Tells you the title for the given page ID string
   229  * @param string Page ID string (ex: Special:Administration)
   244  * @param string Page ID string (ex: Special:Administration)
   745   $q = $db->sql_query('SELECT mimetype,time_id,size FROM '.table_prefix.'files WHERE page_id=\''.$selfn.'\' ORDER BY time_id DESC;');
   760   $q = $db->sql_query('SELECT mimetype,time_id,size FROM '.table_prefix.'files WHERE page_id=\''.$selfn.'\' ORDER BY time_id DESC;');
   746   if(!$q) $db->_die('The file type could not be fetched.');
   761   if(!$q) $db->_die('The file type could not be fetched.');
   747   if($db->numrows() < 1) { echo '<div class="mdg-comment" style="margin-left: 0;"><h3>Uploaded file</h3><p>There are no files uploaded with this name yet. <a href="'.makeUrlNS('Special', 'UploadFile/'.$paths->page_id).'">Upload a file...</a></p></div><br />'; return; }
   762   if($db->numrows() < 1) { echo '<div class="mdg-comment" style="margin-left: 0;"><h3>Uploaded file</h3><p>There are no files uploaded with this name yet. <a href="'.makeUrlNS('Special', 'UploadFile/'.$paths->page_id).'">Upload a file...</a></p></div><br />'; return; }
   748   $r = $db->fetchrow();
   763   $r = $db->fetchrow();
   749   $mimetype = $r['mimetype'];
   764   $mimetype = $r['mimetype'];
   750   $datestring = date('F d, Y h:i a', (int)$r['time_id']);
   765   $datestring = enano_date('F d, Y h:i a', (int)$r['time_id']);
   751   echo '<div class="mdg-comment" style="margin-left: 0;"><p><h3>Uploaded file</h3></p><p>Type: '.$r['mimetype'].'<br />Size: ';
   766   echo '<div class="mdg-comment" style="margin-left: 0;"><p><h3>Uploaded file</h3></p><p>Type: '.$r['mimetype'].'<br />Size: ';
   752   $fs = $r['size'];
   767   $fs = $r['size'];
   753   echo $fs.' bytes';
   768   echo $fs.' bytes';
   754   $fs = (int)$fs;
   769   $fs = (int)$fs;
   755   if($fs >= 1048576)
   770   if($fs >= 1048576)
   782     {
   797     {
   783       echo '(<a href="'.makeUrlNS('Special', 'DownloadFile'.'/'.$selfn.'/'.$r['time_id'].htmlspecialchars(urlSeparator).'download').'">this ver</a>) ';
   798       echo '(<a href="'.makeUrlNS('Special', 'DownloadFile'.'/'.$selfn.'/'.$r['time_id'].htmlspecialchars(urlSeparator).'download').'">this ver</a>) ';
   784       if($session->get_permissions('history_rollback'))
   799       if($session->get_permissions('history_rollback'))
   785         echo ' (<a href="#" onclick="ajaxRollback(\''.$r['time_id'].'\'); return false;">revert</a>) ';
   800         echo ' (<a href="#" onclick="ajaxRollback(\''.$r['time_id'].'\'); return false;">revert</a>) ';
   786       $mimetype = $r['mimetype'];
   801       $mimetype = $r['mimetype'];
   787       $datestring = date('F d, Y h:i a', (int)$r['time_id']);
   802       $datestring = enano_date('F d, Y h:i a', (int)$r['time_id']);
   788       echo $datestring.': '.$r['mimetype'].', ';
   803       echo $datestring.': '.$r['mimetype'].', ';
   789       $fs = $r['size'];
   804       $fs = $r['size'];
   790       $fs = (int)$fs;
   805       $fs = (int)$fs;
   791       if($fs >= 1048576)
   806       if($fs >= 1048576)
   792       {
   807       {