/**
  * redirect request to a host by hashing the given url
  * @param $url
  * @param $numberOfHost
  */
 public static function route($url, $numberOfHost)
 {
     $hashNode = static::strHash($url, $numberOfHost);
     $redirectUrl = "http://tumblr-images-{$hashNode}.appspot.com/main.php?url={$url}";
     $redirectUrl = static::encodeCjkChars($redirectUrl);
     Output::redirect($redirectUrl);
 }
示例#2
0
 public function action_register()
 {
     if (\Auth::check()) {
         \Session::set_flash('error', 'FLASH: Can\'t register while logged in, log out first.');
         \Output::redirect('myauth');
     }
     // The same fields as the example above
     $val = \Validation::factory('myauth2');
     $val->add_field('username', 'Your username', 'required|min_length[3]|max_length[20]');
     //        $val->add_field('username', 'Your username', 'required|min_length[3]|max_length[20]|unique[simpleauth.username]');
     $val->add_field('password', 'Your password', 'required|min_length[3]|max_length[20]');
     $val->add_field('email', 'Email', 'required|valid_email');
     // run validation on just post
     if ($val->run()) {
         if (\Auth::instance()->create_user($val->validated('username'), $val->validated('password'), $val->validated('email'), '100')) {
             \Session::set_flash('notice', 'FLASH: User created.');
             \Output::redirect('myauth');
         } else {
             throw new Exception('Smth went wrong while registering');
         }
     } else {
         // validation failed
         if ($_POST) {
             $data['username'] = $val->validated('username');
             $data['login_error'] = 'All fields are required.';
         } else {
             $data['login_error'] = false;
         }
     }
     $this->template->title = 'Myauth &raquo Register';
     $this->template->login_error = @$data['login_error'];
     $this->template->content = \View::factory('register');
 }
示例#3
0
 function enable()
 {
     $id = $this->uri->get('id');
     if ($id != '') {
         $ret = $this->user_model->updateRecord(array('user_canlogin' => '1'), array('user_id' => $id));
     }
     Output::redirect($this->config['base_url'] . $this->ctrler . '/');
 }
示例#4
0
 protected function get_index()
 {
     $conf = Config::getInstance();
     if (Session::isLogged()) {
         Output::redirect(WWW_PATH);
     }
     $conf = Config::getInstance();
     $tpt = new TemplateRes(array("title" => $conf->get("title"), "description" => $conf->get("description"), "favicon" => $conf->get("favicon", null)));
     $tpt->output("login.php");
 }
示例#5
0
 public function before()
 {
     parent::before();
     if (!\Auth::check()) {
         \Output::redirect('myauth');
     }
     \Asset::remove_path('assets/');
     \Asset::add_path('assets/uploadify/');
     $this->template->css = \Asset::css(array('style.css'), array(), 'layout', false);
     $this->template->js = \Asset::js(array('jquery-1.3.2.min.js', 'swfobject.js', 'jquery.uploadify.v2.1.0.min.js', 'jquery.application.js'), array(), 'layout', false);
 }
示例#6
0
/**
 * @param $isHashHost Boolean Is this host a router
 * @param $hostNumber Number How many host there
 * @param $packImages Boolean make a zip pack for images?
 */
