[Fusionforge-commits] FusionForge branch master updated. v6.0.3-424-gd8bf8d0

Franck Villaume nerville at libremir.placard.fr.eu.org
Mon Mar 21 20:26:26 CET 2016


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "FusionForge".

The branch, master has been updated
       via  d8bf8d0e1a2a0d21fed26a8737bcfec77cfa08ab (commit)
      from  7121949fb3de0b34a6bf73b03d17e80b5c633471 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://scm.fusionforge.org/anonscm/gitweb/?p=fusionforge/fusionforge.git;a=commitdiff;h=d8bf8d0e1a2a0d21fed26a8737bcfec77cfa08ab

commit d8bf8d0e1a2a0d21fed26a8737bcfec77cfa08ab
Author: Franck Villaume <franck.villaume at trivialdev.com>
Date:   Mon Mar 21 20:25:58 2016 +0100

    plugin globalsearch: remove old pl script. add forge home widget

diff --git a/src/plugins/globalsearch/bin/get_assoc_sites_project.php b/src/plugins/globalsearch/bin/get_assoc_sites_project.php
new file mode 100755
index 0000000..d9c8f00
--- /dev/null
+++ b/src/plugins/globalsearch/bin/get_assoc_sites_project.php
@@ -0,0 +1,53 @@
+#! /usr/bin/php
+<?php
+/**
+ * Copyright 2016, Franck Villaume - TrivialDev
+ *
+ * This file is a part of FusionForge.
+ *
+ * FusionForge is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * FusionForge is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with FusionForge. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+require dirname(__FILE__).'/../../env.inc.php';
+require_once $gfcommon.'include/pre.php';
+require_once $gfcommon.'common/include/utils.php';
+
+$res = db_query_params('SELECT assoc_site_id, title, link, onlysw, status_id, rank
+			FROM plugin_globalsearch_assoc_site WHERE enabled=$1 ORDER BY rank', array('t'));
+
+if ($res && db_numrows($res)) {
+	while ($arr = db_fetch_array($res)) {
+		$link = $arr['link'];
+		$filename = $link.'/export/rss_sfprojects.php?showall=1';
+		$simpleXmlLoadedFile = simplexml_load_file($filename);
+		$res2 = db_query_params('DELETE FROM plugin_globalsearch_assoc_site_project WHERE assoc_site_id=$1', array($arr['assoc_site_id']));
+		if ($simpleXmlLoadedFile !== false) {
+			$xmlObjectsArray = $simpleXmlLoadedFile->channel->item;
+			foreach ($xmlObjectsArray as $key => $xmlObject) {
+				$title = (string)$xmlObject->title;
+				$projectsubLink = (string)$xmlObject->link;
+				if ($projectsubLink[0] == '/') {
+					$projectsubLink = substr($projectsubLink, 1);
+				}
+				$projectLink = $link.$projectsubLink;
+				$description = htmlentities((string)$xmlObject->description);
+				$res2 = db_query_params('INSERT INTO plugin_globalsearch_assoc_site_project (assoc_site_id, project_title, project_link, project_description) '.
+							'VALUES ($1, $2, $3, $4)', array($arr['assoc_site_id'], $title, $projectLink, $description));
+			}
+			$res2 = db_query_params('UPDATE plugin_globalsearch_assoc_site SET status_id=$1 WHERE assoc_site_id=$2', array(2, $arr['assoc_site_id']));
+		} else {
+			$res2 = db_query_params('UPDATE plugin_globalsearch_assoc_site SET status_id=$1 WHERE assoc_site_id=$2', array(4, $arr['assoc_site_id']));
+		}
+	}
+}
diff --git a/src/plugins/globalsearch/bin/get_assoc_sites_projects.pl b/src/plugins/globalsearch/bin/get_assoc_sites_projects.pl
deleted file mode 100755
index f2530e3..0000000
--- a/src/plugins/globalsearch/bin/get_assoc_sites_projects.pl
+++ /dev/null
@@ -1,202 +0,0 @@
-#!/usr/bin/perl -w
-#
-# get_assoc_sites_projects.pl: script to get the projects of 
-#   sites associated, to try to make a ring of gforges sindicates
-#   by Vicente J. Ruiz Jurado (vjrj AT ourproject.org) Mar-2004
-#
-# depends: libgetopt-mixed-perl (Getopt::Long), libdbi-perl (DBI),
-#          libxml-rss-perl (XML::RSS), libwww-perl (LWP::Simple),
-#          libcrypt-ssleay-perl (for https sites),
-#          libunicode-string-perl (Unicode::String)
-#
-use DBI;
-use Getopt::Long qw(:config require_order);
-use XML::RSS;
-use LWP::UserAgent ;
-use Unicode::String qw(latin1 utf8);
-
-use strict;
-
-my $source_path = `forge_get_config source_path`;
-chomp $source_path;
-
-require ("$source_path/lib/include.pl") ; # Include all the predefined functions 
-
-# DB 
-#-------------------------------------------------------------------------------
-use vars qw/ $dbh / ; # Predeclaration of global vars
-
-# Variables
-#-------------------------------------------------------------------------------
-
-my $numArgs = @ARGV;
-my @args = @ARGV;
-
-sub usage();
-sub changeSiteStatus($$);
-sub deleteProjectsOfSite($);
-sub myescape($);
-
-
-my $debug;
-my $debugsql;
-my $assoc_site;
-my @results_array;
-my ($projecttitle, $projectlink, $projectdesc);
-
-my $ua = new LWP::UserAgent ;
-# Default get timeout to 30 seconds
-$ua->timeout(30);
-$ua->env_proxy ;
-
-# Options check
-#-------------------------------------------------------------------------------
-
-my $resultOptions = GetOptions(
-"debug" => \$debug,
-"debugsql" => \$debugsql
-);
-
-unless (($debug && $resultOptions == 2) || 
-                                ($debugsql && $resultOptions == 2) || 
-                                (($debug) && ($debugsql) && $resultOptions == 3) || 
-                                ($resultOptions == 1)) {
-        usage();
-        exit(1);
-}
-
-# Start to get de RSS
-#-------------------------------------------------------------------------------
-
-if ($debug) {print STDERR "Getting the associated sites.\n"};
-
-&db_connect;
-$dbh->{AutoCommit} = 0;
-$dbh->{RaiseError} = 1;
-
-my $query = "SELECT assoc_site_id, title, link, onlysw, status_id, rank 
-        FROM plugin_globalsearch_assoc_site WHERE enabled='t' ORDER BY rank";
-
-my $sth = $dbh->prepare($query);
-$sth->execute();
-
-while (my @array = $sth->fetchrow_array ()) {
-        push @results_array, \@array ;
-}
-$sth->execute() or die "Problems with the query '$query' in DB";
-$sth->finish() or die "Problems with the query '$query' in DB";
-$dbh->commit or die $dbh->errstr;
-
-foreach $assoc_site (@results_array) {
-        my ($assoc_site_id, $title, $link, $onlysw, $enabled, $status_id, $rank) = @{$assoc_site};
-        my $urlrss = $link."/export/rss_sfprojects.php?showall=1";
-        my $response = $ua->get($urlrss);
-	
-        if ($response->is_success) {
-   	        my $content = $response->content ;
-                # Correct RSS get
-                if ($debug) {print STDERR "$title get ok.\n"};
-
-                my $rss = new XML::RSS (version => '0.91', encoding => "UTF-8");
-
-                eval {$rss->parse($content);}; 
-                if ($@) {
-                        # Parse error
-                        if ($debug) {print STDERR "ERROR parsing $title.\n"};
-
-                        # Site in db to status unparsable
-                        changeSiteStatus($assoc_site_id, 4);
-                        deleteProjectsOfSite($assoc_site_id);
-                }
-                else {
-                        # Parse ok
-                        deleteProjectsOfSite($assoc_site_id);
-                        # Insert projects in db
-                        if ($debug) {print STDERR "Inserting site $title projects\n"};
-                        foreach my $item (@{$rss->{'items'}}) {
-                                next unless (defined($item->{'title'}) && defined($item->{'link'}) && defined($item->{'description'}));
-                                # utf8 checking
-                                $projecttitle = myescape(utf8($item->{'title'}));
-                                $projectlink = myescape(utf8($item->{'link'}));
-                                $projectdesc = myescape(utf8($item->{'description'}));
-
-                                my $insert = "INSERT INTO plugin_globalsearch_assoc_site_project ".
-                                        "(assoc_site_id, project_title, project_link, project_description) ".
-                                        "VALUES ('$assoc_site_id','$projecttitle','$projectlink','$projectdesc')";
-
-                                if ($debugsql) {print STDERR "SQL: $insert\n"};
-
-                                my $sth = $dbh->prepare($insert);
-                                $sth->execute() or die "Problems with the insert of '$insert' in DB";
-                                $sth->finish() or die "Problems with the insert of '$insert' in DB";
-                                $dbh->commit or die $dbh->errstr;                                
-                        }
-
-                        # Site in db to status ok
-                        changeSiteStatus($assoc_site_id, 2);
-                }
-        }
-        else {
-                # Incorrect RSS get
-                if ($debug) {
-		    print STDERR "$urlrss get fail:\n" ;
-		    print STDERR $response->status_line()."\n" ;
-		};
-
-                # RSS in db to status fail
-                changeSiteStatus($assoc_site_id, 3);
-                deleteProjectsOfSite($assoc_site_id);
-        }
-}
-
-if ($debug) {print STDERR "get_assoc_sites_projects process finished ok\n"};
-exit(0);
-
-# Funcitions
-#-------------------------------------------------------------------------------
-
-sub usage() {
-        print STDERR "usage: get_assoc_sites_projects.pl [--debug] [--debugsql]\n";
-}
-
-
-sub changeSiteStatus($$) {
-        my $site = shift;
-        my $status = shift;
-
-        my $update = "UPDATE plugin_globalsearch_assoc_site SET status_id='$status' WHERE assoc_site_id='$site'";
-
-        if ($debugsql) {print STDERR "SQL: $update\n"};
-        my $sth = $dbh->prepare($update);
-        $sth->execute() or die "Problems with the update of '$update' in DB";
-        $sth->finish() or die "Problems with the update of '$update' in DB";
-        $dbh->commit or die $dbh->errstr;
-
-        return 0;
-}
-
-
-sub deleteProjectsOfSite($) {
-        my $site = shift;
-
-        if ($debug) {print STDERR "Deleting the projects of site $site.\n"};
-
-        my $delete = "DELETE FROM plugin_globalsearch_assoc_site_project WHERE assoc_site_id='$site'";
-
-        if ($debugsql) {print STDERR "SQL: $delete\n"};
-
-        my $sth = $dbh->prepare($delete);
-        $sth->execute() or die "Problems with the delete of '$delete' in DB";
-        $sth->finish() or die "Problems with the delete of '$delete' in DB";
-        $dbh->commit or die $dbh->errstr;
-
-        return 0;
-}
-
-sub myescape($) {
-        my $stringtoesc = shift;
-  $stringtoesc =~ s/'/''/g;
-  $stringtoesc =~ s/\\/\\\\/g;
-
-        return $stringtoesc;
-}
diff --git a/src/plugins/globalsearch/common/GlobalsearchPlugin.class.php b/src/plugins/globalsearch/common/GlobalsearchPlugin.class.php
index 8381bc8..5bc3d5f 100644
--- a/src/plugins/globalsearch/common/GlobalsearchPlugin.class.php
+++ b/src/plugins/globalsearch/common/GlobalsearchPlugin.class.php
@@ -35,6 +35,8 @@ declare a list of other FusionForge sites, and search for projects
 hosted on these forges from your own.");
 		$this->_addHook('site_admin_option_hook');
 		$this->_addHook('features_boxes_top');
+		$this->_addHook('widget_instance');
+		$this->_addHook('widgets');
 	}
 
 	function CallHook($hookname, &$params) {
@@ -76,7 +78,7 @@ hosted on these forges from your own.");
 		global $HTML, $gwords, $gexact, $otherfreeknowledge;
 
 		$return = $HTML->openForm(array('action' => '/plugins/globalsearch/', 'method' => 'post'));
-		$return .= $HTML->html_text_input_img_submit('gwords', 'magnifier.png', 'search_associated_forges', '', $gwords, _('Search associated forges'));
+		$return .= $HTML->html_text_input_img_submit('gwords', 'magnifier20.png', 'search_associated_forges', '', $gwords, _('Search associated forges'));
 		$return .= $HTML->html_checkbox('otherfreeknowledge', '1', 'search_associated_forges_otherfreeknowledge', _('Extend search to include non-software projects'), $otherfreeknowledge);
 		$return .= $HTML->html_checkbox('gexact', '1', 'search_associated_forges_exact', _('Require all words'), $gexact);
 		$return .= $HTML->closeForm();
@@ -138,6 +140,26 @@ hosted on these forges from your own.");
 			return _('No stats available')." ".db_error();
 		}
 	}
+
+
+	function widget_instance($params) {
+		require_once 'common/widget/WidgetLayoutManager.class.php';
+
+		// FORGE HOMEPAGE
+		if ($params['widget'] == 'plugin_globalsearch_home') {
+			require_once 'globalsearch_Widget_Home.class.php';
+			$params['instance'] = new globalsearch_Widget_Home(WidgetLayoutManager::OWNER_TYPE_HOME, 0);
+		}
+
+
+	}
+	function widgets($params) {
+		if ($params['owner_type'] == WidgetLayoutManager::OWNER_TYPE_HOME) {
+			$params['fusionforge_widgets'][] = 'plugin_globalsearch_home';
+			return true;
+		}
+		return false;
+	}
 }
 
 // Local Variables:
diff --git a/src/plugins/globalsearch/common/globalsearch_Widget_Home.class.php b/src/plugins/globalsearch/common/globalsearch_Widget_Home.class.php
new file mode 100644
index 0000000..fd131bc
--- /dev/null
+++ b/src/plugins/globalsearch/common/globalsearch_Widget_Home.class.php
@@ -0,0 +1,51 @@
+<?php
+/**
+ * Copyright 2016, Franck Villaume - TrivialDev
+ *
+ * This file is a part of FusionForge.
+ *
+ * FusionForge is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * FusionForge is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with FusionForge. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+require_once 'common/include/HTTPRequest.class.php';
+
+class globalsearch_Widget_Home extends Widget {
+	var $title = '';
+	var $content = '';
+
+	function globalsearch_Widget_Home($owner_type, $owner_id) {
+		$request =& HTTPRequest::instance();
+		if ($owner_type == WidgetLayoutManager::OWNER_TYPE_HOME) {
+			$this->widget_id = 'plugin_globalsearch_home';
+			$this->group_id = $owner_id;
+		}
+		$this->Widget($this->widget_id);
+		$this->setOwner($owner_id, $owner_type);
+
+	}
+
+	function getTitle() {
+		return ($this->title ? $this->title : _('Global Project Search across multiple forges'));
+	}
+
+	function getDescription() {
+		return _('Search for projects existing on linked forges.');
+	}
+
+	function getContent() {
+		$pluginObject = plugin_get_object('globalsearch');
+		return $pluginObject->search_box();
+	}
+}
+
diff --git a/src/plugins/globalsearch/www/index.php b/src/plugins/globalsearch/www/index.php
index 37354a2..40c1be6 100644
--- a/src/plugins/globalsearch/www/index.php
+++ b/src/plugins/globalsearch/www/index.php
@@ -63,7 +63,7 @@ function highlight_target_words($word_array,$text) {
         return preg_replace("/($re)/i",'<span style="background-color:pink">\1</span>',$text);
 }
 
-$HTML->header(array('title'=>'Search','pagename'=>'search'));
+$HTML->header(array('title'=>_('Global Project Search'),'pagename'=>'search'));
 
 echo "<p>";
 
@@ -145,13 +145,13 @@ $qpa = db_construct_qpa($qpa, ')) ORDER BY '.$order) ;
 
 $limit=25;
 
-$result = db_query_qpa ($qpa, $limit+1, $offset, 'DB_SEARCH');
+$result = db_query_qpa ($qpa, $limit+1, $offset);
 $rows = $rows_returned = db_numrows($result);
 
 if (!$result || $rows < 1) {
         $no_rows = 1;
         echo "<h2>".sprintf (_('No matches found for ā€œ%sā€'), $gwords)."</h2>";
-        echo db_error('DB_SEARCH');
+        echo db_error();
 
 } else {
 
@@ -182,7 +182,7 @@ if (!$result || $rows < 1) {
                         . db_result($result, $i, 'project_link')."\" target=\"blank\">"
                         . html_image("ic/msg.png","10","12",array("border"=>"0"))." "
                         . highlight_target_words($array,db_result($result, $i, 'project_title'))."</a></td>
-<td>".highlight_target_words($array,db_result($result,$i,'project_description'))."</td>
+<td>".highlight_target_words($array,html_entity_decode(db_result($result,$i,'project_description')))."</td>
 <td><center><a href=\"".db_result($result,$i,'link')."\" target=\"_blank\">"
                         . db_result($result,$i,'title')."</a></center></td></tr>\n";
         }

-----------------------------------------------------------------------

Summary of changes:
 .../globalsearch/bin/get_assoc_sites_project.php   |  53 ++++++
 .../globalsearch/bin/get_assoc_sites_projects.pl   | 202 ---------------------
 .../common/GlobalsearchPlugin.class.php            |  24 ++-
 .../common/globalsearch_Widget_Home.class.php      |  51 ++++++
 src/plugins/globalsearch/www/index.php             |   8 +-
 5 files changed, 131 insertions(+), 207 deletions(-)
 create mode 100755 src/plugins/globalsearch/bin/get_assoc_sites_project.php
 delete mode 100755 src/plugins/globalsearch/bin/get_assoc_sites_projects.pl
 create mode 100644 src/plugins/globalsearch/common/globalsearch_Widget_Home.class.php


hooks/post-receive
-- 
FusionForge



More information about the Fusionforge-commits mailing list