/** * Convert a PDF/EPS to JPG/PNG. * * @param $from: File path to the original file. * @param $to: File path where the new file should be saved. * @param $format: Format to convert to. */ protected static function convert($from, $to, $format) { $cmd = binarypool_config::getUtilityPath('pdfconverter'); $cmd .= ' -f ' . $format; $cmd .= ' ' . escapeshellarg($from) . ' ' . escapeshellarg($to); $log = new api_log(); $log->debug("Rendering PDF with command: {$cmd}"); shell_exec($cmd); }
protected static function convert($from, $to) { $cmd = binarypool_config::getUtilityPath('convert'); $cmd .= ' -density 288 -resize 220 +antialias'; # Make sure all output images are in RGB. This handles incoming CMYK # images which some browsers can't display. $cmd .= ' -colorspace RGB -trim '; $cmd .= escapeshellarg($from) . ' ' . escapeshellarg($to); $log = new api_log(); $log->debug("Converting PDF/EPS image using command: {$cmd}"); shell_exec($cmd); }
public function saveRenditions($renditions, $dir) { if ($dir[strlen($dir) - 1] !== '/') { $dir .= '/'; } $retval = array(); $tmpdir = ''; foreach ($renditions as $name => $file) { $remote_file = $dir . basename($file); $this->save($file, $remote_file); $retval[$name] = $remote_file; // Remove the temporary file if (file_exists($file)) { unlink($file); } else { $log = new api_log(); $log->warn("storage_driver_s3::saveRenditions() - No temp file for rendition '%s' at '%s'", $name, $file); } if (empty($tmpdir)) { $tmpdir = dirname($file); } } if ($tmpdir !== '') { // Optimistic removal. If it's not empty, this will fail. @rmdir($tmpdir); if (file_exists($tmpdir)) { $log = new api_log(); $log->warn("storage_driver_s3::saveRenditions() - unable to remove rendition tmpdir '%s'", $tmpdir); } } return $retval; }
/** * Config must provide the following keys: * - server: ActiveMQ server to connect to. Messages go into an in-memory * queue if the server name is "__test__". * @return: null, as the rendition is generated asynchronously. */ public static function render($source, $target, $assetFile, $config) { $bucket = $config['_bucket']; $queue = $config['queue']; $message = array('asset' => $assetFile, 'config' => $config, 'bucket' => $bucket, 'tstamp' => time()); if ($queue == '__test__') { array_push(self::$messages, $message); } else { $log = new api_log(); $log->debug("Queueing message: {$assetFile}"); $conn = new Amazon_SQS_Client($config['access_id'], $config['secret_key']); $response = $conn->sendMessage(array('QueueName' => $queue, 'MessageBody' => json_encode($message))); $result = $response->getSendMessageResult(); $log->debug("Queued message ID %s for asset file %s", $result->getMessageId(), $assetFile); } }
public static function getInstance($forceReload = false) { if (!self::$instance instanceof api_log || $forceReload) { self::$logger = null; self::$instance = new api_log(); } return self::$instance; }
function __construct($route, $request, $response) { $cfg = api_config::getInstance(); $this->config = $cfg; $this->params = $route; $this->request = $request; $this->response = $response; // $writerConfig = $cfg->log; // $this->logger = Zend_Log::factory(array($writerConfig)); $this->logger = api_log::getInstance(); $this->dispatcher = new sfEventDispatcher(); $this->init(); }
function __construct($table) { if (!isset(self::$DB)) { //self::$DB = new PDO('mysql:dbname=mapper;host=localhost', 'mapper', 'mapper' ); self::$DB = api_database::factory(); self::$DB->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); self::$DB->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL); self::$logger = api_log::getInstance(); } //echo "<br />self::DB => "; //$sth = self::$DB->exec("select * from user"); //print_r(self::$DB->errorCode()); //echo "<br />"; $this->driver = self::$DB->getAttribute(PDO::ATTR_DRIVER_NAME); $this->table = $table; switch ($this->driver) { case 'mysql': $this->name_opening = $this->name_closing = '`'; break; case 'mssql': $this->name_opening = '['; $this->name_closing = ']'; break; case 'pgsql': $this->name_opening = "'"; $this->name_closing = "'"; $this->column_opening = $this->column_closing = '"'; break; default: $this->name_opening = $this->name_closing = '"'; break; } $this->table_meta = $this->get_table_meta(); $this->table_meta_minus_pk = $this->table_meta; unset($this->table_meta_minus_pk[$this->primary_key]); $this->selectStmt = "SELECT * FROM " . $this->table . " WHERE {$this->primary_key}=?"; $this->selectAllStmt = "SELECT * FROM {$this->table}"; // $this->updateStmt = $this->buildUpdateStmt(); $this->insertStmt = $this->buildInsertStmt(); $this->deleteStmt = "DELETE FROM {$this->table} WHERE id = ?"; // } foreach ($this->table_meta as $key => $value) { $this->{$key} = ''; } }
public function relink($target, $link) { $this->clearstatcache(); $link = $this->absolutize($link); if (!file_exists($link)) { $this->symlink($target, $link); return; } // "touch" the existing symlink... // first create a symlink using a temporary name, linked to // the target then rename the temporary link to the final // link name, overwriting the existing link (i.e. atomic // vs. deleting existing then create new, non-atomic) $tmplink = sprintf("/tmp/%s%s", sha1($link), microtime(True)); symlink($target, $tmplink); if (!rename($tmplink, $link)) { $log = new api_log(); $log->err("Unable to rename tmplink '%s' to '%s' for target '%s' in bucket '%s'", $tmplink, $link, $target, $this->bucketName); if (file_exists($tmplink)) { unlink($tmplink); } } }
public function login($username, $password) { if ($username === '' && $password === '') { $username = $this->request->getParam('username'); $password = $this->request->getParam('password'); } //print_r($username); if (!empty($username)) { if ($this->checkAuth()) { $this->logout(); } $crudColumns = $this->getConfiguredColumns(); //print_r($crudColumns); // $hash = $this->getOpt('hash'); //$sql = 'SELECT SUBSTR('.$crudColumns['password'].',1,'.(int)$hash['saltLength'].') // FROM '.$this->config->crud['crudTable'].' // WHERE '.$crudColumns['username'].' = '.$this->db->quote($username); //$stmt = $this->db->prepare($sql); //$stmt->execute(array()); //$salt = $stmt->fetchColumn(); //if (empty($salt)) { // api_log::log(api_log::INFO, 'Salt not found in Database'); //} //$hashedPW = api_helpers_hashHelper::crypt_pass($password, $salt, $hash); $select = array(); foreach ($crudColumns as $alias => $val) { $select[] = $val . ' AS ' . $alias; } $select = implode(' ,', $select); $sql = 'SELECT ' . $select . ' FROM ' . $this->config->pam['table'] . ' WHERE ' . $crudColumns['username'] . ' = :username'; //echo $sql; api_log::log(api_log::DEBUG, $sql); $stmt = $this->db->prepare($sql); $sqlParams = array('username' => $username); $stmt->execute($sqlParams); //echo "Here"; //print_r($sqlParams); $userData = $stmt->fetch(PDO::FETCH_ASSOC); //print_r($userData); // Check password if (empty($userData)) { api_log::log(api_log::INFO, 'Credentials not correct'); // echo "Credential not correct"; } else { if (!$this->checkPassword($password, $userData['password'])) { api_log::log(api_log::INFO, 'Password not correct'); // echo "Passwords wrong"; } else { session_regenerate_id(true); unset($userData['password']); // echo "<br />"; // print_r($this->config->appname); // echo "<br />"; //$_SESSION[$this->config->appname]['user'] = $userData; api_log::log(api_log::INFO, 'Login Successful creating user session'); api_session::set('user', $userData); } } } return $this->checkAuth(); }
protected function getFilesUploaded() { $retval = array(); foreach ($_FILES as $key => $file) { if (strpos($key, 'File') === FALSE) { $log = new api_log(); $log->err("Invalid file uploaded: {$key}"); } else { $rendition = $key == 'File' ? '_' : str_replace('File_', '', $key); $retval[$rendition] = array('file' => $file['tmp_name'], 'filename' => $file['name']); } } return $retval; }
/** * Handle a subscription request. * * @param $post * A valid PubSubHubbub subscription request. */ public function subscribe($post) { //error_log( //print_r($post); // Authenticate $received_secret = $post['secret']; api_log::log('DEBUG', "Received secret: {$received_secret}"); $cfg = api_config::getInstance()->hub; $secret = md5($cfg['secret'] . $post['hub_callback']); if ($secret == $received_secret and isset($post['hub_topic']) && isset($post['hub_callback']) && $this->verify($post)) { $this->subscriptions->save($post['hub_topic'], $post['hub_callback'], isset($post['secret']) ? $post['secret'] : ''); // header('HTTP/1.1 204 "No Content"', null, 204); // exit(); */ echo "Good"; return true; } echo "not found"; return false; //header('HTTP/1.1 404 "Not Found"', null, 404); //exit(); */ }
/** * Convert a picture to a different format and/or resize it. * * @param $from: File path to the original file. * @param $to: File path where the new file should be saved. * @param $mime: MIME type of the original image. * @param $maxWidth: Maximum width of the new image. No resizing * is done if this is empty. Can be used without * specifying maxHeight. * @param $maxHeight: Maximum height of the new image. Must be * used together with $maxWidth. */ protected static function convert($from, $to, $mime, $maxWidth = '', $maxHeight = '') { $cmd = binarypool_config::getUtilityPath('convert'); # Make sure all output images are in RGB. This handles incoming CMYK # images which some browsers can't display. $cmd .= ' -colorspace RGB'; switch ($mime) { case 'image/pdf': case 'application/pdf': $cmd .= ' -trim'; break; case 'image/gif': break; default: $cmd .= ' -flatten'; break; } if ($maxWidth != '') { $scale = intval($maxWidth); if ($maxHeight != '') { $scale .= 'x' . intval($maxHeight); # Don't enlarge if the size is already smaller than resized version $scale .= '>'; } $cmd .= ' -resize ' . escapeshellarg($scale) . ''; } if ($mime == 'image/jpeg') { # Sharpen image $cmd .= ' -unsharp 0.5x1'; } $cmd = $cmd . ' ' . escapeshellarg($from) . ' ' . escapeshellarg($to); $log = new api_log(); $log->debug("Resizing image using command: {$cmd}"); shell_exec($cmd); }
public function query($statement) { api_log::log(api_log::INFO, $statement instanceof pdoext_Query ? $statement->toSql($this) : $statement); return parent::query($statement); //$this->log($statement instanceOf pdoext_Query ? $statement->toSql($this) : $statement)); }
/** * 更新日志 * @param unknown_type $log_id * @param unknown_type $response_data */ public function update_log($log_id, $response_data) { $request_md5 = ''; if (!empty($this->comm_wduser_infor['id'])) { $request_md5 = $this->comm_wduser_infor; } elseif (!empty($this->comm_user_infor['id'])) { $request_md5 = $this->comm_user_infor; } core::Singleton('api.api_log'); api_log::update($log_id, $response_data, print_r($request_md5, true)); }