Exemplo n.º 1
0
 public function __construct()
 {
     // Remember the script's current execution time limit and the amount of time that has elapsed since the script
     // started.
     $this->m_exeTimeLimitBeforePause = CSystem::executionTimeLimit();
     $this->m_secondsElaplsedBeforePause = CTime::now()->diffInSeconds(CSystem::startTime());
     // Remove the existing execution time limit.
     CSystem::removeExecutionTimeLimit();
 }
Exemplo n.º 2
0
 function actionChat()
 {
     $userid = $this->userid;
     //管理员的userid
     $page = $this->get('page', 1);
     $limit = $this->get('limit', 20);
     $exArr = array('page' => $page, 'limit' => $limit, 'order' => 'id desc', 'fields' => 'id,userid,targetid friendid,content msg,ctime');
     //lastime
     if (1) {
         $MMessage = $this->LoadApiModel('message');
         $date = $this->get('date');
         list($date_start, $date_end) = CTime::DeltaMonths(-1);
         // echo "$date_start, $date_end";
         $date = $date ? $date : $date_start;
         $friendid = $this->get('id');
         if ($friendid) {
             //我与指定好友的消息(也就是我发给别人的)
             $whArr = array('type' => 0, 'targetid in' => array($friendid, $userid), 'removed>' => -1);
             $messArr = $MMessage->getMessages(null, $whArr, $exArr);
         } else {
             //别人发给我的
             $whArr = array('type' => 0, 'or' => array('userid' => $userid, 'targetid' => $userid), 'removed>' => -1);
             // $exArr['fields'] .= ',max(ctime) lastime';
             // $exArr['group']   = 'userid,targetid';
             $messArr = $MMessage->getLastMessages($userid, $page);
             // print_r($messArr);
             $messArr = array('data' => $messArr, 'total' => count($messArr));
         }
         CFun::removeArrayNull($whArr);
         // print_r($whArr);
         // print_r($messArr);
         if (false !== $messArr) {
             if (isset($messArr['data'])) {
                 $MUser = $this->LoadApiModelMedical('user');
                 $uid_fild = $friendid ? 'userid' : 'friendid';
                 $fid_arr = $this->getArrayColumn($messArr['data'], $uid_fild);
                 $userArr = $MUser->getUsers($fid_arr, null, array('limit' => count($fid_arr), 'only_data' => true, 'fields' => 'id,username,idcard,mobile'));
                 if ($friendid) {
                     $messArr['data'] = $this->joinToArray($messArr['data'], $userArr, 'userid:id', 'user');
                 } else {
                     $messArr['data'] = $this->joinToArray($messArr['data'], $userArr, 'friendid:id', 'user');
                 }
             }
             $this->response($messArr);
         }
     }
     $this->error('没有任何消息');
 }
Exemplo n.º 3
0
 /**
  * Returns the point in time when the request was received.
  *
  * @return CTime The point in time when the request was received.
  */
 public static function time()
 {
     if (CMap::hasKey($_SERVER, "REQUEST_TIME_FLOAT")) {
         $FTime = $_SERVER["REQUEST_TIME_FLOAT"];
         if (isset($FTime)) {
             return CTime::fromFTime($FTime);
         }
     }
     return new CTime($_SERVER["REQUEST_TIME"]);
 }
Exemplo n.º 4
0
 protected static function shiftTimeInTimeZone(CTime $time, $timeUnit, $quantity, $timeZone)
 {
     $units;
     switch ($timeUnit) {
         case self::SECOND:
             $units = "seconds";
             break;
         case self::MINUTE:
             $units = "minutes";
             break;
         case self::HOUR:
             $units = "hours";
             break;
         case self::DAY:
             $units = "days";
             break;
         case self::WEEK:
             $units = "weeks";
             break;
         case self::MONTH:
             $units = "months";
             break;
         case self::YEAR:
             $units = "years";
             break;
         default:
             assert('false', vs(isset($this), get_defined_vars()));
             break;
     }
     $dt = new DateTime();
     $dt->setTimestamp($time->UTime());
     $dt->setTimezone(is_cstring($timeZone) ? new DateTimeZone($timeZone) : $timeZone->DTimeZone());
     $sign = $quantity < 0 ? "-" : "+";
     $absQty = CString::fromInt(CMathi::abs($quantity));
     $dt->modify("{$sign}{$absQty} {$units}");
     $UTime = $dt->getTimestamp();
     $MTime = $time->MTime();
     if ($UTime != 0 && $MTime != 0 && CMathi::sign($UTime) != CMathi::sign($MTime)) {
         if ($UTime < 0) {
             // $MTime > 0
             $UTime++;
             $MTime -= 1000;
         } else {
             // $MTime < 0
             $UTime--;
             $MTime += 1000;
         }
     }
     return new self($UTime, $MTime);
 }
