示例#1
0
 /**
  * @before _secure, changeLayout, _admin
  */
 public function shuffleitem($shuffle_id)
 {
     $this->seo(array("title" => "Shuffle Content", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $fields = array("usr_x", "usr_y", "usr_w", "usr_h", "txt_x", "txt_y", "txt_size", "txt_angle", "txt_color");
     $shuffle = Shuffle::first(array("id = ?" => $shuffle_id));
     if (RequestMethods::post("action") == "shuffle") {
         $item = new ShuffleItem(array("shuffle_id" => $shuffle->id, "meta_key" => "gender", "meta_value" => RequestMethods::post("gender"), "base_im" => $this->_upload("base_im"), "live" => true));
         foreach ($fields as $key => $value) {
             $item->{$value} = RequestMethods::post($value, "0");
         }
         $item->save();
     }
     $items = ShuffleItem::all(array("shuffle_id = ?" => $shuffle->id));
     $view->set("shuffle", $shuffle);
     $view->set("items", $items);
 }
示例#2
0
 protected function _shuffleprocess($game, $campaign, $play_again = true)
 {
     $participant = Participant::first(array("user_id = ?" => $this->user->id, "campaign_id = ?" => $campaign->id));
     if ($participant && !$play_again) {
         return $participant->image;
     }
     $items = ShuffleItem::all(array("shuffle_id = ?" => $game->id, "meta_key = ?" => "gender", "meta_value = ?" => strtolower($this->user->gender)));
     $key = rand(0, count($items) - 1);
     $item = $items[$key];
     $vars = array();
     $user = $this->user;
     $path = APP_PATH . '/public/assets/uploads/images/';
     $user_img = "{$path}user-" . $user->fbid . ".jpg";
     if (!file_exists($user_img)) {
         if (!copy('http://graph.facebook.com/' . $user->fbid . '/picture?width=' . $item->usr_w . '&height=' . $item->usr_h, $user_img)) {
             die('Could not copy image');
         }
     }
     $src_file = $path . $item->base_im;
     $extension = pathinfo($src_file, PATHINFO_EXTENSION);
     if ($participant) {
         $filename = $participant->image;
     } else {
         $filename = Shared\Markup::uniqueString() . ".{$extension}";
     }
     $final_img = $path . $filename;
     copy($src_file, $final_img);
     $dest = Shared\Image::resource($final_img);
     $vars['file'] = $final_img;
     $vars['filename'] = $filename;
     $img = Shared\Image::resize($user_img, $item->usr_w, $item->usr_h);
     $vars['usr'] = Shared\Image::resource($img);
     imagecopymerge($dest, $vars['usr'], $item->usr_x, $item->usr_y, 0, 0, $item->usr_w, $item->usr_h, 100);
     // add text
     $tt_color = $this->_makeColor($dest, $item->txt_color);
     $font = APP_PATH . '/public/assets/fonts/monaco.ttf';
     imagettftext($dest, $item->txt_size, 0, $item->txt_x, $item->txt_y, $tt_color, $font, $user->name);
     Shared\Image::create($dest, $vars['file']);
     $this->_saveParticipant($participant, $campaign, $vars);
     return $participant->image;
 }