当前位置: 首页>>代码示例>>PHP>>正文


PHP Insight::setHeroImage方法代码示例

本文整理汇总了PHP中Insight::setHeroImage方法的典型用法代码示例。如果您正苦于以下问题:PHP Insight::setHeroImage方法的具体用法?PHP Insight::setHeroImage怎么用?PHP Insight::setHeroImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Insight的用法示例。


在下文中一共展示了Insight::setHeroImage方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: generateInsight

 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__);
     if ($this->shouldGenerateInsight($this->slug, $instance, $insight_date = 'today', $regenerate = false)) {
         $baseline_dao = DAOFactory::getDAO('InsightBaselineDAO');
         $met_milestone = 0;
         foreach ($this->milestones as $count => $text) {
             if ($user->follower_count > $count && $user->follower_count < $count * 2) {
                 $met_milestone = $count;
             } else {
                 if ($user->follower_count < $count) {
                     break;
                 }
             }
         }
         if ($met_milestone) {
             $baseline = $baseline_dao->getMostRecentInsightBaseline('follower_vis_last_run', $instance->id);
             if (!isset($baseline->value) || isset($baseline->value) && $met_milestone > $baseline->value) {
                 $baseline_dao->insertInsightBaseline('follower_vis_last_run', $instance->id, $met_milestone);
                 $insight = new Insight();
                 $insight->slug = $this->slug;
                 $insight->instance_id = $instance->id;
                 $insight->date = $this->insight_date;
                 $insight->filename = basename(__FILE__, ".php");
                 $insight->emphasis = Insight::EMPHASIS_HIGH;
                 $insight->headline = $this->getVariableCopy(array($this->milestones[$met_milestone]['headline']), array('total' => number_format($user->follower_count)));
                 $insight->text = $this->getVariableCopy(array($this->milestones[$met_milestone]['text']), array('total' => number_format($user->follower_count), 'thres' => number_format($met_milestone)));
                 $insight->setHeroImage($this->milestones[$met_milestone]["hero_image"]);
                 $this->insight_dao->insertInsight($insight);
             }
         }
     }
     $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
 }
开发者ID:pepeleproso,项目名称:ThinkUp,代码行数:35,代码来源:followcountvisualizer.php

示例2: generateInsight

 public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days)
 {
     if (Utils::isTest() || date("Y-m-d") == '2015-02-23') {
         parent::generateInsight($instance, $user, $last_week_of_posts, $number_days);
         $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
         $hero_image = array('url' => 'https://www.thinkup.com/assets/images/insights/2015-02/oscars2015.jpg', 'alt_text' => 'Oprah got a Lego Oscar!', 'credit' => 'Photo: Disney | ABC Television Group', 'img_link' => 'https://www.flickr.com/photos/disneyabc/16620198142');
         $post_dao = DAOFactory::getDAO('PostDAO');
         $last_month_of_posts = $post_dao->getAllPostsByUsernameOrderedBy($instance->network_username, $network = $instance->network, $count = 0, $order_by = "pub_date", $in_last_x_days = 30, $iterator = false, $is_public = false);
         if (self::shouldGenerateWeeklyInsight('oscars_2015', $instance, $insight_date = 'today', $regenerate_existing_insight = false, $day_of_week = 1, count($last_month_of_posts))) {
             foreach ($last_month_of_posts as $post) {
                 $this->logger->logInfo("Post text is: " . $post->post_text, __METHOD__ . ',' . __LINE__);
                 //  see if $post date is before the awards aired
                 if ($post->pub_date < "2015-02-22 18:00:00") {
                     $mentioned_oscar_winner = self::detectOscarWinnerReferences($post->post_text);
                     $mentioned_oscar_loser = self::detectOscarLoserReferences($post->post_text);
                     $oscar_mention_count = self::countOscarMentions($post->post_text);
                     if ($mentioned_oscar_winner) {
                         $this->logger->logInfo("Winner mention: {$mentioned_oscar_winner}", __METHOD__ . ',' . __LINE__);
                         $insight_body = "{$this->username} was talking about {$mentioned_oscar_winner} before the " . "Academy Award winners were even announced!";
                     } else {
                         $this->logger->logInfo("No winners mentioned, skipping insight. ", __METHOD__ . ',' . __LINE__);
                     }
                     if ($mentioned_oscar_loser) {
                         $this->logger->logInfo("Loser mention: {$mentioned_oscar_loser}", __METHOD__ . ',' . __LINE__);
                         $insight_body_suffix = " Looks like the Academy voters might have missed " . "{$this->username}'s " . $this->terms->getNoun('post', InsightTerms::PLURAL) . " about " . $mentioned_oscar_loser . ", though.";
                     }
                 }
             }
             if ($insight_body_suffix) {
                 $insight_text = $insight_body . $insight_body_suffix;
             } else {
                 $insight_text = $insight_body;
             }
             if ($insight_body) {
                 $headline = "Somebody was ready for the Oscars party!";
                 $my_insight = new Insight();
                 $my_insight->slug = 'oscars_2015';
                 //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->headline = $headline;
                 // or just set a string like 'Ohai';
                 $my_insight->text = $insight_text;
                 // or just set a strong like "Greetings humans";
                 $my_insight->filename = basename(__FILE__, ".php");
                 //Same for every insight, must be set this way
                 $my_insight->emphasis = Insight::EMPHASIS_HIGH;
                 //Optional emphasis, default Insight::EMPHASIS_LOW
                 $my_insight->setHeroImage($hero_image);
                 $this->insight_dao->insertInsight($my_insight);
             }
         }
         $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
     }
 }
