mirror of
https://github.com/php/php-src.git
synced 2024-11-29 21:04:10 +08:00
- new function hw_insertanchors(). It takes a document, a list of anchors
and its destination and inserts the anchors into the text.
This commit is contained in:
parent
0731f54d35
commit
ba862cc06d
@ -364,7 +364,8 @@ DLIST *fnCreateAnchorList(hw_objectID objID, char **anchors, char **docofanchorr
|
||||
if(NULL != anchors[i]) {
|
||||
object = anchors[i];
|
||||
docofanchorptr = docofanchorrec[i];
|
||||
reldestptr = reldestrec[i];
|
||||
if(reldestrec) /* FIXME reldestrec may only be NULL if anchormode != 0 */
|
||||
reldestptr = reldestrec[i];
|
||||
|
||||
/* Determine Position. Doesn't matter if Src or Dest
|
||||
The Position field should always be there. Though there
|
||||
@ -587,7 +588,8 @@ DLIST *fnCreateAnchorList(hw_objectID objID, char **anchors, char **docofanchorr
|
||||
|
||||
efree(anchors[i]);
|
||||
if(docofanchorrec[i]) efree(docofanchorrec[i]);
|
||||
if(reldestrec[i]) efree(reldestrec[i]);
|
||||
if(reldestrec)
|
||||
if(reldestrec[i]) efree(reldestrec[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2166,6 +2168,42 @@ int send_gettext(int sockfd, hw_objectID objectID, int mode, int rootid, char **
|
||||
return(0);
|
||||
}
|
||||
|
||||
send_insertanchors(char **text, int *count, char **anchors, char **destrec, int ancount, char **urlprefix, char **bodytag) {
|
||||
char **reldestrec = NULL;
|
||||
int mode = 0;
|
||||
hw_objectID objectID = 0;
|
||||
#ifdef newlist
|
||||
zend_llist *pAnchorList = NULL;
|
||||
#else
|
||||
DLIST *pAnchorList = NULL;
|
||||
#endif
|
||||
pAnchorList = fnCreateAnchorList(objectID, anchors, destrec, reldestrec, ancount, mode);
|
||||
|
||||
/* Free only the array, the objrecs has been freed in fnCreateAnchorList() */
|
||||
if(anchors) efree(anchors);
|
||||
if(destrec) efree(destrec);
|
||||
if(reldestrec) efree(reldestrec);
|
||||
|
||||
if(pAnchorList != NULL) {
|
||||
char *newtext;
|
||||
char *body;
|
||||
|
||||
newtext = fnInsAnchorsIntoText(*text, pAnchorList, &body, urlprefix);
|
||||
|
||||
#ifdef newlist
|
||||
zend_llist_destroy(pAnchorList);
|
||||
efree(pAnchorList);
|
||||
#else
|
||||
dlst_kill(pAnchorList, fnDeleteAnchor);
|
||||
#endif
|
||||
*bodytag = strdup(body);
|
||||
efree(body);
|
||||
*text = newtext;
|
||||
*count = strlen(newtext);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int send_edittext(int sockfd, char *objattr, char *text)
|
||||
{
|
||||
hg_msg msg, *retmsg;
|
||||
|
@ -225,6 +225,7 @@ extern int send_incollections(int sockfd, int retcol, int cobjids, hw_objectID *
|
||||
extern int send_getsrcbydest(int sockfd, hw_objectID objid, char ***childrec, int *count);
|
||||
extern int send_mapid(int sockfd, int servid, hw_objectID id, int *virtid);
|
||||
extern int send_dummy(int sockfd, hw_objectID objectID, int msgid, char **attributes);
|
||||
extern send_insertanchors(char **text, int *count, char **anchors, char **destrec, int ancount, char **urlprefix, char **bodytag);
|
||||
extern char *get_hw_info(hw_connection *conn);
|
||||
|
||||
#define send_mvcpdocscoll(sockfd,objectIDs,count,from,dest,mvcp) \
|
||||
|
@ -641,18 +641,22 @@ static int * make_ints_from_array(HashTable *lht) {
|
||||
|
||||
static char **make_strs_from_array(HashTable *arrht) {
|
||||
char **carr = NULL;
|
||||
char **ptr;
|
||||
zval *data, **dataptr;
|
||||
|
||||
zend_hash_internal_pointer_reset(arrht);
|
||||
if(NULL == (carr = emalloc(zend_hash_num_elements(arrht) * sizeof(char *))))
|
||||
return(NULL);
|
||||
return(NULL);
|
||||
ptr = carr;
|
||||
|
||||
/* Iterate through hash */
|
||||
while(zend_hash_get_current_data(arrht, (void **) &dataptr) == SUCCESS) {
|
||||
data = *dataptr;
|
||||
switch(data->type) {
|
||||
case IS_STRING:
|
||||
*carr++ = estrdup(data->value.str.val);
|
||||
*ptr = estrdup(data->value.str.val);
|
||||
fprintf(stderr, "carr[] = %s\n", *ptr);
|
||||
ptr++;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -2306,11 +2310,11 @@ PHP_FUNCTION(hw_pipedocument) {
|
||||
{
|
||||
case 2:
|
||||
if (getParameters(ht, 2, &arg1, &arg2) == FAILURE)
|
||||
RETURN_FALSE;
|
||||
WRONG_PARAM_COUNT;
|
||||
break;
|
||||
case 3:
|
||||
if (getParameters(ht, 3, &arg1, &arg2, &arg3) == FAILURE)
|
||||
RETURN_FALSE;
|
||||
WRONG_PARAM_COUNT;
|
||||
break;
|
||||
default:
|
||||
WRONG_PARAM_COUNT;
|
||||
@ -4084,20 +4088,35 @@ PHP_FUNCTION(hw_getrellink) {
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto string hw_insertanchors(int hwdoc, array anchorecs, array dest)
|
||||
/* {{{ proto string hw_insertanchors(int hwdoc, array anchorecs, array dest [, array urlprefixes])
|
||||
Inserts only anchors into text */
|
||||
PHP_FUNCTION(hw_insertanchors) {
|
||||
pval **arg1, **arg2, **arg3, **arg4;
|
||||
hw_document *hwdoc;
|
||||
int type, docid, error;
|
||||
int type, docid, error, argc, count;
|
||||
char *anchorstr;
|
||||
char **anchorrecs;
|
||||
char **dest;
|
||||
char **urlprefix;
|
||||
char *bodytag = NULL;
|
||||
HashTable *arrht;
|
||||
HashTable *prefixarray;
|
||||
|
||||
if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE) {
|
||||
argc = ZEND_NUM_ARGS();
|
||||
switch(argc)
|
||||
{
|
||||
case 3:
|
||||
if (zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE)
|
||||
WRONG_PARAM_COUNT;
|
||||
break;
|
||||
case 4:
|
||||
if (zend_get_parameters_ex(4, &arg1, &arg2, &arg3, &arg4) == FAILURE)
|
||||
WRONG_PARAM_COUNT;
|
||||
break;
|
||||
default:
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
|
||||
convert_to_long_ex(arg1);
|
||||
convert_to_array_ex(arg2);
|
||||
convert_to_array_ex(arg3);
|
||||
@ -4108,6 +4127,50 @@ PHP_FUNCTION(hw_insertanchors) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
/* check for the array with urlprefixes */
|
||||
if(argc == 4) {
|
||||
int i;
|
||||
convert_to_array_ex(arg4);
|
||||
prefixarray =(*arg4)->value.ht;
|
||||
if((prefixarray == NULL) || (zend_hash_num_elements(prefixarray) != 5)) {
|
||||
php_error(E_WARNING,"You must provide 5 urlprefixes (you have provided %d)", zend_hash_num_elements(prefixarray));
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
urlprefix = emalloc(5*sizeof(char *));
|
||||
zend_hash_internal_pointer_reset(prefixarray);
|
||||
for(i=0; i<5; i++) {
|
||||
char *key;
|
||||
zval *data, **dataptr;
|
||||
ulong ind;
|
||||
|
||||
zend_hash_get_current_key(prefixarray, &key, &ind);
|
||||
zend_hash_get_current_data(prefixarray, (void *) &dataptr);
|
||||
data = *dataptr;
|
||||
if (data->type != IS_STRING) {
|
||||
php_error(E_WARNING,"%s must be a String", key);
|
||||
RETURN_FALSE;
|
||||
} else if ( strcmp(key, "HW_DEFAULT_LINK") == 0 ) {
|
||||
urlprefix[HW_DEFAULT_LINK] = data->value.str.val;
|
||||
} else if ( strcmp(key, "HW_IMAGE_LINK") == 0 ) {
|
||||
urlprefix[HW_IMAGE_LINK] = data->value.str.val;
|
||||
} else if ( strcmp(key, "HW_BACKGROUND_LINK") == 0 ) {
|
||||
urlprefix[HW_BACKGROUND_LINK] = data->value.str.val;
|
||||
} else if ( strcmp(key, "HW_INTAG_LINK") == 0 ) {
|
||||
urlprefix[HW_INTAG_LINK] = data->value.str.val;
|
||||
} else if ( strcmp(key, "HW_APPLET_LINK") == 0 ) {
|
||||
urlprefix[HW_APPLET_LINK] = data->value.str.val;
|
||||
} else {
|
||||
php_error(E_WARNING,"%s is not a valid urlprefix", key);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
efree(key);
|
||||
zend_hash_move_forward(prefixarray);
|
||||
}
|
||||
} else {
|
||||
urlprefix = NULL;
|
||||
}
|
||||
|
||||
if(zend_hash_num_elements((*arg2)->value.ht) != zend_hash_num_elements((*arg3)->value.ht)) {
|
||||
php_error(E_WARNING,"Unequal number of elments in arrays");
|
||||
RETURN_FALSE;
|
||||
@ -4118,13 +4181,14 @@ PHP_FUNCTION(hw_insertanchors) {
|
||||
anchorrecs = make_strs_from_array(arrht);
|
||||
arrht = (*arg3)->value.ht;
|
||||
dest = make_strs_from_array(arrht);
|
||||
/*
|
||||
if (0 != (error = insertanchors(hwdoc->data, anchorrecs, dest, zend_hash_num_elements(arrht)))) {
|
||||
|
||||
if (0 != (error = send_insertanchors(&(hwdoc->data), &count, anchorrecs, dest, zend_hash_num_elements(arrht), urlprefix, &bodytag))) {
|
||||
php_error(E_WARNING, "command (insertanchors) returned %d\n", error);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
*/
|
||||
RETURN_STRING(anchorstr, 0);
|
||||
hwdoc->size = count;
|
||||
|
||||
RETURN_TRUE;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user