本文整理汇总了PHP中SpoonFile类的典型用法代码示例。如果您正苦于以下问题:PHP SpoonFile类的具体用法?PHP SpoonFile怎么用?PHP SpoonFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SpoonFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildCache
/**
* Build navigation cache file.
*
* @return void
*/
public function buildCache()
{
// init
$navigationTree = '';
// build tree starting with the root
$this->buildNavigation(0, $navigationTree);
// start generating PHP
$value = '<?php' . "\n";
$value .= '/**' . "\n";
$value .= ' *' . "\n";
$value .= ' * This file is generated by the Backend, it contains' . "\n";
$value .= ' * more information about the navigation in the backend. Do NOT edit.' . "\n";
$value .= ' * ' . "\n";
$value .= ' * @author Backend' . "\n";
$value .= ' * @generated ' . date('Y-m-d H:i:s') . "\n";
$value .= ' */' . "\n";
$value .= "\n";
$value .= "\$navigation = array(\n";
// add navigation tree
$value .= $navigationTree;
// close php
$value .= ");\n";
$value .= "\n";
$value .= '?>';
// store
SpoonFile::setContent(BACKEND_CACHE_PATH . '/navigation/navigation.php', $value);
}
示例2: loadConfig
/**
* Load the config file for the requested module.
* In the config file we have to find disabled actions, the constructor will read the folder
* and set possible actions. Other configurations will also be stored in it.
*/
public function loadConfig()
{
// check if module path is not yet defined
if (!defined('BACKEND_MODULE_PATH')) {
// build path for core
if ($this->getModule() == 'core') {
define('BACKEND_MODULE_PATH', BACKEND_PATH . '/' . $this->getModule());
} else {
define('BACKEND_MODULE_PATH', BACKEND_MODULES_PATH . '/' . $this->getModule());
}
}
// check if the config is present? If it isn't present there is a huge problem, so we will stop our code by throwing an error
if (!SpoonFile::exists(BACKEND_MODULE_PATH . '/config.php')) {
throw new BackendException('The configfile for the module (' . $this->getModule() . ') can\'t be found.');
}
// build config-object-name
$configClassName = 'Backend' . SpoonFilter::toCamelCase($this->getModule() . '_config');
// require the config file, we validated before for existence.
require_once BACKEND_MODULE_PATH . '/config.php';
// validate if class exists (aka has correct name)
if (!class_exists($configClassName)) {
throw new BackendException('The config file is present, but the classname should be: ' . $configClassName . '.');
}
// create config-object, the constructor will do some magic
$this->config = new $configClassName($this->getModule());
}
示例3: getWarnings
/**
* Get warnings for active modules
*
* @return array
*/
public static function getWarnings()
{
// init vars
$warnings = array();
$activeModules = BackendModel::getModules(true);
// add warnings
$warnings = array_merge($warnings, BackendModel::checkSettings());
// loop active modules
foreach ($activeModules as $module) {
// model class
$class = 'Backend' . SpoonFilter::toCamelCase($module) . 'Model';
// model file exists
if (SpoonFile::exists(BACKEND_MODULES_PATH . '/' . $module . '/engine/model.php')) {
// require class
require_once BACKEND_MODULES_PATH . '/' . $module . '/engine/model.php';
}
// method exists
if (is_callable(array($class, 'checkSettings'))) {
// add possible warnings
$warnings = array_merge($warnings, call_user_func(array($class, 'checkSettings')));
}
}
// return
return (array) $warnings;
}
示例4: loadData
/**
* Load the data.
* This will also set some warnings if needed.
*/
private function loadData()
{
// inform that the module is not installed yet
if (!BackendExtensionsModel::isModuleInstalled($this->currentModule)) {
$this->warnings[] = array('message' => BL::getMessage('InformationModuleIsNotInstalled'));
}
// path to information file
$pathInfoXml = BACKEND_MODULES_PATH . '/' . $this->currentModule . '/info.xml';
// information needs to exists
if (SpoonFile::exists($pathInfoXml)) {
try {
// load info.xml
$infoXml = @new SimpleXMLElement($pathInfoXml, LIBXML_NOCDATA, true);
// convert xml to useful array
$this->information = BackendExtensionsModel::processModuleXml($infoXml);
// empty data (nothing useful)
if (empty($this->information)) {
$this->warnings[] = array('message' => BL::getMessage('InformationFileIsEmpty'));
}
// check if cronjobs are installed already
if (isset($this->information['cronjobs'])) {
foreach ($this->information['cronjobs'] as $cronjob) {
if (!$cronjob['active']) {
$this->warnings[] = array('message' => BL::getError('CronjobsNotSet'));
}
break;
}
}
} catch (Exception $e) {
$this->warnings[] = array('message' => BL::getMessage('InformationFileCouldNotBeLoaded'));
}
} else {
$this->warnings[] = array('message' => BL::getMessage('InformationFileIsMissing'));
}
}
示例5: getCM
/**
* Returns the CampaignMonitor object
*
* @param int[optional] $listId The default list id to use.
* @return CampaignMonitor
*/
public static function getCM($listId = null)
{
// campaignmonitor reference exists
if (!Spoon::exists('campaignmonitor')) {
// check if the CampaignMonitor class exists
if (!SpoonFile::exists(PATH_LIBRARY . '/external/campaignmonitor.php')) {
// the class doesn't exist, so throw an exception
throw new SpoonFileException('The CampaignMonitor wrapper class is not found. Please locate and place it in /library/external');
}
// require CampaignMonitor class
require_once 'external/campaignmonitor.php';
// set login data
$url = FrontendModel::getModuleSetting('mailmotor', 'cm_url');
$username = FrontendModel::getModuleSetting('mailmotor', 'cm_username');
$password = FrontendModel::getModuleSetting('mailmotor', 'cm_password');
// init CampaignMonitor object
$cm = new CampaignMonitor($url, $username, $password, 5, self::getClientId());
// set CampaignMonitor object reference
Spoon::set('campaignmonitor', $cm);
// get the default list ID
$listId = !empty($listId) ? $listId : self::getDefaultListID();
// set the default list ID
$cm->setListId($listId);
}
// return the CampaignMonitor object
return Spoon::get('campaignmonitor');
}
示例6: getPath
/**
* Get the file path based on the theme.
* If it does not exist in the theme it will return $file.
*
* @return string Path to the (theme) file.
* @param string $file Path to the file.
*/
public static function getPath($file)
{
// redefine
$file = (string) $file;
// theme name
$theme = self::getTheme();
// theme in use
if (FrontendModel::getModuleSetting('core', 'theme', 'core') != 'core') {
// theme not yet specified
if (strpos($file, 'frontend/themes/' . $theme) === false) {
// add theme location
$themeTemplate = str_replace(array('frontend/'), array('frontend/themes/' . $theme . '/'), $file);
// check if this template exists
if (SpoonFile::exists(PATH_WWW . str_replace(PATH_WWW, '', $themeTemplate))) {
$file = $themeTemplate;
}
}
}
// check if the file exists
if (!SpoonFile::exists(PATH_WWW . str_replace(PATH_WWW, '', $file))) {
throw new FrontendException('The template (' . $file . ') doesn\'t exists.');
}
// return template path
return $file;
}
示例7: loadData
/**
* Load the data.
* This will also set some warnings if needed.
*/
private function loadData()
{
// inform that the theme is not installed yet
if (!BackendExtensionsModel::isThemeInstalled($this->currentTheme)) {
$this->warnings[] = array('message' => BL::getMessage('InformationThemeIsNotInstalled'));
}
// path to information file
$pathInfoXml = FRONTEND_PATH . '/themes/' . $this->currentTheme . '/info.xml';
// information needs to exists
if (SpoonFile::exists($pathInfoXml)) {
try {
// load info.xml
$infoXml = @new SimpleXMLElement($pathInfoXml, LIBXML_NOCDATA, true);
// convert xml to useful array
$this->information = BackendExtensionsModel::processThemeXml($infoXml);
// empty data (nothing useful)
if (empty($this->information)) {
$this->warnings[] = array('message' => BL::getMessage('InformationFileIsEmpty'));
}
} catch (Exception $e) {
$this->warnings[] = array('message' => BL::getMessage('InformationFileCouldNotBeLoaded'));
}
} else {
$this->warnings[] = array('message' => BL::getMessage('InformationFileIsMissing'));
}
}
示例8: parse
/**
* Parse the correct messages into the template
*/
protected function parse()
{
parent::parse();
// grab the error-type from the parameters
$errorType = $this->getParameter('type');
// set correct headers
switch ($errorType) {
case 'module-not-allowed':
case 'action-not-allowed':
SpoonHTTP::setHeadersByCode(403);
break;
case 'not-found':
SpoonHTTP::setHeadersByCode(404);
break;
}
// querystring provided?
if ($this->getParameter('querystring') !== null) {
// split into file and parameters
$chunks = explode('?', $this->getParameter('querystring'));
// get extension
$extension = SpoonFile::getExtension($chunks[0]);
// if the file has an extension it is a non-existing-file
if ($extension != '' && $extension != $chunks[0]) {
// set correct headers
SpoonHTTP::setHeadersByCode(404);
// give a nice error, so we can detect which file is missing
echo 'Requested file (' . htmlspecialchars($this->getParameter('querystring')) . ') not found.';
// stop script execution
exit;
}
}
// assign the correct message into the template
$this->tpl->assign('message', BL::err(SpoonFilter::toCamelCase(htmlspecialchars($errorType), '-')));
}
示例9: validateInstall
/**
* Validate if the module can be installed.
*/
private function validateInstall()
{
// already installed
if (BackendExtensionsModel::isModuleInstalled($this->currentModule)) {
$this->redirect(BackendModel::createURLForAction('modules') . '&error=already-installed&var=' . $this->currentModule);
}
// no installer class present
if (!SpoonFile::exists(BACKEND_MODULES_PATH . '/' . $this->currentModule . '/installer/installer.php')) {
$this->redirect(BackendModel::createURLForAction('modules') . '&error=no-installer-file&var=' . $this->currentModule);
}
}
示例10: validateInstall
/**
* Validate if the theme can be installed.
*/
private function validateInstall()
{
// already installed
if (BackendExtensionsModel::isThemeInstalled($this->currentTheme)) {
$this->redirect(BackendModel::createURLForAction('themes') . '&error=already-installed&var=' . $this->currentTheme);
}
// no information file present
if (!SpoonFile::exists(FRONTEND_PATH . '/themes/' . $this->currentTheme . '/info.xml')) {
$this->redirect(BackendModel::createURLForAction('themes') . '&error=no-information-file&var=' . $this->currentTheme);
}
}
示例11: execute
/**
* Execute the action
*/
public function execute()
{
parent::execute();
// get parameters
$url = SpoonFilter::getPostValue('url', null, '');
$username = SpoonFilter::getPostValue('username', null, '');
$password = SpoonFilter::getPostValue('password', null, '');
// filter out the 'http://' from the URL
if (strpos($url, 'http://') !== false) {
$url = str_replace('http://', '', $url);
}
if (strpos($url, 'https://') !== false) {
$url = str_replace('https://', '', $url);
}
// check input
if (empty($url)) {
$this->output(self::BAD_REQUEST, array('field' => 'url'), BL::err('NoCMAccountCredentials'));
}
if (empty($username)) {
$this->output(self::BAD_REQUEST, array('field' => 'username'), BL::err('NoCMAccountCredentials'));
}
if (empty($password)) {
$this->output(self::BAD_REQUEST, array('field' => 'password'), BL::err('NoCMAccountCredentials'));
}
try {
// check if the CampaignMonitor class exists
if (!SpoonFile::exists(PATH_LIBRARY . '/external/campaignmonitor.php')) {
// the class doesn't exist, so stop here
$this->output(self::BAD_REQUEST, null, BL::err('ClassDoesNotExist', $this->getModule()));
}
// require CampaignMonitor class
require_once 'external/campaignmonitor.php';
// init CampaignMonitor object
new CampaignMonitor($url, $username, $password, 10);
// save the new data
BackendModel::setModuleSetting($this->getModule(), 'cm_url', $url);
BackendModel::setModuleSetting($this->getModule(), 'cm_username', $username);
BackendModel::setModuleSetting($this->getModule(), 'cm_password', $password);
// account was linked
BackendModel::setModuleSetting($this->getModule(), 'cm_account', true);
} catch (Exception $e) {
// timeout occured
if ($e->getMessage() == 'Error Fetching http headers') {
$this->output(self::BAD_REQUEST, null, BL::err('CmTimeout', $this->getModule()));
}
// other error
$this->output(self::ERROR, array('field' => 'url'), sprintf(BL::err('CampaignMonitorError', $this->getModule()), $e->getMessage()));
}
// trigger event
BackendModel::triggerEvent($this->getModule(), 'after_account_linked');
// CM was successfully initialized
$this->output(self::OK, array('message' => 'account-linked'), BL::msg('AccountLinked', $this->getModule()));
}
示例12: write
/**
* Write an error/custom message to the log.
*
* @return void
* @param string $message The messages that should be logged.
* @param string[optional] $type The type of message you want to log, possible values are: error, custom.
*/
public static function write($message, $type = 'error')
{
// milliseconds
list($milliseconds) = explode(' ', microtime());
$milliseconds = round($milliseconds * 1000, 0);
// redefine var
$message = date('Y-m-d H:i:s') . ' ' . $milliseconds . 'ms | ' . $message . "\n";
$type = SpoonFilter::getValue($type, array('error', 'custom'), 'error');
// file
$file = self::getPath() . '/' . $type . '.log';
// rename if needed
if ((int) @filesize($file) >= self::MAX_FILE_SIZE * 1024) {
// start new log file
SpoonDirectory::move($file, $file . '.' . date('Ymdhis'));
}
// write content
SpoonFile::setContent($file, $message, true, true);
}
示例13: execute
/**
* Execute the action
*/
public function execute()
{
$this->id = $this->getParameter('id', 'int');
// does the item exist
if ($this->id !== null && BackendAddressesModel::exists($this->id)) {
parent::execute();
$this->record = (array) BackendAddressesModel::get($this->id);
BackendAddressesModel::delete($this->id);
BackendAddressesModel::deleteGroupsFromAddress($this->id);
// delete the image
\SpoonFile::delete(FRONTEND_FILES_PATH . '/Addresses/Images/Source/' . $this->record['image']);
BackendSearchModel::removeIndex($this->getModule(), $this->id);
BackendModel::triggerEvent($this->getModule(), 'after_delete', array('id' => $this->id));
$this->redirect(BackendModel::createURLForAction('index') . '&report=deleted&var=' . urlencode($this->record['id']));
} else {
$this->redirect(BackendModel::createURLForAction('index') . '&error=non-existing');
}
}
示例14: processFile
/**
* Process the content of the file.
*
* @param string $file The file to process.
* @return boolean|array
*/
private function processFile($file)
{
// if the files doesn't exists we can stop here and just return an empty string
if (!SpoonFile::exists($file)) {
return array();
}
// fetch content from file
$content = SpoonFile::getContent($file);
$json = @json_decode($content, true);
// skip invalid JSON
if ($json === false || $json === null) {
return array();
}
$return = array();
// loop templates
foreach ($json as $template) {
// skip items without a title
if (!isset($template['title'])) {
continue;
}
if (isset($template['file'])) {
if (SpoonFile::exists(PATH_WWW . $template['file'])) {
$template['html'] = SpoonFile::getContent(PATH_WWW . $template['file']);
}
}
// skip items without HTML
if (!isset($template['html'])) {
continue;
}
$image = '';
if (isset($template['image'])) {
// we have to remove the first slash, because that is set in the wrapper. Otherwise the images don't work
$image = ltrim($template['image'], '/');
}
$temp['title'] = $template['title'];
$temp['description'] = isset($template['description']) ? $template['description'] : '';
$temp['image'] = $image;
$temp['html'] = $template['html'];
// add the template
$return[] = $temp;
}
return $return;
}
示例15: loadDataGrid
/**
* Load the datagrid
*
* @return void
*/
private function loadDataGrid()
{
// init var
$items = array();
// get active modules
$modules = BackendModel::getModules();
// loop active modules
foreach ($modules as $module) {
// check if their is a model-file
if (SpoonFile::exists(BACKEND_MODULES_PATH . '/' . $module . '/engine/model.php')) {
// require the model-file
require_once BACKEND_MODULES_PATH . '/' . $module . '/engine/model.php';
// build class name
$className = SpoonFilter::toCamelCase('backend_' . $module . '_model');
// check if the getByTag-method is available
if (is_callable(array($className, 'getByTag'))) {
// make the call and get the item
$moduleItems = (array) call_user_func(array($className, 'getByTag'), $this->id);
// loop items
foreach ($moduleItems as $row) {
// check if needed fields are available
if (isset($row['url'], $row['name'], $row['module'])) {
// add
$items[] = array('module' => ucfirst(BL::lbl(SpoonFilter::toCamelCase($row['module']))), 'name' => $row['name'], 'url' => $row['url']);
}
}
}
}
}
// create datagrid
$this->dgUsage = new BackendDataGridArray($items);
// disable paging
$this->dgUsage->setPaging(false);
// hide columns
$this->dgUsage->setColumnsHidden(array('url'));
// set headers
$this->dgUsage->setHeaderLabels(array('name' => ucfirst(BL::lbl('Title')), 'url' => ''));
// set url
$this->dgUsage->setColumnURL('name', '[url]', ucfirst(BL::lbl('Edit')));
// add use column
$this->dgUsage->addColumn('edit', null, ucfirst(BL::lbl('Edit')), '[url]', BL::lbl('Edit'));
}