function search($search, $language = 'en', $rpp = '10') { $return = array(); $item = array(); $feedUrl = "http://search.twitter.com/search.atom?q=" . urlencode($search) . "&lang={$language}&rpp={$rpp}"; libxml_use_internal_errors(true); $sxml = simplexml_load_file($feedUrl); if ($sxml && !empty($sxml->entry)) { foreach ($sxml->entry as $node) { $attrs_0 = $node->link[0]->attributes(); $attrs_1 = $node->link[1]->attributes(); $datePublished = strtotime($node->published); $author = explode(' ', $node->author[0]->name); $content = htmlentities($node->content); $item["id"] = $attrs_0['href']; $item["published"] = date("Y-m-d H:i:s", $datePublished); $item["content"] = $node->title; $item["thumbnail"] = $attrs_1['href']; $item["title"] = $node->title; $item["author"] = $node->author[0]->name; $item["rating"] = calculateDatarowRating(formatTag($search), $node->title, $author[0]); $return[] = $item; } } else { $this->log('Unable to parse twitter XML.'); } return $return; }
protected function _after_find(&$resultSet, $options) { $resultSet['tags_zh'] = $this->_aBaseOptions['tags'][$resultSet['tags']]; $resultSet['focus_img'] = getFileUrl($resultSet['pic']); $resultSet['tag_zh'] = formatTag($resultSet['tags']); switch ($resultSet['type']) { case '1': $resultSet['case'] = D('Case')->where(array('id' => $resultSet['target']))->find(); $resultSet['info'] = $resultSet['case']['info']; $resultSet['designer'] = D('User_designer')->where(array('uid' => $resultSet['case']['uid']))->find(); $resultSet['header'] = $resultSet['designer']['header']; break; case '2': $resultSet['house'] = D('House')->where(array('id' => $resultSet['target']))->find(); $resultSet['info'] = $resultSet['house']['info']; $resultSet['designer'] = D('User_designer')->where(array('uid' => $resultSet['case']['uid']))->find(); $resultSet['header'] = $resultSet['designer']['header']; break; } }
protected function _after_find(&$resultSet, $options) { $resultSet['housetype_zh'] = $this->_aBaseOptions['houseType'][$resultSet['housetype']]; $resultSet['style_zh'] = $this->_aBaseOptions['style'][$resultSet['style']]; $resultSet['authorize_zh'] = $this->_aBaseOptions['authorize'][$resultSet['authorize']]; $resultSet['focus_img'] = getFileUrl($resultSet['focus']); $resultSet['name'] = str_replace("\\'", "'", $resultSet['name']); $user = D('User')->getById($resultSet['uid']); if ($user['type'] == 2) { $designer = D('User_designer')->where(array('uid' => $resultSet['uid']))->find(); $resultSet['user'] = $designer; $resultSet['user']['name_zh'] = $designer['realname'] ? $designer['realname'] : $designer['nickname']; $resultSet['user']['url'] = __GROUP__ . "/Designer/designerDetails/uid/" . $designer['uid']; } else { if ($user['type'] == 3) { $company = D('Company')->where(array('uid' => $resultSet['uid']))->find(); $resultSet['user'] = $company; $resultSet['user']['name_zh'] = $company['name']; $resultSet['user']['url'] = __GROUP__ . "/Company/companyDetails/uid/" . $company['uid']; } } $resultSet['user']['type'] = $user['type']; $resultSet['user']['header'] = getFileUrl($user['avatar']); $resultSet['tag_zh'] = formatTag($resultSet['tags']); $resultSet['is_original_zh'] = $resultSet['is_original'] ? '原创' : '转发'; $resultSet['createtime_zh'] = time_tran($resultSet['createtime']); $resultSet['info_j'] = infoFormat($resultSet['info']); $resultSet['is_collect'] = 0; if (!empty($this->oCollect['case'])) { foreach ($this->oCollect['case'] as $i) { if ($i['target'] == $resultSet['id'] && $i['type'] == 1) { $resultSet['is_collect'] = 1; } } } }
function rows_as_chart($dbrows, $xvaluefield, $yvaluefields, $colors = array(), $formats = array(), $showSeriesLabel = false, $showMetricLabel = false) { $ret = "<table border=0 width=100%>"; $totalmax = getMaxFromAssoc($dbrows, $yvaluefields); $url = ""; if (!empty($dbrows) && is_array($dbrows)) { foreach ($dbrows as $idx => $dbrow) { if (isset($colors[$idx])) { $color = $colors[$idx]; } else { if (isset($colors[0])) { $color = $colors[0]; } else { $color = "#00F"; } } $countrows = 0; $label = ""; foreach ($yvaluefields as $idx => $yvaluefield) { $xvalue = ""; $yvalue = 0; $ret .= "<tr>"; $xtext = ""; if ($idx == 0) { $xformat = "text"; if (isset($formats[$xvaluefield])) { $xformat = $formats[$xvaluefield]; } if (isset($dbrow[strtoupper($xvaluefield)])) { $xvalue = $dbrow[strtoupper($xvaluefield)]; } elseif (isset($dbrow[strtolower($xvaluefield)])) { $xvalue = $dbrow[strtolower($xvaluefield)]; } if ($xvalue != "") { $xtext = $xvalue; $url = getUrlFromString($xvalue); $ret .= "<td style='width:1px;white-space: nowrap;' rowspan='" . count($yvaluefields) . "'>" . $xtext . "</td>"; if ($showSeriesLabel) { $label = iconToText($xvalue); } } } if (!empty($formats) && isset($formats[$yvaluefield])) { $format = $formats[$yvaluefield]; } else { $format = "number"; } if ($format == "percent") { $max = 1; } else { $max = $totalmax; } if (isset($dbrow[strtoupper($yvaluefield)])) { $yvalue = $dbrow[strtoupper($yvaluefield)]; } elseif (isset($dbrow[strtolower($yvaluefield)])) { $yvalue = $dbrow[strtolower($yvaluefield)]; } if ($showMetricLabel) { $label = formatTag($yvaluefield); } if ($xvaluefield != $yvaluefield && isset($yvalue) && is_numeric($yvalue)) { $color = alterColor($color, $countrows, 'dark'); $ret .= "<td>" . $this->value_as_bar($yvalue, $max, $color, $format, $label, $url) . "</td>"; $countrows++; } $ret .= "</tr>"; } } } $ret .= "</table>"; return $ret; }
function formatValue($value, $format = "text", $shorthand = false) { if ($format == "percent") { $ret = formatDecimalAsPercent($value) . "%"; } else { if (is_numeric($value)) { if ($shorthand) { $ret = formatLargeNumberShorthand($value); } else { $ret = number_format($value); } if ($format == "dollars") { $ret = "\$" . $ret; } } else { if ($format == "html") { $ret = $value; } else { $ret = formatTag($value); } } } return $ret; }