Example #1
0
 /**
  * 输出内容,可以是数组,可以是文本
  *
  * @param array | string $mix 输出内容
  * @param bool $exit 是否结束程序
  */
 public static function output($mix, $exit = true)
 {
     global $_F;
     $response = new self();
     if (is_array($mix)) {
         $response->setContentType('json');
         if ($_F['debug']) {
             $mix['debug_info'] = $_F['debug_info'];
         }
         $response->write(json_encode($mix));
     } elseif (is_string($mix)) {
         $response->write($mix);
     }
     $exit && exit;
 }
 public static function remove($projectModel, $commentId)
 {
     // old method self:mapper($projectModel->databaseName())->remove($commentId);
     $comment = new self($projectModel, $commentId);
     $comment->isDeleted = true;
     return $comment->write();
 }
 /**
  * @param $member
  * @param $category_id
  * @throws ValidationException
  * @throws null
  */
 public static function addChair($member, $category_id)
 {
     $priorChair = SummitTrackChair::get()->filter('MemberID', $member->ID)->first();
     $category = PresentationCategory::get()->byID($category_id);
     if (!$priorChair) {
         $chair = new self();
         $chair->MemberID = $member->ID;
         $chair->write();
         $chair->Categories()->add($category);
         //Find or create the 'track-chairs' group
         if (!($Group = Group::get()->filter('Code', 'track-chairs')->first())) {
             $Group = new Group();
             $Group->Code = "track-chairs";
             $Group->Title = "Track Chairs";
             $Group->Write();
             $member->Groups()->add($Group);
         }
         //Add member to the group
         $member->Groups()->add($Group);
         return $chair->ID;
     } else {
         $priorChair->Categories()->add($category);
         $priorChair->Member()->addToGroupByCode('track-chairs');
         return $priorChair->ID;
     }
 }
Example #4
0
 /**
  * @param string                  $filename
  * @param string|null             $content
  * @param CM_File_Filesystem|null $filesystem
  * @throws CM_Exception_Invalid
  * @return CM_File_UserContent_Temp
  */
 public static function create($filename, $content = null, CM_File_Filesystem $filesystem = null)
 {
     if ($filesystem) {
         throw new CM_Exception_Invalid('Temporary user-content file cannot handle filesystem');
     }
     $filename = (string) $filename;
     if (strlen($filename) > 100) {
         $filename = substr($filename, -100, 100);
     }
     $uniqid = md5(rand() . uniqid());
     CM_Db_Db::insert('cm_tmp_userfile', array('uniqid' => $uniqid, 'filename' => $filename, 'createStamp' => time()));
     $file = new self($uniqid);
     $file->ensureParentDirectory();
     if (null !== $content) {
         $file->write($content);
     }
     return $file;
 }
Example #5
0
 static function coloredOutput($message = "", $print = true)
 {
     $cli = new self('');
     // we're not using regex here because simple str_replace is faster. However,
     // we may need to go that route if this function gets too complex
     $message = str_replace('</M>', '%n', str_replace('<M>', '%M', $message));
     $message = str_replace('</m>', '%n', str_replace('<m>', '%m', $message));
     $message = str_replace('</G>', '%n', str_replace('<G>', '%G', $message));
     $message = str_replace('</y>', '%n', str_replace('<y>', '%y', $message));
     $message = str_replace('</Y>', '%n', str_replace('<Y>', '%Y', $message));
     $message = str_replace('</R>', '%n', str_replace('<R>', '%R', $message));
     $message = str_replace('</r>', '%n', str_replace('<r>', '%r', $message));
     $message = str_replace('</K>', '%n', str_replace('<K>', '%K', $message));
     $message = \cli\Colors::colorize("{$message}", $cli->in_color);
     if ($print) {
         $cli->write(STDOUT, "{$message}\n");
     }
     return $message;
 }