开发者ID:pepeleproso,项目名称:ThinkUp,代码行数:56,代码来源:oscars2015.php

示例3: generateInsight

 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__);
     $has_never_run = !$this->insight_dao->doesInsightExist($this->slug, $instance->id);
     if (Utils::isTest() || $has_never_run && (date("Y-m-d") == '2015-06-27' || date("Y-m-d") == '2015-06-28')) {
         $this->logger->logInfo("Should generate insight", __METHOD__ . ',' . __LINE__);
         $hero_image = array('url' => 'https://www.thinkup.com/assets/images/insights/2015-06/white-house-rainbow.jpg', 'alt_text' => '1600 Pennsylvania Avenue', 'credit' => 'Photo: Jason Goldman', 'img_link' => 'https://twitter.com/Goldman44/status/614599247959322624');
         $topics = array('lovewins' => array("LoveWins", "marriage equality", "scotus", "gay marriage", "pride"));
         $matches = array();
         $matched_posts = array();
         $matched = false;
         foreach ($last_week_of_posts as $post) {
             foreach ($topics as $key => $strings) {
                 foreach ($strings as $string) {
                     if (preg_match_all('/\\b' . strtolower($string) . '\\b/i', strtolower($post->post_text), $matches)) {
                         $matched = true;
                         $this->logger->logInfo("FOUND " . $string . " in " . $post->post_text, __METHOD__ . ',' . __LINE__);
                     } else {
                         $this->logger->logInfo("Didn't find " . $string . " in " . $post->post_text, __METHOD__ . ',' . __LINE__);
                     }
                 }
             }
             if ($matched) {
                 $this->logger->logInfo("Matched post " . $post->post_text, __METHOD__ . ',' . __LINE__);
                 $matched_posts[] = $post;
             }
             $matched = false;
         }
         if (count($matched_posts) > 0) {
             if ($instance->network == 'facebook') {
                 $headline = $this->username . " had enough pride for all 50 states";
                 $insight_text = $this->username . ' joined the <a href="https://facebook.com/celebratepride">marriage equality celebration</a> ' . 'this week!';
             } else {
                 $headline = $this->username . " joined the #LoveWins celebration";
                 $insight_text = $this->username . ' was all about <a href="https://twitter.com/hashtag/LoveWins">marriage equality</a> ' . 'this week.';
             }
             $insight = new Insight();
             $insight->instance_id = $instance->id;
             $insight->slug = $this->slug;
             $insight->date = date("Y-m-d");
             $insight->headline = $headline;
             $insight->text = $insight_text;
             $insight->filename = basename(__FILE__, ".php");
             $insight->emphasis = Insight::EMPHASIS_HIGH;
             $insight->setHeroImage($hero_image);
             $matched_posts_sliced = array_slice($matched_posts, 0, 5);
             $insight->setPosts($matched_posts_sliced);
             $this->insight_dao->insertInsight($insight);
         }
     }
     $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
 }
开发者ID:ngugijames,项目名称:ThinkUp,代码行数:53,代码来源:lovewins.php

