Ejemplo n.º 1
0
 public function Page($Reference)
 {
     $PageModel = new PageModel();
     $Page = $PageModel->GetFullID($Reference);
     if (!$Page) {
         throw NotFoundException();
     }
     $this->Page = $Page;
     if ($this->Head) {
         SetMetaTags($Page, $this);
         if ($Page->CustomCss) {
             $CustomCss = "\n" . $Page->CustomCss;
             if (!StringBeginsWith(trim($CustomCss), '<style', True)) {
                 $CustomCss = Wrap($CustomCss, 'style', array('type' => 'text/css'));
             }
             $this->Head->AddString($CustomCss);
         }
         if ($Page->CustomJs) {
             $CustomJs = $Page->CustomJs;
             if (!StringBeginsWith(trim($CustomJs), '<script', True)) {
                 $CustomJs = Wrap($CustomJs, 'script', array('type' => 'text/javascript'));
             }
             $this->Head->AddString($CustomJs);
         }
     }
     if ($Page->SectionID) {
         $this->Section = BuildNode($Page, 'Section');
         $this->SectionID = $Page->SectionID;
         CandyHooks::AddModules($this, $this->Section);
     }
     $this->FireEvent('ContentPage');
     if ($Page->View) {
         $this->View = $this->FetchViewLocation($this->View, False, False, False);
     }
     if (!$this->View) {
         $this->View = $this->FetchViewLocation('view', 'page', '', False);
         if (!$this->View) {
             $this->View = 'default';
         }
     }
     $this->Title($Page->Title);
     $this->SetData('Content', $Page, True);
     $this->EventArguments['Format'] =& $Page->Format;
     $this->EventArguments['Body'] =& $Page->Body;
     $this->FireEvent('BeforeBodyFormat');
     $this->ContentBodyHtml = Gdn_Format::To($Page->Body, $Page->Format);
     $Doc = PqDocument($this->ContentBodyHtml);
     $Header = $Doc->Find('h1');
     $CountH1 = count($Header);
     if ($CountH1 == 0) {
         $this->SetData('Headline', Gdn_Format::Text($Page->Title));
     } elseif ($CountH1 == 1) {
         $this->SetData('Headline', $Header->Text());
         $Header->Remove();
         $this->ContentBodyHtml = $Doc->Html();
     }
     //
     $this->AddModule('PageInfoModule');
     $this->Render();
 }
Ejemplo n.º 2
0
 /**
  * Converts HTML to Markdown
  */
 function Markdownify($Html)
 {
     $Html = Gdn_Format::To($Html, 'xHtml');
     $Snoopy = Gdn::Factory('Snoopy');
     $Vars = array('input' => $Html, 'keepHTML' => 1);
     $Snoopy->Submit('http://milianw.de/projects/markdownify/demo.php', $Vars);
     $Doc = PqDocument($Snoopy->results);
     $Code = Pq('pre > code:eq(0)')->Text();
     $Result = $Code;
     return $Result;
 }
 /**
  * Converts HTML to Markdown
  */
 function Markdownify($Html)
 {
     if (function_exists('Debug') && Debug()) {
         trigger_error(sprintf('%s is deprecated, use HtmlToMarkdown() instead.', __FUNCTION__), E_USER_DEPRECATED);
     }
     $Html = Gdn_Format::To($Html, 'xHtml');
     $Snoopy = Gdn::Factory('Snoopy');
     $Vars = array('input' => $Html, 'keepHTML' => 1);
     $Snoopy->Submit('http://milianw.de/projects/markdownify/demo.php', $Vars);
     $Doc = PqDocument($Snoopy->results);
     $Code = Pq('pre > code:eq(0)')->Text();
     $Result = $Code;
     return $Result;
 }
Ejemplo n.º 4
0
 function RemoteHtmlToMarkdown($Html, $FormatHtml = False)
 {
     $Snoopy = Gdn::Factory('Snoopy');
     $Vars = array('html' => $Html, 'submit' => 1);
     $Snoopy->Submit('http://modnerd.com/html2markdown/', $Vars);
     $Doc = PqDocument($Snoopy->results, array('FixHtml' => False));
     $Result = Pq('#markdown')->Val();
     $Result = htmlspecialchars_decode($Result, ENT_QUOTES);
     // I don't have a clue why need do htmlspecialchars_decode second time
     $Result = htmlspecialchars_decode($Result, ENT_QUOTES);
     $Result = str_replace('&#xD;', "\r", $Result);
     $Result = trim($Result);
     return $Result;
 }
Ejemplo n.º 5
0
 protected static function StaticPhpQueryReplace(&$String)
 {
     $ImageDimensions = self::ImageDimensions();
     $Domain = Gdn::Request()->Domain();
     $Doc = PqDocument($String, array('FixHtml' => False));
     foreach (Pq('img[src]') as $ImgNode) {
         $PqImg = Pq($ImgNode);
         if (!$PqImg->Attr('width') && !$PqImg->Attr('height')) {
             // TODO: DONT USE AbsoluteSource() for relative paths
             $Src = AbsoluteSource(trim($PqImg->Attr('src'), '/'), $Domain);
             $CrcKey = crc32($Src);
             if (!array_key_exists($CrcKey, $ImageDimensions)) {
                 $ImageSize = getimagesize($Src);
                 $ImageDimensions[$CrcKey] = array($ImageSize[0], $ImageSize[1], '_src' => $Src);
             } else {
                 $ImageSize = $ImageDimensions[$CrcKey];
             }
             $PqImg->Attr('width', $ImageSize[0]);
             $PqImg->Attr('height', $ImageSize[1]);
         }
     }
     // Save cache.
     self::ImageDimensions($ImageDimensions);
     $String = $Doc->document->saveXML();
 }