function create_post($page, $blueprint, $title, $data) { // Where we'll put the content. $PATH = get_content_path($page); $SLUG = str::slug($title); $dir = $PATH . DS . $SLUG; $dir_matches = glob($PATH . DS . "*" . $SLUG . "*"); // If the directory already exists don't override it, // append a number to it, no matter its visibility. // 1-directory // directory_1 // 8-directory_2 if (count($dir_matches) > 0) { $dir .= "_" . count($dir_matches); $title .= "_" . count($dir_matches); } // Pass $title into the $data array for easiest manipulation. $data["title"] = $title; // Create the directory with read&write permissions. mkdir($dir, 0777, true); // Filename with (almost) multilingual support. // Peraphs you'll want to create different files for each // languages code. $filename = $blueprint . ".fr.txt"; // Write the file. $file = fopen($dir . DS . $filename, 'w'); if (flock($file, LOCK_EX)) { fwrite($file, parse_data(get_blueprint($blueprint), $data)); flock($file, LOCK_EX); } fclose($file); }
function run_all_tests() { global $passed; #comment_test(); #submit_test(); $sid = "15/05/08/0149218"; # sd-key-sid of testing article $path = __DIR__ . "/slash_tests"; $filenames = glob($path . "/*"); $test_results = array(); for ($i = 0; $i < count($filenames); $i++) { if ($i > 0) { sleep(120); } $filename = $filenames[$i]; $basename = basename($filename); privmsg("*** processing test comment defined in \"" . $basename . "\""); $data = file_get_contents($filename); if ($data !== False) { $keys = array("parent", "subject_in", "body_in", "subject_out", "body_out"); $result = parse_data($keys, $data); if ($result === False) { privmsg(" error parsing data in \"" . $basename . "\""); $passed = False; break; } $parent_cid = ""; if ($result["parent"] != "") { if (isset($test_results[$result["parent"]]["cid"]) == True) { $parent_cid = $test_results[$result["parent"]]["cid"]; } } $test_results[$basename] = sn_comment($result["subject_in"], $result["body_in"], $sid, $parent_cid); if ($test_results[$basename] === False) { privmsg(" error submitting test comment defined in \"" . $basename . "\""); $passed = False; break; } if ($test_results[$basename]["subject"] != $result["subject_out"]) { privmsg(" subject mismatch for test comment defined in \"" . $basename . "\""); $passed = False; break; } if ($test_results[$basename]["body"] != $result["body_out"]) { privmsg(" body mismatch for test comment defined in \"" . $basename . "\""); $passed = False; break; } } else { privmsg(" error reading \"" . $basename . "\""); $passed = False; break; } } }
function parse_data($data) { if ($data->nodeType == XML_TEXT_NODE) { return iconv('UTF-8', 'ISO-8859-2', $data->nodeValue); } if ($data->firstChild && $data->firstChild->nodeType == XML_TEXT_NODE) { return iconv('UTF-8', 'ISO-8859-2', $data->firstChild->nodeValue); } $ret = array(); foreach ($data->childNodes as $var) { $value = $var->nodeType == XML_ELEMENT_NODE && !$var->hasChildNodes() ? '' : parse_data($var); if ($var->nodeType == XML_ELEMENT_NODE && $var->hasAttribute('name')) { $ret[$var->getAttribute('name')] = $value; } else { $ret[] = $value; } } return $ret; }
$row['doc_number'] = docnumber($row['number'], $row['template'] ? $row['template'] : '%N/LMS/%Y', $row['cdate']); $recipient_mail = $debug_email ? $debug_email : $row['email']; if (!$quiet) { printf("[deadline] %s (%04d) %s: %s\n", $row['name'], $row['id'], $row['doc_number'], $recipient_mail); } if (!$debug) { send_message($msgid, $row['id'], $recipient_mail, $row['name'], $deadline_subject, parse_data($deadline_message, $row), $host, $port, $user, $pass, $auth); } } } } // Debit notes created up to 24 hours ago if ($notes_message && (empty($types) || in_array('notes', $types))) { $documents = $DB->GetAll("SELECT d.id AS docid, c.id, c.pin, d.name,\n\t\td.number, n.template, d.cdate, c.email,\n\t\tCOALESCE(ca.balance, 0) AS balance, v.value\n\t\tFROM documents d\n\t\tJOIN customers c ON (c.id = d.customerid)\n\t\tJOIN (SELECT SUM(value) * -1 AS value, docid\n\t\t\tFROM cash\n\t\t\tGROUP BY docid\n\t\t) v ON (v.docid = d.id)\n\t\tLEFT JOIN numberplans n ON (d.numberplanid = n.id)\n\t\tLEFT JOIN (SELECT SUM(value) AS balance, customerid\n\t\t\tFROM cash\n\t\t\tGROUP BY customerid\n\t\t) ca ON (ca.customerid = d.customerid)\n\t\tWHERE c.email <> '' AND d.type = 5\n\t\t\tAND d.cdate > ?NOW? - 86400"); if (!empty($documents)) { if (!$debug) { $msgid = create_message($notes_subject, $notes_message); } foreach ($documents as $row) { $row['doc_number'] = docnumber($row['number'], $row['template'] ? $row['template'] : '%N/LMS/%Y', $row['cdate']); $recipient_mail = $debug_email ? $debug_email : $row['email']; if (!$quiet) { printf("[new debit note] %s (%04d) %s: %s\n", $row['name'], $row['id'], $row['doc_number'], $recipient_mail); } if (!$debug) { send_message($msgid, $row['id'], $recipient_mail, $row['name'], $notes_subject, parse_data($notes_message, $row), $host, $port, $user, $pass, $auth); } } } } $DB->Destroy();
} if (!$debug) { send_message($msgid, $row['id'], $phone, parse_data($deadline_message, $row), $script_service); } } } } } // Debit notes created up to 24 hours ago if ($notes_message && (empty($types) || in_array('notes', $types))) { $documents = $DB->GetAll("SELECT d.id AS docid, c.id, c.pin, d.name,\n\t\td.number, n.template, d.cdate, x.phone,\n\t\tCOALESCE(ca.balance, 0) AS balance, v.value\n\t\tFROM documents d\n\t\tJOIN customers c ON (c.id = d.customerid)\n\t\tJOIN (SELECT " . $DB->GroupConcat('contact') . " AS phone, customerid\n\t\t\tFROM customercontacts\n\t\t\tWHERE (type & ?) = ?\n\t\t\tGROUP BY customerid\n\t\t) x ON (x.customerid = d.customerid)\n\t\tJOIN (SELECT SUM(value) * -1 AS value, docid\n\t\t\tFROM cash\n\t\t\tGROUP BY docid\n\t\t) v ON (v.docid = d.id)\n\t\tLEFT JOIN numberplans n ON (d.numberplanid = n.id)\n\t\tLEFT JOIN (SELECT SUM(value) AS balance, customerid\n\t\t\tFROM cash\n\t\t\tGROUP BY customerid\n\t\t) ca ON (ca.customerid = d.customerid)\n\t\tWHERE d.type = 5\n\t\t\tAND d.cdate > ?NOW? - 86400\n\t\t\tAND c.mailingnotice = 1", array(CONTACT_MOBILE | CONTACT_DISABLED, CONTACT_MOBILE)); if (!empty($documents)) { if (!$debug) { $msgid = create_message($notes_subject, $notes_message); } foreach ($documents as $row) { $row['doc_number'] = docnumber($row['number'], $row['template'] ? $row['template'] : '%N/LMS/%Y', $row['cdate']); $row['phone'] = $debug_sms ? $debug_sms : $row['phone']; $phones = explode(',', $row['phone']); foreach ($phones as $phone) { if (!$quiet) { printf("[new debit note] %s (%04d) %s: %s" . PHP_EOL, $row['name'], $row['id'], $row['doc_number'], $phone); } if (!$debug) { send_message($msgid, $row['id'], $phone, parse_data($notes_message, $row), $script_service); } } } } } $DB->Destroy();
function send_message($mode, $id, $message, $msgid, $oplata = 0) { #echo "send_message:\n"; global $LMS, $DB, $tmpl, $debug_email, $test, $divisor, $force; $customer = $LMS->GetCustomer($id); if ($mode == 'e-mail') { $emails = $customer['emails']; #print_r($emails); if (is_array($emails)) { foreach ($emails as $email) { $body = parse_data($id, $tmpl['message'], $customer); $name = $customer['lastname'] . ' ' . $customer['name']; $email = $debug_email ? $debug_email : $email['email']; if (!$test) { $result = send_email($msgid, $customer['id'], $email, $name, $tmpl['name'], $body); } $message .= " {$result}\n"; } } else { if ($test) { $message .= " Brak e-maila!\n"; } else { $message = ''; } } } elseif ($mode == 'sms') { $data = parse_data($id, $tmpl['message'], $customer); #echo $data."\n"; $sms = 0; if (!is_array($customer['contacts'])) { if ($test) { return $message . " Brak nr telefonów!\n"; } } foreach ($customer['contacts'] as $contact) { if ($contact['type'] == 1) { $sms = 1; if (!$test) { $result = send_sms($msgid, $customer['id'], $contact['phone'], $data); } $message .= ' ' . $contact['phone']; if ($oplata) { if (!$test) { $add = array('value' => -ConfigHelper::getConfig('finances.sms_cost'), 'userid' => 0, 'customerid' => $customer['id'], 'comment' => 'Opłata za monitorowanie płatności - SMS'); if ($LMS->AddBalance($add)) { $message .= ' [K]'; } } } } } if (!$sms) { if ($test) { $message .= " Brak nr komórkowych!\n"; } else { $message = ''; } } else { $message .= "\n"; } } else { $warning = 0; $access = 1; $nodes = $LMS->GetCustomerNodes($customer['id']); $groups = $LMS->CustomergroupGetForCustomer($customer['id']); if (count($groups)) { foreach ($groups as $group) { if ($group['name'] == 'SILENT') { #return(''); #opcja: return "S " . $message . "\n"; } } } if (count($nodes)) { foreach ($nodes as $node) { $access *= $node['access']; if ($node['warning']) { $warning = 1; } } } if (!$access) { #return(''); #opcja: $message = "! " . $message . "\n"; } elseif ($warning and !$force) { #return(''); #opcja: $message = "* " . $message . "\n"; } else { if (!$test) { $DB->Execute("UPDATE customers SET message='" . $tmpl['message'] . "' WHERE id=" . $customer['id']); $LMS->NodeSetWarnU($customer['id'], 1); } if ($force) { if ($warning) { $message = "F " . $message . "\n"; } else { $message = " " . $message . "\n"; } } else { $message = " " . $message . "\n"; } } } return $message; }
function authenticate($items) { global $exec_list; global $admin_data; global $admin_is_sock; global $admin_accounts; global $admin_aliases; global $operator_aliases; term_echo("[32mdetected cmd 330: {$admin_data}[0m"); $parts = explode(" ", $items["params"]); if ($admin_data != "") { if (count($parts) == 3 and $parts[0] == get_bot_nick()) { $nick = $parts[1]; $account = $parts[2]; $admin_items = parse_data($admin_data); $args = explode(" ", $admin_items["trailing"]); $alias = $args[0]; if ($admin_items["nick"] == $nick) { if (is_operator_alias($alias) == True) { if ($account != OPERATOR_ACCOUNT) { term_echo("authentication failure: \"{$account}\" attempted to run \"{$alias}\" but is not authorized"); } else { $tmp_data = $admin_data; $tmp_is_sock = $admin_is_sock; $admin_data = ""; $admin_is_sock = ""; handle_data($tmp_data, $tmp_is_sock, True); return; } } elseif (in_array($alias, $admin_aliases) == True) { if ($account != OPERATOR_ACCOUNT and in_array($account, $admin_accounts) == False) { term_echo("authentication failure: \"{$account}\" attempted to run \"{$alias}\" but is not authorized"); } else { $tmp_data = $admin_data; $tmp_is_sock = $admin_is_sock; $admin_data = ""; $admin_is_sock = ""; handle_data($tmp_data, $tmp_is_sock, True); return; } } elseif (has_account_list($alias) == True) { if ($account != OPERATOR_ACCOUNT and in_array($account, $exec_list[$alias]["accounts"]) == False and $exec_list[$alias]["accounts_wildcard"] != "*" and in_array($account, $admin_accounts) == False) { term_echo("authentication failure: \"{$account}\" attempted to run \"{$alias}\" but is not authorized"); } else { $tmp_data = $admin_data; $tmp_is_sock = $admin_is_sock; $admin_data = ""; $admin_is_sock = ""; handle_data($tmp_data, $tmp_is_sock, True); return; } } } } } $admin_data = ""; $admin_is_sock = ""; }
function handle_bot_data($data, $bot_nick) { $items = parse_data($data); if ($items !== False) { term_echo("MINION_CMD_{$bot_nick} bucket set"); set_bucket("MINION_CMD_{$bot_nick}", $data); } else { term_echo("invalid command \"{$data}\""); } }
function load_data($_filters) { global $ss, $field_names; $fields = array_keys($field_names); $yr = intval($_filters['yr']); $mo = intval($_filters['mo']); $dy = isset($_filters['dy']) ? intval($_filters['dy']) : false; // work out date range $d0 = $dy ? $dy : 1; $dn = $dy ? $dy : days_in_month($mo, $yr); $start_ts = gmmktime(0, 0, 0, $mo, $d0, $yr); $end_ts = gmmktime(0, 0, 0, $mo, $dn, $yr); $start_date = gmdate('Y-m-d', $start_ts); $end_date = gmdate('Y-m-d', $end_ts); $date_query = $start_date == $end_date ? "`date` = '{$start_date}'" : "`date` >= '{$start_date}' AND `date` <= '{$end_date}'"; $query = "SELECT * FROM `{$ss->tables['visits']}` WHERE `browser` != '1' AND {$date_query}"; // ignore robots for the overview foreach ($fields as $key) { if (!isset($_filters[$key])) { continue; } $v = $ss->esc($_filters[$key]); // resource is tricky if ($key == 'resource') { $query .= " AND `{$key}` LIKE '% {$v}%'"; } else { $query .= " AND `{$key}` = '{$v}'"; } } $result = $ss->query($query); // we also need date/time data for visits $extra_fields = isset($_filters['dy']) ? array('start_time') : array('date'); return parse_data($result, array_merge($fields, $extra_fields), $_filters); }
function format_data_str($data, $formato, $locale = 'pt_BR') { $data = trim($data); setlocale(LC_ALL, $locale); $timestamp = parse_data($data, $locale); if ($timestamp > 0) { if (preg_match('|%|', $formato)) { return strftime($formato, $timestamp); } else { return date($formato, $timestamp); } } else { return false; } }
echo "<tr><td>"; } else { echo "<tr class='oddrow'><td>"; } echo $referrer["source"] . "</td><td class='visits'>" . number_format($referrer["visits"]) . "</td.</tr>"; $table_row++; } echo "</table>"; // For each website, get visits graph data if ($visits_graph_type == "date") { $requrlvisitsgraph = sprintf("https://www.google.com/analytics/feeds/data?ids=%s&dimensions=ga:date&metrics=ga:visits&start-date=%s&end-date=%s", $tableId, $start_date, $end_date); } else { $requrlvisitsgraph = sprintf("https://www.google.com/analytics/feeds/data?ids=%s&dimensions=ga:month,ga:year&metrics=ga:visits&sort=ga:year&start-date=%s&end-date=%s", $tableId, $start_date, $end_date); } $visitsgraphxml = call_api($_SESSION['sessionToken'], $requrlvisitsgraph); $visitsgraph = parse_data($visitsgraphxml); ?> <script type="text/javascript"> function drawPieChart() { var data = new google.visualization.DataTable(); data.addColumn('string', 'Referrer'); data.addColumn('number', 'Visits'); data.addRows(<?php echo sizeof($referrers); ?> ); <?php $row = 0; foreach ($referrers as $referrer) {
<?php /* 根据get表单的code值, * 从网页获取用户信息*/ require_once "common_inc.php"; require_once "libs/ezSQL_init.php"; try { $post_data = file_get_contents("php://input"); //读取发来的json数据 $_js = json_decode($post_data, true); if (is_array($_js)) { parse_data($_js); } else { echo_error(10001); //JSON数据格式错误 } } catch (Exception $e) { echo_error(10003); //PHP异常 } //回复错误信息 function echo_error($code) { $arr = array("result" => "ERROR", "code" => $code); $json = json_encode($arr); echo $json; } //回复登录成功 function echo_success($fds) { $arr = array("result" => "OK", "code" => 10000, "fds" => $fds);