protected function formAction()
 {
     $form = new UrlForm();
     if (App::request()->isPost()) {
         $form->setValue('url', App::request()->getPostVar('url'));
         if ($form->isValid()) {
             // if URL is valid
             // find or generate short URL
             $existsUrlRecord = UrlModel::findOneByLongurl($form->getValue('url'));
             if (false !== $existsUrlRecord) {
                 // alredy exists - use it
                 $shortURI = App::alphaid()->toAlpha($existsUrlRecord->id);
             } else {
                 // not exists - create new
                 $urlRecord = new UrlModel();
                 $urlRecord->longurl = $form->getValue('url');
                 $urlRecord->save();
                 $shortURI = App::alphaid()->toAlpha($urlRecord->id);
             }
             $shortURL = App::router()->createUrl('Redirector', 'redirect', array('url' => $shortURI));
             $form->setValue('shortUrl', $shortURL);
         }
     }
     if (App::request()->isAjaxRequest()) {
         $this->setLayout('ajax');
         $this->view->form = $form->getData();
     } else {
         $this->view->form = $form;
         $this->render();
     }
 }
 protected function redirectAction()
 {
     $shortURI = App::request()->getQueryVar('url');
     $shortURIId = App::alphaid()->toId($shortURI);
     /** @var $urlRecord UrlModel */
     $urlRecord = UrlModel::findOneByPk($shortURIId);
     if (false !== $urlRecord && !empty($urlRecord->longurl)) {
         // TODO cache
         // TODO statictics (hits/lastuse)
         App::response()->redirectAndExit($urlRecord->longurl, 301);
         // SEO friendly redirect
     } else {
         // redirect failed
         App::response()->sendNotFoundAndExit();
     }
 }
Beispiel #3
0
 /**
  * Create a new message group
  *
  * @todo Support team members
  *
  * @param  string $subject   The subject of the group
  * @param  int    $creatorId The ID of the player who created the group
  * @param  array  $members   A list of IDs representing the group's members
  * @return Group  An object that represents the created group
  */
 public static function createGroup($subject, $creatorId, $members = array())
 {
     $group = self::create(array('subject' => $subject, 'creator' => $creatorId, 'status' => "active"), 'sis', 'last_activity');
     foreach ($members as $mid) {
         parent::create(array('player' => $mid, 'group' => $group->getId()), 'ii', null, 'player_groups');
     }
     return $group;
 }
Beispiel #4
0
 /**
  * Get a list containing the IDs of each member team of the conversation
  *
  * @return int[] An array of team IDs
  */
 public function getTeamIds()
 {
     return parent::fetchIds("WHERE `conversation` = ?", "i", $this->id, "team_conversations", "team");
 }
Beispiel #5
0
 /**
  * {@inheritdoc}
  */
 public function delete()
 {
     $this->updateMatchCount(true);
     return parent::delete();
 }
Beispiel #6
0
 /**
  * {@inheritdoc}
  */
 public function delete()
 {
     $this->getVictim()->markAsUnbanned();
     parent::delete();
 }
 /**
  * Fetches and parses an RSS or Atom feed, and returns its items.
  *
  * Each element in the returned array will have the following keys:
  *
  * - **authors** – An array of the item’s authors, where each sub-element has the following keys:
  *     - **name** – The author’s name
  *     - **url** – The author’s URL
  *     - **email** – The author’s email
  * - **categories** – An array of the item’s categories, where each sub-element has the following keys:
  *     - **term** – The category’s term
  *     - **scheme** – The category’s scheme
  *     - **label** – The category’s label
  * - **content** – The item’s main content.
  * - **contributors** – An array of the item’s contributors, where each sub-element has the following keys:
  *     - **name** – The contributor’s name
  *     - **url** – The contributor’s URL
  *     - **email** – The contributor’s email
  * - **date** – A {@link DateTime} object representing the item’s date.
  * - **dateUpdated** – A {@link DateTime} object representing the item’s last updated date.
  * - **permalink** – The item’s URL.
  * - **summary** – The item’s summary content.
  * - **title** – The item’s title.
  *
  * @param string $url           The feed’s URL.
  * @param int    $limit         The maximum number of items to return. Default is 0 (no limit).
  * @param int    $offset        The number of items to skip. Defaults to 0.
  * @param string $cacheDuration Any valid [PHP time format](http://www.php.net/manual/en/datetime.formats.time.php).
  *
  * @return array|string The list of feed items.
  */
 public function getFeedItems($url, $limit = 0, $offset = 0, $cacheDuration = null)
 {
     $items = array();
     if (!extension_loaded('dom')) {
         Craft::log('Craft needs the PHP DOM extension (http://www.php.net/manual/en/book.dom.php) enabled to parse feeds.', LogLevel::Warning);
         return $items;
     }
     if (!$cacheDuration) {
         $cacheDuration = craft()->config->getCacheDuration();
     } else {
         $cacheDuration = DateTimeHelper::timeFormatToSeconds($cacheDuration);
     }
     // Potentially long-running request, so close session to prevent session blocking on subsequent requests.
     craft()->session->close();
     $feed = new \SimplePie();
     $feed->set_feed_url($url);
     $feed->set_cache_location(craft()->path->getCachePath());
     $feed->set_cache_duration($cacheDuration);
     $feed->init();
     // Something went wrong.
     if ($feed->error()) {
         Craft::log('There was a problem parsing the feed: ' . $feed->error(), LogLevel::Warning);
         return array();
     }
     foreach ($feed->get_items($offset, $limit) as $item) {
         // Validate the permalink
         $permalink = $item->get_permalink();
         if ($permalink) {
             $urlModel = new UrlModel();
             $urlModel->url = $item->get_permalink();
             if (!$urlModel->validate()) {
                 Craft::log('An item was omitted from the feed (' . $url . ') because its permalink was an invalid URL: ' . $permalink);
                 continue;
             }
         }
         $date = $item->get_date('U');
         $dateUpdated = $item->get_updated_date('U');
         $items[] = array('authors' => $this->_getItemAuthors($item->get_authors()), 'categories' => $this->_getItemCategories($item->get_categories()), 'content' => $item->get_content(true), 'contributors' => $this->_getItemAuthors($item->get_contributors()), 'date' => $date ? new DateTime('@' . $date) : null, 'dateUpdated' => $dateUpdated ? new DateTime('@' . $dateUpdated) : null, 'permalink' => $item->get_permalink(), 'summary' => $item->get_description(true), 'title' => $item->get_title(), 'enclosures' => $this->_getEnclosures($item->get_enclosures()));
     }
     return $items;
 }
