function import(&$data) { $arr = GetXMLTree($data); $arr = $arr['dataface']; $records = array(); foreach (array_keys($arr) as $tablename) { foreach (array_keys($arr[$tablename]) as $index) { $records[] = new Dataface_Record($tablename, $arr[$tablename][$index]); } } return $records; }
/** * This is the second level response function. * * After reply() this function is the second level function to get the answer to the user's input. * * @uses bget() * @uses debugger() * @uses gettemplate() * @uses GetXMLTree() * @uses recursechildren() * * @global string * @global integer * @global array * @global array * * @param string $sentence The sentence to be matched. * * #return string The response to the user's input. */ function respond($sentence) { global $that, $loopcounter, $patternmatched, $inputmatched; $topic = bget("topic"); $loopcounter++; if ($loopcounter > LOOPINGLIMIT && LOOPINGLIMIT != -1) { return ""; } $inputstarvals = array(); $thatstarvals = array(); $topicstarvals = array(); debugger("respond called with sentence: {$sentence}", 3); flush(); if ($that == "") { $that = "<nothing>"; } if ($topic == "") { $topic = "<nothing>"; } if ($sentence == "") { return ""; } else { //If we found a template $template = gettemplate($sentence, $that, $topic, $inputstarvals, $thatstarvals, $topicstarvals, $s_patternmatched, $s_inputmatched); $patternmatched[] = $s_patternmatched; $inputmatched[] = $s_inputmatched; if ($template != "") { $template = "<xml><TEMPLATE>" . $template . "</TEMPLATE></xml>"; debugger("found template: {$template}", 2); $root = GetXMLTree($template); if (!isset($root[0]['children'][0]['value'])) { $root = $root[0]['children'][0]['children']; } else { $root = $root[0]['children'][0]['value']; } /* if ($root[0]['children'][0]['value']==""){ $root=$root[0]['children'][0]['children']; } else { $root=$root[0]['children'][0]['value']; } */ $myresponse = recursechildren($root, $inputstarvals, $thatstarvals, $topicstarvals); debugger("recursechildren ret: {$myresponse}", 3); return $myresponse; } } }
/** * BackEnd * * Module backend * * @access public */ function admin(&$out) { global $err_msg; if ($err_msg) { $out['ERR_MSG'] = $err_msg; } global $ok_msg; if ($ok_msg) { $out['OK_MSG'] = $ok_msg; } $this->getConfig(); if (is_dir(ROOT . 'saverestore/temp')) { $out['CLEAR_FIRST'] = 1; } $this->getConfig(); $github_feed = getURL('https://github.com/sergejey/majordomo/commits/master.atom', 30 * 60); if ($github_feed != '') { @($tmp = GetXMLTree($github_feed)); @($data = XMLTreeToArray($tmp)); @($items = $data['feed']['entry']); if (is_array($items)) { $total = count($items); if ($total) { if ($total > 5) { $total = 5; } //print_r($items);exit; for ($i = 0; $i < $total; $i++) { $itm = array(); $itm['ID'] = trim($items[$i]['id']['textvalue']); $itm['ID'] = preg_replace('/.+Commit\\//is', '', $itm['ID']); $itm['TITLE'] = trim($items[$i]['title']['textvalue']); $itm['AUTHOR'] = $items[$i]['author']['name']['textvalue']; $itm['LINK'] = $items[$i]['link']['href']; $itm['UPDATED'] = strtotime($items[$i]['updated']['textvalue']); $itm['UPDATE_TEXT'] = date('m/d/Y H:i', $itm['UPDATED']); $out['UPDATES'][] = $itm; } $out['LATEST_ID'] = $out['UPDATES'][0]['ID']; if ($out['LATEST_ID'] != '' && $out['LATEST_ID'] == $this->config['LATEST_UPDATED_ID']) { $out['NO_NEED_TO_UPDATE'] = 1; } //print_r($out['UPDATES']); //exit; } } } if ($this->mode == 'savedetails') { global $ftp_host; global $ftp_username; global $ftp_password; global $ftp_folder; global $ftp_clear; if ($ftp_clear) { $this->config['FTP_USERNAME'] = ''; $this->config['FTP_PASSWORD'] = ''; $this->saveConfig(); $this->redirect("?"); } $out['FTP_HOST'] = $ftp_host; $out['FTP_USERNAME'] = $ftp_username; $out['FTP_PASSWORD'] = $ftp_password; $out['FTP_FOLDER'] = $ftp_folder; $conn_id = @ftp_connect($ftp_host); if ($conn_id) { $login_result = @ftp_login($conn_id, $ftp_username, $ftp_password); if ($login_result) { $systyp = ftp_systype($conn_id); if (!preg_match('/\\/$/', $ftp_folder)) { $ftp_folder .= '/'; } if (@ftp_chdir($conn_id, $ftp_folder . 'saverestore')) { $this->config['FTP_HOST'] = $ftp_host; $this->config['FTP_USERNAME'] = $ftp_username; $this->config['FTP_PASSWORD'] = $ftp_password; $this->config['FTP_FOLDER'] = $ftp_folder; $this->saveConfig(); $this->redirect("?"); } else { $out['FTP_ERR'] = 'Incorrect folder (' . $ftp_folder . ')'; } } else { $out['FTP_ERR'] = 'Incorrect username/password'; } ftp_close($conn_id); } else { $out['FTP_ERR'] = 'Cannot connect to host (' . $ftp_host . ')'; } } if ($this->mode != 'savedetails') { $out['FTP_HOST'] = $this->config['FTP_HOST']; $out['FTP_USERNAME'] = $this->config['FTP_USERNAME']; $out['FTP_PASSWORD'] = $this->config['FTP_PASSWORD']; $out['FTP_FOLDER'] = $this->config['FTP_FOLDER']; } // if ($this->mode=='' || $this->mode=='upload' || $this->mode=='savedetails') { $method = 'ftp'; if (function_exists('getmyuid') && function_exists('fileowner')) { $temp_file = tempnam("./saverestore/", "FOO"); if (file_exists($temp_file)) { $method = 'direct'; unlink($temp_file); } } $out['METHOD'] = $method; $this->method = $method; // } if ($this->mode == 'clear') { $this->removeTree(ROOT . 'saverestore/temp'); $this->redirect("?err_msg=" . urlencode($err_msg) . "&ok_msg=" . urlencode($ok_msg)); } if ($this->mode == 'checksubmit') { $this->checkSubmit($out); } if ($this->mode == 'uploadupdates') { $this->uploadUpdates($out); } if ($this->mode == 'checkupdates') { $this->checkupdatesSVN($out); } if ($this->mode == 'downloadupdates') { $this->downloadupdatesSVN($out); } if ($this->mode == 'checkapps') { $this->checkApps($out); } if ($this->mode == 'downloadapps') { $this->downloadApps($out); } if ($this->mode == 'upload') { $this->upload($out); //$this->redirect("?mode=clear"); } if ($this->mode == 'dump') { $this->dump($out); $this->redirect("?mode=clear"); //$this->redirect("?"); } if ($this->mode == 'delete') { global $file; @unlink(ROOT . 'saverestore/' . $file); $this->redirect("?"); } if ($this->mode == 'getlatest') { $this->getLatest($out); } $source = ROOT . 'saverestore'; $currentdir = getcwd(); chdir($source); array_multisort(array_map('filemtime', $files = glob("*.*")), SORT_DESC, $files); chdir($currentdir); foreach ($files as $file) { $tmp = array(); $tmp['FILENAME'] = $file; $tmp['FILESIZE'] = number_format(filesize($source . "/" . $file) / 1024 / 1024, 2); $out['FILES'][] = $tmp; } }
function XMLToArray($data, $uppercase = 1) { $tree = GetXMLTree($data, $uppercase); return CompackTree($tree); }
/** * BackEnd * * Module backend * * @access public */ function admin(&$out) { global $name; $data_url = 'http://connect.smartliving.ru/market/?lang=' . SETTINGS_SITE_LANGUAGE; global $err_msg; if ($err_msg) { $out['ERR_MSG'] = $err_msg; } global $ok_msg; if ($ok_msg) { $out['OK_MSG'] = $ok_msg; } if (is_dir(ROOT . 'saverestore/temp')) { $out['CLEAR_FIRST'] = 1; } $result = getURL($data_url, 120); $data = json_decode($result); if (!$data->PLUGINS) { $out['ERR'] = 1; return; } $total = count($data->PLUGINS); $old_category = ''; $can_be_updated = array(); for ($i = 0; $i < $total; $i++) { $rec = (array) $data->PLUGINS[$i]; if (is_dir(ROOT . 'modules/' . $rec['MODULE_NAME'])) { $rec['EXISTS'] = 1; $plugin_rec = SQLSelectOne("SELECT * FROM plugins WHERE MODULE_NAME LIKE '" . DBSafe($rec['MODULE_NAME']) . "'"); if ($plugin_rec['ID']) { $rec['INSTALLED_VERSION'] = $plugin_rec['CURRENT_VERSION']; } } if ($rec['CATEGORY'] != $old_category) { $rec['NEW_CATEGORY'] = 1; $old_category = $rec['CATEGORY']; } //if ($rec['MODULE_NAME']==$name) { unset($rec['LATEST_VERSION']); if (preg_match('/github\\.com/is', $rec['REPOSITORY_URL']) && ($rec['EXISTS'] || $rec['MODULE_NAME'] == $name)) { $git_url = str_replace('archive/master.tar.gz', 'commits/master.atom', $rec['REPOSITORY_URL']); $github_feed = getURL($git_url, 5 * 60); @($tmp = GetXMLTree($github_feed)); @($items_data = XMLTreeToArray($tmp)); @($items = $items_data['feed']['entry']); if (is_array($items)) { $latest_item = $items[0]; //print_r($latest_item);exit; $updated = strtotime($latest_item['updated']['textvalue']); $rec['LATEST_VERSION'] = date('Y-m-d H:i:s', $updated); $rec['LATEST_VERSION_COMMENT'] = $latest_item['title']['textvalue']; $rec['LATEST_VERSION_URL'] = $latest_item['link']['href']; } } if ($rec['MODULE_NAME'] == $name) { $url = $rec['REPOSITORY_URL']; $version = $rec['LATEST_VERSION']; } //} if ($rec['EXISTS']) { $can_be_updated[] = array('NAME' => $rec['MODULE_NAME'], 'URL' => $rec['REPOSITORY_URL'], 'VERSION' => $rec['LATEST_VERSION']); //$can_be_updated[]=$rec['MODULE_NAME']; } $out['PLUGINS'][] = $rec; } if ($this->mode == 'update_all') { $this->updateAll($can_be_updated); } if ($this->mode == 'install' && $url) { $this->getLatest($out, $url, $name, $version); } if ($this->mode == 'upload') { $this->upload($out); } if ($this->mode == 'uninstall' && $name) { $this->uninstallPlugin($name); } if ($this->mode == 'clear') { $this->removeTree(ROOT . 'saverestore/temp'); @SaveFile(ROOT . 'reboot', 'updated'); $this->redirect("?err_msg=" . urlencode($err_msg) . "&ok_msg=" . urlencode($ok_msg)); } }