Exemplo n.º 5
0
 /**
  * @ignore
  */
 public static function maybeUpdateThirdParty()
 {
     if (!self::isInCliMode()) {
         // This method can be run in CLI mode only.
         assert('false', vs(isset($this), get_defined_vars()));
         return false;
     }
     $updates = CConfiguration::option("updates");
     $updatesAreEnabled = $updates["enable"];
     if ($updatesAreEnabled) {
         $minTimeBetweenDoUpdatesDays = $updates["minTimeBetweenDoUpdatesDays"];
         $components = $updates["components"];
         assert('is_int($minTimeBetweenDoUpdatesDays)', vs(isset($this), get_defined_vars()));
         // Logging.
         $logging = $updates["logging"];
         $loggingIsEnabled = $logging["enable"];
         $logFp = $logging["logFilePath"];
         if ($loggingIsEnabled) {
             assert('!CString::isEmpty($logFp)', vs(isset($this), get_defined_vars()));
             $logFp = CFilePath::frameworkPath($logFp);
             CShell::setLogging($logFp);
         }
         // Mailing.
         $mailing = $updates["mailing"];
         $mailingIsEnabled = $mailing["enable"];
         if ($mailingIsEnabled) {
             $adminMail = CConfiguration::option("admin.mail");
             $to = $adminMail["to"];
             $from = $adminMail["from"];
             $transport = $adminMail["transport"];
             assert('!CString::isEmpty($to) && !CString::isEmpty($from) && !CString::isEmpty($transport)', vs(isset($this), get_defined_vars()));
             $mail;
             if (CString::equalsCi($transport, "smtp")) {
                 $smtpOutgoingServer = $adminMail["smtpOutgoingServer"];
                 $smtpUsername = $adminMail["smtpUsername"];
                 $smtpPassword = $adminMail["smtpPassword"];
                 assert('!CString::isEmpty($smtpOutgoingServer) && !CString::isEmpty($smtpUsername) && ' . '!CString::isEmpty($smtpPassword)', vs(isset($this), get_defined_vars()));
                 $mail = CMail::makeSmtp($smtpOutgoingServer, $smtpUsername, $smtpPassword, $from, $to);
             } else {
                 if (CString::equalsCi($transport, "system")) {
                     $mail = CMail::makeSystem($from, $to);
                 } else {
                     assert('false', vs(isset($this), get_defined_vars()));
                 }
             }
             CShell::setMailing($mail);
         }
         $thirdPartyDp = $GLOBALS["PHRED_PATH_TO_THIRD_PARTY"];
         $lastUpdateTimeFp = CFilePath::add($thirdPartyDp, self::$ms_thirdPartyLastUpdateTimeFn);
         // Read the file containing the Unix seconds of the last update time stamp (if exists) and compare that
         // time with the current time.
         $numDaysSinceLastUpdate;
         if (CFile::exists($lastUpdateTimeFp)) {
             $lastUpdateTime = new CTime(CString::toInt(CFile::read($lastUpdateTimeFp)));
             $currTime = CTime::now();
             if ($lastUpdateTime->isBefore($currTime)) {
                 $numDaysSinceLastUpdate = $currTime->diffInDays($lastUpdateTime);
                 if ($numDaysSinceLastUpdate < $minTimeBetweenDoUpdatesDays) {
                     // It is too early for updates yet.
                     return false;
                 }
             } else {
                 assert('false', vs(isset($this), get_defined_vars()));
             }
         }
         $date = CShell::currentDate();
         CShell::say("Started on {$date}.");
         if (isset($numDaysSinceLastUpdate)) {
             CShell::say("It has been {$numDaysSinceLastUpdate} day(s) since last successful update.");
         }
         $concurrLockFp = CFilePath::add($thirdPartyDp, self::$ms_thirdPartyConcurrLockFn);
         // Try locking the operation.
         if (!self::setLock($concurrLockFp, false)) {
             assert('false', vs(isset($this), get_defined_vars()));
             CShell::onError(false, "Could not obtain a lock on the operation.");
             CShell::writeToLog("\n");
             return false;
         }
         $phpConfigNeedsReload = false;
         $totalNumComponents = CMap::length($components);
         $numComponentsUpdated = 0;
         // The Browser Capabilities Project (BrowsCap).
         if (CMap::hasKey($components, "browsCap")) {
             $browsCap = $components["browsCap"];
             $skip = $browsCap["skip"];
             if (!$skip) {
                 CShell::say("Updating the Browser Capabilities Project (BrowsCap) ...");
                 $lookupFileUrl = $browsCap["lookupFileUrl"];
                 assert('!CString::isEmpty($lookupFileUrl)', vs(isset($this), get_defined_vars()));
                 // Component-related constants.
                 static $s_configOptName = "browscap";
                 static $s_lookupFileDownloadTimeoutSeconds = 120;
                 if (self::hasConfigOption($s_configOptName)) {
                     $browsCapLookupFp = CString::trim(self::configOption($s_configOptName));
                     if (!CString::isEmpty($browsCapLookupFp)) {
                         $browsCapDp = CFilePath::directory($browsCapLookupFp);
                         CShell::say("Downloading a BrowsCap lookup file from '{$lookupFileUrl}' ...");
                         $temporaryFp = CFile::createTemporary($browsCapDp);
                         $downloadRes = CInetRequest::downloadFile($lookupFileUrl, $temporaryFp, $s_lookupFileDownloadTimeoutSeconds);
                         if ($downloadRes) {
                             // After the file is downloaded into a temporary one, move it to the destination,
                             // safely replacing the existing file, if any.
                             CFile::move($temporaryFp, $browsCapLookupFp);
                             $numComponentsUpdated++;
                             $phpConfigNeedsReload = true;
                             $downloadedFileSizeKB = CUUnit::convertStoragef((double) CFile::size($browsCapLookupFp), CUUnit::BYTE, CUUnit::KILOBYTE);
                             $downloadedFileSizeKB = CMathf::round($downloadedFileSizeKB, 2);
                             CShell::say("Done. The downloaded file is {$downloadedFileSizeKB} KB in size.");
                         } else {
                             CShell::onError(false, "Could not download a BrowsCap lookup file from '{$lookupFileUrl}'.");
                         }
                         // Just in case, check for any temporary files that could have been left by any previous
                         // operations in the directory.
                         $leftoverFiles = CFile::findFiles(CFilePath::add($browsCapDp, CFile::DEFAULT_TEMPORARY_FILE_PREFIX . "*"));
                         if (!CArray::isEmpty($leftoverFiles)) {
                             // Cleanup the directory from the temporary files.
                             $len = CArray::length($leftoverFiles);
                             for ($i = 0; $i < $len; $i++) {
                                 CFile::delete($leftoverFiles[$i]);
                             }
                         }
                     } else {
                         CShell::onError(false, "Could not read the value of '{$s_configOptName}' option " . "in the PHP CLI configuration file.");
                     }
                 } else {
                     CShell::onError(false, "Could not find '{$s_configOptName}' option in the PHP CLI configuration file.");
                 }
             } else {
                 CShell::say("Skipping the Browser Capabilities Project (BrowsCap).");
             }
         }
         // All the components have been processed. Unlock the operation.
         self::unsetLock($concurrLockFp);
         $date = CShell::currentDate();
         if ($numComponentsUpdated != 0) {
             // One or more third-party components have been updated. Put a time stamp on the directory where the
             // components are located.
             CFile::write($lastUpdateTimeFp, CString::fromInt(CTime::currentUTime()));
             if ($numComponentsUpdated == $totalNumComponents) {
                 CShell::speak("Success. All {$totalNumComponents} third-party component(s)");
             } else {
                 CShell::speak("Partial success. {$numComponentsUpdated} out of {$totalNumComponents} third-party component(s)");
             }
             CShell::say("have been updated. Completed on {$date}.");
         } else {
             CShell::say("No third-party components have been updated. Completed on {$date}.");
         }
         return $phpConfigNeedsReload;
     } else {
         return false;
     }
 }
