本文整理汇总了PHP中Jaws_Utils::chmod方法的典型用法代码示例。如果您正苦于以下问题:PHP Jaws_Utils::chmod方法的具体用法?PHP Jaws_Utils::chmod怎么用?PHP Jaws_Utils::chmod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Jaws_Utils
的用法示例。
在下文中一共展示了Jaws_Utils::chmod方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: packTheme
/**
* Creates a .zip file of the theme in themes/ directory
*
* @access public
* @param string $theme Name of the theme
* @param string $srcDir Source directory
* @param string $destDir Target directory
* @param bool $copy_example_to_repository If copy example.png too or not
* @return bool Returns true if:
* - Theme exists
* - Theme exists and could be packed
* Returns false if:
* - Theme doesn't exist
* - Theme doesn't exists and couldn't be packed
*/
function packTheme($theme, $srcDir, $destDir, $copy_example_to_repository = true)
{
$themeSrc = $srcDir . '/' . $theme;
if (!is_dir($themeSrc)) {
return new Jaws_Error(_t('TMS_ERROR_THEME_DOES_NOT_EXISTS', $theme));
}
if (!Jaws_Utils::is_writable($destDir)) {
return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_DIRECTORY_UNWRITABLE', $destDir), $this->gadget->name);
}
$themeDest = $destDir . '/' . $theme . '.zip';
//If file exists.. delete it
if (file_exists($themeDest)) {
@unlink($themeDest);
}
require_once PEAR_PATH . 'File/Archive.php';
$reader = File_Archive::read($themeSrc, $theme);
$innerWriter = File_Archive::toFiles();
$writer = File_Archive::toArchive($themeDest, $innerWriter);
$res = File_Archive::extract($reader, $writer);
if (PEAR::isError($res)) {
return new Jaws_Error(_t('TMS_ERROR_COULD_NOT_PACK_THEME'));
}
Jaws_Utils::chmod($themeDest);
if ($copy_example_to_repository) {
//Copy image to repository/images
if (file_exists($srcDir . '/example.png')) {
@copy($srcDir . '/example.png', JAWS_DATA . "themes/repository/Resources/images/{$theme}.png");
Jaws_Utils::chmod(JAWS_DATA . 'themes/repository/Resources/images/' . $theme . '.png');
}
}
return $themeDest;
}
示例2: Install
/**
* Installs the gadget
*
* @access public
* @return mixed True on successful installation, Jaws_Error otherwise
*/
function Install()
{
if (!Jaws_Utils::is_writable(JAWS_DATA)) {
return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_DIRECTORY_UNWRITABLE', JAWS_DATA));
}
$new_dir = JAWS_DATA . 'emblems' . DIRECTORY_SEPARATOR;
if (!Jaws_Utils::mkdir($new_dir)) {
return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_CREATING_DIR', $new_dir));
}
$result = $this->installSchema('schema.xml');
if (Jaws_Error::IsError($result)) {
return $result;
}
// If you are here, then copy the default jaws and feeds images
$emblems = array('jaws', 'php', 'apache', 'mysql', 'pgsql', 'xhtml', 'css', 'atom', 'rss');
foreach ($emblems as $emblem) {
copy(JAWS_PATH . "gadgets/Emblems/Resources/images/{$emblem}.png", $new_dir . "{$emblem}.png");
Jaws_Utils::chmod($new_dir . "{$emblem}.png");
}
$variables = array();
$variables['timestamp'] = Jaws_DB::getInstance()->date();
// Dump database data
$result = $this->installSchema('insert.xml', $variables, 'schema.xml', true);
if (Jaws_Error::IsError($result)) {
return $result;
}
return true;
}
示例3: RSS
/**
* Displays or writes a RDF feed for the link group
*
* @access public
* @return string xml with RDF feed on display mode, nothing otherwise
*/
function RSS()
{
header('Content-type: application/rss+xml');
$gid = jaws()->request->fetch('id', 'get');
$rss_path = JAWS_DATA . 'xml/link-' . $gid . '.rss';
if (file_exists($rss_path)) {
///FIXME we need to do more error checking over here
$rss = @file_get_contents($rss_path);
return $rss;
}
$rss = $this->GenerateFeed($gid);
if (Jaws_Error::IsError($rss)) {
return '';
}
///FIXME we need to do more error checking over here
@file_put_contents($rss_path, $rss);
Jaws_Utils::chmod($rss_path);
return $rss;
}
示例4: MakeCategoryRSS
/**
* Create RSS of a given category
*
* @access public
* @param int $categoryId Category ID
* @param string $catAtom
* @param bool $writeToDisk Flag that determinates if Atom file should be written to disk
* @return mixed Returns the RSS(string) if it was required, or Jaws_Error on error
*/
function MakeCategoryRSS($categoryId, $catAtom = null, $writeToDisk = false)
{
if (empty($catAtom)) {
$catAtom = $this->GetCategoryAtomStruct($categoryId, 'rss');
if (Jaws_Error::IsError($catAtom)) {
return $catAtom;
}
}
if ($writeToDisk) {
if (!Jaws_Utils::is_writable(JAWS_DATA . 'xml')) {
return new Jaws_Error(_t('BLOG_ERROR_WRITING_CATEGORY_ATOMFILE'));
}
$filename = basename($catAtom->Link->HRef);
$filename = substr($filename, 0, strrpos($filename, '.')) . '.rss';
$catAtom->SetLink($GLOBALS['app']->getDataURL('xml/' . $filename, false));
///FIXME we need to do more error checking over here
@file_put_contents(JAWS_DATA . 'xml/' . $filename, $catAtom->ToRSS2());
Jaws_Utils::chmod(JAWS_DATA . 'xml/' . $filename);
}
return $catAtom->ToRSS2();
}
示例5: UploadFiles
/**
* Upload Files
*
* @access public
* @param array $files $_FILES array
* @param string $dest destination directory(include end directory separator)
* @param string $allow_formats permitted file format
* @param bool $overwrite overwrite file or generate random filename
* null: random, true/false: overwrite?
* @param bool $move_files moving or only copying files. this param avail for non-uploaded files
* @param int $max_size max size of file
* @return mixed Returns uploaded files array on success or Jaws_Error/FALSE on failure
*/
static function UploadFiles($files, $dest, $allow_formats = '', $overwrite = true, $move_files = true, $max_size = null)
{
if (empty($files) || !is_array($files)) {
return false;
}
$result = array();
if (isset($files['tmp_name'])) {
$files = array($files);
}
$finfo = false;
if (extension_loaded('fileinfo')) {
$finfo = finfo_open(FILEINFO_MIME_TYPE);
// return mime type of file extension
}
$dest = rtrim($dest, "\\/") . DIRECTORY_SEPARATOR;
$allow_formats = array_filter(explode(',', $allow_formats));
foreach ($files as $key => $listFiles) {
if (!is_array($listFiles['tmp_name'])) {
$listFiles = array_map(create_function('$item', 'return array($item);'), $listFiles);
}
for ($i = 0; $i < count($listFiles['name']); ++$i) {
$file = array();
$file['name'] = $listFiles['name'][$i];
$file['tmp_name'] = $listFiles['tmp_name'][$i];
$file['size'] = $listFiles['size'][$i];
if (isset($listFiles['error'])) {
$file['error'] = $listFiles['error'][$i];
}
if (isset($file['error']) && !empty($file['error']) && $file['error'] != 4) {
return Jaws_Error::raiseError(_t('GLOBAL_ERROR_UPLOAD_' . $file['error']), __FUNCTION__);
}
if (empty($file['tmp_name'])) {
continue;
}
$file['type'] = $finfo ? finfo_file($finfo, $file['tmp_name']) : '';
$user_filename = isset($file['name']) ? $file['name'] : '';
$host_filename = strtolower(preg_replace('/[^[:alnum:]_\\.\\-]/', '', $user_filename));
// remove deny_formats extension, even double extension
$host_filename = implode('.', array_diff(array_filter(explode('.', $host_filename)), self::$deny_formats));
$fileinfo = pathinfo($host_filename);
if (isset($fileinfo['extension'])) {
if (!empty($allow_formats) && !in_array($fileinfo['extension'], $allow_formats)) {
return new Jaws_Error(_t('GLOBAL_ERROR_UPLOAD_INVALID_FORMAT', $host_filename), __FUNCTION__);
}
$fileinfo['extension'] = '.' . $fileinfo['extension'];
} else {
$fileinfo['extension'] = '';
}
if (is_null($overwrite) || empty($fileinfo['filename'])) {
$host_filename = time() . mt_rand() . $fileinfo['extension'];
} elseif (!$overwrite && file_exists($dest . $host_filename)) {
$host_filename .= $fileinfo['filename'] . '_' . time() . mt_rand() . $fileinfo['extension'];
}
$uploadfile = $dest . $host_filename;
if (is_uploaded_file($file['tmp_name'])) {
if (!move_uploaded_file($file['tmp_name'], $uploadfile)) {
return new Jaws_Error(_t('GLOBAL_ERROR_UPLOAD', $host_filename), __FUNCTION__);
}
} else {
// On windows-systems we can't rename a file to an existing destination,
// So we first delete destination file
if (file_exists($uploadfile)) {
@unlink($uploadfile);
}
$res = $move_files ? @rename($file['tmp_name'], $uploadfile) : @copy($file['tmp_name'], $uploadfile);
if (!$res) {
return new Jaws_Error(_t('GLOBAL_ERROR_UPLOAD', $host_filename), __FUNCTION__);
}
}
// Check if the file has been altered or is corrupted
if (filesize($uploadfile) != $file['size']) {
@unlink($uploadfile);
return new Jaws_Error(_t('GLOBAL_ERROR_UPLOAD_CORRUPTED', $host_filename), __FUNCTION__);
}
Jaws_Utils::chmod($uploadfile);
$result[$key][$i]['user_filename'] = $user_filename;
$result[$key][$i]['host_filename'] = $host_filename;
$result[$key][$i]['host_filetype'] = $file['type'];
$result[$key][$i]['host_filesize'] = $file['size'];
}
}
return $result;
}