示例4: generateInsight

 public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days)
 {
     if (Utils::isTest() || date("Y-m-d") == '2014-02-23') {
         parent::generateInsight($instance, $user, $last_week_of_posts, $number_days);
         $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
         $hero_image = array('url' => 'https://www.thinkup.com/assets/images/insights/2014-02/olympics2014.jpg', 'alt_text' => 'The Olympic rings in Sochi', 'credit' => 'Photo: Atos International', 'img_link' => 'http://www.flickr.com/photos/atosorigin/12568057033/');
         $post_dao = DAOFactory::getDAO('PostDAO');
         $last_month_of_posts = $post_dao->getAllPostsByUsernameOrderedBy($instance->network_username, $network = $instance->network, $count = 0, $order_by = "pub_date", $in_last_x_days = 30, $iterator = false, $is_public = false);
         if (self::shouldGenerateWeeklyInsight('olympics_2014', $instance, $insight_date = 'today', $regenerate_existing_insight = true, $day_of_week = 0, count($last_month_of_posts))) {
             $event_count = 0;
             foreach ($last_month_of_posts as $post) {
                 $event_count += self::countOlympicReferences($post->post_text);
             }
             $this->logger->logInfo("There are {$event_count} Olympic-related mentions", __METHOD__ . ',' . __LINE__);
             if ($event_count > 0) {
                 $headline = "Do they give out medals for " . $this->terms->getNoun('post', InsightTerms::PLURAL) . "?";
                 $insight_text = "{$this->username} mentioned ";
                 if ($event_count > 0) {
                     $this->logger->logInfo("There are event mentions", __METHOD__ . ',' . __LINE__);
                     $insight_text .= "the Olympics ";
                     if ($event_count > 1) {
                         $this->logger->logInfo("there is more than one event mention", __METHOD__ . ',' . __LINE__);
                         $insight_text .= "{$event_count} times since they started.";
                         $insight_text .= " That's kind of like winning {$event_count} gold medals in " . ucfirst($instance->network) . ", right?";
                     } else {
                         $insight_text .= "just as the whole world's attention was focused on the Games.";
                         $insight_text .= " That's a pretty great way to join a global conversation.";
                     }
                 }
                 $my_insight = new Insight();
                 $my_insight->slug = 'olympics_2014';
                 //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->headline = $headline;
                 // or just set a string like 'Ohai';
                 $my_insight->text = $insight_text;
                 // or just set a strong like "Greetings humans";
                 $my_insight->filename = basename(__FILE__, ".php");
                 //Same for every insight, must be set this way
                 $my_insight->emphasis = Insight::EMPHASIS_HIGH;
                 //Optional emphasis, default is Insight::EMPHASIS_LOW
                 $my_insight->setHeroImage($hero_image);
                 $this->insight_dao->insertInsight($my_insight);
             }
         }
         $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
     }
 }
开发者ID:ngugijames,项目名称:ThinkUp,代码行数:50,代码来源:olympics2014.php

示例5: generateInsight

 public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days)
 {
     if (Utils::isTest() || date("Y-m-d") == $this->run_date) {
         parent::generateInsight($instance, $user, $last_week_of_posts, $number_days);
         $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
         $hero_image = array('url' => 'https://www.thinkup.com/assets/images/insights/2015-02/llama.jpg', 'alt_text' => 'Llama', 'credit' => 'Photo: Eric Kilby', 'img_link' => 'https://www.flickr.com/photos/ekilby/8564867495/');
         $should_generate_insight = self::shouldGenerateWeeklyInsight($this->slug, $instance, $insight_date = $this->run_date, $regenerate_existing_insight = false, $day_of_week = 5, count($last_week_of_posts));
         if ($should_generate_insight) {
             $this->logger->logInfo("Should generate", __METHOD__ . ',' . __LINE__);
             $post_dao = DAOFactory::getDAO('PostDAO');
             $topics = array('llama' => array("llama", "llamas"));
             $matches = array();
             foreach ($last_week_of_posts as $post) {
                 foreach ($topics as $key => $strings) {
                     foreach ($strings as $string) {
                         if (preg_match_all('/\\b' . $string . '\\b/i', $post->post_text) > 0) {
                             $matches[$key] = array('term' => $string, 'post' => $post);
                             unset($topics[$key]);
                             break;
                         }
                     }
                 }
             }
             if (count($matches) == 0) {
                 $headline = $this->username . ' managed to avoid llamageddon!';
                 $insight_text = "It seems like half the internet was " . "<a href='http://www.theverge.com/2015/2/26/8116693/live-the-internet-is-going-bananas-" . "for-this-llama-chase'>talking about runaway llamas</a> " . 'yesterday. Kudos to ' . $this->username . ' for showing a llama restraint.';
             } else {
                 $headline = $this->username . " showed a whole llama love";
                 $insight_text = "Two runaway llamas <a href='http://www.theverge.com/2015/2/26/8116693/live-" . "the-internet-is-going-bananas-for-this-llama-chase'>took over Twitter yesterday</a>" . ", and like a llama people, " . $this->username . " couldn't resist.";
             }
             $insight = new Insight();
             $insight->instance_id = $instance->id;
             $insight->slug = $this->slug;
             $insight->date = $this->run_date;
             $insight->headline = $headline;
             $insight->text = $insight_text;
             $insight->filename = basename(__FILE__, ".php");
             $insight->emphasis = Insight::EMPHASIS_HIGH;
             $insight->setHeroImage($hero_image);
             $this->insight_dao->insertInsight($insight);
         }
         $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
     }
 }
