issue 2119. supporting php 5.4. addon module.

git-svn-id: http://xe-core.googlecode.com/svn/branches/maserati@12707 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
flyskyko 2013-02-06 08:04:23 +00:00
parent 8a7c28babc
commit ee9247e866
4 changed files with 309 additions and 103 deletions

View file

@ -1,10 +1,12 @@
<?php
/**
* Admin model class of addon module
* @author NHN (developers@xpressengine.com)
*/
class addonAdminModel extends addon
{
/**
* Initialization
*
@ -12,6 +14,7 @@ class addonAdminModel extends addon
*/
function init()
{
}
/**
@ -23,7 +26,10 @@ class addonAdminModel extends addon
function getAddonPath($addon_name)
{
$class_path = sprintf('./addons/%s/', $addon_name);
if(is_dir($class_path)) return $class_path;
if(is_dir($class_path))
{
return $class_path;
}
return "";
}
@ -36,7 +42,7 @@ class addonAdminModel extends addon
{
$addonList = $this->getAddonList(0, 'site');
$oAutoinstallModel = &getModel('autoinstall');
$oAutoinstallModel = getModel('autoinstall');
foreach($addonList as $key => $addon)
{
// get easyinstall remove url
@ -69,18 +75,25 @@ class addonAdminModel extends addon
// Wanted to add a list of activated
$inserted_addons = $this->getInsertedAddons($site_srl, $gtype);
// Downloaded and installed add-on to the list of Wanted
$searched_list = FileHandler::readDir('./addons','/^([a-zA-Z0-9-_]+)$/');
$searched_list = FileHandler::readDir('./addons', '/^([a-zA-Z0-9-_]+)$/');
$searched_count = count($searched_list);
if(!$searched_count) return;
if(!$searched_count)
{
return;
}
sort($searched_list);
$oAddonAdminController = &getAdminController('addon');
$oAddonAdminController = getAdminController('addon');
for($i=0;$i<$searched_count;$i++)
for($i = 0; $i < $searched_count; $i++)
{
// Add the name of
$addon_name = $searched_list[$i];
if($addon_name == "smartphone") continue;
if($addon_name == "smartphone")
{
continue;
}
// Add the path (files/addons precedence)
$path = $this->getAddonPath($addon_name);
// Wanted information on the add-on
@ -89,9 +102,9 @@ class addonAdminModel extends addon
$info->addon = $addon_name;
$info->path = $path;
$info->activated = false;
$info->mactivated = false;
$info->fixed = false;
$info->activated = FALSE;
$info->mactivated = FALSE;
$info->fixed = FALSE;
// Check if a permossion is granted entered in DB
if(!in_array($addon_name, array_keys($inserted_addons)))
{
@ -101,9 +114,18 @@ class addonAdminModel extends addon
}
else
{
if($inserted_addons[$addon_name]->is_used=='Y') $info->activated = true;
if($inserted_addons[$addon_name]->is_used_m=='Y') $info->mactivated = true;
if ($gtype == 'global' && $inserted_addons[$addon_name]->is_fixed == 'Y') $info->fixed = true;
if($inserted_addons[$addon_name]->is_used == 'Y')
{
$info->activated = TRUE;
}
if($inserted_addons[$addon_name]->is_used_m == 'Y')
{
$info->mactivated = TRUE;
}
if($gtype == 'global' && $inserted_addons[$addon_name]->is_fixed == 'Y')
{
$info->fixed = TRUE;
}
}
$list[] = $info;
@ -123,25 +145,38 @@ class addonAdminModel extends addon
{
// Get a path of the requested module. Return if not exists.
$addon_path = $this->getAddonPath($addon);
if(!$addon_path) return;
if(!$addon_path)
{
return;
}
// Read the xml file for module skin information
$xml_file = sprintf("%sconf/info.xml", $addon_path);
if(!file_exists($xml_file)) return;
if(!file_exists($xml_file))
{
return;
}
$oXmlParser = new XmlParser();
$tmp_xml_obj = $oXmlParser->loadXmlFile($xml_file);
$xml_obj = $tmp_xml_obj->addon;
if(!$xml_obj) return;
if(!$xml_obj)
{
return;
}
// DB is set to bring history
$db_args = new stdClass();
$db_args->addon = $addon;
if($gtype == 'global') $output = executeQuery('addon.getAddonInfo',$db_args);
if($gtype == 'global')
{
$output = executeQuery('addon.getAddonInfo', $db_args);
}
else
{
$db_args->site_srl = $site_srl;
$output = executeQuery('addon.getSiteAddonInfo',$db_args);
$output = executeQuery('addon.getSiteAddonInfo', $db_args);
}
$extra_vals = unserialize($output->data->extra_vars);
@ -164,6 +199,7 @@ class addonAdminModel extends addon
if($xml_obj->version && $xml_obj->attrs->version == '0.2')
{
// addon format v0.2
$date_obj = new stdClass();
sscanf($xml_obj->date->body, '%d-%d-%d', $date_obj->y, $date_obj->m, $date_obj->d);
$addon_info->date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d);
@ -175,9 +211,17 @@ class addonAdminModel extends addon
$addon_info->license = $xml_obj->license->body;
$addon_info->license_link = $xml_obj->license->attrs->link;
if(!is_array($xml_obj->author)) $author_list[] = $xml_obj->author;
else $author_list = $xml_obj->author;
if(!is_array($xml_obj->author))
{
$author_list = array();
$author_list[] = $xml_obj->author;
}
else
{
$author_list = $xml_obj->author;
}
$addon_info->author = array();
foreach($author_list as $author)
{
$author_obj = new stdClass();
@ -191,18 +235,30 @@ class addonAdminModel extends addon
if($xml_obj->extra_vars)
{
$extra_var_groups = $xml_obj->extra_vars->group;
if(!$extra_var_groups) $extra_var_groups = $xml_obj->extra_vars;
if(!is_array($extra_var_groups)) $extra_var_groups = array($extra_var_groups);
if(!$extra_var_groups)
{
$extra_var_groups = $xml_obj->extra_vars;
}
if(!is_array($extra_var_groups))
{
$extra_var_groups = array($extra_var_groups);
}
foreach($extra_var_groups as $group)
{
$extra_vars = $group->var;
if(!is_array($group->var)) $extra_vars = array($group->var);
if(!is_array($group->var))
{
$extra_vars = array($group->var);
}
foreach($extra_vars as $key => $val)
{
$obj = new stdClass();
if(!$val->attrs->type) { $val->attrs->type = 'text'; }
if(!$val->attrs->type)
{
$val->attrs->type = 'text';
}
$obj->group = $group->title->body;
$obj->name = $val->attrs->name;
@ -213,8 +269,14 @@ class addonAdminModel extends addon
{
$obj->value = $extra_vals->{$obj->name};
}
if(strpos($obj->value, '|@|') != false) { $obj->value = explode('|@|', $obj->value); }
if($obj->type == 'mid_list' && !is_array($obj->value)) { $obj->value = array($obj->value); }
if(strpos($obj->value, '|@|') != FALSE)
{
$obj->value = explode('|@|', $obj->value);
}
if($obj->type == 'mid_list' && !is_array($obj->value))
{
$obj->value = array($obj->value);
}
// 'Select'type obtained from the option list.
if($val->options && !is_array($val->options))
@ -237,17 +299,34 @@ class addonAdminModel extends addon
// history
if($xml_obj->history)
{
if(!is_array($xml_obj->history)) $history[] = $xml_obj->history;
else $history = $xml_obj->history;
if(!is_array($xml_obj->history))
{
$history = array();
$history[] = $xml_obj->history;
}
else
{
$history = $xml_obj->history;
}
$addon_info->history = array();
foreach($history as $item)
{
unset($obj);
$obj = new stdClass();
if($item->author)
{
(!is_array($item->author)) ? $obj->author_list[] = $item->author : $obj->author_list = $item->author;
if(!is_array($item->author))
{
$obj->author_list = array();
$obj->author_list[] = $item->author;
}
else
{
$obj->author_list = $item->author;
}
$obj->author = array();
foreach($obj->author_list as $author)
{
$author_obj = new stdClass();
@ -267,8 +346,17 @@ class addonAdminModel extends addon
if($item->log)
{
(!is_array($item->log)) ? $obj->log[] = $item->log : $obj->log = $item->log;
if(!is_array($item->log))
{
$obj->log = array();
$obj->log[] = $item->log;
}
else
{
$obj->log = $item->log;
}
$obj->logs = array();
foreach($obj->log as $log)
{
$log_obj = new stdClass();
@ -284,31 +372,44 @@ class addonAdminModel extends addon
else
{
// addon format 0.1
$addon_info = new stdClass();
$addon_info->addon_name = $addon;
$addon_info->title = $xml_obj->title->body;
$addon_info->description = trim($xml_obj->author->description->body);
$addon_info->version = $xml_obj->attrs->version;
$date_obj = new stdClass();
sscanf($xml_obj->author->attrs->date, '%d. %d. %d', $date_obj->y, $date_obj->m, $date_obj->d);
$addon_info->date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d);
$author_obj->name = $xml_obj->author->name->body;
$author_obj->email_address = $xml_obj->author->attrs->email_address;
$author_obj->homepage = $xml_obj->author->attrs->link;
$addon_info->author = array();
$addon_info->author[] = $author_obj;
if($xml_obj->extra_vars)
{
// Expand the variable order
$extra_var_groups = $xml_obj->extra_vars->group;
if(!$extra_var_groups) $extra_var_groups = $xml_obj->extra_vars;
if(!is_array($extra_var_groups)) $extra_var_groups = array($extra_var_groups);
if(!$extra_var_groups)
{
$extra_var_groups = $xml_obj->extra_vars;
}
if(!is_array($extra_var_groups))
{
$extra_var_groups = array($extra_var_groups);
}
foreach($extra_var_groups as $group)
{
$extra_vars = $group->var;
if(!is_array($group->var)) $extra_vars = array($group->var);
if(!is_array($group->var))
{
$extra_vars = array($group->var);
}
$addon_info->extra_vars = array();
foreach($extra_vars as $key => $val)
{
unset($obj);
$obj = new stdClass();
$obj->group = $group->title->body;
$obj->name = $val->attrs->name;
@ -319,14 +420,21 @@ class addonAdminModel extends addon
{
$obj->value = $extra_vals->{$obj->name};
}
if(strpos($obj->value, '|@|') != false) { $obj->value = explode('|@|', $obj->value); }
if($obj->type == 'mid_list' && !is_array($obj->value)) { $obj->value = array($obj->value); }
if(strpos($obj->value, '|@|') != false)
{
$obj->value = explode('|@|', $obj->value);
}
if($obj->type == 'mid_list' && !is_array($obj->value))
{
$obj->value = array($obj->value);
}
// 'Select'type obtained from the option list.
if($val->options && !is_array($val->options))
{
$val->options = array($val->options);
}
$obj->options = array();
for($i = 0, $c = count($val->options); $i < $c; $i++)
{
$obj->options[$i]->title = $val->options[$i]->title->body;
@ -351,17 +459,23 @@ class addonAdminModel extends addon
{
$args = new stdClass();
$args->list_order = 'addon';
if($gtype == 'global') $output = executeQuery('addon.getAddons', $args);
if($gtype == 'global')
{
$output = executeQueryArray('addon.getAddons', $args);
}
else
{
$args->site_srl = $site_srl;
$output = executeQuery('addon.getSiteAddons', $args);
$output = executeQueryArray('addon.getSiteAddons', $args);
}
if(!$output->data)
{
return array();
}
if(!$output->data) return array();
if(!is_array($output->data)) $output->data = array($output->data);
$activated_count = count($output->data);
for($i=0;$i<$activated_count;$i++)
$addon_list = array();
for($i = 0; $i < $activated_count; $i++)
{
$addon = $output->data[$i];
$addon_list[$addon->addon] = $addon;
@ -380,21 +494,38 @@ class addonAdminModel extends addon
*/
function isActivatedAddon($addon, $site_srl = 0, $type = "pc", $gtype = 'site')
{
$args = new stdClass();
$args->addon = $addon;
if($gtype == 'global')
{
if($type == "pc") $output = executeQuery('addon.getAddonIsActivated', $args);
else $output = executeQuery('addon.getMAddonIsActivated', $args);
if($type == "pc")
{
$output = executeQuery('addon.getAddonIsActivated', $args);
}
else
{
$output = executeQuery('addon.getMAddonIsActivated', $args);
}
}
else
{
$args->site_srl = $site_srl;
if($type == "pc") $output = executeQuery('addon.getSiteAddonIsActivated', $args);
else $output = executeQuery('addon.getSiteMAddonIsActivated', $args);
if($type == "pc")
{
$output = executeQuery('addon.getSiteAddonIsActivated', $args);
}
else
{
$output = executeQuery('addon.getSiteMAddonIsActivated', $args);
}
}
if($output->data->count>0) return true;
return false;
if($output->data->count > 0)
{
return TRUE;
}
return FALSE;
}
}
/* End of file addon.admin.model.php */
/* Location: ./modules/addon/addon.admin.model.php */