/**
  * Down
  **/
 public function down()
 {
     // get all formats on the hub
     $formats = Components\Citations\Models\Format::all();
     $ieee = false;
     // flag for IEEE format
     $apa = false;
     // flag for APA format
     foreach ($formats as $format) {
         // check for IEEE format
         if (strtolower($format->style) == 'ieee') {
             $ieee = $format->id;
         }
         // check for APA style
         if (strtolower($format->style) == 'apa') {
             $apa = $format->id;
         }
     }
     // end foreach
     if ($apa) {
         //insert apa
         $apaFormat = Components\Citations\Models\Format::oneOrFail($apa);
         $apaFormat->destroy();
     }
     if ($ieee) {
         //insert ieee
         $ieeeFormat = Components\Citations\Models\Format::oneOrFail($ieee);
         $ieeeFormat->destroy();
     }
 }
Ejemplo n.º 2
0
 /**
  * Save a type
  *
  * @return     void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     //get format
     $format = Request::getVar('citationFormat', array());
     // create or update custom format
     $model = CitationFormat::oneOrNew($format['id']);
     if ($model->style == 'Hub Custom' || $model->isNew() === true) {
         $model->set(array('style' => 'Hub Custom', 'format' => \Hubzero\Utility\Sanitize::clean($format['format'])));
     } else {
         $model->set(array('format' => \Hubzero\Utility\Sanitize::clean($format['format'])));
     }
     if (!$model->save()) {
         // redirect with error message
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('CITATION_FORMAT_NOT_SAVED'), 'error');
     }
     // successfully set the default value, redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('CITATION_FORMAT_SAVED') . ' ' . $model->style);
 }
Ejemplo n.º 3
0
 public function formatted($config = array('format' => 'apa'), $highlight = NULL)
 {
     //get hub specific details
     $hub_name = \Config::get('sitename');
     $hub_url = rtrim(\Request::base(), '/');
     //get scope specific details
     $coins_only = isset($config['coins_only']) ? $config['coins_only'] : "no";
     $include_coins = isset($config['include_coins']) ? $config['include_coins'] : "no";
     $c_type = 'journal';
     $type = $this->relatedType->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
     // default to IEEE
     try {
         $format = \Components\Citations\Models\Format::oneOrFail($config['citationFormat']);
     } catch (\Exception $e) {
         $format = \Components\Citations\Models\Format::all()->where('style', 'LIKE', '%IEEE%')->row()->toObject();
     }
     //get the template keys
     $template_keys = array("type" => "{TYPE}", "cite" => "{CITE KEY}", "ref_type" => "{REF TYPE}", "date_submit" => "{DATE SUBMITTED}", "date_accept" => "{DATE ACCEPTED}", "date_publish" => "{DATE PUBLISHED}", "author" => "{AUTHORS}", "editor" => "{EDITORS}", "title" => "{TITLE/CHAPTER}", "booktitle" => "{BOOK TITLE}", "chapter" => "{CHAPTER}", "journal" => "{JOURNAL}", "journaltitle" => "{JOURNAL TITLE}", "volume" => "{VOLUME}", "number" => "{ISSUE/NUMBER}", "pages" => "{PAGES}", "isbn" => "{ISBN/ISSN}", "issn" => "{ISSN}", "doi" => "{DOI}", "series" => "{SERIES}", "edition" => "{EDITION}", "school" => "{SCHOOL}", "publisher" => "{PUBLISHER}", "institution" => "{INSTITUTION}", "address" => "{ADDRESS}", "location" => "{LOCATION}", "howpublished" => "{HOW PUBLISHED}", "url" => "{URL}", "eprint" => "{E-PRINT}", "note" => "{TEXT SNIPPET/NOTES}", "organization" => "{ORGANIZATION}", "abstract" => "{ABSTRACT}", "year" => "{YEAR}", "month" => "{MONTH}", "search_string" => "{SECONDARY LINK}", "sec_cnt" => "{SECONDARY COUNT}");
     /**
      * Values used by COINs
      *
      * @var  array
      */
     $coins_keys = array('title' => 'rft.atitle', 'journaltitle' => 'rft.jtitle', 'date_publish' => 'rft.date', 'volume' => 'rft.volume', 'number' => 'rft.issue', 'pages' => 'rft.pages', 'issn' => 'rft.issn', 'isbn' => 'rft.isbn', 'type' => 'rft.genre', 'author' => 'rft.au', 'url' => 'rft_id', 'doi' => 'rft_id=info:doi/', 'author' => 'rft.au');
     // form the formatted citation
     foreach ($template_keys as $k => $v) {
         if (!$this->keyExistsOrIsNotEmpty($k, $this) && $k != 'author') {
             $replace_values[$v] = '';
         } else {
             $replace_values[$v] = $this->{$k};
             //add to coins data if we can but not authors as that will get processed below
             if (in_array($k, array_keys($coins_keys)) && $k != 'author') {
                 //key specific
                 switch ($k) {
                     case 'title':
                         break;
                     case 'doi':
                         $coins_data[] = $this->_coins_keys[$k] . $this->{$k};
                         break;
                     case 'url':
                         $coins_data[] = $this->_coins_keys[$k] . '=' . htmlentities($this->{$k});
                         break;
                     case 'journaltitle':
                         $jt = html_entity_decode($this->{$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] . '=' . $this->{$k};
                 }
             }
             if ($k == 'author') {
                 $a = array();
                 $auth = html_entity_decode($this->{$k});
                 $auth = !preg_match('!\\S!u', $auth) ? utf8_encode($auth) : $auth;
                 // prefer the use of the relational table
                 if ($this->relatedAuthors->count() > 0) {
                     $authors = $this->relatedAuthors;
                     $authorCount = $this->relatedAuthors->count();
                 } elseif ($auth != '' && $this->relatedAuthors->count() == 0) {
                     $author_string = $auth;
                     $authors = explode(';', $author_string);
                     $authorCount = count($authors);
                 } else {
                     $authorCount = 0;
                     $replace_values[$v] = '';
                 }
                 if ($authorCount > 0) {
                     foreach ($authors as $author) {
                         // for legacy profile handling
                         if (is_string($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)));
                         } elseif (is_object($author)) {
                             if ($author->uidNumber > 0) {
                                 $a[] = '<a rel="external" href="' . \Route::url('index.php?option=com_members&id=' . $author->uidNumber) . '">' . $author->author . '</a>';
                             } else {
                                 $a[] = $author->author;
                             }
                         } else {
                             $a[] = $author;
                         }
                     }
                     $replace_values[$v] = implode(", ", $a);
                 }
             }
             if ($k == 'title') {
                 $url_format = isset($config['citation_url']) ? $config['citation_url'] : 'url';
                 $custom_url = isset($config['citation_custom_url']) ? $config['citation_custom_url'] : '';
                 $url = $this->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($this, $field)) {
                                 if (strstr($this->{$field}, 'http')) {
                                     $custom_url = $this->{$field};
                                 } else {
                                     $replaceWith = urlencode($this->{$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($this->{$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('citation_single_view', 0);
                 $singleCitationView = isset($config['citation_single_view']) ? $config['citation_single_view'] : 0;
                 if ($singleCitationView && isset($this->id)) {
                     $title = '<a href="' . \Route::url('index.php?option=com_citations&task=view&id=' . $this->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: " . $this->{$k};
             }
         }
     }
     // Add more to coins
     $template = $format->format;
     $tmpl = isset($template) ? $template : $default_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('%', ' ', '/', ':', '"', '\'', '&amp;');
     $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 == "yes" || $coins_only == "yes") {
         $coins = '<span class="Z3988" title="' . $coins_data . '"></span>';
         if ($coins_only == "yes") {
             return $coins;
         }
         $cite .= $coins;
     }
     // output the citation
     return $cite;
 }
Ejemplo n.º 4
0
 /**
  * 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('%', ' ', '/', ':', '"', '\'', '&amp;');
     $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;
 }
Ejemplo n.º 5
0
 /**
  * Settings for group citations
  *
  * @param null
  * @return void
  *
  *
  */
 private function settingsAction()
 {
     if ($_POST) {
         $display = Request::getVar('display', '');
         $format = Request::getVar('citation-format', '');
         // craft a clever name
         $name = "custom-member-" . $this->member->get('uidNumber');
         // fetch or create new format
         $citationFormat = \Components\Citations\Models\Format::oneOrNew($format);
         // if the setting a custom member citation type
         if ($citationFormat->isNew() || $citationFormat->style == $name && !$citationFormat->isNew()) {
             $citationFormat->set(array('format' => Request::getVar('template'), 'style' => $name));
             // save format
             $citationFormat->save();
             // update group
             $citationFormatID = $citationFormat->id;
         } else {
             // returned value from format select box
             $citationFormatID = $format;
         }
         $include_coins = \Hubzero\Utility\Sanitize::clean(Request::getVar('include_coins', ''));
         $coins_only = \Hubzero\Utility\Sanitize::clean(Request::getVar('coins_only', ''));
         $citation_show_tags = \Hubzero\Utility\Sanitize::clean(Request::getVar('citations_show_tags', ''));
         $citation_show_badges = \Hubzero\Utility\Sanitize::clean(Request::getVar('citations_show_badges', ''));
         // set member citation parameters
         $this->member->setParam('citationFormat', $citationFormatID);
         $this->member->setParam('include_coins', $include_coins);
         $this->member->setParam('coins_only', $coins_only);
         $this->member->setParam('citations_show_tags', $citation_show_tags);
         $this->member->setParam('citations_show_badges', $citation_show_badges);
         // save profile settings
         if (!$this->member->update()) {
             // failed
             App::redirect(Route::url($this->member->getLink() . '&active=' . $this->_name), Lang::txt('PLG_MEMBERS_CITATIONS_SETTINGS_NOT_SAVED'), 'error');
         }
         // redirect after save
         App::redirect(Route::url($this->member->getLink() . '&active=' . $this->_name), Lang::txt('PLG_MEMBERS_CITATIONS_SETTINGS_SAVED'), 'success');
         return;
     } else {
         // instansiate the view
         $view = $this->view('settings');
         // pass the group through
         $view->member = $this->member;
         // get group settings
         $params = json_decode($this->member->get('params'));
         $view->include_coins = isset($params->include_coins) ? $params->include_coins : "false";
         $view->coins_only = isset($params->coins_only) ? $params->coins_only : "false";
         $view->citations_show_tags = isset($params->citations_show_tags) ? $params->citations_show_tags : "true";
         $view->citations_show_badges = isset($params->citations_show_badges) ? $params->citations_show_badges : "true";
         $citationsFormat = isset($params->citationFormat) ? $params->citationFormat : 1;
         // intended for the case that the group's custom
         // format is removed from the jos_citations_format
         try {
             $view->currentFormat = \Components\Citations\Models\Format::oneOrFail($citationsFormat);
         } catch (\Exception $e) {
             $view->currentFormat = \Components\Citations\Models\Format::all()->where('style', 'like', 'ieee');
         }
         // get the name of the current format (see if it's custom)
         // the name of the custom format
         $name = "custom-member-" . $this->member->get('uidNumber');
         $custom = \Components\Citations\Models\Format::all()->where('style', 'LIKE', $name)->count();
         if ($custom > 0) {
             // show the menu entry for the custom
             $view->customFormat = true;
         } else {
             // show menu item for new custom format
             $view->customFormat = false;
         }
         // get formats
         $view->formats = \Components\Citations\Models\Format::all()->where('style', 'NOT LIKE', '%custom-member-%')->where('style', 'NOT LIKE', '%custom-group-%')->orWhere('style', '=', $name)->rows()->toObject();
         $view->templateKeys = \Components\Citations\Models\Format::all()->getTemplateKeys();
         // Output HTML
         foreach ($this->getErrors() as $error) {
             $view->setError($error);
         }
         return $view->loadTemplate();
     }
 }
Ejemplo n.º 6
0
 /**
  * Settings for group citations
  *
  * @param null
  * @return void
  *
  *
  */
 private function _settings()
 {
     if ($_POST) {
         $display = Request::getVar('display', '');
         $format = Request::getVar('citation-format', '');
         $params = json_decode($this->group->get('params'));
         if (!is_object($params)) {
             $params = new stdClass();
         }
         // craft a clever name
         $name = "custom-group-" . $this->group->cn;
         // fetch or create new format
         $citationFormat = \Components\Citations\Models\Format::oneOrNew($format);
         // if the setting a custom group citation type
         if ($citationFormat->isNew() || $citationFormat->style == $name && !$citationFormat->isNew()) {
             $citationFormat->set(array('format' => Request::getVar('template'), 'style' => $name));
             // save format
             $citationFormat->save();
             // update group
             $params->citationFormat = $citationFormat->id;
         } else {
             // returned value from format select box
             $params->citationFormat = $format;
         }
         // more parameters for citations
         $params->display = Request::getVar('display', '');
         $params->include_coins = Request::getVar('include_coins', '');
         $params->coins_only = Request::getVar('coins_only', '');
         $params->citations_show_tags = Request::getVar('citations_show_tags', '');
         $params->citations_show_badges = Request::getVar('citations_show_badges', '');
         // update the group parameters
         $gParams = new Registry($params);
         $gParams->merge($params);
         $this->group->set('params', $gParams->toString());
         $this->group->update();
         // redirect after save
         App::redirect(Route::url('index.php?option=com_groups&cn=' . $this->group->cn . '&active=citations'), Lang::txt('PLG_GROUPS_CITATIONS_SETTINGS_SAVED'), 'success');
         return;
     } else {
         // instansiate the view
         $view = $this->view('default', 'settings');
         // pass the group through
         $view->group = $this->group;
         // get group settings
         $params = json_decode($this->group->get('params'));
         $view->include_coins = isset($params->include_coins) ? $params->include_coins : "false";
         $view->coins_only = isset($params->coins_only) ? $params->coins_only : "false";
         $view->citations_show_tags = isset($params->citations_show_tags) ? $params->citations_show_tags : "true";
         $view->citations_show_badges = isset($params->citations_show_badges) ? $params->citations_show_badges : "true";
         $citationsFormat = isset($params->citationFormat) ? $params->citationFormat : 1;
         // intended for the case that the group's custom
         // format is removed from the jos_citations_format
         try {
             $view->currentFormat = \Components\Citations\Models\Format::oneOrFail($citationsFormat);
         } catch (\Exception $e) {
             $view->currentFormat = \Components\Citations\Models\Format::all()->where('style', 'like', 'ieee');
         }
         // get the name of the current format (see if it's custom)
         // the name of the custom format
         $name = "custom-group-" . $this->group->cn;
         $custom = \Components\Citations\Models\Format::all()->where('style', 'LIKE', $name)->count();
         if ($custom > 0) {
             // show the menu entry for the custom
             $view->customFormat = true;
         } else {
             // show menu item for new custom format
             $view->customFormat = false;
         }
         // get formats
         $view->formats = \Components\Citations\Models\Format::all()->where('style', 'NOT LIKE', '%custom-group-%')->where('style', 'NOT LIKE', '%custom-member-%')->orWhere('style', '=', $name)->rows()->toObject();
         $view->templateKeys = \Components\Citations\Models\Format::all()->getTemplateKeys();
         // Output HTML
         foreach ($this->getErrors() as $error) {
             $view->setError($error);
         }
         return $view->loadTemplate();
     }
 }