ModuleCode: themedownload 0.04
ModuleDescription: Download Themes.
Directory: /modules/themedownload/admin
File: /modules/themedownload/admin/allow.php
<?php
include dirname(__FILE__).'/../../../include/cp_header.php';
/* check theme */
if (false === isset($_GET["theme"])) {
redirect_header(XOOPS_URL."/modules/themedownload/admin/index.php");
}
$themehandler = xoops_getmodulehandler("theme", "themedownload");
/* @var $themehandler themedownloadthemehandler */
$theme = $themehandler->get($_GET["theme"]);
if (false === isset($theme)) {
redirect_header(XOOPS_URL."/modules/themedownload/admin/index.php");
}
/* check download */
if (false === $theme->is_downloaded()) {
redirect_header(XOOPS_URL."/modules/themedownload/admin/index.php");
}
/* check allow */
if (true === $theme->is_allow()) {
redirect_header(XOOPS_URL."/modules/themedownload/admin/index.php");
}
if ("POST" === $_SERVER['REQUEST_METHOD']) {
$themehandler->allow($theme);
redirect_header(XOOPS_URL."/modules/themedownload/admin/index.php");
}
xoops_cp_header();
require_once XOOPS_ROOT_PATH . '/class/template.php';
require_once XOOPS_ROOT_PATH . '/class/theme.php';
require_once XOOPS_ROOT_PATH . '/class/theme_blocks.php';
$xoopsThemeFactory =& new xos_opal_ThemeFactory();
$xoTheme =& $xoopsThemeFactory->createInstance();
$xoopsTpl =& $xoTheme->template;
/* @var $xoopsTpl XoopsTpl */
$xoopsTpl->assign_by_ref("theme", $theme);
$xoopsTpl->display("db:themedownload_admin_allow.html");
xoops_confirm(array(), "", "Are you sure want to allow?");
xoops_cp_footer();
?>
File: /modules/themedownload/admin/delete.php
<?php
include dirname(__FILE__).'/../../../include/cp_header.php';
/* check theme */
if (false === isset($_GET["theme"])) {
redirect_header(XOOPS_URL."/modules/themedownload/admin/index.php");
}
$themehandler = xoops_getmodulehandler("theme", "themedownload");
/* @var $themehandler themedownloadthemehandler */
$theme = $themehandler->get($_GET["theme"]);
if (false === isset($theme)) {
redirect_header(XOOPS_URL."/modules/themedownload/admin/index.php");
}
/* check download */
if (false === $theme->is_downloaded()) {
redirect_header(XOOPS_URL."/modules/themedownload/admin/index.php");
}
if ("POST" === $_SERVER['REQUEST_METHOD']) {
$themehandler->delete($theme);
redirect_header(XOOPS_URL."/modules/themedownload/admin/index.php");
}
xoops_cp_header();
require_once XOOPS_ROOT_PATH . '/class/template.php';
require_once XOOPS_ROOT_PATH . '/class/theme.php';
require_once XOOPS_ROOT_PATH . '/class/theme_blocks.php';
$xoopsThemeFactory =& new xos_opal_ThemeFactory();
$xoTheme =& $xoopsThemeFactory->createInstance();
$xoopsTpl =& $xoTheme->template;
/* @var $xoopsTpl XoopsTpl */
$xoopsTpl->assign_by_ref("theme", $theme);
$xoopsTpl->display("db:themedownload_admin_delete.html");
xoops_confirm(array(), "", "Are you sure want to delete?");
xoops_cp_footer();
?>
File: /modules/themedownload/admin/disallow.php
<?php
include dirname(__FILE__).'/../../../include/cp_header.php';
/* check theme */
if (false === isset($_GET["theme"])) {
redirect_header(XOOPS_URL."/modules/themedownload/admin/index.php");
}
$themehandler = xoops_getmodulehandler("theme", "themedownload");
/* @var $themehandler themedownloadthemehandler */
$theme = $themehandler->get($_GET["theme"]);
if (false === isset($theme)) {
redirect_header(XOOPS_URL."/modules/themedownload/admin/index.php");
}
/* check download */
if (false === $theme->is_downloaded()) {
redirect_header(XOOPS_URL."/modules/themedownload/admin/index.php");
}
/* check allow */
if (false === $theme->is_allow()) {
redirect_header(XOOPS_URL."/modules/themedownload/admin/index.php");
}
if ("POST" === $_SERVER['REQUEST_METHOD']) {
$themehandler->disallow($theme);
redirect_header(XOOPS_URL."/modules/themedownload/admin/index.php");
}
xoops_cp_header();
require_once XOOPS_ROOT_PATH . '/class/template.php';
require_once XOOPS_ROOT_PATH . '/class/theme.php';
require_once XOOPS_ROOT_PATH . '/class/theme_blocks.php';
$xoopsThemeFactory =& new xos_opal_ThemeFactory();
$xoTheme =& $xoopsThemeFactory->createInstance();
$xoopsTpl =& $xoTheme->template;
/* @var $xoopsTpl XoopsTpl */
$xoopsTpl->assign_by_ref("theme", $theme);
$xoopsTpl->display("db:themedownload_admin_disallow.html");
xoops_confirm(array(), "", "Are you sure want to disallow?");
xoops_cp_footer();
?>
File: /modules/themedownload/admin/download.php
<?php
include dirname(__FILE__).'/../../../include/cp_header.php';
/* prepare environment */
$themehandler = xoops_getmodulehandler("theme", "themedownload");
/* @var $themehandler themedownloadthemehandler */
if (false === $themehandler->prepare_environment()) {
redirect_header(XOOPS_URL."/modules/themedownload/admin/help.php");
}
/* check theme */
if (false === isset($_GET["theme"])) {
redirect_header(XOOPS_URL."/modules/themedownload/admin/index.php");
}
$theme = $themehandler->get($_GET["theme"]);
if (false === isset($theme)) {
redirect_header(XOOPS_URL."/modules/themedownload/admin/index.php");
}
if (true === $theme->is_downloaded()) {
redirect_header(XOOPS_URL."/modules/themedownload/admin/index.php");
}
if ("POST" === $_SERVER['REQUEST_METHOD']) {
$themehandler->download($theme);
if ($theme->get_md5() === $theme->get_filemd5()) {
$zipentries = $themehandler->extract($theme);
}
}
xoops_cp_header();
require_once XOOPS_ROOT_PATH . '/class/template.php';
require_once XOOPS_ROOT_PATH . '/class/theme.php';
require_once XOOPS_ROOT_PATH . '/class/theme_blocks.php';
$xoopsThemeFactory =& new xos_opal_ThemeFactory();
$xoTheme =& $xoopsThemeFactory->createInstance();
$xoopsTpl =& $xoTheme->template;
/* @var $xoopsTpl XoopsTpl */
$xoopsTpl->assign_by_ref("theme", $theme);
if ("POST" === $_SERVER['REQUEST_METHOD']) {
$xoopsTpl->assign_by_ref("zipentries", $zipentries);
}
$xoopsTpl->display("db:themedownload_admin_download.html");
if ("POST" !== $_SERVER['REQUEST_METHOD']) {
xoops_confirm(array(), "", "Are you sure want to download?");
}
xoops_cp_footer();
?>
File: /modules/themedownload/admin/help.php
<?php
include dirname(__FILE__).'/../../../include/cp_header.php';
xoops_cp_header();
require_once XOOPS_ROOT_PATH . '/class/template.php';
require_once XOOPS_ROOT_PATH . '/class/theme.php';
require_once XOOPS_ROOT_PATH . '/class/theme_blocks.php';
$xoopsThemeFactory =& new xos_opal_ThemeFactory();
$xoTheme =& $xoopsThemeFactory->createInstance();
$xoopsTpl =& $xoTheme->template;
$xoopsTpl->display("db:themedownload_admin_help.html");
xoops_cp_footer();
?>
File: /modules/themedownload/admin/index.php
<?php
include dirname(__FILE__).'/../../../include/cp_header.php';
xoops_cp_header();
require_once XOOPS_ROOT_PATH.'/class/template.php';
require_once XOOPS_ROOT_PATH.'/class/theme.php';
require_once XOOPS_ROOT_PATH.'/class/theme_blocks.php';
$xoopsThemeFactory =& new xos_opal_ThemeFactory();
$xoTheme =& $xoopsThemeFactory->createInstance();
$xoopsTpl =& $xoTheme->template;
/* @var $xoopsTpl XoopsTpl */
$themehandler = xoops_getmodulehandler("theme", "themedownload");
/* @var $themehandler themedownloadthemehandler */
$xoopsTpl->assign_by_ref("themes", $themehandler->getAll());
$xoopsTpl->display("db:themedownload_admin_index.html");
xoops_cp_footer();
?>
Directory: /modules/themedownload/class
File: /modules/themedownload/class/theme.php
<?php
if (false === defined("XOOPS_ROOT_PATH")) {
exit();
}
define("THEMEDOWNLOAD_THEME_SET_ALLOWED", "theme_set_allowed");
final class themedownloadtheme {
private $name;
private $preview;
private $url;
private $zipbase;
private $md5;
/* override */
public function __construct($name, $preview, $url, $zipbase, $md5) {
$this->name = strval($name);
$this->preview = strval($preview);
$this->url = strval($url);
$this->zipbase = strval($zipbase);
$this->md5 = strval($md5);
return;
}
private function __clone () {
return;
}
/* getter / setter */
public function get_name () {
return $this->name;
}
public function get_preview () {
return $this->preview;
}
public function get_url () {
return $this->url;
}
public function get_zipbase () {
return $this->zipbase;
}
public function get_md5 () {
return $this->md5;
}
public function get_downloadzip () {
$themehandler = xoops_getmodulehandler("theme", "themedownload");
/* @var $themehandler themedownloadthemehandler */
return $themehandler->get_downloadzipdir()."/".$this->name.".zip";
}
public function get_themedir () {
$themehandler = xoops_getmodulehandler("theme", "themedownload");
/* @var $themehandler themedownloadthemehandler */
return $themehandler->get_themedir()."/".$this->name;
}
public function is_downloaded () {
return true === file_exists($this->get_downloadzip());
}
public function get_filemd5 () {
return md5_file($this->get_downloadzip());
}
public function is_allow () {
global $xoopsConfig;
return true === in_array($this->name,
$xoopsConfig[THEMEDOWNLOAD_THEME_SET_ALLOWED]);
}
}
final class themedownloadthemehandler {
private $themes;
/* override */
public function __construct() {
return;
}
private function __clone () {
return;
}
/* cache */
private function ensure_themes () {
if (true === isset($this->themes)) {
return;
}
$this->themes = array();
$themesdata = require(dirname(__FILE__)."/../include/themesdata.php");
foreach ($themesdata as $themedata) {
$this->themes[$themedata["name"]] = new themedownloadtheme(
$themedata["name"], $themedata["preview"], $themedata["url"],
$themedata["zipbase"], $themedata["md5"]);
}
return;
}
/* operation */
/**
* @return themedownloadtheme
*/
public function get ($name) {
settype($name, "string");
$this->ensure_themes();
if (false === array_key_exists($name, $this->themes)) {
return;
}
return $this->themes[$name];
}
public function getAll () {
$this->ensure_themes();
return $this->themes;
}
public function get_downloadzipdir () {
return XOOPS_UPLOAD_PATH."/themedownload";
}
public function get_themedir () {
return XOOPS_ROOT_PATH."/themes";
}
private function rmdir ($dir) {
if (XOOPS_ROOT_PATH !== substr($dir, 0, strlen(XOOPS_ROOT_PATH))) {
return;
}
if (true === is_dir($dir)) {
foreach(scandir($dir) as $filename) {
switch ($filename) {
case ".":
case "..":
break;
default:
$filepath = $dir."/".$filename;
if (true === is_dir($filepath)) {
$this->rmdir($filepath);
} else {
unlink($filepath);
}
break;
}
}
rmdir($dir);
}
return;
}
/* operation */
public function delete (themedownloadtheme $theme) {
$this->ensure_themes();
if (false === in_array($theme, $this->themes)) {
return;
}
if (false === $theme->is_downloaded()) {
return;
}
unlink($theme->get_downloadzip());
$this->rmdir($theme->get_themedir());
return;
}
public function download (themedownloadtheme $theme) {
$this->ensure_themes();
if (false === in_array($theme, $this->themes)) {
return;
}
if (true === $theme->is_downloaded()) {
return;
}
if (false === is_dir($this->get_downloadzipdir())) {
mkdir($this->get_downloadzipdir());
}
$filehandle = fopen($theme->get_downloadzip(), "w");
$curlhandle = curl_init();
curl_setopt($curlhandle, CURLOPT_FILE, $filehandle);
curl_setopt($curlhandle, CURLOPT_URL, $theme->get_url());
curl_exec($curlhandle);
curl_close($curlhandle);
fclose($filehandle);
return;
}
public function extract (themedownloadtheme $theme) {
if (false === is_dir($this->get_themedir())) {
mkdir($this->get_themedir());
}
if (false === is_dir($theme->get_themedir())) {
mkdir($theme->get_themedir());
}
$zipentries = array();
$ziphandle = zip_open($theme->get_downloadzip());
while (false !== ($zipentry = zip_read($ziphandle))) {
$zipentryname = zip_entry_name($zipentry);
$zipentryfilesize = zip_entry_filesize($zipentry);
$filepath = "";
if($theme->get_zipbase() ===
substr($zipentryname, 0, strlen($theme->get_zipbase()))) {
$filepath = $theme->get_themedir()."/".
substr($zipentryname, strlen($theme->get_zipbase()));
if ("/" === substr($zipentryname, strlen($zipentryname) - 1)) {
if (false === is_dir($filepath)) {
mkdir($filepath);
}
} else {
if (true === zip_entry_open($ziphandle, $zipentry, "r")) {
if (false === is_dir(dirname($filepath))) {
mkdir(dirname($filepath));
}
file_put_contents($filepath,
zip_entry_read($zipentry, $zipentryfilesize));
zip_entry_close($zipentry);
}
}
}
$zipentries[] = array(
"name" => $zipentryname,
"filesize" => $zipentryfilesize,
"compressedsize" => zip_entry_compressedsize($zipentry),
"compressionmethod" => zip_entry_compressionmethod($zipentry),
"filepath" => $filepath,
);
}
zip_close($ziphandle);
return $zipentries;
}
public function prepare_environment () {
if (false === extension_loaded("zip")) {
$prefix = (PHP_SHLIB_SUFFIX === 'dll') ? 'php_' : '';
dl($prefix.'zip.'.PHP_SHLIB_SUFFIX);
}
if (false === extension_loaded("zip")) {
return false;
}
return true;
}
public function allow (themedownloadtheme $theme) {
$this->ensure_themes();
if (false === in_array($theme, $this->themes)) {
return;
}
if (false === $theme->is_downloaded()) {
return;
}
if (true === $theme->is_allow()) {
return;
}
$confighandler =& xoops_gethandler('config');
/* @var $confighandler XoopsConfigHandler */
$criteria = new Criteria("conf_name", THEMEDOWNLOAD_THEME_SET_ALLOWED);
list($config) = $confighandler->getConfigs($criteria);
/* @var $config XoopsConfigItem */
$value = $config->getConfValueForOutput();
$value = array_merge($value, array($theme->get_name()));
$config->setConfValueForInput($value);
$confighandler->insertConfig($config);
return;
}
public function disallow (themedownloadtheme $theme) {
$this->ensure_themes();
if (false === in_array($theme, $this->themes)) {
return;
}
if (false === $theme->is_downloaded()) {
return;
}
if (false === $theme->is_allow()) {
return;
}
$confighandler =& xoops_gethandler('config');
/* @var $confighandler XoopsConfigHandler */
$criteria = new Criteria("conf_name", THEMEDOWNLOAD_THEME_SET_ALLOWED);
list($config) = $confighandler->getConfigs($criteria);
/* @var $config XoopsConfigItem */
$value = $config->getConfValueForOutput();
$value = array_diff($value, array($theme->get_name()));
$config->setConfValueForInput($value);
$confighandler->insertConfig($config);
return;
}
}
?>
Directory: /modules/themedownload/include
Directory: /modules/themedownload/templates
File: /modules/themedownload/templates/themedownload_admin_allow.html
<{strip}>
<table>
<tr>
<th>
Name
</th>
<td class="<{cycle values="even,odd"}>">
<{$theme->get_name()}>
</td>
</tr>
<tr>
<th>
Preview
</th>
<td class="<{cycle values="even,odd"}>">
<a href="<{$theme->get_preview()}>" target="_blank">
Preview
</a>
</td>
</tr>
<tr>
<th>
MD5
</th>
<td class="<{cycle values="even,odd"}>">
<{$theme->get_md5()}>
</td>
</tr>
</table>
<{/strip}>
File: /modules/themedownload/templates/themedownload_admin_delete.html
<{strip}>
<table>
<tr>
<th>
Name
</th>
<td class="<{cycle values="even,odd"}>">
<{$theme->get_name()}>
</td>
</tr>
<tr>
<th>
Preview
</th>
<td class="<{cycle values="even,odd"}>">
<a href="<{$theme->get_preview()}>" target="_blank">
Preview
</a>
</td>
</tr>
<tr>
<th>
MD5
</th>
<td class="<{cycle values="even,odd"}>">
<{$theme->get_md5()}>
</td>
</tr>
</table>
<{/strip}>
File: /modules/themedownload/templates/themedownload_admin_disallow.html
<{strip}>
<table>
<tr>
<th>
Name
</th>
<td class="<{cycle values="even,odd"}>">
<{$theme->get_name()}>
</td>
</tr>
<tr>
<th>
Preview
</th>
<td class="<{cycle values="even,odd"}>">
<a href="<{$theme->get_preview()}>" target="_blank">
Preview
</a>
</td>
</tr>
<tr>
<th>
MD5
</th>
<td class="<{cycle values="even,odd"}>">
<{$theme->get_md5()}>
</td>
</tr>
</table>
<{/strip}>
File: /modules/themedownload/templates/themedownload_admin_download.html
<{strip}>
<table>
<tr>
<th>
Name
</th>
<td class="<{cycle values="even,odd"}>">
<{$theme->get_name()}>
</td>
</tr>
<tr>
<th>
Preview
</th>
<td class="<{cycle values="even,odd"}>">
<a href="<{$theme->get_preview()}>" target="_blank">
Preview
</a>
</td>
</tr>
<tr>
<th>
MD5
</th>
<td class="<{cycle values="even,odd"}>">
<{$theme->get_md5()}>
</td>
</tr>
<{if true === $theme->is_downloaded()}>
<tr>
<th>
File MD5
</th>
<td class="<{cycle values="even,odd"}>">
<{$theme->get_filemd5()}>
</td>
</tr>
<{/if}>
</table>
<{if true === isset($zipentries)}>
<table>
<tr>
<th>
Name
</th>
<th>
File Size
</th>
<th>
Compressed Size
</th>
<th>
Compression Method
</th>
<th>
File Path
</th>
</tr>
<{foreach from=$zipentries item="zipentry"}>
<tr class="<{cycle values="even,odd"}>">
<td>
<{$zipentry.name}>
</td>
<td>
<{$zipentry.filesize}>
</td>
<td>
<{$zipentry.compressedsize}>
</td>
<td>
<{$zipentry.compressionmethod}>
</td>
<td>
<{$zipentry.filepath}>
</td>
</tr>
<{/foreach}>
</table>
<{/if}>
<a href="<{$xoops_url}>/modules/themedownload/admin/index.php#<{$theme->get_name()}>">
<{$smarty.const._BACK}>
</a>
<{/strip}>
File: /modules/themedownload/templates/themedownload_admin_help.html
<{strip}>
<div>
This module require <a href="http://www.php.net/manual/en/ref.zip.php">zip extension.</a>
</div>
<{/strip}>
File: /modules/themedownload/templates/themedownload_admin_index.html
<{strip}>
<table>
<tr>
<th>
Name
</th>
<th>
Preview
</th>
<th>
Download
</th>
<th>
Delete
</th>
<th>
Allow
</th>
<th>
Disallow
</th>
<th>
Select
</th>
</tr>
<{foreach from=$themes item="theme"}>
<tr class="<{cycle values="even,odd"}>">
<td>
<a name="<{$theme->get_name()}>"></a>
<{$theme->get_name()}>
</td>
<td>
<a href="<{$theme->get_preview()}>" target="_blank">
Preview
</a>
</td>
<td>
<{if false === $theme->is_downloaded()}>
<a href="<{$xoops_url}>/modules/themedownload/admin/download.php?theme=<{$theme->get_name()}>">
Download
</a>
<{/if}>
</td>
<td>
<{if true === $theme->is_downloaded()}>
<a href="<{$xoops_url}>/modules/themedownload/admin/delete.php?theme=<{$theme->get_name()}>">
Delete
</a>
<{/if}>
</td>
<td>
<{if true === $theme->is_downloaded()}>
<{if false === $theme->is_allow()}>
<a href="<{$xoops_url}>/modules/themedownload/admin/allow.php?theme=<{$theme->get_name()}>">
Allow
</a>
<{/if}>
<{/if}>
</td>
<td>
<{if true === $theme->is_downloaded()}>
<{if true === $theme->is_allow()}>
<a href="<{$xoops_url}>/modules/themedownload/admin/disallow.php?theme=<{$theme->get_name()}>">
Disallow
</a>
<{/if}>
<{/if}>
</td>
<td>
<{if true === $theme->is_downloaded()}>
<{if true === $theme->is_allow()}>
<a href="<{$xoops_url}>?xoops_theme_select=<{$theme->get_name()}>" target="_blank">
Select
</a>
<{/if}>
<{/if}>
</td>
</tr>
<{/foreach}>
</table>
<{/strip}>
File: /modules/themedownload/xoops_version.php
<?php
if (false === defined("XOOPS_ROOT_PATH")) {
exit();
}
$modversion["name"] = "Theme Download";
$modversion["version"] = 0.04;
$modversion["description"] = "Download Themes.";
$modversion["author"] = "Hu Zhenghui http://xoops.org.cn/userinfo.php?uid=8616 QQ: 443089607 QQMail: [email protected] Skype: huzhenghui GMail: [email protected] GTalk: huzhengh";
$modversion['license'] = "All rights reserved.";
$modversion['image'] = "../../images/logo.gif";
$modversion['dirname'] = "themedownload";
$modversion['hasAdmin'] = 1;
$modversion['adminindex'] = "admin/index.php";
$i = 1;
$modversion['templates'][$i]['file'] = 'themedownload_admin_index.html';
$modversion['templates'][$i]['description'] = '';
$i++;
$modversion['templates'][$i]['file'] = 'themedownload_admin_download.html';
$modversion['templates'][$i]['description'] = '';
$i++;
$modversion['templates'][$i]['file'] = 'themedownload_admin_delete.html';
$modversion['templates'][$i]['description'] = '';
$i++;
$modversion['templates'][$i]['file'] = 'themedownload_admin_help.html';
$modversion['templates'][$i]['description'] = '';
$i++;
$modversion['templates'][$i]['file'] = 'themedownload_admin_allow.html';
$modversion['templates'][$i]['description'] = '';
$i++;
$modversion['templates'][$i]['file'] = 'themedownload_admin_disallow.html';
$modversion['templates'][$i]['description'] = '';
$modversion["modulecode"]["ignore"][] = "/modules/themedownload/include/themesdata.php";
?>