/** * xmlをRssに変換する * * @param string $src * @return Rss */ public static function parse($src) { if (Tag::setof($rss, $src, "rss")) { $result = new self(); $result->version($rss->inParam("version", "2.0")); if (Tag::setof($channel, $rss->value(), "channel")) { $result->title($channel->f("title.value()")); $result->link($channel->f("link.value()")); $result->description($channel->f("description.value()")); $result->language($channel->f("language.value()")); $result->copyright($channel->f("copyright.value()")); $result->docs($channel->f("docs.value()")); $result->managingEditor($channel->f("managingEditor.value()")); $result->webMaster($channel->f("webMaster.value()")); $result->lastBuildDate($channel->f("lastBuildDate.value()")); $result->pubDate($channel->f("pubDate.value()")); $value = $channel->value(); $result->item = RssItem::parse($value); return $result; } } throw new Exception("no rss"); /*** $src = text(' <rss version="2.0"> <channel> <title>rhaco</title> <link>http://rhaco.org</link> <description>php</description> <language>ja</language> <copyright>rhaco.org</copyright> <docs>hogehoge</docs> <lastBuildDate>2007-10-10T10:10:10+09:00</lastBuildDate> <managingEditor>tokushima</managingEditor> <pubDate>2007-10-10T10:10:10+09:00</pubDate> <webMaster>kazutaka</webMaster> <item> <title>rhaco</title> <link>http://rhaco.org</link> <description>rhaco desc</description> </item> <item> <title>everes</title> <link>http://www.everes.net</link> <description>everes desc</description> </item> </channel> </rss> '); $xml = Rss::parse($src); eq("2.0",$xml->version()); eq("rhaco",$xml->title()); eq("http://rhaco.org",$xml->link()); eq("php",$xml->description()); eq("ja",$xml->language()); eq("rhaco.org",$xml->copyright()); eq("hogehoge",$xml->docs()); eq(1191978610,$xml->lastBuildDate()); eq("Wed, 10 Oct 2007 10:10:10 +0900",$xml->fmLastBuildDate()); eq("tokushima",$xml->managingEditor()); eq(1191978610,$xml->pubDate()); eq("Wed, 10 Oct 2007 10:10:10 +0900",$xml->fmPubDate()); eq("kazutaka",$xml->webMaster()); eq(2,sizeof($xml->item())); */ }
public static function parse(Tag $entry) { $self = new self(); $self->term($entry->f("category.param(term)")); $self->link($entry->f("link.param(href)")); $self->content($entry->f("content.value()")); $self->updated($entry->f("updated.value()")); $user = new MixiUser(); $user->name($entry->f("author.name.value()")); $user->link($entry->f("author.uri.value()")); $self->author($user); return $self; }
/** * @param int[] $ids * * @return Check */ public static function createByProductIds($ids) { $check = new self(); $check->save(); foreach ($ids as $id) { $product = Product::find()->where(['id' => $id])->one(); if ($product === null) { continue; } $check->link('products', $product); } $check->calculate(); $check->save(); return $check; }
public static function parse(Tag $entry) { $self = new self(); $author = $entry->f("author"); if ($author !== null) { $self->name($author->f("name.value()")); $self->image($author->f("tracks:image.value()")); $self->relation($author->f("tracks:relation.value()")); } else { $self->name($entry->f("title.value()")); $self->image($entry->f("icon.value()")); $self->relation("friends"); } $self->updated($entry->f("updated.value()")); $self->link($entry->f("link.param(href)")); return $self; }
public static function parse($src) { $result = array(); foreach (Tag::anyhow($src)->in("item") as $in) { $o = new self(); $o->title($in->f("title.value()")); $o->link($in->f("link.value()")); $o->description($in->f("description.value()")); $o->author($in->f("author.value()")); $o->category($in->f("category.value()")); $o->comments($in->f("comments.value()")); $o->pubDate($in->f("pubDate.value()")); $o->guid($in->f("guid.value()")); $value = $in->value(); $o->enclosure = RssEnclosure::parse($value); $o->source = RssSource::parse($src); $result[] = $o; } return $result; }
/** * Atomに変換する * * @param string $title * @param string $link * @param iterator $entrys * @return Atom */ public static function convert($title, $link, $entrys) { $atom = new self(); $atom->title($title); $atom->link(new AtomLink("href=" . $link)); foreach ($entrys as $entry) { $atom->add($entry); } return $atom; }
/** * Добавление админом денег пользователю * Возвращает сумму на счёте после проведения операции, * независимо от исхода * * @param int $recipient * @param $money * * @return mixed * * @throws Exception */ public static function giveMoney($recipient, $money) { $transaction = Yii::$app->db->beginTransaction(); $transaction->setIsolationLevel('SERIALIZABLE'); try { Users::addMoney($money, $recipient); $operation = new self(); $operation->sum = $money; $operation->sender = 0; $operation->link('recipient', Users::findOne($recipient)); $transaction->commit(); } catch (OperationException $e) { $transaction->rollback(); return $e->getMessage(); } catch (Exception $e) { $transaction->rollback(); if (YII_DEBUG) { throw $e; } else { return 'Произошла ошибка'; } } return Users::find()->where(['id' => $recipient])->select('sum')->scalar(); }
/** * Generate new token for user * * @param integer $userId * @param integer $expiredSeconds * @return boolean|common\models\UserToken */ public static function createForUser(IdentityInterface $user, $seconds = 0, $remember = false, $verifyIP = false) { $seconds = intval($seconds); if (!$seconds) { $seconds = self::EXPIRE_DEFAULT_SECONDS; } $userToken = new self(['scenario' => self::SCENARIO_CREATE_FOR_USER]); $userToken->token = Yii::$app->getSecurity()->generateRandomString(); $userToken->expired_at = new Expression('DATE_ADD(NOW(), INTERVAL ' . $seconds . ' SECOND)'); $userToken->frozen_expire = !$remember; $userToken->verify_ip = (bool) $verifyIP; $userToken->updateClientInfo(); if ($userToken->save()) { $userToken->link('user', $user); $userToken->refresh(); return $userToken; } else { return false; } }
/** * 生成并缓存路由 * * @param $saveAs * * @return array */ public static function general($saveAs) { static::parse(); if (!static::$parseNewFile && file_exists($saveAs)) { return include $saveAs; } if (file_exists($saveAs)) { unlink($saveAs); } $router = new self('', ''); $routerMap = $router->link(); if (!is_dir(dirname($saveAs))) { mkdir(dirname($saveAs), 0700, true); } //file_put_contents($saveAs, "<?php\nreturn [" . static::serialize($routerMap) . '];'); file_put_contents($saveAs, "<?php\nreturn " . var_export($routerMap, true) . ';'); return $routerMap; }
/** * Atomに変換する * * @param string $title * @param string $link * @param iterator $entrys * @return self */ public static function convert($title, $link, $entrys) { $atom = new self(); $atom->title($title); $atom->link(new \org\rhaco\net\xml\atom\Link('href=' . $link)); foreach ($entrys as $entry) { $atom->add($entry); } return $atom; }