开发者ID:pepeleproso,项目名称:ThinkUp,代码行数:44,代码来源:llamas.php

示例6: testInsightRelatedDataSetters

 public function testInsightRelatedDataSetters()
 {
     $i = new Insight();
     // @TODO Assign and assert that the data is in the array structure it should be
     $i->setPhotos("this is my list of photos");
     $this->assertEqual($i->related_data["photos"], "this is my list of photos");
     $i->setPosts("my posts");
     $this->assertEqual($i->related_data["posts"], "my posts");
     $i->setLineChart("line chart data goes here");
     $this->assertEqual($i->related_data["line_chart"], "line chart data goes here");
     $i->setBarChart("bar chart data goes here");
     $this->assertEqual($i->related_data["bar_chart"], "bar chart data goes here");
     $i->setPeople("list 'o users");
     $this->assertEqual($i->related_data["people"], "list 'o users");
     $i->setLinks("listoflinks");
     $this->assertEqual($i->related_data["links"], "listoflinks");
     $i->setMilestones("milestones");
     $this->assertEqual($i->related_data["milestones"], "milestones");
     $i->setButton("button");
     $this->assertEqual($i->related_data["button"], "button");
     $i->setHeroImage("Hero Image");
     $this->assertEqual($i->related_data["hero_image"], "Hero Image");
 }
开发者ID:ngugijames,项目名称:ThinkUp,代码行数:23,代码来源:TestOfInsight.php

示例7: runInsightForConfig

 private function runInsightForConfig($config, $instance)
 {
     $regex = '/\\b(' . join('|', array_map('preg_quote', $config['words'])) . ')\\b/i';
     $usage = array_fill_keys(array_map('strtolower', $config['words']), 0);
     $post_dao = DAOFactory::getDAO('PostDAO');
     $posts = $post_dao->getAllPostsByUsernameIterator($instance->network_username, $instance->network);
     $first_date = time();
     foreach ($posts as $post) {
         if (preg_match_all($regex, $post->post_text, $matches)) {
             foreach ($matches[1] as $match) {
                 $usage[strtolower($match)]++;
             }
             if (strtotime($post->pub_date) < $first_date) {
                 $first_date = strtotime($post->pub_date);
             }
         }
     }
     $usage = array_filter($usage);
     if (count($usage)) {
         $formatted_usage = array();
         foreach ($usage as $word => $times) {
             foreach ($config['words'] as $formatted_word) {
                 if (strtolower($formatted_word) == $word) {
                     $formatted_usage[$formatted_word] = $times;
                     break;
                 }
             }
         }
         arsort($formatted_usage);
         $insight = new Insight();
         $insight->slug = 'new_dictionary_words';
         $insight->instance_id = $instance->id;
         $insight->date = $this->insight_date;
         $insight->filename = basename(__FILE__, ".php");
         $insight->emphasis = Insight::EMPHASIS_MED;
         if (!empty($config['hero_image'])) {
             $insight->setHeroImage($config['hero_image']);
         }
         if (count($formatted_usage) == 1) {
             $words = array_keys($formatted_usage);
             $template = $config['single_template'];
             $params = array('first_mention' => date('F Y', $first_date), 'word' => $words[0], 'total_times' => $this->terms->getOccurrencesAdverb($formatted_usage[$words[0]]));
         } else {
             $formatted_usage = array_slice($formatted_usage, 0, 5, true);
             $words = array_keys($formatted_usage);
             $template = $config['multiple_template'];
             $params = array('first_mention' => date('F Y', $first_date));
             $times = array();
             $quoted_words = array();
             foreach ($formatted_usage as $word => $t) {
                 $times[] = '"' . $word . '" ' . $this->terms->getOccurrencesAdverb($t);
                 $quoted_words[] = '"' . $word . '"';
             }
             $last = count($times) - 1;
             $times[$last] = 'and ' . $times[$last];
             $quoted_words[$last] = 'and ' . $quoted_words[$last];
             $sep = count($times) == 2 ? ' ' : ', ';
             $params['word_times_list'] = join($sep, $times);
             $params['word_list'] = join($sep, $quoted_words);
         }
         $insight->text = $this->getVariableCopy(array($template), $params);
         $insight->headline = $this->getVariableCopy(array($config['headline']), array('word' => $words[0]));
         $this->insight_dao->insertInsight($insight);
     }
     return array_sum($usage);
 }
