Esempio n. 1
0
 public function buildDataFile($files)
 {
     foreach ($files as $file) {
         $fileData = file_get_contents('../' . $file, true);
         $html = str_get_html($fileData);
         foreach ($html->find('.auto-blog-next, .auto-blog-prev, .auto-blog-has-prev, .auto-blog-has-next') as $pagination) {
             if (strpos($pagination->class, 'auto-blog-next') !== false) {
                 $pagination->href = '<?=getBlogPage("next")?>';
                 $pagination->class = str_replace('auto-blog-next', '', $pagination->class);
                 $this->data['types']['link-next'] = true;
                 $this->data['list-pagination-pages'] = str_replace(array('.html', '.htm'), '', $file);
             } else {
                 if (strpos($pagination->class, 'auto-blog-prev') !== false) {
                     $pagination->href = '<?=getBlogPage("prev")?>';
                     $pagination->class = str_replace('auto-blog-prev', '', $pagination->class);
                     $this->data['types']['link-prev'] = true;
                     $this->data['list-pagination-pages'] = str_replace(array('.html', '.htm'), '', $file);
                 } else {
                     if (strpos($pagination->class, 'auto-blog-has-next') !== false) {
                         $this->data['pagination']['has-next'] = $pagination->style;
                         $pagination->style = '<?=getBlogPage("has-next")?>';
                         $pagination->class = str_replace('auto-blog-has-next', '', $pagination->class);
                     } else {
                         if (strpos($pagination->class, 'auto-blog-has-prev') !== false) {
                             $this->data['pagination']['has-prev'] = $pagination->style;
                             $pagination->style = '<?=getBlogPage("has-prev")?>';
                             $pagination->class = str_replace('auto-blog-has-prev', '', $pagination->class);
                         }
                     }
                 }
             }
         }
         foreach ($html->find('.auto-blog-head, .auto-blog-list, .auto-blog-post') as $blog) {
             if (strpos($blog->class, 'auto-blog-head') !== false) {
                 foreach ($html->find('.auto-blog-head title') as $pageTitle) {
                     $pageTitle->innertext = "<?=getBlog('title')?>";
                     $this->data['types']['title'] = true;
                 }
                 foreach ($html->find('.auto-blog-head meta') as $pageMeta) {
                     if ($pageMeta->name == 'keywords' || $pageMeta->name == 'description' || $pageMeta->name == 'author') {
                         $pageMeta->content = "<?=getBlog('{$pageMeta->name}')?>";
                         $this->data['types'][$pageMeta->name] = true;
                     }
                     if (isset($pageMeta->property) && isset($pageMeta->content)) {
                         $property = preg_replace("/[^a-z^A-Z^0-9_-]/", "", $pageMeta->property);
                         if ($pageMeta->property == "og:image") {
                             $pageMeta->content = "<?=get('autocms-settings.json', 'site-host')?><?=getBlog('image')?>";
                         } else {
                             if ($pageMeta->property == "og:title") {
                                 $pageMeta->content = "<?=getBlog('title')?>";
                             } else {
                                 if ($pageMeta->property == "og:description") {
                                     $pageMeta->content = "<?=getBlog('description')?>";
                                 } else {
                                     if ($pageMeta->property == "og:author" || $pageMeta->property == 'article:author') {
                                         $pageMeta->content = "<?=getBlog('author')?>";
                                     } else {
                                         if ($pageMeta->property == "og:url") {
                                             $pageMeta->content = "<?=getBlog('link-href')?>";
                                         } else {
                                             if ($pageMeta->property == "og:type") {
                                                 $pageMeta->content = "article";
                                             } else {
                                                 if ($pageMeta->property == "og:site_name") {
                                                     $pageMeta->content = "<?=get('autocms-settings.json', 'site-name')?>";
                                                 } else {
                                                     $pageMeta->content = "<?=getBlog('{$property}')?>";
                                                     $this->data['types']['open-graph'] = true;
                                                     $this->data['og-types'][$property] = $pageMeta->property;
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 $blog->innertext .= "<?=get('autocms-analytics.json', 'analytics')?>";
                 $blog->class = str_replace('auto-blog-head', '', $blog->class);
             } else {
                 if (strpos($blog->class, 'auto-blog-list') !== false) {
                     foreach ($html->find('.auto-blog-list .auto-blog-title, .auto-blog-list .auto-blog-date, .auto-blog-list .auto-blog-cats, .auto-blog-list .auto-blog-bg-img, .auto-blog-list .auto-blog-img, .auto-blog-list .auto-blog-short, .auto-blog-list .auto-blog-full, .auto-blog-list .auto-blog-link, .auto-blog-list .auto-blog-link-href') as $list) {
                         if (strpos($list->class, 'auto-blog-title') !== false) {
                             $list->innertext = '<?=getBlog("title", $x)?>';
                             $list->class = str_replace('auto-blog-title', '', $list->class);
                             $this->data['types']['title'] = true;
                         } else {
                             if (strpos($list->class, 'auto-blog-bg-img') !== false) {
                                 $list->style = "background-image: url('<?=getBlog(" . '"image", $x' . ")?>');";
                                 $list->class = str_replace('auto-blog-bg-img', '', $list->class);
                                 $this->data['types']['image'] = true;
                             } else {
                                 if (strpos($list->class, 'auto-blog-img') !== false) {
                                     $list->src = '<?=getBlog("image", $x)?>';
                                     $list->alt = '<?=getBlog("image-alt-text", $x)?>';
                                     $list->class = str_replace('auto-blog-img', '', $list->class);
                                     $this->data['types']['image'] = true;
                                     $this->data['types']['image-alt-text'] = true;
                                 } else {
                                     if (strpos($list->class, 'auto-blog-short') !== false) {
                                         $list->innertext = '<?=getBlog("short-blog", $x)?>';
                                         $list->class = str_replace('auto-blog-short', '', $list->class);
                                         $this->data['types']['short-blog'] = true;
                                     } else {
                                         if (strpos($list->class, 'auto-blog-full') !== false) {
                                             $list->innertext = '<?=getBlog("full-blog", $x)?>';
                                             $list->class = str_replace('auto-blog-full', '', $list->class);
                                             $this->data['types']['full'] = true;
                                         } else {
                                             if (strpos($list->class, 'auto-blog-date') !== false) {
                                                 $list->innertext = '<?=getBlog("date", $x)?>';
                                                 $list->class = str_replace('auto-blog-date', '', $list->class);
                                                 $this->data['types']['date'] = true;
                                             } else {
                                                 if (strpos($list->class, 'auto-blog-cats') !== false) {
                                                     $list->innertext = '<?=getBlog("cats", $x)?>';
                                                     $list->class = str_replace('auto-blog-cats', '', $list->class);
                                                     $this->data['types']['categories'] = true;
                                                 } else {
                                                     if (strpos($list->class, 'auto-blog-link-href') !== false) {
                                                         $list->href = '<?=getBlog("link-href", $x)?>';
                                                         $list->class = str_replace('auto-blog-link-href', '', $list->class);
                                                         $this->data['types']['link-href'] = true;
                                                     } else {
                                                         if (strpos($list->class, 'auto-blog-link') !== false) {
                                                             $list->href = '<?=getBlog("link", $x)?>';
                                                             $list->innertext = '<?=getBlog("link-text", $x)?>';
                                                             $list->class = str_replace('auto-blog-link', '', $list->class);
                                                             $this->data['types']['link-text'] = true;
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                         if (trim($list->class) === '') {
                             $list->class = null;
                         }
                     }
                     $fieldID = uniqid();
                     $blog->class = str_replace('auto-blog-list', '', $blog->class);
                     $blog->outertext = '<?php for ($x = 0; $x ' . '< blogCount("' . $file . '", "' . $fieldID . '");' . ' $x++) { ?>' . $blog->outertext . "<?php } ?>";
                     PagesData::addVariableToPage($file, $fieldID, array('blog-count' => 3, 'description' => 'blog display count', 'type' => 'blog-count'));
                 } else {
                     if (strpos($blog->class, 'auto-blog-post') !== false) {
                         $this->data['post-page'] = str_replace(array('.html', '.htm'), '', $file);
                         foreach ($html->find('.auto-blog-post .auto-blog-title, .auto-blog-post .auto-blog-date, .auto-blog-post .auto-blog-cats, .auto-blog-post .auto-blog-bg-img, .auto-blog-post .auto-blog-img, .auto-blog-post .auto-blog-short, .auto-blog-post .auto-blog-full') as $post) {
                             if (strpos($post->class, 'auto-blog-title') !== false) {
                                 $post->innertext = '<?=getBlog("title")?>';
                                 $post->class = str_replace('auto-blog-title', '', $post->class);
                                 $this->data['types']['title'] = true;
                             } else {
                                 if (strpos($post->class, 'auto-blog-bg-img') !== false) {
                                     $post->style = "background-image: url('<?=getBlog(" . '"image"' . ")?>');";
                                     $post->class = str_replace('auto-blog-bg-img', '', $post->class);
                                     $this->data['types']['image'] = true;
                                 } else {
                                     if (strpos($post->class, 'auto-blog-img') !== false) {
                                         $post->src = '<?=getBlog("image")?>';
                                         $post->alt = '<?=getBlog("image-alt-text")?>';
                                         $post->class = str_replace('auto-blog-img', '', $post->class);
                                         $this->data['types']['image'] = true;
                                         $this->data['types']['image-alt-text'] = true;
                                     } else {
                                         if (strpos($post->class, 'auto-blog-short') !== false) {
                                             $post->innertext = '<?=getBlog("short-blog")?>';
                                             $post->class = str_replace('auto-blog-short', '', $post->class);
                                             $this->data['types']['short-blog'] = true;
                                         } else {
                                             if (strpos($post->class, 'auto-blog-full') !== false) {
                                                 $post->innertext = '<?=getBlog("full-blog")?>';
                                                 $post->class = str_replace('auto-blog-full', '', $post->class);
                                                 $this->data['types']['full-blog'] = true;
                                             } else {
                                                 if (strpos($post->class, 'auto-blog-date') !== false) {
                                                     $post->innertext = '<?=getBlog("date")?>';
                                                     $post->class = str_replace('auto-blog-date', '', $post->class);
                                                     $this->data['types']['date'] = true;
                                                 } else {
                                                     if (strpos($post->class, 'auto-blog-cats') !== false) {
                                                         $post->innertext = '<?=getBlog("cats", "$x")?>';
                                                         $post->class = str_replace('auto-blog-cats', '', $post->class);
                                                         $this->data['types']['categories'] = true;
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                             if (trim($post->class) === '') {
                                 $post->class = null;
                             }
                         }
                         $blog->class = str_replace('auto-blog-post', '', $blog->class);
                     }
                 }
             }
             if (trim($blog->class) === '') {
                 $blog->class = null;
             }
         }
         $fp = fopen('../' . $file, 'w');
         fwrite($fp, $html);
         fclose($fp);
     }
 }