function d($str, $print = TRUE, $class = NULL, $element = 'p', $encode = TRUE) { if (DEBUG || get_debug()) { if ($class != NULL) { $class = " {$class}"; } $str = "<{$element} class='debug{$class}'>" . ($encode ? htmlentities($str) : $str) . "</{$element}>"; if ($print) { echo $str; } return $str; } else { return NULL; } }
/** * schedule file for downloading at qaul app */ function file_schedule($message) { // extract: hash, suffix, description if (preg_match('/(^|\\s)([a-zA-Z0-9]{40})\\.([a-zA-Z0-9]{1,5})(.*)/', $message->msg, $matches)) { $url = 'http://localhost:8081/file_schedule.json'; $post_data = array('hash' => $matches[2], 'suffix' => $matches[3], 'description' => trim($matches[4]), 'size' => 0, 'ip' => $message->ip, 'name' => $message->name, 'e' => 1); // use key 'http' even if you send the request to https://... $options = array('http' => array('header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query($post_data))); $context = stream_context_create($options); $result = file_get_contents($url, false, $context); if (get_debug()) { var_dump($result); } } }
</p> <p class='site-slogan'><?php echo $slogan; ?> </p> </div> </div> </div> <div id='wrap-main'> <div id='main' role='main'> <?php echo get_messages_from_session(); ?> <?php echo @$main; ?> <?php echo render_views(); ?> </div> </div> <div id='wrap-footer'> <div id='footer'> <?php echo $footer; echo get_debug(); ?> </div> </div> </body> </html>
// loop through messages foreach ($data->files as $item) { // check if has been successfully downloaded if ($item->status >= 4) { // check if file already exists $file = FileQuery::create()->filterByHash($item->hash)->findOne(); if (!$file) { // put file information into data base $file = new File(); $file->setHash($item->hash); $file->setSuffix($item->suffix); $file->setDescription($item->description); $file->setSize($item->size); $file->setTime($item->time); $file->setStatus($item->status); $file->save(); // advertise this file via twitter // TODO: send images < 3MB directly to twitter $txt = $file->getDescription() . " " . twitter_file_link($file); twitter_send2twitter($txt); if (get_debug()) { echo "advertised file on twitter: {$txt}\n"; } } } else { if ($item->status == -2) { // delete file $file = FileQuery::create()->filterByHash($item->hash)->delete(); } } }
/** * creates a message string that includes the sender name in the message text. * The string is limited to 140 bytes max. * * @retval message text */ function twitter_message_string_byte($text, $name) { $max = 140; $free = $max - strlen($text); $name_len = strlen($name); if ($free < 0) { $msg_name = ''; $text = mb_strcut($text, 0, $max); } elseif ($free < 3) { $msg_name = ''; } elseif ($free == 3) { $msg_name = '[] '; } elseif ($free == 4) { $msg_name = '[.] '; } elseif ($free == 5 && $name_len > 2) { $msg_name = '[..] '; } elseif ($free < $name_len + 3) { $name_part = mb_strcut($name, 0, $free - 5); $msg_name = '[' . $name_part . '..] '; } else { $msg_name = '[' . $name . '] '; } $message = $msg_name . $text; if (get_debug()) { var_dump($message); } return $message; }