当前位置: 首页>>代码示例>>PHP>>正文


PHP DateTimeHelper::timeFormatToSeconds方法代码示例

本文整理汇总了PHP中DateTimeHelper::timeFormatToSeconds方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTimeHelper::timeFormatToSeconds方法的具体用法?PHP DateTimeHelper::timeFormatToSeconds怎么用?PHP DateTimeHelper::timeFormatToSeconds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DateTimeHelper的用法示例。


在下文中一共展示了DateTimeHelper::timeFormatToSeconds方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getFeedItems

 /**
  * 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);
     }
     $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) {
         $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;
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:61,代码来源:FeedsService.php

示例2: getFeedItems

 /**
  * 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;
 }
开发者ID:scisahaha,项目名称:generator-craft,代码行数:72,代码来源:FeedsService.php

示例3: processUsernameCookie

 /**
  * If the 'rememberUsernameDuration' config setting is set, will save a cookie with the given username for that
  * duration. Otherwise, will delete any existing username cookie.
  *
  * @param string $username The username to save in the cookie.
  *
  * @return null
  */
 public function processUsernameCookie($username)
 {
     // See if the 'rememberUsernameDuration' config item is set. If so, save the name to a cookie.
     $rememberUsernameDuration = craft()->config->get('rememberUsernameDuration');
     if ($rememberUsernameDuration) {
         $this->saveCookie('username', $username, DateTimeHelper::timeFormatToSeconds($rememberUsernameDuration));
     } else {
         // Just in case...
         $this->deleteStateCookie('username');
     }
 }
开发者ID:codeforamerica,项目名称:oakland-beta,代码行数:19,代码来源:UserSessionService.php

示例4: getIdentityCookieValue

 /**
  * Returns the current user identity cookie’s value, if there is one.
  *
  * @param HttpCookie|null The user identity cookie, or `null` if you don’t have it on hand.
  *
  * @return array|null The user identity cookie’s data, or `null` if it didn’t exist.
  */
 public function getIdentityCookieValue(HttpCookie $cookie = null)
 {
     if (!$cookie) {
         $cookie = $this->getIdentityCookie();
     }
     if ($cookie && ($data = $this->getStateCookieValue($cookie)) && is_array($data) && isset($data[0], $data[1], $data[2], $data[3], $data[4], $data[5])) {
         // TODO: remove this code after a while
         // If $data[3] is something besides 0 or 1, it was created before Craft 2.2, and represents the auth timeout
         // rather than whether Remember Me was checked. Let's fix that.
         if ($data[3] != 0 && $data[3] != 1) {
             // Delete the old rememberMe cookie(s)
             craft()->request->deleteCookie('rememberMe');
             $this->deleteStateCookie('rememberMe');
             // Replace $data[3]'s value with a 0 or 1
             $duration = craft()->config->get('rememberedUserSessionDuration');
             if (is_numeric($data[3]) && $data[3] >= DateTimeHelper::timeFormatToSeconds($duration)) {
                 $data[3] = 1;
             } else {
                 $data[3] = 0;
             }
         }
         return $data;
     }
 }
开发者ID:kant312,项目名称:sop,代码行数:31,代码来源:UserSessionService.php

示例5: getElevatedSessionDuration

 /**
  * Returns the configured elevated session duration in seconds.
  *
  * @return int The elevated session duration in seconds.
  */
 public function getElevatedSessionDuration()
 {
     $duration = craft()->config->get('elevatedSessionDuration');
     if ($duration) {
         return DateTimeHelper::timeFormatToSeconds($duration);
     }
     // Default to 5 minutes
     return 300;
 }
开发者ID:codeforamerica,项目名称:oakland-beta,代码行数:14,代码来源:ConfigService.php

示例6: getUserSessionDuration

 /**
  * Returns the configured user session duration in seconds, or `null` if there is none because user sessions should
  * expire when the HTTP session expires.
  *
  * You can choose whether the
  * [rememberedUserSessionDuration](http://craftcms.com/docs/config-settings#rememberedUserSessionDuration)
  * or [userSessionDuration](http://craftcms.com/docs/config-settings#userSessionDuration) config setting
  * should be used with the $remembered param. If rememberedUserSessionDuration’s value is empty (disabling the
  * feature) then userSessionDuration will be used regardless of $remembered.
  *
  * @param bool $remembered Whether the rememberedUserSessionDuration config setting should be used if it’s set.
  *                         Default is `false`.
  *
  * @return int|null The user session duration in seconds, or `null` if user sessions should expire along with the
  *                  HTTP session.
  */
 public function getUserSessionDuration($remembered = false)
 {
     if ($remembered) {
         $duration = craft()->config->get('rememberedUserSessionDuration');
     }
     // Even if $remembered = true, it's possible that they've disabled long-term user sessions
     // by setting rememberedUserSessionDuration = 0
     if (empty($duration)) {
         $duration = craft()->config->get('userSessionDuration');
     }
     if ($duration) {
         return DateTimeHelper::timeFormatToSeconds($duration);
     }
 }
开发者ID:jmstan,项目名称:craft-website,代码行数:30,代码来源:ConfigService.php

示例7: getElevatedSessionDuration

 /**
  * Returns the configured elevated session duration in seconds.
  *
  * @return int|boolean The elevated session duration in seconds or false if it has been disabled.
  */
 public function getElevatedSessionDuration()
 {
     $duration = craft()->config->get('elevatedSessionDuration');
     // See if it has been disabled.
     if ($duration === false) {
         return false;
     }
     if ($duration) {
         return DateTimeHelper::timeFormatToSeconds($duration);
     }
     // Default to 5 minutes
     return 300;
 }
开发者ID:andyra,项目名称:tes,代码行数:18,代码来源:ConfigService.php


注:本文中的DateTimeHelper::timeFormatToSeconds方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。