コード例 #1
0
 function faviconCheck($ico)
 {
     if (substr($ico, 0, 3) == 'GIF' || substr($ico, 6, 4) == 'JFIF' || substr($ico, 1, 3) == 'PNG') {
         return true;
     }
     /* It could be a BMP. It would then start with 'BM',
      * followed by a magic 0 after 6 bytes and a magic 40 after
      * 14 bytes (see http://www.daubnet.com/formats/BMP.html)
      */
     if (strlen($ico) >= 40 && substr($ico, 0, 2) == 'BM' && SB_PageParser::bigEndianBin2long(substr($ico, 6, 4)) == 0 && SB_PageParser::bigEndianBin2long(substr($ico, 14, 4)) == 40) {
         // Highly probable that this is really a BMP
         return true;
     }
     /* It could also be ICO-format. It would then start with
      * a leading zero, followed by a magic 1.
      * (see http://www.daubnet.com/formats/ICO.html)
      */
     if (strlen($ico) >= 4 && SB_PageParser::bigEndianBin2short(substr($ico, 0, 2)) == 0 && SB_PageParser::bigEndianBin2short(substr($ico, 2, 2)) == 1) {
         // Check for the magic 40 after some header bytes
         $offset = SB_PageParser::bigEndianBin2short(substr($ico, 4, 2)) * 16;
         if (SB_PageParser::bigEndianBin2long(substr($ico, 6 + $offset, 4)) == 40) {
             // Highly probable that this is really an ICO
             return true;
         }
     }
     return false;
 }
コード例 #2
0
ファイル: faviconcache.inc.php プロジェクト: kidexx/sitebar
 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;
     }
 }
コード例 #3
0
ファイル: sitebar.inc.php プロジェクト: codeministry/sitebar
    function drawHead()
    {
        $this->drawHeadPage();
        if ($this->useToolTips) {
            ?>
<div id="toolTip"></div>
<?php 
        }
        $this->writeMenu('node', $this->nodeMenu);
        $this->writeMenu('link', $this->linkMenu);
        // TODO       $this->writeMenu('nodeDrag', $this->nodeDragMenu);
        // TODO       $this->writeMenu('linkDrag', $this->linkDragMenu);
        $this->drawHeadLogo();
        $this->drawToolBar();
        $this->drawWarning();
        if ($this->appError) {
            echo <<<_DOC
<div id="warning">
{$this->appError}
</div>
_DOC;
        }
        if ($this->switches['user'] && strlen($this->switches['user'])) {
            $message = SB_T("Hide bookmarks from %s!", $this->switches['user']);
            echo '
<div id="info"><a href="' . SB_Page::absBaseUrl() . '?user="******"http://sitebar.org/version.php");
                    $lines = $page->getContent();
                    if (!$this->hasErrors()) {
                        $this->um->db->setData('version', 'Version');
                        $this->um->db->setData('version', 'lastcheck', time());
                        $this->um->db->setData('version', 'failed_count');
                        foreach ($lines as $line) {
                            if (preg_match("/^(.*)=(.*)\$/", $line, $reg)) {
                                $this->um->db->setData('version', $reg[1], $reg[2]);
                            }
                        }
                    } else {
                        $errors =& $this->getErrors();
                        // Hide errors
                        $errors = array();
                        echo '<div id="versionCheck">';
                        echo SB_T('Error during version check!');
                        echo '<br>';
                        echo SB_T('Will try in %d hours again.', 6);
                        echo "</div>\r";
                        $this->um->db->setData('version', 'lastcheck', time() - $interval + 60 * 60 * 6);
                        $this->um->db->setData('version', 'failed_count', intval($this->um->db->getData('version', 'failed_count')) + 1);
                    }
                }
                if (!$this->um->db->getData('version', 'failed_count')) {
                    $lastVersion = $this->um->db->getData('version', 'Version');
                    if ($lastVersion && version_compare(SB_CURRENT_RELEASE, $lastVersion, '<')) {
                        $this->um->db->setData('version', 'newversion', $lastVersion);
                        echo '<div id="versionCheck">';
                        $link = sprintf(' <a href="%s"' . SB_Page::target() . '>%s</a>', $this->um->db->getData('version', 'Download URL'), $lastVersion);
                        echo SB_T('New version available') . ': ' . $link;
                        echo '<br>';
                        echo SB_T('Severity') . ': ' . $this->um->db->getData('version', 'Severity');
                        echo "</div>\r";
                    }
                }
            }
        }
    }
