public function __construct($data = array())
 {
     parent::__construct();
     $this->entityType = 'article';
     if (!empty($data['id'])) {
         $CMS = new CMS();
         $this->id = $data['id'];
         $this->populate_object($CMS->get_entity_data($this));
     }
     $this->populate_object($data);
     if (empty($this->template)) {
         $templates = new Templates();
         $defaultTemplate = $templates->get_default();
         $this->template = $defaultTemplate['path'];
     }
 }
 private function collect_article_files($entity)
 {
     $files = array();
     /* HTML OF ARTICLE */
     $html = $this->get_html_content($entity);
     /* VERIFY TEMPLATE */
     if (file_exists($entity->template)) {
         $template = $entity->template;
     } else {
         $templates = new Templates();
         $defaultTemplate = $templates->get_default();
         $template = $defaultTemplate['path'];
     }
     /* COLLECT ADDITIONAL FILES FROM A TEMPLATE (CMS) */
     ob_start();
     include_once $template;
     ob_get_clean();
     $templateFiles = $this->get_files_from_template($entity);
     /* DOWNLOAD COLLECTED FILES FROM TEMPLATE FILES */
     foreach ($templateFiles as $file) {
         if (is_array($file)) {
             foreach ($file as $key => $path) {
                 $files[$key] = $this->save_file(basename($key), $path);
             }
         } else {
             if (is_string($file)) {
                 $files[$this->build_asset_path($file)] = $this->save_file(basename($file), $file);
             }
         }
     }
     /* PARSE HTML AND DOWNLOAD LINKED IMAGES / MEDIA / CSS / JS FILES */
     $collected = $this->get_linked_assets_from_html($html, $entity);
     $files = array_merge($files, $collected["assets"]);
     $files["index.html"] = $this->make_file("index", (string) $collected["html"]);
     /* VERIFY ARTICLE FILES */
     foreach ($files as $key => $file) {
         $size = filesize($file);
         if ($size < 1 || $size === FALSE) {
             unset($files[$key]);
         }
     }
     /* CREATE ARTICLE MANIFEST */
     $files["manifest.xml"] = $this->make_file("manifest", $this->create_article_manifest($files));
     return $files;
 }