Beispiel #8
0
 /**
  * 更新菜单
  */
 public function actionUpdateMenu($wechatId)
 {
     $status = -1;
     $token = $this->_getToken($wechatId);
     $tokenValue = $token['tokenValue'];
     if ($tokenValue) {
         //更新菜单
         $menu = MenuactionModel::model()->getTree($wechatId);
         if ($menu) {
             foreach ($menu as $m) {
                 if (isset($m['child']) && $m['child']) {
                     foreach ($m['child'] as $ch) {
                         if ($ch['type'] == Globals::TYPE_URL) {
                             $subV = array('type' => 'view', 'url' => $ch['action']);
                         } else {
                             $subV = array('type' => 'click', 'key' => $ch['action']);
                         }
                         $subV['name'] = urlencode($ch['name']);
                         $sub[] = $subV;
                     }
                     $t = array('name' => urlencode($m['name']), 'sub_button' => $sub);
                     unset($sub);
                 } else {
                     if ($m['type'] == Globals::TYPE_URL) {
                         $urlInfo = UrlModel::model()->findByPk($m['responseId']);
                         $t = array('type' => 'view', 'url' => $urlInfo->url);
                     } else {
                         $t = array('type' => 'click', 'key' => $m['action']);
                     }
                     $t['name'] = urlencode($m['name']);
                 }
                 $buttonValue['button'][] = $t;
             }
             $menuValue = stripslashes(urldecode(json_encode($buttonValue)));
             $url = sprintf(Globals::MENU_UPDATE_URL, $tokenValue);
             $result = HttpRequest::sendHttpRequest($url, $menuValue, 'POST');
             $resultData = json_decode($result['content']);
             $status = $resultData->errcode == Globals::WECHAT_RESPONSE_OK ? 1 : -1;
             $msg = $resultData->errcode == Globals::WECHAT_RESPONSE_OK ? '' : Globals::$wechatErrorCode[$resultData->errcode];
             if ($status == 1) {
                 $settingMenuModel = SettingModel::model()->find("wechatId = :wechatId and `key`=:key", array(':wechatId' => $wechatId, ':key' => Globals::SETTING_KEY_MENU));
                 if (!$settingMenuModel) {
                     $settingMenuModel = new SettingModel();
                     $settingMenuModel->key = Globals::SETTING_KEY_MENU;
                     $settingMenuModel->wechatId = $wechatId;
                 }
                 $settingMenuModel->created_at = time();
                 $settingMenuModel->value = $menuValue;
                 $settingMenuModel->save();
             }
         } else {
             $msg = '菜单为空';
         }
     } else {
         $msg = '获取token异常';
     }
     echo json_encode(array('status' => $status, 'msg' => $msg));
 }
Beispiel #9
0
 /**
  * Get the roles that should be displayed on the "Admins" page
  *
  * @return Role[] An array of Roles that should be displayed on the "Admins" page
  */
 public static function getLeaderRoles()
 {
     return parent::arrayIdToModel(self::fetchIds("WHERE display = 1 ORDER BY display_order ASC"));
 }