function main($isHashHost, $hostNumber, $packImages)
{
    $url = isset($_GET['url']) ? $_GET['url'] : '';
    # URL given
    if ($url) {
        # it's an image url
        if (Input::isImageUrl($url)) {
            Output::redirect($url);
        } elseif ($isHashHost) {
            Router::route($url, $hostNumber);
        } else {
            $mc = new mc();
            Input::loadMemcached($mc);
            Output::loadMemcached($mc);
            Handler::loadMemcached($mc);
            Handler::handle($url, $packImages);
        }
    } else {
        exit_script('Hello Tumblr!');
    }
}
示例#7
0
 function save()
 {
     //echoPre($_POST);
     //echoPRe($_FILES);
     //die;
     if (isPost() && post('vContent')) {
         $whatHappenDt = array('what_happen_order' => post('vOrder'), 'what_happen_flag' => post('vFlag'), 'what_happen_url' => post('vUrl'), 'what_happen_content' => post('vContent'), 'what_happen_image' => post('vImage'), 'what_happen_id' => post('vId'), 'what_happen_schedule' => post('vSchedule'), 'what_happen_headtorial' => post('what_happen_headtorial') == "headtorial" ? "1" : "0", 'what_happen_schedule_end' => post('vSchedule_end'));
         //echoPre($whatHappenDt);   die;
         $whatHappenDateDt = array('what_happen_id' => post('vId'), 'what_happen_schedule' => post('vSchedule'));
         if (post('vId')) {
             $what_happen_id = post('vId');
             $this->what_happen_model->updateRecord($whatHappenDt, array('what_happen_id' => $what_happen_id));
             //$this->what_happen_model->updateDateRecord($whatHappenDateDt, array('what_happen_id' => $what_happen_id));
         } else {
             $what_happen_id = $this->what_happen_model->insertRecord($whatHappenDt);
             //$whatHappenDateDt['what_happen_id'] = $what_happen_id;
             //$this->what_happen_model->insertDateRecord($whatHappenDateDt);
         }
         //processing ilustration upload
         $whatHappenDt['what_happen_schedule'] = post('vSchedule');
         $this->processIlustration($whatHappenDt, $what_happen_id);
         @header('Location: ' . $this->config['base_url'] . $this->ctrler . '/&s=success' . (post('page') != '' ? '&page=' . post('page') : ''));
     } else {
         //$this->redirect('/'.$this->ctrler.'/addnews/');
         Output::redirect($this->config['base_url'] . $this->ctrler . '/add/');
     }
 }
 public static function handle($url, $packImages = false)
 {
     $postParam = static::parseUrlParam($url);
     $quickInfo = null;
     # try to process it
     try {
         # a valid tumblr url given
         if ($postParam) {
             $cachedInfo = Input::fetchQuickInfoCache($postParam);
             # quick response info found
             if ($cachedInfo) {
                 # make just header response
                 if ($_SERVER['REQUEST_METHOD'] === 'HEAD') {
                     syslog(LOG_INFO, "HEAD Response.");
                     foreach ($cachedInfo['headers'] as $header) {
                         header($header);
                     }
                 } else {
                     syslog(LOG_INFO, "Content Response.");
                     $content = $cachedInfo['content'];
                     switch ($cachedInfo['type']) {
                         case 'html':
                             Output::echoHtmlFile($content);
                             break;
                         case 'video':
                         case 'singlePhoto':
                             Output::redirect($content);
                             break;
                         case 'htmlZip':
                             Output::echoZipFile($content);
                             break;
                         case 'error':
                             Output::echoTxtFile($content);
                             break;
                     }
                 }
             } else {
                 $postJSON = Input::fetchPostInfoCache($postParam) ?: Input::queryTumblrApi($postParam);
                 # post json gotten
                 if ($postJSON) {
                     # save post info to memcached
                     Output::setPostInfoCache($postParam, $postJSON);
                     $postInfo = $postJSON['posts'][0];
                     $postType = Content::parsePostType($postInfo);
                     $parserName = 'parse' . ucfirst($postType);
                     switch ($postType) {
                         case 'audio':
                         case 'answer':
                         case 'conversation':
                         case 'link':
                         case 'regular':
                         case 'quote':
                             $output = Content::$parserName($postInfo);
                             $zipStr = Content::getHtmlZipPack($output);
                             Output::echoZipFile($zipStr);
                             $quickInfo = ['type' => 'htmlZip', 'content' => $zipStr];
                             break;
                         case 'video':
                             $output = Content::$parserName($postInfo);
                             # video source parsed
                             if ($output) {
                                 Output::redirect($output);
                                 $quickInfo = ['type' => 'video', 'content' => $output];
                             } else {
                                 $errMsg = "Can't not parse video post, maybe it's too complicated to get the video source out.";
                                 throw new Exception($errMsg);
                             }
                             break;
                         case 'unknow':
                         case 'photo':
                         default:
                             $photoUrls = Content::$parserName($postInfo);
                             $photoCount = count($photoUrls);
                             # photo found
                             if ($photoCount > 0) {
                                 # one photo
                                 if ($photoCount === 1) {
                                     Output::redirect($photoUrls[0]);
                                     $quickInfo = ['type' => 'singlePhoto', 'content' => $photoUrls[0]];
                                 } else {
                                     # to make a images pack
                                     if ($packImages) {
                                         $imagesCache = Input::fetchImagesCache($photoUrls);
                                         $total = count($photoUrls);
                                         $cached = count($imagesCache);
                                         $fetched = 0;
                                         $startTime = microtime(true);
                                         # get images
                                         $imagesCont = array_fill_keys($photoUrls, null);
                                         $randomOrder = array_values($photoUrls);
                                         shuffle($randomOrder);
                                         foreach ($randomOrder as $imgUrl) {
                                             $fileName = basename($imgUrl);
                                             # image in cache found
                                             if (isset($imagesCache[$fileName])) {
                                                 $imagesCont[$imgUrl] =& $imagesCache[$fileName];
                                             } else {
                                                 $imagesCont[$imgUrl] = Input::fetchImage($imgUrl);
                                                 # fetch from network
                                                 $imagesCont[$imgUrl] && static::$mc->singleSet($fileName, $imagesCont[$imgUrl]);
                                                 # write to cache
                                                 $fetched++;
                                             }
                                         }
                                         # output
                                         $zipPack = Content::getImagesZipPack($imagesCont);
                                         Output::echoZipFile($zipPack);
                                         # statement record
                                         $timeUsed = number_format(microtime(true) - $startTime, 3, '.', '');
                                         syslog(LOG_INFO, "Total: {$total}, From cache: {$cached}, From network: {$fetched}, Time used: {$timeUsed}s");
                                         # refresh cache
                                         static::$mc->touchKeys(array_keys($imagesCache));
                                         # Output::writeImagesToCache($images, array_keys($imagesCache));
                                         $quickInfo = ['HEADOnly' => true, 'headers' => []];
                                     } else {
                                         $page = Content::getImagesDownPage($photoUrls);
                                         $readme = "Sever overloading all the time so no more images packing, open the htm file with google chrome and DIY thank you.\r\n服务器扛不住,取消图片打包,请使用谷歌浏览器打开htm文件自行下载,靴靴。";
                                         $zipStr = Content::getHtmlZipPack($page, null, $readme);
                                         Output::echoZipFile($zipStr);
                                         $quickInfo = ['type' => 'htmlZip', 'content' => $zipStr];
                                     }
                                 }
                             } else {
                                 $errMsg = "No images found in the tumblr post.";
                                 throw new Exception($errMsg);
                             }
                             break;
                     }
                 } else {
                     $postParam = false;
                     # don't write quick response
                     $errMsg = 'No post info back from Tumblr.';
                     throw new Exception($errMsg);
                 }
             }
         } else {
             $errMsg = "Not a valid tumblr URL.";
             throw new Exception($errMsg);
         }
     } catch (Exception $e) {
         $errText = Content::getErrorText($e->getMessage());
         $quickInfo = ['type' => 'error', 'content' => $errText];
         Output::echoTxtFile($errText);
     } finally {
         if ($postParam && $quickInfo) {
             $quickInfo['headers'] = headers_list();
             Output::setQuickInfoCache($postParam, $quickInfo);
         }
     }
     return true;
 }
