function plug_upload($idclient = '0', $override = false) { global $rep, $cfg_cms, $sess, $s_upload, $db, $cms_db; if (is_array($s_upload) && $override) { $tmp_file = $s_upload; $returncode = $s_upload['returncode']; if ($sess->is_registered('s_upload')) { $sess->unregister('s_upload'); } } else { $tmp_file = lib_get_upload('plug_upload_file'); } //Es wurde keine Datei hochgeladen if (!is_array($tmp_file) || $tmp_file['error'] == '-1' || $tmp_file['error'] == '-2') { if ($tmp_file['code'] >= 1) { //if (lib_test_safemode()) return array('1801', false); if ($tmp_file['code'] == 1) { return array('0708', false); } if ($tmp_file['code'] == 2) { return array('0709', false); } if ($tmp_file['code'] == 3) { return array('0710', false); } if ($tmp_file['code'] == 4) { return array('0711', false); } } else { return array('1604', false); } } if (!($file_content = $rep->_file($tmp_file['copy']))) { lib_delete_file($tmp_file['copy']); if (lib_test_safemode()) { return array('1801', false); } else { return array('1600', false); } } require_once "Archive/Tar.php"; if (false === ($tar = new Archive_Tar($tmp_file['copy']))) { $return = '1615'; if ($tar->_error_message != '') { $error = $tar->_error_message; } return array($return, $error); } elseif ($tar == '-1') { return array('1621', false); } $tmp_plugin = $tar->listContent(); if ($tmp_plugin[0]['filename'] == '' || $tmp_plugin[0]['typeflag'] != 5) { return array('1604', false); } $name = substr($tmp_plugin[0]['filename'], -1) == '/' ? substr($tmp_plugin[0]['filename'], 0, -1) : $tmp_plugin[0]['filename']; $tmp_cmsplug = $tar->extractInString($name . '/' . $name . '.cmsplug'); //todo: 2remove if (empty($tmp_cmsplug)) { $tmp_cmsplug = $tar->extractInString($name . '/' . $name . '.dediplug'); } list($idplug, $xml_array) = $rep->plug_import($tmp_cmsplug, $idclient, $override); if ($idplug == '-1' || $idplug == '-2') { $s_upload = $tmp_file; $s_upload['returncode'] = $idplug; $s_upload['plugversion'] = $xml_array['version']; $s_upload['plugname'] = $xml_array['name']; list($type, $rid, $uid) = explode(":", $xml_array['repository_id']); $s_upload['plugrepid'] = $type . ':' . $rid; $sess->register('s_upload'); return array('1617', false); } elseif ($idplug == '-3') { $s_upload = $tmp_file; $s_upload['returncode'] = $idplug; $s_upload['plugversion'] = $xml_array['version']; $s_upload['plugname'] = $xml_array['name']; list($type, $rid, $uid) = explode(":", $xml_array['repository_id']); $s_upload['plugrepid'] = $type . ':' . $rid; $sess->register('s_upload'); return array('1619', false); } elseif ($idplug == '-4') { lib_delete_file($tmp_file['copy']); return array('1603', false); } elseif (!$idplug || !is_array($xml_array)) { lib_delete_file($tmp_file['copy']); return array('1600', false); } if (!$tar->extract($cfg_cms['cms_path'] . 'plugins/')) { // check error if ($tar->_error_message != '') { $error = $tar->_error_message; } // force delete the plugin plug_delete($idplug, $idclient); return array('1615', $error); } // get the new Plugin data $plugin = $rep->plug_data($idplug, $idclient); // Event fire_event('plug_upload', array('idplug' => $idplug, 'name' => $plugin['name'])); if ($override && $returncode == '-1' || $returncode == '-2') { if ((bool) $plugin['is_install']) { $rep->plug_execute($idplug, 'update', '', 'meta'); if ((bool) $rep->plug_execute($idplug, 'multi_client') && $idclient == '0') { global $client; $sql = "SELECT idclient from " . $cms_db['plug'] . " WHERE source_id='{$idplug}' AND is_install='1'"; $db->query($sql); while ($db->next_record()) { $client = $db->f('idclient'); $rep->plug_execute($idplug, 'update', 'client', 'meta'); // Event fire_event('plug_update_client', array('idplug' => $idplug, 'name' => $plugin['name'])); } } } // Event fire_event('plug_update', array('idplug' => $idplug, 'name' => $plugin['name'])); } elseif ($override && $returncode == '-3') { if ((bool) $plugin['is_install']) { $_recurse = array(); global $client; if ((bool) $rep->plug_execute($idplug, 'multi_client') && $idclient == '0') { $sql = "SELECT idclient from " . $cms_db['plug'] . " WHERE source_id='{$idplug}' AND is_install='1'"; $db->query($sql); while ($db->next_record()) { array_push($_recurse, $db->f('idclient')); // Event fire_event('plug_reinstall_client', array('idplug' => $idplug, 'name' => $plugin['name'])); } } reset($_recurse); foreach ($_recurse as $_k => $_v) { $client = $_v; $rep->plug_execute($idplug, 'uninstall', 'client', 'meta'); } $rep->plug_execute($idplug, 'uninstall', '', 'meta'); $rep->plug_execute($idplug, 'install', '', 'meta'); foreach ($_recurse as $_k => $_v) { $client = $_v; $rep->plug_execute($idplug, 'install', 'client', 'meta'); } } // Event fire_event('plug_reinstall', array('idplug' => $idplug, 'name' => $plugin['name'])); } lib_delete_file($tmp_file['copy']); return array('1612', false); }
if ($errno == '1617') { // Plugin Update? $link = $sess->url('main.php?area=plug&action=upload&idclient=' . $idclient); $tpl_in['ONLOAD_FUNCTION'] = "SF.Utils.confirmToUrl('" . sprintf($cms_lang['plug_confirm_update'], $s_upload['plugname'], $s_upload['plugversion']) . "','" . $link . "','override');"; $sess->freeze(); } elseif ($errno == '1619') { // Plugin Reinstall? $link = $sess->url('main.php?area=plug&action=upload&idclient=' . $idclient); $tpl_in['ONLOAD_FUNCTION'] = "SF.Utils.confirmToUrl('" . sprintf($cms_lang['plug_confirm_reinstall'], $s_upload['plugname'], $s_upload['plugversion']) . "','" . $link . "','override');"; $sess->freeze(); } break; case 'delete': // Plugin löschen $perm->check(5, 'plug', $idplug); $errno = plug_delete($idplug, $idclient); $sess->freeze(); header('Location:' . $sess->urlRaw("main.php?area=plug&errno=" . $errno . "&idclient=" . $idclient)); break; case 'update': // Plugin updaten Repository $perm->check(12, 'mod', $idplug); $updatedata = $rep->plug_update_data($repid); if ($updatedata['repository_id'] == $repid) { $errno = plug_update($idplug, $repid, $updatedata['name'], $updatedata['description'], $updatedata['version'], $updatedata['cat'], $updatedata['input'], $updatedata['output'], $updatedata['install_sql'], $updatedata['uninstall_sql'], $updatedata['update_sql'], $idclient); } else { $errno = '1500'; } break; case 'import': // Plugin import Repository