/** * Creates an item for the sitemap or sitemap index * * @param array $options various options pertaining to the item * @return string The item * @author Jose Diaz-Gonzalez **/ public function item($options = array()) { $options = array_merge(array('loc' => NULL, 'lastmod' => NULL, 'changefreq' => NULL, 'priority' => NULL, 'encode' => true), $options); if (!empty($options['loc'])) { if (!empty($options['lastmod'])) { $time = new TimeHelper(); $options['lastmod'] = $time->toAtom($options['lastmod']); } if ($options['encode']) { $options['loc'] = $this->_xmlspecialchars($options['loc']); } if ($this->sitemap) { //Construct a sitemapindex item $item = array(); $item['openEntity'] = "<sitemap>"; $item['loc'] = $this->_entityMaker("loc", $options['loc']); $item['lastmod'] = $this->_entityMaker("lastmod", $options['lastmod']); $item['closeEntity'] = "</sitemap>\n"; return $this->_mergeArrayEntities($item); } else { //Construct a sitemap item $item = array(); $item['openEntity'] = "<url>"; $item['loc'] = $this->_entityMaker("loc", $options['loc']); $item['lastmod'] = $this->_entityMaker("lastmod", $options['lastmod']); $item['changefreq'] = $this->_entityMaker("changefreq", $options['changefreq']); $item['priority'] = $this->_entityMaker("priority", $options['priority']); $item['closeEntity'] = "</url>\n"; return $this->_mergeArrayEntities($item); } } return false; }
function index() { $this->layout = 'cart'; $this->loadModel('MasterCategory'); $masterCategories = $this->MasterCategory->find('all', array('order' => array('MasterCategory.priority'), 'recursive' => -1)); $this->Category->Behaviors->attach('Containable'); foreach ($masterCategories as &$masterCategory) { $products = $this->Category->find('all', array('contain' => array('Product' => array('conditions' => array('AND' => array('Product.display = ' => '1', 'Product.stock > ' => '0', 'Product.master_category_id' => $masterCategory['MasterCategory']['id'])))), 'order' => 'Category.priority')); $masterCategory['Products'] = $products; } $this->set('products', $masterCategories); $this->loadModel('Configuration'); $isSiteClosed = $this->Configuration->findByKeyAndOrganizationId('closed', $this->currentUser['User']['organization_id']); if ($isSiteClosed == "yes") { $closed = true; $nextDelivery = $this->Delivery->find('first', array('conditions' => array('Delivery.next_delivery' => true))); App::import('Helper', 'Time'); $time = new TimeHelper(); $nextDeliveryDate = $time->format($format = 'd-m-Y', $nextDelivery['Delivery']['date'], null, "+7.0"); $this->set('nextDeliveryDate', $nextDeliveryDate); } else { $closed = false; } $this->set('closed', $closed); }
function get_recent_orders() { $time = new TimeHelper(); $dayAgo = time() - 86400; $formatedDayAgo = $time->format("Y-m-d H:i:s", $dayAgo); $result = $this->find('all', array('conditions' => array('od_date >=' => $formatedDayAgo))); return $result; }
function _isLastMonth() { App::import('Helper', 'Time'); $time = new TimeHelper(); $last_month[0] = date('Y-m-01', strtotime('-1 month')); $last_month[1] = date(DATE_W3C, mktime(0, 0, 0, date('m'), 0, date('y'))); $q = $time->daysAsSql($last_month[0], $last_month[1], 'modified'); $res = false; if ($this->SbmRanking->hasAny($q)) { $res = true; } return $res; }
public function testAlternateText() { TimeHelper::setTime(3); // Get data ready that insight requires $builders = self::buildDataTeens(); $instance = new Instance(); $instance->id = 100; $instance->network_user_id = 1; $instance->network_username = '******'; $instance->network = 'facebook'; $post_dao = new PostMySQLDAO(); $last_week_of_posts = $post_dao->getAllPostsByUsernameOrderedBy($instance->network_username, $network = $instance->network, $count = 0, $order_by = "pub_date", $in_last_x_days = $number_days, $iterator = false, $is_public = false); $insight_plugin = new AgeAnalysisInsight(); $insight_plugin->generateInsight($instance, null, $last_week_of_posts, 5); // Assert that insight got inserted $insight_dao = new InsightMySQLDAO(); $today = date('Y-m-d'); $result = $insight_dao->getInsight('age_analysis', 100, $today); $related_data = unserialize($result->related_data); $this->assertNotNull($result); $this->assertIsA($result, "Insight"); $this->assertEqual($result->headline, 'Teens said it all'); $this->assertEqual($result->text, "Teens — people less than 18 years old — wrote 100% of the " . "comments on Teen Dude's Facebook posts this week."); $this->assertEqual($related_data['age_data']['18'], 2); $this->assertEqual($related_data['age_data']['18_25'], 0); $this->assertEqual($related_data['age_data']['25_35'], 0); $this->assertEqual($related_data['age_data']['35_45'], 0); $this->assertEqual($related_data['age_data']['45'], 0); $result->id = 1; $this->debug($this->getRenderedInsightInHTML($result)); $this->debug($this->getRenderedInsightInEmail($result)); }
public function nice($dateString = null, $timezone = null, $format = null) { if (empty($format)) { $format = Configure::read('App.l10n.dateFormat'); } return ucfirst(parent::nice($dateString, $timezone, $format)); }
public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days) { parent::generateInsight($instance, $user, $last_week_of_posts, $number_days); $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__); $baseline_dao = DAOFactory::getDAO('InsightBaselineDAO'); foreach ($this->getSchedule() as $baseline_slug => $data) { $now = TimeHelper::getTime(); if ($now >= strtotime($data['start']) && $now <= strtotime($data['end'])) { $this->logger->logInfo("{$now} is in-schedule", __METHOD__ . ',' . __LINE__); $baseline = $baseline_dao->getMostRecentInsightBaseline($baseline_slug, $instance->id); if (!$baseline) { if ($instance->network == 'facebook' && date('w') == 4 || $instance->network == 'twitter' && date('w') == 1 || Utils::isTest()) { $found = $this->runInsightForConfig($data, $instance); $baseline_dao->insertInsightBaseline($baseline_slug, $instance->id, $found); } else { $this->logger->logInfo("Not today", __METHOD__ . ',' . __LINE__); } } else { $this->logger->logInfo("Already exists", __METHOD__ . ',' . __LINE__); } } else { $this->logger->logInfo("Not in-schedule", __METHOD__ . ',' . __LINE__); } } $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); }
public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days) { parent::generateInsight($instance, $user, $last_week_of_posts, $number_days); $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__); $possible_messaging = array(array('headline' => 'Ohai', 'text' => 'Greetings, humans', 'header_image' => 'http://farm3.staticflickr.com/2713/4098259769_725b5fb65b_o.jpg'), array('headline' => 'Hello', 'text' => 'Greetings, earthlings', 'header_image' => 'http://farm9.staticflickr.com/8078/8276342554_5a51725f5f_n.jpg'), array('headline' => 'Yo', 'text' => 'Greetings, peeps', 'header_image' => 'http://farm6.staticflickr.com/5006/5367216303_83c5f2dc39_n.jpg')); //Instantiate the Insight object $my_insight = new Insight(); //REQUIRED: Set the insight's required attributes //We pull some from the options above. But the could just be strings like 'Ohai' $which_messaging = TimeHelper::getTime() % count($possible_messaging); foreach ($possible_messaging[$which_messaging] as $field => $value) { $my_insight->{$field} = $value; } $my_insight->slug = 'my_test_insight_hello_thinkup'; //slug to label this insight's content $my_insight->instance_id = $instance->id; $my_insight->date = $this->insight_date; //date is often this or $simplified_post_date $my_insight->filename = basename(__FILE__, ".php"); //Same for every insight, must be set exactly this way $my_insight->emphasis = Insight::EMPHASIS_MED; //Set emphasis optionally, default is Insight::EMPHASIS_LOW //OPTIONAL: Attach related data of various types using Insight setter functions //$my_insight->setPosts($my_insight_posts); //$my_insight->setLinks($my_insight_links); //$my_insight->setPeople($my_insight_people); //$my_insight->setMilestones($my_insight_milestones); //etc $this->insight_dao->insertInsight($my_insight); $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); }
public function testHelloThinkUpInsight() { $posts = array(); $instance = new Instance(); $instance->id = 1; $instance->network_username = '******'; $instance->network = 'facebook'; $builders = self::setUpPublicInsight($instance); // We have three random options, so we'll check each one here. TimeHelper::setTime(3); $hello_thinkup_insight_plugin = new HelloThinkUpInsight(); $hello_thinkup_insight_plugin->generateInsight($instance, null, $posts, 3); $insight_dao = DAOFactory::getDAO('InsightDAO'); $result = $insight_dao->getInsight('my_test_insight_hello_thinkup', 1, date('Y-m-d')); $this->assertEqual($result->headline, 'Ohai'); $this->assertEqual($result->text, 'Greetings, humans'); $this->assertEqual($result->filename, 'hellothinkupinsight'); $this->assertNull($result->related_data); $this->assertEqual($result->emphasis, Insight::EMPHASIS_MED); TimeHelper::setTime(4); $hello_thinkup_insight_plugin->generateInsight($instance, null, $posts, 3); $insight_dao = DAOFactory::getDAO('InsightDAO'); $result = $insight_dao->getInsight('my_test_insight_hello_thinkup', 1, date('Y-m-d')); $this->assertEqual($result->headline, 'Hello'); $this->assertEqual($result->text, 'Greetings, earthlings'); TimeHelper::setTime(5); $hello_thinkup_insight_plugin->generateInsight($instance, null, $posts, 3); $insight_dao = DAOFactory::getDAO('InsightDAO'); $result = $insight_dao->getInsight('my_test_insight_hello_thinkup', 1, date('Y-m-d')); $this->assertEqual($result->headline, 'Yo'); $this->assertEqual($result->text, 'Greetings, peeps'); /** * Use this code to output the individual insight's fully-rendered HTML to file. * Then, open the file in your browser to view. * * $ TEST_DEBUG=1 php webapp/plugins/insightsgenerator/tests/TestOfHelloThinkUpInsight.php * -t testHelloThinkUpInsight > webapp/insight.html */ $controller = new InsightStreamController(); $_GET['u'] = 'Katniss Everdeen'; $_GET['n'] = 'facebook'; $_GET['d'] = date('Y-m-d'); $_GET['s'] = 'my_test_insight_hello_thinkup'; $results = $controller->go(); //Uncomment this out to see web view of insight //$this->debug($results); /** * Use this code to output the individual insight's fully-rendered email HTML to file. * Then, open the file in your browser to view. * * $ TEST_DEBUG=1 php webapp/plugins/insightsgenerator/tests/TestOfHelloThinkUpInsight.php * -t testHelloThinkUpInsight > webapp/insight_email.html */ $email_insight = $this->getRenderedInsightInEmail($result); //Uncomment this out to see the email view of insight //$this->debug($email_insight); }
public function __get($format) { if (in_array($format, TimeHelper::$formats)) { return TimeHelper::to_string($format, $this->time); } if (in_array($format, DateHelper::$formats)) { return DateHelper::to_string($format, $this->time); } }
function sendEmailSiteReopen() { $User = ClassRegistry::init('User'); $users = $User->find('all', array('conditions' => array('User.status' => 'accepted'))); foreach ($users as $user) { $to = $to . $user['User']['email'] . ", "; } $subject = "GRECOCOS website is now open"; $Delivery = ClassRegistry::init('Delivery'); $nextDelivery = $Delivery->findByNextDelivery(true); App::import('Helper', 'Time'); $timeHelper = new TimeHelper(); $deliveryDate = $timeHelper->format($format = 'd-m-Y', $nextDelivery['Delivery']['date']); $body = "<p>Dear member</p>" . "<p>The GRECOCOS website is opened. " . "You can place your orders now for delivery on " . "{$deliveryDate}.</p>" . "<p><a href=\"http://grecocos.co.cc/index.php\">" . "http://grecocos.co.cc/index.php</a></p>"; $AppengineEmail = ClassRegistry::init('AppengineEmail'); $AppengineEmail->sendEmail($to, $subject, $body); $this->Session->write('sendEmailReOpenSite', true); }
function reset_user_password($key = null) { if (!empty($this->data)) { $user = $this->Ticket->findUser($this->data['Ticket']['email']); $hasTicket = $this->Ticket->find('first', array('conditions' => array('Ticket.email' => $user['User']['email']))); //pr($hasTicket); //die; if (!empty($user) && empty($hasTicket)) { App::import('Helper', 'Time'); $time = new TimeHelper(); $key = Security::hash(String::uuid(), 'sha1', true); $this->data['Ticket']['key'] = $key; $this->data['Ticket']['creation_date'] = $time->format('Y-m-d H:i:s', time()); $url = Router::url(array('controller' => 'tickets', 'action' => 'reset_user_password'), true) . '/' . $key; //pr($url); //die; //ko se ticket shrani v bazo se poslje email (email element: lost_password_notification.ctp) useru, ki je ticket odprl if ($this->Ticket->save($this->data)) { $this->set('url', $url); $this->MyEmail->sendResetPasswordEmail($user['User']['email']); $this->Session->setFlash('notification email has been sent to you with reset data'); } } elseif (!empty($hasTicket)) { if ($this->Ticket->checkTicketDateValidity($hasTicket)) { $this->Session->setFlash('We had already sent you a link to your email address! Go get it, lazy ass!'); } else { $this->Session->setFlash('Your ticket regarding lost password has been deleted due to expiration! Try submitting again'); } } //se prozi kadar user klikne link, ki vsebuje generiran key, v svojem mailu in ga redirecta sem } elseif (isset($key) && !empty($key)) { $result = $this->Ticket->find('first', array('conditions' => array('Ticket.key' => $key))); $this->Ticket->checkTicketDateValidity($result); if (!empty($result)) { $user = $this->Ticket->findUser($result['Ticket']['email']); $this->set('userId', $user['User']['id']); $this->set('key', $key); $this->Ticket->delete($result['Ticket']['id']); //$this->redirect(array('controller' => 'users', 'action' => 'changeUserPassword/uid:'.$user['User']['id'])); } } else { $this->Session->setFlash('Please provide your email!'); } }
function niceShort($dateString = null, $timezone = null) { if (!$dateString) { return '-'; } $ret = parent::niceShort($dateString, $timezone); $aReplaceENG = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jul', 'Jun', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); $aReplace = array(__('Jan'), __('Feb'), __('Mar'), __('Apr'), __('May'), __('Jul'), __('Jun'), __('Aug'), __('Sep'), __('Oct'), __('Nov'), __('Dec')); return $ret; return str_replace(array('st', 'nd', 'th'), '', str_replace($aReplaceENG, $aReplace, $ret)); }
public function time_ago_in_words($from_time, $include_seconds = false) { $now_gmt = new \DateTime("now", new \DateTimeZone("UTC")); if (in_array(get_class($from_time), array("DateTime", "ActiveRecord\\DateTime"))) { $from_gmt = clone $from_time; $from_gmt->setTimezone(new \DateTimeZone("UTC")); } elseif (is_int($from_time)) { $from_gmt = new \DateTime("@" . $from_time, new \DateTimeZone("UTC")); } return TimeHelper::distance_of_time_in_words($from_gmt, $now_gmt, $include_seconds); }
public function setUp() { parent::setUp(); $instance = new Instance(); $instance->id = 1; $instance->network_user_id = 42; $instance->network_username = '******'; $instance->network = 'twitter'; $this->instance = $instance; TimeHelper::setTime(1425329077); // Set it to the March 2015 words timeframe }
public function setUp() { parent::setUp(); $instance = new Instance(); $instance->id = 1; $instance->network_user_id = 42; $instance->network_username = '******'; $instance->network = 'twitter'; $this->instance = $instance; TimeHelper::setTime(1418947200); // Set it to the December 2014 words timeframe }
public function __construct($View = null, $settings = array()) { $settings = Set::merge(array('engine' => 'Tools.DatetimeLib'), $settings); parent::__construct($View, $settings); $i18n = Configure::read('Localization'); if (!empty($i18n['time_offset'])) { $this->userOffset = (int) $i18n['time_offset']; } if (!empty($i18n['daylight_savings'])) { $this->daylightSavings = (bool) $i18n['daylight_savings']; } //$this->Datetime = new DatetimeLib(); }
public function setUp() { parent::setUp(); $instance = new Instance(); $instance->id = 1; $instance->network_user_id = 42; $instance->network_username = '******'; $instance->network = 'twitter'; $this->instance = $instance; $this->insight_dao = DAOFactory::getDAO('InsightDAO'); TimeHelper::setTime(2); // Force one headline for most tests }
public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days) { parent::generateInsight($instance, $user, $last_week_of_posts, $number_days); $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__); $year = date('Y'); $regenerate = false; //testing //$regenerate = true; $should_generate_insight = self::shouldGenerateEndOfYearAnnualInsight($this->slug, $instance, $insight_date = "{$year}-{$this->run_date}", $regenerate, $day_of_year = $this->run_date, null, $excluded_networks = array('twitter')); if ($should_generate_insight) { $this->logger->logInfo("Should generate", __METHOD__ . ',' . __LINE__); $fav_dao = DAOFactory::getDAO('FavoritePostDAO'); $fans = $fav_dao->getUsersWhoFavoritedMostOfYourPosts($instance->network_user_id, $instance->network, TimeHelper::getDaysSinceJanFirst()); if (!isset($fans) || sizeof($fans) == 0) { $this->logger->logInfo("No fans captured", __METHOD__ . ',' . __LINE__); return; } $post_dao = DAOFactory::getDAO('PostDAO'); $earliest_pub_date = $post_dao->getEarliestCapturedPostPubDate($instance); $qualified_year = "."; if (date('Y', strtotime($earliest_pub_date)) == date('Y')) { if (date('n', strtotime($earliest_pub_date)) > 1) { //not January //Earliest post was this year; figure out what month we have data since this year $since = date('F', strtotime($earliest_pub_date)); $qualified_year = " (at least since " . $since . ")."; } } $insight = new Insight(); $insight->instance_id = $instance->id; $insight->slug = $this->slug; $insight->date = "{$year}-{$this->run_date}"; $network = $instance->network; $copy = array('facebook' => array('normal' => array('headline' => "%username's biggest Facebook fans of %year", 'body' => "It feels great to have friends who support you. " . "%user_list liked %username's status updates the most this year%qualified_year")), 'instagram' => array('normal' => array('headline' => "%username's biggest Instagram fans of %year", 'body' => "It means a lot to have friends who love your stuff. " . "%user_list liked %username's Instagram photos and videos the most this year%qualified_year"))); $type = 'normal'; $headline = $this->getVariableCopy(array($copy[$network][$type]['headline']), array('year' => $year)); $fan_list = array(); foreach ($fans as $fan) { $fan_list[] = $fan->full_name; } $fan_list = $this->makeList($fan_list); $insight_text = $this->getVariableCopy(array($copy[$network][$type]['body']), array('user_list' => $fan_list, 'qualified_year' => $qualified_year)); $insight->headline = $headline; $insight->text = $insight_text; $insight->setPeople($fans); $insight->filename = basename(__FILE__, ".php"); $insight->emphasis = Insight::EMPHASIS_HIGH; $this->insight_dao->insertInsight($insight); } $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); }
public function timeAgoInWords($dateTime, $options = array()) { if (!isset($this->Asset) || !$this->settings['relativeTime']['enabled'] || isset($options['useCore'])) { unset($options['useCore']); return parent::timeAgoInWords($dateTime, $options); } if (!$this->_jsAdded) { if ($this->settings['relativeTime']['jsPacket'] !== false) { $this->Asset->js(array('jquery.timeago', 'jquery.mi.relativeTime'), $this->settings['relativeTime']['jsPacket']); } $this->_jsAdded = true; } $date = date('Y-m-d H:i:s O', $this->fromString($dateTime)); return String::insert($this->settings['relativeTime']['tag'], array_merge($options, compact('date'))); }
public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days) { parent::generateInsight($instance, $user, $last_week_of_posts, $number_days); $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__); $year = date('Y'); $regenerate = false; //testing //$regenerate = true; $should_generate_insight = self::shouldGenerateEndOfYearAnnualInsight($this->slug, $instance, $insight_date = "{$year}-{$this->run_date}", $regenerate, $day_of_year = $this->run_date); if ($should_generate_insight) { $this->logger->logInfo("Should generate", __METHOD__ . ',' . __LINE__); $post_dao = DAOFactory::getDAO('PostDAO'); $days = TimeHelper::getDaysSinceJanFirst(); $bestie = $post_dao->getBestie($instance, $days); if (isset($bestie)) { $type = 'normal'; } else { $type = 'none'; } $earliest_pub_date = $post_dao->getEarliestCapturedPostPubDate($instance); $qualified_year = ""; if (date('Y', strtotime($earliest_pub_date)) == date('Y')) { if (date('n', strtotime($earliest_pub_date)) > 1) { //not January //Earliest post was this year; figure out what month we have data since this year $since = date('F', strtotime($earliest_pub_date)); $qualified_year = " (at least since " . $since . ")"; } } $insight = new Insight(); $insight->instance_id = $instance->id; $insight->slug = $this->slug; $insight->date = "{$year}-{$this->run_date}"; $network = $instance->network; $copy = array('twitter' => array('normal' => array('headline' => "%username's Twitter bestie of %year", 'body' => "Nobody likes tweeting into the void. %username and @%bestie made Twitter a " . "void-free place to tweet this year. %username tweeted at @%bestie " . "<strong>%u_to_b times</strong> in 2015, and @%bestie replied " . "<strong>%b_to_u times</strong>%qualified_year. OMG you two!"), 'none' => array('headline' => "%username's Twitter bestie of %year", 'body' => "%username didn't reply to any one person more than 3 times " . "this year%qualified_year. That means no one can claim the title of %username's Twitter " . "bestie. Playing hard-to-get, huh?")), 'facebook' => array('normal' => array('headline' => "%username's Facebook bestie of %year", 'body' => "Everyone loves getting comments from their friends. In 2015, %bestie commented " . "on %username's status updates <strong>%b_to_u times</strong>, more than " . "anyone else%qualified_year. Best friends forever!"), 'none' => array('headline' => "%username's Facebook bestie of %year", 'body' => "%username's friends must consider %username's words definitive - no one replied " . "more than three times to %username's status updates all year%qualified_year.")), 'instagram' => array('normal' => array('headline' => "%username's Instagram bestie of %year", 'body' => "Everyone loves getting comments from their friends. In 2015, %bestie commented " . "on %username's Instagram photos and videos <strong>%b_to_u times</strong>, more than " . "anyone else%qualified_year. Best friends forever!"), 'none' => array('headline' => "%username's Instagram bestie of %year", 'body' => "%username's photos and videos left %username's friends speechless - no one replied " . "more than three times to %username's Instagram posts all year%qualified_year."))); $headline = $this->getVariableCopy(array($copy[$network][$type]['headline']), array('year' => $year)); $insight_text = $this->getVariableCopy(array($copy[$network][$type]['body']), array('bestie' => isset($bestie['user_name']) ? $bestie['user_name'] : "", 'u_to_b' => isset($bestie['total_replies_to']) ? $bestie['total_replies_to'] : "", 'b_to_u' => isset($bestie['total_replies_from']) ? $bestie['total_replies_from'] : "", 'qualified_year' => $qualified_year)); $insight->headline = $headline; $insight->text = $insight_text; $insight->filename = basename(__FILE__, ".php"); $insight->emphasis = Insight::EMPHASIS_HIGH; if (isset($bestie['avatar'])) { $insight->header_image = $bestie['avatar']; } $this->insight_dao->insertInsight($insight); } $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); }
public function testNoHealthyShareLikes() { // Get data ready that insight requires $instance = new Instance(); $instance->id = 10; $instance->network_username = '******'; $instance->network = 'twitter'; $posts = array(); $posts[] = new Post(array('reply_count_cache' => 5, 'retweet_count_cache' => 15, 'favlike_count_cache' => 3)); $posts[] = new Post(array('reply_count_cache' => 0, 'retweet_count_cache' => 5, 'favlike_count_cache' => 15)); $posts[] = new Post(array('reply_count_cache' => 2, 'retweet_count_cache' => 5, 'favlike_count_cache' => 1)); $insight_dao = new InsightMySQLDAO(); $insight_plugin = new ResponseTimeInsight(); TimeHelper::setTime(2); $insight_plugin->generateInsight($instance, null, $posts, 3); $result = $insight_dao->getInsight('response_time', 10, date('Y-m-d')); $this->assertEqual("That's a healthy share of the 21 million tweets each hour.", $result->text); $posts = array(); $posts[] = new Post(array('reply_count_cache' => 5, 'retweet_count_cache' => 15, 'favlike_count_cache' => 13)); $posts[] = new Post(array('reply_count_cache' => 0, 'retweet_count_cache' => 5, 'favlike_count_cache' => 15)); $posts[] = new Post(array('reply_count_cache' => 2, 'retweet_count_cache' => 5, 'favlike_count_cache' => 15)); TimeHelper::setTime(2); $insight_plugin->generateInsight($instance, null, $posts, 3); $result = $insight_dao->getInsight('response_time', 10, date('Y-m-d')); $this->assertNotEqual("That's a healthy share of the 21 million tweets each hour.", $result->text); }
public function testVariableFuckCountInHeadline() { TimeHelper::setTime(3); $insight_dao = DAOFactory::getDAO('InsightDAO'); $post_builders = array(); $post_builders[] = FixtureBuilder::build('posts', array('author_username' => 'testy', 'network' => 'twitter', 'post_text' => 'f**k', 'pub_date' => date('Y-m-d'))); $post_builders[] = FixtureBuilder::build('posts', array('author_username' => 'testy', 'network' => 'facebook', 'post_text' => 'f**k', 'pub_date' => date('Y-m-d'))); $insight_plugin = new FBombCountInsight(); $today = date('Y-m-d'); $insight_plugin->generateInsight($this->instance, null, $posts, 3); $result = $insight_dao->getInsight($insight_plugin->getSlug(), $this->instance->id, $today); $this->assertEqual($result->headline, '@testy really gave a f**k'); $post_builders[] = FixtureBuilder::build('posts', array('author_username' => 'testy', 'network' => 'twitter', 'post_text' => 'f**k', 'pub_date' => date('Y-m-d'))); $insight_plugin->generateInsight($this->instance, null, $posts, 3); $result = $insight_dao->getInsight($insight_plugin->getSlug(), $this->instance->id, $today); $this->assertEqual($result->headline, 'F-bombs rain from the sky'); TimeHelper::setTime(1); }
echo $settings->enable_https ? secure_url('post') : URL::to('post'); echo '/' . $post->slug; ?> "> <div class="thumbnail-overlay"></div> <img src="<?php echo ImageHandler::getImage($post->image, 'medium'); ?> "> <div class="details"> <h2><?php echo $post->title; ?> </h2> <span><?php echo TimeHelper::convert_seconds_to_HMS($post->duration); ?> </span> </div> </a> <div class="block-contents"> <p class="date"><?php echo date("F jS, Y", strtotime($post->created_at)); ?> </p> <p class="desc"><?php if (strlen($post_description) > 90) { echo substr($post_description, 0, 90) . '...'; } else { echo $post->description; }
public function testAlternateHeadlinesFacebook() { $this->instance->network = 'facebook'; $insight_dao = DAOFactory::getDAO('InsightDAO'); $posts = array(new Post(array('post_text' => 'Behold my news feed and weep.'))); $insight_plugin = new MetaPostsCountInsight(); TimeHelper::setTime(1); $insight_plugin->generateInsight($this->instance, null, $posts, 7); $today = date('Y-m-d'); $result = $insight_dao->getInsight($insight_plugin->getSlug(), $this->instance->id, $today); $this->assertEqual($result->headline, "1 status update about Facebook"); $this->assertEqual($result->text, "reflection used Facebook to talk about Facebook once this " . "week. That's 100% of reflection's status updates for the week."); $this->debug($this->getRenderedInsightInHTML($result)); $this->debug($this->getRenderedInsightInEmail($result)); TimeHelper::setTime(2); $insight_plugin->generateInsight($this->instance, null, $posts, 7); $today = date('Y-m-d'); $result = $insight_dao->getInsight($insight_plugin->getSlug(), $this->instance->id, $today); $this->assertEqual($result->headline, "It's Facebook all the way down"); $this->debug($this->getRenderedInsightInHTML($result)); $this->debug($this->getRenderedInsightInEmail($result)); TimeHelper::setTime(3); $insight_plugin->generateInsight($this->instance, null, $posts, 7); $today = date('Y-m-d'); $result = $insight_dao->getInsight($insight_plugin->getSlug(), $this->instance->id, $today); $this->assertEqual($result->headline, "1 status update about Facebook"); $this->debug($this->getRenderedInsightInHTML($result)); $this->debug($this->getRenderedInsightInEmail($result)); }
/** * Get three most retweeted posts this year * @param Instance $instance * @param str $order Defaults to 'retweets' * @return array Three most retweeted posts in descending order */ public function topThreeThisYear(Instance $instance, $order = 'retweet_count_api') { $post_dao = DAOFactory::getDAO('PostDAO'); $days = TimeHelper::getDaysSinceJanFirst(); $posts = $post_dao->getAllPostsByUsernameOrderedBy($instance->network_username, $network = $instance->network, $count = 3, $order_by = $order, $in_last_x_days = $days, $iterator = false, $is_public = false); //Filter out posts with 0 retweets $posts_with_retweets = array(); foreach ($posts as $post) { if ($post->retweet_count_api > 0) { $posts_with_retweets[] = $post; } } return $posts_with_retweets; }
/** * Test element wrapping in timeAgoInWords * * @return void */ public function testTimeAgoInWords() { $Time = new TimeHelper($this->View); $timestamp = strtotime('+8 years, +4 months +2 weeks +3 days'); $result = $Time->timeAgoInWords($timestamp, array('end' => '1 years', 'element' => 'span')); $expected = array('span' => array('title' => $timestamp, 'class' => 'time-ago-in-words'), 'on ' . date('j/n/y', $timestamp), '/span'); $this->assertTags($result, $expected); $result = $Time->timeAgoInWords($timestamp, array('end' => '1 years', 'element' => array('title' => 'testing', 'rel' => 'test'))); $expected = array('span' => array('title' => 'testing', 'class' => 'time-ago-in-words', 'rel' => 'test'), 'on ' . date('j/n/y', $timestamp), '/span'); $this->assertTags($result, $expected); $timestamp = strtotime('+2 weeks'); $result = $Time->timeAgoInWords($timestamp, array('end' => '1 years', 'element' => 'div')); $expected = array('div' => array('title' => $timestamp, 'class' => 'time-ago-in-words'), '2 weeks', '/div'); $this->assertTags($result, $expected); }
public function testInsightV6WithFormattedNumber() { TimeHelper::setTime(34); $yesterday = date('Y-m-d', strtotime('-1 day')); $this->instance->network_user_id = 48; $posts = array(); $posts[] = new Post(array('id' => 1, 'post_text' => 'A Post', 'author_user_id' => $this->instance->network_user_id, 'author_username' => 'lowfollowers', 'author_full_name' => 'The Retweetee', 'in_retweet_of_post_id' => 1, 'in_rt_of_user_id' => 47, 'network' => 'twitter', 'pub_date' => $yesterday)); $insight_plugin = new AmplifierInsight(); $insight_plugin->generateInsight($this->instance, self::makeUser(1000000), $posts, 3); $insight_dao = DAOFactory::getDAO('InsightDAO'); $result = $insight_dao->getInsight('top_amplifier', $this->instance->id, date('Y-m-d')); $this->assertNotNull($result); $this->assertEqual($result->headline, '100,000x more people saw @tester\'s tweet thanks to @tester'); $data = unserialize($result->related_data); $this->assertEqual(count($data['people']), 1); $this->assertEqual($data['people'][0]->username, 'tester'); $this->assertEqual($data['people'][0]->user_id, 47); $this->assertEqual(count($data['posts']), 1); $this->assertEqual($data['posts'][0]->post_text, 'A Post'); $this->debug($this->getRenderedInsightInEmail($result)); $this->debug($this->getRenderedInsightInHTML($result)); }
/** * Get the most talkative day(s) on network * @param Instance $instance * @return array Most talkative day or days */ public function getMostTalkativeDays(Instance $instance) { $post_dao = DAOFactory::getDAO('PostDAO'); $days = TimeHelper::getDaysSinceJanFirst(); $most_talkative_days = $post_dao->getMostTalkativeDays($instance->network_username, $instance->network, $in_last_x_days = $days); $most_posts = $most_talkative_days[0]['post_count']; foreach ($most_talkative_days as $key => $day) { if ($day['post_count'] < $most_posts) { unset($most_talkative_days[$key]); } } return $most_talkative_days; }
/** * Get three most replied to posts this year * @param Instance $instance * @param str $order Defaults to 'reply_count_cache' * @return array Three most replied to posts in descending order */ public function topThreeThisYear(Instance $instance, $order = 'reply_count_cache') { $post_dao = DAOFactory::getDAO('PostDAO'); $days = TimeHelper::getDaysSinceJanFirst(); $posts = $post_dao->getAllPostsByUsernameOrderedBy($instance->network_username, $network = $instance->network, $count = 3, $order_by = $order, $in_last_x_days = $days, $iterator = false, $is_public = false); return $posts; }