canonical = $canonical; $this->base = $base; $this->sidebarColor = $sidebarColor; $this->themecolor = $themecolor; $this->classSidebar = $classSidebar; } /** * Fix an url and convert a relative url into an absolute url * * @param $url * * @return string * @test equals 'http://amp.canon.dom/some/url/image.jpg',this('some/url/image.jpg') */ public function fixRelativeUrl($url) { if (strlen($url) < 4) { return $url; } if (substr($url, 0, 4) == 'http') { return $url; } if (substr($url, 0, 1) == '/') { return $this->base . $url; } if (substr($url, 0, 1) != '/') { return $this->base . '/' . $url; } return ""; } /** * It generates the social and seo structure (Twitter card, Facebook OG and Google Schema) * * @param StructureModel $structured * * @return string * @test greaterThan 100, this(new StructuredModel()) */ private function genStructured($structured) { $mark = " "; return $mark; } /** * Start to generate an Amp site. * * @param HeaderModel $param * @param StructureModel $structured * @param string $lang language */ public function startAmp($param, $structured = null, $lang = 'en') { $param->icon = $this->fixRelativeUrl($param->icon); /** @noinspection HtmlRequiredTitleElement */ $template = " "; if ($structured != null) { $template .= $this->genStructured($structured); } $template .= "{$param->title} "; $this->header = $param; $this->result = $template; $this->resetDefault(); } /** * Generates a sidebar. * * @param LinkModel[] $urls * * @test void this([]) */ public function sidebar($urls) { $template = "
"; $this->result .= $template; $this->styleStack[] = ".ampsidebar amp-sidebar{min-width: 260px;z-index: 1050;background-color: {$this->sidebarColor};} .ampsidebar amp-sidebar.open:after{content: '';position: absolute;top: 0;left: 0;bottom: 0;right: 0;background-color: red;} .ampsidebar .open{transform: translateX(0%);display: block;} .ampsidebar .builder-sidebar{background-color: {$this->sidebarColor};position: relative;height: 100vh;z-index: 1030;padding: 1rem 2rem;max-width: 20rem;} .ampsidebar button.sticky-but{position: fixed;} .ampsidebar .brand{display: flex;align-items: center;align-self: flex-start;padding-right: 30px;} .ampsidebar .brand p{margin: 0;padding: 0;} .ampsidebar .brand-name{color: {$this->themecolor};}"; $this->resetDefault(); } /** * Generates the header navigation * * @param HeadModel $param * @param int|string $width the width of the image. * @param int|string $height the height of the image. * * @test void this(new HeadModel(),0,0) */ public function head($param, $width = 55, $height = 55) { $param->logo = $this->fixRelativeUrl($param->logo); $template = ""; $this->result .= $template; $this->styleStack[] = ".ampsidebar .headerbar{display: flex;flex-direction: column;justify-content: center;padding: .5rem 1rem;min-height: 70px;align-items: center;background: {$this->backgroundColor};} .ampsidebar .headerbar.sticky-nav{position: fixed;z-index: 1000;width: 100%;}"; $this->resetDefault(); } /** * It generates a footer of the amp site. * * @param FooterModel $param * * @test void this(new FooterModel('copyright')) */ public function sectionFooter($param) { if ($this->paddingTop === null) { $paddingTop = 30; $paddingBottom = 30; } else { $paddingTop = $this->paddingTop; $paddingBottom = $this->paddingBottom; } $this->backgroundColor = '#232323'; if ($param->viewDesktop) { $goDestkop = "{$param->viewDesktop}"; } else { $goDestkop = ''; } $template = "

{$param->copyright}  {$goDestkop}

"; $this->result .= $template; $this->styleStack[] = ".ampfooter{" . $this->genModifyStyle($paddingTop, $paddingBottom) . "} .ampfooter p{margin: 0;color: #ffffff;}"; $this->resetDefault(); } /** * Generates a Google Analytics section * * @param string $account UA-XXXXX-Y * @pretest $this->ampGeneratorOne->startAmp(new HeaderModel()); * * @test void this('UA-XXXXX-Y') */ public function sectionAnalytics($account) { $template = ' '; $this->result .= $template; $this->resetDefault(); } /** * It draw a first section (hero style) * * @param SectionModel $content * @param bool $isH1 if true then it uses h1, otherwise it uses h2 * * @test void this(new SectionModel()) */ public function sectionFirst($content, $isH1 = false) { if ($this->paddingTop === null) { $paddingTop = 120; $paddingBottom = 60; } else { $paddingTop = $this->paddingTop; $paddingBottom = $this->paddingBottom; } $content->bgImage = $this->fixRelativeUrl($content->bgImage); $this->secId++; $htag = ($isH1) ? 'h1' : 'h2'; $template = "
<$htag class='ampg-title align-center ampg-fonts-style ampg-bold {$this->classTextColor} text-1'>{$content->title}
"; $this->result .= $template; $this->styleStack[] = ".ampg-section{$this->secId}{" . $this->genModifyStyle($paddingTop, $paddingBottom) . "} .ampg-section{$this->secId} .ampg-title{padding-bottom: 1rem;}"; $this->resetDefault(); } /** * It generates a section with a single button. * * @param SectionModel $content * @param bool $fullscreen * * @test void this(new SectionModel(),false) */ public function sectionImageButton($content, $fullscreen = true) { if (count($content->buttons) == 0) { return; } // no buttons $content->bgImage = $this->fixRelativeUrl($content->bgImage); if ($content->buttons < 1) { die("Error:sectionImageButton must have at least a button"); } $htmlFull = ($fullscreen) ? "ampg-fullscreen" : ""; $this->secId++; $template = "

{$content->title}

{$content->description}

"; $this->result .= $template; $this->styleStack[] = ".ampg-section{$this->secId}{background-image: url('{$content->bgImage}');}"; $this->resetDefault(); } /** * It generates a section with a text. * * @param SectionModel $content * * @test void this(new SectionModel()) */ public function sectionText($content) { if ($this->paddingTop === null) { $paddingTop = 60; $paddingBottom = 60; } else { $paddingTop = $this->paddingTop; $paddingBottom = $this->paddingBottom; } $this->secId++; $template = "

{$content->title}

{$content->description}

"; $this->result .= $template; $this->styleStack[] = ".ampg-section{$this->secId}{" . $this->genModifyStyle($paddingTop, $paddingBottom) . "} .ampg-section{$this->secId} .ampg-text{margin-bottom: 0;} .ampg-section{$this->secId} .ampg-section-title{margin: 0;}"; $this->resetDefault(); } /** * It generates a quote text * * @param SectionModel $content * * @test void this(new SectionModel()) */ public function sectionTextQuote($content) { if ($this->paddingTop === null) { $paddingTop = 60; $paddingBottom = 60; } else { $paddingTop = $this->paddingTop; $paddingBottom = $this->paddingBottom; } $this->secId++; $htmlLink = $this->genLink($content->url); $template = "
{$content->description} {$htmlLink}
"; $this->result .= $template; $this->styleStack[] = ".ampg-section{$this->secId}{" . $this->genModifyStyle($paddingTop, $paddingBottom) . "} .ampg-section{$this->secId} blockquote{border-color: #ffc107;}"; $this->resetDefault(); } /** * It generates an unsorted list section * * @param LinkModel[] $links * * @test void this([]) */ public function sectionUL($links) { if ($this->paddingTop === null) { $paddingTop = 60; $paddingBottom = 60; } else { $paddingTop = $this->paddingTop; $paddingBottom = $this->paddingBottom; } $this->secId++; $template = "
    "; foreach ($links as $link) { $template .= "
  • {$link->description}- {$link->description} " . $link->url . "
  • \n"; } $template .= "
"; $this->result .= $template; $this->styleStack[] = ".ampg-section{$this->secId}{" . $this->genModifyStyle($paddingTop, $paddingBottom) . "} .ampg-section{$this->secId} .counter-container ul{margin-bottom: 0;} .ampg-section{$this->secId} .counter-container ul li{color: inherit;margin-bottom: 1rem;list-style: none;} .ampg-section{$this->secId} .counter-container ul li:before{position: absolute;left: 0px;padding-top: 3px;content: '';display: inline-block;text-align: center;margin: 10px 15px;line-height: 20px;transition: all .2s;color: #ffffff;background: #007bff;width: 10px;height: 10px;border-radius: 50%;border-radius: 0;transform: rotate(45deg);}"; $this->resetDefault(); } /** * It generates a sorted list section * * @param LinkModel[] $links * * @test void this([]) */ public function sectionOL($links) { if ($this->paddingTop === null) { $paddingTop = 60; $paddingBottom = 60; } else { $paddingTop = $this->paddingTop; $paddingBottom = $this->paddingBottom; } $this->secId++; $template = "
    "; foreach ($links as $link) { $template .= "
  1. {$link->description}- {$link->description} " . $link->url . "
  2. \n"; } $template .= "
"; $this->result .= $template; $this->styleStack[] = ".ampg-section{$this->secId}{" . $this->genModifyStyle($paddingTop, $paddingBottom) . "} .ampg-section{$this->secId} .counter-container ol{margin-bottom: 0;counter-reset: myCounter;} .ampg-section{$this->secId} .counter-container ol li{margin-bottom: 2rem;} .ampg-section{$this->secId} .counter-container ol li{z-index: 3;list-style: none;padding-left: .5rem;} .ampg-section{$this->secId} .counter-container ol li:before{z-index: 2;position: absolute;left: 0px;counter-increment: myCounter;content: counter(myCounter);text-align: center;margin: 0 10px;line-height: 30px;transition: all .2s;width: 35px;height: 35px;color: #007bff;font-size: 20px;font-weight: bold;border-radius: 50%;border: 2px solid #007bff;opacity: 0.5;}"; $this->resetDefault(); } /** * It generates a section with one (or more than one) buttons. * * @param SectionModel $content * * @test void this(new SectionModel()) */ public function sectionButtons($content) { if ($this->paddingTop === null) { $paddingTop = 60; $paddingBottom = 60; } else { $paddingTop = $this->paddingTop; $paddingBottom = $this->paddingBottom; } $this->secId++; $template = "
"; foreach ($content->buttons as $button) { $template .= $this->genButton($button) . "\n"; } $template .= "
"; $this->result .= $template; $this->styleStack[] = ".ampg-section{$this->secId}{" . $this->genModifyStyle($paddingTop, $paddingBottom) . "}"; $this->resetDefault(); } /** * It generates a section with columns * * @param SectionModel[] $contents * * @test void this([]) */ public function sectionCols($contents) { if ($this->paddingTop === null) { $paddingTop = 75; $paddingBottom = 75; } else { $paddingTop = $this->paddingTop; $paddingBottom = $this->paddingBottom; } $this->secId++; $num = count($contents); if ($num == 0) { return; } $colmd = 6; $collg = floor(12 / $num); $template = "
"; foreach ($contents as $content) { $template .= "

" . (($content->fontIcon != "") ? "
" : "") . " {$content->title}

{$content->description}

"; } $template .= "
"; $this->result .= $template; $this->styleStack[] = ".ampg-section{$this->secId}{" . $this->genModifyStyle($paddingTop, $paddingBottom) . "} .ampg-section{$this->secId}{" . $this->genModifyStyle($paddingTop, $paddingBottom) . "} .ampg-section{$this->secId} .ampg-row{margin: 0 15px;} @media (max-width: 991px){.ampg-section{$this->secId} .card{margin-bottom: 20px;} } .ampg-section{$this->secId} .ampg-section-title{margin: 0;padding-bottom: 1rem;} .ampg-section{$this->secId} .ampg-text{margin: 0;}"; $this->resetDefault(); } /** * It generates a header central section. It could includes buttons. * * @param SectionModel $content * * @test void this(new SectionModel()) */ public function sectionHeaderCentral($content) { $content->bgImage = $this->fixRelativeUrl($content->bgImage); if ($this->paddingTop === null) { $paddingTop = 90; $paddingBottom = 90; } else { $paddingTop = $this->paddingTop; $paddingBottom = $this->paddingBottom; } $this->secId++; $template = "

{$content->title}

{$content->subtitle}

{$content->description}

"; foreach ($content->buttons as $button) { $template .= $this->genButton($button) . '\n'; } $template .= <<
cin2; $this->result .= $template; $style = ".ampg-section{$this->secId}{" . $this->genModifyStyle($paddingTop, $paddingBottom) . "}"; $style .= ".ampg-section{$this->secId} .ampg-section-subtitle{text-align: center;} .ampg-section{$this->secId} .ampg-text,.ampg-section{$this->secId} .ampg-section-btn{text-align: center;} .ampg-section{$this->secId} .ampg-section-title{text-align: center;}"; $this->styleStack[] = $style; $this->resetDefault(); } public function sectionRaw($txt) { $this->result .= $txt; } /** * It generates a section with an image content. * * @param SectionModel $content * @param int|string $width the width of the image. * @param int|string $height the height of the image. * * @test void this(new SectionModel(),0,0) */ public function sectionImageContent($content, $width, $height) { if ($this->paddingTop === null) { $paddingTop = 30; $paddingBottom = 30; } else { $paddingTop = $this->paddingTop; $paddingBottom = $this->paddingBottom; } $content->bgImage = $this->fixRelativeUrl($content->bgImage); $this->secId++; $template = "

{$content->title}

{$content->description}

"; if (count($content->buttons)) { $template .= "
" . $this->genButton($content->buttons) . "
"; } $template .= "
"; $this->result .= $template; $this->styleStack[] = ".ampg-section{$this->secId}{" . $this->genModifyStyle($paddingTop, $paddingBottom) . "} .ampg-section{$this->secId} .text-block{margin: auto;} .ampg-section{$this->secId} amp-img{text-align: center;}"; $this->resetDefault(); } /** * It generates a section with a image content at the left. * * @param SectionModel $content * @param int|string $width the width of the image. * @param int|string $height the height of the image. * * @test void this(new SectionModel(),0,0) */ public function sectionImageContentLeft($content, $width, $height) { if ($this->paddingTop === null) { $paddingTop = 30; $paddingBottom = 30; } else { $paddingTop = $this->paddingTop; $paddingBottom = $this->paddingBottom; } $content->bgImage = $this->fixRelativeUrl($content->bgImage); $this->secId++; $template = "

{$content->title}

{$content->description}

"; if (count($content->buttons)) { $template .= "
" . $this->genButton($content->buttons) . "
"; } $template .= "
"; $this->result .= $template; $this->styleStack[] = ".ampg-section{$this->secId}{" . $this->genModifyStyle($paddingTop, $paddingBottom) . "} .ampg-section{$this->secId} .text-block{margin: auto;} .ampg-section{$this->secId} amp-img{text-align: center;}"; $this->resetDefault(); } /** * It generates a table * * @param array $cols * * @test void this([]) */ public function sectionTable($cols) { $this->secId++; if ($this->paddingTop === null) { $paddingTop = 75; $paddingBottom = 75; } else { $paddingTop = $this->paddingTop; $paddingBottom = $this->paddingBottom; } if (count($cols) <= 1) { return; } if (is_object($cols[0])) { $cols = json_decode(json_encode($cols), true); // convert objects into array } $headers = array_keys($cols[0]); $template = "
"; foreach ($headers as $h) { $template .= ""; } $template .= ""; foreach ($cols as $c) { $template .= ""; foreach ($headers as $h) { $template .= ""; } $template .= ""; } $template .= "

{$h}

{$c[$h]}

"; $this->result .= $template; $this->styleStack[] = " .ampg-section{$this->secId}{" . $this->genModifyStyle($paddingTop, $paddingBottom) . "} .ampg-section{$this->secId} table{width: 100%;border-collapse: collapse;} .ampg-section{$this->secId} table td{border-top: none;padding: .75rem;} .ampg-section{$this->secId} table th{border-top: none;padding: .75rem;border-bottom: 2px solid #cecece;} .ampg-section{$this->secId} p{padding: 5px;margin: 0px;} .ampg-section{$this->secId} .scroll{overflow-x: auto;} .ampg-section{$this->secId} .wrapscroll{width: 100%;} .ampg-section{$this->secId} .ampg-section-subtitle{color: #7f7e7e;margin-bottom: 2rem;} "; $this->resetDefault(); } /** * It generates an image. The size of the image is required to calculate the ratio * * @param SectionModel $content * @param int|string $width the width of the image. * @param int|string $height the height of the image. * * * * @test void this(new SectionModel(),0,0) */ public function sectionImage($content, $width, $height) { $content->bgImage = $this->fixRelativeUrl($content->bgImage); if ($this->paddingTop === null) { $paddingTop = 90; $paddingBottom = 90; } else { $paddingTop = $this->paddingTop; $paddingBottom = $this->paddingBottom; } $this->secId++; $urlStart = (count($content->url)) ? "" : ""; $urlEnd = (count($content->url)) ? "" : ""; $template = "
{$urlStart} {$urlEnd}

{$content->title}

"; foreach ($content->buttons as $button) { $template .= $this->genButton($button) . "\n"; } $template .= "
"; $this->result .= $template; $this->styleStack[] = ".ampg-section{$this->secId}{" . $this->genModifyStyle($paddingTop, $paddingBottom) . "} .ampg-section{$this->secId} .image-block{margin: auto;width: 66%;width: 100%;} .ampg-section{$this->secId} amp-img{text-align: center;} .ampg-section{$this->secId} .ampg-text{margin: 0;padding: .5rem 0;padding: .5rem 15px;} .ampg-section{$this->secId} .ampg-section-btn{margin: 0;padding: .5rem 0;padding: .5rem 15px;} @media (max-width: 767px){.ampg-section{$this->secId} .image-block{width: 100%;} } "; $this->resetDefault(); } /** * It generates a google map section. It can't be locate at the 30% top of the site (Amp restriction) * * @param SectionModel $content * @param string $googleMapUrl * @param string $placeholder * * @test void this(new SectionModel(),'mapurl','loading..') */ public function sectionGMapFull($content, $googleMapUrl = "", $placeholder = "Google Map Loading...") { if ($this->paddingTop === null) { $paddingTop = 60; $paddingBottom = 60; } else { $paddingTop = $this->paddingTop; $paddingBottom = $this->paddingBottom; } $googleMapUrl = ($googleMapUrl == "") ? "https://www.google.com/maps/embed?pb=!1m10!1m8!1m3!1d13320.170086624597!2d-70.60383335!3d-33.422135749999995!3m2!1i1024!2i768!4f13.1!5e0!3m2!1sen!2scl!4v1536022894740" // some default map : $googleMapUrl; $this->secId++; //$urlStart = (count($content->url)) ? "" : ""; //$urlEnd = (count($content->url)) ? "" : ""; $template = "

{$placeholder}

"; $this->result .= $template; $this->styleStack[] = ".ampg-section{$this->secId}{" . $this->genModifyStyle($paddingTop, $paddingBottom) . "} .ampg-section{$this->secId} .ampg-row{margin-left: 0;margin-right: 0;} .ampg-section{$this->secId} .ampg-section-title{padding-bottom: 3rem;} .ampg-section{$this->secId} .google-map{height: 25rem;position: relative;width: 100%;} .ampg-section{$this->secId} .google-map iframe{height: 100%;width: 100%;} .ampg-section{$this->secId} .google-map [data-state-details]{color: #6b6763;font-family: Montserrat;height: 1.5em;margin-top: -0.75em;padding-left: 1.25rem;padding-right: 1.25rem;position: absolute;text-align: center;top: 50%;width: 100%;} .ampg-section{$this->secId} .google-map[data-state]{background: #e9e5dc;} .ampg-section{$this->secId} .google-map[data-state=\"loading\"] [data-state-details]{display: none;} .ampg-section{$this->secId} .map-placeholder{display: none;} .ampg-section{$this->secId} h4{padding-top: 5rem;color: #767676;text-align: center;} "; $this->resetDefault(); } /** * It generates a google map (boxed) section. It can't be locate at the 30% top of the site (Amp restriction) * * @param SectionModel $content * @param string $googleMapUrl * * @test void this(new SectionModel(),'mapurl') */ public function sectionGMapBoxed($content, $googleMapUrl = "") { if ($this->paddingTop === null) { $paddingTop = 90; $paddingBottom = 90; } else { $paddingTop = $this->paddingTop; $paddingBottom = $this->paddingBottom; } $googleMapUrl = ($googleMapUrl == "") ? "https://www.google.com/maps/embed?pb=!1m10!1m8!1m3!1d13320.170086624597!2d-70.60383335!3d-33.422135749999995!3m2!1i1024!2i768!4f13.1!5e0!3m2!1sen!2scl!4v1536022894740" : $googleMapUrl; $this->secId++; //$urlStart = (count($content->url)) ? "" : ""; //$urlEnd = (count($content->url)) ? "" : ""; $template = "

Google Map Loading..

"; $this->result .= $template; $this->styleStack[] = " .ampg-section{$this->secId}{" . $this->genModifyStyle($paddingTop, $paddingBottom) . "} .ampg-section{$this->secId} .google-map{height: 25rem;position: relative;width: 100%;} .ampg-section{$this->secId} .google-map iframe{height: 100%;width: 100%;} .ampg-section{$this->secId} .google-map [data-state-details]{color: #6b6763;font-family: Montserrat;height: 1.5em;margin-top: -0.75em;padding-left: 1.25rem;padding-right: 1.25rem;position: absolute;text-align: center;top: 50%;width: 100%;} .ampg-section{$this->secId} .google-map[data-state]{background: #e9e5dc;} .ampg-section{$this->secId} .google-map[data-state=\"loading\"] [data-state-details]{display: none;} .ampg-section{$this->secId} .map-placeholder{display: none;} .ampg-section{$this->secId} h4{padding-top: 5rem;color: #767676;text-align: center;} .ampg-section{$this->secId} .ampg-section-title{padding-bottom: 3rem;} "; $this->resetDefault(); } /** * It generates a footer navigation * * @param SectionModel $content * @param string $image the source of the image * @param int|string $width the width of the image. * @param int|string $height the height of the image. * @param LinkModel[] $navCol1 The first column of the navigation * @param LinkModel[] $navCol2 The second column of the navigation * @param LinkModel[] $navCol3 The third column of the navigation * @param LinkModel[] $navCol4 The fourth column of the navigation * * @test void this(new SectionModel()) */ public function sectionNavigation( $content, $image = "", $width = 0, $height = 0, $navCol1 = null, $navCol2 = null, $navCol3 = null, $navCol4 = null ) { $image = $this->fixRelativeUrl($image); $this->secId++; if ($this->paddingTop === null) { $paddingTop = 45; $paddingBottom = 45; } else { $paddingTop = $this->paddingTop; $paddingBottom = $this->paddingBottom; } $num = 1; if ($image != "" || count($content->buttons) > 0) { $num++; } $all = array(); $all[] = $navCol1; if ($navCol1 === null) { return; } // nothing to show. if ($navCol2 !== null) { $num++; $all[] = $navCol2; } if ($navCol3 !== null) { $num++; $all[] = $navCol3; } if ($navCol4 !== null) { $num++; $all[] = $navCol4; } $collg = floor(12 / $num); $template = "
"; if ($image != "") { $template .= "
"; } if ($content->title != '') { if (count($content->buttons)) { $content->buttons[0]->url = $this->fixRelativeUrl($content->buttons[0]->url); } $template .= "

{$content->title}

{$content->description}

{$this->genButton($content->buttons)}
"; } foreach ($all as $col) { $template .= "
"; foreach ($col as $c) { if ($c->isHeader) { $template .= "

{$c->description}

"; } else { $template .= "

{$c->description}

"; } } $template .= "
"; } $template .= "
"; $template .= ""; $this->result .= $template; $this->styleStack[] = ".ampg-section{$this->secId}{" . $this->genModifyStyle($paddingTop, $paddingBottom) . "} .ampg-section{$this->secId} amp-img{text-align: center;} .ampg-section{$this->secId} .items-col .item{margin: 0;} .ampg-section{$this->secId} .item,.ampg-section{$this->secId} .group-title{color: #efefef;padding-top: 0;} @media (max-width: 767px){.ampg-section{$this->secId} .items-col{text-align: center;margin: 2rem 0;} } "; $this->resetDefault(); } /** * It generates a section with images and text. * * @param SectionModel[] $contents * @param int|string $width the width of the image. * @param int|string $height the height of the image. * @param int $maxCol * * @test void this([],0,0,0) */ public function sectionColImage($contents, $width, $height, $maxCol = 3) { $this->secId++; $num = count($contents); if ($num === 0) { return; } //nothing to show. if ($num > $maxCol) { $colmd = 6; $collg = floor(12 / $maxCol); } else { $colmd = 6; $collg = floor(12 / $num); } if ($this->paddingTop === null) { $paddingTop = 30; $paddingBottom = 30; } else { $paddingTop = $this->paddingTop; $paddingBottom = $this->paddingBottom; } $template = "
"; $col = 0; foreach ($contents as $content) { $content->bgImage = $this->fixRelativeUrl($content->bgImage); if ($col % $maxCol === 0 && $col != 0) { $template .= "
"; } $col++; $template .= "
" . (count($content->url) ? "" : "") . " " . (count($content->url) ? "" : "") . "

{$content->title}

{$content->description}

"; if (count($content->buttons)) { $template .= "
" . $this->genButton($content->buttons) . "
"; } $template .= "
"; } $template .= "
"; $this->result .= $template; $this->styleStack[] = ".ampg-section{$this->secId}{" . $this->genModifyStyle($paddingTop, $paddingBottom) . "} .ampg-section{$this->secId} .card{margin-bottom: 20px;position: relative;display: flex;-ms-flex-direction: column;flex-direction: column;min-width: 0;word-wrap: break-word;background-clip: border-box;border-radius: 0;width: 100%;min-height: 1px;} .ampg-section{$this->secId} .card .btn{margin: .4rem 4px;} .ampg-section{$this->secId} .card-title{margin: 0;} .ampg-section{$this->secId} .card-box{padding-top: 2rem;} .ampg-section{$this->secId} amp-img{width: 100%;}"; $this->resetDefault(); } private function genModifyStyle($paddingTop, $paddingBottom) { if ($this->bgImage) { return "padding-top: {$paddingTop}px;padding-bottom: {$paddingBottom}px;background-image: url('{$this->bgImage}');"; } else { return "padding-top: {$paddingTop}px;padding-bottom: {$paddingBottom}px;background-color: {$this->backgroundColor};"; } } /** * Fluent operation, it changes the background color of the next section * * @param string $color Example #ffffff,rgb(30,30,30),white * * @return $this * @test InstanceOf AmpGeneratorOne::class,this('#ffffff') */ public function setBackgroundColor($color) { $this->backgroundColor = $color; return $this; } /** * Fluent operation, it changes the background image of the next section * * @param string $bgImage * * @return $this * @test InstanceOf AmpGeneratorOne::class,this('img.jpg') */ public function setBgImage($bgImage) { $this->bgImage = $bgImage; $this->bgImage = $this->fixRelativeUrl($this->bgImage); return $this; } /** * Fluent operation, it sets the class of the text * * @param string $class text-primary,text-secondary,text-success,text-info,text-warning,text-danger,text-white,text-black * * @return $this * @test InstanceOf AmpGeneratorOne::class,this('text-primary') */ public function setClassTextColor($class) { $this->classTextColor = $class; return $this; } /** * Fluent operation, it changes the padding * * @param $top * @param $bottom * * @return $this * @test InstanceOf AmpGeneratorOne::class,this(0,0) */ public function setPadding($top, $bottom) { $this->paddingTop = $top; $this->paddingBottom = $bottom; return $this; } private function resetDefault() { $this->backgroundColor = $this->defaultBackGroundColor; $this->classTextColor = $this->defaultClassTextColor; $this->paddingTop = null; $this->paddingBottom = null; $this->bgImage = ""; } /** * It reset to the default background color and text class * * @param string $backGroundColor Example #ffffff,rgb(30,30,30),white * @param string $classTextColor text-primary,text-secondary,text-success,text-info,text-warning,text-danger,text-white,text-black */ public function setDefault($backGroundColor, $classTextColor) { $this->defaultBackGroundColor = $backGroundColor; $this->defaultClassTextColor = $classTextColor; } /** * It renders the result page. */ public function render() { $r = implode("\n", $this->styleStack); $this->result = str_replace("/*inserthere*/", $r, $this->result); echo $this->result; } /** * It renders the result to file * * @param string $filename * * @return bool|int */ public function renderToFile($filename) { $r = implode("\n", $this->styleStack); $this->result = str_replace("/*inserthere*/", $r, $this->result); return file_put_contents($filename, $this->result); } //region private functions /** * Generate the first link of an array only if array constains information or the link is not empty. * * @param LinkModel|LinkModel[] $url * * @return string * @test equals 'xxx',this('url/link') */ private function genLink($url) { if (is_array($url)) { if (count($url)) { $htmlLink = "url}/\">{$url[0]->description}"; } else { $htmlLink = ""; } } else { if ($url->description != "") { $htmlLink = "url}/\">{$url->description}"; } else { $htmlLink = ""; } } return $htmlLink; } /** * Generate the first link of an array only if array constains information or the link is not empty. * * @param ButtonModel|ButtonModel[] $url * * @return string */ private function genButton($url) { if (is_array($url)) { if (count($url)) { $htmlLink = "{$url[0]->title}"; } else { $htmlLink = ""; } } else { if ($url->title != "") { $htmlLink = "{$url->title}"; } else { $htmlLink = ""; } } return $htmlLink; } //endregion } // end class //region Models class HeaderModel { var $description; var $title; var $icon; /** * HeaderModel constructor. * * @param string $description * @param string $title * @param string $icon */ public function __construct($description = "", $title = "", $icon = "") { $this->description = $description; $this->title = $title; $this->icon = $icon; } } class HeadModel { var $title; var $logo; /** * HeadModel constructor. * * @param $title * @param $logo */ public function __construct($title = "", $logo = "") { $this->title = $title; $this->logo = $logo; } } class FooterModel { var $copyright; var $viewDesktop; /** * FooterModel constructor. * * @param string $copyright * @param string $viewDesktop Name of the Link."View as Desktop" */ public function __construct($copyright, $viewDesktop = "") { $this->copyright = $copyright; $this->viewDesktop = $viewDesktop; } } class LinkModel { var $url; var $description; var $icon; var $isHeader; /** * LinksModel constructor. * * @param string $description * @param string $url * @param string $icon * @param bool $isHeader */ public function __construct($description = "", $url = "#", $icon = "", $isHeader = false) { $this->url = $url; $this->description = $description; $this->icon = $icon; $this->isHeader = $isHeader; } } class SectionModel { var $title; var $description; var $subtitle; /** @var LinkModel[] */ var $url; var $bgImage; /** @var ButtonModel[] */ var $buttons; var $fontIcon; /** * SectionModel constructor. * * @param string $title * @param string $description * @param string $bgImage * @param string $subtitle * @param string $fontIcon */ public function __construct($title = "", $description = "", $bgImage = "", $subtitle = "", $fontIcon = "") { $this->title = $title; $this->subtitle = $subtitle; $this->description = $description; $this->url = array(); $this->bgImage = $bgImage; $this->buttons = []; $this->fontIcon = $fontIcon; } } class ButtonModel { /** @var string */ var $title; /** @var string */ var $url; /** @var string primary|success|warning|danger */ var $color; /** * ButtonModel constructor. * * @param string $title * @param string $url * @param string $color primary|success|warning|danger */ public function __construct($title = "", $url = "#", $color = "primary") { $this->title = $title; $this->url = $url; $this->color = $color; } } class StructureModel { var $name; var $description; var $url; var $image; var $imageWidth; var $imageHeight; /** @var string * @see http://ogp.me/#types */ var $ogtype = "website"; var $twittercreator; var $twittersite; } //endregion