开发者ID:ngugijames,项目名称:ThinkUp,代码行数:66,代码来源:newdictionarywords.php

示例8: generateInsight

 public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days)
 {
     parent::generateInsight($instance, $user, $last_week_of_posts, $number_days);
     $thanksgiving_day = date('m/j', strtotime("3 weeks thursday", mktime(0, 0, 0, 11, 1, date('Y'))));
     $regenerate = false;
     //test
     // $thanksgiving_day = date('11/20');
     // $regenerate = true;
     if (!$this->shouldGenerateAnnualInsight($this->slug, $instance, 'today', $regenerate, $thanksgiving_day, null, array('instagram'))) {
         $this->logger->logInfo("Skipped generating insight on " . $instance->network, __METHOD__ . ',' . __LINE__);
         return;
     }
     $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
     $user_dao = DAOFactory::getDAO('UserDAO');
     $post_dao = DAOFactory::getDAO('PostDAO');
     $post_iterator = $post_dao->getThisYearOfPostsIterator($instance->network_user_id, $instance->network);
     $thankees = array();
     $thankees_totals = array();
     foreach ($post_iterator as $post) {
         $in_reply_id = $post->in_reply_to_user_id;
         if ($in_reply_id == 0 || $in_reply_id == $instance->network_user_id) {
             // No self thanks, untargeted thanks, or rethanking
             continue;
         }
         $text = strtolower($post->post_text);
         $has_thanks = preg_match('/(\\W|^)(thanks|thank you)(\\W|$)/', $text);
         if ($has_thanks) {
             if (preg_match('/(\\W|^)no (thanks|thank you)/', $text) || preg_match('/thank(s| you),? but/', $text)) {
                 $has_thanks = false;
             }
         }
         if (!$has_thanks) {
             continue;
         }
         if (isset($thankees_totals[$in_reply_id])) {
             $thankees_totals[$in_reply_id] = $thankees_totals[$in_reply_id] + 1;
         } else {
             $thankees_totals[$in_reply_id] = 0;
         }
     }
     arsort($thankees_totals, SORT_NUMERIC);
     foreach ($thankees_totals as $user_id => $count) {
         $user = $user_dao->getDetails($user_id, $instance->network);
         if ($user) {
             $thankees[] = $user;
         }
     }
     if (count($thankees) > 1) {
         $this->logger->logInfo("More than one thankee", __METHOD__ . ',' . __LINE__);
         $insight = new Insight();
         $insight->slug = $this->slug;
         $insight->instance_id = $instance->id;
         $insight->date = $this->insight_date;
         if ($instance->network == 'facebook') {
             $insight->headline = $this->username . ' had friends to be thankful for in ' . date('Y');
             $insight->text = "These are the friends " . $this->username . " was thankful for this year.";
             $insight->setHeroImage(array('url' => 'https://www.thinkup.com/assets/images/insights/2014-11/thanksgiving-2.jpg', 'alt_text' => $insight->headline, 'credit' => 'Photo: John-Morgan', 'img_link' => 'https://www.flickr.com/photos/aidanmorgan/4135626581/'));
         } else {
             $insight->headline = 'Who ' . $this->username . " was thankful for in " . date('Y');
             if (count($thankees) > 20) {
                 $insight->text = "These are just some of the <strong>" . count($thankees) . " people</strong> " . $this->username . " thanked this year.";
             } else {
                 $insight->text = "These are all the people " . $this->username . " thanked this year.";
             }
             $insight->setHeroImage(array('url' => 'https://www.thinkup.com/assets/images/insights/2014-11/thanksgiving-1.jpg', 'alt_text' => $insight->headline, 'credit' => 'Photo: Steve Voght', 'img_link' => 'https://www.flickr.com/photos/voght/2441818832/'));
         }
         $insight->filename = basename(__FILE__, ".php");
         $insight->emphasis = Insight::EMPHASIS_HIGH;
         $this->logger->logInfo("About to setPeople, total is " . count($thankees), __METHOD__ . ',' . __LINE__);
         $thankees_sliced = array_slice($thankees, 0, 20);
         $insight->setPeople($thankees_sliced);
         $this->insight_dao->insertInsight($insight);
     }
     $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
 }
