Mnemo::getSyncNotepads PHP Method

getSyncNotepads() public static method

Returns the notepads that should be used for syncing.
public static getSyncNotepads ( boolean $prune = false ) : array
$prune boolean Remove notepads ids from the sync list that no longer exist. The values are pruned *after* the results are passed back to the client to give sync clients a chance to remove their entries.
return array An array of notepad ids.
    public static function getSyncNotepads($prune = false)
    {
        $haveRemoved = false;
        $cs = unserialize($GLOBALS['prefs']->getValue('sync_notepads'));
        if (!empty($cs)) {
            if ($prune) {
                $notepads = self::listNotepads(true, Horde_Perms::DELETE);
                $cscopy = array_flip($cs);
                foreach ($cs as $c) {
                    if (empty($notepads[$c])) {
                        unset($cscopy[$c]);
                        $haveRemoved = true;
                    }
                }
                if ($haveRemoved) {
                    $GLOBALS['prefs']->setValue('sync_notepads', serialize(array_flip($cscopy)));
                }
            }
            return $cs;
        }
        if ($cs = self::getDefaultNotepad(Horde_Perms::DELETE)) {
            return array($cs);
        }
        return array();
    }

Usage Example

コード例 #1
0
ファイル: Api.php プロジェクト: DSNS-LAB/Dmail
 /**
  * Returns a list of available sources.
  *
  * @param boolean $writeable  If true, limits to writeable sources.
  * @param boolean $sync_only  Only include synchable notepads.
  *
  * @return array  An array of the available sources. Keys are source IDs,
  *                values are source titles.
  * @since 4.2.0
  */
 public function sources($writeable = false, $sync_only = false)
 {
     $out = array();
     foreach (Mnemo::listNotepads(false, $writeable ? Horde_Perms::EDIT : Horde_Perms::READ) as $key => $val) {
         $out[$key] = $val->get('name');
     }
     if ($sync_only) {
         $syncable = Mnemo::getSyncNotepads();
         $out = array_intersect_key($out, array_flip($syncable));
     }
     return $out;
 }