/** * 通过Cookie_Key解密数据或数组 * @param $data * @return array|string */ public function de($data) { if ($data === NULL) { return $data; } return is_array($data) ? array_map(array($this, 'de'), $data) : $this->safe->decrypt($data, $this->key); }
public function inputExists( Safe $inputType = null, Safe $inputName, Safe $inputDefault = null ){ if( $inputType !== null ){ $inputType = $inputType->toString(); } if( $inputDefault !== null ){ $inputDefault = $inputDefault->toString(); } foreach( $this->_inputArray as $inputArray ){ if( $inputArray['inputType'] == $inputType && $inputArray['inputName'] == $inputName->toString() && $inputArray['inputDefault'] == $inputDefault ){ return true; } } return false; }
/** * 通过邮箱找回密码 * @method POST_emailAction * @author NewFuture */ public function POST_emailAction() { $response['status'] = 0; if (!Input::post('email', $email, 'email')) { $response['info'] = '邮箱格式有误或者不支持!'; } elseif (!Input::post('account', $account, Config::get('regex.account'))) { $response['info'] = '学号格式有误!'; } elseif (!Safe::checkTry('pwd_email_' . $account)) { $response['info'] = '尝试次数过多,临时封禁!'; } elseif (!($Printer = PrinterModel::where('account', $account)->field('id,email')->find())) { $response['info'] = '尚未注册,或者账号错误'; } elseif (empty($Printer['email'])) { $response['info'] = '未绑定邮箱,或邮箱不存在'; } elseif ($Printer['email'] != $email) { $response['info'] = '绑定邮箱不一致,或者邮箱错误'; } elseif (!Mail::findPwd($email, $code = Random::code(6))) { $response['info'] = '邮件发送出错,请联系我们!'; } else { /*发送成功*/ $find = ['id' => $user['id'], 'account' => $account, 'code' => strtoupper($code)]; Session::set('find_info_p', $find); Safe::del('pwd_email_' . $account); $response['status'] = 1; $response['info'] = '验证邮件已发送!'; } $this->response = $response; }
/** * 通过邮箱找回密码 * @method POST_emailAction * @author NewFuture */ public function POST_emailAction() { $response['status'] = 0; if (!Input::post('email', $email, 'email')) { $response['info'] = '邮箱格式有误或者不支持!'; } elseif (!Input::post('number', $number, 'card')) { $response['info'] = '学号格式有误!'; } elseif (!Safe::checkTry('pwd_email_' . $number)) { $response['info'] = '尝试次数过多,临时封禁!'; } elseif (!($user = UserModel::where('number', $number)->field('id,name,email')->find())) { $response['info'] = '尚未注册,或者学号错误'; } elseif (empty($user['email'])) { $response['info'] = '未绑定邮箱,或者学号错误'; } elseif (Encrypt::decryptEmail($user['email']) != $email) { $response['info'] = '绑定邮箱不一致,或者邮箱错误'; } elseif (!Mail::findPwd($email, $code = Random::code(6), $user['name'])) { $response['info'] = '邮件发送出错,请联系我们!'; } else { /*发送成功*/ $findPwd = ['id' => $user['id'], 'number' => $number, 'code' => strtoupper($code)]; Session::set('find_info', $findPwd); Safe::del('pwd_email_' . $number); $response['status'] = 1; $response['info'] = '找回验证码已发送到' . $email; } $this->response = $response; }
/** * 登录注册验证 * @method indexAction * @return [type] [description] * @author NewFuture */ public function indexAction() { if (Input::post('number', $number, 'card') && Input::post('password', $password, 'trim')) { Input::post('sch_id', $sch_id, 'int'); $safekey = $sch_id . 'auth_' . $number; if (!Safe::checkTry($safekey, 5)) { $this->response(0, '尝试次过度,账号临时封禁'); } elseif (Input::post('code', $code, 'ctype_alnum')) { /*输入验证码直接验证*/ if ($this->verify($number, $password, $sch_id, $code)) { /*验证通过*/ Safe::del($safekey); } else { $this->response(-1, '学校账号验证失败,请检查密码是否正确,您也可尝试登录该系统!'); } } elseif ($result = $this->login($number, md5($password), $sch_id)) { /*登录成功*/ Safe::del($safekey); } elseif ($sch_id && false === $result) { /*指定学校后登录失败*/ $this->response(-1, '登录失败!请检查学号和密码是否正确,或者找回密码!'); } elseif ($this->verify($number, $password, $sch_id)) { /*验证成功*/ Safe::del($safekey); } else { /*注册验证失败*/ $this->response(-1, '验证出错,请检查学号或者密码是否正确!'); } } else { $this->response(-1, '学号或者密码无效!'); } }
/** * 通过Cookie_Key解密数据或数组 * * @param $data * @return array|string */ public function de($data) { if ($data === null) { return $data; } return is_array($data) ? array_map(array($this, 'de'), $data) : Safe::decrypt($data, COOKIE_KEY); }
function check_file($node) { global $context; global $footprints; $key = substr($node, strlen($context['path_to_root'])); // no extension to check if (strpos($key, '.') === FALSE) { } elseif (!strncmp($node, 'scripts/staging', 16)) { } elseif (!strcmp($key, 'footprints.php')) { } elseif (!strncmp(substr($key, -9), 'index.php', 9) && ($content = Safe::file_get_contents($node)) && !strcmp($content, Safe::mkdir_index_content())) { } elseif (!strncmp($key, 'temporary/cache_i18n_locale_', 28)) { } elseif (!strncmp(substr($key, -4), '.php', 4)) { // one of the parameter files created by yacs if (preg_match('/parameters\\/(agents|control|feeds|files|hooks|letters|root|scripts|services|skins|users|virtual_.+)\\.include\\.php$/i', $key)) { } elseif (isset($footprints[$key])) { $expected = $footprints[$key]; $actual = Scripts::hash($node); if ($expected[0] != $actual[0] || $expected[1] != $actual[1]) { $context['text'] .= sprintf(i18n::s('ERROR: File %s is missing or corrupted.'), $key) . BR . "\n"; } } else { $context['text'] .= sprintf(i18n::s('File %s is not part of Yacs.'), $key) . BR . "\n"; } // not a safe file } elseif (!preg_match('/\\.(bak|bat|css|done|dtd|fdb|flv|gif|ico|jpeg|jpg|js|jsmin|htc|htm|html|mo|off|on|pdf|png|po|pot|reg|sh|sql|swf|tgz|txt|xml|zip)$/i', $key)) { $context['text'] .= sprintf(i18n::s('File %s is not part of Yacs.'), $key) . BR . "\n"; } }
/** * render graphviz object * * @return string the rendered text **/ public function render($matches) { global $context; list($text, $variant) = $matches; // sanity check if (!$text) { $text = 'Hello->World!'; } // remove tags put by WYSIWYG editors $text = strip_tags(str_replace(array('>', '<', '&', '"', '\\"'), array('>', '<', '&', '"', '"'), str_replace(array('<br />', '</p>'), "\n", $text))); // build the .dot content switch ($variant) { case 'digraph': default: $text = 'digraph G { ' . $text . ' }' . "\n"; break; } // id for this object $hash = md5($text); // path to cached files $path = $context['path_to_root'] . 'temporary/graphviz.'; // we cache content if ($content = Safe::file_get_contents($path . $hash . '.html')) { return $content; } // build a .dot file if (!Safe::file_put_contents($path . $hash . '.dot', $text)) { $content = '[error writing .dot file]'; return $content; } // process the .dot file if (isset($context['dot.command'])) { $command = $context['dot.command']; } else { $command = 'dot'; } // $font = '"/System/Library/Fonts/Times.dfont"'; // $command = '/sw/bin/dot -v -Nfontname='.$font $command .= ' -Tcmapx -o "' . $path . $hash . '.map"' . ' -Tpng -o "' . $path . $hash . '.png"' . ' "' . $path . $hash . '.dot"'; if (Safe::shell_exec($command) == NULL) { $content = '[error while using graphviz]'; return $content; } // produce the HTML $content = '<img src="' . $context['url_to_root'] . 'temporary/graphviz.' . $hash . '.png" usemap="#mainmap" />'; $content .= Safe::file_get_contents($path . $hash . '.map'); // put in cache Safe::file_put_contents($path . $hash . '.html', $content); // done return $content; }
/** * login * * The script checks provided name and password against remote server. * * This is done by transmitting the user name and the password * while opening a FTP session to the server. * * @param string the nickname of the user * @param string the submitted password * @return TRUE on succesful authentication, FALSE othewise */ function login($name, $password) { global $context; // we need some parameters if (!isset($this->attributes['authenticator_parameters']) || !$this->attributes['authenticator_parameters']) { Logger::error(i18n::s('Please provide parameters to the authenticator.')); return FALSE; } // prepare network parameters $server = $this->attributes['authenticator_parameters']; if (strstr($server, ':')) { list($server, $port) = explode(':', $server, 2); } else { $port = 21; } // open network socket if (!($handle = Safe::fsockopen($server, $port))) { Logger::error(sprintf(i18n::s('Impossible to connect to %.'), $this->attributes['authenticator_parameters'])); return FALSE; } // read welcome banner if (!($line = fgets($handle, 256)) || !strstr($line, '2')) { fclose($handle); Logger::error(sprintf(i18n::s('Invalid banner message from %s.'), $this->attributes['authenticator_parameters'])); return FALSE; } // submit name fputs($handle, "USER {$username}\r\n"); if (!($line = fgets($handle, 256)) || !strstr($line, '3')) { fclose($handle); Logger::error(sprintf(i18n::s('Impossible to submit name to %s.'), $this->attributes['authenticator_parameters'])); return FALSE; } // submit password fputs($handle, "PASS {$password}\r\n"); if (!($line = fgets($handle, 256)) || !strstr($line, '2')) { fclose($handle); Logger::error(sprintf(i18n::s('Impossible to submit password to %s.'), $this->attributes['authenticator_parameters'])); return FALSE; } // close ftp session fputs($handle, "QUIT\r\n"); fclose($handle); // this is a valid user return TRUE; }
/** * check access rights * * @param string script name * @paral string target anchor, if any * @return boolean FALSE if access is denied, TRUE otherwise */ function allow($script, $anchor = NULL) { global $context; // limit the scope of our check if ($script != 'files/view.php' && $script != 'files/fetch.php' && $script != 'files/fetch_all.php' && $script != 'files/stream.php') { return TRUE; } // sanity check if (!$anchor) { die(i18n::s('No anchor has been found.')); } // stop here if the agreement has been gathered previously if (isset($_SESSION['agreements']) && is_array($agreements = $_SESSION['agreements'])) { foreach ($agreements as $agreement) { if ($agreement == $anchor) { return TRUE; } } } // which agreement? if (!$this->parameters) { die(sprintf(i18n::s('No parameter has been provided to %s'), 'behaviors/agree_on_file_access')); } // do we have a related file to display? if (!is_readable($context['path_to_root'] . 'behaviors/agreements/' . $this->parameters)) { die(sprintf(i18n::s('Bad parameter to behavior <code>%s %s</code>'), 'agree_on_file_access', $this->parameters)); } // splash message $context['text'] .= '<p class="agreement">' . i18n::s('Before moving forward, please read following text and express yourself at the end of the page.') . '</p><hr/>' . "\n"; // load and display the file to be displayed $context['text'] .= Codes::beautify(Safe::file_get_contents($context['path_to_root'] . 'behaviors/agreements/' . $this->parameters)); // target link to record agreement if ($context['with_friendly_urls'] == 'Y') { $agree_link = 'behaviors/agreements/agree.php/' . rawurlencode($anchor); } else { $agree_link = 'behaviors/agreements/agree.php?id=' . urlencode($anchor); } // display confirmation buttons at the end of the agreement $context['text'] .= '<hr/><p class="agreement">' . i18n::s('Do you agree?'); $context['text'] .= ' ' . Skin::build_link($agree_link, i18n::s('Yes'), 'button'); $context['text'] .= ' ' . Skin::build_link('behaviors/agreements/deny.php', i18n::s('No'), 'button') . '</p>' . "\n"; // render the skin based only on text provided by this behavior render_skin(); exit; }
/** * 打印店登录 * @method loginAction * @return [type] [description] * @author NewFuture */ public function POST_indexAction() { $response['status'] = 0; if (!Input::post('account', $account, Config::get('regex.account'))) { $response['info'] = '账号格式错误'; } elseif (!Input::post('password', $password, 'isMd5')) { $response['info'] = '密码未加密处理'; } elseif (!Safe::checkTry('printer_auth_' . $account)) { $response['info'] = '尝试次数过多账号临时封禁,稍后重试或者联系我们'; } elseif (!($Printer = PrinterModel::where('account', $account)->field('id,sch_id,password,status,name')->find())) { $response['info'] = '账号错误'; } elseif (Encrypt::encryptPwd($password, $account) != $Printer['password']) { $response['info'] = '密码错误'; } else { Safe::del('printer_auth_' . $account); unset($Printer['password']); $sid = Session::start(); Session::set('printer', ['id' => $Printer['id'], 'sch_id' => $Printer['sch_id']]); $response['status'] = 1; $response['info'] = ['sid' => $sid, 'printer' => $Printer]; } $this->response = $response; }
// build the form $context['text'] .= Skin::build_form($fields); // the submit button $context['text'] .= '<p>' . Skin::build_submit_button(i18n::s('Send'), i18n::s('Press [s] to submit data'), 's') . '</p>' . "\n"; // end of the form $context['text'] .= '</div></form>'; // the script used for form handling at the browser Page::insert_script('func' . 'tion validateDocumentPost(container) {' . "\n" . ' // letter_title is mandatory' . "\n" . ' if(!container.letter_title.value) {' . "\n" . ' alert("' . i18n::s('No title has been provided.') . '");' . "\n" . ' Yacs.stopWorking();' . "\n" . ' return false;' . "\n" . ' }' . "\n" . ' return true;' . "\n" . '}' . "\n" . "\n" . 'document.main_form.letter_title.focus();' . "\n"); // no mail in demo mode } elseif (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST' && file_exists($context['path_to_root'] . 'parameters/demo.flag')) { Safe::header('Status: 401 Unauthorized', TRUE, 401); Logger::error(i18n::s('You are not allowed to perform this operation in demonstration mode.')); // handle posted data } elseif (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST') { // ensure all letters will be sent even if the browser connection dies Safe::ignore_user_abort(TRUE); // always archive the letter $anchor = Sections::lookup('letters'); // no section yet, create one if (!$anchor) { $context['text'] .= i18n::s('Creating a section for archived letters') . BR . "\n"; $fields['nick_name'] = 'letters'; $fields['title'] = i18n::c('Archived letters'); $fields['introduction'] = i18n::c('To remember our previous messages'); $fields['description'] = i18n::c('YACS puts automatically sent letters into this section.'); $fields['locked'] = 'Y'; // no direct contributions $fields['index_map'] = 'N'; // listed only to associates $fields['rank'] = 30000; // at the end of the list
} elseif (!$permitted) { Safe::header('Status: 401 Unauthorized', TRUE, 401); Logger::error(i18n::s('You are not allowed to perform this operation.')); // deletion is confirmed } elseif (isset($_REQUEST['confirm']) && $_REQUEST['confirm'] == 'yes') { // touch the related anchor before actual deletion, since the table has to be accessible at that time if (is_object($anchor)) { $anchor->touch('table:delete', $item['id']); } // delete and go back to the anchor or to the index page if (Tables::delete($item['id'])) { Tables::clear($item); if (is_object($anchor)) { Safe::redirect($context['url_to_home'] . $context['url_to_root'] . $anchor->get_url()); } else { Safe::redirect($context['url_to_home'] . $context['url_to_root'] . 'articles/'); } } // deletion has to be confirmed } elseif (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST') { Logger::error(i18n::s('The action has not been confirmed.')); } else { // commands $menu = array(); $menu[] = Skin::build_submit_button(i18n::s('Yes, I want to delete this table'), NULL, NULL, 'confirmed'); if (is_object($anchor)) { $menu[] = Skin::build_link($anchor->get_url(), i18n::s('Cancel'), 'span'); } // the submit button $context['text'] .= '<form method="post" action="' . $context['script_url'] . '" id="main_form"><p>' . "\n" . Skin::finalize_list($menu, 'menu_bar') . '<input type="hidden" name="id" value="' . $item['id'] . '" />' . "\n" . '<input type="hidden" name="confirm" value="yes" />' . "\n" . '</p></form>' . "\n"; // set the focus
/** * encode a sequence of HTML tags, or plain text, to PDF * * @param string the text to append * @return the content of PDF * @see articles/fetch_as_pdf.php */ function encode($text) { global $context; // // meta information // // encode it to iso8859 -- sorry // document title if ($context['page_title']) { $this->SetTitle(utf8::to_iso8859(Safe::html_entity_decode($context['page_title'], ENT_COMPAT, 'ISO-8859-15'))); } // document author if ($context['page_author']) { $this->SetAuthor(utf8::to_iso8859(Safe::html_entity_decode($context['page_author'], ENT_COMPAT, 'ISO-8859-15'))); } // document subject if ($context['subject']) { $this->SetSubject(utf8::to_iso8859(Safe::html_entity_decode($context['subject'], ENT_COMPAT, 'ISO-8859-15'))); } // document creator (typically, the tool used to produce the document) $this->SetCreator('yacs'); // // PDF content // // start the rendering engine $this->AliasNbPages(); $this->AddPage(); $this->SetFont('Arial', 'B', 16); // reference view.php instead of ourself to achieve correct links $text = str_replace('/fetch_as_pdf.php', '/view.php', $text); // remove all unsupported tags $text = strip_tags($text, "<a><b><blockquote><br><code><div><em><font><h1><h2><h3><h4><hr><i><img><li><p><pre><strong><table><tr><tt><u><ul>"); // spaces instead of carriage returns $text = str_replace("\n", ' ', $text); // transcode to ISO8859-15 characters $text = utf8::to_iso8859(Safe::html_entity_decode($text, ENT_COMPAT, 'ISO-8859-15')); // locate every HTML/XML tag $areas = preg_split('/<(.*)>/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE); $height = 5; $link = ''; foreach ($areas as $index => $entity) { // a tag entity if ($index % 2) { @(list($tag, $attributes) = explode(' ', $entity, 2)); switch (strtolower($tag)) { case 'a': if (preg_match('/href="(.*)"/i', $attributes, $matches)) { $link = $matches[1]; // suppress local references (eg, in table of content) if (preg_match('/(#.*)/', $link)) { $link = ''; } elseif ($link[0] == '/') { $link = $context['url_to_home'] . $link; } } break; case 'b': $this->SetFont('', 'B'); break; case '/b': $this->SetFont('', ''); break; case 'blockquote': $this->Ln($height); break; case '/blockquote': $this->Ln($height); break; case 'br': $this->Ln($height); break; case 'code': $this->SetFont('Courier', '', 11); $this->SetFontSize(11); break; case '/code': $this->SetFont('Times', '', 12); $this->SetFontSize(12); break; case 'div': case '/div': $this->Ln($height); break; case 'em': $this->SetFont('', 'I'); break; case '/em': $this->SetFont('', ''); break; case 'font': if (preg_match('/color="#(.{6})"/i', $attributes, $matches)) { $color = $matches[1]; $r = hexdec($color[0] . $color[1]); $g = hexdec($color[2] . $color[3]); $b = hexdec($color[4] . $color[5]); $this->SetTextColor($r, $g, $b); } break; case 'font': $this->SetFont('Times', '', 12); $this->SetTextColor(0, 0, 0); $this->SetFontSize(12); break; case 'h1': $this->Ln(10); $this->SetTextColor(150, 0, 0); $this->SetFontSize(22); $height = 8; break; case 'h2': $this->Ln(8); $this->SetFontSize(18); $height = 6; break; case 'h3': $this->Ln(6); $this->SetFontSize(16); $height = 5; break; case 'h4': $this->Ln(6); $this->SetTextColor(102, 0, 0); $this->SetFontSize(14); $height = 5; break; case '/h1': case '/h2': case '/h3': case '/h4': $this->Ln($height); $this->SetFont('Times', '', 12); $this->SetTextColor(0, 0, 0); $this->SetFontSize(12); $height = 5; break; case 'hr': $this->Ln($height + 2); $this->Line($this->GetX(), $this->GetY(), $this->GetX() + 187, $this->GetY()); $this->Ln(3); break; case 'i': $this->SetFont('', 'I'); break; case '/i': $this->SetFont('', ''); break; case 'img': // only accept JPG and PNG if (preg_match('/src="([^"]+\\.(jpg|jpeg|png))"/i', $attributes, $matches)) { $image = $matches[1]; // map on a file $image = preg_replace('/^' . preg_quote($context['url_to_home'] . $context['url_to_root'], '/') . '/', $context['path_to_root'], $image); // include the image only if the file exists if ($attributes = Safe::GetImageSize($image)) { // insert an image at 72 dpi -- the k factor $this->Image($image, $this->GetX(), $this->GetY(), $attributes[0] / $this->k, $attributes[1] / $this->k); // make room for the image $this->y += 3 + $attributes[1] / $this->k; } } break; case 'li': $this->Ln($height); break; case '/li': break; case 'p': case '/p': $this->Ln($height); break; case 'pre': $this->SetFont('Courier', '', 11); $this->SetFontSize(11); $preformatted = TRUE; break; case '/pre': $this->SetFont('Times', '', 12); $this->SetFontSize(12); $preformatted = FALSE; break; case 'strong': $this->SetFont('', 'B'); break; case '/strong': $this->SetFont('', ''); break; case 'table': $this->Ln($height); break; case '/table': $this->Ln($height); break; case 'tr': $this->Ln($height + 2); $this->Line($this->GetX(), $this->GetY(), $this->GetX() + 187, $this->GetY()); $this->Ln(3); break; case 'tt': $this->SetFont('Courier', '', 11); $this->SetFontSize(11); break; case '/tt': $this->SetFont('Times', '', 12); $this->SetFontSize(12); break; case 'u': $this->SetFont('', 'U'); break; case '/u': $this->SetFont('', ''); break; case 'ul': break; case '/ul': break; } // a textual entity } else { // we have to write a link if ($link) { // a blue underlined link $this->SetTextColor(0, 0, 255); $this->SetFont('', 'U'); $this->Write($height, $entity, $link); $link = ''; $this->SetTextColor(0, 0, 0); $this->SetFont('', ''); // regular text } else { $this->Write($height, $entity); } } } // return the PDF content as a string return $this->Output('dummy', 'S'); }
$context['text'] .= Skin::build_block(sprintf(i18n::s('Analyzing table %s...'), SQL::table_name('comments')), 'title'); // scan up to 20000 items $count = 0; $query = "SELECT id, anchor FROM " . SQL::table_name('comments') . " ORDER BY anchor LIMIT 0, 100000"; if (!($result = SQL::query($query))) { return; } else { // fetch one anchor and the linked member $errors_count = 0; while ($row = SQL::fetch($result)) { // animate user screen and take care of time $count++; if (!($count % 500)) { $context['text'] .= sprintf(i18n::s('%d records have been processed'), $count) . BR . "\n"; // ensure enough execution time Safe::set_time_limit(30); } // check that the anchor exists, if any if ($row['anchor'] && !Anchors::get($row['anchor'])) { $context['text'] .= sprintf(i18n::s('Orphan: %s'), 'comment ' . Skin::build_link(Comments::get_url($row['id']), $row['id'])) . BR . "\n"; if (++$errors_count >= 5) { $context['text'] .= i18n::s('Too many successive errors. Aborted') . BR . "\n"; break; } } else { $errors_count = 0; } } } // ending message $context['text'] .= sprintf(i18n::s('%d records have been processed'), $count) . BR . "\n";
} if ($file == 'index.php') { continue; } if ($file == 'behavior.php') { continue; } if ($file == 'behaviors.php') { continue; } if (!preg_match('/(.*)\\.php$/i', $file, $matches)) { continue; } $behaviors[] = $matches[1]; } Safe::closedir($dir); if (@count($behaviors)) { natsort($behaviors); foreach ($behaviors as $behavior) { $context['text'] .= '<li>' . $behavior . "</li>\n"; } } } $context['text'] .= '</ul>'; // how to use behaviors if (Surfer::is_associate()) { $context['text'] .= '<p>' . sprintf(i18n::s('For example, if you want to apply the behavior <code>foo</code>, go to the %s , and select a target section, or add a new one.'), Skin::build_link('sections/', i18n::s('site map'), 'shortcut')) . '</p>' . '<p>' . i18n::s('In the form used to edit the section, type the keyword <code>foo</code> in the behavior field, then save changes.') . '</p>'; } // referrals, if any $context['components']['referrals'] =& Skin::build_referrals('behaviors/index.php'); // render the skin
} if (isset($_REQUEST['switch_contact'])) { $content .= '$context[\'switch_contact\']=\'' . addcslashes($_REQUEST['switch_contact'], "\\'") . "';\n"; } $content .= '?>' . "\n"; // save switch parameters, if any if (!Safe::file_put_contents('parameters/switch.include.php', $content)) { // not enough rights to write the file Logger::error(sprintf(i18n::s('Impossible to write to %s.'), 'parameters/switch.include.php.')); // allow for a manual update $context['text'] .= '<p style="text-decoration: blink;">' . sprintf(i18n::s('To actually change the configuration, please copy and paste following lines by yourself in file %s.'), 'parameters/switch.include.php') . "</p>\n"; // display updated parameters $context['text'] .= Skin::build_box(i18n::s('Configuration'), Safe::highlight_string($content), 'folded'); } // rename the switch file if (Safe::rename($context['path_to_root'] . 'parameters/switch.on', $context['path_to_root'] . 'parameters/switch.off')) { Logger::error(i18n::s('The server has been switched OFF. Switch it back on as soon as possible.')); // remember the change $label = i18n::c('The server has been switched off.'); Logger::remember('control/switch.php: ' . $label); // if the server is currently switched off } elseif (file_exists($context['path_to_root'] . 'parameters/switch.off')) { Logger::error(i18n::s('The server is currently switched off. All users are redirected to the closed page.')); } else { Logger::error(i18n::s('Impossible to rename the file parameters/switch.on to parameters/switch.off. Do it yourself manually if you like.')); } // follow-up commands $menu = array(); // do it again if (file_exists($context['path_to_root'] . 'parameters/switch.off')) { $menu = array_merge($menu, array('control/switch.php?action=on' => i18n::s('Switch on')));
// not found if (!$item['id']) { include '../error.php'; // permission denied } elseif (!$permitted) { // anonymous users are invited to log in or to register if (!Surfer::is_logged()) { Safe::redirect($context['url_to_home'] . $context['url_to_root'] . 'users/login.php?url=' . urlencode(Servers::get_url($item['id']))); } // permission denied to authenticated user Safe::header('Status: 401 Unauthorized', TRUE, 401); Logger::error(i18n::s('You are not allowed to perform this operation.')); // re-enforce the canonical link } elseif ($context['self_url'] && ($canonical = $context['url_to_home'] . $context['url_to_root'] . Servers::get_url($item['id'])) && strncmp($context['self_url'], $canonical, strlen($canonical))) { Safe::header('Status: 301 Moved Permanently', TRUE, 301); Safe::header('Location: ' . $canonical); Logger::error(Skin::build_link($canonical)); // display the server profile } else { $text = ''; // initialize the rendering engine Codes::initialize(Servers::get_url($item['id'])); // the nick name if ($item['host_name'] && Surfer::is_associate()) { $details[] = '"' . $item['host_name'] . '"'; } // information on last update if ($item['edit_name']) { $details[] = sprintf(i18n::s('edited by %s %s'), Users::get_link($item['edit_name'], $item['edit_address'], $item['edit_id']), Skin::build_date($item['edit_date'])); } // restricted to logged members
} elseif (isset($context['arguments'][0])) { $search = $context['arguments'][0]; } $search = strip_tags($search); // search type $type = ''; if (isset($_REQUEST['type'])) { $type = $_REQUEST['type']; } $type = strip_tags($type); // load localized strings i18n::bind('services'); // load a skin engine load_skin('services'); // loads feeding parameters Safe::load('parameters/feeds.include.php'); // set default values if (!$context['channel_title']) { $context['channel_title'] = $context['site_name']; } if (!$context['channel_description']) { $context['channel_description'] = $context['site_description']; } // channel attributes $values = array(); $values['channel'] = array(); // set channel information if ($search) { $values['channel']['title'] = sprintf(i18n::s('%s at %s'), $search, $context['channel_title']); } else { $values['channel']['title'] = $context['channel_title'];
/** * embed an interactive object * * The id designates the target file. * It can also include width and height of the target canvas, as in: '12, 100%, 250px' * * @param string id of the target file * @return string the rendered string **/ public static function render_embed($id) { global $context; // split parameters $attributes = preg_split("/\\s*,\\s*/", $id, 4); $id = $attributes[0]; // get the file if (!($item = Files::get($id))) { $output = '[embed=' . $id . ']'; return $output; } // stream in a separate page if (isset($attributes[1]) && preg_match('/window/i', $attributes[1])) { if (!isset($attributes[2])) { $attributes[2] = i18n::s('Play in a separate window'); } $output = '<a href="' . $context['url_to_home'] . $context['url_to_root'] . Files::get_url($item['id'], 'stream', $item['file_name']) . '" onclick="window.open(this.href); return false;" class="button"><span>' . $attributes[2] . '</span></a>'; return $output; } // file extension $extension = strtolower(substr($item['file_name'], -3)); // set a default size if (!isset($attributes[1])) { if (!strcmp($extension, 'gan')) { $attributes[1] = '98%'; } elseif (!strcmp($extension, 'mm') && isset($context['skins_freemind_canvas_width'])) { $attributes[1] = $context['skins_freemind_canvas_width']; } else { $attributes[1] = 480; } } if (!isset($attributes[2])) { if (!strcmp($extension, 'gan')) { $attributes[2] = '300px'; } elseif (!strcmp($extension, 'mm') && isset($context['skins_freemind_canvas_height'])) { $attributes[2] = $context['skins_freemind_canvas_height']; } else { $attributes[2] = 360; } } // object attributes $width = $attributes[1]; $height = $attributes[2]; $flashvars = ''; if (isset($attributes[3])) { $flashvars = $attributes[3]; } // rendering depends on file extension switch ($extension) { // stream a video case '3gp': case 'flv': case 'm4v': case 'mov': case 'mp4': // a flash player to stream a flash video $flvplayer_url = $context['url_to_home'] . $context['url_to_root'] . 'included/browser/player_flv_maxi.swf'; // file is elsewhere if (isset($item['file_href']) && $item['file_href']) { $url = $item['file_href']; } else { $url = $context['url_to_home'] . $context['url_to_root'] . Files::get_url($item['id'], 'fetch', $item['file_name']); } // pass parameters to the player if ($flashvars) { $flashvars = str_replace('autostart=true', 'autoplay=1', $flashvars) . '&'; } $flashvars .= 'width=' . $width . '&height=' . $height; // if there is a static image for this video, use it if (isset($item['icon_url']) && $item['icon_url']) { $flashvars .= '&startimage=' . urlencode($item['icon_url']); } // if there is a subtitle file for this video, use it if (isset($item['file_name']) && ($srt = 'files/' . str_replace(':', '/', $item['anchor']) . '/' . str_replace('.' . $extension, '.srt', $item['file_name'])) && file_exists($context['path_to_root'] . $srt)) { $flashvars .= '&srt=1&srturl=' . urlencode($context['url_to_home'] . $context['url_to_root'] . $srt); } // if there is a logo file in the skin, use it Skin::define_img_href('FLV_IMG_HREF', 'codes/flvplayer_logo.png', ''); if (FLV_IMG_HREF) { $flashvars .= '&top1=' . urlencode(FLV_IMG_HREF . '|10|10'); } // rely on Flash if (Surfer::has_flash()) { // the full object is built in Javascript --see parameters at http://flv-player.net/players/maxi/documentation/ $output = '<div id="flv_' . $item['id'] . '" class="no_print">Flash plugin or Javascript are turned off. Activate both and reload to view the object</div>' . "\n"; Page::insert_script('var flashvars = { flv:"' . $url . '", ' . str_replace(array('&', '='), array('", ', ':"'), $flashvars) . '", autoload:0, margin:1, showiconplay:1, playeralpha:50, iconplaybgalpha:30, showfullscreen:1, showloading:"always", ondoubleclick:"fullscreen" }' . "\n" . 'var params = { allowfullscreen: "true", allowscriptaccess: "always" }' . "\n" . 'var attributes = { id: "file_' . $item['id'] . '", name: "file_' . $item['id'] . '"}' . "\n" . 'swfobject.embedSWF("' . $flvplayer_url . '", "flv_' . $item['id'] . '", "' . $width . '", "' . $height . '", "9", "' . $context['url_to_home'] . $context['url_to_root'] . 'included/browser/expressinstall.swf", flashvars, params);' . "\n"); // native support } else { // <video> is HTML5, <object> is legacy $output = '<video width="' . $width . '" height="' . $height . '" autoplay="" controls="" src="' . $url . '" >' . "\n" . ' <object width="' . $width . '" height="' . $height . '" data="' . $url . '" type="' . Files::get_mime_type($item['file_name']) . '">' . "\n" . ' <param value="' . $url . '" name="movie" />' . "\n" . ' <param value="true" name="allowFullScreen" />' . "\n" . ' <param value="always" name="allowscriptaccess" />' . "\n" . ' <a href="' . $url . '">No video playback capabilities, please download the file</a>' . "\n" . ' </object>' . "\n" . '</video>' . "\n"; } // job done return $output; // a ganttproject timeline // a ganttproject timeline case 'gan': // where the file is $path = Files::get_path($item['anchor']) . '/' . rawurlencode($item['file_name']); // we actually use a transformed version of the file $cache_id = Cache::hash($path) . '.xml'; // apply the transformation if (!file_exists($context['path_to_root'] . $cache_id) || filemtime($context['path_to_root'] . $cache_id) < filemtime($context['path_to_root'] . $path) || !($text = Safe::file_get_contents($context['path_to_root'] . $cache_id))) { // transform from GanttProject to SIMILE Timeline $text = Files::transform_gan_to_simile($path); // put in cache Safe::file_put_contents($cache_id, $text); } // load the SIMILE Timeline javascript library in shared/global.php $context['javascript']['timeline'] = TRUE; // cache would kill the loading of the library cache::poison(); // 1 week ago $now = gmdate('M d Y H:i:s', time() - 7 * 24 * 60 * 60); // load the right file $output = '<div id="gantt" style="height: ' . $height . '; width: ' . $width . '; border: 1px solid #aaa; font-family: Trebuchet MS, Helvetica, Arial, sans serif; font-size: 8pt"></div>' . "\n"; Page::insert_script('var simile_handle;' . "\n" . 'function onLoad() {' . "\n" . ' var eventSource = new Timeline.DefaultEventSource();' . "\n" . ' var theme = Timeline.ClassicTheme.create();' . "\n" . ' theme.event.bubble.width = 350;' . "\n" . ' theme.event.bubble.height = 300;' . "\n" . ' var bandInfos = [' . "\n" . ' Timeline.createBandInfo({' . "\n" . ' eventSource: eventSource,' . "\n" . ' date: "' . $now . '",' . "\n" . ' width: "80%",' . "\n" . ' intervalUnit: Timeline.DateTime.WEEK,' . "\n" . ' intervalPixels: 200,' . "\n" . ' theme: theme,' . "\n" . ' layout: "original" // original, overview, detailed' . "\n" . ' }),' . "\n" . ' Timeline.createBandInfo({' . "\n" . ' showEventText: false,' . "\n" . ' trackHeight: 0.5,' . "\n" . ' trackGap: 0.2,' . "\n" . ' eventSource: eventSource,' . "\n" . ' date: "' . $now . '",' . "\n" . ' width: "20%",' . "\n" . ' intervalUnit: Timeline.DateTime.MONTH,' . "\n" . ' intervalPixels: 50' . "\n" . ' })' . "\n" . ' ];' . "\n" . ' bandInfos[1].syncWith = 0;' . "\n" . ' bandInfos[1].highlight = true;' . "\n" . ' bandInfos[1].eventPainter.setLayout(bandInfos[0].eventPainter.getLayout());' . "\n" . ' simile_handle = Timeline.create(document.getElementById("gantt"), bandInfos, Timeline.HORIZONTAL);' . "\n" . ' simile_handle.showLoadingMessage();' . "\n" . ' Timeline.loadXML("' . $context['url_to_home'] . $context['url_to_root'] . $cache_id . '", function(xml, url) { eventSource.loadXML(xml, url); });' . "\n" . ' simile_handle.hideLoadingMessage();' . "\n" . '}' . "\n" . "\n" . 'var resizeTimerID = null;' . "\n" . 'function onResize() {' . "\n" . ' if (resizeTimerID == null) {' . "\n" . ' resizeTimerID = window.setTimeout(function() {' . "\n" . ' resizeTimerID = null;' . "\n" . ' simile_handle.layout();' . "\n" . ' }, 500);' . "\n" . ' }' . "\n" . '}' . "\n" . "\n" . '// observe page major events' . "\n" . '$(document).ready( onLoad);' . "\n" . '$(window).resize(onResize);' . "\n"); // job done return $output; // a Freemind map // a Freemind map case 'mm': // if we have an external reference, use it if (isset($item['file_href']) && $item['file_href']) { $target_href = $item['file_href']; // else redirect to ourself } else { // ensure a valid file name $file_name = utf8::to_ascii($item['file_name']); // where the file is $path = Files::get_path($item['anchor']) . '/' . rawurlencode($item['file_name']); // map the file on the regular web space $url_prefix = $context['url_to_home'] . $context['url_to_root']; // redirect to the actual file $target_href = $url_prefix . $path; } // allow several viewers to co-exist in the same page static $freemind_viewer_index; if (!isset($freemind_viewer_index)) { $freemind_viewer_index = 1; } else { $freemind_viewer_index++; } // load flash player $url = $context['url_to_home'] . $context['url_to_root'] . 'included/browser/visorFreemind.swf'; // variables $flashvars = 'initLoadFile=' . $target_href . '&openUrl=_self'; $output = '<div id="freemind_viewer_' . $freemind_viewer_index . '">Flash plugin or Javascript are turned off. Activate both and reload to view the object</div>' . "\n"; Page::insert_script('var params = {};' . "\n" . 'params.base = "' . dirname($url) . '/";' . "\n" . 'params.quality = "high";' . "\n" . 'params.wmode = "transparent";' . "\n" . 'params.menu = "false";' . "\n" . 'params.flashvars = "' . $flashvars . '";' . "\n" . 'swfobject.embedSWF("' . $url . '", "freemind_viewer_' . $freemind_viewer_index . '", "' . $width . '", "' . $height . '", "6", "' . $context['url_to_home'] . $context['url_to_root'] . 'included/browser/expressinstall.swf", false, params);' . "\n"); // offer to download a copy of the map $menu = array($target_href => i18n::s('Browse this map with Freemind')); // display menu commands below the viewer $output .= Skin::build_list($menu, 'menu_bar'); // job done return $output; // native flash // native flash case 'swf': // where to get the file if (isset($item['file_href']) && $item['file_href']) { $url = $item['file_href']; } else { $url = $context['url_to_home'] . $context['url_to_root'] . 'files/' . str_replace(':', '/', $item['anchor']) . '/' . rawurlencode($item['file_name']); } $output = '<div id="swf_' . $item['id'] . '" class="no_print">Flash plugin or Javascript are turned off. Activate both and reload to view the object</div>' . "\n"; Page::insert_script('var params = {};' . "\n" . 'params.base = "' . dirname($url) . '/";' . "\n" . 'params.quality = "high";' . "\n" . 'params.wmode = "transparent";' . "\n" . 'params.allowfullscreen = "true";' . "\n" . 'params.allowscriptaccess = "always";' . "\n" . 'params.flashvars = "' . $flashvars . '";' . "\n" . 'swfobject.embedSWF("' . $url . '", "swf_' . $item['id'] . '", "' . $width . '", "' . $height . '", "6", "' . $context['url_to_home'] . $context['url_to_root'] . 'included/browser/expressinstall.swf", false, params);' . "\n"); return $output; // link to file page // link to file page default: // link label $text = Skin::strip($item['title'] ? $item['title'] : str_replace('_', ' ', $item['file_name'])); // make a link to the target page $url = Files::get_permalink($item); // return a complete anchor $output =& Skin::build_link($url, $text); return $output; } }
$overlay->attributes[$name][$sub_name] = str_replace('\\', '\\\\', $sub_value); } } else { $overlay->attributes[$name] = str_replace('\\', '\\\\', $value); } } // update the record $item['overlay'] = serialize($overlay->attributes); // touch the related anchor if ($article = Anchors::get('article:' . $item['id'])) { $article->touch('vote', $item['id'], isset($_REQUEST['silent']) && $_REQUEST['silent'] == 'Y'); } // update the database if (!Articles::put($item)) { } elseif ($next && !headers_sent()) { Safe::redirect($next); // ask for manual click } else { $context['text'] .= '<p>' . i18n::s('Thank you for your contribution') . "</p>\n"; // link to the poll, depending on access rights $menu = array(); if ($permitted) { $menu = array_merge($menu, array(Articles::get_permalink($item) => i18n::s('View poll results'))); } // back to the front page $menu = array_merge($menu, array($context['url_to_root'] => i18n::s('Front page'))); $context['text'] .= Skin::build_list($menu, 'menu_bar'); } } // render the skin render_skin();
/** * list articles * * @param resource the SQL result * @return string the rendered text * * @see layouts/layout.php **/ function layout($result) { global $context; // we return some text $text = ''; // empty list if (!SQL::count($result)) { return $text; } // sanity check if (!isset($this->focus)) { $this->focus = 'map'; } // put in cache $cache_id = Cache::hash('articles/layout_articles_as_carrousel:' . $this->focus) . '.xml'; // save for one minute if (!file_exists($context['path_to_root'] . $cache_id) || filemtime($context['path_to_root'] . $cache_id) + 60 < time()) { // content of the slideshow $content = '<?xml version="1.0" encoding="utf-8"?><!-- fhShow Carousel 2.0 configuration file Please visit http://www.flshow.net/ -->' . "\n" . '<slide_show>' . "\n" . ' <options>' . "\n" . ' <debug>false</debug> <!-- true, false -->' . "\n" . ' <background>transparent</background> <!-- #RRGGBB, transparent -->' . "\n" . ' <friction>5</friction> <!-- [1,100] -->' . "\n" . ' <fullscreen>false</fullscreen> <!-- true, false -->' . "\n" . ' <margins>' . "\n" . ' <top>0</top> <!-- [-1000,1000] pixels -->' . "\n" . ' <left>0</left> <!-- [-1000,1000] pixels -->' . "\n" . ' <bottom>0</bottom> <!-- [-1000,1000] pixels -->' . "\n" . ' <right>0</right> <!-- [-1000,1000] pixels -->' . "\n" . ' <horizontal_ratio>20%</horizontal_ratio> <!-- [1,50] a photo may occupy at most horizontalRatio percent of the Carousel width -->' . "\n" . ' <vertical_ratio>90%</vertical_ratio> <!-- [1,100] a photo may occupy at most verticalRatio percent of the Carousel height -->' . "\n" . ' </margins>' . "\n" . ' <interaction>' . "\n" . ' <rotation>mouse</rotation> <!-- auto, mouse, keyboard -->' . "\n" . ' <view_point>none</view_point> <!-- none, mouse, keyboard -->' . "\n" . ' <speed>15</speed> <!-- [-360,360] degrees per second -->' . "\n" . ' <default_speed>15</default_speed> <!-- [-360,360] degrees per second -->' . "\n" . ' <default_view_point>20%</default_view_point> <!-- [0,100] percentage -->' . "\n" . ' <reset_delay>20</reset_delay> <!-- [0,600] seconds, 0 means never reset -->' . "\n" . ' </interaction>' . "\n" . ' <far_photos>' . "\n" . ' <size>50%</size> <!-- [0,100] percentage -->' . "\n" . ' <amount>50%</amount> <!-- [0,100] percentage -->' . "\n" . ' <blur>10</blur> <!-- [0,100] amount -->' . "\n" . ' <blur_quality>3</blur_quality> <!-- [1,3] 1=low - 3=high -->' . "\n" . ' </far_photos>' . "\n" . ' <reflection>' . "\n" . ' <amount>25</amount> <!-- [0,1000] pixels -->' . "\n" . ' <blur>2</blur> <!-- [0,100] blur amount -->' . "\n" . ' <distance>0</distance> <!-- [-1000,1000] pixels -->' . "\n" . ' <alpha>40%</alpha> <!-- [0,100] percentage -->' . "\n" . ' </reflection>' . "\n" . ' <titles>' . "\n" . ' <style>font-size: 14px; font-family: Verdana, _serif; color: #000000;</style>' . "\n" . ' <position>above center</position> <!-- [above, below] [left,center,right]-->' . "\n" . ' <background>' . $context['url_to_home'] . $context['url_to_root'] . 'skins/_reference/layouts/carrousel_bubble.png</background> <!-- image url -->' . "\n" . ' <scale9>35 35 35 35</scale9> <!-- [0,1000] pixels -->' . "\n" . ' <padding>8 15 10 15</padding> <!-- [-1000,1000] pixels -->' . "\n" . ' </titles>' . "\n" . ' </options>' . "\n"; // get a default image if (Safe::GetImageSize($context['path_to_root'] . $context['skin'] . '/layouts/map.gif')) { $default_href = $context['url_to_root'] . $context['skin'] . '/layouts/map.gif'; } elseif ($size = Safe::GetImageSize($context['path_to_root'] . 'skins/_reference/layouts/map.gif')) { $default_href = $context['url_to_root'] . 'skins/_reference/layouts/map.gif'; } else { $default_href = NULL; } // process all items in the list while ($item = SQL::fetch($result)) { // get the related overlay $overlay = Overlay::load($item, 'article:' . $item['id']); // get the anchor $anchor = Anchors::get($item['anchor']); // this is visual if (isset($item['icon_url']) && $item['icon_url']) { $image = $item['icon_url']; } elseif (isset($item['thumbnail_url']) && $item['thumbnail_url']) { $image = $item['thumbnail_url']; } elseif (is_callable(array($anchor, 'get_bullet_url')) && ($image = $anchor->get_bullet_url())) { } elseif ($default_href) { $image = $default_href; } else { continue; } // fix relative path if (!preg_match('/^(\\/|http:|https:|ftp:)/', $image)) { $image = $context['url_to_home'] . $context['url_to_root'] . $image; } // build a title if (is_object($overlay)) { $title = Codes::beautify_title($overlay->get_text('title', $item)); } else { $title = Codes::beautify_title($item['title']); } // the url to view this item $url = Articles::get_permalink($item); // add to the list $content .= ' <photo>' . "\n" . ' <title>' . $title . '</title>' . "\n" . ' <src>' . $image . '</src>' . "\n" . ' <href>' . $url . '</href>' . "\n" . ' <target>_self</target>' . "\n" . ' </photo>' . "\n"; } // finalize slideshow content $content .= '</slide_show>'; // put in cache Safe::file_put_contents($cache_id, $content); } // allow multiple instances static $count; if (!isset($count)) { $count = 1; } else { $count++; } // load the right file $text = '<div id="articles_as_carrousel_' . $count . '"></div>' . "\n"; Page::insert_script('swfobject.embedSWF("' . $context['url_to_home'] . $context['url_to_root'] . 'included/browser/carrousel.swf",' . "\n" . '"articles_as_carrousel_' . $count . '",' . "\n" . '"100%",' . "\n" . '"150",' . "\n" . '"9.0.0",' . "\n" . 'false,' . "\n" . '{xmlfile:"' . $context['url_to_home'] . $context['url_to_root'] . $cache_id . '", loaderColor:"0x666666"},' . "\n" . '{wmode: "transparent"},' . "\n" . '{});' . "\n"); // end of processing SQL::free($result); return $text; }
include_once '../services/rss_codec.php'; $result = rss_Codec::encode($values); $status = @$result[0]; $text = @$result[1]; // save in cache for the next request Cache::put($cache_id, $text, 'articles'); } // // transfer to the user agent // // handle the output correctly render_raw('text/xml; charset=' . $context['charset']); // suggest a name on download if (!headers_sent()) { $file_name = utf8::to_ascii($context['site_name'] . '.section.' . $item['id'] . '.rss.xml'); Safe::header('Content-Disposition: inline; filename="' . str_replace('"', '', $file_name) . '"'); } // enable 30-minute caching (30*60 = 1800), even through https, to help IE6 on download http::expire(1800); // strong validator $etag = '"' . md5($text) . '"'; // manage web cache if (http::validate(NULL, $etag)) { return; } // actual transmission except on a HEAD request if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'HEAD') { echo $text; } // the post-processing hook, then exit finalize_page(TRUE);
/** * create a sparkline * * @param array data to be drawn * @param array parameters */ function build($series, $options) { // 1-line 2-fill 3-line+fill 4-intensity if (empty($options['style'])) { $this->style = 2; } else { $this->style = $options['style']; } // heigth if (empty($options['h'])) { $this->h = 64; } else { $this->h = $options['h']; } // gap width if (empty($options['gap'])) { $this->gap = 0.25; } else { $this->gap = $options['gap']; } // interpolation 0-none 1-linear 2-quadratic if (empty($options['order'])) { $this->order = 0; } else { $this->order = $options['order']; } // sample-width if (empty($options['sw'])) { if ($this->gap > 0.1) { $sw = 5; } else { $sw = 6; } } else { $sw = $options['sw']; } // anti-aliasing 0-none 1-yes if (empty($options['aa'])) { $this->aa = 0; } else { $this->aa = $options['aa']; } if (!isset($this->h) || !$this->h) { $this->h = 16; } if ($this->h > 128) { // don't want to tax server/bandwidth too much $this->h = 128; } if (isset($sw) && $sw) { // base width on number of samples? $w = (count($series) - $this->order) * $sw; } if (!isset($w) || !$w) { // or just guess one if not already here $w = $this->h * 4; } if ($w > 1024) { // limit again $w = 1024; } // we'll draw to a 2x res bitmap then downsample... easiest way to antialias for now if (isset($this->aa) && $this->aa) { $w *= 2; $this->h *= 2; } $im = @imagecreatetruecolor($w, $this->h) or die("Couldn't initialize new GD image stream"); // we allow multiple ways to define a color, all use hex bumbers // B = 0xBBBBBB (greyscale) // B9 = 0xB9B9B9 (greyscale) // B94 = 0xBB9944 // B94CD1 = 0xB94CD1 // solid color if (empty($options['fill'])) { $this->fill = 0xcccccc; } else { $this->fill = $this->ParseColorValue($options['fill']); } // allocate inks if (empty($options['bg'])) { $this->bg = 0xffffff; } else { $this->bg = $this->ParseColorValue($options['bg']); } if (empty($options['tint'])) { // used for optional range bars $this->tint = 0xf0f0f0; } else { $this->tint = $this->ParseColorValue($options['tint']); } if (empty($options['line'])) { $this->line = 0x444444; } else { $this->line = $this->ParseColorValue($options['line']); } // clear to background color imagefilledrectangle($im, 0, 0, $w, $this->h, $this->bg); // get data range $this->lower = $this->upper = $series[0]; for ($i = 1; $i < count($series); $i++) { if ($this->lower > $series[$i]) { $this->lower = $series[$i]; } else { if ($this->upper < $series[$i]) { $this->upper = $series[$i]; } } } // if user has supplied additional min and max values [to expand to, not collapse] if (!empty($options['min']) && $this->lower > $options['min']) { $this->lower = $options['min']; } if (!empty($options['max']) && $this->upper < $options['max']) { $this->upper = $options['max']; } if ($this->lower == $this->upper) { $this->upper += 0.5; $this->lower -= 0.5; } $this->fudge = 0; $zero = $this->ScaleForBitmap($zero); if (!($zero & 1) && $this->aa) { $this->fudge = 1; $zero++; } // we can provide color bands to give some visual indications of scale if (!empty($zone)) { $zone = explode(",", $zone); for ($i = 0; $i < count($zone) >> 1; $i++) { imagefilledrectangle($im, 0, $this->ScaleForBitmap($zone[$i * 2 + 1]), $w, $this->ScaleForBitmap($zone[$i * 2]), $this->tint); } } if (!$this->gap) { $this->gap = 0; } $this->gap *= 0.5; // shave half off either end (see below) for ($i = 0; $i < $w; $i++) { if ($this->order == 2) { $x = $i * (count($series) - 2) / $w; $f = $x - (int) $x; $y = ($series[$x] * (1 - ($f * 0.5 + 0.5)) + $series[$x + 1] * ($f * 0.5 + 0.5)) * (1 - $f) + ($series[$x + 1] * (1 - $f * 0.5) + $series[$x + 2] * $f * 0.5) * $f; } else { if ($this->order == 1) { $x = $i * (count($series) - 1) / $w; $f = $x - (int) $x; $y = $series[$x] * (1 - $f) + $series[$x + 1] * $f; } else { $x = $i * count($series) / $w; $f = $x - (int) $x; $y = $series[$x]; } } if ($this->gap && ($f < $this->gap || $f > 1 - $this->gap)) { // per sample gap continue; } $v = $this->ScaleForBitmap($y); if ($this->style & 4) { $color = $this->ScaleForRange($y); // mix the colors $color = ((int) (($this->line & 0xff) * $color + ($this->bg & 0xff) * (1 - $color)) & 0xff) + ((int) (($this->line & 0xff00) * $color + ($this->bg & 0xff00) * (1 - $color)) & 0xff00) + ((int) (($this->line & 0xff0000) * $color + ($this->bg & 0xff0000) * (1 - $color)) & 0xff0000); imagefilledrectangle($im, $i, 0, $i, $this->h, $color); } if ($this->style & 2) { if ($v <= $zero) { $y1 = $v; $y2 = $zero; } else { $y2 = $v + 1; $y1 = $zero + 1; } imagefilledrectangle($im, $i, $y1, $i, $y2, $this->fill); } if ($this->style & 1 || !$this->style) { if (!empty($last)) { if ($this->order) { imageline($im, $i - 1, $last, $i, $v, $this->line); //imageline($im, $i-1, $last+1, $i, $y+1, $this->line); imageline($im, $i, $last, $i + 1, $v, $this->line); } else { imageline($im, $i - 1, $last, $i - 1, $v, $this->line); imageline($im, $i - 1, $v, $i, $v, $this->line); } } $last = $v; } } if ($this->aa) { $im2 = @imagecreatetruecolor(intval($w * 0.5), intval($this->h * 0.5)) or die("Couldn't initialize new GD image stream"); imagecopyresampled($im2, $im, 0, 0, 0, 0, imagesx($im2), imagesy($im2), imagesx($im), imagesy($im)); imagedestroy($im); $im = $im2; } // // transfer to the user agent // // actual transmission except on a HEAD request if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'HEAD') { // doesn't really need to change at all, but added this just in case the algorithm changes // @header("Last-Modified: " . gmdate("D, d M Y H:i:s", intval(time() / 86400) * 86400) . " GMT"); Safe::header("Content-type: image/png"); imagepng($im); imagedestroy($im); } }
$anchor = Anchors::get($id); } // load localized strings i18n::bind('behaviors'); // load the skin, maybe with a variant load_skin('agreements', $anchor); // no subject if (!is_object($anchor)) { Logger::error(i18n::s('No item has the provided id.')); } else { // initialize the list of agreements if (!isset($_SESSION['agreements']) || !is_array($_SESSION['agreements'])) { $_SESSION['agreements'] = array(); } // append the new agreement $_SESSION['agreements'][] = $anchor->get_reference(); // revisit referer if (isset($_SERVER['HTTP_REFERER'])) { Safe::redirect($_SERVER['HTTP_REFERER']); } } // the path to this page if (is_object($anchor)) { $context['path_bar'] = $anchor->get_path_bar(); } // the title of the page if (is_object($anchor)) { $context['page_title'] = $anchor->get_title(); } // render the skin render_skin();
/** * validate a link * * This function submits a HTTP request to the target server to check that the page actually exists * * @param the link to validate * @return A date if Last-Modified has been provided, or TRUE if the link is reachable, FALSE otherwise */ function validate($url) { global $context; // parse this url $items = @parse_url($url); // assume the link is correct if not http if ($items['scheme'] && $items['scheme'] != 'http') { return TRUE; } // no host, assume it's us if (!($host = $items['host'])) { $host = $context['host_name']; } // sometime parse_url() adds a '_' $host = rtrim($host, '_'); // no port, assume the standard if (!($port = $items['port'])) { $port = 80; } // assume the link is correct when outbound web is not authorized if (isset($context['without_outbound_http']) && $context['without_outbound_http'] == 'Y') { return TRUE; } // open a network connection -- wait for up to 10 seconds for the TCP connection if (!($handle = Safe::fsockopen($host, $port, $errno, $errstr, 10))) { if ($context['with_debug'] == 'Y') { logger::remember('links/link.php: ' . $host . ':' . $port . ' is not reachable', $url, 'debug'); } return FALSE; } // ensure enough execution time Safe::set_time_limit(30); // build the path $path = $items['path']; if (!$path) { $path = '/'; } // sometime parse_url() adds a '_' $path = rtrim($path, '_'); // include any query if ($items['query']) { $path .= '?' . $items['query']; } // send an HTTP request fputs($handle, 'HEAD ' . $path . " HTTP/1.0" . CRLF . 'Host: ' . $host . CRLF . "User-Agent: YACS (www.yacs.fr)" . CRLF . "Connection: close" . CRLF . CRLF); // we are interested into the header only $response = ''; while (!feof($handle) && strlen($response) < 5242880) { // ask for Ethernet-sized chunks $chunk = fread($handle, 1500); // split on headers boundary $here = strpos($chunk, CRLF . CRLF); if ($here !== FALSE) { $chunk = substr($chunk, 0, $here); $response .= $chunk; break; } // gather header information $response .= $chunk; } fclose($handle); // split headers into lines $lines = explode(CRLF, $response); // ensure we have a valid HTTP status line if (!preg_match('/^HTTP\\/[0-9\\.]+ 20\\d /', $lines[0])) { if ($context['with_debug'] == 'Y') { logger::remember('links/link.php: bad status: ' . $lines[0], $url, 'debug'); } return FALSE; } // scan lines for "Last-Modified" header foreach ($lines as $line) { if (preg_match('/^Last-Modified: (.*?)/', $line, $matches)) { // return the stamp for this link return date("Y-m-d H:i:s", strtotime($matches[1])); } } // no date, but the link has been validated anyway return TRUE; }
/** * attempt to use the trackback interface * * @param string some text, extracted from the target site, to extract the broker URL, if any * @param string the source address * @param string the target address from which the text has been extracted * @param string title of the source page * @param string excerpt of the source page * @param string blog name of the source page * @return TRUE if the target site has been pinged back, FALSE otherwise * * @link http://www.movabletype.org/docs/mttrackback.html TrackBack Technical Specification */ public static function ping_as_trackback($text, $source, $target, $title = '', $excerpt = '', $blog_name = '') { global $context; // extract all rdf blocks preg_match_all('/<rdf:RDF(.*)<\\/rdf:RDF>/iUs', $text, $blocks); // nothing to do if (!@count($blocks[1])) { return FALSE; } // look for the broker $broker = array(); foreach ($blocks[1] as $block) { // seek the trackback interface if (!preg_match('/(dc:identifier|about)="' . preg_quote($target, '/') . '/mi', $block)) { continue; } // extract the broker link if (preg_match('/trackback:ping="([^"]+)"/mi', $block, $broker)) { break; } } // trackback interface not supported at this page if (!isset($broker[1])) { return FALSE; } // parse the broker URL $items = @parse_url($broker[1]); // no host, assume it's us if (!($host = $items['host'])) { $host = $context['host_name']; } // no port, assume the standard if (!isset($items['port']) || !($port = $items['port'])) { $port = 80; } // outbound web is not authorized if (isset($context['without_outbound_http']) && $context['without_outbound_http'] == 'Y') { if (isset($context['debug_trackback']) && $context['debug_trackback'] == 'Y') { Logger::remember('links/links.php: Links::ping_as_trackback()', 'Outbound HTTP is not authorized.', 'debug'); } return FALSE; } // connect to the server if (!($handle = Safe::fsockopen($host, $port, $errno, $errstr, 30))) { if (isset($context['debug_trackback']) && $context['debug_trackback'] == 'Y') { Logger::remember('links/links.php: Links::ping_as_trackback()', sprintf('Impossible to connect to %s.', $host . ':' . $port), 'debug'); } return FALSE; } // ensure enough execution time Safe::set_time_limit(30); // build the path, including any query $path = $items['path']; if (isset($items['query']) && $items['query']) { $path .= '?' . $items['query']; } // encode the content $data = 'title=' . urlencode($title) . '&url=' . urlencode($source) . '&excerpt=' . urlencode($excerpt) . '&blog_name=' . urlencode($blog_name); $headers = 'Content-Type: application/x-www-form-urlencoded' . CRLF . 'Content-Length: ' . strlen($data) . CRLF; // actual trackback, through HTTP POST $request = "POST " . $path . " HTTP/1.0" . CRLF . 'Host: ' . $host . CRLF . "User-Agent: YACS (www.yacs.fr)" . CRLF . "Connection: close" . CRLF . $headers . CRLF . $data; // save the request if debug mode if (isset($context['debug_trackback']) && $context['debug_trackback'] == 'Y') { Logger::remember('links/links.php: Links::ping_as_trackback() request', str_replace("\r\n", "\n", $request), 'debug'); } // submit the request fputs($handle, $request); // we are interested only in the very first bytes of the response $code = fread($handle, 15); fclose($handle); // save the response if debug mode if (isset($context['debug_trackback']) && $context['debug_trackback'] == 'Y') { Logger::remember('links/links.php: Links::ping_as_trackback() response', $code . '...', 'debug'); } // check HTTP status if (!preg_match('/^HTTP\\/[0-9\\.]+ 200/', $code)) { return FALSE; } // successful trackback if (isset($context['debug_trackback']) && $context['debug_trackback'] == 'Y') { Logger::remember('links/links.php: Links::ping_as_trackback() success', $broker[1], 'debug'); } return TRUE; }
// load the skin, maybe with a variant load_skin('articles', $anchor); // stop crawlers if (Surfer::is_crawler()) { Safe::header('Status: 401 Unauthorized', TRUE, 401); Logger::error(i18n::s('You are not allowed to perform this operation.')); // not found } elseif (!is_object($anchor)) { include '../../error.php'; // permission denied } elseif (!$anchor->is_owned()) { Safe::header('Status: 401 Unauthorized', TRUE, 401); Logger::error(i18n::s('You are not allowed to perform this operation.')); // no overlay } elseif (!is_object($overlay) || !is_callable(array($overlay, 'get_start_url'))) { Logger::error(i18n::s('You are not allowed to perform this operation.')); } elseif (count($context['error'])) { } elseif (!($follow_up = $overlay->get_start_url())) { Logger::error(i18n::s('You are not allowed to perform this operation.')); } else { // remember the action $overlay->start_meeting(); // redirect to the meeting page Safe::redirect($follow_up); } // page title if (is_object($anchor)) { $context['page_title'] = $anchor->get_title(); } // render the skin render_skin();
// stop crawlers if (Surfer::is_crawler()) { Safe::header('Status: 401 Unauthorized', TRUE, 401); Logger::error(i18n::s('You are not allowed to perform this operation.')); // not found } elseif (!is_object($anchor)) { Safe::header('Status: 404 Not Found', TRUE, 404); Logger::error(i18n::s('No item has been found.')); // permission denied } elseif (!$permitted) { // anonymous users are invited to log in or to register if (!Surfer::is_logged()) { Safe::redirect($context['url_to_home'] . $context['url_to_root'] . 'users/login.php?url=' . urlencode(Categories::get_url($member, 'select'))); } // permission denied to authenticated user Safe::header('Status: 401 Unauthorized', TRUE, 401); Logger::error(i18n::s('You are not allowed to perform this operation.')); // build a form to associates some categories to this item } else { // actual update if (isset($_REQUEST['anchor']) && isset($_REQUEST['member'])) { // on error display the form again if ($error = Members::toggle($_REQUEST['anchor'], $_REQUEST['member'], isset($_REQUEST['father']) ? $_REQUEST['father'] : '')) { Logger::error($error); } } // the current list of linked categories $categories =& Members::list_categories_by_title_for_member($member, 0, CATEGORIES_LIST_SIZE, 'raw'); // the form to link additional categories if (!is_array($categories) || count($categories) < CATEGORIES_LIST_SIZE) { $context['text'] .= '<form method="post" action="' . $context['script_url'] . '"><div style="margin-bottom: 2em;">' . i18n::s('Select a category') . ' <select name="anchor">' . Categories::get_options($categories) . '</select>' . ' ' . Skin::build_submit_button(i18n::s('Categorize')) . '<input type="hidden" name="member" value="' . encode_field($member) . '">' . '</div></form>' . "\n";
/** * dynamically generate the page * * @see skins/index.php */ function send_body() { global $context, $local; // $local is required to localize included scripts // include every script that has to be run once global $scripts, $scripts_count; if (@count($scripts)) { // the alphabetical order may be used to control script execution order sort($scripts); reset($scripts); // process each script one by one foreach ($scripts as $item) { // do not execute on first installation if (file_exists('../parameters/switch.on') || file_exists('../parameters/switch.off')) { // ensure we have a valid database resource if (!$context['connection']) { break; } // remember this as an event Logger::remember('scripts/run_once.php: ' . sprintf(i18n::c('script %s has been executed'), $item)); // where scripts actually are $actual_item = str_replace('//', '/', $context['path_to_root'] . 'scripts/run_once/' . $item); // include the script to execute it $scripts_count++; echo Skin::build_block($item, 'subtitle'); include $actual_item; echo "\n"; } // ensure enough overall execution time Safe::set_time_limit(30); // stamp the file to remember execution time Safe::touch($actual_item); // rename the script to avoid further execution Safe::unlink($actual_item . '.done'); Safe::rename($actual_item, $actual_item . '.done'); } // refresh javascript libraries Cache::purge('js'); } // report on actual execution if ($scripts_count) { echo '<p> </p><p>' . sprintf(i18n::ns('%d script has been executed', '%d scripts have been executed', $scripts_count), $scripts_count) . "</p>\n"; } else { echo '<p>' . i18n::s('No script has been executed') . "</p>\n"; } // display the total execution time $time = round(get_micro_time() - $context['start_time'], 2); if ($time > 30) { echo '<p>' . sprintf(i18n::s('Script terminated in %.2f seconds.'), $time) . '</p>'; } // if the server has been switched off, go back to the control panel if (file_exists('../parameters/switch.off')) { echo '<form method="get" action="' . $context['url_to_root'] . 'control/">' . "\n" . '<p class="assistant_bar">' . Skin::build_submit_button(i18n::s('Control Panel')) . '</p>' . "\n" . '</form>' . "\n"; // else back to the control panel as well, but without a button } else { $menu = array('control/' => i18n::s('Control Panel')); echo Skin::build_list($menu, 'menu_bar'); } // purge the cache, since it is likely that we have modified some data Cache::clear(); }