开发者ID:pepeleproso,项目名称:ThinkUp,代码行数:75,代码来源:thanksgivingwhoyouthanked.php

示例9: generateForPeriod

 /**
  * For a given set of posts and named period, possible generate an insight
  * @param $instance Instance The instance we are working with
  * @param $posts arr Posts from the current period
  * @param $old_posts arr Posts from the previous period
  * @param $period str Name of the period, ie. week or month
  */
 private function generateForPeriod($instance, $posts, $old_posts, $period)
 {
     $top_words = $this->getWordsFromPosts($posts);
     $old_words = $this->getWordsFromPosts($old_posts);
     $total_top_words = count($top_words);
     if ($total_top_words == 0) {
         return;
     }
     foreach ($top_words as $key => $word) {
         $top_words[$key] = '&#8220;' . $word;
     }
     $text = $this->username . " said the word <b>" . $top_words[0] . "&#8221;</b> more than any other on " . ucfirst($instance->network) . " last {$period}";
     array_shift($top_words);
     $num_words = count($top_words);
     if ($num_words == 1) {
         $text .= ", followed by " . $top_words[0] . ".&#8221;";
     } else {
         if ($num_words == 2) {
             $top_words[$num_words - 1] = '&#8221; and ' . $top_words[$num_words - 1];
             $text .= ", followed by " . join($num_words > 2 ? ",&#8221; " : "", $top_words) . ".&#8221;";
         } else {
             if ($num_words > 2) {
                 $top_words[$num_words - 1] = ' and ' . $top_words[$num_words - 1];
                 $text .= ", followed by " . join($num_words > 2 ? ",&#8221; " : "", $top_words) . ".&#8221;";
             } else {
                 $text .= '.';
             }
         }
     }
     if (count($old_words)) {
         foreach ($old_words as $key => $word) {
             $old_words[$key] = '&#8220;' . $word;
         }
         $text .= " That's compared to the {$period} before, when " . $this->username . "'s most-used word" . (count($old_words) == 1 ? " was" : "s were") . " ";
         $num_words = count($old_words);
         if ($num_words == 1) {
             $text .= $old_words[0] . ".&#8221;";
         } else {
             if ($num_words == 2) {
                 $old_words[$num_words - 1] = '&#8221; and ' . $old_words[$num_words - 1];
                 $text .= join($num_words > 2 ? ",&#8221; " : "", $old_words) . ".&#8221;";
             } else {
                 $old_words[$num_words - 1] = 'and ' . $old_words[$num_words - 1];
                 $text .= join($num_words > 2 ? ",&#8221; " : " ", $old_words) . ".&#8221;";
             }
         }
     }
     $insight = new Insight();
     $insight->slug = 'top_words_' . $period;
     $insight->instance_id = $instance->id;
     $insight->date = $this->insight_date;
     $insight->headline = $this->username . "'s most-used word" . ($total_top_words == 1 ? '' : 's') . " last {$period}";
     $insight->text = $text;
     $insight->emphasis = $period == 'week' ? Insight::EMPHASIS_MED : Insight::EMPHASIS_HIGH;
     $insight->filename = basename(__FILE__, ".php");
     if ($period == 'month') {
         $hero_image = array('url' => 'https://www.thinkup.com/assets/images/insights/2014-11/topwords.jpg', 'alt_text' => 'Top words', 'credit' => 'Photo: Steve Johnson', 'img_link' => 'https://www.flickr.com/photos/artbystevejohnson/4654424717');
         $insight->setHeroImage($hero_image);
     }
     $this->insight_dao->insertInsight($insight);
 }
开发者ID:pepeleproso,项目名称:ThinkUp,代码行数:68,代码来源:topwords.php