示例#9
0
文件: tag.php 项目: cyberorca/dfp-api
 public function putInTrash()
 {
     if ($this->uri->get('id')) {
         $whereCond = array('id' => $this->uri->get('id'));
         $this->tags_model->deleteTagRecord($whereCond);
     }
     #redirecting page after deleting process
     Output::redirect($this->config['base_url'] . 'tag-management/');
 }
示例#10
0
 function preview()
 {
     $id = $this->uri->get('id');
     if (isset($id)) {
         $ret = $arr = $this->_get_edit_news($id);
         $dt = array('prefix_title' => 'Photo news Preview', 'title' => 'Photo news Preview', 'top_active' => $this->method_by_url[$this->ctrler]['parent_id'], 'sub_menu' => $this->method_by_url[$this->ctrler]['sub_id'], 'content' => $this->provideNewsPreview($ret), 'custom_css' => array($this->config['assets_css_url'] . 'dropzone.css', $this->config['assets_css_url'] . 'news/n_news.css'), 'custom_js' => array($this->config['assets_js_url'] . 'news/n_news.js'));
     } else {
         Output::redirect($this->config['base_url'] . $this->ctrler . '/');
         exit;
     }
     $this->render('url/_templates', $dt);
 }
示例#11
0
    function resetpassword($code)
    {
        $sts = false;
        if ($code) {
            $where = "user_activation_hash='" . $code . "'";
            $row = $this->user_model->get_user($where);
            if (is_array($row) && count($row) > 0) {
                $row = $row[0];
                $change = $this->user_model->updatePassword($row['user_id']);
                if ($change) {
                    $to = $row['user_email'];
                    $toname = $row['user_realname'];
                    $subject = '[' . strtoupper($row['user_realname']) . '] Password reset';
                    $message = '
                        Dear ' . $toname . '<br /><br />
                        Your password has been successfully updated.<br />
                        Your new account is :<br />
                        User : '******'user_email'] . '<br />
                        Password : '******'new_password'] . '<br />
                        Change your password immediatly after you logon into the Application.<br /><br />

                        Regards.
                    ';
                    $sts = send_email($to, $subject, $message);
                }
            }
        }
        if ($sts) {
            $dt = array('url_home' => BASE_URL);
            $content = $this->view("box/_user_reset_pass", $dt, true);
            $this->index($content);
        } else {
            Output::redirect($this->config['base_url']);
        }
    }
