コード例 #1
0
 public function getSitemapFileName($setId, $counter, $compressed = false)
 {
     $path = XenForo_Helper_File::getInternalDataPath() . '/sitemaps';
     if (!XenForo_Helper_File::createDirectory($path, true)) {
         throw new XenForo_Exception("Sitemap directory {$path} could not be created");
     }
     return "{$path}/sitemap-{$setId}-{$counter}.xml" . ($compressed ? '.gz' : '');
 }
コード例 #2
0
 public static function ConvertFilename(&$attachmentFile)
 {
     $xf_code_root = XenForo_Application::getInstance()->getRootDir();
     $internal_data = XenForo_Helper_File::getInternalDataPath();
     $internal_data_uri = self::getInternalDataUrl();
     if ($internal_data_uri && strpos($attachmentFile, $internal_data) === 0) {
         $attachmentFile = str_replace($internal_data, $internal_data_uri, $attachmentFile);
         return true;
     } else {
         if (strpos($attachmentFile, $xf_code_root) === 0) {
             $attachmentFile = str_replace($xf_code_root, '', $attachmentFile);
             return true;
         } else {
             return false;
         }
     }
 }
コード例 #3
0
ファイル: ImageProxy.php プロジェクト: Sywooch/forums
 /**
  * Gets the path to an image in the file system image cache
  *
  * @param array $image
  *
  * @return string
  */
 public function getImagePath(array $image)
 {
     return sprintf('%s/image_cache/%d/%d-%s.data', XenForo_Helper_File::getInternalDataPath(), floor($image['image_id'] / 1000), $image['image_id'], $image['url_hash']);
 }
コード例 #4
0
 protected function __construct()
 {
     $this->_path = XenForo_Helper_File::getInternalDataPath() . '/templates';
 }
コード例 #5
0
 public function isInstalled()
 {
     return file_exists(XenForo_Helper_File::getInternalDataPath() . '/install-lock.php') && file_exists(XenForo_Application::getInstance()->getConfigDir() . '/config.php');
 }
