'openaire.log'), JLog :: ALL, array('openaire')); if(!class_exists("Predis\Client")){ require $GLOBALS['PREDIS_ROOT'] . DS ."autoload.php"; } try { //Predis\Autoloader::register(); $this->cache = new Predis\Client(array( "scheme" => $this->params->get('cachescheme'), "host" => $this->params->get('cacheserver'), "port" => $this->params->get('cacheport'))); $this->cache->connect(); } catch(Exception $e) { JLog :: add("Error connecting to Redis server: ".$e->getMessage(), JLog :: ERROR, 'openaire'); $this->cache = null; } /*OVERALL*/ /*1*/ $this->codes[] = "{include_number PUBS}"; /*2*/ $this->codes[] = "{include_number OAPUBS}"; /*3*/ $this->codes[] = "{include_number NOAPUBS}"; /*4*/ $this->codes[] = "{include_number FPUBS}"; /*5*/ $this->codes[] = "{include_number PROJ}"; /*6*/ $this->codes[] = "{include_number DATASRC}"; /*7*/ $this->codes[] = "{include_number DATASRC-PUBS}"; /*8*/ $this->codes[] = "{include_number DATASRC-PUBREPS}"; /*9*/ $this->codes[] = "{include_number DATASRC-PUBOAJ}"; /*10*/$this->codes[] = "{include_number DATASRC-PUBAGGR}"; /*11*/$this->codes[] = "{include_number FUNDERS}"; /*FOR FP7*/ /*12*/$this->codes[] = "{include_number FP7PUBSTOTAL}"; /*13*/$this->codes[] = "{include_number FP7PROJPUBS}"; /*14*/$this->codes[] = "{include_number FP7PROJTOTAL}"; /*15*/$this->codes[] = "{include_number FP7OAPUBS}"; /*16*/$this->codes[] = "{include_number FP7RESPUBS}"; /*17*/$this->codes[] = "{include_number FP7EMBPUBS}"; /*18*/$this->codes[] = "{include_number SC39FP7PUBSTOTAL}"; /*19*/$this->codes[] = "{include_number SC39FP7PROJPUBS}"; /*20*/$this->codes[] = "{include number SC39FP7PROJTOTAL}"; /*21*/$this->codes[] = "{include_number SC39FP7OAPUBS}"; /*ERC*/ /*22*/$this->codes[] = "{include_number ERCPUBSTOTAL}"; /*23*/$this->codes[] = "{include_number ERCPROJPUBS}"; /*24*/$this->codes[] = "{include_number ERCPROJTOTAL}"; /*25*/$this->codes[] = "{include_number ERCOAPUBS}"; /*26*/$this->codes[] = "{include_number ERCRESPUBS}"; /*27*/$this->codes[] = "{include_number ERCEMBPUBS}"; /*WT*/ /*28*/$this->codes[] = "{include_number WTPUBSTOTAL}"; /*29*/$this->codes[] = "{include_number WTPROJPUBS}"; /*30*/$this->codes[] = "{include_number WTPROJTOTAL}"; /*31*/$this->codes[] = "{include_number WTOAPUBS}"; /*32*/$this->codes[] = "{include_number WTRESPUBS}"; /*33*/$this->codes[] = "{include_number WTEMBPUBS}"; // Latest Natalias requests /*34*/$this->codes[] = "{include_number DATASRC-WITHPUBS}"; /*35*/$this->codes[] = "{include_number ORG-WITHPUBS}"; /*36*/$this->codes[] = "{include_number DATA-TOTAL}"; // FET nums /*37*/$this->codes[] = "{include_number FETPUBS}"; /*38*/$this->codes[] = "{include_number FETOAPUBS}"; /*39*/$this->codes[] = "{include_number FETRESPUBS}"; /*40*/$this->codes[] = "{include_number FETEMBPUBS}"; // DATASETS /*41*/$this->codes[] = "{include_number DATASETPUBS}"; /*42*/$this->codes[] = "{include_number DATASETPROJ}"; /*43*/$this->codes[] = "{include_number PUBSDATASETS}"; // EGI NUMS /*44*/$this->codes[] = "{include_number EGIPUBS}"; /*45*/$this->codes[] = "{include_number EGIVO}"; /*46*/$this->codes[] = "{include_number EGIPROJ}"; // EGI NUMS /*47*/$this->codes[] = "{include_number EGIOA}"; /*48*/$this->codes[] = "{include_number EGIEMB}"; /*49*/$this->codes[] = "{include_number EGIRES}"; /*ERC*/ /*50*/$this->codes[] = "{include_number FCTPUBSTOTAL}"; /*51*/$this->codes[] = "{include_number FCTPROJPUBS}"; /*52*/$this->codes[] = "{include_number FCTPROJTOTAL}"; /*53*/$this->codes[] = "{include_number FCTOAPUBS}"; /*54*/$this->codes[] = "{include_number FCTRESPUBS}"; /*55*/$this->codes[] = "{include_number FCTEMBPUBS}"; JLog :: add('Include number Plugin!', JLog :: DEBUG, 'openaire'); } public function onContentPrepare( $context, &$article, &$params, $page = 0 ) { $regex_base = '\{(include_number)\s+(PUBS|OAPUBS|NOAPUBS|FPUBS|PROJ|DATASRC|DATASRC-PUBS|DATASRC-PUBREPS|DATASRC-PUBOAJ|DATASRC-PUBAGGR|FUNDERS|FP7PUBSTOTAL|FP7PROJPUBS|FP7PROJTOTAL|FP7OAPUBS|FP7RESPUBS|FP7EMBPUBS|SC39FP7PUBSTOTAL|SC39FP7PROJPUBS|SC39FP7PROJTOTAL|SC39FP7OAPUBS|ERCPUBSTOTAL|ERCPROJTOTAL|ERCPROJPUBS|ERCOAPUBS|ERCRESPUBS|ERCEMBPUBS|WTPUBSTOTAL|WTPROJPUBS|WTPROJTOTAL|WTOAPUBS|WTRESPUBS|WTEMBPUBS|DATASRC-WITHPUBS|ORG-WITHPUBS|DATA-TOTAL|FETPUBS|FETOAPUBS|FETRESPUBS|FETEMBPUBS|DATASETPUBS|DATASETPROJ|PUBSDATASETS|EGIPUBS|EGIVO|EGIPROJ|EGIOA|EGIEMB|EGIRESERCPUBSTOTAL|FCTPROJTOTAL|FCTPROJPUBS|FCTOAPUBS|FCTRESPUBS|FCTEMBPUBS)\}'; $regex = "/$regex_base/"; $contents = $article->text; $found = preg_match_all($regex, $contents, $matches); if (!$found){ return true;} try { $str = 'pgsql:host='.$this->params->get('dbhost').';port='.$this->params->get('dbport').';dbname='.$this->params->get('dbname').';user='.$this->params->get('dbuser').';password='.$this->params->get('dbpass'); $this->db = new PDO($str); } catch(Exception $e){ JLog :: add('Could not connect to database: ' . $e->getMessage(), JLog :: ERROR, 'openaire'); return false; } $cnt = count($matches); JLog :: add( "matches found: ".$cnt, JLog :: DEBUG, 'openaire'); $result = NULL; if ($this -> cache != null) { if($this->cache->exists("STATS_NUMBERS")) { $result = $this -> cache -> hgetall("STATS_NUMBERS"); JLog :: add("Found in cache!", JLog :: DEBUG, 'openaire'); } else { $this->cache->quit(); JLog :: add("Not found in cache!", JLog :: DEBUG, 'openaire'); $result = $this->makequeries(true); } } else {//make the queries but don't cache the result $result = $this->makequeries(false); } $article->text = str_replace($this->codes, $result, $article->text); return true; } private function makequeries($addflag){ JLog :: add("Not found in cache!", JLog :: DEBUG, 'openaire'); $temp = array(); /*OVERALL*/ /*1*/ $qpubs = "SELECT count(*) FROM result where type='publication'"; /*2*/ $qoapubs = "SELECT count(*) FROM result WHERE access_mode='Open Access' and type='publication'"; /*3*/ $qnoapubs = "SELECT count(*) FROM result WHERE access_mode='Closed Access' and type='publication'"; /*4*/ $qfpubs = "SELECT count(distinct result_projects.id) FROM result, result_projects where result.result_projects = result_projects.id and type='publication'"; /*5*/ $qproj = "SELECT count(*) FROM project"; /*6*/ $qdatasrc = "SELECT count(*) FROM datasource"; /*7*/ $qdtsrcpubs = "SELECT count(*) from datasource where compatibility!='non compatible' and compatibility!='unknown'"; /*8*/ $qdtsrcpubreps = "SELECT count(*) FROM datasource WHERE type='Repository'"; /*9*/ $qdtsrcoaj = "SELECT count(*) FROM datasource WHERE type='Aggregated Journal'"; /*10*/$qdtsrcpubaggr = "SELECT count(*) FROM datasource WHERE type='Aggregated Repository'"; /*11*/$qfunders = "SELECT count(distinct funding_lvl0) FROM project WHERE funding_lvl0 !=''"; /*FP7*/ /*12: total number of fp7 pubs */ $qfp7pubstotal = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects = result_projects.id and type='publication' and result_projects.project = project.id and funding_lvl0 = 'FP7'"; /*13: number of fp7 projects with publications*/ $qfp7projpubs = "SELECT count(distinct project.id) FROM result, result_projects, project WHERE result.result_projects = result_projects.id and type='publication' and result_projects.project = project.id and funding_lvl0='FP7'"; /*14: total number of fp7 projects*/ $qfp7projtotal = "SELECT count(id) FROM project WHERE funding_lvl0 = 'FP7'"; /*15: fp7 open access pubs*/ $qfp7oapubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result_projects = result_projects.id AND result_projects.project = project.id and type='publication' and funding_lvl0 = 'FP7' and access_mode='Open Access'"; /*16: fp7 restricted pubs*/ $qfp7respubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects=result_projects.id AND result_projects.project = project.id and funding_lvl0 = 'FP7' and access_mode='Restricted' and type='publication'"; /*17: fp7 pubs in embargo*/ $qfp7embpubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects = result_projects.id AND result_projects.project = project.id and funding_lvl0 = 'FP7' and access_mode='Embargo' and type='publication'"; /*18: total number of fp7 pubs with sc39*/ $qsc39fp7pubstotal = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result_projects.project = project.id and funding_lvl0 = 'FP7' and sc39='yes' and result.result_projects = result_projects.id and type='publication'"; /*19: fp7 projs with sc39 and pubs*/ $qsc39fp7projpubs = "SELECT count(distinct project.id) FROM result, result_projects, project WHERE result_projects.project=project.id and funding_lvl0 = 'FP7' and sc39='yes' and result.result_projects = result_projects.id and type='publication'"; /*20: total number of fp7 proj with sc39*/ $qsc39fp7projtotal = "SELECT count(number) from project where funding_lvl0='FP7' and sc39='yes'"; /*21: open access fp7 pubs with sc39*/ $qsc39fp7oapubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects = result_projects.id AND result_projects.project = project.id and funding_lvl0 = 'FP7' and access_mode='Open Access' and sc39='yes' and type='publication'"; /*ERC*/ /*22: total number of erc pubs*/ $qercpubstotal = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result_projects.project = project.id and funding_lvl2 = 'ERC' and result.result_projects = result_projects.id and type='publication'"; /*23: erc projects with pubs*/ $qercprojpubs = "SELECT count(distinct project.id) FROM result, project, result_projects where result_projects.project = project.id and project.funding_lvl2='ERC' and result.result_projects = result_projects.id and type='publication'"; /*24: total erc projects*/ $qercprojtotal = "SELECT count(id) FROM project WHERE funding_lvl2 = 'ERC'"; /*25: erc open access pubs*/ $qercoapubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects= result_projects.id AND result_projects.project = project.id and funding_lvl2 = 'ERC' and access_mode='Open Access' and type='publication'"; /*26: erc restricted pubs*/ $qercrespubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects = result_projects.id AND result_projects.project = project.id and funding_lvl2 = 'ERC' and access_mode='Restricted' and type='publication'"; /*27: erc embargo pubs*/ $qercembpubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects=result_projects.id AND result_projects.project = project.id and funding_lvl2 = 'ERC' and access_mode='Embargo' and type='publication'"; /*WT*/ /*28: total number of wt pubs*/ $qwtpubstotal = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result_projects.project = project.id and funding_lvl0 = 'WT' and result.result_projects = result_projects.id and type='publication'"; /*29: wt projects with pubs*/ $qwtprojpubs = "SELECT count(distinct project.id) FROM result, project, result_projects where result_projects.project = project.id and project.funding_lvl0='WT' and result.result_projects = result_projects.id and type='publication'"; /*30: total wt projects*/ $qwtprojtotal = "SELECT count(id) FROM project WHERE funding_lvl0 = 'WT'"; /*31: wt open access pubs*/ $qwtoapubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects= result_projects.id AND result_projects.project = project.id and funding_lvl0 = 'WT' and access_mode='Open Access' and type='publication'"; /*32: wt restricted pubs*/ $qwtrespubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects = result_projects.id AND result_projects.project = project.id and funding_lvl0 = 'WT' and access_mode='Restricted' and type='publication'"; /*33: wt embargo pubs*/ $qwtembpubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects=result_projects.id AND result_projects.project = project.id and funding_lvl0 = 'WT' and access_mode='Embargo' and type='publication'"; /*Natalia's extra stuff */ /*34: datasources with publication results */ $datasrc_withpubs = "SELECT count(distinct rd.datasource) from result_datasources rd join result r on r.id=rd.id where r.type='publication'"; /*35: organisations with publication results */ $org_withpubs = "select count(*) from (select dor.organization as organization from datasource_organizations dor join result_datasources rd on rd.datasource=dor.id join result r on r.id=rd.id where r.type='publication' union select por.organization as organization from project_organizations por join result_projects rp on rp.project=por.id join result r on r.id=rp.id where r.type='publication') as foo"; /*36: number of datasets */ $data_total = "select count(distinct id) from result where type='dataset';"; /*FET */ $fetpubs ="select count(distinct rc.id) as field0 from result_concepts rc join concept c on c.id=rc.concept join category cat on cat.id=c.category where cat.context ='fet'"; $fetoapubs ="select count(distinct rc.id) as field0 from result_concepts rc join result r on r.id=rc.id join concept c on c.id=rc.concept join category cat on cat.id=c.category where cat.context ='fet' and r. bestlicense='Open Access'"; $fetrespubs ="select count(distinct rc.id) as field0 from result_concepts rc join result r on r.id=rc.id join concept c on c.id=rc.concept join category cat on cat.id=c.category where cat.context ='fet' and r. bestlicense='Restricted'"; $fetembpubs ="select count(distinct rc.id) as field0 from result_concepts rc join result r on r.id=rc.id join concept c on c.id=rc.concept join category cat on cat.id=c.category where cat.context ='fet' and r. bestlicense='Embargo'"; /*DATASETS */ $datasetpubs= "select count(distinct r.id) from result r join result_results rr on rr.id=r.id join result rp on rp.id=rr.result where r.type='dataset' and rp.type='publication'" ; //# of datasets linked to projects $datasetproj="select count(distinct r.id) from result r join result_projects rp on rp.id=r.id join project p on p.id=rp.project where r.type='dataset' "; //# of publications linked to datasets $pubsdatasets ="select count(distinct r.id) from result r join result_results rr on rr.id=r.id join result rp on rp.id=rr.result where r.type='publication' and rp.type='dataset'"; /*EGI PAGE NUMS*/ $egivo="select count(distinct c.name) as field0 from result_concepts rc join concept c on c.id=rc.concept join category cat on cat.id=c.category where cat.id='egi::virtual'"; $egiproj="select count(distinct c.name) as field0 from result_concepts rc join concept c on c.id=rc.concept join category cat on cat.id=c.category where cat.id='egi::projects' "; $egipubs= " select count( distinct rc.id) as field0 from result r,result_concepts rc, concept con, category cat where rc.id=r.id and con.id=rc.concept and con.category= cat.id and cat.context ='egi'"; $egioa="select count(distinct r.id) as field0 from result r join result_concepts rc on r.id=rc.id join concept c on c.id=rc.concept where bestlicense='Open Access'"; $egiemb="select count(distinct r.id) as field0 from result r join result_concepts rc on r.id=rc.id join concept c on c.id=rc.concept where bestlicense='Embargo'"; $egires="select count(distinct r.id) as field0 from result r join result_concepts rc on r.id=rc.id join concept c on c.id=rc.concept where bestlicense='Restricted'"; /* FCT*/ /*FCT*/ /*22: total number of FCTpubs*/ $qfctpubstotal = "SELECT count( distinct result.id) FROM result, project, result_projects where result_projects.project = project.id and project.funding_lvl0='FCT' and result.result_projects = result_projects.id and result.type='publication'"; /*23: FCTprojects with pubs*/ $qfctprojpubs = "SELECT count(distinct project.id) FROM result, project, result_projects where result_projects.project = project.id and project.funding_lvl0='FCT' and result.result_projects = result_projects.id and type='publication'"; /*24: total FCTprojects*/ $qfctprojtotal = "SELECT count(id) FROM project WHERE funding_lvl0 = 'FCT'"; /*25: FCTopen access pubs*/ $qfctoapubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects= result_projects.id AND result_projects.project = project.id and funding_lvl0 = 'FCT' and bestlicense='Open Access' and type='publication'"; /*26: FCTrestricted pubs*/ $qfctrespubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects = result_projects.id AND result_projects.project = project.id and funding_lvl0 = 'FCT' and bestlicense='Restricted' and type='publication'"; /*27: FCTembargo pubs*/ $qfctembpubs = "SELECT count(distinct result_projects.id) FROM result, result_projects, project WHERE result.result_projects=result_projects.id AND result_projects.project = project.id and funding_lvl0 = 'FCT' and bestlicense='Embargo' and type='publication'"; /*FCT*/ /*22*/$temp['fctpubstotal'] = $this->doQuery($qfctpubstotal); /*23*/$temp['fctprojpubs'] = $this->doQuery($qfctprojpubs); /*24*/$temp['fctprojtotal'] = $this->doQuery($qfctprojtotal); /*25*/$temp['fctoapubs'] = $this->doQuery($qfctoapubs); /*26*/$temp['fctrespubs'] = $this->doQuery($qfctrespubs); /*27*/$temp['fctembpubs'] = $this->doQuery($qfctembpubs); /*1*/ $temp['pubs'] = $this->doQuery($qpubs); /*2*/ $temp['oapubs'] = $this->doQuery($qoapubs); /*3*/ $temp['noapubs'] = $this->doQuery($qnoapubs); /*4*/ $temp['fpubs'] = $this->doQuery($qfpubs); /*5*/ $temp['proj'] = $this->doQuery($qproj); /*6*/ $temp['datasrc'] = $this->doQuery($qdatasrc); /*7*/ $temp['dtsrcpubs'] = $this->doQuery($qdtsrcpubs); /*8*/ $temp['dtsrcpubreps'] = $this->doQuery($qdtsrcpubreps); /*9*/ $temp['dtsrcoaj'] = $this->doQuery($qdtsrcoaj); /*10*/$temp['dtsrcpubaggr'] = $this->doQuery($qdtsrcpubaggr); /*11*/$temp['funders'] = $this->doQuery($qfunders); /*FP7*/ /*12*/$temp['fp7pubstotal'] = $this->doQuery($qfp7pubstotal); /*13*/$temp['fp7projpubs'] = $this->doQuery($qfp7projpubs); /*14*/$temp['fp7projtotal'] = $this->doQuery($qfp7projtotal); /*15*/$temp['fp7oapubs'] = $this->doQuery($qfp7oapubs); /*16*/$temp['fp7respubs'] = $this->doQuery($qfp7respubs); /*17*/$temp['fp7embpubs'] = $this->doQuery($qfp7embpubs); /*18*/$temp['sc39fp7pubstotal'] = $this->doQuery($qsc39fp7pubstotal); /*19*/$temp['sc39fp7projpubs'] = $this->doQuery($qsc39fp7projpubs); /*20*/$temp['sc39fp7projtotal'] = $this->doQuery($qsc39fp7projtotal); /*21*/$temp['sc39fp7oapubs'] = $this->doQuery($qsc39fp7oapubs); /*ERC*/ /*22*/$temp['ercpubstotal'] = $this->doQuery($qercpubstotal); /*23*/$temp['ercprojpubs'] = $this->doQuery($qercprojpubs); /*24*/$temp['ercprojtotal'] = $this->doQuery($qercprojtotal); /*25*/$temp['ercoapubs'] = $this->doQuery($qercoapubs); /*26*/$temp['ercrespubs'] = $this->doQuery($qercrespubs); /*27*/$temp['ercembpubs'] = $this->doQuery($qercembpubs); /*WT*/ /*28*/$temp['wtpubstotal'] = $this->doQuery($qwtpubstotal); /*29*/$temp['wtprojpubs'] = $this->doQuery($qwtprojpubs); /*30*/$temp['wtprojtotal'] = $this->doQuery($qwtprojtotal); /*31*/$temp['wtoapubs'] = $this->doQuery($qwtoapubs); /*32*/$temp['wtrespubs'] = $this->doQuery($qwtrespubs); /*33*/$temp['wtembpubs'] = $this->doQuery($qwtembpubs); /*34*/$temp['datasrc_withpubs'] = $this->doQuery($datasrc_withpubs); /*35*/$temp['org_withpubs'] = $this->doQuery($org_withpubs); /*36*/$temp['data_total'] = $this->doQuery($data_total); //FET NUMS /*37*/$temp['fetpubs'] = $this->doQuery($fetpubs); /*38*/$temp['fetoapubs'] = $this->doQuery($fetoapubs); /*39*/$temp['fetrespubs'] = $this->doQuery($fetrespubs); /*40*/$temp['fetembpubs'] = $this->doQuery($fetembpubs); /*41*/$temp['datasetpubs'] = $this->doQuery($datasetpubs); /*42*/$temp['datasetproj'] = $this->doQuery($datasetproj); /*43*/$temp['pubsdatasets'] = $this->doQuery($pubsdatasets); /*44*/$temp['egivo'] = $this->doQuery($egivo); /*45*/$temp['egiproj'] = $this->doQuery($egiproj); /*46*/$temp['egipubs'] = $this->doQuery($egipubs); /*44*/$temp['egioa'] = $this->doQuery($egioa); /*45*/$temp['egiemb'] = $this->doQuery($egiemb); /*46*/$temp['egires'] = $this->doQuery($egires); if($addflag){ JLog:: add("params to store: ".print_r($temp, TRUE), JLog :: ERROR, 'openaire'); $this->cache = new Predis\Client(array( "scheme" => $this->params->get('cachescheme'), "host" => $this->params->get('cacheserver'), "port" => $this->params->get('cacheport'))); $this->cache->connect(); $this->cache->hmset("STATS_NUMBERS", $temp); $this->cache->save(); $this->cache->quit(); } return $temp; } private function doQuery($query){ $stmt = $this->db->query($query); if(!$stmt){ $arr = $this->db->errorInfo(); JLog :: add("Error executing query: ".$query." ".$arr[2], JLog :: ERROR, 'openaire'); return "-"; } $t = $stmt->fetch(); return number_format($t[0]); } } ?>