function first_og_image_from_html_string($str = '') { if (empty($str)) { return false; } $urls = hrefs_from_html_string($str); foreach ($urls as $url) { if (is_opengraphable_image($url)) { return $url; } } return false; }
<meta property="og:description" content="<?php if (isset($page->version_index)) { echo htmlspecialchars(create_excerpt($page->versions[$page->version_index]->content, 34)); } else { echo htmlspecialchars(trim(strip_tags($description))); } ?> " /> <meta property="og:image" content="<?php $default_img = $app_root . 'views/arbors/html5_RDFa/scalar_logo_300x300.png'; if (isset($page->version_index)) { $img = first_og_image_from_html_string($page->versions[$page->version_index]->content); $url = $page->versions[$page->version_index]->url; if (!empty($img)) { echo abs_url(str_replace(' ', '%20', $img), base_url() . $book->slug); } elseif (!empty($url) && is_opengraphable_image($url)) { echo abs_url(str_replace(' ', '%20', $url), base_url() . $book->slug); } elseif (!empty($banner)) { echo abs_url(str_replace(' ', '%20', $banner), base_url() . $book->slug); } elseif (!empty($background)) { echo abs_url(str_replace(' ', '%20', $background), base_url() . $book->slug); } else { echo $default_img; } } else { echo $default_img = $app_root . 'views/arbors/html5_RDFa/scalar_logo_300x300.png'; } ?> " /> <meta property="og:type" content="article" /> <?php