コード例 #6
0
ファイル: ImageResizer.php プロジェクト: Sywooch/forums
    public function actionUpdate()
    {
        //########################################
        // Update each attachment because
        // the pixel width is over maxWidth
        // setting in options.
        //########################################
        // get user group permissions
        if (!XenForo_Visitor::getInstance()->hasPermission('imageResizerGroupID', 'imageResizerID')) {
            throw $this->getNoPermissionResponseException();
        }
        // get options from Admin CP -> Options -> Image Resizer -> Default Image Processor
        $imPecl = XenForo_Application::get('options')->imageLibrary['class'];
        // check option
        if ($imPecl != 'imPecl') {
            return $this->responseError(new XenForo_Phrase('imageresizer_imagemagick_with_pecl_required'));
        }
        // get options from Admin CP -> Options -> Image Resizer -> Maximum Width
        $maximumWidth = XenForo_Application::get('options')->imageResizerMaximumWidth;
        // check option
        if ($maximumWidth == 0) {
            return $this->responseError(new XenForo_Phrase('imageresizer_maximum_width_in_options_not_set'));
        }
        // get options from Admin CP -> Options -> Image Resizer -> Maximum Height
        $maximumHeight = XenForo_Application::get('options')->imageResizerMaximumHeight;
        // check option
        if ($maximumHeight == 0) {
            return $this->responseError(new XenForo_Phrase('imageresizer_maximum_height_in_options_not_set'));
        }
        // get limit
        $limit = $this->_input->filterSingle('limit', XenForo_Input::UINT);
        // verify limit set
        if ($limit == '') {
            return $this->responseError(new XenForo_Phrase('imageresizer_limit_switch_missing_in_url'));
        }
        //########################################
        // start update process
        //########################################
        // get internalDataPath
        $internalDataPath = XenForo_Helper_File::getInternalDataPath();
        // get data path
        $externalDataPath = XenForo_Helper_File::getExternalDataPath();
        // get database
        $db = XenForo_Application::get('db');
        // run query
        $attachments = $db->fetchAll("\n\t\tSELECT xf_attachment_data.*, xf_attachment.*, xf_user.username\n\t\tFROM xf_attachment_data\n\t\tINNER JOIN xf_attachment ON xf_attachment.data_id = xf_attachment_data.data_id\n\t\tINNER JOIN xf_user ON xf_user.user_id = xf_attachment_data.user_id\n\t\tWHERE xf_attachment.unassociated = 0\n\t\tAND xf_attachment.content_type = 'post'\n\t\tAND\t(xf_attachment_data.width > " . $maximumWidth . "\n\t\tOR xf_attachment_data.height > " . $maximumHeight . ")\n\t\tORDER BY xf_attachment_data.width DESC, xf_attachment_data.data_id DESC\n\t\tLIMIT " . $limit . "\n\t\t");
        foreach ($attachments as $k => $v) {
            // clear variable
            $skip = '';
            //#####################################
            // define last folder name
            // 0-999 are stored in the 0 directory
            // 1000-1999 stored in the 1 directory etc
            //#####################################
            $dataId = $v['data_id'];
            $fileHash = $v['file_hash'];
            $lastFolder = floor($dataId / 1000);
            //#####################################
            // define attachment full path
            //#####################################
            // attachment path
            $attachmentFullPath = $internalDataPath . '/attachments/' . $lastFolder . '/' . $dataId . '-' . $fileHash . '.data';
            // throw error if file missing
            if (!file_exists($attachmentFullPath)) {
                throw new XenForo_Exception(new XenForo_Phrase('imageresizer_attachment_missing_from_file_directory') . ' ' . $attachmentFullPath, true);
            }
            //#####################################
            // get file information
            //#####################################
            // get size
            $filesize = filesize($attachmentFullPath);
            // get dimensions
            list($width, $height) = getimagesize($attachmentFullPath);
            //#####################################
            // If file information is different
            // than information in database, update
            // database first.
            //#####################################
            // verify database information is correct
            if ($filesize != $v['file_size'] or $width != $v['width'] or $height != $v['height']) {
                // run query
                $db->query('
				UPDATE xf_attachment_data SET
					file_size = "' . $filesize . '",
					width = "' . $width . '",
					height = "' . $height . '"
				WHERE data_id = ?
				', $dataId);
                // skip resize
                $skip = 'yes';
            }
            // resize if required
            if ($skip != 'yes') {
                //#####################################
                // Database information is correct,
                // resize image.
                //#####################################
                // get options from Admin CP -> Options -> Image Resizer -> Maximum Width
                $maximumWidth = XenForo_Application::get('options')->imageResizerMaximumWidth;
                // get options from Admin CP -> Options -> Image Resizer -> Maximum Height
                $maximumHeight = XenForo_Application::get('options')->imageResizerMaximumHeight;
                // resize based on width
                if ($width > $maximumWidth) {
                    // resize image - (use the '\>' flag)
                    exec("/usr/bin/convert {$attachmentFullPath} -resize {$maximumWidth} x {$maximumHeight}\\> {$attachmentFullPath}");
                }
                // resize based on height
                if ($width <= $maximumWidth and $height > $maximumHeight) {
                    // resize based on height only
                    exec("/usr/bin/convert {$attachmentFullPath} -resize x{$maximumHeight} {$attachmentFullPath}");
                }
                //#####################################
                // Rename attachment with new file hash
                // in the filename.
                //#####################################
                // get new hash
                $filehashNew = hash_file('md5', $attachmentFullPath);
                // prepare new filename (with new file hash)
                $newFilenameDataPath = $internalDataPath . '/attachments/' . $lastFolder . '/' . $dataId . '-' . $filehashNew . '.data';
                // rename original filename to new filename
                exec("mv {$attachmentFullPath} {$newFilenameDataPath}");
                //#####################################
                // update xf_attachment_data
                //#####################################
                // get size
                $filesize = filesize($newFilenameDataPath);
                // get dimensions
                list($width, $height) = getimagesize($newFilenameDataPath);
                // run query
                $db->query('
				UPDATE xf_attachment_data SET
					file_size = "' . $filesize . '",
					file_hash = "' . $filehashNew . '",
					width = "' . $width . '",
					height = "' . $height . '"
				WHERE data_id = ?
				', $dataId);
                //#####################################
                // Update thumbnail with new file hash
                // in the filename.
                //#####################################
                // thumbpath original name
                $thumbpath = $externalDataPath . '/attachments/' . $lastFolder . '/' . $dataId . '-' . $fileHash . '.jpg';
                // throw error if file missing
                if (!file_exists($thumbpath)) {
                    throw new XenForo_Exception(new XenForo_Phrase('imageresizer_attachment_missing_from_file_directory') . ' ' . $thumbpath, true);
                }
                // thumbpath new name
                $thumbpathNew = $externalDataPath . '/attachments/' . $lastFolder . '/' . $dataId . '-' . $filehashNew . '.jpg';
                // rename thumbnail
                exec("mv {$thumbpath} {$thumbpathNew}");
            }
        }
        // response redirect
        return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildPublicLink('imageresizer/updateconfirm'));
    }
コード例 #7
0
    public function stepMedia($start, array $options)
    {
        $options = array_merge(array('path' => XenForo_Helper_File::getInternalDataPath() . '/xfru/useralbums/images', 'limit' => 5, 'max' => false), $options);
        $sDb = $this->_sourceDb;
        if ($options['max'] === false) {
            $options['max'] = $sDb->fetchOne('
				SELECT MAX(image_id)
				FROM xfr_useralbum_image
			');
        }
        $userAlbumsMoreInstalled = '';
        if (XenForo_Application::isRegistered('addOns')) {
            $addOns = XenForo_Application::get('addOns');
            if (!empty($addOns['XfRuUserAlbumsMore'])) {
                $userAlbumsMoreInstalled = ', album.selected_users';
            }
        }
        $media = $sDb->fetchAll($sDb->limit('
				SELECT image.*, data.*,
				album.album_id, album.album_type, album.moderation
				' . $userAlbumsMoreInstalled . '
				FROM xfr_useralbum_image AS image
				INNER JOIN xfr_useralbum_image_data AS data ON
					(image.data_id = data.data_id)
				INNER JOIN xfr_useralbum AS album ON
					(image.album_id = album.album_id)
				WHERE image.image_id > ' . $sDb->quote($start) . '
					AND image.unassociated = 0
					AND data.attach_count > 0
				ORDER BY image.image_id
			', $options['limit']));
        if (!$media) {
            return true;
        }
        $next = 0;
        $total = 0;
        foreach ($media as $item) {
            $next = $item['image_id'];
            $user = $sDb->fetchRow('
				SELECT user_id, username
				FROM xf_user
				WHERE user_id = ?
			', $item['user_id']);
            if (!$user) {
                continue;
            }
            $success = $this->_importMedia($item, $options);
            if ($success) {
                $total++;
            } else {
                continue;
            }
        }
        $this->_session->incrementStepImportTotal($total);
        return array($next, $options, $this->_getProgressOutput($next, $options['max']));
    }
コード例 #8
0
ファイル: Bible.php プロジェクト: ThemeHouse-XF/Biblea
 public function deleteTemporaryFiles($bibleId)
 {
     $internalDataPath = XenForo_Helper_File::getInternalDataPath();
     $path = $internalDataPath . DIRECTORY_SEPARATOR . 'bibles' . DIRECTORY_SEPARATOR . $bibleId;
     if (is_dir($path)) {
         $files = scandir($path);
         foreach ($files as $file) {
             if (!is_dir($file)) {
                 @unlink($path . "/" . $file);
             }
         }
         @rmdir($path);
     }
 }
コード例 #9
0
 /**
  * Gets the full path to this attachment's data.
  *
  * @param array $data Attachment data info
  *
  * @return string
  */
 public function getAttachmentDataFilePath(array $data)
 {
     return XenForo_Helper_File::getInternalDataPath() . '/attachments/' . floor($data['data_id'] / 1000) . "/{$data['data_id']}-{$data['file_hash']}.data";
 }
コード例 #10
0
 /**
  * Gets the path to an thumbnail in the file system thumbnail cache
  *
  * @param array $thumbnail
  *
  * @return string
  */
 public function getThumbnailPath(array $thumbnail)
 {
     return sprintf('%s/thumbnail_cache/%d/%d-%s.data', XenForo_Helper_File::getInternalDataPath(), floor($thumbnail['thumbnail_id'] / 1000), $thumbnail['thumbnail_id'], $thumbnail['url_hash']);
 }
コード例 #11
0
 /**
  * Gets the full path to this attachment's data.
  *
  * @param array $data Attachment data info
  * @param string Internal data path
  *
  * @return string
  */
 public function getAttachmentDataFilePath(array $data, $internalDataPath = null)
 {
     if ($internalDataPath === null) {
         $internalDataPath = XenForo_Helper_File::getInternalDataPath();
     }
     return sprintf('%s/attachments/%d/%d-%s.data', $internalDataPath, floor($data['data_id'] / 1000), $data['data_id'], $data['file_hash']);
 }
コード例 #12
0
ファイル: Album.php プロジェクト: VoDongMy/xenforo-laravel5.1
 public function getAlbumThumbnailFilePath($albumId, $original = false)
 {
     if ($original) {
         return sprintf('%s/xengallery/originals/album/%d/%d.jpg', XenForo_Helper_File::getInternalDataPath(), floor($albumId / 1000), $albumId);
     } else {
         return sprintf('%s/xengallery/album/%d/%d.jpg', XenForo_Helper_File::getExternalDataPath(), floor($albumId / 1000), $albumId);
     }
 }
コード例 #13
0
ファイル: User.php プロジェクト: ThemeHouse-XF/UserImpEx
 public function actionImportForm()
 {
     $this->_checkCsrfFromToken($this->_request->getParam('_xfToken'));
     $input = $this->_input->filter(array('options' => XenForo_Input::ARRAY_SIMPLE, 'mode' => XenForo_Input::STRING));
     $xenOptions = XenForo_Application::get('options');
     $input['options'] = array_merge(array('start_row' => 0, 'row_count' => $xenOptions->th_userImpEx_batchImportUsers, 'filename' => ''), $input['options']);
     $userModel = $this->_getUserModel();
     if ($input['mode'] == 'upload') {
         $upload = XenForo_Upload::getUploadedFile('upload');
         if (!$upload) {
             return $this->responseError(new XenForo_Phrase('th_please_upload_valid_users_xml_file_userimpex'));
         }
         $document = $this->getHelper('Xml')->getXmlFromFile($upload);
         $users = $userModel->getUsersFromXml($document);
     } elseif ($input['mode'] == 'uploadcsv') {
         if (!$input['options']['filename']) {
             $upload = XenForo_Upload::getUploadedFile('uploadcsv');
             if (!$upload) {
                 return $this->responseError(new XenForo_Phrase('th_please_upload_valid_users_csv_file_userimpex'));
             }
             $tempFile = $upload->getTempFile();
             if ($input['options']['row_count']) {
                 $internalDataPath = XenForo_Helper_File::getInternalDataPath();
                 XenForo_Helper_File::createDirectory($internalDataPath . '/userimpex/');
                 $filename = $internalDataPath . '/userimpex/' . XenForo_Application::$time . '.csv';
                 copy($tempFile, $filename);
             } else {
                 $filename = $tempFile;
             }
         } else {
             $filename = $input['options']['filename'];
         }
         $users = $this->getHelper('ThemeHouse_UserImpEx_ControllerHelper_Csv')->getCsvFromFile($filename, $input['options']['start_row'], $input['options']['row_count']);
         if (count($users) == $input['options']['row_count']) {
             $input['options']['start_row'] = $input['options']['start_row'] + $input['options']['row_count'];
             $input['options']['filename'] = $filename;
         } else {
             unset($input['options']['start_row'], $input['options']['row_count']);
         }
     } else {
         $users = $this->_input->filterSingle('users', XenForo_Input::ARRAY_SIMPLE);
     }
     $userCount = count($users);
     $users = $userModel->massImportUsers($users);
     $usersImported = $userCount - count($users);
     /* @var $userChangeLogModel XenForo_Model_UserChangeLog */
     $userChangeLogModel = $this->getModelFromCache('XenForo_Model_UserChangeLog');
     $fields = array();
     foreach ($users as $user) {
         foreach ($user as $fieldName => $fieldValue) {
             if (!isset($fields[$fieldName])) {
                 $field = array('field' => $fieldName, 'old_value' => '', 'new_value' => '');
                 $field = $userChangeLogModel->prepareField($field);
                 $fields[$fieldName] = $field['name'];
             }
         }
     }
     $viewParams = array('options' => $input['options'], 'mode' => $input['mode'], 'users' => $users, 'usersImported' => $usersImported, 'fields' => $fields);
     if (!$users && empty($input['options']['filename'])) {
         return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildAdminLink('users/list'));
     }
     return $this->responseView('ThemeHouse_UserImpEx_ViewAdmin_User_ImportForm', 'th_user_import_form_userimpex', $viewParams);
 }
コード例 #14
0
ファイル: Import.php プロジェクト: ThemeHouse-XF/Biblea
 public function execute(array $deferred, array $data, $targetRunTime, &$status)
 {
     $data = array_merge(array('position' => 0, 'count' => 0, 'imported' => XenForo_Application::$time), $data);
     if (empty($data['bible_id'])) {
         return false;
     }
     $db = XenForo_Application::getDb();
     /* @var $bibleModel ThemeHouse_Bible_Model_Bible */
     $bibleModel = XenForo_Model::create('ThemeHouse_Bible_Model_Bible');
     /* @var $bookModel ThemeHouse_Bible_Model_Book */
     $bookModel = XenForo_Model::create('ThemeHouse_Bible_Model_Book');
     /* @var $verseModel ThemeHouse_Bible_Model_Verse */
     $verseModel = XenForo_Model::create('ThemeHouse_Bible_Model_Verse');
     $internalDataPath = XenForo_Helper_File::getInternalDataPath();
     $path = $internalDataPath . DIRECTORY_SEPARATOR . 'bibles' . DIRECTORY_SEPARATOR . $data['bible_id'];
     if (!file_exists($path) || !is_dir($path)) {
         return false;
     }
     $mappedFilename = $path . DIRECTORY_SEPARATOR . $data['bible_id'] . '_utf8_mapped_to_NRSVA.txt';
     $utf8Filename = $path . DIRECTORY_SEPARATOR . $data['bible_id'] . '_utf8.txt';
     $mappingFilename = $path . DIRECTORY_SEPARATOR . $data['bible_id'] . '_mapping_to_NRSVA.txt';
     if (file_exists($mappedFilename)) {
         $handle = fopen($mappedFilename, 'r');
     } elseif (file_exists($utf8Filename)) {
         $handle = fopen($utf8Filename, 'r');
     }
     $bibleInfo = array();
     $columns = array();
     $fields = array('name', 'copyright', 'abbreviation', 'language', 'note');
     if (isset($handle)) {
         $position = 0;
         while ($row = fgets($handle)) {
             $row = explode("\t", rtrim($row, "\r\n"));
             if (empty($row[0])) {
                 // do nothing
             } elseif (substr($row[0], 0, 1) != '#') {
                 fseek($handle, $position);
                 break;
             } elseif (in_array(substr($row[0], 1), $fields)) {
                 if (!empty($row[1])) {
                     $key = substr(array_shift($row), 1);
                     $bibleInfo[$key] = implode(',', $row);
                 } else {
                     $bibleInfo[substr($row[0], 1)] = '';
                 }
             } elseif (substr($row[0], 1) == 'columns') {
                 array_shift($row);
                 $columns = $row;
             }
             $position = ftell($handle);
         }
     }
     $bibleId = $data['bible_id'];
     $bible = $bibleModel->getBibleById($bibleId);
     $bookNamesFilename = $path . '/book_names.txt';
     if (!file_exists($bookNamesFilename)) {
         return false;
     }
     $bookIndexes = array();
     $bookNamesHandle = fopen($bookNamesFilename, 'r');
     while ($row = fgets($bookNamesHandle)) {
         $row = explode("\t", rtrim($row, "\r\n"));
         if (empty($row[0])) {
             continue;
         }
         $bookIndexes[$row[0]] = $row[1];
     }
     fclose($bookNamesHandle);
     $bookNameIds = array();
     if ($data['position'] == 0 || $bibleInfo && !$bible) {
         $bibleDw = XenForo_DataWriter::create('ThemeHouse_Bible_DataWriter_Bible');
         if ($bible) {
             $bibleDw->setExistingData($bible);
         } else {
             $bibleDw->set('bible_id', $bibleId);
         }
         if (strpos($bibleInfo['name'], ':') !== false) {
             $title = trim(substr($bibleInfo['name'], strpos($bibleInfo['name'], ':') + 2));
         } else {
             $title = $bibleInfo['name'];
         }
         $bibleDw->setExtraData(ThemeHouse_Bible_DataWriter_Bible::DATA_TITLE, $title);
         $bibleDw->bulkSet($bibleInfo);
         $bibleDw->save();
         $bible = $bibleDw->getMergedData();
         if ($bible) {
             $htmlFilename = $path . DIRECTORY_SEPARATOR . $bibleId . '.html';
             if (file_exists($htmlFilename)) {
                 $html = file_get_contents($htmlFilename);
                 preg_match('#<body>(.*)</body>#s', $html, $matches);
                 if (!empty($matches[1])) {
                     $html = $matches[1];
                 }
             } else {
                 $html = '';
             }
             $title = $bibleModel->getTemplateTitle(array('bible_id' => $bibleId));
             /* @var $templateModel XenForo_Model_Template */
             $templateModel = XenForo_Model::create('XenForo_Model_Template');
             $template = $templateModel->getTemplateInStyleByTitle($title);
             if (!$template || $html) {
                 $templateWriter = XenForo_DataWriter::create('XenForo_DataWriter_Template');
                 if ($template) {
                     $templateWriter->setExistingData($template);
                 }
                 $templateWriter->set('title', $title);
                 $templateWriter->set('template', $html);
                 $templateWriter->set('style_id', 0);
                 $templateWriter->set('addon_id', '');
                 $templateWriter->save();
             }
         }
         $bookNamesFilename = $path . '/book_names.txt';
         if (file_exists($bookNamesFilename)) {
             $phraseModel = XenForo_Model::create('XenForo_Model_Phrase');
             $bibleBookNameValues = array();
             $priorities = array();
             foreach ($bookIndexes as $bookIndex => $bookTitle) {
                 $book = $bookModel->getBookByName(strtolower($bookTitle));
                 if (!$book) {
                     $urlPortion = strtolower(XenForo_Link::getTitleForUrl($bookTitle, true));
                     $book = $bookModel->getBookByUrlPortion($urlPortion);
                 } else {
                     $urlPortion = $book['url_portion'];
                 }
                 $title = $verseModel->getBookPhraseTitle($urlPortion);
                 $phraseModel->insertOrUpdateMasterPhrase($title, $bookTitle, '', array(), array(XenForo_DataWriter_Phrase::OPTION_REBUILD_LANGUAGE_CACHE => false, XenForo_DataWriter_Phrase::OPTION_RECOMPILE_TEMPLATE => false));
                 if ($book) {
                     $bookId = $book['book_id'];
                     $priorities[$book['section']] = $book['priority'];
                 } else {
                     $section = substr($bookIndex, -1, 1);
                     if (isset($priorities[$section])) {
                         $priorities[$section] = $priorities[$section] + 10;
                     } else {
                         $priorities[$section] = 10;
                     }
                     $db->query('
                             UPDATE xf_bible_book
                             SET priority = priority + 10
                             WHERE priority >= ? AND section = ?
                         ', array($priorities[$section], $section));
                     $db->query('
                             INSERT INTO xf_bible_book
                             (url_portion, priority, section)
                             VALUES (?, ?, ?)
                         ', array($urlPortion, $priorities[$section], $section));
                     $bookId = $db->lastInsertId();
                     $bibleBookNameValues[] = '(' . $db->quote(strtolower($bookTitle)) . ',' . $db->quote($bookId) . ')';
                 }
                 $bookNameIds[strtolower($bookTitle)] = $bookId;
             }
             if ($bibleBookNameValues) {
                 $db->query('
                         INSERT INTO xf_bible_book_name
                         (book_name, book_id)
                         VALUES ' . implode(',', $bibleBookNameValues) . '
                         ON DUPLICATE KEY UPDATE book_name = book_name
                     ');
             }
         }
     }
     if (!isset($handle) || empty($columns)) {
         @fclose($handle);
         $bibleModel->deleteTemporaryFiles($bibleId);
         return false;
     }
     $requiredColumns = array('orig_book_index', 'orig_chapter', 'orig_verse', 'text');
     foreach ($requiredColumns as $requiredColumn) {
         if (!in_array($requiredColumn, $columns)) {
             fclose($handle);
             $bibleModel->deleteTemporaryFiles($bibleId);
             return false;
         }
     }
     $startTime = microtime(true);
     if (ftell($handle) < $data['position']) {
         $seek = fseek($handle, $data['position']);
         $row = explode("\t", rtrim(fgets($handle), "\r\n"));
         if (feof($handle)) {
             fclose($handle);
             $bibleModel->deleteTemporaryFiles($bibleId);
             return false;
         }
     }
     while ($row = fgets($handle)) {
         $row = explode("\t", rtrim($row, "\r\n"));
         if (empty($row[0])) {
             continue;
         }
         $data['position'] = ftell($handle);
         $verseData = array_combine($columns, $row);
         $bookName = strtolower($bookIndexes[$verseData['orig_book_index']]);
         if (!isset($bookNameIds[$bookName])) {
             $book = $bookModel->getBookByName($bookName);
             $bookNameIds[$bookName] = $book['book_id'];
         }
         $bookId = $bookNameIds[$bookName];
         $origChapter = $verseData['orig_chapter'];
         $origVerse = $verseData['orig_verse'];
         $text = $verseData['text'];
         $verse = $verseModel->getSpecificVerse($bibleId, $bookId, $origChapter, $origVerse);
         // TODO manage subverses here?
         $verseDw = XenForo_DataWriter::create('ThemeHouse_Bible_DataWriter_Verse');
         if ($verse) {
             $verseDw->setExistingData($verse);
         }
         $verseDw->bulkSet(array('bible_id' => $bibleId, 'book_id' => $bookId, 'chapter' => $origChapter, 'verse' => $origVerse, 'text' => $text));
         $verseDw->save();
         $data['count']++;
         if ($targetRunTime && microtime(true) - $startTime > $targetRunTime) {
             break;
         }
     }
     if (feof($handle)) {
         fclose($handle);
         $bibleModel->deleteTemporaryFiles($bibleId);
         $bookModel->rebuildBookCache();
         return false;
     }
     $actionPhrase = new XenForo_Phrase('importing');
     $typePhrase = new XenForo_Phrase('th_bible_verses_bible');
     $status = sprintf('%s... %s (%s)', $actionPhrase, $typePhrase, XenForo_Locale::numberFormat($data['count']));
     return $data;
 }
コード例 #15
0
ファイル: Error.php プロジェクト: darkearl/projectT122015
 public static function logException($e, $rollbackTransactions = true, $messagePrefix = '')
 {
     $isValidArg = $e instanceof Exception || $e instanceof Throwable;
     if (!$isValidArg) {
         throw new Exception("logException requires an Exception or a Throwable");
     }
     try {
         $db = XenForo_Application::getDb();
         if ($db->getConnection()) {
             if ($rollbackTransactions) {
                 @XenForo_Db::rollbackAll($db);
             }
             $dbVersionId = @$db->fetchOne("SELECT option_value FROM xf_option WHERE option_id = 'currentVersionId'");
             if ($dbVersionId && $dbVersionId != XenForo_Application::$versionId) {
                 // do not log errors when an upgrade is pending
                 return;
             }
             if (!file_exists(XenForo_Helper_File::getInternalDataPath() . '/install-lock.php')) {
                 // install hasn't finished yet, don't write
                 return;
             }
             $rootDir = XenForo_Application::getInstance()->getRootDir();
             $file = $e->getFile();
             if (strpos($file, $rootDir) === 0) {
                 $file = substr($file, strlen($rootDir));
                 if (strlen($file) && ($file[0] == '/' || $file[0] == '\\')) {
                     $file = substr($file, 1);
                 }
             }
             $requestPaths = XenForo_Application::get('requestPaths');
             $request = array('url' => $requestPaths['fullUri'], '_GET' => $_GET, '_POST' => $_POST);
             // don't log passwords
             foreach ($request['_POST'] as $key => &$value) {
                 if (strpos($key, 'password') !== false || $key == '_xfToken') {
                     $value = '********';
                 }
             }
             $db->insert('xf_error_log', array('exception_date' => XenForo_Application::$time, 'user_id' => XenForo_Visitor::hasInstance() ? XenForo_Visitor::getUserId() : null, 'ip_address' => XenForo_Helper_Ip::getBinaryIp(), 'exception_type' => get_class($e), 'message' => $messagePrefix . $e->getMessage(), 'filename' => $file, 'line' => $e->getLine(), 'trace_string' => $e->getTraceAsString(), 'request_state' => serialize($request)));
         }
     } catch (Exception $e) {
     }
 }
コード例 #16
0
ファイル: Media.php プロジェクト: VoDongMy/xenforo-laravel5.1
 public function getOriginalDataFilePath(array $data, $checkExists = false, $internalDataPath = null)
 {
     if ($internalDataPath === null) {
         $internalDataPath = XenForo_Helper_File::getInternalDataPath();
     }
     $filePath = sprintf('%s/xengallery/originals/%d/%d-file_hash.data', $internalDataPath, floor($data['data_id'] / 1000), $data['data_id']);
     if (XenForo_Application::getOptions()->xengalleryEnableWatermarking == 'disabled' && empty($data['watermark_id'])) {
         @unlink($filePath);
         $checkExists = true;
     }
     if ($checkExists && (!file_exists($filePath) || !is_readable($filePath))) {
         $filePath = $this->getAttachmentDataFilePath($data);
     }
     return $filePath;
 }
コード例 #17
0
 /**
  * Gets the full path to this attachment's data.
  *
  * @param array $data Attachment data info
  * @param string Internal data path
  *
  * @return string
  */
 public function getAttachmentDataFilePath(array $data, $internalDataPath = null)
 {
     if ($internalDataPath === null) {
         $internalDataPath = XenForo_Helper_File::getInternalDataPath();
     }
     if (!empty($data['file_path'])) {
         $placeholders = array('%INTERNAL%' => $internalDataPath, '%DATA%' => XenForo_Helper_File::getExternalDataPath(), '%DATA_ID%' => $data['data_id'], '%FLOOR%' => floor($data['data_id'] / 1000), '%HASH%' => $data['file_hash']);
         return strtr($data['file_path'], $placeholders);
     } else {
         return sprintf('%s/attachments/%d/%d-%s.data', $internalDataPath, floor($data['data_id'] / 1000), $data['data_id'], $data['file_hash']);
     }
 }
コード例 #18
0
ファイル: Template.php プロジェクト: maitandat1507/DevHelper
 public static function getTemplateDirPath()
 {
     return call_user_func_array('sprintf', array('%s/DevHelper/templates', XenForo_Helper_File::getInternalDataPath()));
 }