コード例 #4
0
 function buildProperties()
 {
     $fields = array();
     $link = null;
     if ($this->command != 'Add Bookmark') {
         $link = $this->tree->getLink(SB_reqValInt('lid_acl'));
         if (!$link) {
             return null;
         }
     } else {
         $link = new SB_Tree_Link(array());
     }
     $fields['-hidden1-'] = array('name' => 'lid_acl', 'value' => $link->id);
     $fields['URL'] = array('name' => 'url');
     if ($this->command != 'Delete Bookmark') {
         /* Show the 'Retrieve Info' button only in case it has not been yet
          * performed
          */
         $fields['Get Bookmark Information'] = array('type' => 'addbutton');
         $fields['-hidden4-'] = array('name' => 'origin', 'value' => $this->command);
     }
     $fields['Bookmark Name'] = array('name' => 'name', 'maxlength' => 255);
     $size = strlen($link->comment);
     $MAXSIZETOEDIT = 4096;
     if ($size <= $MAXSIZETOEDIT) {
         $fields['Description'] = array('name' => 'comment', 'type' => 'textarea');
     } else {
         $fields['-raw1-'] = SB_T("Description too long for inplace editing, please use export feature!");
     }
     if ($this->um->getParam('user', 'use_favicons')) {
         $fields['Favicon'] = array('name' => 'favicon', 'maxsize' => 32000);
         $fields['-raw2-'] = '';
     }
     if (strlen(SB_reqVal('url'))) {
         $link->url = SB_reqVal('url');
     }
     if ($this->getInfo && strlen(SB_reqVal('url'))) {
         $link->name = SB_reqVal('name');
         $link->comment = SB_reqVal('comment');
         $link->favicon = SB_reqVal('favicon');
         /* Try to get the title and favicon */
         require_once './inc/pageparser.inc.php';
         $page = new SB_PageParser($link->url);
         if ($page->getInformation(array('CHARSET', 'TITLE', 'FAVURL', 'DESC', 'KEYWORDS'))) {
             $cp = 'iso-8859-1';
             if ($page->errorCode['CHARSET'] < PP_ERR) {
                 $cp = $page->info['CHARSET'];
             }
             require_once './inc/converter.inc.php';
             $c = new SB_Converter($this->um->getParam('config', 'use_conv_engine'), $cp);
             if (!$link->name && isset($page->info['TITLE'])) {
                 $link->name = $c->utf8RawUrlDecode($page->info['TITLE']);
             }
             if (!$link->comment && isset($page->info['DESC'])) {
                 $link->comment = $c->utf8RawUrlDecode($page->info['DESC']);
             }
             if ($this->um->getParam('user', 'use_favicons')) {
                 if (!$link->favicon && isset($page->info['FAVURL'])) {
                     $link->favicon = $page->info['FAVURL'];
                     /* Show the retrieved favicon. */
                     if ($this->command == 'Add Bookmark') {
                         /* Show the retrieved favicon. */
                         $wrong = SB_Skin::imgsrc('link_wrong_favicon');
                         $fields['-raw2-'] = "<div><img class='favicon' alt='' src='" . $link->favicon . "' onerror='this.src=\"{$wrong}\"'></div>";
                     } else {
                         $fields['-raw2-'] = $this->_buildFavicon(SB_reqValInt('lid_acl'), $link->favicon);
                     }
                 }
             }
         }
     }
     $fields['URL']['value'] = $link->url;
     $fields['Bookmark Name']['value'] = $link->name;
     $fields['Description']['value'] = $link->comment;
     if ($this->um->getParam('user', 'use_favicons')) {
         if ($this->command != 'Add Bookmark') {
             $favicon = $link->favicon;
             if (substr($link->favicon, 0, 7) == 'binary:') {
                 require_once './inc/faviconcache.inc.php';
                 $fc =& SB_FaviconCache::staticInstance();
                 $favicon = 'data:image/x-icon;base64,' . base64_encode($fc->faviconGet($link->favicon, null));
             }
             if ($link->favicon) {
                 $fields['-raw2-'] = $this->_buildFavicon($link->id, $link->favicon);
             }
         }
         $fields['Favicon']['value'] = $link->favicon;
     }
     $size = strlen($link->comment);
     $MAXSIZETOEDIT = 4096;
     if ($size <= $MAXSIZETOEDIT) {
         $fields['Description'] = array('name' => 'comment', 'type' => 'textarea', 'value' => $link->comment);
     } else {
         $fields['-raw1-'] = SB_T("Description too long for inplace editing, please use export feature!");
     }
     $fields['Feed Bookmark'] = array('name' => 'is_feed', 'type' => 'checkbox', 'title' => SB_P('command::tooltip_is_feed'));
     if ($link->is_feed) {
         $fields['Feed Bookmark']['checked'] = null;
     }
     if ($this->command == 'Add Bookmark' || $this->tree->inMyTree($link->id_parent)) {
         $fields['Private'] = array('name' => 'private', 'type' => 'checkbox', 'title' => SB_P('command::tooltip_private'));
         if ($link->private) {
             $fields['Private']['checked'] = null;
         }
     }
     if ($link->is_dead) {
         $fields['Dead Bookmark'] = array('name' => 'is_dead_check', 'type' => 'checkbox', 'checked' => null, 'title' => SB_P('command::tooltip_is_dead_check'));
         $fields['-hidden2-'] = array('name' => 'is_dead', 'type' => 'hidden', 'value' => 1);
     }
     if ($this->um->getParam('config', 'use_outbound_connection')) {
         $fields['Exclude From Validation'] = array('name' => 'novalidate', 'type' => 'checkbox', 'title' => SB_P('command::tooltip_novalidate'));
         if (!$link->validate) {
             $fields['Exclude From Validation']['checked'] = null;
         }
     }
     $fields['Target'] = array('name' => 'link_target', 'value' => $link->target);
     if ($this->command != 'Delete Bookmark') {
         if ($this->um->getParam('config', 'comment_impex') && strlen($link->comment) > 0 || strlen($link->comment) >= $MAXSIZETOEDIT) {
             $fields['Export Description'] = array('name' => 'command', 'type' => 'addbutton');
         }
         if ($this->um->getParam('config', 'comment_impex')) {
             $fields['Import Description'] = array('name' => 'command', 'type' => 'addbutton');
         }
     }
     if ($this->command == 'Properties') {
         $fields['Delete Bookmark'] = array('type' => 'addbutton');
     }
     return $fields;
 }
