/** * @return mixed */ public function getRankspaths() { $template = KunenaFactory::getTemplate(); $selected = $this->getRank(); $rankpath = $template->getRankPath(); $files1 = (array) KunenaFolder::Files(JPATH_SITE . '/' . $rankpath, false, false, false, array('index.php', 'index.html')); $files1 = (array) array_flip($files1); foreach ($files1 as $key => &$path) { $path = $rankpath . $key; } $rankpath = 'media/kunena/ranks/'; $files2 = (array) KunenaFolder::Files(JPATH_SITE . '/' . $rankpath, false, false, false, array('index.php', 'index.html')); $files2 = (array) array_flip($files2); foreach ($files2 as $key => &$path) { $path = $rankpath . $key; } $rank_images = $files1 + $files2; ksort($rank_images); $rank_list = array(); foreach ($rank_images as $file => $path) { $rank_list[] = JHtml::_('select.option', $path, $file); } $list = JHtml::_('select.genericlist', $rank_list, 'rank_image', 'class="inputbox" onchange="update_rank(this.options[selectedIndex].value);" onmousemove="update_rank(this.options[selectedIndex].value);"', 'value', 'text', isset($selected->rank_image) ? $rank_images[$selected->rank_image] : ''); return $list; }
public function compileLess($inputFile, $outputFile) { if (!class_exists('lessc')) { require_once KPATH_FRAMEWORK . '/external/lessc/lessc.php'; } // Load the cache. $cacheDir = JPATH_CACHE . '/kunena'; if (!is_dir($cacheDir)) { KunenaFolder::create($cacheDir); } $cacheFile = "{$cacheDir}/kunena.bootstrap.{$inputFile}.cache"; if (is_file($cacheFile)) { $cache = unserialize(file_get_contents($cacheFile)); } else { $cache = KPATH_MEDIA . '/less/bootstrap/' . $inputFile; } $outputFile = KPATH_MEDIA . '/css/joomla25/' . $outputFile; $less = new lessc(); //$less->setVariables($this->style_variables); $newCache = $less->cachedCompile($cache); if (!is_array($cache) || $newCache['updated'] > $cache['updated'] || !is_file($outputFile)) { $cache = serialize($newCache); KunenaFile::write($cacheFile, $cache); KunenaFile::write($outputFile, $newCache['compiled']); } }
public function getSmileyspaths() { $template = KunenaFactory::getTemplate(); $selected = $this->getSmiley(); $smileypath = $template->getSmileyPath(); $files1 = (array) KunenaFolder::Files(JPATH_SITE . '/' . $smileypath, false, false, false, array('index.php', 'index.html')); $files1 = (array) array_flip($files1); foreach ($files1 as $key => &$path) { $path = $smileypath . $key; } $smileypath = 'media/kunena/emoticons/'; $files2 = (array) KunenaFolder::Files(JPATH_SITE . '/' . $smileypath, false, false, false, array('index.php', 'index.html')); $files2 = (array) array_flip($files2); foreach ($files2 as $key => &$path) { $path = $smileypath . $key; } $smiley_images = $files1 + $files2; ksort($smiley_images); $smiley_list = array(); foreach ($smiley_images as $file => $path) { $smiley_list[] = JHtml::_('select.option', $path, $file); } $list = JHtml::_('select.genericlist', $smiley_list, 'smiley_url', 'class="inputbox" onchange="update_smiley(this.options[selectedIndex].value);" onmousemove="update_smiley(this.options[selectedIndex].value);"', 'value', 'text', !empty($selected->location) ? $smiley_images[$selected->location] : ''); return $list; }
/** * Get geshi code types. * * @return array|null */ public function getCodeTypes() { if (!$this->config->highlightcode) { return null; } $paths = array( JPATH_ROOT.'/plugins/content/geshiall/geshi/geshi', JPATH_ROOT.'/plugins/content/geshi/geshi/geshi' ); foreach ($paths as $path) { if (!is_dir($path)) { continue; } $files = KunenaFolder::files($path, ".php"); $options = array(); $options[] = JHTML::_('select.option', '', JText::_('COM_KUNENA_EDITOR_CODE_TYPE')); foreach ($files as $file) { $options[] = JHTML::_('select.option', substr($file,0,-4), substr($file,0,-4)); } $list = JHTML::_('select.genericlist', $options, 'kcodetype', 'class="kbutton form-control"' , 'value', 'text', '-1' ); return $list; } return null; }
public static function parseXmlFiles($templateBaseDir = null) { // Read the template folder to find templates if (!$templateBaseDir) { $templateBaseDir = KPATH_SITE . '/template'; } $data = self::parseXmlFile('', $templateBaseDir); if ($data) { // Guess template folder. $data->directory = preg_replace('/[^a-z0-9_]/', '', preg_replace('/\\s+/', '_', strtolower($data->name))); if (!$data->directory) { return array(); } // Template found from the root (folder cannot contain more than one template) return array('' => $data); } $templateDirs = KunenaFolder::folders($templateBaseDir); $rows = array(); // Check that the directory contains an xml file foreach ($templateDirs as $templateDir) { $data = self::parseXmlFile($templateDir, $templateBaseDir); if ($data) { $rows[$templateDir] = $data; } } ksort($rows); return $rows; }
/** * Create new re-sized version of the original image. * * @param string $file Incoming file * @param string $folder Folder for the new image. * @param string $filename Filename for the new image. * @param int $maxWidth Maximum width for the image. * @param int $maxHeight Maximum height for the image. * @param int $quality Quality for the file (1-100). * @param int $scale See available KunenaImage constants. * @param int $crop Define if you want crop the image. * * @return bool True on success. */ public static function version($file, $folder, $filename, $maxWidth = 800, $maxHeight = 800, $quality = 70, $scale = KunenaImage::SCALE_INSIDE, $crop = 0) { try { // Create target directory if it does not exist. if (!KunenaFolder::exists($folder) && !KunenaFolder::create($folder)) { return false; } // Make sure that index.html exists in the folder. KunenaFolder::createIndex($folder); $info = KunenaImage::getImageFileProperties($file); if ($info->width > $maxWidth || $info->height > $maxHeight) { // Make sure that quality is in allowed range. if ($quality < 1 || $quality > 100) { $quality = 70; } // Calculate quality for PNG. if ($info->type == IMAGETYPE_PNG) { $quality = intval(($quality - 1) / 10); } $options = array('quality' => $quality); // Resize image and copy it to temporary file. $image = new KunenaImage($file); if ($crop && $info->width > $info->height) { $image = $image->resize($info->width * $maxHeight / $info->height, $maxHeight, false, $scale); $image = $image->crop($maxWidth, $maxHeight); } elseif ($crop && $info->width < $info->height) { $image = $image->resize($maxWidth, $info->height * $maxWidth / $info->width, false, $scale); $image = $image->crop($maxWidth, $maxHeight); } else { $image = $image->resize($maxWidth, $maxHeight, false, $scale); } $temp = KunenaPath::tmpdir() . '/kunena_' . md5(rand()); $image->toFile($temp, $info->type, $options); unset($image); // Move new file to its proper location. if (!KunenaFile::move($temp, "{$folder}/{$filename}")) { unlink($temp); return false; } } else { // Copy original file to the new location. if (!KunenaFile::copy($file, "{$folder}/{$filename}")) { return false; } } } catch (Exception $e) { return false; } return true; }
/** * Set attachment file. * * Copies the attachment into proper location and makes sure that all the unset fields get properly assigned. * * @param string $source Absolute path to the upcoming attachment. * @param string $basename Filename without extension. * @param string $extension File extension. * @param bool $unlink Whether to delete the original file or not. * @param bool $overwrite If not allowed, throw exception if the file exists. * * @return bool * @throws InvalidArgumentException * @throws RuntimeException * * @since K4.0 */ public function saveFile($source, $basename = null, $extension = null, $unlink = false, $overwrite = false) { if (!is_file($source)) { throw new InvalidArgumentException(__CLASS__ . '::' . __METHOD__ . '(): Attachment file not found.'); } // Hash, size and MIME are set during saving, so let's deal with all other variables. $this->userid = is_null($this->userid) ? KunenaUserHelper::getMyself() : $this->userid; $this->folder = is_null($this->folder) ? "media/kunena/attachments/{$this->userid}" : $this->folder; $this->protected = is_null($this->protected) ? (bool) KunenaConfig::getInstance()->attachment_protection : $this->protected; if (!$this->filename_real) { $this->filename_real = $this->filename; } if (!$this->filename || $this->filename == $this->filename_real) { if (!$basename || !$extension) { throw new InvalidArgumentException(__CLASS__ . '::' . __METHOD__ . '(): Parameters $basename or $extension not provided.'); } // Find available filename. $this->filename = KunenaAttachmentHelper::getAvailableFilename($this->folder, $basename, $extension, $this->protected); } // Create target directory if it does not exist. if (!KunenaFolder::exists(JPATH_ROOT . "/{$this->folder}") && !KunenaFolder::create(JPATH_ROOT . "/{$this->folder}")) { throw new RuntimeException(JText::_('Failed to create attachment directory.')); } $destination = JPATH_ROOT . "/{$this->folder}/{$this->filename}"; // Move the file into the final location (if not already in there). if ($source != $destination) { // Create target directory if it does not exist. if (!$overwrite && is_file($destination)) { throw new RuntimeException(JText::sprintf('Attachment %s already exists.'), $this->filename_real); } if ($unlink) { @chmod($source, 0644); } $success = KunenaFile::copy($source, $destination); if (!$success) { throw new RuntimeException(JText::sprintf('COM_KUNENA_UPLOAD_ERROR_NOT_MOVED', $destination)); } KunenaPath::setPermissions($destination); if ($unlink) { unlink($source); } } return $this->save(); }
/** * Clear cached template files. */ public static function clearTemplateFiles() { // Delete all cached files. $cacheDir = JPATH_ROOT."/media/kunena/cache"; if (is_dir($cacheDir)) { KunenaFolder::delete($cacheDir); } KunenaFolder::create($cacheDir); }
/** * @return array */ function getAllImagesInGallery() { $path = JPATH_ROOT . '/media/kunena/avatars/gallery'; $galleryFolders = KunenaFolder::folders($path); $files_list = array(); $defaultGallery = KunenaFolder::files($path); $newdefaultGallery = array(); foreach ($defaultGallery as $image) { if ($image != 'index.html') { $newdefaultGallery[] = $image; } } $files_list['default'] = json_encode($newdefaultGallery); foreach ($galleryFolders as $folder) { $tmp = KunenaFolder::files($path . '/' . $folder); $newgalleryFolders = array(); foreach ($tmp as $img) { if ($img != 'index.html') { $newgalleryFolders[] = $img; } } $files_list[$folder] = json_encode($newgalleryFolders); } return $files_list; }
/** * Delete previoulsy uplaoded avatars from filesystem * * @return void */ protected function deleteOldAvatars() { if (preg_match('|^users/|', $this->me->avatar)) { // Delete old uploaded avatars: if (is_dir(KPATH_MEDIA . '/avatars/resized')) { $deletelist = KunenaFolder::folders(KPATH_MEDIA . '/avatars/resized', '.', false, true); foreach ($deletelist as $delete) { if (is_file($delete . '/' . $this->me->avatar)) { KunenaFile::delete($delete . '/' . $this->me->avatar); } } } if (is_file(KPATH_MEDIA . '/avatars/' . $this->me->avatar)) { KunenaFile::delete(KPATH_MEDIA . '/avatars/' . $this->me->avatar); } } }
function getCodeTypes() { if (!$this->config->highlightcode) { return null; } $paths = array(JPATH_ROOT . '/plugins/content/geshiall/geshi/geshi', JPATH_ROOT . '/plugins/content/geshi/geshi/geshi'); foreach ($paths as $path) { if (!is_dir($path)) { continue; } $files = KunenaFolder::files($path, ".php"); $options = array(); $options[] = JHTML::_('select.option', '', JText::_('COM_KUNENA_EDITOR_CODE_TYPE')); foreach ($files as $file) { $options[] = JHTML::_('select.option', substr($file, 0, -4), substr($file, 0, -4)); } $javascript = "document.id('helpbox').set('value', '" . JText::_('COM_KUNENA_EDITOR_HELPLINE_CODETYPE', true) . "')"; $list = JHTML::_('select.genericlist', $options, 'kcodetype"', 'class="kbutton" onmouseover="' . $javascript . '"', 'value', 'text', '-1'); return $list; } return null; }
/** * Get files from selected gallery. * * @param string $path Absolute path for the gallery. * * @return array */ protected function getGallery($path) { return KunenaFolder::files($path, $this->imageFilter); }
/** * Tries to find the extension manifest file and returns version * * @param $path $path Path to extension directory * * @return string Version number */ public function findExtensionVersion($path) { if (is_file($path)) { // Make array from the xml file $xmlfiles = array($path); } elseif (is_dir($path)) { // Get an array of all the XML files from the directory $xmlfiles = KunenaFolder::files($path, '\\.xml$', 1, true); } $version = null; if (!empty($xmlfiles)) { $installer = JInstaller::getInstance(); foreach ($xmlfiles as $file) { // Is it a valid Joomla installation manifest file? $manifest = $installer->isManifest($file); $newversion = $manifest ? (string) $manifest->version[0] : null; // We check all files just in case if there are more than one manifest file if (version_compare($newversion, $version, '>')) { $version = $newversion; } } } return $version; }
/** * Upload a file via AJAX, supports chunks and fallback to regular file upload. * * @param array $options Upload options. * * @return array Updated options. * @throws Exception|RuntimeException */ public function ajaxUpload(array $options) { static $defaults = array('completed' => false, 'filename' => null, 'size' => 0, 'mime' => null, 'hash' => null, 'chunkStart' => 0, 'chunkEnd' => 0); $options += $defaults; $config = KunenaConfig::getInstance(); $exception = null; $in = null; $out = null; $size = $bytes = 0; $outFile = null; // Look for the content type header if (isset($_SERVER['HTTP_CONTENT_TYPE'])) { $contentType = $_SERVER['HTTP_CONTENT_TYPE']; } elseif (isset($_SERVER['CONTENT_TYPE'])) { $contentType = $_SERVER['CONTENT_TYPE']; } else { $contentType = ''; } try { // Set filename for future queries. $this->filename = $options['filename']; $folder = $this->getFolder(); // Create target directory if it does not exist. if (!KunenaFolder::exists($folder) && !KunenaFolder::create($folder)) { throw new RuntimeException(JText::_('Failed to create upload directory.'), 500); } // Calculate temporary filename. $outFile = $this->getProtectedFile(); if ($options['chunkEnd'] > $options['size'] || $options['chunkStart'] > $options['chunkEnd']) { throw new RuntimeException(JText::_('COM_KUNENA_UPLOAD_ERROR_EXTRA_CHUNK'), 400); } if ($options['size'] > max($config->filesize, $config->imagesize) * 1024) { throw new RuntimeException(JText::sprintf('COM_KUNENA_UPLOAD_ERROR_SIZE_X', $this->bytes($options['size'])), 400); } if (strpos($contentType, 'multipart') !== false) { // Older WebKit browsers didn't support multi-part in HTML5. $exception = $this->checkUpload($_FILES['file']); if ($exception) { throw $exception; } $in = fopen($_FILES['file']['tmp_name'], 'rb'); } else { // Multi-part upload. $in = fopen('php://input', 'rb'); } if (!$in) { throw new RuntimeException(JText::_('Failed to open upload input stream.'), 500); } // Open temporary file. $out = fopen($outFile, !$options['chunkStart'] ? 'wb' : 'r+b'); if (!$out) { throw new RuntimeException(JText::_('Failed to open upload output stream.'), 500); } // Get current size for the file. $stat = fstat($out); if (!$stat) { throw new RuntimeException(JText::_('COM_KUNENA_UPLOAD_ERROR_STAT', $options['filename']), 500); } $size = $stat['size']; if ($options['chunkStart'] > $size) { throw new RuntimeException(JText::sprintf('Missing data chunk at location %d.', $size), 500); } fseek($out, $options['chunkStart']); while (!feof($in)) { // Set script execution time to 8 seconds in order to interrupt stalled file transfers (< 1kb/sec). // Not sure if it works, though, needs some testing. :) @set_time_limit(8); $buff = fread($in, 8192); if ($buff === false) { throw new RuntimeException(JText::_('Failed to read from upload input stream.'), 500); } $bytes = fwrite($out, $buff); if ($bytes === false) { throw new RuntimeException(JText::_('Failed to write into upload output stream.'), 500); } $size += $bytes; if ($size > max($config->filesize, $config->imagesize) * 1024) { throw new RuntimeException(JText::sprintf('COM_KUNENA_UPLOAD_ERROR_SIZE_X', $this->bytes($size)), 400); } } } catch (Exception $exception) { } // Reset script execution time. @set_time_limit(25); if ($in) { fclose($in); } if ($out) { fclose($out); } if ($exception instanceof Exception) { $this->cleanup(); throw $exception; } // Generate response. if (is_null($options['size']) && $size || $size === $options['size']) { $options['size'] = (int) $size; $options['completed'] = true; } $options['chunkStart'] = (int) $size; $options['chunkEnd'] = min($size + 1024 * 1024, $size + $this->getMaxSize(), max($size, $options['size'], is_null($options['size']) ? $this->getMaxSize() : 0)) - 1; if ($options['completed']) { $options['mime'] = KunenaFile::getMime($outFile); $options['hash'] = md5_file($outFile); } else { if ($size) { $options['mime'] = KunenaFile::getMime($outFile); } } return $options; }
function uploadFile($uploadPath, $input = 'kattachment', $filename = '', $ajax = true) { $this->resetStatus(); // create upload directory if it does not exist if (!JFolder::exists($uploadPath)) { if (!JFolder::create($uploadPath)) { $this->fail(JText::_('COM_KUNENA_UPLOAD_ERROR_CREATE_DIR')); return false; } } KunenaFolder::createIndex($uploadPath); // Get file name and validate with path type $this->fileName = JRequest::getString($input . '_name', '', 'post'); $this->fileSize = 0; $chunk = JRequest::getInt('chunk', 0); $chunks = JRequest::getInt('chunks', 0); if ($chunks && $chunk >= $chunks) { $this->error = JText::_('COM_KUNENA_UPLOAD_ERROR_EXTRA_CHUNK'); } //If uploaded by using normal form (no AJAX) if ($ajax == false || isset($_REQUEST["multipart"])) { $file = JRequest::getVar($input, null, 'files', 'array'); // File upload if (!empty($file['error'])) { // Any errors the server registered on uploading switch ($file['error']) { case 0: // UPLOAD_ERR_OK : break; case 1: // UPLOAD_ERR_INI_SIZE : // UPLOAD_ERR_INI_SIZE : case 2: // UPLOAD_ERR_FORM_SIZE : $this->fail(JText::_('COM_KUNENA_UPLOAD_ERROR_SIZE') . 'DEBUG: file[error]' . htmlspecialchars($file['error'], ENT_COMPAT, 'UTF-8')); break; case 3: // UPLOAD_ERR_PARTIAL : $this->fail(JText::_('COM_KUNENA_UPLOAD_ERROR_PARTIAL')); break; case 4: // UPLOAD_ERR_NO_FILE : $this->fail(JText::_('COM_KUNENA_UPLOAD_ERROR_NO_FILE')); break; case 5: // UPLOAD_ERR_NO_TMP_DIR : $this->fail(JText::_('COM_KUNENA_UPLOAD_ERROR_NO_TMP_DIR')); break; case 7: // UPLOAD_ERR_CANT_WRITE, PHP 5.1.0 $this->fail(JText::_('COM_KUNENA_UPLOAD_ERROR_CANT_WRITE')); break; case 8: // UPLOAD_ERR_EXTENSION, PHP 5.2.0 $this->fail(JText::_('COM_KUNENA_UPLOAD_ERROR_PHP_EXTENSION')); break; default: $this->fail(JText::_('COM_KUNENA_UPLOAD_ERROR_UNKNOWN')); } return false; } elseif (!is_uploaded_file($file['tmp_name'])) { $this->fail(JText::_('COM_KUNENA_UPLOAD_ERROR_NOT_UPLOADED')); return false; } $this->fileTemp = $file['tmp_name']; $this->fileSize = $file['size']; if (!$this->fileName) { // Need to add additonal path type check as array getVar does not $this->fileName = $file['name']; } } else { // Currently not in use: this is meant for experimental AJAX uploads // Open temp file $this->fileTemp = KunenaPath::tmpdir() . '/kunena_' . md5($this->_my->id . '/' . $this->_my->username . '/' . $this->fileName); $out = fopen($this->fileTemp, $chunk == 0 ? "wb" : "ab"); if ($out) { // Read binary input stream and append it to temp file $in = fopen("php://input", "rb"); if ($in) { while (($buff = fread($in, 8192)) != false) { fwrite($out, $buff); } } else { $this->fail(JText::_('COM_KUNENA_UPLOAD_ERROR_NO_INPUT')); } clearstatcache(); $fileInfo = fstat($out); $this->fileSize = $fileInfo['size']; fclose($out); if (!$this->error) { $this->checkFileSize($this->fileSize); } if ($chunk + 1 < $chunks) { $this->status = empty($this->error); return $this->status; } } else { $this->fail(JText::_('COM_KUNENA_UPLOAD_ERROR_CANT_WRITE')); } } // Terminate early if we already hit an error if ($this->error) { return false; } // assume the extension is false until we know its ok $extOk = false; $fileparts = $this->getValidExtension($this->validFileExts); $uploadedFileExtension = ''; if ($fileparts) { $this->_isfile = true; $extOk = true; $uploadedFileBasename = $fileparts[0]; $uploadedFileExtension = $fileparts[1]; } $fileparts = $this->getValidExtension($this->validImageExts); if ($fileparts) { $this->_isimage = true; $extOk = true; $uploadedFileBasename = $fileparts[0]; $uploadedFileExtension = $fileparts[1]; } if ($extOk == false) { $imglist = implode(', ', $this->validImageExts); $filelist = implode(', ', $this->validFileExts); if ($imglist && $filelist) { $this->fail(JText::sprintf('COM_KUNENA_UPLOAD_ERROR_EXTENSION', $imglist, $filelist)); } else { if ($imglist && !$filelist) { $this->fail(JText::sprintf('COM_KUNENA_UPLOAD_ERROR_EXTENSION_FILE', $this->_config->filetypes)); } else { if (!$imglist && $filelist) { $this->fail(JText::sprintf('COM_KUNENA_UPLOAD_ERROR_EXTENSION_IMAGE', $this->_config->imagetypes)); } else { $this->fail(JText::sprintf('COM_KUNENA_UPLOAD_ERROR_NOT_ALLOWED', $filelist)); } } } $this->not_valid_img_ext = false; return false; } // Special processing for images if ($this->_isimage) { $this->imageInfo = CKunenaImageHelper::getProperties($this->fileTemp); // Let see if we need to check the MIME type if ($this->_config->checkmimetypes) { // check against whitelist of MIME types $validFileTypes = explode(",", $this->_config->imagemimetypes); //if the temp file does not have a width or a height, or it has a non ok MIME, return if (!is_int($this->imageInfo->width) || !is_int($this->imageInfo->height) || !in_array($this->imageInfo->mime, $validFileTypes)) { $this->fail(JText::sprintf('COM_KUNENA_UPLOAD_ERROR_MIME', $this->imageInfo->mime, $this->_config->imagetypes)); return false; } } // If image is not inside allowed size limits, resize it if ($this->fileSize > $this->imagesize || $this->imageInfo->width > $this->imagewidth || $this->imageInfo->height > $this->imageheight) { $options = array('quality' => $this->imagequality); $imageRaw = new CKunenaImage($this->fileTemp); if ($imageRaw->getError()) { $this->fail(JText::_($imageRaw->getError())); return false; } $image = $imageRaw->resize($this->imagewidth, $this->imageheight); $type = $imageRaw->getType(); unset($imageRaw); $image->toFile($this->fileTemp, $type, $options); clearstatcache(); // Re-calculate physical file size: image has been shrunk $stat = stat($this->fileTemp); if (!$stat) { $this->fail(JText::_('COM_KUNENA_UPLOAD_ERROR_STAT', htmlspecialchars($this->fileTemp, ENT_COMPAT, 'UTF-8'))); return false; } $this->fileSize = $stat['size']; } } $this->checkFileSize($this->fileSize); // Check again for error and terminate early if we already hit an error if ($this->error) { return false; } // Populate hash, file size and other info // Get a hash value from the file $this->fileHash = md5_file($this->fileTemp); // Override filename if given in the parameter if ($filename) { $uploadedFileBasename = $filename; } $uploadedFileBasename = KunenaFile::makeSafe($uploadedFileBasename); if (empty($uploadedFileBasename)) { $uploadedFileBasename = 'h' . substr($this->fileHash, 2, 7); } // Rename file if there is already one with the same name $newFileName = $uploadedFileBasename . "." . $uploadedFileExtension; $newFileName = preg_replace('/[[:space:]]/', '', $newFileName); $uploadedFileBasename = preg_replace('/[[:space:]]/', '', $uploadedFileBasename); if (file_exists($uploadPath . '/' . $newFileName)) { $newFileName = $uploadedFileBasename . "." . $uploadedFileExtension; for ($i = 2; file_exists("{$uploadPath}/{$newFileName}"); $i++) { $newFileName = $uploadedFileBasename . "-{$i}." . $uploadedFileExtension; } } $this->fileName = $newFileName; // All the processing is complete - now we need to move the file(s) into the final location @chmod($this->fileTemp, 0644); if (!JFile::copy($this->fileTemp, $uploadPath . '/' . $this->fileName)) { $this->fail(JText::sprintf('COM_KUNENA_UPLOAD_ERROR_NOT_MOVED', htmlspecialchars($uploadPath . '/' . $this->fileName, ENT_COMPAT, 'UTF-8'))); unlink($this->fileTemp); return false; } unlink($this->fileTemp); JPath::setPermissions($uploadPath . '/' . $this->fileName); $this->ready = true; return $this->status = true; }
/** * */ function uninstall() { $cid = $this->app->input->get('cid', array(), 'method', 'array'); $id = array_shift($cid); $template = $id; if (!JSession::checkToken('post')) { $this->app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error'); $this->setRedirect(KunenaRoute::_($this->baseurl, false)); return; } // Initialize variables $otemplate = KunenaTemplateHelper::parseXmlFile($id); if (!$otemplate) { $this->app->enqueueMessage(JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_TEMPLATE_NOT_SPECIFIED'), 'error'); $this->setRedirect(KunenaRoute::_($this->baseurl, false)); return; } if (in_array($id, $this->locked)) { $this->app->enqueueMessage(JText::sprintf('COM_KUNENA_A_CTRL_TEMPLATES_ERROR_UNINSTALL_SYSTEM_TEMPLATE', $otemplate->name), 'error'); $this->setRedirect(KunenaRoute::_($this->baseurl, false)); return; } if (KunenaTemplateHelper::isDefault($template)) { $this->app->enqueueMessage(JText::sprintf('COM_KUNENA_A_CTRL_TEMPLATES_ERROR_UNINSTALL_DEFAULT_TEMPLATE', $otemplate->name), 'error'); $this->setRedirect(KunenaRoute::_($this->baseurl, false)); return; } $tpl = KPATH_SITE . '/template/' . $template; // Delete the template directory if (is_dir($tpl)) { $retval = KunenaFolder::delete($tpl); // Clear all cache, just in case. KunenaCacheHelper::clearAll(); $this->app->enqueueMessage(JText::sprintf('COM_KUNENA_A_TEMPLATE_MANAGER_UNINSTALL_SUCCESS', $id)); } else { $this->app->enqueueMessage(JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_TEMPLATE') . ' ' . JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_UNINSTALL') . ': ' . JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_DIR_NOT_EXIST')); $retval = false; } $this->setRedirect(KunenaRoute::_($this->baseurl, false)); }
public static function version($file, $newpath, $newfile, $maxwidth = 800, $maxheight = 800, $quality = 70, $scale = CKunenaImage::SCALE_INSIDE) { require_once KPATH_SITE . '/lib/kunena.file.class.php'; // create upload directory if it does not exist $imageinfo = self::getProperties($file); if (!$imageinfo) { return false; } if (!JFolder::exists($newpath)) { if (!JFolder::create($newpath)) { return false; } } KunenaFolder::createIndex($newpath); if ($imageinfo->width > $maxwidth || $imageinfo->height > $maxheight) { $image = new CKunenaImage($file); if ($image->getError()) { return false; } if ($quality < 1 || $quality > 100) { $quality = 70; } $options = array('quality' => $quality); $image = $image->resize($maxwidth, $maxheight, true, $scale); $type = $image->getType(); $temp = KunenaPath::tmpdir() . '/kunena_' . md5(rand()); $image->toFile($temp, $type, $options); unset($image); if (!KunenaFile::move($temp, $newpath . '/' . $newfile)) { unlink($temp); return false; } } else { if (!KunenaFile::copy($file, $newpath . '/' . $newfile)) { return false; } } return true; }
function compileLess($inputFile, $outputFile) { if (!class_exists('lessc')) { require_once KPATH_FRAMEWORK . '/external/lessc/lessc.php'; } // Load the cache. $cacheDir = JPATH_CACHE . '/kunena'; if (!is_dir($cacheDir)) { KunenaFolder::create($cacheDir); } $cacheFile = "{$cacheDir}/kunena.{$this->name}.{$inputFile}.cache"; if (is_file($cacheFile)) { $cache = unserialize(file_get_contents($cacheFile)); } else { $cache = JPATH_SITE . '/' . $this->getFile($inputFile, false, 'less'); } $outputDir = KPATH_MEDIA . "/cache/{$this->name}/css"; if (!is_dir($outputDir)) { KunenaFolder::create($outputDir); } $outputFile = "{$outputDir}/{$outputFile}"; $less = new lessc(); $class = $this; $less->registerFunction('url', function ($arg) use($class) { list($type, $q, $values) = $arg; $value = reset($values); return "url({$q}{$class->getFile($value, true, 'media', 'media/kunena')}{$q})"; }); $less->setVariables($this->style_variables); $newCache = $less->cachedCompile($cache); if (!is_array($cache) || $newCache['updated'] > $cache['updated'] || !is_file($outputFile)) { $cache = serialize($newCache); KunenaFile::write($cacheFile, $cache); KunenaFile::write($outputFile, $newCache['compiled']); } }
/** * @return array */ public function getAdminOptions() { $category = $this->getAdminCategory(); if (!$category) { return false; } $catList = array(); $catList[] = JHtml::_('select.option', 0, JText::_('COM_KUNENA_TOPLEVEL')); // make a standard yes/no list $published = array(); $published[] = JHtml::_('select.option', 1, JText::_('COM_KUNENA_PUBLISHED')); $published[] = JHtml::_('select.option', 0, JText::_('COM_KUNENA_UNPUBLISHED')); // make a standard yes/no list $yesno = array(); $yesno[] = JHtml::_('select.option', 0, JText::_('COM_KUNENA_NO')); $yesno[] = JHtml::_('select.option', 1, JText::_('COM_KUNENA_YES')); // Anonymous posts default $post_anonymous = array(); $post_anonymous[] = JHtml::_('select.option', '0', JText::_('COM_KUNENA_CATEGORY_ANONYMOUS_X_REG')); $post_anonymous[] = JHtml::_('select.option', '1', JText::_('COM_KUNENA_CATEGORY_ANONYMOUS_X_ANO')); $cat_params = array(); $cat_params['ordering'] = 'ordering'; $cat_params['toplevel'] = JText::_('COM_KUNENA_TOPLEVEL'); $cat_params['sections'] = 1; $cat_params['unpublished'] = 1; $cat_params['catid'] = $category->id; $cat_params['action'] = 'admin'; $channels_params = array(); $channels_params['catid'] = $category->id; $channels_params['action'] = 'admin'; $channels_options = array(); $channels_options[] = JHtml::_('select.option', 'THIS', JText::_('COM_KUNENA_CATEGORY_CHANNELS_OPTION_THIS')); $channels_options[] = JHtml::_('select.option', 'CHILDREN', JText::_('COM_KUNENA_CATEGORY_CHANNELS_OPTION_CHILDREN')); if (empty($category->channels)) { $category->channels = 'THIS'; } $topic_ordering_options = array(); $topic_ordering_options[] = JHtml::_('select.option', 'lastpost', JText::_('COM_KUNENA_CATEGORY_TOPIC_ORDERING_OPTION_LASTPOST')); $topic_ordering_options[] = JHtml::_('select.option', 'creation', JText::_('COM_KUNENA_CATEGORY_TOPIC_ORDERING_OPTION_CREATION')); $topic_ordering_options[] = JHtml::_('select.option', 'alpha', JText::_('COM_KUNENA_CATEGORY_TOPIC_ORDERING_OPTION_ALPHA')); $aliases = array_keys($category->getAliases()); $lists = array(); $lists['accesstypes'] = KunenaAccess::getInstance()->getAccessTypesList($category); $lists['accesslists'] = KunenaAccess::getInstance()->getAccessOptions($category); $lists['categories'] = JHtml::_('kunenaforum.categorylist', 'parent_id', 0, null, $cat_params, 'class="inputbox"', 'value', 'text', $category->parent_id); $lists['channels'] = JHtml::_('kunenaforum.categorylist', 'channels[]', 0, $channels_options, $channels_params, 'class="inputbox" multiple="multiple"', 'value', 'text', explode(',', $category->channels)); $lists['aliases'] = $aliases ? JHtml::_('kunenaforum.checklist', 'aliases', $aliases, true) : null; $lists['published'] = JHtml::_('select.genericlist', $published, 'published', 'class="inputbox"', 'value', 'text', $category->published); $lists['forumLocked'] = JHtml::_('select.genericlist', $yesno, 'locked', 'class="inputbox" size="1"', 'value', 'text', $category->locked); $lists['forumReview'] = JHtml::_('select.genericlist', $yesno, 'review', 'class="inputbox" size="1"', 'value', 'text', $category->review); $lists['allow_polls'] = JHtml::_('select.genericlist', $yesno, 'allow_polls', 'class="inputbox" size="1"', 'value', 'text', $category->allow_polls); $lists['allow_anonymous'] = JHtml::_('select.genericlist', $yesno, 'allow_anonymous', 'class="inputbox" size="1"', 'value', 'text', $category->allow_anonymous); $lists['post_anonymous'] = JHtml::_('select.genericlist', $post_anonymous, 'post_anonymous', 'class="inputbox" size="1"', 'value', 'text', $category->post_anonymous); $lists['topic_ordering'] = JHtml::_('select.genericlist', $topic_ordering_options, 'topic_ordering', 'class="inputbox" size="1"', 'value', 'text', $category->topic_ordering); $options = array(); $options[0] = JHtml::_('select.option', '0', JText::_('COM_KUNENA_A_CATEGORY_CFG_OPTION_NEVER')); $options[1] = JHtml::_('select.option', '1', JText::_('COM_KUNENA_A_CATEGORY_CFG_OPTION_SECTION')); $options[2] = JHtml::_('select.option', '2', JText::_('COM_KUNENA_A_CATEGORY_CFG_OPTION_CATEGORY')); $options[3] = JHtml::_('select.option', '3', JText::_('COM_KUNENA_A_CATEGORY_CFG_OPTION_SUBCATEGORY')); $lists['display_parent'] = JHtml::_('select.genericlist', $options, 'params[display][index][parent]', 'class="inputbox" size="1"', 'value', 'text', $category->params->get('display.index.parent', '3')); unset($options[1]); $lists['display_children'] = JHtml::_('select.genericlist', $options, 'params[display][index][children]', 'class="inputbox" size="1"', 'value', 'text', $category->params->get('display.index.children', '3')); $topicicons = array(); $topiciconslist = KunenaFolder::folders(JPATH_ROOT . '/media/kunena/topic_icons'); foreach ($topiciconslist as $icon) { $topicicons[] = JHtml::_('select.option', $icon, $icon); } $lists['category_iconset'] = JHtml::_('select.genericlist', $topicicons, 'iconset', 'class="inputbox" size="1"', 'value', 'text', $category->iconset); return $lists; }