Exemple #1
0
<?php

if (!defined('MIGRATE')) {
    exit;
}
@$this->_query("ALTER TABLE {$atbl} ADD preview_id INT(11) DEFAULT 0");
$albums = $this->_query("SELECT id, aTn FROM {$atbl} WHERE aTn IS NOT NULL AND aTn <> ''");
if ($this->_rows($albums) > 0) {
    while ($row = $this->_array($albums)) {
        $tn = $row['aTn'];
        list($tn, $aid) = explode(':', $tn);
        if (empty($aid)) {
            $aid = $row['id'];
        }
        $image = $this->_query("SELECT id,anchor,src FROM {$itbl} WHERE src = '{$tn}' AND aid = {$aid}");
        $i = $this->_array($image);
        list($x, $y) = parse_anchor($i['anchor']);
        $tn = join(':', array($i['src'], $aid, $x, $y));
        if (is_numeric($i['id'])) {
            $this->_query("UPDATE {$atbl} SET preview_id = {$i['id']}, aTn = '{$tn}' WHERE id = {$row['id']}");
        }
    }
}
 function anchor($id)
 {
     $this->Image->id = $id;
     $this->Image->saveField('anchor', serialize($this->data));
     $image = $this->Image->read(null, $id);
     $this->Image->clearCaches($image['Image']['src'], ALBUMS . DS . 'album-' . $image['Album']['id']);
     $this->set('image', $image);
     $bit = $image['Image']['src'] . ':' . $image['Image']['aid'];
     list($x, $y) = parse_anchor(serialize($this->data));
     $new = join(':', array($image['Image']['src'], $image['Image']['aid'], $x, $y));
     $new_vid = join(':', array($image['Image']['src'], $x, $y));
     $this->Image->Album->updateAll(array('aTn' => "'{$new}'"), array('aTn LIKE' => "{$bit}:%"));
     $this->Image->updateAll(array('lg_preview' => "'{$new_vid}'"), array('lg_preview_id' => $image['Image']['id']));
     $this->Image->updateAll(array('tn_preview' => "'{$new_vid}'"), array('tn_preview_id' => $image['Image']['id']));
     $previews = $this->Image->find('all', array('conditions' => array('lg_preview_id' => $image['Image']['id']), 'recursive' => -1));
     $this->set('previews', $previews);
     $this->render('anchor', 'ajax');
 }