Exemplo n.º 6
0
 /**
  * Sets the declarative time when a message was sent.
  *
  * @param  CTime $time The point in time to be declared as the moment of the message's dispatching.
  *
  * @return void
  */
 public function setTime(CTime $time)
 {
     assert('isset($this->m_swiftMessage)', vs(isset($this), get_defined_vars()));
     $this->m_swiftMessage->setDate($time->UTime());
 }
Exemplo n.º 7
0
 public function testWithYearLocal()
 {
     $year = 2009;
     $month = 2;
     $day = 13;
     $hour = 23;
     $minute = 31;
     $second = 30;
     $time = CTime::fromComponentsLocal($year, $month, $day, $hour, $minute, $second);
     $time = $time->withYearLocal(1930);
     $this->assertTrue($time->toStringLocal(CTime::PATTERN_MYSQL)->equals("1930-02-13 23:31:30"));
 }
Exemplo n.º 8
0
 public function testModificationTime()
 {
     $filePath = CFile::createTemporary();
     $modTime = CFile::modificationTime($filePath);
     $this->assertTrue($modTime->diffInSeconds(CTime::now()) <= 5);
     CFile::delete($filePath);
 }
Exemplo n.º 9
0
 /**
  * Returns the point in time when the response's entity was last modified, according to the value of the
  * "Last-Modified" HTTP header.
  *
  * This method can be called for HTTP requests only.
  *
  * @return CTime The point in time when the response's entity was last modified, according to the value of the
  * "Last-Modified" HTTP header.
  */
 public function responseModificationTime()
 {
     assert('$this->isHttp() && $this->m_done && !$this->m_hasError', vs(isset($this), get_defined_vars()));
     assert('$this->responseHasModificationTime()', vs(isset($this), get_defined_vars()));
     $modificationTime = $this->responseHeader(CHttpResponse::LAST_MODIFIED);
     return CTime::fromString($modificationTime);
 }
