Ejemplo n.º 1
0
	/**
	 * Method to determine if script owns the path.
	 *
	 * @param   string  $path  Path to check ownership.
	 *
	 * @return  boolean  True if the php script owns the path passed.
	 */
	public static function isOwner($path)
	{
		if (!self::$owner)
		{
			$dir = JFactory::getConfig()->get('tmp_path');
			$tmp = 'jj'.md5(mt_rand());

			$test = $dir . '/' . $tmp;

			// Create the test file
			$content = 'test';
			$success = KunenaFile::write($test, $content, false);

			if (!$success)
			{
				return false;
			}

			self::$owner = fileowner($test);

			// Delete the test file
			KunenaFile::delete($test);
		}

		// Test ownership
		return (self::$owner == fileowner($path));
	}
Ejemplo n.º 2
0
 /**
  * @internal
  * @since  K4.0
  */
 protected function deleteFile()
 {
     if (self::$_directory != substr($this->folder, 0, strlen(self::$_directory))) {
         return;
     }
     $path = JPATH_ROOT . "/{$this->folder}";
     $filename = $path . '/' . $this->filename;
     if (is_file($filename)) {
         KunenaFile::delete($filename);
     }
     $filename = $path . '/raw/' . $this->filename;
     if (is_file($filename)) {
         KunenaFile::delete($filename);
     }
     $filename = $path . '/thumb/' . $this->filename;
     if (is_file($filename)) {
         KunenaFile::delete($filename);
     }
 }
Ejemplo n.º 3
0
 /**
  * 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);
         }
     }
 }
Ejemplo n.º 4
0
 /**
  *
  */
 public function install()
 {
     $tmp = JPATH_ROOT . '/tmp/';
     $tmp_kunena = JPATH_ROOT . '/tmp/kinstall/';
     $dest = KPATH_SITE . '/template/';
     $file = $this->app->input->files->get('install_package', null, 'raw');
     if (!JSession::checkToken('post')) {
         $this->app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error');
         $this->setRedirect(KunenaRoute::_($this->baseurl, false));
         return;
     }
     if (empty($file['tmp_name']) || !is_uploaded_file($file['tmp_name']) || !empty($file['error'])) {
         $this->app->enqueueMessage(JText::sprintf('COM_KUNENA_A_TEMPLATE_MANAGER_INSTALL_EXTRACT_MISSING', $this->escape($file['name'])), 'notice');
     } else {
         $success = KunenaFile::upload($file['tmp_name'], $tmp . $file['name'], false, true);
         if ($success) {
             try {
                 JArchive::extract($tmp . $file['name'], $tmp_kunena);
             } catch (Exception $e) {
                 $this->app->enqueueMessage(JText::sprintf('COM_KUNENA_A_TEMPLATE_MANAGER_INSTALL_EXTRACT_FAILED', $this->escape($file['name'])), 'notice');
             }
         }
         if (is_dir($tmp_kunena)) {
             $templates = KunenaTemplateHelper::parseXmlFiles($tmp_kunena);
             if (!empty($templates)) {
                 foreach ($templates as $template) {
                     // Never overwrite locked templates
                     if (in_array($template->directory, $this->locked)) {
                         continue;
                     }
                     if (is_dir($dest . $template->directory)) {
                         if (is_file($dest . $template->directory . '/params.ini')) {
                             if (is_file($tmp_kunena . $template->sourcedir . '/params.ini')) {
                                 KunenaFile::delete($tmp_kunena . $template->sourcedir . '/params.ini');
                             }
                             KunenaFile::move($dest . $template->directory . '/params.ini', $tmp_kunena . $template->sourcedir . '/params.ini');
                         }
                         KunenaFolder::delete($dest . $template->directory);
                     }
                     $success = KunenaFolder::move($tmp_kunena . $template->sourcedir, $dest . $template->directory);
                     if ($success !== true) {
                         $this->app->enqueueMessage(JText::sprintf('COM_KUNENA_A_TEMPLATE_MANAGER_INSTALL_FAILED', $template->directory), 'notice');
                     } else {
                         $this->app->enqueueMessage(JText::sprintf('COM_KUNENA_A_TEMPLATE_MANAGER_INSTALL_SUCCESS', $template->directory));
                     }
                 }
                 // Delete the tmp install directory
                 if (is_dir($tmp_kunena)) {
                     KunenaFolder::delete($tmp_kunena);
                 }
                 // Clear all cache, just in case.
                 KunenaCacheHelper::clearAll();
             } else {
                 $this->app->enqueueMessage(JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_TEMPLATE_MISSING_FILE'), 'error');
             }
         } 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'), 'error');
         }
     }
     $this->setRedirect(KunenaRoute::_($this->baseurl, false));
 }