示例10: generateInsight

 public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days)
 {
     parent::generateInsight($instance, $user, $last_week_of_posts, $number_days);
     $thanksgiving_day = date('m/j', strtotime("3 weeks thursday", mktime(0, 0, 0, 11, 1, date('Y'))));
     //test
     //$thanksgiving_day = date('11/21');
     if (!$this->shouldGenerateAnnualInsight($this->slug, $instance, 'today', false, $thanksgiving_day)) {
         $this->logger->logInfo("Skipped generating insight", __METHOD__ . ',' . __LINE__);
         return;
     }
     $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
     $user_dao = DAOFactory::getDAO('UserDAO');
     $post_dao = DAOFactory::getDAO('PostDAO');
     $iterator = $post_dao->getAllRepliesInRange($instance->network_user_id, $instance->network, $count = 0, $from = date('Y-m-d', strtotime('January 1')), $until = date('Y-m-d'), $page = 1, $order_by = 'pub_date', $direction = 'DESC', $is_public = false, $iterator = true);
     $thankees = array();
     $seen = array();
     foreach ($iterator as $post) {
         $author_id = $post->author_user_id;
         if ($author_id == $instance->network_user_id || in_array($author_id, $seen)) {
             // Skip ourselves or people we've seen.
             continue;
         }
         $text = strtolower($post->post_text);
         $has_thanks = preg_match('/(\\W|^)(thanks|thank you)(\\W|$)/', $text);
         if ($has_thanks) {
             if (preg_match('/(\\W|^)no (thanks|thank you)/', $text) || preg_match('/thank(s| you),? but/', $text)) {
                 $has_thanks = false;
             }
         }
         if (!$has_thanks) {
             continue;
         }
         $seen[] = $author_id;
         $user = $user_dao->getDetails($author_id, $instance->network);
         if ($user) {
             $thankees[] = $user;
         }
     }
     $thankees_totals = array();
     foreach ($post_iterator as $post) {
         $author_id = $post->author_user_id;
         if ($author_id == $instance->network_user_id) {
             // Skip ourselves
             continue;
         }
         $text = strtolower($post->post_text);
         $has_thanks = preg_match('/(\\W|^)(thanks|thank you)(\\W|$)/', $text);
         if ($has_thanks) {
             if (preg_match('/(\\W|^)no (thanks|thank you)/', $text) || preg_match('/thank(s| you),? but/', $text)) {
                 $has_thanks = false;
             }
         }
         if (!$has_thanks) {
             continue;
         }
         if (isset($thankees_totals[$author_id])) {
             $thankees_totals[$author_id] = $thankees_totals[$author_id] + 1;
         } else {
             $thankees_totals[$author_id] = 0;
         }
     }
     arsort($thankees_totals, SORT_NUMERIC);
     foreach ($thankees_totals as $user_id => $count) {
         $user = $user_dao->getDetails($user_id, $instance->network);
         if ($user) {
             $thankees[] = $user;
         }
     }
     if (count($thankees) > 1) {
         $num = count($thankees);
         $insight = new Insight();
         $insight->slug = $this->slug;
         $insight->instance_id = $instance->id;
         $insight->date = $this->insight_date;
         if ($instance->network == 'facebook') {
             $insight->headline = $num . " Facebook friends were thankful for " . $this->username;
             $insight->text = "It's great to have friends who share the love. These {$num} people were thankful for " . $this->username . " over the past year.";
             $insight->setHeroImage(array('url' => 'https://www.thinkup.com/assets/images/insights/2014-11/thanksgiving-3.jpg', 'alt_text' => '', 'credit' => 'Photo: paul bica', 'img_link' => 'https://www.flickr.com/photos/dexxus/2981387336/'));
         } else {
             $insight->headline = $num . " people were thankful for " . $this->username;
             if (count($thankees) > 20) {
                 $insight->text = "These are just some of the people who shared an appreciation for " . $this->username . " this year.";
             } else {
                 $insight->text = "These are all the people who shared an appreciation for " . $this->username . " this year.";
             }
             $insight->text = $insight->text . " Who says you can't build meaningful relationships on Twitter?";
             $insight->setHeroImage(array('url' => 'https://www.thinkup.com/assets/images/insights/2014-11/thanksgiving-4.jpg', 'alt_text' => '', 'credit' => 'Photo: David Joyce', 'img_link' => 'https://www.flickr.com/photos/deapeajay/3024604627/'));
         }
         $insight->filename = basename(__FILE__, ".php");
         $insight->emphasis = Insight::EMPHASIS_HIGH;
         $thankees_sliced = array_slice($thankees, 0, 20);
         $insight->setPeople($thankees_sliced);
         $this->insight_dao->insertInsight($insight);
     }
     $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
 }
