$act = 'acquire'; $arg = OC_Shorty_Type::req_argument($key,OC_Shorty_Type::URL,FALSE); break 2; // skip switch AND foreach // no recognizable key but something else, hm... // this _might_ be some unexcepted argument, or: // it is an expected argument, but without recognizable key, so we try to guess by examining the content // we restrict this 'guessing' to cases where only a single argument is specified default: if ( (1==sizeof($_GET)) // only one single request argument &&( ! reset($_GET)) ) // no value, so maybe just an id { // use that source instead of $key, since $key contains replaced chars (php specific exceptions due to var name problems) $raw = urldecode($_SERVER['QUERY_STRING']); // now try to interpret its content if (NULL!==($value=OC_Shorty_Type::normalize($raw,OC_Shorty_Type::URL,FALSE))) { // the query string is a url, acquire it as a new shorty $act = 'acquire'; $arg = $raw; break 2; } else { // no pattern recognized, so we assume an ordinary index action $act = 'index'; break 2; } } // if $act='index'; break 2;
case 'id': case 'shorty': // this looks like the request refers to a Shortys ID, lets see if we know that one $id = OC_Shorty_Type::req_argument($key,OC_Shorty_Type::ID,FALSE); $param = array ( ':id' => OC_Shorty_Type::normalize($id,OC_Shorty_Type::ID) ); $query = OCP\DB::prepare ( OC_Shorty_Query::URL_BY_ID ); break 2; // skip switch AND foreach, we have all details we need... case 'url': case 'uri': case 'ref': case 'source': case 'target': // this looks like the request refers to a full url, lets see if we know that one as a Shortys source $source = OC_Shorty_Type::req_argument($key,OC_Shorty_Type::URL,FALSE); $param = array ( ':source' => OC_Shorty_Type::normalize($source,OC_Shorty_Type::URL) ); $query = OCP\DB::prepare ( OC_Shorty_Query::URL_BY_SOURCE ); break 2; // skip switch AND foreach, we have all details we need... } // switch } // foreach // generate qrcode for the specified id/url, IF it exists and has not expired in the database try { if ( $query ) { $result = $query->execute($param)->FetchAll(); if ( FALSE===$result ) throw new OC_Shorty_HttpException ( 500 ); elseif ( ! is_array($result) ) throw new OC_Shorty_HttpException ( 500 );
// swallow any accidential output generated by php notices and stuff to preserve a clean JSON reply structure OC_Shorty_Tools::ob_control ( TRUE ); //no apps or filesystem $RUNTIME_NOSETUPFS = true; // Sanity checks OCP\JSON::callCheck ( ); OCP\JSON::checkLoggedIn ( ); OCP\JSON::checkAppEnabled ( 'shorty' ); try { $p_id = OC_Shorty_Type::req_argument ( 'id', OC_Shorty_Type::ID, TRUE ); $p_status = OC_Shorty_Type::req_argument ( 'status', OC_Shorty_Type::STATUS, FALSE ); $param = array ( 'user' => OCP\User::getUser ( ), 'id' => $p_id, 'status' => $p_status, ); $query = OCP\DB::prepare ( OC_Shorty_Query::URL_STATUS ); $query->execute ( $param ); // swallow any accidential output generated by php notices and stuff to preserve a clean JSON reply structure OC_Shorty_Tools::ob_control ( FALSE ); OCP\Util::writeLog( 'shorty', sprintf("Status change for shorty with id '%s' saved",$p_id), OCP\Util::INFO ); OCP\JSON::success ( array ( 'data' => array('id'=>$p_id), 'level' => 'info',
OCP\JSON::checkAppEnabled ( 'shorty' ); try { $data = array(); switch ( $_SERVER['REQUEST_METHOD'] ) { case 'POST': // detect provided preferences $data = array(); foreach (array_keys($_POST) as $key) { if ( isset(OC_Shorty_Type::$PREFERENCE[$key]) ) // ignore unknown preference keys { $type = OC_Shorty_Type::$PREFERENCE[$key]; $data[$key] = OC_Shorty_Type::req_argument ( $key, $type, FALSE ); } } // store settings foreach ( $data as $key=>$val ) OCP\Config::setUserValue( OCP\User::getUser(), 'shorty', $key, $val ); // swallow any accidential output generated by php notices and stuff to preserve a clean JSON reply structure OC_Shorty_Tools::ob_control ( FALSE ); OCP\Util::writeLog( 'shorty', sprintf("Preference '%s' saved",implode(',',array_keys($data))), OCP\Util::DEBUG ); OCP\JSON::success ( array ( 'data' => $data, 'level' => 'debug', 'message' => OC_Shorty_L10n::t("Preference '%s' saved",implode(',',array_keys($data))) ) );
$RUNTIME_NOSETUPFS = true; // Sanity checks OCP\JSON::callCheck ( ); OCP\JSON::checkLoggedIn ( ); OCP\JSON::checkAppEnabled ( 'shorty' ); try { $p_id = OC_Shorty_Type::req_argument ( 'id', OC_Shorty_Type::ID, TRUE ); $p_status = OC_Shorty_Type::req_argument ( 'status', OC_Shorty_Type::STATUS, FALSE ); $p_title = OC_Shorty_Type::req_argument ( 'title', OC_Shorty_Type::STRING, FALSE ); $p_target = OC_Shorty_Type::req_argument ( 'target', OC_Shorty_Type::URL, FALSE ); $p_until = OC_Shorty_Type::req_argument ( 'until', OC_Shorty_Type::DATE, FALSE ); $p_notes = OC_Shorty_Type::req_argument ( 'notes', OC_Shorty_Type::STRING, FALSE ); $p_favicon = OC_Shorty_Type::req_argument ( 'favicon', OC_Shorty_Type::URL, FALSE ); $param = array ( ':user' => OCP\User::getUser ( ), ':id' => $p_id, ':status' => $p_status ? $p_status : '', ':title' => $p_title ? substr($p_title, 0,1024) : '', ':favicon' => $p_favicon ? substr($p_favicon,0,1024) : '', ':target' => $p_target ? substr($p_target, 0,4096) : '', ':notes' => $p_notes ? substr($p_notes, 0,4096) : '', ':until' => $p_until ? $p_until : null, ); $query = OCP\DB::prepare ( OC_Shorty_Query::URL_UPDATE ); $query->execute ( $param ); // read new entry for feedback
* @return json: success/error state indicator * @return array: Associative array of meta data aspects * @author Christian Reiner */ // swallow any accidential output generated by php notices and stuff to preserve a clean JSON reply structure OC_Shorty_Tools::ob_control ( TRUE ); //no apps or filesystem $RUNTIME_NOSETUPFS = true; // Sanity checks OCP\JSON::callCheck ( ); OCP\JSON::checkLoggedIn ( ); OCP\JSON::checkAppEnabled ( 'shorty' ); try { $target = OC_Shorty_Type::req_argument ( 'target', OC_Shorty_Type::URL, TRUE ); $meta = OC_Shorty_Meta::fetchMetaData(htmlspecialchars_decode($target)); // swallow any accidential output generated by php notices and stuff to preserve a clean JSON reply structure OC_Shorty_Tools::ob_control ( FALSE ); OCP\Util::writeLog( 'shorty', sprintf("Target meta data retrieved for url '%s'.",$target), OCP\Util::DEBUG ); OCP\JSON::success ( array ( 'data' => $meta, 'level' => 'info', 'message' => OC_Shorty_L10n::t("Target url '%s' is valid", $meta['target']) ) ); } catch ( Exception $e ) { OC_Shorty_Exception::JSONerror($e); } ?>
*/ // swallow any accidential output generated by php notices and stuff to preserve a clean JSON reply structure OC_Shorty_Tools::ob_control ( TRUE ); //no apps or filesystem $RUNTIME_NOSETUPFS = true; // Sanity checks OCP\JSON::callCheck ( ); OCP\JSON::checkLoggedIn ( ); OCP\JSON::checkAppEnabled ( 'shorty' ); try { $p_id = OC_Shorty_Type::req_argument ( 'id', OC_Shorty_Type::ID, TRUE ); $param = array ( 'user' => OCP\User::getUser(), 'id' => $p_id, ); $query = OCP\DB::prepare ( OC_Shorty_Query::URL_DELETE ); $query->execute($param); // swallow any accidential output generated by php notices and stuff to preserve a clean JSON reply structure OC_Shorty_Tools::ob_control ( FALSE ); OCP\Util::writeLog( 'shorty', sprintf("Deleted Shorty with id '%s'",$p_id), OCP\Util::INFO ); OCP\JSON::success ( array ( 'data' => array('id'=>$p_id), 'level' => 'info', 'message' => OC_Shorty_L10n::t("Shorty with id '%s' deleted",$p_id) ) );
} // an id was specified, ordinary or special meaning ? if ( '0000000000'==$arg ) { // this is a pseudo id, used to test the setup, so just return a positive message. // this is used to test the setup of the static backend, shorty calls itself from there OCP\Util::writeLog( 'shorty', "Positiv validation of static backend base url.", OCP\Util::DEBUG ); // we have to react to a jsonp request, so we have to reply valid jsonp manually: // note that we use 'static' jsonp, so no callback parameter is provided, instead it is hard coded here // this reduces the complexity of setting up the backend, since no additional parameter has to be handled echo sprintf ( 'verifyStaticBackend(%s)', json_encode(array('status'=>'success')) ); exit(); } // detect requested shorty id from request $p_id = trim ( OC_Shorty_Type::normalize($arg,OC_Shorty_Type::ID) ) ; if ( $p_id ) { $param = array ( 'id' => $p_id ); $query = OCP\DB::prepare ( OC_Shorty_Query::URL_RELAY ); $result = $query->execute($param)->FetchAll(); $request = array ( 'address' => $_SERVER['REMOTE_ADDR'], 'host' => isset($_SERVER['REMOTE_HOST'])?$_SERVER['REMOTE_HOST']:gethostbyaddr($_SERVER['REMOTE_ADDR']), 'time' => $_SERVER['REQUEST_TIME'], 'user' => OCP\User::getUser(), ); if ( FALSE===$result ) throw new OC_Shorty_HttpException ( 500 ); elseif ( ! is_array($result) ) throw new OC_Shorty_HttpException ( 500 );
/** * @method OC_Shorty_Backend::registerUrl_tinyurl * @brief Registers a given local relay url at the tinyURL shortening service * @param string id * @param url relay * @return Registered and validated relay url * @access public * @author Chrisian Reiner */ static function registerUrl_tinyurl ( $id, $relay ) { $curl = curl_init ( ); curl_setopt ( $curl, CURLOPT_URL, sprintf('http://tinyurl.com/api-create.php?url=%s', urlencode(trim($relay))) ); curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, TRUE ); if ( (FALSE===($reply=curl_exec($curl))) ||( ! preg_match( '/^(.+)$/', $reply, $match )) ) { throw new OC_Shorty_Exception ( "Failed to register url at backend 'tinyUrl'. \nError %s: %s", array(curl_errno($curl),curl_error($curl)) ); } curl_close ( $curl ); return OC_Shorty_Type::validate ( $match[1], OC_Shorty_Type::URL ); } // OC_Shorty_Backend::registerUrl_tinyurl
*/ // swallow any accidential output generated by php notices and stuff to preserve a clean JSON reply structure OC_Shorty_Tools::ob_control ( TRUE ); // Session checks OCP\App::checkAppEnabled ( 'shorty' ); $RUNTIME_NOSETUPFS = true; try { $p_id = OC_Shorty_Type::req_argument ( 'id', OC_Shorty_Type::ID, FALSE ); $p_query = OC_Shorty_Type::req_argument ( 'query', OC_Shorty_Type::STRING, FALSE ); $p_format = OC_Shorty_Type::req_argument ( 'format', OC_Shorty_Type::STRING, FALSE ); $p_sort = OC_Shorty_Type::req_argument ( 'sort', OC_Shorty_Type::STRING, 'ka' ); $param = array ( ':user' => OCP\User::getUser ( ), ':id' => $p_id, ':sort' => OC_Shorty_Type::$SORTING[$p_sort], ':format' => $p_format, ':sort' => $p_sort, ':query' => $p_query, ); $match = NULL; $candidates = OC_Shorty_Hooks::requestQueries(); foreach ($candidates['list'] as $candidate) if ($candidate['id']==$p_query) $match = $candidate; if ( ! $match )
// swallow any accidential output generated by php notices and stuff to preserve a clean JSON reply structure OC_Shorty_Tools::ob_control ( TRUE ); //no apps or filesystem $RUNTIME_NOSETUPFS = true; // Sanity checks OCP\JSON::callCheck ( ); OCP\JSON::checkLoggedIn ( ); OCP\JSON::checkAppEnabled ( 'shorty' ); try { if (isset($_GET['id'])) { $p_id = OC_Shorty_Type::req_argument ( $_GET['id'], OC_Shorty_Type::ID, TRUE ); $param = array ( ':id' => $p_id, ':time' => 'NOW()', ); // record the click $query = OCP\DB::prepare ( OC_Shorty_Query::URL_CLICK ); $query->execute ( $param ); // allow further processing by registered hooks $details = array ( ); // for this we need two things: details about the Shorty AND about the request $query = OCP\DB::prepare ( OC_Shorty_Query::URL_VERIFY ); $entries = $query->execute($param)->FetchAll(); if ( (1==count($entries))