CVS update: php3/functions
| From: | shane | Date: | Tue, 01 Sep 1998 19:40:50 +0000 |
| Subject: | CVS update: php3/functions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-721@lists.php.net to get a copy of this message | ||
Date: Tuesday September 1, 1998 @ 15:40
Author: shane
Update of /repository/php3/functions
In directory asf:/u2/tmp/cvs-serv28282/functions
Modified Files:
file.c file.h
Log Message:
add get_meta_tags function
Index: php3/functions/file.c
diff -c php3/functions/file.c:1.176 php3/functions/file.c:1.177
*** php3/functions/file.c:1.176 Tue Aug 25 14:49:05 1998
--- php3/functions/file.c Tue Sep 1 15:40:49 1998
***************
*** 26,32 ****
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
+----------------------------------------------------------------------+
*/
! /* $Id: file.c,v 1.176 1998/08/25 18:49:05 rasmus Exp $ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
--- 26,32 ----
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
+----------------------------------------------------------------------+
*/
! /* $Id: file.c,v 1.177 1998/09/01 19:40:49 shane Exp $ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
***************
*** 197,202 ****
--- 197,203 ----
{"copy", php3_file_copy, NULL},
{"tempnam", php3_tempnam, NULL},
{"file", php3_file, NULL},
+ {"get_meta_tags", php3_get_meta_tags, NULL},
{"set_socket_blocking", php3_set_socket_blocking, NULL},
#if (0 && HAVE_SYS_TIME_H && HAVE_SETSOCKOPT && defined(SO_SNDTIMEO)
&& defined(SO_RCVTIMEO))
{"set_socket_timeout", php3_set_socket_timeout, NULL},
***************
*** 207,212 ****
--- 208,341 ----
php3_module_entry php3_file_module_entry = {
"PHP_file", php3_file_functions, php3_minit_file, NULL, NULL, NULL, NULL,
STANDARD_MODULE_PROPERTIES
};
+
+ /* get_meta_tags(string filename);
+ extracts all meta tags from a file and creates variables from them (prefixed with meta_)
+ The meta tag must have a name and content attribute, otherwise it will be skipped.
+ The variable type created is always a string.
+ The function stops parsing at the closing head tag.
+ */
+ void php3_get_meta_tags(INTERNAL_FUNCTION_PARAMETERS) {
+ pval *filename, *arg2;
+ FILE *fp;
+ char buf[8192];
+ register int i=0;
+ int use_include_path = 0;
+
+ int issock=0, socketd=0;
+ TLS_VARS;
+
+ /* check args */
+ switch (ARG_COUNT(ht)) {
+ case 1:
+ if (getParameters(ht,1,&filename) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+ break;
+ case 2:
+ if (getParameters(ht,2,&filename,&arg2) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+ convert_to_long(arg2);
+ use_include_path = arg2->value.lval;
+ break;
+ default:
+ WRONG_PARAM_COUNT;
+ }
+ convert_to_string(filename);
+
+ fp = php3_fopen_wrapper(filename->value.str.val,"r",
use_include_path|ENFORCE_SAFE_MODE, &issock, &socketd);
+ if (!fp && !socketd) {
+ if (issock != BAD_URL) {
+ php3_strip_url_passwd(filename->value.str.val);
+ php3_error(E_WARNING,"File(\"%s\") -
%s",filename->value.str.val,strerror(errno));
+ }
+ RETURN_FALSE;
+ }
+
+ /* Initialize return array */
+ if (array_init(return_value) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ /* Now loop through the file and do the magic quotes thing if needed */
+ memset(buf,0,8191);
+ while((issock?SOCK_FGETS(buf,8191,socketd):(int)fgets(buf,8191,fp))
+ && !strstr(buf,"</head>") &&
!strstr(buf,"</HEAD>")) {
+ if(strstr(buf,"<meta")||strstr(buf,"<META")) {
+ pval entry;
+ int len,var_namelen;
+ char var_name[50],*var,*tmp,*end;
+
+ /* get the variable name from the name attribute of the meta tag */
+ tmp=strstr(buf,"name=\"");
+ if(tmp){
+ tmp+=6;
+ end=strstr(tmp,"\"");
+ if(end){
+ unsigned char *c;
+ *end='\0';
+ snprintf(var_name,50,"meta_%s",tmp);
+ *end='"';
+
+ c = var_name;
+ while (*c) {
+ switch(*c) {
+ case '.':
+ case '\\':
+ case '+':
+ case '*':
+ case '?':
+ case '[':
+ case '^':
+ case ']':
+ case '$':
+ case '(':
+ case ')':
+ case ' ':
+ *c++ ='_';
+ break;
+ default:
+ *c++ = tolower((unsigned char)*c);
+ }
+ }
+ var_namelen=strlen(var_name);
+ }
+
+ /* get the variable value from the content attribute of the meta tag */
+ tmp=strstr(buf,"content=\"");
+ if(tmp) {
+ tmp+=9;
+ end=strstr(tmp,"\"");
+ if(end) {
+ *end='\0';
+ var=estrdup(tmp);
+ *end='"';
+ }
+ }
+ }
+ if(var) {
+ if (php3_ini.magic_quotes_runtime) {
+ entry.value.str.val = _php3_addslashes(var,0,&len,0);
+ } else {
+ entry.value.str.len = strlen(var);
+ entry.value.str.val = var;
+ }
+ entry.type = IS_STRING;
+ _php3_hash_update(GLOBAL(active_symbol_table), var_name, var_namelen+1, (void *) &entry,
sizeof(pval),NULL);
+ }
+ }
+ }
+ if (issock) {
+ #if WIN32|WINNT
+ closesocket(socketd);
+ #else
+ close(socketd);
+ #endif
+ } else {
+ fclose(fp);
+ }
+ }
void php3_file(INTERNAL_FUNCTION_PARAMETERS) {
pval *filename, *arg2;
Index: php3/functions/file.h
diff -c php3/functions/file.h:1.24 php3/functions/file.h:1.25
*** php3/functions/file.h:1.24 Fri May 15 06:57:23 1998
--- php3/functions/file.h Tue Sep 1 15:40:50 1998
***************
*** 27,33 ****
+----------------------------------------------------------------------+
*/
! /* $Id: file.h,v 1.24 1998/05/15 10:57:23 zeev Exp $ */
#ifndef _FILE_H
#define _FILE_H
--- 27,33 ----
+----------------------------------------------------------------------+
*/
! /* $Id: file.h,v 1.25 1998/09/01 19:40:50 shane Exp $ */
#ifndef _FILE_H
#define _FILE_H
***************
*** 64,68 ****
--- 64,69 ----
extern void php3_file(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_set_socket_blocking(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_set_socket_timeout(INTERNAL_FUNCTION_PARAMETERS);
+ extern void php3_get_meta_tags(INTERNAL_FUNCTION_PARAMETERS);
#endif /* _FILE_H */
--
PHP Development Mailing List http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net
For help: php-dev-help@lists.php.net