Example #1
0
 public function getArticle($site)
 {
     $article = new Article();
     $article->setSite($site);
     // Main Data
     $article->setTitle($this->title);
     $article->setSlug($this->title);
     $article->setUrl($this->url);
     $article->setDescription($this->description);
     $article->setPublication($this->publication);
     // Slug
     $slug = mb_strtolower($this->title);
     $slug = str_replace(' ', '-', $slug);
     $slug = str_replace(['á', 'é', 'í', 'ó', 'ú'], ['a', 'e', 'i', 'o', 'u'], $slug);
     $slug = preg_replace('/[^\\w\\d-]+/', '-', $slug);
     $slug = preg_replace('/-+/', '-', $slug);
     $slug = trim($slug, '-');
     $article->setSlug($slug);
     // Images
     $this->images = [];
     preg_match_all('/<img .*src="([^"]+)"/i', $this->content, $matches);
     if (isset($matches[1])) {
         foreach ($matches[1] as $idx => $imageUrl) {
             $imageHash = sha1($imageUrl) . '.jpg';
             $imageInfo = @getimagesize($imageUrl);
             if ($imageInfo && isset($imageInfo[1]) && $imageInfo[1] > 50) {
                 $this->images[$imageHash] = $imageUrl;
                 // Replace Images
                 $this->content = str_replace($imageUrl, '/assets/' . $site->getSlug() . '/' . $imageHash, $this->content);
                 // Set main image
                 if ($idx == 0) {
                     $article->setMainImage($imageHash);
                 }
             }
         }
     }
     $article->setContent($this->content);
     $article->calculateHash();
     return $article;
 }