<?php
require_once('copytool.php');
require_once('sfYaml.class.php');

//
// update banner, background and javascript
//
$stmt = execSQL('select bl_id, bl_module_config, bl_lastupdate from tblblog order by bl_hit desc limit 1000');

while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
  list($bl_id, $bl_config, $bl_lastupdate) = array_values($row);
  $config = sfYaml::load($bl_config);
  $config = $config['config'];

  foreach (array(@$config['banner']['url'], @$config['banner']['swfurl'], @$config['background']['url']) as $fname)
    if ($fname != null) mycopy("uploads/blogs/$bl_id/layout/$fname");

  $last = date('ymdHis', strtotime($bl_lastupdate));
  mycopy("uploads/blogs/$bl_id/js/jcat$last.js");
}

//
// update entry images and thumbnails
//
$stmt = execSQL('select entry_id, entry_content, entry_blog, entry_thumb from tblblogentry use index (PRIMARY) '.
                'where entry_type=2 order by entry_id desc limit 10000');

while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
  list($id, $content, $blog, $thumb) = array_values($row);
  preg_match_all('/<img.*?src="(.*?)".*?>/', $content, $matchs);
  foreach ($matchs[1] as $src)
    if (preg_match('/^\/(.*)$/', $src, $match) || preg_match('/^http:\/\/.*?violet\.vn\/(.*)$/', $src, $match))
      mycopy(preg_replace('/\/(resources|previews)\/blog\//', '/blogs/', $match[1]));
  if ($thumb == 1) mycopy("uploads/blogs/$blog/entrythumb/$id.jpg");
}