Example #6
0
 static function __init()
 {
     self::$savePath = $CONFIG['session.save_path'];
     self::$cookiePath = $CONFIG['session.cookie_path'];
     self::$cookieDomain = $CONFIG['session.cookie_domain'];
     $CONFIG['session.auth_vars'] && (self::$authVars = array_merge(self::$authVars, $CONFIG['session.auth_vars']));
     $CONFIG['session.group_vars'] && (self::$groupVars = array_merge(self::$groupVars, $CONFIG['session.group_vars']));
     self::$authVars = array_flip(self::$authVars);
     self::$groupVars = array_flip(self::$groupVars);
     if (self::$maxIdleTime < 1 && self::$maxLifeTime < 1) {
         user_error('At least one of the SESSION::$max*Time variables must be strictly positive.');
     }
     if (mt_rand(1, self::$gcProbabilityDenominator) <= self::$gcProbabilityNumerator) {
         $adapter = new self('0lastGC');
         $i = $adapter->read();
         $j = max(self::$maxIdleTime, self::$maxLifeTime);
         if ($j && $_SERVER['REQUEST_TIME'] - $i > $j) {
             $adapter->write($_SERVER['REQUEST_TIME']);
             register_shutdown_function(array(__CLASS__, 'gc'), $j);
         }
         unset($adapter);
     }
     if (isset($_COOKIE['SID'])) {
         self::setSID($_COOKIE['SID']);
         self::$adapter = new self(self::$SID);
         $i = self::$adapter->read();
     } else {
         $i = false;
     }
     if ($i) {
         $i = unserialize($i);
         self::$lastseen = $i[0];
         self::$birthtime = $i[1];
         if (self::$maxIdleTime && $_SERVER['REQUEST_TIME'] - self::$lastseen > self::$maxIdleTime) {
             // Session has idled
             self::onIdle();
             self::$isIdled = true;
         } else {
             if (self::$maxLifeTime && $_SERVER['REQUEST_TIME'] - self::$birthtime > self::$maxLifeTime) {
                 // Session has expired
                 self::onExpire();
             } else {
                 self::$DATA =& $i[2];
             }
         }
         if (isset($_SERVER['HTTPS']) && (!isset($_COOKIE['SSL']) || $i[3] != $_COOKIE['SSL'])) {
             self::regenerateId(true);
         } else {
             self::$sslid = $i[3];
             if ('-' == self::$sslid[0] && isset($_SERVER['HTTPS'])) {
                 self::$sslid = p::strongId();
                 setcookie('SSL', self::$sslid, 0, self::$cookiePath, self::$cookieDomain, true, true);
                 unset($_SERVER['HTTP_IF_NONE_MATCH'], $_SERVER['HTTP_IF_MODIFIED_SINCE']);
             }
         }
     } else {
         self::regenerateId(true);
     }
 }
Example #7
0
 /**
  * Writes all of the models
  *
  * @param Configuration $configuration
  * @param string[] $ignoredTables
  *
  * @return void
  */
 public static function writeAll(Configuration $configuration, array $ignoredTables = [])
 {
     $results = $configuration->getConnection()->query('SHOW FULL TABLES WHERE Table_Type!="VIEW"');
     while ($result = $results->fetch()) {
         $result = (object) $result;
         $table = null;
         foreach ($result as $column) {
             $table = $column;
             break;
         }
         if (in_array($table, $ignoredTables)) {
             continue;
         }
         $index = new self($configuration, $table);
         $index->write();
     }
 }
