function run() { $go = new ShortURL(); if( isset( $this->request['action'] ) ) { if( $this->request['action'] == 'add' ) { $go->print_results(); } elseif( $this->request['action'] == 'req' ) { $go->print_request_form(); } elseif( $this->request['action'] == 'email' ) { $go->send_email(); } } else { $go->print_form(); } //Since we connected to a different DB inside ShortURL, we need to //reconnect to Reason after we are done. connectDB( REASON_DB ); }
/** * Log article related event. * * @param Article $p_article * @param string $p_text * @param int $p_userId * @param int $p_eventId * @param bool $p_short * * @return void */ public static function ArticleMessage(Article $p_article, $p_text, $p_userId = NULL, $p_eventId = 0, $p_short = FALSE) { ob_start(); echo getGS('Article'), ': ', $p_article->getTitle(); if (!$p_short) { // add publication, issue, section echo ' ('; echo getGS('Publication'), ': ', $p_article->getPublicationId(); echo ', '; echo getGS('Issue'), ': ', $p_article->getIssueNumber(); echo ', '; echo getGS('Section'), ': ', $p_article->getSectionNumber(); echo ")\n"; } // generate url $url = ShortURL::GetURL($p_article->getPublicationId(), $p_article->getLanguageId(), $p_article->getIssueNumber(), $p_article->getSectionNumber(), $p_article->getArticleNumber()); if (strpos($url, 'http') !== FALSE) { // no url for deleted echo getGS('Article URL'), ': ', $url, "\n"; } echo getGS('Article Number'), ': ', $p_article->getArticleNumber(), "\n"; echo getGS('Language'), ': ', $p_article->getLanguageName(), "\n"; echo "\n"; echo getGS('Action') . ': ', $p_text; $message = ob_get_clean(); self::Message($message, $p_userId, $p_eventId); }
public static function GetURL($publicationId, $languageId = null, $issueNo = null, $sectionNo = null, $articleNo = null) { $publicationService = \Zend_Registry::get('container')->getService('newscoop.publication_service'); if ($publicationService->getPublication()) { if ($publicationService->getPublication()->getId() == $publicationId) { $publication = $publicationService->getPublication(); } else { $em = \Zend_Registry::get('container')->getService('em'); $publication = $em->getRepository('Newscoop\\Entity\\Publication')->findOneById($publicationId); if (!$publication) { throw new \Exception('Publication does not exist.'); } } } else { $em = \Zend_Registry::get('container')->getService('em'); $publication = $em->getRepository('Newscoop\\Entity\\Publication')->findOneById($publicationId); if (!$publication) { throw new \Exception('Publication does not exist.'); } } if (!isset($languageId)) { $languageId = $publication->getDefaultLanguage()->getId(); } $uri = ShortURL::GetURI($publicationId, $languageId, $issueNo, $sectionNo, $articleNo); if (!is_string($uri) && PEAR::isError($uri)) { return $uri; } $scheme = $_SERVER['SERVER_PORT'] == 443 ? 'https://' : 'http://'; return $scheme . $publication->getDefaultAlias()->getName() . $uri; }
public static function GetURL($p_publicationId, $p_languageId = null, $p_issueNo = null, $p_sectionNo = null, $p_articleNo = NULL, $p_port = null) { global $g_ado_db; global $_SERVER; if (is_null($p_port)) { if (!isset($_SERVER['SERVER_PORT'])) { $_SERVER['SERVER_PORT'] = 80; } $p_port = $_SERVER['SERVER_PORT']; } $publicationObj = new Publication($p_publicationId); if (!$publicationObj->exists()) { return new PEAR_Error(getGS('Publication does not exist.')); } if (!isset($p_languageId)) { $p_languageId = $publicationObj->getDefaultLanguageId(); } $scheme = $_SERVER['SERVER_PORT'] == 443 ? 'https://' : 'http://'; $defaultAlias = new Alias($publicationObj->getDefaultAliasId()); $uri = ShortURL::GetURI($p_publicationId, $p_languageId, $p_issueNo, $p_sectionNo, $p_articleNo); if (!is_string($uri) && PEAR::isError($uri)) { return $uri; } return $scheme . $defaultAlias->getName() . $uri; }
/** * Log article related event. * * @param Article $p_article * @param string $p_text * @param int $p_userId * @param int $p_eventId * @param bool $p_short * * @return void */ public static function ArticleMessage(Article $p_article, $p_text, $p_userId = NULL, $p_eventId = 0, $p_short = FALSE) { ob_start(); $translator = \Zend_Registry::get('container')->getService('translator'); echo $translator->trans('Article'), ': ', $p_article->getTitle(); if (!$p_short) { // add publication, issue, section echo ' ('; echo $translator->trans('Publication'), ': ', $p_article->getPublicationId(); echo ', '; echo $translator->trans('Issue'), ': ', $p_article->getIssueNumber(); echo ', '; echo $translator->trans('Section'), ': ', $p_article->getSectionNumber(); echo ")\n"; } // generate url $url = ShortURL::GetURL($p_article->getPublicationId(), $p_article->getLanguageId(), $p_article->getIssueNumber(), $p_article->getSectionNumber(), $p_article->getArticleNumber()); if (strpos($url, 'http') !== FALSE) { // no url for deleted echo $translator->trans('Article URL', array(), 'api'), ': ', $url, "\n"; } echo $translator->trans('Article Number', array(), 'api'), ': ', $p_article->getArticleNumber(), "\n"; echo $translator->trans('Language'), ': ', $p_article->getLanguageName(), "\n"; echo "\n"; echo $translator->trans('Action') . ': ', $p_text; $message = ob_get_clean(); self::Message(substr($message, 0, 254), $p_userId, $p_eventId); }
/** * Generates a shortened string for a given $target url and stores it inside the database. * * The generated string (here $short) follows several rules: * * - if strlen($target) > 4 then strlen($target) > strlen($short) else strlen($short) = 4 * * - $target !== $short * * - length of $short is 4 * * - $short contains only numbers and capitalised consonants. * * The function assumes that the $target url exists. Aim of the function is * to generate a string that is similar to the target url. * The return value is of type ShortURL which holds * several information about the generated URL. * * @param string $url * the target * @return ShortURL */ public function generateShortURL($target) { $newTarget = preg_replace('/[aeiou,.\\/\\\\-_&=:\\s]+/i', '', $target); $newTarget = strtoupper($newTarget); $newTarget = str_shuffle($newTarget); /* * If string has more than 4 character pick the first 4 character. * else if string has less than 4 character fill missing character. */ if (strlen($newTarget) > 4) { $newTarget = substr($newTarget, 0, 4); } else { if (strlen($newTarget) < 4) { $newTarget = $newTarget . $this->generateRandomString(4 - strlen($newTarget)); } } if ($this->exists($newTarget)) { $newTarget = $this->randomizer($newTarget); } $short = new ShortURL($this->config['shortener']['targetURL']); $short->setTarget($target); $short->setShortName($newTarget); $short->setDateCreated(time()); $short->setDateExpire($short->getDateCreated() + 4 * 24 * 60 * 60); $this->dbManager->insertShortURL($short); return $short; }
/** * Send request to refresh article cache on Facebook * * @param int $number * @param int $languageId * * @return mixed response from Facebook about url, or array with error message */ private function clearpageCache($number, $languageId) { $article = new \Article($languageId, $number); if (!$article->isPublished()) { return array('message' => $this->get('translator')->trans('fb.label.errornot')); } $url = \ShortURL::GetURL($article->getPublicationId(), $article->getLanguageId(), $article->getIssueNumber(), $article->getSectionNumber(), $article->getArticleNumber()); try { $curlClient = new \Buzz\Client\Curl(); $curlClient->setTimeout(10000); $browser = new \Buzz\Browser($curlClient); $result = $browser->post('https://graph.facebook.com/?id=' . $url . '&scrape=true'); $urlInfo = json_decode($result->getContent(), true); } catch (\Buzz\Exception\ClientException $e) { return array('message' => $this->get('translator')->trans('fb.label.error')); } return $urlInfo; }
private function update_tweetbacks(Post $post) { // Get the lastest tweetback in database $tweetbacks = $post->comments->tweetbacks; if ($tweetbacks->count > 0) { $tweet_url = explode('/', $tweetbacks[0]->url); $since_id = end($tweet_url); } else { $since_id = 0; } // Get short urls $aliases = array_filter((array) ShortURL::get($post)); //$aliases[] = $post->permalink; // Do not include original permalink, because Twitter Search has character limit, too. // Construct request URL $url = 'http://search.twitter.com/search.json?'; $url .= http_build_query(array('ors' => implode(' ', $aliases), 'rpp' => 50, 'since_id' => $since_id), '', '&'); // Get JSON content $call = new RemoteRequest($url); $call->set_timeout(5); $result = $call->execute(); if (Error::is_error($result)) { throw Error::raise(_t('Unable to contact Twitter.', $this->class_name)); } $response = $call->get_response_body(); // Decode JSON $obj = json_decode($response); if (isset($obj->results) && is_array($obj->results)) { $obj = $obj->results; } else { throw Error::raise(_t('Response is not correct, Twitter server may be down or API is changed.', $this->class_name)); } // Store new tweetbacks into database foreach ($obj as $tweet) { Comment::create(array('post_id' => $post->id, 'name' => $tweet->from_user, 'url' => sprintf('http://twitter.com/%1$s/status/%2$d', $tweet->from_user, $tweet->id), 'content' => $tweet->text, 'status' => Comment::STATUS_APPROVED, 'date' => HabariDateTime::date_create($tweet->created_at), 'type' => Comment::TWEETBACK)); } }
/** * @Route("/plugin/articlescalendar/articlesoftheday/get") */ public function getArticlesOfTheDayAction(Request $request) { $em = $this->container->get('em'); $lastArticleOfTheDay = $em->getRepository('Newscoop\\ArticlesCalendarBundle\\Entity\\ArticleOfTheDay')->createQueryBuilder('a')->where('a.is_active = true')->orderBy('a.created_at', 'DESC')->setMaxResults(1)->getQuery()->getSingleResult(); $response = new Response(); $response->setLastModified($lastArticleOfTheDay->getCreatedAt()); $response->setPublic(); if ($response->isNotModified($request)) { return $response; } $articleOfTheDayService = $this->container->get('newscoop_articles_calendar.articles_calendar_service'); $settings = $em->getRepository('Newscoop\\ArticlesCalendarBundle\\Entity\\Settings')->findOneBy(array('is_active' => true)); $publicationNumbers = explode(',', $request->get('publication_numbers', $settings->getPublicationNumbers())); $renditionName = $request->get('renditionName', $settings->getRendition()); $imageWidth = $request->get('image_width', $settings->getImageWidth()); $imageHeight = $request->get('image_height', $settings->getImageHeight()); $start = $request->get('start'); $end = $request->get('end'); $query = ""; foreach ($publicationNumbers as $value) { $query .= "a.publicationNumbers LIKE '" . $value . "%' OR "; } $articlesOfTheDay = $articleOfTheDayService->getArticleOfTheDay(new \DateTime($start), new \DateTime($end), $query); $results = array(); foreach ($articlesOfTheDay as $dayArticle) { $element = array(); $articleNumber = $dayArticle['articleNumber']; $image = $this->container->get('image.rendition')->getArticleRenditionImage($articleNumber, $renditionName, $imageWidth ? $imageWidth : null, $imageHeight ? $imageHeight : null); $element['title'] = $dayArticle['name']; if (isset($image)) { $element['image'] = $this->container->get('zend_router')->assemble(array('src' => $image['src']), 'image', true, false); } else { $element['image'] = null; } $date = $dayArticle['date']->format('Y-m-d'); $date = explode(" ", $date); $YMD = explode("-", $date[0]); $element['date'] = array("year" => intval($YMD[0]), "month" => intval($YMD[1]), "day" => intval($YMD[2])); $element['url'] = \ShortURL::GetURL($dayArticle['publicationId'], $dayArticle['articleLanguageId'], null, null, $articleNumber); $results[] = $element; } $response->setContent(json_encode(array('articles' => $results))); $response->headers->set('Content-Type', 'application/json'); return $response; }
{ $_SERVER['SERVER_PORT'] = 80; } $scheme = $_SERVER['SERVER_PORT'] == 443 ? 'https://' : 'http://'; $siteAlias = new Alias($publicationObj->getDefaultAliasId()); $websiteURL = $scheme.$siteAlias->getName() . $GLOBALS['Campsite']['SUBDIR']; $accessParams = "LoginUserId=" . $g_user->getUserId() . "&LoginUserKey=" . $g_user->getKeyId() . "&AdminAccess=all"; if ($publicationObj->getUrlTypeId() == 1) { $templateObj = new Template($templateId); $url = "$websiteURL/tpl/" . $templateObj->getName() . "?IdLanguage=$f_language_id" . "&IdPublication=$f_publication_id&NrIssue=$f_issue_number&NrSection=$f_section_number" . "&NrArticle=$f_article_number&$accessParams"; } else { $url = ShortURL::GetURL($f_publication_id, $f_language_selected, null, null, $f_article_number); if (PEAR::isError($url)) { $errorStr = $url->getMessage(); } $url .= '?' . $accessParams; } $selectedLanguage = (int)CampRequest::GetVar('f_language_selected'); $url .= "&previewLang=$selectedLanguage"; $siteTitle = (!empty($Campsite['site']['title'])) ? htmlspecialchars($Campsite['site']['title']) : putGS("Newscoop") . $Campsite['VERSION']; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en" xml:lang="en"> <head> <title><?php p($siteTitle); ?></title> </head>
</div> </div> <?php camp_html_copyright_notice(); return; } // Get proper URL to switch between modes if ($articleObj->userCanModify($g_user)) { $switchModeUrl = camp_html_article_url($articleObj, $f_language_id, 'edit.php') . '&f_edit_mode=' . ($inEditMode ? 'view' : 'edit'); } // Display either the "Go to live article" or "Preview" button // depending on article status $doPreviewLink = ''; if (isset($publicationObj) && $articleObj->isPublished()) { if ($publicationObj->getUrlTypeId() == 2) { $previewLinkURL = ShortURL::GetURL($publicationObj->getPublicationId(), $articleObj->getLanguageId(), null, null, $articleObj->getArticleNumber()); $doPreviewLink = 'live'; $seoFields = $publicationObj->getSeo(); $articleEndLink = $articleObj->getSEOURLEnd($seoFields, $articleObj->getLanguageId()); if (strlen($articleEndLink) > 0) { $previewLinkURL .= $articleEndLink; } if (!is_string($previewLinkURL) && PEAR::isError($previewLinkURL)) { $doLiveLink = ''; } } } else { if (isset($publicationObj) && 0 < $f_publication_id && 0 < $f_issue_number && 0 < $f_section_number) { $doPreviewLink = 'preview'; $previewLinkURL = "/{$ADMIN}/articles/preview.php?f_publication_id={$f_publication_id}" . "&f_issue_number={$f_issue_number}&f_section_number={$f_section_number}" . "&f_article_number={$f_article_number}&f_language_id={$f_language_id}&f_language_selected={$f_language_selected}"; }
/** * Inserts a ShortURL into the database. * * @param \ShortURL $url * the ShortURL that needs be stored inside the database. * @return \\ShortURL which is updated by this method. */ public function insertShortURL(\ShortURL $url) { $con = $this->getConnection(); if (isset($con)) { $query = "INSERT INTO shortener (id, shortName, target, dateCreated, dateExpired) \n VALUES (null, :shortName, :target, :dateCreated, :dateExpired)"; $stmt = $con->prepare($query); $stmt->bindParam(':shortName', $url->getShortName()); $stmt->bindParam(':target', $url->getTarget()); $stmt->bindParam(':dateCreated', $url->getDateCreated()); $stmt->bindParam(':dateExpired', $url->getDateExpire()); $stmt->execute(); $id = $con->lastInsertId(); $url->setId($id); return $url; } }
/** * Send comment notification * * @param Newscoop\Entity\Comment $comment * @param Newscoop\Entity\Article $article * @param array $authors * @param Newscoop\Entity\User $user * * @return void */ public function sendCommentNotification(Comment $comment, Article $article, array $authors, User $user = null) { $publicationService = $this->container->get('newscoop_newscoop.publication_service'); $templatesService = $this->container->get('newscoop.templates.service'); $placeholdersService = $this->container->get('newscoop.placeholders.service'); $preferencesService = $this->container->get('preferences'); $translator = $this->container->get('translator'); $emails = array_unique(array_filter(array_map(function ($author) { return $author->getEmail(); }, $authors))); $publication = $publicationService->getPublication(); $moderatorTo = $this->getModeratorEmailIfModerationEnabled($publication, $user); $moderatorTo ? $emails['moderator'] = $moderatorTo : null; $moderatorFrom = $publication->getModeratorFrom(); if (empty($emails)) { return; } $smarty = $templatesService->getSmarty(); $uri = \CampSite::GetURIInstance(); if ($user) { $smarty->assign('username', $user->getUsername()); } else { $smarty->assign('username', $translator->trans('anonymous')); } $smarty->assign('comment', $comment); $smarty->assign('article', new \MetaArticle($article->getLanguageId(), $article->getNumber())); $smarty->assign('publication', $uri->getBase()); $smarty->assign('site', $uri->getBase()); $smarty->assign('articleLink', \ShortURL::GetURI($article->getPublicationId(), $article->getLanguageId(), $article->getIssueId(), $article->getSectionId(), $article->getNumber())); $message = $templatesService->fetchTemplate("email_comment-notify.tpl"); $this->send($placeholdersService->get('subject'), $message, $emails, $moderatorFrom ?: $preferencesService->EmailFromAddress); }
protected function getUrl() { return ShortURL::GetURL($this->m_dbObject->getPublicationId(), $this->m_dbObject->getLanguageId(), null, null, $this->m_dbObject->getArticleNumber()); }