function extension_for($type) { $types = mime_types(); foreach ($types as $key => $val) { if ($val == $type) { return $key; } } return "html"; }
function render_partial(&$request, $template) { trigger_before('render_partial', $this, $this); // content_for_layout() passes the $request->action as $template $ext = $this->pick_template_extension($request, $template); $view = $request->get_template_path($ext, $template); if ($template == 'get') { $template = 'index'; } if (file_exists($view)) { $action = "_" . $template; } else { $action = $template; } global $db; if (file_exists($view) && function_exists($action)) { trigger_before($request->action, $request, $db); $result = $action(array_merge($this->named_vars, $db->get_resource())); trigger_after($request->action, $request, $db); if (is_array($result)) { extract($result); } if (!$this->header_sent) { $content_type = 'Content-Type: ' . $this->pick_content_type($ext); if ($this->pick_content_charset($ext)) { $content_type .= '; charset=' . $this->pick_content_charset($ext); } header($content_type); $this->header_sent = true; } include $view; } else { // no template, check for blobcall if (in_array(type_of($ext), mime_types()) && !$this->header_sent) { $model =& $db->get_table($request->resource); if (isset($model->blob)) { $template = $model->blob; } trigger_before($request->action, $request, $db); $Member = $this->collection->MoveFirst(); render_blob($Member->{$template}, $ext); } else { if (strpos($request->uri, 'robots') === false || strpos($request->uri, 'crawl') === false) { admin_alert($request->uri . " {$view} {$action} " . $_SERVER[REMOTE_HOST]); } } } }
function CheckHttpdConf_mime_module() { $unix = new unix(); $httpdconf = $unix->LOCATE_APACHE_CONF_PATH(); $DAEMON_PATH = $unix->getmodpathfromconf($httpdconf); mime_types("{$DAEMON_PATH}/mime.types"); $f[] = "<IfModule mod_mime.c>"; $f[] = "\tTypesConfig /etc/mime.types"; $f[] = "\tAddType application/octet-stream \t\t\t.acl"; $f[] = "\tAddType application/octet-stream\t\t\t\t\t.ova"; $f[] = "\tAddType application/octet-stream\t\t\t\t\t.ovf"; $f[] = "\tAddType application/octet-stream\t\t\t\t\t.xva"; $f[] = "\tAddType application/octet-stream\t\t\t\t\t.hdx"; $f[] = "\tAddType application/x-gzip \t\t\t\t\t.tgz"; $f[] = "\tAddType text/html \t\t\t\t\t\t\t.html .htm"; $f[] = "\tAddType application/x-shockwave-flash \t\t.swf "; $f[] = "\tAddType text/plain \t\t\t\t\t\t\t.txt"; $f[] = "\tAddType text/richtext \t\t\t\t\t\t.rtx"; $f[] = "\tAddType text/tab-separated-values \t\t\t.tsv"; $f[] = "\tAddType text/x-setext \t\t\t\t\t\t.etx"; $f[] = "\tAddType text/x-server-parsed-html \t\t\t.shtml .sht"; $f[] = "\tAddType application/macbinhex-40 \t\t\t.hqx"; $f[] = "\tAddType application/netalivelink \t\t\t.nel"; $f[] = "\tAddType application/netalive \t\t\t\t.net"; $f[] = "\tAddType application/octet-stream \t\t\t.bin .exe"; $f[] = "\tAddType application/oda \t\t\t\t\t.oda"; $f[] = "\tAddType application/pdf \t\t\t\t\t.pdf"; $f[] = "\tAddType application/postscript \t\t\t\t.ai .eps .ps"; $f[] = "\tAddType application/rtf \t\t\t\t\t.rtf"; $f[] = "\tAddType application/zip \t\t\t\t\t.zip"; $f[] = "\tAddType application/x-mif \t\t\t\t\t.mif"; $f[] = "\tAddType application/x-csh \t\t\t\t\t.csh"; $f[] = "\tAddType application/x-dvi \t\t\t\t\t.dvi"; $f[] = "\tAddType application/x-hdf \t\t\t\t\t.hdf"; $f[] = "\tAddType application/x-latex \t\t\t\t.latex"; $f[] = "\tAddType application/x-netcdf \t\t\t\t.nc .cdf"; $f[] = "\tAddType application/x-sh \t\t\t\t\t.sh"; $f[] = "\tAddType application/x-tcl .tcl"; $f[] = "\tAddType application/x-tex .tex"; $f[] = "\tAddType application/x-texinfo .texinfo .texi"; $f[] = "\tAddType application/x-troff .t .tr .roff"; $f[] = "\tAddType application/x-troff-man .man"; $f[] = "\tAddType application/x-troff-me .me"; $f[] = "\tAddType application/x-troff-ms .ms"; $f[] = "\tAddType application/x-wais-source .src"; $f[] = "\tAddType application/x-bcpio .bcpio"; $f[] = "\tAddType application/x-cpio .cpio"; $f[] = "\tAddType application/x-gtar .gtar"; $f[] = "\tAddType application/x-shar .shar"; $f[] = "\tAddType application/x-sv4cpio .sv4cpio"; $f[] = "\tAddType application/x-sv4crc .sv4crc"; $f[] = "\tAddType application/x-tar .tar"; $f[] = "\tAddType application/x-ustar .ustar"; $f[] = "\tAddType application/x-director .dcr"; $f[] = "\tAddType application/x-director .dir"; $f[] = "\tAddType application/x-director .dxr"; $f[] = "\tAddType application/x-onlive .sds"; $f[] = "\tAddType application/x-httpd-cgi .cgi"; $f[] = "\tAddType image/gif .gif .GIF"; $f[] = "\tAddType image/ief .ief"; $f[] = "\tAddType image/jpeg .jpeg .jpg .jpe .JPG"; $f[] = "\tAddType image/tiff .tiff .tif"; $f[] = "\tAddType image/x-cmu-raster .ras"; $f[] = "\tAddType image/x-portable-anymap .pnm"; $f[] = "\tAddType image/x-portable-bitmap .pbm"; $f[] = "\tAddType image/x-portable-graymap .pgm"; $f[] = "\tAddType image/x-portable-pixmap .ppm"; $f[] = "\tAddType image/x-rgb .rgb"; $f[] = "\tAddType image/x-xbitmap .xbm"; $f[] = "\tAddType image/x-xpixmap .xpm"; $f[] = "\tAddType image/x-xwindowdump .xwd"; $f[] = "\tAddType audio/basic .au .snd"; $f[] = "\tAddType audio/x-aiff .aif .aiff .aifc"; $f[] = "\tAddType audio/x-wav .wav"; $f[] = "\tAddType audio/x-pn-realaudio .ram"; $f[] = "\tAddType audio/x-midi .mid"; $f[] = "\tAddType video/mpeg .mpeg .mpg .mpe"; $f[] = "\tAddType video/quicktime .qt .mov"; $f[] = "\tAddType video/x-msvideo .avi"; $f[] = "\tAddType video/x-sgi-movie .movie"; $f[] = "\tAddType x-world/x-vrml .wrl"; $f[] = "\tAddType application/x-compress .Z"; $f[] = "\tAddType application/x-gzip .gz .tgz"; $f[] = "\tAddType application/x-bzip2 .bz2"; $f[] = ""; $f[] = "#"; $f[] = "# DefaultLanguage and AddLanguage allows you to specify the language of "; $f[] = "# a document. You can then use content negotiation to give a browser a "; $f[] = "# file in a language the user can understand."; $f[] = "#"; $f[] = "# Specify a default language. This means that all data"; $f[] = "# going out without a specific language tag (see below) will "; $f[] = "# be marked with this one. You probably do NOT want to set"; $f[] = "# this unless you are sure it is correct for all cases."; $f[] = "#"; $f[] = "# * It is generally better to not mark a page as "; $f[] = "# * being a certain language than marking it with the wrong"; $f[] = "# * language!"; $f[] = "#"; $f[] = "# DefaultLanguage us"; $f[] = "#"; $f[] = "# Note 1: The suffix does not have to be the same as the language"; $f[] = "# keyword --- those with documents in Polish (whose net-standard"; $f[] = "# language code is pl) may wish to use \"AddLanguage pl .po\" to"; $f[] = "# avoid the ambiguity with the common suffix for perl scripts."; $f[] = "#"; $f[] = "# Note 2: The example entries below illustrate that in some cases "; $f[] = "# the two character 'Language' abbreviation is not identical to "; $f[] = "# the two character 'Country' code for its country,"; $f[] = "# E.g. 'Danmark/dk' versus 'Danish/da'."; $f[] = "#"; $f[] = "# Note 3: In the case of 'ltz' we violate the RFC by using a three char"; $f[] = "# specifier. There is 'work in progress' to fix this and get"; $f[] = "# the reference data for rfc1766 cleaned up."; $f[] = "#"; $f[] = "# Catalan (ca) - Croatian (hr) - Czech (cs) - Danish (da) - Dutch (nl)"; $f[] = "# English (en) - Esperanto (eo) - Estonian (et) - French (fr) - German (de)"; $f[] = "# Greek-Modern (el) - Hebrew (he) - Italian (it) - Japanese (ja)"; $f[] = "# Korean (ko) - Luxembourgeois* (ltz) - Norwegian Nynorsk (nn)"; $f[] = "# Norwegian (no) - Polish (pl) - Portugese (pt)"; $f[] = "# Brazilian Portuguese (pt-BR) - Russian (ru) - Swedish (sv)"; $f[] = "# Simplified Chinese (zh-CN) - Spanish (es) - Traditional Chinese (zh-TW)"; $f[] = "#"; $f[] = "AddLanguage am .amh"; $f[] = "AddLanguage ar .ara"; $f[] = "AddLanguage be .be"; $f[] = "AddLanguage bg .bg"; $f[] = "AddLanguage bn .bn"; $f[] = "AddLanguage br .br"; $f[] = "AddLanguage bs .bs"; $f[] = "AddLanguage ca .ca"; $f[] = "AddLanguage cs .cz .cs"; $f[] = "AddLanguage cy .cy"; $f[] = "AddLanguage da .dk"; $f[] = "AddLanguage de .de"; $f[] = "AddLanguage dz .dz"; $f[] = "AddLanguage el .el"; $f[] = "AddLanguage en .en"; $f[] = "AddLanguage eo .eo"; $f[] = "# es is ecmascript in /etc/mime.types"; $f[] = "RemoveType es"; $f[] = "AddLanguage es .es"; $f[] = "AddLanguage et .et"; $f[] = "AddLanguage eu .eu"; $f[] = "AddLanguage fa .fa"; $f[] = "AddLanguage fi .fi"; $f[] = "AddLanguage fr .fr"; $f[] = "AddLanguage ga .ga"; $f[] = "AddLanguage gl .glg"; $f[] = "AddLanguage gu .gu"; $f[] = "AddLanguage he .he"; $f[] = "AddLanguage hi .hi"; $f[] = "AddLanguage hr .hr"; $f[] = "AddLanguage hu .hu"; $f[] = "AddLanguage hy .hy"; $f[] = "AddLanguage id .id"; $f[] = "AddLanguage is .is"; $f[] = "AddLanguage it .it"; $f[] = "AddLanguage ja .ja"; $f[] = "AddLanguage ka .ka"; $f[] = "AddLanguage kk .kk"; $f[] = "AddLanguage km .km"; $f[] = "AddLanguage kn .kn"; $f[] = "AddLanguage ko .ko"; $f[] = "AddLanguage ku .ku"; $f[] = "AddLanguage lo .lo"; $f[] = "AddLanguage lt .lt"; $f[] = "AddLanguage ltz .ltz"; $f[] = "AddLanguage lv .lv"; $f[] = "AddLanguage mg .mg"; $f[] = "AddLanguage mk .mk"; $f[] = "AddLanguage ml .ml"; $f[] = "AddLanguage mr .mr"; $f[] = "AddLanguage ms .msa"; $f[] = "AddLanguage nb .nob"; $f[] = "AddLanguage ne .ne"; $f[] = "AddLanguage nl .nl"; $f[] = "AddLanguage nn .nn"; $f[] = "AddLanguage no .no"; $f[] = "AddLanguage pa .pa"; $f[] = "AddLanguage pl .po"; $f[] = "AddLanguage pt-BR .pt-br"; $f[] = "AddLanguage pt .pt"; $f[] = "AddLanguage ro .ro"; $f[] = "AddLanguage ru .ru"; $f[] = "AddLanguage sa .sa"; $f[] = "AddLanguage se .se"; $f[] = "AddLanguage si .si"; $f[] = "AddLanguage sk .sk"; $f[] = "AddLanguage sl .sl"; $f[] = "AddLanguage sq .sq"; $f[] = "AddLanguage sr .sr"; $f[] = "AddLanguage sv .sv"; $f[] = "AddLanguage ta .ta"; $f[] = "AddLanguage te .te"; $f[] = "AddLanguage th .th"; $f[] = "AddLanguage tl .tl"; $f[] = "RemoveType tr"; $f[] = "# tr is troff in /etc/mime.types"; $f[] = "AddLanguage tr .tr"; $f[] = "AddLanguage uk .uk"; $f[] = "AddLanguage ur .ur"; $f[] = "AddLanguage vi .vi"; $f[] = "AddLanguage wo .wo"; $f[] = "AddLanguage xh .xh"; $f[] = "AddLanguage zh-CN .zh-cn"; $f[] = "AddLanguage zh-TW .zh-tw"; $f[] = ""; $f[] = "#"; $f[] = "# Commonly used filename extensions to character sets. You probably"; $f[] = "# want to avoid clashes with the language extensions, unless you"; $f[] = "# are good at carefully testing your setup after each change."; $f[] = "# See http://www.iana.org/assignments/character-sets for the"; $f[] = "# official list of charset names and their respective RFCs."; $f[] = "#"; $f[] = "AddCharset us-ascii .ascii .us-ascii"; $f[] = "AddCharset ISO-8859-1 .iso8859-1 .latin1"; $f[] = "AddCharset ISO-8859-2 .iso8859-2 .latin2 .cen"; $f[] = "AddCharset ISO-8859-3 .iso8859-3 .latin3"; $f[] = "AddCharset ISO-8859-4 .iso8859-4 .latin4"; $f[] = "AddCharset ISO-8859-5 .iso8859-5 .cyr .iso-ru"; $f[] = "AddCharset ISO-8859-6 .iso8859-6 .arb .arabic"; $f[] = "AddCharset ISO-8859-7 .iso8859-7 .grk .greek"; $f[] = "AddCharset ISO-8859-8 .iso8859-8 .heb .hebrew"; $f[] = "AddCharset ISO-8859-9 .iso8859-9 .latin5 .trk"; $f[] = "AddCharset ISO-8859-10 .iso8859-10 .latin6"; $f[] = "AddCharset ISO-8859-13 .iso8859-13"; $f[] = "AddCharset ISO-8859-14 .iso8859-14 .latin8"; $f[] = "AddCharset ISO-8859-15 .iso8859-15 .latin9"; $f[] = "AddCharset ISO-8859-16 .iso8859-16 .latin10"; $f[] = "AddCharset ISO-2022-JP .iso2022-jp .jis"; $f[] = "AddCharset ISO-2022-KR .iso2022-kr .kis"; $f[] = "AddCharset ISO-2022-CN .iso2022-cn .cis"; $f[] = "AddCharset Big5 .Big5 .big5 .b5"; $f[] = "AddCharset cn-Big5 .cn-big5"; $f[] = "# For russian, more than one charset is used (depends on client, mostly):"; $f[] = "AddCharset WINDOWS-1251 .cp-1251 .win-1251"; $f[] = "AddCharset CP866 .cp866"; $f[] = "AddCharset KOI8 .koi8"; $f[] = "AddCharset KOI8-E .koi8-e"; $f[] = "AddCharset KOI8-r .koi8-r .koi8-ru"; $f[] = "AddCharset KOI8-U .koi8-u"; $f[] = "AddCharset KOI8-ru .koi8-uk .ua"; $f[] = "AddCharset ISO-10646-UCS-2 .ucs2"; $f[] = "AddCharset ISO-10646-UCS-4 .ucs4"; $f[] = "AddCharset UTF-7 .utf7"; $f[] = "AddCharset UTF-8 .utf8"; $f[] = "AddCharset UTF-16 .utf16"; $f[] = "AddCharset UTF-16BE .utf16be"; $f[] = "AddCharset UTF-16LE .utf16le"; $f[] = "AddCharset UTF-32 .utf32"; $f[] = "AddCharset UTF-32BE .utf32be"; $f[] = "AddCharset UTF-32LE .utf32le"; $f[] = "AddCharset euc-cn .euc-cn"; $f[] = "AddCharset euc-gb .euc-gb"; $f[] = "AddCharset euc-jp .euc-jp"; $f[] = "AddCharset euc-kr .euc-kr"; $f[] = "#Not sure how euc-tw got in - IANA doesn't list it???"; $f[] = "AddCharset EUC-TW .euc-tw"; $f[] = "AddCharset gb2312 .gb2312 .gb"; $f[] = "AddCharset iso-10646-ucs-2 .ucs-2 .iso-10646-ucs-2"; $f[] = "AddCharset iso-10646-ucs-4 .ucs-4 .iso-10646-ucs-4"; $f[] = "AddCharset shift_jis .shift_jis .sjis"; $f[] = ""; $f[] = "#"; $f[] = "# AddHandler allows you to map certain file extensions to \"handlers\":"; $f[] = "# actions unrelated to filetype. These can be either built into the server"; $f[] = "# or added with the Action directive (see below)"; $f[] = "#"; $f[] = "# To use CGI scripts outside of ScriptAliased directories:"; $f[] = "# (You will also need to add \"ExecCGI\" to the \"Options\" directive.)"; $f[] = "#"; $f[] = "#AddHandler cgi-script .cgi"; $f[] = ""; $f[] = "#"; $f[] = "# For files that include their own HTTP headers:"; $f[] = "#"; $f[] = "#AddHandler send-as-is asis"; $f[] = ""; $f[] = "#"; $f[] = "# For server-parsed imagemap files:"; $f[] = "#"; $f[] = "#AddHandler imap-file map"; $f[] = ""; $f[] = "#"; $f[] = "# For type maps (negotiated resources):"; $f[] = "# (This is enabled by default to allow the Apache \"It Worked\" page"; $f[] = "# to be distributed in multiple languages.)"; $f[] = "#"; $f[] = "AddHandler type-map var"; $f[] = ""; $f[] = "#"; $f[] = "# Filters allow you to process content before it is sent to the client."; $f[] = "#"; $f[] = "# To parse .shtml files for server-side includes (SSI):"; $f[] = "# (You will also need to add \"Includes\" to the \"Options\" directive.)"; $f[] = "#"; $f[] = "AddType text/html .shtml"; $f[] = "AddOutputFilter INCLUDES .shtml"; $f[] = ""; $f[] = "</IfModule>"; $f[] = ""; @file_put_contents("{$DAEMON_PATH}/mime.conf", @implode("\n", $f)); }