Jump to content

googlexx

Members
  • Posts

    38
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

googlexx's Achievements

Member

Member (2/5)

0

Reputation

  1. This is my first oop php library and wanted to get advice on how I can improve what I wrote. This is what I needed to do: I'm also not sure on what it meant by "proportionally resize the shape up or down, given a floating-point scale factor" I think what I did might be right but I could be wrong. Also am I supposed to have a new class for each shape or is there a better solution? Any help is much appreciated. <?PHP echo "Circle (r=5) <br/>"; $circle = new circle(5); $circle->getArea(); $circle->getPerimiter(); $circle->scale(up, .5); echo "Scaled up .5<br/>"; $circle->getArea(); $circle->getPerimiter(); echo "<br/>Right Triangle (a=4, b=5) <br/>"; $rt = new RightTriangle(4, 5); $rt->getArea(); $rt->getPerimiter(); $rt->scale(down, .5); echo "Scaled down .5<br/>"; $rt->getArea(); $rt->getPerimiter(); echo "<br/>Equilateral Triangle <br/>"; $et = new EquilateralTriangle(6); $et->getArea(); $et->getPerimiter(); $et->scale(up, .; echo "Scaled Up .8<br/>"; $et->getArea(); $et->getPerimiter(); echo "<br/>Rectangle<br/>"; $r = new Rectangle(8, 7); $r->getArea(); $r->getPerimiter(); $r->scale(down, .; echo "Scaled Down .8<br/>"; $r->getArea(); $r->getPerimiter(); echo "<br/>Square<br/>"; $s = new Square(25); $s->getArea(); $s->getPerimiter(); $s->scale(up, 2.5); echo "Scaled Up 2.5<br/>"; $s->getArea(); $s->getPerimiter(); echo "<br/>Parallelogram<br/>"; $p = new Parallelogram(5.7, 6.; $p->getArea(); $p->getPerimiter(); $p->scale(up, 1); echo "Scaled Up 1<br/>"; $p->getArea(); $p->getPerimiter(); class Circle { public function __construct( $radius ) { $this->radius = $radius; } public function getArea() { echo number_format(pow($this->radius, 2) * M_PI, 2)."<br/>"; } public function getPerimiter() { echo number_format(2 * M_PI * $this->radius, 2)."<br/>"; } public function scale($direction, $scale) { if($direction == 'up') { $this->radius = $this->radius + ($this->radius * $scale); } else { $this->radius = $this->radius - ($this->radius * $scale); } } } class RightTriangle { public function __construct( $a, $b ) { $this->a = $a; $this->b = $b; } public function getArea() { echo number_format(($this->a*$this->b/2), 2)."<br/>"; } public function getPerimiter() { echo number_format($this->a + $this->b + sqrt(pow($this->a, 2) + pow($this->b, 2)), 2)."<br/>"; } public function scale($direction, $scale) { if($direction == 'up') { $this->a = $this->a + ($this->a * $scale); $this->b = $this->b + ($this->b * $scale); } else { $this->a = $this->a - ($this->a * $scale); $this->b = $this->b + ($this->b * $scale); } } } class EquilateralTriangle { public function __construct( $a ) { $this->a = $a; } public function getArea() { echo number_format((sqrt(3)/4)*pow($this->a,2),2)."<br/>"; } public function getPerimiter() { echo number_format(3 * $this->a, 2)."<br/>"; } public function scale($direction, $scale) { if($direction == 'up') { $this->a = $this->a + ($this->a * $scale); } else { $this->a = $this->a - ($this->a * $scale); } } } class Rectangle { public function __construct( $w, $l ) { $this->w = $w; $this->l = $l; } public function getArea() { echo number_format($this->w * $this->l,2)."<br/>"; } public function getPerimiter() { echo number_format(2 * ($this->w + $this->l), 2)."<br/>"; } public function scale($direction, $scale) { if($direction == 'up') { $this->w = $this->w + ($this->w * $scale); $this->l = $this->l + ($this->l * $scale); } else { $this->w = $this->w - ($this->w * $scale); $this->l = $this->l - ($this->l * $scale); } } } class Square { public function __construct( $a ) { $this->a = $a; } public function getArea() { echo number_format(pow($this->a,2),2)."<br/>"; } public function getPerimiter() { echo number_format(4 * $this->a, 2)."<br/>"; } public function scale($direction, $scale) { if($direction == 'up') { $this->a = $this->a + ($this->a * $scale); } else { $this->a = $this->a - ($this->a * $scale); } } } class Parallelogram { public function __construct( $a, $b ) { $this->a = $a; $this->b = $b; $this->h = $a/$b; } public function getArea() { echo number_format($this->b * $this->h,2)."<br/>"; } public function getPerimiter() { echo number_format(2 * ($this->a + $this->b), 2)."<br/>"; } public function scale($direction, $scale) { if($direction == 'up') { $this->a = $this->a + ($this->a * $scale); $this->b = $this->b + ($this->b * $scale); } else { $this->a = $this->a - ($this->a * $scale); $this->b = $this->b - ($this->b * $scale); } } } ?>
  2. i'm trying to call a php file using ajax and it seems to be returning false, but i have no idea why. any ideas? <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> <form method="get" action="test.php"> <input id="myvar" type="hidden" name="albumid" /> <button type="submit" id="btnsubmit">Submit</button> </form> <script type="text/javascript"> $('form').submit(function() { $.ajax({ url: "newAlbum.php", data: {albumid: $('#myvar').val()}, success: function(data){ var album = data; $('#myvar').val(album); return true; } }); return false; }); </script> newAlbum.php <?php echo '11'; ?> test.php <?php echo $_GET["albumid"]; ?>
  3. Hey guys, I've setup a php fb login on my site and its working perfectly. However, I'm trying to get it to remember the person so everytime they close their browser they dont have to click login again. I've tried storing the cookie but i'm not sure its working or if its even possible with facebook. Im using this: https://developers.facebook.com/docs/reference/php/ <?php /** * Copyright 2011 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain * a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ require_once "base_facebook.php"; /** * Extends the BaseFacebook class with the intent of using * PHP sessions to store user ids and access tokens. */ class Facebook extends BaseFacebook { const FBSS_COOKIE_NAME = 'fbss'; // We can set this to a high number because the main session // expiration will trump this. const FBSS_COOKIE_EXPIRE = 31556926; // 1 year // Stores the shared session ID if one is set. protected $sharedSessionID; /** * Identical to the parent constructor, except that * we start a PHP session to store the user ID and * access token if during the course of execution * we discover them. * * @param Array $config the application configuration. Additionally * accepts "sharedSession" as a boolean to turn on a secondary * cookie for environments with a shared session (that is, your app * shares the domain with other apps). * @see BaseFacebook::__construct in facebook.php */ public function __construct($config) { if (!session_id()) { session_start(); } parent::__construct($config); if (!empty($config['sharedSession'])) { $this->initSharedSession(); } } protected static $kSupportedKeys = array('state', 'code', 'access_token', 'user_id'); protected function initSharedSession() { $cookie_name = $this->getSharedSessionCookieName(); if (isset($_COOKIE[$cookie_name])) { $data = $this->parseSignedRequest($_COOKIE[$cookie_name]); if ($data && !empty($data['domain']) && self::isAllowedDomain($this->getHttpHost(), $data['domain'])) { // good case $this->sharedSessionID = $data['id']; return; } // ignoring potentially unreachable data } // evil/corrupt/missing case $base_domain = $this->getBaseDomain(); $this->sharedSessionID = md5(uniqid(mt_rand(), true)); $cookie_value = $this->makeSignedRequest( array( 'domain' => $base_domain, 'id' => $this->sharedSessionID, ) ); $_COOKIE[$cookie_name] = $cookie_value; if (!headers_sent()) { $expire = time() + self::FBSS_COOKIE_EXPIRE; setcookie($cookie_name, $cookie_value, $expire, '/', '.'.$base_domain); } else { // @codeCoverageIgnoreStart self::errorLog( 'Shared session ID cookie could not be set! You must ensure you '. 'create the Facebook instance before headers have been sent. This '. 'will cause authentication issues after the first request.' ); // @codeCoverageIgnoreEnd } } /** * Provides the implementations of the inherited abstract * methods. The implementation uses PHP sessions to maintain * a store for authorization codes, user ids, CSRF states, and * access tokens. */ protected function setPersistentData($key, $value) { if (!in_array($key, self::$kSupportedKeys)) { self::errorLog('Unsupported key passed to setPersistentData.'); return; } $session_var_name = $this->constructSessionVariableName($key); $_SESSION[$session_var_name] = $value; } protected function getPersistentData($key, $default = false) { if (!in_array($key, self::$kSupportedKeys)) { self::errorLog('Unsupported key passed to getPersistentData.'); return $default; } $session_var_name = $this->constructSessionVariableName($key); return isset($_SESSION[$session_var_name]) ? $_SESSION[$session_var_name] : $default; } protected function clearPersistentData($key) { if (!in_array($key, self::$kSupportedKeys)) { self::errorLog('Unsupported key passed to clearPersistentData.'); return; } $session_var_name = $this->constructSessionVariableName($key); unset($_SESSION[$session_var_name]); } protected function clearAllPersistentData() { foreach (self::$kSupportedKeys as $key) { $this->clearPersistentData($key); } if ($this->sharedSessionID) { $this->deleteSharedSessionCookie(); } } protected function deleteSharedSessionCookie() { $cookie_name = $this->getSharedSessionCookieName(); unset($_COOKIE[$cookie_name]); $base_domain = $this->getBaseDomain(); setcookie($cookie_name, '', 1, '/', '.'.$base_domain); } protected function getSharedSessionCookieName() { return self::FBSS_COOKIE_NAME . '_' . $this->getAppId(); } protected function constructSessionVariableName($key) { $parts = array('fb', $this->getAppId(), $key); if ($this->sharedSessionID) { array_unshift($parts, $this->sharedSessionID); } return implode('_', $parts); } }
  4. Hey everyone, I'm having some trouble sizing a flash object inside a div. I'm trying to get it when you resize the window the flash objects resizes as well but it keeps its dimensions. This is what I have: When I change #flashcontent to height and width of 100% it does what I want it to do but I dont want it the entire size of the page I'm trying to get it the full size of a div. Any help is appreciated. Thanks <style type="text/css"> html { height: 100%; } #flashcontent { height: 480px; width: 720px; } #content { position: absolute; height: 100%; width: 100%; } /* end hide */ body { height: 100%; margin: 0; padding: 0; background-color: #eee; } </style> </head> <body> <div id="content"> <div id="flashcontent"> <object style='height:100%;' type="application/x-shockwave-flash" height="100%" width="100%" id="live_embed_player_flash" data="http://www.twitch.tv/widgets/live_embed_player.swf?channel=dotahut" bgcolor="#000000"><param name="allowFullScreen" value="true" /> <param name="allowScriptAccess" value="always" /> <param name="allowNetworking" value="all" /><param name="movie" value="http://www.twitch.tv/widgets/live_embed_player.swf" /><param name="flashvars" value="hostname=www.twitch.tv&channel=dotahut&auto_play=true&start_volume=25" /></object> </div> </div> </body>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.