Ejemplo n.º 1
0
 /**
  * This is an interesting method. It returns an image, not HTML!
  * @return void
  */
 public function action_image()
 {
     $this->auto_render_layout = FALSE;
     $EzLink = new Model_EzLink();
     $image = $EzLink->getStatisticsImage();
     $this->response->header('Content-type', 'image/png');
     imagepng($image);
 }
Ejemplo n.º 2
0
 /**
  * Runs after the action. Executes the layout/main view file.
  * @return void
  */
 public function postAction()
 {
     if ($this->auto_render_layout) {
         $EzLink = new Model_EzLink();
         $this->page_data['count_urls'] = $EzLink->countUrls();
         $this->page_data['count_clicks'] = $EzLink->countClicks();
         $this->response->view('layout/main', $this->page_data);
     }
 }
Ejemplo n.º 3
0
 /**
  * This is the page the user hits when submitting a URL via their browser.
  * @return void
  */
 public function action_submit()
 {
     $url = $this->request->post('url');
     $this->page_data['code'] = FALSE;
     if ($url && filter_var($url, FILTER_VALIDATE_URL)) {
         $EzLink = new Model_EzLink();
         $id = $EzLink->insertUrl($url);
         $this->page_data['code'] = Model_EzLink::integerToCode($id);
     }
     $this->page_data['content'] = \Sleek\View::render('pages/submit', $this->page_data, TRUE);
 }
Ejemplo n.º 4
0
 /**
  * This function is run when someone visits /link/abcDEF123
  * @return void
  */
 public function noAction()
 {
     $id = Model_EzLink::codeToInteger($this->request->urlAction());
     $hidden = $this->request->get('h') !== NULL;
     $EzLink = new Model_EzLink();
     $url = $EzLink->getUrlById($id);
     $EzLink->clickUrl($id, date("Y"), date("n"));
     if ($hidden) {
         echo "<meta http-equiv=\"refresh\" content=\"0; URL={$url}\">";
     } else {
         $this->response->redirect($url);
     }
 }
Ejemplo n.º 5
0
 /**
  * Program visits /api/create?url=http://www.example.com
  * @return void
  */
 public function action_create()
 {
     // Disables the layout stuff
     $this->auto_render_layout = FALSE;
     // Get the ?url= parameter
     $url = $this->request->get('url');
     if (!$url) {
         echo "ERROR: Empty URL";
     } else {
         if (!filter_var($url, FILTER_VALIDATE_URL)) {
             echo "ERROR: Invalid URL";
         } else {
             $EzLink = new Model_EzLink();
             $id = $EzLink->insertUrl($url);
             // Controllers shouldn't really output directly, but it seems like a waste of a view file otherwise
             echo 'http://' . $this->request->server('HTTP_HOST') . '/link/' . Model_EzLink::integerToCode($id);
         }
     }
 }