Ejemplo n.º 1
0
 function attach_db_init()
 {
     //	global $xoopsDB,$vars,$post,$get;
     if (!$this->func->exist_plugin('attach')) {
         return;
     }
     $attach = $this->func->get_plugin_instance('attach');
     if (!$attach) {
         return;
     }
     if ($dir = @opendir($this->cont['UPLOAD_DIR'])) {
         // 処理済ファイルリストデーター
         $work = $this->cont['CACHE_DIR'] . "dbsync_a.dat";
         $domix = $dones = array();
         $done = 0;
         if (is_file($work)) {
             $dones = unserialize(file_get_contents($work));
             if (!isset($dones[1])) {
                 $dones[1] = array();
             }
             $docnt = count($dones[1]);
             $domix = array_merge($dones[0], $dones[1]);
             $done = count($domix);
         }
         if ($done) {
             echo "<div style=\"font-size:14px;\"><b>DB '" . $this->root->mydirname . "_attach' Already converted {$docnt} pages.</b></div>";
         } else {
             $query = "DELETE FROM " . $this->db->prefix($this->root->mydirname . "_attach");
             if (!($result = $this->db->queryF($query))) {
                 echo 'SQL Error: ' . $query . '<br />';
             }
         }
         echo "<div style=\"font-size:14px;\"><b>DB '" . $this->root->mydirname . "_attach' Now converting... </b>( * = 10 Pages)<hr>";
         $counter = 0;
         $page_pattern = '(?:[0-9A-F]{2})+';
         $age_pattern = '(?:\\.([0-9]+))?';
         $pattern = "/^({$page_pattern})_((?:[0-9A-F]{2})+){$age_pattern}\$/";
         $files = array();
         while ($file = readdir($dir)) {
             $files[] = $file;
         }
         foreach (array_diff($files, $domix) as $file) {
             $matches = array();
             if (!preg_match($pattern, $file, $matches)) {
                 $dones[0][] = $file;
                 continue;
             }
             $page = $this->func->decode($matches[1]);
             $name = $this->func->decode($matches[2]);
             $age = array_key_exists(3, $matches) ? $matches[3] : 0;
             // サムネイルは除外
             if (preg_match("/^\\d\\d?%/", $name)) {
                 $dones[0][] = $file;
                 continue;
             }
             $obj = new XpWikiAttachFile($this->xpwiki, $page, $name, $age);
             $obj->getstatus();
             $obj->status['md5'] = md5_file($obj->filename);
             $obj->putstatus();
             $data['pgid'] = $this->func->get_pgid_by_name($page);
             $data['name'] = $name;
             $data['mtime'] = $obj->time;
             $data['size'] = $obj->size;
             $data['type'] = $obj->type;
             $data['status'] = $obj->status;
             $data['status']['age'] = $age;
             // ページが存在しない
             if (!$data['pgid']) {
                 $dones[0][] = $file;
                 continue;
             }
             if ($this->func->attach_db_write($data, "insert")) {
                 //echo "$page::$name;:$age<br >";
                 $counter++;
                 $dones[1][] = $file;
                 if ($counter / 10 == floor($counter / 10)) {
                     echo "*";
                 }
                 if ($counter / 100 == floor($counter / 100)) {
                     echo " ( Done " . $counter . " Files !)<br />";
                 }
             } else {
                 $dones[0][] = $file;
             }
             if ($this->check_time_limit()) {
                 // 処理済ファイルリスト保存
                 if ($fp = fopen($work, "wb")) {
                     fputs($fp, serialize($dones));
                     fclose($fp);
                 }
                 closedir($dir);
                 $this->plugin_dbsync_next_do();
             }
         }
         closedir($dir);
         echo " ( Done " . $counter . " Files !)<hr />";
         echo "</div>";
         @unlink($work);
     }
     $this->root->post['attach'] = "";
 }
Ejemplo n.º 2
0
 function attach_open()
 {
     //	global $vars,$_attach_messages;
     foreach (array('refer', 'file', 'age') as $var) {
         ${$var} = array_key_exists($var, $this->root->vars) ? $this->root->vars[$var] : '';
     }
     $obj = new XpWikiAttachFile($this->xpwiki, $refer, $file, $age);
     return $obj->getstatus() ? $obj->open() : array('header' => array('HTTP/1.0 404 Not Found', 'Status: 404 Not Found'), 'msg' => 'File Not Found.');
 }
Ejemplo n.º 3
0
 function get_attachstatus($file)
 {
     if (is_array($file)) {
         $page = $file['page'];
         $name = $file['name'];
         $age = $file['age'];
     } else {
         $file = basename($file);
         $pattern = "/^((?:[0-9A-F]{2})+)_((?:[0-9A-F]{2})+)(?:\\.([0-9]+))?\$/";
         if (preg_match($pattern, $file, $matches)) {
             $page = $this->decode($matches[1]);
             $name = $this->decode($matches[2]);
             $age = isset($matches[3]) ? $matches[3] : 0;
         } else {
             return array();
         }
     }
     $obj = new XpWikiAttachFile($this->xpwiki, $page, $name, $age);
     if ($obj->getstatus()) {
         $status = $obj->status;
     } else {
         $status = array();
     }
     $obj = NULL;
     unset($obj);
     return $status;
 }