本文整理汇总了PHP中Articles::insert方法的典型用法代码示例。如果您正苦于以下问题:PHP Articles::insert方法的具体用法?PHP Articles::insert怎么用?PHP Articles::insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Articles
的用法示例。
在下文中一共展示了Articles::insert方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionModified
/**
* 提交信息
*/
public function actionModified()
{
$data = $this->Common->getFilter($_POST);
$aid = (int) $data['aid'];
$article = $data['aritcle'];
$content = $data['a_content'];
$Articles = new Articles();
$ArticlesContent = new ArticlesContent();
if ($aid == 0) {
$article['add_date'] = $this->Common->getDate();
$content['aid'] = $Articles->insert($article);
$ArticlesContent->insert($content);
$article['aid'] = $content['aid'];
} else {
$where = array('aid' => $aid);
$Articles->update($article, $where);
$count = $ArticlesContent->getCount('*', $where);
if ($count > 0) {
$ArticlesContent->update($content, $where);
} else {
$content['aid'] = $aid;
$ArticlesContent->insert($content);
}
}
$this->jumpBox('成功!', Wave::app()->homeUrl . 'articles', 1);
}
示例2: parse
function parse($config, $db)
{
$folder = $config["dir"] . $config["scopus_dir"];
if ($config["test"] === true) {
$folder = $config["test_dir"] . $config["scopus_dir"];
}
// Hard set PHP config, used for CSV file line endings
ini_set("auto_detect_line_endings", true);
$scanned_directory = array_diff(scandir($folder), array('..', '.'));
if (!isset($scanned_directory)) {
echo "Warning: no files found in: " . $folder . '<br/>';
return;
}
$articles = array();
foreach ($scanned_directory as $file) {
// Open the file
if (($handle = @fopen($folder . "/" . $file, "r")) === false) {
echo "Warning: file not found at: " . $folder . "/" . $file;
return;
}
while ($line = fgets($handle)) {
// Split csv
$line = str_getcsv($line);
// Check if this is the first line
if ($line[1] === 'Title') {
continue;
}
// Title
$title = $line[1];
// Abstract
$abstract = $line[15];
// Journal-Title
$journal_title = $line[3];
// Journal-ISO
$journal_iso = "";
// ISSN
$issn = "";
// DOI
$doi = "";
$pattern = '/[0-9\\.]+\\/.*/';
preg_match($pattern, $line[11], $match);
if (count($match) > 0) {
$doi = $match[0];
}
// Publication date
$day = "";
$month = "";
$year = $line[2];
array_push($articles, array("title" => $title, "abstract" => $abstract, "doi" => $doi, "journal_title" => $journal_title, "journal_iso" => $journal_iso, "journal_issn" => $issn, "day" => $day, "month" => $month, "year" => $year));
}
fclose($handle);
}
require_once "models/articles.php";
$article_model = new Articles();
foreach ($articles as $article) {
$article_model->insert($db, $article, 'scopus');
}
}
示例3: Articles
<?php
include "Mapper.php";
include "MapperCollection.php";
include "Articles.php";
$map = new Articles("articles");
// Find
echo "Find\n";
$result = $map->find(2);
print_r($result);
// insert
echo "\nInsert\n";
$obj = new stdClass();
$obj->name = "Ny artikel";
$obj->body = "Blah blah yada yada";
$obj->author_id = 2;
$map->insert($obj);
echo "Inserted object:\n";
print_r($obj);
echo "delete\n";
$map->delete($obj);
//update
echo "\nUpdate:\n";
$result->name = "Modified";
$map->update($result);
示例4: parse
//.........这里部分代码省略.........
}
$xml_parser = new XML_parser();
$scanned_directory = array_diff(scandir($folder), array('..', '.'));
if (!isset($scanned_directory)) {
echo "Warning: no files found in: " . $folder . '<br/>';
return;
}
$articles = array();
foreach ($scanned_directory as $file) {
// Open the file
if (($handle = @fopen($folder . "/" . $file, "r")) === false) {
echo "Error: file not found at: " . $folder . "/" . $file;
return;
}
// Get the nodestring incrementally from the xml file by defining a callback
$articles = $xml_parser->nodeStringFromXMLFile($handle, "<article", "</article>", $db, function ($xml_parser, $db, $nodeText) {
$simpleXML = simplexml_load_string($nodeText);
// Title
$title = "";
$result = $simpleXML->xpath('//title-group/article-title');
if (isset($result[0])) {
$title = (string) $result[0];
}
// Abstract
$abstract = "";
$result = $simpleXML->xpath('//abstract');
if (isset($result[0])) {
foreach ($result as $item) {
// Abstract contain HTML tags for some reason
// Revert to plain XML string
$xml = $item->asXML();
// Remove the tags
$no_tags = trim(strip_tags($xml));
// Remove any extra whitespace
$abstract .= ' ' . preg_replace('/(\\s)+/', ' ', $no_tags);
}
}
// Keywords
$keywords = array();
$result = $simpleXML->xpath('//kwd-group/kwd');
while (list(, $keyword) = each($result)) {
array_push($keywords, (string) $keyword);
}
// Journal-Title
$journal_title = "";
$result = $simpleXML->xpath('//journal-title');
if (isset($result[0])) {
$journal_title = (string) $result[0];
}
// Journal-ISO
$journal_iso = "";
$result = $simpleXML->xpath('//journal-meta/journal-id[@journal-id-type="iso-abbrev"]');
if (isset($result[0])) {
$journal_iso = (string) $result[0];
}
// ISSN
$issn = "";
$result = $simpleXML->xpath('//issn[@pub-type="ppub"]');
if (isset($result[0])) {
$issn = (string) $result[0];
}
// DOI
$doi = "";
$result = $simpleXML->xpath('//article-meta/article-id[@pub-id-type="doi"]');
if (isset($result[0])) {
$doi = (string) $result[0];
$pattern = '/[0-9\\.]+\\/.*/';
preg_match($pattern, $doi, $match);
if (count($match) > 0) {
$doi = $match[0];
} else {
$doi = "";
}
}
// Publication date
$day = "";
$result = $simpleXML->xpath('//pub-date/day');
if (isset($result[0])) {
$day = (string) $result[0];
}
$month = "";
$result = $simpleXML->xpath('//pub-date/month');
if (isset($result[0])) {
$month = (string) $result[0];
}
$year = "";
$result = $simpleXML->xpath('//pub-date/year');
if (isset($result[0])) {
$year = (string) $result[0];
}
return array("title" => $title, "abstract" => $abstract, "doi" => $doi, "journal_title" => $journal_title, "journal_iso" => $journal_iso, "journal_issn" => $issn, "day" => $day, "month" => $month, "year" => $year);
});
fclose($handle);
}
require_once "models/articles.php";
$article_model = new Articles();
foreach ($articles as $article) {
$article_model->insert($db, $article, 'pubmed_central');
}
}
示例5: parse
function parse($config, $db)
{
$folder = $config["dir"] . $config["ovid_dir"];
if ($config["test"] === true) {
$folder = $config["test_dir"] . $config["ovid_dir"];
}
require_once "libraries/parse_large_xml.php";
$xml_parser = new XML_parser();
$scanned_directory = array_diff(scandir($folder), array('..', '.'));
if (!isset($scanned_directory)) {
echo "Warning: no files found in: " . $folder . '<br/>';
return;
}
require_once "models/articles.php";
$article_model = new Articles();
foreach ($scanned_directory as $file) {
// Open the XML
if (($handle = @fopen($folder . "/" . $file, "r")) === false) {
echo "Warning: XML file not found at: " . $folder . "/" . $file;
return;
}
// Get the nodestring incrementally from the xml file by defining a callback
$articles = $xml_parser->nodeStringFromXMLFile($handle, "<record ", "</record>", $db, function ($xml_parser, $db, $nodeText) {
$simpleXML = simplexml_load_string($nodeText);
if (!$simpleXML) {
echo $nodeText;
}
// Title
$title = "";
$result = $simpleXML->xpath('//F[@L="Title"]/D');
if (isset($result[0])) {
$title = (string) $result[0];
}
// Abstract
$abstract = "";
$result = $simpleXML->xpath('//F[@L="Abstract"]/D');
if (isset($result[0])) {
foreach ($result as $item) {
// Abstract contain HTML tags for some reason
// Revert to plain XML string
$xml = $item->asXML();
// Remove the tags
$no_tags = trim(strip_tags($xml));
// Remove any extra whitespace
$abstract .= ' ' . preg_replace('/(\\s)+/', ' ', $no_tags);
}
}
// Journal-Title
$journal_title = "";
$result = $simpleXML->xpath('//F[@L="Source"]/D');
if (isset($result[0])) {
$journal_title = substr($result[0]->asXML(), 12, strpos($result[0]->asXML(), '<T>') - 12);
}
// Journal-ISO
$journal_iso = "";
// $result = $simpleXML->xpath('//journal-meta/journal-id[@journal-id-type="iso-abbrev"]');
// if (isset($result[0])) {
// $journal_iso = (string) $result[0];
// }
// ISSN
$issn = "";
$result = $simpleXML->xpath('//F[@L="ISSN"]/D');
if (isset($result[0])) {
$issn = (string) $result[0];
}
// DOI
$doi = "";
$result = $simpleXML->xpath('//F[@L="Digital Object Identifier"]/D');
if (isset($result[0])) {
$doi = (string) $result[0];
$pattern = '/[0-9\\.]+\\/.*/';
preg_match($pattern, $doi, $match);
if (count($match) > 0) {
$doi = $match[0];
} else {
$doi = "";
}
}
// Publication date
$day = "";
$month = "";
$year = "";
$result = $simpleXML->xpath('//F[@L="Year of Publication"]/D');
if (isset($result[0])) {
$year = (string) $result[0];
} else {
$result = $simpleXML->xpath('//F[@L="Date of Publication"]/D');
if (isset($result[0])) {
$year = (string) $result[0];
$year = preg_replace('/[^\\d]/', '', $year);
$year = substr($year, -4);
}
}
return array("title" => $title, "abstract" => $abstract, "doi" => $doi, "journal_title" => $journal_title, "journal_iso" => $journal_iso, "journal_issn" => $issn, "day" => $day, "month" => $month, "year" => $year);
});
fclose($handle);
foreach ($articles as $article) {
$article_model->insert($db, $article, 'ovid');
}
}
//.........这里部分代码省略.........
示例6: SimpleImage
//article picture small
$article_picture_small = new SimpleImage();
$article_picture_small->load($_FILES['img']['tmp_name'])->resize(145, 100)->save("../view/images/" . $final_article_picture_small_name);
//article slider picture
$article_slider_picture = new SimpleImage();
$article_slider_picture->load($_FILES['img']['tmp_name'])->resize(636, 331)->save("../view/images/" . $final_article_slider_picture);
//article slider small
$article_slider_picture_small = new SimpleImage();
$article_slider_picture_small->load($_FILES['img']['tmp_name'])->resize(636, 331)->save("../view/images/" . $final_article_slider_picture_small);
/**************************************************************************************/
//var_dump($img);
$article = new Articles();
$article->article_title = $_POST['article_title'];
$article->article_subtitle = $_POST['article_subtitle'];
$article->article_creator = $_POST['article_creator'];
$article->article_time = date("Y-m-d H-m-i");
$article->article_main_cat = $main_category;
$article->article_cat = $sub_category;
$article->article_picture_small = $final_article_picture_small_name;
$article->article_picture = $final_article_picture_name;
$article->article_picture_slider_small = $final_article_slider_picture_small;
$article->article_picture_slider = $final_article_slider_picture;
$article->article_intro_text = $_POST['article_intro_text'];
$article->article_text = $_POST['article_text'];
$article->article_slider_status = $_POST['slider'];
$article->article_index_status = $_POST['homepage'];
$article->article_category_page_status = $_POST['maincat'];
$article->main_category_top_story = $_POST['topstory'];
$article->article_status = $_POST['publish'];
$article->insert();
}