Conditions | 15 |
Paths | 224 |
Total Lines | 79 |
Code Lines | 48 |
Lines | 0 |
Ratio | 0 % |
Changes | 8 | ||
Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
34 | function fbcom_plugin(&$metas, $plugin_env) |
||
35 | { |
||
36 | global $xoopsDB; |
||
37 | |||
38 | $dir = basename(dirname(__DIR__)); |
||
39 | // Access module configs from block: |
||
40 | $moduleHandler = xoops_getHandler('module'); |
||
41 | $module = $moduleHandler->getByDirname($dir); |
||
42 | $configHandler = xoops_getHandler('config'); |
||
43 | $moduleConfig = $configHandler->getConfigsByCat(0, $module->getVar('mid')); |
||
44 | |||
45 | $wikihome = strtolower($moduleConfig['wiki_home_page']); |
||
46 | |||
47 | // fake a full url with page if at top of module |
||
48 | if (!isset($plugin_env['page']) && substr($metas['og:url'], -1) === '/') { |
||
49 | $plugin_env['page'] = $wikihome; |
||
50 | $metas['og:url'] .= 'index.php'; //$metas['og:url'] = $metas['og:url'] . 'index.php'; |
||
51 | } |
||
52 | |||
53 | if (isset($plugin_env['page'])) { |
||
54 | // cononicalize our url with our rules |
||
55 | // - page needs to be case insensitve (AbCde and AbcDe yield the same page) |
||
56 | $keyword = strtolower($plugin_env['page']); |
||
57 | // - strip any OOB data |
||
58 | if (substr($keyword, -1) === ')') { |
||
59 | $lparen = strpos($keyword, '('); |
||
60 | if ($lparen !== false) { |
||
61 | $keyword = substr($keyword, 0, $lparen); |
||
62 | } |
||
63 | } |
||
64 | |||
65 | // - eliminate index.php?page=wikihome |
||
66 | $ourscript = explode('?', urldecode($metas['og:url'])); |
||
67 | $ourscript_parts = pathinfo($ourscript[0]); |
||
68 | if ($ourscript_parts['basename'] !== 'index.php') { |
||
69 | return false; |
||
70 | } |
||
71 | if ($keyword === $wikihome && $ourscript_parts['basename'] === 'index.php') { |
||
72 | $newscript = $ourscript_parts['dirname'] . '/'; |
||
73 | } else { |
||
74 | $newscript = $ourscript[0] . '?page=' . $keyword; |
||
75 | } |
||
76 | $metas['og:url'] = $newscript; |
||
77 | |||
78 | $wikitable = $xoopsDB->prefix('gwiki_pages'); |
||
79 | $imagetable = $xoopsDB->prefix('gwiki_page_images'); |
||
80 | $sql = "SELECT title, meta_description, search_body, image_file FROM {$wikitable} p "; |
||
81 | $sql .= " left join {$imagetable} i on p.keyword=i.keyword and use_to_represent = 1 "; |
||
82 | $sql .= " where p.keyword = '{$keyword}' and active=1 "; |
||
83 | |||
84 | // set title and description |
||
85 | $result = $xoopsDB->query($sql); |
||
86 | if ($result) { |
||
87 | // if(!$xoopsDB->getRowsNum($result)) return false; |
||
88 | if ($myrow = $xoopsDB->fetchArray($result)) { |
||
89 | if (!empty($myrow['title'])) { |
||
90 | $metas['og:title'] = $myrow['title']; |
||
91 | } |
||
92 | if (!empty($myrow['search_body'])) { |
||
93 | $description = $myrow['search_body']; |
||
94 | $description = substr($description, 0, 40) . '...'; |
||
95 | $metas['og:description'] = $description; |
||
96 | } |
||
97 | if (!empty($myrow['meta_description'])) { |
||
98 | $description = $myrow['meta_description']; |
||
99 | $metas['og:description'] = $description; |
||
100 | } |
||
101 | if (!empty($myrow['image_file'])) { |
||
102 | $image_file = $myrow['image_file']; |
||
103 | $metas['og:image'] = XOOPS_URL . '/uploads/' . $dir . '/' . $image_file; |
||
104 | } |
||
105 | |||
106 | return true; |
||
107 | } |
||
108 | } |
||
109 | } |
||
110 | |||
111 | return false; |
||
112 | } |
||
113 |