Completed
Push — master ( c1777d...d193e2 )
by Michael
13:22
created

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * $Id: entry.php v 1.0 8 May 2004 hsalazar Exp $
4
 * Module: Lexikon - glossary module
5
 * Version: v 1.00
6
 * Release Date: 8 May 2004
7
 * Author: hsalazar
8
 * Licence: GNU
9
 */
10
11
include( "header.php" );
12
$xoopsOption['template_main'] = 'lx_entry.html';
13
include_once( XOOPS_ROOT_PATH . "/header.php" );
14
global $xoTheme, $xoopsUser,$lexikon_module_header;
15
$myts = MyTextSanitizer::getInstance();
16
xoops_load('XoopsUserUtility');
17
18
include_once XOOPS_ROOT_PATH.'/modules/lexikon/include/common.inc.php';
19
$highlight = lx_getmoduleoption('config_highlighter');
20
if ( $highlight ) include_once XOOPS_ROOT_PATH.'/modules/lexikon/class/keyhighlighter.class.php';
21
22
$entryID = isset($_GET['entryID']) ? intval($_GET['entryID']) : 0;
23
if (empty($entryID)) {
24
    redirect_header(XOOPS_URL.'/modules/lexikon/index.php',3,_MD_LEXIKON_UNKNOWNERROR);
25
    exit();
26
}
27
$entrytype = 1;
28
// permissions
29
$gperm_handler = xoops_gethandler('groupperm');
30
$groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
31
$module_id = $xoopsModule->getVar('mid');
32
$allowed_cats = $gperm_handler->getItemIds("lexikon_view", $groups, $module_id);
33
$catids = implode(',', $allowed_cats);
34
$catperms = " AND categoryID IN ($catids) ";
35
36
// If there's no entries yet in the system...
37
$publishedwords = lx_countWords();
38
$xoopsTpl->assign('publishedwords', $publishedwords);
39
if ( $publishedwords == 0 ) {
40
    $xoopsTpl -> assign ('empty', '1');
41
    $xoopsTpl -> assign ('stillnothing', _MD_LEXIKON_STILLNOTHINGHERE);
42
}
43
44
// To display the linked letter list
45
$alpha = lx_alphaArray();
46
$xoopsTpl->assign('alpha', $alpha);
47
48
// list($howmanyother) = $xoopsDB -> fetchRow($xoopsDB->query("SELECT COUNT(*) FROM " . $xoopsDB -> prefix ( "lxentries") . " WHERE init = '#' AND offline ='0' ".$catperms."" ));
49
list($howmanyother) = $xoopsDB -> fetchRow($xoopsDB->query("SELECT COUNT(entryID) FROM " . $xoopsDB -> prefix ( "lxentries") . " WHERE init = '#' AND offline ='0' ".$catperms." " ));
50
$xoopsTpl->assign('totalother', $howmanyother);
51
52
$xoopsTpl->assign('multicats', intval($xoopsModuleConfig['multicats']));
53
// To display the list of categories
54 View Code Duplication
if ( $xoopsModuleConfig['multicats'] == 1 ) {
55
    $xoopsTpl -> assign ( 'block0', lx_CatsArray() );
56
    $xoopsTpl->assign('layout', CONFIG_CATEGORY_LAYOUT_PLAIN);
57
    if ( $xoopsModuleConfig['useshots'] == 1 ) {
58
        $xoopsTpl->assign('show_screenshot', true);
59
        $xoopsTpl->assign('logo_maximgwidth', $xoopsModuleConfig['logo_maximgwidth']);
60
        $xoopsTpl->assign('lang_noscreenshot', _MD_LEXIKON_NOSHOTS);
61
    } else {
62
        $xoopsTpl->assign('show_screenshot', false);
63
    }
64
}
65
66
if ( !$entryID ) {
67
    redirect_header("javascript:history.go(-1)" , 2, _MD_LEXIKON_UNKNOWNERROR ) ;
68
    exit();
69
} else {
70
    if ($entryID <= 0) {
71
        redirect_header('javascript:history.go(-1)', 2, _MD_LEXIKON_UNKNOWNERROR);
72
        exit();
73
    }
74
    if ( !$xoopsUser || ( $xoopsUser->isAdmin($xoopsModule->mid()) && $xoopsModuleConfig['adminhits'] == 1 ) || ( $xoopsUser && !$xoopsUser -> isAdmin( $xoopsModule -> mid() ) ) ) {
75
        $xoopsDB -> queryF( "UPDATE " . $xoopsDB -> prefix( "lxentries" ) . " SET counter = counter+1 WHERE entryID = $entryID " );
76
    }
77
78
    $result = $xoopsDB -> query( "SELECT entryID, categoryID, term, init, definition, ref, url, uid, submit, datesub, counter, html, smiley, xcodes, breaks, block, offline, notifypub
79
                                 FROM " . $xoopsDB -> prefix( "lxentries" ) . "
80
                                 WHERE entryID = $entryID" );
81
    // verify result
82
    if ($xoopsDB->getRowsNum($result) <= 0) {
83
        redirect_header('javascript:history.go(-1)', 2, _MD_LEXIKON_UNKNOWNERROR);
84
        exit();
85
    }
86
}
87
88
while (list( $entryID, $categoryID, $term, $init, $definition, $ref, $url, $uid, $submit, $datesub, $counter, $html, $smiley, $xcodes, $breaks, $block, $offline) = $xoopsDB->fetchRow($result)) {
89
    $catID = intval($categoryID);
90 View Code Duplication
    if (!$gperm_handler->checkRight('lexikon_view', intval($categoryID), $groups, $module_id)) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
91
        redirect_header('index.php', 3, _NOPERM);
92
        exit();
93
    }
94
95
    $thisterm = array();
96
    $xoopsModule = XoopsModule::getByDirname("lexikon");
97
    $thisterm['id'] = intval($entryID);
98
    $thisterm['offline'] = intval($offline);
99
    // exit if offline - except admin
100
    if ($thisterm['offline'] == 1 && !$xoopsUserIsAdmin) {
101
        redirect_header('javascript:history.go(-1)' , 3, _MD_LEXIKON_ENTRYISOFF ) ;
102
        exit();
103
    }
104 View Code Duplication
    if ($xoopsModuleConfig['multicats'] == 1) {
105
        $thisterm['categoryID'] = intval($categoryID);
106
        $catname = $xoopsDB -> query ( "SELECT name FROM " . $xoopsDB -> prefix ( "lxcategories" ) . " WHERE categoryID = $categoryID ");
107
        while (list ($name) = $xoopsDB -> fetchRow ( $catname )) {
108
            $thisterm['catname'] = $myts -> htmlSpecialChars( $name );
109
        }
110
    }
111
112
    $glossaryterm = $myts -> htmlSpecialChars( $term );
113
    $thisterm['term'] = ucfirst($myts -> htmlSpecialChars( $term ));
114
    if ($init == '#') {
115
        $thisterm['init'] = _MD_LEXIKON_OTHER;
116
    } else {
117
        $thisterm['init'] = ucfirst($init);
118
    }
119
    $thisterm['offline'] = intval($offline);
120
121
    if ($xoopsModuleConfig['linkterms'] !=1 && $xoopsModuleConfig['linkterms'] != 2 ) {
122
        lx_module_header();
123
        $xoopsTpl->assign('xoops_module_header', $lexikon_module_header);
124
     } else {
125
        $xoopsTpl->assign("xoops_module_header", '<link rel="stylesheet" type="text/css" href="style.css" />');
126
     }
127
128
    if ($xoopsModuleConfig['linkterms'] != 1) {
129
        // Code to make links out of glossary terms
130
        $parts = explode(">", $definition);
131
132
        // First, retrieve all terms from the glossary...
133
        $allterms = $xoopsDB -> query( "SELECT entryID, term, definition FROM " . $xoopsDB -> prefix( "lxentries" ) . " WHERE offline ='0' ".$catperms." " );
134
135
        while ( list( $entryID, $term, $definition ) = $xoopsDB -> fetchrow( $allterms )) {
136
            foreach($parts as $key=>$part) {
137
                if ( $term != $glossaryterm) {
138
                    $term_q = preg_quote($term, '/');
139
                    $search_term = "/\b$term_q\b/SsUi";
140
                    //static link
141
                    $staticURL = "".XOOPS_URL."/modules/".$xoopsModule->getVar('dirname')."/entry.php?entryID=".ucfirst($entryID)."";
142
          switch ($xoopsModuleConfig['linkterms']) {
143
                        default:
144
                            $replace_term = '<span><b><a style="cursor:help;border-bottom: 1px dotted #000;color: #2F5376;" href="'.$staticURL.'" >'.$term.'</a></b></span>';
145
                            break;
146 View Code Duplication
                        case 3: //tooltip
147
                            $tooltipdef = $myts->htmlSpecialChars(xoops_substr(strip_tags($definition), 0, 150));
148
                            $replace_term = '<a class="parser" href="'.$staticURL.'" onMouseover="ddrivetip(\''.$tooltipdef.'\', 300)"; onMouseout=\'hideddrivetip()\'>'.$term.'</a>';
149
                            break;
150
                        case 4://simple popup
151
                            $replace_term = '<a style="cursor:help;border-bottom: 1px dotted #000;color: #2F5376;" href="#" onClick=\'popup("popup.php?entryID='.$entryID.'","details", 420, 350); return false\'>'.$term.'</a>';
152
                            break;
153 View Code Duplication
                        case 5:// balloon tooltip
154
                            $tooltipdef = $myts->htmlSpecialChars(xoops_substr(strip_tags($definition),0,150));
155
                            $replace_term = '<a class="parser" href="'.$staticURL.'" onMouseover="showToolTip(event,\''.$tooltipdef.'\');return false"; onMouseout=\'hideToolTip()\'>'.$term.'</a>';
156
                            break;
157 View Code Duplication
                        case 6:// shadow tooltip
158
                            $tooltipdef = $myts->htmlSpecialChars(xoops_substr(strip_tags($definition),0,150));
159
                            $replace_term = '<a class="parser" href="'.$staticURL.'" onmouseout="hideTooltip()" onmouseover="showTooltip(event,\''.$tooltipdef.'\')"; >'.$term.'</a>';
160
                            break;
161
                    }
162
                    $parts[$key] = preg_replace($search_term, $replace_term, $parts[$key]);
163
                }
164
            }
165
        }
166
        $definition = implode(">", $parts);
167
    }
168
    $thisterm['definition'] = $myts -> displayTarea( $definition, $html, $smiley, $xcodes, 1, $breaks );
169
    $thisterm['ref'] = $myts -> displayTarea( $ref, $html, $smiley, $xcodes, 1, $breaks );
170
    $thisterm['url'] = $myts -> makeClickable($url, $allowimage = 0);
171
    //$thisterm['submitter'] = XoopsUserUtility::getUnameFromId ( $uid );
172
    if ($xoopsModuleConfig['showsubmitter'] == 1 ) {
173
        $xoopsTpl -> assign('showsubmitter', true);
174
        if ($xoopsModuleConfig['authorprofile'] == 1 ) {
175
            $thisterm['submitter'] = lx_getLinkedProfileFromId ( $uid );
176
        } else {
177
            $thisterm['submitter'] = XoopsUserUtility::getUnameFromId ( $uid );
178
        }
179
    } else {
180
        $xoopsTpl -> assign('showsubmitter', false);
181
    }
182
    $thisterm['submit'] = intval($submit);
183
    $thisterm['datesub'] = formatTimestamp($datesub,$xoopsModuleConfig['dateformat']);
184
    $thisterm['counter'] = intval($counter);
185
    $thisterm['block'] = intval($block);
186
    $thisterm['dir'] = $xoopsModule->dirname();
187
    if ($highlight && isset($_GET['keywords'])) {
188
        $keywords = $myts -> htmlSpecialChars(trim(urldecode($_GET['keywords'])));
189
        $h= new lx_keyhighlighter ($keywords, true , 'lx_myhighlighter');
190
        $thisterm['definition'] = $h -> highlight($thisterm['definition']);
191
        $thisterm['ref'] = $h -> highlight( $thisterm['ref'] );
192
    }
193
}
194
//smartry strings
195
$xoopsTpl -> assign( 'thisterm', $thisterm );
196
$microlinks = lx_serviceLinks ( $thisterm );
197
$microlinksnew = lx_serviceLinksnew ( $thisterm );
198
$xoopsTpl -> assign ( 'microlinks', $microlinks );
199
$xoopsTpl -> assign ( 'microlinksnew', $microlinksnew );
200
$xoopsTpl -> assign ( 'lang_modulename', $xoopsModule->name() );
201
$xoopsTpl -> assign ( 'lang_moduledirname', $xoopsModule->getVar('dirname') );
202
$xoopsTpl -> assign ( 'entryID', $entryID);
203
$xoopsTpl -> assign ( 'submittedon', sprintf(_MD_LEXIKON_SUBMITTEDON,  $thisterm['datesub']) );
204
if ($xoopsModuleConfig['showsubmitter'] == 1 ) {
205
    $xoopsTpl -> assign ( 'submitter', sprintf(_MD_LEXIKON_SUBMITTEDBY, $thisterm['submitter']) );
206
}
207
$xoopsTpl -> assign ( 'counter', sprintf(_MD_LEXIKON_COUNT, $thisterm['counter']) );
208
$xoopsTpl -> assign ( 'entrytype', '1' );
209
210
// --- keywordshighligher ---
211
function lx_myhighlighter ($matches) {
212
    return '<span style="font-weight: bolder; background-color: #FFFF80;">' . $matches[0] . '</span>';
213
}
214
215
//--- Display tags of this term
216
#$itemid = $entryID;
217
$module_handler = xoops_gethandler('module');
218
$tagsModule = $module_handler->getByDirname("tag");
219
if (is_object($tagsModule)) {
220
    include_once XOOPS_ROOT_PATH."/modules/tag/include/tagbar.php";
221
222
    $itemid = isset($_GET['entryID']) ? intval($_GET['entryID']) : 0;
223
    $catid = 0;
224
    //$xoopsTpl->assign('tagbar', tagBar($itemid, $catid = 0));
225
    $tagbar = tagBar($itemid, $catid);
226
    if($tagbar) {
227
        $xoopsTpl->assign('tagbar',$tagbar);
228
        $tagsmeta = implode(' ',$tagbar["tags"]);
229
    } else {
230
        $tagsmeta = '';
231
    }
232
}   else {
233
    $xoopsTpl->assign('tagbar', false);
234
    $tagsmeta = '';
235
}
236
237
//--- linkterms assigns
238
// Balloontips
239
if ($xoopsModuleConfig['linkterms'] == 5 ) {
240
    $xoopsTpl->assign("balloontips", true);
241
} else {
242
    $xoopsTpl->assign("balloontips", false);
243
}
244
245
// Show Bookmark icons ?
246
switch ($xoopsModuleConfig['bookmarkme']) {
247
  case "0":
248
  default:
249
  $xoopsTpl->assign('bookmarkme', false);
250
  break;
251
  case "1":
252
    $xoopsTpl->assign('bookmarkme', 1);
253
    $xoopsTpl->assign('encoded_title', rawurlencode( $thisterm['term']));
254
  break;
255
  case "2":
256
  $xoopsTpl->assign('bookmarkme', 2);
257
  break;
258
  case "3":
259
  $xoopsTpl->assign('bookmarkme', 3);
260
  break;
261
}
262
// Meta data
263
$meta_description = xoops_substr( lx_html2text($thisterm['definition']), 0, 150 );
264
if ($xoopsModuleConfig['multicats'] == 1 ) {
265
    lx_create_pagetitle($thisterm['term']. ' - ' .$thisterm['catname']);
266
    lx_extract_keywords($myts->htmlSpecialChars($xoopsModule->name()).' ,'.$thisterm['term']. ' ,'.$thisterm['catname'].', '.$meta_description .', '.$tagsmeta);
267
    lx_get_metadescription($myts->htmlSpecialChars($xoopsModule->name()).' '.$thisterm['catname'].' '.$thisterm['term'].' '. $meta_description);
268
} else {
269
    lx_create_pagetitle($thisterm['term']);
270
    lx_extract_keywords($myts->htmlSpecialChars($xoopsModule->name()).' ,'.$thisterm['term'].', '.$meta_description .', '.$tagsmeta);
271
    lx_get_metadescription($myts->htmlSpecialChars($xoopsModule->name()).' '.$thisterm['term'].' '.$meta_description);
272
}
273
//Mondarse
274
include XOOPS_ROOT_PATH.'/include/comment_view.php';
275
//Mondarse
276
include_once XOOPS_ROOT_PATH.'/footer.php';
277