public function interpretRow($row) { if (isset($row['scope']) && $row['scope'] == 'GLOBAL') { define($row['name'], $row['value']); } parent::interpretRow($row); }
/** * Sets a cache block within the handler. This method overrides our parent set. * What this method does differently is that it will turn our supplied object into * a crud object and serialize it. * * @param String $name name identification of the object, can not use duplicates! * @param Mixed $obj object to save, this object will be serialized, object advanced object types. */ public function set($name, $obj) { $block = new Cache_Block(); $block->name = $name; $block->data = serialize($obj); parent::set($name, $block); }
public static function upload(&$return) { if (!isset($_POST['meta']) || empty($_POST['meta'])) { $return['sucess'] = false; $return['error'] = 'Please provide a meta type for the file upload (TEXT, FILE).'; return; } $meta = strtoupper($_POST['meta']); if ($meta != 'FILE' && $meta != 'TEXT') { $return['sucess'] = false; $return['error'] = 'Invalid meta type! : ' . $meta; return; } if ($meta == 'FILE') { $err = isValidFile(PASTE_FILE_TMP_NAME, PASTE_MAX_LENGTH_MB * 1000 * 1000); if ($err != true) { $return['sucess'] = false; $return['error'] = 'Bad file! Error: ' . $err; return; } } /* ensure that no output is sent to the json output */ /* create and fill the paste object */ $paste = new PasteHandler_Paste(); $paste->fill($_POST); $paste->type = $meta; if ($meta == 'FILE') { $fileName = $_FILES[PASTE_FILE_TMP_NAME]['name']; if (!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } $dir = currentSite()->relativePath . 'uploads/'; $permFile = $dir . getRandomString() . '_' . $fileName; $tmp = $_FILES[PASTE_FILE_TMP_NAME]["tmp_name"]; /* change name so there's no colissions if someone uploads a file named the same thing */ // $_FILES[PASTE_FILE_TMP_NAME]["tmp_name"] = $_FILES[PASTE_FILE_TMP_NAME]["name"] = getRandomString() . $_FILES[PASTE_FILE_TMP_NAME]["name"] ; /* move the file out of the tmp directory */ move_uploaded_file($tmp, $permFile); //echo 'tmp: ' . $tmp; //echo 'path : ' . currentSite()->absolutePath . 'uploads/' . getRandomString() . $_FILES[PASTE_FILE_TMP_NAME]["name"]; if (exif_imagetype($permFile) !== false) { $paste->type = 'IMAGE'; } $paste->datapath = $permFile; $paste->title = $fileName; } if (strlen($paste->data) > PASTE_MAX_LENGTH_MB * 1000 * 1000) { $return['sucess'] = false; $return['error'] = 'Paste too big. Please paste below ' . PASTE_MAX_LENGTH_MB . 'MB of data!'; return; } if ($paste->exposure === 'private' && !Account_AccountAPI::getLoggedIn()) { $return['sucess'] = false; $return['error'] = 'You cannot use private pastes without being logged in.'; return; } $longIP = findIPLong(); /* check that this ip has not submitted more then the limit of pastes in last hour */ $res = Lunor::$base->db->query('SELECT id from ' . TABLE_PREFIX . PASTE_TABLE_PREFIX . 'paste where `ip` = \'' . $longIP . '\' and DATE_SUB(NOW(), INTERVAL 1 HOUR) <= `since`;'); if ($res !== false) { $res = Lunor::$base->dbi->fetchAll($res); $entries = sizeof($res); if ($entries >= PASTE_MAX_UPLOADS_PER_HOUR) { $return['sucess'] = false; $return['error'] = 'You have pasted too many items within the last hour. Please slow down. This is in place to stop spam bots.'; return; } } /* give generated id */ $paste->id = self::generateUID(); $cur = new ORM_Operator(new PasteHandler_Paste(), array('id' => $paste->id)); while (!$cur->isEmpty()) { $paste->id = self::generateUID(); $cur = new ORM_Operator(new PasteHandler_Paste(), array('id' => $paste->id)); } $paste->views = 0; $paste->since = 'CURRENT_TIMESTAMP'; $paste->ip = $longIP; /* inset data into db */ Lunor::$base->dbi->beginTransaction(); Lunor::$base->dbi->setAdditionalPrefix(PASTE_TABLE_PREFIX); /* insert base class into the db */ $paste->insert(); /* now need to put in variable table data */ if ($_POST['expiration'] === 'views') { /* we are using the views table*/ Lunor::$base->dbi->insert('expiration_views')->map(array('paste_id' => $paste->id, 'view_limit' => $_POST['views']))->go(); } else { /* otherwise we use the time table */ Lunor::$base->dbi->insert('expiration_time')->map(array('paste_id' => $paste->id, 'expires' => self::getTimestamp()))->go(); } if ($_POST['meta'] === 'text') { /* if type is text we need to insert for the syntax highlighting */ Lunor::$base->dbi->insert('paste_text')->map(array('paste_id' => $paste->id, 'syntax_highlighting' => $_POST['paste_mode']))->go(); } /* adds our ip to the viewed list so we don't increment it ourself */ Lunor::$base->dbi->insert('paste_view')->map(array('paste_id' => $paste->id, 'ip_address' => $longIP))->go(); /* poster is not Guest! */ if (Account_AccountAPI::getLoggedIn()) { Lunor::$base->dbi->insert('user_paste')->map(array('paste_id' => $paste->id, 'user_id' => Account_AccountAPI::getUserId()))->go(); } /* if the transaction has to rollback then we let the client know it failed */ if (Lunor::$base->dbi->endTransaction() === false) { $return['sucess'] = false; return; } $return['id'] = $paste->id; $return['sucess'] = true; return; }