开发者ID:Nitin216,项目名称:ThinkUp,代码行数:96,代码来源:thanksgivingwhothankedyou.php

示例11: generateMonthlyInsight

 private function generateMonthlyInsight($instance, $posts)
 {
     $located_posts = 0;
     $geo_data = array();
     foreach ($posts as $p) {
         if ($this->isPreciselyLocated($p)) {
             $geo_data[] = $p->geo;
             $located_posts++;
         }
     }
     if ($located_posts < 1) {
         return;
     }
     $insight = new Insight();
     $insight->slug = $this->slug;
     $insight->instance_id = $instance->id;
     $insight->date = $this->insight_date;
     $insight->related_data = array('map_points' => array_unique($geo_data));
     $insight->headline = $this->getHeadline($located_posts, 'month');
     $insight->text = $this->getText('month', $located_posts);
     $insight->emphasis = Insight::EMPHASIS_HIGH;
     $insight->setHeroImage($this->getHeroImage());
     $button = $this->getButton($instance);
     if ($button) {
         $insight->setButton($button);
     }
     $insight->filename = basename(__FILE__, ".php");
     $this->insight_dao->insertInsight($insight);
 }
开发者ID:ngugijames,项目名称:ThinkUp,代码行数:29,代码来源:locationawareness.php

示例12: generateInsight

 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__);
     if (Utils::isTest() || date("Y-m-d") == $this->run_date) {
         $this->logger->logInfo("Should generate insight", __METHOD__ . ',' . __LINE__);
         $hero_image = array('url' => 'https://www.thinkup.com/assets/images/insights/2015-05/starwars.jpg', 'alt_text' => 'RockTrooper', 'credit' => 'Photo: JD Hancock', 'img_link' => 'https://www.flickr.com/photos/jdhancock/4932301604');
         $post_dao = DAOFactory::getDAO('PostDAO');
         $last_year_of_posts = $post_dao->getPostsByUserInRange($author_id = $instance->network_user_id, $network = $instance->network, $from = date('Y-m-d', strtotime('-1 year')), $until = date('Y-m-d'), $order_by = 'pub_date', $direction = 'DESC', $iterator = true, $is_public = false);
         $topics = array('force' => array("star wars", "force awakens", "bb-8", "darth vader", "bb8", "StarWars", "StarWarsDay"));
         $matches = array();
         $matched_posts = array();
         $matched = false;
         //print_r($last_year_of_posts);
         foreach ($last_year_of_posts as $post) {
             foreach ($topics as $key => $strings) {
                 foreach ($strings as $string) {
                     if (preg_match_all('/\\b' . strtolower($string) . '\\b/i', strtolower($post->post_text), $matches)) {
                         $matched = true;
                     }
                     //DEBUG
                     // else {
                     //     $this->logger->logInfo("Didn't find ".$string." in ".$post->post_text,
                     //         __METHOD__.','.__LINE__);
                     // }
                 }
             }
             if ($matched) {
                 $this->logger->logInfo("Matched post " . $post->post_text, __METHOD__ . ',' . __LINE__);
                 $matched_posts[] = $post;
             }
             $matched = false;
         }
         if (count($matched_posts) > 0) {
             $headline = "The Force is strong with " . $this->username . " on #StarWarsDay";
             $insight_text = $this->username . " was ready for Star Wars Day. May the fourth be with you... always.";
             $insight = new Insight();
             $insight->instance_id = $instance->id;
             $insight->slug = $this->slug;
             $insight->date = $this->run_date;
             $insight->headline = $headline;
             $insight->text = $insight_text;
             $insight->filename = basename(__FILE__, ".php");
             $insight->emphasis = Insight::EMPHASIS_HIGH;
             $insight->setHeroImage($hero_image);
             $matched_posts_sliced = array_slice($matched_posts, 0, 20);
             $insight->setPosts($matched_posts_sliced);
             $this->insight_dao->insertInsight($insight);
         }
     }
     $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
 }
开发者ID:ngugijames,项目名称:ThinkUp,代码行数:52,代码来源:maythefourth.php


注:本文中的Insight::setHeroImage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。