Last active
August 29, 2015 14:06
-
-
Save lukespragg/d6f88c909c530cd595ff to your computer and use it in GitHub Desktop.
Simplified XenForo API made specifically for grabbing the latest version of a resource.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$resource = XenAPI::getResource(1); | |
echo json_encode($resource); | |
class XenAPI | |
{ | |
private static $isset = FALSE; | |
private static $xf_dir; | |
private static $modules = array(); | |
private static function checkInstallation() | |
{ | |
if (self::$isset !== TRUE) { | |
self::$xf_dir = dirname(__FILE__); | |
require_once(self::getRootDirectory() . '/library/XenForo/Autoloader.php'); | |
XenForo_Autoloader::getInstance()->setupAutoloader(self::getLibraryDirectory()); | |
XenForo_Application::initialize(self::getLibraryDirectory(), self::getRootDirectory()); | |
XenForo_Application::set('page_start_time', microtime(TRUE)); | |
$deps = new XenForo_Dependencies_Public(); | |
$deps->preLoadData(); | |
self::$modules['resource'] = XenForo_Model::create('XenResource_Model_Resource'); | |
self::$modules['resource_version'] = XenForo_Model::create('XenResource_Model_Version'); | |
self::$modules['attachment'] = XenForo_Model::create('XenForo_Model_Attachment'); | |
self::$isset = TRUE; | |
} | |
} | |
private static function getRootDirectory() | |
{ | |
return self::$xf_dir; | |
} | |
private static function getLibraryDirectory() | |
{ | |
return self::getRootDirectory() . '/library'; | |
} | |
public static function getResource($resource_id, $fetch_options = array()) | |
{ | |
self::checkInstallation(); | |
$resource = self::getModule('resource')->getResourceById($resource_id, $fetch_options); | |
$resource_version = self::getModule('resource_version')->getVersionById( | |
$resource['current_version_id'], | |
array('join' => XenResource_Model_Version::FETCH_FILE) | |
); | |
$resource['current_version_string'] = $resource_version['version_string']; | |
if ($resource['is_fileless'] === 0) { | |
$attachment_id = $resource_version['attachment_id']; | |
$attachment = $this->getModels()->getModel('attachment')->getAttachmentById($attachment_id); | |
$resource['current_file_hash'] = $attachment['file_hash']; | |
} | |
return $resource; | |
} | |
private static function getModule($module) | |
{ | |
return self::$modules[$module]; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment