319 // POST check added in 1.1.x because Firefox asks us if we want to "resend the form |
319 // POST check added in 1.1.x because Firefox asks us if we want to "resend the form |
320 // data to the new location", which can be confusing for some users. |
320 // data to the new location", which can be confusing for some users. |
321 if ( $timeout == 0 && empty($_POST) ) |
321 if ( $timeout == 0 && empty($_POST) ) |
322 { |
322 { |
323 header('Location: ' . $url); |
323 header('Location: ' . $url); |
|
324 header('Content-length: 0'); |
324 header('HTTP/1.1 307 Temporary Redirect'); |
325 header('HTTP/1.1 307 Temporary Redirect'); |
|
326 |
|
327 // with 3xx codes HTTP clients expect a response of 0 bytes, so just die here |
|
328 exit(); |
325 } |
329 } |
326 |
330 |
327 if ( !is_object($template) ) |
331 if ( !is_object($template) ) |
328 { |
332 { |
329 $template = new template_nodb(); |
333 $template = new template_nodb(); |
330 $template->load_theme('oxygen', 'bleu', false); |
334 $template->load_theme('oxygen', 'bleu', false); |
331 $template->tpl_strings['SITE_NAME'] = 'Enano'; |
335 $template->tpl_strings['SITE_NAME'] = 'Enano'; |
332 $template->tpl_strings['SITE_DESC'] = 'This site is experiencing a critical error and cannot load.'; |
336 $template->tpl_strings['SITE_DESC'] = 'This site is experiencing a critical error and cannot load.'; |
333 $template->tpl_strings['COPYRIGHT'] = 'Powered by Enano CMS - © 2007 Dan Fuhry. This program is Free Software; see the <a href="' . scriptPath . '/install.php?mode=license">GPL file</a> included with this package for details.'; |
337 $template->tpl_strings['COPYRIGHT'] = 'Powered by Enano CMS - © 2006-2008 Dan Fuhry. This program is Free Software; see the <a href="' . scriptPath . '/install.php?mode=license">GPL file</a> included with this package for details.'; |
334 $template->tpl_strings['PAGE_NAME'] = htmlspecialchars($title); |
338 $template->tpl_strings['PAGE_NAME'] = htmlspecialchars($title); |
335 } |
339 } |
336 |
340 |
337 $template->add_header('<meta http-equiv="refresh" content="' . $timeout . '; url=' . str_replace('"', '\\"', $url) . '" />'); |
341 $template->add_header('<meta http-equiv="refresh" content="' . $timeout . '; url=' . str_replace('"', '\\"', $url) . '" />'); |
338 $template->add_header('<script type="text/javascript"> |
342 $template->add_header('<script type="text/javascript"> |
768 */ |
768 */ |
769 |
769 |
770 function show_file_info() |
770 function show_file_info() |
771 { |
771 { |
772 global $db, $session, $paths, $template, $plugins; // Common objects |
772 global $db, $session, $paths, $template, $plugins; // Common objects |
773 if($paths->namespace != 'File') return null; // Prevent unnecessary work |
773 global $lang; |
774 $selfn = $paths->page_id; // substr($paths->page, strlen($paths->nslist['File']), strlen($paths->cpage)); |
774 |
775 if(substr($paths->cpage['name'], 0, strlen($paths->nslist['File']))==$paths->nslist['File']) $selfn = substr($paths->page_id, strlen($paths->nslist['File']), strlen($paths->page_id)); |
775 // Prevent unnecessary work |
|
776 if ( $paths->namespace != 'File' ) |
|
777 return null; |
|
778 |
|
779 $selfn = $paths->page_id; |
|
780 if ( substr($paths->cpage['name'], 0, strlen($paths->nslist['File'])) == $paths->nslist['File']) |
|
781 { |
|
782 $selfn = substr($paths->page_id, strlen($paths->nslist['File']), strlen($paths->page_id)); |
|
783 } |
776 $q = $db->sql_query('SELECT mimetype,time_id,size FROM '.table_prefix.'files WHERE page_id=\''.$selfn.'\' ORDER BY time_id DESC;'); |
784 $q = $db->sql_query('SELECT mimetype,time_id,size FROM '.table_prefix.'files WHERE page_id=\''.$selfn.'\' ORDER BY time_id DESC;'); |
777 if(!$q) $db->_die('The file type could not be fetched.'); |
785 if ( !$q ) |
778 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; } |
786 { |
|
787 $db->_die('The file type could not be fetched.'); |
|
788 } |
|
789 |
|
790 if ( $db->numrows() < 1 ) |
|
791 { |
|
792 echo '<div class="mdg-comment" style="margin-left: 0;"> |
|
793 <h3>' . $lang->get('onpage_filebox_heading') . '</h3> |
|
794 <p>' . $lang->get('onpage_filebox_msg_not_found', array('upload_link' => makeUrlNS('Special', 'UploadFile/'.$paths->page_id))) . '</p> |
|
795 </div> |
|
796 <br />'; |
|
797 return; |
|
798 } |
779 $r = $db->fetchrow(); |
799 $r = $db->fetchrow(); |
780 $mimetype = $r['mimetype']; |
800 $mimetype = $r['mimetype']; |
781 $datestring = enano_date('F d, Y h:i a', (int)$r['time_id']); |
801 $datestring = enano_date('F d, Y h:i a', (int)$r['time_id']); |
782 echo '<div class="mdg-comment" style="margin-left: 0;"><p><h3>Uploaded file</h3></p><p>Type: '.$r['mimetype'].'<br />Size: '; |
802 echo '<div class="mdg-comment" style="margin-left: 0;"> |
783 $fs = $r['size']; |
803 <h3>' . $lang->get('onpage_filebox_heading') . '</h3> |
784 echo $fs.' bytes'; |
804 <p>' . $lang->get('onpage_filebox_lbl_type') . ' '.$r['mimetype'].'<br />'; |
785 $fs = (int)$fs; |
805 |
786 if($fs >= 1048576) |
806 $size = $r['size'] . ' ' . $lang->get('etc_unit_bytes'); |
787 { |
807 if ( $r['size'] >= 1048576 ) |
788 $fs = round($fs / 1048576, 1); |
808 { |
789 echo ' ('.$fs.' MB)'; |
809 $size .= ' (' . ( round($r['size'] / 1048576, 1) ) . ' ' . $lang->get('etc_unit_megabytes_short') . ')'; |
790 } elseif($fs >= 1024) { |
810 } |
791 $fs = round($fs / 1024, 1); |
811 else if ( $r['size'] >= 1024 ) |
792 echo ' ('.$fs.' KB)'; |
812 { |
793 } |
813 $size .= ' (' . ( round($r['size'] / 1024, 1) ) . ' ' . $lang->get('etc_unit_kilobytes_short') . ')'; |
794 echo '<br />Uploaded: '.$datestring.'</p>'; |
814 } |
795 if(substr($mimetype, 0, 6)!='image/' && ( substr($mimetype, 0, 5) != 'text/' || $mimetype == 'text/html' || $mimetype == 'text/javascript' )) |
815 |
796 { |
816 echo $lang->get('onpage_filebox_lbl_size', array('size' => $size)); |
797 echo '<div class="warning-box">This file type may contain viruses or other code that could harm your computer. You should exercise caution if you download it.</div>'; |
817 |
798 } |
818 echo '<br />' . $lang->get('onpage_filebox_lbl_uploaded') . ' ' . $datestring . '</p>'; |
799 if(substr($mimetype, 0, 6)=='image/') |
819 if ( substr($mimetype, 0, 6) != 'image/' && ( substr($mimetype, 0, 5) != 'text/' || $mimetype == 'text/html' || $mimetype == 'text/javascript' ) ) |
800 { |
820 { |
801 echo '<p><a href="'.makeUrlNS('Special', 'DownloadFile'.'/'.$selfn).'"><img style="border: 0;" alt="'.$paths->page.'" src="'.makeUrlNS('Special', 'DownloadFile'.'/'.$selfn.htmlspecialchars(urlSeparator).'preview').'" /></a></p>'; |
821 echo '<div class="warning-box"> |
802 } |
822 ' . $lang->get('onpage_filebox_msg_virus_warning') . ' |
803 echo '<p><a href="'.makeUrlNS('Special', 'DownloadFile'.'/'.$selfn.'/'.$r['time_id'].htmlspecialchars(urlSeparator).'download').'">Download this file</a>'; |
823 </div>'; |
|
824 } |
|
825 if ( substr($mimetype, 0, 6) == 'image/' ) |
|
826 { |
|
827 echo '<p> |
|
828 <a href="'.makeUrlNS('Special', 'DownloadFile'.'/'.$selfn).'"> |
|
829 <img style="border: 0;" alt="'.$paths->page.'" src="'.makeUrlNS('Special', 'DownloadFile'.'/'.$selfn.htmlspecialchars(urlSeparator).'preview').'" /> |
|
830 </a> |
|
831 </p>'; |
|
832 } |
|
833 echo '<p> |
|
834 <a href="'.makeUrlNS('Special', 'DownloadFile'.'/'.$selfn.'/'.$r['time_id'].htmlspecialchars(urlSeparator).'download').'"> |
|
835 ' . $lang->get('onpage_filebox_btn_download') . ' |
|
836 </a>'; |
804 if(!$paths->page_protected && ( $paths->wiki_mode || $session->get_permissions('upload_new_version') )) |
837 if(!$paths->page_protected && ( $paths->wiki_mode || $session->get_permissions('upload_new_version') )) |
805 { |
838 { |
806 echo ' | <a href="'.makeUrlNS('Special', 'UploadFile'.'/'.$selfn).'">Upload new version</a>'; |
839 echo ' | <a href="'.makeUrlNS('Special', 'UploadFile'.'/'.$selfn).'"> |
|
840 ' . $lang->get('onpage_filebox_btn_upload_new') . ' |
|
841 </a>'; |
807 } |
842 } |
808 echo '</p>'; |
843 echo '</p>'; |
809 if($db->numrows() > 1) |
844 if ( $db->numrows() > 1 ) |
810 { |
845 { |
811 echo '<h3>File history</h3><p>'; |
846 echo '<h3>' . $lang->get('onpage_filebox_heading_history') . '</h3><p>'; |
812 while($r = $db->fetchrow()) |
847 while ( $r = $db->fetchrow() ) |
813 { |
848 { |
814 echo '(<a href="'.makeUrlNS('Special', 'DownloadFile'.'/'.$selfn.'/'.$r['time_id'].htmlspecialchars(urlSeparator).'download').'">this ver</a>) '; |
849 echo '(<a href="'.makeUrlNS('Special', 'DownloadFile'.'/'.$selfn.'/'.$r['time_id'].htmlspecialchars(urlSeparator).'download').'">' . $lang->get('onpage_filebox_btn_this_version') . '</a>) '; |
815 if($session->get_permissions('history_rollback')) |
850 if ( $session->get_permissions('history_rollback') ) |
816 echo ' (<a href="#" onclick="ajaxRollback(\''.$r['time_id'].'\'); return false;">revert</a>) '; |
851 echo ' (<a href="#" onclick="ajaxRollback(\''.$r['time_id'].'\'); return false;">' . $lang->get('onpage_filebox_btn_revert') . '</a>) '; |
817 $mimetype = $r['mimetype']; |
852 $mimetype = $r['mimetype']; |
818 $datestring = enano_date('F d, Y h:i a', (int)$r['time_id']); |
853 $datestring = enano_date('F d, Y h:i a', (int)$r['time_id']); |
|
854 |
819 echo $datestring.': '.$r['mimetype'].', '; |
855 echo $datestring.': '.$r['mimetype'].', '; |
|
856 |
820 $fs = $r['size']; |
857 $fs = $r['size']; |
821 $fs = (int)$fs; |
858 $fs = (int)$fs; |
|
859 |
822 if($fs >= 1048576) |
860 if($fs >= 1048576) |
823 { |
861 { |
824 $fs = round($fs / 1048576, 1); |
862 $fs = round($fs / 1048576, 1); |
825 echo ' '.$fs.' MB'; |
863 $size = $fs . ' ' . $lang->get('etc_unit_megabytes_short'); |
826 } elseif($fs >= 1024) { |
864 } |
|
865 else |
|
866 if ( $fs >= 1024 ) |
|
867 { |
827 $fs = round($fs / 1024, 1); |
868 $fs = round($fs / 1024, 1); |
828 echo ' '.$fs.' KB'; |
869 $size = $fs . ' ' . $lang->get('etc_unit_kilobytes_short'); |
829 } else { |
870 } |
830 echo ' '.$fs.' bytes'; |
871 else |
831 } |
872 { |
|
873 $size = $fs . ' ' . $lang->get('etc_unit_bytes'); |
|
874 } |
|
875 |
|
876 echo $size; |
|
877 |
832 echo '<br />'; |
878 echo '<br />'; |
833 } |
879 } |
834 echo '</p>'; |
880 echo '</p>'; |
835 } |
881 } |
836 $db->free_result(); |
882 $db->free_result(); |
874 { |
920 { |
875 eval($cmd); |
921 eval($cmd); |
876 } |
922 } |
877 show_file_info(); |
923 show_file_info(); |
878 show_category_info(); |
924 show_category_info(); |
879 } |
|
880 |
|
881 /** |
|
882 * Deprecated, do not use. |
|
883 */ |
|
884 |
|
885 function password_prompt($id = false) |
|
886 { |
|
887 global $db, $session, $paths, $template, $plugins; // Common objects |
|
888 if(!$id) $id = $paths->page; |
|
889 if(isset($paths->pages[$id]['password']) && strlen($paths->pages[$id]['password']) == 40 && !isset($_REQUEST['pagepass'])) |
|
890 { |
|
891 die_friendly('Password required', '<p>You must supply a password to access this page.</p><form action="'.makeUrl($paths->pages[$id]['urlname']).'" method="post"><p>Password: <input name="pagepass" type="password" /></p><p><input type="submit" value="Submit" /></p>'); |
|
892 } elseif(isset($_REQUEST['pagepass'])) { |
|
893 $p = (preg_match('#^([a-f0-9]*){40}$#', $_REQUEST['pagepass'])) ? $_REQUEST['pagepass'] : sha1($_REQUEST['pagepass']); |
|
894 if($p != $paths->pages[$id]['password']) die_friendly('Password required', '<p style="color: red;">The password you entered is incorrect.</p><form action="'.makeUrl($paths->page).'" method="post"><p>Password: <input name="pagepass" type="password" /></p><p><input type="submit" value="Submit" /></p>'); |
|
895 } |
|
896 } |
|
897 |
|
898 /** |
|
899 * Some sort of primitive hex converter from back in the day. Deprecated, do not use. |
|
900 * @param string Text to encode |
|
901 * @return string |
|
902 */ |
|
903 |
|
904 function str_hex($string){ |
|
905 $hex=''; |
|
906 for ($i=0; $i < strlen($string); $i++){ |
|
907 $hex .= ' '.dechex(ord($string[$i])); |
|
908 } |
|
909 return substr($hex, 1, strlen($hex)); |
|
910 } |
925 } |
911 |
926 |
912 /** |
927 /** |
913 * Essentially an return code reader for a socket. Don't use this unless you're writing mail code and smtp_send_email doesn't cut it. Ported from phpBB's smtp.php. |
928 * Essentially an return code reader for a socket. Don't use this unless you're writing mail code and smtp_send_email doesn't cut it. Ported from phpBB's smtp.php. |
914 * @param socket A socket resource |
929 * @param socket A socket resource |