/** * List types * * @return void */ public function displayTask() { $ct = new Type($this->database); $this->view->types = $ct->getType(); // Output the HTML $this->view->display(); }
/** * Show a form for editing an entry * * @return void */ public function editTask() { // Check if they're logged in if (User::isGuest()) { $this->loginTask(); return; } // Check if admin $isAdmin = false; if (User::authorise('core.manage', $this->_option)) { $isAdmin = true; } // are we allowing user to add citation $allowImport = $this->config->get('citation_import', 1); if ($allowImport == 0 || $allowImport == 2 && User::get('usertype') == 'Super Administrator') { // Redirect App::redirect(Route::url('index.php?option=' . $this->_option, false), Lang::txt('COM_CITATION_EDIT_NOTALLOWED'), 'warning'); return; } // get the citation types $ct = new Type($this->database); $types = $ct->getType(); $fields = array(); foreach ($types as $type) { if (isset($type['fields'])) { $f = $type['fields']; if (strpos($f, ',') !== false) { $f = str_replace(',', "\n", $f); } $f = array_map('trim', explode("\n", $f)); $f = array_values(array_filter($f)); $fields[strtolower(str_replace(' ', '', $type['type_title']))] = $f; } } // add an empty value for the first type array_unshift($types, array('type' => '', 'type_title' => ' - Select a Type —')); // Incoming - expecting an array id[]=4232 $id = Request::getInt('id', 0); // Pub author $pubAuthor = false; // Load the associations object $assoc = new Association($this->database); // Get associations if ($id) { $this->view->assocs = $assoc->getRecords(array('cid' => $id), $isAdmin); $pubAuthor = $this->isPubAuthor($this->view->assocs); } // Is user authorized to edit citations? if (!$isAdmin && !$pubAuthor) { $id = 0; } // Load the object $this->view->row = new Citation($this->database); $this->view->row->load($id); //make sure title isnt too long $maxTitleLength = 30; $shortenedTitle = strlen($this->view->row->title) > $maxTitleLength ? substr($this->view->row->title, 0, $maxTitleLength) . '…' : $this->view->row->title; // Set the pathway Pathway::append(Lang::txt(strtoupper($this->_option)), 'index.php?option=' . $this->_option); if ($id && $id != 0) { Pathway::append($shortenedTitle, 'index.php?option=' . $this->_option . '&task=view&id=' . $this->view->row->id); } Pathway::append(Lang::txt('COM_CITATIONS_EDIT'), 'index.php?option=' . $this->_option . '&task=edit&id=' . $this->view->row->id); // Set the page title Document::setTitle(Lang::txt('COM_CITATIONS_CITATION') . $shortenedTitle); //push jquery to doc Document::addScriptDeclaration('var fields = ' . json_encode($fields) . ';'); // Instantiate a new view $this->view->title = Lang::txt(strtoupper($this->_option)) . ': ' . Lang::txt(strtoupper($this->_option) . '_' . strtoupper($this->_task)); $this->view->config = $this->config; // No ID, so we're creating a new entry // Set the ID of the creator if (!$id) { $this->view->row->uid = User::get('id'); // It's new - no associations to get $this->view->assocs = array(); //tags & badges $this->view->tags = array(); $this->view->badges = array(); } else { //tags & badges $this->view->tags = Format::citationTags($this->view->row, $this->database, false); $this->view->badges = Format::citationBadges($this->view->row, $this->database, false); } //get the citation types $ct = new Type($this->database); $this->view->types = $ct->getType(); // Output HTML foreach ($this->getErrors() as $error) { $this->view->setError($error); } $this->view->setLayout('edit')->display(); }
/** * Edit a citation * * @return void */ public function editTask() { //stop menu from working? Request::setVar('hidemainmenu', 1); //get request vars - expecting an array id[]=4232 $id = Request::getVar('id', array()); if (is_array($id)) { $id = !empty($id) ? $id[0] : 0; } //get all citations sponsors $cs = new Sponsor($this->database); $this->view->sponsors = $cs->getSponsor(); //get all citation types $ct = new Type($this->database); $this->view->types = $ct->getType(); //empty citation object $this->view->row = new Citation($this->database); //if we have an id load that citation data if (isset($id) && $id != '' && $id != 0) { // Load the citation object $this->view->row->load($id); // Get the associations $assoc = new Association($this->database); $this->view->assocs = $assoc->getRecords(array('cid' => $id)); //get sponsors for citation $this->view->row_sponsors = $cs->getCitationSponsor($this->view->row->id); //get the citations tags $this->view->tags = Format::citationTags($this->view->row, \App::get('db'), false); //get the badges $this->view->badges = Format::citationBadges($this->view->row, \App::get('db'), false); //parse citation params $this->view->params = new Registry($this->view->row->params); } else { //set the creator $this->view->row->uid = User::get('id'); // It's new - no associations to get $this->view->assocs = array(); //array of sponsors - empty $this->view->row_sponsors = array(); //empty tags and badges arrays $this->view->tags = array(); $this->view->badges = array(); //empty params object $this->view->params = new Registry(''); } //are we padding back the citation data if (isset($this->row)) { $this->view->row = $this->row; } //are we passing back the tags from edit if ($this->tags != '') { $this->tags = explode(',', $this->tags); foreach ($this->tags as $tag) { $this->view->tags[]['raw_tag'] = $tag; } } //are we passing back the tags from edit if ($this->badges != '') { $this->badges = explode(',', $this->badges); foreach ($this->badges as $badge) { $this->view->badges[]['raw_tag'] = $badge; } } // Set any errors if ($this->getError()) { $this->view->setError($this->getError()); } //set vars for view $this->view->config = $this->config; // Output the HTML $this->view->setLayout('edit')->display(); }
/** * Function to format citation based on template * * @param object $citation Citation object * @param string $highlight String that we want to highlight * @param boolean $include_coins Include COINs? * @param object $config Registry * @param boolean $coins_only Only output COINs? * @return string Formatted citation */ public function formatCitation($citation, $highlight = NULL, $include_coins = true, $config, $coins_only = false) { //get hub specific details $hub_name = \Config::get('sitename'); $hub_url = rtrim(\Request::base(), '/'); $c_type = 'journal'; $db = \App::get('db'); $ct = new Type($db); $types = $ct->getType(); $type = ''; foreach ($types as $t) { if ($t['id'] == $citation->type) { $type = $t['type']; } } switch (strtolower($type)) { case 'book': case 'inbook': case 'conference': case 'proceedings': case 'inproceedings': $c_type = "book"; break; case 'journal': case 'article': case 'journal article': $c_type = "journal"; break; default: break; } //var to hold COinS data $coins_data = array("ctx_ver=Z39.88-2004", "rft_val_fmt=info:ofi/fmt:kev:mtx:{$c_type}", "rfr_id=info:sid/{$hub_url}:{$hub_name}"); //array to hold replace vals $replace_values = array(); //get the template if ($config->get('default_citation_format') != '') { $template = CitationFormat::all()->where('style', 'LIKE', $config->get('default_citation_format'))->limit(1)->row()->format; } else { $template = $this->getTemplate(); } //get the template keys $template_keys = $this->getTemplateKeys(); foreach ($template_keys as $k => $v) { if (!self::keyExistsOrIsNotEmpty($k, $citation)) { $replace_values[$v] = ''; } else { $replace_values[$v] = $citation->{$k}; //add to coins data if we can but not authors as that will get processed below if (in_array($k, array_keys($this->_coins_keys)) && $k != 'author') { //key specific switch ($k) { case 'title': break; case 'doi': $coins_data[] = $this->_coins_keys[$k] . $citation->{$k}; break; case 'url': $coins_data[] = $this->_coins_keys[$k] . '=' . htmlentities($citation->{$k}); break; case 'journaltitle': $jt = html_entity_decode($citation->{$k}); $jt = !preg_match('!\\S!u', $jt) ? utf8_encode($jt) : $jt; $coins_data[] = $this->_coins_keys[$k] . '=' . $jt; break; default: $coins_data[] = $this->_coins_keys[$k] . '=' . $citation->{$k}; } } if ($k == 'author') { $a = array(); $auth = html_entity_decode($citation->{$k}); $auth = !preg_match('!\\S!u', $auth) ? utf8_encode($auth) : $auth; $author_string = $auth; $authors = explode(';', $author_string); foreach ($authors as $author) { preg_match('/{{(.*?)}}/s', $author, $matches); if (!empty($matches)) { $id = trim($matches[1]); if (is_numeric($id)) { $user = \User::getInstance($id); if (is_object($user)) { $a[] = '<a rel="external" href="' . \Route::url('index.php?option=com_members&id=' . $matches[1]) . '">' . str_replace($matches[0], '', $author) . '</a>'; } else { $a[] = $author; } } } else { $a[] = $author; } //add author coins $coins_data[] = 'rft.au=' . trim(preg_replace('/\\{\\{\\d+\\}\\}/', '', trim($author))); } $replace_values[$v] = implode(", ", $a); } if ($k == 'title') { $url_format = $config->get("citation_url", "url"); $custom_url = $config->get("citation_custom_url", ''); $url = $citation->url; if ($url_format == 'custom' && $custom_url != '') { //parse custom url to make sure we are not using any vars preg_match_all('/\\{(\\w+)\\}/', $custom_url, $matches, PREG_SET_ORDER); if ($matches) { foreach ($matches as $match) { $field = strtolower($match[1]); $replace = $match[0]; $replaceWith = ''; if (property_exists($citation, $field)) { if (strstr($citation->{$field}, 'http')) { $custom_url = $citation->{$field}; } else { $replaceWith = urlencode($citation->{$field}); $custom_url = str_replace($replace, $replaceWith, $custom_url); } } } //set the citation url to be the new custom url parsed $url = $custom_url; } } //prepare url if (strstr($url, "\r\n")) { $url = array_filter(array_values(explode("\r\n", $url))); $url = $url[0]; } elseif (strstr($url, " ")) { $url = array_filter(array_values(explode(" ", $url))); $url = $url[0]; } $t = html_entity_decode($citation->{$k}); $t = !preg_match('!\\S!u', $t) ? utf8_encode($t) : $t; $title = $url != '' && preg_match('/http:|https:/', $url) ? '<a rel="external" class="citation-title" href="' . $url . '">' . $t . '</a>' : '<span class="citation-title">' . $t . '</span>'; //do we want to display single citation $singleCitationView = $config->get('citation_single_view', 0); if ($singleCitationView && isset($citation->id)) { $title = '<a href="' . \Route::url('index.php?option=com_citations&task=view&id=' . $citation->id) . '">' . $t . '</a>'; } //send back title to replace title placeholder ({TITLE}) $replace_values[$v] = '"' . $title . '"'; //add title to coin data but fixing bad chars first $coins_data[] = 'rft.atitle=' . $t; } if ($k == 'pages') { $replace_values[$v] = "pg: " . $citation->{$k}; } if ($k == 'version') { $replace_values[$v] = "(Version " . $citation->{$k} . ")"; } } } // Add more to coins $tmpl = isset($this->_default_format[$template]) ? $this->_default_format[$template] : $template; $cite = strtr($tmpl, $replace_values); // Strip empty tags $pattern = "/<[^\\/>]*>([\\s]?)*<\\/[^>]*>/"; $cite = preg_replace($pattern, '', $cite); //reformat dates $pattern = "/(\\d{4})-(\\d{2})-(\\d{2}) (\\d{2}):(\\d{2}):(\\d{2})/"; $cite = preg_replace($pattern, "\$2-\$3-\$1", $cite); // Reduce multiple spaces to one $pattern = "/\\s/s"; $cite = preg_replace($pattern, ' ', $cite); // Strip empty punctuation inside $b = array("''" => '', '""' => '', '()' => '', '{}' => '', '[]' => '', '??' => '', '!!' => '', '..' => '.', ',,' => ',', ' ,' => '', ' .' => '', ',.' => '.', '","' => '', 'doi:.' => '', '(DOI:).' => ''); foreach ($b as $k => $i) { $cite = str_replace($k, $i, $cite); } // Strip empty punctuation from the start $c = array("' ", '" ', '(', ') ', ', ', '. ', '? ', '! ', ': ', '; '); foreach ($c as $k) { if (substr($cite, 0, 2) == $k) { $cite = substr($cite, 2); } } // remove trailing commas $cite = trim($cite); if (substr($cite, -1) == ',') { $cite = substr($cite, 0, strlen($cite) - 1); } // percent encode chars $chars = array('%', ' ', '/', ':', '"', '\'', '&'); $replace = array("%20", "%20", "%2F", "%3A", "%22", "%27", "%26"); $coins_data = str_replace($chars, $replace, implode('&', $coins_data)); $cite = preg_replace('/, :/', ':', $cite); // highlight citation data // do before appendnind coins as we dont want that data accidentily highlighted (causes style issues) $cite = $highlight ? String::highlight($cite, $highlight) : $cite; // if we want coins add them if ($include_coins || $coins_only) { $coins = '<span class="Z3988" title="' . $coins_data . '"></span>'; if ($coins_only == true) { return $coins; } $cite .= $coins; } // output the citation return $cite; }
/** * Get a list of citations requiring attention * * @param array $action_attention * @param array $action_no_attention * @return array */ public function process($action_attention = array(), $action_no_attention = array()) { $results = array('saved' => array(), 'not_saved' => array(), 'error' => array()); $now = with(new Date('now'))->toSql(); $user = $this->get('user'); $scope = $this->get('scope'); $scope_id = $this->get('scope_id'); $published = $this->get('published', null); // loop through each citation that required attention from user if ($cites_require_attention = $this->readRequiresAttention()) { foreach ($cites_require_attention as $k => $cra) { $cc = new Tables\Citation($this->database); // add a couple of needed keys $cra['uid'] = $user; $cra['created'] = $now; // reset tags and badges $tags = ''; $badges = ''; // remove errors unset($cra['errors']); // if tags were sent over if (array_key_exists('tags', $cra)) { $tags = $cra['tags']; unset($cra['tags']); } // if badges were sent over if (array_key_exists('badges', $cra)) { $badges = $cra['badges']; unset($cra['badges']); } //take care fo type $ct = new Tables\Type($this->database); $types = $ct->getType(); $type = ''; foreach ($types as $t) { if (strtolower($t['type_title']) == strtolower($cra['type'])) { $type = $t['id']; } } $cra['type'] = $type ? $type : '1'; switch ($action_attention[$k]) { case 'overwrite': $cra['id'] = $cra['duplicate']; break; case 'both': break; case 'discard': $results['not_saved'][] = $cra; continue 2; break; } // remove duplicate flag unset($cra['duplicate']); //sets group if set if ($scope) { $cra['scope'] = $scope; } if ($scope_id) { $cra['scope_id'] = $scope_id; } if (!is_null($published)) { $cra['published'] = $published; } // save the citation if (!$cc->save($cra)) { $results['error'][] = $cra; } else { // tags if ($this->tags && isset($tags)) { $this->tag($user, $cc->id, $tags, ''); } // badges if ($this->badges && isset($badges)) { $this->tag($user, $cc->id, $badges, 'badge'); } // add the citattion to the saved $results['saved'][] = $cc->id; } } } if ($cites_require_no_attention = $this->readRequiresNoAttention()) { foreach ($cites_require_no_attention as $k => $crna) { // new citation object $cc = new Tables\Citation($this->database); // add a couple of needed keys $crna['uid'] = $user; $crna['created'] = $now; // reset tags and badges $tags = ''; $badges = ''; // remove errors unset($crna['errors']); // if tags were sent over if (array_key_exists('tags', $crna)) { $tags = $crna['tags']; unset($crna['tags']); } // if badges were sent over if (array_key_exists('badges', $crna)) { $badges = $crna['badges']; unset($crna['badges']); } // verify we haad this one checked to be submitted if ($action_no_attention[$k] != 1) { $results['not_saved'][] = $crna; continue; } // take care fo type $ct = new Tables\Type($this->database); $types = $ct->getType(); $type = ''; foreach ($types as $t) { // TODO: undefined index type? I just suppressed the error b/c I'm not sure what the logic is supposed to be /SS if (strtolower($t['type_title']) == strtolower($crna['type'])) { $type = $t['id']; } } $crna['type'] = $type ? $type : '1'; // remove duplicate flag unset($crna['duplicate']); // sets group if set if ($scope) { $crna['scope'] = $scope; } if ($scope_id) { $crna['scope_id'] = $scope_id; } if (!is_null($published)) { $crna['published'] = $published; } // save the citation if (!$cc->save($crna)) { $results['error'][] = $crna; } else { // tags if ($this->tags && isset($tags)) { $this->tag($user, $cc->id, $tags, ''); } // badges if ($this->badges && isset($badges)) { $this->tag($user, $cc->id, $badges, 'badge'); } // add the citattion to the saved $results['saved'][] = $cc->id; } } } $this->cleanup(); return $results; }
/** * Format the file * * @param object $row Record to format * @return string */ public function format($row) { //get fields to not include for all citations $config = \Component::params('com_citations'); $exclude = $config->get('citation_download_exclude', ''); if (strpos($exclude, ",") !== false) { $exclude = str_replace(',', "\n", $exclude); } $exclude = array_values(array_filter(array_map('trim', explode("\n", $exclude)))); //get fields to not include for specific citation $cparams = new \Hubzero\Config\Registry($row->params); $citation_exclude = $cparams->get('exclude', ''); if (strpos($citation_exclude, ',') !== false) { $citation_exclude = str_replace(',', "\n", $citation_exclude); } $citation_exclude = array_values(array_filter(array_map('trim', explode("\n", $citation_exclude)))); //merge overall exclude and specific exclude $exclude = array_values(array_unique(array_merge($exclude, $citation_exclude))); //var to hold document conetnt $doc = ''; //get all the citation types $db = \App::get('db'); $ct = new Type($db); $types = $ct->getType(); $type = ''; foreach ($types as $t) { if ($t['id'] == $row->type) { $type = $t['type_title']; } } //set the type to generic if we dont have one $type = $type != '' ? $type : 'Generic'; //set the type $doc .= "%0 {$type}" . "\r\n"; if ($row->booktitle && !in_array('booktitle', $exclude)) { $bt = html_entity_decode($row->booktitle); $bt = !preg_match('!\\S!u', $bt) ? utf8_encode($bt) : $bt; $doc .= "%B " . $bt . "\r\n"; } if ($row->journal && !in_array('journal', $exclude)) { $j = html_entity_decode($row->journal); $j = !preg_match('!\\S!u', $j) ? utf8_encode($j) : $j; $doc .= "%J " . $j . "\r\n"; } if ($row->year && !in_array('year', $exclude)) { $doc .= "%D " . trim($row->year) . "\r\n"; } if ($row->title && !in_array('title', $exclude)) { $t = html_entity_decode($row->title); $t = !preg_match('!\\S!u', $t) ? utf8_encode($t) : $t; $doc .= "%T " . $t . "\r\n"; } if (!in_array('authors', $exclude)) { $author = html_entity_decode($row->author); $author = !preg_match('!\\S!u', $author) ? utf8_encode($author) : $author; $author_array = explode(';', stripslashes($author)); foreach ($author_array as $auth) { $auth = preg_replace('/{{(.*?)}}/s', '', $auth); if (!strstr($auth, ',')) { $bits = explode(' ', $auth); $n = array_pop($bits) . ', '; $bits = array_map('trim', $bits); $auth = $n . trim(implode(' ', $bits)); } $doc .= "%A " . trim($auth) . "\r\n"; } } if ($row->address && !in_array('address', $exclude)) { $doc .= "%C " . htmlspecialchars_decode(trim(stripslashes($row->address))) . "\r\n"; } if ($row->editor && !in_array('editor', $exclude)) { $editor = html_entity_decode($row->editor); $editor = !preg_match('!\\S!u', $editor) ? utf8_encode($editor) : $editor; $author_array = explode(';', stripslashes($editor)); foreach ($author_array as $auth) { $doc .= "%E " . trim($auth) . "\r\n"; } } if ($row->publisher && !in_array('publisher', $exclude)) { $p = html_entity_decode($row->publisher); $p = !preg_match('!\\S!u', $p) ? utf8_encode($p) : $p; $doc .= "%I " . $p . "\r\n"; } if ($row->number && !in_array('number', $exclude)) { $doc .= "%N " . trim($row->number) . "\r\n"; } if ($row->pages && !in_array('pages', $exclude)) { $doc .= "%P " . trim($row->pages) . "\r\n"; } if ($row->url && !in_array('url', $exclude)) { $doc .= "%U " . trim($row->url) . "\r\n"; } if ($row->volume && !in_array('volume', $exclude)) { $doc .= "%V " . trim($row->volume) . "\r\n"; } if ($row->note && !in_array('note', $exclude)) { $n = html_entity_decode($row->note); $n = !preg_match('!\\S!u', $n) ? utf8_encode($n) : $n; $doc .= "%Z " . $n . "\r\n"; } if ($row->edition && !in_array('edition', $exclude)) { $doc .= "%7 " . trim($row->edition) . "\r\n"; } if ($row->month && !in_array('month', $exclude)) { $doc .= "%8 " . trim($row->month) . "\r\n"; } if ($row->isbn && !in_array('isbn', $exclude)) { $doc .= "%@ " . trim($row->isbn) . "\r\n"; } if ($row->doi && !in_array('doi', $exclude)) { $doc .= "%1 " . trim($row->doi) . "\r\n"; } if ($row->keywords && !in_array('keywords', $exclude)) { $k = html_entity_decode($row->keywords); $k = !preg_match('!\\S!u', $k) ? utf8_encode($k) : $k; $doc .= "%K " . $k . "\r\n"; } if ($row->research_notes && !in_array('research_notes', $exclude)) { $rn = html_entity_decode($row->research_notes); $rn = !preg_match('!\\S!u', $rn) ? utf8_encode($rn) : $rn; $doc .= "%< " . $rn . "\r\n"; } if ($row->abstract && !in_array('abstract', $exclude)) { $a = html_entity_decode($row->abstract); $a = !preg_match('!\\S!u', $a) ? utf8_encode($a) : $a; $doc .= "%X " . $a . "\r\n"; } if ($row->label && !in_array('label', $exclude)) { $l = html_entity_decode($row->label); $l = !preg_match('!\\S!u', $l) ? utf8_encode($l) : $l; $doc .= "%F " . $label . "\r\n"; } if ($row->language && !in_array('language', $exclude)) { $lan = html_entity_decode($row->language); $lan = !preg_match('!\\S!u', $lan) ? utf8_encode($lan) : $lan; $doc .= "%G " . $lan . "\r\n"; } if ($row->author_address && !in_array('author_address', $exclude)) { $aa = html_entity_decode($row->author_address); $aa = !preg_match('!\\S!u', $aa) ? utf8_encode($aa) : $aa; $doc .= "%+ " . $aa . "\r\n"; } if ($row->accession_number && !in_array('accession_number', $exclude)) { $an = html_entity_decode($row->accession_number); $an = !preg_match('!\\S!u', $an) ? utf8_encode($an) : $an; $doc .= "%M " . trim($an) . "\r\n"; } if ($row->call_number && !in_array('callnumber', $exclude)) { $doc .= "%L " . trim($row->call_number) . "\r\n"; } if ($row->short_title && !in_array('short_title', $exclude)) { $st = html_entity_decode($row->short_title); $st = !preg_match('!\\S!u', $st) ? utf8_encode($st) : $st; $doc .= "%! " . htmlspecialchars_decode(trim($st)) . "\r\n"; } //get the endnote import params //we want to get the endnote key used for importing badges to export them $endnote_import_plugin_params = \Hubzero\Plugin\Plugin::getParams('endnote', 'citation'); $custom_tags = explode("\n", $endnote_import_plugin_params->get('custom_tags')); $citation_endnote_tags = array(); $citation_badges_key = ""; foreach ($custom_tags as $ct) { $citation_endnote_tags[] = explode("-", trim($ct)); } foreach ($citation_endnote_tags as $cet) { if ($cet[0] == 'badges') { $citation_badges_key = $cet[1]; } } //if we found a key to export badges then add to export if (isset($row->badges) && $row->badges && !in_array('badges', $exclude) && $citation_badges_key != '') { $doc .= $citation_badges_key . ' ' . $row->badges; } $doc .= "\r\n"; return $doc; }
/** * Format the file * * @param object $row Record to format * @return string */ public function format($row) { // get fields to not include for all citations $config = \Component::params('com_citations'); $exclude = $config->get('citation_download_exclude', ''); if (strpos($exclude, ',') !== false) { $exclude = str_replace(',', "\n", $exclude); } $exclude = array_values(array_filter(array_map('trim', explode("\n", $exclude)))); //get fields to not include for specific citation $cparams = new \Hubzero\Config\Registry($row->params); $citation_exclude = $cparams->get('exclude', ''); if (strpos($citation_exclude, ',') !== false) { $citation_exclude = str_replace(',', "\n", $citation_exclude); } $citation_exclude = array_values(array_filter(array_map('trim', explode("\n", $citation_exclude)))); //merge overall exclude and specific exclude $exclude = array_values(array_unique(array_merge($exclude, $citation_exclude))); include_once dirname(__DIR__) . DS . 'helpers' . DS . 'BibTex.php'; $bibtex = new \Structures_BibTex(); $addarray = array(); //get all the citation types $db = \App::get('db'); $ct = new Type($db); $types = $ct->getType(); //find the right title $type = ''; foreach ($types as $t) { if ($t['id'] == $row->type) { $type = $t['type']; } } $type = $type != '' ? $type : 'Generic'; if (!$row->cite) { $au = new \Components\Citations\Tables\Author($db); $authors = $au->getRecords(array('cid' => $row->id, 'start' => 0, 'limit' => 1)); foreach ($authors as $author) { $row->cite .= strtolower($author->surname); } $row->cite .= $row->year; $t = preg_replace('/[^a-zA-Z0-9]/', '', strtolower($row->title)); $row->cite .= strlen($t) > 10 ? substr($t, 0, 10) : $t; } $addarray['type'] = $type; $addarray['cite'] = $row->cite; $addarray['title'] = $row->title; $addarray['address'] = $row->address; $auths = explode(';', $row->author); for ($i = 0, $n = count($auths); $i < $n; $i++) { $author = trim($auths[$i]); $author_arr = explode(',', $author); $author_arr = array_map('trim', $author_arr); $addarray['author'][$i]['first'] = isset($author_arr[1]) ? $author_arr[1] : ''; $addarray['author'][$i]['last'] = isset($author_arr[0]) ? $author_arr[0] : ''; $addarray['author'][$i]['first'] = preg_replace('/\\{\\{\\d+\\}\\}/', '', $addarray['author'][$i]['first']); $addarray['author'][$i]['last'] = preg_replace('/\\{\\{\\d+\\}\\}/', '', $addarray['author'][$i]['last']); } $addarray['booktitle'] = $row->booktitle; $addarray['chapter'] = $row->chapter; $addarray['edition'] = $row->edition; $addarray['editor'] = $row->editor; $addarray['eprint'] = $row->eprint; $addarray['howpublished'] = $row->howpublished; $addarray['institution'] = $row->institution; $addarray['journal'] = $row->journal; $addarray['key'] = $row->key; $addarray['location'] = $row->location; $addarray['month'] = $row->month != 0 || $row->month != '0' ? $row->month : ''; $addarray['note'] = $row->note; $addarray['number'] = $row->number; $addarray['organization'] = $row->organization; $addarray['pages'] = $row->pages != 0 || $row->pages != '0' ? $row->pages : ''; $addarray['publisher'] = $row->publisher; $addarray['series'] = $row->series; $addarray['school'] = $row->school; $addarray['url'] = $row->url; $addarray['volume'] = $row->volume; $addarray['year'] = $row->year; if ($row->journal != '') { $addarray['issn'] = $row->isbn; } else { $addarray['isbn'] = $row->isbn; } $addarray['doi'] = $row->doi; $addarray['language'] = $row->language; $addarray['accession_number'] = $row->accession_number; $addarray['short_title'] = html_entity_decode($row->short_title); $addarray['author_address'] = $row->author_address; $addarray['keywords'] = str_replace("\r\n", ', ', $row->keywords); $addarray['abstract'] = $row->abstract; $addarray['call_number'] = $row->call_number; $addarray['label'] = $row->label; $addarray['research_notes'] = $row->research_notes; foreach ($addarray as $k => $v) { if (in_array($k, $exclude)) { unset($addarray[$k]); } } $bibtex->addEntry($addarray); //$file = 'download_'.$id.'.bib'; //$mime = 'application/x-bibtex'; $doc = $bibtex->bibTex(); return $doc; }
/** * Show the results of the import * * @return void */ public function savedTask() { // Get the session object $session = App::get('session'); // Get the citations $citations_saved = $session->get('citations_saved'); $citations_not_saved = $session->get('citations_not_saved'); $citations_error = $session->get('citations_error'); // Check to make sure we have citations if (!$citations_saved && !$citations_not_saved) { App::redirect(Route::url('index.php?option=com_citations&task=import'), Lang::txt('COM_CITATIONS_IMPORT_MISSING_FILE_CONTINUE'), 'error'); return; } // Set the page title $this->_buildTitle(); // Set the pathway $this->_buildPathway(); // Filters for gettiung just previously uploaded $filters = array('start' => 0, 'search' => ''); // Instantiate a new view $this->view->title = Lang::txt(strtoupper($this->_option)) . ': ' . Lang::txt(strtoupper($this->_option) . '_' . strtoupper($this->_task)); $this->view->config = $this->config; $this->view->database = $this->database; $this->view->filters = $filters; $this->view->citations = array(); foreach ($citations_saved as $cs) { $cc = new Citation($this->database); $cc->load($cs); $this->view->citations[] = $cc; } $this->view->openurl['link'] = ''; $this->view->openurl['text'] = ''; $this->view->openurl['icon'] = ''; //take care fo type $ct = new Type($this->database); $this->view->types = $ct->getType(); //get any messages $this->view->messages = Notify::messages('citations'); //display view $this->view->display(); }