protected function _updateDb()
 {
     list($title, $id) = DevTools_Helper_File::getIdAndTitleFromFileName($this->_data['fileName']);
     $data = array('title' => $title, 'phrase_text' => $this->_data['contents'], 'language_id' => 0, 'global_cache' => $this->_data['global_cache'], 'addon_id' => $this->_data['addon_id']);
     if (!$this->_getPhraseModel()->canModifyPhraseInLanguage($data['language_id'])) {
         $this->printDebugInfo('E: ' . new XenForo_Phrase('this_phrase_can_not_be_modified') . "\n");
         return 0;
     }
     $writer = XenForo_DataWriter::create('XenForo_DataWriter_Phrase');
     $writer->setOption(XenForo_DataWriter_Phrase::OPTION_DATA_FROM_FILE, true);
     if (!$this->isNewFile()) {
         $writer->setExistingData($this->_data['id']);
     }
     $writer->bulkSet($data);
     if ($writer->isChanged('title') or $writer->isChanged('phrase_text') or $writer->get('language_id') > 0) {
         $writer->updateVersionId();
     }
     try {
         $this->assertNoDwErrors($writer, 'save', $this->getDataType());
     } catch (XenForo_Exception $e) {
         return 0;
     } catch (Exception $e) {
         throw $e;
     }
     $writer->save();
     if (!$this->isNewfile()) {
         $this->printDebugInfo("- phrase updated in database\n");
     }
     return $writer->get('phrase_id');
 }
 protected function _updateTemplateDb($styleId)
 {
     $dw = $this->_getDataWriter();
     $new = $this->isNewFile();
     $modified = ($new or $this->isModified());
     if (!$new) {
         $dw->setExistingData($this->_data['id']);
     }
     if ($styleId != -1) {
         $dw->set('style_id', $styleId);
     }
     list($title, $id) = DevTools_Helper_File::getIdAndTitleFromFileName($this->_data['fileName']);
     if (substr($title, -5) == '.html') {
         $title = substr($title, 0, -5);
     }
     $data = array('title' => $title, 'addon_id' => $this->_data['addon_id']);
     if ($modified) {
         $properties = $this->getPropertiesInStyle($styleId);
         $propertyChanges = $this->_getPropertyModel()->translateEditorPropertiesToArray($this->_data['contents'], $contents, $properties);
         $contents = $this->_getTemplateModel()->replaceLinkRelWithIncludes($contents);
         $data['template'] = $contents;
     }
     $dw->bulkSet($data);
     try {
         $this->assertNoDwErrors($dw, 'save', $this->getDataType());
     } catch (XenForo_Exception $e) {
         return 0;
     } catch (Exception $e) {
         throw $e;
     }
     $dw->save();
     if (!$new and $dw->isChanged('title')) {
         $this->printDebugInfo("- updated title to \"{$title}\"\n");
     }
     if (!$new and $dw->isChanged('addon_id')) {
         $this->printDebugInfo('- updated addon_id to "' . $dw->get('addon_id') . "\"\n");
     }
     if ($modified) {
         if (!$new) {
             $this->printDebugInfo("- updated template contents\n");
         }
         $this->_getPropertyModel()->saveStylePropertiesInStyleFromTemplate($styleId, $propertyChanges, $properties);
     }
     return $dw->get('template_id');
 }
 protected function _loadFile()
 {
     if (!file_exists($this->_filePath)) {
         if ($this->_id > 0) {
             foreach ($this->getOriginalFiles() as $file) {
                 list($title, $id) = DevTools_Helper_File::getIdAndTitleFromFileName($file['fileName']);
                 if ($id == $this->_id) {
                     $this->_filePath = $file['filePath'];
                 }
             }
         }
         if (!file_exists($this->_filePath)) {
             $this->_data = false;
             return;
         }
     }
     $file = new SplFileInfo($this->_filePath);
     if (!$file->isFile() or !$file->isReadable() or !$file->isWritable()) {
         return;
     }
     list($title, $id) = DevTools_Helper_File::getIdAndTitleFromFileName($file->getFilename());
     $this->_data = array('id' => $id, 'title' => $title, 'fileName' => $file->getFilename(), 'contents' => file_get_contents($file->getPathname()), 'lastModifiedTime' => $file->getMTime(), 'filePath' => $file->getPathname());
 }
 public function getFilesFromDirectory($dir, &$files)
 {
     $dir = new DirectoryIterator($dir);
     foreach ($dir as $file) {
         if ($file->isDot() or substr($file->getFilename(), 0, 1) == '.' or $file->getFilename() == 'Thumbs.db' or $file->getFilename() == 'desktop.ini') {
             continue;
         }
         if ($file->isDir()) {
             $this->getFilesFromDirectory($file->getPathname(), $files);
             continue;
         }
         if ($file->isFile()) {
             list($title, $id) = DevTools_Helper_File::getIdAndTitleFromFileName($file->getFileName());
             if (!$id or !isset($files[$id]) or $files[$id]['filePath'] != $file->getPathname()) {
                 $files[-count($files) - 1] = array('id' => $id, 'title' => $title, 'fileName' => $file->getFilename(), 'filePath' => $file->getPathname(), 'contents' => file_get_contents($file->getPathname()), 'lastModifiedTime' => $file->getMTime());
             }
         }
     }
 }