Example #8
0
 /**
  * Dumps a Geometry Object into a  WKT string
  *
  * @param Geometry\Geometry $geometry
  *
  * @return String A WKT string corresponding to passed object
  */
 public static function dump(Geometry\Geometry $geometry)
 {
     $instance = new self();
     return $instance->write($geometry);
 }
 /**
  * 
  * @param string $tmp_name path to file
  * @param string $type mime type
  * @return self
  * @throws Exception
  */
 public static function createFromFile($tmp_name, $type)
 {
     $mime_type = ElggFile::detectMimeType($tmp_name, $type);
     if (false == in_array($mime_type, array("image/jpeg", "image/jpg"))) {
         register_error(elgg_echo("gallery_field:only_jpg"));
         return null;
     }
     $ext = "jpg";
     $file = new self();
     $thumb_file = new ElggFile();
     $random_guid = self::genGUID();
     $file->setFilename($random_guid . "." . $ext);
     $thumb_file->setFilename($random_guid . "_thumb." . $ext);
     $file->setMimeType($mime_type);
     $thumb_file->setMimeType($mime_type);
     $imgsizearray = getimagesize($tmp_name);
     if ($imgsizearray == false) {
         register_error("bad file");
         return null;
     }
     $width = $imgsizearray[0];
     $height = $imgsizearray[1];
     $file->open("write");
     $file->write(self::cropImage($tmp_name, $width, $height, 760, 580));
     $file->close();
     $file->access_id = 2;
     $thumb_file->open("write");
     $thumb_file->write(self::cropImage($tmp_name, $width, $height, 200, 140));
     $thumb_file->close();
     $thumb_file->access_id = 2;
     $thumb_file->save();
     $file->thumb_file_guid = $thumb_file->guid;
     $file->save();
     return $file;
 }
Example #10
0
 /**
  * Crea un file ed inserisce il contenuto al suo interno
  * @param type $text
  * @param type $filename
  * @return \self
  */
 public static function createFileFromText($text, $filename = null)
 {
     if (is_null($filename)) {
         $filename = tmpfile();
     }
     $self = new self($filename, 'w+');
     $self->write($text);
     return $self;
 }
Example #11
0
 /**
  * Generate code within a class and return it.
  * 
  * @param string $key Will be prepended to the class name to make it unique.
  * @return string
  */
 public function generateCode($key)
 {
     if ($this->extends === NULL && $this->output != '') {
         $this->buffer .= "\t\t\$out->write(" . var_export($this->output, true) . ");\n";
         $this->output = '';
     }
     $buffer = sprintf("<?php\n\nnamespace %s {\n\n", __NAMESPACE__);
     $buffer .= 'use KoolKode\\View\\TagBuilder;' . "\n";
     $buffer .= "\n";
     $buffer .= sprintf('final class CompiledTemplate_%s extends CompiledTemplate {' . "\n\n", $key);
     for ($count = count($this->fields), $step = 8, $i = 0; $i < $count; $i += $step) {
         $buffer .= "\tprivate \$" . $this->fields[$i];
         for ($max = min($count, $i + $step), $j = $i + 1; $j < $max; $j++) {
             $buffer .= ', $' . $this->fields[$j];
         }
         $buffer .= ";\n";
     }
     $buffer .= "\n\tpublic function getResource() {\n";
     $buffer .= "\t\treturn " . var_export($this->resource, true) . ";\n";
     $buffer .= "\t}\n";
     if ($this->extends === NULL) {
         $buffer .= "\n\tprotected function renderMain(OutputBuffer \$out) {\n\n";
         $buffer .= "\t\t\$pout = \$this->context->set('@out', \$out);\n";
         $buffer .= "\t\t\$pthis = \$this->context->set('@this', \$this);\n";
         $buffer .= "\t\ttry {\n";
         $buffer .= "\n" . $this->buffer . "\n";
         $buffer .= "\t\t} finally {\n";
         $buffer .= "\t\t\t\$this->context->set('@out', \$pout);\n";
         $buffer .= "\t\t\t\$this->context->set('@this', \$pthis);\n";
         $buffer .= "\t\t}\n";
         $buffer .= "\t}\n";
     } else {
         $compiler = new self($this->renderer);
         foreach ($this->extends as $i => $node) {
             if ($i != 0) {
                 $compiler->write(' . ');
             }
             $node->compile($compiler, NodeInterface::FLAG_RAW);
         }
         $buffer .= "\n\tprotected function getExtended() {\n";
         $buffer .= "\t\treturn " . $compiler->getBuffer() . ";\n";
         $buffer .= "\t}\n";
     }
     foreach ($this->blocks as $block) {
         $buffer .= "\n" . $block;
     }
     $buffer .= "}}\n ?>";
     return $buffer;
 }