示例#12
0
 function savenews()
 {
     if (isPost() && post('news_title')) {
         $newsDt = array('news_id' => post('news_id'), 'news_entry' => date('Y-m-d H:i:s'), 'news_level' => post('news_level'), 'news_top_headline' => '0', 'news_editor_pick' => post('news_editor_pick') ? '1' : '0', 'news_category' => json_encode(array(post('news_category'))), 'news_title' => post('news_title'), 'news_subtitle' => post('news_subtitle'), 'news_synopsis' => post('news_lead'), 'news_content' => post('news_content'), 'news_image_headline' => '0', 'news_imageinfo' => post('news_imageinfo'), 'news_url' => post('news_subtitle') ? url_title(post('news_title') . '-' . post('news_subtitle')) : url_title(post('news_title')), 'news_date_publish' => post('news_date_publish') ? post('news_date_publish') : date('Y-m-d H:i:s'), 'news_invalid' => '0', 'news_user_id' => sess('usr_id'), 'news_type' => '0', 'news_reporter' => $this->processReporter(post('news_reporter')), 'news_editor' => json_encode(array(array('email' => sess('usr_email'), 'user_fullname' => sess('usr_fullname')))), 'news_initial' => '', 'news_photographer' => $this->processReporter(post('news_photographer')), 'news_hastag' => post('news_hastag'), 'news_city' => post('news_city') ? post('news_city') : 'Jakarta', 'photo_slideshow' => '0', 'news_source' => '', 'info_grafis' => '0', 'external_url' => '', 'has_paging' => '0', 'news_tag_activated' => rand(1, 4), 'news_mature' => post('news_mature') ? '1' : '0', 'popular_keyword' => rand(1, 2));
         if (post('news_id')) {
             unset($newsDt['news_id']);
             unset($newsDt['news_entry']);
             unset($newsDt['news_editor']);
             $news_id = post('news_id');
             $this->news_model->updateNews($newsDt, array('news_id' => $news_id));
             //deleting news keyword data
             $this->news_model->deleteRecord('mdk_news_keywords', array('nk_news_id' => $news_id));
             //delete news tag data
             $this->news_model->deleteRecord('mdk_tag_news', array('tag_news_news_id' => $news_id));
         } else {
             $news_id = $this->news_model->saveNewRecord($newsDt, 'mdk_news');
         }
         $this->processNewsTags($news_id, post('news_tags'));
         $this->processNewsKeywords($news_id, post('news_keywords'));
         //processing news ilustration upload
         $this->processNewsIlustration($newsDt, $news_id);
         //save to mdk_news_rubric
         $this->saveMdkNewsRubric($newsDt, $news_id);
         //$this->redirect('/'.$this->ctrler.'/edit/&id='.$news_id."&t=".date("s"));
         Output::redirect($this->config['base_url'] . $this->ctrler . '/');
     } else {
         //$this->redirect('/'.$this->ctrler.'/addnews/');
         Output::redirect($this->config['base_url'] . $this->ctrler . '/addnews/');
     }
 }