/**
  * Add method
  *
  * @return void Redirects on successful add, renders view otherwise.
  */
 public function add()
 {
     $minute = $this->Minutes->newEntity();
     if ($this->request->is('post')) {
         //perform content extraction
         $f = $this->request->data['uploaded_file'];
         $extractor = new \ContentExtractor($f['type']);
         if ($extractor->supported()) {
             try {
                 $minute['content'] = $extractor->extract($f['tmp_name']);
             } catch (Exception $e) {
                 $minute['content'] = '';
             }
         }
         //set meeting date
         $date = new \DateTime($this->request->data['meeting_date']);
         $minute['meeting_date'] = $date;
         //process upload data. Always set to private
         $ret = $this->Upload->attachToEntity($minute, $f);
         if ($ret['success'] && $this->Minutes->save($minute)) {
             $this->Flash->success(__('The minutes have been saved.'));
             return $this->redirect(['action' => 'index']);
         }
         //if we haven't been re-directed yet, we've failed
         $msg = $ret['message'];
         $this->Flash->error(__("The uploaded file could not be saved. Error message was: '{$msg}'"));
     }
     $this->set(compact('minute'));
     $this->set('_serialize', ['minute']);
 }
예제 #2
0
                }
            }
        }
        return array($link_cnt, $word_cnt, $text_len, 'delete' => $delete);
    }
    function decode($str)
    {
        $str = str_replace(array('&#', ';'), array('', ''), $str);
        $dec = intval($str[0]);
        if ($dec < 128) {
            $utf .= chr($dec);
        } else {
            if ($dec < 2048) {
                $utf .= chr(192 + ($dec - $dec % 64) / 64);
                $utf .= chr(128 + $dec % 64);
            } else {
                $utf .= chr(224 + ($dec - $dec % 4096) / 4096);
                $utf .= chr(128 + ($dec % 4096 - $dec % 64) / 64);
                $utf .= chr(128 + $dec % 64);
            }
        }
        return $utf;
    }
}
/****************************
	Simple usage example
*****************************/
$html = file_get_contents('http://www.techweb.com.cn/news/2010-07-20/644329.shtml');
$extractor = new ContentExtractor();
$content = $extractor->extract($html);
echo $content;