Example #1
0
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
 public function executeIndex(sfWebRequest $request)
 {
     $lUrl = $request->getParameter("url", null);
     $lUrl = UrlUtils::narmalizeUrlScheme($lUrl);
     $request->setParameter("url", $lUrl);
     $this->url = $lUrl;
     $this->error = $this->pError = null;
     if (!$lUrl) {
         return $this->setTemplate("share");
     }
     if ($request->getMethod() == "POST") {
         $lParams = $request->getParameter('like');
         $lParams['u_id'] = $this->getUser()->getUserId();
         $lActivity = new Documents\YiidActivity();
         $lActivity->fromArray($lParams);
         // try to save activity
         try {
             $lActivity->save();
             $this->redirect("@deal?url=" . urlencode($lUrl));
         } catch (Exception $e) {
             // send error on exception
             $this->getLogger()->err($e->getMessage());
             $this->pError = $e->getMessage();
         }
     }
     $dm = MongoManager::getDM();
     $this->pActivity = $dm->getRepository("Documents\\YiidActivity")->findOneBy(array("url" => $lUrl, "u_id" => intval($this->getUser()->getId()), "d_id" => array('$exists' => false)));
     // if user has already liked
     if ($this->pActivity) {
         $this->redirect("@deal?url=" . urlencode($lUrl));
     }
     $lYiidMeta = new YiidMeta();
     $lYiidMeta->fromParams($request->getParameterHolder());
     $this->pYiidMeta = SocialObjectParser::fetch($request->getParameter("url"), $lYiidMeta);
     if ($this->pYiidMeta === false) {
         $this->error = "the url '{$lUrl}' is not well formed!";
         return $this->setTemplate("share");
     }
     $domainProfile = DomainProfileTable::getInstance()->retrieveByUrl($lUrl);
     $this->trackingUrl = null;
     if ($domainProfile) {
         $this->trackingUrl = $domainProfile->getTrackingUrl();
     }
     $this->getResponse()->setSlot('js_document_ready', $this->getPartial('like/js_init_like.js', array('pImgCount' => count($this->pYiidMeta->getImages()), 'pUrl' => $request->getParameter("url"))));
 }
Example #2
0
 /**
  * handles the parsing of a new social-object
  * currently parsed: opengraph and metatags
  *
  * @param string $pUrl
  * @return array $pArray
  */
 public static function fetch($pUrl, $pYiidMeta = null)
 {
     $pUrl = trim(urldecode($pUrl));
     $pUrl = str_replace(" ", "+", $pUrl);
     try {
         //get the html as string
         $lHtml = UrlUtils::getUrlContent($pUrl, 'GET');
         if (!$lHtml) {
             return false;
         }
         // boost performance and use alreade the header
         $lHeader = substr($lHtml, 0, stripos($lHtml, '</head>'));
         if (!$pYiidMeta) {
             $pYiidMeta = new YiidMeta();
         }
         $pYiidMeta->setUrl($pUrl);
         if ((preg_match('~http://opengraphprotocol.org/schema/~i', $lHeader) || preg_match('~http://ogp.me/ns#~i', $lHeader) || preg_match('~property=[\\"\']og:~i', $lHeader)) && !$pYiidMeta->isComplete()) {
             //get the opengraph-tags
             $lOpenGraph = OpenGraph::parse($lHeader);
             $pYiidMeta->fromOpenGraph($lOpenGraph);
         }
         if (preg_match('~application/(xml|json)\\+oembed"~i', $lHeader) && !$pYiidMeta->isComplete()) {
             try {
                 $lOEmbed = OEmbedParser::fetchByCode($lHeader);
                 $pYiidMeta->fromOembed($lOEmbed);
             } catch (Exception $e) {
                 // catch exception and try to go on
             }
         }
         if (!$pYiidMeta->isComplete()) {
             $lMeta = MetaTagParser::getKeys($lHtml, $pUrl);
             $pYiidMeta->fromMeta($lMeta);
         }
         return $pYiidMeta;
     } catch (Exception $e) {
         return false;
     }
 }