$param = array ( ':user' => OCP\User::getUser ( ), ':sort' => $p_sort, // ':offset' => $p_offset, // ':limit' => PAGE_SIZE, ); $query = OCP\DB::prepare ( OC_Shorty_Query::URL_LIST ); $result = $query->execute($param); $reply = $result->fetchAll(); foreach (array_keys($reply) as $key) { if (isset($reply[$key]['id'])) { // enhance all entries with the relay url $reply[$key]['relay']=OC_Shorty_Tools::relayUrl ( $reply[$key]['id'] ); // make sure there is _any_ favicon contained, otherwise layout in MS-IE browser is broken... if (empty($reply[$key]['favicon'])) $reply[$key]['favicon'] = OCP\Util::imagePath('shorty', 'blank.png'); } } // foreach // 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("Constructed list of defined shortys holding %s entries.",sizeof($reply)), OCP\Util::DEBUG ); OCP\JSON::success ( array ( 'data' => $reply, 'level' => 'debug', 'count' => sizeof($reply), 'message' => OC_Shorty_L10n::t("Number of entries: %s", count($reply)) ) ); } catch ( Exception $e ) { OC_Shorty_Exception::JSONerror($e); } ?>
/** * @method OC_Shorty_Exception::JSONerror * @brief Calls OCP\JSON::error with a pretty formated version of an exception * @param exception: An exception object holding information * @return json: OCP\JSON::error * @access public * @author Christian Reiner */ static function JSONerror ( $e ) { $title = OC_Shorty_L10n::t("Exception"); switch ( get_class($e) ) { case 'OC_Shorty_Exception': $message = $e->getTranslation(); break; case 'PDOException': $message = sprintf ( OC_Shorty_L10n::t( "%s\nMessage(code): %s (%s)\nFile(line): %s (%s)\nInfo: %%s", OC_Shorty_L10n::t("Exception (%s)", get_class($e)), htmlspecialchars($e->getMessage()), htmlspecialchars($e->getCode()), htmlspecialchars($e->getFile()), htmlspecialchars($e->getLine()) ), (method_exists($e,'errorInfo') ? trim($e->errorInfo()) : '-/-') ); break; default: if ( is_a($e,'Exception') ) $message = OC_Shorty_L10n::t("Unexpected type of exception caught:%s\n%s", get_class($e), $e->getMessage()); else $message = OC_Shorty_L10n::t("Unexpected thrown object of type caught:\n%s", get_class($e)); } // switch // swallow any accidential output generated by php notices and stuff to preserve a clean JSON reply structure $output = trim ( OC_Shorty_Tools::ob_control(FALSE) ); if ( $output ) { $message = "! Swallowing accidential output from ajax routines ! \n" ."Please fix this ! Here is the first line: \n" .substr ( $output, 0, strpos($output,"\n") ); OCP\Util::writeLog( 'shorty', $message, OCP\Util::WARN ); } // output // return a clean JSON error return OCP\JSON::error ( array ('title' => $title, 'level' => 'error', 'message' => sprintf("%s:\n%s", $title, $message) ) ); } // function error