<?php

/**
 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 * @package clearFusionCMS
 * @copyright Copyright (c) 2012 - 2017 clearFusionCMS. All rights reserved.
 * @link http://clearfusioncms.com
 */

/**
 * cfBackendBrowsectntAction Class
 *
 * The action class to show the content tree for embedding in WYSIWYG editor.
 *
 * @package clearFusionCMS
 */
class cfBackendBrowsectntAction extends cfBackendControllerAction {
	/**
	 * Process the page.
	 */
	function process() {
		$this->testPermission('cfContent.documents');

		$params = $this->request->getParam('*', array());
		if(count($params) == 1 && preg_match('/^[a-z0-9_]+$/', $params[0]))
			$editor = $params[0];
		else
			$editor = '';

		$rootTree = new cfContentTree('cfDocumentBrowseTreeView', new cfContent($this->db, clearFusionCMS::getSite()), null, null, null, false);

		if(!empty($editor))
			$this->tpl->getCodeBuffer()->bufferHeadJS("system/modules/$editor/browsedocs.js");

		$this->response
			->setBody($this->tpl->parseDocument('managerDocBrowser',
				'backend_' . $this->request->getSelf(),
				array('page_title' => __('Document Browser', 'cfBackend'),
					'content' => $rootTree->render($this->tpl->getCodeBuffer())
				)))
			->sendResponse();
	}
}
