page.php
4 years ago
page_author_archive.php
4 years ago
page_date_archive.php
4 years ago
page_home.php
4 years ago
page_not_found.php
4 years ago
page_post_type_archive.php
4 years ago
page_search.php
4 years ago
page_singular.php
4 years ago
page_term_archive.php
4 years ago
referrer.php
4 years ago
referrer.php
578 lines
| 1 | <?php |
| 2 | |
| 3 | use League\Uri\Uri; |
| 4 | |
| 5 | if (!class_exists('IAWP_Referrer')) { |
| 6 | class IAWP_Referrer |
| 7 | { |
| 8 | private $id = null; |
| 9 | private $url = null; |
| 10 | protected $host = null; |
| 11 | protected $matched_domain = null; |
| 12 | private $name = null; |
| 13 | private $referrer_type = null; |
| 14 | protected $views; |
| 15 | |
| 16 | private static $domains = [ |
| 17 | 'google.com' => [ |
| 18 | 'name' => 'Google', |
| 19 | 'referrer_type' => 'Search', |
| 20 | ], |
| 21 | 'google.ad' => 'google.com', |
| 22 | 'google.ae' => 'google.com', |
| 23 | 'google.com.af' => 'google.com', |
| 24 | 'google.com.ag' => 'google.com', |
| 25 | 'google.com.ai' => 'google.com', |
| 26 | 'google.al' => 'google.com', |
| 27 | 'google.am' => 'google.com', |
| 28 | 'google.co.ao' => 'google.com', |
| 29 | 'google.com.ar' => 'google.com', |
| 30 | 'google.as' => 'google.com', |
| 31 | 'google.at' => 'google.com', |
| 32 | 'google.com.au' => 'google.com', |
| 33 | 'google.az' => 'google.com', |
| 34 | 'google.ba' => 'google.com', |
| 35 | 'google.com.bd' => 'google.com', |
| 36 | 'google.be' => 'google.com', |
| 37 | 'google.bf' => 'google.com', |
| 38 | 'google.bg' => 'google.com', |
| 39 | 'google.com.bh' => 'google.com', |
| 40 | 'google.bi' => 'google.com', |
| 41 | 'google.bj' => 'google.com', |
| 42 | 'google.com.bn' => 'google.com', |
| 43 | 'google.com.bo' => 'google.com', |
| 44 | 'google.com.br' => 'google.com', |
| 45 | 'google.bs' => 'google.com', |
| 46 | 'google.bt' => 'google.com', |
| 47 | 'google.co.bw' => 'google.com', |
| 48 | 'google.by' => 'google.com', |
| 49 | 'google.com.bz' => 'google.com', |
| 50 | 'google.ca' => 'google.com', |
| 51 | 'google.cd' => 'google.com', |
| 52 | 'google.cf' => 'google.com', |
| 53 | 'google.cg' => 'google.com', |
| 54 | 'google.ch' => 'google.com', |
| 55 | 'google.ci' => 'google.com', |
| 56 | 'google.co.ck' => 'google.com', |
| 57 | 'google.cl' => 'google.com', |
| 58 | 'google.cm' => 'google.com', |
| 59 | 'google.cn' => 'google.com', |
| 60 | 'google.com.co' => 'google.com', |
| 61 | 'google.co.cr' => 'google.com', |
| 62 | 'google.com.cu' => 'google.com', |
| 63 | 'google.cv' => 'google.com', |
| 64 | 'google.com.cy' => 'google.com', |
| 65 | 'google.cz' => 'google.com', |
| 66 | 'google.de' => 'google.com', |
| 67 | 'google.dj' => 'google.com', |
| 68 | 'google.dk' => 'google.com', |
| 69 | 'google.dm' => 'google.com', |
| 70 | 'google.com.do' => 'google.com', |
| 71 | 'google.dz' => 'google.com', |
| 72 | 'google.com.ec' => 'google.com', |
| 73 | 'google.ee' => 'google.com', |
| 74 | 'google.com.eg' => 'google.com', |
| 75 | 'google.es' => 'google.com', |
| 76 | 'google.com.et' => 'google.com', |
| 77 | 'google.fi' => 'google.com', |
| 78 | 'google.com.fj' => 'google.com', |
| 79 | 'google.fm' => 'google.com', |
| 80 | 'google.fr' => 'google.com', |
| 81 | 'google.ga' => 'google.com', |
| 82 | 'google.ge' => 'google.com', |
| 83 | 'google.gg' => 'google.com', |
| 84 | 'google.com.gh' => 'google.com', |
| 85 | 'google.com.gi' => 'google.com', |
| 86 | 'google.gl' => 'google.com', |
| 87 | 'google.gm' => 'google.com', |
| 88 | 'google.gr' => 'google.com', |
| 89 | 'google.com.gt' => 'google.com', |
| 90 | 'google.gy' => 'google.com', |
| 91 | 'google.com.hk' => 'google.com', |
| 92 | 'google.hn' => 'google.com', |
| 93 | 'google.hr' => 'google.com', |
| 94 | 'google.ht' => 'google.com', |
| 95 | 'google.hu' => 'google.com', |
| 96 | 'google.co.id' => 'google.com', |
| 97 | 'google.ie' => 'google.com', |
| 98 | 'google.co.il' => 'google.com', |
| 99 | 'google.im' => 'google.com', |
| 100 | 'google.co.in' => 'google.com', |
| 101 | 'google.iq' => 'google.com', |
| 102 | 'google.is' => 'google.com', |
| 103 | 'google.it' => 'google.com', |
| 104 | 'google.je' => 'google.com', |
| 105 | 'google.com.jm' => 'google.com', |
| 106 | 'google.jo' => 'google.com', |
| 107 | 'google.co.jp' => 'google.com', |
| 108 | 'google.co.ke' => 'google.com', |
| 109 | 'google.com.kh' => 'google.com', |
| 110 | 'google.ki' => 'google.com', |
| 111 | 'google.kg' => 'google.com', |
| 112 | 'google.co.kr' => 'google.com', |
| 113 | 'google.com.kw' => 'google.com', |
| 114 | 'google.kz' => 'google.com', |
| 115 | 'google.la' => 'google.com', |
| 116 | 'google.com.lb' => 'google.com', |
| 117 | 'google.li' => 'google.com', |
| 118 | 'google.lk' => 'google.com', |
| 119 | 'google.co.ls' => 'google.com', |
| 120 | 'google.lt' => 'google.com', |
| 121 | 'google.lu' => 'google.com', |
| 122 | 'google.lv' => 'google.com', |
| 123 | 'google.com.ly' => 'google.com', |
| 124 | 'google.co.ma' => 'google.com', |
| 125 | 'google.md' => 'google.com', |
| 126 | 'google.me' => 'google.com', |
| 127 | 'google.mg' => 'google.com', |
| 128 | 'google.mk' => 'google.com', |
| 129 | 'google.ml' => 'google.com', |
| 130 | 'google.com.mm' => 'google.com', |
| 131 | 'google.mn' => 'google.com', |
| 132 | 'google.ms' => 'google.com', |
| 133 | 'google.com.mt' => 'google.com', |
| 134 | 'google.mu' => 'google.com', |
| 135 | 'google.mv' => 'google.com', |
| 136 | 'google.mw' => 'google.com', |
| 137 | 'google.com.mx' => 'google.com', |
| 138 | 'google.com.my' => 'google.com', |
| 139 | 'google.co.mz' => 'google.com', |
| 140 | 'google.com.na' => 'google.com', |
| 141 | 'google.com.ng' => 'google.com', |
| 142 | 'google.com.ni' => 'google.com', |
| 143 | 'google.ne' => 'google.com', |
| 144 | 'google.nl' => 'google.com', |
| 145 | 'google.no' => 'google.com', |
| 146 | 'google.com.np' => 'google.com', |
| 147 | 'google.nr' => 'google.com', |
| 148 | 'google.nu' => 'google.com', |
| 149 | 'google.co.nz' => 'google.com', |
| 150 | 'google.com.om' => 'google.com', |
| 151 | 'google.com.pa' => 'google.com', |
| 152 | 'google.com.pe' => 'google.com', |
| 153 | 'google.com.pg' => 'google.com', |
| 154 | 'google.com.ph' => 'google.com', |
| 155 | 'google.com.pk' => 'google.com', |
| 156 | 'google.pl' => 'google.com', |
| 157 | 'google.pn' => 'google.com', |
| 158 | 'google.com.pr' => 'google.com', |
| 159 | 'google.ps' => 'google.com', |
| 160 | 'google.pt' => 'google.com', |
| 161 | 'google.com.py' => 'google.com', |
| 162 | 'google.com.qa' => 'google.com', |
| 163 | 'google.ro' => 'google.com', |
| 164 | 'google.ru' => 'google.com', |
| 165 | 'google.rw' => 'google.com', |
| 166 | 'google.com.sa' => 'google.com', |
| 167 | 'google.com.sb' => 'google.com', |
| 168 | 'google.sc' => 'google.com', |
| 169 | 'google.se' => 'google.com', |
| 170 | 'google.com.sg' => 'google.com', |
| 171 | 'google.sh' => 'google.com', |
| 172 | 'google.si' => 'google.com', |
| 173 | 'google.sk' => 'google.com', |
| 174 | 'google.com.sl' => 'google.com', |
| 175 | 'google.sn' => 'google.com', |
| 176 | 'google.so' => 'google.com', |
| 177 | 'google.sm' => 'google.com', |
| 178 | 'google.sr' => 'google.com', |
| 179 | 'google.st' => 'google.com', |
| 180 | 'google.com.sv' => 'google.com', |
| 181 | 'google.td' => 'google.com', |
| 182 | 'google.tg' => 'google.com', |
| 183 | 'google.co.th' => 'google.com', |
| 184 | 'google.com.tj' => 'google.com', |
| 185 | 'google.tl' => 'google.com', |
| 186 | 'google.tm' => 'google.com', |
| 187 | 'google.tn' => 'google.com', |
| 188 | 'google.to' => 'google.com', |
| 189 | 'google.com.tr' => 'google.com', |
| 190 | 'google.tt' => 'google.com', |
| 191 | 'google.com.tw' => 'google.com', |
| 192 | 'google.co.tz' => 'google.com', |
| 193 | 'google.com.ua' => 'google.com', |
| 194 | 'google.co.ug' => 'google.com', |
| 195 | 'google.co.uk' => 'google.com', |
| 196 | 'google.com.uy' => 'google.com', |
| 197 | 'google.co.uz' => 'google.com', |
| 198 | 'google.com.vc' => 'google.com', |
| 199 | 'google.co.ve' => 'google.com', |
| 200 | 'google.vg' => 'google.com', |
| 201 | 'google.co.vi' => 'google.com', |
| 202 | 'google.com.vn' => 'google.com', |
| 203 | 'google.vu' => 'google.com', |
| 204 | 'google.ws' => 'google.com', |
| 205 | 'google.rs' => 'google.com', |
| 206 | 'google.co.za' => 'google.com', |
| 207 | 'google.co.zm' => 'google.com', |
| 208 | 'google.co.zw' => 'google.com', |
| 209 | 'google.cat' => 'google.com', |
| 210 | 'search.yahoo.com' => [ |
| 211 | 'name' => 'Yahoo', |
| 212 | 'referrer_type' => 'Search', |
| 213 | ], |
| 214 | 'at.search.yahoo.com' => 'search.yahoo.com', |
| 215 | 'be.search.yahoo.com' => 'search.yahoo.com', |
| 216 | 'br.search.yahoo.com' => 'search.yahoo.com', |
| 217 | 'ca.search.yahoo.com' => 'search.yahoo.com', |
| 218 | 'ch.search.yahoo.com' => 'search.yahoo.com', |
| 219 | 'de.search.yahoo.com' => 'search.yahoo.com', |
| 220 | 'es.search.yahoo.com' => 'search.yahoo.com', |
| 221 | 'espanol.search.yahoo.com' => 'search.yahoo.com', |
| 222 | 'fi.search.yahoo.com' => 'search.yahoo.com', |
| 223 | 'fr.search.yahoo.com' => 'search.yahoo.com', |
| 224 | 'gr.search.yahoo.com' => 'search.yahoo.com', |
| 225 | 'hk.search.yahoo.com' => 'search.yahoo.com', |
| 226 | 'id.search.yahoo.com' => 'search.yahoo.com', |
| 227 | 'ie.search.yahoo.com' => 'search.yahoo.com', |
| 228 | 'il.search.yahoo.com' => 'search.yahoo.com', |
| 229 | 'in.search.yahoo.com' => 'search.yahoo.com', |
| 230 | 'it.search.yahoo.com' => 'search.yahoo.com', |
| 231 | 'malaysia.search.yahoo.com' => 'search.yahoo.com', |
| 232 | 'nl.search.yahoo.com' => 'search.yahoo.com', |
| 233 | 'no.search.yahoo.com' => 'search.yahoo.com', |
| 234 | 'ph.search.yahoo.com' => 'search.yahoo.com', |
| 235 | 'pl.search.yahoo.com' => 'search.yahoo.com', |
| 236 | 'qc.search.yahoo.com' => 'search.yahoo.com', |
| 237 | 'ro.search.yahoo.com' => 'search.yahoo.com', |
| 238 | 'ru.search.yahoo.com' => 'search.yahoo.com', |
| 239 | 'se.search.yahoo.com' => 'search.yahoo.com', |
| 240 | 'sg.search.yahoo.com' => 'search.yahoo.com', |
| 241 | 'tr.search.yahoo.com' => 'search.yahoo.com', |
| 242 | 'tw.search.yahoo.com' => 'search.yahoo.com', |
| 243 | 'ua.search.yahoo.com' => 'search.yahoo.com', |
| 244 | 'uk.search.yahoo.com' => 'search.yahoo.com', |
| 245 | 'vn.search.yahoo.com' => 'search.yahoo.com', |
| 246 | 'za.search.yahoo.com' => 'search.yahoo.com', |
| 247 | 'uk.search.yahoo.com' => 'search.yahoo.com', |
| 248 | 'bing.com' => [ |
| 249 | 'name' => 'Bing', |
| 250 | 'referrer_type' => 'Search', |
| 251 | ], |
| 252 | 'yandex.com' => [ |
| 253 | 'name' => 'Yandex', |
| 254 | 'referrer_type' => 'Search', |
| 255 | ], |
| 256 | 'yandex.ru' => 'yandex.com', |
| 257 | 'yandex.ua' => 'yandex.com', |
| 258 | 'yandex.by' => 'yandex.com', |
| 259 | 'yandex.kz' => 'yandex.com', |
| 260 | 'yandex.uz' => 'yandex.com', |
| 261 | 'yandex.com.tr' => 'yandex.com', |
| 262 | 'yandex.fr' => 'yandex.com', |
| 263 | 'yandex.az' => 'yandex.com', |
| 264 | 'yandex.com.ge' => 'yandex.com', |
| 265 | 'yandex.com.am' => 'yandex.com', |
| 266 | 'yandex.co.il' => 'yandex.com', |
| 267 | 'yandex.lv' => 'yandex.com', |
| 268 | 'yandex.lt' => 'yandex.com', |
| 269 | 'yandex.ee' => 'yandex.com', |
| 270 | 'yandex.md' => 'yandex.com', |
| 271 | 'yandex.tm' => 'yandex.com', |
| 272 | 'yandex.tj' => 'yandex.com', |
| 273 | 'duckduckgo.com' => [ |
| 274 | 'name' => 'DuckDuckGo', |
| 275 | 'referrer_type' => 'Search', |
| 276 | ], |
| 277 | 'ecosia.org' => [ |
| 278 | 'name' => 'Ecosia', |
| 279 | 'referrer_type' => 'Search', |
| 280 | ], |
| 281 | 'qwant.com' => [ |
| 282 | 'name' => 'Qwant', |
| 283 | 'referrer_type' => 'Search', |
| 284 | ], |
| 285 | 'alohafind.com' => [ |
| 286 | 'name' => 'AlohaFind', |
| 287 | 'referrer_type' => 'Search', |
| 288 | ], |
| 289 | 'twitter.com' => [ |
| 290 | 'name' => 'Twitter', |
| 291 | 'referrer_type' => 'Social', |
| 292 | ], |
| 293 | 'facebook.com' => [ |
| 294 | 'name' => 'Facebook', |
| 295 | 'referrer_type' => 'Social', |
| 296 | ], |
| 297 | 'm.facebook.com' => 'facebook.com', |
| 298 | 'instagram.com' => [ |
| 299 | 'name' => 'Instagram', |
| 300 | 'referrer_type' => 'Social', |
| 301 | ], |
| 302 | 'tiktok.com' => [ |
| 303 | 'name' => 'TikTok', |
| 304 | 'referrer_type' => 'Social', |
| 305 | ], |
| 306 | 'linkedin.com' => [ |
| 307 | 'name' => 'LinkedIn', |
| 308 | 'referrer_type' => 'Social', |
| 309 | ], |
| 310 | 'pinterest.com' => [ |
| 311 | 'name' => 'Pinterest', |
| 312 | 'referrer_type' => 'Social', |
| 313 | ], |
| 314 | 'youtube.com' => [ |
| 315 | 'name' => 'YouTube', |
| 316 | 'referrer_type' => 'Social', |
| 317 | ], |
| 318 | 'artstation.com' => [ |
| 319 | 'name' => 'ArtStation', |
| 320 | 'referrer_type' => 'Social', |
| 321 | ], |
| 322 | 'bandcamp.com' => [ |
| 323 | 'name' => 'Bandcamp', |
| 324 | 'referrer_type' => 'Social', |
| 325 | ], |
| 326 | 'behance.net' => [ |
| 327 | 'name' => 'Behance', |
| 328 | 'referrer_type' => 'Social', |
| 329 | ], |
| 330 | 'bitbucket.org' => [ |
| 331 | 'name' => 'Bitbucket', |
| 332 | 'referrer_type' => 'Social', |
| 333 | ], |
| 334 | 'codepen.io' => [ |
| 335 | 'name' => 'CodePen', |
| 336 | 'referrer_type' => 'Social', |
| 337 | ], |
| 338 | 'deviantart.com' => [ |
| 339 | 'name' => 'DeviantArt', |
| 340 | 'referrer_type' => 'Social', |
| 341 | ], |
| 342 | 'discord.com' => [ |
| 343 | 'name' => 'Discord', |
| 344 | 'referrer_type' => 'Social', |
| 345 | ], |
| 346 | 'dribbble.com' => [ |
| 347 | 'name' => 'Dribble', |
| 348 | 'referrer_type' => 'Social', |
| 349 | ], |
| 350 | 'flickr.com' => [ |
| 351 | 'name' => 'Flickr', |
| 352 | 'referrer_type' => 'Social', |
| 353 | ], |
| 354 | 'github.com' => [ |
| 355 | 'name' => 'GitHub', |
| 356 | 'referrer_type' => 'Social', |
| 357 | ], |
| 358 | 'goodreads.com' => [ |
| 359 | 'name' => 'Goodreads', |
| 360 | 'referrer_type' => 'Social', |
| 361 | ], |
| 362 | 'news.ycombinator.com' => [ |
| 363 | 'name' => 'Hacker News', |
| 364 | 'referrer_type' => 'Social', |
| 365 | ], |
| 366 | 'meetup.com' => [ |
| 367 | 'name' => 'Meetup', |
| 368 | 'referrer_type' => 'Social', |
| 369 | ], |
| 370 | 'mixcloud.com' => [ |
| 371 | 'name' => 'Mixcloud', |
| 372 | 'referrer_type' => 'Social', |
| 373 | ], |
| 374 | 'patreon.com' => [ |
| 375 | 'name' => 'Patreon', |
| 376 | 'referrer_type' => 'Social', |
| 377 | ], |
| 378 | 'quora.com' => [ |
| 379 | 'name' => 'Quora', |
| 380 | 'referrer_type' => 'Social', |
| 381 | ], |
| 382 | 'qq.com' => [ |
| 383 | 'name' => 'Tencent QQ', |
| 384 | 'referrer_type' => 'Social', |
| 385 | ], |
| 386 | 'ravelry.com' => [ |
| 387 | 'name' => 'Ravelry', |
| 388 | 'referrer_type' => 'Social', |
| 389 | ], |
| 390 | 'reddit.com' => [ |
| 391 | 'name' => 'Reddit', |
| 392 | 'referrer_type' => 'Social', |
| 393 | ], |
| 394 | 'slack.com' => [ |
| 395 | 'name' => 'Slack', |
| 396 | 'referrer_type' => 'Social', |
| 397 | ], |
| 398 | 'slideshare.net' => [ |
| 399 | 'name' => 'SlideShare', |
| 400 | 'referrer_type' => 'Social', |
| 401 | ], |
| 402 | 'snapchat.com' => [ |
| 403 | 'name' => 'Snapchat', |
| 404 | 'referrer_type' => 'Social', |
| 405 | ], |
| 406 | 'soundcloud.com' => [ |
| 407 | 'name' => 'SoundCloud', |
| 408 | 'referrer_type' => 'Social', |
| 409 | ], |
| 410 | 'stackoverflow.com' => [ |
| 411 | 'name' => 'Stack Overflow', |
| 412 | 'referrer_type' => 'Social', |
| 413 | ], |
| 414 | 'stumbleupon.com' => [ |
| 415 | 'name' => 'StumbleUpon', |
| 416 | 'referrer_type' => 'Social', |
| 417 | ], |
| 418 | 'telegram.org' => [ |
| 419 | 'name' => 'Telegram', |
| 420 | 'referrer_type' => 'Social', |
| 421 | ], |
| 422 | 'weibo.com' => [ |
| 423 | 'name' => 'Weibo', |
| 424 | 'referrer_type' => 'Social', |
| 425 | ], |
| 426 | 'tumblr.com' => [ |
| 427 | 'name' => 'Tumblr', |
| 428 | 'referrer_type' => 'Social', |
| 429 | ], |
| 430 | 'twitch.tv' => [ |
| 431 | 'name' => 'Twitch', |
| 432 | 'referrer_type' => 'Social', |
| 433 | ], |
| 434 | 'vimeo.com' => [ |
| 435 | 'name' => 'Vimeo', |
| 436 | 'referrer_type' => 'Social', |
| 437 | ], |
| 438 | 'wechat.com' => [ |
| 439 | 'name' => 'WeChat', |
| 440 | 'referrer_type' => 'Social', |
| 441 | ], |
| 442 | 'whatsapp.com' => [ |
| 443 | 'name' => 'WhatsApp', |
| 444 | 'referrer_type' => 'Social', |
| 445 | ], |
| 446 | '500px.com' => [ |
| 447 | 'name' => '500px', |
| 448 | 'referrer_type' => 'Social', |
| 449 | ], |
| 450 | ]; |
| 451 | |
| 452 | public function __construct($id, $url, $views) |
| 453 | { |
| 454 | $this->id = $id; |
| 455 | $this->views = $views; |
| 456 | |
| 457 | $components = Uri::createFromString($url ?? ''); |
| 458 | $host = $components->getHost(); |
| 459 | |
| 460 | if (!is_null($host)) { |
| 461 | $this->url = $url; |
| 462 | $this->host = $host; |
| 463 | $this->populate_domain_data(); |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | private function populate_domain_data($host = null) |
| 468 | { |
| 469 | $host = $host ?? $this->host; |
| 470 | $matched_domain = null; |
| 471 | $data = null; |
| 472 | |
| 473 | foreach (self::$domains as $key => $value) { |
| 474 | if (str_ends_with($host, $key)) { |
| 475 | $matched_domain = $key; |
| 476 | $data = $value; |
| 477 | break; |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | if (is_array($data)) { |
| 482 | $this->url = 'https://' . $host; |
| 483 | $this->host = $host; |
| 484 | $this->matched_domain = $matched_domain; |
| 485 | $this->name = $data['name']; |
| 486 | $this->referrer_type = $data['referrer_type']; |
| 487 | } elseif (is_string($data)) { |
| 488 | $this->populate_domain_data($data); |
| 489 | } else { |
| 490 | return null; |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | public function id() |
| 495 | { |
| 496 | return $this->id; |
| 497 | } |
| 498 | |
| 499 | public function referrer_name() |
| 500 | { |
| 501 | if (!is_null($this->name)) { |
| 502 | return $this->name; |
| 503 | } elseif (!is_null($this->host)) { |
| 504 | if (str_starts_with($this->host, 'www.')) { |
| 505 | return substr($this->host, 4); |
| 506 | } |
| 507 | |
| 508 | return $this->host; |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | public function referrer() |
| 513 | { |
| 514 | if (!is_null($this->url)) { |
| 515 | return $this->url; |
| 516 | } else { |
| 517 | return 'Direct'; |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | public function referrer_type() |
| 522 | { |
| 523 | if (!is_null($this->referrer_type)) { |
| 524 | return $this->referrer_type; |
| 525 | } elseif (!is_null($this->host)) { |
| 526 | return 'Referrer'; |
| 527 | } else { |
| 528 | return 'Direct'; |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | public function views() |
| 533 | { |
| 534 | return $this->views; |
| 535 | } |
| 536 | |
| 537 | public function is_direct() |
| 538 | { |
| 539 | return !$this->is_referrer(); |
| 540 | } |
| 541 | |
| 542 | public function is_referrer() |
| 543 | { |
| 544 | return !is_null($this->url); |
| 545 | } |
| 546 | |
| 547 | public static function merge($referrers) |
| 548 | { |
| 549 | $merged_referrers = []; |
| 550 | |
| 551 | foreach ($referrers as $referrer) { |
| 552 | $match = false; |
| 553 | |
| 554 | foreach ($merged_referrers as $potential_match) { |
| 555 | if (!is_null($referrer->matched_domain) && !is_null($potential_match->matched_domain) && $referrer->matched_domain == $potential_match->matched_domain) { |
| 556 | $match = true; |
| 557 | $potential_match->views += $referrer->views; |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | if ($match == false) { |
| 562 | $merged_referrers[] = $referrer; |
| 563 | } |
| 564 | } |
| 565 | |
| 566 | usort($merged_referrers, function ($a, $b) { |
| 567 | if ($a->views == $b->views) { |
| 568 | return 0; |
| 569 | } else { |
| 570 | return ($a->views < $b->views) ? 1 : -1; |
| 571 | } |
| 572 | }); |
| 573 | |
| 574 | return $merged_referrers; |
| 575 | } |
| 576 | } |
| 577 | } |
| 578 |