コード例 #5
0
 function validate($lid, $getFavicon)
 {
     if (!$this->um->isAuthorized('Validation', false, null, null, $lid)) {
         echo 'Access denied!';
         die;
     }
     $link = $this->tree->getLink($lid);
     $deadCount = $link->is_dead + 1;
     // Mark as dead
     $set = array('tested' => array('now' => ''), 'is_dead' => $deadCount < 127 ? $deadCount : 0);
     $this->tree->updateLink($link->id, $set, false);
     $page = new SB_PageParser($link->url);
     $page->getInformation($getFavicon ? array('FAVURL') : null);
     // Unmark early if not dead
     if (!intval($page->isDead)) {
         $set['is_dead'] = 0;
         $this->tree->updateLink($link->id, $set, false);
     }
     $location = SB_Skin::imgsrc('link');
     if ($page->isDead) {
         $location = SB_Skin::imgsrc('link_wrong_favicon');
     } else {
         $set = array();
         if (isset($page->info['FAVURL'])) {
             $favicon = $page->info['FAVURL'];
             $set['favicon'] = $favicon;
             if ($this->um->getParam('config', 'use_favicon_cache')) {
                 $location = 'favicon.php?' . md5($favicon) . '=' . $link->id;
             } else {
                 $location = $favicon;
             }
         } else {
             if ($getFavicon) {
                 $set['favicon'] = '';
             }
         }
         if (isset($set['favicon'])) {
             $this->tree->updateLink($link->id, $set, false);
         }
     }
     header('Location: ' . $location);
     exit;
 }