public function archiveAction($month, $page = 1, Files $file) { list($startTime, $endTime) = myTools::getBetweenTimes($month); $this->view->page = $this->getPaginatorByQueryBuilder($file->getResultsBetween($startTime, $endTime), 25, $page); $this->view->page->statistics = myParser::getStatistics(); $this->view->page->month = $month; }
public function showArchiveAction($repository, $month, $page = 1) { list($startTime, $endTime) = myTools::getBetweenTimes($month); $builder = $this->modelsManager->createBuilder()->from('Files')->rightJoin(myParser::getModelName($repository), 'sub.file_id = Files.id', 'sub')->where('created_at > :start:', ['start' => $startTime->toDateTimeString()])->andWhere('created_at < :end:', ['end' => $endTime->toDateTimeString()])->orderBy('Files.id DESC')->columns(['Files.*', 'sub.*']); $this->view->page = $this->getPaginatorByQueryBuilder($builder, 25, $page); $this->view->page->month = $month; $this->view->page->repository = myParser::getModelBySourceId($repository); }
public function execute(&$value, &$error) { $slug = myTools::stripText($value); $event_id_param = $this->getParameter('event_id'); $event_id = $this->getContext()->getRequest()->getParameter($event_id_param); $c = new Criteria(); $c->add(EventPeer::SLUG, $slug); $event_slug = EventPeer::doSelectOne($c); if ($event_slug && $event_slug->getId() != $event_id) { $error = $this->getParameter('slug_error'); return false; } return true; }
public function getHtml($key) { if (null == $this->{$key}) { return null; } if ($key == 'abstract' or $key == 'Abstract') { if ($this->{$key} == null) { return null; } $maxLength = 200; //最大显示长度 if (mb_strlen($this->{$key}) > $maxLength) { return '<div class="abstract" style="display: block;">' . '<pre>' . myTools::cut($this->{$key}, $maxLength) . ' <a href="#" id="expand">展开</a></pre>' . '</div><div class="abstract" style="display: none;">' . '<pre>' . $this->{$key} . ' <a href="#" id="collaps">收起</a></pre></div>'; } return '<pre>' . myTools::cut($this->{$key}, $maxLength) . '</pre>'; } if ($key == 'Subject_Categories') { $result = ''; foreach (preg_split('/<br>\\s*/m', $this->{$key}) as $category) { $result .= '<span>' . trim($category) . '</span>'; } return $result; } if ($key == 'keywords') { $delimiter = ' '; if (static::class == 'Baiduxueshu') { $delimiter = '/'; } $result = []; $words = explode($delimiter, $this->{$key}); foreach ($words as $word) { $word = trim($word); $result[] = '<span><a class="btn-link" href="http://standard.zhaobing/search/' . $word . '">' . $word . '</a></span>'; } return implode(' ', $result); } if ($key == 'Descriptors') { $result = ''; $words = explode(',', $this->{$key}); foreach ($words as $word) { $word = preg_replace('|^.+\\*|', '', $word); $result .= '<span><a href="http://standard.zhaobing/search/' . $word . '">' . $word . '</a></span> '; } return $result; } return $this->{$key}; }
public static function stemPhrase($phrase) { // split into words $words = str_word_count(strtolower($phrase), 1); // ignore stop words $words = myTools::removeStopWordsFromArray($words); // stem words $stemmed_words = array(); foreach ($words as $word) { // ignore 1 and 2 letter words if (strlen($word) <= 2) { continue; } // stem word (stemming is specific for each language) $stemmed_words[] = PorterStemmer::stem($word, true); } return $stemmed_words; }
function list_people($object, $method, $type, $obj_type, $outside = false) { $list = ""; $people = call_user_func(array($object, $method)); $list .= "<ul>\n"; foreach ($people as $person) { if (strtolower($person->getPersonType()->getName()) == strtolower($type)) { $list .= "<li>\n"; $list .= $person->getName(); $list .= " " . $person->getEmail(); $list .= " " . $person->getPhone(); if (!$outside) { $list .= " " . link_to_remote(image_tag('delete', array('alt' => 'delete')), array('url' => $obj_type . '/deletePerson?id=' . $person->getId(), 'update' => array('success' => $obj_type . '_' . myTools::stripText($type)))); } $list .= "</li>\n"; } } $list .= "</ul>\n"; return $list; }
public function uploadAndStoreAttachment(\Phalcon\Http\Request $request) { $user = \Phalcon\Di::getDefault()->get('auth'); /** @var myModel $this */ foreach ($request->getUploadedFiles() as $f) { $data = []; $data['name'] = $f->getName(); $data['url'] = myTools::storeAttachment($f); $data['user_id'] = $user->id; $data['attachable_id'] = $this->id; $data['attachable_type'] = get_class($this); (new Attachments())->save($data); $this->increaseCount('attachmentCount'); } if (is_a($this, 'Tags')) { $meta = $this->getTagmetaOrNew(); $meta->save(); } return $this; }
public function getMediaPotentialString() { return myTools::yesNo($this->getMediaPotential()); }
public function getTaggedFilesByMonth($month) { return $this->make('files', function () use($month) { list($startTime, $endTime) = myTools::getBetweenTimes($month); $user = \Phalcon\Di::getDefault()->get('auth'); return Files::query()->rightJoin('Taggables', 'Taggables.taggable_id = Files.id AND Taggables.taggable_type="Files"')->where('Taggables.tag_id = :tag:', ['tag' => $this->id])->andWhere('Taggables.created_at > :start:', ['start' => $startTime->toDateTimeString()])->andWhere('Taggables.created_at < :end:', ['end' => $endTime->toDateTimeString()])->andWhere('Taggables.user_id = :user:'******'user' => $user->id])->columns(['Files.*', 'Taggables.*'])->groupBy('Files.id')->orderBy('Taggables.created_at DESC')->execute(); }); }
public function getAttendingString() { return myTools::yesNo($this->getAttending()); }
public static function search($phrase, $exact = false, $offset = 0, $max = 10) { $words = array_values(myTools::stemPhrase($phrase)); $nb_words = count($words); if (!$words) { return array(); } $con = Propel::getConnection(); $query = ' SELECT DISTINCT %s, COUNT(*) AS nb, SUM(%s) AS total_weight FROM %s '; if (sfConfig::get('app_permanent_tag')) { $query .= sprintf(' LEFT JOIN %s ON %s = %s WHERE %s = ? AND ', QuestionTagPeer::TABLE_NAME, QuestionTagPeer::QUESTION_ID, SearchIndexPeer::QUESTION_ID, QuestionTagPeer::NORMALIZED_TAG); } else { $query .= 'WHERE'; } $query .= ' (' . implode(' OR ', array_fill(0, $nb_words, SearchIndexPeer::WORD . ' = ?')) . ') GROUP BY %s '; // AND query? if ($exact) { $query .= ' HAVING nb = ' . $nb_words; } $query .= ' ORDER BY nb DESC, total_weight DESC'; $query = sprintf($query, SearchIndexPeer::QUESTION_ID, SearchIndexPeer::WEIGHT, SearchIndexPeer::TABLE_NAME, SearchIndexPeer::QUESTION_ID); $stmt = $con->prepareStatement($query); $stmt->setOffset($offset); $stmt->setLimit($max); $placeholder_offset = 1; if (sfConfig::get('app_permanent_tag')) { $stmt->setString(1, sfConfig::get('app_permanent_tag')); $placeholder_offset = 2; } for ($i = 0; $i < $nb_words; $i++) { $stmt->setString($i + $placeholder_offset, $words[$i]); } $rs = $stmt->executeQuery(ResultSet::FETCHMODE_NUM); $questions = array(); while ($rs->next()) { $questions[] = self::retrieveByPK($rs->getInt(1)); } return $questions; }
/** * send mail to client * @param Object $sf_guard_user * @param Object $message * @param Object $client_profile */ private function sendMailToClient($sf_guard_user, $message, $client_profile) { $profile = $this->getUser()->getGuardUser()->getProfile(); $set_action = 'Send mail to client'; $client_full_name = $client_profile->getFname() . ' ' . $client_profile->getLname(); $client_mail = $client_profile->getEmail(); $tools = new myTools(); // if user tick checkbox to send the mail if ($client_mail && $tools->isValidEmail($client_mail)) { $category = $message->getCategory(); $msgs_category = new Messages(); $category_change_to_title = $msgs_category->messageCategory($category); sfConfig::set('sf_web_debug', false); $content = get_partial('mail_data', array('profile' => $profile)); $change_to = str_replace('changeto', "{$client_full_name}", $content); $change_from = str_replace('changefrom', $sf_guard_user->getProfile()->getFullname(), $change_to); $change_subject = str_replace('changesbjct', $message->getSubject(), $change_from); $change_cat = str_replace('changecat', $category_change_to_title, $change_subject); $change_body = str_replace('changebody', $message->getBody(), $change_cat); $mailBody = $change_body; // send mail to client $mailclass_obj = new mailSend(); $mailclass_obj->sendMailToUser($mailBody, $client_mail, $set_action); } }
?> </div> <?php echo include_partial('add_person', array('etime_id' => $etime->getId(), 'obj_type' => 'etime', 'type' => 'organiser', 'event_id' => $etime->getEvent()->getId())); ?> </div> <div class="clear_float"></div> <div class="label">Location:</div> <div class="value"><?php print $etime->getLocation(); ?> </div> <div class="clear_float"></div> <div class="label">Date:</div> <div class="value"><?php print myTools::oneDate($etime->getStartDate(), $etime->getEndDate()); ?> </div> <div class="clear_float"></div> <div class="label">Time:</div> <div class="value"><?php print $etime->getStartTime(); ?> - <?php print $etime->getEndTime(); ?> </div> <div class="clear_float"></div> <div class="label">All day:</div> <div class="value"><?php print $etime->getAllDayString();
public function setTitle($v) { parent::setTitle($v); $this->setStrippedTitle(myTools::stripText($v)); }
/** * @todo Should we throw an exception if the config value does not exist? */ public static function getConfigValueFor($input) { $cache = sfConfig::get('app_phpbb_cache', false); if (!$cache) { $configValues = self::getConfigValues(); if (isset($configValues[$input])) { return $configValues[$input]; } } if ($cache) { $cacheKeyNonDynamic = 'config_values'; $cacheKeyDynamic = 'config_values_dynamic'; if (sfProcessCache::has($cacheKeyNonDynamic)) { $configValues = sfProcessCache::get($cacheKeyNonDynamic); } else { $configValues = self::getConfigValues(0); sfProcessCache::set($cacheKeyNonDynamic, $configValues, myTools::getConfig('app_cache_config_non_dynamic', 86400)); } if (isset($configValues[$input])) { return $configValues[$input]; } // Reset config values before we check dynamic config values unset($configValues); if (sfProcessCache::has($cacheKeyDynamic)) { $configValues = sfProcessCache::get($cacheKeyDynamic); } else { $configValues = self::getConfigValues(1); sfProcessCache::set($cacheKeyDynamic, $configValues, myTools::getConfig('app_cache_config_dynamic', 60)); } if (isset($configValues[$input])) { return $configValues[$input]; } } // If we get here, there is no config value for this input. return null; }
public function getHasFeeString() { return myTools::yesNo($this->getHasFee()); }
<?php include dirname(__FILE__) . '/../bootstrap/unit.php'; include dirname(__FILE__) . '/../../lib/myTools.class.php'; $t = new lime_test(4, new lime_output_color()); $t->diag('myTools::yesNo'); $t->isa_ok(myTools::yesNo(true), 'string', 'myTools::yesNo() returns a string of Yes or No'); $t->is(myTools::yesNo(true), "Yes"); $t->is(myTools::yesNo(false), "No"); $t->is(myTools::yesNo(null), "No");
if (count(explode("|", (string) $xml->{"" . $columnName . ""}->displayColumn)) > 1) { $concatDisplay = ""; foreach (explode("|", (string) $xml->{"" . $columnName . ""}->displayColumn) as $columnConcat) { $concatDisplay .= $resultChoices[0][$columnConcat] . " "; } $xmlRetour->text($concatDisplay); } else { if (array_key_exists((string) $xml->{"" . $columnName . ""}->displayColumn, $picturesThumnailColumn)) { $xmlRetour->writeCData("<img src='" . $picturesThumnailColumn[(string) $xml->{"" . $columnName . ""}->displayColumn] . $resultChoices[0][(string) $xml->{"" . $columnName . ""}->displayColumn] . "'/>"); } else { $xmlRetour->text($resultChoices[0][(string) $xml->{"" . $columnName . ""}->displayColumn]); } } } else { if ((string) $xml->{"" . $columnName . ""}->dateField['enabled'] == "true") { $xmlRetour->text(myTools::getDateFromTimeAndCustomFormat($columnValue, $gb->getGlobalInfoForNodeAndTable("global_date_format", $table))); } else { if ((string) $xml->{"" . $columnName . ""}->booleanField['enabled'] == "true") { if ($columnValue == 0) { $xmlRetour->text((string) $xml->{"" . $columnName . ""}->booleanField->boolean_false_label); } if ($columnValue == 1) { $xmlRetour->text((string) $xml->{"" . $columnName . ""}->booleanField->boolean_true_label); } } else { //we return the value $xmlRetour->text($columnValue); } } } }
private function addCommentFile($comment_id, $file) { $ext = pathinfo($file['name'], PATHINFO_EXTENSION); $type = split('/', $file['type']); $type = $type[0]; $data = array('posts_comment_id' => $comment_id, 'file_name' => myTools::generateFileName($ext, $comment_id, null), 'name' => $file['name'], 'type' => $type); $this->PostsCommentsFile->set($data); $this->PostsCommentsFile->save(); }
* 设置dispatch, 类似router binding,将model注入到controller中,替换路由参数 */ $di->set('dispatcher', function () { return include "dispatcher.php"; }, true); /* * 设置redis */ $di->set("redis", function () { return new myRedis(); }, true); $di->set("carbon", function () { return new \Carbon\Carbon(); }, true); $di->set("myTools", function () use($config) { $tools = new myTools(); $tools->setSiteName($config->siteName); return $tools; }, true); /* * 为什么在volt中不能够直接引用呢?奇怪!! * 是因为使用静态调用导致的吗? */ $di->set("allTags", function () { return new Tags(); }, true); /* * 设置Event Manager */ $di->set('Event', function () { return include 'events.php';
/** * method that save a picture before save a element in the database * @param string columnname(fieldname) in the database * @return boolean true if the operation succeded , else false */ private function savePictures($field) { $now = time(); //we define a name for the file $extension = "." . myTools::getExtension($this->arrayFields[$field]["currentValue"]); //we define the extension //we loop on the differents formats foreach ($this->arrayFields[$field]["pictureField"] as $key => $value) { if (!in_array($extension, $value["formats"])) { return false; } //we do the good transformation looking at the xml switch ($value["resizeType"]) { case "resizeHomo": //if the file doesn't exists in a directory, it is not a big deal if (!file_exists("../tmp/" . $this->arrayFields[$field]["currentValue"])) { return true; } $imgHandler = new imgSaver(str_replace(".", "", $extension), "../tmp/" . $this->arrayFields[$field]["currentValue"]); if (!$imgHandler->init() || !$imgHandler->handleImage()) { return false; } $imgHandler->resizeHomo((int) $value["ratio"], "pictureSave"); if (!$imgHandler->saveImg("../" . (string) $value["path"] . $now, "pictureSave")) { return false; } break; case "resizeFix": //if the file doesn't exists in a directory, it is not a big deal if (!file_exists("../tmp/" . $this->arrayFields[$field]["currentValue"])) { return true; } $imgHandler = new imgSaver(str_replace(".", "", $extension), "../tmp/" . $this->arrayFields[$field]["currentValue"]); if (!$imgHandler->init() || !$imgHandler->handleImage()) { return false; } $imgHandler->resizeFix((int) $value["width"], (int) $value["height"], "pictureSave"); if (!$imgHandler->saveImg("../" . (string) $value["path"] . $now, "pictureSave")) { return false; } break; case "resizeHomoW": //if the file doesn't exists in a directory, it is not a big deal if (!file_exists("../tmp/" . $this->arrayFields[$field]["currentValue"])) { return true; } $imgHandler = new imgSaver(str_replace(".", "", $extension), "../tmp/" . $this->arrayFields[$field]["currentValue"]); if (!$imgHandler->init() || !$imgHandler->handleImage()) { return false; } $imgHandler->resizeHomoW((int) $value["width"], "pictureSave"); if (!$imgHandler->saveImg("../" . (string) $value["path"] . $now, "pictureSave")) { return false; } break; case "resizeHomoH": //if the file doesn't exists in a directory, it is not a big deal if (!file_exists("../tmp/" . $this->arrayFields[$field]["currentValue"])) { return true; } $imgHandler = new imgSaver(str_replace(".", "", $extension), "../tmp/" . $this->arrayFields[$field]["currentValue"]); if (!$imgHandler->init() || !$imgHandler->handleImage()) { return false; } $imgHandler->resizeHomoH((int) $value["height"], "pictureSave"); if (!$imgHandler->saveImg("../" . (string) $value["path"] . $now, "pictureSave")) { return false; } break; default: //if the file doesn't exists in a directory, it is not a big deal if (!file_exists("../tmp/" . $this->arrayFields[$field]["currentValue"])) { return true; } $imgHandler = new imgSaver(str_replace(".", "", $extension), "../tmp/" . $this->arrayFields[$field]["currentValue"]); if (!$imgHandler->init() || !$imgHandler->handleImage()) { return false; } $imgHandler->noResize("pictureSave"); if (!$imgHandler->saveImg("../" . (string) $value["path"] . $now, "pictureSave")) { return false; } break; } } $this->arrayFields[$field]["currentValue"] = $now . $extension; return true; }
static function storeAttachment(\Phalcon\Http\Request\File $attachment) { $uploadDir = 'files'; //上传路径的设置 $time = time(); $path = myTools::makePath($uploadDir, $time); $ext = preg_replace('%^.*?(\\.[\\w]+)$%', "\$1", $attachment->getName()); //获取文件的后缀 $url = md5($attachment->getName()); $filename = $path . $time . $url . $ext; $attachment->moveTo($filename); return $filename; }
public function setName($v) { parent::setName(strtoupper(myTools::stripText($v))); }
public function getWords() { // body $raw_text = str_repeat(' ' . strip_tags($this->getHtmlBody()), sfConfig::get('app_search_body_weight')); // title $raw_text .= str_repeat(' ' . $this->getTitle(), sfConfig::get('app_search_title_weight')); // title and body stemming $stemmed_words = myTools::stemPhrase($raw_text); // unique words with weight $words = array_count_values($stemmed_words); // add tags $max = 0; foreach ($this->getPopularTags(20) as $tag => $count) { if (!$max) { $max = $count; } $stemmed_tag = PorterStemmer::stem($tag); if (!isset($words[$stemmed_tag])) { $words[$stemmed_tag] = 0; } $words[$stemmed_tag] += ceil($count / $max * sfConfig::get('app_search_tag_weight')); } return $words; }