Exemplo n.º 10
0
 /**
  * Formats a point in time as a string in a specified time zone according to a specified pattern and the formatting
  * rules used in the default or some other locale and returns the formatted string.
  *
  * The formatting patterns that you can use to format a point in time with this method are described in
  * [Date Format Patterns](http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns) of the Unicode
  * Technical Standard #35.
  *
  * @param  CTime $time The point in time to be formatted.
  * @param  CTimeZone $timeZone The time zone in which the components in the resulting string are to appear.
  * @param  string $pattern The formatting pattern.
  * @param  CULocale $inLocale **OPTIONAL. Default is** *the application's default locale*. The locale in which the
  * point in time is to be formatted.
  *
  * @return CUStringObject A string with the formatted point in time.
  */
 public static function timeWithPattern(CTime $time, CTimeZone $timeZone, $pattern, CULocale $inLocale = null)
 {
     assert('is_cstring($pattern)', vs(isset($this), get_defined_vars()));
     $locale = isset($inLocale) ? $inLocale->name() : CULocale::defaultLocaleName();
     $intlDateFormatter = new IntlDateFormatter($locale, IntlDateFormatter::FULL, IntlDateFormatter::FULL, $timeZone->ITimeZone(), null, $pattern);
     $strTime = $intlDateFormatter->format($time->UTime());
     if (is_cstring($strTime)) {
         return $strTime;
     } else {
         assert('false', vs(isset($this), get_defined_vars()));
         return "";
     }
 }
