Public paste
view
By: fruffl | Date: Mar 6 2010 00:42 | Format: PHP | Expires: never | Size: 14.83 KB | Hits: 1298

  1. <?php
  2.  
  3.  
  4.         FINAL CLASS FRUFFL_SequenceFrontend_LinkView EXTENDS FRUFFL_SequenceFrontend_Link
  5.         {              
  6.                 private $headMeta = array();
  7.                 private $headTitle = '';
  8.                 private $headTitlePrefix = '';
  9.                 private $headStyle = NULL;
  10.                 private $headScript = array();
  11.                 private $layout = '';
  12.                 private $layoutEnabled = TRUE;
  13.                 private $viewEnabled = TRUE;
  14.                 private $headContentType = 'text/html';
  15.                 private $ASSIGN = NULL;
  16.                 private $document = '';
  17.                 private $VIEW = NULL;
  18.                 private $_bufferContent = '';
  19.                 private $_viewFile = '';
  20.                 private $PARTIALCACHE = NULL;
  21.                
  22.                 public function init()
  23.                 {
  24.                                
  25.                         $this->ASSIGN = new FRUFFL_ArrayObject();
  26.                         $this->ASSIGN->setFlags(FRUFFL_ArrayObject::ARRAY_AS_PROPS);
  27.                        
  28.                         $this->headStyle = new FRUFFL_ArrayObject();
  29.                         $this->headStyle->setFlags(FRUFFL_ArrayObject::ARRAY_AS_PROPS);
  30.                        
  31.                         $this->INSTANCES
  32.                                 -> setNameMask(__CLASS__.$this->getChildNameMask())
  33.                                 -> setReferenceObject($this)
  34.                                 -> init();
  35.                        
  36.                 }
  37.                
  38.                 public function run()
  39.                 {
  40.                         $REGISTRY = $this->_root->Boot->System->Registry;
  41.                         $this->layout = $REGISTRY->get()->SETTINGS->LAYOUT;
  42.                        
  43.                         $this->headTitlePrefix = $REGISTRY->get()->SETTINGS->PAGETITLE;
  44.                        
  45.                 }
  46.                
  47.                 public function headMeta($meta = '', $content = '')
  48.                 {
  49.                         if(!empty($meta))
  50.                                 if(!isset($this->headMeta[$meta]))
  51.                                         $this->headMeta[$meta] = $content;
  52.                                
  53.                         return $this->headMeta;
  54.                 }
  55.                
  56.                 public function headTitle($title = '')
  57.                 {
  58.                         if(!empty($title))
  59.                                 if(empty($this->headTitle))
  60.                                         $this->headTitle = $title;
  61.                                        
  62.                         return $this->headTitle;
  63.                 }
  64.                
  65.                 public function headTitlePrefix($title = '')
  66.                 {
  67.                         if(!empty($title))
  68.                                 if(empty($this->headTitlePrefix))
  69.                                         $this->headTitlePrefix = $title;
  70.                                        
  71.                         return $this->headTitlePrefix;
  72.                 }
  73.                
  74.                 public function mime($type)
  75.                 {      
  76.                
  77.                         $mime = array(
  78.                                 " "     => "application/octet-stream",
  79.                                 "323"   => "text/h323",
  80.                                 "acx"   => "application/internet-property-stream",
  81.                                 "ai"    => "application/postscript",
  82.                                 "aif"   => "audio/x-aiff",
  83.                                 "aifc"  => "audio/x-aiff",
  84.                                 "aiff"  => "audio/x-aiff",
  85.                                 "asf"   => "video/x-ms-asf",
  86.                                 "asr"   => "video/x-ms-asf",
  87.                                 "asx"   => "video/x-ms-asf",
  88.                                 "au"    => "audio/basic",
  89.                                 "avi"   => "video/x-msvideo",
  90.                                 "axs"   => "application/olescript",
  91.                                 "bas"   => "text/plain",
  92.                                 "bcpio" => "application/x-bcpio",
  93.                                 "bin"   => "application/octet-stream",
  94.                                 "bmp"   => "image/bmp",
  95.                                 "c"     => "text/plain",
  96.                                 "cat"   => "application/vnd.ms-pkiseccat",
  97.                                 'cc'    => 'text/plain',
  98.                                 "cdf"   => "application/x-cdf",
  99.                                 "cer"   => "application/x-x509-ca-cert",
  100.                                 "class" => "application/octet-stream",
  101.                                 "clp"   => "application/x-msclip",
  102.                                 "cmx"   => "image/x-cmx",
  103.                                 "cod"   => "image/cis-cod",
  104.                                 "cpio"  => "application/x-cpio",
  105.                                 'cpp'   => 'text/plain',
  106.                                 'c++'   => 'text/plain',
  107.                                 "crd"   => "application/x-mscardfile",
  108.                                 "crl"   => "application/pkix-crl",
  109.                                 "crt"   => "application/x-x509-ca-cert",
  110.                                 "csh"   => "application/x-csh",
  111.                                 "css"   => "text/css",
  112.                                 "dcr"   => "application/x-director",
  113.                                 "der"   => "application/x-x509-ca-cert",                               
  114.                                 "dir"   => "application/x-director",
  115.                                 "dll"   => "application/x-msdownload",
  116.                                 "dms"   => "application/octet-stream",
  117.                                 "doc"   => "application/msword",
  118.                                 "dot"   => "application/msword",
  119.                                 'dtd'   => 'text/plain',
  120.                                 "dvi"   => "application/x-dvi",
  121.                                 "dxr"   => "application/x-director",
  122.                                 "eps"   => "application/postscript",
  123.                                 "etx"   => "text/x-setext",
  124.                                 "evy"   => "application/envoy",
  125.                                 "exe"   => "application/octet-stream",
  126.                                 "fif"   => "application/fractals",
  127.                                 "flr"   => "x-world/x-vrml",
  128.                                 "gif"   => "image/gif",
  129.                                 "gtar"  => "application/x-gtar",
  130.                                 "gz"    => "application/x-gzip",
  131.                                 "h"     => "text/plain",
  132.                                 "hdf"   => "application/x-hdf",
  133.                                 "hlp"   => "application/winhlp",
  134.                                 "hqx"   => "application/mac-binhex40",
  135.                                 "hta"   => "application/hta",
  136.                                 "htc"   => "text/x-component",
  137.                                 "htm"   => "text/html",
  138.                                 "html"  => "text/html",
  139.                                 "htmls" => "text/html",
  140.                                 "htt"   => "text/webviewhtml",
  141.                                 "ico"   => "image/x-icon",
  142.                                 "ief"   => "image/ief",
  143.                                 "iii"   => "application/x-iphone",
  144.                                 'inc'   => 1, // parse as PHP
  145.                                 "ins"   => "application/x-internet-signup",
  146.                                 "isp"   => "application/x-internet-signup",
  147.                                 "jfif"  => "image/pipeg",
  148.                                 "jpe"   => "image/jpeg",
  149.                                 "jpeg"  => "image/jpeg",
  150.                                 "jpg"   => "image/jpeg",
  151.                                 "js"    => "application/x-javascript",
  152.                                 "json"  => "application/x-javascript",
  153.                                 "latex" => "application/x-latex",
  154.                                 "lha"   => "application/octet-stream",
  155.                                 'log'   => 'text/plain',
  156.                                 "lsf"   => "video/x-la-asf",
  157.                                 "lsx"   => "video/x-la-asf",
  158.                                 "lzh"   => "application/octet-stream",
  159.                                 "m13"   => "application/x-msmediaview",
  160.                                 "m14"   => "application/x-msmediaview",
  161.                                 "m3u"   => "audio/x-mpegurl",
  162.                                 "man"   => "application/x-troff-man",
  163.                                 "mdb"   => "application/x-msaccess",
  164.                                 "me"    => "application/x-troff-me",
  165.                                 "mht"   => "message/rfc822",
  166.                                 "mhtml" => "message/rfc822",
  167.                                 "mid"   => "audio/midi",
  168.                                 'midi'  => 'audio/midi',
  169.                                 "mny"   => "application/x-msmoney",
  170.                                 'mod'   => 'audio/mod',
  171.                                 "mov"   => "video/quicktime",
  172.                                 "movie" => "video/x-sgi-movie",
  173.                                 "mp2"   => "video/mpeg",
  174.                                 "mp3"   => "audio/mpeg",
  175.                                 "mpa"   => "video/mpeg",
  176.                                 "mpe"   => "video/mpeg",
  177.                                 "mpeg"  => "video/mpeg",
  178.                                 "mpg"   => "video/mpeg",
  179.                                 "mpp"   => "application/vnd.ms-project",
  180.                                 "mpv2"  => "video/mpeg",
  181.                                 "ms"    => "application/x-troff-ms",
  182.                                 "mvb"   => "application/x-msmediaview",
  183.                                 "nws"   => "message/rfc822",
  184.                                 "oda"   => "application/oda",
  185.                                 "p10"   => "application/pkcs10",
  186.                                 "p12"   => "application/x-pkcs12",
  187.                                 "p7b"   => "application/x-pkcs7-certificates",
  188.                                 "p7c"   => "application/x-pkcs7-mime",
  189.                                 "p7m"   => "application/x-pkcs7-mime",
  190.                                 "p7r"   => "application/x-pkcs7-certreqresp",
  191.                                 "p7s"   => "application/x-pkcs7-signature",
  192.                                 "pbm"   => "image/x-portable-bitmap",
  193.                                 "pdf"   => "application/pdf",
  194.                                 "pfx"   => "application/x-pkcs12",
  195.                                 "pgm"   => "image/x-portable-graymap",
  196.                                 'php'   => 1, // parse as PHP
  197.                                 'phps'  => 2, // pass to highlight_file()
  198.                                 "pko"   => "application/ynd.ms-pkipko",
  199.                                 "pma"   => "application/x-perfmon",
  200.                                 "pmc"   => "application/x-perfmon",
  201.                                 "pml"   => "application/x-perfmon",
  202.                                 "pmr"   => "application/x-perfmon",
  203.                                 "pmw"   => "application/x-perfmon",
  204.                                 'png'   => 'image/png',
  205.                                 "pnm"   => "image/x-portable-anymap",
  206.                                 "pot"   => "application/vnd.ms-powerpoint",
  207.                                 "ppm"   => "image/x-portable-pixmap",
  208.                                 "pps"   => "application/vnd.ms-powerpoint",
  209.                                 "ppt"   => "application/vnd.ms-powerpoint",
  210.                                 "prf"   => "application/pics-rules",
  211.                                 "ps"    => "application/postscript",
  212.                                 "pub"   => "application/x-mspublisher",
  213.                                 "qt"    => "video/quicktime",
  214.                                 "ra"    => "audio/x-pn-realaudio",
  215.                                 "ram"   => "audio/x-pn-realaudio",
  216.                                 "ras"   => "image/x-cmu-raster",
  217.                                 "rgb"   => "image/x-rgb",
  218.                                 "rmi"   => "audio/mid",
  219.                                 'rng'   => 'text/plain',
  220.                                 "roff"  => "application/x-troff",
  221.                                 "rtf"   => "application/rtf",
  222.                                 "rtx"   => "text/richtext",
  223.                                 "scd"   => "application/x-msschedule",
  224.                                 "sct"   => "text/scriptlet",
  225.                                 "setpay" => "application/set-payment-initiation",
  226.                                 "setreg" => "application/set-registration-initiation",
  227.                                 "sh"    => "application/x-sh",
  228.                                 "shar"  => "application/x-shar",
  229.                                 "sit"   => "application/x-stuffit",
  230.                                 "snd"   => "audio/basic",
  231.                                 "spc"   => "application/x-pkcs7-certificates",
  232.                                 "spl"   => "application/futuresplash",
  233.                                 "src"   => "application/x-wais-source",
  234.                                 "sst"   => "application/vnd.ms-pkicertstore",
  235.                                 "stl"   => "application/vnd.ms-pkistl",
  236.                                 "stm"   => "text/html",
  237.                                 "svg"   => "image/svg+xml",
  238.                                 "sv4cpio" => "application/x-sv4cpio",
  239.                                 "sv4crc" => "application/x-sv4crc",
  240.                                 "swf"   => "application/x-shockwave-flash",
  241.                                 "t"     => "application/x-troff",
  242.                                 "tar"   => "application/x-tar",
  243.                                 "tcl"   => "application/x-tcl",
  244.                                 "tex"   => "application/x-tex",
  245.                                 "texi"  => "application/x-texinfo",
  246.                                 "texinfo" => "application/x-texinfo",
  247.                                 'text'  => 'text/plain',
  248.                                 "tgz"   => "application/x-compressed",
  249.                                 "tif"   => "image/tiff",
  250.                                 "tiff"  => "image/tiff",
  251.                                 "tr"    => "application/x-troff",
  252.                                 "trm"   => "application/x-msterminal",
  253.                                 "tsv"   => "text/tab-separated-values",
  254.                                 "txt"   => "text/plain",
  255.                                 "uls"   => "text/iuls",
  256.                                 "ustar" => "application/x-ustar",
  257.                                 "vcf"   => "text/x-vcard",
  258.                                 "vrml"  => "x-world/x-vrml",
  259.                                 "wav"   => "audio/x-wav",
  260.                                 "wcm"   => "application/vnd.ms-works",
  261.                                 "wdb"   => "application/vnd.ms-works",
  262.                                 "wks"   => "application/vnd.ms-works",
  263.                                 "wmf"   => "application/x-msmetafile",
  264.                                 "wps"   => "application/vnd.ms-works",
  265.                                 "wri"   => "application/x-mswrite",
  266.                                 "wrl"   => "x-world/x-vrml",
  267.                                 "wrz"   => "x-world/x-vrml",
  268.                                 "xaf"   => "x-world/x-vrml",
  269.                                 "xbm"   => "image/x-xbitmap",
  270.                                 "xhtml" => "text/html",
  271.                                 "xla"   => "application/vnd.ms-excel",
  272.                                 "xlc"   => "application/vnd.ms-excel",
  273.                                 "xlm"   => "application/vnd.ms-excel",
  274.                                 "xls"   => "application/vnd.ms-excel",
  275.                                 "xlt"   => "application/vnd.ms-excel",
  276.                                 "xlw"   => "application/vnd.ms-excel",
  277.                                 'xml'   => 'text/xml',
  278.                                 "xof"   => "x-world/x-vrml",
  279.                                 "xpm"   => "image/x-xpixmap",
  280.                                 'xsd'   => 'text/plain',
  281.                                 'xsl'   => 'text/xml',
  282.                                 "xwd"   => "image/x-xwindowdump",
  283.                                 "z"     => "application/x-compress",
  284.                                 "zip"   => "application/zip"
  285.                                
  286.                         );
  287.                
  288.                         if(array_key_exists($type, $mime))
  289.                         {
  290.                                 if(preg_match('#text/#i', $mime[$type]))
  291.                                         return $mime[$type].'; charset='.$this->_root->Boot->System->Registry->get()->SETTINGS->ENCODING;
  292.                                        
  293.                                 return $mime[$type];
  294.                         }
  295.                        
  296.                         return 'application/octet-stream';
  297.                 }
  298.                
  299.                 public function headContentType($type = '')
  300.                 {
  301.                         if(!empty($type))
  302.                         {              
  303.                                 $this->headContentType = $this->mime($type);
  304.                                 if(!preg_match('#text/html#i', $this->headContentType))
  305.                                         $this->headDisableLayout();
  306.                                
  307.                                        
  308.                                 $this->_root->Boot->System->Registry->add('HEADER', 'content-type', $this->headContentType);
  309.                         }
  310.                        
  311.                         return $this->headContentType;
  312.                 }
  313.                
  314.                 public function header($name, $value)
  315.                 {
  316.                         if(!empty($name))
  317.                                 $this->_root->Boot->System->Registry->add('HEADER', $name, $value);
  318.                 }
  319.                
  320.                 public function prependStyle($src = '', $id = '')
  321.                 {
  322.                         if(!empty($src))
  323.                         {
  324.                                 $this->headStyle->prepend(array('src' => $src, 'id' => $id));
  325.                                 return $this;
  326.                         }
  327.                         return $this->headStyle;
  328.                 }
  329.                
  330.                 public function appendStyle($src = '', $id = '')
  331.                 {
  332.                         if(!empty($src))
  333.                         {
  334.                                 $this->headStyle->append(array('src' => $src, 'id' => $id));
  335.                                 return $this;
  336.                         }
  337.                         return $this->headStyle;
  338.                 }
  339.                
  340.                 public function headInlineStyle($script = '')
  341.                 {
  342.                         if(!empty($script))
  343.                         {
  344.                                 $headStyle['script']  = $script;
  345.                                 $this->headStyle[] = $headStyle;
  346.                         }
  347.                         return $this->headStyle;
  348.                 }
  349.                
  350.                 public function headScript($src = '', $id = '')
  351.                 {
  352.                         if(!empty($src))
  353.                         {
  354.                                 $headScript['src'] = $src;
  355.                                 $headScript['id']  = $id;
  356.                                
  357.                                 $this->headScript[] = $headScript;
  358.                         }
  359.                         return $this->headScript;
  360.                 }
  361.                
  362.                 public function headInlineScript($script = '')
  363.                 {
  364.                         if(!empty($script))
  365.                         {
  366.                                 $headScript['script']  = $script;
  367.                                 $this->headScript[] = $headScript;
  368.                         }
  369.                         return $this->headScript;
  370.                 }
  371.                
  372.                 public function headLayout($layout = '')
  373.                 {
  374.                         if(!empty($layout))
  375.                                 $this->layout = $layout;
  376.                         return $this->layout;
  377.                 }
  378.                
  379.                 public function headIncludeLayout()
  380.                 {
  381.                         return $this->layoutEnabled;
  382.                 }
  383.                
  384.                 public function headDisableLayout()
  385.                 {
  386.                         $this->layoutEnabled = FALSE;
  387.                         return $this->layoutEnabled;
  388.                 }
  389.                
  390.                 public function headEnableLayout()
  391.                 {
  392.                         $this->layoutEnabled = TRUE;
  393.                         return $this->layoutEnabled;
  394.                 }
  395.                
  396.                 public function headIncludeView()
  397.                 {
  398.                         return $this->viewEnabled;
  399.                 }
  400.                
  401.                 public function headDisableView()
  402.                 {
  403.                         $this->viewEnabled = FALSE;
  404.                         return $this->viewEnabled;
  405.                 }
  406.                
  407.                 public function headEnableView()
  408.                 {
  409.                         $this->viewEnabled = TRUE;
  410.                         return $this->viewEnabled;
  411.                 }
  412.                
  413.                
  414.                
  415.                
  416.                
  417.                 public function renderStyleInline()
  418.                 {
  419.                         $render  = '<style type="text/css">'."n";
  420.                         $render .= '<!--/*--><![CDATA[/*><!--*/'."n";
  421.  
  422.                        
  423.                         foreach($this->headStyle as $style)
  424.                         {
  425.                                 if(isset($style['src']))
  426.                                 {
  427.                                         $render .= '@import url(''.$REGISTRY->get()->URI->BASE.'/'.'media/styles/'.$style['src'].'');'."n";
  428.                                 }
  429.                                 if(isset($style['script']))
  430.                                 {
  431.                                         $render .= $style['script']."n";
  432.                                 }
  433.                         }
  434.                        
  435.                        
  436.                         $render .= '/*]]>*/-->'."n";
  437.                         $render .= '</style>'."n";
  438.                        
  439.                         return $render;
  440.                 }
  441.                
  442.                 public function renderStyleTags()
  443.                 {
  444.  
  445.                         $REGISTRY = $this->_root->Boot->System->Registry;
  446.                         $render  = '';
  447.                         foreach($this->headStyle as $style)
  448.                         {
  449.                                 if(isset($style['src']))
  450.                                 {
  451.                                         $render .= '<link ';
  452.                                         $render .= 'type="text/css" ';
  453.                                         $render .= 'rel="stylesheet" ';
  454.                                         $render .= 'href="'.$REGISTRY->get()->URI->BASE.'/'.'media/styles/'.$style['src'].'" />'."n";
  455.                                        
  456.                                 }
  457.                                 if(isset($style['script']))
  458.                                 {
  459.                                         $render  = '<style type="text/css">'."n";
  460.                                         $render .= '<!--/*--><![CDATA[/*><!--*/'."n";
  461.                                         $render .= $style['script']."n";
  462.                                         $render .= '/*]]>*/-->'."n";
  463.                                         $render .= '</style>'."n";
  464.                                 }
  465.                         }
  466.                        
  467.                        
  468.                        
  469.                         return $render;
  470.                 }
  471.                
  472.                 public function renderMeta()
  473.                 {
  474.  
  475.                         $render  = '';
  476.                         foreach($this->headMeta as $name => $content)
  477.                         {
  478.                                 $render .= '<meta ';
  479.                                 $render .= 'name="'.$name.'" ';
  480.                                 $render .= 'content="'.$content.'" />'."n";
  481.                         }
  482.                        
  483.                         return $render;
  484.                 }
  485.                
  486.                 public function renderTitle()
  487.                 {
  488.  
  489.                         if(!empty($this->headTitlePrefix))
  490.                                 $prefix = $this->headTitlePrefix;
  491.                                
  492.                         if(!empty($this->headTitle))
  493.                                 $prefix = $this->headTitlePrefix.' : ';
  494.                                
  495.                         $render = '<title>'.$prefix.$this->headTitle.'</title>'."n";                   
  496.                         return $render;
  497.                 }
  498.                
  499.                 public function assign($name = '', $value = '')
  500.                 {
  501.                         if(!is_scalar($name))
  502.                                 return false;
  503.                                
  504.                         if(!empty($name))
  505.                                 $this->ASSIGN->$name = $value;
  506.                                
  507.                         return $this->ASSIGN;
  508.                 }
  509.                
  510.                 protected function partial($path, array $config = array())
  511.                 {
  512.                         return FRUFFL_Partial::init(str_replace('/', DIRECTORY_SEPARATOR,$this->_root->Boot->System->Registry->get()->CORE_DIR->PARTIALS.$path), $config)->_include();
  513.                 }
  514.                
  515.                 public function bufferContent()
  516.                 {      
  517.                                
  518.                         $this->_viewFile = $this->_root->Boot->System->Registry->get()->DISPATCH->INVOKE->viewFile;
  519.                        
  520.                         try
  521.                         {
  522.                                 if(!is_file($this->_viewFile))
  523.                                         throw new FRUFFL_SequenceFrontend_LinkView_Exception
  524.                                                 ('File '.$this->_viewFile.' not found.');
  525.                         }
  526.                         catch(FRUFFL_SequenceFrontend_LinkView_Exception $e){$e->w();}
  527.                        
  528.                        
  529.                         ob_start();
  530.                         require_once $this->_viewFile;
  531.                         $this->_bufferContent = ob_get_clean();
  532.                 }
  533.                
  534.                 public function renderContent()
  535.                 {
  536.                         return $this->_bufferContent;
  537.                 }
  538.                
  539.         }