示例#1
0
 *
 * 2. Change CSS_FILENAME in the configuration below to match your css stylesheet
 *
 * 3. Open a terminal, go to the right directory, and run :
 *
 * 4. `php css2URI.php > my-new-stylesheet.css`
 *
 * 5. Or run it from a web-browser and paste the result in a new css file
 *
 */
/* ------------ CONFIG --------------*/
define('CSS_FILENAME', 'style.css');
/* ------------ SCRIPT --------------*/
$file = realpath(dirname(__FILE__)) . '/' . CSS_FILENAME;
$css_str = file_get_contents($file);
$urls = get_images_url($css_str);
$css = get_css_with_data_uri($css_str, $urls);
echo $css;
/* ------------ FUNCTIONS -----------*/
function get_images_url($css_str)
{
    preg_match_all('/url\\(([\\s])?([\\"|\'])?(.*?)([\\"|\'])?([\\s])?\\)/i', $css_str, $matches, PREG_PATTERN_ORDER);
    if ($matches) {
        foreach ($matches[3] as $key => $match) {
            if (!is_image_url($match)) {
                unset($matches[3][$key]);
            }
        }
    }
    return $matches[3];
}
示例#2
0
 function social_meta_data($data, $type)
 {
     $out = false;
     if (isset($data->id) > 0) {
         if ($type == 1) {
             $url = get_articles_url($data->staties_id, $data->slug);
             $image = get_news_img($data->img);
             $desc = !empty($data->meta_desc) ? $data->meta_desc : $data->head;
         } else {
             $url = url() . get_images_url($data->id, $data->slug);
             $image = unserialize($data->images);
             $image = get_gallery_img($image[0]);
             $desc = !empty($data->meta_desc) ? $data->meta_desc : substr($data->body, 0, 100);
         }
         $out .= '<meta name="description" lang="ge" content="' . $data->meta_desc . '" />';
         $out .= '<meta name="keywords" lang="ge" content="' . $data->meta_key . '" />';
         $out .= '<title>' . $data->title . '</title>';
         $out .= '<meta property="og:title" content="' . str_replace('"', '&quot;', $data->title) . '" />';
         $out .= '<meta property="og:type" content="website" />';
         $out .= '<meta property="og:url" content="' . $url . '" />';
         $out .= '<meta property="og:image" content="' . $image . '" />';
         $out .= '<meta property="og:site_name" content=""/>';
         $out .= '<meta property="og:description" content="' . $desc . '"/>';
     }
     return $out;
 }