Conditions | 15 |
Paths | 224 |
Total Lines | 75 |
Code Lines | 45 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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 | $moduleHelper = Xmf\Module\Helper::getHelper($dir); |
||
40 | |||
41 | $wikihome = strtolower($moduleHelper->getConfig('wiki_home_page')); |
||
42 | |||
43 | // fake a full url with page if at top of module |
||
44 | if (!isset($plugin_env['page']) && substr($metas['og:url'], -1) === '/') { |
||
45 | $plugin_env['page'] = $wikihome; |
||
46 | $metas['og:url'] .= 'index.php'; //$metas['og:url'] = $metas['og:url'] . 'index.php'; |
||
47 | } |
||
48 | |||
49 | if (isset($plugin_env['page'])) { |
||
50 | // cononicalize our url with our rules |
||
51 | // - page needs to be case insensitve (AbCde and AbcDe yield the same page) |
||
52 | $keyword = strtolower($plugin_env['page']); |
||
53 | // - strip any OOB data |
||
54 | if (substr($keyword, -1) === ')') { |
||
55 | $lparen = strpos($keyword, '('); |
||
56 | if ($lparen !== false) { |
||
57 | $keyword = substr($keyword, 0, $lparen); |
||
58 | } |
||
59 | } |
||
60 | |||
61 | // - eliminate index.php?page=wikihome |
||
62 | $ourscript = explode('?', urldecode($metas['og:url'])); |
||
63 | $ourscript_parts = pathinfo($ourscript[0]); |
||
64 | if ($ourscript_parts['basename'] !== 'index.php') { |
||
65 | return false; |
||
66 | } |
||
67 | if ($keyword === $wikihome && $ourscript_parts['basename'] === 'index.php') { |
||
68 | $newscript = $ourscript_parts['dirname'] . '/'; |
||
69 | } else { |
||
70 | $newscript = $ourscript[0] . '?page=' . $keyword; |
||
71 | } |
||
72 | $metas['og:url'] = $newscript; |
||
73 | |||
74 | $wikitable = $xoopsDB->prefix('gwiki_pages'); |
||
75 | $imagetable = $xoopsDB->prefix('gwiki_page_images'); |
||
76 | $sql = "SELECT title, meta_description, search_body, image_file FROM {$wikitable} p "; |
||
77 | $sql .= " left join {$imagetable} i on p.keyword=i.keyword and use_to_represent = 1 "; |
||
78 | $sql .= " where p.keyword = '{$keyword}' and active=1 "; |
||
79 | |||
80 | // set title and description |
||
81 | $result = $xoopsDB->query($sql); |
||
82 | if ($result) { |
||
83 | // if(!$xoopsDB->getRowsNum($result)) return false; |
||
84 | if ($myrow = $xoopsDB->fetchArray($result)) { |
||
85 | if (!empty($myrow['title'])) { |
||
86 | $metas['og:title'] = $myrow['title']; |
||
87 | } |
||
88 | if (!empty($myrow['search_body'])) { |
||
89 | $description = $myrow['search_body']; |
||
90 | $description = substr($description, 0, 40) . '...'; |
||
91 | $metas['og:description'] = $description; |
||
92 | } |
||
93 | if (!empty($myrow['meta_description'])) { |
||
94 | $description = $myrow['meta_description']; |
||
95 | $metas['og:description'] = $description; |
||
96 | } |
||
97 | if (!empty($myrow['image_file'])) { |
||
98 | $image_file = $myrow['image_file']; |
||
99 | $metas['og:image'] = XOOPS_URL . '/uploads/' . $dir . '/' . $image_file; |
||
100 | } |
||
101 | |||
102 | return true; |
||
103 | } |
||
104 | } |
||
105 | } |
||
106 | |||
107 | return false; |
||
108 | } |
||
109 |