Пример #1
0
 /**
  * 判断验证码是否正确
  */
 public function checkAuthCode()
 {
     $this->outType = 'json';
     $number = CommonRequest::getRequest('number');
     $autoCode = CommonRequest::getRequest('authCode');
     $cache = CommonCache::getInstance('localhost', 11211);
     $randNumber = $cache->get($number . "_authCode");
     if ($autoCode == $randNumber) {
         $_SESSION['number'] = $number;
         $this->out = array('flag' => true);
     } else {
         $this->out = array('flag' => false);
     }
 }
Пример #2
0
 /**
  * Render the source or file
  *
  * @see HamlParser::fetch()
  * @return string
  */
 public function render(array $aContext = array())
 {
     $__aSource = explode(self::TOKEN_LINE, $this->sRealSource = $this->sSource = $this->parseBreak($this->sSource));
     $__sCompiled = '';
     if ($this->oParent instanceof HamlParser) {
         $__sCompiled = $this->parseLine($__aSource[0]);
     } else {
         $__oCache = new CommonCache($this->sTmp, 'hphp', $this->sSource);
         $this->aChildren = array();
         if ($__oCache->isCached() && $this->bCompile && !$this->isDebug()) {
             $__sCompiled = $__oCache->getFilename();
         } else {
             $__sGenSource = $this->parseIncludes($this->sSource);
             $this->sSource = $this->sRealSource = $__sGenSource;
             $__aSource = explode(self::TOKEN_LINE, $__sGenSource);
             $__sCompiled = $__oCache->setCached($this->parseFile($__aSource))->cacheIt()->getFilename();
         }
         $__c = $this->execute($__sCompiled, $aContext);
         return $__c;
     }
     return $__sCompiled;
 }
 /**
  * Render Sass code
  *
  * @param string Filename
  * @param string SassRenderer type
  * @return string
  */
 public function render($file = null, $type = null)
 {
     if (!is_null($file)) {
         $this->setFile($file);
     }
     if (!is_null($type)) {
         $this->setRenderer($type);
     }
     $cache = new CommonCache($this->getTmp(), 'css', $this->getSource());
     if (!$cache->isCached()) {
         // BEGIN: Flat to tree structure
         $lines = explode(self::TOKEN_LINE, $this->getSource());
         $last = array(-1 => null);
         $attributes = array();
         $attributeLevel = 0;
         $namespace = null;
         $namespaceLevel = 0;
         foreach ($lines as $line) {
             $stop = true;
             $cleaned = $this->cleanLine($line);
             $level = $this->countLevel($line);
             // Check for constant definition
             if (preg_match('/^' . preg_quote(self::TOKEN_CONSTANT) . '(.+?)[ ]?' . preg_quote(self::TOKEN_CONSTANT_VALUE) . '[ ]?["]?(.+)["]?/', $cleaned, $matches)) {
                 $this->setConstant($matches[1], $matches[2]);
             } else {
                 // Check for dynamic attribute definition
                 if (preg_match('/^' . preg_quote(self::TOKEN_ATTRIBUTE) . '(.+?)[ ]?' . preg_quote(self::TOKEN_ATTRIBUTE_CALCULATE) . '[ ]?(.+)/', $cleaned, $matches)) {
                     if ($namespaceLevel + 1 != $level) {
                         $namespace = null;
                     }
                     $attributes[empty($namespace) ? $matches[1] : "{$namespace}-{$matches[1]}"] = $this->calculate($matches[2]);
                     $attributeLevel = $level - (empty($namespace) ? 1 : 2);
                 } else {
                     // Check for attribute definition
                     if (preg_match('/^' . preg_quote(self::TOKEN_ATTRIBUTE) . '(.+?) (.+)/', $cleaned, $matches)) {
                         if ($namespaceLevel + 1 != $level) {
                             $namespace = null;
                         }
                         $attributes[empty($namespace) ? $matches[1] : "{$namespace}-{$matches[1]}"] = $matches[2];
                         $attributeLevel = $level - (empty($namespace) ? 1 : 2);
                     } else {
                         // Check for attribute namespace
                         if (preg_match('/^' . preg_quote(self::TOKEN_ATTRIBUTE_NAMESPACE) . '(.+)/', $cleaned, $matches)) {
                             $namespace = $matches[1];
                             $namespaceLevel = $level;
                         } else {
                             // Check for comment
                             if (preg_match('|^' . preg_quote(self::TOKEN_COMMENT) . '|', $cleaned)) {
                                 $stop = true;
                             } else {
                                 $stop = false;
                                 $namespace = null;
                             }
                         }
                     }
                 }
             }
             // Remove blank lines
             if (empty($cleaned) || $stop) {
                 continue;
             }
             // Assign attributes
             if (!empty($attributes) && $last[$attributeLevel] instanceof SassElement) {
                 foreach ($attributes as $name => $value) {
                     $last[$attributeLevel]->setAttribute($name, $value);
                 }
                 $attributeLevel = 0;
                 $attributes = array();
             }
             // Get parent element
             $parent = $last[$level - 1];
             // Create new element
             $element = new SassElement($parent, $cleaned);
             // Mark as parent
             $last[$level] = $element;
             if ($level == 0) {
                 $this->addElement($element);
             }
         }
         // Assign attributes
         if (!empty($attributes) && $last[$attributeLevel] instanceof SassElement) {
             foreach ($attributes as $name => $value) {
                 $last[$attributeLevel]->setAttribute($name, $value);
             }
             $attributeLevel = 0;
             $attributes = array();
         }
         // END: Flat to tree structure
         // Render to CSS
         return $cache->setCached(SassRenderer::getInstance($this->getElements(), $this->getRenderer())->render())->cacheIt()->getCached();
     } else {
         return $cache->getCached();
     }
 }