function faviconGet($favicon_md5, $lid, $refresh = false) { $maxAge = $this->um->getParam('config', 'max_icon_age'); $select = $this->db->select('cvalue, to_days(now()) - to_days(created) as age', 'sitebar_cache', array('^1' => "type='favicon' AND", 'ckey' => $favicon_md5)); $found = $this->db->fetchRecord($select, true); $oldIcon = null; if (is_array($found)) { $oldIcon = $found['cvalue']; if (!$refresh && ($found['age'] <= $maxAge || !$lid)) { return $oldIcon; } } // if lid is not specified, the favicon wont be fetched into the cache if ($lid) { $favurl = ''; // If we are numeric if ($lid == "" . intval($lid)) { // Get the url corresponding to the link id $rset = $this->db->select(null, 'sitebar_link', array('lid' => $lid)); // Fetch the link properties $rlink = $this->db->fetchRecord($rset); // No such link? Return empty? if (!$rlink || !$rlink['favicon']) { return null; } $favurl = $rlink['favicon']; } else { $favurl = $lid; } $newIcon = ''; // Retrieve and test icon as binary string $page = new SB_PageParser($favurl); $errorCode = $page->retrieveFAVICON($newIcon); // We have unrecoverable error if ($errorCode >= 500) { return null; } // We have probably connection problem if ($errorCode >= 400) { if ($oldIcon) { $this->db->update('sitebar_cache', array('created' => array('now' => '')), array('^1' => "type='favicon' AND", 'ckey' => $favicon_md5)); } return $oldIcon; } if ($oldIcon) { $this->db->update('sitebar_cache', array('cvalue' => $newIcon), array('^1' => "type='favicon' AND", 'ckey' => $favicon_md5)); } else { if ($this->hasSpace()) { $this->saveFavicon($favurl, $newIcon); } } return $newIcon; } }