Exemplo n.º 11
0
 /**
  * Sets the point in time after which a cookie should be considered expired, as a known moment.
  *
  * @param  CTime $time The point in time when the cookie should expire.
  *
  * @return void
  */
 public function setExpireTime(CTime $time)
 {
     $this->m_expireUTime = $time->UTime();
 }
Exemplo n.º 12
0
 public function testOrderDesc()
 {
     $this->assertTrue(CComparator::orderDesc(u("Hello there!"), u("Hello there!")) == 0);
     $this->assertTrue(CComparator::orderDesc(u("A"), u("B")) > 0);
     $this->assertTrue(CComparator::orderDesc(u("C"), u("B")) < 0);
     $this->assertTrue(CComparator::orderDesc(u("¡Hola señor!"), u("¡Hola señor!")) == 0);
     $this->assertTrue(CComparator::orderDesc(u("A"), u("B")) > 0);
     $this->assertTrue(CComparator::orderDesc(u("C"), u("B")) < 0);
     $this->assertTrue(CComparator::orderDesc(a("a", "b", "c"), a("a", "b", "c")) == 0);
     $this->assertTrue(CComparator::orderDesc(a("b", "b", "c"), a("a", "b", "c")) < 0);
     $this->assertTrue(CComparator::orderDesc(m(["one" => "a", "two" => "b", "three" => "c"]), m(["one" => "a", "two" => "b", "three" => "c"])) == 0);
     $this->assertTrue(CComparator::orderDesc(m(["one" => "b", "two" => "b", "three" => "c"]), m(["one" => "a", "two" => "b", "three" => "c"])) < 0);
     $this->assertTrue(CComparator::orderDesc(CTime::fromString("11/5/1955 12:00:00 PST"), CTime::fromString("11/5/1955 12:00:00 PST")) == 0);
     $this->assertTrue(CComparator::orderDesc(CTime::fromString("11/5/1955 12:00:00 PST"), CTime::fromString("11/5/1985 12:00:00 PST")) > 0);
     $this->assertTrue(CComparator::orderDesc(CTime::fromString("11/5/1985 12:00:01 PST"), CTime::fromString("11/5/1985 12:00:00 PST")) < 0);
     $this->assertTrue(CComparator::orderDesc(true, true) == 0);
     $this->assertTrue(CComparator::orderDesc(false, true) > 0);
     $this->assertTrue(CComparator::orderDesc(true, false) < 0);
     $this->assertTrue(CComparator::orderDesc(1234, 1234) == 0);
     $this->assertTrue(CComparator::orderDesc(1234, 5678) > 0);
     $this->assertTrue(CComparator::orderDesc(5678, 1234) < 0);
     $this->assertTrue(CComparator::orderDesc(12.34, 12.34) == 0);
     $this->assertTrue(CComparator::orderDesc(12.34, 56.78) > 0);
     $this->assertTrue(CComparator::orderDesc(56.78, 12.34) < 0);
     $this->assertTrue(CComparator::orderDesc(null, null) == 0);
     $this->assertTrue(CComparator::orderDesc("Hello there!", "Hello there!") == 0);
     $this->assertTrue(CComparator::orderDesc("A", "B") > 0);
     $this->assertTrue(CComparator::orderDesc("C", "B") < 0);
     $this->assertTrue(CComparator::orderDesc(CArray::fromElements("a", "b", "c"), CArray::fromElements("a", "b", "c")) == 0);
     $this->assertTrue(CComparator::orderDesc(CArray::fromElements("a", "b", "c"), CArray::fromElements("b", "b", "c")) > 0);
     $this->assertTrue(CComparator::orderDesc(CArray::fromElements("b", "b", "c"), CArray::fromElements("a", "b", "c")) < 0);
     $this->assertTrue(CComparator::orderDesc(["one" => "a", "two" => "b", "three" => "c"], ["one" => "a", "two" => "b", "three" => "c"]) == 0);
     $this->assertTrue(CComparator::orderDesc(["one" => "a", "two" => "b", "three" => "c"], ["one" => "b", "two" => "b", "three" => "c"]) > 0);
     $this->assertTrue(CComparator::orderDesc(["one" => "b", "two" => "b", "three" => "c"], ["one" => "a", "two" => "b", "three" => "c"]) < 0);
 }